diff --git a/Items/Inventory.cs b/Items/Inventory.cs index 825c5bf..a385fc7 100644 --- a/Items/Inventory.cs +++ b/Items/Inventory.cs @@ -239,6 +239,21 @@ public partial class Inventory : Node2D, IItemCollection public bool Remove(ItemMetadata item) { + int indexInInventory = Items.IndexOf(item); + if (indexInInventory < 0) + { + return false; + } + + // remove instances of item from hotbar + int indexInHotbar = HotbarToItemIndexMap.IndexOf(indexInInventory); + if (indexInHotbar >= 0) + { + HotbarToItemIndexMap[indexInHotbar] = -1; + Hotbar[indexInHotbar].QueueFree(); + } + + Items[indexInInventory] = null; return Items.Remove(item); } diff --git a/Items/Item.cs b/Items/Item.cs index c38fc0b..f6d2af6 100644 --- a/Items/Item.cs +++ b/Items/Item.cs @@ -65,4 +65,15 @@ public abstract partial class Item : Node2D { } + + public virtual void Remove() + { + if (IsUsing) + { + Deuse(); + } + + Unequip(CharacterOwner); + QueueFree(); + } }