literally half of the game
This commit is contained in:
parent
1590b5faa6
commit
b842289076
77 changed files with 11904 additions and 72 deletions
30
Assets/Scripts/Inventory/CraftingSystem.cs
Normal file
30
Assets/Scripts/Inventory/CraftingSystem.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CraftingSystem : MonoBehaviour
|
||||
{
|
||||
public bool TryCraftingItem(Item requestedItem)
|
||||
{
|
||||
List<InventoryManager.ItemAmount> missingItems = new();
|
||||
foreach (InventoryManager.ItemAmount requiredMaterial in requestedItem.requiredMaterials)
|
||||
{
|
||||
if (InventoryManager.instance.CheckItemAmount(requiredMaterial.item) < requiredMaterial.amount)
|
||||
{
|
||||
InventoryManager.ItemAmount newMissingItem = new();
|
||||
newMissingItem.item = requiredMaterial.item;
|
||||
newMissingItem.amount = requiredMaterial.amount - InventoryManager.instance.CheckItemAmount(requiredMaterial.item);
|
||||
}
|
||||
}
|
||||
if (missingItems.Count > 0)
|
||||
{
|
||||
return false; //supposed to return what items were missing
|
||||
}
|
||||
foreach (InventoryManager.ItemAmount requiredMaterial in requestedItem.requiredMaterials)
|
||||
{
|
||||
InventoryManager.instance.RemoveItem(requiredMaterial.item, requiredMaterial.amount);
|
||||
}
|
||||
InventoryManager.instance.AddItem(requestedItem, requestedItem.craftedAmount);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue