public static void UnequipItem(Item item, short destinationSlot = 0) { //check for item type if (item.ItemType != ItemConstants.ItemType.Equipment) { throw new InvalidOperationException("Can only unequip equipment items."); } // slot to move item from short sourceSlot = item.Slot; // if no destination given then find first free slot for equip type if (destinationSlot == 0) { destinationSlot = item.Parent.GetNextFreeSlot(ItemConstants.ItemType.Equipment); } // change slot of item being unequipped to free equip slot item.Slot = destinationSlot; // send packet to carry out the un-equip item action item.Character.Client.Send(ItemPackets.EquipOrUnequipItems(item, sourceSlot, destinationSlot)); // update char appearance CharacterAppearance.UpdateApperance(item.Character); }
public static void EquipItem(Item item) { // Check ItemType if (item.ItemType != ItemConstants.ItemType.Equipment) { throw new InvalidOperationException("Can only equip equipment items."); } // If were not VIP user then check for requirements if (!item.Character.IsMaster) { if (item.Character.Stats.Strength < item.RequiredStrength || item.Character.Stats.Dexterity < item.RequiredDexterity || item.Character.Stats.Intelligence < item.RequiredIntelligence || item.Character.Stats.Luck < item.RequiredLuck || item.Character.Stats.Fame < item.RequiredFame) { return; } } // slot to move item from short sourceSlot = item.Slot; // slot to move item into ItemConstants.EquipmentSlot destinationSlot = item.GetEquippedSlot(); // get char's items Item top = item.Parent[ItemConstants.EquipmentSlot.Top]; Item bottom = item.Parent[ItemConstants.EquipmentSlot.Bottom]; Item weapon = item.Parent[ItemConstants.EquipmentSlot.Weapon]; Item shield = item.Parent[ItemConstants.EquipmentSlot.Shield]; // get item at char's destination slot Item destination = item.Parent[destinationSlot]; // if there is an item if (destination != null) { // put it into slot of item to be replaced with destination.Slot = sourceSlot; } // item to replace acquires destination slot item.Slot = (short)destinationSlot; // unequipped blocking items switch (destinationSlot) { case ItemConstants.EquipmentSlot.Bottom: { if (top?.IsOverall == true) { UnequipItem(top); } } break; case ItemConstants.EquipmentSlot.Top: { if (item.IsOverall && bottom != null) { UnequipItem(bottom); } } break; case ItemConstants.EquipmentSlot.Shield: { if (weapon?.IsTwoHanded == true) { UnequipItem(weapon); } } break; case ItemConstants.EquipmentSlot.Weapon: { if (item.IsTwoHanded && shield != null) { UnequipItem(shield); } } break; } // send packet to carry out the equipped action item.Character.Client.Send(ItemPackets.EquipOrUnequipItems(item, sourceSlot, (short)destinationSlot)); // update char appearance CharacterAppearance.UpdateApperance(item.Character); }