public static void EquipItem(ItemUsage itemUsage, Client.GameState client)
        {
            if (!client.AlternateEquipment)
            {
                if (itemUsage.dwParam < 20)
                {

                    Interfaces.IConquerItem item = null;
                    client.Entity.AttackPacket = null;

                    if (client.Inventory.TryGetItem(itemUsage.UID, out item) && client.Booth == null)
                    {
                        if (item.Suspicious)
                            return;

                        Positions pos = GetPositionFromID(item.ID);
                        if (client.Entity.MapID == 2060)
                        {
                            if (pos == Positions.Garment)
                            {
                                return;
                            }
                        }
                        if (client.Entity.MapID == 7009)
                        {
                            if (pos == Positions.Garment)
                            {
                                return;
                            }
                        }
                        if (pos == Positions.Inventory)
                        {
                            UseItem(item, client);
                            return;
                        }
                        #region Sanity checks

                        bool can2hand = false;
                        bool can2wpn = false;
                        if (client.Entity.Class >= 11 && client.Entity.Class <= 75)
                            can2hand = true;
                        if (client.Entity.Class >= 11 && client.Entity.Class <= 15 || client.Entity.Class >= 51 && client.Entity.Class <= 55 || client.Entity.Class >= 61 && client.Entity.Class <= 65 || client.Entity.Class >= 71 && client.Entity.Class <= 75)
                            can2wpn = true;
                        if (client.Entity.Class >= 71 && client.Entity.Class <= 75)
                            can2wpn = true;
                        if (!Equipable(item, client))
                            return;
                        if (ItemPosition(item.ID) == 5)
                        {
                            itemUsage.dwParam = 5;
                            if (!can2hand && !can2wpn)
                                return;
                            if (client.Equipment.Free(4) || (client.Equipment.TryGetItem(4).ID / 1000 != 500 && IsArrow(item.ID)))
                                return;
                        }
                        if (ItemPosition(item.ID) == 4)
                        {
                            if (itemUsage.dwParam == 5)
                                if (!can2hand || !can2wpn)
                                    return;
                        }
                        if (!((itemUsage.dwParam == 4 || itemUsage.dwParam == 5) && (ItemPosition(item.ID) == 4 || ItemPosition(item.ID) == 5)))
                        {
                            if (!IsAccessory(item.ID))
                                itemUsage.dwParam = ItemPosition(item.ID);
                        }
                        bool twohand = IsTwoHand(item.ID);

                        if (!twohand && itemUsage.dwParam == 4)
                            if (!client.Equipment.Free(5))
                                if (client.Inventory.Count < 40)
                                {
                                    if (IsArrow(client.Equipment.TryGetItem(5).ID))
                                        client.Equipment.Remove(5);
                                    else
                                    {
                                        if (client.Equipment.TryGetItem(4) != null)
                                        {
                                            if (IsTwoHand(client.Equipment.TryGetItem(4).ID))
                                                client.Equipment.Remove(4);
                                        }
                                    }
                                }
                        #endregion

                        if (client.Map.ID == 1039)
                            client.Entity.AttackPacket = null;

                        item.Position = (ushort)itemUsage.dwParam;
                        if (ItemPosition(item.ID) == 5 && !IsArrow(item.ID))
                        {
                            if (IsTwoHand(client.Equipment.TryGetItem(4).ID))
                            {
                                if (!client.Spells.ContainsKey(10311))//Perseverance
                                {
                                    client.Send(new Message("You need to know Perseverance (Warrior Pure skill) to be able to wear 2-handed weapon and shield.", System.Drawing.Color.Red, Message.Talk));
                                    return;
                                }
                            }
                        }

                        //Database.ConquerItemTable.ClearPosition(client.Entity.UID, (byte)itemUsage.dwParam);
                        client.Inventory.Remove(item, Game.Enums.ItemUse.Move, true);
                        if (client.Equipment.Free((byte)itemUsage.dwParam))
                        {
                            if (twohand)
                                client.Equipment.Remove(5);
                            item.Position = (byte)itemUsage.dwParam;
                            if (!client.AlternateEquipment)
                            {
                                client.Equipment.Add(item);
                            }
                            else
                            {
                                client.Equipment.Add505(item);
                            }
                            item.Mode = Game.Enums.ItemMode.Update;
                            item.Send(client);
                        }
                        else
                        {
                            if (twohand)
                                client.Equipment.Remove(5);
                            client.Equipment.Remove((byte)itemUsage.dwParam);
                            item.Position = (byte)itemUsage.dwParam;
                            if (!client.AlternateEquipment)
                            {
                                client.Equipment.Add(item);
                            }
                            else
                            {
                                client.Equipment.Add505(item);
                            }
                        }

                        if (!client.AlternateEquipment)
                        {
                            client.LoadItemStats(client.Entity);
                            client.CalculateStatBonus();
                            client.CalculateHPBonus();
                            ClientEquip equips = new ClientEquip();
                            equips.DoEquips(client);
                            client.Send(equips);
                            client.Equipment.UpdateEntityPacket();
                        }
                        else
                        {
                            ClientEquip equips = new ClientEquip(client);
                            //equips.DoEquips(client);
                            client.Send(equips);
                            client.Equipment.UpdateEntityPacket2();
                        }

                        Database.ConquerItemTable.UpdateLocation(item, client);
                    }
                }
                else
                {
                    Interfaces.IConquerItem item = null;
                    client.Entity.AttackPacket = null;

                    if (client.Inventory.TryGetItem(itemUsage.UID, out item) && client.Booth == null)
                    {
                        if (item.Suspicious)
                            return;

                        Positions pos = GetPositionFromID2(item.ID);
                        if (client.Entity.MapID == 2060)
                        {
                            if (pos == Positions.AltGarment)
                            {
                                return;
                            }
                        }
                        if (client.Entity.MapID == 7009)
                        {
                            if (pos == Positions.AltGarment)
                            {
                                return;
                            }
                        }
                        if (pos == Positions.Inventory)
                        {
                            UseItem(item, client);
                            return;
                        }
                        #region Sanity checks

                        bool can2hand = false;
                        bool can2wpn = false;
                        if (client.Entity.Class >= 11 && client.Entity.Class <= 75)
                            can2hand = true;
                        if (client.Entity.Class >= 11 && client.Entity.Class <= 15 || client.Entity.Class >= 51 && client.Entity.Class <= 55 || client.Entity.Class >= 61 && client.Entity.Class <= 65 || client.Entity.Class >= 71 && client.Entity.Class <= 75)
                            can2wpn = true;
                        if (client.Entity.Class >= 71 && client.Entity.Class <= 75)
                            can2wpn = true;
                        if (!Equipable(item, client))
                            return;
                        if (ItemPosition2(item.ID) == 25)
                        {
                            itemUsage.dwParam = 25;
                            if (!can2hand && !can2wpn)
                                return;
                            if (client.Equipment.Free(24) || (client.Equipment.TryGetItem(24).ID / 1000 != 500 && IsArrow(item.ID)))
                                return;
                        }
                        if (ItemPosition2(item.ID) == 24)
                        {
                            if (itemUsage.dwParam == 25)
                                if (!can2hand || !can2wpn)
                                    return;
                        }
                        if (!((itemUsage.dwParam == 24 || itemUsage.dwParam == 25) && (ItemPosition2(item.ID) == 24 || ItemPosition2(item.ID) == 25)))
                        {
                            if (!IsAccessory(item.ID))
                                itemUsage.dwParam = ItemPosition2(item.ID);
                        }
                        bool twohand = IsTwoHand(item.ID);
                        if (!twohand && itemUsage.dwParam == 24)
                            if (!client.Equipment.Free(25))
                                if (client.Inventory.Count < 40)
                                {
                                    if (IsArrow(client.Equipment.TryGetItem(25).ID))
                                        client.Equipment.Remove(25);
                                    else
                                    {
                                        if (client.Equipment.TryGetItem(24) != null)
                                        {
                                            if (IsTwoHand(client.Equipment.TryGetItem(24).ID))
                                                client.Equipment.Remove(24);
                                        }
                                    }
                                }
                        #endregion

                        if (client.Map.ID == 1039)
                            client.Entity.AttackPacket = null;

                        item.Position = (ushort)itemUsage.dwParam;
                        if (ItemPosition2(item.ID) == 25 && !IsArrow(item.ID))
                        {
                            if (IsTwoHand(client.Equipment.TryGetItem(24).ID))
                            {
                                if (!client.Spells.ContainsKey(10311))//Perseverance
                                {
                                    client.Send(new Message("You need to know Perseverance (Warrior Pure skill) to be able to wear 2-handed weapon and shield.", System.Drawing.Color.Red, Message.Talk));
                                    return;
                                }
                            }
                        }

                        //Database.ConquerItemTable.ClearPosition(client.Entity.UID, (byte)itemUsage.dwParam);
                        client.Inventory.Remove(item, Game.Enums.ItemUse.Move, true);
                        if (client.Equipment.Free((byte)itemUsage.dwParam))
                        {
                            if (twohand)
                                client.Equipment.Remove(25);
                            item.Position = (byte)itemUsage.dwParam;
                            if (!client.AlternateEquipment)
                            {
                                client.Equipment.Add(item);
                            }
                            else
                            {
                                client.Equipment.Add600(item);
                            }
                            item.Mode = Game.Enums.ItemMode.Update;
                            item.Send(client);
                        }
                        else
                        {
                            if (twohand)
                                client.Equipment.Remove(25);
                            client.Equipment.Remove((byte)itemUsage.dwParam);
                            item.Position = (byte)itemUsage.dwParam;
                            if (!client.AlternateEquipment)
                            {
                                client.Equipment.Add(item);
                            }
                            else
                            {
                                client.Equipment.Add600(item);
                            }
                        }
                        if (client.AlternateEquipment)
                        {
                            client.LoadItemStats2(client.Entity);
                            client.CalculateStatBonus();
                            client.CalculateHPBonus();

                            ClientEquip equips = new ClientEquip(client);
                            client.Send(equips);
                            client.Equipment.UpdateEntityPacket2();
                        }
                        else
                        {

                        }
                        Database.ConquerItemTable.UpdateLocation(item, client);
                    }
                }
                client.LoadItemStats(client.Entity);
                client.CalculateStatBonus();
                client.CalculateHPBonus();
            }
            else
            {
                if (itemUsage.dwParam < 20)
                {

                    Interfaces.IConquerItem item = null;
                    client.Entity.AttackPacket = null;

                    if (client.Inventory.TryGetItem(itemUsage.UID, out item) && client.Booth == null)
                    {
                        if (item.Suspicious)
                            return;

                        Positions pos = GetPositionFromID(item.ID);
                        if (client.Entity.MapID == 2060)
                        {
                            if (pos == Positions.Garment)
                            {
                                return;
                            }
                        }
                        if (client.Entity.MapID == 7009)
                        {
                            if (pos == Positions.Garment)
                            {
                                return;
                            }
                        }
                        if (pos == Positions.Inventory)
                        {
                            UseItem(item, client);
                            return;
                        }
                        #region Sanity checks

                        bool can2hand = false;
                        bool can2wpn = false;
                        if (client.Entity.Class >= 11 && client.Entity.Class <= 75)
                            can2hand = true;
                        if (client.Entity.Class >= 11 && client.Entity.Class <= 15 || client.Entity.Class >= 51 && client.Entity.Class <= 55 || client.Entity.Class >= 61 && client.Entity.Class <= 65 || client.Entity.Class >= 71 && client.Entity.Class <= 75)
                            can2wpn = true;
                        if (client.Entity.Class >= 71 && client.Entity.Class <= 75)
                            can2wpn = true;
                        if (!Equipable(item, client))
                            return;
                        if (ItemPosition(item.ID) == 5)
                        {
                            itemUsage.dwParam = 5;
                            if (!can2hand && !can2wpn)
                                return;
                            if (client.Equipment.Free(4) || (client.Equipment.TryGetItem(4).ID / 1000 != 500 && IsArrow(item.ID)))
                                return;
                        }
                        if (ItemPosition(item.ID) == 4)
                        {
                            if (itemUsage.dwParam == 5)
                                if (!can2hand || !can2wpn)
                                    return;
                        }
                        if (!((itemUsage.dwParam == 4 || itemUsage.dwParam == 5) && (ItemPosition(item.ID) == 4 || ItemPosition(item.ID) == 5)))
                        {
                            if (!IsAccessory(item.ID))
                                itemUsage.dwParam = ItemPosition(item.ID);
                        }
                        bool twohand = IsTwoHand(item.ID);
                        if (!twohand && itemUsage.dwParam == 4)
                            if (!client.Equipment.Free(5))
                                if (client.Inventory.Count < 40)
                                {
                                    if (IsArrow(client.Equipment.TryGetItem(5).ID))
                                        client.Equipment.Remove(5);
                                    else
                                    {
                                        if (client.Equipment.TryGetItem(4) != null)
                                        {
                                            if (IsTwoHand(client.Equipment.TryGetItem(4).ID))
                                                client.Equipment.Remove(4);
                                        }
                                    }
                                }
                        #endregion

                        if (client.Map.ID == 1039)
                            client.Entity.AttackPacket = null;

                        item.Position = (ushort)itemUsage.dwParam;
                        if (ItemPosition(item.ID) == 5 && !IsArrow(item.ID))
                        {
                            if (IsTwoHand(client.Equipment.TryGetItem(4).ID))
                            {
                                if (!client.Spells.ContainsKey(10311))//Perseverance
                                {
                                    client.Send(new Message("You need to know Perseverance (Warrior Pure skill) to be able to wear 2-handed weapon and shield.", System.Drawing.Color.Red, Message.Talk));
                                    return;
                                }
                            }
                        }

                        //Database.ConquerItemTable.ClearPosition(client.Entity.UID, (byte)itemUsage.dwParam);
                        client.Inventory.Remove(item, Game.Enums.ItemUse.Move, true);
                        if (client.Equipment.Free((byte)itemUsage.dwParam))
                        {
                            if (twohand)
                                client.Equipment.Remove(5);
                            item.Position = (byte)itemUsage.dwParam;
                            if (!client.AlternateEquipment)
                            {
                                client.Equipment.Add(item);
                            }
                            else
                            {
                                client.Equipment.Add505(item);
                            }
                            item.Mode = Game.Enums.ItemMode.Update;
                            item.Send(client);
                        }
                        else
                        {
                            if (twohand)
                                client.Equipment.Remove(5);
                            client.Equipment.Remove((byte)itemUsage.dwParam);
                            item.Position = (byte)itemUsage.dwParam;
                            if (!client.AlternateEquipment)
                            {
                                client.Equipment.Add(item);
                            }
                            else
                            {
                                client.Equipment.Add505(item);
                            }
                        }

                        if (!client.AlternateEquipment)
                        {
                            client.LoadItemStats(client.Entity);
                            client.CalculateStatBonus();
                            client.CalculateHPBonus();
                            ClientEquip equips = new ClientEquip();
                            equips.DoEquips(client);
                            client.Send(equips);
                            client.Equipment.UpdateEntityPacket();
                        }
                        else
                        {
                            client.LoadItemStats2(client.Entity);
                            client.CalculateStatBonus();
                            client.CalculateHPBonus();
                            ClientEquip equips = new ClientEquip(client);
                            //equips.DoEquips(client);
                            client.Send(equips);
                            client.Equipment.UpdateEntityPacket2();
                        }

                        Database.ConquerItemTable.UpdateLocation(item, client);
                    }
                }
                else
                {
                    Interfaces.IConquerItem item = null;
                    client.Entity.AttackPacket = null;

                    if (client.Inventory.TryGetItem(itemUsage.UID, out item) && client.Booth == null)
                    {
                        if (item.Suspicious)
                            return;

                        Positions pos = GetPositionFromID2(item.ID);
                        if (client.Entity.MapID == 2060)
                        {
                            if (pos == Positions.AltGarment)
                            {
                                return;
                            }
                        }
                        if (client.Entity.MapID == 7009)
                        {
                            if (pos == Positions.AltGarment)
                            {
                                return;
                            }
                        }
                        if (pos == Positions.Inventory)
                        {
                            UseItem(item, client);
                            return;
                        }
                        #region Sanity checks

                        bool can2hand = false;
                        bool can2wpn = false;
                        if (client.Entity.Class >= 11 && client.Entity.Class <= 75)
                            can2hand = true;
                        if (client.Entity.Class >= 11 && client.Entity.Class <= 15 || client.Entity.Class >= 51 && client.Entity.Class <= 55 || client.Entity.Class >= 61 && client.Entity.Class <= 65 || client.Entity.Class >= 71 && client.Entity.Class <= 75)
                            can2wpn = true;
                        if (client.Entity.Class >= 71 && client.Entity.Class <= 75)
                            can2wpn = true;
                        if (!Equipable(item, client))
                            return;
                        if (ItemPosition2(item.ID) == 25)
                        {
                            itemUsage.dwParam = 25;
                            if (!can2hand && !can2wpn)
                                return;
                            if (client.Equipment.Free(24) || (client.Equipment.TryGetItem(24).ID / 1000 != 500 && IsArrow(item.ID)))
                                return;
                        }
                        if (ItemPosition2(item.ID) == 24)
                        {
                            if (itemUsage.dwParam == 25)
                                if (!can2hand || !can2wpn)
                                    return;
                        }
                        if (!((itemUsage.dwParam == 24 || itemUsage.dwParam == 25) && (ItemPosition2(item.ID) == 24 || ItemPosition2(item.ID) == 25)))
                        {
                            if (!IsAccessory(item.ID))
                                itemUsage.dwParam = ItemPosition2(item.ID);
                        }
                        bool twohand = IsTwoHand(item.ID);
                        if (!twohand && itemUsage.dwParam == 24)
                            if (!client.Equipment.Free(25))
                                if (client.Inventory.Count < 40)
                                {
                                    if (IsArrow(client.Equipment.TryGetItem(25).ID))
                                        client.Equipment.Remove(25);
                                    else
                                    {
                                        if (client.Equipment.TryGetItem(24) != null)
                                        {
                                            if (IsTwoHand(client.Equipment.TryGetItem(24).ID))
                                                client.Equipment.Remove(24);
                                        }
                                    }
                                }
                        #endregion

                        if (client.Map.ID == 1039)
                            client.Entity.AttackPacket = null;

                        item.Position = (ushort)itemUsage.dwParam;
                        if (ItemPosition2(item.ID) == 25 && !IsArrow(item.ID))
                        {
                            if (IsTwoHand(client.Equipment.TryGetItem(24).ID))
                            {
                                if (!client.Spells.ContainsKey(10311))//Perseverance
                                {
                                    client.Send(new Message("You need to know Perseverance (Warrior Pure skill) to be able to wear 2-handed weapon and shield.", System.Drawing.Color.Red, Message.Talk));
                                    return;
                                }
                            }
                        }

                        //Database.ConquerItemTable.ClearPosition(client.Entity.UID, (byte)itemUsage.dwParam);
                        client.Inventory.Remove(item, Game.Enums.ItemUse.Move, true);
                        if (client.Equipment.Free((byte)itemUsage.dwParam))
                        {
                            if (twohand)
                                client.Equipment.Remove(25);
                            item.Position = (byte)itemUsage.dwParam;
                            if (!client.AlternateEquipment)
                            {
                                client.Equipment.Add(item);
                            }
                            else
                            {
                                client.Equipment.Add600(item);
                            }
                            item.Mode = Game.Enums.ItemMode.Update;
                            item.Send(client);
                        }
                        else
                        {
                            if (twohand)
                                client.Equipment.Remove(25);
                            client.Equipment.Remove((byte)itemUsage.dwParam);
                            item.Position = (byte)itemUsage.dwParam;
                            if (!client.AlternateEquipment)
                            {
                                client.Equipment.Add(item);
                            }
                            else
                            {
                                client.Equipment.Add600(item);
                            }
                        }
                        if (client.AlternateEquipment)
                        {
                            client.LoadItemStats2(client.Entity);
                            client.CalculateStatBonus();
                            client.CalculateHPBonus();
                            ClientEquip equips = new ClientEquip(client);
                            client.Send(equips);
                            client.Equipment.UpdateEntityPacket2();
                        }
                        else
                        {

                        }
                        Database.ConquerItemTable.UpdateLocation(item, client);
                    }
                }
                client.LoadItemStats2(client.Entity);
                client.CalculateStatBonus();
                client.CalculateHPBonus();
            }
        }
        static void DropItem(ItemUsage itemUsage, Client.GameState client)
        {
            if (client.Booth != null)
            {
                Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Sorry you cant drop items while you in Booth");
                npc.OptionID = 255;
                client.Send(npc.ToArray());
                return;
            }
            Interfaces.IConquerItem item = null;
            if (client.Inventory.TryGetItem(itemUsage.UID, out item))
            {
                if (item.ID == 0)
                    return;
                Database.ConquerItemInformation infos = new Database.ConquerItemInformation(item.ID, 0);
                if (item.Lock != 0 || item.Suspicious)
                    return;
                if (infos.BaseInformation.Type == Database.ConquerItemBaseInformation.ItemType.Dropable && !item.Bound)
                {
                    ushort X = client.Entity.X, Y = client.Entity.Y;
                    if (client.Map.SelectCoordonates(ref X, ref Y))
                    {
                        FloorItem floorItem = new FloorItem(true);
                        floorItem.Item = item;
                        floorItem.ItemID = item.ID;
                        floorItem.ItemColor = item.Color;
                        floorItem.MapID = client.Map.ID;
                        floorItem.MapObjType = Game.MapObjectType.Item;
                        floorItem.X = X;
                        floorItem.Y = Y;
                        floorItem.Type = FloorItem.Drop;
                        floorItem.OnFloor = Time32.Now;
                        floorItem.UID = FloorItem.FloorUID.Next;
                        while (client.Map.Npcs.ContainsKey(floorItem.UID))
                            floorItem.UID = FloorItem.FloorUID.Next;
                        client.SendScreenSpawn(floorItem, true);
                        client.Map.AddFloorItem(floorItem);
                        client.Inventory.Remove(item, Game.Enums.ItemUse.Remove);

                        /* #region DropLog
                         var dt = DateTime.Now;
                         string date = dt.Year + "-" + dt.Month + "//";
                         string datess = +dt.Day + "//";
                         if (!Directory.Exists(System.Windows.Forms.Application.StartupPath + ServerBase.Constants.Unhandledgmlog))
                             Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog);

                         if (!Directory.Exists(System.Windows.Forms.Application.StartupPath + ServerBase.Constants.Unhandledgmlog + "\\Drop"))
                             Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\Drop");

                         if (!Directory.Exists(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\Drop\\" + date + ""))
                             Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\Drop\\" + date + "");
                         if (!File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\Drop\\" + date + "\\" + dt.Day + ".txt"))
                             File.CreateText(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\Drop\\" + date + "\\" + dt.Day + ".txt");

                         File.WriteAllText(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\Drop\\" + date + "\\" + dt.Day + ".txt",
             File.ReadAllText(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\Drop\\" + date + "\\" + dt.Day + ".txt") +
             "\r\n" + client.Entity.Name + " Droped item: [" + Database.ConquerItemInformation.BaseInformations[item.ID].Name + "] item UID: [" + item.UID + "] Plus: [" + item.Plus + "]");
                         #endregion*/
                    }
                }
                else
                    client.Inventory.Remove(item, Game.Enums.ItemUse.Remove);
            }
        }
        static void AddItemOnBooth(ItemUsage usage, Client.GameState client)
        {
            if (client.Booth != null && !client.Trade.InTrade)
            {
                if (!client.Booth.ItemList.ContainsKey(usage.UID))
                {
                    if (client.Inventory.ContainsUID(usage.UID))
                    {
                        Game.ConquerStructures.BoothItem item = new PhoenixProject.Game.ConquerStructures.BoothItem();
                        item.Cost = usage.dwParam;
                        client.Inventory.TryGetItem(usage.UID, out item.Item);
                        Database.ConquerItemInformation infos = new Database.ConquerItemInformation(item.Item.ID, 0);
                        if (item.Item.Lock != 0 || item.Item.Suspicious || item.Item.Bound || infos.BaseInformation.Type != Database.ConquerItemBaseInformation.ItemType.Dropable)
                        {
                            return;
                        }

                        item.Cost_Type = usage.ID == ItemUsage.AddItemOnBoothForSilvers ? PhoenixProject.Game.ConquerStructures.BoothItem.CostType.Silvers : PhoenixProject.Game.ConquerStructures.BoothItem.CostType.ConquerPoints;
                        client.Booth.ItemList.Add(item.Item.UID, item);
                        client.Send(usage);
                        BoothItem Item = new BoothItem(true);
                        Item.Fill(item, client.Booth.Base.UID);
                        client.SendScreen(Item, false);
                    }
                }
            }
        }
 static void BuyFromBooth(ItemUsage usage, Client.GameState client)
 {
     if (client.Trade.InTrade)
         return;
     Client.GameState Owner = null;
     Game.Entity entity = null;
     if (usage.dwParam > 1000000)
     {
         if (client.Screen.TryGetValue((uint)((usage.dwParam - 1000000) + 10000000), out entity))
         {
             if (entity.Owner == null)
                 return;
             Owner = entity.Owner;
             if (Owner.Booth == null)
             {
                 Owner.Disconnect();
                 return;
             }
             if (Owner != null)
             {
                 if (Owner.Entity.UID != client.Entity.UID)
                 {
                     if (Owner.Booth.ItemList.ContainsKey(usage.UID))
                     {
                         Game.ConquerStructures.BoothItem item;
                         if (Owner.Booth.ItemList.TryGetValue(usage.UID, out item))
                         {
                             if (client.Inventory.Count <= 39)
                             {
                                 if (item.Cost_Type == PhoenixProject.Game.ConquerStructures.BoothItem.CostType.Silvers)
                                 {
                                     if (client.Entity.Money >= item.Cost)
                                     {
                                         client.Entity.Money -= item.Cost;
                                         //Database.EntityTable.UpdateMoney(client);
                                         Owner.Entity.Money += item.Cost;
                                         //Database.EntityTable.UpdateMoney(Owner);
                                         client.Send(usage);
                                         client.Inventory.Add(item.Item, Game.Enums.ItemUse.Move);
                                         usage.ID = ItemUsage.RemoveItemFromBooth;
                                         Owner.Send(usage);
                                         Owner.Inventory.Remove(item.Item.UID, Game.Enums.ItemUse.None, false);
                                         usage.ID = ItemUsage.RemoveInventory;
                                         Owner.Send(usage);
                                         Owner.Booth.ItemList.Remove(item.Item.UID);
                                         Database.ConquerItemInformation infos = new Database.ConquerItemInformation(item.Item.ID, 0);
                                         Owner.Send(ServerBase.Constants.BoothItemSell(client.Entity.Name, infos.BaseInformation.Name, false, item.Cost));
                                     }
                                 }
                                 else
                                 {
                                     if (client.Entity.ConquerPoints >= item.Cost)
                                     {
                                         client.Entity.ConquerPoints -= item.Cost;
                                         Database.EntityTable.UpdateCps(client);
                                         Owner.Entity.ConquerPoints += item.Cost;
                                         Database.EntityTable.UpdateCps(Owner);
                                         client.Send(usage);
                                         client.Inventory.Add(item.Item, Game.Enums.ItemUse.Move);
                                         usage.ID = ItemUsage.RemoveItemFromBooth;
                                         Owner.Send(usage);
                                         Owner.Inventory.Remove(item.Item.UID, Game.Enums.ItemUse.None, false);
                                         usage.ID = ItemUsage.RemoveInventory;
                                         Owner.Send(usage);
                                         Owner.Booth.ItemList.Remove(item.Item.UID);
                                         Database.ConquerItemInformation infos = new Database.ConquerItemInformation(item.Item.ID, 0);
                                         Owner.Send(ServerBase.Constants.BoothItemSell(client.Entity.Name, infos.BaseInformation.Name, true, item.Cost));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         if (client.Screen.TryGetValue((uint)((usage.dwParam - 100000) + 1000000), out entity))
         {
             if (entity.Owner == null)
                 return;
             Owner = entity.Owner;
             if (Owner.Booth == null)
             {
                 Owner.Disconnect();
                 return;
             }
             if (Owner != null)
             {
                 if (Owner.Entity.UID != client.Entity.UID)
                 {
                     if (Owner.Booth.ItemList.ContainsKey(usage.UID))
                     {
                         Game.ConquerStructures.BoothItem item;
                         if (Owner.Booth.ItemList.TryGetValue(usage.UID, out item))
                         {
                             if (client.Inventory.Count <= 39)
                             {
                                 if (item.Cost_Type == PhoenixProject.Game.ConquerStructures.BoothItem.CostType.Silvers)
                                 {
                                     if (client.Entity.Money >= item.Cost)
                                     {
                                         client.Entity.Money -= item.Cost;
                                         //Database.EntityTable.UpdateMoney(client);
                                         Owner.Entity.Money += item.Cost;
                                         //Database.EntityTable.UpdateMoney(Owner);
                                         client.Send(usage);
                                         client.Inventory.Add(item.Item, Game.Enums.ItemUse.Move);
                                         usage.ID = ItemUsage.RemoveItemFromBooth;
                                         Owner.Send(usage);
                                         Owner.Inventory.Remove(item.Item.UID, Game.Enums.ItemUse.None, false);
                                         usage.ID = ItemUsage.RemoveInventory;
                                         Owner.Send(usage);
                                         Owner.Booth.ItemList.Remove(item.Item.UID);
                                         Database.ConquerItemInformation infos = new Database.ConquerItemInformation(item.Item.ID, 0);
                                         Owner.Send(ServerBase.Constants.BoothItemSell(client.Entity.Name, infos.BaseInformation.Name, false, item.Cost));
                                     }
                                 }
                                 else
                                 {
                                     if (client.Entity.ConquerPoints >= item.Cost)
                                     {
                                         client.Entity.ConquerPoints -= item.Cost;
                                         Database.EntityTable.UpdateCps(client);
                                         Owner.Entity.ConquerPoints += item.Cost;
                                         Database.EntityTable.UpdateCps(Owner);
                                         client.Send(usage);
                                         client.Inventory.Add(item.Item, Game.Enums.ItemUse.Move);
                                         usage.ID = ItemUsage.RemoveItemFromBooth;
                                         Owner.Send(usage);
                                         Owner.Inventory.Remove(item.Item.UID, Game.Enums.ItemUse.None, false);
                                         usage.ID = ItemUsage.RemoveInventory;
                                         Owner.Send(usage);
                                         Owner.Booth.ItemList.Remove(item.Item.UID);
                                         Database.ConquerItemInformation infos = new Database.ConquerItemInformation(item.Item.ID, 0);
                                         Owner.Send(ServerBase.Constants.BoothItemSell(client.Entity.Name, infos.BaseInformation.Name, true, item.Cost));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 public static void PrepareSpell(Database.SpellInformation spell, Client.GameState client)
 {
     if (spell.NeedXP == 1)
         client.Entity.RemoveFlag(Update.Flags.XPList);
     if (client.Map.ID != 1039)
     {
         if (spell.UseMana > 0)
             if (client.Entity.Mana >= spell.UseMana)
                 client.Entity.Mana -= spell.UseMana;
         if (spell.UseStamina > 0)
             if (client.Entity.Stamina >= spell.UseStamina)
                 client.Entity.Stamina -= spell.UseStamina;
         if (spell.UseArrows > 0 && isArcherSkill(spell.ID))
         {
             if (!client.AlternateEquipment)
             {
                 if (!client.Equipment.Free((byte)ConquerItem.LeftWeapon))
                 {
                     Interfaces.IConquerItem arrow = client.Equipment.TryGetItem(ConquerItem.LeftWeapon);
                     arrow.Durability -= spell.UseArrows;
                     ItemUsage usage = new ItemUsage(true) { UID = arrow.UID, dwParam = arrow.Durability, ID = ItemUsage.UpdateDurability };
                     usage.Send(client);
                     if (arrow.Durability <= spell.UseArrows || arrow.Durability > 5000)
                     {
                         Network.PacketHandler.ReloadArrows(client.Equipment.TryGetItem(ConquerItem.LeftWeapon), client);
                     }
                 }
             }
             else
             {
                 if (!client.Equipment.Free((byte)ConquerItem.AltLeftHand))
                 {
                     Interfaces.IConquerItem arrow = client.Equipment.TryGetItem(ConquerItem.AltLeftHand);
                     arrow.Durability -= spell.UseArrows;
                     ItemUsage usage = new ItemUsage(true) { UID = arrow.UID, dwParam = arrow.Durability, ID = ItemUsage.UpdateDurability };
                     usage.Send(client);
                     if (arrow.Durability <= spell.UseArrows || arrow.Durability > 5000)
                     {
                         Network.PacketHandler.ReloadArrows(client.Equipment.TryGetItem(ConquerItem.AltLeftHand), client);
                     }
                 }
             }
         }
     }
 }
        public static void UnequipItem(ItemUsage usage, Client.GameState client)
        {
            Positions pos = GetPositionFromID(usage.UID);
            if (client.Entity.MapID == 2060)
            {
                if (usage.dwParam == 9)
                {
                    return;
                }
            }
            if (client.Entity.MapID == 7009)
            {
                if (usage.dwParam == 9)
                {
                    return;
                }
            }
            if (client.Equipment.Remove((byte)usage.dwParam))
            {
                if (client.Map.ID == 1039)
                    client.Entity.AttackPacket = null;
                if (!client.AlternateEquipment)
                {
                    client.LoadItemStats(client.Entity);
                    client.CalculateStatBonus();
                    client.CalculateHPBonus();
                    ClientEquip equips = new ClientEquip();
                    equips.DoEquips(client);
                    client.Send(equips);
                    client.Equipment.UpdateEntityPacket();
                }
                else
                {
                    client.LoadItemStats2(client.Entity);
                    client.CalculateStatBonus();
                    client.CalculateHPBonus();

                    ClientEquip equips = new ClientEquip(client);
                    client.Send(equips);
                    client.Equipment.UpdateEntityPacket2();
                }
            }
        }
        static void SocketTalismanWithCPs(ItemUsage itemUsage, Client.GameState client)
        {
            Interfaces.IConquerItem talisman = client.Equipment.TryGetItem(itemUsage.UID);
            if (talisman == null)
                return;

            uint price = 0;
            if (talisman.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
            {
                double procent = 100 - (talisman.SocketProgress * 25600 / 2048000);
                if (100 - procent < 25)
                    return;
                price = (uint)(procent * 55);
            }
            else if (talisman.SocketTwo == PhoenixProject.Game.Enums.Gem.NoSocket)
            {
                double procent = 100 - (talisman.SocketProgress * 25600 / 5120000);
                if (100 - procent < 25)
                    return;
                price = (uint)(procent * 110);
            }
            else
                return;
            if (client.Entity.ConquerPoints >= price)
            {
                client.Entity.ConquerPoints -= price;
                if (talisman.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
                    talisman.SocketOne = PhoenixProject.Game.Enums.Gem.EmptySocket;
                else if (talisman.SocketTwo == PhoenixProject.Game.Enums.Gem.NoSocket)
                    talisman.SocketTwo = PhoenixProject.Game.Enums.Gem.EmptySocket;
                talisman.SocketProgress = 0;
                Database.ConquerItemTable.UpdateSockets(talisman);
                talisman.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                talisman.Send(client);
            }
        }
        static void HandleBuyFromNPC(ItemUsage itemUsage, Client.GameState client)
        {
            if (client.Trade.InTrade)
                return;
            if (client.Entity.MapID == 3031)
                return;
            if (itemUsage == null)
                return;
            if (client == null)
                return;
            Interfaces.INpc npc = null;
            if (client.Map.Npcs.TryGetValue(itemUsage.UID, out npc) || itemUsage.UID == 2888 || itemUsage.UID == 6000)
            {
                Interfaces.IConquerItem _ExistingItem;
                Database.ConquerItemInformation iteminfo = new PhoenixProject.Database.ConquerItemInformation(itemUsage.dwParam, 0);

                if (client.Inventory.Count == 40 && !client.Inventory.Contains(iteminfo.BaseInformation.ID, iteminfo.BaseInformation.StackSize, out _ExistingItem))
                    return;
                if (itemUsage.UID != 2888 && itemUsage.UID != 6000)
                    if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, npc.X, npc.Y) > 17)
                        return;
                Database.ShopFile.Shop shop = new PhoenixProject.Database.ShopFile.Shop();

                if (Database.ShopFile.Shops.TryGetValue(itemUsage.UID, out shop))
                {
                    if (shop.UID == 0)
                        return;
                    if (shop.UID != 6000 && shop.UID != 6001)
                    {
                        if (!shop.Items.Contains(itemUsage.dwParam))
                        { Console.WriteLine("Error! Cannot puchase item ID: " + itemUsage.dwParam + " from shop ID: " + itemUsage.UID); return; }
                    }
                    else
                    {
                        if (shop.UID == 6000)
                        {
                            if (!shop.HonorShopItems.ContainsKey(itemUsage.dwParam))
                            {
                                return;
                            }
                        }
                        else
                        {
                            if (shop.UID == 6001)
                            {
                                if (!shop.SteedShops.ContainsKey(itemUsage.dwParam))
                                {
                                    return;
                                }
                            }
                        }
                    }

                    uint Amount = itemUsage.dwExtraInfo > 0 ? itemUsage.dwExtraInfo : 1;

                    Interfaces.IConquerItem item = new ConquerItem(true);

                    switch (shop.MoneyType)
                    {
                        case Database.ShopFile.MoneyType.HonorPoints:
                            {

                                Database.ShopFile.Shop.HonorShopItem hshopi;
                                if (shop.HonorShopItems.TryGetValue(itemUsage.dwParam, out hshopi))
                                {
                                    if (client.ArenaStatistic != null)
                                    {
                                        if (client.Inventory.Count <= 39)
                                        {
                                            if (client.ArenaStatistic.CurrentHonor >= hshopi.cost)
                                            {
                                                Interfaces.IConquerItem newItem = new GamePackets.ConquerItem(true);
                                                newItem.ID = itemUsage.dwParam;
                                                Database.ConquerItemBaseInformation ibi;
                                                if (Database.ConquerItemInformation.BaseInformations.TryGetValue(newItem.ID, out ibi))
                                                {
                                                    if (ibi.Durability > 0)
                                                    {
                                                        newItem.Durability = ibi.Durability;
                                                        newItem.MaximDurability = ibi.Durability;
                                                    }
                                                }
                                                client.Inventory.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                                Data data = new Data(true);
                                                data.ID = GamePackets.Data.OpenCustom;
                                                data.UID = client.Entity.UID;
                                                data.TimeStamp = Time32.Now;
                                                data.dwParam = 3382;
                                                data.wParam1 = client.Entity.X;
                                                data.wParam2 = client.Entity.Y;
                                                client.Send(data);
                                                client.ArenaStatistic.CurrentHonor -= hshopi.cost;
                                                client.ArenaStatistic.Send(client);

                                            }
                                            else client.Send(new Message("You do not have enough Honor Points", Color.Red, Message.TopLeft));
                                        }
                                        else client.Send(new Message("You do not have enough space in your inventory", Color.Red, Message.TopLeft));
                                    }
                                }
                                else client.Send(new Message("Can not find this item", Color.Red, Message.TopLeft));
                                break;

                            }
                        case Database.ShopFile.MoneyType.RaceShop:
                            {

                                Database.ShopFile.Shop.SteedShop hshopi;
                                if (shop.SteedShops.TryGetValue(itemUsage.dwParam, out hshopi))
                                {
                                    if (client.Entity.RacePoints >= hshopi.cost)
                                    {
                                        if (client.Inventory.Count <= 39)
                                        {
                                            if (client.Entity.RacePoints >= hshopi.cost)
                                            {
                                                Interfaces.IConquerItem newItem = new GamePackets.ConquerItem(true);
                                                newItem.ID = itemUsage.dwParam;
                                                Database.ConquerItemBaseInformation ibi;
                                                if (Database.ConquerItemInformation.BaseInformations.TryGetValue(newItem.ID, out ibi))
                                                {
                                                    if (ibi.Durability > 0)
                                                    {
                                                        newItem.Durability = ibi.Durability;
                                                        newItem.MaximDurability = ibi.Durability;
                                                    }
                                                }
                                                client.Inventory.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                                Data data = new Data(true);
                                                data.ID = GamePackets.Data.OpenCustom;
                                                data.UID = client.Entity.UID;
                                                data.TimeStamp = Time32.Now;
                                                data.dwParam = 3382;
                                                data.wParam1 = client.Entity.X;
                                                data.wParam2 = client.Entity.Y;
                                                client.Send(data);
                                                client.Entity.RacePoints -= hshopi.cost;
                                            }
                                            else client.Send(new Message("You do not have enough Race Points", Color.Red, Message.TopLeft));
                                        }
                                        else client.Send(new Message("You do not have enough space in your inventory", Color.Red, Message.TopLeft));
                                    }
                                }
                                else client.Send(new Message("Can not find this item", Color.Red, Message.TopLeft));
                                break;

                            }
                        case PhoenixProject.Database.ShopFile.MoneyType.Gold:
                            {
                                if (iteminfo.BaseInformation.GoldWorth * Amount > client.Entity.Money)
                                    return;
                                if (client.Entity.Money - (iteminfo.BaseInformation.GoldWorth * Amount) > client.Entity.Money)
                                    return;
                                item.ID = itemUsage.dwParam;
                                item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                item.Color = (PhoenixProject.Game.Enums.Color)3;

                                uint NewAmount = itemUsage.dwExtraInfo > 0 ? itemUsage.dwExtraInfo : 1;
                                while (NewAmount > 0)
                                {
                                    if (client.Inventory.Contains(iteminfo.BaseInformation.ID, iteminfo.BaseInformation.StackSize, out _ExistingItem))
                                    {
                                        if (_ExistingItem.StackSize == 0)
                                            _ExistingItem.StackSize = 1;

                                        ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                        _StackCount -= (ushort)_ExistingItem.StackSize;

                                        if (_StackCount >= NewAmount)
                                            _StackCount = (ushort)NewAmount;
                                        _ExistingItem.StackSize += _StackCount;

                                        Database.ConquerItemTable.UpdateStack(_ExistingItem);
                                        _ExistingItem.Mode = Game.Enums.ItemMode.Update;
                                        _ExistingItem.Send(client);
                                        _ExistingItem.Mode = Game.Enums.ItemMode.Default;
                                        NewAmount -= _StackCount;
                                        Data data = new Data(true);
                                        data.ID = GamePackets.Data.OpenCustom;
                                        data.UID = client.Entity.UID;
                                        data.TimeStamp = Time32.Now;
                                        data.dwParam = 3382;
                                        data.wParam1 = client.Entity.X;
                                        data.wParam2 = client.Entity.Y;
                                        client.Send(data);

                                        //uint _TotalItemStacks = Math.Min(1, (itemUsage.dwExtraInfo / iteminfo.BaseInformation.StackSize));
                                    }
                                    else
                                    {
                                        if (iteminfo.BaseInformation.StackSize > 1 && itemUsage.dwExtraInfo > 1)
                                        {
                                            item = new ConquerItem(true);
                                            item.ID = itemUsage.dwParam;
                                            item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                            item.Color = (PhoenixProject.Game.Enums.Color)3;
                                            ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                            if (NewAmount <= iteminfo.BaseInformation.StackSize)
                                                _StackCount = (ushort)NewAmount;
                                            item.StackSize = (ushort)_StackCount;
                                            client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                            Database.ConquerItemTable.UpdateStack(item);
                                            NewAmount -= _StackCount;
                                            Data data = new Data(true);
                                            data.ID = GamePackets.Data.OpenCustom;
                                            data.UID = client.Entity.UID;
                                            data.TimeStamp = Time32.Now;
                                            data.dwParam = 3382;
                                            data.wParam1 = client.Entity.X;
                                            data.wParam2 = client.Entity.Y;
                                            client.Send(data);
                                        }
                                        else
                                        {
                                            item = new ConquerItem(true);
                                            item.ID = itemUsage.dwParam;
                                            item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                            item.Color = (PhoenixProject.Game.Enums.Color)3;
                                            item.StackSize = 1;
                                            client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                            NewAmount--;
                                            Data data = new Data(true);
                                            data.ID = GamePackets.Data.OpenCustom;
                                            data.UID = client.Entity.UID;
                                            data.TimeStamp = Time32.Now;
                                            data.dwParam = 3382;
                                            data.wParam1 = client.Entity.X;
                                            data.wParam2 = client.Entity.Y;
                                            client.Send(data);
                                        }
                                    }
                                }
                                client.Entity.Money -= (iteminfo.BaseInformation.GoldWorth * Amount);

                                //if (Amount > 1 && canMakeStack)
                                //{
                                //    item.StackSize = (ushort)Amount > 5 ? (ushort)5 : (ushort)Amount;
                                //    item.MaxStackSize = 5;
                                //    Amount -= (uint)item.StackSize - 1;
                                //    Database.ConquerItemTable.UpdateStack(item);
                                //}
                                //client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                //if (client.Inventory.ContainsUID(item.UID))
                                //    if (canMakeStack)
                                //        client.Entity.Money -= iteminfo.BaseInformation.GoldWorth * Amount;
                                //    else
                                //        client.Entity.Money -= iteminfo.BaseInformation.GoldWorth;
                                //        //Database.EntityTable.UpdateMoney(client);
                                break;
                            }
                        case PhoenixProject.Database.ShopFile.MoneyType.ConquerPoints:
                            {

                                if (itemUsage.dwExtraInfo3 == 1)
                                {
                                    if (iteminfo.BaseInformation.ConquerPointsWorth * Amount > client.Entity.ConquerPoints)
                                        return;
                                    if (client.Entity.ConquerPoints - (iteminfo.BaseInformation.ConquerPointsWorth * Amount) > client.Entity.ConquerPoints)
                                        return;
                                    item.ID = itemUsage.dwParam;
                                    if (item.ID % 730000 <= 12)
                                        item.Plus = (Byte)(item.ID % 730000);
                                    item.Color = (PhoenixProject.Game.Enums.Color)ServerBase.Kernel.Random.Next(4, 8);
                                    item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                    uint NewAmount = itemUsage.dwExtraInfo > 0 ? itemUsage.dwExtraInfo : 1;
                                    while (NewAmount > 0)
                                    {
                                        if (client.Inventory.Contains(iteminfo.BaseInformation.ID, iteminfo.BaseInformation.StackSize, out _ExistingItem))
                                        {
                                            if (_ExistingItem.StackSize == 0)
                                                _ExistingItem.StackSize = 1;

                                            ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                            _StackCount -= (ushort)_ExistingItem.StackSize;

                                            if (_StackCount >= NewAmount)
                                                _StackCount = (ushort)NewAmount;
                                            _ExistingItem.StackSize += _StackCount;

                                            Database.ConquerItemTable.UpdateStack(_ExistingItem);
                                            _ExistingItem.Mode = Game.Enums.ItemMode.Update;
                                            _ExistingItem.Send(client);
                                            _ExistingItem.Mode = Game.Enums.ItemMode.Default;
                                            NewAmount -= _StackCount;
                                            Data data = new Data(true);
                                            data.ID = GamePackets.Data.OpenCustom;
                                            data.UID = client.Entity.UID;
                                            data.TimeStamp = Time32.Now;
                                            data.dwParam = 3382;
                                            data.wParam1 = client.Entity.X;
                                            data.wParam2 = client.Entity.Y;
                                            client.Send(data);

                                            //uint _TotalItemStacks = Math.Min(1, (itemUsage.dwExtraInfo / iteminfo.BaseInformation.StackSize));
                                        }
                                        else
                                        {
                                            if (iteminfo.BaseInformation.StackSize > 1 && itemUsage.dwExtraInfo > 1)
                                            {
                                                item = new ConquerItem(true);
                                                item.ID = itemUsage.dwParam;
                                                item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                                item.Color = (PhoenixProject.Game.Enums.Color)3;
                                                ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                                if (NewAmount <= iteminfo.BaseInformation.StackSize)
                                                    _StackCount = (ushort)NewAmount;
                                                item.StackSize = (ushort)_StackCount;
                                                client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                                Database.ConquerItemTable.UpdateStack(item);
                                                NewAmount -= _StackCount;
                                                Data data = new Data(true);
                                                data.ID = GamePackets.Data.OpenCustom;
                                                data.UID = client.Entity.UID;
                                                data.TimeStamp = Time32.Now;
                                                data.dwParam = 3382;
                                                data.wParam1 = client.Entity.X;
                                                data.wParam2 = client.Entity.Y;
                                                client.Send(data);
                                            }
                                            else
                                            {
                                                item = new ConquerItem(true);
                                                item.ID = itemUsage.dwParam;
                                                item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                                item.Color = (PhoenixProject.Game.Enums.Color)3;
                                                item.StackSize = 1;
                                                if (item.ID == 730001)
                                                {
                                                    item.Plus = 1;
                                                }
                                                if (item.ID == 730002)
                                                {
                                                    item.Plus = 2;
                                                }
                                                if (item.ID == 730003)
                                                {
                                                    item.Plus = 3;
                                                }
                                                if (item.ID == 730004)
                                                {
                                                    item.Plus = 4;
                                                }
                                                if (item.ID == 730005)
                                                {
                                                    item.Plus = 5;
                                                }
                                                if (item.ID == 730006)
                                                {
                                                    item.Plus = 6;
                                                }
                                                if (item.ID == 730007)
                                                {
                                                    item.Plus = 7;
                                                }
                                                if (item.ID == 730008)
                                                {
                                                    item.Plus = 8;
                                                }
                                                if (item.ID == 730009)
                                                {
                                                    item.Plus = 9;
                                                }
                                                client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                                NewAmount--;
                                                Data data = new Data(true);
                                                data.ID = GamePackets.Data.OpenCustom;
                                                data.UID = client.Entity.UID;
                                                data.TimeStamp = Time32.Now;
                                                data.dwParam = 3382;
                                                data.wParam1 = client.Entity.X;
                                                data.wParam2 = client.Entity.Y;
                                                client.Send(data);
                                            }
                                        }
                                    }
                                    client.Entity.ConquerPoints -= (iteminfo.BaseInformation.ConquerPointsWorth * Amount);
                                    break;
                                }
                                else
                                {
                                    ushort postion = ItemPosition(itemUsage.dwParam);
                                    if (ServerBase.Constants.AllowedBound.Contains(itemUsage.dwParam) || postion == ConquerItem.LeftWeaponAccessory || postion == ConquerItem.Garment)
                                    {
                                        if (iteminfo.BaseInformation.ConquerPointsWorth * Amount > client.Entity.BConquerPoints)
                                            return;
                                        if (client.Entity.BConquerPoints - (iteminfo.BaseInformation.ConquerPointsWorth * Amount) > client.Entity.BConquerPoints)
                                            return;
                                        item.ID = itemUsage.dwParam;
                                        if (item.ID % 730000 <= 12)
                                            item.Plus = (Byte)(item.ID % 730000);
                                        item.Color = (PhoenixProject.Game.Enums.Color)ServerBase.Kernel.Random.Next(4, 8);
                                        item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                        item.Bound = true;
                                        uint NewAmount = itemUsage.dwExtraInfo > 0 ? itemUsage.dwExtraInfo : 1;
                                        while (NewAmount > 0)
                                        {
                                            if (client.Inventory.Contains(iteminfo.BaseInformation.ID, iteminfo.BaseInformation.StackSize, out _ExistingItem))
                                            {
                                                if (_ExistingItem.StackSize == 0)
                                                    _ExistingItem.StackSize = 1;

                                                ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                                _StackCount -= (ushort)_ExistingItem.StackSize;

                                                if (_StackCount >= NewAmount)
                                                    _StackCount = (ushort)NewAmount;
                                                _ExistingItem.StackSize += _StackCount;

                                                Database.ConquerItemTable.UpdateStack(_ExistingItem);
                                                _ExistingItem.Mode = Game.Enums.ItemMode.Update;
                                                _ExistingItem.Send(client);
                                                _ExistingItem.Mode = Game.Enums.ItemMode.Default;
                                                NewAmount -= _StackCount;
                                                Data data = new Data(true);
                                                data.ID = GamePackets.Data.OpenCustom;
                                                data.UID = client.Entity.UID;
                                                data.TimeStamp = Time32.Now;
                                                data.dwParam = 3382;
                                                data.wParam1 = client.Entity.X;
                                                data.wParam2 = client.Entity.Y;
                                                client.Send(data);

                                                //uint _TotalItemStacks = Math.Min(1, (itemUsage.dwExtraInfo / iteminfo.BaseInformation.StackSize));
                                            }
                                            else
                                            {
                                                if (iteminfo.BaseInformation.StackSize > 1 && itemUsage.dwExtraInfo > 1)
                                                {
                                                    item = new ConquerItem(true);
                                                    item.ID = itemUsage.dwParam;
                                                    item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                                    item.Color = (PhoenixProject.Game.Enums.Color)3;
                                                    ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                                    if (NewAmount <= iteminfo.BaseInformation.StackSize)
                                                        _StackCount = (ushort)NewAmount;
                                                    item.StackSize = (ushort)_StackCount;
                                                    if (item.ID == 730001)
                                                    {
                                                        item.Plus = 1;
                                                    }
                                                    if (item.ID == 730002)
                                                    {
                                                        item.Plus = 2;
                                                    }
                                                    if (item.ID == 730003)
                                                    {
                                                        item.Plus = 3;
                                                    }
                                                    if (item.ID == 730004)
                                                    {
                                                        item.Plus = 4;
                                                    }
                                                    if (item.ID == 730005)
                                                    {
                                                        item.Plus = 5;
                                                    }
                                                    if (item.ID == 730006)
                                                    {
                                                        item.Plus = 6;
                                                    }
                                                    if (item.ID == 730007)
                                                    {
                                                        item.Plus = 7;
                                                    }
                                                    if (item.ID == 730008)
                                                    {
                                                        item.Plus = 8;
                                                    }
                                                    if (item.ID == 730009)
                                                    {
                                                        item.Plus = 9;
                                                    }
                                                    client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                                    Database.ConquerItemTable.UpdateStack(item);
                                                    NewAmount -= _StackCount;
                                                    Data data = new Data(true);
                                                    data.ID = GamePackets.Data.OpenCustom;
                                                    data.UID = client.Entity.UID;
                                                    data.TimeStamp = Time32.Now;
                                                    data.dwParam = 3382;
                                                    data.wParam1 = client.Entity.X;
                                                    data.wParam2 = client.Entity.Y;
                                                    client.Send(data);
                                                }
                                                else
                                                {
                                                    item = new ConquerItem(true);
                                                    item.ID = itemUsage.dwParam;
                                                    item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                                    item.Color = (PhoenixProject.Game.Enums.Color)3;
                                                    item.StackSize = 1;
                                                    if (item.ID == 730001)
                                                    {
                                                        item.Plus = 1;
                                                    }
                                                    if (item.ID == 730002)
                                                    {
                                                        item.Plus = 2;
                                                    }
                                                    if (item.ID == 730003)
                                                    {
                                                        item.Plus = 3;
                                                    }
                                                    if (item.ID == 730004)
                                                    {
                                                        item.Plus = 4;
                                                    }
                                                    if (item.ID == 730005)
                                                    {
                                                        item.Plus = 5;
                                                    }
                                                    if (item.ID == 730006)
                                                    {
                                                        item.Plus = 6;
                                                    }
                                                    if (item.ID == 730007)
                                                    {
                                                        item.Plus = 7;
                                                    }
                                                    if (item.ID == 730008)
                                                    {
                                                        item.Plus = 8;
                                                    }
                                                    if (item.ID == 730009)
                                                    {
                                                        item.Plus = 9;
                                                    }
                                                    client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                                    NewAmount--;
                                                    Data data = new Data(true);
                                                    data.ID = GamePackets.Data.OpenCustom;
                                                    data.UID = client.Entity.UID;
                                                    data.TimeStamp = Time32.Now;
                                                    data.dwParam = 3382;
                                                    data.wParam1 = client.Entity.X;
                                                    data.wParam2 = client.Entity.Y;
                                                    client.Send(data);
                                                }
                                            }
                                        }
                                        client.Entity.BConquerPoints -= (iteminfo.BaseInformation.ConquerPointsWorth * Amount);
                                        itemUsage.dwParam = 1;
                                        client.Send(itemUsage);
                                    }
                                    else
                                    {
                                        itemUsage.dwParam = 0;
                                        client.Send(itemUsage);
                                    }
                                    break;
                                }
                            }

                    }
                    Amount--;
                }
            }
        }
 static void RemoveItemFromBooth(ItemUsage usage, Client.GameState client)
 {
     if (client.Booth.ItemList.ContainsKey(usage.UID))
     {
         client.Booth.ItemList.Remove(usage.UID);
         client.SendScreen(usage, true);
     }
 }
        static void ShowBoothItems(ItemUsage usage, Client.GameState client)
        {
            Client.GameState Owner = null;
            Game.Entity entity = null;

            if (usage.UID > 1000000)
            {
                //Console.WriteLine("Sk: " + usage.UID + "");//1000176
                //Console.WriteLine("Sv: " + (uint)((usage.UID - 1000000) + 10000000) + "");
                if (client.Screen.TryGetValue((uint)((usage.UID - 1000000) + 10000000), out entity))
                {
                    Owner = entity.Owner;
                    if (Owner != null)
                    {
                        if (Owner.Entity.UID != client.Entity.UID)
                        {
                            BoothItem Item = new BoothItem(true);
                            if (Owner.Booth != null)
                            {
                                foreach (Game.ConquerStructures.BoothItem item in Owner.Booth.ItemList.Values)
                                {
                                    Item.Fill(item, Owner.Booth.Base.UID);
                                    client.Send(Item);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // Console.WriteLine("Methods: " + usage.UID + "");//10000176
                //Console.WriteLine("Method: " + (uint)((usage.UID - 100000) + 1000000) + "");
                if (client.Screen.TryGetValue((uint)((usage.UID - 100000) + 1000000), out entity))
                {
                    Owner = entity.Owner;
                    if (Owner != null)
                    {
                        if (Owner.Entity.UID != client.Entity.UID)
                        {
                            BoothItem Item = new BoothItem(true);
                            if (Owner.Booth != null)
                            {
                                foreach (Game.ConquerStructures.BoothItem item in Owner.Booth.ItemList.Values)
                                {
                                    Item.Fill(item, Owner.Booth.Base.UID);
                                    client.Send(Item);
                                }
                            }
                        }
                    }
                }
            }
        }
        static void LoginMessages(Client.GameState client)
        {
            if (client.WentToComplete)
                return;
            Data datas = new Data(true);
            datas.UID = client.Entity.UID;
            datas.ID = 116;
            datas.dwParam = 1197;
            client.Send(datas);
            client.SocketDisposed = false;

            // client.Send(Unknown2078Packet.Create(0x4f999eba));
            // client.TimeStamps.LoggedInTime = DateTime.Now;
            client.Send(new byte[] { 8, 0, 0x1f, 8, 0, 0, 0, 0, 0x54, 0x51, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72 });

            client.Send(new byte[] {
                    0x1c, 1, 0x25, 4, 0, 0, 0x22, 0, 0x7a, 3, 0, 0, 0, 0, 0, 0,
                    0xb2, 2, 0, 0, 0xff, 0xff, 0xff, 0xff, 0x8a, 2, 0, 0, 0, 0, 0, 0,
                    0x5b, 3, 0, 0, 0xff, 0xff, 0xff, 0xff, 90, 3, 0, 0, 0xff, 0xff, 0xff, 0xff,
                    0x59, 3, 0, 0, 0xff, 0xff, 0xff, 0xff, 0x58, 3, 0, 0, 0xff, 0xff, 0xff, 0xff,
                    0x57, 3, 0, 0, 0xff, 0xff, 0xff, 0xff, 0x56, 3, 0, 0, 0xff, 0xff, 0xff, 0xff,
                    0x55, 3, 0, 0, 0xff, 0xff, 0xff, 0xff, 0x54, 3, 0, 0, 0xff, 0xff, 0xff, 0xff,
                    0x53, 3, 0, 0, 0xff, 0xff, 0xff, 0xff, 0x52, 3, 0, 0, 0xff, 0xff, 0xff, 0xff,
                    0x57, 2, 0, 0, 0, 0, 0, 0, 0x56, 2, 0, 0, 0, 0, 0, 0,
                    0x55, 2, 0, 0, 0, 0, 0, 0, 0x54, 2, 0, 0, 0, 0, 0, 0,
                    0x53, 2, 0, 0, 0, 0, 0, 0, 0x52, 2, 0, 0, 0, 0, 0, 0,
                    0x51, 2, 0, 0, 0, 0, 0, 0, 80, 2, 0, 0, 0, 0, 0, 0,
                    0x4f, 2, 0, 0, 0, 0, 0, 0, 0x4e, 2, 0, 0, 0, 0, 0, 0,
                    0xf3, 1, 0, 0, 0, 0, 0, 0, 0xf2, 1, 0, 0, 0, 0, 0, 0,
                    0xf1, 1, 0, 0, 0, 0, 0, 0, 240, 1, 0, 0, 0, 0, 0, 0,
                    0xef, 1, 0, 0, 0, 0, 0, 0, 0xee, 1, 0, 0, 0, 0, 0, 0,
                    0xed, 1, 0, 0, 0, 0, 0, 0, 0xec, 1, 0, 0, 0, 0, 0, 0,
                    0xeb, 1, 0, 0, 0, 0, 0, 0, 0xea, 1, 0, 0, 0, 0, 0, 0,
                    210, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x54, 0x51, 0x53, 0x65,
                    0x72, 0x76, 0x65, 0x72
                 });
            client.Send(new byte[] {
                    60, 0, 0x7e, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x54, 0x51, 0x53, 0x65,
                    0x72, 0x76, 0x65, 0x72
                 });
            client.Send(new byte[] {
                    60, 0, 0x7e, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x54, 0x51, 0x53, 0x65,
                    0x72, 0x76, 0x65, 0x72
                 });
            client.Send(new byte[] {
                    0x54, 0, 0x20, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0x54, 0x51, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72
                 });

            DateTime time2 = new DateTime(0x7b2, 1, 1);
            TimeSpan span = (TimeSpan)(client.Entity.LastLogin - time2.ToLocalTime());
            uint num = (uint)span.TotalSeconds - 3600;
            // uint num = (uint)client.Entity.LastLogin.ToFileTime();
            if (num == 0)
            {
                DateTime time3 = new DateTime(0x7b2, 1, 1);
                TimeSpan span3 = (TimeSpan)(DateTime.Now - time3.ToLocalTime());

                num = (uint)span3.TotalSeconds - 3600;
            }
            LastLogin login = new LastLogin
            {
                TotalSeconds = num,
                Type = ((client.Account.IP != string.Empty) && (client.Account.IP != client.Account.OldIP)) ? PhoenixProject.Network.GamePackets.LastLogin.LastLoginTypes.DifferentCity : PhoenixProject.Network.GamePackets.LastLogin.LastLoginTypes.LastLogin,
                Unknown = 1
            };
            client.Send((byte[])login);

            if (client.Spells.ContainsKey(3050))
            {
                if (client.Entity.SecondRebornClass == 15 && client.Entity.FirstRebornClass == 15)
                {
                    // client.AddSpell(new Spell(true) { ID = 3050 });
                }
                else
                {
                    if (client.Entity.SecondRebornClass == 15 && client.Entity.Class >= 10 && client.Entity.Class <= 15)
                    {
                        // client.AddSpell(new Spell(true) { ID = 3050 });
                    }
                    else
                    {
                        if (client.Entity.FirstRebornClass == 15 && client.Entity.Class >= 10 && client.Entity.Class <= 15)
                        {
                            // client.AddSpell(new Spell(true) { ID = 3050 });
                        }
                        else
                        {
                            client.RemoveSpell(new Spell(true) { ID = 3050 });
                        }
                    }
                }
            }

            if (client.Spells.ContainsKey(11100))
            {
                if (client.Entity.SecondRebornClass == 75 && client.Entity.FirstRebornClass == 75)
                {
                    // client.AddSpell(new Spell(true) { ID = 3050 });
                }
                else
                {
                    if (client.Entity.SecondRebornClass == 75 && client.Entity.Class >= 70 && client.Entity.Class <= 75)
                    {
                        // client.AddSpell(new Spell(true) { ID = 3050 });
                    }
                    else
                    {
                        if (client.Entity.FirstRebornClass == 75 && client.Entity.Class >= 70 && client.Entity.Class <= 75)
                        {
                            // client.AddSpell(new Spell(true) { ID = 3050 });
                        }
                        else
                        {
                            client.RemoveSpell(new Spell(true) { ID = 11100 });
                        }
                    }
                }
            }

            if (client.Spells.ContainsKey(11050))
            {
                if (client.Spells[11050].Level > 0)
                {
                    client.RemoveSpell(new Spell(true) { ID = 11050 });
                    client.AddSpell(new Spell(true) { ID = 11050 });
                }
            }

            if (client.Entity.Class >= 50 && client.Entity.Class <= 55)
            {
                if (!client.Spells.ContainsKey(11230))
                {
                    client.AddSpell(new Spell(true) { ID = 11230 });
                }
            }
            else
            {
                if (client.Spells.ContainsKey(11230))
                {
                    client.RemoveSpell(new Spell(true) { ID = 11230 });
                }

            }

            if (client.Entity.Class >= 142 && client.Entity.Class <= 145 && client.Entity.FirstRebornClass == 145 && client.Entity.SecondRebornClass == 145)
            {
                if (!client.Spells.ContainsKey(10310))
                {
                    client.AddSpell(new Spell(true) { ID = 10310 });
                }
            }
            else
            {
                if (client.Spells.ContainsKey(10310))
                {
                    client.RemoveSpell(new Spell(true) { ID = 10310 });
                }

            }

            if (client.Entity.Class >= 132 && client.Entity.Class <= 135 && client.Entity.FirstRebornClass == 135 && client.Entity.SecondRebornClass == 135)
            {
                if (!client.Spells.ContainsKey(30000))
                {
                    client.AddSpell(new Spell(true) { ID = 30000 });
                }
            }
            else
            {
                if (client.Spells.ContainsKey(30000))
                {
                    client.RemoveSpell(new Spell(true) { ID = 30000 });
                }

            }

            if (client.Entity.Class >= 70 && client.Entity.Class <= 75 && client.Entity.FirstRebornClass == 75 && client.Entity.SecondRebornClass == 75)
            {
                if (!client.Spells.ContainsKey(11040))
                {
                    client.AddSpell(new Spell(true) { ID = 11040 });
                }
            }
            else
            {
                if (client.Spells.ContainsKey(11040))
                {
                    client.RemoveSpell(new Spell(true) { ID = 11040 });
                }

            }

            if (client.Entity.Class >= 50 && client.Entity.Class <= 55 && client.Entity.FirstRebornClass <= 55 && client.Entity.FirstRebornClass >= 50 && client.Entity.SecondRebornClass <= 55 && client.Entity.SecondRebornClass >= 50)
            {
                if (!client.Spells.ContainsKey(6003))
                {
                    client.AddSpell(new Spell(true) { ID = 6003 });
                }
            }
            else
            {
                if (client.Spells.ContainsKey(6003))
                {
                    client.RemoveSpell(new Spell(true) { ID = 6003 });
                }

            }
            if (client.Entity.Class >= 60 && client.Entity.Class <= 65 && client.Entity.FirstRebornClass <= 65 && client.Entity.FirstRebornClass >= 60 && client.Entity.SecondRebornClass <= 65 && client.Entity.SecondRebornClass >= 60)
            {
                if (!client.Spells.ContainsKey(10405))
                {
                    client.AddSpell(new Spell(true) { ID = 10405 });
                }
            }
            else
            {
                if (client.Spells.ContainsKey(10405))
                {
                    client.RemoveSpell(new Spell(true) { ID = 10405 });
                }

            }

            if (client.Entity.Class >= 40 && client.Entity.Class <= 45 && client.Entity.FirstRebornClass <= 45 && client.Entity.FirstRebornClass >= 40 && client.Entity.SecondRebornClass <= 45 && client.Entity.SecondRebornClass >= 40)
            {
                if (!client.Spells.ContainsKey(10313))
                {
                    client.AddSpell(new Spell(true) { ID = 10313 });
                }
            }
            else
            {
                if (client.Spells.ContainsKey(10313))
                {
                    client.RemoveSpell(new Spell(true) { ID = 10313 });
                }

            }
            if (client.Entity.Class >= 20 && client.Entity.Class <= 25 && client.Entity.FirstRebornClass <= 25 && client.Entity.FirstRebornClass >= 20 && client.Entity.SecondRebornClass <= 25 && client.Entity.SecondRebornClass >= 20)
            {
                if (!client.Spells.ContainsKey(10311))
                {
                    client.AddSpell(new Spell(true) { ID = 10311 });
                }
            }
            else
            {
                if (client.Spells.ContainsKey(10311))
                {
                    client.RemoveSpell(new Spell(true) { ID = 10311 });
                }

            }

            if (client.Entity.Class >= 10 && client.Entity.Class <= 15 && client.Entity.FirstRebornClass <= 15 && client.Entity.FirstRebornClass >= 10 && client.Entity.SecondRebornClass <= 15 && client.Entity.SecondRebornClass >= 10)
            {
                if (!client.Spells.ContainsKey(10315))
                {
                    client.AddSpell(new Spell(true) { ID = 10315 });
                }
            }
            else
            {
                if (client.Spells.ContainsKey(10315))
                {
                    client.RemoveSpell(new Spell(true) { ID = 10315 });
                }

            }

            if (client.Entity.Class >= 40 && client.Entity.Class <= 45)
            {
                if (client.Spells.ContainsKey(1025))
                {
                    client.RemoveSpell(new Spell(true) { ID = 1025 });//SuperMan
                }
            }
            if (client.Entity.Class >= 142 && client.Entity.Class <= 145)
            {
                if (client.Spells.ContainsKey(6002))
                {
                    client.RemoveSpell(new Spell(true) { ID = 6002 });//PiosnStar
                }
            }
            client.WentToComplete = true;
            client.Entity.SendUpdates = true;
            foreach (Interfaces.IConquerItem item in client.Inventory.Objects)
            {
                item.Send(client);
            }
            foreach (Interfaces.IConquerItem item in client.Equipment.Objects)
                if (item != null)
                {
                    if (Database.ConquerItemInformation.BaseInformations.ContainsKey(item.ID))
                    {
                        item.Send(client);
                        ItemUsage usage = new ItemUsage(true) { ID = ItemUsage.EquipItem };
                        usage.UID = item.UID;
                        usage.dwParam = item.Position;
                        client.Send(usage);
                        client.LoadItemStats(client.Entity);
                        client.CalculateStatBonus();
                        client.CalculateHPBonus();
                    }
                    else
                    {
                        client.Equipment.DestroyArrow(item.Position);
                    }
                }

            client.LoadItemStats(client.Entity);
            client.CalculateStatBonus();
            client.CalculateHPBonus();
            client.Equipment.UpdateEntityPacket();
            ClientEquip equips = new ClientEquip();
            equips.DoEquips(client);
            client.Send(equips);
            foreach (var Guild in ServerBase.Kernel.Guilds.Values)
            {
                Guild.SendName(client);
            }
            if (client.Entity.ClanId != 0 && client.Entity.ClanRank != 0 && client.Entity.ClanName != "")
            {
                if (client.Entity.Myclan != null)
                {
                    Network.GamePackets.Clan cl = new PhoenixProject.Network.GamePackets.Clan(client, 1);
                    client.Send(cl.ToArray());
                }
            }
            ServerTime time = new ServerTime();
            time.Year = (uint)DateTime.Now.Year;
            time.Month = (uint)DateTime.Now.Month;
            time.DayOfYear = (uint)DateTime.Now.DayOfYear;
            time.DayOfMonth = (uint)DateTime.Now.Day;
            time.Hour = (uint)DateTime.Now.Hour;
            time.Minute = (uint)DateTime.Now.Minute;
            time.Second = (uint)DateTime.Now.Second;
            client.Send(time);

            client.Entity.DoubleExperienceTime = (ushort)(client.Entity.DoubleExperienceTime + (1 - 1));
            client.Entity.HeavenBlessing = (ushort)(client.Entity.HeavenBlessing + (1 - 1));

            if (client.Mentor != null)
            {
                if (client.Mentor.IsOnline)
                {
                    MentorInformation Information = new MentorInformation(true);
                    Information.Mentor_Type = 1;
                    Information.Mentor_ID = client.Mentor.Client.Entity.UID;
                    Information.Apprentice_ID = client.Entity.UID;
                    Information.Enrole_Date = client.Mentor.EnroleDate;
                    Information.Mentor_Level = client.Mentor.Client.Entity.Level;
                    Information.Mentor_Class = client.Mentor.Client.Entity.Class;
                    Information.Mentor_PkPoints = client.Mentor.Client.Entity.PKPoints;
                    Information.Mentor_Mesh = client.Mentor.Client.Entity.Mesh;
                    Information.Mentor_Online = true;
                    Information.Shared_Battle_Power = (uint)(((client.Mentor.Client.Entity.BattlePower - client.Mentor.Client.Entity.ExtraBattlePower) - (client.Entity.BattlePower - client.Entity.ExtraBattlePower)) / 3.3F);
                    Information.String_Count = 3;
                    Information.Mentor_Name = client.Mentor.Client.Entity.Name;
                    Information.Apprentice_Name = client.Entity.Name;
                    Information.Mentor_Spouse_Name = client.Mentor.Client.Entity.Spouse;
                    client.ReviewMentor();
                    client.Send(Information);

                    ApprenticeInformation AppInfo = new ApprenticeInformation();
                    AppInfo.Apprentice_ID = client.Entity.UID;
                    AppInfo.Apprentice_Level = client.Entity.Level;
                    AppInfo.Apprentice_Class = client.Entity.Class;
                    AppInfo.Apprentice_PkPoints = client.Entity.PKPoints;
                    AppInfo.Apprentice_Experience = client.AsApprentice.Actual_Experience;
                    AppInfo.Apprentice_Composing = client.AsApprentice.Actual_Plus;
                    AppInfo.Apprentice_Blessing = client.AsApprentice.Actual_HeavenBlessing;
                    AppInfo.Apprentice_Name = client.Entity.Name;
                    AppInfo.Apprentice_Online = true;
                    AppInfo.Apprentice_Spouse_Name = client.Entity.Spouse;
                    AppInfo.Enrole_date = client.Mentor.EnroleDate;
                    AppInfo.Mentor_ID = client.Mentor.ID;
                    AppInfo.Mentor_Mesh = client.Mentor.Client.Entity.Mesh;
                    AppInfo.Mentor_Name = client.Mentor.Name;
                    AppInfo.Type = 2;
                    client.Mentor.Client.Send(AppInfo);
                }
                else
                {
                    MentorInformation Information = new MentorInformation(true);
                    Information.Mentor_Type = 1;
                    Information.Mentor_ID = client.Mentor.ID;
                    Information.Apprentice_ID = client.Entity.UID;
                    Information.Enrole_Date = client.Mentor.EnroleDate;
                    Information.Mentor_Online = false;
                    Information.String_Count = 2;
                    Information.Mentor_Name = client.Mentor.Name;
                    Information.Apprentice_Name = client.Entity.Name;

                    client.Send(Information);
                }
            }
            NobilityInfo update = new NobilityInfo(true);
            update.Type = NobilityInfo.Icon;
            update.dwParam = client.NobilityInformation.EntityUID;
            update.UpdateString(client.NobilityInformation);
            client.Send(update);
            client.Entity.Update(Update.Merchant, 255, false);

            foreach (Interfaces.IConquerItem item in client.Inventory.Objects)
                item.Send(client);

            foreach (Interfaces.IConquerItem item in client.Equipment.Objects)
                if (item != null)
                {
                    if (Database.ConquerItemInformation.BaseInformations.ContainsKey(item.ID))
                    {
                        item.Send(client);
                        //kimoSystem.Threading.Thread.Sleep(1);
                        // item.Send(client);

                    }
                    else
                    {
                        client.Equipment.DestroyArrow(item.Position);
                        Console.WriteLine("Announcement: Item have been removed because of invalid info. UID: " + item.UID + ". OWNER: " + client.Entity.Name);
                    }
                }
            client.LoadItemStats(client.Entity);
            client.CalculateStatBonus();
            client.CalculateHPBonus();
            if (!client.Equipment.Free(5))
            {
                if (IsArrow(client.Equipment.TryGetItem(5).ID))
                {
                    if (client.Equipment.Free(4))
                        client.Equipment.DestroyArrow(5);
                    else
                    {
                        client.Equipment.Remove(5);
                    }
                }
            }
            client.GemAlgorithm();
            client.CalculateStatBonus();
            client.CalculateHPBonus();
            client.Entity.Stamina = 100;

            client.Send(new Message(String.Format(
             "Welcome in " + PhoenixProject.Database.rates.servername + " - Legends Return Season III", client.Entity.Name,
             client.Entity.LastLogin.ToLongDateString().Replace('-', ' '),
             client.Entity.LastLogin.ToLongTimeString()), System.Drawing.Color.Red,
             Message.Service));
            client.Entity.UpdateEffects(true);

            // client.Send(new Message("Welcome in "+Database.rates.servername+"", System.Drawing.Color.Red, Message.Middle));

            if (client.Entity.VIPLevel > 0)
            {
                Network.GamePackets.VipStatus vip = new Network.GamePackets.VipStatus();
                client.Send(vip.ToArray());
            }
            client.Send(new MapStatus() { BaseID = (ushort)client.Map.BaseID, ID = (uint)client.Map.ID, Status = Database.MapsTable.MapInformations[client.Map.ID].Status, Weather = Database.MapsTable.MapInformations[client.Map.ID].Weather });

            if (client.Entity.Hitpoints == 0)
                client.Entity.Hitpoints = 1;
            client.Entity.VIPLevel = (byte)(client.Entity.VIPLevel + 0);
            client.Entity.HandleTiming = true;
            if (client.Entity.GuildSharedBp != 0)
                client.Entity.Update(Network.GamePackets.Update.GuildShareBP, client.Entity.GuildSharedBp, false);

            if (client.Entity.ExtraBattlePower != 0)
                client.Entity.Update(Network.GamePackets.Update.ExtraBattlePower, client.Entity.ExtraBattlePower, false);
            if (client.Guild != null)
                client.Guild.SendAllyAndEnemy(client);
            if (Game.ConquerStructures.Broadcast.CurrentBroadcast.EntityID > 2)
                client.Send(new Network.GamePackets.Message(Game.ConquerStructures.Broadcast.CurrentBroadcast.Message, "ALLUSERS", Game.ConquerStructures.Broadcast.CurrentBroadcast.EntityName, System.Drawing.Color.Red, Network.GamePackets.Message.BroadcastMessage));
            client.Entity.Update(Network.GamePackets.Update.LuckyTimeTimer, (byte)client.BlessTime, false);
            if (client.Entity.HeavenBlessing != 0)
                client.Entity.Update(Network.GamePackets.Update.OnlineTraining, client.OnlineTrainingPoints, false);
            if (client.ClaimableItem.Count > 0)
                foreach (var item in client.ClaimableItem.Values)
                    item.Send(client);
            if (client.DeatinedItem.Count > 0)
                foreach (var item in client.DeatinedItem.Values)
                    item.Send(client);
            if (client.ItemGive == true)
            {
                client.Inventory.Add(1001010, 0, 5);
                if (client.Entity.Class != 70)
                {
                    client.Inventory.AddandWear(132008, 0, 1, client);

                }
                else
                {
                    client.Inventory.AddandWear(132008, 0, 1, client);
                }
                if (client.Entity.Class == 10 || client.Entity.Class == 20)
                {
                    client.Inventory.AddandWear(410301, 0, 1, client);

                }
                if (client.Entity.Class >= 100)
                {
                    client.Inventory.AddandWear(421301, 0, 1, client);

                }
                if (client.Entity.Class == 70)
                {
                    client.Inventory.AddandWear(611301, 0, 1, client);

                }
                if (client.Entity.Class == 60)
                {
                    client.Inventory.AddandWear(610301, 0, 1, client);

                }
                if (client.Entity.Class == 50)
                {
                    client.Inventory.AddandWear(601301, 0, 1, client);

                }
                if (client.Entity.Class == 40)
                {
                    client.Inventory.AddandWear(500301, 0, 1, client);

                }
                client.ItemGive = false;
            }
            client.Entity.RacePoints = client.Entity.RacePoints;
            send1136(client);
            client.Equipment.UpdateEntityPacket();
        }
        static void HandleSellToNPC(ItemUsage itemUsage, Client.GameState client)
        {
            Interfaces.INpc npc = null;
            if (client.Map.Npcs.TryGetValue(itemUsage.UID, out npc))
            {
                if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, npc.X, npc.Y) > 17)
                    return;
                Interfaces.IConquerItem item = null;
                if (client.Inventory.TryGetItem(itemUsage.dwParam, out item))
                {
                    if (item.Lock != 0 || item.Suspicious)
                        return;
                    uint Price = new Database.ConquerItemInformation(item.ID, 0).BaseInformation.GoldWorth;
                    Price = Price / 3;
                    if (item.Durability > 0 && item.Durability < item.MaximDurability)
                        Price = (Price * item.Durability) / item.MaximDurability;

                    if (item.Durability > 0 && item.Durability <= item.MaximDurability)
                    {
                        client.Inventory.Remove(item, Game.Enums.ItemUse.Remove);
                        client.Entity.Money += Price;
                    }
                    else
                    {
                        client.Inventory.Remove(item, Game.Enums.ItemUse.Remove);
                    }
                }
            }
        }
        static void HandleRepair(ItemUsage itemUsage, Client.GameState client)
        {
            Interfaces.IConquerItem item = null;
            if (client.Inventory.TryGetItem(itemUsage.UID, out item))
            {
                if (item.Suspicious)
                    return;
                if (IsArrow(item.ID))
                    return;
                if (item.Durability > 0 && item.Durability < item.MaximDurability)
                {
                    uint Price = new Database.ConquerItemInformation(item.ID, 0).BaseInformation.GoldWorth;
                    byte Quality = (byte)(item.ID % 10);
                    double QualityMultipier = 0;

                    switch (Quality)
                    {
                        case 9: QualityMultipier = 1.125; break;
                        case 8: QualityMultipier = 0.975; break;
                        case 7: QualityMultipier = 0.9; break;
                        case 6: QualityMultipier = 0.825; break;
                        default: QualityMultipier = 0.75; break;
                    }

                    int nRepairCost = 0;
                    if (Price > 0)
                        nRepairCost = (int)Math.Ceiling((Price * (item.MaximDurability - item.Durability) / item.MaximDurability) * QualityMultipier);

                    nRepairCost = Math.Max(1, nRepairCost);
                    if (client.Entity.Money >= nRepairCost)
                    {
                        client.Entity.Money -= (uint)nRepairCost;
                        item.Durability = item.MaximDurability;
                        item.Mode = Game.Enums.ItemMode.Update;
                        item.Send(client);
                        Database.ConquerItemTable.UpdateDurabilityItem(item);
                    }
                }
                else if (item.Durability == 0)
                {
                    if (client.Inventory.Remove(1088001, 5))
                    {
                        item.Durability = item.MaximDurability;
                        item.Mode = Game.Enums.ItemMode.Update;
                        item.Send(client);
                        Database.ConquerItemTable.UpdateDurabilityItem(item);
                    }
                }
            }
        }
        static void DropMoney(ItemUsage itemUsage, Client.GameState client)
        {
            if (client.Entity.Money >= itemUsage.UID)
            {
                ushort X = client.Entity.X, Y = client.Entity.Y;
                if (client.Map.SelectCoordonates(ref X, ref Y))
                {
                    uint ItemID = MoneyItemID(itemUsage.UID);
                    FloorItem floorItem = new FloorItem(true);
                    floorItem.ValueType = FloorItem.FloorValueType.Money;
                    floorItem.Value = itemUsage.UID;
                    floorItem.ItemID = ItemID;
                    floorItem.MapID = client.Map.ID;
                    floorItem.MapObjType = Game.MapObjectType.Item;
                    floorItem.X = X;
                    floorItem.Y = Y;
                    floorItem.Type = FloorItem.Drop;
                    floorItem.OnFloor = Time32.Now;
                    floorItem.UID = FloorItem.FloorUID.Next;
                    while (client.Map.Npcs.ContainsKey(floorItem.UID))
                        floorItem.UID = FloorItem.FloorUID.Next;
                    client.SendScreenSpawn(floorItem, true);
                    client.Map.AddFloorItem(floorItem);
                    client.Entity.Money -= itemUsage.UID;

                }
            }
        }
        static void SocketTalismanWithItem(ItemUsage itemUsage, Client.GameState client)
        {
            Interfaces.IConquerItem talisman = client.Equipment.TryGetItem(itemUsage.UID);
            Interfaces.IConquerItem item = null;
            if (client.Inventory.TryGetItem(itemUsage.dwParam, out item))
            {
                if (talisman == null)
                    return;
                if (item.ID / 1000 == talisman.ID / 1000)
                    return;
                if (item.Bound == true)
                    return;
                if (talisman.SocketTwo != PhoenixProject.Game.Enums.Gem.NoSocket)
                    return;

                ushort Points = 0;
                switch (item.ID % 10)
                {
                    case 6: Points += 5; break;
                    case 7: Points += 10; break;
                    case 8: Points += 40; break;
                    case 9: Points += 1000; break;
                }
                Points += Database.DataHolder.TalismanPlusPoints(item.Plus);

                int position = ItemPosition(item.ID);
                switch (position)
                {
                    case 0: return;
                    case 4:
                    case 5:
                        if (item.ID % 10 >= 8)
                        {
                            if (item.SocketOne != PhoenixProject.Game.Enums.Gem.NoSocket)
                                Points += 160;
                            if (item.SocketTwo != PhoenixProject.Game.Enums.Gem.NoSocket)
                                Points += 800;
                        }
                        break;
                    default:
                        if (item.ID % 10 >= 8)
                        {
                            if (item.SocketOne != PhoenixProject.Game.Enums.Gem.NoSocket)
                                Points += 2000;
                            if (item.SocketTwo != PhoenixProject.Game.Enums.Gem.NoSocket)
                                Points += 6000;
                        }
                        break;
                }
                talisman.SocketProgress += Points;
                if (talisman.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
                {
                    if (talisman.SocketProgress >= 8000)
                    {
                        talisman.SocketProgress -= 8000;
                        talisman.SocketOne = PhoenixProject.Game.Enums.Gem.EmptySocket;

                        talisman.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                        talisman.Send(client);
                    }
                }
                if (talisman.SocketOne != PhoenixProject.Game.Enums.Gem.NoSocket)
                {
                    if (talisman.SocketProgress >= 20000)
                    {
                        talisman.SocketProgress = 0;
                        talisman.SocketTwo = PhoenixProject.Game.Enums.Gem.EmptySocket;
                    }
                }
                Database.ConquerItemTable.UpdateSocketProgress(talisman);
                Database.ConquerItemTable.UpdateSockets(talisman);
                talisman.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                talisman.Send(client);
                client.Inventory.Remove(item, PhoenixProject.Game.Enums.ItemUse.Remove);
            }
        }
 static void EnchantItem(ItemUsage itemUsage, Client.GameState client)
 {
     Interfaces.IConquerItem Item = null, EnchantGem = null;
     if (client.Inventory.TryGetItem(itemUsage.UID, out Item) && client.Inventory.TryGetItem(itemUsage.dwParam, out EnchantGem))
     {
         byte gemBase = (byte)(EnchantGem.ID % 1000);
         UInt32 iType = Item.ID / 1000;
         Positions pos = GetPositionFromID(Item.ID);
         if (pos == Positions.Garment)
         {
             client.Account.State = Database.AccountTable.AccountState.Cheat;
             client.Account.Savekimo();
             client.Disconnect();
             return;
         }
         if (pos == Positions.RightAccessory)
         {
             client.Account.State = Database.AccountTable.AccountState.Cheat;
             client.Account.Savekimo();
             client.Disconnect();
             return;
         }
         if (pos == Positions.LeftAccessory)
         {
             client.Account.State = Database.AccountTable.AccountState.Cheat;
             client.Account.Savekimo();
             client.Disconnect();
             return;
         }
         if (pos == Positions.Bottle)
         {
             client.Account.State = Database.AccountTable.AccountState.Cheat;
             client.Account.Savekimo();
             client.Disconnect();
             return;
         }
         if (pos == Positions.Steed)
         {
             client.Account.State = Database.AccountTable.AccountState.Cheat;
             client.Account.Savekimo();
             client.Disconnect();
             return;
         }
         if (pos == Positions.SteedArmor)
         {
             client.Account.State = Database.AccountTable.AccountState.Cheat;
             client.Account.Savekimo();
             client.Disconnect();
             return;
         }
         if (pos == Positions.SteedTalisman)
         {
             client.Account.State = Database.AccountTable.AccountState.Cheat;
             client.Account.Savekimo();
             client.Disconnect();
             return;
         }
         if (pos == Positions.AttackTalisman)
         {
             client.Account.State = Database.AccountTable.AccountState.Cheat;
             client.Account.Savekimo();
             client.Disconnect();
             return;
         }
         if (pos == Positions.DefenceTalisman)
         {
             client.Account.State = Database.AccountTable.AccountState.Cheat;
             client.Account.Savekimo();
             client.Disconnect();
             return;
         }
         if (Enum.IsDefined(typeof(Game.Enums.Gem), gemBase))
         {
             byte Enchant = 0;
             switch (EnchantGem.ID % 10)
             {
                 case 1:
                     {
                         Enchant = (byte)ServerBase.Kernel.Random.Next(1, 59);
                         break;
                     }
                 case 2:
                     {
                         if (EnchantGem.ID == 700012)
                             Enchant = (byte)ServerBase.Kernel.Random.Next(100, 159);
                         else if (EnchantGem.ID == 700002 || EnchantGem.ID == 700052 || EnchantGem.ID == 700062)
                             Enchant = (byte)ServerBase.Kernel.Random.Next(60, 109);
                         else if (EnchantGem.ID == 700032)
                             Enchant = (byte)ServerBase.Kernel.Random.Next(80, 129);
                         else
                             Enchant = (byte)ServerBase.Kernel.Random.Next(40, 89);
                         break;
                     }
                 default:
                     {
                         if (EnchantGem.ID == 700013)
                             Enchant = (byte)ServerBase.Kernel.Random.Next(200, 255);
                         else if (EnchantGem.ID == 700003 || EnchantGem.ID == 700073 || EnchantGem.ID == 700033)
                             Enchant = (byte)ServerBase.Kernel.Random.Next(170, 229);
                         else if (EnchantGem.ID == 700063 || EnchantGem.ID == 700053)
                             Enchant = (byte)ServerBase.Kernel.Random.Next(140, 199);
                         else if (EnchantGem.ID == 700023)
                             Enchant = (byte)ServerBase.Kernel.Random.Next(90, 149);
                         else
                             Enchant = (byte)ServerBase.Kernel.Random.Next(70, 119);
                         break;
                     }
             }
             client.Send(ServerBase.Constants.Enchant(Item.Enchant, Enchant));
             if (Enchant > Item.Enchant)
             {
                 Item.Enchant = Enchant;
                 Item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                 Item.Send(client);
                 itemUsage.dwParam = 1;
                 Database.ConquerItemTable.UpdateEnchant(Item, client);
                 client.Inventory.Remove(EnchantGem, PhoenixProject.Game.Enums.ItemUse.Remove);
             }
             else
             {
                 itemUsage.dwParam = 1;
                 client.Inventory.Remove(EnchantGem, PhoenixProject.Game.Enums.ItemUse.Remove);
             }
         }
     }
 }
 static void UpgradeItem(ItemUsage itemUsage, Client.GameState client)
 {
     Interfaces.IConquerItem item = null;
     if (client.Inventory.TryGetItem(itemUsage.UID, out item))
     {
         if (IsArrow(item.ID))
             return;
         Interfaces.IConquerItem upgrade = null;
         if (client.Inventory.TryGetItem(itemUsage.dwParam, out upgrade))
         {
             Database.ConquerItemInformation infos = new PhoenixProject.Database.ConquerItemInformation(item.ID, item.Plus);
             switch (upgrade.ID)
             {
                 case 1088000:
                     {
                         if (item.ID % 10 == (byte)Game.Enums.ItemQuality.Super)
                             break;
                         byte chance = (byte)(70 - ((infos.BaseInformation.Level - (infos.BaseInformation.Level > 100 ? 30 : 0)) / (10 - item.ID % 10)));
                         if (item.Durability < item.MaximDurability)
                             break;
                         if (ServerBase.Kernel.Rate(chance))
                         {
                             switch ((Game.Enums.ItemQuality)(item.ID % 10))
                             {
                                 case Game.Enums.ItemQuality.Normal:
                                 case Game.Enums.ItemQuality.NormalV1:
                                 case Game.Enums.ItemQuality.NormalV2:
                                 case Game.Enums.ItemQuality.NormalV3: item.ID = (item.ID - (item.ID % 10)) + (byte)Game.Enums.ItemQuality.Refined; break;
                                 default: item.ID++; break;
                             }
                             Database.ConquerItemTable.UpdateItemID(item, client);
                             item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                             item.Send(client);
                         }
                         else
                         {
                             item.Durability = (ushort)(item.Durability / 2);
                             Database.ConquerItemTable.UpdateDurabilityItem(item);
                             item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                             item.Send(client);
                         }
                         item = ItemSocket(item, 1);
                         client.Inventory.Remove(upgrade, PhoenixProject.Game.Enums.ItemUse.Remove);
                         break;
                     }
                 case 1088001:
                     {
                         if (infos.BaseInformation.Level == ItemMaxLevel(ItemPosition(infos.BaseInformation.ID)))
                             break;
                         byte chance = 70;
                         chance -= (byte)(infos.BaseInformation.Level / 10 * 3);
                         chance -= (byte)(((item.ID % 10) + 1) * 3);
                         if (item.Durability < item.MaximDurability)
                             break;
                         uint newid = infos.CalculateUplevel();
                         if (newid != 0 && newid != item.ID)
                         {
                             if (ServerBase.Kernel.Rate(chance))
                             {
                                 item.ID = newid;
                                 infos = new PhoenixProject.Database.ConquerItemInformation(item.ID, item.Plus);
                                 item.Durability = item.MaximDurability = infos.BaseInformation.Durability;
                                 Database.ConquerItemTable.UpdateItemID(item, client);
                                 Database.ConquerItemTable.UpdateDurabilityItem(item);
                                 item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                 item.Send(client);
                             }
                             else
                             {
                                 item.Durability = (ushort)(item.Durability / 2);
                                 Database.ConquerItemTable.UpdateDurabilityItem(item);
                                 item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                 item.Send(client);
                             }
                             //item = ItemSocket(item, 2);
                             client.Inventory.Remove(upgrade, PhoenixProject.Game.Enums.ItemUse.Remove);
                         }
                         break;
                     }
                 case 1088002:
                     {
                         ushort postion = ItemPosition(infos.BaseInformation.ID);
                         byte level = ItemMinLevel(postion);
                         if (postion == 6)
                         {
                             if (infos.BaseInformation.ID.ToString()[2] == '1')
                                 level = 13;
                         }
                         if (infos.BaseInformation.Level <= level)
                         {
                             client.Send(new Message("This item's level is too low. It can't be downgraded more.", System.Drawing.Color.MistyRose, Message.TopLeft));
                             break;
                         }
                         byte chance = 100;
                         if (item.Durability < item.MaximDurability)
                             break;
                         uint newid = infos.CalculateDownlevel();
                         if (newid != 0 && newid != item.ID)
                         {
                             if (ServerBase.Kernel.Rate(chance))
                             {
                                 item.ID = newid;
                                 infos = new PhoenixProject.Database.ConquerItemInformation(item.ID, item.Plus);
                                 item.Durability = item.MaximDurability = infos.BaseInformation.Durability;
                                 Database.ConquerItemTable.UpdateItemID(item, client);
                                 Database.ConquerItemTable.UpdateDurabilityItem(item);
                                 item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                 item.Send(client);
                             }
                             else
                             {
                                 item.Durability = (ushort)(item.Durability / 2);
                                 Database.ConquerItemTable.UpdateDurabilityItem(item);
                                 item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                 item.Send(client);
                             }
                             //item = ItemSocket(item, 2);
                             client.Inventory.Remove(upgrade, PhoenixProject.Game.Enums.ItemUse.Remove);
                         }
                         break;
                     }
             }
         }
     }
 }
        static unsafe void HandlePacket(byte[] packet, Client.GameState client)
        {
            try
            {

                if (packet == null)
                    return;
                if (client == null)
                    return;
                fixed (byte* ptr = packet)
                {
                    var type = *((ushort*)(ptr + 2));
                    ushort Length = BitConverter.ToUInt16(packet, 0);
                    ushort ID = BitConverter.ToUInt16(packet, 2);

                    ushort ID2 = BitConverter.ToUInt16(packet, 4);
                    switch (ID)
                    {
                        #region Packet Spook Mob
                        case 2400:
                            {
                                client.Send(new NpcReply(NpcReply.MessageBox, "The Thrilling Spooks are sealed up, inside here Better speak to the Heavenly Master ,if you want more detalis"));
                                #region
                                client.OnMessageBoxOK =
                                delegate
                                {
                                    client.Entity.Teleport(8892, 28, 26);
                                };
                                client.OnMessageBoxCANCEL =
                                    delegate
                                    {
                                        client.OnMessageBoxEventParams = new object[0];
                                    };
                                #endregion

                                break;
                            }
                        #endregion
                        #region Arsenal [2201][2202][2203]
                        case 2202:
                            {
                                if (packet[16] == 0) packet[16] = 8;
                                client.Send(ArsenalPacket.ArsenalInscribedPage(client, packet, (PhoenixProject.Game.Features.Arsenal_ID)packet[16]));
                                break;
                            }
                        case 2203:
                            {
                                client.Send(ArsenalPacket.GuildArsenal(client));
                                if (client.Guild != null)
                                    if (client.Guild.Arsenal != null)
                                        client.Guild.Arsenal.Update(client.Guild);
                                byte pType = packet[4];
                                byte i_type = packet[8];
                                uint i_Uid = BitConverter.ToUInt32(packet, 12);

                                if (i_type == 0) i_type = 8;
                                switch (pType)
                                {
                                    case 0:
                                        {
                                            if (client.Guild != null)
                                                client.Guild.Arsenal.UnlockArsenal(client, (PhoenixProject.Game.Features.Arsenal_ID)i_type);
                                            break;
                                        }
                                    case 1:
                                        {
                                            PhoenixProject.Interfaces.IConquerItem Item = null;
                                            if (client.Inventory.TryGetItem(i_Uid, out Item))
                                            {
                                                if (client != null)
                                                {
                                                    if (Item != null)
                                                    {
                                                        if (i_type != 0 && i_type <= 8)
                                                        {
                                                            if (client.Guild != null)
                                                            {
                                                                if (client.Guild.Arsenal != null)
                                                                {
                                                                    client.Guild.Arsenal.InscribeItem(client, Item, (PhoenixProject.Game.Features.Arsenal_ID)i_type);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    case 2://Uninscribe
                                        {
                                            PhoenixProject.Game.Features.Arsenal_Client ac = null;
                                            if (client.Guild.Arsenal.Arsenals[(PhoenixProject.Game.Features.Arsenal_ID)i_type].Inscribed.TryGetValue(i_Uid, out ac))
                                                client.Guild.Arsenal.RemoveItem(client, ac.Item, (PhoenixProject.Game.Features.Arsenal_ID)i_type);
                                            break;
                                        }
                                    case 4:
                                        {
                                            client.Send(ArsenalPacket.GuildArsenal(client));
                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion
                        #region EnitityCreate (1001)
                        case 1001:
                            {
                                if (client.Action == 1)
                                {
                                    EnitityCreate EC = new EnitityCreate();
                                    EC.Deserialize(packet);
                                    string Message = "";
                                    Boolean Created = Database.EntityTable.CreateEntity(EC, client, ref Message);
                                    client.Send(new Message(Message, "ALLUSERS", System.Drawing.Color.Orange, GamePackets.Message.PopUP));
                                    if (Created)
                                        Console.WriteLine(client.Account.Username + " Sucesfully Created a new Character " + EC.Name);
                                    client.JustCreated = true;
                                }
                                break;
                            }
                        #endregion
                        #region Chat/Message (1004)
                        case 1004:
                            {
                                if (client.Action != 2)
                                    return;
                                Message message = new Message();
                                message.Deserialize(packet);
                                if (message.__Message.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries).Length > 0)
                                    message.__Message = message.__Message.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries)[0];
                                Chat(message, client);
                                break;
                            }
                        #endregion
                        #region Item/Ping (1009)
                        case 1009:
                            {
                                if (client.Action != 2)
                                    return;
                                ItemUsage usage = new ItemUsage(false);
                                usage.Deserialize(packet);
                                if (!client.Entity.Dead || usage.ID == ItemUsage.Ping)
                                {
                                    switch (usage.ID)
                                    {
                                        case 53:
                                            {
                                                uint ItemAdd = BitConverter.ToUInt32(packet, 8);

                                                Interfaces.IConquerItem item_new = null;
                                                if (client.Inventory.TryGetItem(ItemAdd, out item_new))
                                                {
                                                    uint obtined_points = 0;
                                                    Database.ConquerItemInformation iteminfo = new PhoenixProject.Database.ConquerItemInformation(ItemAdd, 0);
                                                    Dictionary<uint, uint> amount = new Dictionary<uint, uint>();//packet[20]);
                                                    for (ushort i = 84; i < 84 + 4 * packet[20]; i += 4)
                                                    {
                                                        uint item_swap = BitConverter.ToUInt32(packet, i);
                                                        if (client.Inventory.ContainsUID(item_swap))
                                                        {
                                                            Interfaces.IConquerItem item = null;
                                                            if (client.Inventory.TryGetItem(item_swap, out item))
                                                            {
                                                                amount.Add(item_swap, i);
                                                            }
                                                            switch (item.ID)
                                                            {
                                                                case 191505:
                                                                case 191605:
                                                                case 191705:
                                                                case 191805:
                                                                case 191905:
                                                                case 191405:
                                                                case 183325:
                                                                case 183315:
                                                                case 183375:
                                                                case 183305:
                                                                    {
                                                                        obtined_points += 300;
                                                                        break;
                                                                    }
                                                                default:
                                                                    obtined_points += 50;
                                                                    break;
                                                            }
                                                        }
                                                    }
                                                    if (iteminfo.BaseInformation.ConquerPointsWorth > obtined_points)
                                                    {
                                                        uint add_cps = 0;
                                                        add_cps = (uint)(iteminfo.BaseInformation.ConquerPointsWorth - obtined_points);
                                                        if (add_cps < client.Entity.ConquerPoints)
                                                        {
                                                            client.Entity.ConquerPoints -= (uint)add_cps;
                                                            foreach (uint key in amount.Keys)
                                                            {
                                                                if (client.Inventory.ContainsUID(key))
                                                                    client.Inventory.Remove(key, PhoenixProject.Game.Enums.ItemUse.Remove, true);
                                                            }
                                                            client.Inventory.Add(ItemAdd, 0, 1);

                                                        }
                                                    }
                                                    else
                                                    {
                                                        foreach (uint key in amount.Keys)
                                                        {
                                                            if (client.Inventory.ContainsUID(key))
                                                                client.Inventory.Remove(key, PhoenixProject.Game.Enums.ItemUse.Remove, true);
                                                        }
                                                        client.Inventory.Add(ItemAdd, 0, 1);

                                                    }
                                                }
                                                break;
                                            }
                                        case 52:
                                            {
                                                var item = Database.ConquerItemTable.LoadItem(usage.UID);
                                                item.Mode = PhoenixProject.Game.Enums.ItemMode.ChatItem;
                                                item.Send(client);
                                                break;
                                            }
                                        case 41:
                                            {
                                                // var item = Database.ConquerItemTable.LoadItem(usage.UID);
                                                usage.dwParam = 1;
                                                client.Send(usage);
                                                break;
                                            }
                                        case ItemUsage.SwitchEquipsBack:
                                        case ItemUsage.SwitchEquips:
                                            {
                                                client.AlternateEquipment = usage.ID == ItemUsage.SwitchEquips;
                                                if (usage.ID == 45)
                                                {
                                                    ClientEquip equips = new ClientEquip(client);
                                                    client.Send(equips);
                                                    client.Equipment.UpdateEntityPacket2();

                                                    client.LoadItemStats2(client.Entity);
                                                    client.CalculateStatBonus();
                                                    client.CalculateHPBonus();
                                                    client.Send(WindowStats(client));
                                                }
                                                else
                                                {
                                                    ClientEquip equips = new ClientEquip();
                                                    equips.DoEquips(client);
                                                    client.Send(equips);
                                                    client.Equipment.UpdateEntityPacket();

                                                    client.LoadItemStats(client.Entity);
                                                    client.CalculateStatBonus();
                                                    client.CalculateHPBonus();
                                                    client.Send(WindowStats(client));
                                                }
                                                usage.dwParam = 1;
                                                client.Send(usage);
                                                break;
                                            }
                                        case ItemUsage.ArrowReload:
                                            {
                                                ReloadArrows(client.Equipment.TryGetItem(ConquerItem.LeftWeapon), client);
                                                break;
                                            }
                                        case ItemUsage.ShowBoothItems:
                                            {
                                                ShowBoothItems(usage, client);
                                                break;
                                            }
                                        case ItemUsage.AddItemOnBoothForSilvers:
                                        case ItemUsage.AddItemOnBoothForConquerPoints:
                                            {
                                                AddItemOnBooth(usage, client);
                                                break;
                                            }
                                        case ItemUsage.BuyFromBooth:
                                            {
                                                BuyFromBooth(usage, client);
                                                break;
                                            }
                                        case ItemUsage.RemoveItemFromBooth:
                                            {
                                                RemoveItemFromBooth(usage, client);
                                                break;
                                            }
                                        case ItemUsage.EquipItem:
                                            {

                                                EquipItem(usage, client);

                                                break;
                                            }
                                        case ItemUsage.UnequipItem:
                                            {

                                                UnequipItem(usage, client);

                                                break;
                                            }
                                        case ItemUsage.BuyFromNPC:
                                            {
                                                HandleBuyFromNPC(usage, client);
                                                break;
                                            }
                                        case ItemUsage.SellToNPC:
                                            {
                                                HandleSellToNPC(usage, client);
                                                break;
                                            }
                                        case ItemUsage.Repair:
                                            {
                                                HandleRepair(usage, client);
                                                break;
                                            }
                                        case ItemUsage.MeteorUpgrade:
                                        case ItemUsage.DragonBallUpgrade:
                                            {
                                                UpgradeItem(usage, client);
                                                break;
                                            }
                                        case ItemUsage.Ping:
                                            {
                                                if (Time32.Now < client.LastPing.AddSeconds(2))
                                                {
                                                    client.PingCount++;
                                                    if (client.PingCount == 40)
                                                    {
                                                        client.Send(new Message("Speed hack detected!", System.Drawing.Color.BlanchedAlmond, Message.TopLeft));
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                }

                                                client.LastPingT = client.LastPing;
                                                client.LastPing = Time32.Now;

                                                if (client.LastPing > client.LastPingT.AddSeconds(2))
                                                    client.PingCount = 0;
                                                usage.TimeStamp += 200;
                                                client.Send(ReturnFinal(packet));
                                                client.Send(usage);

                                                break;
                                            }
                                        case ItemUsage.ViewWarehouse:
                                            {
                                                usage.dwParam = client.MoneySave;
                                                client.Send(usage);
                                                break;
                                            }
                                        case ItemUsage.WarehouseDeposit:
                                            {
                                                if (client.Entity.Money >= usage.dwParam)
                                                {
                                                    client.Entity.Money -= usage.dwParam;
                                                    client.MoneySave += usage.dwParam;
                                                }
                                                break;
                                            }
                                        case ItemUsage.WarehouseWithdraw:
                                            {
                                                if (client.MoneySave >= usage.dwParam)
                                                {
                                                    client.Entity.Money += usage.dwParam;
                                                    client.MoneySave -= usage.dwParam;
                                                }
                                                break;
                                            }
                                        case ItemUsage.DropItem:
                                            {
                                                DropItem(usage, client);
                                                break;
                                            }
                                        case ItemUsage.DropMoney:
                                            {
                                                DropMoney(usage, client);
                                                break;
                                            }
                                        case ItemUsage.Enchant:
                                            {
                                                EnchantItem(usage, client);
                                                break;
                                            }
                                        case ItemUsage.SocketTalismanWithItem:
                                            {
                                                SocketTalismanWithItem(usage, client);
                                                break;
                                            }
                                        case ItemUsage.SocketTalismanWithCPs:
                                            {
                                                SocketTalismanWithCPs(usage, client);
                                                break;
                                            }
                                        case ItemUsage.RedeemGear:
                                            {
                                                var item = client.DeatinedItem[usage.UID];
                                                if (item != null)
                                                {
                                                    if (DateTime.Now > item.Date.AddDays(7))
                                                    {
                                                        client.Send(new Message("This item is expired!", System.Drawing.Color.Red, Message.TopLeft));

                                                        return;
                                                    }
                                                    if (client.Entity.ConquerPoints >= item.ConquerPointsCost)
                                                    {
                                                        client.Entity.ConquerPoints -= item.ConquerPointsCost;
                                                        Database.EntityTable.UpdateCps(client);

                                                        usage.dwParam = client.Entity.UID;
                                                        usage.dwExtraInfo3 = item.ConquerPointsCost;
                                                        client.Send(usage);

                                                        client.Inventory.Add(item.Item, PhoenixProject.Game.Enums.ItemUse.Add);

                                                        Database.ClaimItemTable.Redeem(usage.UID, client);
                                                        Database.DetainedItemTable.Claim(usage.UID, client);
                                                        client.DeatinedItem.Remove(item.UID);

                                                        if (ServerBase.Kernel.GamePool.ContainsKey(item.GainerUID))
                                                        {
                                                            GameState pClient;
                                                            if (ServerBase.Kernel.GamePool.TryGetValue(item.GainerUID, out pClient))
                                                            {
                                                                if (pClient.Entity != null)
                                                                {
                                                                    pClient.ClaimableItem[item.UID].OwnerUID = 500;
                                                                    pClient.ClaimableItem[item.UID].MakeItReadyToClaim();
                                                                    usage.dwParam = pClient.Entity.UID;
                                                                    usage.ID = ItemUsage.ClaimGear;
                                                                    pClient.Send(usage);
                                                                    pClient.ClaimableItem[item.UID].Send(pClient);
                                                                }
                                                            }
                                                        }

                                                        Message message = new Message(" " + client.Entity.Name + " has redeemed his Gear and Pay " + item.ConquerPointsCost + " CPS . Congratulations!", System.Drawing.Color.Wheat, Message.Talk);
                                                        ServerBase.Kernel.SendWorldMessage(message, ServerBase.Kernel.GamePool.Values);
                                                    }
                                                }
                                                else
                                                {
                                                    client.Send(new Message("The item you want to redeem has already been redeemed.", System.Drawing.Color.Red, Message.TopLeft));
                                                }
                                                break;
                                            }
                                        case ItemUsage.ClaimGear:
                                            {
                                                // Console.WriteLine(" usage " + usage.UID + "");
                                                var item = client.ClaimableItem[usage.UID];
                                                // Console.WriteLine(" usage i  " + item.UID + "");
                                                if (item != null)
                                                {
                                                    if (item.Bound)
                                                    {
                                                        client.Send(new Message("Unnclaimable item!", System.Drawing.Color.Red, Message.TopLeft));
                                                        return;
                                                    }
                                                    if (DateTime.Now < item.Date.AddDays(7) && item.OwnerUID != 500)
                                                    {
                                                        client.Send(new Message("This item is not expired. You cannot claim it yet!", System.Drawing.Color.Red, Message.TopLeft));
                                                        return;
                                                    }
                                                    if (item.OwnerUID == 500)
                                                        client.Entity.ConquerPoints += item.ConquerPointsCost;
                                                    else
                                                    {
                                                        client.Inventory.Add(item.Item, PhoenixProject.Game.Enums.ItemUse.Move);
                                                        Message message = new Message("Thank you for arresting " + item.OwnerName + " , " + item.GainerName + ". The arrested one has redeemed his items and you have received a great deal of ConquerPoints as reward. Congratulations!", System.Drawing.Color.Wheat, Message.Talk);
                                                        ServerBase.Kernel.SendWorldMessage(message, ServerBase.Kernel.GamePool.Values);
                                                    }
                                                    Database.ClaimItemTable.Claim(usage.UID, client);
                                                    client.ClaimableItem.Remove(item.UID);

                                                    usage.dwParam = client.Entity.UID;
                                                    usage.dwExtraInfo3 = item.ConquerPointsCost;
                                                    //Database.EntityTable.UpdateCps(client);
                                                    client.Send(usage);
                                                    Message message2 = new Message("Thank you for arresting red/black name players " + client.Entity.Name + " has recived " + item.ConquerPointsCost + " CPS . Congratulations!", System.Drawing.Color.Wheat, Message.Talk);
                                                    ServerBase.Kernel.SendWorldMessage(message2, ServerBase.Kernel.GamePool.Values);
                                                }
                                                else
                                                {
                                                    client.Send(new Message("The item you want to claim has already been claimed.", System.Drawing.Color.Red, Message.TopLeft));
                                                }
                                                break;
                                            }
                                        case 43:
                                            {
                                                uint UID = BitConverter.ToUInt32(packet, 4);
                                                if (packet[20] == 1)
                                                {
                                                    if (client.Inventory.ContainsUID(BitConverter.ToUInt32(packet, 84)))//76
                                                    {
                                                        Interfaces.IConquerItem item = null;
                                                        if (client.Inventory.TryGetItem(UID, out item))
                                                        {
                                                            UInt32 iType = item.ID / 1000;
                                                            Positions pos = GetPositionFromID(item.ID);
                                                            if (pos == Positions.Garment)
                                                            {
                                                                client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                                client.Account.Savekimo();
                                                                client.Disconnect();
                                                                return;
                                                            }
                                                            if (pos == Positions.RightAccessory)
                                                            {
                                                                client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                                client.Account.Savekimo();
                                                                client.Disconnect();
                                                                return;
                                                            }
                                                            if (pos == Positions.LeftAccessory)
                                                            {
                                                                client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                                client.Account.Savekimo();
                                                                client.Disconnect();
                                                                return;
                                                            }
                                                            if (pos == Positions.Bottle)
                                                            {
                                                                client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                                client.Account.Savekimo();
                                                                client.Disconnect();
                                                                return;
                                                            }
                                                            if (pos == Positions.Steed)
                                                            {
                                                                client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                                client.Account.Savekimo();
                                                                client.Disconnect();
                                                                return;
                                                            }
                                                            if (pos == Positions.SteedArmor)
                                                            {
                                                                client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                                client.Account.Savekimo();
                                                                client.Disconnect();
                                                                return;
                                                            }
                                                            if (pos == Positions.SteedTalisman)
                                                            {
                                                                client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                                client.Account.Savekimo();
                                                                client.Disconnect();
                                                                return;
                                                            }
                                                            if (pos == Positions.AttackTalisman)
                                                            {
                                                                client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                                client.Account.Savekimo();
                                                                client.Disconnect();
                                                                return;
                                                            }
                                                            if (pos == Positions.DefenceTalisman)
                                                            {
                                                                client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                                client.Account.Savekimo();
                                                                client.Disconnect();
                                                                return;
                                                            }
                                                            if (item.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                            {
                                                                if (item.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                                {
                                                                    if (item.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                                        item.SocketOne = PhoenixProject.Game.Enums.Gem.EmptySocket;
                                                                    client.Inventory.Remove(BitConverter.ToUInt32(packet, 84), PhoenixProject.Game.Enums.ItemUse.Remove, true);
                                                                    item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                                                    item.Send(client);
                                                                    usage.dwParam = 1;
                                                                    client.LoadItemStats(client.Entity);
                                                                    client.CalculateStatBonus();
                                                                    client.CalculateHPBonus();
                                                                    Database.ConquerItemTable.UpdateSockets(item);
                                                                }
                                                            }
                                                            else if (item.SocketTwo == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                            {
                                                                uint rand = (uint)PhoenixProject.ServerBase.Kernel.Random.Next(1, 700);
                                                                if (rand > 320)
                                                                // if (PhoenixProject.ServerBase.Kernel.PercentSuccess(30))
                                                                {
                                                                    if (item.SocketTwo == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                                        item.SocketTwo = PhoenixProject.Game.Enums.Gem.EmptySocket;
                                                                    client.Inventory.Remove(BitConverter.ToUInt32(packet, 84), PhoenixProject.Game.Enums.ItemUse.Remove, true);
                                                                    item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                                                    item.Send(client);
                                                                    usage.dwParam = 1;
                                                                    client.LoadItemStats(client.Entity);
                                                                    client.CalculateStatBonus();
                                                                    client.CalculateHPBonus();
                                                                    Database.ConquerItemTable.UpdateSockets(item);
                                                                }
                                                                else
                                                                {
                                                                    usage.dwParam = 0;
                                                                    client.Inventory.Add(1200006, 0, 1);
                                                                    client.Inventory.Remove(BitConverter.ToUInt32(packet, 84), PhoenixProject.Game.Enums.ItemUse.Remove, true);
                                                                }
                                                            }
                                                            /*&  }
                                                              else
                                                              {
                                                                  if (item.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                                      item.SocketOne = PhoenixProject.Game.Enums.Gem.EmptySocket;
                                                                  client.Inventory.Remove(BitConverter.ToUInt32(packet, 80), PhoenixProject.Game.Enums.ItemUse.Remove, true);
                                                                  item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                                                  item.Send(client);
                                                                  client.LoadItemStats(item);
                                                                  Database.ConquerItemTable.UpdateItem(item, client);
                                                              }*/
                                                        }
                                                    }
                                                }
                                                if (packet[20] == 5)
                                                {
                                                    Interfaces.IConquerItem item = null;
                                                    if (client.Inventory.TryGetItem(UID, out item))
                                                    {
                                                        Dictionary<uint, uint> dbs = new Dictionary<uint, uint>();//packet[20]);
                                                        for (ushort i = 84; i < 84 + 4 * packet[20]; i += 4)
                                                        {
                                                            if (client.Inventory.ContainsUID(BitConverter.ToUInt32(packet, i)))
                                                            {
                                                                dbs.Add(BitConverter.ToUInt32(packet, i), i);
                                                            }
                                                        }

                                                        if (client.Inventory.Contains(1088000, 5))
                                                        {
                                                            if (item.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                                return;
                                                            if (item.SocketTwo == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                                item.SocketTwo = PhoenixProject.Game.Enums.Gem.EmptySocket;
                                                            foreach (uint key in dbs.Keys)
                                                            {
                                                                if (client.Inventory.ContainsUID(key))
                                                                    client.Inventory.Remove(key, PhoenixProject.Game.Enums.ItemUse.Remove, true);
                                                            }
                                                            usage.dwParam = 1;
                                                            item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                                            item.Send(client);
                                                            client.LoadItemStats(client.Entity);
                                                            client.CalculateStatBonus();
                                                            client.CalculateHPBonus();
                                                            Database.ConquerItemTable.UpdateSockets(item);
                                                        }
                                                    }
                                                }
                                                if (packet[20] == 7)
                                                {
                                                    Interfaces.IConquerItem item = null;
                                                    if (client.Inventory.TryGetItem(UID, out item))
                                                    {
                                                        if (item.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                            return;

                                                        Dictionary<uint, uint> drill = new Dictionary<uint, uint>();//packet[20]);
                                                        for (ushort i = 84; i < 84 + 4 * packet[20]; i += 4)
                                                        {
                                                            if (client.Inventory.ContainsUID(BitConverter.ToUInt32(packet, i)))
                                                            {
                                                                drill.Add(BitConverter.ToUInt32(packet, i), i);
                                                            }
                                                        }

                                                        if (client.Inventory.Contains(1200006, 7))
                                                        {

                                                            if (item.SocketTwo == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                                item.SocketTwo = PhoenixProject.Game.Enums.Gem.EmptySocket;
                                                            foreach (uint key in drill.Keys)
                                                            {
                                                                if (client.Inventory.ContainsUID(key))
                                                                    client.Inventory.Remove(key, PhoenixProject.Game.Enums.ItemUse.Remove, true);
                                                            }
                                                            usage.dwParam = 1;
                                                            item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                                            item.Send(client);
                                                            client.LoadItemStats(client.Entity);
                                                            client.CalculateStatBonus();
                                                            client.CalculateHPBonus();
                                                            Database.ConquerItemTable.UpdateSockets(item);
                                                        }
                                                    }
                                                }
                                                if (packet[20] == 12)
                                                {
                                                    Interfaces.IConquerItem item = null;
                                                    if (client.Inventory.TryGetItem(UID, out item))
                                                    {
                                                        Dictionary<uint, uint> dbs = new Dictionary<uint, uint>();//packet[20]);
                                                        for (ushort i = 84; i < 84 + 4 * packet[20]; i += 4)
                                                        {
                                                            if (client.Inventory.ContainsUID(BitConverter.ToUInt32(packet, i)))
                                                            {
                                                                dbs.Add(BitConverter.ToUInt32(packet, i), i);
                                                            }
                                                        }

                                                        if (client.Inventory.Contains(1088000, 12))
                                                        {
                                                            if (item.SocketOne != PhoenixProject.Game.Enums.Gem.NoSocket)
                                                                return;
                                                            if (item.SocketOne == PhoenixProject.Game.Enums.Gem.NoSocket)
                                                                item.SocketOne = PhoenixProject.Game.Enums.Gem.EmptySocket;
                                                            foreach (uint key in dbs.Keys)
                                                            {
                                                                if (client.Inventory.ContainsUID(key))
                                                                    client.Inventory.Remove(key, PhoenixProject.Game.Enums.ItemUse.Remove, true);
                                                            }
                                                            usage.dwParam = 1;
                                                            //client.Inventory.Remove(DragonBall, 12);
                                                            item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                                            item.Send(client);
                                                            client.LoadItemStats(client.Entity);
                                                            client.CalculateStatBonus();
                                                            client.CalculateHPBonus();
                                                            Database.ConquerItemTable.UpdateSockets(item);
                                                        }
                                                    }

                                                }
                                                client.Send(packet);
                                                break;
                                            }
                                        case 40:
                                            {
                                                uint ItemAdd = (uint)((packet[4] & 0xFF) | ((packet[5] & 0xFF) << 8) | ((packet[6] & 0xFF) << 16) | ((packet[7] & 0xFF) << 24));

                                                Interfaces.IConquerItem item_new = null;
                                                if (client.Inventory.TryGetItem(ItemAdd, out item_new))
                                                {
                                                    UInt32 iType = item_new.ID / 1000;
                                                    Positions pos = GetPositionFromID(item_new.ID);
                                                    if (pos == Positions.Garment)
                                                    {
                                                        client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                        client.Account.Savekimo();
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                    if (pos == Positions.RightAccessory)
                                                    {
                                                        client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                        client.Account.Savekimo();
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                    if (pos == Positions.LeftAccessory)
                                                    {
                                                        client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                        client.Account.Savekimo();
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                    if (pos == Positions.Bottle)
                                                    {
                                                        client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                        client.Account.Savekimo();
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                    if (pos == Positions.Steed)
                                                    {
                                                        client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                        client.Account.Savekimo();
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                    if (pos == Positions.SteedArmor)
                                                    {
                                                        client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                        client.Account.Savekimo();
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                    if (pos == Positions.SteedTalisman)
                                                    {
                                                        client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                        client.Account.Savekimo();
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                    if (pos == Positions.AttackTalisman)
                                                    {
                                                        client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                        client.Account.Savekimo();
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                    if (pos == Positions.DefenceTalisman)
                                                    {
                                                        client.Account.State = Database.AccountTable.AccountState.Cheat;
                                                        client.Account.Savekimo();
                                                        client.Disconnect();
                                                        return;
                                                    }
                                                    if (item_new.Bless == 7)
                                                        return;

                                                    Queue<uint> amount = new Queue<uint>(packet[20]);

                                                    for (ushort i = 84; i < 84 + 4 * packet[20]; i += 4)
                                                    {
                                                        if (client.Inventory.ContainsUID((uint)((packet[i] & 0xFF) | ((packet[(byte)(i + 1)] & 0xFF) << 8) | ((packet[(byte)(i + 2)] & 0xFF) << 16) | ((packet[(byte)(i + 3)] & 0xFF) << 24))))
                                                            amount.Enqueue((uint)((packet[i] & 0xFF) | ((packet[(byte)(i + 1)] & 0xFF) << 8) | ((packet[(byte)(i + 2)] & 0xFF) << 16) | ((packet[(byte)(i + 3)] & 0xFF) << 24)));
                                                        else
                                                            return;
                                                    }

                                                    byte oldbless = item_new.Bless;
                                                    if (item_new.Bless == 0 && amount.Count == 5)
                                                        item_new.Bless = 1;
                                                    else if (item_new.Bless == 1 && amount.Count == 1)
                                                        item_new.Bless = 3;
                                                    else if (item_new.Bless == 3 && amount.Count == 3)
                                                        item_new.Bless = 5;
                                                    else if (item_new.Bless == 5 && amount.Count == 5)
                                                        item_new.Bless = 7;
                                                    if (oldbless == item_new.Bless)
                                                        return;

                                                    while (amount.Count != 0)
                                                        client.Inventory.Remove(amount.Dequeue(), PhoenixProject.Game.Enums.ItemUse.Remove, true);

                                                    item_new.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                                    item_new.Send(client);
                                                    usage.dwParam = 1;
                                                    Database.ConquerItemTable.UpdateBless(item_new);
                                                }
                                                client.Send(packet);
                                                break;
                                            }
                                        case ItemUsage.GemCompose:
                                            {
                                                #region GemCompose
                                                UInt32 Ident = usage.UID;
                                                client.Inventory.Remove(Ident, 15);
                                                client.Inventory.Add(Ident + 1, 0, 1);
                                                usage.dwParam = 1;
                                                client.Send(usage);
                                                #endregion
                                                break;
                                            }
                                        case ItemUsage.ToristSuper:
                                            {
                                                #region GemCompose
                                                if (client.Entity.Money >= 100000)
                                                {
                                                    client.Inventory.Remove(700002, 1);
                                                    client.Inventory.Remove(700012, 1);
                                                    client.Inventory.Remove(700022, 1);
                                                    client.Inventory.Remove(700032, 1);
                                                    client.Inventory.Remove(700042, 1);
                                                    client.Inventory.Remove(700052, 1);
                                                    client.Inventory.Remove(700062, 1);
                                                    client.Entity.Money -= 100000;
                                                    client.Inventory.Add(700072, 0, 1);

                                                    usage.dwParam = 1;
                                                    client.Send(usage);
                                                }
                                                usage.dwParam = 0;
                                                client.Send(usage);
                                                #endregion
                                                break;
                                            }
                                        case ItemUsage.SplitStack:
                                            {
                                                Interfaces.IConquerItem mainItem = null;
                                                Interfaces.IConquerItem minorItem = new ConquerItem(true);
                                                Database.ConquerItemInformation infos = null;
                                                minorItem.Color = (PhoenixProject.Game.Enums.Color)ServerBase.Kernel.Random.Next(4, 8);
                                                if (client.Inventory.TryGetItem(usage.UID, out mainItem))
                                                {
                                                    infos = new PhoenixProject.Database.ConquerItemInformation(mainItem.ID, 0);
                                                    if (mainItem.StackSize > 1 && mainItem.StackSize <= infos.BaseInformation.StackSize)
                                                    {
                                                        if (client.Inventory.Count < 40)
                                                        {
                                                            client.SpiltStack = false;
                                                            ushort Amount = (ushort)usage.dwParam;

                                                            mainItem.StackSize -= Amount;
                                                            mainItem.Mode = Game.Enums.ItemMode.Update;
                                                            mainItem.Send(client);
                                                            mainItem.Mode = Game.Enums.ItemMode.Default;
                                                            Database.ConquerItemTable.UpdateStack(mainItem);
                                                            minorItem.ID = mainItem.ID;
                                                            minorItem.StackSize += Amount;
                                                            minorItem.Durability = mainItem.Durability;
                                                            client.Inventory.Add(minorItem, Game.Enums.ItemUse.CreateAndAdd);

                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        case ItemUsage.MergeStackableItems:
                                            {
                                                Interfaces.IConquerItem mainItem = null;
                                                Interfaces.IConquerItem minorItem = new ConquerItem(true);
                                                Database.ConquerItemInformation infos = null;
                                                minorItem.Color = (PhoenixProject.Game.Enums.Color)ServerBase.Kernel.Random.Next(4, 8);
                                                if (client.Inventory.TryGetItem(usage.UID, out mainItem) && client.Inventory.TryGetItem(usage.dwParam, out minorItem))
                                                {
                                                    if (mainItem.ID == minorItem.ID)
                                                    {
                                                        infos = new PhoenixProject.Database.ConquerItemInformation(mainItem.ID, 0);
                                                        if (mainItem.StackSize < 1)
                                                            mainItem.StackSize = 1;
                                                        if (minorItem.StackSize < 1)
                                                            minorItem.StackSize = 1;

                                                        if ((mainItem.StackSize + minorItem.StackSize) <= infos.BaseInformation.StackSize)
                                                        {
                                                            mainItem.StackSize += minorItem.StackSize;
                                                            mainItem.Mode = Game.Enums.ItemMode.Update;
                                                            mainItem.Send(client);
                                                            mainItem.Mode = Game.Enums.ItemMode.Default;
                                                            Database.ConquerItemTable.UpdateStack(mainItem);

                                                            client.Inventory.Remove(minorItem, Game.Enums.ItemUse.Remove);
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        case 34:
                                            {
                                                break;
                                            }
                                        case 54://downgrade
                                            {
                                                Interfaces.IConquerItem item = null;
                                                Interfaces.IConquerItem minorItem = new ConquerItem(true);
                                                //Database.ConquerItemInformation infos = null;
                                                // uint newid = infos.LowestID(infos.BaseInformation.Level);

                                                //minorItem.Color = (PhoenixProject.Game.Enums.Color)ServerBase.Kernel.Random.Next(4, 8);
                                                if (client.Inventory.TryGetItem(usage.UID, out item) && client.Entity.ConquerPoints >= 54)
                                                {
                                                    Database.ConquerItemInformation cii = new PhoenixProject.Database.ConquerItemInformation(item.ID, item.Plus);

                                                    uint kimzz = 0;
                                                    kimzz = item.ID;

                                                Kimozzz:
                                                    uint kimo = kimzz - 10;
                                                    uint kimo2 = kimzz - 20;
                                                    uint kimo3 = kimzz - 30;
                                                    ushort postion = ItemPosition(kimo);
                                                    ushort postion2 = ItemPosition(kimo2);
                                                    ushort postion3 = ItemPosition(kimo3);
                                                    Database.ConquerItemInformation cii1 = new PhoenixProject.Database.ConquerItemInformation(kimo, 0);
                                                    Database.ConquerItemInformation cii2 = new PhoenixProject.Database.ConquerItemInformation(kimo2, 0);
                                                    Database.ConquerItemInformation cii3 = new PhoenixProject.Database.ConquerItemInformation(kimo3, 0);

                                                    if (Database.ConquerItemInformation.BaseInformations.ContainsKey(kimo))
                                                    {
                                                        if (cii1.BaseInformation.Level >= 10 && postion != 4 && postion != 5)
                                                        {
                                                            kimzz = kimo;
                                                            goto Kimozzz;
                                                        }
                                                        else
                                                        {
                                                            if (cii1.BaseInformation.Level > 10)
                                                            {
                                                                kimzz = kimo;
                                                                goto Kimozzz;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (Database.ConquerItemInformation.BaseInformations.ContainsKey(kimo2))
                                                        {
                                                            if (cii2.BaseInformation.Level >= 10 && postion2 != 4 && postion2 != 5)
                                                            {
                                                                kimzz = kimo2;
                                                                goto Kimozzz;
                                                            }
                                                            else
                                                            {
                                                                if (cii2.BaseInformation.Level > 10)
                                                                {
                                                                    kimzz = kimo2;
                                                                    goto Kimozzz;
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (Database.ConquerItemInformation.BaseInformations.ContainsKey(kimo3))
                                                            {
                                                                if (cii3.BaseInformation.Level >= 10 && postion3 != 4 && postion3 != 5)
                                                                {
                                                                    kimzz = kimo3;
                                                                    goto Kimozzz;
                                                                }
                                                                else
                                                                {
                                                                    if (cii3.BaseInformation.Level > 10)
                                                                    {
                                                                        kimzz = kimo3;
                                                                        goto Kimozzz;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {

                                                                // return;
                                                            }
                                                        }
                                                    }

                                                    item.ID = kimzz;

                                                    PhoenixProject.Database.ConquerItemTable.UpdateItemID(item, client);
                                                    item.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                                    item.Send(client);
                                                    client.Entity.ConquerPoints -= 54;
                                                }
                                                else
                                                {
                                                    usage.dwParam = 2;
                                                }
                                                break;
                                            }
                                        default:
                                            {
                                                Console.WriteLine("Unhandled item usage type : " + usage.ID);
                                                break;
                                            }
                                    }
                                }
                                break;
                            }
                        #endregion
                        #region String (1015)
                        case 1015:
                            {
                                if (client.Action == 2)
                                {
                                    _String str2 = new _String(false);
                                    str2.Deserialize(packet);
                                    if ((str2.Type == 0x1a) && (str2.Texts.Count > 0))
                                    {
                                        IEnumerator enumerator = Kernel.GamePool.Values.GetEnumerator();
                                        enumerator.MoveNext();
                                        int count = Kernel.GamePool.Count;
                                        for (uint i = 0; i < count; i++)
                                        {
                                            if (i >= count)
                                            {
                                                break;
                                            }
                                            current = enumerator.Current as GameState;
                                            if (current.Entity.Name == str2.Texts[0])
                                            {
                                                string str3 = "";
                                                str3 = ((str3 + current.Entity.UID + " ") + current.Entity.Level + " ") + current.Entity.BattlePower + " #";
                                                if (current.Entity.GuildID != 0)
                                                {
                                                    str3 = str3 + current.Guild.Name + " fNone# ";
                                                }
                                                else
                                                {
                                                    str3 = str3 + "None fNone# ";
                                                }
                                                str3 = (str3 + current.Entity.Spouse + " ") + ((byte)current.Entity.NobilityRank) + " ";
                                                if ((current.Entity.Body % 10) < 3)
                                                {
                                                    str3 = str3 + "1";
                                                }
                                                else
                                                {
                                                    str3 = str3 + "0";
                                                }
                                                str2.Texts.Add(str3);
                                                client.Send(str2);
                                            }
                                            enumerator.MoveNext();
                                        }
                                    }
                                    break;
                                }
                            }
                            break;
                        #endregion
                        #region KnownPersons (1019)
                        case 1019:
                            {
                                KnownPersons knownP = new KnownPersons(false);
                                knownP.Deserialize(packet);
                                switch (knownP.Type)
                                {
                                    case KnownPersons.RequestFriendship:
                                        {
                                            AddFriend(knownP, client);
                                            break;
                                        }
                                    case KnownPersons.RemovePerson:
                                        {
                                            RemoveFriend(knownP, client);
                                            break;
                                        }
                                    case KnownPersons.RemoveEnemy:
                                        {
                                            RemoveEnemy(knownP, client);
                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion
                        #region Vote /Attack
                        case 1022:
                            {

                                if (client.Action != 2)
                                    return;
                                uint dmg = BitConverter.ToUInt32(packet, 24);
                                uint AttackType = BitConverter.ToUInt32(packet, 20);
                                uint AttackType2 = BitConverter.ToUInt32(packet, 26);

                                switch (AttackType)
                                {
                                    case 36:
                                        {
                                            GamePackets.Attack attack2 = new Attack(false);
                                            attack2.Deserialize(packet);
                                            CloudSaintsJar.Execute(client, attack2);
                                            break;
                                        }
                                    case 39:
                                        {
                                            if (!Kernel.VotePool.ContainsKey(client.Account.IP))
                                            {
                                                if (!Kernel.VotePoolUid.ContainsKey(client.Entity.UID))
                                                {
                                                    client.Entity.ConquerPoints += Database.rates.VotePrize;
                                                    PhoenixProject.Game.ConquerStructures.PlayersVot Vot = new PhoenixProject.Game.ConquerStructures.PlayersVot();
                                                    Vot.AdressIp = client.Account.IP;
                                                    Vot.Uid = client.Entity.UID;
                                                    Kernel.VotePool.Add(Vot.AdressIp, Vot);
                                                    Kernel.VotePoolUid.Add(Vot.Uid, Vot);
                                                    Database.EntityTable.SavePlayersVot(Vot);
                                                    client.Send(new Message("" + PhoenixProject.Database.rates.VoteUrl + "", System.Drawing.Color.Red, Network.GamePackets.Message.Website));
                                                }
                                                else
                                                {
                                                    client.Send(new Message("" + PhoenixProject.Database.rates.VoteUrl + "", System.Drawing.Color.Red, Network.GamePackets.Message.Website));
                                                }
                                            }
                                            else
                                            {
                                                client.Send(new Message("" + PhoenixProject.Database.rates.VoteUrl + "", System.Drawing.Color.Red, Network.GamePackets.Message.Website));

                                            }
                                            break;
                                        }
                                    default:
                                        {
                                            if (client.Entity.MapID == 8880 || client.Entity.MapID == 8881) return;
                                            GamePackets.Attack attack = new Attack(false);
                                            attack.Deserialize(packet);
                                            Attack(attack, client);
                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion
                        #region ChiSystem
                        case 2533:
                            {

                                ChiSystem2.Handle(packet, client);
                                break;
                            }
                        #endregion
                        #region CountryFlag
                        case 2430:
                            {
                                KimoCountryFlag kimo = new KimoCountryFlag(false);
                                kimo.Deserialize(packet);
                                client.Entity.CountryFlag = kimo.FlagID;
                                kimo.UID = client.Entity.UID;
                                client.SendScreen(kimo, true);
                                break;
                            }
                        #endregion
                        #region Teams (1023)
                        case 1023:
                            {
                                if (client.Action != 2)
                                    return;
                                Team teamPacket = new Team();
                                teamPacket.Deserialize(packet);
                                switch (teamPacket.Type)
                                {
                                    case Team.Create: CreateTeam(teamPacket, client); break;
                                    case Team.AcceptJoinRequest: AcceptRequestToJoinTeam(teamPacket, client); break;
                                    case Team.AcceptInvitation: AcceptInviteToJoinTeam(teamPacket, client); break;
                                    case Team.InviteRequest: SendInviteToJoinTeam(teamPacket, client); break;
                                    case Team.JoinRequest: SendRequestJoinToTeam(teamPacket, client); break;
                                    case Team.ExitTeam: LeaveTeam(teamPacket, client); break;
                                    case Team.Dismiss: DismissTeam(teamPacket, client); break;
                                    case Team.Kick: KickFromTeam(teamPacket, client); break;
                                    case Team.ForbidJoining:
                                        {
                                            foreach (Client.GameState Teammate in client.Team.Teammates)
                                                if (Teammate != null)
                                                {
                                                    Teammate.Team.ForbidJoin = true;
                                                    Teammate.Send(teamPacket);
                                                }

                                            break;
                                        }
                                    case Team.UnforbidJoining:
                                        {
                                            foreach (Client.GameState Teammate in client.Team.Teammates)
                                                if (Teammate != null)
                                                {
                                                    Teammate.Team.ForbidJoin = false;
                                                    Teammate.Send(teamPacket);
                                                }

                                            break;
                                        }
                                    case Team.LootMoneyOff:
                                        {
                                            foreach (Client.GameState Teammate in client.Team.Teammates)
                                                if (Teammate != null)
                                                {
                                                    Teammate.Team.PickupMoney = false;
                                                    Teammate.Send(teamPacket);
                                                }
                                            break;
                                        }
                                    case Team.LootMoneyOn:
                                        {
                                            foreach (Client.GameState Teammate in client.Team.Teammates)
                                                if (Teammate != null)
                                                {
                                                    Teammate.Team.PickupMoney = true;
                                                    Teammate.Send(teamPacket);
                                                }
                                            break;
                                        }
                                    case Team.LootItemsOn:
                                        {
                                            foreach (Client.GameState Teammate in client.Team.Teammates)
                                                if (Teammate != null)
                                                {
                                                    Teammate.Team.PickupItems = true;
                                                    Teammate.Send(teamPacket);
                                                }
                                            break;
                                        }
                                    case Team.LootItemsOff:
                                        {
                                            foreach (Client.GameState Teammate in client.Team.Teammates)
                                                if (Teammate != null)
                                                {
                                                    Teammate.Team.PickupItems = false;
                                                    Teammate.Send(teamPacket);
                                                }
                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion
                        #region Atributes Set (1024)
                        case 1024:
                            {
                                if (client.Action != 2)
                                    return;
                                uint AddStr = BitConverter.ToUInt32(packet, 8);
                                uint AddAgi = BitConverter.ToUInt32(packet, 12);
                                uint AddVit = BitConverter.ToUInt32(packet, 16);
                                uint AddSpi = BitConverter.ToUInt32(packet, 20);
                                if (client.Entity.Atributes == 0)
                                    return;

                                uint TotalStatPoints = AddStr + AddAgi + AddVit + AddSpi;

                                if (client.Entity.Atributes >= TotalStatPoints)
                                {
                                    client.Entity.Strength += (ushort)AddStr;
                                    client.Entity.Agility += (ushort)AddAgi;
                                    client.Entity.Vitality += (ushort)AddVit;
                                    client.Entity.Spirit += (ushort)AddSpi;
                                    client.Entity.Atributes -= (ushort)TotalStatPoints;
                                    client.Send(packet);
                                }
                                client.CalculateStatBonus();
                                client.CalculateHPBonus();
                                client.GemAlgorithm();
                                break;
                            }
                        #endregion
                        #region Socketing (1027)
                        case 1027:
                            {
                                EmbedSocket socket = new EmbedSocket(false);
                                socket.Deserialize(packet);
                                SocketItem(socket, client);
                                break;
                            }
                        #endregion
                        #region Character Statistics (1040)
                        case 1040:
                            {
                                uint UID = BitConverter.ToUInt32(packet, 4);
                                Client.GameState Client;
                                if (ServerBase.Kernel.GamePool.TryGetValue(UID, out Client))
                                {
                                    client.Send(WindowStats(Client));
                                }
                                break;
                            }
                        #endregion
                        #region LoginPacket (1052)
                        case 1052:
                            {
                                if (client.Action == 1)
                                {
                                    Connect connect = new Connect();
                                    connect.Deserialize(packet);
                                    AppendConnect(connect, client);
                                }
                                else
                                {
                                    //Console.WriteLine(" yes");
                                    client.Disconnect();
                                    //DoLogin(client);
                                }
                                break;
                            }
                        #endregion
                        #region Trade (1056)

                        case 1056:
                            {
                                if (client.Action != 2)
                                    return;
                                Trade trade = new Trade(false);
                                trade.Deserialize(packet);
                                switch (trade.Type)
                                {
                                    case Trade.Request:
                                        RequestTrade(trade, client);
                                        break;
                                    case Trade.Close:
                                        CloseTrade(trade, client);
                                        break;
                                    case Trade.AddItem:
                                        AddTradeItem(trade, client);
                                        break;
                                    case Trade.SetMoney:
                                        SetTradeMoney(trade, client);
                                        break;
                                    case Trade.SetConquerPoints:
                                        SetTradeConquerPoints(trade, client);
                                        break;
                                    case Trade.Accept:
                                        AcceptTrade(trade, client);
                                        break;
                                }
                                break;
                            }

                        #endregion Trade (1056)
                        #region Floor items (1101)
                        case 1101:
                            {
                                if (client.Action != 2)
                                    return;
                                FloorItem floorItem = new FloorItem(false);
                                floorItem.Deserialize(packet);
                                client.SpiltStack = true;
                                PickupItem(floorItem, client);
                                client.SpiltStack = false;
                                break;
                            }
                        #endregion
                        #region Warehouses (1102)
                        case 1102:
                            {
                                if (client.Action != 2)
                                    return;

                                Warehouse warehousepacket = new Warehouse(false);
                                warehousepacket.Deserialize(packet);
                                switch (warehousepacket.Type)
                                {
                                    case Warehouse.Entire:
                                        {
                                            Game.ConquerStructures.Warehouse wh = client.Warehouses[(PhoenixProject.Game.ConquerStructures.Warehouse.WarehouseID)warehousepacket.NpcID];
                                            if (wh == null) return;
                                            byte count = 0;
                                            warehousepacket.Count = 1;
                                            warehousepacket.Type = Warehouse.AddItem;
                                            for (; count < wh.Count; count++)
                                            {
                                                warehousepacket.Append(wh.Objects[count]);
                                                client.Send(warehousepacket);
                                            }
                                            break;
                                        }
                                    case Warehouse.AddItem:
                                        {
                                            if (client.Booth != null)
                                            {
                                                Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Sorry you cant add items into your warehouse while you in Booth");
                                                npc.OptionID = 255;
                                                client.Send(npc.ToArray());
                                                return;
                                            }
                                            Game.ConquerStructures.Warehouse wh = client.Warehouses[(PhoenixProject.Game.ConquerStructures.Warehouse.WarehouseID)warehousepacket.NpcID];
                                            if (wh == null) return;
                                            Interfaces.IConquerItem item = null;
                                            if (client.Inventory.TryGetItem(warehousepacket.UID, out item))
                                            {
                                                if (item.ID >= 729960 && item.ID <= 729970)
                                                    return;
                                                if (item.ID == 750000)
                                                    return;
                                                if (!ConquerItem.isRune(item.UID))
                                                {
                                                    if (wh.Add(item))
                                                    {
                                                        warehousepacket.UID = 0;
                                                        warehousepacket.Count = 1;
                                                        warehousepacket.Append(item);
                                                        client.Send(warehousepacket);
                                                        return;
                                                    }
                                                }
                                                else client.Send(new Message("You can not store Flame Stone Rune's in Warehouse", System.Drawing.Color.Red, Message.TopLeft));
                                            }
                                            break;
                                        }
                                    case Warehouse.RemoveItem:
                                        {
                                            Game.ConquerStructures.Warehouse wh = client.Warehouses[(PhoenixProject.Game.ConquerStructures.Warehouse.WarehouseID)warehousepacket.NpcID];
                                            if (wh == null) return;
                                            if (wh.ContainsUID(warehousepacket.UID))
                                            {
                                                if (wh.Remove(warehousepacket.UID))
                                                {
                                                    client.Send(warehousepacket);
                                                    return;
                                                }
                                            }
                                            break;
                                        }
                                    default:
                                        {
                                            Console.WriteLine("Unknown type: " + warehousepacket.Type);
                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion
                        #region GuildCommands (1107)
                        case 1107:
                            {
                                GuildCommand command = new GuildCommand(false);
                                command.Deserialize(packet);
                                switch (command.Type)
                                {
                                    case GuildCommand.Neutral1:
                                    case GuildCommand.Neutral2:
                                        {
                                            string name = System.Text.Encoding.UTF7.GetString(packet, 26, packet[25]);
                                            if (client.Guild != null)
                                            {
                                                if (client.AsMember.Rank == PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                {
                                                    client.Guild.RemoveAlly(name);
                                                    foreach (var guild in ServerBase.Kernel.Guilds.Values)
                                                    {
                                                        if (guild.Name == name && client.Guild.Name != name)
                                                        {
                                                            guild.RemoveAlly(client.Guild.Name);
                                                        }
                                                    }
                                                    client.Guild.RemoveEnemy(name);
                                                }
                                            }
                                            break;
                                        }
                                    case GuildCommand.Allied:
                                        {
                                            string name = System.Text.Encoding.UTF8.GetString(packet, 26, packet[25]);
                                            if (client.Guild != null)
                                            {
                                                if (client.AsMember.Rank == PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                {
                                                    AllyGuilds(name, client);
                                                }
                                            }
                                            break;
                                        }
                                    case GuildCommand.Enemied:
                                        {
                                            string name = System.Text.Encoding.UTF7.GetString(packet, 26, packet[25]);
                                            if (client.Guild != null)
                                            {
                                                if (client.AsMember.Rank == PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                {
                                                    client.Guild.AddEnemy(name);
                                                }
                                            }
                                            break;
                                        }
                                    default:
                                        {
                                            client.Send(packet);
                                            break;
                                        }
                                    case GuildCommand.Bulletin:
                                        {
                                            string message = System.Text.Encoding.UTF7.GetString(packet, 26, packet[25]);
                                            if (client.Guild != null)
                                            {
                                                if (client.AsMember.Rank == PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                {
                                                    client.Guild.Bulletin = message;
                                                    client.Guild.SendGuild(client);
                                                    Database.GuildTable.UpdateBulletin(client.Guild, client.Guild.Bulletin);
                                                }
                                            }
                                            break;
                                        }
                                    case GuildCommand.DonateSilvers:
                                        {
                                            if (client.Guild != null)
                                            {
                                                if (client.Entity.Money >= command.dwParam)
                                                {
                                                    client.Guild.SilverFund += command.dwParam;
                                                    Database.GuildTable.SaveFunds(client.Guild);
                                                    client.AsMember.SilverDonation += command.dwParam;
                                                    client.Entity.Money -= command.dwParam;
                                                    client.Guild.SendGuild(client);
                                                }
                                            }
                                            break;
                                        }
                                    case GuildCommand.DonateConquerPoints:
                                        {
                                            if (client.Guild != null)
                                            {
                                                if (client.Entity.ConquerPoints >= command.dwParam)
                                                {
                                                    client.Guild.ConquerPointFund += command.dwParam;
                                                    Database.GuildTable.SaveFunds(client.Guild);
                                                    client.AsMember.ConquerPointDonation += command.dwParam;
                                                    client.Entity.ConquerPoints -= command.dwParam;
                                                    client.Guild.SendGuild(client);
                                                }
                                            }
                                            break;
                                        }
                                    case GuildCommand.Refresh:
                                        {
                                            if (client.AsMember != null)
                                            {
                                                if (client.Guild != null)
                                                    client.Guild.SendGuild(client);
                                            }
                                            break;
                                        }
                                    case GuildCommand.Discharge:
                                        {
                                            string name = System.Text.Encoding.UTF7.GetString(packet, 26, packet[25]);
                                            if (client.Guild != null)
                                            {
                                                if (client.AsMember.Rank == PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                {
                                                    var member = client.Guild.GetMemberByName(name);
                                                    if (member != null)
                                                    {
                                                        if (member.ID != client.Entity.UID)
                                                        {
                                                            if (member.Rank == PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                                            {
                                                                client.Guild.DeputyLeaderCount--;
                                                                member.Rank = PhoenixProject.Game.Enums.GuildMemberRank.Member;
                                                                if (member.IsOnline)
                                                                {
                                                                    client.Guild.SendGuild(member.Client);
                                                                    member.Client.Entity.GuildRank = (ushort)member.Rank;
                                                                    member.Client.Screen.FullWipe();
                                                                    member.Client.Screen.Reload(null);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    case GuildCommand.Promote:
                                        {
                                            if (client.Guild != null)
                                            {
                                                if (client.AsMember.Rank == PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                {
                                                    if (client.Guild.Members.ContainsKey(command.dwParam))
                                                    {
                                                        var member = client.Guild.Members[command.dwParam];
                                                        if (member.Rank == PhoenixProject.Game.Enums.GuildMemberRank.Member)
                                                        {
                                                            member.Rank = PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader;
                                                            if (member.IsOnline)
                                                            {
                                                                client.Guild.SendGuild(member.Client);
                                                                member.Client.Entity.GuildRank = (ushort)member.Rank;
                                                                member.Client.Screen.FullWipe();
                                                                member.Client.Screen.Reload(null);
                                                            }
                                                        }
                                                        else if (member.Rank == PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                                        {
                                                            member.Rank = PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader;
                                                            if (member.IsOnline)
                                                            {
                                                                client.Guild.SendGuild(member.Client);
                                                                member.Client.Entity.GuildRank = (ushort)member.Rank;
                                                                member.Client.Screen.FullWipe();
                                                                member.Client.Screen.Reload(null);
                                                            }
                                                            client.AsMember.Rank = PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader;
                                                            client.Guild.SendGuild(client);
                                                            client.Entity.GuildRank = (ushort)client.AsMember.Rank;
                                                            client.Screen.FullWipe();
                                                            client.Screen.Reload(null);
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    case GuildCommand.JoinRequest:
                                        {
                                            if (ServerBase.Kernel.GamePool.ContainsKey(command.dwParam))
                                            {
                                                var Client = ServerBase.Kernel.GamePool[command.dwParam];
                                                if (Client.OnHoldGuildJoin == client.OnHoldGuildJoin && Client.OnHoldGuildJoin != 0)
                                                {
                                                    if (Client.Guild != null)
                                                    {
                                                        if (Client.AsMember.Rank != PhoenixProject.Game.Enums.GuildMemberRank.Member)
                                                        {
                                                            Client.Guild.AddMember(client);
                                                            Client.OnHoldGuildJoin = 0;
                                                            client.OnHoldGuildJoin = 0;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (client.AsMember.Rank != PhoenixProject.Game.Enums.GuildMemberRank.Member)
                                                        {
                                                            client.Guild.AddMember(Client);
                                                            Client.OnHoldGuildJoin = 0;
                                                            client.OnHoldGuildJoin = 0;
                                                        }
                                                    }
                                                    return;
                                                }
                                                if (client.Guild == null)
                                                {
                                                    command.dwParam = client.Entity.UID;
                                                    Client.Send(command);
                                                    Client.OnHoldGuildJoin = (uint)new Random().Next();
                                                    client.OnHoldGuildJoin = Client.OnHoldGuildJoin;
                                                }
                                            }
                                            break;
                                        }
                                    case GuildCommand.InviteRequest:
                                        {
                                            if (ServerBase.Kernel.GamePool.ContainsKey(command.dwParam))
                                            {
                                                var Client = ServerBase.Kernel.GamePool[command.dwParam];
                                                if (Client.OnHoldGuildJoin == client.OnHoldGuildJoin && Client.OnHoldGuildJoin != 0)
                                                {
                                                    if (Client.Guild != null)
                                                    {
                                                        if (Client.AsMember.Rank != PhoenixProject.Game.Enums.GuildMemberRank.Member)
                                                        {
                                                            Client.Guild.AddMember(client);
                                                            Client.OnHoldGuildJoin = 0;
                                                            client.OnHoldGuildJoin = 0;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (client.AsMember.Rank != PhoenixProject.Game.Enums.GuildMemberRank.Member)
                                                        {
                                                            client.Guild.AddMember(Client);
                                                            Client.OnHoldGuildJoin = 0;
                                                            client.OnHoldGuildJoin = 0;
                                                        }
                                                    }
                                                    return;
                                                }
                                                if (client.Guild != null)
                                                {
                                                    command.dwParam = client.Entity.UID;
                                                    Client.Send(command);
                                                    Client.OnHoldGuildJoin = 0;
                                                    client.OnHoldGuildJoin = Client.OnHoldGuildJoin;
                                                }
                                            }
                                            break;
                                        }
                                    case GuildCommand.Quit:
                                        {
                                            if (client.Guild != null)
                                            {
                                                if (client.AsMember.Rank != PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                {
                                                    client.Guild.ExpelMember(client.Entity.Name, true);
                                                }
                                            }
                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion

                        #region Enlight (1127)
                        case 1127:
                            {
                                Enlight enlight = new Enlight(false);
                                enlight.Deserialize(packet);
                                if (ServerBase.Kernel.GamePool.ContainsKey(enlight.Enlighted))
                                {
                                    var Client = ServerBase.Kernel.GamePool[enlight.Enlighted];

                                    if (enlight.Enlighter == client.Entity.UID && enlight.Enlighted != enlight.Enlighter)
                                    {
                                        if (Client.Entity.ReceivedEnlightenPoints < 5)
                                        {
                                            if (client.Entity.EnlightenPoints >= 100)
                                            {
                                                if (Client.Entity.EnlightmentTime <= 80)
                                                {
                                                    client.Entity.EnlightenPoints -= 100;
                                                    Client.Entity.EnlightmentStamp = Time32.Now;
                                                    Client.IncreaseExperience(Game.Attacking.Calculate.Percent((int)Client.ExpBall, .10F), false);
                                                    Client.SendScreen(packet, true);
                                                    Client.Entity.ReceivedEnlightenPoints++;
                                                    Client.Entity.EnlightmentTime += 20;
                                                    if (client.Entity.EnlightmentTime > 80)
                                                        client.Entity.EnlightmentTime = 100;
                                                    else if (client.Entity.EnlightmentTime > 60)
                                                        client.Entity.EnlightmentTime = 80;
                                                    else if (client.Entity.EnlightmentTime > 40)
                                                        client.Entity.EnlightmentTime = 60;
                                                    else if (client.Entity.EnlightmentTime > 20)
                                                        client.Entity.EnlightmentTime = 40;
                                                    else if (client.Entity.EnlightmentTime > 0)
                                                        client.Entity.EnlightmentTime = 20;
                                                }
                                                else client.Send(new Message("You can't enlighten " + Client.Entity.Name + " yet because he has to wait a few minutes until he can be enlightened again.", System.Drawing.Color.Red, Message.TopLeft));
                                            }
                                            else client.Send(new Message("You can't enlighten " + Client.Entity.Name + " because you don't have enough enlighten points!", System.Drawing.Color.Red, Message.TopLeft));
                                        }
                                        else client.Send(new Message("You can't enlighten " + Client.Entity.Name + " because he/she was enlightened today five times already!", System.Drawing.Color.Red, Message.TopLeft));
                                    }
                                }
                                break;
                            }
                        #endregion
                        #region QuizShow (2068)
                        case 2068:
                            {
                                try
                                {

                                    byte Answered = (byte)(packet[8] - 1);

                                    int L = Environment.TickCount;
                                    int Now = (L - client.QuizInfo.LastAnswer) / 1000 + 1;
                                    ushort qn = PhoenixProject.Game.ConquerStructures.QuizShow.QuestionNO;
                                    if ((ushort)((30 - Now) * PhoenixProject.Game.ConquerStructures.QuizShow.Questions[(ushort)(qn - 1)].Answers[Answered].Points) > 0)
                                    {
                                        client.QuizInfo.Time += (ushort)Now;
                                        client.QuizInfo.Score += (ushort)((30 - Now) * PhoenixProject.Game.ConquerStructures.QuizShow.Questions[(ushort)(qn - 1)].Answers[Answered].Points);
                                        client.Entity.QuizPoints += (ushort)((30 - Now) * PhoenixProject.Game.ConquerStructures.QuizShow.Questions[(ushort)(qn - 1)].Answers[Answered].Points);
                                        client.Entity.ConquerPoints += (ushort)((30 - Now) * PhoenixProject.Game.ConquerStructures.QuizShow.Questions[(ushort)(qn - 1)].Answers[Answered].Points * 10);
                                        client.Send(new Message("You have won " + ((30 - Now) * PhoenixProject.Game.ConquerStructures.QuizShow.Questions[(ushort)(qn - 1)].Answers[Answered].Points).ToString() + " quiz points and " + ((30 - Now) * PhoenixProject.Game.ConquerStructures.QuizShow.Questions[(ushort)(qn - 1)].Answers[Answered].Points * 10).ToString() + " ConquerPoints", System.Drawing.Color.Red, Message.TopLeft));
                                        uint exp = 1000;
                                        exp = (uint)(exp * ((30 - Now) * PhoenixProject.Game.ConquerStructures.QuizShow.Questions[(ushort)(qn - 1)].Answers[Answered].Points));
                                        client.IncreaseExperience((ulong)exp, false);
                                        Program.kimo3 = Answered;
                                    }
                                    else
                                    {
                                        client.QuizInfo.Time += (ushort)Now;
                                        client.QuizInfo.Score += (ushort)((30 - Now) * PhoenixProject.Game.ConquerStructures.QuizShow.Questions[(ushort)(qn - 1)].Answers[Answered].Points);
                                        uint exp = 1000;
                                        exp = (uint)(exp * ((30 - Now) * PhoenixProject.Game.ConquerStructures.QuizShow.Questions[(ushort)(qn - 1)].Answers[Answered].Points));
                                        client.IncreaseExperience((ulong)exp, false);
                                        client.Send(new Message("Ops Wrong Answer try Google if you dont know www.Google.com!!", System.Drawing.Color.Red, Message.TopLeft));

                                    }
                                    if (client.QuizInfo.Score >= 0)
                                    {
                                        /* int MyPlace = 0;
                                         for (int i = 0; i < 499; i++)
                                         {
                                             if (client.QuizInfo.Score < PhoenixProject.Game.ConquerStructures.QuizShow.Scores[i].Score)
                                             {
                                                 MyPlace++;
                                             }
                                             else
                                             {
                                                 if (client.Entity.UID == PhoenixProject.Game.ConquerStructures.QuizShow.Scores[i].EntityID)
                                                 {
                                                 }
                                                 else
                                                 {
                                                     if (client.QuizInfo.Score == PhoenixProject.Game.ConquerStructures.QuizShow.Scores[i].Score)
                                                     {
                                                         MyPlace++;
                                                     }
                                                 }
                                             }
                                         }*/
                                        if (client.QuizInfo.Score >= Kernel.MainQuiz.Score[0])
                                        {
                                            Kernel.MainQuiz.Name[0] = client.Entity.Name;
                                            Kernel.MainQuiz.Score[0] = client.QuizInfo.Score;
                                            Kernel.MainQuiz.Time[0] = client.QuizInfo.Time;
                                        }
                                        client.Send(new GamePackets.QuizInfo().InfoBuffer(client.QuizInfo.Score, client.QuizInfo.Time, client.QuizInfo.Rank));

                                    }

                                }
                                catch { }
                                break;
                            }
                        #endregion
                        #region NPC Dialog (2031 + 2032)
                        case 2031:
                        case 2032:
                            {
                                if (client.Action != 2)
                                    return;
                                NpcRequest req = new NpcRequest();
                                req.Deserialize(packet);
                                #region CaptureFlag
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 234 && client.Map.BaseID != 700)//CaptureFlag
                                {
                                    client.Entity.Teleport(1002, 384, 348);
                                }
                                #endregion
                                #region DemonCave
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 235 && client.Map.BaseID != 700)//DemonCave
                                {
                                    if (DateTime.Now.Hour == Game.KimoEvents.DemonHour && DateTime.Now.Minute < 5)
                                    {
                                        if (!client.DemonCave)
                                        {
                                            client.DemonCave = true;
                                            client.Entity.Teleport(1, 77, 69);
                                            client.Entity.DemonCave1 = 0;
                                            client.Entity.DemonCave2 = 0;
                                            client.Entity.DemonCave3 = 0;
                                            Data data = new Data(true);
                                            data.ID = Data.OpenCustom;
                                            data.UID = client.Entity.UID;
                                            data.TimeStamp = Time32.Now;
                                            data.dwParam = 3378;
                                            data.wParam1 = client.Entity.X;
                                            data.wParam2 = client.Entity.Y;
                                            client.Send(data);
                                        }
                                    }
                                }
                                #endregion
                                #region SkillTeam
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 236 && client.Map.BaseID != 700)//SkillTeamPK
                                {
                                    client.Entity.Teleport(1002, 460, 367);
                                }
                                #endregion
                                #region DonationWar
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 237 && client.Map.BaseID != 700)//dONATION
                                {
                                    client.Entity.Teleport(1002, 428, 392);
                                }
                                #endregion
                                #region ElitePk
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 249 && client.Map.BaseID != 700)//ElitePk
                                {
                                    if (DateTime.Now.Hour == Game.KimoEvents.EBHour && DateTime.Now.Minute >= 5 && DateTime.Now.Minute < 20)
                                    {
                                        if (!Game.Tournaments.EliteTournament.Top8.ContainsKey(client.Entity.UID))
                                        {
                                            Game.Tournaments.EliteTournament.AddMap(client);
                                            Data data = new Data(true);
                                            data.ID = Data.OpenCustom;
                                            data.UID = client.Entity.UID;
                                            data.TimeStamp = Time32.Now;
                                            data.dwParam = 3378;
                                            data.wParam1 = client.Entity.X;
                                            data.wParam2 = client.Entity.Y;
                                            client.Send(data);
                                        }
                                    }
                                }
                                #endregion
                                #region classpk
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 248 && client.Map.BaseID != 700)//ClassPk
                                {
                                    if (DateTime.Now.Hour == Game.KimoEvents.ClassHour && DateTime.Now.Minute < 05)
                                    {
                                        if (client.Entity.Class >= 10 && client.Entity.Class <= 15)
                                        {
                                            client.Entity.Teleport(7001, 25, 40);
                                        }
                                        if (client.Entity.Class >= 20 && client.Entity.Class <= 25)
                                        {
                                            client.Entity.Teleport(4500, 25, 40);
                                        }
                                        if (client.Entity.Class >= 40 && client.Entity.Class <= 45)
                                        {
                                            client.Entity.Teleport(4501, 25, 40);
                                        }
                                        if (client.Entity.Class >= 50 && client.Entity.Class <= 55)
                                        {
                                            client.Entity.Teleport(4502, 25, 40);
                                        }
                                        if (client.Entity.Class >= 60 && client.Entity.Class <= 65)
                                        {
                                            client.Entity.Teleport(4503, 25, 40);
                                        }
                                        if (client.Entity.Class >= 70 && client.Entity.Class <= 75)
                                        {
                                            client.Entity.Teleport(4504, 25, 40);
                                        }
                                        if (client.Entity.Class >= 132 && client.Entity.Class <= 135)
                                        {
                                            client.Entity.Teleport(4505, 25, 40);
                                        }
                                        if (client.Entity.Class >= 142 && client.Entity.Class <= 145)
                                        {
                                            client.Entity.Teleport(4506, 25, 40);
                                        }
                                        Data data = new Data(true);
                                        data.ID = Data.OpenCustom;
                                        data.UID = client.Entity.UID;
                                        data.TimeStamp = Time32.Now;
                                        data.dwParam = 3378;
                                        data.wParam1 = client.Entity.X;
                                        data.wParam2 = client.Entity.Y;
                                        client.Send(data);

                                    }
                                }
                                #endregion
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 247 && client.Map.BaseID != 700 && client.Entity.invite)//WeeklyPk
                                {
                                    client.Entity.Teleport(1002, 453, 294);
                                }
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 246 && client.Map.BaseID != 700)//MonthlyPk
                                {
                                    client.Entity.Teleport(1002, 428, 243);
                                }
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 245 && client.Map.BaseID != 700)//DisCity
                                {
                                    client.Entity.Teleport(1020, 534, 484);
                                }
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 244 && client.Map.BaseID != 700)//GuildWar
                                {
                                    client.Disconnect();
                                    return;
                                }
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 233 && client.Map.BaseID != 700)//ClanWar
                                {
                                    client.Entity.Teleport(1002, 413, 246);
                                }
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 198 && client.Map.BaseID != 700)//ClanWar
                                {
                                    client.Entity.Teleport(1002, 450, 372);
                                }
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 196 && client.Map.BaseID != 700)//ClanWar
                                {
                                    client.Entity.Teleport(1002, 425, 385);
                                }
                                #region DailyPk
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 243 && client.Map.BaseID != 700)//DailyPk
                                {
                                    if (DateTime.Now.Minute >= 00 && DateTime.Now.Minute < 05)
                                    {
                                        client.Entity.Teleport(8877, 52, 44);
                                        Data data = new Data(true);
                                        data.ID = Data.OpenCustom;
                                        data.UID = client.Entity.UID;
                                        data.TimeStamp = Time32.Now;
                                        data.dwParam = 3378;
                                        data.wParam1 = client.Entity.X;
                                        data.wParam2 = client.Entity.Y;
                                        client.Send(data);
                                    }
                                }
                                #endregion
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 242 && client.Map.BaseID != 700)//SteedRace
                                {
                                    client.Entity.Teleport(1002, 423, 245);
                                }
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 241 && client.Map.BaseID != 700)//SpouseWar
                                {
                                    client.Entity.Teleport(1002, 421, 292);
                                }
                                #region LastMan
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 240 && client.Map.BaseID != 700)//LastMan
                                {
                                    if (DateTime.Now.Minute >= 30 && DateTime.Now.Minute <= 32)
                                    {
                                        Random R = new Random();
                                        int Nr = R.Next(1, 10);
                                        if (Nr == 1) client.Entity.Teleport(3333, 51, 73);
                                        if (Nr == 2) client.Entity.Teleport(3333, 33, 34);
                                        if (Nr == 3) client.Entity.Teleport(3333, 67, 34);
                                        if (Nr == 4) client.Entity.Teleport(3333, 51, 73);
                                        if (Nr == 5) client.Entity.Teleport(3333, 33, 34);
                                        if (Nr == 6) client.Entity.Teleport(3333, 67, 34);
                                        if (Nr == 7) client.Entity.Teleport(3333, 51, 73);
                                        if (Nr == 8) client.Entity.Teleport(3333, 33, 34);
                                        if (Nr == 9) client.Entity.Teleport(3333, 67, 34);
                                        if (Nr == 10) client.Entity.Teleport(3333, 68, 57);

                                        Data data = new Data(true);
                                        data.ID = Data.OpenCustom;
                                        data.UID = client.Entity.UID;
                                        data.TimeStamp = Time32.Now;
                                        data.dwParam = 3378;
                                        data.wParam1 = client.Entity.X;
                                        data.wParam2 = client.Entity.Y;
                                        client.Send(data);
                                    }
                                }
                                #endregion
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 239 && client.Map.BaseID != 700)//EliteGW
                                {
                                    client.Entity.Teleport(1002, 414, 259);
                                }
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 238 && client.Map.BaseID != 700)//TreasueBox
                                {
                                    client.Entity.Teleport(1002, 441, 352);
                                }
                                if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead && req.OptionID == 233 && client.Map.BaseID != 700)//LordsWar
                                {
                                    client.Entity.Teleport(1002, 382, 394);
                                }
                                if (req.InteractType == NpcReply.MessageBox)
                                {
                                    if (client.Entity.ActivePOPUP == 99995)
                                    {
                                        client.Entity.ActivePOPUP = 0;
                                        break;
                                    }
                                    if (req.OptionID == 255)
                                    {
                                        if (client.OnMessageBoxOK != null)
                                        {
                                            client.OnMessageBoxOK.Invoke();
                                            client.OnMessageBoxOK = null;
                                        }
                                    }
                                    else
                                    {
                                        if (client.OnMessageBoxCANCEL != null)
                                        {
                                            client.OnMessageBoxCANCEL.Invoke();
                                            client.OnMessageBoxCANCEL = null;
                                        }
                                    }
                                }
                                else
                                {
                                    if (ID == 2031)
                                        client.ActiveNpc = req.NpcID;
                                    if (req.NpcID == 12)
                                    {
                                        if (client.Entity.VIPLevel > 0)
                                        {
                                            Data data = new Data(true);
                                            data.ID = Data.OpenWindow;
                                            data.UID = client.Entity.UID;
                                            data.TimeStamp = Time32.Now;
                                            data.dwParam = Data.WindowCommands.VIPWarehouse;
                                            data.wParam1 = client.Entity.X;
                                            data.wParam2 = client.Entity.Y;
                                            client.Send(data);
                                            break;
                                        }
                                    }
                                    Interfaces.INpc npc = null;
                                    if (req.InteractType == 102)
                                    {
                                        if (client.Guild != null)
                                        {
                                            if (client.AsMember.Rank == PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                            {
                                                client.Guild.ExpelMember(req.Input, false);
                                            }
                                        }
                                        return;
                                    }
                                    if (client.Map.Npcs.TryGetValue(client.ActiveNpc, out npc))
                                    {
                                        if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, npc.X, npc.Y) > 17)
                                            return;
                                        if (req.OptionID == 255 || (req.OptionID == 0 && ID == 2032))
                                            return;
                                        if (client.Entity.Dead)
                                            return;
                                        req.NpcID = client.ActiveNpc;
                                        //NpcDialogs.Dialogs.GetDialog(req, client);
                                        Dialogs.GetDialog(req, client);
                                    }
                                }
                                break;
                            }
                        #endregion
                        #region Compose (2036)
                        case 2036:
                            {
                                Compose compose = new Compose(false);
                                compose.Deserialize(packet);
                                ComposePlus(compose, client);
                                break;
                            }
                        #endregion
                        #region Offline TG (2044)
                        case 2044:
                            {
                                OfflineTGRequest otgr = new OfflineTGRequest(false);
                                otgr.Deserialize(packet);
                                switch (otgr.ID)
                                {
                                    case OfflineTGRequest.OnTrainingTimeRequested:
                                        {
                                            otgr.Minutes = 900;
                                            client.Send(otgr);
                                            break;
                                        }
                                    case OfflineTGRequest.OnConfirmation:
                                        {
                                            if (client.Map.BaseID == 6000 || client.Map.BaseID == 6001 || client.Entity.Dead)
                                            {
                                                return;
                                            }
                                            if (client.Entity.MapID == 1036 || client.Entity.MapID == 1039 || ServerBase.Constants.OfflineTG.Contains(client.Entity.MapID))
                                            {
                                                switch (client.Entity.PreviousMapID)
                                                {

                                                    case 1000:
                                                        {
                                                            client.Entity.PreviousMapID = 1000;
                                                            client.Entity.PrevX = 500;
                                                            client.Entity.PrevY = 560;
                                                            break;
                                                        }
                                                    case 1020:
                                                        {
                                                            client.Entity.PreviousMapID = 1020;
                                                            client.Entity.PrevX = 565;
                                                            client.Entity.PrevY = 562;
                                                            //client.Entity.Teleport(1020, 565, 562);
                                                            break;
                                                        }
                                                    case 1011:
                                                        {
                                                            client.Entity.PreviousMapID = 1011;
                                                            client.Entity.PrevX = 188;
                                                            client.Entity.PrevY = 264;
                                                            //client.Entity.Teleport(1011, 188, 264);
                                                            break;
                                                        }
                                                    case 1015:
                                                        {
                                                            client.Entity.PreviousMapID = 1015;
                                                            client.Entity.PrevX = 717;
                                                            client.Entity.PrevY = 571;
                                                            // client.Entity.Teleport(1015, 717, 571);
                                                            break;
                                                        }
                                                    default:
                                                        {
                                                            client.Entity.PreviousMapID = 1002;
                                                            client.Entity.PrevX = 429;
                                                            client.Entity.PrevY = 378;
                                                            //client.Entity.Teleport(1002, 429, 378);
                                                            break;
                                                        }
                                                }
                                                client.Entity.PreviousMapID = client.Entity.PreviousMapID;
                                                //client.Entity.PrevX = client.Entity.PrevX;
                                                //client.Entity.PrevY = client.Entity.PrevY;
                                            }
                                            else
                                            {
                                                client.Entity.PreviousMapID = client.Entity.MapID;
                                                client.Entity.PrevX = client.Entity.X;
                                                client.Entity.PrevY = client.Entity.Y;
                                            }

                                            client.Entity.MapID = 601;
                                            client.Entity.X = 64;
                                            client.Entity.Y = 56;
                                            client.OfflineTGEnterTime = DateTime.Now;
                                            client.Disconnect();
                                            break;
                                        }
                                    case OfflineTGRequest.ClaimExperience:
                                        {
                                            var T1 = new TimeSpan(DateTime.Now.Ticks);
                                            var T2 = new TimeSpan(client.OfflineTGEnterTime.Ticks);
                                            ushort minutes = (ushort)(T1.TotalMinutes - T2.TotalMinutes);
                                            minutes = (ushort)Math.Min((ushort)900, minutes);
                                            double expballGain = (double)300 * (double)minutes / (double)900;
                                            while (expballGain >= 100)
                                            {
                                                expballGain -= 100;
                                                client.IncreaseExperience(client.ExpBall, false);
                                            }
                                            if (expballGain != 0)
                                                client.IncreaseExperience((uint)(client.ExpBall * (expballGain / 100)), false);

                                            client.Entity.SetLocation(client.Entity.PreviousMapID, client.Entity.PrevX, client.Entity.PrevY);
                                            if (client.Entity.PreviousMapID == 1036 || client.Entity.PreviousMapID == 1039)
                                                switch (client.Entity.PreviousMapID)
                                                {

                                                    case 1000:
                                                        {
                                                            client.Entity.Teleport(1000, 500, 650);
                                                            break;
                                                        }
                                                    case 1020:
                                                        {
                                                            client.Entity.Teleport(1020, 565, 562);
                                                            break;
                                                        }
                                                    case 1011:
                                                        {
                                                            client.Entity.Teleport(1011, 188, 264);
                                                            break;
                                                        }
                                                    case 1015:
                                                        {
                                                            client.Entity.Teleport(1015, 717, 571);
                                                            break;
                                                        }
                                                    default:
                                                        {
                                                            client.Entity.Teleport(1002, 429, 378);
                                                            break;
                                                        }
                                                }
                                            else
                                            {
                                                client.Entity.Teleport(client.Entity.PreviousMapID, client.Entity.PrevX, client.Entity.PrevY);
                                            }
                                            client.OfflineTGEnterTime = DateTime.Now;
                                            break;
                                        }
                                    default:
                                        client.Send(otgr);
                                        break;
                                }
                                break;
                            }
                        #endregion
                        #region Trade partner (2046)
                        case 2046:
                            {
                                TradePartner partner = new TradePartner(false);
                                partner.Deserialize(packet);
                                switch (partner.Type)
                                {
                                    case TradePartner.RequestPartnership:
                                        RequestTradePartnership(partner, client);
                                        break;
                                    case TradePartner.RejectRequest:
                                        RejectPartnership(partner, client);
                                        break;
                                    case TradePartner.BreakPartnership:
                                        BreakPartnership(partner, client);
                                        break;
                                }
                                break;
                            }
                        #endregion
                        #region ItemLock (2048)
                        case 2048:
                            {
                                if (client.Action != 2)
                                    return;
                                ItemLock itemlock = new ItemLock(false);
                                itemlock.Deserialize(packet);
                                switch (itemlock.ID)
                                {
                                    case ItemLock.RequestLock:
                                        LockItem(itemlock, client);
                                        break;
                                    case ItemLock.RequestUnlock:
                                        UnlockItem(itemlock, client);
                                        break;
                                }
                                break;
                            }
                        #endregion
                        #region Broadcast (2050)
                        case 2050:
                            {
                                Broadcast cast = new Broadcast(false);
                                cast.Deserialize(packet);
                                switch (cast.Type)
                                {
                                    case Broadcast.ReleaseSoonMessages:
                                        {
                                            BroadcastInfoAwaiting(cast, client);
                                            break;
                                        }
                                    case Broadcast.MyMessages:
                                        {
                                            BroadcastClientMessages(cast, client);
                                            break;
                                        }
                                    case Broadcast.BroadcastMessage:
                                        {
                                            if (client.Trade.InTrade)
                                            {
                                                client.Send(new Message("You cannot send any broadcasts While you inTrade.", System.Drawing.Color.Red, Message.TopLeft));
                                                break;
                                            }
                                            if (client.Entity.MapID == 3031)
                                            {
                                                client.Send(new Message("You cannot send any broadcasts while you in LordsWar Tourment.", System.Drawing.Color.Red, Message.TopLeft));
                                                break;
                                            }
                                            if (Game.ConquerStructures.Broadcast.Broadcasts.Count == ServerBase.Constants.MaxBroadcasts)
                                            {
                                                client.Send(new Message("You cannot send any broadcasts for now. The limit has been reached. Wait until a broadcast is chopped down.", System.Drawing.Color.Red, Message.TopLeft));
                                                break;
                                            }
                                            if (client.Entity.ConquerPoints >= 5)
                                            {
                                                client.Entity.ConquerPoints -= 5;
                                                Game.ConquerStructures.Broadcast.BroadcastStr broadcast = new PhoenixProject.Game.ConquerStructures.Broadcast.BroadcastStr();
                                                broadcast.EntityID = client.Entity.UID;
                                                broadcast.EntityName = client.Entity.Name;
                                                broadcast.ID = Game.ConquerStructures.Broadcast.BroadcastCounter.Next;
                                                if (cast.List[0].Length > 80)
                                                    cast.List[0] = cast.List[0].Remove(80);
                                                broadcast.Message = cast.List[0];
                                                if (Game.ConquerStructures.Broadcast.Broadcasts.Count == 0)
                                                {
                                                    if (Game.ConquerStructures.Broadcast.CurrentBroadcast.EntityID == 1)
                                                    {
                                                        Game.ConquerStructures.Broadcast.CurrentBroadcast = broadcast;
                                                        Game.ConquerStructures.Broadcast.LastBroadcast = DateTime.Now;
                                                        ServerBase.Kernel.SendWorldMessage(new Message(cast.List[0], "ALLUSERS", client.Entity.Name, System.Drawing.Color.Red, Message.BroadcastMessage), ServerBase.Kernel.GamePool.Values);
                                                        client.Send(cast);
                                                        break;
                                                    }
                                                }
                                                Game.ConquerStructures.Broadcast.Broadcasts.Add(broadcast);
                                                cast.dwParam = (uint)Game.ConquerStructures.Broadcast.Broadcasts.Count;
                                                client.Send(cast);
                                                break;
                                            }
                                            break;
                                        }
                                    case Broadcast.Urgen5CPs:
                                        {
                                            for (int c = 0; c < Game.ConquerStructures.Broadcast.Broadcasts.Count; c++)
                                            {
                                                var broadcast = Game.ConquerStructures.Broadcast.Broadcasts[c];
                                                if (broadcast.ID == cast.dwParam)
                                                {
                                                    if (c != 0)
                                                    {
                                                        if (client.Entity.ConquerPoints > 5)
                                                        {
                                                            broadcast.SpentCPs += 5;
                                                            client.Entity.ConquerPoints -= 5;
                                                            if (Game.ConquerStructures.Broadcast.Broadcasts[c - 1].SpentCPs <= broadcast.SpentCPs)
                                                            {

                                                                Game.ConquerStructures.Broadcast.Broadcasts[c] = Game.ConquerStructures.Broadcast.Broadcasts[c - 1];
                                                                Game.ConquerStructures.Broadcast.Broadcasts[c - 1] = broadcast;
                                                            }
                                                            else
                                                            {
                                                                Game.ConquerStructures.Broadcast.Broadcasts[c] = broadcast;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    case Broadcast.Urgen15CPs:
                                        {
                                            for (int c = 0; c < Game.ConquerStructures.Broadcast.Broadcasts.Count; c++)
                                            {
                                                var broadcast = Game.ConquerStructures.Broadcast.Broadcasts[c];
                                                if (broadcast.ID == cast.dwParam)
                                                {
                                                    if (c != 0)
                                                    {
                                                        if (client.Entity.ConquerPoints > 15)
                                                        {
                                                            broadcast.SpentCPs += 15;
                                                            client.Entity.ConquerPoints -= 15;
                                                            for (int b = c - 1; b > 0; b--)
                                                                Game.ConquerStructures.Broadcast.Broadcasts[b] = Game.ConquerStructures.Broadcast.Broadcasts[b - 1];

                                                            Game.ConquerStructures.Broadcast.Broadcasts[0] = broadcast;
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion
                        #region Nobility (2064)
                        case 2064:
                            {
                                NobilityInfo nobility = new NobilityInfo(false);
                                nobility.Deserialize(packet);
                                Game.ConquerStructures.Nobility.Handle(nobility, client);
                                break;
                            }
                        #endregion
                        #region TopGuilds
                        case 1058:
                            {
                                if (client.Guild != null && client.AsMember != null)
                                {
                                    if (client.AsMember != null)
                                    {
                                        Writer.WriteUInt32((uint)client.AsMember.SilverDonation, 8, packet);
                                        if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                            if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                if (client.AsMember.SilverDonation > client.Guild.SilverFund)
                                                {
                                                    client.Guild.SilverFund = (uint)client.AsMember.SilverDonation;
                                                    client.Entity.GuildRank = (ushort)PhoenixProject.Game.Enums.GuildMemberRank.OSupervisor;
                                                    client.AsMember.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)client.Entity.GuildRank;
                                                }

                                        Writer.WriteUInt32((uint)client.AsMember.ConquerPointDonation, 20, packet);
                                        if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                            if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                if (client.AsMember.ConquerPointDonation > client.Guild.ConquerPointFund)
                                                {
                                                    client.Guild.ConquerPointFund = (uint)client.AsMember.ConquerPointDonation;
                                                    client.Entity.GuildRank = (ushort)PhoenixProject.Game.Enums.GuildMemberRank.CPSupervisor;
                                                    client.AsMember.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)client.Entity.GuildRank;
                                                }

                                    }
                                    Writer.WriteUInt32(client.Entity.PKPoints, 12, packet);
                                    if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                        if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                            if (client.Entity.PKPoints > client.Guild.pkp_donation)
                                            {
                                                client.Guild.pkp_donation = (uint)client.Entity.PKPoints;
                                                client.Entity.GuildRank = (ushort)PhoenixProject.Game.Enums.GuildMemberRank.PKSupervisor;
                                                client.AsMember.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)client.Entity.GuildRank;
                                            }

                                    if (client.ArenaStatistic != null)
                                    {
                                        Writer.WriteUInt32(client.ArenaStatistic.CurrentHonor, 24, packet);
                                        if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                            if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                if (client.ArenaStatistic.CurrentHonor > client.Guild.honor_donation)
                                                {
                                                    client.Guild.honor_donation = (uint)client.ArenaStatistic.CurrentHonor;
                                                    client.Entity.GuildRank = (ushort)PhoenixProject.Game.Enums.GuildMemberRank.HonoraryManager;
                                                    client.AsMember.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)client.Entity.GuildRank;
                                                }
                                    }
                                    Writer.WriteUInt32(0, 16, packet);
                                    if (client.Entity != null)
                                        if (client.Entity.Flowers != null)
                                        {
                                            Writer.WriteUInt32((uint)client.Entity.Flowers.RedRoses, 28, packet);
                                            if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                                if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                    if (client.Entity.Flowers.RedRoses > client.Guild.rose_donation)
                                                    {
                                                        client.Guild.rose_donation = (uint)client.Entity.Flowers.RedRoses;
                                                        client.Entity.GuildRank = (ushort)PhoenixProject.Game.Enums.GuildMemberRank.RoseSupervisor;
                                                        client.AsMember.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)client.Entity.GuildRank;
                                                    }

                                            Writer.WriteUInt32((uint)client.Entity.Flowers.Tulips, 32, packet);
                                            if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                                if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                    if (client.Entity.Flowers.Tulips > client.Guild.tuil_donation)
                                                    {
                                                        client.Guild.tuil_donation = (uint)client.Entity.Flowers.Tulips;
                                                        client.Entity.GuildRank = (ushort)PhoenixProject.Game.Enums.GuildMemberRank.TulipFollower;
                                                        client.AsMember.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)client.Entity.GuildRank;
                                                    }

                                            Writer.WriteUInt32((uint)client.Entity.Flowers.Lilies, 36, packet);
                                            if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                                if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                    if (client.Entity.Flowers.Lilies > client.Guild.lilies_donation)
                                                    {
                                                        client.Guild.lilies_donation = (uint)client.Entity.Flowers.Lilies;
                                                        client.Entity.GuildRank = (ushort)PhoenixProject.Game.Enums.GuildMemberRank.LilySupervisor;
                                                        client.AsMember.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)client.Entity.GuildRank;
                                                    }

                                            Writer.WriteUInt32((uint)client.Entity.Flowers.Orchads, 40, packet);
                                            if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                                if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                                    if (client.Entity.Flowers.Orchads > client.Guild.orchid_donation)
                                                    {
                                                        client.Guild.orchid_donation = (uint)client.Entity.Flowers.Orchads;
                                                        client.Entity.GuildRank = (ushort)PhoenixProject.Game.Enums.GuildMemberRank.OrchidFollower;
                                                        client.AsMember.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)client.Entity.GuildRank;
                                                    }
                                            Writer.WriteUInt32((uint)(client.Entity.Flowers.Orchads
                                                + (uint)client.Entity.Flowers.RedRoses
                                                + (uint)client.Entity.Flowers.Tulips
                                                + (uint)client.Entity.Flowers.Lilies), 44, packet);
                                        }
                                    if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                                        if (client.Entity.GuildRank != (ushort)PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                                        {
                                            if (client.Entity.Name == client.Guild.LeaderName)
                                            {
                                                client.Entity.GuildRank = (ushort)PhoenixProject.Game.Enums.GuildMemberRank.LeaderSpouse;
                                                client.AsMember.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)client.Entity.GuildRank;
                                            }
                                        }
                                    if (client.Guild != null)
                                        client.Guild.SendGuild(client);
                                    client.Send(packet);
                                }
                                break;
                            }
                        #endregion
                        #region Flowers (1150 & 1151)
                        case 1150:
                            {
                                new Game.Features.Flowers.FlowerSystem(packet, client);
                                break;
                            }
                        #endregion
                        #region Flowers (1150 & 1151)
                        case 1151:
                            {
                                int subtype = packet[4];
                                AddFlowers(client, packet);

                                break;
                            }
                        #endregion
                        #region Mentor prize (2067)
                        case 2067:
                            {
                                MentorPrize prize = new MentorPrize(false);
                                prize.Deserialize(packet);
                                switch (prize.Prize_Type)
                                {
                                    case MentorPrize.ClaimExperience:
                                        {
                                            client.IncreaseExperience((ulong)(((double)client.PrizeExperience / 606) * client.ExpBall), false);
                                            client.PrizeExperience = 0;
                                            foreach (var appr in client.Apprentices.Values)
                                            {
                                                appr.Actual_Experience = 0;
                                                Database.KnownPersons.SaveApprenticeInfo(appr);
                                            }
                                            prize.Mentor_ID = client.Entity.UID;
                                            prize.Prize_Type = MentorPrize.Show;
                                            prize.Prize_Experience = client.PrizeExperience;
                                            prize.Prize_HeavensBlessing = client.PrizeHeavenBlessing;
                                            prize.Prize_PlusStone = client.PrizePlusStone;
                                            client.Send(prize);
                                            break;
                                        }
                                    case MentorPrize.ClaimHeavenBlessing:
                                        {
                                            client.AddBless(client.PrizeHeavenBlessing);
                                            client.PrizeHeavenBlessing = 0;
                                            foreach (var appr in client.Apprentices.Values)
                                            {
                                                appr.Actual_HeavenBlessing = 0;
                                                Database.KnownPersons.SaveApprenticeInfo(appr);
                                            }
                                            prize.Mentor_ID = client.Entity.UID;
                                            prize.Prize_Type = MentorPrize.Show;
                                            prize.Prize_Experience = client.PrizeExperience;
                                            prize.Prize_HeavensBlessing = client.PrizeHeavenBlessing;
                                            prize.Prize_PlusStone = client.PrizePlusStone;
                                            client.Send(prize);
                                            break;
                                        }
                                    case MentorPrize.ClaimPlus:
                                        {
                                            int stones = client.PrizePlusStone / 100;
                                            int totake = stones;
                                            if (stones > 0)
                                            {
                                                for (; stones > 0; stones--)
                                                {
                                                    client.PrizePlusStone -= 100;
                                                    if (!client.Inventory.Add(730001, 1, 1))
                                                        break;
                                                }
                                            }
                                            foreach (var appr in client.Apprentices.Values)
                                            {
                                                if (appr.Actual_Plus >= totake)
                                                {
                                                    appr.Actual_Plus -= (ushort)totake;
                                                    totake = 0;
                                                }
                                                else
                                                {
                                                    totake -= appr.Actual_Plus;
                                                    appr.Actual_Plus = 0;
                                                }
                                                Database.KnownPersons.SaveApprenticeInfo(appr);
                                            }
                                            prize.Mentor_ID = client.Entity.UID;
                                            prize.Prize_Type = MentorPrize.Show;
                                            prize.Prize_Experience = client.PrizeExperience;
                                            prize.Prize_HeavensBlessing = client.PrizeHeavenBlessing;
                                            prize.Prize_PlusStone = client.PrizePlusStone;
                                            client.Send(prize);
                                            break;
                                        }
                                    case MentorPrize.Show:
                                        {
                                            prize.Mentor_ID = client.Entity.UID;
                                            prize.Prize_Type = MentorPrize.Show;
                                            prize.Prize_Experience = client.PrizeExperience;
                                            prize.Prize_HeavensBlessing = client.PrizeHeavenBlessing;
                                            prize.Prize_PlusStone = client.PrizePlusStone;
                                            client.Send(prize);
                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion
                        #region ElitePk Tournament 2223 | 2219
                        case 2223:
                            {
                                if (client.Entity.MapID == 6002)
                                    break;

                                if (Game.Tournaments.EliteTournament.Start)
                                    break;

                                GamePackets.Elite_Pk pk = new Elite_Pk(client.Entity.UID);
                                pk.Send(client);
                                break;
                            }
                        case 2219:
                            {
                                if (client.Entity.MapID == 6002)
                                    break;
                                byte[] sed = new byte[36]
                        {
                        0x1C ,0x00 ,0xAB ,0x08 ,0x04 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0x00    //  ; «         
            ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x54 ,0x51 ,0x53 ,0x65     // ;            TQSe
            ,0x72 ,0x76 ,0x65 ,0x72                                         // ;rver
                        };
                                client.Send(sed);
                                break;

                            }
                        case 1063:
                            {
                                GamePackets.Guild_Pk pk = new Guild_Pk(client.Entity.UID);
                                pk.Send(client);
                                break;
                            }
                        /* case 2224:
                             {
                                 client.Send(packet);
                                 break;
                             }
                         case 2232:
                             {
                                 client.Send(packet);
                                 break;
                             }
                         case 2242:
                             {
                                 client.Send(packet);
                                 break;
                             }
                         case 2243:
                             {
                                 client.Send(packet);
                                 break;
                             }*/
                        /*case 2242://Request Arena ranking List 2245 2242 2244
                            {
                                //Code snippet that belongs to Ultimation
                                Game.ConquerStructures.TeamArena.Statistics.ShowWiners(client);
                                break;
                            }
                        case 2245:
                            {
                                client.TeamArenaStatistic.Send(client);
                                break;
                            }*/
                        /*case 2245:
                            {
                                client.Send(packet);
                                break;
                            }*/
                        /* case 2233:
                             {
                                 GamePackets.Team_Pk pk = new Team_Pk(client.Entity.UID);
                                 pk.Send(client);
                                 break;
                             }*/
                        /* case 2252:
                             {
                                 client.Send(packet);
                                 break;
                             }*/
                        /* case 2253:
                             {
                                 GamePackets.Team_PkComun pk = new Team_PkComun(client.Entity.UID);
                                 pk.Send(client);
                                 break;
                             }*/
                        case 1130:
                            {
                                if (client.Entity.TitlePacket != null)
                                {
                                    if (packet[9] == 4)
                                    {
                                        if (client.Entity.TitlePacket.dwParam2 != 0)
                                            client.Entity.TitlePacket.Send(client);
                                    }
                                    if (packet[9] == 3)
                                    {
                                        client.Entity.TitleActivated = packet[8];
                                        client.Send(packet);
                                        client.SendScreen(client.Entity.SpawnPacket, false);
                                    }
                                }
                                break;
                            }
                        #endregion

                        #region vipteleport
                        case 1128:
                            {
                                p1128 vp = new p1128(false);
                                vp.Deserialize(packet);
                                if (ServerBase.Constants.VipNo.Contains(client.Entity.MapID))
                                    return;
                                if (client.Entity.ContainsFlag(Network.GamePackets.Update.Flags.Ghost))
                                    return;
                                switch (vp.UID)
                                {
                                    case 0://player city teleport
                                        {
                                            switch (vp.UID2)
                                            {
                                                ////////////////////////////////////////////////////////////////////////////////////////////////////
                                                case 1://tc
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1002, 429, 378);
                                                    break;
                                                case 2://pc
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1011, 188, 264);
                                                    break;
                                                case 3://ac
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1020, 565, 562);
                                                    break;
                                                case 4://dc
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1000, 500, 650);
                                                    break;
                                                case 5://bc
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1015, 717, 571);
                                                    break;
                                                    ////////////////////////////////////////////////////////////////////////////////////////
                                                    {

                                                    }
                                                default: Console.WriteLine("Unknown 1128 portal subtype 1 : " + vp.UID2); break;
                                            }
                                            break;
                                        }
                                    case 1://Team city teleport
                                        {
                                            switch (vp.UID2)
                                            {
                                                ////////////////////////////////////////////////////////////////////////////////////////////////////
                                                case 1://tc
                                                    foreach (Client.GameState teammate in client.Entity.Owner.Team.Teammates)
                                                    {
                                                        if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, teammate.Entity.X, teammate.Entity.Y) <= 18)
                                                        {
                                                            if (client.Map.BaseID != 700)
                                                            {
                                                                teammate.Entity.Teleport(1002, 429, 378);
                                                            }
                                                        }
                                                    }
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1002, 429, 378);
                                                    break;
                                                case 2://pc
                                                    foreach (Client.GameState teammate in client.Entity.Owner.Team.Teammates)
                                                    {
                                                        if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, teammate.Entity.X, teammate.Entity.Y) <= 18)
                                                        {
                                                            if (client.Map.BaseID != 700)
                                                            {
                                                                teammate.Entity.Teleport(1011, 188, 264);
                                                            }
                                                        }
                                                    }
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1011, 188, 264);
                                                    break;
                                                case 3://ac
                                                    foreach (Client.GameState teammate in client.Entity.Owner.Team.Teammates)
                                                    {
                                                        if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, teammate.Entity.X, teammate.Entity.Y) <= 18)
                                                        {
                                                            if (client.Map.BaseID != 700)
                                                            {
                                                                teammate.Entity.Teleport(1020, 565, 562);
                                                            }
                                                        }
                                                    }
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1020, 565, 562);
                                                    break;
                                                case 4://dc
                                                    foreach (Client.GameState teammate in client.Entity.Owner.Team.Teammates)
                                                    {
                                                        if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, teammate.Entity.X, teammate.Entity.Y) <= 18)
                                                        {
                                                            if (client.Map.BaseID != 700)
                                                            {
                                                                teammate.Entity.Teleport(1000, 500, 650);
                                                            }
                                                        }
                                                    }
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1000, 500, 650);
                                                    break;
                                                case 5://bc
                                                    foreach (Client.GameState teammate in client.Entity.Owner.Team.Teammates)
                                                    {
                                                        if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, teammate.Entity.X, teammate.Entity.Y) <= 18)
                                                        {
                                                            if (client.Map.BaseID != 700)
                                                            {
                                                                teammate.Entity.Teleport(1015, 717, 571);
                                                            }
                                                        }
                                                    }
                                                    if (client.Map.BaseID != 700)
                                                        client.Entity.Teleport(1015, 717, 571);
                                                    break;
                                                    ////////////////////////////////////////////////////////////////////////////////////////
                                                    {

                                                    }
                                                default: Console.WriteLine("Unknown 1128 portal subtype 2 : " + vp.UID2); break;
                                            }
                                            break;
                                        }

                                    default:
                                        Console.WriteLine("Unknown 1128 subtype: " + vp.UID); break;
                                }
                                break;
                            }
                        #endregion
                        #region MentorApprentice (2065)
                        case 2065:
                            {
                                MentorApprentice ma = new MentorApprentice(false);
                                ma.Deserialize(packet);
                                switch (ma.Type)
                                {
                                    case MentorApprentice.LeaveMentor:
                                        {
                                            LeaveMentor(ma, client);
                                            break;
                                        }
                                    case MentorApprentice.ExpellApprentice:
                                        {
                                            ExpelApprentice(ma, client);
                                            break;
                                        }
                                    case MentorApprentice.RequestApprentice:
                                        {
                                            AddApprentice(ma, client);
                                            break;
                                        }
                                    case MentorApprentice.RequestMentor:
                                        {
                                            AddMentor(ma, client);
                                            break;
                                        }
                                    case MentorApprentice.AcceptRequestApprentice:
                                        {
                                            AcceptRequestApprentice(ma, client);
                                            break;
                                        }
                                    case MentorApprentice.AcceptRequestMentor:
                                        {
                                            AcceptRequestMentor(ma, client);
                                            break;
                                        }
                                }
                                break;
                            }
                        case 2066:
                            {
                                MentorInformation info = new MentorInformation(false);
                                info.Deserialize(packet);
                                if (info.Mentor_Type == 1)
                                {
                                    client.ReviewMentor();
                                }
                                break;
                            }
                        #endregion
                        #region Guild members (2102)
                        case 2102:
                            {
                                ushort Page = BitConverter.ToUInt16(packet, 8);
                                if (client.Guild != null)
                                {
                                    if (client.AsMember != null)
                                        client.Guild.SendMembers(client, Page);
                                }
                                break;
                            }
                        #endregion
                        #region Arena (2207<->2211)
                        case 2207://Request Arena ranking List 2245 2242 2244
                            {
                                //Code snippet that belongs to Ultimation
                                ushort PageIndex = BitConverter.ToUInt16(packet, 6);
                                Game.ConquerStructures.Arena.Statistics.ShowRankingPage(packet[4], PageIndex, client);
                                break;
                            }
                        case 2206:
                            {
                                //Code snippet that belongs to Ultimation
                                ushort PageIndex = BitConverter.ToUInt16(packet, 4);
                                Game.ConquerStructures.Arena.QualifyEngine.RequestGroupList(client, PageIndex);
                                break;
                            }
                        case 2205://Arena Signup!
                            {
                                //Code snippet that belongs to Ultimation
                                uint DialogID = BitConverter.ToUInt32(packet, 4);
                                uint ButtonID = BitConverter.ToUInt32(packet, 8);
                                switch (DialogID)
                                {
                                    case 4:
                                        {
                                            switch (ButtonID)
                                            {
                                                case 0:
                                                    {
                                                        Game.ConquerStructures.Arena.QualifyEngine.DoQuit(client);
                                                        break;
                                                    }
                                            }
                                            break;
                                        }
                                    case 0: Game.ConquerStructures.Arena.QualifyEngine.DoSignup(client); client.Send(packet); break;
                                    case 1: Game.ConquerStructures.Arena.QualifyEngine.DoQuit(client); client.Send(packet); break;
                                    case 3:
                                        {
                                            switch (ButtonID)
                                            {
                                                case 2: Game.ConquerStructures.Arena.QualifyEngine.DoGiveUp(client); break;
                                                case 1: Game.ConquerStructures.Arena.QualifyEngine.DoAccept(client); break;
                                            }
                                            break;
                                        }
                                    case 5:
                                        {
                                            if (client.ArenaStatistic.ArenaPoints <= 1500)
                                                if (client.Entity.Money >= 9000000)
                                                {
                                                    client.Entity.Money -= 9000000;
                                                    client.ArenaStatistic.ArenaPoints += 1500;
                                                    client.Send(client.ArenaStatistic);
                                                }
                                            break;
                                        }
                                    case 11://Win/Lose Dialog
                                        {
                                            switch (ButtonID)
                                            {
                                                case 0: Game.ConquerStructures.Arena.QualifyEngine.DoSignup(client); break;
                                            }
                                            break;
                                        }

                                }
                                break;
                            }
                        case 2208://Request Arena Winner List
                            {
                                //Code snippet that belongs to Ultimation
                                Game.ConquerStructures.Arena.Statistics.ShowWiners(client);
                                break;
                            }
                        case 2209:
                            {//bug in console
                                client.ArenaStatistic.Send(client);
                                break;
                            }
                        case 2211:
                            {
                                if (client.Map.BaseID == 6001 || client.Map.BaseID == 6000)
                                    return;
                                ushort Type = BitConverter.ToUInt16(packet, 4);
                                uint Fighter = BitConverter.ToUInt32(packet, 10);
                                if (Type == 0)
                                {
                                    if (ServerBase.Kernel.GamePool.ContainsKey(Fighter))
                                    {
                                        Client.GameState Client = ServerBase.Kernel.GamePool[Fighter];
                                        if (Client.QualifierGroup != null)
                                        {
                                            if (Client.QualifierGroup.Inside)
                                            {
                                                if (!Client.QualifierGroup.Done)
                                                {
                                                    Client.QualifierGroup.BeginWatching(client);
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (Type == 1)
                                {
                                    Game.ConquerStructures.Arena.QualifyEngine.DoLeave(client);
                                }
                                else if (Type == 4)
                                {
                                    string name = "";
                                    for (int c = 22; c < packet.Length; c++)
                                    {
                                        if (packet[c] != 0)
                                            name += (char)packet[c];
                                        else
                                            break;
                                    }
                                    Game.ConquerStructures.Arena.QualifyEngine.DoCheer(client, name);
                                }
                                break;
                            }
                        #endregion
                        #region Movement/Walk (10005)
                        case 10005:
                            {
                                if (client.Action != 2)
                                    return;
                                GroundMovement groundMovement = new GroundMovement(false);
                                groundMovement.Deserialize(packet);
                                PlayerGroundMovment(groundMovement, client);

                                break;
                            }
                        #endregion
                        //24 2533 53 152 1 0 0 0 84
                        //60 0 229 9 50 151 152 0 1 0 0 0 0 0 0 0 84 81 83 101 114 118 101 114
                        //3c 00 e5 09 32 97 98 00 01 00 00 00 00 00 00 00 54 51 53 65 72 76 65 72
                        /* case 2533:
                             {
                                 KimoChi prize = new KimoChi(false);
                                 prize.Deserialize(packet);
                                 client.Send(packet);
                                 client.Send(prize);
                                 break;

                             }*/
                        #region Lottery2
                        case 1314://1314
                            {

                                Game.Lottery.Handle(packet, client);
                                break;
                            }
                        #endregion
                        #region New AutoInvite
                        case 1126://1314
                            {

                                EventAlert2.Handle(packet, client);
                                break;
                            }
                        #endregion
                        #region ClanWar inv (1313)
                        case 1313://1313
                            {
                                if (packet[4] == 8)
                                {
                                    client.Entity.Teleport(1002, 413, 246);
                                }

                                return;
                            }
                        #endregion //packet[8] = 1;

                        #region ChangeName (2080)
                        case 2080:
                            {
                                NameChange prize = new NameChange(false);
                                //prize.EditAllowed = 1;
                                //prize.EditCount = 1;
                                prize.Deserialize(packet);

                                switch (prize.Action)//string name = System.Text.Encoding.UTF7.GetString(packet, 26, packet[25]);
                                {

                                    case PhoenixProject.Network.GamePackets.NameChange.NameChangeAction.Request:
                                        {
                                            string newname = System.Text.Encoding.UTF7.GetString(packet, 10, 16).TrimEnd('\0');

                                            packet[6] = (byte)client.Entity.EditeName;
                                            packet[8] = (byte)(5 - client.Entity.EditeName);
                                            prize.Send(client);
                                            client.Send(prize);
                                            if (newname != "")
                                            {
                                                if (newname == "")
                                                    return;
                                                if (newname.Contains("[") && newname.Contains("]"))
                                                    return;
                                                if (Dialogs.InvalidCharacters(newname) && Dialogs.InvalidCharacters3(newname) && !newname.Contains("[") && !newname.Contains("]"))
                                                {
                                                    PhoenixProject.Database.MySqlCommand cmd2 = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.SELECT).Select("entities").Where("name", newname);//debug and test!
                                                    PhoenixProject.Database.MySqlReader r = new PhoenixProject.Database.MySqlReader(cmd2);
                                                    if (!r.Read())//wait
                                                    {
                                                        if (client.Entity.ConquerPoints >= PhoenixProject.Database.rates.ChangeName)
                                                        {
                                                            client.Entity.ConquerPoints -= PhoenixProject.Database.rates.ChangeName;

                                                            // PhoenixProject.Database.MySqlCommand cmd = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                                                            //  cmd.Update("entities").Set("namechange", newname).Where("UID", client.Entity.UID).Execute();
                                                            r.Close();
                                                            r.Dispose();
                                                            client.Entity.NewName = newname;

                                                            // Console.WriteLine(client.Entity.Name + ", Changed hes Name to : " + newname);
                                                            ServerBase.Kernel.SendWorldMessage(new Message(client.Entity.Name + ", Changed He's/Hers Name to " + newname + ", Will be affected after  Relogin.",
                                                                System.Drawing.Color.Red, Message.Talk), ServerBase.Kernel.GamePool.Values);

                                                            // client.Edita = 0;
                                                            // client.Edite = 1;
                                                            client.Entity.EditeName += 1;
                                                            packet[4] = 1;
                                                            prize.Send(client);
                                                            client.Send(prize);
                                                            Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Your new name is : " + newname + ", After relog You will get your new name, Want to Relog?");
                                                            npc.OptionID = 244;
                                                            client.Send(npc.ToArray());
                                                        }
                                                        else
                                                        {
                                                            Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Come back when you have " + PhoenixProject.Database.rates.ChangeName + " CPS.");
                                                            npc.OptionID = 255;
                                                            client.Send(npc.ToArray());
                                                            r.Close();
                                                            r.Dispose();

                                                        }
                                                    }
                                                    else
                                                    {
                                                        packet[4] = 2;
                                                        prize.Send(client);
                                                        client.Send(prize);
                                                        r.Close();
                                                        r.Dispose();

                                                    }
                                                }
                                                else
                                                {
                                                    Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "im sorry not allowed now close the dialog and try again");
                                                    npc.OptionID = 255;
                                                    client.Send(npc.ToArray());
                                                    //r.Close();
                                                    //r.Dispose();

                                                }
                                            }
                                            break;
                                        }
                                }
                                //packet[8] = 1;
                                //byte NewClass = packet[4];
                                //ushort NewBody = packet[8];

                                break;
                            }
                        #endregion

                        #region Reincarnation (1066)
                        case 1066:
                            {
                                if (client.Entity.Reborn != 2) return;
                                if (ServerBase.Kernel.ReincarnatedCharacters.ContainsKey(client.Entity.UID))
                                    return;
                                byte NewClass = packet[4];
                                ushort NewBody = packet[8];
                                if (client.Entity.Body.ToString().EndsWith("1") || client.Entity.Body.ToString().EndsWith("2"))
                                    NewBody += 2000;
                                else NewBody += 1000;

                                if (client.Inventory.Contains(711083, 1) && client.Entity.ConquerPoints >= PhoenixProject.Database.rates.Riencration)
                                {
                                    client.Entity.Body = NewBody;
                                    new PacketHandler.Reincarnation(client, NewClass);
                                    client.Inventory.Remove(711083, 1);
                                    client.Entity.ConquerPoints -= PhoenixProject.Database.rates.Riencration;
                                }
                                break;
                            }
                        #endregion
                        #region PurifyItem (2076)
                        case 2076:
                            {
                                Purification ps = new Purification(false);
                                ps.Deserialize(packet);
                                switch (ps.Mode)
                                {
                                    case Purification.Purify:
                                        PurifyItem(ps, client); break;
                                    case Purification.ItemArtifact:
                                        PurifyRefinery(ps, client); break;
                                    //case Purification.Stabilaze:
                                    //new Game.Features.Refinery.Handle(packet, client); break;
                                }
                                break;
                            }
                        #endregion
                        #region KimoClans
                        case 1312:
                            {
                                //GameState targets;
                                switch (packet[4])
                                {
                                    case 21:
                                        {

                                            if (client.Entity.Myclan != null)
                                            {
                                                try
                                                {
                                                    uint lider = 0;
                                                    string name_receive = System.Text.Encoding.UTF7.GetString(packet, 18, packet[17]);

                                                    foreach (Client.GameState clien in ServerBase.Kernel.GamePool.Values)
                                                    {

                                                        if (clien.Entity.Name == name_receive)
                                                        {
                                                            lider = clien.Entity.UID;
                                                        }
                                                    }

                                                    if (lider == client.Entity.UID) return;
                                                    Client.GameState aClient = null;
                                                    if (PhoenixProject.ServerBase.Kernel.GamePool.TryGetValue(lider, out aClient))
                                                    {

                                                        if (PhoenixProject.ServerBase.Kernel.ServerClans.ContainsKey(client.Entity.Myclan.ClanId))
                                                        {
                                                            if (PhoenixProject.ServerBase.Kernel.ServerClans[client.Entity.Myclan.ClanId].Members.ContainsKey(aClient.Entity.UID))
                                                            {
                                                                PhoenixProject.ServerBase.Kernel.ServerClans[client.Entity.Myclan.ClanId].ClanLider = aClient.Entity.Name;
                                                                aClient.Entity.ClanRank = 100;
                                                                aClient.Entity.Myclan.Members[aClient.Entity.UID].Rank = 100;
                                                                //if (aClient.Entity.Myclan.Members.ContainsKey(client.Entity.UID))
                                                                //aClient.Entity.Myclan.Members[client.Entity.UID].Rank = 0;
                                                                client.Entity.ClanRank = 10;
                                                                client.Entity.Myclan.Members[client.Entity.UID].Rank = 10;
                                                                Database.Clans.SaveClan(aClient.Entity.Myclan);
                                                                //Database.Clans.JoinClan(client);
                                                                Network.GamePackets.Clan cl = new PhoenixProject.Network.GamePackets.Clan(client, 1);
                                                                client.Send(cl.ToArray());
                                                                ClanMembers clan = new ClanMembers(client);
                                                                client.Send(clan.ToArray());
                                                                Network.GamePackets.Clan cls = new PhoenixProject.Network.GamePackets.Clan(aClient, 1);
                                                                aClient.Send(cls.ToArray());
                                                                ClanMembers clans = new ClanMembers(aClient);
                                                                aClient.Send(clans.ToArray());
                                                                ServerBase.Kernel.GamePool[aClient.Entity.UID].Screen.FullWipe();
                                                                ServerBase.Kernel.GamePool[aClient.Entity.UID].Screen.Reload(null);
                                                                ServerBase.Kernel.GamePool[client.Entity.UID].Screen.FullWipe();
                                                                ServerBase.Kernel.GamePool[client.Entity.UID].Screen.Reload(null);
                                                            }
                                                        }

                                                    }
                                                    else
                                                    {
                                                        PhoenixProject.ServerBase.Kernel.ServerClans[client.Entity.Myclan.ClanId].ClanLider = name_receive;
                                                        client.Entity.ClanRank = 10;
                                                        client.Entity.Myclan.Members[client.Entity.UID].Rank = 10;
                                                        Database.Clans.SaveClan(client.Entity.Myclan);
                                                        Database.Clans.TransferClan(name_receive);
                                                        Network.GamePackets.Clan cl = new PhoenixProject.Network.GamePackets.Clan(client, 1);
                                                        client.Send(cl.ToArray());
                                                        ClanMembers clan = new ClanMembers(client);
                                                        client.Send(clan.ToArray());
                                                        ServerBase.Kernel.GamePool[client.Entity.UID].Screen.FullWipe();
                                                        ServerBase.Kernel.GamePool[client.Entity.UID].Screen.Reload(null);
                                                        //Console.WriteLine("gggf");

                                                    }
                                                }
                                                catch (Exception e)
                                                {
                                                    Program.SaveException(e);
                                                }
                                            }
                                            break;
                                        }

                                    case (byte)Game.Clan_Typ.Quit:
                                        {
                                            if (client.Entity.Myclan != null)
                                            {
                                                if (client.Entity.ClanRank != 100)
                                                {
                                                    client.Entity.Myclan.ExpelMember(client.Entity.Name, true);
                                                }
                                            }

                                            break;
                                        }
                                    case 25:
                                        {
                                            if (client.Entity.Myclan == null) return;
                                            string buletin = System.Text.Encoding.UTF7.GetString(packet, 18, packet[17]);
                                            if (PhoenixProject.ServerBase.Kernel.ServerClans.ContainsKey(client.Entity.Myclan.ClanId))
                                                PhoenixProject.ServerBase.Kernel.ServerClans[client.Entity.Myclan.ClanId].ClanBuletion = buletin;
                                            Database.Clans.SaveClan(PhoenixProject.ServerBase.Kernel.ServerClans[client.Entity.Myclan.ClanId]);
                                            client.Send(packet);
                                            break;
                                        }
                                    case 22:
                                        {
                                            if (client.Entity.Myclan != null)
                                            {
                                                if (client.Entity.ClanRank == 100)
                                                {
                                                    string name = System.Text.Encoding.UTF7.GetString(packet, 18, packet[17]);
                                                    if (client.Entity.Myclan != null)
                                                    {
                                                        if (client.Entity.ClanRank == 100)
                                                        {
                                                            client.Entity.Myclan.ExpelMember(name, false);
                                                            Database.Clans.KickClan(name);
                                                        }
                                                    }

                                                }
                                            }

                                            break;
                                        }

                                    case 26:
                                        {
                                            uint money = BitConverter.ToUInt32(packet, 8);
                                            if (client.Entity.Money >= money && client.Entity.Myclan != null)
                                            {
                                                client.Entity.Myclan.Members[client.Entity.UID].Donation += money;
                                                client.Entity.Money -= money;
                                                if (PhoenixProject.ServerBase.Kernel.ServerClans.ContainsKey(client.Entity.Myclan.ClanId))
                                                    PhoenixProject.ServerBase.Kernel.ServerClans[client.Entity.Myclan.ClanId].ClanDonation += money;
                                                Network.GamePackets.Clan cl = new PhoenixProject.Network.GamePackets.Clan(client, 1);
                                                client.Send(cl.ToArray());
                                                Database.Clans.SaveClientDonation(client);
                                                Database.Clans.SaveClan(PhoenixProject.ServerBase.Kernel.ServerClans[client.Entity.Myclan.ClanId]);
                                            }
                                            break;
                                        }
                                    case 11:
                                        {

                                            uint lider = BitConverter.ToUInt32(packet, 8);
                                            if (PhoenixProject.ServerBase.Kernel.GamePool.ContainsKey(lider))
                                            {
                                                packet[4] = 11;
                                                Network.Writer.WriteUInt32(client.Entity.UID, 8, packet);
                                                packet[16] = 1;
                                                packet[17] = (byte)client.Entity.Name.Length;
                                                for (int i = 0; i < client.Entity.Name.Length; i++)
                                                {
                                                    try
                                                    {
                                                        packet[18 + i] = Convert.ToByte(client.Entity.Name[i]);

                                                    }
                                                    catch { }
                                                }
                                                if (PhoenixProject.ServerBase.Kernel.GamePool[lider].Entity.Myclan != null)
                                                    PhoenixProject.ServerBase.Kernel.GamePool[lider].Send(packet);
                                            }
                                            break;
                                        }
                                    case 12:
                                        {
                                            if (packet[16] == 1)
                                            {
                                                if (client.Entity.Myclan != null)
                                                    if (client.Entity.Myclan.Members[client.Entity.UID].Rank == 100)
                                                    {
                                                        {
                                                            if (client.Entity.Myclan.Members.Count < 7)
                                                            {

                                                                uint memeber = BitConverter.ToUInt32(packet, 8);
                                                                if (ServerBase.Kernel.GamePool.ContainsKey(memeber))
                                                                {
                                                                    Game.ClanMembers member = new PhoenixProject.Game.ClanMembers();
                                                                    member.UID = ServerBase.Kernel.GamePool[memeber].Entity.UID;
                                                                    member.Donation = 0;
                                                                    member.Rank = 10;
                                                                    member.Class = ServerBase.Kernel.GamePool[memeber].Entity.Class;
                                                                    member.Level = ServerBase.Kernel.GamePool[memeber].Entity.Level;
                                                                    member.Name = ServerBase.Kernel.GamePool[memeber].Entity.Name;
                                                                    if (!client.Entity.Myclan.Members.ContainsKey(memeber))
                                                                        client.Entity.Myclan.Members.Add(member.UID, member);

                                                                    ServerBase.Kernel.GamePool[memeber].Entity.ClanRank = 10;
                                                                    ServerBase.Kernel.GamePool[memeber].Entity.ClanId = client.Entity.ClanId;
                                                                    ServerBase.Kernel.GamePool[memeber].Entity.Myclan = client.Entity.Myclan;
                                                                    ServerBase.Kernel.GamePool[memeber].Entity.ClanName = client.Entity.ClanName;
                                                                    Database.Clans.JoinClan(ServerBase.Kernel.GamePool[memeber]);
                                                                    ServerBase.Kernel.GamePool[memeber].Screen.FullWipe();
                                                                    ServerBase.Kernel.GamePool[memeber].Screen.Reload(null);
                                                                    Network.GamePackets.Clan cl = new PhoenixProject.Network.GamePackets.Clan(client, 1);
                                                                    client.Send(cl.ToArray());
                                                                    ClanMembers clan = new ClanMembers(client);
                                                                    client.Send(clan.ToArray());
                                                                }
                                                            }
                                                        }
                                                    }
                                            }
                                            break;
                                        }
                                    case 4:
                                        {
                                            ClanMembers clan = new ClanMembers(client);
                                            client.Send(clan.ToArray());
                                            break;
                                        }
                                    case 0x1d:
                                        {
                                            if (client.Entity.Myclan != null)
                                            {
                                                Network.Writer.WriteUInt32(client.Entity.Myclan.ClanId, 8, packet);
                                                Network.Writer.WriteByte(1, 16, packet);
                                                Network.Writer.WriteByte(0x0d, 17, packet);
                                                Network.Writer.WriteString("0 0 0 0 0 0 0", 18, packet);
                                                client.Send(packet);
                                                Network.GamePackets.Clan cl = new PhoenixProject.Network.GamePackets.Clan(client, 1);
                                                client.Send(cl.ToArray());
                                                client.Send(packet);

                                                if (client.Entity.Myclan.ClanBuletion != "")
                                                    client.Send(cl.UpgradeBuletin(client.Entity.Myclan.ClanBuletion));
                                            }
                                            else
                                            {
                                                client.Send(packet);
                                                packet[4] = 23;
                                            }

                                            break;
                                        }
                                    case 0x18:
                                        {
                                            client.Send(packet);
                                            break;
                                        }
                                    case (byte)Game.Clan_Typ.AddAlly:
                                        {
                                            Game.Clans clan = client.Entity.Myclan;
                                            if (clan != null)
                                            {
                                                Client.GameState target;
                                                UInt32 Identifier = BitConverter.ToUInt32(packet, 8);

                                                if (client.Entity.ClanRank == 100)
                                                {
                                                    if (clan.Allies.Count >= 5)
                                                    { client.Send(new Message("The Amount of Allies You can Have is exceeded", System.Drawing.Color.Red, Message.TopLeft)); break; }

                                                    if (ServerBase.Kernel.GamePool.TryGetValue(Identifier, out target))
                                                    {
                                                        Game.Clans tclan = target.Entity.Myclan;
                                                        if (tclan != null)
                                                        {
                                                            if (target.Entity.ClanRank == 100)
                                                            {
                                                                if (tclan.Allies.Count >= 5)
                                                                { client.Send(new Message("The Amount of Allies the Target Clan can Have is exceeded", System.Drawing.Color.Red, Message.TopLeft)); break; }

                                                                if (!clan.Allies.ContainsKey(tclan.ClanId))
                                                                {
                                                                    if (!clan.Enemies.ContainsKey(tclan.ClanId))
                                                                    {
                                                                        String clanName = client.Entity.ClanName;

                                                                        Clan2 clanp = new Clan2();

                                                                        clanp.Deserialize(packet);

                                                                        clanp.Offset16 = 2;
                                                                        clanp.Identifier = client.Entity.UID;

                                                                        Writer.WriteByte((Byte)clanName.Length, 17, clanp.ToArray());
                                                                        Writer.WriteString(clanName, 18, clanp.ToArray());

                                                                        tclan.AllyRequest = clan.ClanId;

                                                                        target.Send(clanp);
                                                                    }
                                                                    else client.Send(new Message("The clan is Your Enemy.", System.Drawing.Color.Red, Message.TopLeft));
                                                                }
                                                            }
                                                            else client.Send(new Message("This target is not the clan leader.", System.Drawing.Color.Red, Message.TopLeft));
                                                        }
                                                    }
                                                    else client.Send(new Message("Can not find target.", System.Drawing.Color.Red, Message.TopLeft));
                                                }
                                                else client.Send(new Message("You are not the clan leader.", System.Drawing.Color.Red, Message.TopLeft));
                                            }
                                            break;
                                        }
                                    case (byte)Game.Clan_Typ.AcceptAlliance:
                                        {
                                            Game.Clans clan = client.Entity.Myclan;
                                            if (clan != null)
                                            {
                                                if (client.Entity.ClanRank == 100)
                                                {
                                                    Game.Clans tclan;
                                                    if (ServerBase.Kernel.ServerClans.TryGetValue(clan.AllyRequest, out tclan))
                                                    {
                                                        if (tclan != null)
                                                        {
                                                            if (!tclan.Enemies.ContainsKey(clan.ClanId))
                                                            {
                                                                if (!clan.Enemies.ContainsKey(tclan.ClanId))
                                                                {
                                                                    if (!clan.Allies.ContainsKey(tclan.ClanId))
                                                                        clan.Allies.Add(tclan.ClanId, tclan);

                                                                    tclan.Allies.Add(clan.ClanId, clan);

                                                                    clan.SendMessage(new ClanRelations(clan, ClanRelations.RelationTypes.Allies));
                                                                    tclan.SendMessage(new ClanRelations(tclan, ClanRelations.RelationTypes.Allies));

                                                                    clan.SendMessage(new Message(String.Format("Our Clan has Allianced with {0}", tclan.ClanName), System.Drawing.Color.Red, Message.Clan));
                                                                    tclan.SendMessage(new Message(String.Format("Our Clan has Allianced with {0}", clan.ClanName), System.Drawing.Color.Red, Message.Clan));

                                                                    clan.AddRelation(tclan.ClanId, ClanRelations.RelationTypes.Allies);
                                                                    tclan.AddRelation(clan.ClanId, ClanRelations.RelationTypes.Allies);

                                                                    clan.AllyRequest = tclan.AllyRequest = 0;
                                                                }
                                                                else client.Send(new Message("This Clan is Your Enemy.", System.Drawing.Color.Red, Message.TopLeft));
                                                            }
                                                            client.Send(new Message("This Clan Has Enemied You!.", System.Drawing.Color.Red, Message.TopLeft));
                                                        }
                                                    }
                                                    else client.Send(new Message("Can not find target", System.Drawing.Color.Red, Message.TopLeft));
                                                }
                                                else client.Send(new Message("You are not the clan leader.", System.Drawing.Color.Red, Message.TopLeft));
                                            }
                                            break;
                                        }
                                    case (byte)Game.Clan_Typ.DeleteEnemy:
                                        {
                                            Game.Clans clan = client.Entity.Myclan;
                                            if (clan != null)
                                            {
                                                if (client.Entity.ClanRank == 100)
                                                {
                                                    Clan2 clanp = new Clan2();
                                                    clanp.Deserialize(packet);

                                                    String EnemyTarget = clanp.Offset18String;
                                                    UInt32 ClanId = clanp.GetClanId(EnemyTarget);

                                                    Game.Clans tclan;
                                                    if (ServerBase.Kernel.ServerClans.TryGetValue(ClanId, out tclan))
                                                    {
                                                        clan.Enemies.Remove(ClanId);

                                                        clan.DeleteRelation(ClanId, ClanRelations.RelationTypes.Enemies);

                                                        clan.SendMessage(new ClanRelations(clan, ClanRelations.RelationTypes.Enemies));

                                                        clan.SendMessage(new Message(String.Format("We are no longer Enemies With {0}", clan.ClanId), System.Drawing.Color.Red, Message.Clan));

                                                        client.Send(clanp);
                                                    }
                                                }
                                                else client.Send(new Message("You are not authorized to continue with this action", System.Drawing.Color.Red, Message.TopLeft));
                                            }
                                            break;
                                        }
                                    case (byte)Game.Clan_Typ.DeleteAlly:
                                        {
                                            Game.Clans clan = client.Entity.Myclan;
                                            if (clan != null)
                                            {
                                                if (client.Entity.ClanRank == 100)
                                                {
                                                    Clan2 clanp = new Clan2();
                                                    clanp.Deserialize(packet);

                                                    String AlliedTarget = clanp.Offset18String;
                                                    UInt32 ClanId = clanp.GetClanId(AlliedTarget);

                                                    Game.Clans tclan;
                                                    if (clan.Allies.TryGetValue(ClanId, out tclan))
                                                    {
                                                        clan.Allies.Remove(ClanId);
                                                        tclan.Allies.Remove(clan.ClanId);

                                                        clan.DeleteRelation(ClanId, ClanRelations.RelationTypes.Allies);
                                                        tclan.DeleteRelation(clan.ClanId, ClanRelations.RelationTypes.Allies);

                                                        clan.SendMessage(new ClanRelations(clan, ClanRelations.RelationTypes.Allies));
                                                        tclan.SendMessage(new ClanRelations(tclan, ClanRelations.RelationTypes.Allies));

                                                        clan.SendMessage(new Message(String.Format("We are no longer allied with {0}", tclan.ClanName), System.Drawing.Color.Red, Message.Clan));
                                                        tclan.SendMessage(new Message(String.Format("We are no longer allied with {0}", clan.ClanName), System.Drawing.Color.Red, Message.Clan));

                                                        client.Send(clanp);
                                                    }
                                                }
                                                else client.Send(new Message("You are not authorized to continue with this action", System.Drawing.Color.Red, Message.TopLeft));
                                            }
                                            break;
                                        }
                                    case (byte)Game.Clan_Typ.AddEnemy:
                                        {
                                            Game.Clans clan = client.Entity.Myclan;
                                            if (clan != null)
                                            {
                                                if (client.Entity.ClanRank == 100)
                                                {
                                                    String Enemy = System.Text.Encoding.UTF7.GetString(packet, 18, packet[17]).Trim(new Char[] { '\0' });
                                                    UInt32 ClanId = 0;
                                                    var AllCland = ServerBase.Kernel.ServerClans.Values.ToArray();
                                                    foreach (Game.Clans c_clan in AllCland)
                                                    {
                                                        if (Enemy == c_clan.ClanName)
                                                        {
                                                            ClanId = c_clan.ClanId;
                                                            break;
                                                        }
                                                    }
                                                    if (ClanId == 0) break;
                                                    if (!clan.Enemies.ContainsKey(ClanId))
                                                    {
                                                        if (!clan.Allies.ContainsKey(ClanId))
                                                        {
                                                            if (clan.Enemies.Count >= 5)
                                                            { client.Send(new Message("The Ammount of Enemies You can Have is exceeded", System.Drawing.Color.Red, Message.TopLeft)); break; }

                                                            Game.Clans tclan;
                                                            if (ServerBase.Kernel.ServerClans.TryGetValue(ClanId, out tclan))
                                                            {
                                                                if (!clan.Enemies.ContainsKey(tclan.ClanId))
                                                                    clan.Enemies.Add(tclan.ClanId, tclan);

                                                                clan.AddRelation(ClanId, ClanRelations.RelationTypes.Enemies);

                                                                clan.SendMessage(new ClanRelations(clan, ClanRelations.RelationTypes.Enemies));

                                                                clan.SendMessage(new Message(String.Format("We Have Enemied the clan {0}", tclan.ClanName), System.Drawing.Color.Red, Message.Clan));
                                                                tclan.SendMessage(new Message(String.Format("The Clan {0} Has Made us their Enemy!", clan.ClanName), System.Drawing.Color.Red, Message.Clan));
                                                            }
                                                        }
                                                        else client.Send(new Message("This clan is one of your alliance, What has gone wrong?", System.Drawing.Color.Red, Message.TopLeft));
                                                    }
                                                    else client.Send(new Message("This clan is Already One of Your Enemies", System.Drawing.Color.Red, Message.TopLeft));
                                                }
                                            }
                                            break;
                                        }
                                    default:
                                        Console.WriteLine("Clan Type " + packet[4]);
                                        break;

                                }
                                break;
                            }
                        #endregion
                        #region SubClass (2320)
                        case 2320:
                            {
                                byte[] Packet = null;
                                switch (packet[4])
                                {
                                    //9 = learn 10= upgrade pro
                                    #region [Restore/Switch]
                                    case 0:
                                        byte To = packet[6];
                                        Packet = new byte[0];
                                        client.Send(packet);
                                        if (To > 0)//Switch
                                        {
                                            /*switch ((Game.ClassID)To)
                                            {
                                                case Game.ClassID.Wrangler:
                                                    {
                                                        switch (client.Entity.SubClasses.Classes[To].Level)
                                                        {
                                                            case 9:
                                                                {
                                                                    //client.Entity.Hitpoints += 1200;
                                                                    //client.Entity.MaxHitpoints += 1200;
                                                                    break;
                                                                }
                                                        }
                                                        break;
                                                    }
                                            }*/
                                            Packet = new byte[0];
                                            Packet = new SubClassShowFull(true) { ID = 1, Class = To, Level = client.Entity.SubClasses.Classes[To].Phase }.ToArray();//client.Entity.SubClasses.Classes[To].Phase
                                            client.Send(Packet);
                                            //Packet = new SubClass(client.Entity).ToArray();
                                            //client.Send(Packet);
                                            client.Entity.SubClass = To;
                                            /// client.Entity.SubClassLevel = client.Entity.SubClasses.Classes[To].Level;
                                            client.Entity.SubClasses.Active = To;
                                            client.Entity.SubClassesActive = To;
                                            // Console.WriteLine("s " + To + "");
                                        }
                                        else//Restore
                                        {
                                            client.Entity.SubClass = 0;
                                            //client.Entity.SubClassLevel = 0;
                                            client.Entity.SubClasses.Active = 0;
                                            client.Entity.SubClassesActive = 0;
                                            Packet = new SubClassShowFull(true) { ID = 1 }.ToArray();
                                            client.Send(Packet);
                                        }
                                        client.SendScreen(client.Entity.SpawnPacket, false);
                                        break;
                                    #endregion
                                    #region [Upgrade]
                                    case 2:
                                        {
                                            byte Class = packet[6];
                                            ushort Required = 0;
                                            Statement.SubClass Sc = client.Entity.SubClasses.Classes[Class];
                                            #region [Set Required]
                                            switch ((Statement.ClassID)Sc.ID)
                                            {
                                                case Statement.ClassID.MartialArtist:
                                                    switch (Sc.Level)
                                                    {
                                                        case 1: Required = 300; break;
                                                        case 2: Required = 900; break;
                                                        case 3: Required = 1800; break;
                                                        case 4: Required = 2700; break;
                                                        case 5: Required = 3600; break;
                                                        case 6: Required = 5100; break;
                                                        case 7: Required = 6900; break;
                                                        case 8: Required = 8700; break;
                                                        case 9: Required = ushort.MaxValue; break;
                                                    }
                                                    break;
                                                case Statement.ClassID.Warlock:
                                                    switch (Sc.Level)
                                                    {
                                                        case 1: Required = 300; break;
                                                        case 2: Required = 900; break;
                                                        case 3: Required = 1800; break;
                                                        case 4: Required = 2700; break;
                                                        case 5: Required = 3600; break;
                                                        case 6: Required = 5100; break;
                                                        case 7: Required = 6900; break;
                                                        case 8: Required = 8700; break;
                                                        case 9: Required = ushort.MaxValue; break;
                                                    }
                                                    break;
                                                case Statement.ClassID.ChiMaster:
                                                    switch (Sc.Level)
                                                    {
                                                        case 1: Required = 600; break;
                                                        case 2: Required = 1800; break;
                                                        case 3: Required = 3600; break;
                                                        case 4: Required = 5400; break;
                                                        case 5: Required = 7200; break;
                                                        case 6: Required = 10200; break;
                                                        case 7: Required = 13800; break;
                                                        case 8: Required = 17400; break;
                                                        case 9: Required = ushort.MaxValue; break;
                                                    }
                                                    break;
                                                case Statement.ClassID.Sage:
                                                    switch (Sc.Level)
                                                    {
                                                        case 1: Required = 400; break;
                                                        case 2: Required = 1200; break;
                                                        case 3: Required = 2400; break;
                                                        case 4: Required = 3600; break;
                                                        case 5: Required = 4800; break;
                                                        case 6: Required = 6800; break;
                                                        case 7: Required = 9200; break;
                                                        case 8: Required = 11600; break;
                                                        case 9: Required = ushort.MaxValue; break;
                                                    }
                                                    break;
                                                case Statement.ClassID.Apothecary:
                                                    switch (Sc.Level)
                                                    {
                                                        case 1: Required = 100; break;
                                                        case 2: Required = 200; break;
                                                        case 3: Required = 300; break;
                                                        case 4: Required = 400; break;
                                                        case 5: Required = 500; break;
                                                        case 6: Required = 1000; break;
                                                        case 7: Required = 4000; break;
                                                        case 8: Required = 9000; break;
                                                        case 9: Required = ushort.MaxValue; break;
                                                    }
                                                    break;
                                                case Statement.ClassID.Wrangler:
                                                case Statement.ClassID.Performer:
                                                    switch (Sc.Level)
                                                    {
                                                        case 1: Required = 400; break;
                                                        case 2: Required = 1200; break;
                                                        case 3: Required = 2400; break;
                                                        case 4: Required = 3600; break;
                                                        case 5: Required = 4800; break;
                                                        case 6: Required = 6800; break;
                                                        case 7: Required = 9200; break;
                                                        case 8: Required = 11600; break;
                                                        case 9: Required = ushort.MaxValue; break;
                                                    }
                                                    break;
                                            }
                                            #endregion
                                            if (client.Entity.SubClasses.StudyPoints >= Required)
                                            {
                                                client.Entity.SubClasses.StudyPoints -= Required;
                                                client.Entity.SubClasses.Classes[Class].Level++;
                                                Packet = new byte[0];
                                                Packet = new SubClassShowFull(true) { ID = 1, Class = Class, Level = client.Entity.SubClasses.Classes[Class].Level }.ToArray();
                                                client.Send(Packet);
                                                Packet = new SubClass(client.Entity).ToArray();
                                                client.Send(Packet);
                                                Database.SubClassTable.Update(client.Entity, client.Entity.SubClasses.Classes[Class]);
                                                //Database.SubClassTable.Update(client);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region [Info]
                                    case 6:
                                        Game.Entity Owner = client.Entity;
                                        if (Owner.SubClasses.Classes.Count > 0)
                                        {
                                            Statement.SubClass[] Classes = new Statement.SubClass[Owner.SubClasses.Classes.Count];
                                            Owner.SubClasses.Classes.Values.CopyTo(Classes, 0);
                                            foreach (Statement.SubClass Class in Classes)
                                            {
                                                if (Class.ID == 9)
                                                {
                                                    for (byte i = 0; i < Class.Phase; i++)
                                                    {
                                                        Packet = new byte[0];
                                                        Packet = new SubClassShowFull(true) { ID = 4, Class = Class.ID, Level = Class.Level }.ToArray();
                                                        client.Send(Packet);
                                                    }
                                                    continue;
                                                }
                                                Packet = new byte[0];
                                                Packet = new SubClassShowFull(true) { ID = 4, Class = Class.ID, Level = Class.Level }.ToArray();
                                                client.Send(Packet);
                                            }
                                        }
                                        Packet = new SubClass(client.Entity).ToArray();
                                        client.Send(Packet);
                                        break;
                                    #endregion
                                    #region [Learn]
                                    case 9://class type packet6
                                        byte Class1 = packet[6];
                                        if (PacketHandler.PassLearn((byte)packet[6], client.Entity))
                                        {
                                            if (!client.Entity.SubClasses.Classes.ContainsKey((byte)packet[6]))
                                            {
                                                {
                                                    client.Entity.SubClasses.Classes.Add((byte)packet[6], new PhoenixProject.Statement.SubClass() { ID = (byte)packet[6], Level = 1, Phase = 1 });
                                                    PhoenixProject.Database.SubClassTable.Insert(client.Entity, (byte)packet[6]);
                                                    Packet = new byte[0];
                                                    Packet = new SubClassShowFull(true) { ID = 1, Class = Class1, Level = client.Entity.SubClasses.Classes[Class1].Level }.ToArray();
                                                    client.Send(Packet);
                                                    Packet = new SubClass(client.Entity).ToArray();
                                                    client.Send(Packet);
                                                }
                                            }
                                        }

                                        break;
                                    #endregion
                                    #region [UpgradePro]
                                    case 10:
                                        byte Class2 = packet[6];

                                        if (client.Entity.SubClasses.Classes[(byte)Class2].Phase < client.Entity.SubClasses.Classes[(byte)Class2].Level)
                                        {
                                            client.Entity.SubClasses.Classes[(byte)Class2].Phase++;
                                            Database.SubClassTable.Update(client.Entity, client.Entity.SubClasses.Classes[(byte)Class2]);
                                            Packet = new byte[0];
                                            Packet = new SubClassShowFull(true) { ID = 1, Class = Class2, Level = client.Entity.SubClasses.Classes[Class2].Level }.ToArray();
                                            client.Send(Packet);
                                            Packet = new SubClass(client.Entity).ToArray();
                                            client.Send(Packet);
                                        }

                                        break;
                                    #endregion
                                    default:
                                        Console.WriteLine("Unknown 2320 packet type " + packet[4]);
                                        break;
                                }
                                break;
                            }
                        #endregion
                        #region ItemAdding Stabilization
                        case 1038:
                            {
                                ItemAddingStabilization stabilization = new ItemAddingStabilization(false);
                                stabilization.Deserialize(packet);
                                StabilazeArtifact(stabilization, client);
                                break;
                            }
                        #endregion
                        #region Data (10010)
                        case 10010:
                            {

                                if (client.Action != 2)
                                    return;
                                Data gData = new Data(false);
                                gData.Deserialize(packet);
                                if (client.Account.State == PhoenixProject.Database.AccountTable.AccountState.Coder)
                                {
                                    client.Send(new Message("Data ID: " + gData.ID, System.Drawing.Color.CadetBlue, Message.Talk));
                                }
                                switch (gData.ID)
                                {
                                    /*case Data.AllowAnimation:
                                        {
                                            LoginMessages(client);
                                            client.Send(new FlowerPacket(client.Entity.Flowers));
                                            //Database.SubClassTable.Load(client.Entity);
                                            ClientEquip equips = new ClientEquip();
                                            equips.DoEquips(client);
                                            client.Send(equips);
                                            client.Send(packet);
                                        }
                                        break;*/
                                    #region Appearance
                                    case 0xb2:
                                        {
                                            byte appearance = (byte)gData.dwParam;
                                            Data app = new Data(true)
                                            {
                                                ID = 0xb2,
                                                UID = client.Entity.UID,
                                                dwParam = appearance,
                                                wParam1 = client.Entity.X,
                                                wParam2 = client.Entity.Y
                                            };
                                            client.Send(gData);
                                            client.Send(app);
                                            client.SendScreen(gData, true);
                                            client.SendScreen(app, true);
                                            return;
                                        }
                                    #endregion
                                    case 132:
                                        {
                                            // Console.WriteLine(" this ");
                                            client.Disconnect();
                                            break;
                                        }
                                    /* case Data.KimoGearDis:
                                         {
                                             Console.WriteLine("data " + gData.dwParam + "");
                                             break;
                                         }*/
                                    case Data.UpdateProf:
                                        if (client != null)
                                        {
                                            ushort UplevelProficiency;
                                            UplevelProficiency = (ushort)gData.dwParam;

                                            var prof = client.Proficiencies[UplevelProficiency];

                                            if ((prof.Level >= 1) && (prof.Level <= 19))
                                            {
                                                if (prof.Level == 19 && client.Entity.ConquerPoints >= 1420)
                                                {
                                                    client.Entity.ConquerPoints -= 1420;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 18 && client.Entity.ConquerPoints >= 1154)
                                                {
                                                    client.Entity.ConquerPoints -= 1154;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 17 && client.Entity.ConquerPoints >= 799)
                                                {
                                                    client.Entity.ConquerPoints -= 799;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 16 && client.Entity.ConquerPoints >= 548)
                                                {
                                                    client.Entity.ConquerPoints -= 548;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 15 && client.Entity.ConquerPoints >= 375)
                                                {
                                                    client.Entity.ConquerPoints -= 375;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level >= 11 && prof.Level <= 14 && client.Entity.ConquerPoints >= 324)
                                                {
                                                    client.Entity.ConquerPoints -= 324;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 10 && client.Entity.ConquerPoints >= 270)
                                                {
                                                    client.Entity.ConquerPoints -= 270;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 9 && client.Entity.ConquerPoints >= 162)
                                                {
                                                    client.Entity.ConquerPoints -= 162;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 8 && client.Entity.ConquerPoints >= 135)
                                                {
                                                    client.Entity.ConquerPoints -= 135;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 7 && client.Entity.ConquerPoints >= 81)
                                                {
                                                    client.Entity.ConquerPoints -= 81;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 6 && client.Entity.ConquerPoints >= 54)
                                                {
                                                    client.Entity.ConquerPoints -= 54;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level >= 2 && prof.Level <= 5 && client.Entity.ConquerPoints >= 27)
                                                {
                                                    client.Entity.ConquerPoints -= 27;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                                if (prof.Level == 1)
                                                {
                                                    client.Entity.ConquerPoints -= 22;

                                                    prof.Level++;
                                                    prof.Experience = 0;
                                                    prof.Send(client);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            //break;
                                        }
                                        break;
                                    case Data.UpdateSpell:
                                        if (client != null)
                                        {
                                            ushort UplevelProficiency;
                                            UplevelProficiency = (ushort)gData.dwParam;
                                            if (client.Spells.ContainsKey(UplevelProficiency))
                                            {
                                                var prof = client.Spells[UplevelProficiency];
                                                if (prof != null)
                                                {
                                                    int num2 = (int)Database.SpellTable.SpellInformations[UplevelProficiency][prof.Level].CPUpgradeRatio;
                                                    int num3 = Math.Max((int)prof.Experience, 1);
                                                    int num4 = 100 - ((int)(((ulong)num3) / ((ulong)Math.Max((uint)(Database.SpellTable.SpellInformations[UplevelProficiency][prof.Level].NeedExperience / 100), (uint)1))));
                                                    uint num = (uint)(((double)((num2 * num4) / 100)) / 22.2);
                                                    if (client.Entity.ConquerPoints >= num)
                                                    {

                                                        client.Entity.ConquerPoints -= num;
                                                        // Console.WriteLine(" " + num + "");
                                                        prof.Level++;
                                                        prof.Experience = 0;
                                                        prof.Send(client);
                                                        break;
                                                    }
                                                    else
                                                    {
                                                        Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Sorry you dont have " + num + " cps i cant help you!");
                                                        npc.OptionID = 255;
                                                        client.Send(npc.ToArray());
                                                        break;
                                                        //sorry you dont have 100 cps
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                        else
                                        {
                                            //break;
                                        }
                                        break;
                                    case Data.SwingPickaxe:
                                        client.Mining = true;
                                        break;
                                    case Data.Revive:
                                        Revive(gData, client);
                                        break;
                                    case Data.UsePortal:
                                        UsePortal(gData, client);
                                        break;
                                    case Data.ChangePKMode:
                                        ChangePKMode(gData, client);
                                        break;
                                    case Data.ChangeAction:
                                        ChangeAction(gData, client);
                                        break;
                                    case Data.ChangeDirection:
                                        ChangeDirection(gData, client);
                                        break;
                                    case Data.Hotkeys:
                                        client.Send(packet);
                                        break;
                                    case Data.ConfirmSpells:
                                        if (client.Spells != null)
                                            foreach (Interfaces.ISkill spell in client.Spells.Values)
                                                if (spell.ID != 3060)
                                                    spell.Send(client);
                                        client.Send(packet);
                                        break;
                                    case Data.ConfirmProficiencies:
                                        if (client.Proficiencies != null)
                                            foreach (Interfaces.IProf proficiency in client.Proficiencies.Values)
                                                proficiency.Send(client);
                                        client.Send(packet);
                                        break;
                                    case Data.ConfirmGuild:
                                        client.Send(packet);
                                        break;
                                    case Data.ConfirmFriends:
                                        #region Friends/Enemy/TradePartners/Apprentices
                                        Message msg2 = new Message("Your friend, " + client.Entity.Name + ", has logged on.", System.Drawing.Color.Red, Message.TopLeft);

                                        foreach (Game.ConquerStructures.Society.Friend friend in client.Friends.Values)
                                        {
                                            if (friend.IsOnline)
                                            {
                                                var pckt = new KnownPersons(true)
                                                {
                                                    UID = client.Entity.UID,
                                                    Type = KnownPersons.RemovePerson,
                                                    Name = client.Entity.Name,
                                                    Online = true
                                                };
                                                friend.Client.Send(pckt);
                                                pckt.Type = KnownPersons.AddFriend;
                                                friend.Client.Send(pckt);
                                                friend.Client.Send(msg2);
                                            }
                                            client.Send(new KnownPersons(true)
                                            {
                                                UID = friend.ID,
                                                Type = KnownPersons.AddFriend,
                                                Name = friend.Name,
                                                Online = friend.IsOnline
                                            });
                                            if (friend.Message != "")
                                            {
                                                client.Send(new Message(friend.Message, client.Entity.Name, friend.Name, System.Drawing.Color.Red, Message.Whisper));
                                                Database.KnownPersons.UpdateMessageOnFriend(friend.ID, client.Entity.UID, "");
                                            }
                                        }

                                        foreach (Game.ConquerStructures.Society.Enemy enemy in client.Enemy.Values)
                                        {
                                            client.Send(new KnownPersons(true)
                                            {
                                                UID = enemy.ID,
                                                Type = KnownPersons.AddEnemy,
                                                Name = enemy.Name,
                                                Online = enemy.IsOnline
                                            });
                                        }
                                        Message msg3 = new Message("Your partner, " + client.Entity.Name + ", has logged in.", System.Drawing.Color.Red, Message.TopLeft);

                                        foreach (Game.ConquerStructures.Society.TradePartner partner in client.Partners.Values)
                                        {
                                            if (partner.IsOnline)
                                            {
                                                var packet3 = new TradePartner(true)
                                                {
                                                    UID = client.Entity.UID,
                                                    Type = TradePartner.BreakPartnership,
                                                    Name = client.Entity.Name,
                                                    HoursLeft = (int)(new TimeSpan(partner.ProbationStartedOn.AddDays(3).Ticks).TotalHours - new TimeSpan(DateTime.Now.Ticks).TotalHours),
                                                    Online = true
                                                };
                                                partner.Client.Send(packet3);
                                                packet3.Type = TradePartner.AddPartner;
                                                partner.Client.Send(packet3);
                                                partner.Client.Send(msg3);
                                            }
                                            var packet4 = new TradePartner(true)
                                            {
                                                UID = partner.ID,
                                                Type = TradePartner.AddPartner,
                                                Name = partner.Name,
                                                HoursLeft = (int)(new TimeSpan(partner.ProbationStartedOn.AddDays(3).Ticks).TotalHours - new TimeSpan(DateTime.Now.Ticks).TotalHours),
                                                Online = partner.IsOnline
                                            };
                                            client.Send(packet4);
                                        }

                                        foreach (Game.ConquerStructures.Society.Apprentice appr in client.Apprentices.Values)
                                        {
                                            if (appr.IsOnline)
                                            {
                                                ApprenticeInformation AppInfo = new ApprenticeInformation();
                                                AppInfo.Apprentice_ID = appr.ID;
                                                AppInfo.Apprentice_Level = appr.Client.Entity.Level;
                                                AppInfo.Apprentice_Class = appr.Client.Entity.Class;
                                                AppInfo.Apprentice_PkPoints = appr.Client.Entity.PKPoints;
                                                AppInfo.Apprentice_Experience = appr.Actual_Experience;
                                                AppInfo.Apprentice_Composing = appr.Actual_Plus;
                                                AppInfo.Apprentice_Blessing = appr.Actual_HeavenBlessing;
                                                AppInfo.Apprentice_Name = appr.Name;
                                                AppInfo.Apprentice_Online = true;
                                                AppInfo.Apprentice_Spouse_Name = appr.Client.Entity.Spouse;
                                                AppInfo.Enrole_date = appr.EnroleDate;
                                                AppInfo.Mentor_ID = client.Entity.UID;
                                                AppInfo.Mentor_Mesh = client.Entity.Mesh;
                                                AppInfo.Mentor_Name = client.Entity.Name;
                                                AppInfo.Type = 2;
                                                client.Send(AppInfo);

                                                MentorInformation Information = new MentorInformation(true);
                                                Information.Mentor_Type = 1;
                                                Information.Mentor_ID = client.Entity.UID;
                                                Information.Apprentice_ID = appr.ID;
                                                Information.Enrole_Date = appr.EnroleDate;
                                                Information.Mentor_Level = client.Entity.Level;
                                                Information.Mentor_Class = client.Entity.Class;
                                                Information.Mentor_PkPoints = client.Entity.PKPoints;
                                                Information.Mentor_Mesh = client.Entity.Mesh;
                                                Information.Mentor_Online = true;
                                                Information.Shared_Battle_Power = (uint)(((client.Entity.BattlePower - client.Entity.ExtraBattlePower) - (appr.Client.Entity.BattlePower - appr.Client.Entity.ExtraBattlePower)) / 3.3F);
                                                Information.String_Count = 3;
                                                Information.Mentor_Name = client.Entity.Name;
                                                Information.Apprentice_Name = appr.Name;
                                                Information.Mentor_Spouse_Name = client.Entity.Spouse;
                                                appr.Client.ReviewMentor();
                                                appr.Client.Send(Information);
                                            }
                                            else
                                            {
                                                ApprenticeInformation AppInfo = new ApprenticeInformation();
                                                AppInfo.Apprentice_ID = appr.ID;
                                                AppInfo.Apprentice_Name = appr.Name;
                                                AppInfo.Apprentice_Online = false;
                                                AppInfo.Enrole_date = appr.EnroleDate;
                                                AppInfo.Mentor_ID = client.Entity.UID;
                                                AppInfo.Mentor_Mesh = client.Entity.Mesh;
                                                AppInfo.Mentor_Name = client.Entity.Name;
                                                AppInfo.Type = 2;
                                                client.Send(AppInfo);
                                            }
                                        }
                                        #endregion
                                        client.Send(packet);
                                        break;
                                    case Data.EndTeleport:
                                        break;
                                    case Data.GetSurroundings:
                                        if (client.Booth != null)
                                        {
                                            client.Entity.TransformationID = 0;
                                            client.Booth.Remove();
                                            client.Booth = null;
                                        }
                                        GetSurroundings(client);
                                        client.Send(new MapStatus() { BaseID = (ushort)client.Map.BaseID, ID = (uint)client.Map.ID, Status = Database.MapsTable.MapInformations[client.Map.ID].Status });
                                        Game.Weather.CurrentWeatherBase.Send(client);
                                        client.Send(gData);
                                        break;
                                    case Data.SetLocation:
                                        SetLocation(gData, client);
                                        client.Entity.MapRegion = Region.Region.FindRegion((uint)client.Map.BaseID, client.Entity.X, client.Entity.Y);
                                        break;
                                    case Data.Jump:
                                        {
                                            PlayerJump(gData, client);

                                            break;
                                        }
                                    case Data.BlueCountdown:
                                        {
                                            // PlayerJump(gData, client);

                                            break;
                                        }
                                    case Data.UnknownEntity:
                                        {
                                            #region UnknownEntity
                                            Client.GameState pClient = null;
                                            if (ServerBase.Kernel.GamePool.TryGetValue(gData.dwParam, out pClient))
                                            {
                                                if (ServerBase.Kernel.GetDistance(pClient.Entity.X, pClient.Entity.Y, client.Entity.X, client.Entity.Y) <= ServerBase.Constants.pScreenDistance && client.Map.ID == pClient.Map.ID)
                                                {
                                                    if (pClient.Guild != null)
                                                        pClient.Guild.SendName(client);
                                                    if (client.Guild != null)
                                                        client.Guild.SendName(pClient);
                                                    if (pClient.Entity.UID != client.Entity.UID)
                                                    {
                                                        if (pClient.Map.ID == client.Map.ID)
                                                        {
                                                            if (pClient.Map.BaseID == 700)
                                                            {
                                                                if (client.QualifierGroup != null)
                                                                {
                                                                    if (pClient.QualifierGroup != null)
                                                                    {
                                                                        client.Entity.SendSpawn(pClient, false);
                                                                        pClient.Entity.SendSpawn(client, false);
                                                                    }
                                                                    else
                                                                    {
                                                                        client.Entity.SendSpawn(pClient, false);
                                                                        client.Screen.Add(pClient.Entity);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (pClient.QualifierGroup != null)
                                                                    {
                                                                        pClient.Entity.SendSpawn(client, false);
                                                                        pClient.Screen.Add(client.Entity);
                                                                    }
                                                                    else
                                                                    {
                                                                        client.Entity.SendSpawn(pClient, false);
                                                                        pClient.Entity.SendSpawn(client, false);
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                client.Entity.SendSpawn(pClient, false);
                                                                pClient.Entity.SendSpawn(client, false);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Game.Entity monster = null;
                                                for (int x = 0; x < client.Map.Entities.Count; x++)
                                                {
                                                    if (x >= client.Map.Entities.Count)
                                                        break;
                                                    if (client.Map.Entities[x] != null)
                                                    {
                                                        if (client.Map.Entities[x].UID == gData.dwParam)
                                                        {
                                                            monster = client.Map.Entities[x];
                                                            break;
                                                        }
                                                    }
                                                }
                                                if (monster != null)
                                                {
                                                    if (ServerBase.Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y) <= ServerBase.Constants.pScreenDistance)
                                                    {
                                                        monster.SendSpawn(client, false);
                                                    }
                                                }
                                                for (int x = 0; x < client.Map.Companions.Count; x++)
                                                {
                                                    if (x >= client.Map.Companions.Count)
                                                        break;
                                                    if (client.Map.Companions[x] != null)
                                                    {
                                                        if (client.Map.Companions[x].UID == gData.dwParam)
                                                        {
                                                            monster = client.Map.Companions[x];
                                                            break;
                                                        }
                                                    }
                                                }
                                                if (monster != null)
                                                {
                                                    if (ServerBase.Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y) <= ServerBase.Constants.pScreenDistance)
                                                    {
                                                        monster.SendSpawn(client, false);
                                                    }
                                                }
                                            }
                                            #endregion
                                            break;
                                        }
                                    case Data.CompleteLogin:
                                        {
                                            client.MonsterHunterStats = new MonsterHunterStats(client);
                                            //client.MonsterHunterStats.Kills = (ushort)client.Entity.Status4;
                                            // client.MonsterHunterStats.Load(client);
                                            LoginMessages(client);
                                            Network.GamePackets.Weather weather = new Network.GamePackets.Weather(true);
                                            weather.WeatherType = (uint)Program.WeatherType;
                                            weather.Intensity = 100;
                                            weather.Appearence = 2;
                                            weather.Direction = 4;

                                            client.Send(new FlowerPacket(client.Entity.Flowers));
                                            client.Send(new FlowerPacket3(client));
                                            /*ClientEquip equips = new ClientEquip();
                                            equips.DoEquips(client);
                                            client.Send(equips);*/
                                            client.Send(packet);
                                            client.Send(weather);
                                            break;
                                        }
                                    case Data.ChangeFace:
                                        ChangeFace(gData, client);
                                        break;
                                    case Data.ObserveEquipment:
                                        ObserveEquipment2(gData, client);
                                        break;
                                    case Data.ObserveEquipment2:
                                        ObserveEquipment(gData, client);
                                        break;
                                    case 408:
                                        {
                                            /* if (!client.ChangeGear)
                                             {
                                                 Game.KimoChangeGear.Load(client);
                                             }
                                             else
                                             {

                                                 Game.KimoChangeGear.Load2(client);
                                             }
                                             client.ChangeGear = true;*/
                                            break;
                                        }

                                    case Data.ObserveKnownPerson:
                                        ObserveEquipment(gData, client);
                                        break;
                                    case Data.ViewEnemyInfo:
                                        {
                                            if (client.Enemy.ContainsKey(gData.dwParam))
                                            {
                                                if (client.Enemy[gData.dwParam].IsOnline)
                                                {
                                                    KnownPersonInfo info = new KnownPersonInfo(true);
                                                    info.Fill(client.Enemy[gData.dwParam], true, false);
                                                    if (client.Enemy[gData.dwParam].Client.Guild != null)
                                                        client.Enemy[gData.dwParam].Client.Guild.SendName(client);
                                                    client.Send(info);
                                                }
                                            }
                                            break;
                                        }
                                    case Data.ViewFriendInfo:
                                        {
                                            if (client.Friends.ContainsKey(gData.dwParam))
                                            {
                                                if (client.Friends[gData.dwParam].IsOnline)
                                                {
                                                    KnownPersonInfo info = new KnownPersonInfo(true);
                                                    info.Fill(client.Friends[gData.dwParam], false, false);
                                                    if (client.Friends[gData.dwParam].Client.Guild != null)
                                                        client.Friends[gData.dwParam].Client.Guild.SendName(client);
                                                    client.Send(info);
                                                }
                                            }
                                            break;
                                        }
                                    case Data.ViewPartnerInfo:
                                        {
                                            if (client.Partners.ContainsKey(gData.dwParam))
                                            {
                                                if (client.Partners[gData.dwParam].IsOnline)
                                                {
                                                    TradePartnerInfo info = new TradePartnerInfo(true);
                                                    info.Fill(client.Partners[gData.dwParam]);
                                                    if (client.Partners[gData.dwParam].Client.Guild != null)
                                                        client.Partners[gData.dwParam].Client.Guild.SendName(client);
                                                    client.Send(info);
                                                }
                                            }
                                            break;
                                        }
                                    case Data.EndFly:
                                        client.Entity.RemoveFlag(Update.Flags.Fly);
                                        break;
                                    case Data.EndTransformation:
                                        client.Entity.Untransform();
                                        break;
                                    case Data.XPListEnd:
                                    case Data.Die:
                                        break;
                                    case Data.Confiscator:
                                        client.Send(packet);
                                        break;
                                    case Data.OwnBooth:
                                        {
                                            client.Booth = new PhoenixProject.Game.ConquerStructures.Booth(client, gData);
                                            client.Send(new Data(true) { ID = Data.ChangeAction, UID = client.Entity.UID, dwParam = 0 });
                                            break;
                                        }

                                    case Data.Away:
                                        {
                                            if (client.Entity.Away == 0)
                                                client.Entity.Away = 1;
                                            else
                                                client.Entity.Away = 0;
                                            client.SendScreenSpawn(client.Entity, false);
                                            break;
                                        }
                                    case Data.DeleteCharacter:
                                        {
                                            if ((client.WarehousePW == null || client.WarehousePW == "" || client.WarehousePW == "0" && gData.dwParam == 0) || (client.WarehousePW == gData.dwParam.ToString()))
                                            {
                                                client.Account.TempID = 400;

                                                client.Disconnect();
                                            }
                                            break;
                                        }

                                    case Data.TeamSearchForMember:
                                        {
                                            if (client.Team != null)
                                            {
                                                Client.GameState Client = null;
                                                if (!client.Team.IsTeammate(gData.UID))
                                                    return;
                                                if (Kernel.GamePool.TryGetValue(gData.UID, out Client))
                                                {
                                                    // Console.WriteLine(" " + gData.dwParam + "");
                                                    gData.wParam1 = Client.Entity.X;
                                                    gData.wParam2 = Client.Entity.Y;
                                                    gData.Send(client);
                                                }
                                            }
                                            break;
                                        }
                                    default:
                                        if (client.Account.State == PhoenixProject.Database.AccountTable.AccountState.ProjectManager || client.Account.State == PhoenixProject.Database.AccountTable.AccountState.Coder)
                                            client.Send(new Message("Unknown generaldata id: " + gData.ID, System.Drawing.Color.CadetBlue, Message.Talk));
                                        break;
                                }
                                break;
                            }
                        #endregion
                        #region TimePacket (1033)
                        case 1033:
                            {
                                ServerTime time = new ServerTime();
                                time.Year = (uint)DateTime.Now.Year;
                                time.Month = (uint)DateTime.Now.Month;
                                time.DayOfYear = (uint)DateTime.Now.DayOfYear;
                                time.DayOfMonth = (uint)DateTime.Now.Day;
                                time.Hour = (uint)DateTime.Now.Hour;
                                time.Minute = (uint)DateTime.Now.Minute;
                                time.Second = (uint)DateTime.Now.Second;
                                client.Send(time);
                                break;
                            }
                        #endregion
                        #region MemoryAgate
                        case 2110:
                            {
                                uint ItemUID = BitConverter.ToUInt32(packet, 8);
                                switch (packet[4])
                                {
                                    case 1:
                                        {
                                            if (client.Map.IsDynamic()) return;
                                            if (ServerBase.Constants.revnomap.Contains(client.Entity.MapID))
                                                return;
                                            Interfaces.IConquerItem Item = null;

                                            if (client.Inventory.TryGetItem(ItemUID, out Item))
                                            {
                                                if (Item.Agate_map.ContainsKey(packet[12]))
                                                {
                                                    Item.Agate_map[(uint)packet[12]] = client.Entity.MapID
                                                       + "~" + client.Entity.X
                                                       + "~" + client.Entity.Y;
                                                    Database.ConquerItemTable.UpdateItemAgate(Item);
                                                    Item.SendAgate(client);
                                                    break;
                                                }
                                                if (packet[12] > Item.Agate_map.Count)
                                                {
                                                    Item.Agate_map.Add((byte)(Item.Agate_map.Count), client.Entity.MapID
                                                       + "~" + client.Entity.X
                                                       + "~" + client.Entity.Y);
                                                    Database.ConquerItemTable.UpdateItemAgate(Item);
                                                    Item.SendAgate(client);
                                                    break;
                                                }
                                                else
                                                {
                                                    if (!Item.Agate_map.ContainsKey(packet[12]))
                                                    {

                                                        Item.Agate_map.Add(packet[12], client.Entity.MapID
                                                            + "~" + client.Entity.X

                                                           + "~" + client.Entity.Y);
                                                        Database.ConquerItemTable.UpdateItemAgate(Item);
                                                        Item.SendAgate(client);
                                                    }
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                    case 3:
                                        {
                                            if (client.Map.IsDynamic()) return;
                                            if (ServerBase.Constants.revnomap.Contains(client.Entity.MapID))
                                                return;
                                            Interfaces.IConquerItem Item = null;
                                            if (client.Inventory.TryGetItem(ItemUID, out Item))
                                            {

                                                if (Item.Agate_map.ContainsKey(packet[12]))
                                                {
                                                    if (ServerBase.Constants.MemoryAgateNotAllowedMap.Contains(ushort.Parse(Item.Agate_map[packet[12]].Split('~')[0].ToString())))
                                                    {
                                                        return;
                                                    }
                                                    /*if (ushort.Parse(Item.Agate_map[packet[12]].Split('~')[0].ToString()) == 1038)
                                                        return;
                                                    if (ushort.Parse(Item.Agate_map[packet[12]].Split('~')[0].ToString()) == 6001)
                                                        return;*/
                                                    client.Entity.Teleport(ushort.Parse(Item.Agate_map[packet[12]].Split('~')[0].ToString())
                                                        , ushort.Parse(Item.Agate_map[packet[12]].Split('~')[1].ToString())
                                                        , ushort.Parse(Item.Agate_map[packet[12]].Split('~')[2].ToString()));
                                                    Item.Durability--;
                                                    Item.SendAgate(client);
                                                    Database.ConquerItemTable.UpdateItemAgate(Item);
                                                }
                                            }
                                            break;
                                        }
                                    case 4:
                                        {
                                            if (ServerBase.Constants.MemoryAgateNotAllowedMap.Contains(client.Entity.MapID))
                                                return;
                                            Interfaces.IConquerItem Item = null;
                                            if (client.Inventory.TryGetItem(ItemUID, out Item))
                                            {
                                                uint cost = (uint)(Item.MaximDurability - Item.Durability) / 2;
                                                if (cost == 0)
                                                    cost = 1;
                                                if (client.Entity.ConquerPoints > cost)
                                                {
                                                    client.Entity.ConquerPoints -= cost;
                                                    Item.Durability = Item.MaximDurability;
                                                    Item.SendAgate(client);
                                                    Database.ConquerItemTable.UpdateItemAgate(Item);
                                                }
                                            }
                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion
                        #region Ayudante
                        case 1321:
                        case 1322:
                        case 1136:
                        case 1320:

                            client.Send(packet);
                            break;
                        case 2261:
                            {
                                client.Send(packet);
                            }
                            break;
                        #endregion
                        #region Advertise
                        case 2226:
                            {
                                byte[] firstpacket = new byte[724]{0xCC,0x02,0xB2,0x08,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00//;̲0x,0x0x0x
            ,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x67,0x01,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x,0xg0x0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x75,0x83,0x83,0x50//;0x0x0x,0x,0xPuƒƒP
            ,0x75,0x83,0x83,0x50,0x61,0x24,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;uƒƒPa$$0x0x0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44//;0x0x0x0x0xD
            ,0x65,0x76,0x69,0x6C,0x5F,0x44,0x6F,0x67,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;evil_Dogg0x0x,0x
            ,0x01,0x00,0x00,0x00,0x83,0x00,0x00,0x00,0x81,0xC3,0x15,0x00,0x00,0x00,0x00,0x00//;0xƒ0xÃ0x,0x,0x
            ,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;,0x0x0x0x0x,0x
            ,0x7E,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;~0x0x0x0x,0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x41,0x4F,0x57,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0xAOW0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;0x0x0x0x0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x73,0x61,0x61,0x6E,0x00,0x00,0x00,0x00,0x00//;0x0x,0xsaan0x,0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0D,0x00,0x00,0x00//;0x0x,0x,0x0x0x
            ,0xA5,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00//;¥0x,0x,0x,0x0x,0x,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x54,0x51,0x53,0x65//;0x0x0x0xTQSe
            ,0x72,0x76,0x65,0x72};//;rver
                                client.Send(firstpacket);
                                byte[] secondpacket = new byte[724]{0xCC,0x02,0xB2,0x08,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00//;̲//////,0x//,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x01,0x00,0x00,0x00,0x00,0x00,0x00//;//////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x2A,0x41,0x75,0x74//;//////,0x`*Aut
            ,0x68,0x65,0x6E,0x74,0x69,0x63,0x2A,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;hentic*`////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4E//;//////,0xN
            ,0x61,0x72,0x72,0x63,0x6F,0x74,0x69,0x63,0x7A,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;arrcoticz//,0x
            ,0x01,0x00,0x00,0x00,0x59,0x00,0x00,0x00,0xDF,0xA3,0x59,0x00,0x00,0x00,0x00,0x00//;//,0xY//,0xߣY////,0x
            ,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;,0x////,0x
            ,0x7B,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;{//////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x7E,0x2A,0x44,0x65,0x5F,0x41,0x5F,0x74,0x68,0x2A,0x7E,0x00,0x00//;//,0x~*De_A_th*~//
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//;////////
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5E,0x5E,0x5E,0x5E,0x5E,0x32,0x5E,0x5E,0x5E//;//,0x^^^^^2^^^
            ,0x5E,0x5E,0x5E,0x5E,0x5E,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00//;^^^^^//,0x//,0x//,0x
            ,0x10,0x27,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00//;'//,0x////,0x
            ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x54,0x51,0x53,0x65//;////TQSe
            ,0x72,0x76,0x65,0x72};//////////////;rver
                                client.Send(secondpacket);
                                break;
                            }
                        #endregion
                        #region OneArmedBandit 1351 AboRagab/Kimo/Amro kan bys2f
                        case 1351:
                            {
                                if (packet[4] == 0)
                                {
                                    if (client.Entity.ConquerPoints >= 100 * packet[5])
                                    {
                                        client.Send(packet);
                                        Sendonearmed(client);
                                        //PrintPacket(packet);
                                        client.Entity.ConquerPoints -= (uint)(100 * packet[5]);
                                        //Console.WriteLine("cps " +(uint)(100 * packet[5]));
                                    }
                                }
                                else
                                {
                                    Sendonearmed2(client);
                                    Prize3X(client);
                                    client.Entity.ConquerPoints += client.Entity.CPSS * packet[5];
                                    //Console.WriteLine("Win " + (uint)(client.Entity.CPSS * packet[5]));
                                    //PrintPacket(packet);
                                }
                                break;
                            }

                        #endregion
                        /*case 1044:
                            PrintPacket(packet);
                            client.Send(packet);
                            break;*/
                        /*#region PK Explorer (2220)
                         case 2220:
                             {
                                 PkExplorer pk = new PkExplorer(packet, client);
                                 pk.SubType = 1;
                                 client.Send(pk.Build());
                                 break;
                             }
                         #endregion*/
                        /* #region Cases de Packs
                         case 1034:
                         case 1037:
                             {
                                 client.Send(packet);
                                 break;
                             }
                         case 1135:
                             client.Send(packet);
                             break;
                         case 1134:
                             {
                                 switch (ID2)
                                 {
                                     case 1:
                                         client.Send(packet);
                                         break;
                                     case 2:
                                         client.Send(packet);
                                         break;
                                     case 3:
                                         client.Send(packet);
                                         break;
                                     case 4:
                                         client.Send(packet);
                                         break;
                                     case 5:
                                         client.Send(packet);
                                         break;
                                     case 6:
                                         client.Send(packet);
                                         break;
                                     case 7:
                                         client.Send(packet);
                                         break;
                                     case 8:
                                         client.Send(packet);
                                         break;
                                     case 9:
                                         client.Send(packet);
                                         break;
                                     case 10:
                                         client.Send(packet);
                                         break;
                                 }
                                 break;
                             }
                         #endregion*/
                        /*case 1134:
                            {
                                PhoenixProject.Network.GamePackets.Quest.QuestInfo.Handle(packet, client);
                                break;
                            }
                        case 1135:
                            {
                                PhoenixProject.Network.GamePackets.Quest.QuestQuery2.Handle(packet, client);
                                break;
                            }*/
                        /* case 1136:
                             {
                                 //PrintPacket(packet);
                                 client.Send(packet);
                                // PrintPacket(packet);
                                 break;
                             }*/
                        default:
                            {
                                if (client.Account.State == PhoenixProject.Database.AccountTable.AccountState.Coder)
                                {
                                    ushort key = BitConverter.ToUInt16(packet, 2);
                                    //PrintPacket(packet);
                                    Console.WriteLine("[Kimo]=> Unknown Packet: " + key + "");
                                    // Console.WriteLine("[Kimo]=> Unknown Packet: " + key + " " + PacketConstructor.Dump(packet) + "");

                                }

                                break;
                            }
                    }
                }
            }
            catch (Exception e)
            {
                Program.SaveException(e);
            }
        }
        private void Execute()
        {
            #region interactions
            if (attack != null)
            {
                switch (attack.AttackType)
                {
                    case (uint)Network.GamePackets.Attack.InteractionRequest:
                        new InteractionRequest(attack, attacker);
                        return;
                    case (uint)Network.GamePackets.Attack.InteractionEffect:
                        new InteractionEffect(attack, attacker);
                        return;

                    case (uint)Network.GamePackets.Attack.InteractionAccept:
                        new InteractionAccept(attack, attacker);
                        return;
                    case (uint)Network.GamePackets.Attack.InteractionRefuse:
                        new InteractionRefuse(attack, attacker);
                        return;
                    case (uint)Network.GamePackets.Attack.InteractionStopEffect:
                        new InteractionStopEffect(attack, attacker);
                        return;
                }
            }
            #endregion
            #region Monster -> Player \ Monster
            if (attack == null)
            {
                if (attacker.EntityFlag != EntityFlag.Monster)
                    return;
                if (attacker.Companion)
                {
                    if (ServerBase.Constants.PKForbiddenMaps.Contains(attacker.MapID))
                        return;
                }
                if (attacked.EntityFlag == EntityFlag.Player)
                {
                    if (!attacked.Owner.Attackable)
                        return;
                    if (attacked.Dead && attacker.MonsterInfo.SpellID != 1050)
                        return;

                    if (attacker.MonsterInfo.SpellID == 0)// from this bracket to the next die delay replce this with urs
                    {
                        attack = new Attack(true);
                        attack.Effect1 = Attack.AttackEffects1.None;
                        uint damage = Calculate.Melee(attacker, attacked, ref attack);
                        attack.Attacker = attacker.UID;
                        attack.Attacked = attacked.UID;
                        attack.AttackType = Attack.Melee;
                        attack.Damage = damage;
                        attack.X = attacked.X;
                        attack.Y = attacked.Y;
                        BlessEffect.Effect(attacked);
                        if (attacked.EntityFlag == EntityFlag.Player)
                        {
                            if (attacked.Action == Enums.ConquerAction.Sit)
                                if (attacked.Stamina > 20)
                                    attacked.Stamina -= 20;
                                else
                                    attacked.Stamina = 0;
                            attacked.Action = Enums.ConquerAction.None;
                            //Console.WriteLine("ssS");
                        }
                        if (attacked.Hitpoints <= damage)
                        {
                            attacked.Owner.SendScreen(attack, true);
                            attacked.Die(attacker);
                        }
                        else
                        {
                            attacked.Hitpoints -= damage;
                            attacked.Owner.SendScreen(attack, true);
                        }
                    }
                    else
                    {
                        SpellUse suse = new SpellUse(true);
                        attack = new Attack(true);
                        attack.Effect1 = Attack.AttackEffects1.None;
                        uint damage = Calculate.Magic(attacker, attacked, attacker.MonsterInfo.SpellID, 0, ref attack);
                        suse.Effect1 = attack.Effect1;
                        if (attacked.EntityFlag == EntityFlag.Player)
                        {
                            if (attacked.Action == Enums.ConquerAction.Sit)
                                if (attacked.Stamina > 20)
                                    attacked.Stamina -= 20;
                                else
                                    attacked.Stamina = 0;
                            attacked.Action = Enums.ConquerAction.None;
                            //Console.WriteLine("ssS");
                        }
                        if (attacked.Hitpoints <= damage)
                        {
                            attacked.Die(attacker);
                        }
                        else
                        {
                            attacked.Hitpoints -= damage;
                        }
                        if (attacker.Companion)
                            attacker.Owner.IncreaseExperience(Math.Min(damage, attacked.Hitpoints), true);

                        suse.Attacker = attacker.UID;
                        suse.SpellID = attacker.MonsterInfo.SpellID;
                        suse.X = attacked.X;
                        suse.Y = attacked.Y;
                        suse.Targets.Add(attacked.UID, damage);
                        attacked.Owner.SendScreen(suse, true);
                    }
                }
                else
                {
                    if (attacker.MonsterInfo.SpellID == 0)
                    {
                        attack = new Attack(true);
                        attack.Effect1 = Attack.AttackEffects1.None;
                        uint damage = Calculate.Melee(attacker, attacked, ref attack);
                        attack.Attacker = attacker.UID;
                        attack.Attacked = attacked.UID;
                        attack.AttackType = Attack.Melee;
                        attack.Damage = damage;
                        attack.X = attacked.X;
                        attack.Y = attacked.Y;
                        attacked.MonsterInfo.SendScreen(attack);
                        if (attacker.Companion)
                            if (damage > attacked.Hitpoints)
                                attacker.Owner.IncreaseExperience(Math.Min(damage, attacked.Hitpoints), true);
                            else
                                attacker.Owner.IncreaseExperience(damage, true);
                        if (attacked.Hitpoints <= damage)
                        {
                            attacked.Die(attacker);
                            attack = new Attack(true);
                            attack.Attacker = attacker.UID;
                            attack.Attacked = attacked.UID;
                            attack.AttackType = Network.GamePackets.Attack.Kill;
                            attack.X = attacked.X;
                            attack.Y = attacked.Y;
                            attacked.MonsterInfo.SendScreen(attack);
                        }
                        else
                        {
                            attacked.Hitpoints -= damage;
                        }
                    }
                    else
                    {
                        SpellUse suse = new SpellUse(true);
                        if (attack != null) attack.Effect1 = Attack.AttackEffects1.None;
                        uint damage = Calculate.Magic(attacker, attacked, attacker.MonsterInfo.SpellID, 0, ref attack);
                        if (attack != null) suse.Effect1 = attack.Effect1;

                        suse.Attacker = attacker.UID;
                        suse.SpellID = attacker.MonsterInfo.SpellID;
                        suse.X = attacked.X;
                        suse.Y = attacked.Y;
                        suse.Targets.Add(attacked.UID, damage);
                        attacked.MonsterInfo.SendScreen(suse);
                        if (attacker.Companion)
                            if (damage > attacked.Hitpoints)
                                attacker.Owner.IncreaseExperience(Math.Min(damage, attacked.Hitpoints), true);
                            else
                                attacker.Owner.IncreaseExperience(damage, true);
                        if (attacked.Hitpoints <= damage)
                        {
                            attacked.Die(attacker);
                            attack = new Attack(true);
                            attack.Attacker = attacker.UID;
                            attack.Attacked = attacked.UID;
                            attack.AttackType = Network.GamePackets.Attack.Kill;
                            attack.X = attacked.X;
                            attack.Y = attacked.Y;
                            attacked.MonsterInfo.SendScreen(attack);
                        }
                        else
                        {
                            attacked.Hitpoints -= damage;
                        }
                    }
                }
            }
            #endregion
            #region Player -> Player \ Monster \ Sob Npc
            else
            {
                #region Merchant
                if (attack.AttackType == Attack.MerchantAccept || attack.AttackType == Attack.MerchantRefuse)
                {

                    attacker.AttackPacket = null;
                    return;
                }
                #endregion
                #region Marriage
                if (attack.AttackType == Attack.MarriageAccept || attack.AttackType == Attack.MarriageRequest)
                {
                    if (attack.AttackType == Attack.MarriageRequest)
                    {
                        Client.GameState Spouse = null;
                        uint takeout = attack.Attacked;
                        if (takeout == attacker.UID)
                            takeout = attack.Attacker;
                        if (ServerBase.Kernel.GamePool.TryGetValue(takeout, out Spouse))
                        {
                            if (attacker.Spouse != "None" || Spouse.Entity.Spouse != "None")
                            {
                                attacker.Owner.Send(new Message("You cannot marry someone that is already married with someone else!", System.Drawing.Color.Black, Message.TopLeft));
                            }
                            else
                            {
                                uint id1 = attacker.Mesh % 10, id2 = Spouse.Entity.Mesh % 10;

                                if (id1 <= 2 && id2 >= 3 || id1 >= 2 && id2 <= 3)
                                {

                                    attack.X = Spouse.Entity.X;
                                    attack.Y = Spouse.Entity.Y;

                                    Spouse.Send(attack);
                                }
                                else
                                {
                                    attacker.Owner.Send(new Message("You cannot marry someone of your gender!", System.Drawing.Color.Black, Message.TopLeft));
                                }
                            }
                        }
                    }
                    else
                    {
                        Client.GameState Spouse = null;
                        if (ServerBase.Kernel.GamePool.TryGetValue(attack.Attacked, out Spouse))
                        {
                            if (attacker.Spouse != "None" || Spouse.Entity.Spouse != "None")
                            {
                                attacker.Owner.Send(new Message("You cannot marry someone that is already married with someone else!", System.Drawing.Color.Black, Message.TopLeft));
                            }
                            else
                            {
                                if (attacker.Mesh % 10 <= 2 && Spouse.Entity.Mesh % 10 >= 3 || attacker.Mesh % 10 >= 3 && Spouse.Entity.Mesh % 10 <= 2)
                                {
                                    Spouse.Entity.Spouse = attacker.Name;
                                    attacker.Spouse = Spouse.Entity.Name;
                                    Message message = null;
                                    if (Spouse.Entity.Mesh % 10 >= 3)
                                        message = new Message("Joy and happiness! " + Spouse.Entity.Name + " and " + attacker.Name + " have joined together in the holy marriage. We wish them a stone house.", System.Drawing.Color.BurlyWood, Message.Center);
                                    else
                                        message = new Message("Joy and happiness! " + attacker.Name + " and " + attacker.Spouse + " have joined together in the holy marriage. We wish them a stone house.", System.Drawing.Color.BurlyWood, Message.Center);

                                    foreach (Client.GameState client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        client.Send(message);
                                    }

                                    Spouse.Entity.Update(_String.Effect, "firework-2love", true);
                                    attacker.Update(_String.Effect, "firework-2love", true);
                                }
                                else
                                {
                                    attacker.Owner.Send(new Message("You cannot marry someone of your gender!", System.Drawing.Color.Black, Message.TopLeft));
                                }
                            }
                        }
                    }
                }
                #endregion
                #region Attacking
                else
                {

                    attacker.Owner.Attackable = true;
                    Entity attacked = null;

                    SobNpcSpawn attackedsob = null;

                    #region Checks
                    if (attack.Attacker != attacker.UID)
                        return;
                    if (attacker.EntityFlag != EntityFlag.Player)
                        return;
                    attacker.RemoveFlag(Update.Flags.Invisibility);

                    bool pass = false;
                    if (attack.AttackType == Attack.Melee)
                    {
                        if (attacker.OnFatalStrike())
                        {
                            if (attack.Attacked < 600000)
                            {
                                pass = true;
                            }
                        }
                    }
                    ushort decrease = 0;
                    if (attacker.OnCyclone())
                        decrease = 1;

                    if (attacker.OnSuperman())
                        decrease = 300;
                    if (!pass)
                    {
                        int milliSeconds = 1000 - attacker.Agility - decrease;
                        if (milliSeconds < 0 || milliSeconds > 5000)
                            milliSeconds = 0;
                        if (Time32.Now < attacker.AttackStamp.AddMilliseconds(milliSeconds))
                            return;
                    }
                    if (attacker.Dead)
                    {
                        if (attacker.AttackPacket != null)
                            attacker.AttackPacket = null;
                        return;
                    }
                    attacker.AttackStamp = Time32.Now;
                    if (attacker.Owner.QualifierGroup != null)
                    {
                        if (Time32.Now < attacker.Owner.QualifierGroup.CreateTime.AddSeconds(12))
                        {
                            return;
                        }
                    }

                restart:

                    #region Extract attack information
                    ushort SpellID = 0, X = 0, Y = 0;
                    uint Target = 0;
                    if (attack.AttackType == Attack.Magic)
                    {
                        if (!attack.Decoded)
                        {

                            #region GetSkillID
                            SpellID = Convert.ToUInt16(((long)attack.ToArray()[24] & 0xFF) | (((long)attack.ToArray()[25] & 0xFF) << 8));
                            SpellID ^= (ushort)0x915d;
                            SpellID ^= (ushort)attacker.UID;
                            SpellID = (ushort)(SpellID << 0x3 | SpellID >> 0xd);
                            SpellID -= 0xeb42;
                            #endregion
                            #region GetCoords
                            X = (ushort)((attack.ToArray()[16] & 0xFF) | ((attack.ToArray()[17] & 0xFF) << 8));
                            X = (ushort)(X ^ (uint)(attacker.UID & 0xffff) ^ 0x2ed6);
                            X = (ushort)(((X << 1) | ((X & 0x8000) >> 15)) & 0xffff);
                            X = (ushort)((X | 0xffff0000) - 0xffff22ee);

                            Y = (ushort)((attack.ToArray()[18] & 0xFF) | ((attack.ToArray()[19] & 0xFF) << 8));
                            Y = (ushort)(Y ^ (uint)(attacker.UID & 0xffff) ^ 0xb99b);
                            Y = (ushort)(((Y << 5) | ((Y & 0xF800) >> 11)) & 0xffff);
                            Y = (ushort)((Y | 0xffff0000) - 0xffff8922);
                            #endregion
                            #region GetTarget
                            Target = ((uint)attack.ToArray()[12] & 0xFF) | (((uint)attack.ToArray()[13] & 0xFF) << 8) | (((uint)attack.ToArray()[14] & 0xFF) << 16) | (((uint)attack.ToArray()[15] & 0xFF) << 24);
                            Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ attacker.UID) - 0x746F4AE6;
                            #endregion

                            attack.X = X;
                            attack.Y = Y;
                            attack.Damage = SpellID;
                            attack.Attacked = Target;
                            attack.Decoded = true;

                        }
                        else
                        {
                            X = attack.X;
                            Y = attack.Y;
                            SpellID = (ushort)attack.Damage;
                            Target = attack.Attacked;
                        }
                    }
                    #endregion
                    #endregion

                    if (attacker.ContainsFlag(Update.Flags.Ride) && attacker.Owner.Equipment.TryGetItem(18) == null)
                    {
                        if (attack.AttackType != Attack.Magic)
                            attacker.RemoveFlag(Update.Flags.Ride);
                        else
                            if (!(SpellID == 7003 || SpellID == 7002))
                                attacker.RemoveFlag(Update.Flags.Ride);
                    }
                    if (attacker.ContainsFlag(Update.Flags.CastPray))
                        attacker.RemoveFlag(Update.Flags.CastPray);
                    if (attacker.ContainsFlag(Update.Flags.Praying))
                        attacker.RemoveFlag(Update.Flags.Praying);


                    #region Dash
                    if (SpellID == 1051)
                    {
                        if (ServerBase.Kernel.GetDistance(attack.X, attack.Y, attacker.X, attacker.Y) > 4)
                        {
                            attacker.Owner.Disconnect();
                            return;
                        }
                        attacker.X = attack.X; attacker.Y = attack.Y;
                        ushort x = attacker.X, y = attacker.Y;
                        Game.Map.UpdateCoordonatesForAngle(ref x, ref y, (Enums.ConquerAngle)Target);
                        for (int c = 0; c < attacker.Owner.Screen.Objects.Count; c++)
                        {
                            if (c >= attacker.Owner.Screen.Objects.Count)
                                break;
                            //List<IMapObject> list = new List<IMapObject>();
                            IMapObject obj = attacker.Owner.Screen.Objects[c];
                            if (obj == null)
                                continue;
                            if (obj.X == x && obj.Y == y && (obj.MapObjType == MapObjectType.Monster || obj.MapObjType == MapObjectType.Player))
                            {
                                Entity entity = obj as Entity;
                                if (!entity.Dead)
                                {
                                    Target = obj.UID;
                                    break;
                                }
                            }
                        }
                    }
                    #endregion
                    #region CounterKill
                    if (attack.AttackType == Attack.CounterKillSwitch)
                    {
                        if (attacked != null)
                            if (attacked.ContainsFlag(Update.Flags.Fly))
                            { attacker.AttackPacket = null; return; }
                        if (attacker != null)
                            if (attacker.ContainsFlag(Update.Flags.Fly))
                            { attacker.AttackPacket = null; return; }
                        if (attacker.Owner.Spells.ContainsKey(6003))
                        {
                            if (!attacker.CounterKillSwitch)
                            {
                                if (Time32.Now >= attacker.CounterKillStamp.AddSeconds(30))
                                {
                                    attacker.CounterKillStamp = Time32.Now;
                                    attacker.CounterKillSwitch = true;
                                    Attack m_attack = new Attack(true);
                                    m_attack.Attacked = attacker.UID;
                                    m_attack.Attacker = attacker.UID;
                                    m_attack.AttackType = Attack.CounterKillSwitch;
                                    m_attack.Damage = 1;
                                    m_attack.X = attacker.X;
                                    m_attack.Y = attacker.Y;
                                    m_attack.Send(attacker.Owner);
                                }
                            }
                            else
                            {
                                attacker.CounterKillSwitch = false;
                                Attack m_attack = new Attack(true);
                                m_attack.Attacked = attacker.UID;
                                m_attack.Attacker = attacker.UID;
                                m_attack.AttackType = Attack.CounterKillSwitch;
                                m_attack.Damage = 0;
                                m_attack.X = attacker.X;
                                m_attack.Y = attacker.Y;
                                m_attack.Send(attacker.Owner);
                            }

                            attacker.Owner.IncreaseSpellExperience(100, 6003);
                            attacker.AttackPacket = null;
                        }
                    }
                    #endregion
                    #region Melee
                    else if (attack.AttackType == Attack.Melee)
                    {
                        if (attacker.Owner.Screen.TryGetValue(attack.Attacked, out attacked))
                        {
                            if (!attacker.Owner.AlternateEquipment)
                            {
                                CheckForExtraWeaponPowers(attacker.Owner, attacked);
                            }
                            else
                            {
                                CheckForExtraWeaponPowers2(attacker.Owner, attacked);
                            }
                            if (!CanAttack(attacker, attacked, null, attack.AttackType == Attack.Melee))
                                return;
                            pass = false;
                            if (attacker.OnFatalStrike())
                            {
                                if (attacked.EntityFlag == EntityFlag.Monster)
                                {
                                    pass = true;
                                }
                            }
                            ushort range = attacker.AttackRange;
                            if (attacker.Transformed)
                                range = (ushort)attacker.TransformationAttackRange;
                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= range || pass)
                            {
                                attack.Effect1 = Attack.AttackEffects1.None;
                                uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, ref attack);
                                attack.Damage = damage;
                                if (attacker.OnFatalStrike())
                                {
                                    if (attacked.EntityFlag == EntityFlag.Monster)
                                    {
                                        if (!attacker.Owner.AlternateEquipment)
                                        {
                                            bool can = false;
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.RightWeapon))
                                                if (attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.RightWeapon).ID / 1000 == 601)
                                                    can = true;
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.LeftWeapon))
                                                if (attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.LeftWeapon).ID / 1000 == 601)
                                                    can = true;
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.RightWeapon))
                                                if (attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.RightWeapon).ID / 1000 == 511)
                                                    can = true;
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.LeftWeapon))
                                                if (attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.LeftWeapon).ID / 1000 == 511)
                                                    can = true;
                                            if (!can)
                                                return;
                                            ushort x = attacked.X;
                                            ushort y = attacked.Y;
                                            Map.UpdateCoordonatesForAngle(ref x, ref y, ServerBase.Kernel.GetAngle(attacked.X, attacked.Y, attacker.X, attacker.Y));
                                            attacker.Shift(x, y);
                                            attack.X = x;
                                            attack.Y = y;
                                            attack.AttackType = Attack.FatalStrike;
                                        }
                                        else
                                        {
                                            bool can = false;
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltRightHand))
                                                if (attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.AltRightHand).ID / 1000 == 601)
                                                    can = true;
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltLeftHand))
                                                if (attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.AltLeftHand).ID / 1000 == 601)
                                                    can = true;
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltRightHand))
                                                if (attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.AltRightHand).ID / 1000 == 511)
                                                    can = true;
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltLeftHand))
                                                if (attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.AltLeftHand).ID / 1000 == 511)
                                                    can = true;
                                            if (!can)
                                                return;
                                            ushort x = attacked.X;
                                            ushort y = attacked.Y;
                                            Map.UpdateCoordonatesForAngle(ref x, ref y, ServerBase.Kernel.GetAngle(attacked.X, attacked.Y, attacker.X, attacker.Y));
                                            attacker.Shift(x, y);
                                            attack.X = x;
                                            attack.Y = y;
                                            attack.AttackType = Attack.FatalStrike;
                                        }
                                    }
                                }
                                //over:
                                if (!attacker.Owner.AlternateEquipment)
                                {
                                    if (!attacker.Owner.Equipment.Free((byte)ConquerItem.RightWeapon))
                                    {
                                        Interfaces.IConquerItem rightweapon = attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.RightWeapon);
                                        ushort wep1subyte = (ushort)(rightweapon.ID / 1000), wep2subyte = 0;
                                        bool wep1bs = false, wep2bs = false;
                                        /*if (wep1subyte == 421)
                                        {
                                            wep1bs = true;
                                            wep1subyte = 420;
                                        }
                                        if (wep1subyte == 511)
                                        {
                                            wep1bs = true;
                                            wep1subyte = 601;
                                        }*/
                                        ushort wep1spellid = 0, wep2spellid = 0;
                                        if (Database.SpellTable.WeaponSpells.ContainsKey(wep1subyte))
                                        {
                                            wep1spellid = Database.SpellTable.WeaponSpells[wep1subyte];
                                        }
                                        /*if (wep1subyte == 601 || wep1subyte == 511)
                                        {
                                            if (Database.SpellTable.WeaponSpells.ContainsKey(11230))
                                            {
                                                wep1spellid = 11230;
                                            }
                                        }*/
                                        Database.SpellInformation wep1spell = null, wep2spell = null;
                                        bool doWep1Spell = false, doWep2Spell = false;
                                        if (attacker.Owner.Spells.ContainsKey(wep1spellid) && Database.SpellTable.SpellInformations.ContainsKey(wep1spellid))
                                        {
                                            wep1spell = Database.SpellTable.SpellInformations[wep1spellid][attacker.Owner.Spells[wep1spellid].Level];
                                            if (wep1spell != null)
                                            {
                                                doWep1Spell = ServerBase.Kernel.Rate(wep1spell.Percent);
                                            }

                                        }

                                        if (!doWep1Spell)
                                        {
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.LeftWeapon))
                                            {
                                                Interfaces.IConquerItem leftweapon = attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.LeftWeapon);
                                                wep2subyte = (ushort)(leftweapon.ID / 1000);
                                                /* if (wep2subyte == 421)
                                                 {
                                                     wep2bs = true;
                                                     wep2subyte = 420;
                                                 }
                                                 if (wep2subyte == 511)
                                                 {
                                                     wep2bs = true;
                                                     wep2subyte=601;
                                                 }*/
                                                if (wep2subyte == 900 || leftweapon.ID == 1050002)
                                                {
                                                    return;
                                                }

                                                if (Database.SpellTable.WeaponSpells.ContainsKey(wep2subyte))
                                                {
                                                    wep2spellid = Database.SpellTable.WeaponSpells[wep2subyte];
                                                }

                                                if (attacker.Owner.Spells.ContainsKey(wep2spellid) && Database.SpellTable.SpellInformations.ContainsKey(wep2spellid))
                                                {
                                                    wep2spell = Database.SpellTable.SpellInformations[wep2spellid][attacker.Owner.Spells[wep2spellid].Level];
                                                    if (wep2spell != null)
                                                    {
                                                        doWep2Spell = ServerBase.Kernel.Rate(wep2spell.Percent);
                                                    }

                                                }

                                            }
                                        }

                                        if (!attacker.Transformed)
                                        {
                                            if (doWep1Spell)
                                            {
                                                attack.AttackType = Attack.Magic;
                                                attack.Decoded = true;
                                                attack.X = attacked.X;
                                                attack.Y = attacked.Y;
                                                attack.Attacked = attacked.UID;
                                                attack.Damage = wep1spell.ID;
                                                goto restart;
                                            }
                                            if (doWep2Spell)
                                            {
                                                attack.AttackType = Attack.Magic;
                                                attack.Decoded = true;
                                                attack.X = attacked.X;
                                                attack.Y = attacked.Y;
                                                attack.Attacked = attacked.UID;
                                                attack.Damage = wep2spell.ID;
                                                goto restart;
                                            }
                                            if (wep1bs)
                                                wep1subyte++;
                                            if (attacker.EntityFlag == EntityFlag.Player && attacked.EntityFlag != EntityFlag.Player)
                                                if (damage > attacked.Hitpoints)
                                                {
                                                    attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attacked.Hitpoints), wep1subyte);
                                                    if (wep2subyte != 0)
                                                    {
                                                        if (wep2bs)
                                                            wep2subyte++;
                                                        attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attacked.Hitpoints), wep2subyte);
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.Owner.IncreaseProficiencyExperience(damage, wep1subyte);
                                                    if (wep2subyte != 0)
                                                    {
                                                        if (wep2bs)
                                                            wep2subyte++;
                                                        attacker.Owner.IncreaseProficiencyExperience(damage, wep2subyte);
                                                    }
                                                }
                                        }
                                    }
                                    else
                                    {
                                        if (!attacker.Transformed)
                                        {
                                            if (attacker.EntityFlag == EntityFlag.Player && attacked.EntityFlag != EntityFlag.Player)
                                                if (damage > attacked.Hitpoints)
                                                {
                                                    attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attacked.Hitpoints), 0);
                                                }
                                                else
                                                {
                                                    attacker.Owner.IncreaseProficiencyExperience(damage, 0);
                                                }
                                        }
                                    }
                                }
                                else
                                {
                                    if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltRightHand))
                                    {
                                        Interfaces.IConquerItem rightweapon = attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.AltRightHand);
                                        ushort wep1subyte = (ushort)(rightweapon.ID / 1000), wep2subyte = 0;
                                        bool wep1bs = false, wep2bs = false;
                                        /* if (wep1subyte == 421)
                                         {
                                             wep1bs = true;
                                             wep1subyte = 420;
                                         }
                                         if (wep1subyte == 511)
                                         {
                                             wep1bs = true;
                                             wep1subyte = 601;
                                         }*/

                                        ushort wep1spellid = 0, wep2spellid = 0;
                                        if (Database.SpellTable.WeaponSpells.ContainsKey(wep1subyte))
                                        {
                                            wep1spellid = Database.SpellTable.WeaponSpells[wep1subyte];
                                        }

                                        Database.SpellInformation wep1spell = null, wep2spell = null;
                                        bool doWep1Spell = false, doWep2Spell = false;
                                        if (attacker.Owner.Spells.ContainsKey(wep1spellid) && Database.SpellTable.SpellInformations.ContainsKey(wep1spellid))
                                        {
                                            wep1spell = Database.SpellTable.SpellInformations[wep1spellid][attacker.Owner.Spells[wep1spellid].Level];
                                            doWep1Spell = ServerBase.Kernel.Rate(wep1spell.Percent);

                                        }

                                        if (!doWep1Spell)
                                        {
                                            if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltLeftHand))
                                            {
                                                Interfaces.IConquerItem leftweapon = attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.AltLeftHand);
                                                wep2subyte = (ushort)(leftweapon.ID / 1000);
                                                /* if (wep2subyte == 421)
                                                 {
                                                     wep2bs = true;
                                                     wep2subyte = 420;
                                                 }
                                                 if (wep2subyte == 511)
                                                 {
                                                     wep2bs = true;
                                                     wep2subyte = 601;
                                                 }*/
                                                if (wep2subyte == 900 || leftweapon.ID == 1050002)
                                                {
                                                    return;
                                                }
                                                if (Database.SpellTable.WeaponSpells.ContainsKey(wep2subyte))
                                                {
                                                    wep2spellid = Database.SpellTable.WeaponSpells[wep2subyte];
                                                }

                                                if (attacker.Owner.Spells.ContainsKey(wep2spellid) && Database.SpellTable.SpellInformations.ContainsKey(wep2spellid))
                                                {
                                                    wep2spell = Database.SpellTable.SpellInformations[wep2spellid][attacker.Owner.Spells[wep2spellid].Level];
                                                    doWep2Spell = ServerBase.Kernel.Rate(wep2spell.Percent);

                                                }

                                            }
                                        }

                                        if (!attacker.Transformed)
                                        {
                                            if (doWep1Spell)
                                            {
                                                attack.AttackType = Attack.Magic;
                                                attack.Decoded = true;
                                                attack.X = attacked.X;
                                                attack.Y = attacked.Y;
                                                attack.Attacked = attacked.UID;
                                                attack.Damage = wep1spell.ID;
                                                goto restart;
                                            }
                                            if (doWep2Spell)
                                            {
                                                attack.AttackType = Attack.Magic;
                                                attack.Decoded = true;
                                                attack.X = attacked.X;
                                                attack.Y = attacked.Y;
                                                attack.Attacked = attacked.UID;
                                                attack.Damage = wep2spell.ID;
                                                goto restart;
                                            }
                                            if (wep1bs)
                                                wep1subyte++;
                                            if (attacker.EntityFlag == EntityFlag.Player && attacked.EntityFlag != EntityFlag.Player)
                                                if (damage > attacked.Hitpoints)
                                                {
                                                    attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attacked.Hitpoints), wep1subyte);
                                                    if (wep2subyte != 0)
                                                    {
                                                        if (wep2bs)
                                                            wep2subyte++;
                                                        attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attacked.Hitpoints), wep2subyte);
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.Owner.IncreaseProficiencyExperience(damage, wep1subyte);
                                                    if (wep2subyte != 0)
                                                    {
                                                        if (wep2bs)
                                                            wep2subyte++;
                                                        attacker.Owner.IncreaseProficiencyExperience(damage, wep2subyte);
                                                    }
                                                }
                                        }
                                    }
                                    else
                                    {
                                        if (!attacker.Transformed)
                                        {
                                            if (attacker.EntityFlag == EntityFlag.Player && attacked.EntityFlag != EntityFlag.Player)
                                                if (damage > attacked.Hitpoints)
                                                {
                                                    attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attacked.Hitpoints), 0);
                                                }
                                                else
                                                {
                                                    attacker.Owner.IncreaseProficiencyExperience(damage, 0);
                                                }
                                        }
                                    }
                                }
                                ReceiveAttack(attacker, attacked, attack, damage, null);
                                attack.AttackType = Attack.Melee;
                            }
                            else
                            {
                                attacker.AttackPacket = null;
                            }
                        }
                        else if (attacker.Owner.Screen.TryGetSob(attack.Attacked, out attackedsob))
                        {
                            // Console.WriteLine("Ss");
                            if (CanAttack(attacker, attackedsob, null))
                            {
                                ushort range = attacker.AttackRange;
                                if (attacker.Transformed)
                                    range = (ushort)attacker.TransformationAttackRange;
                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= range)
                                {
                                    attack.Effect1 = Attack.AttackEffects1.None;
                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);

                                    if (!attacker.Owner.AlternateEquipment)
                                    {
                                        if (!attacker.Owner.Equipment.Free((byte)ConquerItem.RightWeapon))
                                        {
                                            Interfaces.IConquerItem rightweapon = attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.RightWeapon);
                                            ushort wep1subyte = (ushort)(rightweapon.ID / 1000), wep2subyte = 0;
                                            bool wep1bs = false, wep2bs = false;
                                            /* if (wep1subyte == 421)
                                             {
                                                 wep1bs = true;
                                                 wep1subyte=420;
                                             }
                                             if (wep1subyte == 511)
                                             {
                                                 wep1bs = true;
                                                 wep1subyte=601;
                                             }*/
                                            ushort wep1spellid = 0, wep2spellid = 0;
                                            if (Database.SpellTable.WeaponSpells.ContainsKey(wep1subyte))
                                                wep1spellid = Database.SpellTable.WeaponSpells[wep1subyte];
                                            Database.SpellInformation wep1spell = null, wep2spell = null;
                                            bool doWep1Spell = false, doWep2Spell = false;
                                            if (attacker.Owner.Spells.ContainsKey(wep1spellid) && Database.SpellTable.SpellInformations.ContainsKey(wep1spellid))
                                            {
                                                wep1spell = Database.SpellTable.SpellInformations[wep1spellid][attacker.Owner.Spells[wep1spellid].Level];
                                                doWep1Spell = ServerBase.Kernel.Rate(wep1spell.Percent);
                                            }
                                            if (!doWep1Spell)
                                            {
                                                if (!attacker.Owner.Equipment.Free((byte)ConquerItem.LeftWeapon))
                                                {
                                                    Interfaces.IConquerItem leftweapon = attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.LeftWeapon);
                                                    wep2subyte = (ushort)(leftweapon.ID / 1000);
                                                    /* if (wep2subyte == 421)
                                                     {
                                                         wep2bs = true;
                                                         wep2subyte = 420;
                                                     }
                                                     if (wep2subyte == 511)
                                                     {
                                                         wep2bs = true;
                                                         wep2subyte = 601;
                                                     }*/
                                                    if (Database.SpellTable.WeaponSpells.ContainsKey(wep2subyte))
                                                        wep2spellid = Database.SpellTable.WeaponSpells[wep2subyte];
                                                    if (attacker.Owner.Spells.ContainsKey(wep2spellid) && Database.SpellTable.SpellInformations.ContainsKey(wep2spellid))
                                                    {
                                                        wep2spell = Database.SpellTable.SpellInformations[wep2spellid][attacker.Owner.Spells[wep2spellid].Level];
                                                        doWep2Spell = ServerBase.Kernel.Rate(wep2spell.Percent);
                                                    }
                                                }
                                            }

                                            if (!attacker.Transformed)
                                            {

                                                if (doWep1Spell)
                                                {
                                                    attack.AttackType = Attack.Magic;
                                                    attack.Decoded = true;
                                                    attack.X = attackedsob.X;
                                                    attack.Y = attackedsob.Y;
                                                    attack.Attacked = attackedsob.UID;
                                                    attack.Damage = wep1spell.ID;
                                                    goto restart;
                                                }
                                                if (doWep2Spell)
                                                {
                                                    attack.AttackType = Attack.Magic;
                                                    attack.Decoded = true;
                                                    attack.X = attackedsob.X;
                                                    attack.Y = attackedsob.Y;
                                                    attack.Attacked = attackedsob.UID;
                                                    attack.Damage = wep2spell.ID;
                                                    goto restart;
                                                }
                                                if (attacker.MapID == 1039)
                                                {
                                                    /* if (wep1bs)
                                                         wep1subyte++;*/
                                                    if (attacker.EntityFlag == EntityFlag.Player)
                                                        if (damage > attackedsob.Hitpoints)
                                                        {
                                                            attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attackedsob.Hitpoints), wep1subyte);
                                                            if (wep2subyte != 0)
                                                            {
                                                                /* if (wep2bs)
                                                                     wep2subyte++;*/
                                                                attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attackedsob.Hitpoints), wep2subyte);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            attacker.Owner.IncreaseProficiencyExperience(damage, wep1subyte);
                                                            if (wep2subyte != 0)
                                                            {
                                                                /*if (wep2bs)
                                                                    wep2subyte++;*/
                                                                attacker.Owner.IncreaseProficiencyExperience(damage, wep2subyte);
                                                            }
                                                        }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltRightHand))
                                        {
                                            Interfaces.IConquerItem rightweapon = attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.AltRightHand);
                                            ushort wep1subyte = (ushort)(rightweapon.ID / 1000), wep2subyte = 0;
                                            bool wep1bs = false, wep2bs = false;
                                            /*if (wep1subyte == 421)
                                            {
                                                wep1bs = true;
                                                wep1subyte = 420;
                                            }
                                            if (wep1subyte == 511)
                                            {
                                                wep1bs = true;
                                                wep1subyte = 601;
                                            }*/
                                            ushort wep1spellid = 0, wep2spellid = 0;
                                            if (Database.SpellTable.WeaponSpells.ContainsKey(wep1subyte))
                                                wep1spellid = Database.SpellTable.WeaponSpells[wep1subyte];
                                            Database.SpellInformation wep1spell = null, wep2spell = null;
                                            bool doWep1Spell = false, doWep2Spell = false;
                                            if (attacker.Owner.Spells.ContainsKey(wep1spellid) && Database.SpellTable.SpellInformations.ContainsKey(wep1spellid))
                                            {
                                                wep1spell = Database.SpellTable.SpellInformations[wep1spellid][attacker.Owner.Spells[wep1spellid].Level];
                                                doWep1Spell = ServerBase.Kernel.Rate(wep1spell.Percent);
                                            }
                                            if (!doWep1Spell)
                                            {
                                                if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltLeftHand))
                                                {
                                                    Interfaces.IConquerItem leftweapon = attacker.Owner.Equipment.TryGetItem((byte)ConquerItem.AltLeftHand);
                                                    wep2subyte = (ushort)(leftweapon.ID / 1000);
                                                    /* if (wep2subyte == 421)
                                                     {
                                                         wep2bs = true;
                                                         wep2subyte = 420;
                                                     }
                                                     if (wep2subyte == 511)
                                                     {
                                                         wep2bs = true;
                                                         wep2subyte = 601;
                                                     }*/
                                                    if (Database.SpellTable.WeaponSpells.ContainsKey(wep2subyte))
                                                        wep2spellid = Database.SpellTable.WeaponSpells[wep2subyte];
                                                    if (attacker.Owner.Spells.ContainsKey(wep2spellid) && Database.SpellTable.SpellInformations.ContainsKey(wep2spellid))
                                                    {
                                                        wep2spell = Database.SpellTable.SpellInformations[wep2spellid][attacker.Owner.Spells[wep2spellid].Level];
                                                        doWep2Spell = ServerBase.Kernel.Rate(wep2spell.Percent);
                                                    }
                                                }
                                            }

                                            if (!attacker.Transformed)
                                            {
                                                if (doWep1Spell)
                                                {
                                                    attack.AttackType = Attack.Magic;
                                                    attack.Decoded = true;
                                                    attack.X = attackedsob.X;
                                                    attack.Y = attackedsob.Y;
                                                    attack.Attacked = attackedsob.UID;
                                                    attack.Damage = wep1spell.ID;
                                                    goto restart;
                                                }
                                                if (doWep2Spell)
                                                {
                                                    attack.AttackType = Attack.Magic;
                                                    attack.Decoded = true;
                                                    attack.X = attackedsob.X;
                                                    attack.Y = attackedsob.Y;
                                                    attack.Attacked = attackedsob.UID;
                                                    attack.Damage = wep2spell.ID;
                                                    goto restart;
                                                }
                                                if (attacker.MapID == 1039)
                                                {
                                                    if (wep1bs)
                                                        wep1subyte++;
                                                    if (attacker.EntityFlag == EntityFlag.Player)
                                                        if (damage > attackedsob.Hitpoints)
                                                        {
                                                            attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attackedsob.Hitpoints), wep1subyte);
                                                            if (wep2subyte != 0)
                                                            {
                                                                if (wep2bs)
                                                                    wep2subyte++;
                                                                attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attackedsob.Hitpoints), wep2subyte);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            attacker.Owner.IncreaseProficiencyExperience(damage, wep1subyte);
                                                            if (wep2subyte != 0)
                                                            {
                                                                if (wep2bs)
                                                                    wep2subyte++;
                                                                attacker.Owner.IncreaseProficiencyExperience(damage, wep2subyte);
                                                            }
                                                        }
                                                }
                                            }
                                        }
                                    }
                                    attack.Damage = damage;
                                    ReceiveAttack(attacker, attackedsob, attack, damage, null);
                                }
                                else
                                {
                                    attacker.AttackPacket = null;
                                }
                            }
                        }
                        else
                        {
                            attacker.AttackPacket = null;
                        }
                    }
                    #endregion
                    #region Ranged
                    else if (attack.AttackType == Attack.Ranged)
                    {

                        if (attacker.Owner.Screen.TryGetValue(attack.Attacked, out attacked))
                        {
                            if (!attacker.Owner.AlternateEquipment)
                            {
                                CheckForExtraWeaponPowers(attacker.Owner, attacked);
                            }
                            else
                            {
                                CheckForExtraWeaponPowers2(attacker.Owner, attacked);
                            }
                            if (attacker.Owner.Equipment.TryGetItem(ConquerItem.LeftWeapon) == null)
                                return;
                            if (!CanAttack(attacker, attacked, null, attack.AttackType == Attack.Melee))
                                return;
                            if (!attacker.Owner.AlternateEquipment)
                            {
                                if (!attacker.Owner.Equipment.Free((byte)ConquerItem.LeftWeapon))
                                {
                                    Interfaces.IConquerItem arrow = attacker.Owner.Equipment.TryGetItem(ConquerItem.LeftWeapon);
                                    arrow.Durability -= 1;
                                    ItemUsage usage = new ItemUsage(true) { UID = arrow.UID, dwParam = arrow.Durability, ID = ItemUsage.UpdateDurability };
                                    usage.Send(attacker.Owner);
                                    if (arrow.Durability <= 0 || arrow.Durability > 5000)
                                    {
                                        Network.PacketHandler.ReloadArrows(attacker.Owner.Equipment.TryGetItem(ConquerItem.LeftWeapon), attacker.Owner);
                                    }
                                }
                            }
                            else
                            {
                                if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltLeftHand))
                                {
                                    Interfaces.IConquerItem arrow = attacker.Owner.Equipment.TryGetItem(ConquerItem.AltLeftHand);
                                    arrow.Durability -= 1;
                                    ItemUsage usage = new ItemUsage(true) { UID = arrow.UID, dwParam = arrow.Durability, ID = ItemUsage.UpdateDurability };
                                    usage.Send(attacker.Owner);
                                    if (arrow.Durability <= 0 || arrow.Durability > 5000)
                                    {
                                        Network.PacketHandler.ReloadArrows(attacker.Owner.Equipment.TryGetItem(ConquerItem.AltLeftHand), attacker.Owner);
                                    }
                                }
                            }
                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= ServerBase.Constants.pScreenDistance)
                            {
                                attack.Effect1 = Attack.AttackEffects1.None;
                                uint damage = Game.Attacking.Calculate.Ranged(attacker, attacked, ref attack);

                                attack.Damage = damage;
                                if (attacker.EntityFlag == EntityFlag.Player && attacked.EntityFlag != EntityFlag.Player)
                                    if (damage > attacked.Hitpoints)
                                    {
                                        attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attacked.Hitpoints), 500);
                                    }
                                    else
                                    {
                                        attacker.Owner.IncreaseProficiencyExperience(damage, 500);
                                    }
                                ReceiveAttack(attacker, attacked, attack, damage, null);
                            }
                        }
                        else if (attacker.Owner.Screen.TryGetSob(attack.Attacked, out attackedsob))
                        {
                            if (CanAttack(attacker, attackedsob, null))
                            {
                                if (attacker.Owner.Equipment.TryGetItem(ConquerItem.LeftWeapon) == null)
                                    return;
                                if (attacker.MapID != 1039)
                                {
                                    if (!attacker.Owner.AlternateEquipment)
                                    {
                                        if (!attacker.Owner.Equipment.Free((byte)ConquerItem.LeftWeapon))
                                        {
                                            Interfaces.IConquerItem arrow = attacker.Owner.Equipment.TryGetItem(ConquerItem.LeftWeapon);
                                            arrow.Durability -= 1;
                                            ItemUsage usage = new ItemUsage(true) { UID = arrow.UID, dwParam = arrow.Durability, ID = ItemUsage.UpdateDurability };
                                            usage.Send(attacker.Owner);
                                            if (arrow.Durability <= 0 || arrow.Durability > 5000)
                                            {
                                                Network.PacketHandler.ReloadArrows(attacker.Owner.Equipment.TryGetItem(ConquerItem.LeftWeapon), attacker.Owner);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (!attacker.Owner.Equipment.Free((byte)ConquerItem.AltLeftHand))
                                        {
                                            Interfaces.IConquerItem arrow = attacker.Owner.Equipment.TryGetItem(ConquerItem.AltLeftHand);
                                            arrow.Durability -= 1;
                                            ItemUsage usage = new ItemUsage(true) { UID = arrow.UID, dwParam = arrow.Durability, ID = ItemUsage.UpdateDurability };
                                            usage.Send(attacker.Owner);
                                            if (arrow.Durability <= 0 || arrow.Durability > 5000)
                                            {
                                                Network.PacketHandler.ReloadArrows(attacker.Owner.Equipment.TryGetItem(ConquerItem.AltLeftHand), attacker.Owner);
                                            }
                                        }
                                    }
                                }
                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= ServerBase.Constants.pScreenDistance)
                                {
                                    attack.Effect1 = Attack.AttackEffects1.None;
                                    uint damage = Game.Attacking.Calculate.Ranged(attacker, attackedsob, ref attack);
                                    attack.Damage = damage;
                                    ReceiveAttack(attacker, attackedsob, attack, damage, null);
                                    if (damage > attackedsob.Hitpoints)
                                    {
                                        attacker.Owner.IncreaseProficiencyExperience(Math.Min(damage, attackedsob.Hitpoints), 500);
                                    }
                                    else
                                    {
                                        attacker.Owner.IncreaseProficiencyExperience(damage, 500);
                                    }
                                }
                            }
                        }
                        else
                        {
                            attacker.AttackPacket = null;
                        }
                    }
                    #endregion
                    #region Magic
                    else if (attack.AttackType == Attack.Magic)
                    {
                        if (!attacker.Owner.AlternateEquipment)
                        {
                            CheckForExtraWeaponPowers(attacker.Owner, attacked);
                        }
                        else
                        {
                            CheckForExtraWeaponPowers2(attacker.Owner, attacked);
                        }
                        uint Experience = 100;
                        bool shuriken = false;
                        ushort spellID = SpellID;
                        if (SpellID >= 3090 && SpellID <= 3306)
                            spellID = 3090;
                        if (spellID == 6012)
                            shuriken = true;

                        if (attacker == null)
                            return;
                        if (attacker.Owner == null)
                        {
                            attacker.AttackPacket = null;
                            return;
                        }
                        if (attacker.Owner.Spells == null)
                        {
                            attacker.Owner.Spells = new SafeDictionary<ushort, PhoenixProject.Interfaces.ISkill>(10000);
                            attacker.AttackPacket = null;
                            return;
                        }
                        if (attacker.Owner.Spells[spellID] == null && spellID != 6012)
                        {
                            attacker.AttackPacket = null;
                            return;
                        }

                        Database.SpellInformation spell = null;
                        if (shuriken)
                            spell = Database.SpellTable.SpellInformations[6010][0];
                        else
                        {
                            byte choselevel = 0;
                            if (spellID == SpellID)
                                choselevel = attacker.Owner.Spells[spellID].Level;
                            if (Database.SpellTable.SpellInformations[SpellID] != null && !Database.SpellTable.SpellInformations[SpellID].ContainsKey(choselevel))
                                choselevel = (byte)(Database.SpellTable.SpellInformations[SpellID].Count - 1);

                            spell = Database.SpellTable.SpellInformations[SpellID][choselevel];
                        }
                        if (spell == null)
                        {
                            attacker.AttackPacket = null;
                            return;
                        }
                        attacked = null;
                        attackedsob = null;
                        if (attacker.Owner.Screen.TryGetValue(Target, out attacked) || attacker.Owner.Screen.TryGetSob(Target, out attackedsob) || Target == attacker.UID || spell.Sort != 1)
                        {
                            if (Target == attacker.UID)
                                attacked = attacker;
                            if (attacked != null)
                            {
                                if (attacked.Dead && spell.Sort != Database.SpellSort.Revive && spell.ID != 10405 && spell.ID != 10425)
                                {
                                    attacker.AttackPacket = null;
                                    return;
                                }
                            }
                            if (Target >= 400000 && Target <= 600000 || Target >= 800000)
                            {
                                if (attacked == null && attackedsob == null)
                                    return;
                            }
                            else if (Target != 0 && attackedsob == null)
                                return;
                            if (attacked != null)
                            {
                                if (attacked.EntityFlag == EntityFlag.Monster)
                                {
                                    if (spell.CanKill == 1)
                                    {
                                        if (attacked.MonsterInfo.InSight == 0)
                                        {
                                            attacked.MonsterInfo.InSight = attacker.UID;
                                        }
                                    }
                                }
                            }
                            if (!attacker.Owner.Spells.ContainsKey(spellID))
                            {
                                if (spellID != 6012)
                                    return;
                            }
                            if (spell != null)
                            {
                                if (!attacker.Owner.AlternateEquipment)
                                {
                                    if (spell.OnlyWithThisWeaponSubtype != 0)
                                    {
                                        uint firstwepsubtype, secondwepsubtype;

                                        if (!attacker.Owner.Equipment.Free(4))
                                        {
                                            firstwepsubtype = attacker.Owner.Equipment.Objects[3].ID / 1000;
                                            if (!attacker.Owner.Equipment.Free(5) && attacker.Owner.Equipment.Objects[4] != null)
                                            {
                                                secondwepsubtype = attacker.Owner.Equipment.Objects[4].ID / 1000;
                                                if (firstwepsubtype != spell.OnlyWithThisWeaponSubtype)
                                                {
                                                    if (secondwepsubtype != spell.OnlyWithThisWeaponSubtype)
                                                    {
                                                        attacker.AttackPacket = null;
                                                        return;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (firstwepsubtype != spell.OnlyWithThisWeaponSubtype)
                                                {
                                                    attacker.AttackPacket = null;
                                                    return;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            attacker.AttackPacket = null;
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        if (spell.OnlyWithThisWeaponSubtype != 0)
                                        {
                                            uint firstwepsubtype, secondwepsubtype;

                                            if (!attacker.Owner.Equipment.Free(24))
                                            {
                                                firstwepsubtype = attacker.Owner.Equipment.Objects[23].ID / 1000;
                                                if (!attacker.Owner.Equipment.Free(24) && attacker.Owner.Equipment.Objects[24] != null)
                                                {
                                                    secondwepsubtype = attacker.Owner.Equipment.Objects[24].ID / 1000;
                                                    if (firstwepsubtype != spell.OnlyWithThisWeaponSubtype)
                                                    {
                                                        if (secondwepsubtype != spell.OnlyWithThisWeaponSubtype)
                                                        {
                                                            attacker.AttackPacket = null;
                                                            return;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (firstwepsubtype != spell.OnlyWithThisWeaponSubtype)
                                                    {
                                                        attacker.AttackPacket = null;
                                                        return;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                attacker.AttackPacket = null;
                                                return;
                                            }
                                        }

                                    }
                                }
                                if (attacker.Owner.Account.State == PhoenixProject.Database.AccountTable.AccountState.Coder)
                                {
                                    attacker.Owner.Send(new Message("Spell ID: " + spellID, System.Drawing.Color.CadetBlue, Message.Talk));
                                }
                                switch (spellID)
                                {
                                    #region Single magic damage spells
                                    case 1000:
                                    case 1001:
                                    case 1002:
                                    case 1150:
                                    case 1160:
                                    case 1180:
                                    case 1320:
                                    case 10310:
                                    case 11180:
                                        //case 11040:
                                        //case 10381:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                if (attacked != null)
                                                {
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Distance)
                                                    {
                                                        SpellUse suse = new SpellUse(true);
                                                        suse.Attacker = attacker.UID;
                                                        suse.SpellID = spell.ID;
                                                        suse.SpellLevel = spell.Level;
                                                        suse.X = X;
                                                        suse.Y = Y;

                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);

                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                            uint damage = Game.Attacking.Calculate.Magic(attacker, attacked, spell, ref attack);
                                                            suse.Effect1 = attack.Effect1;

                                                            ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                            suse.Targets.Add(attacked.UID, damage);

                                                            if (attacked.EntityFlag == EntityFlag.Player)
                                                                attacked.Owner.SendScreen(suse, true);
                                                            else
                                                                attacked.MonsterInfo.SendScreen(suse);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        attacker.AttackPacket = null;
                                                    }
                                                }
                                                else
                                                {
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Distance)
                                                    {
                                                        SpellUse suse = new SpellUse(true);
                                                        suse.Attacker = attacker.UID;
                                                        suse.SpellID = spell.ID;
                                                        suse.SpellLevel = spell.Level;
                                                        suse.X = X;
                                                        suse.Y = Y;

                                                        if (CanAttack(attacker, attackedsob, spell))
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);
                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                            uint damage = Game.Attacking.Calculate.Magic(attacker, attackedsob, spell, ref attack);
                                                            suse.Effect1 = attack.Effect1;

                                                            ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                            suse.Targets.Add(attackedsob.UID, damage);

                                                            attacker.Owner.SendScreen(suse, true);
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                attacker.AttackPacket = null;
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Single heal/meditation spells
                                    case 1190:
                                    case 1195:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;

                                                uint damage = spell.Power;
                                                if (spell.ID == 1190)
                                                {
                                                    Experience = damage = Math.Min(damage, attacker.MaxHitpoints - attacker.Hitpoints);
                                                    attacker.Hitpoints += damage;
                                                }
                                                else
                                                {
                                                    Experience = damage = Math.Min(damage, (uint)(attacker.MaxMana - attacker.Mana));
                                                    attacker.Mana += (ushort)damage;
                                                }

                                                suse.Targets.Add(attacker.UID, spell.Power);

                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Multi heal spells
                                    case 1005:
                                    case 1055:
                                    case 1170:
                                    case 1175:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                if (attackedsob != null)
                                                {
                                                    if (attacker.MapID == 1038)
                                                        break;
                                                    if (attacker.MapID == 2071)
                                                        break;
                                                    if (attacker.MapID == 1509)
                                                        break;
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Distance)
                                                    {
                                                        PrepareSpell(spell, attacker.Owner);

                                                        uint damage = spell.Power;
                                                        damage = Math.Min(damage, attackedsob.MaxHitpoints - attackedsob.Hitpoints);
                                                        attackedsob.Hitpoints += damage;
                                                        Experience += damage;
                                                        suse.Targets.Add(attackedsob.UID, damage);

                                                        attacker.Owner.SendScreen(suse, true);
                                                    }
                                                }
                                                else
                                                {
                                                    if (spell.Multi == 1)
                                                    {
                                                        if (attacker.Owner.Team != null)
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);
                                                            foreach (Client.GameState teammate in attacker.Owner.Team.Teammates)
                                                            {
                                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, teammate.Entity.X, teammate.Entity.Y) <= spell.Distance)
                                                                {
                                                                    uint damage = spell.Power;
                                                                    damage = Math.Min(damage, teammate.Entity.MaxHitpoints - teammate.Entity.Hitpoints);
                                                                    teammate.Entity.Hitpoints += damage;
                                                                    Experience += damage;
                                                                    suse.Targets.Add(teammate.Entity.UID, damage);

                                                                    if (spell.NextSpellID != 0)
                                                                    {
                                                                        attack.Damage = spell.NextSpellID;
                                                                        attacker.AttackPacket = attack;
                                                                    }
                                                                    else
                                                                    {
                                                                        attacker.AttackPacket = null;
                                                                    }
                                                                }
                                                            }
                                                            if (attacked.EntityFlag == EntityFlag.Player)
                                                                attacked.Owner.SendScreen(suse, true);
                                                            else
                                                                attacked.MonsterInfo.SendScreen(suse);
                                                        }
                                                        else
                                                        {
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Distance)
                                                            {
                                                                PrepareSpell(spell, attacker.Owner);

                                                                uint damage = spell.Power;
                                                                damage = Math.Min(damage, attacked.MaxHitpoints - attacked.Hitpoints);
                                                                attacked.Hitpoints += damage;
                                                                Experience += damage;
                                                                suse.Targets.Add(attacked.UID, damage);

                                                                if (spell.NextSpellID != 0)
                                                                {
                                                                    attack.Damage = spell.NextSpellID;
                                                                    attacker.AttackPacket = attack;
                                                                }
                                                                else
                                                                {
                                                                    attacker.AttackPacket = null;
                                                                }
                                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                                    attacked.Owner.SendScreen(suse, true);
                                                                else
                                                                    attacked.MonsterInfo.SendScreen(suse);
                                                            }
                                                            else
                                                            {
                                                                attacker.AttackPacket = null;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Distance)
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);

                                                            uint damage = spell.Power;
                                                            damage = Math.Min(damage, attacked.MaxHitpoints - attacked.Hitpoints);
                                                            attacked.Hitpoints += damage;
                                                            Experience += damage;
                                                            suse.Targets.Add(attacked.UID, damage);

                                                            if (spell.NextSpellID != 0)
                                                            {
                                                                attack.Damage = spell.NextSpellID;
                                                                attacker.AttackPacket = attack;
                                                            }
                                                            else
                                                            {
                                                                attacker.AttackPacket = null;
                                                            }
                                                            if (attacked.EntityFlag == EntityFlag.Player)
                                                                attacked.Owner.SendScreen(suse, true);
                                                            else
                                                                attacked.MonsterInfo.SendScreen(suse);
                                                        }
                                                        else
                                                        {
                                                            attacker.AttackPacket = null;
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                attacker.AttackPacket = null;
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Revive
                                    case 1050:
                                    case 1100:
                                        {
                                            if (attackedsob != null)
                                                return;
                                            if (ServerBase.Constants.revnomap.Contains(attacker.MapID))
                                                return;
                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Distance)
                                            {
                                                if (CanUseSpell(spell, attacker.Owner))
                                                {
                                                    PrepareSpell(spell, attacker.Owner);

                                                    SpellUse suse = new SpellUse(true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = spell.ID;
                                                    suse.SpellLevel = spell.Level;
                                                    suse.X = X;
                                                    suse.Y = Y;

                                                    //suse.Targets.Add(attacked.UID, 0);
                                                    //attacked.Action = PhoenixProject.Game.Enums.ConquerAction.None;
                                                    //attacked.Owner.ReviveStamp = Time32.Now;
                                                    //attacked.Owner.Attackable = false;

                                                    attacked.Owner.Entity.Action = PhoenixProject.Game.Enums.ConquerAction.None;
                                                    attacked.Owner.ReviveStamp = Time32.Now;
                                                    attacked.Owner.Attackable = false;

                                                    attacked.Owner.Entity.TransformationID = 0;
                                                    attacked.Owner.Entity.RemoveFlag(Update.Flags.Dead);
                                                    attacked.Owner.Entity.RemoveFlag(Update.Flags.Ghost);
                                                    attacked.Owner.Entity.Hitpoints = attacked.Owner.Entity.MaxHitpoints;

                                                    attacked.Ressurect();

                                                    attacked.Owner.SendScreen(suse, true);
                                                }
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Linear spells
                                    case 1045:
                                    case 1046:
                                    // case 11110:
                                    case 1260:
                                    case 11000:
                                    case 11005:
                                        {

                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);
                                                Game.Attacking.InLineAlgorithm ila = new PhoenixProject.Game.Attacking.InLineAlgorithm(attacker.X,
                                            X, attacker.Y, Y, (byte)spell.Range, InLineAlgorithm.Algorithm.DDA);
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = SpellID;
                                                suse.SpellLevel = attacker.Owner.Spells[SpellID].Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                int xx = 0;
                                                int yy = 0;
                                                foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                {
                                                    if (_obj == null)
                                                        continue;
                                                    if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                    {
                                                        attacked = _obj as Entity;
                                                        if (ila.InLine(attacked.X, attacked.Y))
                                                        {
                                                            if (attacked.X != xx && attacked.Y != yy)
                                                            {
                                                                if (!CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                    continue;

                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                                suse.Effect1 = attack.Effect1;

                                                                attack.Damage = damage;
                                                                xx = attacked.X;
                                                                yy = attacked.Y;
                                                                ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                suse.Targets.Add(attacked.UID, damage);
                                                            }
                                                        }
                                                    }
                                                    else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                    {
                                                        attackedsob = _obj as SobNpcSpawn;

                                                        if (ila.InLine(attackedsob.X, attackedsob.Y))
                                                        {
                                                            if (!CanAttack(attacker, attackedsob, spell))
                                                                continue;

                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                            damage = (uint)(damage * spell.PowerPercent);
                                                            attack.Damage = damage;

                                                            ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                            suse.Targets.Add(attackedsob.UID, damage);
                                                        }
                                                    }
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region BladeTempst

                                    case 11110:
                                        {

                                            bool yes = true;
                                            Game.Map Map = attacker.Owner.Map;
                                            // ushort rr = ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y);
                                            Game.Attacking.InLineAlgorithm ila = new PhoenixProject.Game.Attacking.InLineAlgorithm(attacker.X,
                                               X, attacker.Y, Y, (byte)ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y), InLineAlgorithm.Algorithm.DDA);
                                            List<InLineAlgorithm.coords>.Enumerator enumerator6;
                                            ushort x = 0;
                                            ushort y = 0;
                                            using (enumerator6 = ila.getCoords.GetEnumerator())
                                            {
                                                while (enumerator6.MoveNext())
                                                {
                                                    if (yes)
                                                    {
                                                        Func<IMapObject, bool> func4 = null;
                                                        InLineAlgorithm.coords coord = enumerator6.Current;

                                                        if (Map.Floor[coord.X, coord.Y, Game.MapObjectType.Player, null])
                                                        {
                                                            if (attacker.MapID == 1038)
                                                            {
                                                                if (attacker.X > 223 && attacker.Y < 185 && coord.X < 224)
                                                                {
                                                                    // Console.WriteLine(" r " + PhoenixProject.Game.ConquerStructures.Society.GuildWar.RightGate.Mesh + "");
                                                                    if (PhoenixProject.Game.ConquerStructures.Society.GuildWar.RightGate.Mesh == 271)
                                                                    {
                                                                        yes = false;
                                                                    }
                                                                    else
                                                                    {
                                                                        yes = true;
                                                                        x = (ushort)coord.X;
                                                                        y = (ushort)coord.Y;
                                                                        foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                                        {
                                                                            if (_obj == null)
                                                                                continue;
                                                                            if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                                            {
                                                                                attacked = _obj as Entity;
                                                                                if (ServerBase.Kernel.GetDistance((ushort)coord.X, (ushort)coord.Y, attacked.X, attacked.Y) <= 1)
                                                                                {
                                                                                    attacked.CanBlade = true;
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    //Console.WriteLine(" r " + PhoenixProject.Game.ConquerStructures.Society.GuildWar.LeftGate.Mesh + "");
                                                                    if (attacker.X < 170 && attacker.Y > 210 && coord.Y < 211)
                                                                    {
                                                                        if (PhoenixProject.Game.ConquerStructures.Society.GuildWar.LeftGate.Mesh == 241)
                                                                        {
                                                                            yes = false;
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        yes = true;
                                                                        x = (ushort)coord.X;
                                                                        y = (ushort)coord.Y;
                                                                        foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                                        {
                                                                            if (_obj == null)
                                                                                continue;
                                                                            if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                                            {
                                                                                attacked = _obj as Entity;
                                                                                if (ServerBase.Kernel.GetDistance((ushort)coord.X, (ushort)coord.Y, attacked.X, attacked.Y) <= 1)
                                                                                {
                                                                                    attacked.CanBlade = true;
                                                                                }
                                                                            }
                                                                        }
                                                                    }

                                                                }



                                                            }
                                                            else
                                                            {
                                                                yes = true;
                                                                x = (ushort)coord.X;
                                                                y = (ushort)coord.Y;
                                                                foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                                {
                                                                    if (_obj == null)
                                                                        continue;
                                                                    if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                                    {
                                                                        attacked = _obj as Entity;
                                                                        if (ServerBase.Kernel.GetDistance((ushort)coord.X, (ushort)coord.Y, attacked.X, attacked.Y) <= 1)
                                                                        {
                                                                            attacked.CanBlade = true;
                                                                        }
                                                                    }
                                                                }
                                                            }

                                                        }
                                                        else
                                                        {
                                                            yes = false;
                                                        }
                                                    }
                                                }
                                            }
                                            yes = true;
                                            X = x;
                                            Y = y;

                                            if (Map.Floor[X, Y, Game.MapObjectType.Player, null] && yes)
                                            {
                                                if (CanUseSpell(spell, attacker.Owner))
                                                {
                                                    PrepareSpell(spell, attacker.Owner);

                                                    SpellUse suse = new SpellUse(true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = SpellID;
                                                    suse.SpellLevel = attacker.Owner.Spells[SpellID].Level;
                                                    suse.X = X;
                                                    suse.Y = Y;
                                                    int xx = 0;
                                                    int yy = 0;
                                                    foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                    {
                                                        if (_obj == null)
                                                            continue;
                                                        if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                        {
                                                            attacked = _obj as Entity;
                                                            if (attacked.CanBlade)
                                                            {

                                                                // if (attacked.X != xx && attacked.Y != yy)
                                                                // {
                                                                if (!CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                    continue;

                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                               // uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                                suse.Effect1 = attack.Effect1;

                                                                attack.Damage = damage;
                                                                // xx = attacked.X;
                                                                // yy = attacked.Y;
                                                                ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                suse.Targets.Add(attacked.UID, damage);
                                                                attacked.CanBlade = false;
                                                                if (!attacked.Dead)
                                                                {
                                                                    if (attacker.Owner.Spells.ContainsKey(11120))
                                                                    {
                                                                        BlackSpot spot = new BlackSpot
                                                                        {
                                                                            Remove = 0,
                                                                            Identifier = attacked.UID
                                                                        };
                                                                        attacker.Owner.Send((byte[])spot);

                                                                        attacked.BlackSpotTime = Time32.Now;
                                                                        attacked.BlackSpotTime2 = 8;
                                                                        attacked.BlackSpots = true;
                                                                        attacker.Owner.IncreaseSpellExperience(80, 11120);
                                                                    }
                                                                }
                                                                // }
                                                            }
                                                        }
                                                        else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                        {
                                                            attackedsob = _obj as SobNpcSpawn;

                                                            if (ila.InLine(attackedsob.X, attackedsob.Y))
                                                            {
                                                                if (!CanAttack(attacker, attackedsob, spell))
                                                                    continue;

                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                damage = (uint)(damage * spell.PowerPercent);
                                                                attack.Damage = damage;

                                                                ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                                suse.Targets.Add(attackedsob.UID, damage);
                                                            }
                                                        }
                                                    }
                                                    attacker.X = X;
                                                    attacker.Y = Y;
                                                    attacker.Owner.SendScreen(attack, true);
                                                    attacker.Owner.SendScreen(suse, true);
                                                    attacker.Owner.Screen.Reload(attack);
                                                }
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region XPSpells inofensive
                                    case 1015:
                                    case 1020:
                                    case 1025:
                                    case 1110:
                                    case 6011:
                                    case 10390:
                                        {

                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;

                                                suse.Targets.Add(attacked.UID, 0);

                                                if (spell.ID == 6011)
                                                {
                                                    attacker.FatalStrikeStamp = Time32.Now;
                                                    attacker.FatalStrikeTime = 60;
                                                    attacker.AddFlag(Update.Flags.FatalStrike);
                                                    attacker.RemoveFlag(Update.Flags.Ride);
                                                }
                                                else
                                                {
                                                    if (spell.ID == 1110 || spell.ID == 1025 || spell.ID == 10390)
                                                    {
                                                        if (!attacked.OnKOSpell())
                                                            attacked.KOCount = 0;

                                                        attacked.KOSpell = spell.ID;
                                                        if (spell.ID == 1110)
                                                        {
                                                            attacked.CycloneStamp = Time32.Now;
                                                            attacked.CycloneTime = 20;
                                                            attacked.AddFlag(Update.Flags.Cyclone);
                                                        }
                                                        else if (spell.ID == 10390)
                                                        {
                                                            attacked.OblivionStamp = Time32.Now;
                                                            attacked.OblivionTime = 20;
                                                            attacked.AddFlag2(Update.Flags2.Oblivion);
                                                        }

                                                        else
                                                        {
                                                            attacked.SupermanStamp = Time32.Now;
                                                            attacked.SupermanTime = 20;
                                                            attacked.AddFlag(Update.Flags.Superman);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (spell.ID == 1020)
                                                        {
                                                            attacked.ShieldTime = 0;
                                                            attacked.ShieldStamp = Time32.Now;
                                                            attacked.MagicShieldStamp = Time32.Now;
                                                            attacked.MagicShieldTime = 0;

                                                            attacked.AddFlag(Update.Flags.MagicShield);
                                                            attacked.ShieldStamp = Time32.Now;
                                                            attacked.ShieldIncrease = spell.PowerPercent;
                                                            attacked.ShieldTime = (byte)spell.Duration;
                                                        }
                                                        else
                                                        {

                                                            attacked.AccuracyStamp = Time32.Now;
                                                            attacked.StarOfAccuracyStamp = Time32.Now;
                                                            attacked.StarOfAccuracyTime = 0;
                                                            attacked.AccuracyTime = 0;

                                                            attacked.AddFlag(Update.Flags.StarOfAccuracy);
                                                            attacked.AccuracyStamp = Time32.Now;
                                                            attacked.AccuracyTime = (byte)spell.Duration;
                                                        }
                                                    }
                                                }
                                                attacked.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Circle spells
                                    case 1010:
                                    case 1115:
                                    case 1120:
                                    case 1125:
                                    case 3090:
                                    case 5001:
                                    case 8030:
                                    case 11170:
                                    case 10315:
                                    case 11190:
                                        //case 11050:
                                        {
                                            // Console.WriteLine("xx3");
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                //Console.WriteLine("x4");
                                                PrepareSpell(spell, attacker.Owner);
                                                //Console.WriteLine("xx5");
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                UInt16 ox, oy;
                                                ox = attacker.X;
                                                oy = attacker.Y;
                                                if (spellID == 10315 || spellID == 11190)
                                                {
                                                    /* if (attacker.MapID == 1950)
                                                     {
                                                         break;
                                                     }*/
                                                    bool yes = true;
                                                    Game.Map Map = attacker.Owner.Map;

                                                    Game.Attacking.InLineAlgorithm ila = new PhoenixProject.Game.Attacking.InLineAlgorithm(attacker.X,
                                                       X, attacker.Y, Y, (byte)spell.Range, InLineAlgorithm.Algorithm.DDA);
                                                    List<InLineAlgorithm.coords>.Enumerator enumerator6;
                                                    ushort x = 0;
                                                    ushort y = 0;
                                                    using (enumerator6 = ila.getCoords.GetEnumerator())
                                                    {
                                                        while (enumerator6.MoveNext())
                                                        {
                                                            if (yes)
                                                            {
                                                                Func<IMapObject, bool> func4 = null;
                                                                InLineAlgorithm.coords coord = enumerator6.Current;
                                                                if (Map.Floor[coord.X, coord.Y, Game.MapObjectType.Player, null])
                                                                {
                                                                    if (attacker.MapID == 1038)
                                                                    {
                                                                        if (attacker.X > 223 && attacker.Y < 185 && coord.X < 224)
                                                                        {
                                                                            // Console.WriteLine(" r " + PhoenixProject.Game.ConquerStructures.Society.GuildWar.RightGate.Mesh + "");
                                                                            if (PhoenixProject.Game.ConquerStructures.Society.GuildWar.RightGate.Mesh == 271)
                                                                            {
                                                                                yes = false;
                                                                            }
                                                                            else
                                                                            {
                                                                                yes = true;
                                                                                x = (ushort)coord.X;
                                                                                y = (ushort)coord.Y;
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            //Console.WriteLine(" r " + PhoenixProject.Game.ConquerStructures.Society.GuildWar.LeftGate.Mesh + "");
                                                                            if (attacker.X < 170 && attacker.Y > 210 && coord.Y < 211)
                                                                            {
                                                                                if (PhoenixProject.Game.ConquerStructures.Society.GuildWar.LeftGate.Mesh == 241)
                                                                                {
                                                                                    yes = false;
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                yes = true;
                                                                                x = (ushort)coord.X;
                                                                                y = (ushort)coord.Y;
                                                                            }

                                                                        }


                                                                    }
                                                                    else
                                                                    {
                                                                        yes = true;
                                                                        x = (ushort)coord.X;
                                                                        y = (ushort)coord.Y;
                                                                    }

                                                                }
                                                                else
                                                                {
                                                                    yes = false;
                                                                }
                                                            }
                                                        }
                                                    }
                                                    yes = true;
                                                    X = x;
                                                    Y = y;

                                                    Attack npacket = new Attack(true);
                                                    npacket.Attacker = attacker.UID;
                                                    npacket.AttackType = 53;
                                                    npacket.X = X;
                                                    npacket.Y = Y;
                                                    Writer.WriteUInt16(spell.ID, 24, npacket.ToArray());
                                                    Writer.WriteByte(spell.Level, 26, npacket.ToArray());
                                                    attacker.Owner.SendScreen(npacket, true);
                                                    attacker.X = X;
                                                    attacker.Y = Y;
                                                    attacker.SendSpawn(attacker.Owner);
                                                    attacker.Owner.Screen.Reload(npacket);
                                                }

                                                List<IMapObject> objects = new List<IMapObject>();
                                                if (attacker.Owner.Screen.Objects.Count() > 0)
                                                    objects = GetObjects(ox, oy, attacker.Owner);
                                                if (objects != null)
                                                {
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= spell.Range)
                                                    {
                                                        if (spellID == 10315 || spellID == 11190)
                                                        {
                                                            foreach (IMapObject objs in objects.ToArray())
                                                            {
                                                                if (objs == null)
                                                                    continue;

                                                                if (objs.MapObjType == MapObjectType.Monster || objs.MapObjType == MapObjectType.Player)
                                                                {
                                                                    attacked = objs as Entity;
                                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Range)
                                                                    {
                                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                        {
                                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, ref attack);
                                                                            suse.Effect1 = attack.Effect1;
                                                                            if (spell.Power > 0)
                                                                            {
                                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                                damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                                                //damage = Game.Attacking.Calculate.Magic(attacker, attacked, spell, ref attack);
                                                                                suse.Effect1 = attack.Effect1;
                                                                            }
                                                                            if (spell.ID == 8030)
                                                                            {
                                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                                damage = Game.Attacking.Calculate.Ranged(attacker, attacked, ref attack);
                                                                            }

                                                                            ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                            suse.Targets.Add(attacked.UID, damage);
                                                                        }
                                                                    }
                                                                }
                                                                else if (objs.MapObjType == MapObjectType.SobNpc)
                                                                {
                                                                    attackedsob = objs as SobNpcSpawn;
                                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Range)
                                                                    {
                                                                        if (CanAttack(attacker, attackedsob, spell))
                                                                        {
                                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                            if (spell.Power > 0)
                                                                            {
                                                                                damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                                               // damage = Game.Attacking.Calculate.Magic(attacker, attackedsob, spell, ref attack);
                                                                            }
                                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                                            if (spell.ID == 8030)
                                                                                damage = Game.Attacking.Calculate.Ranged(attacker, attackedsob, ref attack);
                                                                            suse.Effect1 = attack.Effect1;
                                                                            ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                                            suse.Targets.Add(attackedsob.UID, damage);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                            {
                                                                if (_obj == null)
                                                                    continue;
                                                                if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                                {
                                                                    attacked = _obj as Entity;
                                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Range)
                                                                    {
                                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                        {
                                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, ref attack);
                                                                            suse.Effect1 = attack.Effect1;
                                                                            if (spell.Power > 0)
                                                                            {
                                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                                damage = Game.Attacking.Calculate.Magic(attacker, attacked, spell, ref attack);
                                                                                suse.Effect1 = attack.Effect1;
                                                                            }
                                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                                            if (spell.ID == 8030)
                                                                                damage = Game.Attacking.Calculate.Ranged(attacker, attacked, ref attack);
                                                                            if (spell.ID == 1115)
                                                                                damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);


                                                                            ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                            suse.Targets.Add(attacked.UID, damage);
                                                                        }
                                                                    }
                                                                }
                                                                else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                                {
                                                                    attackedsob = _obj as SobNpcSpawn;
                                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Range)
                                                                    {
                                                                        if (CanAttack(attacker, attackedsob, spell))
                                                                        {
                                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                            if (spell.Power > 0)
                                                                                damage = Game.Attacking.Calculate.Magic(attacker, attackedsob, spell, ref attack);
                                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                                            if (spell.ID == 8030)
                                                                                damage = Game.Attacking.Calculate.Ranged(attacker, attackedsob, ref attack);

                                                                            suse.Effect1 = attack.Effect1;
                                                                            ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                                            suse.Targets.Add(attackedsob.UID, damage);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        attacker.AttackPacket = null;
                                                    }
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Buffers
                                    case 1075:
                                    case 1085:
                                    case 1090:
                                    case 1095:
                                    case 3080:
                                    case 10405://this is not what I edited yesterday...
                                    case 30000:
                                    case 11160:
                                    case 11200:
                                        {
                                            if (attackedsob != null)
                                            {
                                                if (CanUseSpell(spell, attacker.Owner))
                                                {
                                                    PrepareSpell(spell, attacker.Owner);

                                                    SpellUse suse = new SpellUse(true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = spell.ID;
                                                    suse.SpellLevel = spell.Level;
                                                    suse.X = X;
                                                    suse.Y = Y;

                                                    suse.Targets.Add(attackedsob.UID, 0);

                                                    attacker.Owner.SendScreen(suse, true);
                                                }
                                            }
                                            else
                                            {
                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Distance)
                                                {
                                                    if (CanUseSpell(spell, attacker.Owner))
                                                    {
                                                        PrepareSpell(spell, attacker.Owner);

                                                        SpellUse suse = new SpellUse(true);
                                                        suse.Attacker = attacker.UID;
                                                        suse.SpellID = spell.ID;
                                                        suse.SpellLevel = spell.Level;
                                                        suse.X = X;
                                                        suse.Y = Y;

                                                        suse.Targets.Add(attacked.UID, 0);

                                                        if (spell.ID == 1075 || spell.ID == 1085)
                                                        {
                                                            if (spell.ID == 1075)
                                                            {
                                                                attacked.AddFlag(Update.Flags.Invisibility);
                                                                attacked.InvisibilityStamp = Time32.Now;
                                                                attacked.InvisibilityTime = (byte)spell.Duration;
                                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                                    attacked.Owner.Send(ServerBase.Constants.Invisibility((int)spell.Duration));
                                                            }
                                                            else
                                                            {
                                                                attacked.AccuracyStamp = Time32.Now;
                                                                attacked.StarOfAccuracyStamp = Time32.Now;
                                                                attacked.StarOfAccuracyTime = 0;
                                                                attacked.AccuracyTime = 0;

                                                                attacked.AddFlag(Update.Flags.StarOfAccuracy);
                                                                attacked.StarOfAccuracyStamp = Time32.Now;
                                                                attacked.StarOfAccuracyTime = (byte)spell.Duration;
                                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                                    attacked.Owner.Send(ServerBase.Constants.Accuracy((int)spell.Duration));

                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (spell.ID == 1090)
                                                            {
                                                                attacked.ShieldTime = 0;
                                                                attacked.ShieldStamp = Time32.Now;
                                                                attacked.MagicShieldStamp = Time32.Now;
                                                                attacked.MagicShieldTime = 0;

                                                                attacked.AddFlag(Update.Flags.MagicShield);
                                                                attacked.MagicShieldStamp = Time32.Now;
                                                                attacked.MagicShieldIncrease = spell.PowerPercent;
                                                                attacked.MagicShieldTime = (byte)spell.Duration;
                                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                                    attacked.Owner.Send(ServerBase.Constants.Shield(spell.PowerPercent, (int)spell.Duration));
                                                            }
                                                            else if (spell.ID == 1095)
                                                            {
                                                                attacked.AddFlag(Update.Flags.Stigma);
                                                                attacked.StigmaStamp = Time32.Now;
                                                                attacked.StigmaIncrease = spell.PowerPercent;
                                                                attacked.StigmaTime = (byte)spell.Duration;
                                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                                    attacked.Owner.Send(ServerBase.Constants.Stigma(spell.PowerPercent, (int)spell.Duration));
                                                            }
                                                            else if (spell.ID == 11200)
                                                            {

                                                                if (attacker.ContainsFlag(Update.Flags.Ride))
                                                                {
                                                                    attacker.RemoveFlag(Update.Flags.Ride);
                                                                }
                                                                attacker.AddFlag3(Update.Flags3.MagicDefender);
                                                                attacker.MagicDefenderStamp = Time32.Now;
                                                                attacker.MagicDefenderIncrease = spell.PowerPercent;
                                                                attacker.MagicDefenderTime = (byte)spell.Duration;

                                                                if (attacker.EntityFlag == EntityFlag.Player)
                                                                {

                                                                    attacker.Owner.SendScreen(suse, true);
                                                                    SyncPacket packet = new SyncPacket
                                                                    {
                                                                        Identifier = attacker.UID,
                                                                        Count = 2,
                                                                        Type = PhoenixProject.Network.GamePackets.SyncPacket.SyncType.StatusFlag,
                                                                        StatusFlag1 = (ulong)attacker.StatusFlag,
                                                                        StatusFlag2 = (ulong)attacker.StatusFlag2,
                                                                        Unknown1 = 0x31,
                                                                        StatusFlagOffset = 0x80,
                                                                        Time = (uint)spell.Duration,
                                                                        Value = 10,
                                                                        Level = spell.Level
                                                                    };
                                                                    attacker.Owner.Send((byte[])packet);
                                                                }
                                                                break;
                                                            }
                                                            else if (spell.ID == 11160)
                                                            {
                                                                if (attacker.DefensiveStanceTime != 0)
                                                                {
                                                                    attacker.DefensiveStanceTime = 0;
                                                                    attacker.DefensiveStanceIncrease = 0;
                                                                    attacker.RemoveFlag2(Network.GamePackets.Update.Flags2.WarriorWalk);
                                                                }
                                                                else
                                                                {
                                                                    if (attacker.ContainsFlag(Update.Flags.Ride))
                                                                    {
                                                                        attacker.RemoveFlag(Update.Flags.Ride);
                                                                    }
                                                                    attacker.AddFlag2(Update.Flags2.WarriorWalk);
                                                                    attacker.DefensiveStanceStamp = Time32.Now;
                                                                    attacker.DefensiveStanceIncrease = spell.PowerPercent;
                                                                    attacker.DefensiveStanceTime = (byte)spell.Duration;

                                                                    if (attacker.EntityFlag == EntityFlag.Player)
                                                                    {
                                                                        attacker.Owner.Send(ServerBase.Constants.DefensiveStance(spell.Percent, (int)spell.Duration));

                                                                        attacker.Owner.SendScreen(suse, true);
                                                                    }
                                                                }
                                                                break;
                                                            }
                                                            else if (spell.ID == 30000)
                                                            {

                                                                if (attacked.ContainsFlag2(Update.Flags2.AzureShield))
                                                                {
                                                                    return;
                                                                }
                                                                //attack.AttackType = Attack.kimo2;
                                                                attacked.ShieldTime = 0;
                                                                attacked.ShieldStamp = Time32.Now;
                                                                attacked.MagicShieldStamp = Time32.Now;
                                                                attacked.MagicShieldTime = 0;
                                                                //Console.WriteLine("The Dodge is :" + attacked.Dodge.ToString());
                                                                attacked.AddFlag2(Update.Flags2.AzureShield);
                                                                attacked.MagicShieldStamp = Time32.Now;
                                                                attacked.AzureDamage = 12000;
                                                                //Console.WriteLine("AzureShiled granted " + 12000 + "  The Dodge is :" + attacked.Dodge.ToString());
                                                                attacked.MagicShieldIncrease = spell.PowerPercent;
                                                                attacked.MagicShieldTime = 60;
                                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                                {
                                                                    attacked.Owner.Send(ServerBase.Constants.AzureShield(12000, 30));

                                                                    SyncPacket packet4 = new SyncPacket
                                                                    {
                                                                        Identifier = attacked.UID,
                                                                        Count = 2,
                                                                        Type = PhoenixProject.Network.GamePackets.SyncPacket.SyncType.StatusFlag,
                                                                        StatusFlag1 = (ulong)attacked.StatusFlag,
                                                                        StatusFlag2 = (ulong)attacked.StatusFlag2,
                                                                        Unknown1 = 0x31,
                                                                        StatusFlagOffset = 0x5d,
                                                                        Time = (uint)60,
                                                                        Value = (uint)attacked.AzureDamage,
                                                                        Level = spell.Level
                                                                    };
                                                                    attacked.Owner.Send((byte[])packet4);
                                                                }
                                                            }
                                                            if (spell.ID == 10405 && attacked.Dead)
                                                            {
                                                                if ((attacked.BattlePower - attacker.BattlePower) >= 10)
                                                                    return;
                                                                attacked.AddFlag(Update.Flags.Dead);//Flag them as dead... should not be needed. This is no movement
                                                                attacked.ShackleStamp = Time32.Now;//Set stamp so source can remove the flag after X seconds
                                                                attacked.ShackleTime = (short)(30 + 15 * spell.Level);//double checking here. Could be db has this wrong.
                                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                                {
                                                                    attacked.Owner.Send(ServerBase.Constants.Shackled(attacked.ShackleTime));

                                                                    attacked.AddFlag2(Update.Flags2.SoulShackle);//Give them shackeld effect   

                                                                    SyncPacket packet3 = new SyncPacket
                                                                    {
                                                                        Identifier = attacked.UID,
                                                                        Count = 2,
                                                                        Type = PhoenixProject.Network.GamePackets.SyncPacket.SyncType.StatusFlag,
                                                                        StatusFlag1 = (ulong)attacked.StatusFlag,
                                                                        StatusFlag2 = (ulong)attacked.StatusFlag2,
                                                                        Unknown1 = 0x36,
                                                                        StatusFlagOffset = 0x6f,
                                                                        Time = (uint)spell.Duration,
                                                                        Value = 10,
                                                                        Level = spell.Level
                                                                    };
                                                                    attacked.Owner.Send((byte[])packet3);

                                                                }
                                                            }
                                                        }
                                                        attacker.Owner.IncreaseSpellExperience(Experience, spellID);
                                                        if (attacked.EntityFlag == EntityFlag.Player)
                                                            attacked.Owner.SendScreen(suse, true);
                                                        else
                                                            attacked.MonsterInfo.SendScreen(suse);

                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Percent
                                    case 3050:
                                        // case 11230:
                                        {
                                            //Console.WriteLine("1");
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                if (attackedsob != null)
                                                {
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Distance)
                                                    {
                                                        SpellUse suse = new SpellUse(true);
                                                        suse.Attacker = attacker.UID;
                                                        suse.SpellID = spell.ID;
                                                        suse.SpellLevel = spell.Level;
                                                        suse.X = X;
                                                        suse.Y = Y;

                                                        if (CanAttack(attacker, attackedsob, spell))
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);
                                                            uint damage = Game.Attacking.Calculate.Percent(attackedsob, spell.PowerPercent);

                                                            attackedsob.Hitpoints -= damage;

                                                            suse.Targets.Add(attackedsob.UID, damage);

                                                            attacker.Owner.SendScreen(suse, true);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Distance)
                                                    {
                                                        SpellUse suse = new SpellUse(true);
                                                        suse.Attacker = attacker.UID;
                                                        suse.SpellID = spell.ID;
                                                        suse.SpellLevel = spell.Level;
                                                        suse.X = X;
                                                        suse.Y = Y;

                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);
                                                            uint damage = Game.Attacking.Calculate.Percent(attacked, spell.PowerPercent);

                                                            if (attacker.Owner.QualifierGroup != null)
                                                                attacker.Owner.QualifierGroup.UpdateDamage(attacker.Owner, damage);

                                                            attacked.Hitpoints -= damage;

                                                            suse.Targets.Add(attacked.UID, damage);

                                                            if (attacked.EntityFlag == EntityFlag.Player)
                                                                attacked.Owner.SendScreen(suse, true);
                                                            else
                                                                attacked.MonsterInfo.SendScreen(suse);
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region ExtraXP
                                    case 1040:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                if (attacker.Owner.Team != null)
                                                {
                                                    PrepareSpell(spell, attacker.Owner);
                                                    foreach (Client.GameState teammate in attacker.Owner.Team.Teammates)
                                                    {
                                                        if (teammate.Entity.UID != attacker.UID)
                                                        {
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, teammate.Entity.X, teammate.Entity.Y) <= spell.Distance)
                                                            {
                                                                teammate.XPCount += 20;
                                                                Update update = new Update(true);
                                                                update.UID = teammate.Entity.UID;
                                                                update.Append(Update.XPCircle, teammate.XPCount);
                                                                update.Send(teammate);
                                                                suse.Targets.Add(teammate.Entity.UID, 20);

                                                                if (spell.NextSpellID != 0)
                                                                {
                                                                    attack.Damage = spell.NextSpellID;
                                                                    attacker.AttackPacket = attack;
                                                                }
                                                                else
                                                                {
                                                                    attacker.AttackPacket = null;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                    attacked.Owner.SendScreen(suse, true);
                                                else
                                                    attacked.MonsterInfo.SendScreen(suse);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region WeaponSpells
                                    #region Circle
                                    case 5010:
                                    case 7020:

                                        //case 11110:
                                        //case 10490:
                                        {

                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                if (suse.SpellID != 10415)
                                                {
                                                    suse.X = X;
                                                    suse.Y = Y;
                                                }
                                                else
                                                {
                                                    suse.X = 6;
                                                }

                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= attacker.AttackRange + 1)
                                                {
                                                    foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                    {
                                                        if (_obj == null)
                                                            continue;
                                                        if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                        {
                                                            attacked = _obj as Entity;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Range)
                                                            {
                                                                if (attacked.ContainsFlag(Update.Flags.Fly))
                                                                    return;
                                                                if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                {
                                                                    PrepareSpell(spell, attacker.Owner);

                                                                    //attack.Effect1 = Attack.AttackEffects1.None;
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                                    //suse.Effect1 = attack.Effect1;

                                                                    ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                    suse.Targets.Add(attacked.UID, damage);
                                                                }
                                                            }
                                                        }
                                                        else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                        {
                                                            attackedsob = _obj as SobNpcSpawn;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Range)
                                                            {
                                                                if (CanAttack(attacker, attackedsob, spell))
                                                                {
                                                                    PrepareSpell(spell, attacker.Owner);
                                                                    // attack.Effect1 = Attack.AttackEffects1.None;
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                    damage = (uint)(damage * spell.PowerPercent);
                                                                    ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                                    suse.Targets.Add(attackedsob.UID, damage);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }

                                            break;
                                        }
                                    #endregion
                                    #region Single target
                                    case 10490:
                                    case 11140:
                                        //case 11230:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;

                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= attacker.AttackRange + 1)
                                                {
                                                    if (attackedsob != null)
                                                    {
                                                        if (CanAttack(attacker, attackedsob, spell))
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);
                                                            suse.MakeConst();
                                                            for (uint c = 0; c < 3; c++)
                                                            {
                                                                uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                if (damage > attackedsob.Hitpoints)
                                                                    damage = attackedsob.Hitpoints;

                                                                ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                                suse.Targets.Add(attackedsob.UID + c, damage);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);
                                                            suse.MakeConst();
                                                            for (uint c = 0; c < 3; c++)
                                                            {
                                                                uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                                if (damage > attacked.Hitpoints)
                                                                    damage = attacked.Hitpoints;
                                                                ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                suse.Targets.Add(attacked.UID + c, damage);
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    case 1290:
                                    case 5030:
                                    case 5040:
                                    case 7000:
                                    case 7010:
                                    case 7030:
                                    case 7040:
                                    case 11230:
                                        //case 10381:

                                        //case 10490:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;

                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= attacker.AttackRange + 1)
                                                {
                                                    if (attackedsob != null)
                                                    {
                                                        if (CanAttack(attacker, attackedsob, spell))
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);
                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                            damage = (uint)(damage * spell.PowerPercent);
                                                            ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                            suse.Targets.Add(attackedsob.UID, damage);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);

                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                            suse.Effect1 = attack.Effect1;

                                                            ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                            suse.Targets.Add(attacked.UID, damage);
                                                        }
                                                    }
                                                    attacker.AttackPacket = null;
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            attacker.AttackPacket = null;
                                            break;
                                        }
                                    #endregion
                                    #region Sector
                                    case 1250:
                                    case 5050:
                                    case 5020:
                                    case 1300:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                Sector sector = new Sector(attacker.X, attacker.Y, X, Y);
                                                sector.Arrange(spell.Sector, spell.Range);
                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= spell.Distance + 1)
                                                {
                                                    foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                    {
                                                        if (_obj == null)
                                                            continue;
                                                        if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                        {
                                                            attacked = _obj as Entity;

                                                            if (sector.Inside(attacked.X, attacked.Y))
                                                            {
                                                                if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                {
                                                                    attack.Effect1 = Attack.AttackEffects1.None;
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                                    suse.Effect1 = attack.Effect1;

                                                                    ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                    suse.Targets.Add(attacked.UID, damage);
                                                                }
                                                            }
                                                        }
                                                        else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                        {
                                                            attackedsob = _obj as SobNpcSpawn;

                                                            if (sector.Inside(attackedsob.X, attackedsob.Y))
                                                            {
                                                                if (CanAttack(attacker, attackedsob, spell))
                                                                {
                                                                    attack.Effect1 = Attack.AttackEffects1.None;
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                    damage = (uint)(damage * spell.PowerPercent);
                                                                    ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                                    suse.Targets.Add(attackedsob.UID, damage);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #endregion
                                    #region Fly
                                    case 8002:
                                    case 8003:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                if (attacker.MapID == 1950)
                                                    return;
                                                PrepareSpell(spell, attacker.Owner);
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                attacked.FlyStamp = Time32.Now;
                                                attacked.FlyTime = (byte)spell.Duration;

                                                suse.Targets.Add(attacker.UID, attacker.FlyTime);

                                                attacker.AddFlag(Update.Flags.Fly);
                                                attacker.RemoveFlag(Update.Flags.Ride);
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Pirate Spells
                                    #region Xp Skills
                                    case 10309: //Cannon Barrage
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                if (!attacker.ContainsFlag2(Update.Flags2.ChainBoltActive))
                                                {
                                                    //attacker.RemoveFlag(Update.Flags.XPList);
                                                    attacker.ChainBoltStamp = Time32.Now;
                                                    attacker.ChainBoltTime = 30;
                                                    attacker.AddFlag2(Update.Flags2.ChainBoltActive);
                                                }

                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= spell.Range)
                                                {
                                                    for (int c = 0; c < attacker.Owner.Screen.Objects.Count(); c++)
                                                    {
                                                        //For a multi threaded application, while we go through the collection
                                                        //the collection might change. We will make sure that we wont go off  
                                                        //the limits with a check.
                                                        if (c >= attacker.Owner.Screen.Objects.Count())
                                                            break;
                                                        Interfaces.IMapObject _obj = attacker.Owner.Screen.Objects[c];
                                                        if (_obj == null)
                                                            continue;
                                                        if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                        {
                                                            attacked = _obj as Entity;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Range)
                                                            {
                                                                if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                {
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, ref attack);
                                                                    if (spell.Power > 0)
                                                                        damage = Game.Attacking.Calculate.Magic(attacker, attacked, spell, ref attack);
                                                                    if (spell.ID == 8030)
                                                                        damage = Game.Attacking.Calculate.Ranged(attacker, attacked, ref attack);
                                                                    ReceiveAttack(attacker, attacked, attack, damage, spell);
                                                                    suse.Targets.Add(attacked.UID, damage);
                                                                    //attacked.AddFlag(Update.Effects.CannonBarrage);
                                                                }
                                                            }
                                                        }
                                                        else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                        {
                                                            attackedsob = _obj as SobNpcSpawn;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Range)
                                                            {
                                                                if (CanAttack(attacker, attackedsob, spell))
                                                                {
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                    if (spell.Power > 0)
                                                                        damage = Game.Attacking.Calculate.Magic(attacker, attackedsob, spell, ref attack);
                                                                    if (spell.ID == 8030)
                                                                        damage = Game.Attacking.Calculate.Ranged(attacker, attackedsob, ref attack);
                                                                    ReceiveAttack(attacker, attackedsob, attack, damage, spell);
                                                                    suse.Targets.Add(attackedsob.UID, damage);
                                                                    //attacked.AddFlag(Update.Effects.CannonBarrage);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    case 11050: //Cannon Barrage
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                if (!attacker.ContainsFlag2(Update.Flags2.CannonBraga))
                                                {
                                                    // attacker.RemoveFlag(Update.Flags.XPList);
                                                    attacker.CannonBarageStamp = Time32.Now;
                                                    attacker.Cannonbarage = 30;
                                                    attacker.AddFlag2(Update.Flags2.CannonBraga);
                                                }

                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= 10)
                                                {
                                                    for (int c = 0; c < attacker.Owner.Screen.Objects.Count(); c++)
                                                    {
                                                        //For a multi threaded application, while we go through the collection
                                                        //the collection might change. We will make sure that we wont go off  
                                                        //the limits with a check.
                                                        if (c >= attacker.Owner.Screen.Objects.Count())
                                                            break;
                                                        Interfaces.IMapObject _obj = attacker.Owner.Screen.Objects[c];
                                                        if (_obj == null)
                                                            continue;
                                                        if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                        {
                                                            attacked = _obj as Entity;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= 10)
                                                            {
                                                                if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                {
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, ref attack);
                                                                    if (spell.Power > 0)
                                                                        damage = Game.Attacking.Calculate.Magic(attacker, attacked, spell, ref attack);
                                                                    if (spell.ID == 8030)
                                                                        damage = Game.Attacking.Calculate.Ranged(attacker, attacked, ref attack);
                                                                    ReceiveAttack(attacker, attacked, attack, damage, spell);
                                                                    suse.Targets.Add(attacked.UID, damage);
                                                                    //attacked.AddFlag(Update.Effects.CannonBarrage);
                                                                }
                                                            }
                                                        }
                                                        else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                        {
                                                            attackedsob = _obj as SobNpcSpawn;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= 10)
                                                            {
                                                                if (CanAttack(attacker, attackedsob, spell))
                                                                {
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                    if (spell.Power > 0)
                                                                        damage = Game.Attacking.Calculate.Magic(attacker, attackedsob, spell, ref attack);
                                                                    if (spell.ID == 8030)
                                                                        damage = Game.Attacking.Calculate.Ranged(attacker, attackedsob, ref attack);
                                                                    ReceiveAttack(attacker, attackedsob, attack, damage, spell);
                                                                    suse.Targets.Add(attackedsob.UID, damage);
                                                                    //attacked.AddFlag(Update.Effects.CannonBarrage);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    case 11060: // BlackPearl Rage
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                if (!attacker.ContainsFlag2(Update.Flags2.BlackBread))
                                                {
                                                    //attacker.RemoveFlag(Update.Flags.XPList);
                                                    attacker.BlackBeardStamp = Time32.Now;
                                                    attacker.Blackbeard = 30;
                                                    attacker.AddFlag2(Update.Flags2.BlackBread);
                                                }
                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= spell.Range)
                                                {
                                                    for (int c = 0; c < attacker.Owner.Screen.Objects.Count(); c++)
                                                    {
                                                        //For a multi threaded application, while we go through the collection
                                                        //the collection might change. We will make sure that we wont go off  
                                                        //the limits with a check.
                                                        if (c >= attacker.Owner.Screen.Objects.Count())
                                                            break;
                                                        Interfaces.IMapObject _obj = attacker.Owner.Screen.Objects[c];
                                                        if (_obj == null)
                                                            continue;
                                                        if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                        {
                                                            attacked = _obj as Entity;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Range)
                                                            {
                                                                if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                {
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, ref attack);
                                                                    if (spell.Power > 0)
                                                                        damage = Game.Attacking.Calculate.Magic(attacker, attacked, spell, ref attack);
                                                                    if (spell.ID == 8030)
                                                                        damage = Game.Attacking.Calculate.Ranged(attacker, attacked, ref attack);
                                                                    ReceiveAttack(attacker, attacked, attack, damage, spell);
                                                                    suse.Targets.Add(attacked.UID, damage);
                                                                }
                                                            }
                                                        }
                                                        else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                        {
                                                            attackedsob = _obj as SobNpcSpawn;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Range)
                                                            {
                                                                if (CanAttack(attacker, attackedsob, spell))
                                                                {
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                    if (spell.Power > 0)
                                                                        damage = Game.Attacking.Calculate.Magic(attacker, attackedsob, spell, ref attack);
                                                                    if (spell.ID == 8030)
                                                                        damage = Game.Attacking.Calculate.Ranged(attacker, attackedsob, ref attack);
                                                                    ReceiveAttack(attacker, attackedsob, attack, damage, spell);
                                                                    suse.Targets.Add(attackedsob.UID, damage);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    #endregion

                                    #region Auto On Skills
                                    case 11130: //Adrenaline Rush
                                        //case 11130: //BlackSpot
                                        {
                                            spell.RemoveCooldown(0x2b16);
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PhoenixProject.Network.GamePackets.Quest.Target target5 = new PhoenixProject.Network.GamePackets.Quest.Target
                                                {
                                                    Obj = attacker,
                                                    Damage = 0x2b16,
                                                    DamageType = HitType.NoDamage,
                                                    Hit = true
                                                };
                                                if (spell.CoolDown > 0)
                                                {
                                                    spell.AddCooldown(spell.ID, (int)spell.CoolDown);
                                                }


                                            }
                                            break;
                                        }
                                    #endregion // Doesnt Work // Doest Work



                                    #region Linear Skills
                                    /* case 11110: //Blade Tempest
                                        {
                                            //if (Time32.Now < attacker.WhilrwindKick.AddMilliseconds(1500))
                                            // return;
                                            //attacker.WhilrwindKick = Time32.Now;
                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= 5)
                                            {

                                                if (CanUseSpell(spell, attacker.Owner))
                                                {
                                                    PrepareSpell(spell, attacker.Owner);

                                                    SpellUse suse = new SpellUse(true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = spell.ID;
                                                    suse.SpellLevel = spell.Level;
                                                    suse.X = X;
                                                    suse.Y = Y;

                                                    Game.Map Map = ServerBase.Kernel.Maps[attacker.MapID];
                                                    if (Map.SelectCoordonates(ref X, ref Y))
                                                    {

                                                        //attacker.X = X;
                                                        // attacker.Y = Y;
                                                        if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= 5)
                                                        {
                                                            for (int c = 0; c < attacker.Owner.Screen.Objects.Count(); c++)
                                                            {
                                                                //For a multi threaded application, while we go through the collection
                                                                //the collection might change. We will make sure that we wont go off  
                                                                //the limits with a check.
                                                                if (c >= attacker.Owner.Screen.Objects.Count())
                                                                    break;
                                                                Interfaces.IMapObject _obj = attacker.Owner.Screen.Objects[c];
                                                                if (_obj == null)
                                                                    continue;
                                                                if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                                {
                                                                    attacked = _obj as Entity;
                                                                    if (ServerBase.Kernel.GetDistance(X, Y, attacked.X, attacked.Y) <= 1)
                                                                    {

                                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Ranged))
                                                                        {
                                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, ref attack);

                                                                            ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                            suse.Targets.Add(attacked.UID, damage);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        attacker.AttackPacket = null;
                                                    }
                                                    attacker.Owner.SendScreen(suse, true);
                                                }
                                            }
                                            break;
                                        }*/
                                    #endregion

                                    #region Single damage Skill
                                    case 11120:
                                        {
                                            if (attacked != null)
                                            {
                                                if (attacked.EntityFlag == EntityFlag.Player || attacked.EntityFlag == EntityFlag.Monster)
                                                {
                                                    if (!attacked.Dead)
                                                    {
                                                        BlackSpot spot = new BlackSpot
                                                        {
                                                            Remove = 0,
                                                            Identifier = attacked.UID
                                                        };
                                                        attacker.Owner.Send((byte[])spot);

                                                        attacked.BlackSpotTime = Time32.Now;
                                                        attacked.BlackSpotTime2 = 12;
                                                        attacked.BlackSpots = true;
                                                        attacker.Owner.IncreaseSpellExperience(80, 11120);
                                                    }
                                                }

                                            }
                                            break;
                                        }
                                    case 11030: // Eagle Eye

                                        if (CanUseSpell(spell, attacker.Owner))
                                        {
                                            PrepareSpell(spell, attacker.Owner);



                                            SpellUse suse = new SpellUse(true);
                                            suse.Attacker = attacker.UID;
                                            suse.SpellID = spell.ID;
                                            suse.SpellLevel = spell.Level;
                                            suse.X = X;
                                            suse.Y = Y;
                                            suse.Effect1 = 0;
                                            bool kimo = false;
                                            //suse.Targets.Add(attacker.UID, spell.Power);
                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= spell.Distance)
                                            {
                                                if (attackedsob != null)
                                                {
                                                    if (CanAttack(attacker, attackedsob, spell))
                                                    {

                                                        PrepareSpell(spell, attacker.Owner);
                                                        uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                        damage = (uint)(damage * spell.PowerPercent * 30);
                                                        ReceiveAttack(attacker, attackedsob, attack, damage, spell);
                                                        suse.Targets.Add(attackedsob.UID, damage);
                                                    }
                                                }
                                                else
                                                {
                                                    if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                    {
                                                        kimo = attacked.BlackSpots;
                                                        PrepareSpell(spell, attacker.Owner);
                                                        uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                        ReceiveAttack(attacker, attacked, attack, damage, spell);
                                                        suse.Targets.Add(attacked.UID, damage);

                                                    }
                                                }
                                            }

                                            if (attacker.Owner.Spells.ContainsKey(11130))
                                            {
                                                if (kimo)
                                                {
                                                    suse.SpellID = 11060;
                                                    attacker.Owner.SendScreen(suse, true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = 11130;
                                                    suse.SpellLevel = attacker.Owner.Spells[11130].Level;
                                                    suse.X = attacker.X;
                                                    suse.Y = attacker.X;

                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                    suse.Targets.Add(attacked.UID, damage);
                                                    attacker.Owner.SendScreen(suse, true);
                                                    attacker.Owner.IncreaseSpellExperience(80, 11130);
                                                    break;

                                                }
                                            }
                                            if (attacker.Owner.Spells.ContainsKey(11130))
                                            {
                                                if (ServerBase.Kernel.Rate(5))
                                                {
                                                    ////spell.Duration = 0;
                                                    attacker.Update(_String.Effect, "RapidReplace", true);
                                                    suse.SpellID = 11060;
                                                    attacker.Owner.SendScreen(suse, true);

                                                }
                                                else
                                                {
                                                    //// spell.Duration = 0;
                                                    //attacker.Update(_String.Effect, "RapidReplace", true); 
                                                    attacker.Owner.SendScreen(suse, true);
                                                }
                                            }
                                            else
                                            {
                                                // spell.Duration = 0;
                                                // attacker.Update(_String.Effect, "RapidReplace", true); 
                                                attacker.Owner.SendScreen(suse, true);
                                            }


                                        }
                                        break;
                                    #endregion

                                    #region Region Damage Skills
                                    case 11100: //kracken revenge
                                        {
                                            //Console.WriteLine("0");
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                //Console.WriteLine("1");
                                                int counts = 0;
                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= 5)
                                                {
                                                    for (int c = 0; c < attacker.Owner.Screen.Objects.Count(); c++)
                                                    {
                                                        // Console.WriteLine("2");
                                                        if (counts < 5)
                                                        {
                                                            //Console.WriteLine("3");
                                                            //For a multi threaded application, while we go through the collection
                                                            //the collection might change. We will make sure that we wont go off  
                                                            //the limits with a check.
                                                            if (c >= attacker.Owner.Screen.Objects.Count())
                                                                break;
                                                            Interfaces.IMapObject _obj = attacker.Owner.Screen.Objects[c];
                                                            if (_obj == null)
                                                                continue;
                                                            //Console.WriteLine("4");
                                                            if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                            {
                                                                attacked = _obj as Entity;
                                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= 5)
                                                                {
                                                                    // Console.WriteLine("5");
                                                                    if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                    {
                                                                        if (attacked.EntityFlag == EntityFlag.Monster)
                                                                        {

                                                                            BlackSpot spot = new BlackSpot
                                                                            {
                                                                                Remove = 0,
                                                                                Identifier = attacked.UID
                                                                            };
                                                                            attacker.Owner.Send((byte[])spot);

                                                                            attacked.BlackSpotTime = Time32.Now;
                                                                            attacked.BlackSpotTime2 = (byte)spell.Duration;
                                                                            attacked.BlackSpots = true;
                                                                            counts += 1;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (!ServerBase.Constants.BlackSpotNo.Contains(attacker.MapID))
                                                                            {

                                                                                BlackSpot spot = new BlackSpot
                                                                                {
                                                                                    Remove = 0,
                                                                                    Identifier = attacked.UID
                                                                                };
                                                                                attacker.Owner.Send((byte[])spot);

                                                                                attacked.BlackSpotTime = Time32.Now;
                                                                                attacked.BlackSpotTime2 = (byte)spell.Duration;
                                                                                attacked.BlackSpots = true;
                                                                                counts += 1;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                                attacker.Owner.IncreaseSpellExperience(80, spellID);
                                            }
                                            break;
                                        }
                                    case 11040: // Scurvey Bomb
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;

                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= spell.Range)
                                                {
                                                    for (int c = 0; c < attacker.Owner.Screen.Objects.Count(); c++)
                                                    {
                                                        //For a multi threaded application, while we go through the collection
                                                        //the collection might change. We will make sure that we wont go off  
                                                        //the limits with a check.
                                                        if (c >= attacker.Owner.Screen.Objects.Count())
                                                            break;
                                                        Interfaces.IMapObject _obj = attacker.Owner.Screen.Objects[c];
                                                        if (_obj == null)
                                                            continue;
                                                        if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                        {
                                                            attacked = _obj as Entity;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Range)
                                                            {
                                                                if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                {
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, ref attack);
                                                                    if (spell.Power > 0)
                                                                        damage = Game.Attacking.Calculate.Magic(attacker, attacked, spell, ref attack);

                                                                    ReceiveAttack(attacker, attacked, attack, damage, spell);
                                                                    suse.Targets.Add(attacked.UID, damage);
                                                                    attacker.Owner.SendScreen(suse, true);
                                                                }
                                                            }
                                                        }
                                                        else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                        {
                                                            attackedsob = _obj as SobNpcSpawn;
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Range)
                                                            {
                                                                if (CanAttack(attacker, attackedsob, spell))
                                                                {
                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                    if (spell.Power > 0)
                                                                        damage = Game.Attacking.Calculate.Magic(attacker, attackedsob, spell, ref attack);

                                                                    ReceiveAttack(attacker, attackedsob, attack, damage, spell);
                                                                    suse.Targets.Add(attackedsob.UID, damage);
                                                                    attacker.Owner.SendScreen(suse, true);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }

                                            }
                                            break;
                                        }
                                    case 11070: // Gale Bomb
                                        {
                                            if (Time32.Now >= attacker.MagikAttackTimeAtaque.AddMilliseconds(200))
                                            {
                                                attacker.MagikAttackTimeAtaque = Time32.Now;
                                                if (CanUseSpell(spell, attacker.Owner))
                                                {
                                                    PrepareSpell(spell, attacker.Owner);

                                                    SpellUse suse = new SpellUse(true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = spell.ID;
                                                    suse.SpellLevel = spell.Level;
                                                    suse.X = attack.X;
                                                    suse.Y = attack.Y;

                                                    attack.AttackType = 0x1b;
                                                    byte MaxDistance = (byte)spell.UnknownPush;
                                                    int counts = 0;
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= attacker.AttackRange + 3)
                                                    {
                                                        foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                        {
                                                            if (counts < 3)
                                                            {
                                                                if (_obj == null)
                                                                    continue;

                                                                if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                                {
                                                                    attacked = _obj as Entity;
                                                                    if (ServerBase.Kernel.GetDistance(X, Y, attacked.X, attacked.Y) <= 5)
                                                                    {
                                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                        {

                                                                            if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                            {
                                                                                if (Misc.Distance(_obj.X, _obj.Y, (ushort)attack.X, (ushort)attack.Y) < (int)MaxDistance)
                                                                                {

                                                                                    var direction = ServerBase.Kernel.GetAngle(attacker.X, attacker.Y, attacked.X, attacked.Y);
                                                                                    attack = new Attack(true);
                                                                                    byte angle = (byte)(attack.Attacked % 8);
                                                                                    attack.Effect1 = Attack.AttackEffects1.None;
                                                                                    uint damage = Calculate.Melee(attacker, attacked, ref attack);
                                                                                    attack.AttackType = 0x1b;
                                                                                    attack.X = attacker.X;
                                                                                    attack.Y = attacker.Y;
                                                                                    attack.PushBack = angle;
                                                                                    attack.Attacker = attacker.UID;
                                                                                    attack.Attacked = attacked.UID;
                                                                                    attack.Damage = damage;
                                                                                    // attack.ToArray()[27] = (byte)direction;
                                                                                    // attacked.Move(direction);
                                                                                    // attacker.Move(direction);

                                                                                    ReceiveAttack(attacker, attacked, attack, damage, spell);
                                                                                    counts++;
                                                                                    // attacker.Owner.SendScreen(attack, true);
                                                                                    attacker.Owner.SendScreen(suse, true);
                                                                                    //attacker.X = attacker.X;

                                                                                }
                                                                                else
                                                                                    break;



                                                                            }
                                                                            else
                                                                            {
                                                                                suse.Targets.Add(attacked.UID, 0);
                                                                                suse.Targets[attacked.UID].Hit = false;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                                {
                                                                    attackedsob = _obj as SobNpcSpawn;
                                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= 5)
                                                                    {
                                                                        if (CanAttack(attacker, attackedsob, spell))
                                                                        {
                                                                            if (ServerBase.Kernel.Rate(100))
                                                                            {
                                                                                if (CanAttack(attacker, attackedsob, spell))
                                                                                {
                                                                                    uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                                                    ReceiveAttack(attacker, attackedsob, attack, damage, spell);
                                                                                    counts++;
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                suse.Targets.Add(attacked.UID, 0);
                                                                                suse.Targets[attacked.UID].Hit = false;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        attacker.AttackPacket = null;
                                                    }
                                                    attacker.Owner.SendScreen(suse, true);
                                                }
                                            }
                                            break;
                                        }
                                    #endregion

                                    #endregion
                                    #region Ninja Spells
                                    case 6010://Vortex
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;

                                                attacker.AddFlag(Update.Flags.ShurikenVortex);
                                                attacker.RemoveFlag(Update.Flags.Ride);
                                                attacker.ShurikenVortexStamp = Time32.Now;
                                                attacker.ShurikenVortexTime = 20;

                                                attacker.Owner.SendScreen(suse, true);

                                                attacker.VortexPacket = new Attack(true);
                                                attacker.VortexPacket.Decoded = true;
                                                attacker.VortexPacket.Damage = 6012;
                                                attacker.VortexPacket.AttackType = Attack.Magic;
                                                attacker.VortexPacket.Attacker = attacker.UID;
                                            }
                                            break;
                                        }
                                    case 6012://VortexRespone
                                        {
                                            if (!attacker.ContainsFlag(Update.Flags.ShurikenVortex))
                                            {
                                                attacker.AttackPacket = null;
                                                break;
                                            }
                                            SpellUse suse = new SpellUse(true);
                                            suse.Attacker = attacker.UID;
                                            suse.SpellID = spell.ID;
                                            suse.SpellLevel = spell.Level;
                                            suse.X = attacker.X;
                                            suse.Y = attacker.Y;
                                            foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                            {
                                                if (_obj == null)
                                                    continue;
                                                if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                {
                                                    attacked = _obj as Entity;
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Range)
                                                    {
                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                        {
                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);

                                                            suse.Effect1 = attack.Effect1;

                                                            ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                            suse.Targets.Add(attacked.UID, damage);
                                                        }
                                                    }
                                                }
                                                else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                {
                                                    attackedsob = _obj as SobNpcSpawn;
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attackedsob.X, attackedsob.Y) <= spell.Range)
                                                    {
                                                        if (CanAttack(attacker, attackedsob, spell))
                                                        {
                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                            suse.Effect1 = attack.Effect1;
                                                            ReceiveAttack(attacker, attackedsob, attack, damage, spell);
                                                            suse.Targets.Add(attackedsob.UID, damage);
                                                        }
                                                    }
                                                }
                                            }
                                            attacker.Owner.SendScreen(suse, true);
                                            break;
                                        }
                                    case 6001:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= spell.Distance)
                                                {
                                                    foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                    {
                                                        if (_obj.MapObjType == MapObjectType.Player)
                                                        {
                                                            attacked = _obj as Entity;
                                                            if (ServerBase.Kernel.GetDistance(X, Y, attacked.X, attacked.Y) <= spell.Range)
                                                            {
                                                                if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                {
                                                                    int potDifference = attacker.BattlePower - attacked.BattlePower;

                                                                    int rate = spell.Percent + potDifference - 20;

                                                                    if (ServerBase.Kernel.Rate(rate))
                                                                    {
                                                                        attacked.ToxicFogStamp = Time32.Now;
                                                                        attacked.ToxicFogLeft = 20;
                                                                        attacked.ToxicFogPercent = spell.PowerPercent;
                                                                        suse.Targets.Add(attacked.UID, 1);
                                                                    }
                                                                    if (attacker.BattlePower - attacked.BattlePower > 0)
                                                                    {
                                                                        attacked.ToxicFogStamp = Time32.Now;
                                                                        attacked.ToxicFogLeft = 20;
                                                                        attacked.ToxicFogPercent = spell.PowerPercent;
                                                                        suse.Targets.Add(attacked.UID, 1);
                                                                    }
                                                                    else
                                                                    {
                                                                        suse.Targets.Add(attacked.UID, 0);
                                                                        suse.Targets[attacked.UID].Hit = false;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (_obj.MapObjType == MapObjectType.Monster)
                                                            {
                                                                attacked = _obj as Entity;
                                                                if (!ServerBase.Constants.NoFog.Contains(attacked.Name))
                                                                {

                                                                    if (ServerBase.Kernel.GetDistance(X, Y, attacked.X, attacked.Y) <= spell.Range)
                                                                    {
                                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                        {
                                                                            int potDifference = attacker.BattlePower - attacked.BattlePower;

                                                                            int rate = spell.Percent + potDifference - 20;

                                                                            if (ServerBase.Kernel.Rate(rate))
                                                                            {
                                                                                attacked.ToxicFogStamp = Time32.Now;
                                                                                attacked.ToxicFogLeft = 20;
                                                                                attacked.ToxicFogPercent = spell.PowerPercent;
                                                                                suse.Targets.Add(attacked.UID, 1);
                                                                            }
                                                                            if (attacker.BattlePower - attacked.BattlePower > 0)
                                                                            {
                                                                                attacked.ToxicFogStamp = Time32.Now;
                                                                                attacked.ToxicFogLeft = 20;
                                                                                attacked.ToxicFogPercent = spell.PowerPercent;
                                                                                suse.Targets.Add(attacked.UID, 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                suse.Targets.Add(attacked.UID, 0);
                                                                                suse.Targets[attacked.UID].Hit = false;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                                attacker.Owner.IncreaseSpellExperience(80, spellID);
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    case 6000:
                                    case 10381:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                ushort Xx, Yx;
                                                if (attacked != null)
                                                {
                                                    Xx = attacked.X;
                                                    Yx = attacked.Y;
                                                }
                                                else
                                                {
                                                    Xx = attackedsob.X;
                                                    Yx = attackedsob.Y;
                                                }
                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, Xx, Yx) <= spell.Range)
                                                {
                                                    if (attackedsob == null)
                                                        if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.Fly))
                                                            return;
                                                    //if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.Fly))
                                                    //  return;
                                                    if (attacker.ContainsFlag(Network.GamePackets.Update.Flags.Fly))
                                                        return;
                                                    PrepareSpell(spell, attacker.Owner);

                                                    SpellUse suse = new SpellUse(true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = spell.ID;
                                                    suse.SpellLevel = spell.Level;
                                                    suse.X = X;
                                                    suse.Y = Y;

                                                    bool send = false;

                                                    if (attackedsob == null)
                                                    {
                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                        {
                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);
                                                            suse.Effect1 = attack.Effect1;

                                                            ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                            suse.Targets.Add(attacked.UID, damage);
                                                            send = true;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (CanAttack(attacker, attackedsob, spell))
                                                        {
                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                            uint damage = Game.Attacking.Calculate.Melee(attacker, attackedsob, ref attack);
                                                            damage = (uint)(damage * spell.PowerPercent);
                                                            ReceiveAttack(attacker, attackedsob, attack, damage, spell);
                                                            suse.Effect1 = attack.Effect1;

                                                            suse.Targets.Add(attackedsob.UID, damage);
                                                            send = true;
                                                        }
                                                    }
                                                    if (send)
                                                        attacker.Owner.SendScreen(suse, true);
                                                }
                                                else
                                                {
                                                    attacker.AttackPacket = null;
                                                }
                                            }
                                            break;
                                        }
                                    case 6002:
                                        {
                                            if (attackedsob != null)
                                                return;
                                            if (attacked.EntityFlag == EntityFlag.Monster)
                                                return;
                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Distance)
                                            {
                                                if (CanUseSpell(spell, attacker.Owner))
                                                {
                                                    PrepareSpell(spell, attacker.Owner);

                                                    int potDifference = attacker.BattlePower - attacked.BattlePower;

                                                    int rate = spell.Percent + potDifference;

                                                    SpellUse suse = new SpellUse(true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = spell.ID;
                                                    suse.SpellLevel = spell.Level;
                                                    suse.X = X;
                                                    suse.Y = Y;
                                                    if (CanAttack(attacker, attacked, spell, false))
                                                    {
                                                        suse.Targets.Add(attacked.UID, 0);
                                                        if (ServerBase.Kernel.Rate(rate))
                                                        {
                                                            attacked.NoDrugsStamp = Time32.Now;
                                                            attacked.NoDrugsTime = (short)spell.Duration;
                                                            if (attacked.EntityFlag == EntityFlag.Player)
                                                            {
                                                                attacker.Owner.IncreaseSpellExperience(80, spellID);
                                                                attacked.Owner.Send(ServerBase.Constants.NoDrugs((int)spell.Duration));
                                                            }
                                                        }
                                                        else
                                                        {
                                                            suse.Targets[attacked.UID].Hit = false;
                                                        }

                                                        attacked.Owner.SendScreen(suse, true);
                                                    }
                                                }
                                            }

                                            break;
                                        }
                                    case 6004:
                                        {
                                            if (attackedsob != null)
                                                return;
                                            if (attacked.EntityFlag == EntityFlag.Monster)
                                                return;
                                            if (!attacked.ContainsFlag(Update.Flags.Fly))
                                                return;
                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Distance)
                                            {
                                                if (CanUseSpell(spell, attacker.Owner))
                                                {
                                                    PrepareSpell(spell, attacker.Owner);

                                                    int potDifference = attacker.BattlePower - attacked.BattlePower;

                                                    int rate = spell.Percent + potDifference;

                                                    SpellUse suse = new SpellUse(true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = spell.ID;
                                                    suse.SpellLevel = spell.Level;
                                                    suse.X = X;
                                                    suse.Y = Y;
                                                    if (CanAttack(attacker, attacked, spell, false))
                                                    {
                                                        uint dmg = Calculate.Percent(attacked, 0.1F);
                                                        suse.Targets.Add(attacked.UID, dmg);

                                                        if (ServerBase.Kernel.Rate(rate))
                                                        {
                                                            attacked.Hitpoints -= dmg;
                                                            attacked.RemoveFlag(Update.Flags.Fly);
                                                        }
                                                        else
                                                        {
                                                            suse.Targets[attacked.UID].Hit = false;
                                                        }

                                                        attacked.Owner.SendScreen(suse, true);
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Riding

                                    case 7001:
                                        {
                                            if (attacker.ContainsFlag2(Update.Flags2.WarriorWalk))
                                                return;
                                            if (attacker.ContainsFlag(Update.Flags.ShurikenVortex))
                                                return;
                                            if (ServerBase.Constants.steedguard.Contains(attacker.MapID))
                                                return;
                                            if (!attacker.Owner.Equipment.Free(12))
                                            {
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;

                                                if (attacker.ContainsFlag(Update.Flags.Ride))
                                                {
                                                    attacker.RemoveFlag(Update.Flags.Ride);
                                                }
                                                else
                                                {
                                                    if (attacker.Owner.Equipment.TryGetItem((byte)12).Plus < attacker.MapRegion.Lineage)
                                                        break;
                                                    if (attacker.Stamina >= 100 && (attacker.Owner.QualifierGroup == null || attacker.Owner.QualifierGroup != null && !attacker.Owner.QualifierGroup.Inside))
                                                    {
                                                        attacker.AddFlag(Update.Flags.Ride);
                                                        attacker.Stamina -= 100;
                                                        attacker.Vigor = (ushort)attacker.MaxVigor;
                                                        Network.GamePackets.Vigor vigor = new Network.GamePackets.Vigor(true);
                                                        vigor.VigorValue = attacker.Owner.Entity.MaxVigor;
                                                        vigor.Send(attacker.Owner);
                                                    }
                                                }
                                                suse.Targets.Add(attacker.UID, 0);
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    case 7002:
                                        {//Spook
                                            if (attacked.ContainsFlag(Update.Flags.Ride) && attacker.ContainsFlag(Update.Flags.Ride))
                                            {
                                                Interfaces.IConquerItem attackedSteed = null, attackerSteed = null;
                                                if ((attackedSteed = attacked.Owner.Equipment.TryGetItem(ConquerItem.Steed)) != null)
                                                {
                                                    if ((attackerSteed = attacker.Owner.Equipment.TryGetItem(ConquerItem.Steed)) != null)
                                                    {
                                                        SpellUse suse = new SpellUse(true);
                                                        suse.Attacker = attacker.UID;
                                                        suse.SpellID = spell.ID;
                                                        suse.SpellLevel = spell.Level;
                                                        suse.X = X;
                                                        suse.Y = Y;
                                                        suse.Targets.Add(attacked.UID, 0);

                                                        if (attackedSteed.Plus < attackerSteed.Plus)
                                                            attacked.RemoveFlag(Update.Flags.Ride);
                                                        else if (attackedSteed.Plus == attackerSteed.Plus && attackedSteed.PlusProgress <= attackerSteed.PlusProgress)
                                                            attacked.RemoveFlag(Update.Flags.Ride);
                                                        else
                                                            suse.Targets[attacked.UID].Hit = false;
                                                        attacker.Owner.SendScreen(suse, true);
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    case 7003:
                                        {//WarCry
                                            SpellUse suse = new SpellUse(true);
                                            suse.Attacker = attacker.UID;
                                            suse.SpellID = spell.ID;
                                            suse.SpellLevel = spell.Level;
                                            suse.X = X;
                                            suse.Y = Y;
                                            Interfaces.IConquerItem attackedSteed = null, attackerSteed = null;
                                            foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                            {
                                                if (_obj == null)
                                                    continue;
                                                if (_obj.MapObjType == MapObjectType.Player && _obj.UID != attacker.UID)
                                                {
                                                    attacked = _obj as Entity;
                                                    if ((attackedSteed = attacked.Owner.Equipment.TryGetItem(ConquerItem.Steed)) != null)
                                                    {
                                                        if ((attackerSteed = attacker.Owner.Equipment.TryGetItem(ConquerItem.Steed)) != null)
                                                        {
                                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= attackedSteed.Plus)
                                                            {
                                                                if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                                {
                                                                    suse.Targets.Add(attacked.UID, 0);
                                                                    if (attackedSteed.Plus < attackerSteed.Plus)
                                                                        attacked.RemoveFlag(Update.Flags.Ride);
                                                                    else if (attackedSteed.Plus == attackerSteed.Plus && attackedSteed.PlusProgress <= attackerSteed.PlusProgress)
                                                                        attacked.RemoveFlag(Update.Flags.Ride);
                                                                    else
                                                                        suse.Targets[attacked.UID].Hit = false;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            attacker.Owner.SendScreen(suse, true);
                                            break;
                                        }
                                    #endregion
                                    #region Dash
                                    case 1051:
                                        {
                                            if (attacked != null)
                                            {
                                                if (!attacked.Dead)
                                                {
                                                    var direction = ServerBase.Kernel.GetAngle(attacker.X, attacker.Y, attacked.X, attacked.Y);
                                                    if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                    {
                                                        attack = new Attack(true);
                                                        attack.Effect1 = Attack.AttackEffects1.None;
                                                        uint damage = Calculate.Melee(attacker, attacked, ref attack);
                                                        attack.AttackType = Attack.Dash;
                                                        attack.X = attacked.X;
                                                        attack.Y = attacked.Y;
                                                        attack.Attacker = attacker.UID;
                                                        attack.Attacked = attacked.UID;
                                                        attack.Damage = damage;
                                                        attack.ToArray()[27] = (byte)direction;
                                                        attacked.Move(direction);
                                                        attacker.Move(direction);

                                                        ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                        attacker.Owner.SendScreen(attack, true);
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    #endregion

                                    #region RapidFire
                                    case 8000:
                                        {
                                            if (attackedsob != null)
                                            {
                                                if (CanUseSpell(spell, attacker.Owner))
                                                {
                                                    if (CanAttack(attacker, attackedsob, spell))
                                                    {
                                                        PrepareSpell(spell, attacker.Owner);
                                                        SpellUse suse = new SpellUse(true);
                                                        suse.Attacker = attacker.UID;
                                                        suse.SpellID = spell.ID;
                                                        suse.SpellLevel = spell.Level;
                                                        suse.X = attackedsob.X;
                                                        suse.Y = attackedsob.Y;
                                                        attack.Effect1 = Attack.AttackEffects1.None;
                                                        uint damage = Calculate.Ranged(attacker, attackedsob, ref attack);
                                                        suse.Effect1 = attack.Effect1;
                                                        damage = (uint)(damage * spell.PowerPercent);
                                                        suse.Targets.Add(attackedsob.UID, damage);

                                                        ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                        attacker.Owner.SendScreen(suse, true);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (!attacked.Dead)
                                                {
                                                    if (CanUseSpell(spell, attacker.Owner))
                                                    {
                                                        if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                        {
                                                            PrepareSpell(spell, attacker.Owner);
                                                            SpellUse suse = new SpellUse(true);
                                                            suse.Attacker = attacker.UID;
                                                            suse.SpellID = spell.ID;
                                                            suse.SpellLevel = spell.Level;
                                                            suse.X = attacked.X;
                                                            suse.Y = attacked.Y;
                                                            attack.Effect1 = Attack.AttackEffects1.None;
                                                            uint damage = Calculate.Ranged(attacker, attacked, ref attack);
                                                            damage = (uint)(damage * spell.PowerPercent);
                                                            suse.Targets.Add(attacked.UID, damage);

                                                            ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                            attacker.Owner.SendScreen(suse, true);
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region FireOfHell
                                    case 1165:
                                    case 7014:
                                    case 7012:
                                    case 9971:
                                    case 7017:
                                    case 7015:
                                    case 7013:
                                    case 10360:
                                    case 9966:
                                    case 30010:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                Sector sector = new Sector(attacker.X, attacker.Y, X, Y);
                                                sector.Arrange(spell.Sector, spell.Distance);
                                                foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                {
                                                    if (_obj == null)
                                                        continue;
                                                    if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                    {
                                                        attacked = _obj as Entity;

                                                        if (sector.Inside(attacked.X, attacked.Y))
                                                        {
                                                            if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                            {
                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                uint damage = Game.Attacking.Calculate.Magic(attacker, attacked, spell, ref attack);
                                                                suse.Effect1 = attack.Effect1;

                                                                ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                suse.Targets.Add(attacked.UID, damage);
                                                            }
                                                        }
                                                    }
                                                    else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                    {
                                                        attackedsob = _obj as SobNpcSpawn;

                                                        if (sector.Inside(attackedsob.X, attackedsob.Y))
                                                        {
                                                            if (CanAttack(attacker, attackedsob, spell))
                                                            {
                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                uint damage = Game.Attacking.Calculate.Magic(attacker, attackedsob, spell, ref attack);
                                                                suse.Effect1 = attack.Effect1;
                                                                ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                                suse.Targets.Add(attackedsob.UID, damage);
                                                            }
                                                        }
                                                    }
                                                }
                                                attacker.Owner.SendScreen(suse, true);

                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Scatter
                                    case 8001:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                if (attacker.xx == attacker.X && attacker.yy == attacker.Y)
                                                {
                                                    attacker.scatter += 1;
                                                    if (attacker.scatter > 30)
                                                    {
                                                        attacker.Owner.Disconnect();
                                                    }
                                                }
                                                else
                                                {
                                                    attacker.xx = attacker.X;
                                                    attacker.yy = attacker.Y;
                                                    attacker.scatter = 0;
                                                }

                                                Sector sector = new Sector(attacker.X, attacker.Y, X, Y);
                                                sector.Arrange(spell.Sector, spell.Distance);
                                                foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                {
                                                    if (_obj == null)
                                                        continue;
                                                    if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                    {
                                                        attacked = _obj as Entity;

                                                        if (sector.Inside(attacked.X, attacked.Y))
                                                        {
                                                            if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                            {
                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                uint damage = Game.Attacking.Calculate.Ranged(attacker, attacked, spell, ref attack);

                                                                ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                suse.Targets.Add(attacked.UID, damage);
                                                            }
                                                        }
                                                    }
                                                    else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                    {
                                                        attackedsob = _obj as SobNpcSpawn;

                                                        if (sector.Inside(attackedsob.X, attackedsob.Y))
                                                        {
                                                            if (CanAttack(attacker, attackedsob, spell))
                                                            {
                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                uint damage = Game.Attacking.Calculate.Ranged(attacker, attackedsob, ref attack);
                                                                suse.Effect1 = attack.Effect1;
                                                                if (damage == 0)
                                                                    damage = 1;
                                                                damage = Game.Attacking.Calculate.Percent((int)damage, spell.PowerPercent);

                                                                ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                                suse.Targets.Add(attackedsob.UID, damage);
                                                            }
                                                        }
                                                    }
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Intensify
                                    case 9000:
                                        {
                                            attacker.IntensifyStamp = Time32.Now;
                                            attacker.OnIntensify = true;
                                            SpellUse suse = new SpellUse(true);
                                            suse.Attacker = attacker.UID;
                                            suse.SpellID = spell.ID;
                                            suse.SpellLevel = spell.Level;
                                            suse.X = X;
                                            suse.Y = Y;
                                            suse.Targets.Add(attacker.UID, 0);
                                            suse.Send(attacker.Owner);
                                            break;
                                        }
                                    #endregion
                                    #region StarArrow
                                    case 10313:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                Sector sector = new Sector(attacker.X, attacker.Y, X, Y);
                                                sector.Arrange(spell.Sector, spell.Distance);
                                                foreach (Interfaces.IMapObject _obj in attacker.Owner.Screen.Objects)
                                                {
                                                    if (_obj == null)
                                                        continue;
                                                    if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                    {
                                                        attacked = _obj as Entity;

                                                        if (sector.Inside(attacked.X, attacked.Y))
                                                        {
                                                            if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Melee))
                                                            {
                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                uint damage = Game.Attacking.Calculate.Ranged(attacker, attacked, spell, ref attack);

                                                                ReceiveAttack(attacker, attacked, attack, damage, spell);

                                                                suse.Targets.Add(attacked.UID, damage);
                                                            }
                                                        }
                                                    }
                                                    else if (_obj.MapObjType == MapObjectType.SobNpc)
                                                    {
                                                        attackedsob = _obj as SobNpcSpawn;

                                                        if (sector.Inside(attackedsob.X, attackedsob.Y))
                                                        {
                                                            if (CanAttack(attacker, attackedsob, spell))
                                                            {
                                                                attack.Effect1 = Attack.AttackEffects1.None;
                                                                uint damage = Game.Attacking.Calculate.Ranged(attacker, attackedsob, ref attack);
                                                                suse.Effect1 = attack.Effect1;
                                                                if (damage == 0)
                                                                    damage = 1;
                                                                damage = Game.Attacking.Calculate.Percent((int)damage, spell.PowerPercent);

                                                                ReceiveAttack(attacker, attackedsob, attack, damage, spell);

                                                                suse.Targets.Add(attackedsob.UID, damage);
                                                            }
                                                        }
                                                    }
                                                }
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Trasnformations
                                    case 1270:
                                    case 1280:
                                    case 1350:
                                    case 1360:
                                    case 3321:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                if (attacker.MapID == 1036)
                                                    return;
                                                bool wasTransformated = attacker.Transformed;
                                                PrepareSpell(spell, attacker.Owner);

                                                #region Atributes
                                                switch (spell.ID)
                                                {
                                                    case 1350:
                                                        switch (spell.Level)
                                                        {
                                                            case 0:
                                                                {
                                                                    attacker.TransformationMaxAttack = 182;
                                                                    attacker.TransformationMinAttack = 122;
                                                                    attacker.TransformationDefence = 1300;
                                                                    attacker.TransformationMagicDefence = 94;
                                                                    attacker.TransformationDodge = 35;
                                                                    attacker.TransformationTime = 39;
                                                                    attacker.TransformationID = 207;
                                                                    break;
                                                                }
                                                            case 1:
                                                                {
                                                                    attacker.TransformationMaxAttack = 200;
                                                                    attacker.TransformationMinAttack = 134;
                                                                    attacker.TransformationDefence = 1400;
                                                                    attacker.TransformationMagicDefence = 96;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 49;
                                                                    attacker.TransformationID = 207;
                                                                    break;
                                                                }
                                                            case 2:
                                                                {
                                                                    attacker.TransformationMaxAttack = 240;
                                                                    attacker.TransformationMinAttack = 160;
                                                                    attacker.TransformationDefence = 1500;
                                                                    attacker.TransformationMagicDefence = 97;
                                                                    attacker.TransformationDodge = 45;
                                                                    attacker.TransformationTime = 59;
                                                                    attacker.TransformationID = 207;
                                                                    break;
                                                                }
                                                            case 3:
                                                                {
                                                                    attacker.TransformationMaxAttack = 258;
                                                                    attacker.TransformationMinAttack = 172;
                                                                    attacker.TransformationDefence = 1600;
                                                                    attacker.TransformationMagicDefence = 98;
                                                                    attacker.TransformationDodge = 50;
                                                                    attacker.TransformationTime = 69;
                                                                    attacker.TransformationID = 267;
                                                                    break;
                                                                }
                                                            case 4:
                                                                {
                                                                    attacker.TransformationMaxAttack = 300;
                                                                    attacker.TransformationMinAttack = 200;
                                                                    attacker.TransformationDefence = 1900;
                                                                    attacker.TransformationMagicDefence = 99;
                                                                    attacker.TransformationDodge = 55;
                                                                    attacker.TransformationTime = 79;
                                                                    attacker.TransformationID = 267;
                                                                    break;
                                                                }
                                                        }
                                                        break;
                                                    case 1270:
                                                        switch (spell.Level)
                                                        {
                                                            case 0:
                                                                {
                                                                    attacker.TransformationMaxAttack = 282;
                                                                    attacker.TransformationMinAttack = 179;
                                                                    attacker.TransformationDefence = 73;
                                                                    attacker.TransformationMagicDefence = 34;
                                                                    attacker.TransformationDodge = 9;
                                                                    attacker.TransformationTime = 34;
                                                                    attacker.TransformationID = 214;
                                                                    break;
                                                                }
                                                            case 1:
                                                                {
                                                                    attacker.TransformationMaxAttack = 395;
                                                                    attacker.TransformationMinAttack = 245;
                                                                    attacker.TransformationDefence = 126;
                                                                    attacker.TransformationMagicDefence = 45;
                                                                    attacker.TransformationDodge = 12;
                                                                    attacker.TransformationTime = 39;
                                                                    attacker.TransformationID = 214;
                                                                    break;
                                                                }
                                                            case 2:
                                                                {
                                                                    attacker.TransformationMaxAttack = 616;
                                                                    attacker.TransformationMinAttack = 367;
                                                                    attacker.TransformationDefence = 180;
                                                                    attacker.TransformationMagicDefence = 53;
                                                                    attacker.TransformationDodge = 15;
                                                                    attacker.TransformationTime = 44;
                                                                    attacker.TransformationID = 214;
                                                                    break;
                                                                }
                                                            case 3:
                                                                {
                                                                    attacker.TransformationMaxAttack = 724;
                                                                    attacker.TransformationMinAttack = 429;
                                                                    attacker.TransformationDefence = 247;
                                                                    attacker.TransformationMagicDefence = 53;
                                                                    attacker.TransformationDodge = 15;
                                                                    attacker.TransformationTime = 49;
                                                                    attacker.TransformationID = 214;
                                                                    break;
                                                                }
                                                            case 4:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1231;
                                                                    attacker.TransformationMinAttack = 704;
                                                                    attacker.TransformationDefence = 499;
                                                                    attacker.TransformationMagicDefence = 50;
                                                                    attacker.TransformationDodge = 20;
                                                                    attacker.TransformationTime = 54;
                                                                    attacker.TransformationID = 274;
                                                                    break;
                                                                }
                                                            case 5:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1573;
                                                                    attacker.TransformationMinAttack = 941;
                                                                    attacker.TransformationDefence = 601;
                                                                    attacker.TransformationMagicDefence = 53;
                                                                    attacker.TransformationDodge = 25;
                                                                    attacker.TransformationTime = 59;
                                                                    attacker.TransformationID = 274;
                                                                    break;
                                                                }
                                                            case 6:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1991;
                                                                    attacker.TransformationMinAttack = 1107;
                                                                    attacker.TransformationDefence = 1029;
                                                                    attacker.TransformationMagicDefence = 55;
                                                                    attacker.TransformationDodge = 30;
                                                                    attacker.TransformationTime = 64;
                                                                    attacker.TransformationID = 274;
                                                                    break;
                                                                }
                                                            case 7:
                                                                {
                                                                    attacker.TransformationMaxAttack = 2226;
                                                                    attacker.TransformationMinAttack = 1235;
                                                                    attacker.TransformationDefence = 1029;
                                                                    attacker.TransformationMagicDefence = 55;
                                                                    attacker.TransformationDodge = 35;
                                                                    attacker.TransformationTime = 69;
                                                                    attacker.TransformationID = 274;
                                                                    break;
                                                                }
                                                        }
                                                        break;
                                                    case 1360:
                                                        switch (spell.Level)
                                                        {
                                                            case 0:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1215;
                                                                    attacker.TransformationMinAttack = 610;
                                                                    attacker.TransformationDefence = 100;
                                                                    attacker.TransformationMagicDefence = 96;
                                                                    attacker.TransformationDodge = 30;
                                                                    attacker.TransformationTime = 59;
                                                                    attacker.TransformationID = 217;
                                                                    break;
                                                                }
                                                            case 1:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1310;
                                                                    attacker.TransformationMinAttack = 650;
                                                                    attacker.TransformationDefence = 400;
                                                                    attacker.TransformationMagicDefence = 97;
                                                                    attacker.TransformationDodge = 30;
                                                                    attacker.TransformationTime = 79;
                                                                    attacker.TransformationID = 217;
                                                                    break;
                                                                }
                                                            case 2:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1420;
                                                                    attacker.TransformationMinAttack = 710;
                                                                    attacker.TransformationDefence = 650;
                                                                    attacker.TransformationMagicDefence = 98;
                                                                    attacker.TransformationDodge = 30;
                                                                    attacker.TransformationTime = 89;
                                                                    attacker.TransformationID = 217;
                                                                    break;
                                                                }
                                                            case 3:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1555;
                                                                    attacker.TransformationMinAttack = 780;
                                                                    attacker.TransformationDefence = 720;
                                                                    attacker.TransformationMagicDefence = 98;
                                                                    attacker.TransformationDodge = 30;
                                                                    attacker.TransformationTime = 99;
                                                                    attacker.TransformationID = 277;
                                                                    break;
                                                                }
                                                            case 4:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1660;
                                                                    attacker.TransformationMinAttack = 840;
                                                                    attacker.TransformationDefence = 1200;
                                                                    attacker.TransformationMagicDefence = 99;
                                                                    attacker.TransformationDodge = 30;
                                                                    attacker.TransformationTime = 109;
                                                                    attacker.TransformationID = 277;
                                                                    break;
                                                                }
                                                        }
                                                        break;
                                                    case 1280:
                                                        switch (spell.Level)
                                                        {
                                                            case 0:
                                                                {
                                                                    attacker.TransformationMaxAttack = 930;
                                                                    attacker.TransformationMinAttack = 656;
                                                                    attacker.TransformationDefence = 290;
                                                                    attacker.TransformationMagicDefence = 45;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 29;
                                                                    attacker.TransformationID = 213;
                                                                    break;
                                                                }
                                                            case 1:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1062;
                                                                    attacker.TransformationMinAttack = 750;
                                                                    attacker.TransformationDefence = 320;
                                                                    attacker.TransformationMagicDefence = 46;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 34;
                                                                    attacker.TransformationID = 213;
                                                                    break;
                                                                }
                                                            case 2:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1292;
                                                                    attacker.TransformationMinAttack = 910;
                                                                    attacker.TransformationDefence = 510;
                                                                    attacker.TransformationMagicDefence = 50;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 39;
                                                                    attacker.TransformationID = 213;
                                                                    break;
                                                                }
                                                            case 3:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1428;
                                                                    attacker.TransformationMinAttack = 1000;
                                                                    attacker.TransformationDefence = 600;
                                                                    attacker.TransformationMagicDefence = 53;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 44;
                                                                    attacker.TransformationID = 213;
                                                                    break;
                                                                }
                                                            case 4:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1570;
                                                                    attacker.TransformationMinAttack = 1100;
                                                                    attacker.TransformationDefence = 700;
                                                                    attacker.TransformationMagicDefence = 55;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 49;
                                                                    attacker.TransformationID = 213;
                                                                    break;
                                                                }
                                                            case 5:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1700;
                                                                    attacker.TransformationMinAttack = 1200;
                                                                    attacker.TransformationDefence = 880;
                                                                    attacker.TransformationMagicDefence = 57;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 54;
                                                                    attacker.TransformationID = 273;
                                                                    break;
                                                                }
                                                            case 6:
                                                                {
                                                                    attacker.TransformationMaxAttack = 1900;
                                                                    attacker.TransformationMinAttack = 1300;
                                                                    attacker.TransformationDefence = 1540;
                                                                    attacker.TransformationMagicDefence = 59;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 59;
                                                                    attacker.TransformationID = 273;
                                                                    break;
                                                                }
                                                            case 7:
                                                                {
                                                                    attacker.TransformationMaxAttack = 2100;
                                                                    attacker.TransformationMinAttack = 1500;
                                                                    attacker.TransformationDefence = 1880;
                                                                    attacker.TransformationMagicDefence = 61;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 59;
                                                                    attacker.TransformationID = 273;
                                                                    break;
                                                                }
                                                            case 8:
                                                                {
                                                                    attacker.TransformationMaxAttack = 2300;
                                                                    attacker.TransformationMinAttack = 1600;
                                                                    attacker.TransformationDefence = 1970;
                                                                    attacker.TransformationMagicDefence = 63;
                                                                    attacker.TransformationDodge = 40;
                                                                    attacker.TransformationTime = 59;
                                                                    attacker.TransformationID = 273;
                                                                    break;
                                                                }
                                                        }
                                                        break;

                                                    case 3321:
                                                        {
                                                            attacker.TransformationMaxAttack = 2000000;
                                                            attacker.TransformationMinAttack = 2000000;
                                                            attacker.TransformationDefence = 65355;
                                                            attacker.TransformationMagicDefence = 65355;
                                                            attacker.TransformationDodge = 35;
                                                            attacker.TransformationTime = 65355;
                                                            attacker.TransformationID = 223;
                                                            break;
                                                        }


                                                }
                                                #endregion

                                                SpellUse spellUse = new SpellUse(true);
                                                spellUse.Attacker = attacker.UID;
                                                spellUse.SpellID = spell.ID;
                                                spellUse.SpellLevel = spell.Level;
                                                spellUse.X = X;
                                                spellUse.Y = Y;
                                                spellUse.Targets.Add(attacker.UID, (uint)0);
                                                attacker.Owner.SendScreen(spellUse, true);
                                                attacker.TransformationStamp = Time32.Now;
                                                attacker.TransformationMaxHP = 3000;
                                                if (spell.ID == 1270)
                                                    attacker.TransformationMaxHP = 50000;
                                                attacker.TransformationAttackRange = 3;
                                                if (spell.ID == 1360)
                                                    attacker.TransformationAttackRange = 10;
                                                if (!wasTransformated)
                                                {
                                                    double maxHP = attacker.MaxHitpoints;
                                                    double HP = attacker.Hitpoints;
                                                    double point = HP / maxHP;

                                                    attacker.Hitpoints = (uint)(attacker.TransformationMaxHP * point);
                                                }
                                                attacker.Update(Update.MaxHitpoints, attacker.TransformationMaxHP, false);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Bless
                                    case 9876:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);
                                                attacker.AddFlag(Update.Flags.CastPray);
                                                SpellUse spellUse = new SpellUse(true);
                                                spellUse.Attacker = attacker.UID;
                                                spellUse.SpellID = spell.ID;
                                                spellUse.SpellLevel = spell.Level;
                                                spellUse.X = X;
                                                spellUse.Y = Y;
                                                spellUse.Targets.Add(attacker.UID, 0);
                                                attacker.Owner.SendScreen(spellUse, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region Companions
                                    case 4000:
                                    case 4010:
                                    case 4020:
                                    case 4050:
                                    case 4060:
                                    case 4070:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                if (ServerBase.Constants.steedguard.Contains(attacker.MapID))
                                                    return;
                                                if (attacker.Owner.Map.BaseID == 700)
                                                    return;
                                                if (attacker.Owner.Companion != null)
                                                {
                                                    if (attacker.Owner.Companion.MonsterInfo != null)
                                                    {
                                                        attacker.Owner.Map.RemoveEntity(attacker.Owner.Companion);
                                                        Data data = new Data(true);
                                                        data.UID = attacker.Owner.Companion.UID;
                                                        data.ID = Data.RemoveEntity;
                                                        attacker.Owner.Companion.MonsterInfo.SendScreen(data);
                                                        attacker.Owner.Companion = null;
                                                    }
                                                }
                                                PrepareSpell(spell, attacker.Owner);
                                                SpellUse spellUse = new SpellUse(true);
                                                spellUse.Attacker = attacker.UID;
                                                spellUse.SpellID = spell.ID;
                                                spellUse.SpellLevel = spell.Level;
                                                spellUse.X = X;
                                                spellUse.Y = Y;
                                                spellUse.Targets.Add(attacker.UID, 0);
                                                attacker.Owner.SendScreen(spellUse, true);
                                                attacker.Owner.Companion = new Entity(EntityFlag.Monster, true);
                                                attacker.Owner.Companion.MonsterInfo = new PhoenixProject.Database.MonsterInformation();
                                                Database.MonsterInformation mt = Database.MonsterInformation.MonsterInfos[spell.Power];
                                                attacker.Owner.Companion.Owner = attacker.Owner;
                                                attacker.Owner.Companion.MapObjType = MapObjectType.Monster;
                                                attacker.Owner.Companion.MonsterInfo = mt.Copy();
                                                attacker.Owner.Companion.MonsterInfo.Owner = attacker.Owner.Companion;
                                                attacker.Owner.Companion.Name = mt.Name;
                                                attacker.Owner.Companion.MinAttack = mt.MinAttack;
                                                attacker.Owner.Companion.MaxAttack = attacker.Owner.Companion.MagicAttack = mt.MaxAttack;
                                                attacker.Owner.Companion.Hitpoints = attacker.Owner.Companion.MaxHitpoints = mt.Hitpoints;
                                                attacker.Owner.Companion.Body = mt.Mesh;
                                                attacker.Owner.Companion.Level = mt.Level; //10000181 - 1000006

                                                attacker.Owner.Companion.UID = (uint)ServerBase.Kernel.Random.Next(900300, 970350);

                                                attacker.Owner.Companion.MapID = attacker.Owner.Map.ID;
                                                attacker.Owner.Companion.SendUpdates = true;
                                                attacker.Owner.Companion.X = attacker.X;
                                                attacker.Owner.Companion.Y = attacker.Y;
                                                attacker.Owner.Map.AddEntity(attacker.Owner.Companion);
                                                attacker.Owner.SendScreenSpawn(attacker.Owner.Companion, true);
                                            }
                                            break;
                                        }
                                    #endregion
                                    #region MonkSpells
                                    //Compassion
                                    case 10395:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);
                                                if (attacker.Owner.Team != null)
                                                {
                                                    foreach (Client.GameState c in attacker.Owner.Team.Teammates)
                                                    {
                                                        if (c.Entity.MapID == attacker.MapID)
                                                        {
                                                            short distance = Kernel.GetDistance(c.Entity.X, c.Entity.Y, attacker.X, attacker.Y);
                                                            if (distance < ServerBase.Constants.pScreenDistance)
                                                            {
                                                                if (c.Entity.UID != attacker.UID)
                                                                {
                                                                    if (!c.AlternateEquipment)
                                                                    {
                                                                        c.LoadItemStats(c.Entity);
                                                                    }
                                                                    else
                                                                    {
                                                                        c.LoadItemStats2(c.Entity);
                                                                    }

                                                                    c.Entity.AuraStamp = Time32.Now;
                                                                    c.Entity.AuraTime = 20;
                                                                    // attacked.MaxAttack += 1000;
                                                                    c.Entity.CriticalStrike += 10;
                                                                    //Console.WriteLine("sk" + attacked.CriticalStrike + "");
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FendAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.MetalAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WoodAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WaterAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.EarthAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FireAura);
                                                                    c.Entity.AddFlag2(Update.Flags2.TyrantAura);
                                                                    //Update ud = new Update(true);
                                                                    //ud.Aura(attacked, attacked.CriticalStrike, spell.Level, (byte)spell.Duration);
                                                                    PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                    switch (spell.ID)
                                                                    {
                                                                        case 0x28b4:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                                            break;

                                                                        case 0x28b5:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                                            break;

                                                                        case 0x28b6:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                                            break;

                                                                        case 0x28b7:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                                            break;

                                                                        case 0x28b8:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                                            break;

                                                                        case 0x2bc0:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                                            break;

                                                                        case 0x289b:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                            break;

                                                                        case 0x28aa:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                                            break;
                                                                    }
                                                                    StatusIconData data2 = new StatusIconData
                                                                    {
                                                                        AuraLevel = spell.Level,
                                                                        AuraPower = spell.Power,
                                                                        AuraType2 = tyrantAura,
                                                                        Identifier = c.Entity.UID,
                                                                        Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                                    };
                                                                    c.Entity.Owner.Send((byte[])data2);
                                                                }
                                                            }
                                                        }

                                                    }
                                                }
                                                if (!attacked.Owner.AlternateEquipment)
                                                {
                                                    attacked.Owner.LoadItemStats(attacked.Owner.Entity);
                                                }
                                                else
                                                {
                                                    attacked.Owner.LoadItemStats2(attacked.Owner.Entity);
                                                }
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                attacker.Owner.SendScreen(suse, true);
                                                attacked.AuraStamp = Time32.Now;
                                                attacked.AuraTime = 20;
                                                // attacked.MaxAttack += 1000;
                                                attacked.CriticalStrike += 10;
                                                //Console.WriteLine("sk" + attacked.CriticalStrike + "");
                                                attacked.RemoveFlag2(Update.Flags2.FendAura);
                                                attacked.RemoveFlag2(Update.Flags2.MetalAura);
                                                attacked.RemoveFlag2(Update.Flags2.WoodAura);
                                                attacked.RemoveFlag2(Update.Flags2.WaterAura);
                                                attacked.RemoveFlag2(Update.Flags2.EarthAura);
                                                attacked.RemoveFlag2(Update.Flags2.FireAura);
                                                attacked.AddFlag2(Update.Flags2.TyrantAura);
                                                //Update ud = new Update(true);
                                                //ud.Aura(attacked, attacked.CriticalStrike, spell.Level, (byte)spell.Duration);
                                                PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                switch (spell.ID)
                                                {
                                                    case 0x28b4:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                        break;

                                                    case 0x28b5:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                        break;

                                                    case 0x28b6:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                        break;

                                                    case 0x28b7:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                        break;

                                                    case 0x28b8:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                        break;

                                                    case 0x2bc0:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                        break;

                                                    case 0x289b:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                        break;

                                                    case 0x28aa:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                        break;
                                                }
                                                StatusIconData data = new StatusIconData
                                                {
                                                    AuraLevel = spell.Level,
                                                    AuraPower = spell.Power,
                                                    AuraType2 = tyrantAura2,
                                                    Identifier = attacker.UID,
                                                    Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                };
                                                attacker.Owner.Send((byte[])data);
                                            }
                                            break;
                                        }
                                    case 10410:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);
                                                if (attacker.Owner.Team != null)
                                                {
                                                    foreach (Client.GameState c in attacker.Owner.Team.Teammates)
                                                    {
                                                        if (c.Entity.MapID == attacker.MapID)
                                                        {
                                                            short distance = Kernel.GetDistance(c.Entity.X, c.Entity.Y, attacker.X, attacker.Y);
                                                            if (distance < ServerBase.Constants.pScreenDistance)
                                                            {
                                                                if (c.Entity.UID != attacker.UID)
                                                                {
                                                                    if (!c.AlternateEquipment)
                                                                    {
                                                                        c.LoadItemStats(c.Entity);
                                                                    }
                                                                    else
                                                                    {
                                                                        c.LoadItemStats2(c.Entity);
                                                                    }

                                                                    c.Entity.AuraStamp = Time32.Now;
                                                                    c.Entity.AuraTime = 20;
                                                                    c.Entity.SkillCStrike += 10;
                                                                    c.Entity.CriticalStrike += 10;
                                                                    // attacked.MaxAttack += 100;
                                                                    c.Entity.RemoveFlag2(Update.Flags2.TyrantAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.MetalAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WoodAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WaterAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.EarthAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FireAura);
                                                                    c.Entity.AddFlag2(Update.Flags2.FendAura);
                                                                    PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                    switch (spell.ID)
                                                                    {
                                                                        case 0x28b4:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                                            break;

                                                                        case 0x28b5:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                                            break;

                                                                        case 0x28b6:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                                            break;

                                                                        case 0x28b7:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                                            break;

                                                                        case 0x28b8:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                                            break;

                                                                        case 0x2bc0:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                                            break;

                                                                        case 0x289b:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                            break;

                                                                        case 0x28aa:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                                            break;
                                                                    }
                                                                    StatusIconData data2 = new StatusIconData
                                                                    {
                                                                        AuraLevel = spell.Level,
                                                                        AuraPower = spell.Power,
                                                                        AuraType2 = tyrantAura2,
                                                                        Identifier = c.Entity.UID,
                                                                        Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                                    };
                                                                    c.Entity.Owner.Send((byte[])data2);
                                                                }
                                                            }
                                                        }

                                                    }
                                                }
                                                if (!attacked.Owner.AlternateEquipment)
                                                {
                                                    attacked.Owner.LoadItemStats(attacked.Owner.Entity);
                                                }
                                                else
                                                {
                                                    attacked.Owner.LoadItemStats2(attacked.Owner.Entity);
                                                }
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                attacker.Owner.SendScreen(suse, true);
                                                attacked.AuraStamp = Time32.Now;
                                                attacked.AuraTime = 20;
                                                attacked.SkillCStrike += 10;
                                                attacked.CriticalStrike += 10;
                                                // attacked.MaxAttack += 100;
                                                attacked.RemoveFlag2(Update.Flags2.TyrantAura);
                                                attacked.RemoveFlag2(Update.Flags2.MetalAura);
                                                attacked.RemoveFlag2(Update.Flags2.WoodAura);
                                                attacked.RemoveFlag2(Update.Flags2.WaterAura);
                                                attacked.RemoveFlag2(Update.Flags2.EarthAura);
                                                attacked.RemoveFlag2(Update.Flags2.FireAura);
                                                attacked.AddFlag2(Update.Flags2.FendAura);
                                                PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                switch (spell.ID)
                                                {
                                                    case 0x28b4:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                        break;

                                                    case 0x28b5:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                        break;

                                                    case 0x28b6:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                        break;

                                                    case 0x28b7:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                        break;

                                                    case 0x28b8:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                        break;

                                                    case 0x2bc0:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                        break;

                                                    case 0x289b:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                        break;

                                                    case 0x28aa:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                        break;
                                                }
                                                StatusIconData data = new StatusIconData
                                                {
                                                    AuraLevel = spell.Level,
                                                    AuraPower = spell.Power,
                                                    AuraType2 = tyrantAura,
                                                    Identifier = attacker.UID,
                                                    Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                };
                                                attacker.Owner.Send((byte[])data);
                                                //Update ud = new Update(true);
                                                //ud.Aura(attacked, attacked.SkillCStrike, spell.Level, (byte)spell.Duration);
                                            }
                                            break;
                                        }
                                    case 10420:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);
                                                if (attacker.Owner.Team != null)
                                                {
                                                    foreach (Client.GameState c in attacker.Owner.Team.Teammates)
                                                    {
                                                        if (c.Entity.MapID == attacker.MapID)
                                                        {
                                                            short distance = Kernel.GetDistance(c.Entity.X, c.Entity.Y, attacker.X, attacker.Y);
                                                            if (distance < ServerBase.Constants.pScreenDistance)
                                                            {
                                                                if (c.Entity.UID != attacker.UID)
                                                                {
                                                                    if (!c.AlternateEquipment)
                                                                    {
                                                                        c.LoadItemStats(c.Entity);
                                                                    }
                                                                    else
                                                                    {
                                                                        c.LoadItemStats2(c.Entity);
                                                                    }

                                                                    c.Entity.AuraStamp = Time32.Now;
                                                                    c.Entity.AuraTime = 20;
                                                                    c.Entity.MetalResistance += 30;
                                                                    c.Entity.RemoveFlag2(Update.Flags2.TyrantAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FendAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WoodAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WaterAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.EarthAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FireAura);
                                                                    c.Entity.AddFlag2(Update.Flags2.MetalAura);
                                                                    PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                    switch (spell.ID)
                                                                    {
                                                                        case 0x28b4:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                                            break;

                                                                        case 0x28b5:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                                            break;

                                                                        case 0x28b6:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                                            break;

                                                                        case 0x28b7:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                                            break;

                                                                        case 0x28b8:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                                            break;

                                                                        case 0x2bc0:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                                            break;

                                                                        case 0x289b:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                            break;

                                                                        case 0x28aa:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                                            break;
                                                                    }
                                                                    StatusIconData data2 = new StatusIconData
                                                                    {
                                                                        AuraLevel = spell.Level,
                                                                        AuraPower = spell.Power,
                                                                        AuraType2 = tyrantAura2,
                                                                        Identifier = c.Entity.UID,
                                                                        Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                                    };
                                                                    c.Entity.Owner.Send((byte[])data2);
                                                                }
                                                            }
                                                        }

                                                    }
                                                }
                                                if (!attacked.Owner.AlternateEquipment)
                                                {
                                                    attacked.Owner.LoadItemStats(attacked.Owner.Entity);
                                                }
                                                else
                                                {
                                                    attacked.Owner.LoadItemStats2(attacked.Owner.Entity);
                                                }
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                attacker.Owner.SendScreen(suse, true);
                                                attacked.AuraStamp = Time32.Now;
                                                attacked.AuraTime = 20;
                                                attacked.MetalResistance += 30;
                                                attacked.RemoveFlag2(Update.Flags2.TyrantAura);
                                                attacked.RemoveFlag2(Update.Flags2.FendAura);
                                                attacked.RemoveFlag2(Update.Flags2.WoodAura);
                                                attacked.RemoveFlag2(Update.Flags2.WaterAura);
                                                attacked.RemoveFlag2(Update.Flags2.EarthAura);
                                                attacked.RemoveFlag2(Update.Flags2.FireAura);
                                                attacked.AddFlag2(Update.Flags2.MetalAura);
                                                PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                switch (spell.ID)
                                                {
                                                    case 0x28b4:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                        break;

                                                    case 0x28b5:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                        break;

                                                    case 0x28b6:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                        break;

                                                    case 0x28b7:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                        break;

                                                    case 0x28b8:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                        break;

                                                    case 0x2bc0:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                        break;

                                                    case 0x289b:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                        break;

                                                    case 0x28aa:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                        break;
                                                }
                                                StatusIconData data = new StatusIconData
                                                {
                                                    AuraLevel = spell.Level,
                                                    AuraPower = spell.Power,
                                                    AuraType2 = tyrantAura,
                                                    Identifier = attacker.UID,
                                                    Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                };
                                                attacker.Owner.Send((byte[])data);
                                            }
                                            //Update ud = new Update(true);
                                            //ud.Aura(attacked, attacked.MetalResistance, spell.Level, (byte)spell.Duration);
                                            break;
                                        }
                                    case 10421:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);
                                                if (attacker.Owner.Team != null)
                                                {
                                                    foreach (Client.GameState c in attacker.Owner.Team.Teammates)
                                                    {
                                                        if (c.Entity.MapID == attacker.MapID)
                                                        {
                                                            short distance = Kernel.GetDistance(c.Entity.X, c.Entity.Y, attacker.X, attacker.Y);
                                                            if (distance < ServerBase.Constants.pScreenDistance)
                                                            {
                                                                if (c.Entity.UID != attacker.UID)
                                                                {
                                                                    if (!c.AlternateEquipment)
                                                                    {
                                                                        c.LoadItemStats(c.Entity);
                                                                    }
                                                                    else
                                                                    {
                                                                        c.LoadItemStats2(c.Entity);
                                                                    }

                                                                    c.Entity.AuraStamp = Time32.Now;
                                                                    c.Entity.AuraTime = 20;
                                                                    c.Entity.WoodResistance += 30;
                                                                    c.Entity.RemoveFlag2(Update.Flags2.TyrantAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FendAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.MetalAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WaterAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.EarthAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FireAura);
                                                                    c.Entity.AddFlag2(Update.Flags2.WoodAura);
                                                                    PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                    switch (spell.ID)
                                                                    {
                                                                        case 0x28b4:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                                            break;

                                                                        case 0x28b5:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                                            break;

                                                                        case 0x28b6:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                                            break;

                                                                        case 0x28b7:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                                            break;

                                                                        case 0x28b8:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                                            break;

                                                                        case 0x2bc0:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                                            break;

                                                                        case 0x289b:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                            break;

                                                                        case 0x28aa:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                                            break;
                                                                    }
                                                                    StatusIconData data2 = new StatusIconData
                                                                    {
                                                                        AuraLevel = spell.Level,
                                                                        AuraPower = spell.Power,
                                                                        AuraType2 = tyrantAura2,
                                                                        Identifier = c.Entity.UID,
                                                                        Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                                    };
                                                                    c.Entity.Owner.Send((byte[])data2);
                                                                }
                                                            }
                                                        }

                                                    }
                                                }
                                                if (!attacked.Owner.AlternateEquipment)
                                                {
                                                    attacked.Owner.LoadItemStats(attacked.Owner.Entity);
                                                }
                                                else
                                                {
                                                    attacked.Owner.LoadItemStats2(attacked.Owner.Entity);
                                                }
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                attacker.Owner.SendScreen(suse, true);
                                                attacked.AuraStamp = Time32.Now;
                                                attacked.AuraTime = 20;
                                                attacked.WoodResistance += 30;
                                                attacked.RemoveFlag2(Update.Flags2.TyrantAura);
                                                attacked.RemoveFlag2(Update.Flags2.FendAura);
                                                attacked.RemoveFlag2(Update.Flags2.MetalAura);
                                                attacked.RemoveFlag2(Update.Flags2.WaterAura);
                                                attacked.RemoveFlag2(Update.Flags2.EarthAura);
                                                attacked.RemoveFlag2(Update.Flags2.FireAura);
                                                attacked.AddFlag2(Update.Flags2.WoodAura);
                                                PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                switch (spell.ID)
                                                {
                                                    case 0x28b4:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                        break;

                                                    case 0x28b5:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                        break;

                                                    case 0x28b6:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                        break;

                                                    case 0x28b7:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                        break;

                                                    case 0x28b8:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                        break;

                                                    case 0x2bc0:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                        break;

                                                    case 0x289b:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                        break;

                                                    case 0x28aa:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                        break;
                                                }
                                                StatusIconData data = new StatusIconData
                                                {
                                                    AuraLevel = spell.Level,
                                                    AuraPower = spell.Power,
                                                    AuraType2 = tyrantAura,
                                                    Identifier = attacker.UID,
                                                    Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                };
                                                attacker.Owner.Send((byte[])data);
                                                //Update ud = new Update(true);
                                            }
                                            //ud.Aura(attacked, attacked.WoodResistance, spell.Level, (byte)spell.Duration);
                                            break;
                                        }
                                    case 10422:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);
                                                if (attacker.Owner.Team != null)
                                                {
                                                    foreach (Client.GameState c in attacker.Owner.Team.Teammates)
                                                    {
                                                        if (c.Entity.MapID == attacker.MapID)
                                                        {
                                                            short distance = Kernel.GetDistance(c.Entity.X, c.Entity.Y, attacker.X, attacker.Y);
                                                            if (distance < ServerBase.Constants.pScreenDistance)
                                                            {
                                                                if (c.Entity.UID != attacker.UID)
                                                                {
                                                                    if (!c.AlternateEquipment)
                                                                    {
                                                                        c.LoadItemStats(c.Entity);
                                                                    }
                                                                    else
                                                                    {
                                                                        c.LoadItemStats2(c.Entity);
                                                                    }

                                                                    c.Entity.AuraStamp = Time32.Now;
                                                                    c.Entity.AuraTime = 20;
                                                                    c.Entity.WaterResistance += 30;
                                                                    c.Entity.RemoveFlag2(Update.Flags2.TyrantAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FendAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.MetalAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WoodAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.EarthAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FireAura);
                                                                    c.Entity.AddFlag2(Update.Flags2.WaterAura);
                                                                    PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                    switch (spell.ID)
                                                                    {
                                                                        case 0x28b4:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                                            break;

                                                                        case 0x28b5:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                                            break;

                                                                        case 0x28b6:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                                            break;

                                                                        case 0x28b7:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                                            break;

                                                                        case 0x28b8:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                                            break;

                                                                        case 0x2bc0:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                                            break;

                                                                        case 0x289b:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                            break;

                                                                        case 0x28aa:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                                            break;
                                                                    }
                                                                    StatusIconData data2 = new StatusIconData
                                                                    {
                                                                        AuraLevel = spell.Level,
                                                                        AuraPower = spell.Power,
                                                                        AuraType2 = tyrantAura2,
                                                                        Identifier = c.Entity.UID,
                                                                        Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                                    };
                                                                    c.Entity.Owner.Send((byte[])data2);
                                                                }
                                                            }
                                                        }

                                                    }
                                                }
                                                if (!attacked.Owner.AlternateEquipment)
                                                {
                                                    attacked.Owner.LoadItemStats(attacked.Owner.Entity);
                                                }
                                                else
                                                {
                                                    attacked.Owner.LoadItemStats2(attacked.Owner.Entity);
                                                }
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                attacker.Owner.SendScreen(suse, true);
                                                attacked.AuraStamp = Time32.Now;
                                                attacked.AuraTime = 20;
                                                attacked.WaterResistance += 30;
                                                attacked.RemoveFlag2(Update.Flags2.TyrantAura);
                                                attacked.RemoveFlag2(Update.Flags2.FendAura);
                                                attacked.RemoveFlag2(Update.Flags2.MetalAura);
                                                attacked.RemoveFlag2(Update.Flags2.WoodAura);
                                                attacked.RemoveFlag2(Update.Flags2.EarthAura);
                                                attacked.RemoveFlag2(Update.Flags2.FireAura);
                                                attacked.AddFlag2(Update.Flags2.WaterAura);
                                                PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                switch (spell.ID)
                                                {
                                                    case 0x28b4:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                        break;

                                                    case 0x28b5:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                        break;

                                                    case 0x28b6:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                        break;

                                                    case 0x28b7:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                        break;

                                                    case 0x28b8:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                        break;

                                                    case 0x2bc0:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                        break;

                                                    case 0x289b:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                        break;

                                                    case 0x28aa:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                        break;
                                                }
                                                StatusIconData data = new StatusIconData
                                                {
                                                    AuraLevel = spell.Level,
                                                    AuraPower = spell.Power,
                                                    AuraType2 = tyrantAura,
                                                    Identifier = attacker.UID,
                                                    Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                };
                                                attacker.Owner.Send((byte[])data);
                                                //Update ud = new Update(true);
                                            }
                                            //ud.Aura(attacked, attacked.WaterResistance, spell.Level, (byte)spell.Duration);
                                            break;
                                        }

                                    case 10424:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);
                                                if (attacker.Owner.Team != null)
                                                {
                                                    foreach (Client.GameState c in attacker.Owner.Team.Teammates)
                                                    {
                                                        if (c.Entity.MapID == attacker.MapID)
                                                        {
                                                            short distance = Kernel.GetDistance(c.Entity.X, c.Entity.Y, attacker.X, attacker.Y);
                                                            if (distance < ServerBase.Constants.pScreenDistance)
                                                            {
                                                                if (c.Entity.UID != attacker.UID)
                                                                {
                                                                    if (!c.AlternateEquipment)
                                                                    {
                                                                        c.LoadItemStats(c.Entity);
                                                                    }
                                                                    else
                                                                    {
                                                                        c.LoadItemStats2(c.Entity);
                                                                    }

                                                                    c.Entity.AuraStamp = Time32.Now;
                                                                    c.Entity.AuraTime = 20;
                                                                    c.Entity.EarthResistance += 30;
                                                                    c.Entity.RemoveFlag2(Update.Flags2.TyrantAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FendAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.MetalAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WoodAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WaterAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FireAura);
                                                                    c.Entity.AddFlag2(Update.Flags2.EarthAura);
                                                                    PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                    switch (spell.ID)
                                                                    {
                                                                        case 0x28b4:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                                            break;

                                                                        case 0x28b5:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                                            break;

                                                                        case 0x28b6:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                                            break;

                                                                        case 0x28b7:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                                            break;

                                                                        case 0x28b8:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                                            break;

                                                                        case 0x2bc0:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                                            break;

                                                                        case 0x289b:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                            break;

                                                                        case 0x28aa:
                                                                            tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                                            break;
                                                                    }
                                                                    StatusIconData data2 = new StatusIconData
                                                                    {
                                                                        AuraLevel = spell.Level,
                                                                        AuraPower = spell.Power,
                                                                        AuraType2 = tyrantAura,
                                                                        Identifier = c.Entity.UID,
                                                                        Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                                    };
                                                                    c.Entity.Owner.Send((byte[])data2);

                                                                }
                                                            }
                                                        }

                                                    }
                                                }
                                                if (!attacked.Owner.AlternateEquipment)
                                                {
                                                    attacked.Owner.LoadItemStats(attacked.Owner.Entity);
                                                }
                                                else
                                                {
                                                    attacked.Owner.LoadItemStats2(attacked.Owner.Entity);
                                                }
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                attacker.Owner.SendScreen(suse, true);
                                                attacked.AuraStamp = Time32.Now;
                                                attacked.AuraTime = 20;
                                                attacked.EarthResistance += 30;
                                                attacked.RemoveFlag2(Update.Flags2.TyrantAura);
                                                attacked.RemoveFlag2(Update.Flags2.FendAura);
                                                attacked.RemoveFlag2(Update.Flags2.MetalAura);
                                                attacked.RemoveFlag2(Update.Flags2.WoodAura);
                                                attacked.RemoveFlag2(Update.Flags2.WaterAura);
                                                attacked.RemoveFlag2(Update.Flags2.FireAura);
                                                attacked.AddFlag2(Update.Flags2.EarthAura);
                                                PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                switch (spell.ID)
                                                {
                                                    case 0x28b4:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                        break;

                                                    case 0x28b5:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                        break;

                                                    case 0x28b6:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                        break;

                                                    case 0x28b7:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                        break;

                                                    case 0x28b8:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                        break;

                                                    case 0x2bc0:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                        break;

                                                    case 0x289b:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                        break;

                                                    case 0x28aa:
                                                        tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                        break;
                                                }
                                                StatusIconData data = new StatusIconData
                                                {
                                                    AuraLevel = spell.Level,
                                                    AuraPower = spell.Power,
                                                    AuraType2 = tyrantAura2,
                                                    Identifier = attacker.UID,
                                                    Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                };
                                                attacker.Owner.Send((byte[])data);
                                                //Update ud = new Update(true);
                                            }
                                            ///ud.Aura(attacked, attacked.EarthResistance, spell.Level, (byte)spell.Duration);
                                            break;
                                        }
                                    case 10423:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);
                                                if (attacker.Owner.Team != null)
                                                {
                                                    foreach (Client.GameState c in attacker.Owner.Team.Teammates)
                                                    {
                                                        if (c.Entity.MapID == attacker.MapID)
                                                        {
                                                            short distance = Kernel.GetDistance(c.Entity.X, c.Entity.Y, attacker.X, attacker.Y);
                                                            if (distance < ServerBase.Constants.pScreenDistance)
                                                            {
                                                                if (c.Entity.UID != attacker.UID)
                                                                {
                                                                    if (!c.AlternateEquipment)
                                                                    {
                                                                        c.LoadItemStats(c.Entity);
                                                                    }
                                                                    else
                                                                    {
                                                                        c.LoadItemStats2(c.Entity);
                                                                    }

                                                                    c.Entity.AuraStamp = Time32.Now;
                                                                    c.Entity.AuraTime = 20;
                                                                    c.Entity.FireResistance += 30;
                                                                    c.Entity.RemoveFlag2(Update.Flags2.TyrantAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.FendAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.MetalAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WoodAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.WaterAura);
                                                                    c.Entity.RemoveFlag2(Update.Flags2.EarthAura);
                                                                    c.Entity.AddFlag2(Update.Flags2.FireAura);
                                                                    PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                    switch (spell.ID)
                                                                    {
                                                                        case 0x28b4:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                                            break;

                                                                        case 0x28b5:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                                            break;

                                                                        case 0x28b6:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                                            break;

                                                                        case 0x28b7:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                                            break;

                                                                        case 0x28b8:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                                            break;

                                                                        case 0x2bc0:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                                            break;

                                                                        case 0x289b:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                                            break;

                                                                        case 0x28aa:
                                                                            tyrantAura2 = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                                            break;
                                                                    }
                                                                    StatusIconData data2 = new StatusIconData
                                                                    {
                                                                        AuraLevel = spell.Level,
                                                                        AuraPower = spell.Power,
                                                                        AuraType2 = tyrantAura2,
                                                                        Identifier = c.Entity.UID,
                                                                        Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                                    };
                                                                    c.Entity.Owner.Send((byte[])data2);

                                                                }
                                                            }
                                                        }

                                                    }
                                                }
                                                if (!attacked.Owner.AlternateEquipment)
                                                {
                                                    attacked.Owner.LoadItemStats(attacked.Owner.Entity);
                                                }
                                                else
                                                {
                                                    attacked.Owner.LoadItemStats2(attacked.Owner.Entity);
                                                }
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;
                                                attacker.Owner.SendScreen(suse, true);
                                                attacked.AuraStamp = Time32.Now;
                                                attacked.AuraTime = 20;
                                                attacked.FireResistance += 30;
                                                attacked.RemoveFlag2(Update.Flags2.TyrantAura);
                                                attacked.RemoveFlag2(Update.Flags2.FendAura);
                                                attacked.RemoveFlag2(Update.Flags2.MetalAura);
                                                attacked.RemoveFlag2(Update.Flags2.WoodAura);
                                                attacked.RemoveFlag2(Update.Flags2.WaterAura);
                                                attacked.RemoveFlag2(Update.Flags2.EarthAura);
                                                attacked.AddFlag2(Update.Flags2.FireAura);
                                                PhoenixProject.Network.GamePackets.StatusIconData.AuraType tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                switch (spell.ID)
                                                {
                                                    case 0x28b4:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MetalAura;
                                                        break;

                                                    case 0x28b5:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WoodAura;
                                                        break;

                                                    case 0x28b6:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.WaterAura;
                                                        break;

                                                    case 0x28b7:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FireAura;
                                                        break;

                                                    case 0x28b8:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.EarthAura;
                                                        break;

                                                    case 0x2bc0:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.MagicDefender;
                                                        break;

                                                    case 0x289b:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.TyrantAura;
                                                        break;

                                                    case 0x28aa:
                                                        tyrantAura = PhoenixProject.Network.GamePackets.StatusIconData.AuraType.FendAura;
                                                        break;
                                                }
                                                StatusIconData data = new StatusIconData
                                                {
                                                    AuraLevel = spell.Level,
                                                    AuraPower = spell.Power,
                                                    AuraType2 = tyrantAura,
                                                    Identifier = attacker.UID,
                                                    Type = PhoenixProject.Network.GamePackets.StatusIconData.AuraDataTypes.Add
                                                };
                                                attacker.Owner.Send((byte[])data);
                                            }
                                            // Update ud = new Update(true);
                                            // ud.Aura(attacked, attacked.FireResistance, spell.Level, (byte)spell.Duration);
                                            break;
                                        }
                                    case 10430:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = spell.ID;
                                                suse.SpellLevel = spell.Level;
                                                suse.X = X;
                                                suse.Y = Y;

                                                if (attacker.Owner.Team != null)
                                                {
                                                    PrepareSpell(spell, attacker.Owner);
                                                    foreach (Client.GameState teammate in attacker.Owner.Team.Teammates)
                                                    {
                                                        if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, teammate.Entity.X, teammate.Entity.Y) <= spell.Distance)
                                                        {
                                                            attacker.RemoveFlag(Update.Flags.Poisoned);

                                                            suse.Targets.Add(teammate.Entity.UID, 1);
                                                        }
                                                    }
                                                    if (attacked.EntityFlag == EntityFlag.Player)
                                                        attacked.Owner.SendScreen(suse, true);
                                                    else
                                                        attacked.MonsterInfo.SendScreen(suse);
                                                }
                                                else
                                                {
                                                    if (attacked == null)
                                                        return;
                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Distance)
                                                    {
                                                        PrepareSpell(spell, attacker.Owner);

                                                        attacker.RemoveFlag(Update.Flags.Poisoned);

                                                        suse.Targets.Add(attacked.UID, 1);

                                                        if (attacked.EntityFlag == EntityFlag.Player)
                                                            attacked.Owner.SendScreen(suse, true);
                                                        else
                                                            attacked.MonsterInfo.SendScreen(suse);
                                                    }
                                                    else
                                                    {
                                                        attacker.AttackPacket = null;
                                                    }
                                                }
                                            }
                                            attacker.AttackPacket = null;
                                            break;
                                        }
                                    //Serenity
                                    case 10400:
                                        {
                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                if (attacker == null) return;

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = SpellID;
                                                suse.SpellLevel = attacker.Owner.Spells[SpellID].Level;
                                                suse.X = X;
                                                suse.Y = Y;

                                                suse.Targets.Add(attacker.UID, 1);

                                                attacker.ToxicFogLeft = 0;
                                                attacker.NoDrugsTime = 0;
                                                attacker.RemoveFlag2(Update.Flags2.SoulShackle);
                                                SyncPacket packet3 = new SyncPacket
                                                {
                                                    Identifier = attacked.UID,
                                                    Count = 2,
                                                    Type = PhoenixProject.Network.GamePackets.SyncPacket.SyncType.StatusFlag,
                                                    StatusFlag1 = (ulong)attacked.StatusFlag,
                                                    StatusFlag2 = (ulong)attacked.StatusFlag2,
                                                    Unknown1 = 0x36,
                                                    StatusFlagOffset = 0x6f,
                                                    Time = 0,
                                                    Value = 0,
                                                    Level = spell.Level
                                                };
                                                attacked.Owner.Send((byte[])packet3);
                                                attacker.Owner.SendScreen(suse, true);
                                            }
                                            attacker.AttackPacket = null;
                                            break;
                                        }
                                    //Tranquility
                                    case 10425:
                                        {
                                            if (attacked == null) return;

                                            if (CanUseSpell(spell, attacker.Owner))
                                            {
                                                PrepareSpell(spell, attacker.Owner);

                                                if (attacked == null) return;

                                                SpellUse suse = new SpellUse(true);
                                                suse.Attacker = attacker.UID;
                                                suse.SpellID = SpellID;
                                                suse.SpellLevel = attacker.Owner.Spells[SpellID].Level;
                                                suse.X = X;
                                                suse.Y = Y;


                                                suse.Targets.Add(attacked.UID, 1);

                                                attacked.ToxicFogLeft = 0;
                                                attacked.ShackleTime = 0;
                                                attacked.NoDrugsTime = 0;
                                                attacked.RemoveFlag2(Update.Flags2.SoulShackle);
                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                {
                                                    SyncPacket packet3 = new SyncPacket
                                                    {
                                                        Identifier = attacked.UID,
                                                        Count = 2,
                                                        Type = PhoenixProject.Network.GamePackets.SyncPacket.SyncType.StatusFlag,
                                                        StatusFlag1 = (ulong)attacked.StatusFlag,
                                                        StatusFlag2 = (ulong)attacked.StatusFlag2,
                                                        Unknown1 = 0x36,
                                                        StatusFlagOffset = 0x6f,
                                                        Time = 0,
                                                        Value = 0,
                                                        Level = spell.Level
                                                    };
                                                    attacked.Owner.Send((byte[])packet3);
                                                }
                                                if (attacked.EntityFlag == EntityFlag.Player)
                                                    attacked.Owner.SendScreen(suse, true);
                                                else
                                                    attacked.MonsterInfo.SendScreen(suse);
                                            }
                                            attacker.AttackPacket = null;
                                            break;
                                        }

                                    //WhirlwindKick
                                    case 10415:
                                        {
                                            if (Time32.Now < attacker.WhilrwindKick.AddMilliseconds(1200))
                                            { attacker.AttackPacket = null; return; }
                                            attacker.WhilrwindKick = Time32.Now;
                                            if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= 3)
                                            {
                                                if (CanUseSpell(spell, attacker.Owner))
                                                {
                                                    PrepareSpell(spell, attacker.Owner);

                                                    SpellUse suse = new SpellUse(true);
                                                    suse.Attacker = attacker.UID;
                                                    suse.SpellID = spell.ID;
                                                    suse.SpellLevel = 0;
                                                    suse.X = (ushort)ServerBase.Kernel.Random.Next(3, 10);
                                                    suse.Y = 0;

                                                    if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, X, Y) <= 3)
                                                    {
                                                        for (int c = 0; c < attacker.Owner.Screen.Objects.Count; c++)
                                                        {
                                                            //For a multi threaded application, while we go through the collection
                                                            //the collection might change. We will make sure that we wont go off  
                                                            //the limits with a check.
                                                            if (c >= attacker.Owner.Screen.Objects.Count)
                                                                break;
                                                            Interfaces.IMapObject _obj = attacker.Owner.Screen.Objects[c];
                                                            if (_obj == null)
                                                                continue;
                                                            if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
                                                            {
                                                                attacked = _obj as Entity;
                                                                if (ServerBase.Kernel.GetDistance(attacker.X, attacker.Y, attacked.X, attacked.Y) <= spell.Range)
                                                                {
                                                                    if (CanAttack(attacker, attacked, spell, attack.AttackType == Attack.Ranged))
                                                                    {
                                                                        uint damage = Game.Attacking.Calculate.Melee(attacker, attacked, spell, ref attack);

                                                                        suse.Effect1 = attack.Effect1;
                                                                        ReceiveAttack(attacker, attacked, attack, damage, spell);
                                                                        attacked.Stunned = true;
                                                                        attacked.StunStamp = Time32.Now;
                                                                        suse.Targets.Add(attacked.UID, damage);

                                                                    }
                                                                }
                                                            }
                                                        }
                                                        attacker.AttackPacket = null;
                                                    }
                                                    else
                                                    {
                                                        attacker.AttackPacket = null; return;
                                                    }
                                                    attacker.Owner.SendScreen(suse, true);
                                                    suse.Targets = new SafeDictionary<uint, SpellUse.DamageClass>();
                                                    attacker.AttackPacket = null; return;
                                                }
                                                attacker.AttackPacket = null;
                                            }
                                            attacker.AttackPacket = null; return;
                                        }
                                    #endregion
                                    default:
                                        if (attacker.Owner.Account.State == PhoenixProject.Database.AccountTable.AccountState.ProjectManager)
                                            attacker.Owner.Send(new Message("Unknown spell id: " + spell.ID, System.Drawing.Color.CadetBlue, Message.Talk));
                                        break;

                                }

                                if (spell.CanKill == 0)
                                {
                                    attacker.Owner.IncreaseSpellExperience(80, spellID);
                                }
                                //  attacker.Owner.IncreaseSpellExperience(Experience, spellID);//kimo
                                if (attacker.MapID == 1039)
                                {
                                    if (spell.ID == 7001 || spell.ID == 9876)
                                    {
                                        attacker.AttackPacket = null;
                                        return;
                                    }
                                    if (attacker.AttackPacket != null)
                                    {
                                        attack.Damage = spell.ID;
                                        attacker.AttackPacket = attack;
                                        if (Database.SpellTable.WeaponSpells.ContainsValue(spell.ID))
                                        {
                                            if (attacker.AttackPacket == null)
                                            {
                                                attack.AttackType = Attack.Melee;
                                                attacker.AttackPacket = attack;
                                            }
                                            else
                                            {
                                                attacker.AttackPacket.AttackType = Attack.Melee;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (spell.NextSpellID != 0)
                                    {
                                        if (spell.NextSpellID >= 1000 && spell.NextSpellID <= 1002)
                                            if (Target >= 1000000)
                                            {
                                                attacker.AttackPacket = null;
                                                return;
                                            }
                                        attack.Damage = spell.NextSpellID;
                                        attacker.AttackPacket = attack;
                                    }
                                    else
                                    {
                                        if (!Database.SpellTable.WeaponSpells.ContainsValue(spell.ID) || spell.ID == 9876)
                                            attacker.AttackPacket = null;
                                        else
                                        {
                                            if (attacker.AttackPacket == null)
                                            {
                                                attack.AttackType = Attack.Melee;
                                                attacker.AttackPacket = attack;
                                            }
                                            else
                                            {
                                                attacker.AttackPacket.AttackType = Attack.Melee;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                attacker.AttackPacket = null;
                            }
                        }
                    #endregion


                    }

                #endregion

                }
            #endregion
            }
        }