コード例 #1
0
        public static void ClientUnequippedItem(ZoneClient pClient, Packet pPacket)
        {
            byte sourceSlot, destinationSlot;

            if (!pPacket.TryReadByte(out sourceSlot) ||
                !pPacket.TryReadByte(out destinationSlot))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read unequip values.");
                return;
            }

            Item sourceEquip = pClient.Character.Inventory.EquippedItems.Find(e => (byte)e.ItemInfo.Slot == sourceSlot);
            //Item destinationItem = pClient.Character.Inventory.EquippedItems.Find(i => i.Slot == destinationSlot);// Item was searched from wrong place
            Item destinationItem;

            pClient.Character.Inventory.InventoryItems.TryGetValue(destinationSlot, out destinationItem);       // check if something there
            if (destinationItem != null && (destinationItem.ItemInfo.Slot == ItemSlot.None))
            {
                Log.WriteLine(LogLevel.Warn, "Equipping an item, not possible.");
                // Failed to unequip message here, no need to log it
                return;
            }

            // TODO: If source and destination types are different return.
            // Except rings and costumes (But that can be done later).

            /*
             * if( sourceEquip.Type != destinationItem.Type ) {
             *  Log.WriteLine(LogLevel.Warn, "SourceType != DestinationType, just debugging message, not important");
             *  // Failed to unequip message here, no need to log it
             *  return;
             * }
             */

            if (destinationItem != null)
            {
                Item destinationEquip = (Item)destinationItem;
                pClient.Character.SwapEquips(sourceEquip, destinationEquip);
            }
            else
            {
                if (sourceEquip == null)
                {
                    Handler12.UpdateEquipSlot(pClient.Character, destinationSlot, 0x24, 0, null);
                    return;
                }
                pClient.Character.UnequipItem(sourceEquip, destinationSlot);
            }
        }