A game perk that increases player maximum health. It registers a Perk named "Healthy Diet" with UI strings and applies a multiplicative MaxHp modifier when refreshed, scaling by perk level.
using System;
using Sandbox;
[Perk( Rarity.Uncommon, alwaysOfferDebug: false )]
public class PerkMaxHealth : Perk
{
private enum Mod { MaxHp };
static PerkMaxHealth()
{
Register<PerkMaxHealth>(
name: "Healthy Diet",
imagePath: "textures/icons/vector/max_health.png",
description: level => $"+{(int)GetValue( level, Mod.MaxHp, true )}% max hp",
upgradeDescription: level => $"+{(int)GetValue( level - 1, Mod.MaxHp, true )}%→{(int)GetValue( level, Mod.MaxHp, true )}% max hp"
);
}
public override void Start()
{
base.Start();
}
public override void Refresh()
{
base.Refresh();
// todo: how does this interact with things that change max hp by a flat amount? should this instead add a flat amount based on current hp, instead of multiplying each time max hp stat is refreshed?
Player.Modify( this, PlayerStat.MaxHp, GetValue( Level, Mod.MaxHp ), ModifierType.Mult );
}
private static float GetValue( int level, Mod mod, bool isPercent = false )
{
switch ( mod )
{
case Mod.MaxHp:
default:
return isPercent
? (5f + 15f * level)
: 1f + (0.05f + 0.15f * level);
}
}
}