public override void Add(ItemSlot itemsToAdd) { base.Add(itemsToAdd); if (itemsToAdd.IsEmpty == false) { Resize(Capacity + 1); var lastSlot = itemSlots[Capacity - 1]; ItemSlot.SwapItems(lastSlot, itemsToAdd); } onItemsUpdated.Invoke(); }
public void HandleSize() { for (int i = 0; i < Capacity - 1; i++) { var current = itemSlots[i]; var next = itemSlots[i + 1]; if (current.IsEmpty && next.IsEmpty == false) { ItemSlot.SwapItems(current, next); } } var occupied = itemSlots.Count(slot => !slot.IsEmpty); Resize(occupied + 1); }
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(); }