Cleaned up project with better structure.

This commit is contained in:
2026-05-09 11:29:48 +02:00
parent 1ad3454f6a
commit 6708aa277f
95 changed files with 711 additions and 700 deletions
+60
View File
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
public class Inventory
{
public List<Item> items = new List<Item>();
public int maxInventorySize = 8;
public event EventHandler OnInventoryUpdate;
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)
{
inventoryItem.currentAmount += amount;
NotifyInventoryChanged();
return true;
}
if (items.Count < maxInventorySize)
{
items.Add(item);
items[items.Count - 1].currentAmount += amount;
NotifyInventoryChanged();
return true;
}
return false;
}
public bool CanCraft(List<Ingredient> neededIngredients, int amount)
{
foreach (Ingredient ingredient in neededIngredients)
{
Item item = items.Find(x => x.data.Id == ingredient.Item && x.currentAmount >= ingredient.Amount * amount);
if (item == null)
{
return false;
}
}
return true;
}
public void RemoveItem(string id, int amount)
{
Item item = items.Find(x => x.data.Id == id && x.currentAmount >= amount);
if (item != null)
{
item.currentAmount -= amount;
NotifyInventoryChanged();
}
}
private void NotifyInventoryChanged()
{
OnInventoryUpdate?.Invoke(this, EventArgs.Empty);
}
}