Working on inventory and crafting system. Translated Excel-Itemlist to .json.

This commit is contained in:
2026-05-05 15:35:42 +02:00
parent 02ba36b665
commit fc26fa2a75
11 changed files with 829 additions and 10 deletions
+45
View File
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using Godot;
public class Inventory
{
public List<Ingredient> inventory = new();
public int maxInventorySize = 8;
public bool AddIngredient(Ingredient ingredient, int amount)
{
Ingredient ing = inventory.Find(x => x.name == ingredient.name && x.currentAmount + amount <= x.stackSize);
if (ing != null)
{
ing.currentAmount += amount;
return true;
}
else
{
if (inventory.Count < maxInventorySize)
{
inventory.Add(ingredient);
inventory[inventory.Count - 1].currentAmount += amount;
return true;
}
}
return false;
}
public bool CanCraft(Dictionary<Ingredient, int> neededIngredients, int amount)
{
bool canCraft = true;
Ingredient ingredient;
foreach(Ingredient key in neededIngredients.Keys)
{
ingredient = inventory.Find(x => x.name == key.name && x.currentAmount >= neededIngredients[key] * amount);
if (ingredient == null)
{
canCraft = false;
break;
}
}
return canCraft;
}
}