Beispiel #1
0
    public void AddItem(Item_Base_Object item, int amount)
    {
        if (item.stack == StackType.StackInf)
        {
            for (int i = 0; i < container.Count; i++)
            {
                if (container[i].item == item)
                {
                    container[i].AddAmount(amount);
                    return;
                }
            }

            container.Add(new Inventory_Slot(item, amount));
        }
        else if (item.stack == StackType.StackMax)
        {
            for (int i = 0; i < container.Count; i++)
            {
                if (container[i].item == item)
                {
                    if (container[i].amount < container[i].item.maxItemCount)
                    {
                        if (container[i].amount + amount <= item.maxItemCount)
                        {
                            container[i].AddAmount(amount);
                            return;
                        }
                        else
                        {
                            int leftOver = item.maxItemCount - container[i].amount;
                            container[i].AddAmount(leftOver);
                            amount -= leftOver;
                        }
                    }
                }
            }

            if (amount <= item.maxItemCount)
            {
                container.Add(new Inventory_Slot(item, amount));
            }
            else
            {
                while (amount > item.maxItemCount)
                {
                    container.Add(new Inventory_Slot(item, item.maxItemCount));
                    amount -= item.maxItemCount;
                }

                container.Add(new Inventory_Slot(item, amount));
            }
        }
    }
Beispiel #2
0
 public Inventory_Slot(Item_Base_Object itemType, int amountItem)
 {
     amount = amountItem;
     item   = itemType;
 }