Add ammo consumption and item pickup systems
This commit is contained in:
19
GameCore/Combat/Effects/ConsumeAmmoCost.cs
Normal file
19
GameCore/Combat/Effects/ConsumeAmmoCost.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using GameCore.Combat.Interfaces;
|
||||
using GameCore.Inventory;
|
||||
|
||||
namespace GameCore.Combat.Effects;
|
||||
|
||||
public class ConsumeAmmoCost(string ammoId, int amount) : ICostEffect
|
||||
{
|
||||
public void Execute(EffectContext context)
|
||||
{
|
||||
var inventory = context.World.GetComponent<InventoryComponent>(context.Owner);
|
||||
inventory?.RemoveItem(ammoId, amount);
|
||||
}
|
||||
|
||||
public bool CanAfford(EffectContext context)
|
||||
{
|
||||
var inventory = context.World.GetComponent<InventoryComponent>(context.Owner);
|
||||
return inventory != null && inventory.HasItem(ammoId, amount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user