A pickup entity that grants a player ammo. It stores which BaseAmmoResource and an amount, checks if the inventory can accept more ammo, gives the ammo on pickup, and logs a stat on the player.
/// <summary>
/// A pickup that gives the player ammo.
/// </summary>
public sealed class AmmoPickup : BasePickup
{
/// <summary>
/// Which ammo <see cref="BaseAmmoResource"/> we give the player
/// </summary>
[Property, Group( "Ammo" )] public BaseAmmoResource AmmoResource { get; set; }
/// <summary>
/// The quantity of ammo
/// </summary>
[Property, Group( "Ammo" )] public int AmmoAmount { get; set; }
public override bool CanPickup( Player player, PlayerInventory inventory )
{
if ( !AmmoResource.IsValid() || !inventory.IsValid() )
return false;
return inventory.GetAmmo( AmmoResource ) < AmmoResource.MaxReserve;
}
protected override bool OnPickup( Player player, PlayerInventory inventory )
{
inventory.GiveAmmo( AmmoResource, AmmoAmount, true );
player.PlayerData.AddStat( $"pickup.ammo.{AmmoResource.Title}" );
return true;
}
}