40 lines
746 B
C#
40 lines
746 B
C#
namespace Sasalka;
|
|
|
|
public abstract class AmmoUseableBase : UseableBase
|
|
{
|
|
protected InventoryItem AmmoItem => FindAmmoItem();
|
|
|
|
private InventoryItem FindAmmoItem()
|
|
{
|
|
// var ammoDefinition = new InventoryItemDefinition();
|
|
|
|
return Dedugan.Local.Inventory.Items.FirstOrDefault( i => i.Definition.Name == "Pistol Ammo" );
|
|
}
|
|
|
|
public override bool CanUse()
|
|
{
|
|
var ammo = AmmoItem;
|
|
return base.CanUse() && ammo != null && ammo.Count > 0;
|
|
}
|
|
|
|
public override void Use()
|
|
{
|
|
if ( !CanUse() )
|
|
return;
|
|
|
|
OnUse();
|
|
|
|
var ammo = AmmoItem;
|
|
if ( ammo != null )
|
|
{
|
|
ammo.Count--;
|
|
Log.Info( $"[AmmoUseableBase] Ammo left: {ammo.Count}" );
|
|
|
|
if ( ammo.Count <= 0 )
|
|
{
|
|
Dedugan.Local.Inventory.RemoveItem( ammo );
|
|
}
|
|
}
|
|
}
|
|
}
|