Items/Pickups/ArmourPickup.cs

A sealed pickup component that gives armour to a player. It defines a configurable ArmourGive value, prevents pickup if the player already has max armour and the pickup would add positive armour, and on pickup adds the armour clamped to the player's MaxArmour and increments a pickup stat.

/// <summary>
/// A pickup that gives the player some armour.
/// </summary>
public sealed class ArmourPickup : BasePickup
{
	/// <summary>
	/// How much armour to give to the player
	/// </summary>
	[Property, Group( "Armour" )] float ArmourGive { get; set; } = 0;

	public override bool CanPickup( Player player, PlayerInventory inventory )
	{
		if ( player.Armour >= player.MaxArmour && ArmourGive > 0 )
			return false;

		return true;
	}

	protected override bool OnPickup( Player player, PlayerInventory inventory )
	{
		player.Armour = (player.Armour + ArmourGive).Clamp( 0, player.MaxArmour );
		player.PlayerData.AddStat( $"pickup.armor" );

		return true;
	}
}