Refactor ConsumeAmmoCost to use readonly field for ammoId and improve Entity struct equality methods
This commit is contained in:
@@ -6,20 +6,22 @@ namespace GameCore.Combat.Effects;
|
||||
|
||||
public class ConsumeAmmoCost(string ammoId, int amount) : ICostEffect
|
||||
{
|
||||
public readonly string AmmoId = ammoId;
|
||||
|
||||
public void Execute(EffectContext context)
|
||||
{
|
||||
var inventory = context.World.GetComponent<InventoryComponent>(context.Owner);
|
||||
if (inventory == null) return;
|
||||
|
||||
inventory.RemoveItem(ammoId, amount);
|
||||
inventory.RemoveItem(AmmoId, amount);
|
||||
|
||||
var newQuantity = inventory.GetItemCount(ammoId);
|
||||
context.World.PublishEvent(new InventoryItemChangedEvent(context.Owner, ammoId, newQuantity));
|
||||
var newQuantity = inventory.GetItemCount(AmmoId);
|
||||
context.World.PublishEvent(new InventoryItemChangedEvent(context.Owner, AmmoId, newQuantity));
|
||||
}
|
||||
|
||||
public bool CanAfford(EffectContext context)
|
||||
{
|
||||
var inventory = context.World.GetComponent<InventoryComponent>(context.Owner);
|
||||
return inventory != null && inventory.HasItem(ammoId, amount);
|
||||
return inventory != null && inventory.HasItem(AmmoId, amount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user