Exemplo n.º 1
0
        public void HandleChat(string[] str2, string str)
        {
            if (str2[0] == "@go")
            {
                if (str2.Count() > 1)
                {
                    HandleGo(str2[1]);
                }
            }
            else if (str2[0] == "@commands")
            {
                UpdateChat("@go, @bug, @rank, @reset, @automp 0.10, @autohp 0.10, ");
                UpdateChat("@addstat str 100, @remitee, @autoloot, @autohit ");
                UpdateChat("@bankslot 0 (1,2..), @ping, @stats, @pkstats ");
            }
            else if (str[0] == '!')
            {
                var message = str.Remove(0, 1);
                message = "[" + player.Name + "] : " + message;
                World.SendToAll(new QueDele(player.Serial, "all", new UpdateChatBox(0xff, 0xff, 0x95, (short)message.Count(), message).Compile()));
            }
            else if (str[0] == '~' || str2[0] == "@tele" || str2[0] == "@learn" ||
                     str2[0] == "@invis" || str2[0] == "@createitem" || str2[0] == "@kick")
            {
                HandleGMChat(str2);
            }
            else if (str == "promote me")
            {
                var AronNpc = World.NewNpcs.Where(xe => xe.Value.Name == "Aron").FirstOrDefault();
                if (AronNpc.Value != null && World.Dist2d(player.X, player.Y, AronNpc.Value.X, AronNpc.Value.Y) < 7 &&
                    player.Level >= 80)
                {
                    if (AronStage == 0)
                    {
                        string achat = "[Aron]: Bring the life of drug from Alias.";
                        SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)achat.Count(), achat).Compile());
                        AronStage = 4;
                    }
                }
            }
            else if (str2[0] == "@drops")
            {
            }
            else if (str2[0] == "@ping")
            {
                long totalTime = 0;
                int  timeout   = 60;
                System.Net.NetworkInformation.Ping pingSender = new Ping();

                for (int i = 0; i < 1; i++)
                {
                    PingReply reply = pingSender.Send(connection.RemoteEndPoint.Address, timeout);
                    if (reply.Status == IPStatus.Success)
                    {
                        totalTime += reply.RoundtripTime;
                    }
                }
                long   res   = totalTime / 1;
                string achat = res + " ms";
                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)achat.Count(), achat).Compile());
            }
            else if (str == "give me the life drug")
            {
                if (player.m_Map == "Village1" && World.Dist2d(player.Loc, new Point2D(90, 173)) <= 4)
                {
                    AliasStage = 1;
                    string achat = "[Alias]: I have a life drug. Do you need it?";
                    SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)achat.Count(), achat).Compile());
                }
            }
            else if (str2[0] == "@bug")
            {
                if (LKCamelot.Server.tickcount.ElapsedMilliseconds - 3000 > lastcmd)
                {
                    lastcmd = LKCamelot.Server.tickcount.ElapsedMilliseconds;

                    string bug = player.Name + " : " + str.Substring(4);
                    Console.WriteLine(bug);
                    WriteBug(bug);
                    string achat = "Bug report sent.";
                    SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)achat.Count(), achat).Compile());
                }
                else
                {
                    string achat = "Please wait before issuing another command.";
                    SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)achat.Count(), achat).Compile());
                }
            }
            else if (str2[0] == "@bankslot")
            {
                try { Convert.ToInt32(str2[1]); }
                catch { return; }
                player.BankTab = Convert.ToInt32(str2[1]);
                var invslots = (player.BankTab * 12) + 40;
                for (int x = 0; x < 12; x++)
                {
                    SendPacket(new DeleteEntrustSlot((byte)x).Compile());
                }
                foreach (var itm in player.BankContent.Where(xe => xe.InvSlot >= invslots && xe.InvSlot < (invslots + 12)))
                {
                    SendPacket(new AddItemToEntrust(itm).Compile());
                }
            }
            else if (str == "@reset")
            {
                if (player.GetFreeSlots() > 5)
                {
                    foreach (var it in player.Equipped2.Values)
                    {
                        it.Unequip(player, it.InvSlot);
                    }

                    var total = player.m_Str + player.m_Dex + player.m_Men + player.m_Vit + player.Extra;
                    player.Extra   = (uint)total;
                    player.m_Str   = 0;
                    player.m_Dex   = 0;
                    player.m_Men   = 0;
                    player.m_Vit   = 0;
                    player.m_HPCur = player.HP;
                    player.m_MPCur = player.MP;
                    SendPacket(new UpdateCharStats(player).Compile());
                }
                else
                {
                    string achat = "Free up 5 slots";
                    SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)achat.Count(), achat).Compile());
                }
            }
            else if (str == "give me the magic drug")
            {
                if (player.m_Map == "Village1" && World.Dist2d(player.Loc, new Point2D(90, 173)) <= 2)
                {
                    AliasStage = 2;
                    string achat = "[Alias]: I have a magic drug. Do you need it?";
                    SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)achat.Count(), achat).Compile());
                }
            }
            else if (str == "yes")
            {
                if (player.m_Map == "Village1" && World.Dist2d(player.Loc, new Point2D(90, 173)) <= 2 &&
                    AliasStage > 0)
                {
                    if (AliasStage == 1)
                    {
                        AliasStage = 0;
                        var newitem = new script.item.PromoteLifeDrug().Inventory(player);
                        World.NewItems.TryAdd(newitem.m_Serial, newitem);
                        SendPacket(new AddItemToInventory2(newitem).Compile());
                    }
                    if (AliasStage == 2)
                    {
                        AliasStage = 0;
                        var newitem = new script.item.PromoteMagicDrug().Inventory(player);
                        World.NewItems.TryAdd(newitem.m_Serial, newitem);
                        SendPacket(new AddItemToInventory2(newitem).Compile());
                    }
                }

                var AronNpc = World.NewNpcs.Where(xe => xe.Value.Name == "Aron").FirstOrDefault();
                if (AronNpc.Value != null && World.Dist2d(player.X, player.Y, AronNpc.Value.X, AronNpc.Value.Y) < 7 &&
                    (player.Level >= 80 && player.Level <= 99) || (player.Level == (100 + (20 * player.Promo))))
                {
#if PROMOCAP12
                    if (player.Promo == 12)
                    {
                        return;
                    }
#else
                    if (player.Promo == 7)
                    {
                        return;
                    }
#endif

                    if (AronStage >= 1)
                    {
                        AronStage = 0;
                        if (player.Promo == 0)
                        {
                            player.XP     = 0;
                            player.Level  = 101;
                            player.Extra += 30;
                        }
                        else if (player.Promo >= 1)
                        {
                            player.XP = 0;
                            if (player.Promo == 1)
                            {
                                player.Extra += 50;
                            }
                            if (player.Promo == 2)
                            {
                                player.Extra += 80;
                            }
                            if (player.Promo == 3)
                            {
                                player.Extra += 120;
                            }
                            if (player.Promo == 4)
                            {
                                player.Extra += 180;
                            }
                            if (player.Promo == 5)
                            {
                                player.Extra += 260;
                            }
                            if (player.Promo == 6)
                            {
                                player.Extra += 360;
                            }
#if PROMOCAP12
                            if (player.Promo == 7)
                            {
                                player.Extra += 480;
                            }
                            if (player.Promo == 8)
                            {
                                player.Extra += 620;
                            }
                            if (player.Promo == 9)
                            {
                                player.Extra += 780;
                            }
                            if (player.Promo == 10)
                            {
                                player.Extra += 960;
                            }
                            if (player.Promo == 11)
                            {
                                player.Extra += 1160;
                            }
#endif
                            if (player.Promo == 6 && player.GetFreeSlots() > 0)
                            {
                                script.item.Item prize = null;
                                if (player.Class == LKCamelot.library.Class.Knight)
                                {
                                    prize = new script.item.Excalibur().Inventory(player);
                                }
                                if (player.Class == LKCamelot.library.Class.Swordsman)
                                {
                                    prize = new script.item.DaeungDaegum().Inventory(player);
                                }
                                if (player.Class == LKCamelot.library.Class.Wizard)
                                {
                                    prize = new script.item.Kassandra().Inventory(player);
                                }
                                if (player.Class == LKCamelot.library.Class.Shaman)
                                {
                                    prize = new script.item.TaegkFan().Inventory(player);
                                }
                                try
                                {
                                    World.NewItems.TryAdd(prize.m_Serial, prize);
                                    SendPacket(new AddItemToInventory2(prize).Compile());
                                }
                                catch { Console.WriteLine("failed to add promo item"); }
                            }

                            player.Level++;
                        }
                        SendPacket(new SetLevelGold(player).Compile());
                        SendPacket(new UpdateCharStats(player).Compile());
                    }
                }
            }
            else if (str2[0] == "@automp")
            {
                if (!player.AutoMana)
                {
                    player.AutoMana = true;
                }
                else
                {
                    player.AutoMana = false;
                }
                if (str2.Count() > 1)
                {
                    try
                    {
                        var temp = Convert.ToDouble(str2[1]);
                        if (temp > 1)
                        {
                            temp = 1;
                        }
                        if (temp < 0)
                        {
                            temp = 0;
                        }
                        player.AutoManaP = temp;
                    }
                    catch { }
                }
            }
            else if (str2[0] == "@stats")
            {
                string hpmp  = string.Format("HP:{0}, MP:{1}, Level:{2}", player.HP, player.MP, player.Level);
                string stats = string.Format("Str:{0}, Men:{1}, Dex:{2}, Vit:{3}",
                                             player.GetStat("str"), player.GetStat("men"), player.GetStat("dex"), player.GetStat("vit"));
                string ats = string.Format("AC:{0}, Dam:{1}, Hit:{2}, Extra:{3}",
                                           player.AC, player.Dam, player.Hit, player.Extra);
                string golds = string.Format("Gold:{0}, Diamonds:{1}",
                                             player.Gold, 0);
                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)hpmp.Count(), hpmp).Compile());
                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)stats.Count(), stats).Compile());
                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)ats.Count(), ats).Compile());
                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)golds.Count(), golds).Compile());
            }
            else if (str2[0] == "@pkstats")
            {
                string hpmp = string.Format("TempPKCount:{0}, RedTime:{1}",
                                            player.pklastpk.Count, ((player.pklastpk.Count * player.pkRedDelay) / 1000) / 60 + "m");
                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)hpmp.Count(), hpmp).Compile());
            }
            else if (str2[0] == "@addstat")
            {
                try
                {
                    var extras = Convert.ToUInt16(str2[2]);
                    var stat   = str2[1];
                    if (player.Extra >= extras)
                    {
                        if (stat == "str")
                        {
                            player.AddStat(ref player.m_Str, extras);
                        }
                        if (stat == "men")
                        {
                            player.AddStat(ref player.m_Men, extras);
                        }
                        if (stat == "dex")
                        {
                            player.AddStat(ref player.m_Dex, extras);
                        }
                        if (stat == "vit")
                        {
                            player.AddStat(ref player.m_Vit, extras);
                        }
                        SendPacket(new UpdateCharStats(player).Compile());
                    }
                }
                catch
                {
                    string rankr = "Failed. Use: @addstat stat amount ";
                    SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)rankr.Count(), rankr).Compile());
                }
            }
            else if (str2[0] == "@autohp")
            {
                if (!player.AutoHP)
                {
                    player.AutoHP = true;
                }
                else
                {
                    player.AutoHP = false;
                }

                if (str2.Count() > 1)
                {
                    try
                    {
                        var temp = Convert.ToDouble(str2[1]);
                        if (temp > 1)
                        {
                            temp = 1;
                        }
                        if (temp < 0)
                        {
                            temp = 0;
                        }
                        player.AutoHPP = temp;
                    }
                    catch { }
                }
            }
            else if (str2[0] == "@tele")
            {
                if (player.Name != "SIR" && player.Name != "PATHFINDER")
                {
                    return;
                }
                if (str2.Count() == 2)
                {
                    var teleon = handler.add.Where(xe => xe.Value != null && xe.Value.Name == str2[1]).FirstOrDefault().Value;
                    if (teleon != null)
                    {
                        player.Loc = new Point2D(teleon.Loc.X, teleon.Loc.Y);
                        player.Map = teleon.Map;
                    }
                }
                else if (str2.Count() == 4)
                {
                    player.Loc = new Point2D(Convert.ToInt16(str2[2]), Convert.ToInt16(str2[3]));
                    player.Map = str2[1];
                }
            }
            else if (str2[0] == "@learn")
            {
                if (player.Name != "SIR" && player.Name != "PATHFINDER")
                {
                    return;
                }
                try
                {
                    string activatorstring = "LKCamelot.script.spells.";
                    var    tempspell       = Activator.CreateInstance(Type.GetType(activatorstring + str2[1]));
                    (tempspell as script.spells.Spell).Slot    = player.GetFreeSpellSlot();
                    (tempspell as script.spells.Spell).SLevel2 = 99;
                    (tempspell as script.spells.Spell).Level   = 12;
                    player.m_MagicLearned.Add((tempspell as script.spells.Spell));
                    SendPacket(new CreateSlotMagic2((tempspell as script.spells.Spell)).Compile());
                }
                catch { return; }
            }
            else if (str2[0] == "@invis")
            {
                if (player.Name != "SIR" && player.Name != "PATHFINDER")
                {
                    return;
                }
                if (player.Transparancy == 0)
                {
                    player.Transparancy = 100;
                    World.SendToAll(new QueDele(player.Map, new SetObjectEffectsPlayer(player).Compile()));
                }
                else
                {
                    player.Transparancy = 0;
                }
            }
            else if (str2[0] == "@createitem")
            {
                if (player.Name != "SIR")
                {
                    return;
                }
                script.item.Item temp;
                try
                {
                    temp = (script.item.Item)Activator.CreateInstance(Type.GetType("LKCamelot.script.item." + str2[1]));
                }
                catch { return; }

                var newitem = temp.Inventory(player);
                World.NewItems.TryAdd(newitem.m_Serial, newitem);
                SendPacket(new AddItemToInventory2(newitem).Compile());
            }
            else if (str2[0] == "@kick")
            {
                if (player.Name != "SIR" && player.Name != "PATHFINDER")
                {
                    return;
                }

                if (str2[1] != "")
                {
                    var plr = handler.add.Where(xe => xe.Value != null && xe.Value.Name == str2[1].ToUpper()).FirstOrDefault().Value;
                    plr.loggedIn = false;
                    World.w_server.Disconnect(plr.client.connection);
                }
            }
            else if (str2[0] == "@remitee")
            {
                if (str2.Count() <= 2 || player.m_Map != "Loen")
                {
                    return;
                }
                try
                {
                    if (Convert.ToUInt64(str2[2]) < 0)
                    {
                        return;
                    }
                }
                catch { return; }

                var tradep = handler.add.Where(xe => xe.Key != null && xe.Value != null && xe.Value.Name == str2[1].ToUpper() && xe.Value.Map == "Loen").FirstOrDefault().Value;
                if (tradep != null && tradep != null && tradep.Name != player.Name && player.Gold >= Convert.ToUInt64(str2[2]))
                {
                    player.Gold -= Convert.ToUInt64(str2[2]);
                    tradep.Gold += Convert.ToUInt64(str2[2]);
                }
            }
            else if (str2[0] == "@cast")
            {
                /*   if (str2.Count() <= 7)
                 *     return;
                 *
                 * int par;
                 * for (int x = 1; x < 9; x++)
                 * {
                 *     if (int.TryParse(str2[x], out par) == false)
                 *         return;
                 * }
                 *
                 * World.SendToAll(new QueDele(player.Map, new CurveMagic(player.Serial, Convert.ToInt16(str2[1]), Convert.ToInt16(str2[2]), new script.spells.SpellSequence(Convert.ToInt32(str2[3]), Convert.ToInt32(str2[4]),
                 *     Convert.ToInt32(str2[5]), Convert.ToInt32(str2[6]), Convert.ToInt32(str2[7]), Convert.ToInt32(str2[8]), Convert.ToInt32(str2[9]))).Compile()));
                 */
            }
            else if (str2[0] == "@rank")
            {
                if (LKCamelot.Server.tickcount.ElapsedMilliseconds - 2000 > ChatTimeout)
                {
                    ChatTimeout = LKCamelot.Server.tickcount.ElapsedMilliseconds;
                    string rankr = "Ranks: ";
                    var    keys  = handler.add.Values.Where(xe => xe != null && xe.Name.ToUpper() != "PATHFINDER" && xe.Name.ToUpper() != "SIR").ToList();
                    var    kl    = keys.OrderByDescending(xe => xe.Level).ToList();
                    if (kl.Count > 25)
                    {
                        kl.RemoveRange(24, kl.Count - 24 - 1);
                    }

                    foreach (var rnk in kl)
                    {
                        rankr += rnk.Name + ", ";
                        if (rankr.Count() / 35 >= 1)
                        {
                            rankr = rankr.Substring(0, rankr.Count() - 2);
                            SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)rankr.Count(), rankr).Compile());
                            rankr = "";
                        }
                    }
                    if (rankr.Count() > 0)
                    {
                        rankr = rankr.Substring(0, rankr.Count() - 2);
                        SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)rankr.Count(), rankr).Compile());
                        rankr = "";
                    }
                    var online = handler.add.Values.Where(xe => xe != null && xe.Name.ToUpper() != "PATHFINDER" && xe.Name.ToUpper() != "SIR" && xe.loggedIn && xe.apistate == 0).ToList();
                    rankr = string.Format("Players Online: {0}", online.Count);
                    SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)rankr.Count(), rankr).Compile());
                }

                /*8          if (LKCamelot.Server.tickcount.ElapsedMilliseconds - ChatTimeout > LastAttack)
                 *        {
                 *            ChatTimeout = LKCamelot.Server.tickcount.ElapsedMilliseconds;
                 *            string rankr = "Highest Ranks: ";
                 *            foreach (var rnk in World.DBConnect.GetRank(this))
                 *            {
                 *                rankr += rnk.Name +", ";
                 *                rankr = rankr.Substring(0, rankr.Count()-2);
                 *                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)rankr.Count(), rankr).Compile());
                 *            }
                 *        }*/
            }
            else if (str2[0] == "@autoloot")
            {
                var strloot = "";
                if (player.AutoLoot)
                {
                    player.AutoLoot = false;
                    strloot         = "Autoloot disabled.";
                }
                else
                {
                    player.AutoLoot = true;
                    strloot         = "Autoloot enabled.";
                }
                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)strloot.Count(), strloot).Compile());
            }
            else if (str2[0] == "@autohit")
            {
                var strloot = "";
                if (player.AutoHit)
                {
                    player.AutoHit = false;
                    strloot        = "Autohit disabled.";
                }
                else
                {
                    player.AutoHit = true;
                    strloot        = "Autohit enabled.";
                }
                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)strloot.Count(), strloot).Compile());
            }
            else if (str2[0] == "make" && str2[1] == "me" && str2[2] == "a")
            {
                var AronNpc = World.NewNpcs.Where(xe => xe.Value.Name == "Aron").FirstOrDefault();
                if (AronNpc.Value != null && World.Dist2d(player.X, player.Y, AronNpc.Value.X, AronNpc.Value.Y) < 7 &&
                    player.Level >= 5 && player.Promo == 0)
                {
                    switch (str2[3])
                    {
                    case "knight":
                        player.Class = LKCamelot.library.Class.Knight;
                        break;

                    case "swordman":
                        player.Class = LKCamelot.library.Class.Swordsman;
                        break;

                    case "wizard":
                        player.Class = LKCamelot.library.Class.Wizard;
                        break;

                    case "shaman":
                        player.Class = LKCamelot.library.Class.Shaman;
                        break;
                    }
                }
            }
            else if (str[0] == '/')
            {
                if (str2.Count() <= 1)
                {
                    return;
                }
                var str3 = player.Name + "> " + str.Substring(str2[0].Count());

                var parsename = str2[0].ToString().Substring(1).ToUpper();
                var whisp     = handler.add.Where(xe => xe.Value != null && xe.Value.Name == parsename).FirstOrDefault();
                if (whisp.Key != null && whisp.Value != null && whisp.Value.loggedIn)
                {
                    var str1 = whisp.Value.Name + "< " + str.Substring(str2[0].Count());
                    SendPacket(new UpdateChatBox(0xff, 0x70, 1, (short)str1.Count(), str1).Compile());
                    whisp.Value.client.SendPacket(new UpdateChatBox(0xff, 0x70, 1, (short)str3.Count(), str3).Compile());
                }
            }
            else
            {
                str = "[" + player.Name + "] : " + str;
                World.SendToAllRange(new QueDele(player.Map, new UpdateChatBox(0xff, 0xff, 1, (short)str.Count(), str).Compile()), player, 10);
            }
        }
