miepzerino
2025-03-30 884103d805270bd776b7a485d9431401c0c05594
Assets/Scripts/Inventory/Inventory.cs
@@ -23,33 +23,37 @@
    public bool AddItem(Item item, int quantity = 1)
    {
        if (items.Count >= maxInventorySize && !item.isStackable)
        {
            //TODO: Show inventory full message
            Debug.Log("Inventory is full");
            return false;
        }
        InventorySlot existingSlot = items.Find(slot => slot.item.itemName == item.itemName);
        if (existingSlot != null && item.isStackable)
        {
            //Add to existing stack
            if (existingSlot.quantity + quantity <= item.maxStackSize)
            {
                existingSlot.quantity += quantity;
                return true;
            }
            else
            {
                int remainingQuantity = item.maxStackSize - existingSlot.quantity;
                existingSlot.quantity = item.maxStackSize;
                return AddItem(item, quantity - remainingQuantity);
                //TODO: Show inventory overflow message
                Debug.Log("Inventory overflow");
                existingSlot.quantity += remainingQuantity;
            }
        }
        else
        {
            if (items.Count < maxInventorySize)
            {
            //Add new item to inventory
                items.Add(new InventorySlot(item, quantity));
        }
        GameStateEvents.inventoryChanged?.Invoke();
                return true;
            }
            return false;
        }
    }
    public void RemoveItem(Item item, int quantity = 1)
@@ -67,6 +71,7 @@
                items.Remove(existingSlot);
            }
        }
        GameStateEvents.inventoryChanged?.Invoke();
    }
}