private void LeftClickItemIcon(object[] eventParams) { Debug.Assert(eventParams.Length == 1 && eventParams[0] is ItemIcon); ItemIcon itemIcon = (ItemIcon)eventParams[0]; SlotPosition slotPosition = itemIcon.Position; IPickupable pickupable = itemIcon.Item as IPickupable; IEquipable equipable = itemIcon.Item as IEquipable; if (_airItem.IsEmpty) { if (itemIcon.IsEquipmentIcon) { equipable.OnUnequip(_equipment, _stats); } else if (itemIcon.Item is IStackable) { EventManager.TriggerEvent(EventName.OPEN_SPLIT_SCREEN, eventParams); return; } else { pickupable.OnRemoveFromInventory(_inventory, slotPosition); } pickupable.OnPutInAir(_airItem, slotPosition); } else { IPickupable pickupableAir = _airItem.Item as IPickupable; if (slotPosition.RowIndex == EquipmentSlot.EQUIPMENT_SLOT_ROW_INDEX) { IEquipable equipableAir = _airItem.Item as IEquipable; if (equipableAir == null) { Debug.Log("Not equipable"); return; } if ((Equipment.EquipmentType)slotPosition.SlotIndex != equipableAir.EquipmentType) { Debug.Log("Not the same equipment type"); return; } if (equipable.IsDurable == false) { Debug.Log("Not durable"); } equipable.OnUnequip(_equipment, _stats); pickupableAir.OnRemoveFromAir(_airItem); equipableAir.OnEquip(_equipment, _stats); pickupable.OnPutInAir(_airItem, slotPosition); } else { pickupable.OnRemoveFromInventory(_inventory, slotPosition); pickupableAir.OnRemoveFromAir(_airItem); pickupableAir.OnPutInInventory(_inventory, slotPosition); pickupable.OnPutInAir(_airItem, slotPosition); } } }
private void SplitStackableItem(object[] eventParams) { Debug.Assert(eventParams.Length == 2 && eventParams[0] is ItemIcon && eventParams[1] is int); ItemIcon itemIcon = (ItemIcon)eventParams[0]; int splitCount = (int)eventParams[1]; Item item = itemIcon.Item; SlotPosition slotPosition = itemIcon.Position; IStackable stackable = (IStackable)item; if (splitCount == stackable.Count) { IPickupable pickupable = (IPickupable)item; pickupable.OnRemoveFromInventory(_inventory, slotPosition); pickupable.OnPutInAir(_airItem, slotPosition); } else { Item splitItem = item.Copy(); ((IStackable)splitItem).Count = splitCount; ((IPickupable)splitItem).OnPutInAir(_airItem, slotPosition); stackable.OnSplit(_inventory, slotPosition, splitCount); } }