Example #1
0
    public int GetItemSupplyAmount(ItemInfo item)
    {
        if (ItemsSupply.ContainsKey(item))
        {
            return(ItemsSupply[item]);
        }

        return(0);
    }
Example #2
0
    public void AddItemSupply(ItemInfo item, int amount = 1)
    {
        if (!ItemsSupply.ContainsKey(item))
        {
            ItemsSupply.Add(item, amount);
        }
        else
        {
            ItemsSupply[item] += amount;
        }

        if (onUpdateItemSupplyAmount != null)
        {
            onUpdateItemSupplyAmount.Invoke(item, ItemsSupply[item]);
        }
    }
Example #3
0
    public void RemoveItemSupply(ItemInfo item, int amount = 1)
    {
        if (ItemsSupply.ContainsKey(item))
        {
            var current = ItemsSupply[item];
            current -= amount;
            if (current <= 0)
            {
                current = 0;
                ItemsSupply.Remove(item);
            }
            else
            {
                ItemsSupply[item] = current;
            }

            if (onUpdateItemSupplyAmount != null)
            {
                onUpdateItemSupplyAmount.Invoke(item, current);
            }
        }
    }