45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
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;
|
|
}
|
|
} |