charms/CharmHealthpackExtraArmor.cs

Charm component that converts excess health from healthpacks into armor for the player. It defines an item id, a description, and overrides OnGainHealthpack to calculate excess healed amount and grant that as armor via an RPC.

Networking
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 );
	}
}