perks/PerkPoisonDoubleDmgLoseHp.cs

A Perk class 'Poison Veins' for a game. It doubles poison damage via a player stat multiplier and reduces the player's max HP by 1 each time the player is hit (except self damage), showing a floater and highlight on hit.

Networking
using System;
using Sandbox;

[Perk( Rarity.Unique, includedAtStart: false, locked: true, minUnlocksReq: 2, alwaysOfferDebug: false )]
public class PerkPoisonDoubleDmgLoseHp : Perk
{
	private int _maxHp;

	static PerkPoisonDoubleDmgLoseHp()
	{
		Register<PerkPoisonDoubleDmgLoseHp>(
			name: "Poison Veins",
			imagePath: "textures/icons/vector/poison_double_dmg_lose_hp.png",
			description: level => $"+100% poison dmg\n-1 max hp when hit"
		);
	}

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

		HighlightColor = new Color( 1f, 0f, 0f );
		HighlightDuration = 0.2f;
		HighlightOpacity = 4f;
	}

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

		Player.Modify( this, PlayerStat.PoisonDamage, 2f, ModifierType.Mult );
	}

	public override void OnHit( float amount, DamageType damageType, bool isSelfInflicted, Vector2 dir, float force, Enemy enemySource, EnemyType enemyType, float previousHealth )
	{
		base.OnHit( amount, damageType, isSelfInflicted, dir, force, enemySource, enemyType, previousHealth );

		if ( damageType == DamageType.Self )
			return;

		_maxHp--;
		Player.Modify( this, PlayerStat.MaxHp, _maxHp, 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);
	}
}