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(); }
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(); }