예제 #1
0
        public static void Equip(Character pChar, short slotFrom, short slotTo)
        {
            var itemToEquip = pChar.InventoryEquip.GetKvp(slotFrom);

            if (itemToEquip.Value == null)
            {
                return;                                        // passed empty slot
            }
            var v1 = Math.Abs(slotTo);

            if (v1 < 200 && v1 >= 100)
            {
                v1 -= 100;
            }

            if (!ItemConstants.is_correct_bodypart(itemToEquip.Value.nItemID, (BodyPart)v1))
            {
                pChar.SendMessage($"Unable to equip item with ID {itemToEquip.Value.nItemID} to slot {slotTo} ({v1})");
                return;
            }

            var dstEquipInv = GetInventory(pChar, slotTo);

            var itemToUnequip = dstEquipInv.GetKvp(slotTo);

            // remove item from equip inventory
            if (!pChar.InventoryEquip.Remove(itemToEquip.Key))
            {
                return;                                                            // means theres no item in the given slot
            }
            // remove item from equipped inventory
            if (dstEquipInv.Remove(itemToUnequip.Key))
            {
                pChar.InventoryEquip.Add(itemToEquip.Key, itemToUnequip.Value);
                pChar.Skills.ModifyOptionSkills(itemToUnequip.Value, false);
            }

            pChar.Skills.ModifyOptionSkills(itemToEquip.Value, true);

            pChar.Modify.Inventory(ctx =>
            {
                if (itemToEquip.Value.EquipTemplate.EquipTradeBlock)
                {
                    itemToEquip.Value.nAttribute |= ItemAttributeFlags.Untradeable;
                    ctx.Remove(InventoryType.Equip, itemToEquip.Key);
                    ctx.Add(InventoryType.Equip, slotTo, itemToEquip.Value);                     // essentially forcing an equip update into a new slot
                }
                else
                {
                    ctx.Move(InventoryType.Equip, itemToEquip.Key, slotTo);
                }

                dstEquipInv.Add(slotTo, itemToEquip.Value);
            });
        }