예제 #1
0
        public virtual void Add(ItemSlot itemsToAdd)
        {
            foreach (var slot in itemSlots)
            {
                if (itemsToAdd.IsEmpty)
                {
                    break;
                }

                if (ItemInstance.CanStack(itemsToAdd.ItemInstance, slot.ItemInstance) || slot.IsEmpty)
                {
                    Combine(itemsToAdd, slot);
                }
            }

            onItemsUpdated.Invoke();
        }
예제 #2
0
        public void Combine(ItemSlot itemsToAdd, ItemSlot target)
        {
            if (itemsToAdd == target)
            {
                return;
            }

            if (ItemInstance.CanStack(itemsToAdd.ItemInstance, target.ItemInstance))
            {
                var quantity = target.Quantity + itemsToAdd.Quantity;
                quantity            = Mathf.Min(quantity, target.ItemInstance.Data.MaxStack);
                itemsToAdd.Quantity = itemsToAdd.Quantity - (quantity - target.Quantity);
                target.Quantity     = quantity;
            }
            else
            {
                ItemSlot.SwapItems(itemsToAdd, target);
            }

            onItemsUpdated.Invoke();
        }