using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName ="New Inventory", menuName = "Inventory System/Inventory")]
public class InventoryObject : ScriptableObject
{
    public List<InventorySlotObject> Container = new List<InventorySlotObject>();


    public void AddItem(ItemObject _item, int _count)
    {
        bool hasItem = false;

        for (int i = 0; i < Container.Count; i++)
        {
            if(Container[i].item == _item && Container[i].item.stackable)
            {
                Container[i].AddCount(_count);
                hasItem = true;
                break;
            }
        }
        if (!hasItem)
        {
            Container.Add(new InventorySlotObject(_item, _count));
        }
    }
}

[System.Serializable]
public class InventorySlotObject
{
    public ItemObject item;
    public int count;

    public InventorySlotObject(ItemObject _item, int _count)
    {
        this.item = _item;
        this.count = _count;
    }

    public void AddCount(int _count)
    {
        this.count += _count;
    }
}