A perk component for a player called PerkFrictionReduction (disabled by attribute). It defines modifiers for move speed, dash strength, and friction and applies them on Refresh by calling Player.Modify with values from GetValue.
using System;
using Sandbox;
[Perk( Rarity.Unique, disabled: true, alwaysOfferDebug: false )]
public class PerkFrictionReduction : Perk
{
private enum Mod { MoveSpeed, DashStrength, FrictionReductionPercent };
static PerkFrictionReduction()
{
//Register<PerkFrictionReduction>(
// name: "Rollerblades",
// imagePath: "textures/icons/vector/friction_reduction.png",
// description: level => $"-{GetValue( level, Mod.MoveSpeed, true )}% move speed\n-{GetValue( level, Mod.DashStrength, true )}% dash strength\n-{GetValue( level, Mod.FrictionReductionPercent, true )}% friction",
// upgradeDescription: level => $"-{GetValue( level - 1, Mod.MoveSpeed, true )}%→-{GetValue( level, Mod.MoveSpeed, true )}% move speed\n-{GetValue( level - 1, Mod.DashStrength, true )}%→-{GetValue( level, Mod.DashStrength, true )}% dash strength\n-{GetValue( level - 1, Mod.FrictionReductionPercent, true )}%→-{GetValue( level, Mod.FrictionReductionPercent, true )}% friction"
//);
}
public override void Start()
{
base.Start();
}
// todo: this is OP?
public override void Refresh()
{
base.Refresh();
Player.Modify( this, PlayerStat.MoveSpeedMultiplier, GetValue( Level, Mod.MoveSpeed ), ModifierType.Mult );
Player.Modify( this, PlayerStat.DashStrength, GetValue( Level, Mod.DashStrength ), ModifierType.Mult );
Player.Modify( this, PlayerStat.Friction, GetValue( Level, Mod.FrictionReductionPercent ), ModifierType.Mult );
}
private static float GetValue( int level, Mod mod, bool isPercent = false )
{
switch ( mod )
{
case Mod.MoveSpeed:
default:
return isPercent
? 40f
: 1f - 0.4f;
case Mod.DashStrength:
return isPercent
? 60f * level
: 1f - 0.60f;
case Mod.FrictionReductionPercent:
return isPercent
? 70f
: 1f - 0.7f;
}
}
}