using System.Collections.Generic; using Godot; public class Inventory { public List inventory = new(); public int maxInventorySize = 8; public bool AddItem(Item item, int amount) { Item inventoryItem = inventory.Find(x => x.data.Id == item.data.Id && x.currentAmount + amount <= x.data.StackSize); if (inventoryItem != null) { inventoryItem.currentAmount += amount; return true; } else { if (inventory.Count < maxInventorySize) { inventory.Add(item); inventory[inventory.Count - 1].currentAmount += amount; return true; } } return false; } public bool CanCraft(List neededIngredients, int amount) { bool canCraft = true; Item item; foreach(Ingredient ingredient in neededIngredients) { item = inventory.Find(x => x.data.Id == ingredient.item && x.currentAmount >= ingredient.amount * amount); if (item == null) { canCraft = false; break; } } return canCraft; } }