Exemplo n.º 2
0
        public void HandleIncoming(Byte[] data)
        {
            if (nsa != null)
            {
                nsa.AppendPacketIn(data);
            }
            PacketReader p = null;

            switch (data[0])
            {
            case 0x34:     // Keep Alive
                keepalive = Server.tickcount.ElapsedMilliseconds;
                break;

            //Identifiy

            /*     case 0x37:
             *       //     for (int x = 0; x < 40; x++)
             *       //     {
             *       //        SendPacket(new CreateSlotMagic(new MagicSpell((byte)(x+81), "Hii", 1, 1, (byte)x, library.MagicType.Casted)).Compile());
             *       //    }
             *       int y = 14;
             *       byte sprite = 0;
             *       for (int x = 0; x < 255; x++)
             *       {
             *           Thread.Sleep(100);
             *           if (x != 0 && x % 19 == 0)
             *           {
             *               y += 3;
             *               x -= 19;
             *           }
             *           //    SendPacket(new CreateMonster(new Monster(3, (short)(x+23),(short)y,"village.map", sprite.ToString(), sprite, 0), Serial.NewMobile).Compile());
             *           sprite++;
             *       }
             *       break;*/
            case 0x3A:     //find
                if (player.Map == "Loen")
                {
                    var slot       = data[1] + 40 + (12 * player.BankTab);
                    var itemtofind = World.NewItems.Where(xe => xe.Value.ParSer == player.Serial && xe.Value.InvSlot == slot).FirstOrDefault();
                    if (itemtofind.Value != null)
                    {
                        if (player.GetFreeSlot() != -1)
                        {
                            SendPacket(new DeleteEntrustSlot((byte)data[1]).Compile());

                            itemtofind.Value.InvSlot = player.GetFreeSlot();
                            SendPacket(new AddItemToInventory2(itemtofind.Value).Compile());
                        }
                    }
                }
                break;

            case 0x36:     //Entrust
                if (player.Map == "Loen")
                {
                    var itemtoentrust = World.NewItems.Where(xe => xe.Value.ParSer == player.Serial && xe.Value.InvSlot == data[1]).FirstOrDefault();
                    if (itemtoentrust.Value != null)
                    {
                        SendPacket(new DeleteItemSlot((byte)itemtoentrust.Value.InvSlot).Compile());
                        itemtoentrust.Value.InvSlot = player.FreeBankSlot;
                        SendPacket(new AddItemToEntrust(itemtoentrust.Value).Compile());
                    }
                }
                break;

            case 0x35:     //sell
                if (player.Map == "Loen")
                {
                    var itemtosell = World.NewItems.Where(xe => xe.Value.ParSer == player.Serial && xe.Value.InvSlot == data[1]).FirstOrDefault();
                    if (itemtosell.Value != null && itemtosell.Value.SellPrice > 0)
                    {
                        player.Gold += (uint)itemtosell.Value.SellPrice;
                        itemtosell.Value.Delete(player);
                    }
                }
                break;

            //Cast
            //  3D-00-00-01-00-00-00-0A-00-09-00
            case 0x3D:
            case 0x19:
            case 0x18:
                if (LKCamelot.Server.tickcount.ElapsedMilliseconds - player.CastSpeed > LastCast)
                {
                    LastCast = LKCamelot.Server.tickcount.ElapsedMilliseconds;
                    p        = new PacketReader(data, data.Count(), true);
                    int spellslot = p.ReadInt16();
                    if (player.MagicLearned.Count() < spellslot)
                    {
                        return;
                    }
                    int   castonid = p.ReadInt32();
                    short castx    = p.ReadInt16();
                    short casty    = p.ReadInt16();

                    script.spells.Spell castspell = player.MagicLearned.Where(xe => xe.Slot == spellslot).FirstOrDefault();
                    if (castspell == null)
                    {
                        return;
                    }

                    castHandler.HandleCast(data[0], castspell, player, castonid, castx, casty);
                }
                break;

            //Attack
            case 0x17:
                if (LKCamelot.Server.tickcount.ElapsedMilliseconds - player.AttackSpeed > LastAttack)
                {
                    LastAttack = LKCamelot.Server.tickcount.ElapsedMilliseconds;

                    World.SendToAll(new QueDele(player.Serial, player.Map, new SwingAnimationChar(player.Serial, player.Face).Compile()));
                    combatHandler.HandleMelee(player, data[1]);
                }
                break;

            //NPC Shop
            case 0x45:
                var npclook = World.NewNpcs.Where(xe => xe.Key == data[1]).FirstOrDefault();
                if (npclook.Value != null)
                {
                    if (npclook.Value.Name == "Loen")
                    {
                        SendPacket(new SpawnShopGump2(npclook.Value.Gump).Compile());
                    }
                    if (npclook.Value.Name == "Arnold")
                    {
                        SendPacket(new SpawnShopGump2(npclook.Value.Gump).Compile());
                    }
                    if (npclook.Value.Name == "Employee")
                    {
                        SendPacket(new SpawnShopGump2(npclook.Value.Gump).Compile());
                    }
                    if (npclook.Value.Name == "Boy")
                    {
                        SendPacket(new SpawnShopGump2(npclook.Value.Gump).Compile());
                    }
                }
                break;

            case 0x2B:     //2B-03-00-00-00-01-00-04-00-4D-65-6E-75-00
                p = new PacketReader(data, data.Count(), true);
                var npcid   = p.ReadInt32();
                var buyslot = p.ReadByte();

                var npcitself = World.NewNpcs.Where(xe => xe.Key == npcid).FirstOrDefault();
                if (npcitself.Value != null)
                {
                    npcitself.Value.Buy(player, buyslot);
                }

                break;

            //Inventory
            case 0x00:     //use
                if (data[1] == 0)
                {
                    return;
                }
                var itemu = World.NewItems.Where(xe => xe.Value.m_Parent == player &&
                                                 xe.Value.InvSlot == data[1]).FirstOrDefault();

                if (itemu.Value != null)
                {
                    itemu.Value.Use(player);
                }

                break;

            case 0x20:     //drop
                var item = World.NewItems.Where(xe => xe.Value.m_Parent == player &&
                                                xe.Value.InvSlot == data[1]).FirstOrDefault();

                if (item.Value != null)
                {
                    item.Value.Drop(player);
                }
                break;

            case 0x1F:     //pickup
                var item1 = World.NewItems.Where(xe => xe.Value.m_Map != null &&
                                                 xe.Value.m_Map == player.Map &&
                                                 xe.Value.Loc.X == player.X && xe.Value.Loc.Y == player.Y)
                            .FirstOrDefault();

                if (item1.Value != null)
                {
                    item1.Value.PickUp(player);
                }

                break;

            case 0x1E:     //equip Use
                // case 0x36:
                var eitem = World.NewItems.Where(xe => xe.Value.m_Parent == player &&
                                                 xe.Value.InvSlot == data[1]).FirstOrDefault();

                if (eitem.Value != null)
                {
                    if (eitem.Value is script.item.BaseArmor || eitem.Value is script.item.BaseWeapon)
                    {
                        eitem.Value.Equip(player);
                    }
                    if (eitem.Value is script.item.BaseSpellbook)
                    {
                        eitem.Value.Use(player);
                    }
                    if (eitem.Value is script.item.BasePotion)
                    {
                        eitem.Value.Use(player);
                    }
                }

                break;

            case 0x23:    //unequip
                var uitem = World.NewItems.Where(xe => xe.Value.m_Parent == player &&
                                                 xe.Value.InvSlot == (data[1] + 25)).FirstOrDefault();

                if (uitem.Value != null)
                {
                    uitem.Value.Unequip(player, data[1] + 25);
                }
                break;

            case 0x25:     //swap items
                var item11 = World.NewItems.Where(xe => xe.Value.ParSer == player.Serial && xe.Value.InvSlot == data[1]).FirstOrDefault().Value;
                int sss    = 0;
                if (data.Count() > 3)
                {
                    sss = data[3];
                }

                var target1 = World.NewItems.Where(xe => xe.Value.ParSer == player.Serial && xe.Value.InvSlot == sss).FirstOrDefault().Value;

                player.SwapItems(item11, target1, sss);

                break;

            case 0x24:     //drag,drop
                var itemdragdrop = World.NewItems.Where(xe => xe.Value.ParSer == player.Serial && xe.Value.InvSlot == data[1]).FirstOrDefault().Value;
                if (itemdragdrop != null)
                {
                    p = new PacketReader(data, data.Count(), false);
                    var targetid = p.ReadInt32();

                    script.item.Item targeti = null;
                    World.NewItems.TryGetValue(targetid, out targeti);
                    if (targeti != null)
                    {
                        string fail = "Refining failed.";
                        string succ = "Refining success.";
                        if ((itemdragdrop is script.item.Zel && targeti is script.item.BaseArmor) ||
                            (itemdragdrop is script.item.Dai && targeti is script.item.BaseWeapon))
                        {
                            if (targeti.TryUpgrade())
                            {
                                castHandler.CreateMagicEffect(targeti.Loc, targeti.m_Map, 42);
                                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)succ.Count(), succ).Compile());
                                SendPacket(new DeleteObject(targeti.m_Serial).Compile());
                                SendPacket(new CreateItemGround2(targeti, targeti.m_Serial).Compile());
                            }
                            else
                            {
                                castHandler.CreateMagicEffect(targeti.Loc, targeti.m_Map, 56);
                                SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)fail.Count(), fail).Compile());
                            }
                            itemdragdrop.Delete(player);
                        }
                    }

                    if (targetid == 4)
                    {
                        if (itemdragdrop.Name == "Promote Life Drug" && AronStage == 4)
                        {
                            AronStage = 1;
                            itemdragdrop.Delete(player);
                            string achat = "[Aron]: Are you ready for the promotion?";
                            SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)achat.Count(), achat).Compile());
                        }
                        if (itemdragdrop.Name == "Promote Magic Drug" && AronStage == 4)
                        {
                            AronStage = 2;
                            itemdragdrop.Delete(player);
                            string achat = "[Aron]: Are you ready for the promotion?";
                            SendPacket(new UpdateChatBox(0xff, 0xff, 1, (short)achat.Count(), achat).Compile());
                        }
                    }
                }
                break;

            //Chat message
            case 0x16:
                p = new PacketReader(data, data.Count(), false);
                var str  = p.ReadString();
                var str2 = str.Split(' ');

                if (Util.ContainsUnicodeCharacter(str))
                {
                    var x = 1;
                }

                HandleChat(str2, str);

                break;

            //Movement
            case 0x14:
                player.Face = data[1];
                World.SendToAll(new QueDele(player.Serial, player.Map, new ChangeFace(player.Serial, player.Face).Compile()));
                break;

            case 0x15:

                if (Server.tickcount.ElapsedMilliseconds - player.lastmove < 150)
                {
                    return;
                }

                long totalwalk = 0;
                foreach (var loc in walktrace)
                {
                    totalwalk += loc;
                }

                //  if(player.Name == "SIR")
                //  Console.WriteLine(string.Format("{0},{1}   {2}", px, py, Server.tickcount.ElapsedMilliseconds));
                if (Server.tickcount.ElapsedMilliseconds - player.lastmove > player.m_MoveSpeed)
                {
                    p           = new PacketReader(data, data.Count(), true);
                    player.Face = p.ReadInt16();
                    var px = p.ReadInt16();
                    var py = p.ReadInt16();

                    walktrace.Add(Server.tickcount.ElapsedMilliseconds - player.lastmove);
                    player.lastmove = Server.tickcount.ElapsedMilliseconds;

                    /*
                     * if (walktrace.Count > 3 && totalwalk < 1600)
                     * {
                     *  SendPacket(new MoveSpriteWalkChar(player.Serial, player.Face, player.X, player.Y).Compile());
                     *  return;
                     * }
                     *
                     * while (walktrace.Count > 4)
                     *  walktrace.Remove(walktrace.ElementAt(0));
                     */
                    if (World.Dist2d(new Point2D(px, py), player.m_Loc) > 3)
                    {
                        SendPacket(new MoveSpriteWalkChar(player.Serial, player.Face, player.X, player.Y).Compile());
                        return;
                    }
                    player.X = px;
                    player.Y = py;

                    World.SendToAll(new QueDele(player.Serial, player.Map, new MoveSpriteWalkChar(player.Serial, player.Face,
                                                                                                  player.X, player.Y).Compile()));
                    parseFace();
                }
                else
                {
                    SendPacket(new MoveSpriteWalkChar(player.Serial, player.Face, player.X, player.Y).Compile());
                }
                break;

            //Stats
            case 0x2C:
                player.AddStat(ref player.m_Str);
                SendPacket(new UpdateCharStats(player).Compile());
                break;

            case 0x2D:
                player.AddStat(ref player.m_Men);
                SendPacket(new UpdateCharStats(player).Compile());
                break;

            case 0x2E:
                player.AddStat(ref player.m_Dex);
                SendPacket(new UpdateCharStats(player).Compile());
                break;

            case 0x2F:
                player.AddStat(ref player.m_Vit);
                SendPacket(new UpdateCharStats(player).Compile());
                break;


            case 0x03:     //Login
                var result = TryLogin(data);
                switch (result[0])
                {
                case '1':
                    var puser2 = result.Remove(0, 1).Split(',');
                    player          = handler.add.Where(xe => xe.Value.Name == puser2[0]).FirstOrDefault().Value;
                    player.client   = this;
                    player.loggedIn = true;
                    LoadPlayer();
                    SendPacket(new CloseLogin().Compile());
                    break;

                case '2':
                    SendPacket(new WrongPass().Compile());
                    break;

                case '3':
                    SendPacket(new WrongID().Compile());
                    break;

                case '4':         //invalid chars
                    SendPacket(new WrongID().Compile());
                    break;

                case '5':
                    SendPacket(new AlreadyOnline().Compile());
                    break;

                case '6':
                    player = new Player(this);
                    player.CreateBeginner(result.Remove(0, 1));
                    firstlogin = true;
                    LoadPlayer();
                    player.Pass = Cryption.CreateSaltedSHA256(player.Pass, player.Name);
                    try
                    {
                        handler.add.TryAdd(player.Name, player);
                        var touch = handler.add.Where(xe => xe.Key == player.Name).FirstOrDefault();
                        touch.Value.client   = this;
                        touch.Value.loggedIn = true;
                        //   BinaryIO.SavePlayer(player);
                        // World.DBConnect.InsertPlayer(player);
                    }
                    catch
                    {
                        Console.WriteLine("failed to insert new player");
                    }
                    SendPacket(new CloseLogin().Compile());
                    break;
                }
                break;

            case 0x49:     //delete magic
                var magdelslot = data[1];
                player.DeleteMagic(magdelslot);
                break;

            case 0x26:     //swap magic
                if (data.Count() < 4)
                {
                    player.SwapMagic(data[1], 0);
                }
                else
                {
                    player.SwapMagic(data[1], data[3]);
                }
                break;

            case 0xff:
                SendPacket(new PlayMusic(1000).Compile());
                if (true)     //Login
                {
                    //         SendPacket(new CloseLogin().Compile());

                    //           SendPacket(new LoadWorld(1, 0x12, 0x12, new byte[] { 00, 04, 00, 00, 00, 00, 00, 00, 00, 03 },
                    //               01, 01, 00, 03, 04, 00, 00,
                    //               new byte[] { 0x69, 0x70, 0x69, 0x67, 0x6d, 0x79, 0x31, 0x2e, 0x6d, 0x61, 0x70, 00 }).Format());
                    break;
                }
            }
        }