Esempio n. 1
0
        public static void MoveItem_Req(InPacket lea, Client gc)
        {
            byte SourceType = lea.ReadByte();
            byte SourceSlot = lea.ReadByte();
            byte TargetType = lea.ReadByte();
            byte TargetSlot = lea.ReadByte();
            int  Quantity   = lea.ReadInt();
            Item Source     = gc.Character.Items.getItem(SourceType, SourceSlot);
            Item Target     = gc.Character.Items.getItem(TargetType, TargetSlot);
            var  chr        = gc.Character;

            if (SourceType != (byte)InventoryType.ItemType.Pet5 && Source.IsLocked == 1 && TargetType == (byte)InventoryType.ItemType.Equip)
            {
                Source.IsLocked = 0;
            }

            if (TargetType == 0x63 && TargetSlot == 0x63)
            {
                if (SourceType == 0xFF && SourceSlot == 0xFF)
                {
                    return;
                }
                Map Map = MapFactory.GetMap(chr.MapX, chr.MapY);
                foreach (Character All in Map.Characters)
                {
                    InventoryPacket.CharDropItem(All.Client, Map.ObjectID, Source.ItemID, chr.PlayerX, (short)(chr.PlayerY - 50), Quantity == 0 ? 1 : Quantity);
                }
                Map.Item.Add(Map.ObjectID, new Drop(Map.ObjectID, Source.ItemID, Quantity == 0 ? (short)1 : (short)Quantity));
                Map.ObjectID++;
                chr.Items.Remove(SourceType, SourceSlot, Quantity == 0 ? 1 : Quantity);
            }
            else
            {
                if (chr.Items.getItem(TargetType, TargetSlot) == null)
                {
                    if (SourceType != 5 && TargetType != 5)
                    {
                        // 普通物品
                        Source.Type = TargetType;
                        Source.Slot = TargetSlot;
                        if (TargetType == (byte)InventoryType.ItemType.Equip || SourceType == (byte)InventoryType.ItemType.Equip)
                        {
                            UpdateCharacterInventoryStatus(gc, Source, SourceType > 0);
                        }
                    }
                    else
                    {
                        // 寵物
                        Pet Src = chr.Pets.Pet(SourceType, SourceSlot);
                        Pet Tar = chr.Pets.Pet(TargetType, TargetSlot);

                        if (SourceType == 5)
                        {
                            chr.UseSlot[(byte)InventoryType.ItemType.Pet5] = Src.Slot;
                        }
                        else if (TargetType == 5)
                        {
                            chr.UseSlot[(byte)InventoryType.ItemType.Pet5] = 0xFF;
                        }

                        if (chr.Pets.Pet(TargetType, TargetSlot) == null)
                        {
                            Src.Type = TargetType;
                            Src.Slot = TargetSlot;
                        }
                        else
                        {
                            // 交換位置(swap)
                            chr.Pets.Remove(SourceType, SourceSlot);
                            chr.Pets.Remove(TargetType, TargetSlot);
                            // 類型
                            byte swapType = Src.Type;
                            Src.Type = Tar.Type;
                            Tar.Type = swapType;
                            // 欄位
                            byte swapSlot = Src.Slot;
                            Src.Slot = Tar.Slot;
                            Tar.Slot = swapSlot;
                            //
                            chr.Pets.Add(Src);
                            chr.Pets.Add(Tar);
                        }
                    }
                }
                else
                {
                    if ((SourceType == TargetType) &&
                        ((TargetType == (byte)InventoryType.ItemType.Spend3) ||
                         (TargetType == (byte)InventoryType.ItemType.Other4)) &&
                        (Source.ItemID == Target.ItemID))
                    {
                        // 合併消費物品跟其他物品
                        if (chr.Items[(InventoryType.ItemType)Target.Type, Target.Slot].Quantity + Source.Quantity > 100)
                        {
                            short newqu = (short)(Source.Quantity - (100 - chr.Items[(InventoryType.ItemType)Target.Type, Target.Slot].Quantity));
                            chr.Items[(InventoryType.ItemType)Source.Type, Source.Slot].Quantity = newqu;
                            chr.Items[(InventoryType.ItemType)Target.Type, Target.Slot].Quantity = 100;
                        }
                        else
                        {
                            chr.Items.Remove(SourceType, SourceSlot);
                            chr.Items[(InventoryType.ItemType)Target.Type, Target.Slot].Quantity += Source.Quantity;
                        }
                    }
                    else
                    {
                        // 交換位置(swap)
                        chr.Items.Remove(SourceType, SourceSlot);
                        chr.Items.Remove(TargetType, TargetSlot);
                        // 類型
                        byte swapType = Source.Type;
                        Source.Type = Target.Type;
                        Target.Type = swapType;
                        // 欄位
                        byte swapSlot = Source.Slot;
                        Source.Slot = Target.Slot;
                        Target.Slot = swapSlot;
                        //
                        chr.Items.Add(Source);
                        chr.Items.Add(Target);
                    }
                    if (SourceType == (byte)InventoryType.ItemType.Equip && TargetType == (byte)InventoryType.ItemType.Equip1)
                    {
                        UpdateCharacterInventoryStatus(gc, Source, false);
                        UpdateCharacterInventoryStatus(gc, Target, true);
                    }
                    else if (SourceType == (byte)InventoryType.ItemType.Equip || TargetType == (byte)InventoryType.ItemType.Equip)
                    {
                        UpdateCharacterInventoryStatus(gc, Target, false);
                        UpdateCharacterInventoryStatus(gc, Source, true);
                    }
                }
            }
            UpdateInventory(gc, SourceType, TargetType);
        }