private void InteractWithItemObject(ItemObject itemObject) { Debug.Assert(itemObject.Item != null); IUsable usable = itemObject.Item as IUsable; IPickupable pickupable = itemObject.Item as IPickupable; IEquipable equipable = itemObject.Item as IEquipable; IStackable stackable = itemObject.Item as IStackable; if (usable != null) { usable.OnUse(_stats, itemObject); } else if (pickupable != null) { if (equipable != null && equipable.IsDurable && _equipment.EquipmentTable[equipable.EquipmentType].IsEmpty) { equipable.OnEquip(_equipment, _stats); } else if (stackable != null) { stackable.OnStack(_inventory); } else { pickupable.OnPutInInventory(_inventory); } pickupable.OnRemoveFromGround(itemObject); } }
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 UnequipItemNoDurability(object[] eventParams) { Debug.Assert(eventParams.Length == 1 && eventParams[0] is Item); IPickupable pickupable = eventParams[0] as IPickupable; IEquipable equipable = eventParams[0] as IEquipable; equipable.OnUnequip(_equipment, _stats); pickupable.OnPutInInventory(_inventory); }
private void ReturnAirItem(object[] eventParams) { if (_airItem.IsEmpty) { return; } SlotPosition originalPosition = _airItem.OriginalPosition; Item itemAir = _airItem.Item; IPickupable pickupableAir = itemAir as IPickupable; IEquipable equipableAir = itemAir as IEquipable; IStackable stackableAir = itemAir as IStackable; pickupableAir.OnRemoveFromAir(_airItem); if (originalPosition.RowIndex == EquipmentSlot.EQUIPMENT_SLOT_ROW_INDEX) { Equipment.EquipmentType equipmentType = (Equipment.EquipmentType)originalPosition.SlotIndex; if (_equipment.EquipmentTable[equipmentType].IsEmpty) { equipableAir.OnEquip(_equipment, _stats); } else { pickupableAir.OnPutInInventory(_inventory); } } else { if (stackableAir != null) { stackableAir.OnStack(_inventory, originalPosition); } else if (_inventory.IsItemEmpty(originalPosition)) { pickupableAir.OnPutInInventory(_inventory, originalPosition); } else { pickupableAir.OnPutInInventory(_inventory); } } }
private void EquipItem(object[] eventParams) { Debug.Assert(eventParams.Length == 1 && eventParams[0] is ItemIcon); if (_airItem.IsEmpty == false) { Debug.Log("Air Item is not null"); return; } ItemIcon itemIcon = (ItemIcon)eventParams[0]; IPickupable pickupable = itemIcon.Item as IPickupable; IEquipable equipable = itemIcon.Item as IEquipable; if (equipable == null) { Debug.Log("Not equipable"); return; } if (equipable.IsDurable == false) { Debug.Log("Not durable"); } if (itemIcon.IsEquipmentIcon) { equipable.OnUnequip(_equipment, _stats); pickupable.OnPutInInventory(_inventory); } else { Item equippedItem = _equipment.EquipmentTable[equipable.EquipmentType].Item; pickupable.OnRemoveFromInventory(_inventory, itemIcon.Position); if (equippedItem != null) { ((IEquipable)equippedItem).OnUnequip(_equipment, _stats); ((IPickupable)equippedItem).OnPutInInventory(_inventory, itemIcon.Position); } equipable.OnEquip(_equipment, _stats); } }
private void LeftClickItemSlot(object[] eventParams) { Debug.Assert(eventParams.Length == 1 && eventParams[0] is SlotPosition); SlotPosition slotPosition = (SlotPosition)eventParams[0]; if (_airItem.IsEmpty) { return; } IPickupable pickupable = _airItem.Item as IPickupable; if (slotPosition.RowIndex == EquipmentSlot.EQUIPMENT_SLOT_ROW_INDEX) { IEquipable equipable = _airItem.Item as IEquipable; if (equipable == null) { Debug.Log("Not equipable"); return; } if ((Equipment.EquipmentType)slotPosition.SlotIndex != equipable.EquipmentType) { Debug.Log("Not the same equipment type"); return; } if (equipable.IsDurable == false) { Debug.Log("Not durable"); } pickupable.OnRemoveFromAir(_airItem); equipable.OnEquip(_equipment, _stats); } else { pickupable.OnRemoveFromAir(_airItem); pickupable.OnPutInInventory(_inventory, slotPosition); } }