charms/CharmHealthpackExtraArmor.cs

A charm component that converts any excess health gained from a healthpack into armor. It defines an item id, a description string, and overrides OnGainHealthpack to compute excess healing and award armor via an RPC.

using System;

public class CharmHealthpackExtraArmor : Charm
{
	public const string ItemId = "charm_healthpack_extra_armor";

	public static string Description() => $"Excess healthpack hp becomes armor-item";

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

		float excess = Math.Max( 0f, amount - (Player.GetSyncStat( PlayerStat.MaxHp ) - Player.Health) );
		if ( excess > 0f )
			Player.GainArmorRpc( (int)excess );
	}
}