Files
RuinAdventurer/Scripts/Crafting/Inventory.cs
T

46 lines
1.2 KiB
C#

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