/// <summary> /// This will be called at server to order character to equip equipments /// </summary> /// <param name="nonEquipIndex"></param> /// <param name="equipPosition"></param> protected virtual void NetFuncEquipItem(short nonEquipIndex, byte byteInventoryType, short oldEquipIndex) { if (!CanDoActions() || nonEquipIndex >= nonEquipItems.Count) { return; } CharacterItem equippingItem = nonEquipItems[nonEquipIndex]; GameMessage.Type gameMessageType; bool shouldUnequipRightHand; bool shouldUnequipLeftHand; if (!CanEquipItem(equippingItem, (InventoryType)byteInventoryType, oldEquipIndex, out gameMessageType, out shouldUnequipRightHand, out shouldUnequipLeftHand)) { gameManager.SendServerGameMessage(ConnectionId, gameMessageType); return; } // Unequip equipped item that already equipped if (shouldUnequipRightHand) { NetFuncUnEquipItem((byte)InventoryType.EquipWeaponRight, 0); } if (shouldUnequipLeftHand) { NetFuncUnEquipItem((byte)InventoryType.EquipWeaponLeft, 0); } // Equipping items EquipWeapons tempEquipWeapons = EquipWeapons; switch ((InventoryType)byteInventoryType) { case InventoryType.EquipWeaponRight: tempEquipWeapons.rightHand = equippingItem; EquipWeapons = tempEquipWeapons; break; case InventoryType.EquipWeaponLeft: tempEquipWeapons.leftHand = equippingItem; EquipWeapons = tempEquipWeapons; break; case InventoryType.EquipItems: if (oldEquipIndex < 0) { oldEquipIndex = (short)this.IndexOfEquipItem(equippingItem.GetArmorItem().EquipPosition); } if (oldEquipIndex >= 0) { NetFuncUnEquipItem((byte)InventoryType.EquipItems, oldEquipIndex); } equipItems.Add(equippingItem); equipItemIndexes.Add(equippingItem.GetArmorItem().EquipPosition, equipItems.Count - 1); break; } nonEquipItems.RemoveAt(nonEquipIndex); this.FillEmptySlots(); }
public void UpdateData(ICharacterData character) { this.character = character; // Clear slots data foreach (UICharacterItem slot in CacheEquipItemSlots.Values) { slot.Setup(GetEmptyUIData(slot.InventoryType), character, -1); slot.Show(); } if (character == null) { return; } string tempPosition; UICharacterItem tempSlot; IList <CharacterItem> equipItems = character.EquipItems; for (int i = 0; i < equipItems.Count; ++i) { CharacterItem equipItem = equipItems[i]; Item armorItem = equipItem.GetArmorItem(); if (armorItem == null) { continue; } tempPosition = armorItem.EquipPosition; if (CacheEquipItemSlots.TryGetValue(tempPosition, out tempSlot)) { tempSlot.Setup(new CharacterItemTuple(equipItem, equipItem.level, InventoryType.EquipItems), character, i); } } EquipWeapons equipWeapons = character.EquipWeapons; CharacterItem rightHand = equipWeapons.rightHand; CharacterItem leftHand = equipWeapons.leftHand; Item rightHandEquipment = rightHand.GetEquipmentItem(); Item leftHandEquipment = leftHand.GetEquipmentItem(); tempPosition = GameDataConst.EQUIP_POSITION_RIGHT_HAND; if (CacheEquipItemSlots.TryGetValue(tempPosition, out tempSlot)) { if (rightHandEquipment != null) { tempSlot.Setup(new CharacterItemTuple(rightHand, rightHand.level, InventoryType.EquipWeaponRight), character, 0); } } tempPosition = GameDataConst.EQUIP_POSITION_LEFT_HAND; if (CacheEquipItemSlots.TryGetValue(tempPosition, out tempSlot)) { if (leftHandEquipment != null) { tempSlot.Setup(new CharacterItemTuple(leftHand, leftHand.level, InventoryType.EquipWeaponLeft), character, 0); } } }
public bool RequestEquipItem(short nonEquipIndex) { if (!CanDoActions() || nonEquipIndex >= NonEquipItems.Count) { return(false); } CharacterItem characterItem = NonEquipItems[nonEquipIndex]; Item armorItem = characterItem.GetArmorItem(); Item weaponItem = characterItem.GetWeaponItem(); Item shieldItem = characterItem.GetShieldItem(); if (weaponItem != null) { if (weaponItem.EquipType == WeaponItemEquipType.OneHandCanDual) { Item rightWeapon = EquipWeapons.rightHand.GetWeaponItem(); if (rightWeapon != null && rightWeapon.EquipType == WeaponItemEquipType.OneHandCanDual) { return(RequestEquipItem(nonEquipIndex, (byte)InventoryType.EquipWeaponLeft, 0)); } else { return(RequestEquipItem(nonEquipIndex, (byte)InventoryType.EquipWeaponRight, 0)); } } else { return(RequestEquipItem(nonEquipIndex, (byte)InventoryType.EquipWeaponRight, 0)); } } else if (shieldItem != null) { return(RequestEquipItem(nonEquipIndex, (byte)InventoryType.EquipWeaponLeft, 0)); } else if (armorItem != null) { return(RequestEquipItem(nonEquipIndex, (byte)InventoryType.EquipItems, (short)this.IndexOfEquipItem(armorItem.EquipPosition))); } return(false); }