A Perk class that registers a unique rarity perk called "Ultra Rare" and increases the player's chance to get Legendary and Unique items based on the perk level.
using System;
using Sandbox;
[Perk( Rarity.Unique, locked: true, alwaysOfferDebug: false )]
public class PerkRarityUnique : Perk
{
private enum Mod { Chance };
static PerkRarityUnique()
{
Register<PerkRarityUnique>(
name: "Ultra Rare",
imagePath: "textures/icons/vector/rarity_unique.png",
description: level => $"+{(int)GetValue( level, Mod.Chance, true )}% chance of\nLegendary and Unique perks"
);
}
public override void Start()
{
base.Start();
}
public override void Refresh()
{
base.Refresh();
Player.Modify( this, PlayerStat.RarityIncreaseLegendary, GetValue( Level, Mod.Chance ), ModifierType.Add );
Player.Modify( this, PlayerStat.RarityIncreaseUnique, GetValue( Level, Mod.Chance ), ModifierType.Add );
}
private static float GetValue( int level, Mod mod, bool isPercent = false )
{
switch ( mod )
{
case Mod.Chance:
default:
return isPercent
? 300f * level
: 3.00f * level;
}
}
}