Perk class 'PerkDashLength' that registers a rare perk called "Leg Day" and modifies player dash stats. It increases dash distance and dash invulnerability time based on perk level and exposes description strings including percent values.
using System;
using Sandbox;
[Perk( Rarity.Rare, alwaysOfferDebug: false )]
public class PerkDashLength : Perk
{
private enum Mod { DashLength };
static PerkDashLength()
{
Register<PerkDashLength>(
name: "Leg Day",
imagePath: "textures/icons/vector/dash_strength.png",
description: level => $"+{GetValue( level, Mod.DashLength, true )}% dash distance",
upgradeDescription: level => $"+{GetValue( level - 1, Mod.DashLength, true )}%→{GetValue( level, Mod.DashLength, true )}% dash distance"
);
}
public override void Start()
{
base.Start();
}
public override void Refresh()
{
base.Refresh();
Player.Modify( this, PlayerStat.DashStrength, GetValue( Level, Mod.DashLength ), ModifierType.Mult );
Player.Modify( this, PlayerStat.DashInvulnTime, GetValue( Level, Mod.DashLength ), ModifierType.Mult );
}
private static float GetValue( int level, Mod mod, bool isPercent = false )
{
switch ( mod )
{
case Mod.DashLength:
default:
return isPercent
? 15f + 25f * level
: 1f + 0.15f + 0.25f * level;
}
}
}