46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using Godot;
|
|
|
|
public class Inventory
|
|
{
|
|
public List<Item> 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)
|
|
{
|
|
GD.Print(inventory.IndexOf(inventoryItem) + ": " + inventoryItem.currentAmount);
|
|
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<Ingredient> 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;
|
|
}
|
|
} |