A pickup entity that awards reserve ammo for a specific ammo resource. It stores an AmmoType and AmmoAmount, checks if the player can pick it up by comparing current reserve to the resource max, and adds ammo via the inventory GiveAmmo call.
/// <summary>
/// A pickup that gives the player reserve ammo for a matching weapon.
/// </summary>
public sealed class AmmoPickup : BasePickup
{
/// <summary>
/// The ammo resource this pickup gives ammo for.
/// When set, ammo is added directly to the player's shared pool for that resource.
/// </summary>
[Property, Group( "Ammo" )] public BaseAmmoResource AmmoType { get; set; }
/// <summary>
/// The quantity of ammo to give.
/// </summary>
[Property, Group( "Ammo" )] public int AmmoAmount { get; set; }
public override bool CanPickup( Player player, PlayerInventory inventory )
{
if ( AmmoType is null || inventory is null ) return false;
return inventory.GetAmmo( AmmoType ) < AmmoType.MaxReserve;
}
protected override bool OnPickup( Player player, PlayerInventory inventory )
{
if ( AmmoType is null || inventory is null ) return false;
// GiveAmmo clamps to the resource's max and reports what actually went in.
return inventory.GiveAmmo( AmmoType, AmmoAmount ) > 0;
}
}