perks/CurseHealthpackMaxHp.cs

A unique curse perk that reduces the player's max HP each time they pick up a healthpack. It tracks cumulative reductions in _hpLost, applies a negative modifier to PlayerStat.MaxHp, spawns a floater text, and triggers icon/visual highlights.

Networking
using Sandbox;

[Perk( Rarity.Unique, curse: true, alwaysOfferDebug: false )]
public class CurseHealthpackMaxHp : Perk
{
	private int _hpLost;

	static CurseHealthpackMaxHp()
	{
		Register<CurseHealthpackMaxHp>(
			name: "Attrition",
			imagePath: "textures/icons/vector/curse_healthpack_max_hp.png",
			description: level => "-1 max hp when you get healthpack"
		);
	}

	public override void Start()
	{
		base.Start();

		HighlightColor = new Color( 0.7f, 0.2f, 0.2f );
		HighlightDuration = 0.35f;
		HighlightOpacity = 3f;
	}

	public override void Refresh()
	{
		base.Refresh();
	}

	public override void OnGainHealthpack( float amount )
	{
		base.OnGainHealthpack( amount );

		_hpLost += 1;
		Player.Modify( this, PlayerStat.MaxHp, -_hpLost, ModifierType.Add );

		Manager.Instance.SpawnFloaterTextRpc( Player.WorldPosition.WithZ( 65f ), $"-1 MAX HP", new Color( 0.8f, 0.1f, 0.5f ), size: 1.1f, floaterType: FloaterType.NegativeMessage );

		Highlight();

		IconScale = Game.Random.Float( 1.1f, 1.2f );
		IconAngleOffset = Game.Random.Float( 8f, 14f ) * (Game.Random.Int( 0, 1 ) == 0 ? -1f : 1f);
	}
}