60 lines
1.2 KiB
C#
60 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
|
|
public class InventoryManager : MonoBehaviour
|
|
{
|
|
public int maxCapacity;
|
|
public int currentlyStored;
|
|
public Dictionary<Item, int> storedItems = new();
|
|
public Item[] itemList;
|
|
public int money;
|
|
|
|
public bool RemoveMoney(int change)
|
|
{
|
|
if (money - change >= 0)
|
|
{
|
|
money -= change;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public void AddMoney(int change)
|
|
{
|
|
money += change;
|
|
}
|
|
|
|
public int AddItem(Item itemToAdd, int amount = 1)
|
|
{
|
|
if (currentlyStored < maxCapacity)
|
|
{
|
|
if (!storedItems.ContainsKey(itemToAdd))
|
|
{
|
|
storedItems[itemToAdd] = 0;
|
|
}
|
|
if (currentlyStored + amount <= maxCapacity)
|
|
{
|
|
storedItems[itemToAdd] += amount;
|
|
currentlyStored += amount;
|
|
return 0;
|
|
}
|
|
//return the amount that wasn't able to be stored.
|
|
int stored = maxCapacity - currentlyStored;
|
|
storedItems[itemToAdd] += stored;
|
|
currentlyStored += stored;
|
|
amount -= stored;
|
|
return amount;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public bool RemoveItem(Item itemToRemove, int amount = 1)
|
|
{
|
|
if (!storedItems.ContainsKey(itemToRemove) || storedItems[itemToRemove] < amount)
|
|
{
|
|
return false;
|
|
}
|
|
storedItems[itemToRemove] -= amount;
|
|
return true;
|
|
}
|
|
}
|