Exemplo n.º 1
0
    public int Consume(int amount)
    {
        if (Amount <= 0)
        {
            Amount = 0;
            return(0);
        }
        Item oldItem   = Item;
        int  oldAmount = Amount;
        int  consumed  = Mathf.Min(Amount, amount);

        Amount -= consumed;
        if (Amount <= 0)
        {
            Item = null;
            if (oldItem != null)
            {
                OnSlotItemChanged?.Invoke(Index, oldItem);
            }
            Amount = 0;
        }
        OnSlotAmountChanged?.Invoke(Index, oldAmount);
        OnSlotChanged?.Invoke(Index);
        return(consumed);
    }
Exemplo n.º 2
0
    public void SetItemAmount(Item item, int amount)
    {
        Item oldItem   = Item;
        int  oldAmount = Amount;

        Item   = item;
        Amount = amount;
        OnSlotChanged?.Invoke(Index);
        OnSlotItemChanged?.Invoke(Index, oldItem);
        OnSlotAmountChanged?.Invoke(Index, oldAmount);
    }
Exemplo n.º 3
0
    public void SetAmount(int amount)
    {
        Item oldItem   = Item;
        int  oldAmount = Amount;

        Amount = Mathf.Max(amount, 0);
        if (Amount == 0)
        {
            Item = null;
            OnSlotItemChanged?.Invoke(Index, oldItem);
        }
        Amount = amount;
        OnSlotChanged?.Invoke(Index);
        OnSlotAmountChanged?.Invoke(Index, oldAmount);
    }
Exemplo n.º 4
0
    public int AddAmount(int amount)
    {
        int oldAmount = Amount;
        int maxAdd    = 0;

        if (Item.stackable)
        {
            maxAdd  = 64 - Amount;
            Amount += Mathf.Min(maxAdd, amount);
        }
        else if (Amount <= 0)
        {
            Amount = 1;
            maxAdd = 1;
        }
        OnSlotChanged?.Invoke(Index);
        OnSlotAmountChanged?.Invoke(Index, oldAmount);
        return(Mathf.Min(maxAdd, amount));
    }