using System; using System.Collections.Generic; namespace SpellBoundAR.Items.Inventories { public interface IInventory { public static event Action OnAnyInventoryChanged; public static void InvokeOnAnyInventoryChanged(IInventory inventory, IItemTypeData itemTypeData) { OnAnyInventoryChanged?.Invoke(inventory, itemTypeData); } public event Action OnEntriesChanged; public string ID { get; } public List GetAllEntries(); public IInventoryEntry GetEntry(IItemTypeData itemTypeData); public void Add(IItemTypeData itemTypeData, int quantity); public void Remove(IItemTypeData itemTypeData, int quantity); public void RemoveAll(IItemTypeData itemTypeData); public void Clear(); public int GetItemQuantity(IItemTypeData itemTypeData) { if (itemTypeData == null) return 0; IInventoryEntry entry = GetEntry(itemTypeData); return entry?.Quantity ?? 0; } public List GetEntries() where T : IItemTypeData { List entries = new List(); foreach (IInventoryEntry entry in GetAllEntries()) { if (entry == null) continue; if (entry.Quantity <= 0) continue; if (entry.ItemTypeData is not T) continue; entries.Add(entry); } return entries; } } }