public static void SkillTeamRes(Client.GameState client)
 {
     string[] scores = new string[3];
     scores[0] = "SkillTeam PkWar:";
     scores[1] = "Red Team: " + RKills + " Score";
     scores[2] = "Yellow Team: " + YKills + " Score";
        // scores[3] = "Red   Team: " + Game.ConquerStructures.TeamDeathMatchScore.RedTeamScore + " Score";
     //scores[4] = "Your Score: " + Entity.TeamDeathMatch_Kills + " kills";
     for (int i = 0; i < scores.Length; i++)
     {
         Message msg = new Message(scores[i], System.Drawing.Color.Red, i == 0 ? Message.FirstRightCorner : Message.ContinueRightCorner);
         client.Send(msg);
     }
 }
        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);
            }
        }
        public static bool CheckCommand2(Message message, Client.GameState client)
        {
            try
            {
                if (message.__Message.StartsWith("@"))
                {
                    string Message = message.__Message.Substring(1).ToLower();
                    string Mess = message.__Message.Substring(1);
                    string[] Data = Message.Split(' ');

                    return true;
                }
                return false;
            }
            catch { client.Send(new Message("Impossible to handle this command", System.Drawing.Color.BurlyWood, Message.TopLeft)); return false; }
        }
        static bool CheckCommand(Message message, Client.GameState client)
        {
            try
            {
                if (message.__Message.StartsWith("@"))
                {
                    string Message = message.__Message.Substring(1).ToLower();
                    string Mess = message.__Message.Substring(1);
                    string[] Data = Message.Split(' ');
                    #region GMs PMs
                    if (client.Account.State == PhoenixProject.Database.AccountTable.AccountState.ProjectManager || client.Account.State == PhoenixProject.Database.AccountTable.AccountState.Coder)
                    {
                        switch (Data[0])
                        {

                            case "addcps":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            if (!Game.PrizeNPC.PrizeNpcInformations.ContainsKey(pClient.Entity.UID))
                                            {
                                                PhoenixProject.Game.PrizeNPC.PrizeNpcInfo info = new PhoenixProject.Game.PrizeNPC.PrizeNpcInfo();
                                                info.Owner = pClient.Entity.UID;
                                                info.type = 1;
                                                info.amount = uint.Parse(Data[2]);
                                                info.itemid = 0;
                                                PhoenixProject.Game.PrizeNPC.PrizeNpcInformations.Add(info.Owner, info);
                                                PhoenixProject.Database.MySqlCommand cmd = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.INSERT);
                                                cmd.Insert("prizenpc").Insert("Owner", client.Entity.UID).Insert("type", info.type).Insert("Amount", info.amount).Insert("itemid", info.itemid);
                                                cmd.Execute();
                                                Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Congratulation you have got an Donation Prize " + info.amount + " Cps go to PrizeNpc to Claim It?");
                                                npc.OptionID = 255;
                                                pClient.Send(npc.ToArray());

                                                Network.GamePackets.NpcReply npc2 = new Network.GamePackets.NpcReply(6, "" + pClient.Entity.Name + " has Recived " + info.amount + " Cps");
                                                npc2.OptionID = 255;
                                                client.Send(npc2.ToArray());

                                                Console.WriteLine("" + pClient.Entity.Name + " has got Donation Prize Cps " + info.amount + "");
                                            }
                                            else
                                            {
                                                Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Sorry the player already have prize not claimed yet");
                                                npc.OptionID = 255;
                                                client.Send(npc.ToArray());
                                            }
                                        }
                                    }
                                    break;
                                }
                            case "who":
                                {
                                    var varr = ServerBase.Kernel.GamePool.Values.GetEnumerator();
                                    varr.MoveNext();
                                    int COunt = ServerBase.Kernel.GamePool.Count;
                                    for (uint x = 0;
                                        x < COunt;
                                        x++)
                                    {
                                        if (x >= COunt) break;

                                        Client.GameState pClient = (varr.Current as Client.GameState);

                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            client.Send(new Message("[Whois " + pClient.Entity.Name + "]", System.Drawing.Color.Gold, GamePackets.Message.FirstRightCorner));
                                            client.Send(new Message("Username: "******"Password: "******"IP: " + pClient.Account.IP, System.Drawing.Color.Gold, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("CPs: " + pClient.Entity.ConquerPoints, System.Drawing.Color.Gold, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Money: " + pClient.Entity.Money, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Class: " + pClient.Entity.Class, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("UID: " + pClient.Entity.UID, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Level: " + pClient.Entity.Level, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Strength: " + pClient.Entity.Strength, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Agility: " + pClient.Entity.Agility, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Vitality: " + pClient.Entity.Vitality, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Spirit: " + pClient.Entity.Spirit, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Atributes: " + pClient.Entity.Atributes, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Hitpoints: " + pClient.Entity.Hitpoints, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("PKPoints: " + pClient.Entity.PKPoints, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("VIPLevel: " + pClient.Entity.VIPLevel, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                            client.Send(new Message("Map: [" + pClient.Entity.MapID + "] " + pClient.Entity.X + "," + pClient.Entity.Y, System.Drawing.Color.Green, GamePackets.Message.ContinueRightCorner));
                                        }

                                        varr.MoveNext();
                                    }
                                    break;
                                }
                            case "additem":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            if (!Game.PrizeNPC.PrizeNpcInformations.ContainsKey(pClient.Entity.UID))
                                            {
                                                PhoenixProject.Game.PrizeNPC.PrizeNpcInfo info = new PhoenixProject.Game.PrizeNPC.PrizeNpcInfo();
                                                info.Owner = pClient.Entity.UID;
                                                info.type = 2;
                                                info.amount = 0;
                                                info.itemid = uint.Parse(Data[2]);
                                                PhoenixProject.Game.PrizeNPC.PrizeNpcInformations.Add(info.Owner, info);

                                                PhoenixProject.Database.MySqlCommand cmd = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.INSERT);
                                                cmd.Insert("prizenpc").Insert("Owner", client.Entity.UID).Insert("type", info.type).Insert("Amount", info.amount).Insert("itemid", info.itemid);
                                                cmd.Execute();
                                                Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Congratulation you have got an Donation item go to PrizeNpc to Claim It?");
                                                npc.OptionID = 255;
                                                pClient.Send(npc.ToArray());

                                                Network.GamePackets.NpcReply npc2 = new Network.GamePackets.NpcReply(6, "" + pClient.Entity.Name + " has Recived item id: " + info.itemid + "");
                                                npc2.OptionID = 255;
                                                client.Send(npc2.ToArray());
                                                Console.WriteLine("" + pClient.Entity.Name + " has got Donation Prize item " + info.itemid + "");
                                            }
                                            else
                                            {
                                                Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Sorry the player already have prize not claimed yet");
                                                npc.OptionID = 255;
                                                client.Send(npc.ToArray());
                                            }
                                        }
                                    }
                                    break;
                                }
                            case "summon":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            pClient.Entity.Teleport(client.Entity.MapID, client.Entity.X, client.Entity.Y);
                                        }
                                    }
                                    break;
                                }
                            case "scroll":
                                {
                                    if (client.Entity.MapID == 700)
                                        break;
                                    switch (Data[1].ToLower())
                                    {
                                        case "tc": client.Entity.Teleport(1002, 430, 380); break;
                                        case "pc": client.Entity.Teleport(1011, 195, 260); break;
                                        case "ac":
                                        case "am": client.Entity.Teleport(1020, 566, 563); break;
                                        case "dc": client.Entity.Teleport(1000, 500, 645); break;
                                        case "bi": client.Entity.Teleport(1015, 723, 573); break;
                                        case "pka": client.Entity.Teleport(1005, 050, 050); break;
                                        case "ma": client.Entity.Teleport(1036, 211, 196); break;
                                        case "ja": client.Entity.Teleport(6000, 100, 100); break;
                                    }
                                    break;
                                }

                            case "test":
                                {
                                    byte IDs = byte.Parse(Data[1]);
                                    Data data = new Data(true);
                                    data.UID = client.Entity.UID;
                                    data.dwParam = 2;
                                    data.ID = IDs;//157
                                    data.wParam1 = client.Entity.X;
                                    data.wParam2 = client.Entity.Y;
                                    client.Send(data);
                                    break;
                                }
                            case "jar":
                                {
                                    ConquerItem item2 = new ConquerItem(true);
                                    item2.ID = 750000;
                                    //item2.Color =  PhoenixProject.Game.Enums.Color.Blue;
                                    item2.Durability = 0;
                                    item2.MaximDurability = 2;
                                    client.Inventory.Add(item2, PhoenixProject.Game.Enums.ItemUse.CreateAndAdd);
                                    break;
                                }
                            case "id":
                                {

                                    byte[] data = new byte[24 + 8];
                                    Writer.WriteUInt32(24, 0, data);
                                    Writer.WriteUInt32(1010, 2, data);
                                    Writer.WriteUInt32(client.Entity.UID, 4, data);
                                    Writer.WriteUInt32(1, 7, data);
                                    Writer.WriteUInt32(client.Entity.UID, 8, data);
                                    Writer.WriteUInt32(client.Entity.UID, 12, data);
                                    Writer.WriteUInt32(client.Entity.UID, 16, data);
                                    Writer.WriteUInt32(1, 19, data);
                                    Writer.WriteUInt32(7, 20, data);
                                    Writer.WriteUInt32(121, 22, data);

                                    // Writer.WriteUInt32(9828, 12, data);
                                    client.Send(data);
                                    // client.Entity.CountryFlag = uint.Parse(Data[1]);
                                    break;
                                }
                            case "itemeffect":
                                {
                                    Kernel.boundID = int.Parse(Data[1]);
                                    Kernel.boundIDEnd = int.Parse(Data[2]);
                                    break;
                                }
                            case "kiko":
                                {
                                    string[] Strings = new string[2];

                                    Strings[0] = (Data[1]);
                                    Strings[1] = "1";
                                    _String SoundPacket = new _String(true);
                                    SoundPacket.UID = client.Entity.UID;
                                    SoundPacket.Type = 20;
                                    SoundPacket.TextsCount = 2;
                                    SoundPacket.Texts.Add(Strings[0]);
                                    SoundPacket.Texts.Add(Strings[1]);
                                    client.Send(SoundPacket);
                                    break;
                                    //client.Entity.ActualMyTypeFlower = 30010102;
                                    // break;
                                }
                            case "ss":
                                {

                                    byte[] data = new byte[80 + 8];
                                    Writer.WriteUInt32(80, 0, data);
                                    Writer.WriteUInt32(1151, 2, data);
                                    Writer.WriteUInt32(2, 4, data);
                                    Writer.WriteUInt32(1, 8, data);
                                    Writer.WriteUInt32(1, 16, data);
                                    Writer.WriteUInt32(227, 32, data);
                                    Writer.WriteUInt32(client.Entity.UID, 40, data);
                                    Writer.WriteUInt32(client.Entity.UID, 44, data);
                                    Writer.WriteString(client.Entity.Name, 48, data);
                                    Writer.WriteString(client.Entity.Name, 64, data);
                                    client.Send(data);
                                    byte[] data2 = new byte[80 + 8];
                                    Writer.WriteUInt32(80, 0, data2);
                                    Writer.WriteUInt32(1151, 2, data2);
                                    Writer.WriteUInt32(2, 4, data2);
                                    Writer.WriteUInt32(2, 8, data2);
                                    Writer.WriteUInt32(1, 16, data2);
                                    Writer.WriteUInt32(282, 32, data2);
                                    Writer.WriteUInt32(client.Entity.UID, 40, data2);
                                    Writer.WriteUInt32(client.Entity.UID, 44, data2);
                                    Writer.WriteString(client.Entity.Name, 48, data2);
                                    Writer.WriteString(client.Entity.Name, 64, data2);
                                    client.Send(data2);
                                    // client.Send(new Message("Test Channel Mesaage!", System.Drawing.Color.Red, uint.Parse(Data[1])));
                                    //client.Entity.ClanSharedBp = 4;
                                    // Game.KimoCarnaval.Load();
                                    /*NpcInitial initial = new NpcInitial
                                    {
                                        Identifier = 1,
                                        Lookface = (num != 0x2008) ? ((ushort)0x1a) : ((ushort)3),
                                        Mode = PhoenixProject.Network.GamePackets.NpcInitial.NpcModes.Place,
                                        Furniture = num
                                    };
                                    client.Send((byte[])initial);*/
                                    break;
                                }
                            case "600":
                                {
                                    Game.Map Map = ServerBase.Kernel.Maps[client.Entity.MapID];
                                    Network.GamePackets.FloorItem floorItem = new Network.GamePackets.FloorItem(true);

                                    floorItem.MapObjType = Game.MapObjectType.Item;
                                    floorItem.ItemID = uint.Parse(Data[1]);
                                    floorItem.MapID = client.Entity.MapID;

                                    floorItem.X = ushort.Parse(Data[2]);
                                    floorItem.Y = ushort.Parse(Data[3]);
                                    floorItem.Type = 10;
                                    floorItem.OnFloor = Time32.Now.AddHours(24);
                                    floorItem.UID = Network.GamePackets.FloorItem.FloorUID.Next;
                                    while (Map.Npcs.ContainsKey(floorItem.UID))
                                        floorItem.UID = Network.GamePackets.FloorItem.FloorUID.Next;
                                    Map.AddFloorItem(floorItem);
                                    client.SendScreenSpawn(floorItem, true);
                                    client.Effect = true;
                                    /* _String str = new _String(true);
                                     str.UID = client.Entity.UID;
                                     str.TextsCount = 2;
                                     str.Type = _String.Sound;
                                     str.Texts.Add("sound");
                                     str.Texts.Add("gethp.wav");
                                     client.Send(str);*/

                                    // client.Entity.TitlePacket.dwParam2 = (byte)PhoenixProject.Game.Tournaments.top_typ.GoldenRacer;
                                    break;
                                }
                            case "quiz":
                                {
                                    //PhoenixProject.Game.ConquerStructures.QuizShow.Start();
                                    // client.Send(GamePackets.QuizInfo.tempQuestionBuffer());
                                    //Game.ConquerStructures.QuizShow.Start();
                                    Game.ConquerStructures.QuizShow.Start2();
                                    Program.QuizStamp = Time32.Now;
                                    break;
                                }
                            case "me":
                                {
                                    /* MessageTick m = new MessageTick();
                                     m.Identifier = client.Entity.UID;
                                     m.Response = client.Entity.UID;
                                     client.Send(m);*/

                                    MapStatus mbox = new MapStatus();
                                    mbox.BaseID = 1002;
                                    client.Send(mbox);
                                    break;
                                }
                            case "quiz2":
                                {
                                    //PhoenixProject.Game.ConquerStructures.QuizShow.Start();
                                    // client.Send(GamePackets.QuizInfo.tempQuestionBuffer());
                                    //Game.ConquerStructures.QuizShow.Start();
                                    Game.ConquerStructures.QuizShow.Stop();
                                    break;
                                }
                            case "q":
                                {
                                    //PhoenixProject.Game.ConquerStructures.QuizShow.Start();
                                    // client.Send(GamePackets.QuizInfo.tempQuestionBuffer());
                                    //Game.ConquerStructures.QuizShow.Start();
                                    client.Send(GamePackets.QuizInfo.tempQuestionBuffer());
                                    break;
                                }
                            case "team":
                                {
                                    {
                                        Game.KimoSkillWar.Started = true;
                                        Game.KimoSkillWar.SignUP = true;

                                    }
                                    break;
                                }
                            case "geartest":
                                {
                                    //181315 515black
                                    uint UID = 92000;
                                    PhoenixProject.Interfaces.IConquerItem newItem = new PhoenixProject.Network.GamePackets.ConquerItem(true);
                                    newItem.ID = 181825;
                                    newItem.UID = UID;
                                    newItem.Durability = 1000;
                                    newItem.MaximDurability = 1000;
                                    newItem.Position = 9;
                                    //client.Inventory.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                    client.Equipment.Remove(9);
                                    if (client.Equipment.Objects[8] != null)
                                        client.Equipment.Objects[8] = null;
                                    client.Equipment.Add(newItem);
                                    newItem.Mode = PhoenixProject.Game.Enums.ItemMode.Update;
                                    newItem.Send(client);
                                    ClientEquip equips = new ClientEquip();
                                    equips.DoEquips(client);
                                    client.Send(equips);
                                    client.Equipment.UpdateEntityPacket();
                                    break;

                                }
                            case "quarantine":
                                {
                                    //542363
                                    PhoenixProject.Game.ConquerStructures.Quarantine.Started = true;
                                    break;
                                }
                            case "test2":
                                {
                                    client.Entity.RemoveFlag(ulong.Parse(Data[1]));
                                    break;
                                }
                            case "arrest":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            pClient.Entity.Teleport(6004, 30, 74);
                                        }
                                    }
                                    break;
                                }

                            case "pkp":
                                {
                                    client.Entity.PKPoints = ushort.Parse(Data[1]);

                                    break;
                                }
                            case "dropevent":
                                {

                                    Interfaces.IConquerItem Item = null;

                                    #region Get Item
                                    string ItemName = Data[1];
                                    bool SpecialItem = false;
                                    uint SpecialID = 0;
                                    if (ItemName.Contains("cp") || ItemName.Contains("met") || ItemName.Contains("db") || ItemName.Contains("stone") || ItemName.Contains("soul"))
                                    {
                                        if (ItemName.Contains("cp"))
                                            SpecialID = 729911;
                                        else if (ItemName.Contains("db"))
                                            SpecialID = 1088000;
                                        else if (ItemName.Contains("met"))
                                            SpecialID = 1088001;
                                        else if (ItemName.Contains("stone"))
                                            SpecialID = 730008;
                                        else if (ItemName.Contains("Soul"))
                                            SpecialID = 800110;
                                        SpecialItem = true; goto PrepareDrop;
                                    }
                                    if (ItemName.ToLower() == "exp")
                                    {
                                        for (int c = 0; c < client.Screen.Objects.Count; c++)
                                        {
                                            if (c >= client.Screen.Objects.Count)
                                                break;
                                            Interfaces.IMapObject ClientObj = client.Screen.Objects[c];
                                            if (ClientObj != null)
                                            {
                                                if (ClientObj is Game.Entity)
                                                {
                                                    if (ClientObj.MapObjType == PhoenixProject.Game.MapObjectType.Player)
                                                    {
                                                        ClientObj.Owner.IncreaseExperience(ClientObj.Owner.ExpBall, false);
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                    Game.Enums.ItemQuality Quality = Game.Enums.ItemQuality.NormalV3;
                                    if (Data.Length > 2)
                                    {
                                        switch (Data[3].ToLower())
                                        {
                                            case "fixed": Quality = Game.Enums.ItemQuality.Fixed; break;
                                            case "normal": Quality = Game.Enums.ItemQuality.Normal; break;
                                            case "normalv1": Quality = Game.Enums.ItemQuality.NormalV1; break;
                                            case "normalv2": Quality = Game.Enums.ItemQuality.NormalV2; break;
                                            case "normalv3": Quality = Game.Enums.ItemQuality.NormalV3; break;
                                            case "refined": Quality = Game.Enums.ItemQuality.Refined; break;
                                            case "unique": Quality = Game.Enums.ItemQuality.Unique; break;
                                            case "elite": Quality = Game.Enums.ItemQuality.Elite; break;
                                            case "super": Quality = Game.Enums.ItemQuality.Super; break;
                                            case "other": Quality = Game.Enums.ItemQuality.Other; break;
                                            default:
                                                {
                                                    Quality = (PhoenixProject.Game.Enums.ItemQuality)int.Parse(Data[4]);
                                                    break;
                                                }
                                        }
                                    }
                                    Database.ConquerItemBaseInformation CIBI = null;
                                    foreach (Database.ConquerItemBaseInformation infos in Database.ConquerItemInformation.BaseInformations.Values)
                                    {
                                        if (infos.Name.ToLower() == ItemName.ToLower() && Quality == (Game.Enums.ItemQuality)(infos.ID % 10))
                                        {
                                            CIBI = infos;
                                        }
                                        else
                                        {
                                            if (infos.Name.ToLower() == ItemName.ToLower())
                                                CIBI = infos;
                                        }
                                    }
                                    if (CIBI == null)
                                        break;
                                    Item = new GamePackets.ConquerItem(true);
                                    Item.ID = CIBI.ID;
                                    Item.Durability = CIBI.Durability;
                                    Item.MaximDurability = CIBI.Durability;
                                    if (Data.Length > 3)
                                        Item.Plus = byte.Parse(Data[4]);
                                    #endregion

                                PrepareDrop:
                                    {
                                        if (Item != null || SpecialItem)
                                        {
                                            //dropevent Name Quality
                                            for (int i = 0; i < int.Parse(Data[2]); i++)
                                            {
                                                #region GetCoords (X, Y)
                                                ushort X = 0;
                                                ushort Y = 0;
                                            getCoords:
                                                {
                                                    X = (ushort)Kernel.Random.Next(client.Entity.X - 20, client.Entity.X + 20);
                                                    Y = (ushort)Kernel.Random.Next(client.Entity.Y - 20, client.Entity.Y + 20);
                                                }
                                                while (!client.Map.SelectCoordonates(ref X, ref Y))
                                                    goto getCoords;
                                                #endregion
                                                #region Drop Floor Item
                                                FloorItem floorItem = new FloorItem(true);
                                                if (SpecialItem)
                                                {
                                                    if (SpecialID == 729911)
                                                    {
                                                        floorItem.ValueType = Network.GamePackets.FloorItem.FloorValueType.ConquerPoints;
                                                        floorItem.Value = 20;
                                                    }
                                                    floorItem.ItemID = SpecialID;
                                                    floorItem.Item = new ConquerItem(true);
                                                    floorItem.Item.ID = SpecialID;
                                                    floorItem.Item.UID = FloorItem.FloorUID.Next;
                                                    floorItem.UID = floorItem.Item.UID;
                                                    floorItem.Item.MobDropped = true;
                                                    while (client.Map.Npcs.ContainsKey(floorItem.Item.UID))
                                                    {
                                                        floorItem.Item.UID = FloorItem.FloorUID.Next;
                                                        floorItem.UID = FloorItem.FloorUID.Next;
                                                    }

                                                }
                                                else
                                                {
                                                    floorItem.Item = new ConquerItem(true);
                                                    floorItem.Item.Color = Item.Color;
                                                    floorItem.Item.Durability = Item.Durability;
                                                    floorItem.Item.ID = Item.ID;
                                                    floorItem.Item.Mode = Game.Enums.ItemMode.Default;
                                                    floorItem.Item.UID = FloorItem.FloorUID.Next;
                                                    floorItem.UID = floorItem.Item.UID;
                                                    floorItem.Item.MobDropped = true;
                                                    floorItem.ItemColor = Item.Color;
                                                    floorItem.ItemID = Item.ID;
                                                    while (client.Map.Npcs.ContainsKey(floorItem.Item.UID))
                                                    {
                                                        floorItem.Item.UID = FloorItem.FloorUID.Next;
                                                        floorItem.UID = FloorItem.FloorUID.Next;
                                                    }
                                                }

                                                floorItem.MapID = client.Map.ID;
                                                floorItem.MapObjType = Game.MapObjectType.Item;
                                                floorItem.X = X;
                                                floorItem.Y = Y;
                                                floorItem.Type = FloorItem.Drop;
                                                floorItem.OnFloor = Time32.Now;
                                                client.SendScreenSpawn(floorItem, true);
                                                client.Map.AddFloorItem(floorItem);
                                            }
                                        }
                                                #endregion
                                    }
                                    break;
                                }
                            case "testtitle":
                                {
                                    TitlePacket title = new TitlePacket(byte.Parse(Data[1]) == 1);
                                    title.UID = client.Entity.UID;
                                    title.Title = byte.Parse(Data[2]);
                                    title.Type = byte.Parse(Data[3]);
                                    title.dwParam = byte.Parse(Data[4]);
                                    title.dwParam2 = byte.Parse(Data[5]);
                                    client.Send(title);
                                    break;
                                }
                            case "resetvote":
                                {
                                    Kernel.VotePoolUid.Clear();
                                    Kernel.VotePool.Clear();
                                    Database.EntityTable.DeletVotes();
                                    break;
                                }
                            case "invite":
                                {
                                    Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "Weekly has Started! You Wana Join?");
                                    npc.OptionID = 247;
                                    //npc.times = 10;
                                    client.Send(npc.ToArray());
                                    client.Entity.InviteSendStamp = Time32.Now;
                                    client.Entity.invite = true;
                                    break;
                                }
                            case "bo7sen":
                                {

                                    PhoenixProject.Network.GamePackets.Data Datas = new PhoenixProject.Network.GamePackets.Data(true);
                                    Datas.UID = client.Entity.UID;
                                    Datas.ID = 126;
                                    Datas.dwParam = uint.Parse(Data[1]);
                                    Datas.wParam1 = client.Entity.X;
                                    Datas.wParam2 = client.Entity.Y;
                                    client.Send(Datas);

                                    break;
                                }
                            case "ww":
                                {
                                    Program.kimo = ushort.Parse(Data[1]);
                                    break;
                                }
                            case "halo":
                                {
                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.MagicDefender);
                                    break;
                                }
                            case "halo2":
                                {

                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo2);

                                    break;
                                }
                            case "halo3":
                                {

                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo3);
                                    break;
                                }
                            case "halo4":
                                {

                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo4);

                                    break;
                                }
                            case "halo29":
                                {

                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo29);
                                    break;
                                }
                            case "halo30":
                                {

                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo30);

                                    break;
                                }
                            case "halo31":
                                {

                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo31);
                                    break;
                                }
                            case "halo32":
                                {

                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo32);

                                    break;
                                }
                            case "halo33":
                                {

                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo33);
                                    break;
                                }
                            case "halo34":
                                {

                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo34);

                                    break;
                                }
                            case "halo35":
                                {

                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo35);
                                    break;
                                }
                            case "halo36":
                                {

                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo36);

                                    break;
                                }
                            case "halo37":
                                {

                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo37);
                                    break;
                                }
                            case "halo38":
                                {

                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo38);

                                    break;
                                }
                            case "halo39":
                                {
                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo39);
                                    break;
                                }
                            case "halo40":
                                {
                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo40);
                                    break;
                                }
                            case "halo41":
                                {
                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo41);
                                    break;
                                }
                            case "halo42":
                                {
                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo42);
                                    break;
                                }
                            case "halo43":
                                {
                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo43);
                                    break;
                                }
                            case "halo44":
                                {
                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo44);
                                    break;
                                }
                            case "halo45":
                                {
                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo45);
                                    break;
                                }
                            case "halo46":
                                {
                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo46);

                                    break;
                                }
                            case "halo47":
                                {
                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo47);
                                    break;
                                }
                            case "halo48":
                                {
                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo48);
                                    break;
                                }
                            case "halo49":
                                {
                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo49);
                                    break;
                                }
                            case "halo50":
                                {
                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo50);
                                    break;
                                }
                            case "halo51":
                                {
                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo51);
                                    break;
                                }
                            case "halo52":
                                {
                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo52);

                                    break;
                                }
                            case "halo53":
                                {

                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo53);
                                    break;
                                }
                            case "halo54":
                                {

                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo54);

                                    break;
                                }
                            case "halo55":
                                {

                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo55);
                                    break;
                                }
                            case "halo56":
                                {

                                    //client.Entity.StatusFlag2 = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo56);

                                    break;
                                }
                            case "halo57":
                                {

                                    // client.Entity.StatusFlag = 0;
                                    client.Entity.AddFlag3(GamePackets.Update.Flags3.kimo57);
                                    break;
                                }

                            case "lottery1":
                                {

                                    break;
                                }
                            case "bbs":
                                {

                                    Console.WriteLine(" " + client.Entity.BattlePower + "");
                                    break;
                                }
                            case "lottery2":
                                {

                                    uint randprize = (uint)PhoenixProject.ServerBase.Kernel.Random.Next(1, (int)Database.DROP_SOULS.Count_Jar);
                                    //Database.Monster.Souls[randsouls].item_id
                                    uint ItemID = ServerBase.Kernel.JarItem[randprize].item_id;
                                    client.Inventory.Add(ItemID, 0, 1);
                                    ServerBase.Kernel.SendWorldMessage(new Message("Congratulations, " + client.Entity.Name + " has finished CloudSaint Jar Quest and Obtained " + Database.ConquerItemInformation.BaseInformations[ItemID].Name + "  !", System.Drawing.Color.Red, Network.GamePackets.Message.Talk), ServerBase.Kernel.GamePool.Values);
                                    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);
                                    break;
                                }
                            case "kimo":
                                {

                                    Program.kimo = ushort.Parse(Data[1]);
                                    // Program.kimo2 = ushort.Parse(Data[2]);
                                    // Program.kimo3 = ushort.Parse(Data[3]);
                                    testpacket str = new testpacket(true);
                                    client.Send(str);
                                    break;
                                }
                            case "3":
                                {
                                    PhoenixProject.Game.KimoCarnaval.Load();
                                    /*Program.kimo3 = ushort.Parse(Data[1]);
                                    Network.GamePackets.Weather weather = new Network.GamePackets.Weather(true);
                                    weather.WeatherType = (uint)Program.kimo3;
                                    weather.Intensity = 100;
                                    weather.Appearence = 2;
                                    weather.Direction = 4;
                                    client.Send(weather);*/
                                    break;
                                }
                            case "kimo4":
                                {
                                    //PhoenixProject.Game.KimoCarnaval.Npc();
                                    /*Program.kimo3 = ushort.Parse(Data[1]);
                                    Network.GamePackets.Weather weather = new Network.GamePackets.Weather(true);
                                    weather.WeatherType = (uint)Program.kimo3;
                                    weather.Intensity = 100;
                                    weather.Appearence = 2;
                                    weather.Direction = 4;
                                    client.Send(weather);*/
                                    break;
                                }
                            case "33":
                                {
                                    client.Entity.Action = PhoenixProject.Game.Enums.ConquerAction.poker;

                                    /*Program.kimo3 = ushort.Parse(Data[1]);
                                    Data data = new Data(true);
                                    data.ID = GamePackets.Data.OpenCustom;
                                    data.UID = client.Entity.UID;
                                    data.TimeStamp = Time32.Now;
                                    data.dwParam = (uint)Program.kimo3;
                                    data.wParam1 = client.Entity.X;
                                    data.wParam2 = client.Entity.Y;
                                    client.Send(data);*/

                                    // client.Send(new Data(true) { UID = client.Entity.UID, ID = GamePackets.Data.OpenWindow, dwParam = GamePackets.Data.CustomCommands.Reincarnation, wParam1 = client.Entity.X, wParam2 = client.Entity.Y });

                                    break;
                                }
                            case "p1":
                                {
                                    client.Entity.Action = PhoenixProject.Game.Enums.ConquerAction.poker2;
                                    break;
                                }
                            case "p2":
                                {
                                    client.Entity.Action = PhoenixProject.Game.Enums.ConquerAction.poker3;
                                    break;
                                }
                            case "p3":
                                {
                                    client.Entity.Action = PhoenixProject.Game.Enums.ConquerAction.poker4;
                                    break;
                                }
                            case "p4":
                                {
                                    client.Entity.Action = PhoenixProject.Game.Enums.ConquerAction.poker;
                                    break;
                                }
                            case "p5":
                                {
                                    client.Entity.Action = PhoenixProject.Game.Enums.ConquerAction.poker;
                                    break;
                                }
                            case "p6":
                                {
                                    client.Entity.Action = PhoenixProject.Game.Enums.ConquerAction.poker5;
                                    break;
                                }
                            case "bb":
                                {

                                    PhoenixProject.Database.MySqlCommand command = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.DELETE);
                                    command.Delete("skills", "ID", "1110").And("EntityID", client.Entity.UID).Execute();

                                    break;
                                }
                            case "bo":
                                {
                                    _String str = new _String(true);
                                    str.UID = client.Entity.UID;
                                    str.TextsCount = 1;
                                    str.Type = _String.Sound;
                                    str.Texts.Add("zhengfu");
                                    client.Send(str);
                                    //client.Send(new Data(true) { UID = client.Entity.UID, ID = Network.GamePackets.Data.OpenWindow, dwParam = uint.Parse(Data[1]), wParam1 = client.Entity.X, wParam2 = client.Entity.Y });
                                    //datas.dwParam = uint.Parse(Data[1]);
                                    //client.Send(datas);
                                    break;
                                }

                            case "pok":
                                {

                                    break;
                                }
                            case "n":
                                {

                                    {
                                        Random disco = new Random();
                                        uint discocolor = (uint)disco.Next(50000, 999999999);
                                        Program.ScreenColor = 5855577;
                                        foreach (Client.GameState C in ServerBase.Kernel.GamePool.Values)
                                        {
                                            Data datas = new Data(true);
                                            datas.UID = C.Entity.UID;
                                            datas.ID = 104;
                                            Program.ScreenColor = 5855577;
                                            datas.dwParam = 5855577;
                                            C.Send(datas);
                                        }
                                    }

                                    break;
                                }
                            case "d":
                                {

                                    {
                                        Random disco = new Random();
                                        uint discocolor = (uint)disco.Next(50000, 999999999);
                                        Program.ScreenColor = 0;
                                        foreach (Client.GameState C in ServerBase.Kernel.GamePool.Values)
                                        {
                                            Data datas = new Data(true);
                                            datas.UID = C.Entity.UID;
                                            datas.ID = 104;
                                            datas.dwParam = 0;
                                            //datas.wParam1 = (ushort)Program.ScreenColor;
                                            //datas.wParam2 = (ushort)Program.ScreenColor;
                                            //datas.wParam2 = 104;
                                            //datas.wParam4 = (ushort)Program.ScreenColor;
                                            C.Send(datas);
                                        }
                                    }

                                    break;
                                }
                            case "give":
                                {
                                    foreach (var Client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (Client.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            switch (Data[2])
                                            {
                                                case "vip":
                                                    Client.Entity.VIPLevel = byte.Parse(Data[3]);
                                                    break;
                                                case "cps":
                                                    Client.Entity.ConquerPoints += uint.Parse(Data[3]);
                                                    break;
                                                case "money":
                                                    Client.Entity.Money += uint.Parse(Data[3]);
                                                    break;
                                                case "spell":
                                                    Client.AddSpell(new Spell(true) { ID = ushort.Parse(Data[3]) });
                                                    break;
                                                case "level":
                                                    Client.Entity.Level = byte.Parse(Data[3]);
                                                    break;
                                                case "plustone":
                                                    {
                                                        UInt32 ItemId = UInt32.Parse(Data[3]);
                                                        if (Database.ConquerItemInformation.BaseInformations.ContainsKey(ItemId))
                                                        {
                                                            Database.ConquerItemBaseInformation iteminfo;
                                                            if (Database.ConquerItemInformation.BaseInformations.TryGetValue(ItemId, out iteminfo))
                                                            {
                                                                Interfaces.IConquerItem newItem = new GamePackets.ConquerItem(true);
                                                                newItem.ID = iteminfo.ID;
                                                                Byte Plus = (Byte)(newItem.ID % 730000);
                                                                Console.WriteLine("Item Plus " + Plus);
                                                                newItem.Plus = (Byte)(newItem.ID % 730000);
                                                                Client.Inventory.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                                            }
                                                        }
                                                        break;
                                                    }
                                                case "item":
                                                    {
                                                        string ItemName = Data[3];
                                                        Game.Enums.ItemQuality Quality = Game.Enums.ItemQuality.Fixed;
                                                        switch (Data[4].ToLower())
                                                        {
                                                            case "fixed": Quality = Game.Enums.ItemQuality.Fixed; break;
                                                            case "normal": Quality = Game.Enums.ItemQuality.Normal; break;
                                                            case "normalv1": Quality = Game.Enums.ItemQuality.NormalV1; break;
                                                            case "normalv2": Quality = Game.Enums.ItemQuality.NormalV2; break;
                                                            case "normalv3": Quality = Game.Enums.ItemQuality.NormalV3; break;
                                                            case "refined": Quality = Game.Enums.ItemQuality.Refined; break;
                                                            case "unique": Quality = Game.Enums.ItemQuality.Unique; break;
                                                            case "elite": Quality = Game.Enums.ItemQuality.Elite; break;
                                                            case "super": Quality = Game.Enums.ItemQuality.Super; break;
                                                            case "other": Quality = Game.Enums.ItemQuality.Other; break;
                                                            default:
                                                                {
                                                                    Quality = (PhoenixProject.Game.Enums.ItemQuality)int.Parse(Data[4]);
                                                                    break;
                                                                }
                                                        }
                                                        Database.ConquerItemBaseInformation CIBI = null;
                                                        foreach (Database.ConquerItemBaseInformation infos in Database.ConquerItemInformation.BaseInformations.Values)
                                                        {
                                                            if (infos.Name.ToLower() == ItemName.ToLower() && Quality == (Game.Enums.ItemQuality)(infos.ID % 10))
                                                            {
                                                                CIBI = infos;
                                                            }
                                                        }
                                                        if (CIBI == null)
                                                            break;
                                                        Interfaces.IConquerItem newItem = new GamePackets.ConquerItem(true);
                                                        newItem.ID = CIBI.ID;
                                                        newItem.Durability = CIBI.Durability;
                                                        newItem.MaximDurability = CIBI.Durability;
                                                        if (Data.Length > 3)
                                                        {
                                                            byte plus = 0;
                                                            byte.TryParse(Data[3], out plus);
                                                            newItem.Plus = Math.Min((byte)15, plus);
                                                            if (Data.Length > 4)
                                                            {
                                                                byte bless = 0;
                                                                byte.TryParse(Data[6], out bless);
                                                                newItem.Bless = Math.Min((byte)7, bless);
                                                                if (Data.Length > 5)
                                                                {
                                                                    byte ench = 0;
                                                                    byte.TryParse(Data[7], out ench);
                                                                    newItem.Enchant = Math.Min((byte)255, ench);
                                                                    if (Data.Length > 6)
                                                                    {
                                                                        byte soc1 = 0;
                                                                        byte.TryParse(Data[8], out soc1);
                                                                        if (Enum.IsDefined(typeof(Game.Enums.Gem), soc1))
                                                                        {
                                                                            newItem.SocketOne = (Game.Enums.Gem)soc1;
                                                                        }
                                                                        if (Data.Length > 7)
                                                                        {
                                                                            byte soc2 = 0;
                                                                            byte.TryParse(Data[9], out soc2);
                                                                            if (Enum.IsDefined(typeof(Game.Enums.Gem), soc2))
                                                                            {
                                                                                newItem.SocketTwo = (Game.Enums.Gem)soc2;
                                                                            }
                                                                        }
                                                                        if (Data.Length > 10)
                                                                        {
                                                                            byte R = 0, G = 0, B = 0;
                                                                            byte.TryParse(Data[10], out R);
                                                                            byte.TryParse(Data[11], out G);
                                                                            byte.TryParse(Data[12], out B);
                                                                            newItem.SocketProgress = (uint)(B | (G << 8) | (R << 16));
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        newItem.Color = (PhoenixProject.Game.Enums.Color)ServerBase.Kernel.Random.Next(4, 8);
                                                        Client.Inventory.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                                        break;
                                                    }
                                                case "equip":
                                                    {
                                                        string ItemName = Data[3];
                                                        Game.Enums.ItemQuality Quality = Game.Enums.ItemQuality.NormalV3;
                                                        Database.ConquerItemBaseInformation CIBI = null;
                                                        foreach (Database.ConquerItemBaseInformation infos in Database.ConquerItemInformation.BaseInformations.Values)
                                                        {
                                                            if (infos.Name.ToLower() == ItemName.ToLower() && Quality == (Game.Enums.ItemQuality)(infos.ID % 10))
                                                            {
                                                                CIBI = infos;
                                                            }
                                                        }
                                                        if (CIBI == null)
                                                            break;
                                                        Interfaces.IConquerItem newItem = new GamePackets.ConquerItem(true);
                                                        newItem.ID = CIBI.ID;
                                                        newItem.Position = 9;
                                                        newItem.Durability = CIBI.Durability;
                                                        newItem.MaximDurability = CIBI.Durability;
                                                        newItem.Color = (PhoenixProject.Game.Enums.Color)ServerBase.Kernel.Random.Next(4, 8);
                                                        Client.Equipment.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                                        break;
                                                    }
                                            }
                                            break;
                                        }
                                    }
                                    break;
                                }
                            case "cps":
                                {
                                    client.Entity.ConquerPoints = uint.Parse(Data[1]);
                                    break;
                                }
                            case "hors":
                                {
                                    client.Entity.RacePoints = uint.Parse(Data[1]);
                                    break;
                                }
                            case "money":
                                {
                                    client.Entity.Money = uint.Parse(Data[1]);
                                    break;
                                }

                            case "open":
                                {
                                    GamePackets.Data data = new GamePackets.Data(true);
                                    data.ID = GamePackets.Data.OpenCustom;
                                    data.UID = client.Entity.UID;
                                    data.TimeStamp = Time32.Now;
                                    data.dwParam = uint.Parse(Data[1]);
                                    data.wParam1 = client.Entity.X;
                                    data.wParam2 = client.Entity.Y;
                                    client.Send(data);
                                    break;
                                }
                            case "xp":
                                {
                                    client.Entity.AddFlag(Update.Flags.XPList);
                                    client.XPListStamp = Time32.Now;
                                    break;
                                }

                            case "guildwar":
                                {
                                    switch (Data[1])
                                    {
                                        case "on":
                                            {
                                                if (!Game.ConquerStructures.Society.GuildWar.IsWar)
                                                {
                                                    Game.ConquerStructures.Society.GuildWar.Start();
                                                }
                                                break;
                                            }
                                        case "off":
                                            {
                                                if (Game.ConquerStructures.Society.GuildWar.IsWar)
                                                {
                                                    Game.ConquerStructures.Society.GuildWar.End();
                                                }
                                                break;
                                            }
                                    }
                                    break;
                                }

                        }
                    }
                    if (client.Account.State == PhoenixProject.Database.AccountTable.AccountState.GameMaster
                    || client.Account.State == PhoenixProject.Database.AccountTable.AccountState.ProjectManager || client.Account.State == PhoenixProject.Database.AccountTable.AccountState.Coder)
                    {
                        switch (Data[0])
                        {
                            case "invisible":
                                Console.WriteLine("sd");
                                break;
                            /* case "reloadmobs":
                                 {
                                     client.Map.FreezeMonsters = true;
                                     var Clone = client.Map.Entities.Base.Values.ToArray();
                                     foreach (var mob in Clone)
                                         if (!mob.Companion)
                                         {
                                             client.Map.Floor[mob.X, mob.Y, PhoenixProject.Game.MapObjectType.Monster, mob] = true;
                                             client.Map.Entities.Remove(mob.UID);
                                         }
                                     Clone = new Game.Entity[0];
                                     client.Map.EntityUIDCounter.Now = 400000;
                                     client.Map.LoadMonsters();
                                     client.Map.FreezeMonsters = false;
                                     foreach (Client.GameState Client in ServerBase.Kernel.GamePool.Values)
                                     {
                                         if (Client.Map.ID == client.Map.ID)
                                         {
                                             Client.Entity.Teleport(Client.Entity.MapID, Client.Entity.X, Client.Entity.Y);
                                         }
                                     }
                                     break;
                                 }*/
                            case "mobmesh":
                                {
                                    client.Entity.Body = ushort.Parse(Data[1]);
                                    break;
                                }
                            case "trace":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            client.Entity.Teleport(pClient.Entity.MapID, pClient.Entity.X, pClient.Entity.Y);
                                        }
                                    }
                                    break;
                                }
                            case "bring":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]) || Data[1].ToLower() == "all")
                                            if (Data[1].ToLower() == "all")
                                            {
                                                pClient.Entity.Teleport(client.Entity.MapID,
                                                    (ushort)Kernel.Random.Next(client.Entity.X - 5, client.Entity.X + 5),
                                                    (ushort)Kernel.Random.Next(client.Entity.Y - 5, client.Entity.Y + 5));
                                            }
                                            else
                                                pClient.Entity.Teleport(client.Entity.MapID, client.Entity.X, client.Entity.Y);

                                    }
                                    break;
                                }
                            case "restart":
                                {
                                    Program.CommandsAI("@restart");
                                    break;
                                }
                            case "kick":
                                {
                                    foreach (var Client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (Client.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            Client.Disconnect();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            case "ban":
                                {
                                    foreach (var Client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (Client.Account.State >= client.Account.State)
                                            continue;
                                        if (Client.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            Client.Account.State = PhoenixProject.Database.AccountTable.AccountState.Banned;
                                            Client.Account.Savekimo();
                                            Client.Disconnect();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            case "unban":
                                {
                                    var Account = new Database.AccountTable(Data[1]);
                                    if (Account.State == PhoenixProject.Database.AccountTable.AccountState.Banned)
                                    {
                                        Account.State = PhoenixProject.Database.AccountTable.AccountState.Player;
                                        Account.Savekimo();
                                    }
                                    break;
                                }
                            case "chatban":
                                {
                                    foreach (var Client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (Client.Entity.Name.Contains(Data[1]))
                                        {
                                            Client.ChatBanLasts = uint.Parse(Data[2]);
                                            Client.ChatBanTime = DateTime.Now;
                                            Client.ChatBanned = true;
                                        }
                                    }
                                    break;
                                }
                            case "increaseexp":
                                {
                                    client.IncreaseExperience(ulong.Parse(Data[1]), true);
                                    break;
                                }
                            case "chatunban":
                                {
                                    foreach (var Client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (Client.Entity.Name.Contains(Data[1]))
                                        {
                                            Client.ChatBanned = false;
                                        }
                                    }
                                    break;
                                }
                            case "bc":
                                {
                                    Game.ConquerStructures.Broadcast.Broadcasts.Clear();
                                    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;
                                    broadcast.Message = Message.Remove(0, 2);
                                    ServerBase.Kernel.SendWorldMessage(new Message(Message.Remove(0, 2), "ALLUSERS", client.Entity.Name, System.Drawing.Color.Red, GamePackets.Message.BroadcastMessage), ServerBase.Kernel.GamePool.Values);
                                    Game.ConquerStructures.Broadcast.CurrentBroadcast.EntityID = 1;
                                    Game.ConquerStructures.Broadcast.CurrentBroadcast = broadcast;
                                    break;
                                }
                            case "broadcast":
                                {
                                    Game.ConquerStructures.Broadcast.Broadcasts.Clear();
                                    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;
                                    broadcast.Message = Message.Remove(0, 9);
                                    ServerBase.Kernel.SendWorldMessage(new Message(Message.Remove(0, 9), "ALLUSERS", client.Entity.Name, System.Drawing.Color.Red, GamePackets.Message.BroadcastMessage), ServerBase.Kernel.GamePool.Values);
                                    Game.ConquerStructures.Broadcast.CurrentBroadcast.EntityID = 1;
                                    Game.ConquerStructures.Broadcast.CurrentBroadcast = broadcast;
                                    break;
                                }
                            case "ann":
                                {
                                    ServerBase.Kernel.SendWorldMessage(new Message("[Announce] by " + client.Entity.Name + ": " + Mess.Remove(0, 3), System.Drawing.Color.Red, Network.GamePackets.Message.Center), ServerBase.Kernel.GamePool.Values);
                                    ServerBase.Kernel.SendWorldMessage(new Message("[Announce] by " + client.Entity.Name + ": " + Mess.Remove(0, 3), System.Drawing.Color.Red, Network.GamePackets.Message.World), ServerBase.Kernel.GamePool.Values);
                                    break;
                                }
                            case "announce":
                                {
                                    ServerBase.Kernel.SendWorldMessage(new Message("[Announce] by " + client.Entity.Name + ": " + Mess.Remove(0, 8), System.Drawing.Color.Red, Network.GamePackets.Message.Center), ServerBase.Kernel.GamePool.Values);
                                    ServerBase.Kernel.SendWorldMessage(new Message("[Announce] by " + client.Entity.Name + ": " + Mess.Remove(0, 8), System.Drawing.Color.Red, Network.GamePackets.Message.World), ServerBase.Kernel.GamePool.Values);
                                    break;
                                }
                            case "arenapoints":
                                {
                                    client.ArenaStatistic.ArenaPoints = uint.Parse(Data[1]);
                                    client.ArenaStatistic.Send(client);
                                    break;
                                }
                            case "record":
                                {
                                    if (client.Account.State != Database.AccountTable.AccountState.ProjectManager)
                                        break;
                                    switch (Data[1])
                                    {
                                        case "on": client.Entity.Mode = Game.Enums.Mode.Recording; break;
                                        case "off": Program.CommandsAI("/saverecord"); break;
                                    } break;
                                }
                            case "clearinventory":
                                {
                                    Interfaces.IConquerItem[] inventory = new Interfaces.IConquerItem[client.Inventory.Objects.Length];
                                    client.Inventory.Objects.CopyTo(inventory, 0);

                                    foreach (Interfaces.IConquerItem item in inventory)
                                    {
                                        client.Inventory.Remove(item, PhoenixProject.Game.Enums.ItemUse.Remove);
                                    }
                                    break;
                                }
                            case "online":
                                {
                                    client.Send(new Message("Online players count: " + ServerBase.Kernel.GamePool.Count, System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                    string line = "";
                                    foreach (Client.GameState pClient in ServerBase.Kernel.GamePool.Values)
                                        line += pClient.Entity.Name + ",";

                                    if (line.Length >= 255)
                                        return true;
                                    client.Send(new GamePackets.Message(line, System.Drawing.Color.Beige, GamePackets.Message.Talk));
                                    break;
                                }
                            case "reallot":
                                {
                                    if (client.Entity.Reborn != 0)
                                    {
                                        client.Entity.Agility = 0;
                                        client.Entity.Strength = 0;
                                        client.Entity.Vitality = 1;
                                        client.Entity.Spirit = 0;
                                        if (client.Entity.Reborn == 1)
                                        {
                                            client.Entity.Atributes = (ushort)(client.ExtraAtributePoints(client.Entity.FirstRebornLevel, client.Entity.FirstRebornLevel)
                                                + 52 + 3 * (client.Entity.Level - 15));
                                        }
                                        else
                                        {
                                            client.Entity.Atributes = (ushort)(client.ExtraAtributePoints(client.Entity.FirstRebornLevel, client.Entity.FirstRebornClass) +
                                                client.ExtraAtributePoints(client.Entity.SecondRebornLevel, client.Entity.SecondRebornClass) + 52 + 3 * (client.Entity.Level - 15));
                                        }
                                        client.CalculateStatBonus();
                                        client.CalculateHPBonus();
                                    }
                                    break;
                                }
                            case "str":
                                {
                                    ushort atr = 0;
                                    ushort.TryParse(Data[1], out atr);
                                    if (client.Entity.Atributes >= atr)
                                    {
                                        client.Entity.Strength += atr;
                                        client.Entity.Atributes -= atr;
                                        client.CalculateStatBonus();
                                        client.CalculateHPBonus();
                                    }
                                    break;
                                }
                            case "agi":
                                {
                                    ushort atr = 0;
                                    ushort.TryParse(Data[1], out atr);
                                    if (client.Entity.Atributes >= atr)
                                    {
                                        client.Entity.Agility += atr;
                                        client.Entity.Atributes -= atr;
                                        client.CalculateStatBonus();
                                        client.CalculateHPBonus();
                                    }
                                    break;
                                }
                            case "vit":
                                {
                                    ushort atr = 0;
                                    ushort.TryParse(Data[1], out atr);
                                    if (client.Entity.Atributes >= atr)
                                    {
                                        client.Entity.Vitality += atr;
                                        client.Entity.Atributes -= atr;
                                        client.CalculateStatBonus();
                                        client.CalculateHPBonus();
                                    }
                                    break;
                                }
                            case "spi":
                                {
                                    ushort atr = 0;
                                    ushort.TryParse(Data[1], out atr);
                                    if (client.Entity.Atributes >= atr)
                                    {
                                        client.Entity.Spirit += atr;
                                        client.Entity.Atributes -= atr;
                                        client.CalculateStatBonus();
                                        client.CalculateHPBonus();
                                    }
                                    break;
                                }
                            case "reborn":
                                {
                                    if (client.Entity.Reborn < 2)
                                    {
                                        if (client.Entity.Class % 10 == 5)
                                        {
                                            if (client.Entity.Class != 15 &&
                                                client.Entity.Class != 25 &&
                                                client.Entity.Class != 45 &&
                                                client.Entity.Class != 55 &&
                                                client.Entity.Class != 65 &&
                                                client.Entity.Class != 75 &&
                                                client.Entity.Class != 135 &&
                                                client.Entity.Class != 145)
                                            {
                                                client.Send(new Message("You need to be an existing class.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                            }
                                            else
                                            {
                                                byte newclass = 10;
                                                byte.TryParse(Data[1], out newclass);
                                                if (newclass != 11 &&
                                                newclass != 21 &&
                                                newclass != 41 &&
                                                newclass != 51 &&
                                                newclass != 61 &&
                                                newclass != 71 &&
                                                newclass != 132 &&
                                                newclass != 142)
                                                {
                                                    client.Send(new Message("You need to reborn into an existing class. For fire class = 142 and for waters class = 132.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                                }
                                                else
                                                {
                                                    if (!client.Reborn(newclass))
                                                        client.Send(new Message("You need atleast 2 spaces in your inventory.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                                }
                                            }
                                        }
                                        else
                                            client.Send(new Message("You need to be a master to be able to reborn.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                    }
                                    else
                                        client.Send(new Message("You can't reborn any more.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                    break;
                                }

                            case "dc":
                                {
                                    client.Disconnect();
                                    break;
                                }
                            case "prof":
                                {
                                    Interfaces.IProf proficiency = new GamePackets.Proficiency(true);
                                    if (Data.Length > 1)
                                        proficiency.ID = ushort.Parse(Data[1]);
                                    if (Data.Length > 2)
                                        proficiency.Level = byte.Parse(Data[2]);
                                    if (Data.Length > 3)
                                        proficiency.Experience = uint.Parse(Data[3]);
                                    client.AddProficiency(proficiency);
                                    break;
                                }
                            case "spell":
                                {
                                    Interfaces.ISkill spell = new GamePackets.Spell(true);
                                    if (Data.Length > 1)
                                        spell.ID = ushort.Parse(Data[1]);
                                    if (Data.Length > 2)
                                        spell.Level = byte.Parse(Data[2]);
                                    if (Data.Length > 3)
                                        spell.Experience = uint.Parse(Data[3]);
                                    client.AddSpell(spell);
                                    break;
                                }

                            case "level":
                                {
                                    byte level = client.Entity.Level;
                                    byte.TryParse(Data[1], out level);
                                    level = Math.Min((byte)140, Math.Max((byte)1, level));
                                    client.Entity.Level = level;
                                    client.Entity.Experience = 0;
                                    if (client.Entity.Reborn == 0)
                                    {
                                        Database.DataHolder.GetStats(client.Entity.Class, level, client);
                                        client.CalculateStatBonus();
                                        client.CalculateHPBonus();
                                        client.GemAlgorithm();
                                    }
                                    break;
                                }
                            case "class":
                                {
                                    byte _class = client.Entity.Class;
                                    byte.TryParse(Data[1], out _class);
                                    _class = Math.Min((byte)145, Math.Max((byte)1, _class));
                                    client.Entity.Class = _class;
                                    if (client.Entity.Reborn == 0)
                                    {
                                        Database.DataHolder.GetStats(_class, client.Entity.Level, client);
                                        client.CalculateStatBonus();
                                        client.CalculateHPBonus();
                                        client.GemAlgorithm();
                                    }
                                    break;
                                }
                            case "body":
                                {
                                    ushort body = client.Entity.Body;
                                    ushort.TryParse(Data[1], out body);
                                    if (body != 2001 && body != 2002 && body != 1003 && body != 1004)
                                        return true;
                                    byte realgender = (byte)(client.Entity.Body % 10);
                                    byte gender = (byte)(body % 10);
                                    if (client.Equipment.Objects[8] != null)
                                        if (gender >= 3 && realgender <= 2)
                                            return true;
                                    client.Entity.Body = body;
                                    if (gender >= 3 && realgender <= 2)
                                        client.Entity.Face -= 200;
                                    if (gender <= 2 && realgender >= 3)
                                        client.Entity.Face += 200;
                                    break;
                                }
                            case "hair":
                                {
                                    ushort hair = client.Entity.HairStyle;
                                    ushort.TryParse(Data[1], out hair);
                                    client.Entity.HairStyle = hair;
                                    break;
                                }
                            case "map":
                                {
                                    client.Send(new Message("Map: " + client.Entity.MapID, System.Drawing.Color.Blue, GamePackets.Message.TopLeft));
                                    break;
                                }
                            case "map2":
                                {
                                    client.Send(new Message("Map base: " + client.Map.BaseID, System.Drawing.Color.Blue, GamePackets.Message.TopLeft));
                                    break;
                                }
                            case "tele":
                                {
                                    if (Data.Length > 3)
                                    {
                                        client.Entity.Teleport(ulong.Parse(Data[1]), ushort.Parse(Data[2]), ushort.Parse(Data[3]));
                                    }
                                    break;
                                }
                            case "tele2":
                                {
                                    if (Data.Length > 3)
                                    {
                                        client.Entity.TeleportHouse(ulong.Parse(Data[1]), ushort.Parse(Data[2]), ushort.Parse(Data[3]));
                                    }
                                    break;
                                }
                            case "transform":
                                {
                                    if (client.Entity.Dead)
                                        break;
                                    bool wasTransformated = client.Entity.Transformed;
                                    if (wasTransformated)
                                    {
                                        client.Entity.Hitpoints = client.Entity.MaxHitpoints;
                                        client.Entity.TransformationID = 0;
                                        client.Entity.TransformationStamp = Time32.Now;
                                        return true;
                                    }
                                    ushort transformation = client.Entity.TransformationID;
                                    ushort.TryParse(Data[1], out transformation);
                                    client.Entity.TransformationID = transformation;
                                    client.Entity.TransformationStamp = Time32.Now;
                                    client.Entity.TransformationTime = 110;
                                    SpellUse spellUse = new SpellUse(true);
                                    spellUse.Attacker = client.Entity.UID;
                                    spellUse.SpellID = 1360;
                                    spellUse.SpellLevel = 4;
                                    spellUse.X = client.Entity.X;
                                    spellUse.Y = client.Entity.Y;
                                    spellUse.Targets.Add(client.Entity.UID, (uint)0);
                                    client.Send(spellUse);
                                    client.Entity.TransformationMaxHP = 3000;
                                    double maxHP = client.Entity.MaxHitpoints;
                                    double HP = client.Entity.Hitpoints;
                                    double point = HP / maxHP;

                                    client.Entity.Hitpoints = (uint)(client.Entity.TransformationMaxHP * point);
                                    client.Entity.Update(Update.MaxHitpoints, client.Entity.TransformationMaxHP, false);
                                    break;
                                }
                            case "item":
                                {
                                    if (Data.Length > 2)
                                    {
                                        string ItemName = Data[1];
                                        Game.Enums.ItemQuality Quality = Game.Enums.ItemQuality.Fixed;
                                        switch (Data[2].ToLower())
                                        {
                                            case "fixed": Quality = Game.Enums.ItemQuality.Fixed; break;
                                            case "normal": Quality = Game.Enums.ItemQuality.Normal; break;
                                            case "normalv1": Quality = Game.Enums.ItemQuality.NormalV1; break;
                                            case "normalv2": Quality = Game.Enums.ItemQuality.NormalV2; break;
                                            case "normalv3": Quality = Game.Enums.ItemQuality.NormalV3; break;
                                            case "refined": Quality = Game.Enums.ItemQuality.Refined; break;
                                            case "unique": Quality = Game.Enums.ItemQuality.Unique; break;
                                            case "elite": Quality = Game.Enums.ItemQuality.Elite; break;
                                            case "super": Quality = Game.Enums.ItemQuality.Super; break;
                                            case "other": Quality = Game.Enums.ItemQuality.Other; break;
                                            default:
                                                {
                                                    Quality = (PhoenixProject.Game.Enums.ItemQuality)int.Parse(Data[2]);
                                                    break;
                                                }
                                        }
                                        Database.ConquerItemBaseInformation CIBI = null;
                                        foreach (Database.ConquerItemBaseInformation infos in Database.ConquerItemInformation.BaseInformations.Values)
                                        {
                                            if (infos.Name.ToLower() == ItemName.ToLower() && Quality == (Game.Enums.ItemQuality)(infos.ID % 10))
                                            {
                                                CIBI = infos;
                                            }
                                        }
                                        if (CIBI == null)
                                            break;
                                        Interfaces.IConquerItem newItem = new GamePackets.ConquerItem(true);
                                        newItem.ID = CIBI.ID;
                                        newItem.Durability = CIBI.Durability;
                                        newItem.MaximDurability = CIBI.Durability;
                                        if (Data.Length > 3)
                                        {
                                            byte plus = 0;
                                            byte.TryParse(Data[3], out plus);
                                            newItem.Plus = Math.Min((byte)12, plus);
                                            if (Data.Length > 4)
                                            {
                                                byte bless = 0;
                                                byte.TryParse(Data[4], out bless);
                                                newItem.Bless = Math.Min((byte)7, bless);
                                                if (Data.Length > 5)
                                                {
                                                    byte ench = 0;
                                                    byte.TryParse(Data[5], out ench);
                                                    newItem.Enchant = Math.Min((byte)255, ench);
                                                    if (Data.Length > 6)
                                                    {
                                                        byte soc1 = 0;
                                                        byte.TryParse(Data[6], out soc1);
                                                        if (Enum.IsDefined(typeof(Game.Enums.Gem), soc1))
                                                        {
                                                            newItem.SocketOne = (Game.Enums.Gem)soc1;
                                                        }
                                                        if (Data.Length > 7)
                                                        {
                                                            byte soc2 = 0;
                                                            byte.TryParse(Data[7], out soc2);
                                                            if (Enum.IsDefined(typeof(Game.Enums.Gem), soc2))
                                                            {
                                                                newItem.SocketTwo = (Game.Enums.Gem)soc2;
                                                            }
                                                        }
                                                        if (Data.Length > 10)
                                                        {
                                                            byte R = 0, G = 0, B = 0;
                                                            byte.TryParse(Data[8], out R);
                                                            byte.TryParse(Data[9], out G);
                                                            byte.TryParse(Data[10], out B);
                                                            newItem.SocketProgress = (uint)(B | (G << 8) | (R << 16));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        newItem.Color = (PhoenixProject.Game.Enums.Color)ServerBase.Kernel.Random.Next(4, 8);
                                        if (client.Account.State == PhoenixProject.Database.AccountTable.AccountState.GameMaster)
                                            newItem.Bound = true;
                                        client.Inventory.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                    }
                                    break;
                                }
                        }
                        return true;
                    }
                    #endregion

                    #region VIPs
                    if (client.Entity.VIPLevel > 0)
                    {
                        switch (Data[0])
                        {
                            case "transform":
                                {
                                    if (client.Entity.Dead)
                                        break;
                                    bool wasTransformated = client.Entity.Transformed;
                                    if (wasTransformated)
                                    {
                                        client.Entity.Hitpoints = client.Entity.MaxHitpoints;
                                        client.Entity.TransformationID = 0;
                                        client.Entity.TransformationStamp = Time32.Now;
                                        return true;
                                    }
                                    ushort transformation = client.Entity.TransformationID;
                                    ushort.TryParse(Data[1], out transformation);
                                    client.Entity.TransformationID = transformation;
                                    client.Entity.TransformationStamp = Time32.Now;
                                    client.Entity.TransformationTime = 110;
                                    SpellUse spellUse = new SpellUse(true);
                                    spellUse.Attacker = client.Entity.UID;
                                    spellUse.SpellID = 1360;
                                    spellUse.SpellLevel = 4;
                                    spellUse.X = client.Entity.X;
                                    spellUse.Y = client.Entity.Y;
                                    spellUse.Targets.Add(client.Entity.UID, (uint)0);
                                    client.Send(spellUse);
                                    client.Entity.TransformationMaxHP = 3000;
                                    double maxHP = client.Entity.MaxHitpoints;
                                    double HP = client.Entity.Hitpoints;
                                    double point = HP / maxHP;

                                    client.Entity.Hitpoints = (uint)(client.Entity.TransformationMaxHP * point);
                                    client.Entity.Update(Update.MaxHitpoints, client.Entity.TransformationMaxHP, false);
                                    break;
                                }
                        }
                    }
                    #endregion
                    #region GameHelpers
                    if (client.Account.State == PhoenixProject.Database.AccountTable.AccountState.GameHelper)
                    {
                        switch (Data[0])
                        {
                            case "scroll":
                                {
                                    if (client.Entity.MapID == 700)
                                        break;
                                    switch (Data[1].ToLower())
                                    {
                                        case "tc": client.Entity.Teleport(1002, 430, 380); break;
                                        case "pc": client.Entity.Teleport(1011, 195, 260); break;
                                        case "ac":
                                        case "am": client.Entity.Teleport(1020, 566, 563); break;
                                        case "dc": client.Entity.Teleport(1000, 500, 645); break;
                                        case "bi": client.Entity.Teleport(1015, 723, 573); break;
                                        case "pka": client.Entity.Teleport(1005, 050, 050); break;
                                        case "ma": client.Entity.Teleport(1036, 211, 196); break;
                                        case "ja": client.Entity.Teleport(6000, 100, 100); break;
                                    }
                                    break;
                                }

                            case "summon":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            pClient.Entity.Teleport(client.Entity.MapID, client.Entity.X, client.Entity.Y);
                                        }
                                    }
                                    break;
                                }
                            case "arrest":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            pClient.Entity.Teleport(6004, 30, 74);
                                        }
                                    }
                                    break;
                                }
                            case "pkp":
                                {
                                    client.Entity.PKPoints = ushort.Parse(Data[1]);

                                    break;
                                }

                            case "cps":
                                {
                                    client.Entity.ConquerPoints = uint.Parse(Data[1]);
                                    break;
                                }
                            case "money":
                                {
                                    client.Entity.Money = uint.Parse(Data[1]);
                                    break;
                                }

                            case "xp":
                                {
                                    client.Entity.AddFlag(Update.Flags.XPList);
                                    client.XPListStamp = Time32.Now;
                                    break;
                                }

                        }
                    }
                    if (client.Account.State == PhoenixProject.Database.AccountTable.AccountState.GameHelper)
                    {
                        switch (Data[0])
                        {
                            case "invisible":
                                Console.WriteLine("Hammy");
                                break;
                            case "arrest":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            pClient.Entity.Teleport(6004, 30, 74);
                                        }
                                    }
                                    break;
                                }
                            case "trace":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            client.Entity.Teleport(pClient.Entity.MapID, pClient.Entity.X, pClient.Entity.Y);
                                        }
                                    }
                                    break;
                                }
                            case "bring":
                                {
                                    foreach (var pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient.Entity.Name.ToLower().Contains(Data[1]) || Data[1].ToLower() == "all")
                                            if (Data[1].ToLower() == "all")
                                            {
                                                pClient.Entity.Teleport(client.Entity.MapID,
                                                    (ushort)Kernel.Random.Next(client.Entity.X - 5, client.Entity.X + 5),
                                                    (ushort)Kernel.Random.Next(client.Entity.Y - 5, client.Entity.Y + 5));
                                            }
                                            else
                                                pClient.Entity.Teleport(client.Entity.MapID, client.Entity.X, client.Entity.Y);

                                    }
                                    break;
                                }
                            case "kick":
                                {
                                    foreach (var Client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (Client.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            Client.Disconnect();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            case "ban":
                                {
                                    foreach (var Client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (Client.Account.State >= client.Account.State)
                                            continue;
                                        if (Client.Entity.Name.ToLower().Contains(Data[1]))
                                        {
                                            Client.Account.State = PhoenixProject.Database.AccountTable.AccountState.Banned;
                                            Client.Account.Savekimo();
                                            Client.Disconnect();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            case "unban":
                                {
                                    var Account = new Database.AccountTable(Data[1]);
                                    if (Account.State == PhoenixProject.Database.AccountTable.AccountState.Banned)
                                    {
                                        Account.State = PhoenixProject.Database.AccountTable.AccountState.Player;
                                        Account.Savekimo();
                                    }
                                    break;
                                }
                            case "chatban":
                                {
                                    foreach (var Client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (Client.Entity.Name.Contains(Data[1]))
                                        {
                                            Client.ChatBanLasts = uint.Parse(Data[2]);
                                            Client.ChatBanTime = DateTime.Now;
                                            Client.ChatBanned = true;
                                        }
                                    }
                                    break;
                                }

                            case "chatunban":
                                {
                                    foreach (var Client in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (Client.Entity.Name.Contains(Data[1]))
                                        {
                                            Client.ChatBanned = false;
                                        }
                                    }
                                    break;
                                }

                            case "ann":
                                {
                                    ServerBase.Kernel.SendWorldMessage(new Message("[Announce] by " + client.Entity.Name + ": " + Mess.Remove(0, 3), System.Drawing.Color.Red, Network.GamePackets.Message.Center), ServerBase.Kernel.GamePool.Values);
                                    ServerBase.Kernel.SendWorldMessage(new Message("[Announce] by " + client.Entity.Name + ": " + Mess.Remove(0, 3), System.Drawing.Color.Red, Network.GamePackets.Message.World), ServerBase.Kernel.GamePool.Values);
                                    break;
                                }
                            case "announce":
                                {
                                    ServerBase.Kernel.SendWorldMessage(new Message("[Announce] by " + client.Entity.Name + ": " + Mess.Remove(0, 8), System.Drawing.Color.Red, Network.GamePackets.Message.Center), ServerBase.Kernel.GamePool.Values);
                                    ServerBase.Kernel.SendWorldMessage(new Message("[Announce] by " + client.Entity.Name + ": " + Mess.Remove(0, 8), System.Drawing.Color.Red, Network.GamePackets.Message.World), ServerBase.Kernel.GamePool.Values);
                                    break;
                                }

                            case "record":
                                {
                                    if (client.Account.State != Database.AccountTable.AccountState.ProjectManager)
                                        break;
                                    switch (Data[1])
                                    {
                                        case "on": client.Entity.Mode = Game.Enums.Mode.Recording; break;
                                        case "off": Program.CommandsAI("/saverecord"); break;
                                    } break;
                                }
                            case "clearinventory":
                                {
                                    Interfaces.IConquerItem[] inventory = new Interfaces.IConquerItem[client.Inventory.Objects.Length];
                                    client.Inventory.Objects.CopyTo(inventory, 0);

                                    foreach (Interfaces.IConquerItem item in inventory)
                                    {
                                        client.Inventory.Remove(item, PhoenixProject.Game.Enums.ItemUse.Remove);
                                    }
                                    break;
                                }
                            case "online":
                                {
                                    client.Send(new Message("Online players count: " + ServerBase.Kernel.GamePool.Count, System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                    string line = "";
                                    foreach (Client.GameState pClient in ServerBase.Kernel.GamePool.Values)
                                        line += pClient.Entity.Name + ",";

                                    if (line.Length >= 255)
                                        return true;
                                    client.Send(new GamePackets.Message(line, System.Drawing.Color.Beige, GamePackets.Message.Talk));
                                    break;
                                }

                            case "reborn":
                                {
                                    if (client.Entity.Reborn < 2)
                                    {
                                        if (client.Entity.Class % 10 == 5)
                                        {
                                            if (client.Entity.Class != 15 &&
                                                client.Entity.Class != 25 &&
                                                client.Entity.Class != 45 &&
                                                client.Entity.Class != 55 &&
                                                client.Entity.Class != 65 &&
                                                client.Entity.Class != 135 &&
                                                client.Entity.Class != 145)
                                            {
                                                client.Send(new Message("You need to be an existing class.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                            }
                                            else
                                            {
                                                byte newclass = 10;
                                                byte.TryParse(Data[1], out newclass);
                                                if (newclass != 11 &&
                                                newclass != 21 &&
                                                newclass != 41 &&
                                                newclass != 51 &&
                                                newclass != 61 &&
                                                newclass != 132 &&
                                                newclass != 142)
                                                {
                                                    client.Send(new Message("You need to reborn into an existing class. For fire class = 142 and for waters class = 132.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                                }
                                                else
                                                {
                                                    if (!client.Reborn(newclass))
                                                        client.Send(new Message("You need atleast 2 spaces in your inventory.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                                }
                                            }
                                        }
                                        else
                                            client.Send(new Message("You need to be a master to be able to reborn.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                    }
                                    else
                                        client.Send(new Message("You can't reborn any more.", System.Drawing.Color.BurlyWood, GamePackets.Message.TopLeft));
                                    break;
                                }

                            case "dc":
                                {
                                    client.Disconnect();
                                    break;
                                }
                            case "prof":
                                {
                                    Interfaces.IProf proficiency = new GamePackets.Proficiency(true);
                                    if (Data.Length > 1)
                                        proficiency.ID = ushort.Parse(Data[1]);
                                    if (Data.Length > 2)
                                        proficiency.Level = byte.Parse(Data[2]);
                                    if (Data.Length > 3)
                                        proficiency.Experience = uint.Parse(Data[3]);
                                    client.AddProficiency(proficiency);
                                    break;
                                }
                            case "spell":
                                {
                                    Interfaces.ISkill spell = new GamePackets.Spell(true);
                                    if (Data.Length > 1)
                                        spell.ID = ushort.Parse(Data[1]);
                                    if (Data.Length > 2)
                                        spell.Level = byte.Parse(Data[2]);
                                    if (Data.Length > 3)
                                        spell.Experience = uint.Parse(Data[3]);
                                    client.AddSpell(spell);
                                    break;
                                }

                            case "level":
                                {
                                    byte level = client.Entity.Level;
                                    byte.TryParse(Data[1], out level);
                                    level = Math.Min((byte)140, Math.Max((byte)1, level));
                                    client.Entity.Level = level;
                                    client.Entity.Experience = 0;
                                    if (client.Entity.Reborn == 0)
                                    {
                                        Database.DataHolder.GetStats(client.Entity.Class, level, client);
                                        client.CalculateStatBonus();
                                        client.CalculateHPBonus();
                                        client.GemAlgorithm();
                                    }
                                    break;
                                }
                            case "class":
                                {
                                    byte _class = client.Entity.Class;
                                    byte.TryParse(Data[1], out _class);
                                    _class = Math.Min((byte)145, Math.Max((byte)1, _class));
                                    client.Entity.Class = _class;
                                    if (client.Entity.Reborn == 0)
                                    {
                                        Database.DataHolder.GetStats(_class, client.Entity.Level, client);
                                        client.CalculateStatBonus();
                                        client.CalculateHPBonus();
                                        client.GemAlgorithm();
                                    }
                                    break;
                                }
                            case "body":
                                {
                                    ushort body = client.Entity.Body;
                                    ushort.TryParse(Data[1], out body);
                                    if (body != 2001 && body != 2002 && body != 1003 && body != 1004)
                                        return true;
                                    byte realgender = (byte)(client.Entity.Body % 10);
                                    byte gender = (byte)(body % 10);
                                    if (client.Equipment.Objects[8] != null)
                                        if (gender >= 3 && realgender <= 2)
                                            return true;
                                    client.Entity.Body = body;
                                    if (gender >= 3 && realgender <= 2)
                                        client.Entity.Face -= 200;
                                    if (gender <= 2 && realgender >= 3)
                                        client.Entity.Face += 200;
                                    break;
                                }
                            case "hair":
                                {
                                    ushort hair = client.Entity.HairStyle;
                                    ushort.TryParse(Data[1], out hair);
                                    client.Entity.HairStyle = hair;
                                    break;
                                }
                            case "map":
                                {
                                    client.Send(new Message("Map: " + client.Map.ID, System.Drawing.Color.Blue, GamePackets.Message.TopLeft));
                                    break;
                                }
                            case "tele":
                                {
                                    if (Data.Length > 3)
                                    {
                                        client.Entity.Teleport(ushort.Parse(Data[1]), ushort.Parse(Data[2]), ushort.Parse(Data[3]));
                                    }
                                    break;
                                }
                            case "tele2":
                                {
                                    if (Data.Length > 3)
                                    {
                                        client.Entity.TeleportHouse(ushort.Parse(Data[1]), ushort.Parse(Data[2]), ushort.Parse(Data[3]));
                                    }
                                    break;
                                }
                            case "transform":
                                {
                                    if (client.Entity.Dead)
                                        break;
                                    bool wasTransformated = client.Entity.Transformed;
                                    if (wasTransformated)
                                    {
                                        client.Entity.Hitpoints = client.Entity.MaxHitpoints;
                                        client.Entity.TransformationID = 0;
                                        client.Entity.TransformationStamp = Time32.Now;
                                        return true;
                                    }
                                    ushort transformation = client.Entity.TransformationID;
                                    ushort.TryParse(Data[1], out transformation);
                                    client.Entity.TransformationID = transformation;
                                    client.Entity.TransformationStamp = Time32.Now;
                                    client.Entity.TransformationTime = 110;
                                    SpellUse spellUse = new SpellUse(true);
                                    spellUse.Attacker = client.Entity.UID;
                                    spellUse.SpellID = 1360;
                                    spellUse.SpellLevel = 4;
                                    spellUse.X = client.Entity.X;
                                    spellUse.Y = client.Entity.Y;
                                    spellUse.Targets.Add(client.Entity.UID, (uint)0);
                                    client.Send(spellUse);
                                    client.Entity.TransformationMaxHP = 3000;
                                    double maxHP = client.Entity.MaxHitpoints;
                                    double HP = client.Entity.Hitpoints;
                                    double point = HP / maxHP;

                                    client.Entity.Hitpoints = (uint)(client.Entity.TransformationMaxHP * point);
                                    client.Entity.Update(Update.MaxHitpoints, client.Entity.TransformationMaxHP, false);
                                    break;
                                }
                            case "item":
                                {
                                    if (Data.Length > 2)
                                    {
                                        string ItemName = Data[1];
                                        Game.Enums.ItemQuality Quality = Game.Enums.ItemQuality.Fixed;
                                        switch (Data[2].ToLower())
                                        {
                                            case "fixed": Quality = Game.Enums.ItemQuality.Fixed; break;
                                            case "normal": Quality = Game.Enums.ItemQuality.Normal; break;
                                            case "normalv1": Quality = Game.Enums.ItemQuality.NormalV1; break;
                                            case "normalv2": Quality = Game.Enums.ItemQuality.NormalV2; break;
                                            case "normalv3": Quality = Game.Enums.ItemQuality.NormalV3; break;
                                            case "refined": Quality = Game.Enums.ItemQuality.Refined; break;
                                            case "unique": Quality = Game.Enums.ItemQuality.Unique; break;
                                            case "elite": Quality = Game.Enums.ItemQuality.Elite; break;
                                            case "super": Quality = Game.Enums.ItemQuality.Super; break;
                                            case "other": Quality = Game.Enums.ItemQuality.Other; break;
                                            default:
                                                {
                                                    Quality = (PhoenixProject.Game.Enums.ItemQuality)int.Parse(Data[2]);
                                                    break;
                                                }
                                        }
                                        Database.ConquerItemBaseInformation CIBI = null;
                                        foreach (Database.ConquerItemBaseInformation infos in Database.ConquerItemInformation.BaseInformations.Values)
                                        {
                                            if (infos.Name.ToLower() == ItemName.ToLower() && Quality == (Game.Enums.ItemQuality)(infos.ID % 10))
                                            {
                                                CIBI = infos;
                                            }
                                        }
                                        if (CIBI == null)
                                            break;
                                        Interfaces.IConquerItem newItem = new GamePackets.ConquerItem(true);
                                        newItem.ID = CIBI.ID;
                                        newItem.Durability = CIBI.Durability;
                                        newItem.MaximDurability = CIBI.Durability;
                                        if (Data.Length > 3)
                                        {
                                            byte plus = 0;
                                            byte.TryParse(Data[3], out plus);
                                            newItem.Plus = Math.Min((byte)12, plus);
                                            if (Data.Length > 4)
                                            {
                                                byte bless = 0;
                                                byte.TryParse(Data[4], out bless);
                                                newItem.Bless = Math.Min((byte)7, bless);
                                                if (Data.Length > 5)
                                                {
                                                    byte ench = 0;
                                                    byte.TryParse(Data[5], out ench);
                                                    newItem.Enchant = Math.Min((byte)255, ench);
                                                    if (Data.Length > 6)
                                                    {
                                                        byte soc1 = 0;
                                                        byte.TryParse(Data[6], out soc1);
                                                        if (Enum.IsDefined(typeof(Game.Enums.Gem), soc1))
                                                        {
                                                            newItem.SocketOne = (Game.Enums.Gem)soc1;
                                                        }
                                                        if (Data.Length > 7)
                                                        {
                                                            byte soc2 = 0;
                                                            byte.TryParse(Data[7], out soc2);
                                                            if (Enum.IsDefined(typeof(Game.Enums.Gem), soc2))
                                                            {
                                                                newItem.SocketTwo = (Game.Enums.Gem)soc2;
                                                            }
                                                        }
                                                        if (Data.Length > 10)
                                                        {
                                                            byte R = 0, G = 0, B = 0;
                                                            byte.TryParse(Data[8], out R);
                                                            byte.TryParse(Data[9], out G);
                                                            byte.TryParse(Data[10], out B);
                                                            newItem.SocketProgress = (uint)(B | (G << 8) | (R << 16));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        newItem.Color = (PhoenixProject.Game.Enums.Color)ServerBase.Kernel.Random.Next(4, 8);
                                        if (client.Account.State == PhoenixProject.Database.AccountTable.AccountState.GameMaster)
                                            newItem.Bound = true;
                                        client.Inventory.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                    }
                                    break;
                                }
                        }
                        return true;
                    }
                    #endregion

                    return true;
                }
                return false;
            }
            catch { client.Send(new Message("Impossible to handle this command. Check your syntax.", System.Drawing.Color.BurlyWood, Message.TopLeft)); return false; }
        }
        static void Chat(Message message, Client.GameState client)
        {
            //Console.WriteLine("[" + client.Entity.Name + "][Chat] " + message.__Message);
            if (!CheckCommand(message, client))
            {
                if (message.ChatType != Message.Service)
                {
                    if (client.ChatBanned)
                        if (DateTime.Now > client.ChatBanTime.AddMinutes(client.ChatBanLasts))
                            client.ChatBanned = false;
                        else
                        {
                            int minutes = (int)new TimeSpan((client.ChatBanTime.AddMinutes(client.ChatBanLasts) - DateTime.Now).Ticks).TotalMinutes;
                            client.Send(new Message("You are banned from chat. You have to wait: " + minutes + " minutes before you can speak again!", System.Drawing.Color.Green, Message.Talk));
                            return;
                        }
                }
                if (client.Entity.Name == message._From)
                {
                    switch (message.ChatType)
                    {
                        case Message.HawkMessage:
                            {
                                if (client.Booth != null)
                                {
                                    client.Booth.HawkMessage = message;
                                    client.SendScreen(message, true);
                                }
                                break;
                            }
                        case Message.Talk:
                            {
                                client.SendScreen(message, false);
                                break;
                            }
                        case Message.Whisper:
                            {
                                foreach (Client.GameState pClient in ServerBase.Kernel.GamePool.Values)
                                {
                                    if (pClient != null)
                                    {
                                        if (pClient.Entity.Name == message._To)
                                        {
                                            message.Mesh = client.Entity.Mesh;
                                            pClient.Send(message);
                                            if (client.Account.State == Database.AccountTable.AccountState.GameMaster)
                                            {
                                                #region msglog
                                                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 + "\\msglog"))
                                                    Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\msglog");

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

                                                File.WriteAllText(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\msglog\\" + date + "\\" + dt.Day + ".txt",
                        File.ReadAllText(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\msglog\\" + date + "\\" + dt.Day + ".txt") +
                        "\r\n" + client.Entity.Name + " Talk to : [" + pClient.Entity.Name + "] Message: [" + message.__Message + "]");
                                                #endregion
                                            }
                                            if (client.Account.State == Database.AccountTable.AccountState.ProjectManager)
                                            {
                                                #region msglog
                                                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 + "\\msglog"))
                                                    Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\msglog");

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

                                                File.WriteAllText(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\msglog\\" + date + "\\" + dt.Day + ".txt",
                        File.ReadAllText(System.Windows.Forms.Application.StartupPath + "\\" + ServerBase.Constants.Unhandledgmlog + "\\msglog\\" + date + "\\" + dt.Day + ".txt") +
                        "\r\n" + client.Entity.Name + " Talk to : [" + pClient.Entity.Name + "] Message: [" + message.__Message + "]");
                                                #endregion
                                            }
                                            return;
                                        }
                                    }
                                }
                                foreach (Game.ConquerStructures.Society.Friend friend in client.Friends.Values)
                                {
                                    if (friend.Name == message._To)
                                    {
                                        message.__Message = message.__Message.Replace("'", "¹");
                                        client.OnMessageBoxEventParams = new object[3];
                                        client.OnMessageBoxEventParams[0] = client.Entity.UID;
                                        client.OnMessageBoxEventParams[1] = friend.ID;
                                        client.OnMessageBoxEventParams[2] = Console.TimeStamp() + message.__Message;
                                        client.OnMessageBoxOK =
                                            delegate
                                            {
                                                Database.KnownPersons.UpdateMessageOnFriend(Convert.ToUInt32(client.OnMessageBoxEventParams[0]), Convert.ToUInt32(client.OnMessageBoxEventParams[1]), Convert.ToString(client.OnMessageBoxEventParams[2]));
                                                client.Send(new Message("Message sent!", System.Drawing.Color.Green, Message.TopLeft));
                                            };
                                        client.OnMessageBoxCANCEL =
                                            delegate
                                            {
                                                client.OnMessageBoxEventParams = new object[0];
                                            };
                                        client.Send(new NpcReply(NpcReply.MessageBox, "To " + friend.Name + ": \r\n" + message.__Message + "\r\n\r\nSend? (It will replace other messages.)"));
                                        return;
                                    }
                                }
                                client.Send(new Message("The player is not online.", System.Drawing.Color.Orange, Message.Service));
                                break;
                            }
                        case Message.Service:
                            {
                                foreach (Client.GameState pClient in ServerBase.Kernel.GamePool.Values)
                                {
                                    if (pClient.Account.State == Database.AccountTable.AccountState.GameMaster || pClient.Account.State == Database.AccountTable.AccountState.ProjectManager)
                                    {
                                        message.ChatType = Message.Talk;
                                        string _Message = "Service-> " + client.Entity.Name + " needs your help. Respond to him/her right now!!!";
                                        message.__Message = _Message;
                                        pClient.Send(message);
                                        return;
                                    }
                                }
                                break;
                            }
                        case Message.World:
                            {
                                if (client.Entity.Level >= 70 || client.Entity.Reborn != 0)
                                {
                                    foreach (Client.GameState pClient in ServerBase.Kernel.GamePool.Values)
                                    {
                                        if (pClient != null)
                                        {
                                            if (pClient.Entity.UID != client.Entity.UID)
                                                message._From = client.Entity.Name;//kimozo
                                            pClient.Send(message);
                                        }
                                    }
                                }
                                break;
                            }
                        case Message.Guild:
                            {
                                if (client.Guild != null)
                                    client.Guild.SendGuildMessage(message);
                                break;
                            }
                        case Message.Team:
                            {
                                if (client.Team != null)
                                {
                                    foreach (Client.GameState Client in client.Team.Teammates)
                                    {
                                        if (client.Entity.UID != Client.Entity.UID)
                                            Client.Send(message);
                                    }
                                }
                                break;
                            }
                        case Message.Friend:
                            {
                                foreach (Game.ConquerStructures.Society.Friend friend in client.Friends.Values)
                                {
                                    if (friend.IsOnline)
                                        friend.Client.Send(message);
                                }
                                break;
                            }
                        default:
                            {
                                client.SendScreen(message, true);
                                break;
                            }

                    }
                }
                else
                {
                    client.Account.State = Database.AccountTable.AccountState.Cheat;
                    client.Account.Savekimo();
                    client.Disconnect();
                }
            }
        }
 public static void WorldMessage(string message)
 {
     Message msg = new Message(message, System.Drawing.Color.MediumBlue, Message.Center);
     foreach (Client.GameState pClient in ServerBase.Kernel.GamePool.Values)
         pClient.Send(msg);
 }
        static void ServerStuff_Execute()
        {
            if (ServerRrestart == false)
            {
                //Console.Title = "["+Database.rates.servername+"]Phoenix Conquer Project. Start time: " + StartDate.ToString("dd MM yyyy hh:mm") + ". Players online: " + ServerBase.Kernel.GamePool.Count + "/" + PlayerCap;
                // Console.WriteLine("kimozzzzzz");
                // new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("GuildID", Game.ConquerStructures.Society.Guild.GuildCounter.Now).Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", ServerBase.Constants.ServerName).Execute();
                //var Values = ServerBase.Kernel.WasInGamePool.Base.ToArray();

                if (DateTime.Now > Game.ConquerStructures.Broadcast.LastBroadcast.AddMinutes(1))
                {
                    if (Game.ConquerStructures.Broadcast.Broadcasts.Count > 0)
                    {
                        Game.ConquerStructures.Broadcast.CurrentBroadcast = Game.ConquerStructures.Broadcast.Broadcasts[0];
                        Game.ConquerStructures.Broadcast.Broadcasts.Remove(Game.ConquerStructures.Broadcast.CurrentBroadcast);
                        Game.ConquerStructures.Broadcast.LastBroadcast = DateTime.Now;
                        ServerBase.Kernel.SendWorldMessage(new Network.GamePackets.Message(Game.ConquerStructures.Broadcast.CurrentBroadcast.Message, "ALLUSERS", Game.ConquerStructures.Broadcast.CurrentBroadcast.EntityName, System.Drawing.Color.Red, Network.GamePackets.Message.BroadcastMessage), ServerBase.Kernel.GamePool.Values);
                    }
                    else
                        Game.ConquerStructures.Broadcast.CurrentBroadcast.EntityID = 1;
                }

                DateTime Now = DateTime.Now;

                if (Now > LastRandomReset.AddMinutes(30))
                {
                    LastRandomReset = Now;
                    ServerBase.Kernel.Random = new Random(RandomSeed);
                }
                Today = Now.DayOfWeek;
                if (Now >= StartDate.AddHours(12))
                 {
                     if (mess == 0)
                     {
                         foreach (Client.GameState Server in ServerBase.Kernel.GamePool.Values)
                         {
                             //if (DateTime.Now.DayOfWeek == DayOfWeek.Monday || DateTime.Now.DayOfWeek == DayOfWeek.Wednesday || DateTime.Now.DayOfWeek == DayOfWeek.Friday)
                             //{

                             PhoenixProject.Network.GamePackets.Message FiveMinute = new Network.GamePackets.Message("The server will be brought down for maintenance in 5 Minutes. Please exit the game now.", System.Drawing.Color.Red, Network.GamePackets.Message.Center);

                             Server.Send(FiveMinute);

                             // }
                         }
                         mess++;
                         messtime = Time32.Now;
                     }
                     if (mess == 1 && Time32.Now >= messtime.AddMinutes(1))
                     {
                         foreach (Client.GameState Server in ServerBase.Kernel.GamePool.Values)
                         {

                             PhoenixProject.Network.GamePackets.Message FiveMinute = new Network.GamePackets.Message("The server will be brought down for maintenance in 4 Minutes. Please exit the game now.", System.Drawing.Color.Red, Network.GamePackets.Message.Center);
                              Server.Send(FiveMinute);

                         }
                         mess++;
                         messtime = Time32.Now;
                     }
                     if (mess == 2 && Time32.Now >= messtime.AddMinutes(1))
                     {
                         foreach (Client.GameState Server in ServerBase.Kernel.GamePool.Values)
                         {

                             PhoenixProject.Network.GamePackets.Message FiveMinute = new Network.GamePackets.Message("The server will be brought down for maintenance in 3 Minutes. Please exit the game now.", System.Drawing.Color.Red, Network.GamePackets.Message.Center);
                             Server.Send(FiveMinute);

                         }
                         mess++;
                         messtime = Time32.Now;
                     }
                     if (mess == 3 && Time32.Now >= messtime.AddMinutes(1))
                     {
                         foreach (Client.GameState Server in ServerBase.Kernel.GamePool.Values)
                         {

                             PhoenixProject.Network.GamePackets.Message FiveMinute = new Network.GamePackets.Message("The server will be brought down for maintenance in 2 Minutes. Please exit the game now.", System.Drawing.Color.Red, Network.GamePackets.Message.Center);
                             Server.Send(FiveMinute);

                         }
                         mess++;
                         messtime = Time32.Now;
                     }
                     if (mess == 4 && Time32.Now >= messtime.AddMinutes(1))
                     {
                         foreach (Client.GameState Server in ServerBase.Kernel.GamePool.Values)
                         {

                             PhoenixProject.Network.GamePackets.Message FiveMinute = new Network.GamePackets.Message("The server will be brought down for maintenance in 1 Minute. Please exit the game now.", System.Drawing.Color.Red, Network.GamePackets.Message.Center);
                             Server.Send(FiveMinute);

                         }
                         mess++;
                         messtime = Time32.Now;
                     }
                }
                if (Now >= StartDate.AddHours(12) && !restarted && mess == 5)
                {
                    CommandsAI("@restart");
                    restarted = true;
                    ServerRrestart = true;
                    return;
                }
                  var Values = ServerBase.Kernel.WasInGamePool.Base.ToArray();

                  foreach (KeyValuePair<uint, Client.GameState> vals in Values)
                  {
                      Client.GameState client = vals.Value;

                      if (client == null || client.Entity == null || client.Account == null)
                      {
                          ServerBase.Kernel.WasInGamePool.Remove(vals.Key);
                          //Console.WriteLine("kimo4");
                          return;
                      }
                      if (client.Disconnected2 == true)
                          return;
                      if (client.Socket != null)
                      {

                          if (!client.Socket.Connected)
                          {
                              Database.EntityTable.SaveEntity(client);
                              Database.SkillTable.SaveProficiencies(client);
                              Database.SkillTable.SaveSpells(client);
                              Database.ArenaTable.SaveArenaStatistics(client.ArenaStatistic);
                              ServerBase.Kernel.WasInGamePool.Remove(vals.Key);
                              Database.EntityTable.UpdateOnlineStatus(client, false);
                              if (ServerBase.Kernel.GamePool.ContainsKey(vals.Key))
                              {
                                  ServerBase.Kernel.GamePool.Remove(vals.Key);
                              }
                              if (ServerBase.Kernel.WasInGamePool.ContainsKey(vals.Key))
                              {
                                  ServerBase.Kernel.WasInGamePool.Remove(vals.Key);
                              }

                              /*if (ServerBase.Kernel.AwaitingPool.ContainsKey(vals.Key))
                              {
                                  ServerBase.Kernel.AwaitingPool.Remove(vals.Key);
                              }*/
                              // Console.WriteLine("kimo5");
                              //Database.FlowerSystemTable.SaveFlowerTable(client);
                              if (client.Socket != null)
                              {
                                  if (!client.SocketDisposed)
                                  {

                                      // Monitor.Exit(_socket);
                                      // Monitor.Exit(Cryptography);
                                      // Console.WriteLine(" Close4 ");
                                      client.SocketDisposed = true;
                                      client.Socket.Disconnect(false);
                                      client.Socket.Shutdown(System.Net.Sockets.SocketShutdown.Both);
                                      client.Socket.Close();
                                  }
                              }
                          }
                      }
                      else
                      {

                          Database.EntityTable.SaveEntity(client);
                          Database.SkillTable.SaveProficiencies(client);
                          Database.SkillTable.SaveSpells(client);
                          Database.ArenaTable.SaveArenaStatistics(client.ArenaStatistic);
                          if (ServerBase.Kernel.WasInGamePool.ContainsKey(vals.Key))
                          {
                              ServerBase.Kernel.WasInGamePool.Remove(vals.Key);
                          }
                          if (ServerBase.Kernel.GamePool.ContainsKey(vals.Key))
                          {
                              ServerBase.Kernel.GamePool.Remove(vals.Key);
                          }
                          Database.EntityTable.UpdateOnlineStatus(client, false);

                      }
                  }

                // Thread.Sleep(1000);
            }
        }
 public void SendStatMessage()
 {
     this.ReviewMentor();
     Network.GamePackets.Message Msg = new PhoenixProject.Network.GamePackets.Message(" Your status has been changed", System.Drawing.Color.DarkGoldenrod
         , Network.GamePackets.Message.TopLeft);
     Msg.__Message = string.Format(Msg.__Message,
         new object[] { Entity.MinAttack, Entity.MaxAttack, Entity.MagicAttack, Entity.Defence, (Entity.MagicDefence + Entity.MagicDefence), Entity.Dodge, Entity.PhysicalDamageDecrease, Entity.MagicDamageDecrease, Entity.PhysicalDamageIncrease, Entity.MagicDamageIncrease, Entity.Hitpoints, Entity.MaxHitpoints, Entity.Mana, Entity.MaxMana, Entity.BattlePower });
     this.Send(Msg);
 }
        public static void Win(Client.GameState winner, Client.GameState loser)
        {
            if (winner == null && loser != null)
            {
                loser.ArenaStatistic.PlayWith = 0;
                loser.ArenaStatistic.AcceptBox = false;
                if (loser.ArenaStatistic.ArenaPoints > 80000)
                    loser.ArenaStatistic.ArenaPoints = 0;
                ArenaSignup sign = new ArenaSignup();
                sign.DialogID = ArenaSignup.MainIDs.Match;
                loser.Send(sign.BuildPacket());

                sign = new ArenaSignup();
                sign.DialogID = ArenaSignup.MainIDs.Match;
                sign.OptionID = ArenaSignup.DialogButton.MatchOff;
                loser.Send(sign.BuildPacket());
                if (loser.ArenaStatistic.ArenaPoints == 0)
                {
                    QualifyEngine.DoQuit(loser);
                }
                loser.ArenaStatistic.TotalLose++;

                Sort();
                loser.Send(loser.ArenaStatistic);
                QualifyEngine.DoQuit(loser);

            }
            else if (loser == null && winner != null)
            {
                winner.ArenaStatistic.PlayWith = 0;
                winner.ArenaStatistic.AcceptBox = false;
                winner.ArenaStatistic.TodayWin++;
                winner.ArenaStatistic.TotalWin++;
                ArenaSignup sign = new ArenaSignup();
                sign.DialogID = ArenaSignup.MainIDs.Match;
                sign.OptionID = ArenaSignup.DialogButton.Win;
                winner.Send(sign.BuildPacket());

                sign = new ArenaSignup();
                sign.DialogID = ArenaSignup.MainIDs.Match;
                sign.OptionID = ArenaSignup.DialogButton.MatchOff;
                winner.Send(sign.BuildPacket());
                Sort();
                QualifyEngine.DoQuit(winner);
                winner.Send(winner.ArenaStatistic);
            }
            else if (loser == null && winner == null)
            {
                return;
            }
            else
            {
                if (winner.ArenaStatistic.PlayWith != 0 && loser.ArenaStatistic.PlayWith != 0)
                {
                    int diff = (int)winner.ArenaStatistic.ArenaPoints - (int)loser.ArenaStatistic.ArenaPoints;
                    diff = diff < 0 ? -diff : diff;
                    if (diff == 0 || diff > 50)
                        diff = ServerBase.Kernel.Random.Next(30, 50);

                    ArenaSignup sign = new ArenaSignup();
                    sign.DialogID = ArenaSignup.MainIDs.Match;
                    loser.Send(sign.BuildPacket());
                    sign.OptionID = ArenaSignup.DialogButton.Win;
                    winner.Send(sign.BuildPacket());

                    sign = new ArenaSignup();
                    sign.DialogID = ArenaSignup.MainIDs.Match;
                    sign.OptionID = ArenaSignup.DialogButton.MatchOff;
                    loser.Send(sign.BuildPacket());
                    winner.Send(sign.BuildPacket());

                    winner.ArenaStatistic.PlayWith = 0;
                    loser.ArenaStatistic.PlayWith = 0;
                    winner.ArenaStatistic.AcceptBox = false;
                    loser.ArenaStatistic.AcceptBox = false;
                    winner.ArenaStatistic.ArenaPoints += (uint)diff;
                    Message message = null;
                    message = new Message("" + winner.ArenaStatistic.Name + " has Defeated " + loser.ArenaStatistic.Name + " in the Qualifier, and is currently ranked No. " + winner.ArenaStatistic.Rank + "!", System.Drawing.Color.Red, Message.Qualifier);
                    foreach (Client.GameState client in ServerBase.Kernel.GamePool.Values)
                    {
                        client.Send(message);
                    }
                    loser.ArenaStatistic.ArenaPoints -= (uint)diff;
                    if (loser.ArenaStatistic.ArenaPoints > 80000)
                        loser.ArenaStatistic.ArenaPoints = 0;
                    if (loser.ArenaStatistic.ArenaPoints == 0)
                        QualifyEngine.DoQuit(loser);

                    winner.ArenaStatistic.TodayWin++;
                    winner.ArenaStatistic.TotalWin++;
                    if (winner.ArenaStatistic.TodayWin == 9)
                        winner.IncreaseExperience(winner.ExpBall, false);
                    if (winner.ArenaStatistic.TodayBattles == 20)
                        winner.IncreaseExperience(winner.ExpBall, false);
                    if (loser.ArenaStatistic.TodayBattles == 20)
                        loser.IncreaseExperience(loser.ExpBall, false);
                    loser.ArenaStatistic.TotalLose++;

                    Sort();
                    winner.Send(winner.ArenaStatistic);
                    loser.Send(loser.ArenaStatistic);
                    QualifyEngine.DoQuit(winner);
                    QualifyEngine.DoQuit(loser);

                    winner.QualifierGroup = null;
                    loser.QualifierGroup = null;

                    _String str = new _String(true);
                    str.UID = winner.Entity.UID;
                    str.TextsCount = 1;
                    str.Type = _String.Effect;
                    str.Texts.Add("sports_victory");
                    winner.SendScreen(str, true);

                    _String strs = new _String(true);
                    strs.UID = loser.Entity.UID;
                    strs.TextsCount = 1;
                    strs.Type = _String.Effect;
                    strs.Texts.Add("sports_failure");
                    loser.SendScreen(strs, true);
                }
            }
        }
 public void Disband()
 {
     var members = Members.Values.ToArray();
     foreach (Member member in members)
     {
         uint uid = member.ID;
         if (member.IsOnline)
         {
             GuildCommand command = new GuildCommand(true);
             command.Type = GuildCommand.Disband;
             command.dwParam = ID;
             member.Client.Entity.GuildID = 0;
             member.Client.Entity.GuildRank = 0;
             member.Client.Send(command);
             member.Client.Screen.FullWipe();
             member.Client.Screen.Reload(null);
             member.Client.AsMember = null;
             member.Client.Guild = null;
             Message message = null;
             message = new Message("guild " + Name + " has been Disbanded!", System.Drawing.Color.White, Message.World);
             foreach (Client.GameState client in ServerBase.Kernel.GamePool.Values)
             {
                 client.Send(message);
             }
         }
         else
         {
             member.GuildID = 0;
         }
         if (member.IsOnline == true)
         {
             foreach (Interfaces.IConquerItem Equi in member.Client.Inventory.Objects)
             {
                 if (Equi != null)
                 {
                     if (Equi.Inscribed)
                     {
                         Equi.Inscribed = false;
                         Equi.Send(member.Client);
                     }
                 }
             }
             foreach (Interfaces.IConquerItem Equi in member.Client.Equipment.Objects)
             {
                 if (Equi != null)
                 {
                     if (Equi.Inscribed)
                     {
                         Equi.Inscribed = false;
                         Equi.Send(member.Client);
                     }
                 }
             }
         }
         Database.ConquerItemTable.UpdateInscre3(uid);
         MemberCount--;
         Members.Remove(uid);
     }
     var ally_ = Ally.Values.ToArray();
     foreach (Guild ally in ally_)
     {
         RemoveAlly(ally.Name);
         ally.RemoveAlly(Name);
     }
     Database.GuildTable.Disband(this);
     //shit? ServerBase.Kernel.GamePool.Remove(ID);
 }
 public bool Create(string name)
 {
     if (name.Length < 16)
     {
         Name = name;
         SilverFund = 500000;
         Members.Add(Leader.ID, Leader);
         try
         {
             Database.GuildTable.Create(this);
         }
         catch { return false; }
         ServerBase.Kernel.Guilds.Add(ID, this);
         Message message = null;
         message = new Message("Congratulations, " + leaderName + " has created guild " + name + " Succesfully!", System.Drawing.Color.White, Message.World);
         foreach (Client.GameState client in ServerBase.Kernel.GamePool.Values)
         {
             client.Send(message);
         }
         return true;
     }
     return false;
 }
 public void DeamDeathS()
 {
     string[] scores = new string[5];
     scores[0] = "Black Team: " + Game.ConquerStructures.TeamDeathMatchScore.BlackTeamScore + " Score";
     scores[1] = "White Team: " + Game.ConquerStructures.TeamDeathMatchScore.WhiteTeamScore + " Score";
     scores[2] = "Blue  Team: " + Game.ConquerStructures.TeamDeathMatchScore.BlueTeamScore + " Score";
     scores[3] = "Red   Team: " + Game.ConquerStructures.TeamDeathMatchScore.RedTeamScore + " Score";
     scores[4] = "Your Score: " + Entity.TeamDeathMatch_Kills + " kills";
     for (int i = 0; i < scores.Length; i++)
     {
         Message msg = new Message(scores[i], System.Drawing.Color.Red, i == 0 ? Message.FirstRightCorner : Message.ContinueRightCorner);
         Send(msg);
     }
 }
        private void ShutDown()
        {
            try
            {
                if (Disconnected)
                    return;
                if (Logger != null)
                {
                    Logger.Close();
                    Logger = null;
                }

                if (this != null && this.Entity != null)
                {
                    if (this.JustCreated)
                        return;
                    if (ServerBase.Kernel.GamePool.ContainsKey(Account.EntityID))
                    {
                        ServerBase.Kernel.GamePool.Remove(Account.EntityID);
                    }
                    if (ServerBase.Kernel.WasInGamePool.ContainsKey(Account.EntityID))
                    {
                        ServerBase.Kernel.WasInGamePool.Remove(Account.EntityID);
                    }
                    //if (ServerBase.Kernel.AwaitingPool.ContainsKey(Account.EntityID))
                    //{
                    //    ServerBase.Kernel.AwaitingPool.Remove(Account.EntityID);
                    //}
                    Time32 now = Time32.Now;
                    RemoveScreenSpawn(this.Entity, false);
                    /* for (byte i = 1; i < 12; i++)
                     {
                         Interfaces.IConquerItem item = this.Equipment.TryGetItem(i);
                         if (item != null && item.ID != 0)
                         {
                             Database.ConquerItemTable.PonerDurabilidad(item);
                         }
                     }*/
                    if (this.Entity.ContainsFlag2(Network.GamePackets.Update.Flags2.CaryingFlag))
                    {

                        Game.Team.RedCapture = false;
                        Game.Team.BlueCapture = false;
                        Game.Team.BlackCapture = false;
                        Game.Team.WhiteCapture = false;
                    }
                    if (this.Entity.ContainsFlag(Update.Flags.Dead))
                    {
                        if (this.Entity.MapID == 1038 && DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                        {
                            if (DateTime.Now.Hour >= 19 && DateTime.Now.Hour < 20 && DateTime.Now.Minute > 29)
                            {
                                this.Entity.Teleport(6001, 31, 74);
                            }
                        }
                    }

                    if (Booth != null)
                    {
                        Booth.Remove();
                    }

                    //Database.SubClassTable.save(this.Entity);
                    //Database.FlowerSystemTable.SaveFlowerTable(this);

                    if (Companion != null)
                    {
                        Map.RemoveEntity(Companion);
                        Data data = new Data(true);
                        data.UID = Companion.UID;
                        data.ID = Data.RemoveEntity;
                        Companion.MonsterInfo.SendScreen(data);
                    }
                    if (QualifierGroup != null)
                        QualifierGroup.End(this);

                    if (ArenaStatistic.Status != Network.GamePackets.ArenaStatistic.NotSignedUp)
                        Game.ConquerStructures.Arena.QualifyEngine.DoQuit(this);

                    Database.FlowerSystemTable.SaveFlowerTable(this);
                    Database.EntityTable.SaveEntity(this);

                    Database.SkillTable.SaveProficiencies(this);
                    Database.SkillTable.SaveSpells(this);

                    Database.ArenaTable.SaveArenaStatistics(this.ArenaStatistic);

                    RemoveScreenSpawn(this.Entity, false);
                    Database.EntityTable.UpdateOnlineStatus(this, false);

                    string name200 = Entity.Name;
                    string name300 = Entity.NewName;
                    if (Entity.NewName != "")
                    {
                        // Console.WriteLine("Change Name In Progress");
                        if (Entity.NewName != "")
                        {
                            PhoenixProject.Database.MySqlCommand cmdupdate = null;
                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("apprentice").Set("MentorName", Entity.NewName).Where("MentorID", Entity.UID).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("apprentice").Set("ApprenticeName", Entity.NewName).Where("ApprenticeID", Entity.UID).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("elitepk").Set("Name", Entity.NewName).Where("UID", Entity.UID).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopArcher", Entity.NewName).Where("TopArcher", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopPirate", Entity.NewName).Where("TopPirate", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopTrojan", Entity.NewName).Where("TopTrojan", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopGuildLeader", Entity.NewName).Where("TopGuildLeader", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopNinja", Entity.NewName).Where("TopNinja", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopMonk", Entity.NewName).Where("TopMonk", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopWarrior", Entity.NewName).Where("TopWarrior", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopSpouse", Entity.NewName).Where("TopSpouse", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopWaterTaoist", Entity.NewName).Where("TopWaterTaoist", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopFireTaoist", Entity.NewName).Where("TopFireTaoist", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("MonthlyPkChampion", Entity.NewName).Where("MonthlyPkChampion", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("WeeklyPkChampion", Entity.NewName).Where("WeeklyPkChampion", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopDeputyLeader", Entity.NewName).Where("TopDeputyLeader", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopDeputyLeader2", Entity.NewName).Where("TopDeputyLeader2", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopDeputyLeader3", Entity.NewName).Where("TopDeputyLeader3", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopDeputyLeader4", Entity.NewName).Where("TopDeputyLeader4", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("flags").Set("TopDeputyLeader5", Entity.NewName).Where("TopDeputyLeader5", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("arena").Set("EntityName", Entity.NewName).Where("EntityID", Entity.UID).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("claimitems").Set("OwnerName", Entity.NewName).Where("OwnerName", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("claimitems").Set("GainerName", Entity.NewName).Where("GainerName", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("detaineditems").Set("OwnerName", Entity.NewName).Where("OwnerName", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("detaineditems").Set("GainerName", Entity.NewName).Where("GainerName", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("enemy").Set("EnemyName", Entity.NewName).Where("EnemyID", Entity.UID).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("friends").Set("FriendName", Entity.NewName).Where("FriendID", Entity.UID).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("guilds").Set("Name", Entity.NewName).Where("Name", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("guilds").Set("LeaderName", Entity.NewName).Where("LeaderName", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("clans").Set("Leader", Entity.NewName).Where("Leader", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("nobility").Set("EntityName", Entity.NewName).Where("EntityUID", Entity.UID).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("partners").Set("PartnerName", Entity.NewName).Where("PartnerID", Entity.UID).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("entities").Set("Spouse", Entity.NewName).Where("Spouse", Entity.Name).Execute();

                            cmdupdate = new PhoenixProject.Database.MySqlCommand(PhoenixProject.Database.MySqlCommandType.UPDATE);
                            cmdupdate.Update("entities").Set("Name", Entity.NewName).Where("Name", Entity.Name).Execute();

                            if (Game.ConquerStructures.Nobility.Board.ContainsKey(Entity.UID))
                            {
                                Game.ConquerStructures.Nobility.Board[Entity.UID].Name = Entity.NewName;
                            }
                            if (Game.ConquerStructures.Arena.ArenaStatistics.ContainsKey(Entity.UID))
                            {
                                Game.ConquerStructures.Arena.ArenaStatistics[Entity.UID].Name = Entity.NewName;
                            }

                            if (Guild != null)
                            {
                                if (Guild.LeaderName == name200)
                                {
                                    ServerBase.Kernel.Guilds[Guild.ID].LeaderName = Entity.NewName;
                                    ServerBase.Kernel.Guilds[Guild.ID].Members[Entity.UID].Name = Entity.NewName;
                                }
                            }
                            if (Entity.ClanId != 0 && Entity.Myclan != null)
                            {
                                if (Entity.Myclan.ClanLider == name200)
                                {
                                    PhoenixProject.ServerBase.Kernel.ServerClans[Entity.ClanId].ClanLider = Entity.NewName;
                                    PhoenixProject.ServerBase.Kernel.ServerClans[Entity.ClanId].Members[Entity.UID].Name = Entity.NewName;
                                }
                            }
                            //foreach (Client.GameState c in ServerBase.Kernel.GamePool.Values)
                            //{
                            //   if(c.Enemy.ContainsKey(Entity.UID))
                            //    {

                            //        var packet = new KnownPersons(true)
                            //        {
                            //            UID = Entity.UID,
                            //            Type = KnownPersons.RemovePerson,
                            //            Name = name200,
                            //            Online = false
                            //        };
                            //        c.Send(packet);
                            //        c.Enemy[Entity.UID].Name = Entity.NewName;
                            //        packet.Type = KnownPersons.AddEnemy;
                            //        c.Send(packet);
                            //    }
                            //}
                        }
                    }

                    #region Friend/TradePartner/Apprentice
                    Message msg = new Message("Your friend, " + name200 + ", has logged off.", System.Drawing.Color.Red, Message.TopLeft);
                    if (Friends == null)
                        Friends = new SafeDictionary<uint, PhoenixProject.Game.ConquerStructures.Society.Friend>(100);
                    foreach (Game.ConquerStructures.Society.Friend friend in Friends.Values)
                    {
                        if (friend.IsOnline)
                        {
                            var packet = new KnownPersons(true)
                            {
                                UID = Entity.UID,
                                Type = KnownPersons.RemovePerson,
                                Name = name200,
                                Online = false
                            };
                            friend.Client.Send(packet);
                            if (Entity.NewName != "")
                            {
                                if (friend.Client.Friends.ContainsKey(Entity.UID))
                                {
                                    friend.Client.Friends[Entity.UID].Name = Entity.NewName;
                                }
                            }
                            packet.Type = KnownPersons.AddFriend;
                            if (friend != null)
                            {
                                if (friend.Client != null)
                                {
                                    friend.Client.Send(packet);
                                    friend.Client.Send(msg);
                                }
                            }
                        }
                    }
                    Message msg2 = new Message("Your partner, " + name200 + ", has logged off.", System.Drawing.Color.Red, Message.TopLeft);

                    foreach (Game.ConquerStructures.Society.TradePartner partner in Partners.Values)
                    {
                        if (partner.IsOnline)
                        {
                            var packet = new TradePartner(true)
                            {
                                UID = Entity.UID,
                                Type = TradePartner.BreakPartnership,
                                Name = name200,
                                HoursLeft = (int)(new TimeSpan(partner.ProbationStartedOn.AddDays(3).Ticks).TotalHours - new TimeSpan(DateTime.Now.Ticks).TotalHours),
                                Online = false
                            };
                            partner.Client.Send(packet);
                            if (Entity.NewName != "")
                            {
                                if (partner.Client.Partners.ContainsKey(Entity.UID))
                                {
                                    partner.Client.Partners[Entity.UID].Name = Entity.NewName;
                                }
                            }

                            packet.Type = TradePartner.AddPartner;
                            if (partner != null)
                            {
                                if (partner.Client != null)
                                {
                                    partner.Client.Send(packet);
                                    partner.Client.Send(msg2);
                                }
                            }
                        }
                    }
                    MentorInformation Information = new MentorInformation(true);
                    Information.Mentor_Type = 1;
                    Information.Mentor_ID = Entity.UID;
                    Information.Mentor_Level = Entity.Level;
                    Information.Mentor_Class = Entity.Class;
                    Information.Mentor_PkPoints = Entity.PKPoints;
                    Information.Mentor_Mesh = Entity.Mesh;
                    Information.Mentor_Online = false;
                    Information.String_Count = 3;
                    Information.Mentor_Name = name200;
                    Information.Mentor_Spouse_Name = Entity.Spouse;
                    foreach (var appr in Apprentices.Values)
                    {
                        if (appr.IsOnline)
                        {
                            Information.Apprentice_ID = appr.ID;
                            Information.Enrole_Date = appr.EnroleDate;
                            Information.Apprentice_Name = appr.Name;
                            appr.Client.Send(Information);
                            appr.Client.ReviewMentor();
                            if (Entity.NewName != "")
                            {
                                if (appr.Client.Apprentices.ContainsKey(Entity.UID))
                                {
                                    appr.Client.Apprentices[Entity.UID].Name = Entity.NewName;
                                }
                            }
                        }
                    }
                    if (Mentor != null)
                    {
                        if (Mentor.IsOnline)
                        {
                            ApprenticeInformation AppInfo = new ApprenticeInformation();
                            AppInfo.Apprentice_ID = Entity.UID;
                            AppInfo.Apprentice_Level = Entity.Level;
                            AppInfo.Apprentice_Name = name200;
                            AppInfo.Apprentice_Online = false;
                            AppInfo.Apprentice_Spouse_Name = Entity.Spouse;
                            AppInfo.Enrole_date = Mentor.EnroleDate;
                            AppInfo.Mentor_ID = Mentor.Client.Entity.UID;
                            AppInfo.Mentor_Mesh = Mentor.Client.Entity.Mesh;
                            AppInfo.Mentor_Name = Mentor.Client.Entity.Name;
                            AppInfo.Type = 2;
                            Mentor.Client.Send(AppInfo);
                        }
                    }

                    #endregion
                    if (Team != null)
                    {
                        if (Team.TeamLeader)
                        {
                            Network.GamePackets.Team team = new Team();
                            team.UID = Account.EntityID;
                            team.Type = Network.GamePackets.Team.Dismiss;
                            foreach (Client.GameState Teammate in Team.Teammates)
                            {
                                if (Teammate != null)
                                {
                                    if (Teammate.Entity.UID != Account.EntityID)
                                    {
                                        Teammate.Send(team);
                                        Teammate.Team = null;
                                    }
                                }
                            }
                        }
                        else
                        {
                            Network.GamePackets.Team team = new Team();
                            team.UID = Account.EntityID;
                            team.Type = Network.GamePackets.Team.ExitTeam;
                            foreach (Client.GameState Teammate in Team.Teammates)
                            {
                                if (Teammate != null)
                                {
                                    if (Teammate.Entity.UID != Account.EntityID)
                                    {
                                        Teammate.Send(team);
                                        Teammate.Team.Remove(Account.EntityID);
                                    }
                                }
                            }
                        }
                    }
                    if (Account.TempID == 400)
                    {
                        Account.EntityID = 0;
                        Account.Save();
                    }
                    if (!Disconnected)
                    {
                        Console.WriteLine(this.Entity.Name + " has logged off! Ip:[" + this.Account.IP + "]");
                        Console.Title = "[" + Database.rates.servername + "]Kimo Proj. Start time: " + Program.StartDate.ToString("dd MM yyyy hh:mm") + ". Players online: " + ServerBase.Kernel.GamePool.Count + "/" + Program.PlayerCap + " Max Online: " + Program.MaxOn + "";
                    }
                    Disconnected = true;
                    try
                    {
                        if (_socket != null)
                        {
                            // Console.WriteLine(" Close1 ");
                            if (_socket.Connected)
                            {
                                // Console.WriteLine(" Close2 ");
                                if (!SocketDisposed)
                                {
                                    //Monitor.Exit(_socket);
                                    // Monitor.Exit(Cryptography);
                                    // Console.WriteLine(" Close3 ");
                                    SocketDisposed = true;
                                    _socket.Disconnect(false);
                                    _socket.Shutdown(SocketShutdown.Both);
                                    _socket.Close();
                                    _socket = null;
                                }
                            }

                        }
                    }
                    catch (Exception e)
                    {
                        Program.SaveException(e);
                        //Disabled = true;
                    }

                }
            }
            catch (Exception e)
            {
                Program.SaveException(e);
                if (ServerBase.Kernel.GamePool.ContainsKey(Account.EntityID))
                {
                    ServerBase.Kernel.GamePool.Remove(Account.EntityID);
                }
                if (ServerBase.Kernel.WasInGamePool.ContainsKey(Account.EntityID))
                {
                    ServerBase.Kernel.WasInGamePool.Remove(Account.EntityID);
                }
                //if (ServerBase.Kernel.AwaitingPool.ContainsKey(Account.EntityID))
                //{
                //    ServerBase.Kernel.AwaitingPool.Remove(Account.EntityID);
                //}
                RemoveScreenSpawn(this.Entity, false);
                Database.EntityTable.UpdateOnlineStatus(this, false);
                if (Account.TempID == 400)
                {
                    Account.EntityID = 0;
                    Account.Save();
                }
                if (!Disconnected)
                {
                    Console.WriteLine(this.Entity.Name + " has logged off! Ip:[" + this.Account.IP + "] Temp");
                    Console.Title = "[" + Database.rates.servername + "]Kimo Proj. Start time: " + Program.StartDate.ToString("dd MM yyyy hh:mm") + ". Players online: " + ServerBase.Kernel.GamePool.Count + "/" + Program.PlayerCap + " Max Online: " + Program.MaxOn + "";
                }
                Disconnected = true;
                try
                {
                    if (_socket != null)
                    {
                        // Console.WriteLine(" Close1 ");
                        if (_socket.Connected)
                        {
                            // Console.WriteLine(" Close2 ");
                            if (!SocketDisposed)
                            {

                                SocketDisposed = true;
                                _socket.Disconnect(false);
                                _socket.Shutdown(SocketShutdown.Both);
                                _socket.Close();
                                _socket = null;
                            }
                        }

                    }
                }
                catch (Exception ex)
                {
                    Program.SaveException(ex);
                    //Disabled = true;
                }

            }
        }
 public void UpdateQuarantineScore()
 {
     string[] scores = new string[3];
     scores[0] = "Black team: " + PhoenixProject.Game.ConquerStructures.Quarantine.BlackScore.ToString() + " wins";
     scores[1] = "White team: " + PhoenixProject.Game.ConquerStructures.Quarantine.WhiteScore.ToString() + " wins";
     scores[2] = "Your score: " + quarantineKill + " kills, " + quarantineDeath + " death";
     for (int i = 0; i < scores.Length; i++)
     {
         Message msg = new Message(scores[i], System.Drawing.Color.Red, i == 0 ? Message.FirstRightCorner : Message.ContinueRightCorner);
         Send(msg);
     }
 }
        public static void SendScores()
        {
            if (scoreMessages == null)
                scoreMessages = new string[0];
            if (Scores.Count == 0)
                return;
            if (changed)
                SortScores(out CurrentTopLeader);

            for (int c = 0; c < scoreMessages.Length; c++)
            {
                Message msg = new Message(scoreMessages[c], System.Drawing.Color.Red, c == 0 ? Message.FirstRightCorner : Message.ContinueRightCorner);
                ServerBase.Kernel.SendWorldMessage(msg, ServerBase.Kernel.GamePool.Values, (ushort)1038);
                ServerBase.Kernel.SendWorldMessage(msg, ServerBase.Kernel.GamePool.Values, (ushort)6001);
            }
        }
 public static void CaptureRes(Client.GameState client)
 {
     string[] scores = new string[5];
     scores[0] = "CaptureTheFlag PkWar:";
     scores[1] = "Red   Team Score: "+ RScore +"";
     scores[2] = "Blue  Team Score: "+ BScore +"";
     scores[3] = "Black Team Score: "+ BLScore +"";
     scores[4] = "White Team Score: "+ WScore +"";
     // scores[3] = "Red   Team: " + Game.ConquerStructures.TeamDeathMatchScore.RedTeamScore + " Score";
     //scores[4] = "Your Score: " + Entity.TeamDeathMatch_Kills + " kills";
     for (int i = 0; i < scores.Length; i++)
     {
         Message msg = new Message(scores[i], System.Drawing.Color.Red, i == 0 ? Message.FirstRightCorner : Message.ContinueRightCorner);
         client.Send(msg);
     }
 }
        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
            }
        }