Exemple #1
0
        public static void Teleport(int Map, ushort X, ushort Y, int Instance, ClientSocket CSocket)
        {
            if (Map > 0 && X > 0 && Y > 0 && CSocket != null)
            {
                if (Instance == 0)
                    Instance = Map;
                //@TODO: Check Map Pos is Valid.
                EudemonPacket.ToLocal(EudemonPacket.General(CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y, CSocket.Client.Direction, Struct.DataType.EntityRemove, 0), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);

                CSocket.Client.Map = (Struct.Maps)Map;
                CSocket.Client.X = X;
                CSocket.Client.Y = Y;
                //TODO: Instance pairing.
                CSocket.Send(EudemonPacket.General(CSocket.Client.ID, X, Y, CSocket.Client.Direction, Struct.DataType.actionFlyMap, Map));
                CSocket.Send(EudemonPacket.NewMap((int)CSocket.Client.Map, 2097152, Instance));
                EudemonPacket.ToLocal(EudemonPacket.SpawnCharacter(CSocket), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                //@TODO: work out the point of ARGB.
                //CSocket.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y, CSocket.Client.Direction, Struct.DataType.actionMapARGB, 65535));

                EudemonPacket.ToLocal(EudemonPacket.String(CSocket, 10, "other05"), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
                CSocket.Client.PrevX = 0;
                CSocket.Client.PrevY = 0;
                Spawn.All(CSocket);
            }
        }
Exemple #2
0
 public static void ItemSell(byte[] Data, ClientSocket CSocket)
 {
     int ItemUID = PacketProcessor.ReadLong(Data, 8);
     if (CSocket.Client.Inventory.ContainsKey(ItemUID))
     {
         Struct.ItemInfo Item = new Struct.ItemInfo();
         Item = CSocket.Client.Inventory[ItemUID];
         if (MainGS.Items.ContainsKey(Item.ItemID))
         {
             Struct.ItemData iData = MainGS.Items[Item.ItemID];
             int Money = iData.Cost / 3;
             if (Money > 0)
             {
                 CSocket.Client.Money += Money;
                 CSocket.Client.Inventory.Remove(Item.UID);
                 CSocket.Send(EudemonPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveDropItem));
                 Database.Database.DeleteItem(Item.UID);
                 CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.Money, Struct.StatusTypes.InvMoney));
             }
         }
     }
     else
     {
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You do not have that item..", Struct.ChatType.System));
     }
 }
Exemple #3
0
 public static void NewCharacter(byte[] Packet, ClientSocket CSocket)
 {
     int Mesh = PacketProcessor.ReadLong(Packet, 100);
     int Class = Packet[104];
     string Name = "";
     int X = 20;
     while (X < 36 && Packet[X] != 0x00)
     {
         Name += Convert.ToChar(Packet[X]);
         X++;
     }
     if (!ValidName(Name))
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", "Error: Invalid character name.", Struct.ChatType.Dialog));
     else if (Database.Database.CharExists(Name))
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", "Error: Character already exists.", Struct.ChatType.Dialog));
     else
     {
         Console.WriteLine("NewCharacter");
         int CharID = Database.Database.NewCharacter(Name, Mesh, Class, CSocket.AccountName);
         if (CharID > -1)
         {
             CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", "Characted created! Please hit back twice and then re-log in to the game!", Struct.ChatType.Dialog));
             CSocket.Disconnect();
         }
         else
         {
             Console.WriteLine("CharID: " + CharID);
             CSocket.Disconnect();
         }
     }
 }
Exemple #4
0
        public static void Attack(ClientSocket CSocket)
        {
            CSocket.Client.MaxAttack = CSocket.Client.BaseMaxAttack;//TODO: Revise Attack Calcucations!
            CSocket.Client.MinAttack = CSocket.Client.BaseMinAttack;
            CSocket.Client.MagicAttack = CSocket.Client.BaseMagicAttack;
            int MaxAdd = 0;
            int MinAdd = 0;
            int MagicAdd = 0;
            if (CSocket.Client.NCG > 0)
            {
                MaxAdd += (int)Math.Floor(CSocket.Client.MaxAttack * (CSocket.Client.NCG * .05));
                MinAdd += (int)Math.Floor(CSocket.Client.MinAttack * (CSocket.Client.NCG * .05));
            }
            if (CSocket.Client.RCG > 0)
            {
                MaxAdd += (int)Math.Floor(CSocket.Client.MaxAttack * (CSocket.Client.RCG * .10));
                MinAdd += (int)Math.Floor(CSocket.Client.MinAttack * (CSocket.Client.RCG * .10));
            }
            if (CSocket.Client.SCG > 0)
            {
                MaxAdd += (int)Math.Floor(CSocket.Client.MaxAttack * (CSocket.Client.SCG * .20));
                MinAdd += (int)Math.Floor(CSocket.Client.MinAttack * (CSocket.Client.SCG * .20));
            }
            CSocket.Client.MaxAttack += MaxAdd;
            CSocket.Client.MinAttack += MinAdd;

            CSocket.Client.MagicAttack += MagicAdd;
            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Max: " + CSocket.Client.MaxAttack + " Min: " + CSocket.Client.MinAttack + " Magic: " + CSocket.Client.MagicAttack + " / " + CSocket.Client.BonusMagicAttack + " Defense: " + CSocket.Client.Defense + " Bless: " + CSocket.Client.Bless + "% Dodge: " + CSocket.Client.Dodge + " % MaxHP/MP: " + CSocket.Client.MaxHP + "/" + CSocket.Client.MaxMP, Struct.ChatType.CenterGm));
        }
Exemple #5
0
 public static void Portal(int X, int Y, ClientSocket CSocket)
 {
     string PID = X + "," + Y + "," + (int)CSocket.Client.Map + "," + 0;
     if (MainGS.Portals.ContainsKey(PID))
     {
         Struct.Portal Port = MainGS.Portals[PID];
         Handler.Teleport(Port.EndMap, (ushort)Port.EndX, (ushort)Port.EndY, Port.EndInstance, CSocket);
     }
     else
     {
         Handler.Teleport((int)CSocket.Client.Map, CSocket.Client.PrevX, CSocket.Client.PrevY, 0, CSocket);
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown portal: " + PID, Struct.ChatType.System));
     }
 }
        public static void ProcessPacket(byte[] data, ClientSocket CSocket)
        {
            try
            {
                byte[] Split1 = null;
                byte[] Split2 = null;
                byte[] Split3 = null;
                //byte[] Split4;
                //byte[] Split5;
                int Type = (BitConverter.ToInt16(data, 2));
                int Length = (data[1] << 8) + data[0]; Length += 8;
                //if (data.Length > Length)
                //{
                //    int Len2 = (data[Length + 1] << 8) + data[Length]; Len2 += 8;
                //    Split1 = new byte[Len2];
                //    Array.Copy(data, Length, Split1, 0, Len2);
                //    if (Len2 + Length < data.Length)
                //    {
                //        int Len3 = (data[Length + Len2 + 1] << 8) + data[Length + Len2]; Len3 += 8;
                //        Split2 = new byte[Len3];
                //        Array.Copy(data, Length + Len2, Split2, 0, Len3);
                //        if (Len2 + Len3 + Length < data.Length)
                //        {
                //            int Len4 = (data[Length + Len2 + Len3 + 1] << 8) + data[Length + Len2 + Len3]; Len4 += 8;
                //            Split3 = new byte[Len4];
                //            Array.Copy(data, Length + Len2 + Len3, Split3, 0, Len4);
                //        }
                //    }
                //}
                //byte[] data = new byte[Length];
                //Array.Copy(data, data, Length);
                Console.WriteLine("[PacketLog] New Packet Recived, Type: " + Type);
                Console.WriteLine(Dump(data));
                switch (Type)
                {
                    case 1052: //End Authorization Process.
                        {
                            ulong Keys;
                            Keys = data[11];
                            Keys = (Keys << 8) | data[10];
                            Keys = (Keys << 8) | data[9];
                            Keys = (Keys << 8) | data[8];
                            Keys = (Keys << 8) | data[7];
                            Keys = (Keys << 8) | data[6];
                            Keys = (Keys << 8) | data[5];
                            Keys = (Keys << 8) | data[4];
                            Console.WriteLine("[GameServer] Confirming login with LoginServer");
                            if (Nano.AuthenticatedLogins.ContainsKey(Keys))
                            {
                                CSocket.AccountName = Nano.AuthenticatedLogins[Keys].Account;
                                Console.WriteLine("[GameServer] Authenticated Login.");
                                ConnectionRequest User = Nano.AuthenticatedLogins[Keys];
                                User.Expire(false);
                                CSocket.Client = Database.Database.GetCharacter(User.Account);
                                if (CSocket.Client == null)
                                {
                                    if (Database.Database.LoadNovaCharacter(User.Account))
                                    {
                                        Console.WriteLine("user has account");
                                        CSocket.Client = Database.Database.GetCharacter(User.Account);
                                    }
                                    else
                                    {
                                        Console.WriteLine("user making account");

                                        //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", "NEW_ROLE", Struct.ChatType.LoginInformation));
                                        CSocket.Send(ConquerPacket.Chat(5, "SYSTEM", "ALLUSERS", "NEW_ROLE", Struct.ChatType.LoginInformation));
                                        return;
                                    }
                                }
                                if (CSocket.Client == null)
                                {

                                    //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", "NEW_ROLE", Struct.ChatType.LoginInformation));
                                    CSocket.Send(ConquerPacket.Chat(5, "SYSTEM", "ALLUSERS", "NEW_ROLE", Struct.ChatType.LoginInformation));
                                    return;
                                }
                                Calculation.Vitals(CSocket, true);
                                if (CSocket.Client.First)
                                {
                                    CSocket.Client.CurrentMP = CSocket.Client.MaxMP;
                                    CSocket.Client.CurrentHP = CSocket.Client.MaxHP;
                                }
                                Database.Database.GetItems(CSocket);
                                if (Nano.ClientPool.ContainsKey(CSocket.Client.ID))
                                {
                                    ClientSocket C = Nano.ClientPool[CSocket.Client.ID];
                                    C.Send(ConquerPacket.Chat(0, "SYSTEM", C.Client.Name, "[ERROR] Your character has logged in from another location, you're being booted.", Struct.ChatType.Talk));
                                    C.Disconnect();
                                }
                                //lock(Nano.ClientPool)
                                //{
                                try
                                {
                                    Monitor.Enter(Nano.ClientPool);
                                    Nano.ClientPool.Add(CSocket.Client.ID, CSocket);
                                    //}
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.ToString());
                                }
                                finally
                                {
                                    Monitor.Exit(Nano.ClientPool);
                                }
                                //}
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", "ANSWER_OK", Struct.ChatType.LoginInformation));
                                CSocket.Send(ConquerPacket.CharacterInfo(CSocket));
                                //PLEASE DO NOT REMOVE THIS CODE!
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "This server is a branch of CoEmu code. Portions are expressly owned by the CoEmu Foundation.", Struct.ChatType.Talk));
                                //
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Welcome to CoEmu v2: Nano, " + CSocket.Client.Name, Struct.ChatType.Talk));
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "There are currently " + Nano.ClientPool.Count + " players online.", Struct.ChatType.Talk));
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Use of this server binds you to the Terms of Service (ToS) located on http://www.coemu.org", Struct.ChatType.Talk));
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Current server rates: Prof: " + Nano.PROF_MULTIPLER + "x, Skill: " + Nano.SKILL_MULTIPLER + "x, Exp: " + Nano.EXP_MULTIPLER + "x.", Struct.ChatType.Talk));
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Be kind to your fellow player and have a good time.", Struct.ChatType.Talk));
                                /*Handler.Text("Welcome to CoEmu.Nano. As you will undoubtedly notice, you can't do much right now.\n", CSocket);
                                Handler.Text("If you are connected and see this message, you are helping to test Nano out. Thank you.\n", CSocket);
                                Handler.Text("Please do not whisper or bug PMs/GMs, we know that you can't do most of the things you should be able to.\n", CSocket);
                                Handler.Text("As you can obviously see, you are naked. Go hunt!\n", CSocket);
                                Handler.End(CSocket);*/
                                if (CSocket.Client.First)
                                {
                                    Database.Database.SaveCharacter(CSocket.Client);
                                    //Handler.Text("Welcome to the WONDERFUL world of CoEmu.Nano,\n CoEmu v2's leveling server!", CSocket);
                                    //Handler.Text("\n On behalf of every GM, PM, and supporter of CoEmu v2,", CSocket);
                                    //Handler.Text("\n I would like to thank you all for the\n wonder that Nova was.", CSocket);
                                    //Handler.Text("\n This server is dedicated to not only\n Rimik from Pyramid", CSocket);
                                    //Handler.Text("\n But to every CoEmu v2 supporter that has\n ever been a part of our family.", CSocket);
                                    //Handler.Text("\n Good luck in this new world, conquerer.", CSocket);
                                    //Handler.Text("\n You've been started off with some basic items to help your journey.", CSocket);
                                    //Handler.Text("\n Use of this server BINDS YOU to the CoEmu v2 terms of service.", CSocket);
                                    //Handler.End(CSocket);
                                }
                                ConquerPacket.ToServer(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", CSocket.Client.Name + " has come online.", Struct.ChatType.Top), 0);
                            }
                            else
                            {
                                Console.WriteLine("[GameServer] Unauthenticated Login.");
                                CSocket.Disconnect();
                            }
                            break;
                        }
                    #region CreateCharacter
                    case 1001://Create Character
                        {
                            Handler.NewCharacter(data, CSocket);
                            break;
                        }
                    #endregion
                    #region 0x3f2(1010) Multi-Function Packet
                    case 1010: // 0x3f2, Multi-Function Packet
                        {
                            if (data.Length < 0x16)
                                break;
                            int SubType = data[0x16];
                            switch (SubType)
                            {
                                case 74: //Start login sequence.
                                    {
                                        Console.WriteLine("[GameServer] Login Sequence started for " + CSocket.Client.Name);
                                        //CSocket.Send(ConquerPacket.General(CSocket.Client.ID, (int)CSocket.Client.Map, CSocket.Client.X, CSocket.Client.Y, 0, Struct.DataType.MapShow));
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, (int)CSocket.Client.Map, 0, CSocket.Client.X, CSocket.Client.Y, 0, Struct.DataType.MapShow));
                                        ConquerPacket.ToLocal(ConquerPacket.SpawnCharacter(CSocket), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                        Spawn.All(CSocket);
                                        /*CSocket.Client.Save = new Timer();
                                        CSocket.Client.Save.Elapsed += delegate {
                                            Database.Database.SaveCharacter(CSocket.Client);
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Saved " + CSocket.Client.Name, Struct.ChatType.Top));
                                        };
                                        CSocket.Client.Save.Interval = 20000;
                                        CSocket.Client.Save.Start();*/
                                        CSocket.Client.CurrentStam = 100;
                                        CSocket.Client.UpStam = new System.Timers.Timer();
                                        CSocket.Client.UpStam.Interval = 100;
                                        CSocket.Client.UpStam.Elapsed += delegate { CSocket.AddStam(); };
                                        CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.CurrentStam, Struct.StatusTypes.Stamina));
                                        CSocket.Client.LastAttack = System.Environment.TickCount;
                                        break;
                                    }
                                case 114: //Request to show minimap
                                    {
                                        CSocket.Send(ConquerPacket.MiniMap(true));
                                        break;
                                    }
                                case 75: //Request Hotkeys
                                    {
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 0, 0, 0, 0, 0, Struct.DataType.HotKeys));
                                        break;
                                    }
                                case 76: //Request Friends
                                    {
                                        //TODO: Friends lists
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 0, 0, 0, 0, 0, Struct.DataType.ConfirmFriends));
                                        break;
                                    }
                                case 77://Weapon Prof.
                                    {
                                        Database.Database.GetProfs(CSocket);
                                        foreach (KeyValuePair<int, Struct.CharProf> Prof in CSocket.Client.Profs)
                                        {
                                            CSocket.Send(ConquerPacket.Prof(Prof.Value.ID, Prof.Value.Level, Prof.Value.Exp));
                                        }
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 0, 0, 0, 0, 0, Struct.DataType.ConfirmProf));
                                        break;
                                    }
                                case 78://Confirm Skills
                                    {
                                        Database.Database.GetSkills(CSocket);
                                        foreach (KeyValuePair<int, Struct.CharSkill> Skill in CSocket.Client.Skills)
                                        {
                                            CSocket.Send(ConquerPacket.Skill(Skill.Value.ID, Skill.Value.Level, Skill.Value.Exp));
                                        }
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 0, 0, 0, 0, 0, Struct.DataType.ConfirmSkills));
                                        break;
                                    }
                                case 85: //Portal
                                    {
                                        int X = ReadShort(data, 12);
                                        int Y = ReadShort(data, 14);
                                        Handler.Portal(X, Y, CSocket);
                                        break;
                                    }
                                case 97: //Confirm Guild
                                    {
                                        //TODO: Guild
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 0, 0, 0, 0, 0, Struct.DataType.ConfirmGuild));
                                        break;
                                    }
                                case 130: //Confirm Login Complete
                                    {
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 0, 0, 0, 0, 0, Struct.DataType.ConfirmLoginComplete));
                                        foreach (KeyValuePair<int, Struct.ItemInfo> Item in CSocket.Client.Inventory)
                                        {
                                            CSocket.Send(ConquerPacket.ItemInfo(Item.Value.UID, Item.Value.ItemID, Item.Value.Plus, Item.Value.Bless, Item.Value.Enchant, Item.Value.Soc1, Item.Value.Soc2, Item.Value.Dura, Item.Value.MaxDura, Item.Value.Position, Item.Value.Color));
                                        }
                                        #region ItemCalculations
                                        foreach (KeyValuePair<int, Struct.ItemInfo> Item in CSocket.Client.Equipment)
                                        {
                                            switch (Item.Value.Soc1)
                                            {
                                                case 1:
                                                    {
                                                        CSocket.Client.NPG++;
                                                        break;
                                                    }
                                                case 2:
                                                    {
                                                        CSocket.Client.RPG++;
                                                        break;
                                                    }
                                                case 3:
                                                    {
                                                        CSocket.Client.SPG++;
                                                        break;
                                                    }
                                                case 11:
                                                    {
                                                        CSocket.Client.NDG++;
                                                        break;
                                                    }
                                                case 12:
                                                    {
                                                        CSocket.Client.RDG++;
                                                        break;
                                                    }
                                                case 13:
                                                    {
                                                        CSocket.Client.SDG++;
                                                        break;
                                                    }
                                                case 71:
                                                    {
                                                        CSocket.Client.NTG++;
                                                        break;
                                                    }
                                                case 72:
                                                    {
                                                        CSocket.Client.RTG++;
                                                        break;
                                                    }
                                                case 73:
                                                    {
                                                        CSocket.Client.STG++;
                                                        break;
                                                    }
                                                default:
                                                    {
                                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown GemID: " + Item.Value.Soc1, Struct.ChatType.Talk));
                                                        break;
                                                    }

                                            }
                                            switch (Item.Value.Soc2)
                                            {
                                                case 1:
                                                    {
                                                        CSocket.Client.NPG++;
                                                        break;
                                                    }
                                                case 2:
                                                    {
                                                        CSocket.Client.RPG++;
                                                        break;
                                                    }
                                                case 3:
                                                    {
                                                        CSocket.Client.SPG++;
                                                        break;
                                                    }
                                                case 11:
                                                    {
                                                        CSocket.Client.NDG++;
                                                        break;
                                                    }
                                                case 12:
                                                    {
                                                        CSocket.Client.RDG++;
                                                        break;
                                                    }
                                                case 13:
                                                    {
                                                        CSocket.Client.SDG++;
                                                        break;
                                                    }
                                                case 71:
                                                    {
                                                        CSocket.Client.NTG++;
                                                        break;
                                                    }
                                                case 72:
                                                    {
                                                        CSocket.Client.RTG++;
                                                        break;
                                                    }
                                                case 73:
                                                    {
                                                        CSocket.Client.STG++;
                                                        break;
                                                    }
                                                default:
                                                    {
                                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown GemID: " + Item.Value.Soc2, Struct.ChatType.Talk));
                                                        break;
                                                    }

                                            }
                                            switch (Item.Value.Bless)
                                            {
                                                case 7:
                                                    {
                                                        CSocket.Client.Bless += 7;
                                                        break;
                                                    }
                                                case 5:
                                                    {
                                                        CSocket.Client.Bless += 5;
                                                        break;
                                                    }
                                                case 3:
                                                    {
                                                        CSocket.Client.Bless += 3;
                                                        break;
                                                    }
                                                case 1:
                                                    {
                                                        CSocket.Client.Bless += 1;
                                                        break;
                                                    }
                                                case 0:
                                                    {
                                                        break;
                                                    }
                                                default:
                                                    {
                                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Invalid bless: " + Item.Value.Bless, Struct.ChatType.Top));
                                                        break;
                                                    }
                                            }
                                            if (Nano.Items.ContainsKey(Item.Value.ItemID))
                                            {
                                                Struct.ItemData ItemD = Nano.Items[Item.Value.ItemID];
                                                CSocket.Client.BaseMagicAttack += ItemD.MagicAttack;
                                                if (Item.Value.Position == 5)
                                                {
                                                    CSocket.Client.BaseMaxAttack += (int)Math.Floor(.5 * ItemD.MaxDamage);
                                                    CSocket.Client.BaseMinAttack += (int)Math.Floor(.5 * ItemD.MinDamage);
                                                }
                                                else
                                                {
                                                    CSocket.Client.BaseMaxAttack += ItemD.MaxDamage;
                                                    CSocket.Client.BaseMinAttack += ItemD.MinDamage;
                                                }
                                                CSocket.Client.Defense += ItemD.DefenseAdd;
                                                CSocket.Client.MaxHP += ItemD.HPAdd;
                                                CSocket.Client.MaxHP += Item.Value.Enchant;
                                                CSocket.Client.MagicDefense += ItemD.MDefenseAdd;
                                                CSocket.Client.MaxMP += ItemD.MPAdd;
                                                CSocket.Client.Dodge += ItemD.DodgeAdd;
                                            }
                                            if (Item.Value.Plus > 0)
                                            {
                                                string s_ItemID = Convert.ToString(Item.Value.ItemID);
                                                int itemidsimple = 0;
                                                if ((Item.Value.ItemID >= 900000 && Item.Value.ItemID <= 900999) || (Item.Value.ItemID >= 111303 && Item.Value.ItemID <= 118999) || (Item.Value.ItemID >= 130003 && Item.Value.ItemID <= 139999))//Shields, Helms, Armors
                                                {
                                                    /*s_ItemID = s_ItemID.Remove((s_ItemID.Length - 3), 1);
                                                    s_ItemID = s_ItemID.Insert((s_ItemID.Length - 2), "0");
                                                    s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                                                    s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");*/
                                                    s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                                                    s_ItemID = s_ItemID.Insert(s_ItemID.Length, "0");
                                                    itemidsimple = Convert.ToInt32(s_ItemID);
                                                }
                                                else if ((Item.Value.ItemID >= 150000 && Item.Value.ItemID <= 160250) || (Item.Value.ItemID >= 500000 && Item.Value.ItemID <= 500400) || (Item.Value.ItemID >= 120003 && Item.Value.ItemID <= 121249) || (Item.Value.ItemID >= 421003 && Item.Value.ItemID <= 421339))//BS's, Bows, Necky/Bags
                                                {
                                                    s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                                                    s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");
                                                    itemidsimple = Convert.ToInt32(s_ItemID);
                                                }
                                                else if (Item.Value.ItemID >= 510000 && Item.Value.ItemID <= 580400)//2 Hander
                                                {
                                                    s_ItemID = s_ItemID.Remove(0, 3);
                                                    s_ItemID = s_ItemID.Insert(0, "555");
                                                    s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                                                    s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");
                                                    itemidsimple = Convert.ToInt32(s_ItemID);
                                                }
                                                else if (Item.Value.ItemID >= 410000 && Item.Value.ItemID <= 490400 && itemidsimple == 0)//1 Handers
                                                {
                                                    s_ItemID = s_ItemID.Remove(0, 3);
                                                    s_ItemID = s_ItemID.Insert(0, "444");
                                                    s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                                                    s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");
                                                    itemidsimple = Convert.ToInt32(s_ItemID);
                                                }
                                                if (Nano.ItemPluses.ContainsKey(itemidsimple))
                                                {
                                                    Struct.ItemPlusDB IPlus = Nano.ItemPluses[itemidsimple];
                                                    if (IPlus.DB.ContainsKey(Item.Value.Plus))
                                                    {
                                                        Struct.ItemPlus iPlus = IPlus.DB[Item.Value.Plus];
                                                        CSocket.Client.BaseMaxAttack += iPlus.MaxDmg;
                                                        CSocket.Client.BaseMinAttack += iPlus.MinDmg;
                                                        CSocket.Client.Defense += iPlus.DefenseAdd;
                                                        CSocket.Client.BaseMagicAttack += iPlus.MDamageAdd;
                                                        CSocket.Client.BonusMagicAttack += iPlus.MDamageAdd;
                                                        CSocket.Client.BonusMagicDefense += iPlus.MDefAdd;
                                                        CSocket.Client.MaxHP += iPlus.HPAdd;
                                                        CSocket.Client.Dodge += iPlus.DodgeAdd;
                                                        //TODO: HP, etc
                                                    }
                                                }
                                            }
                                        #endregion
                                            CSocket.Send(ConquerPacket.ItemInfo(Item.Value.UID, Item.Value.ItemID, Item.Value.Plus, Item.Value.Bless, Item.Value.Enchant, Item.Value.Soc1, Item.Value.Soc2, Item.Value.Dura, Item.Value.MaxDura, Item.Value.Position, Item.Value.Color));
                                        }
                                        Calculation.Attack(CSocket);
                                        CSocket.Send(ConquerPacket.Status(CSocket, 2, 0, Struct.StatusTypes.StatusEffect));
                                        break;
                                    }
                                case 79: //Direction
                                    {
                                        int Direction = ReadShort(data, 20);
                                        if (Direction >= 0 && Direction <= 7)
                                            CSocket.Client.Direction = Direction;
                                        ConquerPacket.ToLocal(ConquerPacket.General(CSocket.Client.ID, 0, 0, CSocket.Client.X, CSocket.Client.Y, CSocket.Client.Direction, Struct.DataType.Direction), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                        break;
                                    }
                                case 102:
                                    {
                                        int Target = ReadLong(data, 12);
                                        if (Nano.ClientPool.ContainsKey(Target))
                                            CSocket.Send(ConquerPacket.SpawnCharacter(Nano.ClientPool[Target]));
                                        else if (Nano.Monsters.ContainsKey(Target))
                                        {
                                            Monster Mob = Nano.Monsters[Target];
                                            CSocket.Send(ConquerPacket.SpawnMonster(Mob.UID, Mob.Info.Mesh, Mob.X, Mob.Y, Mob.Info.Name, Mob.CurrentHP, Mob.Level, Mob.Direction));
                                        }
                                        break;
                                    }
                                case 81: //Action
                                    {
                                        int Action = ReadLong(data, 12);
                                        if (Enum.IsDefined(typeof(Struct.ActionType), (Struct.ActionType)Action))
                                        {
                                            CSocket.Client.Action = Action;
                                            ConquerPacket.ToLocal(ConquerPacket.General(CSocket.Client.ID, CSocket.Client.Action, 0, CSocket.Client.X, CSocket.Client.Y, CSocket.Client.Direction, Struct.DataType.Action), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                            if (Action == 250 && !CSocket.Client.UpStam.Enabled)
                                            {
                                                CSocket.Client.UpStam.Start();
                                            }
                                            else if (Action != 250 && CSocket.Client.UpStam.Enabled)
                                            {
                                                CSocket.Client.UpStam.Stop();
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report bug: Unknown action type: " + Action, Struct.ChatType.Talk));
                                        }
                                        break;
                                    }
                                case 96: //PK Mode
                                    {
                                        int PkType = data[12];
                                        if (PkType > 4)
                                            break;
                                        CSocket.Client.PKMode = (Struct.PkType)PkType;
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, PkType, 0, 0, 0, 0, Struct.DataType.PkMode));
                                        break;
                                    }
                                case 94://Revive
                                    {
                                        //TODO: Revive points
                                        if (CSocket.Client.Dead)
                                        {
                                            CSocket.Client.CurrentHP = CSocket.Client.MaxHP;
                                            CSocket.Client.Dead = false;
                                            CSocket.Send(ConquerPacket.Status(CSocket, 2, 0, Struct.StatusTypes.StatusEffect));
                                            CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.Model, Struct.StatusTypes.Model));
                                            CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                                            ConquerPacket.ToLocal(ConquerPacket.General(CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y, 0, 0, 0, Struct.DataType.EntityRemove), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                            ConquerPacket.ToLocal(ConquerPacket.SpawnCharacter(CSocket), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
                                            ConquerPacket.ToLocal(ConquerPacket.Effect(CSocket.Client.ID, "relive"), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
                                        }
                                        break;
                                    }
                                case 133: // Jump
                                    {
                                        CSocket.Client.LastAttack = 0;
                                        //TODO: Pet jumps
                                        int NewX = ReadShort(data, 12);
                                        int NewY = ReadShort(data, 14);
                                        if (CSocket.Client.Attack != null)
                                        {
                                            if (CSocket.Client.Attack.Enabled)
                                            {
                                                CSocket.Client.Attack.Stop();
                                                CSocket.Client.Attack.Dispose();
                                            }
                                        }
                                        if (CSocket.Client.UpStam.Enabled)
                                        {
                                            CSocket.Client.UpStam.Stop();
                                        }
                                        Handler.Jump(NewX, NewY, CSocket);
                                        break;
                                    }
                                default:
                                    {
                                        Console.WriteLine("[GameServer] Unknown 0x3F2 Packet Subtype: " + SubType);
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region 0x3F1(1009) Item / Ping Packet
                    case 1009:
                        {
                            int Subtype = data[12];
                            //TODO: Prevent this packet from being used as a ghost.
                            if (CSocket.Client.Dead && Subtype != 27)
                            {
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You are dead.", Struct.ChatType.Top));
                                break;
                            }
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled && Subtype != 27)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }
                            switch (Subtype)
                            {
                                case 1:
                                    {
                                        Handler.ItemBuy(data, CSocket);
                                        //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[TODO] ItemBuy.", Struct.ChatType.Top));
                                        break;
                                    }
                                case 2:
                                    {
                                        Handler.ItemSell(data, CSocket);
                                        break;
                                    }
                                case 4:
                                    {
                                        int UID = ReadLong(data, 4);
                                        int Location = data[8];
                                        Handler.ItemEquip(Location, UID, CSocket);
                                        break;
                                    }
                                case 6:
                                    {
                                        int UID = ReadLong(data, 4);
                                        int Location = data[8];
                                        Handler.ItemUnequip(Location, UID, CSocket);
                                        break;
                                    }
                                case 9://Request WHS Money
                                    {
                                        int ID = ReadLong(data, 4);
                                        CSocket.Send(ConquerPacket.ItemUsage(ID, CSocket.Client.WHMoney, Struct.ItemUsage.ViewWarehouse));
                                        break;
                                    }
                                case 10://Deposit WHS Money
                                    {
                                        int Amount = ReadLong(data, 8);
                                        if (CSocket.Client.Money >= Amount)
                                        {
                                            CSocket.Client.Money -= Amount;
                                            CSocket.Client.WHMoney += Amount;
                                            CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.Money, Struct.StatusTypes.InvMoney));
                                        }
                                        break;
                                    }
                                case 11://Withdraw WHS Money
                                    {
                                        int Amount = ReadLong(data, 8);
                                        if (CSocket.Client.WHMoney >= Amount)
                                        {
                                            CSocket.Client.WHMoney -= Amount;
                                            CSocket.Client.Money += Amount;
                                            CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.Money, Struct.StatusTypes.InvMoney));
                                        }
                                        break;
                                    }
                                case 20://Upgrade Item w/ met
                                    {
                                        int Reagent = ReadLong(data, 8);
                                        int ItemUID = ReadLong(data, 4);
                                        if (CSocket.Client.Inventory.ContainsKey(ItemUID) && CSocket.Client.Inventory.ContainsKey(Reagent))
                                        {
                                            Struct.ItemInfo Meteor = CSocket.Client.Inventory[Reagent];
                                            if (Meteor.ItemID != 1088001)
                                                break;
                                            Struct.ItemInfo Item = CSocket.Client.Inventory[ItemUID];
                                            if (Calculation.CanUpgrade(Convert.ToString(Item.ItemID)))
                                            {
                                                Struct.ItemData iData = Nano.Items[Item.ItemID];
                                                if (iData.Level < 130)
                                                {
                                                    if (Calculation.Type2(Convert.ToString(Item.ItemID)) == 11 && Calculation.WeaponType(Convert.ToString(Item.ItemID)) != 117 && iData.Level < 120 || Calculation.WeaponType(Convert.ToString(Item.ItemID)) == 117 && iData.Level < 112 || Calculation.Type2(Convert.ToString(Item.ItemID)) == 13 && iData.Level < 120 || Calculation.Type2(Convert.ToString(Item.ItemID)) == 15 && iData.Level < 127 || Calculation.Type2(Convert.ToString(Item.ItemID)) == 16 && iData.Level < 129 || Calculation.Type1(Convert.ToString(Item.ItemID)) == 4 || Calculation.Type1(Convert.ToString(Item.ItemID)) == 5 || Calculation.Type2(Convert.ToString(Item.ItemID)) == 12 || Calculation.WeaponType(Convert.ToString(Item.ItemID)) == 132 && iData.Level <= 12)
                                                    {
                                                        bool Upgraded = false;
                                                        double LessChance = iData.Level / 3;
                                                        Console.WriteLine(Calculation.Quality(Convert.ToString(Item.ItemID)) + ", " + (120 - LessChance));
                                                        if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 3 || Calculation.Quality(Convert.ToString(Item.ItemID)) == 4 || Calculation.Quality(Convert.ToString(Item.ItemID)) == 5)
                                                        {
                                                            if (Calculation.PercentSuccess(99 - LessChance))
                                                                Upgraded = true;
                                                        }
                                                        else if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 6)
                                                        {
                                                            if (Calculation.PercentSuccess(90 - LessChance))
                                                                Upgraded = true;
                                                        }
                                                        else if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 7)
                                                        {
                                                            if (Calculation.PercentSuccess(87 - LessChance))
                                                                Upgraded = true;
                                                        }
                                                        else if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 8)
                                                        {
                                                            if (Calculation.PercentSuccess(83 - LessChance))
                                                                Upgraded = true;
                                                        }
                                                        else if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 9)
                                                        {
                                                            if (Calculation.PercentSuccess(79 - LessChance))
                                                            {
                                                                Upgraded = true;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (Calculation.PercentSuccess(99 - LessChance))
                                                                Upgraded = true;
                                                        }
                                                        if (Upgraded)
                                                        {
                                                            CSocket.Send(ConquerPacket.ItemUsage(Reagent, 255, Struct.ItemUsage.RemoveItem));
                                                            CSocket.Send(ConquerPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveItem));
                                                            Database.Database.DeleteItem(Reagent);
                                                            CSocket.Client.Inventory.Remove(Reagent);
                                                            Item.ItemID = Calculation.NextEquipLevel(Item.ItemID);
                                                            if (Item.Soc1 == 0)
                                                            {
                                                                if (Calculation.PercentSuccess(0.00033))
                                                                {
                                                                    Item.Soc1 = 255;
                                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "What a lucky person, your item has just gotten an extra socket! Congratulations!", Struct.ChatType.Top));
                                                                }
                                                            }
                                                            if (Item.Soc1 > 0)
                                                            {
                                                                if (Item.Soc2 == 0)
                                                                {
                                                                    if (Calculation.PercentSuccess(0.00022))
                                                                    {
                                                                        Item.Soc2 = 255;
                                                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "What a lucky person, your item has just gotten an extra socket! Congratulations!", Struct.ChatType.Top));
                                                                    }
                                                                }
                                                            }
                                                            Database.Database.UpdateItem(Item);
                                                            CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                                                        }
                                                        else
                                                        {
                                                            CSocket.Send(ConquerPacket.ItemUsage(Reagent, 255, Struct.ItemUsage.RemoveItem));
                                                            Database.Database.DeleteItem(Reagent);
                                                            CSocket.Client.Inventory.Remove(Reagent);
                                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Better luck next time!", Struct.ChatType.Top));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case 19://DB Upgrade
                                    {
                                        int ItemUID = ReadLong(data, 4);
                                        int Reagent = ReadLong(data, 8);
                                        if (CSocket.Client.Inventory.ContainsKey(ItemUID) && CSocket.Client.Inventory.ContainsKey(Reagent))
                                        {
                                            Struct.ItemInfo Item = CSocket.Client.Inventory[ItemUID];
                                            Struct.ItemInfo DB = CSocket.Client.Inventory[Reagent];
                                            if (DB.ItemID != 1088000)
                                                break;
                                            if (Calculation.CanUpgrade(Convert.ToString(Item.ItemID)))
                                            {
                                                Struct.ItemData iData = Nano.Items[Item.ItemID];
                                                if (Calculation.Quality(Convert.ToString(Item.ItemID)) < 9)
                                                {
                                                    bool Upgraded = false;
                                                    double LessChance = iData.Level / 3;
                                                    if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 3 || Calculation.Quality(Convert.ToString(Item.ItemID)) == 4 || Calculation.Quality(Convert.ToString(Item.ItemID)) == 5)
                                                    {
                                                        if (Calculation.PercentSuccess(90 - LessChance))
                                                            Upgraded = true;
                                                    }
                                                    else if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 6)
                                                    {
                                                        if (Calculation.PercentSuccess(80 - LessChance))
                                                            Upgraded = true;
                                                    }
                                                    else if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 7)
                                                    {
                                                        if (Calculation.PercentSuccess(70 - LessChance))
                                                            Upgraded = true;
                                                    }
                                                    else if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 8)
                                                    {
                                                        if (Calculation.PercentSuccess(55 - LessChance))
                                                            Upgraded = true;
                                                    }
                                                    else
                                                    {
                                                        if (Calculation.PercentSuccess(90 - LessChance))
                                                            Upgraded = true;
                                                    }
                                                    if (Upgraded)
                                                    {
                                                        CSocket.Send(ConquerPacket.ItemUsage(Reagent, 255, Struct.ItemUsage.RemoveItem));
                                                        CSocket.Send(ConquerPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveItem));
                                                        Database.Database.DeleteItem(Reagent);
                                                        CSocket.Client.Inventory.Remove(Reagent);
                                                        if (Calculation.Quality(Convert.ToString(Item.ItemID)) == 3 || Calculation.Quality(Convert.ToString(Item.ItemID)) == 4)
                                                            Item.ItemID += 6 - Calculation.Quality(Convert.ToString(Item.ItemID));
                                                        else
                                                            Item.ItemID += 1;
                                                        if (Item.Soc1 == 0)
                                                        {
                                                            if (Calculation.PercentSuccess(0.00033))
                                                            {
                                                                Item.Soc1 = 255;
                                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "What a lucky person, your item has just gotten an extra socket! Congratulations!", Struct.ChatType.Top));
                                                            }
                                                        }
                                                        if (Item.Soc1 > 0)
                                                        {
                                                            if (Item.Soc2 == 0)
                                                            {
                                                                if (Calculation.PercentSuccess(0.00022))
                                                                {
                                                                    Item.Soc2 = 255;
                                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "What a lucky person, your item has just gotten an extra socket! Congratulations!", Struct.ChatType.Top));
                                                                }
                                                            }
                                                        }
                                                        Database.Database.UpdateItem(Item);
                                                        CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                                                    }
                                                    else
                                                    {
                                                        CSocket.Send(ConquerPacket.ItemUsage(Reagent, 255, Struct.ItemUsage.RemoveItem));
                                                        Database.Database.DeleteItem(Reagent);
                                                        CSocket.Client.Inventory.Remove(Reagent);
                                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Better luck next time!", Struct.ChatType.Top));
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case 27://Reply to ping
                                    {
                                        CSocket.Send(ReturnFinal(data));
                                        Database.Database.SaveCharacter(CSocket.Client);
                                        break;
                                    }
                                case 37://Drop item
                                    {
                                        int UID = ReadLong(data, 4);
                                        Handler.DropItem(UID, CSocket);
                                        break;
                                    }
                                default:
                                    {
                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown 1009 Subtype: " + Subtype, Struct.ChatType.Talk));
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region 0x3ED(1005) Walk Packet
                    case 1005: //Walk packet
                        {
                            //CSocket.Client.LastAttack = 0;
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }
                            Handler.Walk((ReadShort(data, 8) % 8), CSocket);
                            break;
                        }
                    #endregion
                    #region 3EC(1004) Chat Packet
                    case 1004:
                        {
                            Handler.Chat(data, CSocket);
                            break;
                        }
                    #endregion
                    #region NPC Talks
                    case 2031: //Initial NPC talk
                        {
                            int ID = ReadLong(data, 4);
                            Handler.NpcTalk(CSocket, ID, 0);
                            break;
                        }
                    case 2032: //Reply NPC Talk
                        {
                            int ID = CSocket.Client.LastNPC;
                            int LinkBack = data[10];
                            if (LinkBack != 255)
                                Handler.NpcTalk(CSocket, ID, LinkBack);
                            break;
                        }
                    #endregion
                    #region Attack
                    case 1022:
                        {
                            int AType = (data[23] << 24) + (data[22] << 16) + (data[21] << 8) + (data[20]);
                            //Console.WriteLine(System.Environment.TickCount - CSocket.Client.LastAttack);
                            if (System.Environment.TickCount - CSocket.Client.LastAttack < 450 && CSocket.Client.LastAttack > 0)
                            {
                                break;
                            }
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }
                            if (CSocket.Client.UpStam.Enabled)
                            {
                                CSocket.Client.UpStam.Stop();
                            }
                            CSocket.Client.LastAttack = System.Environment.TickCount;
                            switch (AType)
                            {
                                case 2://Melee
                                    {
                                        int Target = (data[15] << 24) + (data[14] << 16) + (data[13] << 8) + (data[12]);
                                        Handler.Attack(Target, 0, 2, CSocket.Client.X, CSocket.Client.Y, CSocket);
                                        break;
                                    }
                                case 21: // Magical
                                    {
                                        int TargetID = 0;
                                        int decskill = 0;
                                        int decx = 0;
                                        int decy = 0;
                                        long targ = ((long)data[12] & 0xFF) | (((long)data[13] & 0xFF) << 8) | (((long)data[14] & 0xFF) << 16) | (((long)data[15] & 0xFF) << 24);
                                        targ = ((((targ & 0xffffe000) >> 13) | ((targ & 0x1fff) << 19)) ^ 0x5F2D2463 ^ CSocket.Client.ID) - 0x746F4AE6;
                                        TargetID = Convert.ToInt32(targ);
                                        ushort myvar = Convert.ToUInt16(((long)data[24] & 0xFF) | (((long)data[25] & 0xFF) << 8));
                                        myvar ^= (ushort)0x915d;
                                        myvar ^= (ushort)CSocket.Client.ID;
                                        myvar = (ushort)(myvar << 0x3 | myvar >> 0xd);
                                        myvar -= 0xeb42;
                                        decskill = myvar;
                                        long xx = (data[16] & 0xFF) | ((data[17] & 0xFF) << 8);
                                        long yy = (data[18] & 0xFF) | ((data[19] & 0xFF) << 8);
                                        xx = xx ^ (CSocket.Client.ID & 0xffff) ^ 0x2ed6;
                                        xx = ((xx << 1) | ((xx & 0x8000) >> 15)) & 0xffff;
                                        xx |= 0xffff0000;
                                        xx -= 0xffff22ee;
                                        yy = yy ^ (CSocket.Client.ID & 0xffff) ^ 0xb99b;
                                        yy = ((yy << 5) | ((yy & 0xF800) >> 11)) & 0xffff;
                                        yy |= 0xffff0000;
                                        yy -= 0xffff8922;
                                        decx = Convert.ToInt32(xx);
                                        decy = Convert.ToInt32(yy);
                                        Handler.Attack(TargetID, decskill, 21, decx, decy, CSocket);
                                        break;
                                    }
                                case 25:
                                    {
                                        int TargetID = (data[15] << 24) + (data[14] << 16) + (data[13] << 8) + (data[12]);
                                        Handler.Attack(TargetID, 0, 25, CSocket.Client.X, CSocket.Client.Y, CSocket);
                                        break;
                                    }
                                default:
                                    {
                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Handler-Error] Please report: Unable to handle 1002 subtype " + AType, Struct.ChatType.Top));
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region ItemPickup
                    case 1101: //Item pickup
                        {
                            int UID = (int)((data[7] << 24) + (data[6] << 16) + (data[5] << 8) + data[4]);
                            Handler.PickupItem(UID, CSocket);
                            break;
                        }
                    #endregion
                    #region SocketGem
                    case 1027:
                        {
                            int ItemID = (data[11] << 24) + (data[10] << 16) + (data[9] << 8) + (data[8]);
                            int GemID = (data[15] << 24) + (data[14] << 16) + (data[13] << 8) + (data[12]);
                            int socket = (data[17] << 8) + (data[16]);
                            Handler.SocketGem(ItemID, GemID, socket, CSocket);
                            break;
                        }
                    #endregion
                    #region Attribute Points
                    case 1024:
                        {
                            int Str = data[4];
                            int Dex = data[5];
                            int Vit = data[6];
                            int Spi = data[7];
                            if (Str > 0)
                            {
                                if (CSocket.Client.StatPoints >= 1)
                                {
                                    CSocket.Client.StatPoints -= 1;
                                    CSocket.Client.Strength += 1;
                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You now have " + CSocket.Client.Strength + " strength!", Struct.ChatType.Top));
                                }
                                else
                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You do not have enough attribute points to add more points into that attribute.", Struct.ChatType.Top));
                            }
                            if (Dex > 0)
                            {
                                if (CSocket.Client.StatPoints >= 1)
                                {
                                    CSocket.Client.StatPoints -= 1;
                                    CSocket.Client.Dexterity += 1;
                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You now have " + CSocket.Client.Dexterity + " dexterity!", Struct.ChatType.Top));
                                }
                                else
                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You do not have enough attribute points to add more points into that attribute.", Struct.ChatType.Top));
                            }
                            if (Vit > 0)
                            {
                                if (CSocket.Client.StatPoints >= 1)
                                {
                                    CSocket.Client.StatPoints -= 1;
                                    CSocket.Client.Vitality += 1;
                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You now have " + CSocket.Client.Vitality + " vitality!", Struct.ChatType.Top));
                                }
                                else
                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You do not have enough attribute points to add more points into that attribute.", Struct.ChatType.Top));
                            }
                            if (Spi > 0)
                            {
                                if (CSocket.Client.StatPoints >= 1)
                                {
                                    CSocket.Client.StatPoints -= 1;
                                    CSocket.Client.Spirit += 1;
                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You now have " + CSocket.Client.Spirit + " spirit!", Struct.ChatType.Top));
                                }
                                else
                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You do not have enough attribute points to add more points into that attribute.", Struct.ChatType.Top));
                            }
                            Calculation.Vitals(CSocket, false);
                            break;
                        }
                    #endregion
                    #region Team
                    case 1023:
                        {
                            int subtype = data[4];
                            switch (subtype)
                            {
                                case 0://Create team
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Client.Team = new Struct.Team();
                                            CSocket.Client.Team.LeaderID = CSocket.Client.ID;
                                            CSocket.Client.Team.Forbid = false;
                                            CSocket.Client.Team.Members.Add(CSocket.Client.ID, CSocket);
                                            CSocket.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.MakeTeam));
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are already in a team!", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 1://Request to join
                                    {
                                        if (CSocket.Client.Team != null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are already in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        int Leader = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(Leader))
                                        {
                                            ClientSocket TeamLeader = Nano.ClientPool[Leader];
                                            if (TeamLeader.Client.Team != null)
                                            {
                                                if (TeamLeader.Client.Team.LeaderID == TeamLeader.Client.ID)
                                                {
                                                    if (!TeamLeader.Client.Team.Forbid)
                                                    {
                                                        if (TeamLeader.Client.Team.Members.Count < 5)
                                                        {
                                                            TeamLeader.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.JoinTeam));
                                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Team] Request to join team sent to " + TeamLeader.Client.Name, Struct.ChatType.Top));
                                                        }
                                                        else
                                                        {
                                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + "'s team is full.", Struct.ChatType.Top));
                                                        }
                                                    }
                                                    else
                                                    {
                                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + "'s team forbids new members.", Struct.ChatType.Top));
                                                    }
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + " is not the team leader.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + " has not created a team.", Struct.ChatType.Top));
                                            }
                                        }
                                        break;
                                    }
                                case 2://Exit Team
                                    {
                                        if (CSocket.Client.Team != null)
                                        {
                                            ClientSocket Leader = Nano.ClientPool[CSocket.Client.Team.LeaderID];
                                            foreach (KeyValuePair<int, ClientSocket> Member in Leader.Client.Team.Members)
                                            {
                                                if (Member.Value.Client.ID != CSocket.Client.ID)
                                                {
                                                    Member.Value.Send(ConquerPacket.Chat(0, "SYSTEM", Member.Value.Client.Name, "[Team] " + CSocket.Client.Name + " has just left the team!", Struct.ChatType.Top));
                                                    Member.Value.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.LeaveTeam));
                                                }
                                            }
                                            Leader.Client.Team.Members.Remove(CSocket.Client.ID);
                                            CSocket.Client.Team = null;
                                            //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Team] You have left the team.", Struct.ChatType.Top));
                                            CSocket.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.LeaveTeam));
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 3: //Accept Invite
                                    {
                                        if (CSocket.Client.Team != null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are already in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        int Inviter = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(Inviter))
                                        {
                                            ClientSocket TeamLeader = Nano.ClientPool[Inviter];
                                            if (TeamLeader.Client.Team != null)
                                            {
                                                if (TeamLeader.Client.Team.Members.Count < 5)
                                                {
                                                    if (!TeamLeader.Client.Team.Forbid)
                                                    {
                                                        foreach (KeyValuePair<int, ClientSocket> Member in TeamLeader.Client.Team.Members)
                                                        {
                                                            Member.Value.Send(ConquerPacket.TeamMember(CSocket.Client));
                                                            CSocket.Send(ConquerPacket.TeamMember(Member.Value.Client));
                                                        }
                                                        TeamLeader.Client.Team.Members.Add(CSocket.Client.ID, CSocket);
                                                        CSocket.Client.Team = TeamLeader.Client.Team;
                                                    }
                                                    else
                                                    {
                                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter's team does not accept new members.", Struct.ChatType.Top));
                                                    }
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter's team is full.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter no longer has a team.", Struct.ChatType.Top));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter is no longer online.", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 4: //Invite to join
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot invite new members!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        int Invited = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(Invited))
                                        {
                                            ClientSocket InvitedCSocket = Nano.ClientPool[Invited];
                                            if (InvitedCSocket.Client.Team == null)
                                            {
                                                if (!CSocket.Client.Team.Forbid)
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Team] Invited " + InvitedCSocket.Client.Name + " to join your team.", Struct.ChatType.Top));
                                                    InvitedCSocket.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.Invite));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your team forbids new members from joining.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target is already in a team.", Struct.ChatType.Top));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target does not exist.", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 5://Accept join request
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot accept join requests.", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        int ToJoin = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(ToJoin))
                                        {
                                            ClientSocket Invited = Nano.ClientPool[ToJoin];
                                            if (Invited.Client.Team == null)
                                            {
                                                if (!CSocket.Client.Team.Forbid)
                                                {
                                                    foreach (KeyValuePair<int, ClientSocket> Member in CSocket.Client.Team.Members)
                                                    {
                                                        Member.Value.Send(ConquerPacket.TeamMember(Invited.Client));
                                                        Invited.Send(ConquerPacket.TeamMember(Member.Value.Client));
                                                    }
                                                    CSocket.Client.Team.Members.Add(Invited.Client.ID, Invited);
                                                    Invited.Client.Team = CSocket.Client.Team;
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your team forbids new members from joining.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target is already in a team.", Struct.ChatType.Top));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target does not exist.", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 6: //Dismiss
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot dismiss the team.", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        foreach (KeyValuePair<int, ClientSocket> Member in CSocket.Client.Team.Members)
                                        {
                                            if (Member.Value.Client.ID != CSocket.Client.ID)
                                            {
                                                Member.Value.Send(ConquerPacket.Team(Member.Value.Client.ID, Struct.TeamOption.DismissTeam));
                                                Member.Value.Client.Team = null;
                                            }
                                        }
                                        CSocket.Client.Team = null;
                                        CSocket.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.DismissTeam));
                                        break;
                                    }
                                case 7: //Kick from team
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot kick team members.", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        int Kick = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(Kick))
                                        {
                                            if (CSocket.Client.Team.Members.ContainsKey(Kick))
                                            {
                                                foreach (KeyValuePair<int, ClientSocket> Member in CSocket.Client.Team.Members)
                                                {
                                                    Member.Value.Send(ConquerPacket.Team(Kick, Struct.TeamOption.Kick));
                                                    if (Member.Value.Client.ID == Kick)
                                                    {
                                                        Member.Value.Client.Team = null;
                                                    }
                                                }
                                                CSocket.Client.Team.Members.Remove(Kick);
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target not in team.", Struct.ChatType.Top));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target does not exist.", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 8://Forbid
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (!CSocket.Client.Team.Forbid)
                                        {
                                            CSocket.Client.Team.Forbid = true;
                                        }
                                        break;
                                    }
                                case 9: //Unforbid
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.Forbid)
                                        {
                                            CSocket.Client.Team.Forbid = false;
                                        }
                                        break;
                                    }
                                case 10://unForbidMoney
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.ForbidMoney)
                                        {
                                            CSocket.Client.Team.ForbidMoney = false;
                                        }
                                        break;
                                    }
                                case 11://forbidMoney
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.ForbidMoney)
                                        {
                                            CSocket.Client.Team.ForbidMoney = false;
                                        }
                                        break;
                                    }
                                case 12://ForbidItems
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (!CSocket.Client.Team.ForbidItems)
                                        {
                                            CSocket.Client.Team.ForbidItems = true;
                                        }
                                        break;
                                    }
                                case 13://unForbidItems
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.ForbidItems)
                                        {
                                            CSocket.Client.Team.ForbidItems = false;
                                        }
                                        break;
                                    }
                                default:
                                    {
                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown team subtype: " + subtype, Struct.ChatType.Top));
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region Warehouse
                    case 1102:
                        {
                            int ID = ReadLong(data, 4);
                            int SType = data[8];
                            if (SType == 0)
                            {
                                CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                            }
                            else if (SType == 1)//Put into WHS
                            {
                                int UID = ReadLong(data, 12);
                                if (CSocket.Client.Inventory.ContainsKey(UID))
                                {
                                    Struct.ItemInfo Item = CSocket.Client.Inventory[UID];
                                    switch ((int)CSocket.Client.Map)
                                    {
                                        case 1002:
                                            {
                                                if (CSocket.Client.TCWhs.Count < 20)
                                                {
                                                    Item.Position = 1002;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.Inventory.Remove(UID);
                                                    CSocket.Send(ConquerPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveItem));
                                                    CSocket.Client.TCWhs.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] TC Whs is full.", Struct.ChatType.Top));
                                                }
                                                break;
                                            }
                                        case 1011:
                                            {
                                                if (CSocket.Client.PCWhs.Count < 20)
                                                {
                                                    Item.Position = 1011;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.Inventory.Remove(UID);
                                                    CSocket.Send(ConquerPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveItem));
                                                    CSocket.Client.PCWhs.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] PC Whs is full.", Struct.ChatType.Top));
                                                }
                                                break;
                                            }
                                        case 1000:
                                            {
                                                if (CSocket.Client.DCWhs.Count < 20)
                                                {
                                                    Item.Position = 1000;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.Inventory.Remove(UID);
                                                    CSocket.Send(ConquerPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveItem));
                                                    CSocket.Client.DCWhs.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] DC Whs is full.", Struct.ChatType.Top));
                                                }
                                                break;
                                            }
                                        case 1015:
                                            {
                                                if (CSocket.Client.BIWhs.Count < 20)
                                                {
                                                    Item.Position = 1015;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.Inventory.Remove(UID);
                                                    CSocket.Send(ConquerPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveItem));
                                                    CSocket.Client.BIWhs.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] BI Whs is full.", Struct.ChatType.Top));
                                                }
                                                break;
                                            }
                                        case 1020:
                                            {
                                                if (CSocket.Client.AMWhs.Count < 20)
                                                {
                                                    Item.Position = 1020;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.Inventory.Remove(UID);
                                                    CSocket.Send(ConquerPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveItem));
                                                    CSocket.Client.AMWhs.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] AC(M) Whs is full.", Struct.ChatType.Top));
                                                }
                                                break;
                                            }
                                        case 1036:
                                            {
                                                if (CSocket.Client.MAWhs.Count < 40)
                                                {
                                                    Item.Position = 1036;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.Inventory.Remove(UID);
                                                    CSocket.Send(ConquerPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveItem));
                                                    CSocket.Client.MAWhs.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] MA Whs is full.", Struct.ChatType.Top));
                                                }
                                                break;
                                            }
                                    }
                                }
                            }
                            else if (SType == 2)//Take out
                            {
                                int UID = ReadLong(data, 12);
                                switch ((int)CSocket.Client.Map)
                                {
                                    case 1002:
                                        {
                                            if (CSocket.Client.TCWhs.ContainsKey(UID))
                                            {
                                                if (CSocket.Client.Inventory.Count < 40)
                                                {
                                                    Struct.ItemInfo Item = CSocket.Client.TCWhs[UID];
                                                    Item.Position = 0;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.TCWhs.Remove(UID);
                                                    CSocket.Client.Inventory.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                    CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inventory is full.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item isn't in TC Whs.", Struct.ChatType.Top));
                                            }
                                            break;
                                        }
                                    case 1011:
                                        {
                                            if (CSocket.Client.PCWhs.ContainsKey(UID))
                                            {
                                                if (CSocket.Client.Inventory.Count < 40)
                                                {
                                                    Struct.ItemInfo Item = CSocket.Client.PCWhs[UID];
                                                    Item.Position = 0;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.PCWhs.Remove(UID);
                                                    CSocket.Client.Inventory.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                    CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inventory is full.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item isn't in PC Whs.", Struct.ChatType.Top));
                                            }
                                            break;
                                        }
                                    case 1000:
                                        {
                                            if (CSocket.Client.DCWhs.ContainsKey(UID))
                                            {
                                                if (CSocket.Client.Inventory.Count < 40)
                                                {
                                                    Struct.ItemInfo Item = CSocket.Client.DCWhs[UID];
                                                    Item.Position = 0;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.DCWhs.Remove(UID);
                                                    CSocket.Client.Inventory.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                    CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inventory is full.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item isn't in DC Whs.", Struct.ChatType.Top));
                                            }
                                            break;
                                        }
                                    case 1015:
                                        {
                                            if (CSocket.Client.BIWhs.ContainsKey(UID))
                                            {
                                                if (CSocket.Client.Inventory.Count < 40)
                                                {
                                                    Struct.ItemInfo Item = CSocket.Client.BIWhs[UID];
                                                    Item.Position = 0;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.BIWhs.Remove(UID);
                                                    CSocket.Client.Inventory.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                    CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inventory is full.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item isn't in BI Whs.", Struct.ChatType.Top));
                                            }
                                            break;
                                        }
                                    case 1020:
                                        {
                                            if (CSocket.Client.AMWhs.ContainsKey(UID))
                                            {
                                                if (CSocket.Client.Inventory.Count < 40)
                                                {
                                                    Struct.ItemInfo Item = CSocket.Client.AMWhs[UID];
                                                    Item.Position = 0;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.AMWhs.Remove(UID);
                                                    CSocket.Client.Inventory.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                    CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inventory is full.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item isn't in AC(M) Whs.", Struct.ChatType.Top));
                                            }
                                            break;
                                        }
                                    case 1036:
                                        {
                                            if (CSocket.Client.MAWhs.ContainsKey(UID))
                                            {
                                                if (CSocket.Client.Inventory.Count < 40)
                                                {
                                                    Struct.ItemInfo Item = CSocket.Client.MAWhs[UID];
                                                    Item.Position = 0;
                                                    Database.Database.UpdateItem(Item);
                                                    CSocket.Client.MAWhs.Remove(UID);
                                                    CSocket.Client.Inventory.Add(UID, Item);
                                                    CSocket.Send(ConquerPacket.WarehouseItems(CSocket, ID));
                                                    CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inventory is full.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item isn't in MA Whs.", Struct.ChatType.Top));
                                            }
                                            break;
                                        }
                                }
                            }
                            break;
                        }
                    #endregion
                    default:
                        {
                            Console.WriteLine("[GameServer] Unknown packet type: " + Type);
                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Handler-Error] Please report: Unable to handle packet type " + Type, Struct.ChatType.Top));
                            break;
                        }
                }
                if (Split1 != null)
                    ProcessPacket(Split1, CSocket);
                if (Split2 != null)
                    ProcessPacket(Split2, CSocket);
                if (Split3 != null)
                    ProcessPacket(Split3, CSocket);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return;
            }
        }
Exemple #7
0
 public static void Text(string value, ClientSocket CSocket)
 {
     CSocket.Send(EudemonPacket.NPCTalk(255, 1, value));
 }
Exemple #8
0
 public static void Link(string value, int LinkBack, ClientSocket CSocket)
 {
     CSocket.Send(EudemonPacket.NPCTalk(LinkBack, 2, value));
 }
Exemple #9
0
 public static void End(ClientSocket CSocket)
 {
     CSocket.Send(EudemonPacket.NPCTalk(0, 0, 255, 100));
 }
Exemple #10
0
        public static void ProcessPacket(byte[] data, ClientSocket CSocket)
        {
            try
            {
                #region Packet Splitter
                //@TODO: move packetsplitting to a faster function, possibly async for faster packet processing (consider thread counts of doing so however.. also need to remove the creation of a new thread for each client, upon a lot of load it wouldn't work out well)

                byte[] Split1 = null;
                byte[] Split2 = null;
                byte[] Split3 = null;
                byte[] Split4 = null;
                byte[] Split5 = null;

                int Type = (BitConverter.ToInt16(data, 2));
                int Length = (BitConverter.ToInt16(data, 0));
                String Tmp = BitConverter.ToString(data);
                if (data.Length > Length)
                {
                    int Len2 = BitConverter.ToInt16(data, 0 + Length);
                    Split1 = new byte[Len2];
                    Array.Copy(data,Length,Split1,0,Len2);

                    if (data.Length > Length + Len2)
                    {

                        int Len3 = BitConverter.ToInt16(data, 0 + Length + Len2);
                        Split2 = new byte[Len3];
                        Array.Copy(data, Length + Len2, Split2, 0, Len3);

                        if (data.Length > Length + Len2 + Len3)
                        {
                            int Len4 = BitConverter.ToInt16(data, 0 + Length + Len2 + Len3);
                            Split3 = new byte[Len4];
                            Array.Copy(data, Length + Len2 + Len3, Split3, 0, Len4);

                            if (data.Length > Length + Len2 + Len3 + Len4)
                            {
                                int Len5 = BitConverter.ToInt16(data, 0 + Length + Len2 + Len3 + Len4);
                                Split4 = new byte[Len5];
                                Array.Copy(data, Length + Len2 + Len3 + Len4, Split4, 0, Len5);

                                if (data.Length > Length + Len2 + Len3 + Len4 + Len5)
                                {
                                    int Len6 = BitConverter.ToInt16(data, 0 + Length + Len2 + Len3 + Len4 + Len5);
                                    Split5 = new byte[Len6];
                                    Array.Copy(data, Length + Len2 + Len3 + Len4 + Len5, Split5, 0, Len6);

                                    if (data.Length > Length + Len2 + Len3 + Len4 + Len5 + Len6)
                                    {
                                        Console.WriteLine("WARNING: Too many bulk packets");
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
                Console.ForegroundColor = ConsoleColor.Red;
                if(CSocket.Client != null)
                    Console.WriteLine("[PacketLog] New Packet Received From [" + CSocket.Client.ID + " - " + CSocket.Client.Name + "] Packet Type: " + Type + " Packet Size: " + Length);
                else
                    Console.WriteLine("[PacketLog] New Packet Received From [Unknown Client] Packet Type: " + Type + " Packet Size: " + Length);
                Console.ResetColor();
                Console.WriteLine(Dump(data));
                switch (Type)
                {
                    #region Begin Cleint Auth (1052)
                    case 1052: //End Authorization Process.
                        {
                            ulong Keys;
                            Keys = data[11];
                            Keys = (Keys << 8) | data[10];
                            Keys = (Keys << 8) | data[9];
                            Keys = (Keys << 8) | data[8];
                            Keys = (Keys << 8) | data[7];
                            Keys = (Keys << 8) | data[6];
                            Keys = (Keys << 8) | data[5];
                            Keys = (Keys << 8) | data[4];
                            Console.WriteLine("[GameServer] Confirming login with LoginServer");

                            if (MainGS.AuthenticatedLogins.ContainsKey(Keys))
                            {
                                CSocket.AccountName = MainGS.AuthenticatedLogins[Keys].Account;
                                Console.WriteLine("[GameServer] Authenticated Login.");
                                ConnectionRequest User = MainGS.AuthenticatedLogins[Keys];
                                User.Expire(false);
                                CSocket.Client = Database.Database.GetCharacter(User.Account);
                                if (CSocket.Client == null)
                                {
                                    Console.WriteLine("[" + MainGS.AuthenticatedLogins[Keys].Key + "] Making account");

                                    CSocket.Send(EudemonPacket.Chat(5, "SYSTEM", "ALLUSERS", "NEW_ROLE", Struct.ChatType.LoginInformation));
                                    return;
                                }

                                Console.WriteLine("[GameServer] Login Sequence started for " + CSocket.Client.Name);
                                Calculation.Vitals(CSocket, true);
                                Database.Database.GetItems(CSocket);

                                Calculation.BP(CSocket.Client);
                                if (CSocket.Client.First)
                                {
                                    CSocket.Client.CurrentMP = CSocket.Client.MaxMP;
                                    CSocket.Client.CurrentHP = CSocket.Client.MaxHP;
                                }
                                if (MainGS.ClientPool.ContainsKey(CSocket.Client.ID))
                                {
                                    ClientSocket C = MainGS.ClientPool[CSocket.Client.ID];
                                    C.Send(EudemonPacket.Chat(0, "SYSTEM", C.Client.Name, "[ERROR] Your character has logged in from another location, you're being booted.", Struct.ChatType.Talk));
                                    C.Disconnect();
                                }
                                try
                                {
                                    Monitor.Enter(MainGS.ClientPool);
                                    MainGS.ClientPool.Add(CSocket.Client.ID, CSocket);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.ToString());
                                }
                                finally
                                {
                                    Monitor.Exit(MainGS.ClientPool);
                                }
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", "ANSWER_OK", Struct.ChatType.LoginInformation));
                                CSocket.Send(EudemonPacket.CharacterInfo(CSocket));
                                CSocket.Send(EudemonPacket.Status(CSocket, Struct.StatusTypes.MAXMANA, CSocket.Client.MaxMP));

                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Welcome to EO Emu, " + CSocket.Client.Name, Struct.ChatType.Talk));
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "There are currently " + MainGS.ClientPool.Count + " players online.", Struct.ChatType.Talk));

                                if (CSocket.Client.First)
                                {
                                    Database.Database.SaveCharacter(CSocket.Client);
                                    Handler.Text("Welcome to the world of EOEmu!", CSocket);
                                    Handler.End(CSocket);
                                }
                                EudemonPacket.ToServer(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", CSocket.Client.Name + " has come online.", Struct.ChatType.System), 0);

                                CSocket.Client.Save = new System.Timers.Timer();
                                CSocket.Client.Save.Elapsed += delegate
                                {
                                    Database.Database.SaveCharacter(CSocket.Client);
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Saved " + CSocket.Client.Name, Struct.ChatType.System));
                                };
                                CSocket.Client.Save.Interval = 200000;
                                CSocket.Client.Save.Start();
                                CSocket.Client.UpStam = new System.Timers.Timer();
                                CSocket.Client.UpStam.Interval = 1000;
                                CSocket.Client.UpStam.Elapsed += delegate
                                {
                                    CSocket.AddStam();
                                };
                                CSocket.Client.UpStam.Start();
                                CSocket.Client.LastAttack = System.Environment.TickCount;

                                CSocket.Client.Tick = new System.Timers.Timer();
                                CSocket.Client.Tick.Interval = 10000;
                                CSocket.Client.Tick.Elapsed += delegate
                                {
                                    CSocket.Send(EudemonPacket.Tick(CSocket.Client.ID));
                                };
                                CSocket.Client.Tick.Start();
                                CSocket.Send(EudemonPacket.Tick(CSocket.Client.ID));

                            }
                            else
                            {
                                Console.WriteLine("[GameServer] Unauthenticated Login.");
                                CSocket.Disconnect();
                            }
                            break;
                        }
                    #endregion
                    #region CreateCharacter (1001)
                    case 1001://Create Character
                        {
                            Handler.NewCharacter(data, CSocket);
                            break;
                        }
                    #endregion
                    #region Item Packet (1009)
                    case 1009:
                        {
                            int Subtype = data[12];

                            if (CSocket.Client.Dead && Subtype != 27)
                            {
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You are dead.", Struct.ChatType.System));
                                break;
                            }
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled && Subtype != 27)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }

                            switch ((Struct.ItemUsage)Subtype)
                            {
                                case Struct.ItemUsage.BuyItem://Buy Item
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Not implemented packet 1009 Subtype: " + Subtype, Struct.ChatType.Talk));
                                        break;
                                    }
                                case Struct.ItemUsage.SellItem://Sell Item
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Not implemented packet 1009 Subtype: " + Subtype, Struct.ChatType.Talk));
                                        break;
                                    }
                                case Struct.ItemUsage.RemoveDropItem://Drop item
                                    {
                                        int UID = ReadLong(data, 4);
                                        Handler.DropItem(UID, CSocket);
                                        break;
                                    }
                                case Struct.ItemUsage.EquipUseItem://Use Item
                                    {
                                        int UID = ReadLong(data, 4);
                                        int location = data[8];
                                        Handler.ItemEquip(location, UID, CSocket);
                                        break;

                                    }
                                case Struct.ItemUsage.UnequipItem://Unequip Item
                                    {
                                        int UID = ReadLong(data, 4);
                                        int location = data[8];
                                        Handler.ItemUnequip(location, UID, CSocket);
                                        break;
                                    }
                                case Struct.ItemUsage.SplitItem://Split Item
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Not implemented packet 1009 Subtype: " + Subtype, Struct.ChatType.Talk));
                                        break;
                                    }
                                case Struct.ItemUsage.CombineItem://Combie Item
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Not implemented packet 1009 Subtype: " + Subtype, Struct.ChatType.Talk));
                                        break;
                                    }
                                case Struct.ItemUsage.ViewWarehouse://Request Money in Warehouse
                                    {

                                        int NPCID = (BitConverter.ToInt16(data, 4));
                                        CSocket.Send(EudemonPacket.ItemUsage(NPCID, CSocket.Client.WHMoney, Struct.ItemUsage.ViewWarehouse));
                                        break;
                                    }
                                case Struct.ItemUsage.DepositCash://Deposit money to Warehouse
                                    {
                                        int NPCID = (BitConverter.ToInt16(data, 4));
                                        int Money = (BitConverter.ToInt16(data, 8));
                                        if (CSocket.Client.Money >= Money)
                                        {
                                            CSocket.Client.Money -= Money;
                                            CSocket.Client.WHMoney += Money;
                                            CSocket.Send(EudemonPacket.Status(CSocket, Struct.StatusTypes.InvMoney, CSocket.Client.Money));
                                        }
                                        break;
                                    }
                                case Struct.ItemUsage.WithdrawCash://Withdraw Money from Warehouse
                                    {
                                        int NPCID = (BitConverter.ToInt16(data, 4));
                                        int Amount = (BitConverter.ToInt16(data, 8));
                                        if (CSocket.Client.WHMoney >= Amount)
                                        {
                                            CSocket.Client.WHMoney -= Amount;
                                            CSocket.Client.Money += Amount;
                                            CSocket.Send(EudemonPacket.Status(CSocket, Struct.StatusTypes.InvMoney, CSocket.Client.Money));
                                        }
                                        break;
                                    }
                                case Struct.ItemUsage.DropMoney://Drop money
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Not implemented packet 1009 Subtype: " + Subtype, Struct.ChatType.Talk));
                                        break;
                                    }
                                case Struct.ItemUsage.Repair://repair item
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Not implemented packet 1009 Subtype: " + Subtype, Struct.ChatType.Talk));
                                        break;
                                    }
                                default:
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown 1009 Subtype: " + Subtype, Struct.ChatType.Talk));
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region 2036 (function keys - excape)
                    case 1123:
                        {
                            PacketBuilder Packet = new PacketBuilder(1123, 16);
                            Packet.Long(0);
                            Packet.Long(EudemonPacket.Timer);
                            Packet.Long(25200);
                            CSocket.Send(Packet.getFinal());
                            break;
                        }
                    #endregion
                    #region GameActions
                    case 2036:// excape key its seems
                        {
                            int Action = BitConverter.ToInt16(data, 4);
                            switch (Action)
                            {
                                case 473: //Game Exit
                                    {
                                        CSocket.Send(EudemonPacket.ExitPacket());
                                        break;
                                    }
                                case 515:
                                case 518:
                                    {
                                        bool Upgraded = false;

                                        int ItemId = BitConverter.ToInt32(data, 8);
                                        int GemID = BitConverter.ToInt32(data, 12);
                                        if (CSocket.Client.Inventory.ContainsKey(GemID) && CSocket.Client.Inventory.ContainsKey(ItemId))
                                        {
                                            Struct.ItemInfo Gem = CSocket.Client.Inventory[GemID];
                                            Struct.ItemInfo Item = CSocket.Client.Inventory[ItemId];

                                            List<int> PossibleGems = new List<int>(new int[]{ 1037150, 1037159 });
                                            //if (Gem.ItemID != 1037150 || Gem.ItemID != 1037159)
                                            if(!PossibleGems.Contains(Gem.ItemID))
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You Need to use a Yellow Stone Or A Super Yellow Stone!", Struct.ChatType.Talk));
                                                //@TODO: Log Uses of Non YellowStones
                                                break; //Gem isnt a YellowStone!
                                            }
                                            if (Item.Plus >= 9 && Gem.ItemID == 1037159)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You Need to use a Yellow Stone for bonuses above 9!", Struct.ChatType.Talk));
                                                break; //cant be a super yellow!
                                            }

                                            Struct.ItemData iData = MainGS.Items[Item.ItemID];

                                            double LessChance = iData.Level / 3;

                                            switch (Item.Plus)
                                            {
                                                case 0:
                                                    {
                                                        Upgraded = Calculation.PercentSuccess(90 - LessChance);
                                                        break;
                                                    }
                                                case 1:
                                                case 2:
                                                case 3:
                                                    {
                                                        Upgraded = Calculation.PercentSuccess(85 - LessChance);
                                                        break;
                                                    }
                                                case 4:
                                                    {
                                                        Upgraded = Calculation.PercentSuccess(80 - LessChance);
                                                        break;
                                                    }
                                                case 5:
                                                case 6:
                                                    {
                                                        Upgraded = Calculation.PercentSuccess(75 - LessChance);
                                                        break;
                                                    }
                                                case 7:
                                                case 8:
                                                    {
                                                        Upgraded = Calculation.PercentSuccess(70 - LessChance);
                                                        break;
                                                    }
                                                case 9:
                                                    {
                                                        Upgraded = Calculation.PercentSuccess(60 - LessChance);
                                                        break;
                                                    }
                                                case 10:
                                                case 11:
                                                    {
                                                        Upgraded = Calculation.PercentSuccess(50 - LessChance);
                                                        break;
                                                    }
                                                case 12:
                                                    {
                                                        Upgraded = Calculation.PercentSuccess(45 - LessChance);
                                                        break;
                                                    }
                                            }

                                            if (Gem.ItemID == 1037159)
                                                Upgraded = true;

                                            if (Upgraded)
                                            {
                                                Item.Plus += 1;
                                            }
                                            else
                                            {
                                                if (Item.Plus > 0)
                                                {
                                                    Item.Plus -= 1;
                                                }
                                            }

                                            CSocket.Send(EudemonPacket.ItemUsage(GemID, 0, Struct.ItemUsage.RemoveDropItem));
                                            Database.Database.DeleteItem(GemID);
                                            Database.Database.UpdateItem(Item);
                                            CSocket.Send(EudemonPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, 0, 0, 0));
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Inventory.ContainsKey(GemID))
                                                CSocket.Send(EudemonPacket.Chat(0, "ItemUpgrader", CSocket.Client.Name, "[ERROR] Gem Doesnt exist", Struct.ChatType.Talk));
                                            if (CSocket.Client.Inventory.ContainsKey(ItemId))
                                                CSocket.Send(EudemonPacket.Chat(0, "ItemUpgrader", CSocket.Client.Name, "[ERROR] Item Doesnt exist", Struct.ChatType.Talk));
                                        }

                                        break;
                                    }

                                default:
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown 2036 Actiontype: " + Action, Struct.ChatType.Talk));
                                        break;
                                    }

                            }
                            break;
                        }
                    case 1032:
                        {
                            int Subtype = data[22];
                            switch (Subtype)
                            {
                                case 107:
                                    {
                                        CSocket.Send(EudemonPacket.Dialog(898));
                                        break;
                                    }
                                case 29:
                                    {
                                        CSocket.Send(EudemonPacket.Dialog(473));
                                        break;
                                    }
                                default:
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown 1032 Subtype: " + Subtype, Struct.ChatType.Talk));
                                        break;
                                    }

                            }
                            //CSocket.Send(EudemonPacket.ExitPacket());
                            break;
                        }

                    #endregion
                    #region WalkRun Packet (3005)
                    case 3005: //WalkRun packet
                        {
                            //CSocket.Client.LastAttack = 0;
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }
                            int RX = (BitConverter.ToInt16(data, 12));
                            int RY = (BitConverter.ToInt16(data, 14));
                            //@TODO: check last cords vs current.

                            int ucDir = BitConverter.ToInt16(data, 16);

                            Handler.Walk(ucDir, CSocket);
                            break;
                        }
                    #endregion
                    #region Tick Packet (1012)
                    case 1012:
                        {
                            //@TODO: actually process and get the 1012
                            break;
                        }
                    #endregion

                    #region Multi-Function Packet 0x3f2(1010)
                    case 1010: // 0x3f2, Multi-Function Packet
                        {
                            int SubType = BitConverter.ToInt16(data, 24) - 9527;
                            ushort Dir = BitConverter.ToUInt16(data, 16);
                            int idTarget = BitConverter.ToInt32(data, 20);
                            uint dwData = BitConverter.ToUInt32(data, 20);

                            switch ((Struct.DataType)SubType)
                            {
                                case Struct.DataType.actionEnterMap: //Start login sequence. //actionEnterMap //14
                                    {
                                        Console.WriteLine("[GameServer] "+ CSocket.Client.Name + " Is Entering the Map " + CSocket.Client.Map.ToString());
                                        CSocket.Send(EudemonPacket.GeneralOld(1, (int)CSocket.Client.Map, CSocket.Client.X, CSocket.Client.Y, 0, (int)CSocket.Client.Map, Structs.Struct.DataType.actionEnterMap));
                                        CSocket.Send(EudemonPacket.NewMap((int)CSocket.Client.Map, 2097152, (int)CSocket.Client.Map)); //@TODO: Check for Instancing and Load map type from database.
                                        EudemonPacket.ToLocal(EudemonPacket.SpawnCharacter(CSocket), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                        Spawn.All(CSocket);

                                        break;
                                    }
                                case Struct.DataType.actionQueryPlayer:
                                    {
                                        ClientSocket targetCS = null;
                                        try
                                        {
                                            Monitor.Enter(MainGS.ClientPool);
                                            foreach (KeyValuePair<int, ClientSocket> Tests in MainGS.ClientPool)
                                            {
                                                ClientSocket C = Tests.Value;
                                                if (C.Client.ID == idTarget)
                                                    targetCS = C;
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e.ToString());
                                        }
                                        finally
                                        {
                                            Monitor.Exit(MainGS.ClientPool);
                                        }
                                        //@TODO: Move this to dedicated function.
                                        if (targetCS != null)
                                        {
                                            if (Calculation.GetDistance(CSocket.Client.X, CSocket.Client.Y, targetCS.Client.X, targetCS.Client.Y) <= 18) //CELLS_PER_VIEW
                                            {
                                                CSocket.Send(EudemonPacket.SpawnCharacter(targetCS));
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Info] Querying Player.", Struct.ChatType.System));//@TODO: remove debug message.
                                            }
                                            else
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Too Far from Player.", Struct.ChatType.System));//@TODO: remove debug message.
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Invalid Player ID.", Struct.ChatType.System));
                                        }
                                        break;
                                    }

                                case Struct.DataType.actionChgDir:
                                    {
                                        CSocket.Client.Direction = Dir;
                                        EudemonPacket.ToLocal(EudemonPacket.General(CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y, CSocket.Client.Direction, Struct.DataType.actionChgDir, 0), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                        break;
                                    }
                                case Struct.DataType.actionChgMap:
                                    {
                                        if (CSocket.Client.Dead)
                                        {
                                            //@TODO: handle making sure dead is dead.
                                            break;
                                        }
                                        //@TODO: Make sure Player has stopped all actions.

                                        break;
                                    }
                                case Struct.DataType.actionGetItemSet: //actionGetItemSet //15
                                    {
                                        foreach (KeyValuePair<int, Struct.ItemInfo> Item in CSocket.Client.Inventory)
                                        {
                                            CSocket.Send(EudemonPacket.ItemInfo(Item.Value.UID, Item.Value.ItemID, Item.Value.Plus, Item.Value.Soc1, Item.Value.Soc2, Item.Value.Dura, Item.Value.MaxDura, Item.Value.Position, 0, 0, 0));
                                        }
                                        foreach (KeyValuePair<int, Struct.ItemInfo> Item in CSocket.Client.Equipment)
                                        {
                                            CSocket.Send(EudemonPacket.ItemInfo(Item.Value.UID, Item.Value.ItemID, Item.Value.Plus, Item.Value.Soc1, Item.Value.Soc2, Item.Value.Dura, Item.Value.MaxDura, Item.Value.Position, 0, 0, 0));
                                        }

                                        CSocket.Send(EudemonPacket.General(0, 0, 0, 0, Struct.DataType.actionGetItemSet, 0)); //@NOTE: DO NOT SEND CLIENT ID HERE. - @TODO: Work out why this causes odd issues.
                                        CSocket.Send(EudemonPacket.GeneralOld(0, CSocket.Client.ID, 0, 0, 0, 1, Struct.DataType.actionSetPkMode)); //Make sure Client is in sync.
                                       break;
                                    }
                                case Struct.DataType.actionGetGoodFriend:
                                    {
                                        CSocket.Send(EudemonPacket.General(CSocket.Client.ID, 0, 0, 0, Struct.DataType.actionGetGoodFriend, 0));
                                        //@TODO: actually handle this.
                                        break;
                                    }
                                case Struct.DataType.actionGetWeaponSkillSet:
                                    {
                                        CSocket.Send(EudemonPacket.General(CSocket.Client.ID, 0, 0, 0, Struct.DataType.actionGetWeaponSkillSet, 0));
                                        //@TODO: actually handle this.
                                        break;
                                    }
                                case Struct.DataType.actionSetPkMode: //PK Mode //29
                                    {
                                        uint PkType = dwData;
                                        if (PkType > 4)
                                            break; //spot of error checking
                                        CSocket.Client.PKMode = (Struct.PkType)PkType;
                                        CSocket.Send(EudemonPacket.GeneralOld(0, CSocket.Client.ID, 0, 0, 0, (int)PkType, Struct.DataType.actionSetPkMode));
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "PK Mode Changed to " + CSocket.Client.PKMode.ToString() + " Mode.", Struct.ChatType.System));
                                        break;
                                    }

                                default:
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Handler-Error] Please report: Unable to handle packet 0x3F2 Sub type " + SubType, Struct.ChatType.System));
                                        Console.WriteLine("[GameServer] Unknown 0x3F2 Packet Subtype: " + SubType);
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region NPC Talks (2031 & 2032)
                    case 2031: //Initial NPC talk
                        {
                            int ID = ReadLong(data, 4);
                            Handler.NpcTalk(CSocket, ID, 0);
                            break;
                        }
                    case 2032: //Reply NPC Talk
                        {
                            int ID = CSocket.Client.LastNPC;
                            int LinkBack = data[10];
                            if (LinkBack != 255)
                                Handler.NpcTalk(CSocket, ID, LinkBack);
                            break;
                        }
                    #endregion
                    #region ItemPickup
                    case 1101: //Item pickup
                        {
                            data[4] = (byte)(data[4] ^ 0x37);//removing TQs half assed encryption.
                            data[5] = (byte)(data[5] ^ 0x25);
                            int UID = BitConverter.ToInt32(data, 4);
                            Handler.PickupItem(UID, CSocket);
                            break;
                        }
                    #endregion

                    #region Team - NEEDS WORK
                    case 10283:
                        {
                            Console.WriteLine("team Packet");
                            int subtype = data[4];
                            switch (subtype)
                            {
                                case 0://Create team
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Client.Team = new Struct.Team();
                                            CSocket.Client.Team.LeaderID = CSocket.Client.ID;
                                            CSocket.Client.Team.Forbid = false;
                                            CSocket.Client.Team.Members.Add(CSocket.Client.ID, CSocket);
                                            CSocket.Send(EudemonPacket.Team(CSocket.Client.ID, Struct.TeamOption.MakeTeam));
                                        }
                                        else
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are already in a team!", Struct.ChatType.System));
                                        }
                                        break;
                                    }
                                case 1://Request to join
                                    {
                                        if (CSocket.Client.Team != null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are already in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        int Leader = ReadLong(data, 8);
                                        if (MainGS.ClientPool.ContainsKey(Leader))
                                        {
                                            ClientSocket TeamLeader = MainGS.ClientPool[Leader];
                                            if (TeamLeader.Client.Team != null)
                                            {
                                                if (TeamLeader.Client.Team.LeaderID == TeamLeader.Client.ID)
                                                {
                                                    if (!TeamLeader.Client.Team.Forbid)
                                                    {
                                                        if (TeamLeader.Client.Team.Members.Count < 5)
                                                        {
                                                            TeamLeader.Send(EudemonPacket.Team(CSocket.Client.ID, Struct.TeamOption.JoinTeam));
                                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Team] Request to join team sent to " + TeamLeader.Client.Name, Struct.ChatType.System));
                                                        }
                                                        else
                                                        {
                                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + "'s team is full.", Struct.ChatType.System));
                                                        }
                                                    }
                                                    else
                                                    {
                                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + "'s team forbids new members.", Struct.ChatType.System));
                                                    }
                                                }
                                                else
                                                {
                                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + " is not the team leader.", Struct.ChatType.System));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + " has not created a team.", Struct.ChatType.System));
                                            }
                                        }
                                        break;
                                    }
                                case 2://Exit Team
                                    {
                                        if (CSocket.Client.Team != null)
                                        {
                                            ClientSocket Leader = MainGS.ClientPool[CSocket.Client.Team.LeaderID];
                                            foreach (KeyValuePair<int, ClientSocket> Member in Leader.Client.Team.Members)
                                            {
                                                if (Member.Value.Client.ID != CSocket.Client.ID)
                                                {
                                                    Member.Value.Send(EudemonPacket.Chat(0, "SYSTEM", Member.Value.Client.Name, "[Team] " + CSocket.Client.Name + " has just left the team!", Struct.ChatType.System));
                                                    Member.Value.Send(EudemonPacket.Team(CSocket.Client.ID, Struct.TeamOption.LeaveTeam));
                                                }
                                            }
                                            Leader.Client.Team.Members.Remove(CSocket.Client.ID);
                                            CSocket.Client.Team = null;
                                            //CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Team] You have left the team.", Struct.ChatType.Top));
                                            CSocket.Send(EudemonPacket.Team(CSocket.Client.ID, Struct.TeamOption.LeaveTeam));
                                        }
                                        else
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                        }
                                        break;
                                    }
                                case 3: //Accept Invite
                                    {
                                        if (CSocket.Client.Team != null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are already in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        int Inviter = ReadLong(data, 8);
                                        if (MainGS.ClientPool.ContainsKey(Inviter))
                                        {
                                            ClientSocket TeamLeader = MainGS.ClientPool[Inviter];
                                            if (TeamLeader.Client.Team != null)
                                            {
                                                if (TeamLeader.Client.Team.Members.Count < 5)
                                                {
                                                    if (!TeamLeader.Client.Team.Forbid)
                                                    {
                                                        foreach (KeyValuePair<int, ClientSocket> Member in TeamLeader.Client.Team.Members)
                                                        {
                                                            Member.Value.Send(EudemonPacket.TeamMember(CSocket.Client));
                                                            CSocket.Send(EudemonPacket.TeamMember(Member.Value.Client));
                                                        }
                                                        TeamLeader.Client.Team.Members.Add(CSocket.Client.ID, CSocket);
                                                        CSocket.Client.Team = TeamLeader.Client.Team;
                                                    }
                                                    else
                                                    {
                                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter's team does not accept new members.", Struct.ChatType.System));
                                                    }
                                                }
                                                else
                                                {
                                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter's team is full.", Struct.ChatType.System));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter no longer has a team.", Struct.ChatType.System));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter is no longer online.", Struct.ChatType.System));
                                        }
                                        break;
                                    }
                                case 4: //Invite to join
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot invite new members!", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        int Invited = ReadLong(data, 8);
                                        if (MainGS.ClientPool.ContainsKey(Invited))
                                        {
                                            ClientSocket InvitedCSocket = MainGS.ClientPool[Invited];
                                            if (InvitedCSocket.Client.Team == null)
                                            {
                                                if (!CSocket.Client.Team.Forbid)
                                                {
                                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Team] Invited " + InvitedCSocket.Client.Name + " to join your team.", Struct.ChatType.System));
                                                    InvitedCSocket.Send(EudemonPacket.Team(CSocket.Client.ID, Struct.TeamOption.Invite));
                                                }
                                                else
                                                {
                                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your team forbids new members from joining.", Struct.ChatType.System));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target is already in a team.", Struct.ChatType.System));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target does not exist.", Struct.ChatType.System));
                                        }
                                        break;
                                    }
                                case 5://Accept join request
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot accept join requests.", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        int ToJoin = ReadLong(data, 8);
                                        if (MainGS.ClientPool.ContainsKey(ToJoin))
                                        {
                                            ClientSocket Invited = MainGS.ClientPool[ToJoin];
                                            if (Invited.Client.Team == null)
                                            {
                                                if (!CSocket.Client.Team.Forbid)
                                                {
                                                    foreach (KeyValuePair<int, ClientSocket> Member in CSocket.Client.Team.Members)
                                                    {
                                                        Member.Value.Send(EudemonPacket.TeamMember(Invited.Client));
                                                        Invited.Send(EudemonPacket.TeamMember(Member.Value.Client));
                                                    }
                                                    CSocket.Client.Team.Members.Add(Invited.Client.ID, Invited);
                                                    Invited.Client.Team = CSocket.Client.Team;
                                                }
                                                else
                                                {
                                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your team forbids new members from joining.", Struct.ChatType.System));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target is already in a team.", Struct.ChatType.System));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target does not exist.", Struct.ChatType.System));
                                        }
                                        break;
                                    }
                                case 6: //Dismiss
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot dismiss the team.", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        foreach (KeyValuePair<int, ClientSocket> Member in CSocket.Client.Team.Members)
                                        {
                                            if (Member.Value.Client.ID != CSocket.Client.ID)
                                            {
                                                Member.Value.Send(EudemonPacket.Team(Member.Value.Client.ID, Struct.TeamOption.DismissTeam));
                                                Member.Value.Client.Team = null;
                                            }
                                        }
                                        CSocket.Client.Team = null;
                                        CSocket.Send(EudemonPacket.Team(CSocket.Client.ID, Struct.TeamOption.DismissTeam));
                                        break;
                                    }
                                case 7: //Kick from team
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot kick team members.", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        int Kick = ReadLong(data, 8);
                                        if (MainGS.ClientPool.ContainsKey(Kick))
                                        {
                                            if (CSocket.Client.Team.Members.ContainsKey(Kick))
                                            {
                                                foreach (KeyValuePair<int, ClientSocket> Member in CSocket.Client.Team.Members)
                                                {
                                                    Member.Value.Send(EudemonPacket.Team(Kick, Struct.TeamOption.Kick));
                                                    if (Member.Value.Client.ID == Kick)
                                                    {
                                                        Member.Value.Client.Team = null;
                                                    }
                                                }
                                                CSocket.Client.Team.Members.Remove(Kick);
                                            }
                                            else
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target not in team.", Struct.ChatType.System));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target does not exist.", Struct.ChatType.System));
                                        }
                                        break;
                                    }
                                case 8://Forbid
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        if (!CSocket.Client.Team.Forbid)
                                        {
                                            CSocket.Client.Team.Forbid = true;
                                        }
                                        break;
                                    }
                                case 9: //Unforbid
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.Forbid)
                                        {
                                            CSocket.Client.Team.Forbid = false;
                                        }
                                        break;
                                    }
                                case 10://unForbidMoney
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.ForbidMoney)
                                        {
                                            CSocket.Client.Team.ForbidMoney = false;
                                        }
                                        break;
                                    }
                                case 11://forbidMoney
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.ForbidMoney)
                                        {
                                            CSocket.Client.Team.ForbidMoney = false;
                                        }
                                        break;
                                    }
                                case 12://ForbidItems
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        if (!CSocket.Client.Team.ForbidItems)
                                        {
                                            CSocket.Client.Team.ForbidItems = true;
                                        }
                                        break;
                                    }
                                case 13://unForbidItems
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.System));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.ForbidItems)
                                        {
                                            CSocket.Client.Team.ForbidItems = false;
                                        }
                                        break;
                                    }
                                default:
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown team subtype: " + subtype, Struct.ChatType.System));
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region Attack
                    case 1022:
                        {
                            int AType = data[20];
                            //Console.WriteLine(System.Environment.TickCount - CSocket.Client.LastAttack);
                            if (System.Environment.TickCount - CSocket.Client.LastAttack < 450 && CSocket.Client.LastAttack > 0)
                            {
                                break;
                            }
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }
                            if (CSocket.Client.UpStam.Enabled)
                            {
                                CSocket.Client.UpStam.Stop();
                            }
                            CSocket.Client.LastAttack = System.Environment.TickCount;
                            switch (AType)
                            {
                                case 2://Melee
                                    {
                                        int Target = BitConverter.ToInt32(data, 12);
                                        Handler.Attack(Target, 0, 2, CSocket.Client.X, CSocket.Client.Y, CSocket);
                                        break;
                                    }
                                case 21: // Magical
                                    {
                                        int TargetID = 0;
                                        int decskill = 0;
                                        int decx = 0;
                                        int decy = 0;
                                        long targ = ((long)data[12] & 0xFF) | (((long)data[13] & 0xFF) << 8) | (((long)data[14] & 0xFF) << 16) | (((long)data[15] & 0xFF) << 24);
                                        targ = ((((targ & 0xffffe000) >> 13) | ((targ & 0x1fff) << 19)) ^ 0x5F2D2463 ^ CSocket.Client.ID) - 0x746F4AE6;
                                        TargetID = Convert.ToInt32(targ);
                                        ushort myvar = Convert.ToUInt16(((long)data[24] & 0xFF) | (((long)data[25] & 0xFF) << 8));
                                        myvar ^= (ushort)0x915d;
                                        myvar ^= (ushort)CSocket.Client.ID;
                                        myvar = (ushort)(myvar << 0x3 | myvar >> 0xd);
                                        myvar -= 0xeb42;
                                        decskill = myvar;
                                        long xx = (data[16] & 0xFF) | ((data[17] & 0xFF) << 8);
                                        long yy = (data[18] & 0xFF) | ((data[19] & 0xFF) << 8);
                                        xx = xx ^ (CSocket.Client.ID & 0xffff) ^ 0x2ed6;
                                        xx = ((xx << 1) | ((xx & 0x8000) >> 15)) & 0xffff;
                                        xx |= 0xffff0000;
                                        xx -= 0xffff22ee;
                                        yy = yy ^ (CSocket.Client.ID & 0xffff) ^ 0xb99b;
                                        yy = ((yy << 5) | ((yy & 0xF800) >> 11)) & 0xffff;
                                        yy |= 0xffff0000;
                                        yy -= 0xffff8922;
                                        decx = Convert.ToInt32(xx);
                                        decy = Convert.ToInt32(yy);
                                        Handler.Attack(TargetID, decskill, 21, decx, decy, CSocket);
                                        break;
                                    }
                                case 25:
                                    {
                                        int TargetID = (data[15] << 24) + (data[14] << 16) + (data[13] << 8) + (data[12]);
                                        Handler.Attack(TargetID, 0, 25, CSocket.Client.X, CSocket.Client.Y, CSocket);
                                        break;
                                    }
                                default:
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Handler-Error] Please report: Unable to handle 1002 subtype " + AType, Struct.ChatType.System));
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region 3EC(1004) Chat Packet
                    case 1004:
                        {
                            Handler.Chat(data, CSocket);
                            break;
                        }
                    #endregion
                    default:
                        {
                            Console.WriteLine("[GameServer] Unknown packet type: " + Type);
                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Handler-Error] Please report: Unable to handle packet type " + Type, Struct.ChatType.System));
                            break;
                        }
                }
                if (Split1 != null)
                    ProcessPacket(Split1, CSocket);
                if (Split2 != null)
                    ProcessPacket(Split2, CSocket);
                if (Split3 != null)
                    ProcessPacket(Split3, CSocket);
                if (Split4 != null)
                    ProcessPacket(Split4, CSocket);
                if (Split5 != null)
                    ProcessPacket(Split5, CSocket);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return;
            }
        }
Exemple #11
0
        public static void ItemUnequip(int Location, int UID, ClientSocket CSocket)
        {
            if (CSocket.Client.Equipment.ContainsKey(Location))
            {
                if (CSocket.Client.Inventory.Count < 40)
                {
                    if (!CSocket.Client.Inventory.ContainsKey(UID))
                    {
                        Struct.ItemInfo Item = CSocket.Client.Equipment[Location];
                        CSocket.Client.Equipment.Remove(Location);
                        Item.Position = 50;
                        CSocket.Client.Inventory.Add(Item.UID, Item);
                        Database.Database.UpdateItem(Item);
                        CSocket.Send(EudemonPacket.ItemUsage(UID, Location, Struct.ItemUsage.UnequipItem));
                        #region ItemCalculations
                        switch (Item.Soc1)
                        {
                            case 0:
                                break;
                            case 11:
                                {
                                    CSocket.Client.NCG--;
                                    break;
                                }
                            case 12:
                                {
                                    CSocket.Client.RCG--;
                                    break;
                                }
                            case 13:
                                {
                                    CSocket.Client.SCG--;
                                    break;
                                }
                            case 71:
                                {
                                    CSocket.Client.NBG--;
                                    break;
                                }
                            case 72:
                                {
                                    CSocket.Client.RBG--;
                                    break;
                                }
                            case 73:
                                {
                                    CSocket.Client.SBG--;
                                    break;
                                }
                            default:
                                {
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown GemID: " + Item.Soc1, Struct.ChatType.Talk));
                                    break;
                                }

                        }
                        switch (Item.Soc2)
                        {
                            case 0:
                                break;
                            case 11:
                                {
                                    CSocket.Client.NCG--;
                                    break;
                                }
                            case 12:
                                {
                                    CSocket.Client.RCG--;
                                    break;
                                }
                            case 13:
                                {
                                    CSocket.Client.SCG--;
                                    break;
                                }
                            case 71:
                                {
                                    CSocket.Client.NBG--;
                                    break;
                                }
                            case 72:
                                {
                                    CSocket.Client.RBG--;
                                    break;
                                }
                            case 73:
                                {
                                    CSocket.Client.SBG--;
                                    break;
                                }
                            default:
                                {
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown GemID: " + Item.Soc2, Struct.ChatType.Talk));
                                    break;
                                }

                        }
                        switch (Item.Bless)
                        {
                            case 7:
                                {
                                    CSocket.Client.Bless -= 7;
                                    break;
                                }
                            case 5:
                                {
                                    CSocket.Client.Bless -= 5;
                                    break;
                                }
                            case 3:
                                {
                                    CSocket.Client.Bless -= 3;
                                    break;
                                }
                            case 1:
                                {
                                    CSocket.Client.Bless -= 1;
                                    break;
                                }
                            case 0:
                                {
                                    break;
                                }
                            default:
                                {
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Invalid bless: " + Item.Bless, Struct.ChatType.System));
                                    break;
                                }
                        }
                        if (MainGS.Items.ContainsKey(Item.ItemID))
                        {
                            Struct.ItemData ItemD = MainGS.Items[Item.ItemID];
                            CSocket.Client.BaseMagicAttack -= ItemD.MinMagicAttack;
                            if (Location == 5)
                            {
                                CSocket.Client.BaseMaxAttack -= (int)Math.Floor(.5 * ItemD.MaxDamage);
                                CSocket.Client.BaseMinAttack -= (int)Math.Floor(.5 * ItemD.MinDamage);
                            }
                            else
                            {
                                CSocket.Client.BaseMaxAttack -= ItemD.MaxDamage;
                                CSocket.Client.BaseMinAttack -= ItemD.MinDamage;
                            }
                            CSocket.Client.Defense -= ItemD.DefenseAdd;
                            CSocket.Client.MaxHP -= ItemD.HPAdd;
                            CSocket.Client.MaxHP -= Item.Enchant;
                            CSocket.Client.MagicDefense -= ItemD.MDefenseAdd;
                            CSocket.Client.MaxMP -= ItemD.MPAdd;
                            CSocket.Client.Dodge -= ItemD.DodgeAdd;
                        }
                        if (Item.Plus > 0)
                        {
                            string s_ItemID = Convert.ToString(Item.ItemID);
                            int itemidsimple = 0;
                            if ((Item.ItemID >= 900000 && Item.ItemID <= 900999) || (Item.ItemID >= 111303 && Item.ItemID <= 118999) || (Item.ItemID >= 130003 && Item.ItemID <= 139999))//Shields, Helms, Armors
                            {
                                s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                                s_ItemID = s_ItemID.Insert(s_ItemID.Length, "0");
                                itemidsimple = Convert.ToInt32(s_ItemID);
                            }
                            else if ((Item.ItemID >= 150000 && Item.ItemID <= 160250) || (Item.ItemID >= 500000 && Item.ItemID <= 500400) || (Item.ItemID >= 120003 && Item.ItemID <= 121249) || (Item.ItemID >= 421003 && Item.ItemID <= 421339))//BS's, Bows, Necky/Bags
                            {
                                s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                                s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");
                                itemidsimple = Convert.ToInt32(s_ItemID);
                            }
                            else if (Item.ItemID >= 510000 && Item.ItemID <= 580400)//2 Hander
                            {
                                s_ItemID = s_ItemID.Remove(0, 3);
                                s_ItemID = s_ItemID.Insert(0, "555");
                                s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                                s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");
                                itemidsimple = Convert.ToInt32(s_ItemID);
                            }
                            else if (Item.ItemID >= 410000 && Item.ItemID <= 490400 && itemidsimple == 0)//1 Handers
                            {
                                s_ItemID = s_ItemID.Remove(0, 3);
                                s_ItemID = s_ItemID.Insert(0, "444");
                                s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                                s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");
                                itemidsimple = Convert.ToInt32(s_ItemID);
                            }
                            if (MainGS.ItemPluses.ContainsKey(itemidsimple))
                            {
                                Struct.ItemPlusDB IPlus = MainGS.ItemPluses[itemidsimple];
                                if (IPlus.DB.ContainsKey(Item.Plus))
                                {
                                    Struct.ItemPlus iPlus = IPlus.DB[Item.Plus];
                                    CSocket.Client.BaseMaxAttack -= iPlus.MaxDmg;
                                    CSocket.Client.BaseMinAttack -= iPlus.MinDmg;
                                    CSocket.Client.Defense -= iPlus.DefenseAdd;
                                    //CSocket.Client.BaseMagicAttack -= iPlus.MDamageAdd;//@TODO: recalc this
                                    //CSocket.Client.BonusMagicAttack -= iPlus.MDamageAdd;
                                    CSocket.Client.BonusMagicDefense -= iPlus.MDefAdd;
                                    CSocket.Client.MaxHP -= iPlus.HPAdd;
                                    CSocket.Client.Dodge -= iPlus.DodgeAdd;
                                    //TODO: Dodge, etc
                                }
                            }
                        }
                        #endregion
                        Calculation.Attack(CSocket);
                        EudemonPacket.ToLocal(EudemonPacket.SpawnCharacter(CSocket), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                    }
                }
                else
                {
                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your inventory is full.", Struct.ChatType.System));
                }
            }
            else
            {
                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] That item is not equipped.", Struct.ChatType.System));
            }
        }
Exemple #12
0
        public static void DropItem(int UID, ClientSocket CSocket)
        {
            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Item UID: " + UID, Struct.ChatType.Normal));
            if (CSocket.Client.Inventory.ContainsKey(UID))
            {
                Struct.ItemInfo Ii = CSocket.Client.Inventory[UID];
                Struct.ItemGround IG = new Struct.ItemGround();
                IG.CopyItem(Ii);
                IG.Position = (int)Struct.ItemPosition.Ground;
                IG.Map = (int)CSocket.Client.Map;
                IG.X = (CSocket.Client.X - MainGS.Rand.Next(4) + MainGS.Rand.Next(4));
                IG.Y = (CSocket.Client.Y - MainGS.Rand.Next(4) + MainGS.Rand.Next(4));
                if (MainGS.Maps.ContainsKey(IG.Map))
                {
                    Struct.DmapData Mapping = MainGS.Maps[IG.Map];
                    byte tries = 0;
                    while (!Mapping.CheckLoc((ushort)IG.X, (ushort)IG.Y))
                    {
                        IG.X = (CSocket.Client.X - MainGS.Rand.Next(4) + MainGS.Rand.Next(4));
                        IG.Y = (CSocket.Client.Y - MainGS.Rand.Next(4) + MainGS.Rand.Next(4));
                        tries++;
                        if (tries > 8)
                            break;
                    }
                }

                IG.OwnerID = CSocket.Client.ID;
                IG.OwnerOnly = new System.Timers.Timer();
                IG.OwnerOnly.Interval = 7000;
                IG.OwnerOnly.AutoReset = false;
                IG.Dispose = new System.Timers.Timer();
                IG.Dispose.Interval = 60000;
                IG.Dispose.AutoReset = false;
                IG.Dispose.Elapsed += delegate { IG.Disappear(); };
                IG.OwnerOnly.Start();
                IG.Dispose.Start();
                if (!MainGS.ItemFloor.ContainsKey(UID))
                {
                    Database.Database.DeleteItem(UID);
                    CSocket.Client.Inventory.Remove(UID);
                    CSocket.Send(EudemonPacket.ItemUsage(UID, 254, Struct.ItemUsage.RemoveDropItem));
                    //EudemonPacket.ToLocal(tmp, IG.X, IG.Y, IG.Map, 0, 0);
                    EudemonPacket.ToLocal(EudemonPacket.DropItem(IG.UID, IG.ItemID, IG.X, IG.Y), IG.X, IG.Y, IG.Map, 0, 0);
                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Ground UID: " + IG.UID + " Dropped at X:  " + IG.X + " Y: " + IG.Y, Struct.ChatType.Normal));

                    //lock(MainGS.ItemFloor)
                    //{
                    try
                    {
                        Monitor.Enter(MainGS.ItemFloor);
                        MainGS.ItemFloor.Add(IG.UID, IG);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                    finally
                    {
                        Monitor.Exit(MainGS.ItemFloor);
                    }
                    //}
                }
            }
            else
            {
                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item does not exist.", Struct.ChatType.System));
            }
        }
        public static void ProcessPacket(byte[] data, ClientSocket CSocket)
        {
            try
            {
                byte[] Split1 = null;
                byte[] Split2 = null;
                byte[] Split3 = null;
                byte[] Split4 = null;
                byte[] Split5 = null;
                int Type = (BitConverter.ToInt16(data, 2));
                int Length = (BitConverter.ToInt16(data, 0));
                //if (data.Length > Length)
                //{
                //    int Len2 = (data[Length + 1] << 8) + data[Length]; Len2 += 8;
                //    Split1 = new byte[Len2];
                //    Array.Copy(data, Length, Split1, 0, Len2);
                //    if (Len2 + Length < data.Length)
                //    {
                //        int Len3 = (data[Length + Len2 + 1] << 8) + data[Length + Len2]; Len3 += 8;
                //        Split2 = new byte[Len3];
                //        Array.Copy(data, Length + Len2, Split2, 0, Len3);
                //        if (Len2 + Len3 + Length < data.Length)
                //        {
                //            int Len4 = (data[Length + Len2 + Len3 + 1] << 8) + data[Length + Len2 + Len3]; Len4 += 8;
                //            Split3 = new byte[Len4];
                //            Array.Copy(data, Length + Len2 + Len3, Split3, 0, Len4);
                //        }
                //    }
                //}
                //byte[] data = new byte[Length];
                //Array.Copy(data, data, Length);
                if (data.Length > Length)
                {
                    int Len2 = BitConverter.ToInt16(data, 0 + Length);
                    Split1 = new byte[Len2];
                    Array.Copy(data,Length,Split1,0,Len2);

                    if (data.Length > Length + Len2)
                    {

                        int Len3 = BitConverter.ToInt16(data, 0 + Length + Len2);
                        Split2 = new byte[Len3];
                        Array.Copy(data, Length + Len2, Split2, 0, Len3);

                        if (data.Length > Length + Len2 + Len3)
                        {
                            int Len4 = BitConverter.ToInt16(data, 0 + Length + Len2 + Len3);
                            Split3 = new byte[Len4];
                            Array.Copy(data, Length + Len2 + Len3, Split3, 0, Len4);

                            if (data.Length > Length + Len2 + Len3 + Len4)
                            {
                                int Len5 = BitConverter.ToInt16(data, 0 + Length + Len2 + Len3 + Len4);
                                Split4 = new byte[Len5];
                                Array.Copy(data, Length + Len2 + Len3 + Len4, Split4, 0, Len5);

                                if (data.Length > Length + Len2 + Len3 + Len4 + Len5)
                                {
                                    int Len6 = BitConverter.ToInt16(data, 0 + Length + Len2 + Len3 + Len4 + Len5);
                                    Split5 = new byte[Len6];
                                    Array.Copy(data, Length + Len2 + Len3 + Len4 + Len5, Split5, 0, Len6);

                                    if (data.Length > Length + Len2 + Len3 + Len4 + Len5 + Len6)
                                    {
                                        Console.WriteLine("WARNING: Too many bulk packets");
                                    }
                                }
                            }
                        }
                    }
                }
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[PacketLog] New Packet Recived, Type: " + Type);
                Console.ResetColor();
                Console.WriteLine(Dump(data));
                switch (Type)
                {
                    #region Begin Cleint Auth
                    case 1052888:
                        {
                            ulong Keys;
                            Keys = data[11];
                            Keys = (Keys << 8) | data[10];
                            Keys = (Keys << 8) | data[9];
                            Keys = (Keys << 8) | data[8];
                            Keys = (Keys << 8) | data[7];
                            Keys = (Keys << 8) | data[6];
                            Keys = (Keys << 8) | data[5];
                            Keys = (Keys << 8) | data[4];
                            Console.WriteLine("SENDING DUMMY PACKET");
                            byte[] test;
                            //byte[] test = String_To_Bytes("1400f903fe3fac780100000023000000320000001400f103fe3fac78000000003e000000fe3fac781c00f2036096c600fe3fac780000000000000000fe3fac78092600001c00f203fe3fac78c602e400280001000000000000000000252600001400f9034567ac780100000023000000320000001400f1034567ac78000000003e0000004567ac781c00f2036096c6004567ac7800000000000000004567ac78092600001c00f2034567ac78c602e400280001000000000000000000252600001400f9031375ac780100000023000000320000001400f1031375ac78000000003e0000001375ac781c00f2036096c6001375ac7800000000000000001375ac78092600001c00f2031375ac78c602e4000e0001000000000000000000252600001400f9034367ac780100000023000000320000001400f1034367ac78000000003e0000004367ac781c00f2036096c6004367ac7800000000000000004367ac78092600001c00f2034367ac78c602e400280001000000000000000000252600001400f9030f75ac780100000023000000320000001400f1030f75ac78000000003e0000000f75ac781c00f2036096c6000f75ac7800000000000000000f75ac78092600001c00f2030f75ac78c602e4000e0001000000000000000000252600001400f9031475ac780100000023000000320000001400f1031475ac78000000003e0000001475ac781c00f2036096c6001475ac7800000000000000001475ac78092600001c00f2031475ac78c602e4000e0004000000000000000000252600001400f9031175ac780100000023000000320000001400f1031175ac78000000003e0000001175ac781c00f2036096c6001175ac7800000000000000001175ac78092600001c00f2031175ac78c602e40016000200000000000000000025260000af00ee03c602e400f149020065000000faf1cc1d0c11466b00000000000000000000000000000000110200000f0000000200640005000400000032003200500000000000000000000000ff0a0000010000000200000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000020b48616c6f3737395b504d5d02cede0000002400f903c602e400030000001a0000000000000028000000e803000003000000500000002400fb030000000000000000000000000000000048616c6f3737395b504d5d00000000001000f403c602e40000000000000000001400f903c602e40001000000090000000a000000");
                            //test = String_To_Bytes("1400F103FE3FAC78000000003E000000FE3FAC78");
                            //CSocket.Send(test);
                            test = String_To_Bytes("1C00F2036096C600FE3FAC780000000000000000FE3FAC7809260000");
                            CSocket.Send(test);
                            //test = String_To_Bytes("1C00F203FE3FAC78C602E40028000100000000000000000025260000");
                            //CSocket.Send(test);
                            //test = String_To_Bytes("1400F9034567AC78010000002300000032000000");
                            //CSocket.Send(test);
                            test = String_To_Bytes("AF00EE03C602E400F149020065000000FAF1CC1D0C11466B00000000000000000000000000000000110200000F0000000200640005000400000032003200500000000000000000000000FF0A0000010000000200000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000020B48616C6F3737395B504D5D02CEDE000000");
                            CSocket.Send(test);
                            ConnectionRequest User = Nano.AuthenticatedLogins[Keys];
                            CSocket.Client = Database.Database.GetCharacter(User.Account);
                            break;

                        }
                    case 1052: //End Authorization Process.
                        {
                            ulong Keys;
                            Keys = data[11];
                            Keys = (Keys << 8) | data[10];
                            Keys = (Keys << 8) | data[9];
                            Keys = (Keys << 8) | data[8];
                            Keys = (Keys << 8) | data[7];
                            Keys = (Keys << 8) | data[6];
                            Keys = (Keys << 8) | data[5];
                            Keys = (Keys << 8) | data[4];
                            Console.WriteLine("[GameServer] Confirming login with LoginServer");
                            if (Nano.AuthenticatedLogins.ContainsKey(Keys))
                            {
                                CSocket.AccountName = Nano.AuthenticatedLogins[Keys].Account;
                                Console.WriteLine("[GameServer] Authenticated Login.");
                                ConnectionRequest User = Nano.AuthenticatedLogins[Keys];
                                User.Expire(false);
                                CSocket.Client = Database.Database.GetCharacter(User.Account);
                                CSocket.Client.PrevX = 0;
                                CSocket.Client.PrevY = 0;
                                byte[] test;
                                test = String_To_Bytes("1C00F2036096C600FE3FAC780000000000000000FE3FAC7809260000");
                                CSocket.Send(test);
                                if (CSocket.Client == null)
                                {
                                    if (Database.Database.LoadNovaCharacter(User.Account))
                                    {
                                        Console.WriteLine("user has account");
                                        CSocket.Client = Database.Database.GetCharacter(User.Account);
                                    }
                                    else
                                    {
                                        Console.WriteLine("user making account");

                                        //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", "NEW_ROLE", Struct.ChatType.LoginInformation));
                                        CSocket.Send(ConquerPacket.Chat(5, "SYSTEM", "ALLUSERS", "NEW_ROLE", Struct.ChatType.LoginInformation));
                                        return;
                                    }
                                }
                                if (CSocket.Client == null)
                                {

                                    //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", "NEW_ROLE", Struct.ChatType.LoginInformation));
                                    CSocket.Send(ConquerPacket.Chat(5, "SYSTEM", "ALLUSERS", "NEW_ROLE", Struct.ChatType.LoginInformation));
                                    return;
                                }
                                Calculation.Vitals(CSocket, true);
                                if (CSocket.Client.First)
                                {
                                    CSocket.Client.CurrentMP = CSocket.Client.MaxMP;
                                    CSocket.Client.CurrentHP = CSocket.Client.MaxHP;
                                }
                                Database.Database.GetItems(CSocket);
                                if (Nano.ClientPool.ContainsKey(CSocket.Client.ID))
                                {
                                    ClientSocket C = Nano.ClientPool[CSocket.Client.ID];
                                    C.Send(ConquerPacket.Chat(0, "SYSTEM", C.Client.Name, "[ERROR] Your character has logged in from another location, you're being booted.", Struct.ChatType.Talk));
                                    C.Disconnect();
                                }
                                //lock(Nano.ClientPool)
                                //{
                                try
                                {
                                    Monitor.Enter(Nano.ClientPool);
                                    Nano.ClientPool.Add(CSocket.Client.ID, CSocket);
                                    //}
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.ToString());
                                }
                                finally
                                {
                                    Monitor.Exit(Nano.ClientPool);
                                }
                                //}
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", "ANSWER_OK", Struct.ChatType.LoginInformation));
                                CSocket.Send(ConquerPacket.CharacterInfo(CSocket));
                                //CSocket.Send(ConquerPacket.MiniMap(true));
                                //PLEASE DO NOT REMOVE THIS CODE!
                               // CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 0, 0, 0, 0, 0, Struct.DataType.ConfirmLoginComplete));
                               // CSocket.Send(ConquerPacket.Status(CSocket, 2, 0, Struct.StatusTypes.StatusEffect));
                                //CSocket.Send(String_To_Bytes("3900F003000000007D494C5EA4410600B60BB80B01000400000000000000000000000000000000000000000000000000000000000000000100"));
                                //CSocket.Send(ConquerPacket.ItemInfo(0,410020 ,50 , 0, 0, 2998, 3000, 4, 0, 0, 0));
                                foreach (KeyValuePair<int, Struct.ItemInfo> Item in CSocket.Client.Inventory)
                                {
                                    //CSocket.Send(ConquerPacket.ItemInfo(Item.Value.UID, Item.Value.ItemID, Item.Value.Plus, Item.Value.Bless, Item.Value.Enchant, Item.Value.Soc1, Item.Value.Soc2, Item.Value.Dura, Item.Value.MaxDura, Item.Value.Position, Item.Value.Color));
                                    CSocket.Send(ConquerPacket.ItemInfo(0, Item.Value.ItemID, Item.Value.Plus, Item.Value.Soc1, Item.Value.Soc2, Item.Value.Dura, Item.Value.MaxDura, Item.Value.Position, 0, 0, 6));
                                }
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Welcome to EO Emu, " + CSocket.Client.Name, Struct.ChatType.Talk));
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "There are currently " + Nano.ClientPool.Count + " players online.", Struct.ChatType.Talk));
                                //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Use of this server binds you to the Terms of Service (ToS) located on http://www.coemu.org", Struct.ChatType.Talk));
                                //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Current server rates: Prof: " + Nano.PROF_MULTIPLER + "x, Skill: " + Nano.SKILL_MULTIPLER + "x, Exp: " + Nano.EXP_MULTIPLER + "x.", Struct.ChatType.Talk));
                                //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Be kind to your fellow player and have a good time.", Struct.ChatType.Talk));
                                if (CSocket.Client.First)
                                {
                                    Database.Database.SaveCharacter(CSocket.Client);
                                    //Handler.Text("Welcome to the WONDERFUL world of CoEmu.Nano,\n CoEmu v2's leveling server!", CSocket);
                                    //Handler.Text("\n On behalf of every GM, PM, and supporter of CoEmu v2,", CSocket);
                                    //Handler.Text("\n I would like to thank you all for the\n wonder that Nova was.", CSocket);
                                    //Handler.Text("\n This server is dedicated to not only\n Rimik from Pyramid", CSocket);
                                    //Handler.Text("\n But to every CoEmu v2 supporter that has\n ever been a part of our family.", CSocket);
                                    //Handler.Text("\n Good luck in this new world, conquerer.", CSocket);
                                    //Handler.Text("\n You've been started off with some basic items to help your journey.", CSocket);
                                    //Handler.Text("\n Use of this server BINDS YOU to the CoEmu v2 terms of service.", CSocket);
                                    //Handler.End(CSocket);
                                }
                                ConquerPacket.ToServer(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", CSocket.Client.Name + " has come online.", Struct.ChatType.Top), 0);

                            }
                            else
                            {
                                Console.WriteLine("[GameServer] Unauthenticated Login.");
                                CSocket.Disconnect();
                            }
                            break;
                        }
                    #endregion
                    #region Testing 1010 packet (disabled)
                    case 10103423://disabled (1010 packet)
                        {
                            byte[] test = String_To_Bytes("1000f403c602e4000000000000000000");
                            CSocket.Send(test);
                            break;
                        }
                    #endregion
                    #region CreateCharacter
                    case 1001://Create Character
                        {
                            Handler.NewCharacter(data, CSocket);
                            break;
                        }
                    #endregion
                    #region 1123 (unkonwn atm)
                    case 112300:
                        {
                            byte[] test = String_To_Bytes("2400FB030000000000000000000000000000000048616C6F3737395B504D5D0000000000");
                            CSocket.Send(test);
                            break;
                        }
                    #endregion
                    #region 1009 (possibly requestion map)
                    case 1009://request map i think
                        {
                            //Console.WriteLine("SENDING DUMMY PACKET");
                            //byte[] test = String_To_Bytes("1400f903c602e4000100000009000000140000001400f10301000000000000003e000000fe3fac781400f10301000000000000003e0000004567ac781400f10301000000000000003e0000001375ac781400f10301000000000000003e0000004367ac781400f10301000000000000003e0000000f75ac781400f10301000000000000003e0000001475ac781400f10301000000000000003e0000001175ac78100063040000000019dd2a4c706200001c00f203f1b2c600e803000026019c0100000000e8030000452500001c00f203f1b2c600c602e40026019c0100000000ffffffff5f25000010005604e8030000e8030000000020002000ee071b0700001801820115470000020001000000000000000000000000002000ee07230400001c019b015e2900007b0001000000000000000000000000002000ee071b0400001b01a40114290000020001000000000000000000000000002000ee07220400001c01a101fb4c00001d0001000000000001000000000000002000ee07400600001c019e01873e0000010001000000000000000000000000002000ee07ce0400001e01ae0112300000020001000000000000000000000000002000ee07a08601001f01a4012a440000020001000000000000000000000000002000ee071d0400002d01830122290000010001000000000000000000000000002000ee071f0400002901a4013c280000010001000000000000000000000000002000ee074a8801002401a401f75500006f00010000000000e8030000000000002000ee074c8801002401ae01f75500006f00010000000000e8030000000000002000ee0721040000390181014a290000010001000000000000000000000000002000ee071c0400003601a0011f290000010001000000000000000000000000001400f903c602e40001000000240000000004000020006704c602e40028dd2a4c00000000000000000004000000000000000000000c00f70301000000800000001400f407df0300000db63201d6980300765c370d120011080100c90d33000b0e00009801c30b");
                            //CSocket.Send(test);
                            //byte[] test = String_To_Bytes("1C00F203F1B2C600E803000026019C0100000000E803000045250000");
                            CSocket.Send(Packets.ConquerPacket.General(1, (int)CSocket.Client.Map, CSocket.Client.X, CSocket.Client.Y, 0, (int)CSocket.Client.Map, Structs.Struct.DataType.MapShow));
                            ConquerPacket.ToLocal(ConquerPacket.SpawnCharacter(CSocket), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                            Spawn.All(CSocket);
                            //CSocket.Send(test);
                            //CSocket.Send(ConquerPacket.NewMap(1000));
                            //test = String_To_Bytes("10004f044567ac7800000000e903000010004f044567ac7800000000b90b000010004f044567ac7800000000d507000010004f044567ac7800000000e60700001c00f203f7bec6001375ac7800000000000000001375ac78092600000001f507010000001375ac781e00000006000000c007000007000000c00700000a000000500000000800000096000000090000001ae4270037000000000000000c000000050000000e000000000000000f0000000000000010000000000000001100000000000000120000000000000013000000070000001500000008000000170000000100000019000000580600001a000000000000001b000000d30000001c00000009000000320000000000000033000000000000001400000000000000180000007f0100000d00000032000000010000005803000000000000660500000300000000000000020000000000000004000000bd040000050000009701000010004f041375ac7800000000e903000010004f041375ac7800000000b90b000010004f041375ac7800000000e607000010004f041375ac7800000000d50700001c00f203f7bec6004367ac7800000000000000004367ac78092600000001f507010000004367ac781e00000006000000280d000007000000280d00000a00000051000000080000009600000009000000d386330037000000000000000c000000020000000e000000d70000000f00000000000000100000000000000011000000000000001200000000000000130000000300000015000000080000001700000001000000190000000f2700001a0000000f2700001b0000000f2700001c000000b002000032000000000000003300000000000000140000000000000018000000190200000d0000003400000001000000df03000000000000e10500000300000019030000020000007105000004000000fb020000050000009702000010004f044367ac7800000000d507000010004f044367ac7800000000e607000010004f044367ac7800000000e903000010004f044367ac7800000000b90b00001c00f203f7bec6000f75ac7800000000000000000f75ac78092600000001f507010000000f75ac781e00000006000000e804000007000000e80400000a000000380000000800000096000000090000003c72020037000000000000000c000000050000000e000000000000000f0000000000000010000000000000001100000000000000120000000000000013000000070000001500000008000000170000000100000019000000cd0000001a000000050400001b000000630200001c0000000f00000032000000000000003300000000000000140000000000000018000000760100000d0000002a000000010000002d00000000000000b600000003000000e0000000020000003201000004000000e4020000050000008001000010004f040f75ac7800000000e903000010004f040f75ac7800000000b90b000010004f040f75ac7800000000e607000010004f040f75ac7800000000d50700001c00f203f7bec6001475ac7800000000000000001475ac78092600000001f507010000001475ac781e000000060000006f0a0000070000006f0a00000a000000500000000800000096000000090000001ae4270037000000000000000c000000050000000e000000000000000f0000000000000010000000000000001100000000000000120000000000000013000000070000001500000008000000170000000100000019000000570600001a000000000000001b0000008f0300001c0000001e000000320000000000000033000000000000001400000000000000180000007d0100000d0000003200000001000000e40200000000000049030000");
                            //CSocket.Send(test);

                            /*PacketBuilder Packet = new PacketBuilder(1019, 36);
                            Packet.Long(0);
                            Packet.Long(0);
                            Packet.Long(0);
                            Packet.Long(0);
                            Packet.Text(CSocket.Client.Name.ToString());
                            CSocket.Send(Packet.getFinal());*/

                            break;
                        }
                    case 2036:// excape key its seems
                        {
                           PacketBuilder Packet = new PacketBuilder(2036,12);
                           Packet.Short(473);
                           Packet.Short(0);
                           Packet.Long(0);

                            CSocket.Send(Packet.getFinal());
                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", "Excape Key (or any other hotkey) May not work currently", Struct.ChatType.Top));
                            break;
                        }

                    #endregion
                    #region 0x3ED(1005) Walk Packet
                    case 3005: //Walk packet
                        {
                            //CSocket.Client.LastAttack = 0;
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }
                            int RX = (BitConverter.ToInt16(data, 12));
                            int RY = (BitConverter.ToInt16(data, 14));
                            CSocket.Client.X = RX;
                            CSocket.Client.Y = RY;
                            int ukwn = (BitConverter.ToInt16(data, 16));
                            //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Dirrection: " + dir.ToString(), Struct.ChatType.Talk));
                            Handler.Walk(ukwn, CSocket);
                            break;
                        }
                    #endregion
                    #region 0x3f2(1010) Multi-Function Packet
                    case 9991010: // 0x3f2, Multi-Function Packet
                        {
                            if (data.Length < 0x29)
                                break;
                            //int SubType = data[0x18];
                            int SubType = data[24];
                            //int SubType = BitConverter.ToInt16(data, 24);
                            switch (SubType)
                            {
                                case 70: //Start login sequence.
                                    {
                                        Console.WriteLine("[GameServer] Login Sequence started for " + CSocket.Client.Name);
                                        //CSocket.Send(ConquerPacket.General(CSocket.Client.ID, (int)CSocket.Client.Map, CSocket.Client.X, CSocket.Client.Y, 0, Struct.DataType.MapShow));
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, (int)CSocket.Client.Map, CSocket.Client.X, CSocket.Client.Y, 0, (int)CSocket.Client.Map, Struct.DataType.MapShow));
                                        ConquerPacket.ToLocal(ConquerPacket.SpawnCharacter(CSocket), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                        Spawn.All(CSocket);
                                        /*CSocket.Client.Save = new Timer();
                                        CSocket.Client.Save.Elapsed += delegate {
                                            Database.Database.SaveCharacter(CSocket.Client);
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Saved " + CSocket.Client.Name, Struct.ChatType.Top));
                                        };
                                        CSocket.Client.Save.Interval = 20000;
                                        CSocket.Client.Save.Start();*/
                                        CSocket.Client.CurrentStam = 100;
                                        CSocket.Client.UpStam = new System.Timers.Timer();
                                        CSocket.Client.UpStam.Interval = 100;
                                        CSocket.Client.UpStam.Elapsed += delegate { CSocket.AddStam(); };
                                        //CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.CurrentStam, Struct.StatusTypes.Stamina));
                                        CSocket.Client.LastAttack = System.Environment.TickCount;
                                        break;
                                    }
                                case 114: //Request to show minimap
                                    {
                                        CSocket.Send(ConquerPacket.MiniMap(true));
                                        break;
                                    }
                                case 75: //Request Hotkeys
                                    {
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 0, 0, 0, 0, 0, Struct.DataType.HotKeys));
                                        break;
                                    }
                                case 76: //Request Friends
                                    {
                                        //TODO: Friends lists
                                        CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 0, 0, 0, 0, 0, Struct.DataType.ConfirmFriends));
                                        break;
                                    }

                                default:
                                    {
                                        Console.WriteLine("[GameServer] Unknown 0x3F2 Packet Subtype: " + SubType);
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region NPC Talks
                    case 2031: //Initial NPC talk
                        {
                            int ID = ReadLong(data, 4);
                            Handler.NpcTalk(CSocket, ID, 0);
                            break;
                        }
                    case 2032: //Reply NPC Talk
                        {
                            int ID = CSocket.Client.LastNPC;
                            int LinkBack = data[10];
                            if (LinkBack != 255)
                                Handler.NpcTalk(CSocket, ID, LinkBack);
                            break;
                        }
                    #endregion

                    #region Team
                    case 1023:
                        {
                            Console.WriteLine("team Packet");
                            int subtype = data[4];
                            switch (subtype)
                            {
                                case 0://Create team
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Client.Team = new Struct.Team();
                                            CSocket.Client.Team.LeaderID = CSocket.Client.ID;
                                            CSocket.Client.Team.Forbid = false;
                                            CSocket.Client.Team.Members.Add(CSocket.Client.ID, CSocket);
                                            CSocket.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.MakeTeam));
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are already in a team!", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 1://Request to join
                                    {
                                        if (CSocket.Client.Team != null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are already in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        int Leader = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(Leader))
                                        {
                                            ClientSocket TeamLeader = Nano.ClientPool[Leader];
                                            if (TeamLeader.Client.Team != null)
                                            {
                                                if (TeamLeader.Client.Team.LeaderID == TeamLeader.Client.ID)
                                                {
                                                    if (!TeamLeader.Client.Team.Forbid)
                                                    {
                                                        if (TeamLeader.Client.Team.Members.Count < 5)
                                                        {
                                                            TeamLeader.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.JoinTeam));
                                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Team] Request to join team sent to " + TeamLeader.Client.Name, Struct.ChatType.Top));
                                                        }
                                                        else
                                                        {
                                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + "'s team is full.", Struct.ChatType.Top));
                                                        }
                                                    }
                                                    else
                                                    {
                                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + "'s team forbids new members.", Struct.ChatType.Top));
                                                    }
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + " is not the team leader.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + TeamLeader.Client.Name + " has not created a team.", Struct.ChatType.Top));
                                            }
                                        }
                                        break;
                                    }
                                case 2://Exit Team
                                    {
                                        if (CSocket.Client.Team != null)
                                        {
                                            ClientSocket Leader = Nano.ClientPool[CSocket.Client.Team.LeaderID];
                                            foreach (KeyValuePair<int, ClientSocket> Member in Leader.Client.Team.Members)
                                            {
                                                if (Member.Value.Client.ID != CSocket.Client.ID)
                                                {
                                                    Member.Value.Send(ConquerPacket.Chat(0, "SYSTEM", Member.Value.Client.Name, "[Team] " + CSocket.Client.Name + " has just left the team!", Struct.ChatType.Top));
                                                    Member.Value.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.LeaveTeam));
                                                }
                                            }
                                            Leader.Client.Team.Members.Remove(CSocket.Client.ID);
                                            CSocket.Client.Team = null;
                                            //CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Team] You have left the team.", Struct.ChatType.Top));
                                            CSocket.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.LeaveTeam));
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 3: //Accept Invite
                                    {
                                        if (CSocket.Client.Team != null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are already in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        int Inviter = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(Inviter))
                                        {
                                            ClientSocket TeamLeader = Nano.ClientPool[Inviter];
                                            if (TeamLeader.Client.Team != null)
                                            {
                                                if (TeamLeader.Client.Team.Members.Count < 5)
                                                {
                                                    if (!TeamLeader.Client.Team.Forbid)
                                                    {
                                                        foreach (KeyValuePair<int, ClientSocket> Member in TeamLeader.Client.Team.Members)
                                                        {
                                                            Member.Value.Send(ConquerPacket.TeamMember(CSocket.Client));
                                                            CSocket.Send(ConquerPacket.TeamMember(Member.Value.Client));
                                                        }
                                                        TeamLeader.Client.Team.Members.Add(CSocket.Client.ID, CSocket);
                                                        CSocket.Client.Team = TeamLeader.Client.Team;
                                                    }
                                                    else
                                                    {
                                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter's team does not accept new members.", Struct.ChatType.Top));
                                                    }
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter's team is full.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter no longer has a team.", Struct.ChatType.Top));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Inviter is no longer online.", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 4: //Invite to join
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot invite new members!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        int Invited = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(Invited))
                                        {
                                            ClientSocket InvitedCSocket = Nano.ClientPool[Invited];
                                            if (InvitedCSocket.Client.Team == null)
                                            {
                                                if (!CSocket.Client.Team.Forbid)
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Team] Invited " + InvitedCSocket.Client.Name + " to join your team.", Struct.ChatType.Top));
                                                    InvitedCSocket.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.Invite));
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your team forbids new members from joining.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target is already in a team.", Struct.ChatType.Top));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target does not exist.", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 5://Accept join request
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot accept join requests.", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        int ToJoin = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(ToJoin))
                                        {
                                            ClientSocket Invited = Nano.ClientPool[ToJoin];
                                            if (Invited.Client.Team == null)
                                            {
                                                if (!CSocket.Client.Team.Forbid)
                                                {
                                                    foreach (KeyValuePair<int, ClientSocket> Member in CSocket.Client.Team.Members)
                                                    {
                                                        Member.Value.Send(ConquerPacket.TeamMember(Invited.Client));
                                                        Invited.Send(ConquerPacket.TeamMember(Member.Value.Client));
                                                    }
                                                    CSocket.Client.Team.Members.Add(Invited.Client.ID, Invited);
                                                    Invited.Client.Team = CSocket.Client.Team;
                                                }
                                                else
                                                {
                                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your team forbids new members from joining.", Struct.ChatType.Top));
                                                }
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target is already in a team.", Struct.ChatType.Top));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target does not exist.", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 6: //Dismiss
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot dismiss the team.", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        foreach (KeyValuePair<int, ClientSocket> Member in CSocket.Client.Team.Members)
                                        {
                                            if (Member.Value.Client.ID != CSocket.Client.ID)
                                            {
                                                Member.Value.Send(ConquerPacket.Team(Member.Value.Client.ID, Struct.TeamOption.DismissTeam));
                                                Member.Value.Client.Team = null;
                                            }
                                        }
                                        CSocket.Client.Team = null;
                                        CSocket.Send(ConquerPacket.Team(CSocket.Client.ID, Struct.TeamOption.DismissTeam));
                                        break;
                                    }
                                case 7: //Kick from team
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot kick team members.", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        int Kick = ReadLong(data, 8);
                                        if (Nano.ClientPool.ContainsKey(Kick))
                                        {
                                            if (CSocket.Client.Team.Members.ContainsKey(Kick))
                                            {
                                                foreach (KeyValuePair<int, ClientSocket> Member in CSocket.Client.Team.Members)
                                                {
                                                    Member.Value.Send(ConquerPacket.Team(Kick, Struct.TeamOption.Kick));
                                                    if (Member.Value.Client.ID == Kick)
                                                    {
                                                        Member.Value.Client.Team = null;
                                                    }
                                                }
                                                CSocket.Client.Team.Members.Remove(Kick);
                                            }
                                            else
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target not in team.", Struct.ChatType.Top));
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target does not exist.", Struct.ChatType.Top));
                                        }
                                        break;
                                    }
                                case 8://Forbid
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (!CSocket.Client.Team.Forbid)
                                        {
                                            CSocket.Client.Team.Forbid = true;
                                        }
                                        break;
                                    }
                                case 9: //Unforbid
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.Forbid)
                                        {
                                            CSocket.Client.Team.Forbid = false;
                                        }
                                        break;
                                    }
                                case 10://unForbidMoney
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.ForbidMoney)
                                        {
                                            CSocket.Client.Team.ForbidMoney = false;
                                        }
                                        break;
                                    }
                                case 11://forbidMoney
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.ForbidMoney)
                                        {
                                            CSocket.Client.Team.ForbidMoney = false;
                                        }
                                        break;
                                    }
                                case 12://ForbidItems
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (!CSocket.Client.Team.ForbidItems)
                                        {
                                            CSocket.Client.Team.ForbidItems = true;
                                        }
                                        break;
                                    }
                                case 13://unForbidItems
                                    {
                                        if (CSocket.Client.Team == null)
                                        {
                                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not in a team!", Struct.ChatType.Top));
                                            break;
                                        }
                                        else
                                        {
                                            if (CSocket.Client.Team.LeaderID != CSocket.Client.ID)
                                            {
                                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You are not the leader and cannot forbid new joins!", Struct.ChatType.Top));
                                                break;
                                            }
                                        }
                                        if (CSocket.Client.Team.ForbidItems)
                                        {
                                            CSocket.Client.Team.ForbidItems = false;
                                        }
                                        break;
                                    }
                                default:
                                    {
                                        CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown team subtype: " + subtype, Struct.ChatType.Top));
                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion
                    #region 3EC(1004) Chat Packet
                    case 1004:
                        {
                            Handler.Chat(data, CSocket);
                            break;
                        }
                    #endregion
                    default:
                        {
                            Console.WriteLine("[GameServer] Unknown packet type: " + Type);
                            CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Handler-Error] Please report: Unable to handle packet type " + Type, Struct.ChatType.Top));
                            break;
                        }
                }
                if (Split1 != null)
                    ProcessPacket(Split1, CSocket);
                if (Split2 != null)
                    ProcessPacket(Split2, CSocket);
                if (Split3 != null)
                    ProcessPacket(Split3, CSocket);
                if (Split4 != null)
                    ProcessPacket(Split4, CSocket);
                if (Split5 != null)
                    ProcessPacket(Split5, CSocket);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return;
            }
        }
Exemple #14
0
 public static void ItemBuy(byte[] Data, ClientSocket CSocket)
 {
     int ID = PacketProcessor.ReadLong(Data, 8);
     if (CSocket.Client.Inventory.Count == 40)
     {
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your inventory is full.", Struct.ChatType.System));
         return;
     }
     string Shop = System.IO.File.ReadAllText("Shop.dat");
     if (itemexist(Convert.ToString(ID), Shop))
     {
         Struct.ItemInfo Item = new Struct.ItemInfo();
         if (MainGS.Items.ContainsKey(ID))
         {
             Struct.ItemData NewItem = MainGS.Items[ID];
             if (NewItem.EPCost > 0)
             {
                 if (CSocket.Client.EPs >= NewItem.EPCost)
                 {
                     Handler.CPs(NewItem.EPCost * -1, CSocket);
                     Item.ItemID = NewItem.ID;
                     Item.UID = MainGS.Rand.Next(1, 9999999);
                     bool created = Database.Database.NewItem(Item, CSocket);
                     while (!created)
                     {
                         Item.UID = MainGS.Rand.Next(1, 9999999);
                         created = Database.Database.NewItem(Item, CSocket);
                     }
                     CSocket.Client.Inventory.Add(Item.UID, Item);
                     CSocket.Send(EudemonPacket.ItemInfo(Item.UID, Item.ItemID, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                 }
                 else
                 {
                     CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You do not have enough EPs.", Struct.ChatType.System));
                 }
             }
             else if (NewItem.Cost > 0)
             {
                 if (CSocket.Client.Money >= NewItem.Cost)
                 {
                     Handler.Money(NewItem.Cost * -1, CSocket);
                     Item.ItemID = NewItem.ID;
                     Item.UID = MainGS.Rand.Next(1, 9999999);
                     bool created = Database.Database.NewItem(Item, CSocket);
                     while (!created)
                     {
                         Item.UID = MainGS.Rand.Next(1, 9999999);
                         created = Database.Database.NewItem(Item, CSocket);
                     }
                     CSocket.Client.Inventory.Add(Item.UID, Item);
                     CSocket.Send(EudemonPacket.ItemInfo(Item.UID, Item.ItemID, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                 }
                 else
                 {
                     CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You do not have enough money.", Struct.ChatType.System));
                 }
             }
             else
             {
                 Item.ItemID = NewItem.ID;
                 Item.UID = MainGS.Rand.Next(1, 9999999);
                 bool created = Database.Database.NewItem(Item, CSocket);
                 while (!created)
                 {
                     Item.UID = MainGS.Rand.Next(1, 9999999);
                     created = Database.Database.NewItem(Item, CSocket);
                 }
                 CSocket.Client.Inventory.Add(Item.UID, Item);
                 CSocket.Send(EudemonPacket.ItemInfo(Item.UID, Item.ItemID, 0, 0, 0, 0, 0, 0, 0, 0, 0));
             }
         }
     }
     else
     {
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item does not exist in Shop.dat", Struct.ChatType.System));
     }
 }
Exemple #15
0
 /// <summary>
 /// Does damage to a conquer online terrain NPC.
 /// </summary>
 /// <param name="CSocket">Attacking client socket.</param>
 /// <param name="AttackedTNpc">Attacked TNpc</param>
 /// <param name="Damage">Damage done</param>
 /// <param name="AType">Type of attack</param>
 public static void doTNpc(ClientSocket CSocket, Struct.TerrainNPC AttackedTNpc, int Damage, int AType)
 {
     if (AttackedTNpc.UID >= 6700)
     {
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] GuildWar is not ready yet.", Struct.ChatType.System));
     }
     else
     {
         GiveExp(CSocket, AttackedTNpc, Damage);
         if (AType != 21)
             EudemonPacket.ToLocal(EudemonPacket.Attack(CSocket.Client.ID, AttackedTNpc.UID, AttackedTNpc.X, AttackedTNpc.Y, Damage, AType), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
     }
 }
Exemple #16
0
 /// <summary>
 /// Does damage to a player
 /// </summary>
 /// <param name="CSocket">Attacking ClientSocket</param>
 /// <param name="ASocket">Attacked ClientSocket</param>
 /// <param name="Damage">Damage to do</param>
 /// <param name="AType">Type of attack</param>
 /// <returns>True if the player dies, otherwise false.</returns>
 public static bool doPlayer(ClientSocket CSocket, ClientSocket ASocket, int Damage, int AType)
 {
     //TODO: Pk points, Flashing names, etc
     Character Attacker = CSocket.Client;
     Character AttackedChar = ASocket.Client;
     if (Damage < AttackedChar.CurrentHP)
     {
         CSocket.Client.Flashing = true;
         if (CSocket.Client.FlashTimer == null)
         {
             CSocket.Client.FlashTimer = new System.Timers.Timer();
             CSocket.Client.FlashTimer.Interval = 10000;
             CSocket.Client.FlashTimer.AutoReset = false;
             CSocket.Client.FlashTimer.Elapsed += delegate
             {
                 CSocket.Client.Flashing = false;
                 CSocket.Client.FlashTimer.Stop();
                 CSocket.Client.FlashTimer.Dispose();
                 EudemonPacket.ToLocal(EudemonPacket.Status(CSocket, 2, 0, Struct.StatusTypes.StatusEffect), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
             };
             CSocket.Client.FlashTimer.Start();
         }
         else
         {
             CSocket.Client.FlashTimer.Stop();
             CSocket.Client.FlashTimer.Dispose();
             CSocket.Client.FlashTimer = new System.Timers.Timer();
             CSocket.Client.FlashTimer.Interval = 10000;
             CSocket.Client.FlashTimer.AutoReset = false;
             CSocket.Client.FlashTimer.Elapsed += delegate
             {
                 CSocket.Client.Flashing = false;
                 CSocket.Client.FlashTimer.Stop();
                 CSocket.Client.FlashTimer.Dispose();
                 EudemonPacket.ToLocal(EudemonPacket.Status(CSocket, 2, 0, Struct.StatusTypes.StatusEffect), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
             };
             CSocket.Client.FlashTimer.Start();
         }
         if (AType != 21)
             EudemonPacket.ToLocal(EudemonPacket.Attack(Attacker.ID, AttackedChar.ID, Attacker.X, Attacker.Y, Damage, AType), Attacker.X, Attacker.Y, (int)Attacker.Map, 0, 0);
         Interlocked.Add(ref AttackedChar.CurrentHP, (Damage * -1));
         ASocket.Send(EudemonPacket.Status(ASocket, 2, AttackedChar.CurrentHP, Struct.StatusTypes.Hp));
         EudemonPacket.ToLocal(EudemonPacket.Status(CSocket, 2, 0, Struct.StatusTypes.StatusEffect), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
         return false;
     }
     else
     {
         CSocket.Client.Flashing = true;
         if (CSocket.Client.FlashTimer == null)
         {
             CSocket.Client.FlashTimer = new System.Timers.Timer();
             CSocket.Client.FlashTimer.Interval = 60000;
             CSocket.Client.FlashTimer.AutoReset = false;
             CSocket.Client.FlashTimer.Elapsed += delegate
             {
                 CSocket.Client.Flashing = false;
                 CSocket.Client.FlashTimer.Stop();
                 CSocket.Client.FlashTimer.Dispose();
                 EudemonPacket.ToLocal(EudemonPacket.Status(CSocket, 2, 0, Struct.StatusTypes.StatusEffect), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
             };
             CSocket.Client.FlashTimer.Start();
         }
         else
         {
             CSocket.Client.FlashTimer.Stop();
             CSocket.Client.FlashTimer.Dispose();
             CSocket.Client.FlashTimer = new System.Timers.Timer();
             CSocket.Client.FlashTimer.Interval = 60000;
             CSocket.Client.FlashTimer.AutoReset = false;
             CSocket.Client.FlashTimer.Elapsed += delegate
             {
                 CSocket.Client.Flashing = false;
                 CSocket.Client.FlashTimer.Stop();
                 CSocket.Client.FlashTimer.Dispose();
                 EudemonPacket.ToLocal(EudemonPacket.Status(CSocket, 2, 0, Struct.StatusTypes.StatusEffect), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
             };
             CSocket.Client.FlashTimer.Start();
         }
         if (AType != 21)
             EudemonPacket.ToLocal(EudemonPacket.Attack(Attacker.ID, AttackedChar.ID, Attacker.X, Attacker.Y, Damage, AType), Attacker.X, Attacker.Y, (int)Attacker.Map, 0, 0);
         EudemonPacket.ToLocal(EudemonPacket.Attack(Attacker.ID, AttackedChar.ID, AttackedChar.X, AttackedChar.Y, Damage, 14), Attacker.X, Attacker.Y, (int)Attacker.Map, 0, 0);
         EudemonPacket.ToLocal(EudemonPacket.Status(ASocket, 2, AttackedChar.GhostModel, Struct.StatusTypes.Model), AttackedChar.X, AttackedChar.Y, (int)AttackedChar.Map, 0, 0);
         CSocket.Client.PkPoints += 10;
         if (ASocket.Client.Flashing)
             ASocket.Client.Flashing = false;
         EudemonPacket.ToLocal(EudemonPacket.Status(ASocket, 2, 1024, Struct.StatusTypes.StatusEffect), AttackedChar.X, AttackedChar.Y, (int)AttackedChar.Map, 0, 0);
         EudemonPacket.ToLocal(EudemonPacket.Status(CSocket, 2, 0, Struct.StatusTypes.StatusEffect), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
         CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.PkPoints, Struct.StatusTypes.PKPoints));
         //TODO: Guild PKPs
         ASocket.Client.Dead = true;
         return true;
     }
 }
Exemple #17
0
 public static void Jump(ushort X, ushort Y, ClientSocket CSocket)
 {
     //Check if jump distance is too large!
     int Dis1 = 0;
     if (X < CSocket.Client.X)
         Dis1 = Math.Abs(X - CSocket.Client.X);
     else
         Dis1 = Math.Abs(CSocket.Client.X - X);
     int Dis2 = 0;
     if (Y < CSocket.Client.Y)
         Dis2 = Math.Abs(Y - CSocket.Client.Y);
     else
         Dis2 = Math.Abs(CSocket.Client.Y - Y);
     if (Dis1 > 18 || Dis2 > 18)
     {
         CSocket.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, 0, 0, CSocket.Client.X, CSocket.Client.Y, 0, Struct.DataType.CorrectCords));
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Jump too large!", Struct.ChatType.System));
         return;
     }
     if (MainGS.Maps.ContainsKey((int)CSocket.Client.Map))
     {
         Struct.DmapData Map = MainGS.Maps[(int)CSocket.Client.Map];
         if (!Map.CheckLoc((ushort)X, (ushort)Y))
         {
             CSocket.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, 0, 0, CSocket.Client.X, CSocket.Client.Y, 0, Struct.DataType.CorrectCords));
             CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Invalid coordinates.", Struct.ChatType.System));
             return;
         }
     }
     else
     {
         CSocket.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, 0, 0, CSocket.Client.X, CSocket.Client.Y, 0, Struct.DataType.CorrectCords));
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Map[" + (int)CSocket.Client.Map + "] not loaded.", Struct.ChatType.System));
         return;
     }
     //TODO: Map / Guild wall / other checks
     CSocket.Client.PrevX = CSocket.Client.X;
     CSocket.Client.PrevY = CSocket.Client.Y;
     CSocket.Client.X = X;
     CSocket.Client.Y = Y;
     byte[] JumpPacket = EudemonPacket.GeneralOld(CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y, CSocket.Client.PrevX, CSocket.Client.PrevY, 0, Struct.DataType.Jump);
     //lock(MainGS.ClientPool)
     //{
     try
     {
         Monitor.Enter(MainGS.ClientPool);
         foreach (KeyValuePair<int, ClientSocket> Tests in MainGS.ClientPool)
         {
             ClientSocket C = Tests.Value;
             if ((int)C.Client.Map == (int)CSocket.Client.Map)
             {
                 bool seen = Calculation.CanSee(CSocket.Client.PrevX, CSocket.Client.PrevY, C.Client.X, C.Client.Y);
                 if (!seen)
                 {
                     if (Calculation.CanSee(CSocket.Client.X, CSocket.Client.Y, C.Client.X, C.Client.Y))
                     {
                         C.Send(EudemonPacket.SpawnCharacter(CSocket));
                     }
                 }
                 else
                 {
                     if (Calculation.CanSee(CSocket.Client.X, CSocket.Client.Y, C.Client.X, C.Client.Y))
                         C.Send(JumpPacket);
                     else
                         C.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, CSocket.Client.PrevX, CSocket.Client.PrevY, 0, 0, 0, Struct.DataType.EntityRemove));
                 }
             }
         }
         //}
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     finally
     {
         Monitor.Exit(MainGS.ClientPool);
     }
     Spawn.All(CSocket);
 }
Exemple #18
0
 public static void CPs(int value, ClientSocket CSocket)
 {
     CSocket.Client.EPs += value;
     CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.EPs, Struct.StatusTypes.InvEPoints));
 }
Exemple #19
0
        public static void ItemEquip(int Location, int UID, ClientSocket CSocket)
        {
            if (CSocket.Client.Inventory.ContainsKey(UID))
            {
                Struct.ItemInfo Item = CSocket.Client.Inventory[UID];
                int TrueLoc = DeterminePosition(Item.ItemID, Location);
                if (Item.ItemID == 1050002 || Item.ItemID == 1050001 || Item.ItemID == 1050000)
                    Location = 5;
                if (TrueLoc == Location)
                {
                    if (CSocket.Client.Equipment.ContainsKey(Location))
                    {
                        int Loc2 = CSocket.Client.Equipment[Location].Position;
                        int UID2 = CSocket.Client.Equipment[Location].UID;
                        ItemUnequip(Loc2, UID2, CSocket);
                    }
                    //TODO: Item bonuses(attack etc)
                    //TODO: Position checks, class requirements
                    if (CSocket.Client.Equipment.ContainsKey(Location))
                    {
                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Could not equip the item into that slot.", Struct.ChatType.System));
                        return;
                    }
                    CSocket.Client.Inventory.Remove(UID);
                    Item.Position = Location;
                    CSocket.Client.Equipment.Add(Location, Item);
                    Database.Database.UpdateItem(Item);
                    //CSocket.Send(EudemonPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                    CSocket.Send(EudemonPacket.ItemUsage(Item.UID, Location, Struct.ItemUsage.UpdateItem));
                    if (Location == 4 || Location == 5)
                    {
                        if (Item.ItemID != 1050002 && Item.ItemID != 1050001 & Item.ItemID != 1050000)
                        {
                            int Type = Calculation.WeaponType(Convert.ToString(Item.ItemID));
                        }
                    }
                    #region ItemCalculations
                    switch (Item.Soc1)
                    {
                        case 0:
                            break;
                        case 11:
                            {
                                CSocket.Client.NCG++;
                                break;
                            }
                        case 12:
                            {
                                CSocket.Client.RCG++;
                                break;
                            }
                        case 13:
                            {
                                CSocket.Client.SCG++;
                                break;
                            }
                        case 71:
                            {
                                CSocket.Client.NBG++;
                                break;
                            }
                        case 72:
                            {
                                CSocket.Client.RBG++;
                                break;
                            }
                        case 73:
                            {
                                CSocket.Client.SBG++;
                                break;
                            }
                        default:
                            {
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown GemID: " + Item.Soc1, Struct.ChatType.Talk));
                                break;
                            }

                    }
                    switch (Item.Soc2)
                    {
                        case 0:
                            break;
                        case 11:
                            {
                                CSocket.Client.NCG++;
                                break;
                            }
                        case 12:
                            {
                                CSocket.Client.RCG++;
                                break;
                            }
                        case 13:
                            {
                                CSocket.Client.SCG++;
                                break;
                            }
                        case 71:
                            {
                                CSocket.Client.NBG++;
                                break;
                            }
                        case 72:
                            {
                                CSocket.Client.RBG++;
                                break;
                            }
                        case 73:
                            {
                                CSocket.Client.SBG++;
                                break;
                            }
                        default:
                            {
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unknown GemID: " + Item.Soc2, Struct.ChatType.Talk));
                                break;
                            }

                    }
                    switch (Item.Bless)
                    {
                        case 7:
                            {
                                CSocket.Client.Bless += 7;
                                break;
                            }
                        case 5:
                            {
                                CSocket.Client.Bless += 5;
                                break;
                            }
                        case 3:
                            {
                                CSocket.Client.Bless += 3;
                                break;
                            }
                        case 1:
                            {
                                CSocket.Client.Bless += 1;
                                break;
                            }
                        case 0:
                            {
                                break;
                            }
                        default:
                            {
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Invalid bless: " + Item.Bless, Struct.ChatType.System));
                                break;
                            }
                    }
                    if (MainGS.Items.ContainsKey(Item.ItemID))
                    {
                        Struct.ItemData ItemD = MainGS.Items[Item.ItemID];
                        CSocket.Client.BaseMagicAttack += ItemD.MinMagicAttack;
                        if (Item.Position == 5)
                        {
                            CSocket.Client.BaseMaxAttack += (int)Math.Floor(.5 * ItemD.MaxDamage);
                            CSocket.Client.BaseMinAttack += (int)Math.Floor(.5 * ItemD.MinDamage);
                        }
                        else
                        {
                            CSocket.Client.BaseMaxAttack += ItemD.MaxDamage;
                            CSocket.Client.BaseMinAttack += ItemD.MinDamage;
                        }
                        CSocket.Client.Defense += ItemD.DefenseAdd;
                        CSocket.Client.MaxHP += ItemD.HPAdd;
                        CSocket.Client.MaxHP += Item.Enchant;
                        CSocket.Client.MagicDefense += ItemD.MDefenseAdd;
                        CSocket.Client.MaxMP += ItemD.MPAdd;
                        CSocket.Client.Dodge += ItemD.DodgeAdd;
                    }
                    if (Item.Plus > 0)
                    {
                        string s_ItemID = Convert.ToString(Item.ItemID);
                        int itemidsimple = 0;
                        if ((Item.ItemID >= 900000 && Item.ItemID <= 900999) || (Item.ItemID >= 111303 && Item.ItemID <= 118999) || (Item.ItemID >= 130003 && Item.ItemID <= 139999))//Shields, Helms, Armors
                        {
                            /*s_ItemID = s_ItemID.Remove((s_ItemID.Length - 3), 1);
                            s_ItemID = s_ItemID.Insert((s_ItemID.Length - 2), "0");
                            s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                            s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");*/
                            s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                            s_ItemID = s_ItemID.Insert(s_ItemID.Length, "0");
                            itemidsimple = Convert.ToInt32(s_ItemID);
                        }
                        else if ((Item.ItemID >= 150000 && Item.ItemID <= 160250) || (Item.ItemID >= 500000 && Item.ItemID <= 500400) || (Item.ItemID >= 120003 && Item.ItemID <= 121249) || (Item.ItemID >= 421003 && Item.ItemID <= 421339))//BS's, Bows, Necky/Bags
                        {
                            s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                            s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");
                            itemidsimple = Convert.ToInt32(s_ItemID);
                        }
                        else if (Item.ItemID >= 510000 && Item.ItemID <= 580400)//2 Hander
                        {
                            s_ItemID = s_ItemID.Remove(0, 3);
                            s_ItemID = s_ItemID.Insert(0, "555");
                            s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                            s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");
                            itemidsimple = Convert.ToInt32(s_ItemID);
                        }
                        else if (Item.ItemID >= 410000 && Item.ItemID <= 490400 && itemidsimple == 0)//1 Handers
                        {
                            s_ItemID = s_ItemID.Remove(0, 3);
                            s_ItemID = s_ItemID.Insert(0, "444");
                            s_ItemID = s_ItemID.Remove((s_ItemID.Length - 1), 1);
                            s_ItemID = s_ItemID.Insert((s_ItemID.Length), "0");
                            itemidsimple = Convert.ToInt32(s_ItemID);
                        }
                        if (MainGS.ItemPluses.ContainsKey(itemidsimple))
                        {
                            Struct.ItemPlusDB IPlus = MainGS.ItemPluses[itemidsimple];
                            if (IPlus.DB.ContainsKey(Item.Plus))
                            {
                                Struct.ItemPlus iPlus = IPlus.DB[Item.Plus];
                                CSocket.Client.BaseMaxAttack += iPlus.MaxDmg;
                                CSocket.Client.BaseMinAttack += iPlus.MinDmg;
                                CSocket.Client.Defense += iPlus.DefenseAdd;
                               // CSocket.Client.BaseMagicAttack += iPlus.MDamageAdd;//@TODO: recalc this
                               // CSocket.Client.BonusMagicAttack += iPlus.MDamageAdd;
                                CSocket.Client.BonusMagicDefense += iPlus.MDefAdd;
                                CSocket.Client.MaxHP += iPlus.HPAdd;
                                CSocket.Client.Dodge += iPlus.DodgeAdd;
                                //TODO: Dodge, etc
                            }
                        }
                    }
                    #endregion
                    Calculation.Attack(CSocket);
                    EudemonPacket.ToLocal(EudemonPacket.SpawnCharacter(CSocket), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                }
                else if (TrueLoc > 0 && TrueLoc != Location)
                {
                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Incorrect equip location.", Struct.ChatType.System));
                }
                else if (TrueLoc == -1)
                {
                    Handler.UseItem(Item, CSocket);
                }
            }
            else
            {
                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item doesn't exist.", Struct.ChatType.System));
            }
        }
Exemple #20
0
 public static void Input(int LinkBack, ClientSocket CSocket)
 {
     CSocket.Send(EudemonPacket.NPCTalk(LinkBack, 3, ""));
 }
Exemple #21
0
        public static void Chat(byte[] Data, ClientSocket CSocket)
        {
            Struct.ChatType Type = (Struct.ChatType)((Data[9] << 8) + Data[8]);
            int Position = 26;
            int Len = 0;
            string From = "";
            string To = "";
            string Message = "";

            for (int C = 0; C < Data[25]; C++)
            {
                From += Convert.ToChar(Data[Position]);
                Position++;
            }
            Len = Data[Position];
            Position++;
            for (int C = 0; C < Len; C++)
            {
                To += Convert.ToChar(Data[Position]);
                Position++;
            }
            Position++;
            Len = Data[Position];
            Position++;
            for (int C = 0; C < Len; C++)
            {
                Message += Convert.ToChar(Data[Position]);
                Position++;
            }
            #region Commands
            try
            {
                if (Message.StartsWith("/"))
                {
                    string[] Command = Message.Substring(1).Split(' ');
                    switch (Command[0].ToLower())
                    {
                        case "heal":
                            {
                                CSocket.Send(EudemonPacket.Status(CSocket, Struct.StatusTypes.Hp, CSocket.Client.MaxHP));
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[GameServer] Healed " + CSocket.Client.Name, Struct.ChatType.System));
                                break;
                            }
                        case "bp":
                            {
                                Calculation.BP(CSocket.Client);
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Info] Current BP " + CSocket.Client.BP, Struct.ChatType.System));
                                break;
                            }
                        case "dc":
                            {
                                CSocket.Disconnect();
                                break;
                            }
                        case "dl":
                            {
                                int type = Convert.ToInt16(Command[1]);
                                CSocket.Send(EudemonPacket.General(CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y, CSocket.Client.Direction, Struct.DataType.Dialog, type));
                                break;
                            }
                        case "pos":
                            {
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[GameServer] Current Pos " + CSocket.Client.X + ", " + CSocket.Client.Y, Struct.ChatType.System));
                                break;
                            }
                        case "unstuck":
                            {
                                Handler.Teleport((int)Struct.Maps.Cronus, 290, 424, 0, CSocket);
                                break;
                            }
                        case "stattest":
                            {

                                CSocket.Send(EudemonPacket.Status(CSocket, Struct.StatusTypes.Hp, 50));

                                break;
                            }
                        case "kick":
                            {
                                if (CSocket.Client.isGM || CSocket.Client.isPM)
                                {
                                    if (Command.Length < 2)
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Command example: /kick player", Struct.ChatType.Talk));
                                        break;
                                    }
                                    bool kicked = false;
                                    try
                                    {
                                        Monitor.Enter(MainGS.ClientPool);
                                        foreach (KeyValuePair<int, ClientSocket> Player in MainGS.ClientPool)
                                        {
                                            if (Player.Value.Client.Name.ToLower() == Command[1].ToLower())
                                            {
                                                if (Player.Value.Client.isPM && !CSocket.Client.isPM)
                                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "GMs cannot kick PMs, sorry!", Struct.ChatType.System));
                                                else
                                                {
                                                    EudemonPacket.ToServer(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", Player.Value.Client.Name + " has been kicked from the server", Struct.ChatType.CenterGm), 0);
                                                    Player.Value.Disconnect();
                                                    kicked = true;
                                                }
                                                break;
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e.ToString());
                                    }
                                    finally
                                    {
                                        Monitor.Exit(MainGS.ClientPool);
                                    }
                                    if (!kicked)
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Cannot kick player.", Struct.ChatType.Talk));
                                    }
                                }
                                break;
                            }
                        case "ban":
                            {
                                if (CSocket.Client.isPM)
                                {
                                    if (Command.Length < 2)
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Command example: /kick player", Struct.ChatType.Talk));
                                        break;
                                    }
                                    bool kicked = false;
                                    Database.Database.BanPlayer(Command[1]);
                                    try
                                    {
                                        Monitor.Enter(MainGS.ClientPool);
                                        foreach (KeyValuePair<int, ClientSocket> Player in MainGS.ClientPool)
                                        {
                                            if (Player.Value.Client.Name.ToLower() == Command[1].ToLower())
                                            {
                                                EudemonPacket.ToServer(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", Player.Value.Client.Name + " has been kicked & banned from the server.", Struct.ChatType.CenterGm), 0);
                                                Player.Value.Disconnect();
                                                kicked = true;
                                                break;
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e.ToString());
                                    }
                                    finally
                                    {
                                        Monitor.Exit(MainGS.ClientPool);
                                    }
                                    if (!kicked)
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Cannot ban player.", Struct.ChatType.Talk));
                                    }
                                }
                                break;
                            }
                        case "save":
                            {
                                Database.Database.SaveCharacter(CSocket.Client);
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[GameServer] Saved " + CSocket.Client.Name, Struct.ChatType.System));
                                break;
                            }
                        case "reload":
                            {
                                if (Command.Length == 2 && CSocket.Client.isGM || CSocket.Client.isPM)
                                {
                                    switch (Command[1].ToLower())
                                    {
                                        case "portals":
                                            {
                                                MainGS.Portals.Clear();
                                                Struct.LoadPortals();
                                                break;
                                            }
                                        case "monsters":
                                            {
                                                MainGS.BaseMonsters.Clear();
                                                MainGS.MonsterSpawns.Clear();
                                                MainGS.Monsters.Clear();
                                                Struct.LoadMonsters();
                                                break;
                                            }
                                        case "npcs":
                                            {
                                                MainGS.Npcs.Clear();
                                                Struct.LoadNpcs();
                                                break;
                                            }
                                        case "tnpcs":
                                            {
                                                MainGS.TerrainNpcs.Clear();
                                                Struct.LoadTNpcs();
                                                break;
                                            }
                                    }
                                }
                                break;
                            }
                        case "scroll":
                            {
                                if (Command.Length == 2)
                                {
                                    switch (Command[1].ToLower())
                                    {
                                        case "tc":
                                            {
                                                Handler.Teleport(1002, 438, 377, 0, CSocket);
                                                break;
                                            }
                                        default:
                                            {
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Unknown scroll location. Example: /scroll tc", Struct.ChatType.Talk));
                                                break;
                                            }
                                    }
                                }
                                else
                                {
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] /scroll tc", Struct.ChatType.Talk));
                                }
                                break;
                            }
                        case "i":
                            {
                                if (CSocket.Client.isGM || CSocket.Client.isPM)
                                {
                                    if (!CSocket.Client.Invincible)
                                    {
                                        CSocket.Client.Invincible = true;
                                        EudemonPacket.ToLocal(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", CSocket.Client.Name + " has just become even more godly..", Struct.ChatType.CenterGm), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
                                    }
                                    else
                                    {
                                        CSocket.Client.Invincible = false;
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You are no longer flagged as invincible.", Struct.ChatType.System));
                                    }
                                    EudemonPacket.ToLocal(EudemonPacket.General(CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y, CSocket.Client.Direction, Struct.DataType.EntityRemove, 0), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                    EudemonPacket.ToLocal(EudemonPacket.SpawnCharacter(CSocket), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);

                                }
                                break;
                            }
                        case "money":
                            {
                                if (Command.Length == 2 && CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    int Money = Convert.ToInt32(Command[1]);
                                    CSocket.Client.Money += Money;
                                    CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.Money, Struct.StatusTypes.InvMoney));
                                }
                                break;
                            }
                        case "eps":
                            {
                                if (Command.Length == 2 && CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    int Ep = Convert.ToInt32(Command[1]);
                                    CSocket.Client.EPs += Ep;
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You now have " + CSocket.Client.EPs + " EPs.", Struct.ChatType.System));
                                    CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.EPs, Struct.StatusTypes.InvEPoints));
                                }
                                break;
                            }
                        case "hair":
                            {
                                if (Command.Length == 2)
                                {
                                    int Hair = Convert.ToInt32(Command[1]);
                                    CSocket.Client.Hair = Hair;
                                    CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.Hair, Struct.StatusTypes.HairStyle));
                                }
                                break;
                            }
                        case "dropitem":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    if (Calculation.PercentSuccess(30))
                                    {
                                        int Level = 137;
                                        int Times = 1;
                                        if (Calculation.PercentSuccess(15))
                                        {
                                            Times = MainGS.Rand.Next(1, 6);
                                        }
                                        for (int i = 0; i < Times; i++)
                                        {
                                            int Money = MainGS.Rand.Next(1, 10);
                                            if (Calculation.PercentSuccess(90))
                                                Money = MainGS.Rand.Next(2, 240);
                                            if (Calculation.PercentSuccess(70))
                                                Money = MainGS.Rand.Next(60, 3000);
                                            if (Calculation.PercentSuccess(50))
                                                Money = MainGS.Rand.Next(200, 4000);
                                            if (Calculation.PercentSuccess(30))
                                                Money = MainGS.Rand.Next(1000, 30000);
                                            if (Calculation.PercentSuccess(100))
                                                Money = MainGS.Rand.Next(2000, 50000);
                                            Money = Money / ((138 - Level) * 10);
                                            if (Money < 1)
                                                Money = 1;
                                            Struct.ItemGround IG = new Struct.ItemGround();
                                            IG.Money = Money;
                                            if (Money < 10)
                                                IG.ItemID = 1090000;
                                            else if (Money < 100)
                                                IG.ItemID = 1090010;
                                            else if (Money < 1000)
                                                IG.ItemID = 1090020;
                                            else if (Money < 3000)
                                                IG.ItemID = 1091000;
                                            else if (Money < 10000)
                                                IG.ItemID = 1091010;
                                            else
                                                IG.ItemID = 1091020;
                                            IG.UID = MainGS.Rand.Next(1, 1000);
                                            while (MainGS.ItemFloor.ContainsKey(IG.UID))
                                            {
                                                IG.UID = MainGS.Rand.Next(1, 1000);
                                            }
                                            IG.X = CSocket.Client.X;
                                            IG.Y = CSocket.Client.Y;
                                            IG.OwnerOnly = new System.Timers.Timer();
                                            IG.Map = (int)CSocket.Client.Map;
                                            IG.Dispose = new System.Timers.Timer();
                                            IG.Dispose.Interval = 60000;
                                            IG.Dispose.AutoReset = false;
                                            IG.Dispose.Elapsed += delegate { IG.Disappear(); };
                                            IG.Dispose.Start();
                                            MainGS.ItemFloor.Add(IG.UID, IG);
                                            EudemonPacket.ToLocal(EudemonPacket.DropItem(IG.UID, IG.ItemID, IG.X, IG.Y), IG.X, IG.Y, IG.Map, 0, 0);
                                        }
                                    }
                                    else
                                    {
                                        if (Calculation.PercentSuccess(5))
                                        {
                                            Struct.ItemGround IG = new Struct.ItemGround();
                                            IG.ItemID = 1088001;
                                            IG.X = CSocket.Client.X;
                                            IG.Y = CSocket.Client.Y;
                                            IG.Map = (int)CSocket.Client.Map;
                                            IG.OwnerOnly = new System.Timers.Timer();
                                            IG.UID = MainGS.Rand.Next(1000, 9999999);
                                            while (MainGS.ItemFloor.ContainsKey(IG.UID))
                                            {
                                                IG.UID = MainGS.Rand.Next(1000, 9999999);
                                            }
                                            //TODO: UID generation that is better.
                                            IG.Dispose.Interval = 10000;
                                            IG.Dispose.AutoReset = false;
                                            IG.Dispose.Elapsed += delegate { IG.Disappear(); };
                                            IG.Dispose.Start();
                                            MainGS.ItemFloor.Add(IG.UID, IG);
                                            EudemonPacket.ToLocal(EudemonPacket.DropItem(IG.UID, IG.ItemID, IG.X, IG.Y), IG.X, IG.Y, IG.Map, 0, 0);
                                        }
                                        else if (Calculation.PercentSuccess(3))
                                        {
                                            Struct.ItemGround IG = new Struct.ItemGround();
                                            IG.ItemID = 1088000;
                                            IG.X = CSocket.Client.X;
                                            IG.Y = CSocket.Client.Y;
                                            IG.Map = (int)CSocket.Client.Map;
                                            IG.OwnerOnly = new System.Timers.Timer();
                                            IG.UID = MainGS.Rand.Next(1000, 9999999);
                                            while (MainGS.ItemFloor.ContainsKey(IG.UID))
                                            {
                                                IG.UID = MainGS.Rand.Next(1000, 9999999);
                                            }
                                            //TODO: UID generation that is better.
                                            IG.Dispose.Interval = 10000;
                                            IG.Dispose.AutoReset = false;
                                            IG.Dispose.Elapsed += delegate { IG.Disappear(); };
                                            IG.Dispose.Start();
                                            MainGS.ItemFloor.Add(IG.UID, IG);
                                            EudemonPacket.ToLocal(EudemonPacket.DropItem(IG.UID, IG.ItemID, IG.X, IG.Y), IG.X, IG.Y, IG.Map, 0, 0);
                                        }
                                    }
                                }
                                break;
                            }
                        case "bringtome":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    if (Command.Length == 2)
                                    {
                                        ClientSocket Target = null;
                                        try
                                        {
                                            Monitor.Enter(MainGS.ClientPool);
                                            foreach (KeyValuePair<int, ClientSocket> Clients in MainGS.ClientPool)
                                            {
                                                if (Clients.Value.Client.Name == Command[1])
                                                {
                                                    Target = Clients.Value;
                                                    break;
                                                }
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e.ToString());
                                        }
                                        finally
                                        {
                                            Monitor.Exit(MainGS.ClientPool);
                                        }
                                        if (Target != null)
                                        {
                                            Handler.Teleport((int)CSocket.Client.Map, CSocket.Client.X, CSocket.Client.Y, 0, Target);
                                            Target.Send(EudemonPacket.Chat(0, "SYSTEM", Target.Client.Name, "You have been summoned by " + CSocket.Client.Name, Struct.ChatType.System));
                                        }
                                        else
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Player not found!", Struct.ChatType.System));
                                        }
                                    }
                                }
                                break;
                            }
                        case "bringmeto":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    if (Command.Length == 2)
                                    {
                                        ClientSocket Target = null;
                                        try
                                        {
                                            Monitor.Enter(MainGS.ClientPool);
                                            foreach (KeyValuePair<int, ClientSocket> Clients in MainGS.ClientPool)
                                            {
                                                if (Clients.Value.Client.Name == Command[1])
                                                {
                                                    Target = Clients.Value;
                                                    break;
                                                }
                                            }
                                            //}
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e.ToString());
                                        }
                                        finally
                                        {
                                            Monitor.Exit(MainGS.ClientPool);
                                        }
                                        if (Target != null)
                                        {
                                            Handler.Teleport((int)Target.Client.Map, Target.Client.X, Target.Client.Y, 0, CSocket);
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Teleported to " + Target.Client.Name, Struct.ChatType.System));
                                        }
                                        else
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Player not found!", Struct.ChatType.System));
                                        }
                                    }
                                }
                                break;
                            }
                        case "bc":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    EudemonPacket.ToServer(EudemonPacket.Chat(0, CSocket.Client.Name, "ALLUSERS", Message.Substring(2 + Command[0].Length), Struct.ChatType.NewBroadcast), 0);
                                }
                                break;
                            }
                        case "gm":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    EudemonPacket.ToServer(EudemonPacket.Chat(0, CSocket.Client.Name, "ALLUSERS", Message.Substring(2 + Command[0].Length), Struct.ChatType.CenterGm), 0);
                                }
                                break;
                            }
                        case "itemtest":
                            {
                                if (Command.Length == 2)
                                {
                                    Struct.ItemInfo NewItem = new Struct.ItemInfo();
                                    NewItem.Bless = 0;
                                    NewItem.Dura = 1;
                                    NewItem.Enchant = 0;
                                    NewItem.ItemID = Convert.ToInt32(Command[1]);
                                    NewItem.MaxDura = 1;
                                    NewItem.Plus = 0;
                                    NewItem.Position = 50;
                                    NewItem.Soc1 = 0;
                                    NewItem.Soc2 = 0;
                                    NewItem.Color = 0;
                                    NewItem.UID = MainGS.Rand.Next(1, 9999999);
                                    bool created = Database.Database.NewItem(NewItem, CSocket);
                                    while (!created)
                                    {
                                        NewItem.UID = MainGS.Rand.Next(1, 9999999);
                                        created = Database.Database.NewItem(NewItem, CSocket);
                                    }
                                    CSocket.Client.Inventory.Add(NewItem.UID, NewItem);
                                    //CSocket.Send(EudemonPacket.ItemInfo(0, Item.Value.ItemID, Item.Value.Plus, Item.Value.Soc1, Item.Value.Soc2, Item.Value.Dura, Item.Value.MaxDura, Item.Value.Position, 0, 0, 6));

                                    CSocket.Send(EudemonPacket.ItemInfo(NewItem.UID, NewItem.ItemID, NewItem.Plus, NewItem.Soc1, NewItem.Soc2, NewItem.Dura, NewItem.MaxDura, NewItem.Position, 0, 0, 0));

                                    // CSocket.Send(EudemonPacket.ItemInfo(NewItem.UID, NewItem.ItemID, NewItem.Plus, NewItem.Bless, NewItem.Enchant, NewItem.Soc1, NewItem.Soc2, NewItem.Dura, NewItem.MaxDura, NewItem.Position, NewItem.Color));
                                    //CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Created a(n) " + Item.Name + " Plus: " + Plus + ", Bless: " + Bless + ", Enchant: " + Enchant + ", Version: " + version, Struct.ChatType.Top));
                                }
                                else
                                {
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Error in command", Struct.ChatType.System));

                                }

                                break;
                            }
                        case "item":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    if (Command.Length == 8)
                                    {
                                        if (CSocket.Client.Inventory.Count == 40)
                                        {
                                            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your inventory is full.", Struct.ChatType.System));
                                            break;
                                        }
                                        foreach (KeyValuePair<int, Struct.ItemData> Items in MainGS.Items)
                                        {
                                            Struct.ItemData Item = Items.Value;
                                            if (Item.Name.ToLower() == Command[1].ToLower())
                                            {
                                                int version = Convert.ToInt32(Command[2]);
                                                int NewItemID = Item.ID;
                                                int Plus = Convert.ToInt32(Command[4]);
                                                int Bless = Convert.ToInt32(Command[5]);
                                                int Enchant = Convert.ToInt32(Command[6]);
                                                int Soc1 = 0;
                                                int Soc2 = 0;
                                                int Color = Convert.ToInt32(Command[7]);
                                                if ((Convert.ToInt32(Command[3])) == 1)
                                                {
                                                    Soc1 = 255;
                                                }
                                                else if ((Convert.ToInt32(Command[3])) == 2)
                                                {
                                                    Soc1 = 255;
                                                    Soc2 = 255;
                                                }
                                                else if ((Convert.ToInt32(Command[3])) == 0)
                                                {
                                                    Soc1 = 0;
                                                    Soc2 = 0;
                                                }
                                                if (Color < 2 || Color > 9)
                                                    if (Bless != 1 && Bless != 3 && Bless != 5 && Bless != 7 && Bless != 0)
                                                    {
                                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + Bless + " is an invalid bless amount. Accepted amounts are 0/1/3/5/7.", Struct.ChatType.System));
                                                        break;
                                                    }
                                                if (Enchant > 255 || Enchant < 0)
                                                {
                                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + Enchant + " is an invalid enchant amount. Accepted amounts are 255>x>0.", Struct.ChatType.System));
                                                    break;
                                                }
                                                if (Plus > 12 || Plus < 0)
                                                {
                                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] " + Plus + " is an invalid plus amount. Accepted amounts are 12>x>0.", Struct.ChatType.System));
                                                    break;
                                                }
                                                string ItemID = Item.ID.ToString();
                                                if (ItemID.EndsWith("0"))
                                                    NewItemID += 3;
                                                #region Version Switch
                                                switch (version)
                                                {
                                                    case 3:
                                                        {
                                                            //the default item
                                                            break;
                                                        }
                                                    case 4:
                                                        {
                                                            NewItemID += 1;
                                                            break;
                                                        }
                                                    case 5:
                                                        {
                                                            NewItemID += 2;
                                                            break;
                                                        }
                                                    case 6:
                                                        {
                                                            NewItemID += 3;
                                                            break;
                                                        }
                                                    case 7:
                                                        {
                                                            NewItemID += 4;
                                                            break;
                                                        }
                                                    case 8:
                                                        {
                                                            NewItemID += 5;
                                                            break;
                                                        }
                                                    case 9:
                                                        {
                                                            NewItemID += 6;
                                                            break;
                                                        }
                                                    case 13:
                                                        {
                                                            NewItemID += 10;
                                                            break;
                                                        }
                                                    case 14:
                                                        {
                                                            NewItemID += 11;
                                                            break;
                                                        }
                                                    case 15:
                                                        {
                                                            NewItemID += 12;
                                                            break;
                                                        }
                                                    case 16:
                                                        {
                                                            NewItemID += 13;
                                                            break;
                                                        }
                                                    case 17:
                                                        {
                                                            NewItemID += 14;
                                                            break;
                                                        }
                                                    case 18:
                                                        {
                                                            NewItemID += 15;
                                                            break;
                                                        }
                                                    case 19:
                                                        {
                                                            NewItemID += 16;
                                                            break;
                                                        }
                                                    case 23:
                                                        {
                                                            NewItemID += 20;
                                                            break;
                                                        }
                                                    case 24:
                                                        {
                                                            NewItemID += 21;
                                                            break;
                                                        }
                                                    case 25:
                                                        {
                                                            NewItemID += 22;
                                                            break;
                                                        }
                                                    case 26:
                                                        {
                                                            NewItemID += 23;
                                                            break;
                                                        }
                                                    case 27:
                                                        {
                                                            NewItemID += 24;
                                                            break;
                                                        }
                                                    case 28:
                                                        {
                                                            NewItemID += 25;
                                                            break;
                                                        }
                                                    case 29:
                                                        {
                                                            NewItemID += 26;
                                                            break;
                                                        }
                                                    case 33:
                                                        {
                                                            NewItemID += 30;
                                                            break;
                                                        }
                                                    case 34:
                                                        {
                                                            NewItemID += 31;
                                                            break;
                                                        }
                                                    case 35:
                                                        {
                                                            NewItemID += 32;
                                                            break;
                                                        }
                                                    case 36:
                                                        {
                                                            NewItemID += 33;
                                                            break;
                                                        }
                                                    case 37:
                                                        {
                                                            NewItemID += 34;
                                                            break;
                                                        }
                                                    case 38:
                                                        {
                                                            NewItemID += 35;
                                                            break;
                                                        }
                                                    case 39:
                                                        {
                                                            NewItemID += 36;
                                                            break;
                                                        }

                                                    case 43:
                                                        {
                                                            NewItemID += 40;
                                                            break;
                                                        }
                                                    case 44:
                                                        {
                                                            NewItemID += 41;
                                                            break;
                                                        }
                                                    case 45:
                                                        {
                                                            NewItemID += 42;
                                                            break;
                                                        }
                                                    case 46:
                                                        {
                                                            NewItemID += 43;
                                                            break;
                                                        }
                                                    case 47:
                                                        {
                                                            NewItemID += 44;
                                                            break;
                                                        }
                                                    case 48:
                                                        {
                                                            NewItemID += 45;
                                                            break;
                                                        }
                                                    case 49:
                                                        {
                                                            NewItemID += 46;
                                                            break;
                                                        }
                                                    case 53:
                                                        {
                                                            NewItemID += 50;
                                                            break;
                                                        }
                                                    case 54:
                                                        {
                                                            NewItemID += 51;
                                                            break;
                                                        }
                                                    case 55:
                                                        {
                                                            NewItemID += 52;
                                                            break;
                                                        }
                                                    case 56:
                                                        {
                                                            NewItemID += 53;
                                                            break;
                                                        }
                                                    case 57:
                                                        {
                                                            NewItemID += 54;
                                                            break;
                                                        }
                                                    case 58:
                                                        {
                                                            NewItemID += 55;
                                                            break;
                                                        }
                                                    case 59:
                                                        {
                                                            NewItemID += 56;
                                                            break;
                                                        }
                                                    case 63:
                                                        {
                                                            NewItemID += 60;
                                                            break;
                                                        }
                                                    case 64:
                                                        {
                                                            NewItemID += 61;
                                                            break;
                                                        }
                                                    case 65:
                                                        {
                                                            NewItemID += 62;
                                                            break;
                                                        }
                                                    case 66:
                                                        {
                                                            NewItemID += 63;
                                                            break;
                                                        }
                                                    case 67:
                                                        {
                                                            NewItemID += 64;
                                                            break;
                                                        }
                                                    case 68:
                                                        {
                                                            NewItemID += 65;
                                                            break;
                                                        }
                                                    case 69:
                                                        {
                                                            NewItemID += 66;
                                                            break;
                                                        }
                                                    case 73:
                                                        {
                                                            NewItemID += 70;
                                                            break;
                                                        }
                                                    case 74:
                                                        {
                                                            NewItemID += 71;
                                                            break;
                                                        }
                                                    case 75:
                                                        {
                                                            NewItemID += 72;
                                                            break;
                                                        }
                                                    case 76:
                                                        {
                                                            NewItemID += 73;
                                                            break;
                                                        }
                                                    case 77:
                                                        {
                                                            NewItemID += 74;
                                                            break;
                                                        }
                                                    case 78:
                                                        {
                                                            NewItemID += 75;
                                                            break;
                                                        }
                                                    case 79:
                                                        {
                                                            NewItemID += 76;
                                                            break;
                                                        }
                                                    case 83:
                                                        {
                                                            NewItemID += 80;
                                                            break;
                                                        }
                                                    case 84:
                                                        {
                                                            NewItemID += 81;
                                                            break;
                                                        }
                                                    case 85:
                                                        {
                                                            NewItemID += 82;
                                                            break;
                                                        }
                                                    case 86:
                                                        {
                                                            NewItemID += 83;
                                                            break;
                                                        }
                                                    case 87:
                                                        {
                                                            NewItemID += 84;
                                                            break;
                                                        }
                                                    case 88:
                                                        {
                                                            NewItemID += 85;
                                                            break;
                                                        }
                                                    case 89:
                                                        {
                                                            NewItemID += 86;
                                                            break;
                                                        }
                                                    case 93:
                                                        {
                                                            NewItemID += 90;
                                                            break;
                                                        }
                                                    case 94:
                                                        {
                                                            NewItemID += 91;
                                                            break;
                                                        }
                                                    case 95:
                                                        {
                                                            NewItemID += 92;
                                                            break;
                                                        }
                                                    case 96:
                                                        {
                                                            NewItemID += 93;
                                                            break;
                                                        }
                                                    case 97:
                                                        {
                                                            NewItemID += 94;
                                                            break;
                                                        }
                                                    case 98:
                                                        {
                                                            NewItemID += 95;
                                                            break;
                                                        }
                                                    case 99:
                                                        {
                                                            NewItemID += 96;
                                                            break;
                                                        }
                                                    case 103:
                                                        {
                                                            NewItemID += 100;
                                                            break;
                                                        }
                                                    case 104:
                                                        {
                                                            NewItemID += 101;
                                                            break;
                                                        }
                                                    case 105:
                                                        {
                                                            NewItemID += 102;
                                                            break;
                                                        }
                                                    case 106:
                                                        {
                                                            NewItemID += 103;
                                                            break;
                                                        }
                                                    case 107:
                                                        {
                                                            NewItemID += 104;
                                                            break;
                                                        }
                                                    case 108:
                                                        {
                                                            NewItemID += 105;
                                                            break;
                                                        }
                                                    case 109:
                                                        {
                                                            NewItemID += 106;
                                                            break;
                                                        }
                                                    case 113:
                                                        {
                                                            NewItemID += 110;
                                                            break;
                                                        }
                                                    case 114:
                                                        {
                                                            NewItemID += 111;
                                                            break;
                                                        }
                                                    case 115:
                                                        {
                                                            NewItemID += 112;
                                                            break;
                                                        }
                                                    case 116:
                                                        {
                                                            NewItemID += 113;
                                                            break;
                                                        }
                                                    case 117:
                                                        {
                                                            NewItemID += 114;
                                                            break;
                                                        }
                                                    case 118:
                                                        {
                                                            NewItemID += 115;
                                                            break;
                                                        }
                                                    case 119:
                                                        {
                                                            NewItemID += 116;
                                                            break;
                                                        }
                                                    default:
                                                        {
                                                            //Do nothing
                                                            break;
                                                        }
                                                }
                                                #endregion
                                                Struct.ItemInfo NewItem = new Struct.ItemInfo();
                                                NewItem.Bless = Bless;
                                                NewItem.Dura = Item.MaxDura;
                                                NewItem.Enchant = Enchant;
                                                NewItem.ItemID = NewItemID;
                                                NewItem.MaxDura = Item.MaxDura;
                                                NewItem.Plus = Plus;
                                                NewItem.Position = 0;
                                                NewItem.Soc1 = Soc1;
                                                NewItem.Soc2 = Soc2;
                                                NewItem.Color = Color;
                                                NewItem.UID = MainGS.Rand.Next(1, 9999999);
                                                bool created = Database.Database.NewItem(NewItem, CSocket);
                                                while (!created)
                                                {
                                                    NewItem.UID = MainGS.Rand.Next(1, 9999999);
                                                    created = Database.Database.NewItem(NewItem, CSocket);
                                                }
                                                CSocket.Client.Inventory.Add(NewItem.UID, NewItem);
                                                CSocket.Send(EudemonPacket.ItemInfo(NewItem.UID, NewItem.ItemID, NewItem.Plus, NewItem.Bless, NewItem.Enchant, NewItem.Soc1, NewItem.Soc2, NewItem.Dura, NewItem.MaxDura, NewItem.Position, NewItem.Color));
                                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Created a(n) " + Item.Name + " Plus: " + Plus + ", Bless: " + Bless + ", Enchant: " + Enchant + ", Version: " + version, Struct.ChatType.System));
                                                break;
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        case "effect":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    if (Command.Length == 2)
                                    {
                                        EudemonPacket.ToLocal(EudemonPacket.Effect(CSocket.Client.ID, Command[1]), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
                                    }
                                }
                                break;
                            }
                        case "modify":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    if (Command.Length > 2)
                                    {
                                        switch (Command[1].ToLower())
                                        {
                                            case "name":
                                                {
                                                    //TODO:Modify name and other's name's.
                                                    break;
                                                }
                                            case "level":
                                                {
                                                    if (Command.Length == 3)
                                                    {
                                                        int NewLevel = Convert.ToInt32(Command[2]);
                                                        if (NewLevel <= 135)
                                                        {
                                                            CSocket.Client.Level = NewLevel;
                                                            CSocket.Client.Exp = 0;
                                                            CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.Level, Struct.StatusTypes.Level));
                                                            EudemonPacket.ToLocal(EudemonPacket.Effect(CSocket.Client.ID, "LevelUp"), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
                                                            if (CSocket.Client.Level == 135)
                                                                EudemonPacket.ToServer(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", "CONGRATULATIONS! " + CSocket.Client.Name + " has just achieved level 135! Great job!", Struct.ChatType.NewBroadcast), 0);

                                                        }
                                                    }
                                                    break;
                                                }
                                            case "dex":
                                                {
                                                    if (Command.Length == 3)
                                                    {
                                                        int Dex = Convert.ToInt32(Command[2]);
                                                        CSocket.Client.Dexterity = Dex;
                                                        CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.Dexterity, Struct.StatusTypes.DexterityStatPoints));
                                                        Calculation.Vitals(CSocket, false);
                                                    }
                                                    break;
                                                }
                                            case "vit":
                                                {
                                                    if (Command.Length == 3)
                                                    {
                                                        int Vit = Convert.ToInt32(Command[2]);
                                                        CSocket.Client.Vitality = Vit;
                                                        CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.Vitality, Struct.StatusTypes.VitalityStatPoints));
                                                        Calculation.Vitals(CSocket, false);
                                                    }
                                                    break;
                                                }
                                        }
                                    }
                                }
                                break;
                            }
                        case "skill":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    if (Command.Length == 3)
                                    {
                                        int ID = Convert.ToInt32(Command[1]);
                                        int Level = Convert.ToInt32(Command[2]);
                                        if (CSocket.Client.Skills.ContainsKey(ID))
                                        {
                                            Struct.CharSkill Skill = CSocket.Client.Skills[ID];
                                            Skill.Level = Level;
                                            Skill.Exp = 0;
                                            Database.Database.SetSkill(Skill.ID, Skill.Level, Skill.Exp, CSocket.Client.ID, true);
                                        }
                                        else
                                        {
                                            Struct.CharSkill Skill = new Struct.CharSkill();
                                            Skill.Level = Level;
                                            Skill.ID = ID;
                                            CSocket.Client.Skills.Add(Skill.ID, Skill);
                                            Database.Database.SetSkill(ID, Level, 0, CSocket.Client.ID, false);
                                        }
                                        CSocket.Send(EudemonPacket.Skill(ID, Level, 0));
                                    }
                                    else
                                    {
                                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] /skill ID Level.", Struct.ChatType.Talk));
                                    }

                                }
                                break;
                            }
                        case "status":
                            {
                                if (CSocket.Client.isPM || CSocket.Client.isGM)
                                {
                                    CSocket.Send(EudemonPacket.Chat(0, "", "", "", Struct.ChatType.ClearTopRight));
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Players online: " + MainGS.ClientPool.Count, Struct.ChatType.TopRight));
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Monsters spawned: " + MainGS.Monsters.Count, Struct.ChatType.TopRight));
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Exp/Prof/Skill Rates: " + MainGS.EXP_MULTIPLER + "/" + MainGS.PROF_MULTIPLER + "/" + MainGS.SKILL_MULTIPLER, Struct.ChatType.TopRight));
                                }
                                break;
                            }
                        /*case "tnpc":
                            {
                                if(CSocket.Client.isPM)
                                {
                                    if(Command.Length == 4)
                                    {
                                        int ID = Convert.ToInt32(Command[1]);
                                        int TType = Convert.ToInt32(Command[2]);
                                        int Flag = Convert.ToInt32(Command[3]);
                                        CSocket.Send(EudemonPacket.TerrainNPC(ID, 100, 100, CSocket.Client.X, CSocket.Client.Y, TType, Flag));
                                    }
                                }
                                break;
                            }*/
                        /*case "killallmobs":
                            {
                                if(CSocket.Client.isPM)
                                {
                                    Dictionary<int, Monster> Mobs = new Dictionary<int, Monster>();
                                    foreach(KeyValuePair<int, Monster> Mon in MainGS.Monsters)
                                    {
                                        Mobs.Add(Mon.Key, Mon.Value);
                                    }
                                    MainGS.Monsters.Clear();
                                    foreach(KeyValuePair<int, Monster> Mon in Mobs)
                                    {
                                        Handler.doMonster(Mon.Value, Mon.Value.CurrentHP, 2, CSocket);
                                    }
                                }
                                break;
                            }*/
                        case "gmove":
                            {
                                if (Command.Length == 4)
                                {
                                    Handler.Teleport(Convert.ToInt32(Command[1]), Convert.ToUInt16(Command[2]), Convert.ToUInt16(Command[3]), 0, CSocket);
                                }
                                break;
                            }
                    }
                }
            #endregion
                #region Chats
                else
                {
                    switch (Type)
                    {
                        case Struct.ChatType.Talk:
                            {
                                EudemonPacket.ToLocal(EudemonPacket.Chat(0, CSocket.Client.Name, To, Message, Type), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                break;
                            }
                        case Struct.ChatType.Team:
                            {
                                if (CSocket.Client.Team != null)
                                {
                                    if (MainGS.ClientPool.ContainsKey(CSocket.Client.Team.LeaderID))
                                    {
                                        ClientSocket Leader = MainGS.ClientPool[CSocket.Client.Team.LeaderID];
                                        foreach (KeyValuePair<int, ClientSocket> Member in Leader.Client.Team.Members)
                                        {
                                            if (Member.Value.Client.ID != CSocket.Client.ID)
                                                Member.Value.Send(EudemonPacket.Chat(0, CSocket.Client.Name, To, Message, Type));
                                        }
                                    }
                                }
                                break;
                            }
                        case Struct.ChatType.Ghost:
                            {
                                EudemonPacket.ToLocal(EudemonPacket.Chat(0, CSocket.Client.Name, To, Message, Type), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, CSocket.Client.ID);
                                break;
                            }
                        case Struct.ChatType.Whisper:
                            {
                                bool online = false;
                                //lock(MainGS.ClientPool)
                                //{
                                try
                                {
                                    Monitor.Enter(MainGS.ClientPool);
                                    foreach (KeyValuePair<int, ClientSocket> Player in MainGS.ClientPool)
                                    {
                                        if (Player.Value.Client.Name == To)
                                        {
                                            Player.Value.Send(EudemonPacket.Chat(0, CSocket.Client.Name, To, Message, Type));
                                            online = true;
                                            break;
                                        }
                                    }
                                    //}
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.ToString());
                                }
                                finally
                                {
                                    Monitor.Exit(MainGS.ClientPool);
                                }
                                //}
                                if (!online)
                                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", "ALLUSERS", "[ERROR] Player not found.", Struct.ChatType.Talk));
                                break;
                            }
                        case Struct.ChatType.Friend:
                            {
                                EudemonPacket.ToServer(EudemonPacket.Chat(0, From, To, Message, Struct.ChatType.Friend), CSocket.Client.ID);
                                break;
                            }
                        default:
                            {
                                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Chat type not coded.", Struct.ChatType.Talk));
                                break;
                            }
                    }
                }
                #endregion
            }
            catch (Exception Except)
            {
                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Exception thrown during command parsing/message handling.", Struct.ChatType.System));
                Console.WriteLine(Except.ToString());
            }
        }
Exemple #22
0
 public static void Money(int value, ClientSocket CSocket)
 {
     CSocket.Client.Money += value;
     CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.Money, Struct.StatusTypes.InvMoney));
 }
Exemple #23
0
 public static void All(ClientSocket CSocket)
 {
     try
     {
         Monitor.Enter(MainGS.ClientPool);
         foreach (KeyValuePair<int, ClientSocket> Locals in MainGS.ClientPool)
         {
             ClientSocket C = Locals.Value;
             if ((int)C.Client.Map == (int)CSocket.Client.Map && CSocket.Client.ID != C.Client.ID)
             {
                 if (!Calculation.CanSee(CSocket.Client.PrevX, CSocket.Client.PrevY, C.Client.X, C.Client.Y))
                 {
                     if (!Calculation.CanSee(CSocket.Client.X, CSocket.Client.Y, C.Client.X, C.Client.Y))
                         CSocket.Send(EudemonPacket.SpawnCharacter(C));
                 }
                 //@TODO: Send guild string packet
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     finally
     {
         Monitor.Exit(MainGS.ClientPool);
     }
     try
     {
         Monitor.Enter(MainGS.Monsters);
         foreach (KeyValuePair<int, Monster> Monsters in MainGS.Monsters)
         {
             Monster Mob = Monsters.Value;
             if ((int)CSocket.Client.Map == Mob.Map)
             {
                 if (!Calculation.CanSee(CSocket.Client.PrevX, CSocket.Client.PrevY, Mob.X, Mob.Y))
                 {
                     if (Calculation.CanSee(CSocket.Client.X, CSocket.Client.Y, Mob.X, Mob.Y))
                     {
                         CSocket.Send(EudemonPacket.SpawnMonster(Mob.UID, Mob.Info.Mesh, Mob.X, Mob.Y, Mob.Info.Name, Mob.CurrentHP, Mob.Level, Mob.Direction));
                         Mob.TriggerMove();
                         //CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[Info] Spawning Monster " + Mob.UID + " X: " + Mob.X + " Y:" + Mob.Y, Struct.ChatType.Talk)); //Debug Code
                     }
                 }
                 if (Calculation.InRange(CSocket.Client.X, CSocket.Client.Y, Mob.X, Mob.Y, Mob.Info.AggroRange))
                     Mob.TriggerMove();
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     finally
     {
         Monitor.Exit(MainGS.Monsters);
     }
     foreach (KeyValuePair<int, Struct.NPC> Npcs in MainGS.Npcs)
     {
         Struct.NPC Npc = Npcs.Value;
         if ((int)CSocket.Client.Map == Npc.Map)
         {
             if(!(Calculation.GetDistance(CSocket.Client.PrevX,CSocket.Client.PrevY,Npc.X,Npc.Y) <= 15))
             {
                 if (Calculation.CanSee(CSocket.Client.X, CSocket.Client.Y, Npc.X, Npc.Y))
                 {
                     CSocket.Send(EudemonPacket.SpawnNPC(Npc.ID, Npc.X, Npc.Y, Npc.SubType, Npc.Direction, Npc.Flag));
                 }
             }
         }
     }
     try
     {
         Monitor.Enter(MainGS.ItemFloor);
         foreach (KeyValuePair<int, Struct.ItemGround> Ig in MainGS.ItemFloor)
         {
             Struct.ItemGround IG = Ig.Value;
             if ((int)CSocket.Client.Map == IG.Map)
             {
                 if (!Calculation.CanSee(CSocket.Client.PrevX, CSocket.Client.PrevY, IG.X, IG.Y))
                 {
                     if (Calculation.CanSee(CSocket.Client.X, CSocket.Client.Y, IG.X, IG.Y))
                     {
                         CSocket.Send(EudemonPacket.DropItem(IG.UID, IG.ItemID, IG.X, IG.Y));
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     finally
     {
         Monitor.Exit(MainGS.ItemFloor);
     }
     foreach (KeyValuePair<int, Struct.TerrainNPC> Tnpcs in MainGS.TerrainNpcs)
     {
         Struct.TerrainNPC TNpc = Tnpcs.Value;
         if (TNpc.Map == (int)CSocket.Client.Map)
         {
             if (!Calculation.CanSee(CSocket.Client.PrevX, CSocket.Client.PrevY, TNpc.X, TNpc.Y))
             {
                 if (Calculation.CanSee(CSocket.Client.X, CSocket.Client.Y, TNpc.X, TNpc.Y))
                 {
                     if (TNpc.Map == 1038)
                     {
                         if (TNpc.UID == 6700)
                         {
                             CSocket.Send(EudemonPacket.TerrainNPC(TNpc.UID, TNpc.MaximumHP, TNpc.CurrentHP, TNpc.X, TNpc.Y, TNpc.Type, MainGS.PoleHolder, TNpc.Flag));
                         }
                         else
                         {
                             CSocket.Send(EudemonPacket.TerrainNPC(TNpc.UID, TNpc.MaximumHP, TNpc.CurrentHP, TNpc.X, TNpc.Y, TNpc.Type, "Gate", TNpc.Flag));
                         }
                     }
                     else
                     {
                         CSocket.Send(EudemonPacket.TerrainNPC(TNpc));
                     }
                 }
             }
         }
     }
 }
Exemple #24
0
        public static void NpcTalk(ClientSocket CSocket, int ID, int LinkBack)
        {
            if (ID > 0)
                CSocket.Client.LastNPC = ID;
            switch (ID)
            {
                case 12040:
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello! The Composer of market.", CSocket);
                            Text("What would you like to do?", CSocket);
                            Link("Main Composing", 1, CSocket);
                            Link("Nevermind!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            CSocket.Send(EudemonPacket.GeneralOld(0, CSocket.Client.ID, 319, 445, 4, 37, Struct.DataType.Dialog));
                        }
                        break;
                    }
                case 1504://high Bonus person
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello! How can I help?.", CSocket);
                            Link("[Add a high Bonus to Gear]", 1, CSocket);
                            Link("[Nevermind]", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            CSocket.Send(EudemonPacket.GeneralOld(0, CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y, 1, (int)Struct.Dialog.ItemHighBonus, Struct.DataType.Dialog));
                        }

                        break;
                    }
                case 741://Low Bonus person
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello! How can I help?.", CSocket);
                            Link("[Add Bonus to Gear]", 1, CSocket);
                            Link("[Nevermind]", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            CSocket.Send(EudemonPacket.GeneralOld(0, CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y, 1, (int)Struct.Dialog.ItemBonus, Struct.DataType.Dialog));
                        }

                        break;
                    }
                case 10012://PC - WHS
                    {
                        CSocket.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
                        break;
                    }
                case 10011://DC - WHS
                    {
                        CSocket.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
                        break;
                    }
                case 10028://AM - WHS
                    {
                        CSocket.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
                        break;
                    }
                case 10027://BI - WHS
                    {
                        CSocket.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
                        break;
                    }
                case 44://MA - WHS
                    {
                        CSocket.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
                        break;
                    }
                case 10050: //TC - Conductress
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello! I am Twin City's Conductress. I can teleport you to a variety of places, for free!", CSocket);
                            Text("What kind of person charges money for teleportaion?", CSocket);
                            Link("Ape City", 1, CSocket);
                            Link("Bird Island", 2, CSocket);
                            Link("Phoenix Castle", 3, CSocket);
                            Link("Desert City", 4, CSocket);
                            Link("Market", 5, CSocket);
                            Link("Nevermind!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1) //Ape City
                        {
                            Teleport(1002, 555, 958, 0, CSocket);
                        }
                        else if (LinkBack == 2) //Bird Island
                        {
                            Teleport(1002, 229, 197, 0, CSocket);
                        }
                        else if (LinkBack == 3)//Phoenix Castle
                        {
                            Teleport(1002, 956, 555, 0, CSocket);
                        }
                        else if (LinkBack == 4)//Desert City
                        {
                            Teleport(1002, 67, 463, 0, CSocket);
                        }
                        else if (LinkBack == 5)//Market
                        {
                            Teleport(1036, 211, 196, 0, CSocket);
                        }
                        break;
                    }
                case 390:   //Market - LoveStone
                    {
                        if (LinkBack == 0)
                        {
                            // Text("Do you wish to propose to your sweetheart?")); Needs to be
                            Text("Do you wish to propose to your sweetheart?", CSocket); //Remove one ) and add, CSocket
                            //Text("Remember that marriage is a serious commitment, do not enter into it lightly.")); Needs to be
                            Text("Remember that marriage is a serious commitment, do not enter into it lightly.", CSocket);// Remove one ) and add CSocket
                            Link("Yes I want to propose", 1, CSocket);
                            Link("No, I am not ready yet", 255, CSocket);//Add 255
                            End(CSocket);
                        }//<-- was a {, needs to be }
                        else if (LinkBack == 1)
                        {

                        }
                        break;
                    }
                case 1152: // Simon the lab teleporter
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello My name is Simon, And I can help you train after you reach Level 70.\n Although I am willing to help you out I have one requirement:\n you pay me 100,000 gold for my services.", CSocket);
                            Link("I am prepared to pay you for your\n wonderful service!", 1, CSocket);
                            Link("I'm sorry I can't agree with your\n demand, But Thank you anyway", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            //Teleport(lab, 000, 000, 0, CSocket); //Don't Know Lab map id
                            if (CSocket.Client.Level >= 70)
                            {
                                if (CSocket.Client.Money >= 100000)
                                {
                                    Money(-100000, CSocket);
                                    Teleport(1351, 20, 130, 0, CSocket);
                                }
                                else
                                {
                                    Text("Dare you try to rip me off?! Be gone, fool!", CSocket);
                                    Link("Sorry sir.", 255, CSocket);
                                    End(CSocket);
                                }
                            }
                            else
                            {
                                Text("You are not yet level 70. Train harder.", CSocket);
                                Link("Oh, sorry. Thanks!", 255, CSocket);
                                End(CSocket);
                            }
                        }
                        break;
                    }
                case 104839: // BoxerLi PC- TG teleporter
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello I can help you train after you reach level 20,\n But I will charge you 1,000 gold.\n Would you like to go to the Training Grounds?", CSocket);
                            Link("Yes Please, Here is the money", 1, CSocket);
                            Link("No Thank you I cannot afford it.", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            if (CSocket.Client.Money >= 1000)
                            {
                                Teleport(1039, 219, 215, 0, CSocket);
                                Money(-1000, CSocket);
                            }
                            else
                            {
                                Text("How dare you try to rip me off! Get lost, Or get my money!", CSocket);
                                Link("I'm sorry, I didn't realize.", 255, CSocket);
                                End(CSocket);
                            }
                        }
                        break;
                    }
                case 45: // Mark. Controller
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello I can teleport You outside of the market for free! Do you want to leave?", CSocket);
                            Link("Why would you be so kind to do so?", 1, CSocket);
                            Link("No, Thank you anyway.", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            Teleport(1002, 439, 390, 0, CSocket);
                        }
                        break;
                    }
                case 104827:// Guild Map-GC 1
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello I can teleport you to The Advanced Zone, \nnFor a tiny fee of 500 gold!", CSocket);
                            Link("Sure here ya are.", 1, CSocket);
                            Link("No Thanks!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            if (CSocket.Client.Money >= 500)
                            {
                                Teleport(1017, 518, 557, 0, CSocket);
                                Money(-500, CSocket);
                            }
                            else
                            {
                                Text("I'm sorry you do not have the required Gold.", CSocket);
                                Link("Okay, I will be back when I have 500 Gold.", 255, CSocket);
                                End(CSocket);
                            }
                        }
                        break;
                    }
                case 104821:// Guild Map-GC 2
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello I can teleport you to Mystic Castle, \nFor a tiny fee of 500 gold!", CSocket);
                            Link("Sure here ya are.", 1, CSocket);
                            Link("No Thanks!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            if (CSocket.Client.Money >= 500)
                            {
                                Teleport(1001, 272, 181, 0, CSocket);
                                Money(-500, CSocket);
                            }
                            else
                            {
                                Text("I'm sorry you do not have the required Gold.", CSocket);
                                Link("Okay, I will be back when i have 500 Gold.", 255, CSocket);
                                End(CSocket);
                            }
                        }
                        break;
                    }
                case 104815:// Guild Map-GC 3
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello I can teleport you to Ape Mountain, \nFor a tiny fee of 500 gold!", CSocket);
                            Link("Sure here ya are.", 1, CSocket);
                            Link("No Thanks!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            if (CSocket.Client.Money >= 500)
                            {
                                Teleport(1020, 539, 534, 0, CSocket);
                                Money(-500, CSocket);
                            }
                            else
                            {
                                Text("I'm sorry you do not have the required Gold.", CSocket);
                                Link("Okay, I will be back when i have 500 Gold.", 255, CSocket);
                                End(CSocket);
                            }
                        }
                        break;
                    }
                case 104809:// Guild Map-GC 4
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello I can teleport you to Bird Island, \nFor a tiny fee of 500 gold!", CSocket);
                            Link("Sure here ya are.", 1, CSocket);
                            Link("No Thanks!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            if (CSocket.Client.Money >= 500)
                            {
                                Teleport(1015, 705, 564, 0, CSocket);
                                Money(-500, CSocket);
                            }
                            else
                            {
                                Text("I'm sorry you do not have the required Gold.", CSocket);
                                Link("Okay, I will be back when i have 500 Gold.", 255, CSocket);
                                End(CSocket);
                            }
                        }
                        break;
                    }
                case 10056: //BI - Conductress
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello! I am Bird Islands' Conductress. I can teleport you to Twin City, or the market for free!", CSocket);
                            Text("What kind of person charges money for teleportation?", CSocket);
                            Link("Twin City", 1, CSocket);
                            Link("Market", 2, CSocket);
                            Link("Nevermind!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1) //Twin City
                        {
                            Teleport(1015, 1010, 710, 0, CSocket);
                        }
                        else if (LinkBack == 2)//Market
                        {
                            Teleport(1036, 211, 196, 0, CSocket);
                        }
                        break;
                    }
                case 10051: //DC - Conductress
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello! I am Desert Citys' Conductress. I can teleport you to Twin City, or the market for free!", CSocket);
                            Text("What kind of person charges money for teleportation?", CSocket);
                            Link("Twin City", 1, CSocket);
                            Link("Market", 2, CSocket);
                            Link("Mystic Castle", 3, CSocket);
                            Link("Nevermind!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1) //Twin City
                        {
                            Teleport(1000, 970, 666, 0, CSocket);
                        }
                        else if (LinkBack == 2)//Market
                        {
                            Teleport(1036, 211, 196, 0, CSocket);
                        }
                        else if (LinkBack == 3)//Mystic Castle
                        {
                            Teleport(1000, 80, 320, 0, CSocket);
                        }
                        break;
                    }
                case 10052: //PC - Conductress
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello! I am Phoenix Castles' Conductress. I can teleport you to Twin City, or the market for free!", CSocket);
                            Text("What kind of person charges money for teleportaion?", CSocket);
                            Link("Twin City", 1, CSocket);
                            Link("Market", 2, CSocket);
                            Link("Nevermind!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1) //Twin City
                        {
                            Teleport(1011, 11, 376, 0, CSocket);
                        }
                        else if (LinkBack == 2)//Market
                        {
                            Teleport(1036, 211, 196, 0, CSocket);
                        }
                        break;
                    }
                case 10053: //AC - Conductress
                    {
                        if (LinkBack == 0)
                        {
                            Text("Hello! I am Ape Citys' Conductress. I can teleport you to Twin City, or the market for free!", CSocket);
                            Text("What kind of person charges money for teleportaion?", CSocket);
                            Link("Twin City", 1, CSocket);
                            Link("Market", 2, CSocket);
                            Link("Nevermind!", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1) //Twin City
                        {
                            Teleport(1020, 381, 20, 0, CSocket);
                        }
                        else if (LinkBack == 2)//Market
                        {
                            Teleport(1036, 211, 196, 0, CSocket);
                        }
                        break;
                    }
                case 10021: // ArenaGuard
                    {
                        if (LinkBack == 0)
                        {
                            Text("The arena is open, you are welcome to challenge others.\n The admission fee is 1000 silver.", CSocket);
                            Link("Enter the arena.", 1, CSocket);
                            Link("Just passing by.", 255, CSocket);
                            End(CSocket);
                        }
                        else if (LinkBack == 1)
                        {
                            if (CSocket.Client.Money >= 1000)
                            {
                                Teleport(1005, 051, 068, 0, CSocket);
                                Money(-1000, CSocket);
                            }
                        }
                        break;
                    }
                case 30084: // GeneralQing
                    {
                        if (LinkBack == 0)
                        {
                            Text("I have sent my soldiers out to fetch the monthly provisions with my army token, but I have received no news since they left.", CSocket);
                            Link("They must have troubles", 255, CSocket);
                            Link("All will be fine", 255, CSocket);
                            End(CSocket);
                        }
                        break;
                    }
                default:
                    {
                        Text("NPC " + ID + "'s dialog is not coded.", CSocket);
                        Link("Aw! That's too bad!", 255, CSocket);
                        End(CSocket);
                        break;
                    }
            }
        }
Exemple #25
0
        public static void Walk(int ucModeDir, ClientSocket CSocket)
        {
            short newXPos = 0;
            short newYPos = 0;

            int Direction = ((ucModeDir >> 0) & 0xff) % 8;
            MovementModes MMode = (MovementModes)((ucModeDir >> 8) & 0xff);

            if(Direction > MAX_DIRSIZE)
                {
                    //Unknown Walking direction.
                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Unknown walking direction.", Struct.ChatType.Talk));
                    CSocket.Disconnect();
                    return;
                }
            newXPos = (short) (CSocket.Client.X + _DELTA_X[Direction]);
            newYPos = (short) (CSocket.Client.Y + _DELTA_Y[Direction]);

            if (MainGS.Maps.ContainsKey((int)CSocket.Client.Map))
            {
                Struct.DmapData Map = MainGS.Maps[(int)CSocket.Client.Map];
                if (!Map.CheckLoc(newXPos, newYPos))
                {
                    CSocket.Send(EudemonPacket.General(CSocket.Client.ID, CSocket.Client.PrevX, CSocket.Client.PrevY, CSocket.Client.Direction, Struct.DataType.actionKickBack, CSocket.Client.PrevX, CSocket.Client.PrevY));
                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Invalid coordinates.", Struct.ChatType.System));
                    return;
                }
            }

            if (MMode >= MovementModes.RUN_DIR0 && MMode <= MovementModes.RUN_DIR7)
            {
                newXPos += _DELTA_X[MMode - MovementModes.RUN_DIR0];
                newYPos += _DELTA_Y[MMode - MovementModes.RUN_DIR0];

                if (MainGS.Maps.ContainsKey((int)CSocket.Client.Map))
                {
                    Struct.DmapData Map = MainGS.Maps[(int)CSocket.Client.Map];
                    if (!Map.CheckLoc(newXPos, newYPos))
                    {
                       CSocket.Send(EudemonPacket.General(CSocket.Client.ID, CSocket.Client.PrevX, CSocket.Client.PrevY, CSocket.Client.Direction, Struct.DataType.actionKickBack, CSocket.Client.PrevX, CSocket.Client.PrevY));
                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Invalid coordinates.", Struct.ChatType.System));
                        return;
                    }
                }
            }

            if (newXPos < 0 || newYPos < 0)
            {
                CSocket.Send(EudemonPacket.General(CSocket.Client.ID, CSocket.Client.PrevX, CSocket.Client.PrevY, CSocket.Client.Direction, Struct.DataType.actionKickBack, CSocket.Client.PrevX, CSocket.Client.PrevY));
                CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Negetive coordinates.", Struct.ChatType.System));
                return;
            }
            //Only set Previous values If dmap check has passed.
            CSocket.Client.PrevX = CSocket.Client.X;
            CSocket.Client.PrevY = CSocket.Client.Y;

            CSocket.Client.X = Convert.ToUInt16(newXPos);
            CSocket.Client.Y = Convert.ToUInt16(newYPos);

            //TODO: Map / Guild wall / other checks
            byte[] WalkPacket = EudemonPacket.WalkRun(ucModeDir, CSocket.Client.ID, CSocket.Client.X, CSocket.Client.Y);
            try
            {
                Monitor.Enter(MainGS.ClientPool);
                foreach (KeyValuePair<int, ClientSocket> Tests in MainGS.ClientPool)
                {
                    ClientSocket C = Tests.Value;
                    if ((int)C.Client.Map == (int)CSocket.Client.Map && C.Client.ID != CSocket.Client.ID)
                    {
                         if (!Calculation.CanSee(CSocket.Client.PrevX, CSocket.Client.PrevY, C.Client.X, C.Client.Y))
                        {
                            if (Calculation.CanSee(CSocket.Client.X, CSocket.Client.Y, C.Client.X, C.Client.Y))
                            {
                                C.Send(EudemonPacket.SpawnCharacter(CSocket));
                            }
                        }
                        else
                        {
                            if (Calculation.CanSee(CSocket.Client.X, CSocket.Client.Y, C.Client.X, C.Client.Y))
                            {
                                C.Send(WalkPacket);
                            }
                            else
                                C.Send(EudemonPacket.GeneralOld(CSocket.Client.ID, CSocket.Client.PrevX, CSocket.Client.PrevY, 0, 0, 0, Struct.DataType.EntityRemove));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                Monitor.Exit(MainGS.ClientPool);
            }
            Spawn.All(CSocket);
        }
Exemple #26
0
        public static void Attack(int Target, int MagicID, int AType, int X, int Y, ClientSocket CSocket)
        {
            #region Checks
            Struct.CharSkill AttackSkill = null;
            if (MagicID != 0)
            {
                if (!CSocket.Client.Skills.ContainsKey(MagicID))
                {
                    CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] You do not have the skill.", Struct.ChatType.System));
                    return;
                }
                else
                {
                    AttackSkill = CSocket.Client.Skills[MagicID];
                }
            }
            if (CSocket.Client.Dead)
            {
                if (CSocket.Client.Attack != null)
                {
                    CSocket.Client.Attack.Stop();
                    CSocket.Client.Attack.Dispose();
                }
                return;
            }
            #endregion
            Character Attacker = CSocket.Client;
            Character AttackedChar = null;
            ClientSocket ASocket = null;
            Monster AttackedMob = null;
            Struct.TerrainNPC AttackedTNpc = null;
            if (CSocket.Client.Equipment.ContainsKey(4))
            {
                if (CSocket.Client.Equipment[4].ItemID != 1050002 && CSocket.Client.Equipment[4].ItemID != 1050001 & CSocket.Client.Equipment[4].ItemID != 1050000)
                {
                    int ID = Calculation.WeaponType(Convert.ToString(CSocket.Client.Equipment[4].ItemID));
                }
            }
            if (CSocket.Client.Equipment.ContainsKey(5))
            {
                if (CSocket.Client.Equipment[5].ItemID != 1050002 && CSocket.Client.Equipment[5].ItemID != 1050001 & CSocket.Client.Equipment[5].ItemID != 1050000)
                {
                    int ID = Calculation.WeaponType(Convert.ToString(CSocket.Client.Equipment[5].ItemID));
                }
            }
            if (MainGS.ClientPool.ContainsKey(Target))
            {
                ASocket = MainGS.ClientPool[Target];
                AttackedChar = MainGS.ClientPool[Target].Client;
            }
            else if (MainGS.Monsters.ContainsKey(Target))
                AttackedMob = MainGS.Monsters[Target];
            else if (MainGS.TerrainNpcs.ContainsKey(Target))
                AttackedTNpc = MainGS.TerrainNpcs[Target];
            else if (Target > 0)
            {
                //CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Target not found.", Struct.ChatType.Top));
                return;
            }
            CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Target: " + ASocket.Client.Name + "Max HP: " + ASocket.Client.MaxHP.ToString() + "Current HP: " + ASocket.Client.CurrentHP , Struct.ChatType.System));

            if (AttackedChar != null)
            {
                if (!CheckMode(CSocket, ASocket))
                {
                    if (CSocket.Client.Attack != null)
                    {
                        CSocket.Client.Attack.Stop();
                        CSocket.Client.Attack.Dispose();
                    }
                    return;
                }
            }
            int Damage = 0;
            #region Melee
            if (AType == 2)
            {
                if (AttackedChar != null && !AttackedChar.Dead)
                {
                    if (!Calculation.InRange(AttackedChar.X, AttackedChar.Y, CSocket.Client.X, CSocket.Client.Y, 2))
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack.Stop();
                                CSocket.Client.Attack.Dispose();
                            }
                        }
                        return;
                    }
                    Damage = Calculation.Damage(Attacker, AttackedChar, AType, 0, 0);
                    Damage = 5;
                    bool killed = Calculation.doPlayer(CSocket, ASocket, Damage, AType);
                    if (!killed)
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (!CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack = new System.Timers.Timer();
                                CSocket.Client.Attack.Interval = 900;
                                CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                                CSocket.Client.Attack.Start();
                            }
                        }
                        else
                        {
                            CSocket.Client.Attack = new System.Timers.Timer();
                            CSocket.Client.Attack.Interval = 900;
                            CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                            CSocket.Client.Attack.Start();
                        }
                    }
                }
                else if (AttackedMob != null)
                {
                    if (!Calculation.InRange(AttackedMob.X, AttackedMob.Y, CSocket.Client.X, CSocket.Client.Y, 2))
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack.Stop();
                                CSocket.Client.Attack.Dispose();
                            }
                        }
                        return;
                    }
                    int RemainingHP = AttackedMob.CurrentHP;
                    Damage = Calculation.Damage(Attacker, AttackedMob, AType, 0, 0);
                    bool killed = Calculation.doMonster(AttackedMob, Damage, AType, CSocket);
                    if (!killed)
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (!CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack = new System.Timers.Timer();
                                CSocket.Client.Attack.Interval = 900;
                                CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                                CSocket.Client.Attack.Start();
                            }
                        }
                        else
                        {
                            CSocket.Client.Attack = new System.Timers.Timer();
                            CSocket.Client.Attack.Interval = 900;
                            CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                            CSocket.Client.Attack.Start();
                        }
                    }
                    else
                    {

                    }
                }
                else if (AttackedTNpc != null)
                {
                    if (!Calculation.InRange(AttackedTNpc.X, AttackedTNpc.Y, CSocket.Client.X, CSocket.Client.Y, 16))
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack.Stop();
                                CSocket.Client.Attack.Dispose();
                            }
                        }
                        return;
                    }
                    if (CSocket.Client.MinAttack < CSocket.Client.MaxAttack)
                        Damage = MainGS.Rand.Next(CSocket.Client.MinAttack, CSocket.Client.MaxAttack);
                    Calculation.doTNpc(CSocket, AttackedTNpc, Damage, AType);

                    if (CSocket.Client.Attack != null)
                    {
                        if (!CSocket.Client.Attack.Enabled)
                        {
                            CSocket.Client.Attack = new System.Timers.Timer();
                            CSocket.Client.Attack.Interval = 900;
                            CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                            CSocket.Client.Attack.Start();
                        }
                    }
                    else
                    {
                        CSocket.Client.Attack = new System.Timers.Timer();
                        CSocket.Client.Attack.Interval = 900;
                        CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                        CSocket.Client.Attack.Start();
                    }
                }
            }
            #endregion
            #region Magic
            else if (AType == 21)
            {
                if (Target == 0 && MagicID != 0)
                {
                    //Non-targeting magical attack(scatter, fb, etc)
                    NoTargetMagic(CSocket, MagicID, X, Y);
                }
                else if (Target > 0 && MagicID != 0 && AttackedChar != null)
                {
                    if (AttackSkill != null)
                    {
                        bool OK = Calculation.MagicCost(AttackSkill.ID, AttackSkill.Level, CSocket);
                        if (!OK)
                        {
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }
                            return;
                        }
                        switch (AttackSkill.ID)
                        {
                            default:
                                {
                                    Dictionary<int, int> Targets = new Dictionary<int, int>();
                                    Damage = Calculation.Damage(CSocket.Client, AttackedChar, AType, AttackSkill.ID, AttackSkill.Level);
                                    Calculation.doPlayer(CSocket, ASocket, Damage, AType);
                                    Targets.Add(AttackedChar.ID, Damage);
                                    EudemonPacket.ToLocal(EudemonPacket.MagicAttack(CSocket.Client.ID, AttackSkill.ID, AttackSkill.Level, Targets, AttackedChar.X, AttackedChar.Y), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
                                    Targets.Clear();
                                    break;
                                }
                        }
                    }
                }
                else if (Target > 0 && MagicID != 0 && AttackedMob != null)
                {
                    if (AttackSkill != null)
                    {
                        bool OK = Calculation.MagicCost(AttackSkill.ID, AttackSkill.Level, CSocket);
                        if (!OK)
                        {
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }
                            return;
                        }
                        switch (AttackSkill.ID)
                        {
                            //TODO: Special effects for spells like FireOfHell, Revive, etc here
                            default:
                                {
                                    Dictionary<int, int> Targets = new Dictionary<int, int>();
                                    int RemainingHP = AttackedMob.CurrentHP;
                                    Damage = Calculation.Damage(CSocket.Client, AttackedMob, AType, AttackSkill.ID, AttackSkill.Level);
                                    bool killed = Calculation.doMonster(AttackedMob, Damage, AType, CSocket);
                                    Targets.Add(AttackedMob.UID, Damage);
                                    EudemonPacket.ToLocal(EudemonPacket.MagicAttack(CSocket.Client.ID, AttackSkill.ID, AttackSkill.Level, Targets, AttackedMob.X, AttackedMob.Y), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);
                                    Targets.Clear();
                                    if (!killed)
                                    {
                                        if (CSocket.Client.Attack != null)
                                        {
                                            if (!CSocket.Client.Attack.Enabled)
                                            {
                                                CSocket.Client.Attack = new System.Timers.Timer();
                                                CSocket.Client.Attack.Interval = 900;
                                                CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                                                CSocket.Client.Attack.Start();
                                            }
                                        }
                                        else
                                        {
                                            CSocket.Client.Attack = new System.Timers.Timer();
                                            CSocket.Client.Attack.Interval = 900;
                                            CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                                            CSocket.Client.Attack.Start();
                                        }
                                        Calculation.SkillExp(AttackSkill.ID, CSocket, Damage);
                                    }
                                    else
                                    {
                                        Calculation.SkillExp(AttackSkill.ID, CSocket, RemainingHP);
                                    }
                                    break;
                                }
                        }
                    }
                }
                else if (Target > 0 && MagicID != 0 && AttackedTNpc != null)
                {
                    if (AttackSkill != null)
                    {
                        if (!Calculation.InRange(AttackedTNpc.X, AttackedTNpc.Y, CSocket.Client.X, CSocket.Client.Y, 16))
                        {
                            if (CSocket.Client.Attack != null)
                            {
                                if (CSocket.Client.Attack.Enabled)
                                {
                                    CSocket.Client.Attack.Stop();
                                    CSocket.Client.Attack.Dispose();
                                }
                            }
                            return;
                        }
                        Damage = Calculation.AddedMagicDamage(AttackSkill.ID, AttackSkill.Level);
                        Damage += CSocket.Client.MagicAttack + CSocket.Client.BonusMagicAttack;
                        Dictionary<int, int> Targets = new Dictionary<int, int>();
                        Targets.Add(AttackedTNpc.UID, Damage);
                        Calculation.doTNpc(CSocket, AttackedTNpc, Damage, AType);
                        EudemonPacket.ToLocal(EudemonPacket.MagicAttack(CSocket.Client.ID, AttackSkill.ID, AttackSkill.Level, Targets, X, Y), AttackedTNpc.X, AttackedTNpc.Y, AttackedTNpc.Map, 0, 0);
                        Targets.Clear();
                        Calculation.SkillExp(AttackSkill.ID, CSocket, Damage / 10);
                        if (CSocket.Client.Attack != null)
                        {
                            if (!CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack = new System.Timers.Timer();
                                CSocket.Client.Attack.Interval = 900;
                                CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                                CSocket.Client.Attack.Start();
                            }
                        }
                        else
                        {
                            CSocket.Client.Attack = new System.Timers.Timer();
                            CSocket.Client.Attack.Interval = 900;
                            CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                            CSocket.Client.Attack.Start();
                        }
                    }
                }
            }
            #endregion
            #region Bow
            else if (AType == 25)
            {
                if (AttackedChar != null && !AttackedChar.Dead)
                {
                    if (!Calculation.InRange(AttackedChar.X, AttackedChar.Y, CSocket.Client.X, CSocket.Client.Y, 16))
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack.Stop();
                                CSocket.Client.Attack.Dispose();
                            }
                        }
                        return;
                    }
                    Damage = Calculation.Damage(Attacker, AttackedChar, AType, 0, 0);
                    bool killed = Calculation.doPlayer(CSocket, ASocket, Damage, AType);
                    if (!killed)
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (!CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack = new System.Timers.Timer();
                                CSocket.Client.Attack.Interval = 450;
                                CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                                CSocket.Client.Attack.Start();
                            }
                        }
                        else
                        {
                            CSocket.Client.Attack = new System.Timers.Timer();
                            CSocket.Client.Attack.Interval = 450;
                            CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                            CSocket.Client.Attack.Start();
                        }
                    }
                }
                else if (AttackedMob != null)
                {
                    if (!Calculation.InRange(AttackedMob.X, AttackedMob.Y, CSocket.Client.X, CSocket.Client.Y, 16))
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack.Stop();
                                CSocket.Client.Attack.Dispose();
                            }
                        }
                        return;
                    }
                    int RemainingHP = AttackedMob.CurrentHP;
                    Damage = Calculation.Damage(Attacker, AttackedMob, AType, 0, 0);
                    bool killed = Calculation.doMonster(AttackedMob, Damage, AType, CSocket);
                    if (!killed)
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (!CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack = new System.Timers.Timer();
                                CSocket.Client.Attack.Interval = 450;
                                CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                                CSocket.Client.Attack.Start();
                            }
                        }
                        else
                        {
                            CSocket.Client.Attack = new System.Timers.Timer();
                            CSocket.Client.Attack.Interval = 450;
                            CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                            CSocket.Client.Attack.Start();
                        }
                    }
                }
                else if (AttackedTNpc != null)
                {
                    if (!Calculation.InRange(AttackedTNpc.X, AttackedTNpc.Y, CSocket.Client.X, CSocket.Client.Y, 16))
                    {
                        if (CSocket.Client.Attack != null)
                        {
                            if (CSocket.Client.Attack.Enabled)
                            {
                                CSocket.Client.Attack.Stop();
                                CSocket.Client.Attack.Dispose();
                            }
                        }
                        return;
                    }
                    if (CSocket.Client.MinAttack < CSocket.Client.MaxAttack)
                        Damage = MainGS.Rand.Next(CSocket.Client.MinAttack, CSocket.Client.MaxAttack);
                    Calculation.doTNpc(CSocket, AttackedTNpc, Damage, AType);
                    if (CSocket.Client.Attack != null)
                    {
                        if (!CSocket.Client.Attack.Enabled)
                        {
                            CSocket.Client.Attack = new System.Timers.Timer();
                            CSocket.Client.Attack.Interval = 450;
                            CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                            CSocket.Client.Attack.Start();
                        }
                    }
                    else
                    {
                        CSocket.Client.Attack = new System.Timers.Timer();
                        CSocket.Client.Attack.Interval = 450;
                        CSocket.Client.Attack.Elapsed += delegate { Attack(Target, MagicID, AType, X, Y, CSocket); };
                        CSocket.Client.Attack.Start();
                    }
                }
            }
            #endregion
        }
Exemple #27
0
 public static bool doPlayer(Monster Attacker, ClientSocket ASocket, int Damage, int AType)
 {
     Character AttackedChar = ASocket.Client;
     if (Damage < AttackedChar.CurrentHP)
     {
         if (AType != 21)
             EudemonPacket.ToLocal(EudemonPacket.Attack(Attacker.UID, AttackedChar.ID, Attacker.X, Attacker.Y, Damage, AType), Attacker.X, Attacker.Y, (int)Attacker.Map, 0, 0);
         Interlocked.Add(ref AttackedChar.CurrentHP, (Damage * -1));
         ASocket.Send(EudemonPacket.Status(ASocket, 2, AttackedChar.CurrentHP, Struct.StatusTypes.Hp));
         return false;
     }
     else
     {
         if (AType != 21)
             EudemonPacket.ToLocal(EudemonPacket.Attack(Attacker.UID, AttackedChar.ID, Attacker.X, Attacker.Y, Damage, AType), Attacker.X, Attacker.Y, (int)Attacker.Map, 0, 0);
         EudemonPacket.ToLocal(EudemonPacket.Attack(Attacker.UID, AttackedChar.ID, AttackedChar.X, AttackedChar.Y, Damage, 14), Attacker.X, Attacker.Y, (int)Attacker.Map, 0, 0);
         EudemonPacket.ToLocal(EudemonPacket.Status(ASocket, 2, AttackedChar.GhostModel, Struct.StatusTypes.Model), AttackedChar.X, AttackedChar.Y, (int)AttackedChar.Map, 0, 0);
         EudemonPacket.ToLocal(EudemonPacket.Status(ASocket, 2, 1024, Struct.StatusTypes.StatusEffect), AttackedChar.X, AttackedChar.Y, (int)AttackedChar.Map, 0, 0);
         ASocket.Client.Dead = true;
         return true;
     }
 }
Exemple #28
0
 public static void PickupItem(int UID, ClientSocket CSocket)
 {
     CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Pickup: " + UID, Struct.ChatType.Normal));
     foreach (Struct.ItemGround IG in MainGS.ItemFloor.Values)
     {
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Item On Ground: " + IG.UID, Struct.ChatType.Normal));
     }
     if (CSocket.Client.Inventory.Count < 40)
     {
         if (MainGS.ItemFloor.ContainsKey(UID))
         {
             Struct.ItemGround IG = MainGS.ItemFloor[UID];
             if (IG.X == CSocket.Client.X && IG.Y == CSocket.Client.Y && IG.Map == (int)CSocket.Client.Map)
             {
                 if (IG.OwnerOnly.Enabled)
                 {
                     //Only able to give the item to its owner, until the timer expires that is, or to his/her team members.. :D
                     int TeamLeaderID = 0;
                     if (CSocket.Client.Team != null)
                     {
                         ClientSocket Leader = MainGS.ClientPool[CSocket.Client.Team.LeaderID];
                         if (IG.Money > 0)
                         {
                             if (!Leader.Client.Team.ForbidMoney)
                                 TeamLeaderID = CSocket.Client.Team.LeaderID;
                         }
                         else
                         {
                             if (!Leader.Client.Team.ForbidItems)
                                 TeamLeaderID = CSocket.Client.Team.LeaderID;
                         }
                     }
                     if (IG.OwnerID == CSocket.Client.ID || IG.OwnerID == TeamLeaderID)
                     {
                         IG.Stop();
                         if (MainGS.ItemFloor.ContainsKey(UID))
                         {
                             //lock(MainGS.ItemFloor)
                             //{
                             try
                             {
                                 Monitor.Enter(MainGS.ItemFloor);
                                 MainGS.ItemFloor.Remove(UID);
                             }
                             catch (Exception e)
                             {
                                 Console.WriteLine(e.ToString());
                             }
                             finally
                             {
                                 Monitor.Exit(MainGS.ItemFloor);
                             }
                             //}
                         }
                         if (IG.Money > 0)
                         {
                             CSocket.Client.Money += IG.Money;
                             CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.Money, Struct.StatusTypes.InvMoney));
                             CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You picked up " + IG.Money + " silvers!", Struct.ChatType.System));
                             EudemonPacket.ToLocal(EudemonPacket.RemoveItemDrop(UID), IG.X, IG.Y, IG.Map, 0, 0);
                             return;
                         }
                         EudemonPacket.ToLocal(EudemonPacket.RemoveItemDrop(UID), IG.X, IG.Y, IG.Map, 0, 0);
                         Struct.ItemInfo Item = new Struct.ItemInfo();
                         Struct.ItemData iData = MainGS.Items[IG.ItemID];
                         Item.Bless = IG.Bless;
                         Item.Dura = IG.Dura;
                         Item.Enchant = IG.Enchant;
                         Item.ItemID = IG.ItemID;
                         Item.Color = IG.Color;
                         Item.MaxDura = IG.MaxDura;
                         Item.Plus = IG.Plus;
                         Item.Position = (int)Struct.ItemPosition.Invetory;
                         Item.Soc1 = IG.Soc1;
                         Item.Soc2 = IG.Soc2;
                         Item.UID = IG.UID;
                         bool created = Database.Database.NewItem(Item, CSocket);
                         while (!created)
                         {
                             Item.UID = MainGS.Rand.Next(1000, 9999999);
                             created = Database.Database.NewItem(Item, CSocket);
                         }
                         CSocket.Send(EudemonPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You have picked up a(n) " + iData.Name + " off the ground.", Struct.ChatType.System));
                         if (!CSocket.Client.Inventory.ContainsKey(Item.UID))
                             CSocket.Client.Inventory.Add(Item.UID, Item);
                     }
                     else
                     {
                         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] That item is not yet yours to pick up.", Struct.ChatType.System));
                     }
                 }
                 else
                 {
                     IG.Stop();
                     if (MainGS.ItemFloor.ContainsKey(UID))
                     {
                         //lock(MainGS.ItemFloor)
                         //{
                         try
                         {
                             Monitor.Enter(MainGS.ItemFloor);
                             MainGS.ItemFloor.Remove(UID);
                         }
                         catch (Exception e)
                         {
                             Console.WriteLine(e.ToString());
                         }
                         finally
                         {
                             Monitor.Exit(MainGS.ItemFloor);
                         }
                         //}
                     }
                     if (IG.Money > 0)
                     {
                         CSocket.Client.Money += IG.Money;
                         CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.Money, Struct.StatusTypes.InvMoney));
                         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You picked up " + IG.Money + " silvers!", Struct.ChatType.System));
                         EudemonPacket.ToLocal(EudemonPacket.RemoveItemDrop(UID), IG.X, IG.Y, IG.Map, 0, 0);
                         return;
                     }
                     EudemonPacket.ToLocal(EudemonPacket.RemoveItemDrop(UID), IG.X, IG.Y, IG.Map, 0, 0);
                     Struct.ItemInfo Item = new Struct.ItemInfo();
                     Struct.ItemData iData = MainGS.Items[IG.ItemID];
                     Item.Bless = IG.Bless;
                     Item.Dura = IG.Dura;
                     Item.Enchant = IG.Enchant;
                     Item.ItemID = IG.ItemID;
                     Item.MaxDura = IG.MaxDura;
                     Item.Plus = IG.Plus;
                     Item.Position = IG.Position;
                     Item.Color = IG.Color;
                     Item.Soc1 = IG.Soc1;
                     Item.Soc2 = IG.Soc2;
                     Item.UID = IG.UID;
                     bool created = Database.Database.NewItem(Item, CSocket);
                     while (!created)
                     {
                         Item.UID = MainGS.Rand.Next(1000, 9999999);
                         created = Database.Database.NewItem(Item, CSocket);
                     }
                     Database.Database.NewItem(Item, CSocket);
                     CSocket.Send(EudemonPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
                     CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You have picked up a(n) " + iData.Name + " off the ground.", Struct.ChatType.System));
                     if (!CSocket.Client.Inventory.ContainsKey(Item.UID))
                         CSocket.Client.Inventory.Add(Item.UID, Item);
                 }
             }
             else
             {
                 CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item is not in range!", Struct.ChatType.System));
             }
         }
         else
         {
             CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Item does not exist in Nano floor.", Struct.ChatType.System));
         }
     }
     else
     {
         CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Your inventory is full.", Struct.ChatType.System));
     }
 }
Exemple #29
0
        public static void UseItem(Struct.ItemInfo Item, ClientSocket CSocket)
        {
            bool Delete = true;
            switch (Item.ItemID)
            {
                case 1000000://Stancher
                    {
                        int AddHP = 70;
                        if (CSocket.Client.CurrentHP >= CSocket.Client.MaxHP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentHP + AddHP > CSocket.Client.MaxHP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, (CSocket.Client.MaxHP - CSocket.Client.CurrentHP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                            else
                            {
                                //Interlocked.Add(ref CSocket.Client.CurrentHP, AddHP);
                                Interlocked.Add(ref CSocket.Client.CurrentHP, AddHP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                        }
                        break;
                    }
                case 1000010://Stancher
                    {
                        int AddHP = 100;
                        if (CSocket.Client.CurrentHP >= CSocket.Client.MaxHP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentHP + AddHP > CSocket.Client.MaxHP)
                            {

                                Interlocked.Add(ref CSocket.Client.CurrentHP, (CSocket.Client.MaxHP - CSocket.Client.CurrentHP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, AddHP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                        }
                        break;
                    }
                case 1000020://Stancher
                    {
                        int AddHP = 250;
                        if (CSocket.Client.CurrentHP >= CSocket.Client.MaxHP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentHP + AddHP > CSocket.Client.MaxHP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, (CSocket.Client.MaxHP - CSocket.Client.CurrentHP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, AddHP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                        }
                        break;
                    }
                case 1000030://Stancher
                    {
                        int AddHP = 500;
                        if (CSocket.Client.CurrentHP >= CSocket.Client.MaxHP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentHP + AddHP > CSocket.Client.MaxHP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, (CSocket.Client.MaxHP - CSocket.Client.CurrentHP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, AddHP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                        }
                        break;
                    }
                case 1002000://Stancher
                    {
                        int AddHP = 800;
                        if (CSocket.Client.CurrentHP >= CSocket.Client.MaxHP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentHP + AddHP > CSocket.Client.MaxHP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, (CSocket.Client.MaxHP - CSocket.Client.CurrentHP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, AddHP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                        }
                        break;
                    }
                case 1002010://Stancher
                    {
                        int AddHP = 1200;
                        if (CSocket.Client.CurrentHP >= CSocket.Client.MaxHP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentHP + AddHP > CSocket.Client.MaxHP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, (CSocket.Client.MaxHP - CSocket.Client.CurrentHP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, AddHP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                        }
                        break;
                    }
                case 1002020://Stancher
                    {
                        int AddHP = 2000;
                        if (CSocket.Client.CurrentHP >= CSocket.Client.MaxHP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentHP + AddHP > CSocket.Client.MaxHP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, (CSocket.Client.MaxHP - CSocket.Client.CurrentHP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, AddHP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                        }
                        break;
                    }
                case 1002050://Stancher
                    {
                        int AddHP = 3000;
                        if (CSocket.Client.CurrentHP >= CSocket.Client.MaxHP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentHP + AddHP > CSocket.Client.MaxHP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, (CSocket.Client.MaxHP - CSocket.Client.CurrentHP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentHP, AddHP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentHP, Struct.StatusTypes.Hp));
                            }
                        }
                        break;
                    }
                case 1001000://Stancher
                    {
                        int AddMP = 70;
                        if (CSocket.Client.CurrentMP >= CSocket.Client.MaxMP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentMP + AddMP > CSocket.Client.MaxMP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, (CSocket.Client.MaxMP - CSocket.Client.CurrentMP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, AddMP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                        }
                        break;
                    }
                case 1001010://Stancher
                    {
                        int AddMP = 200;
                        if (CSocket.Client.CurrentMP >= CSocket.Client.MaxMP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentMP + AddMP > CSocket.Client.MaxMP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, (CSocket.Client.MaxMP - CSocket.Client.CurrentMP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, AddMP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                        }
                        break;
                    }
                case 1001020://Stancher
                    {
                        int AddMP = 450;
                        if (CSocket.Client.CurrentMP >= CSocket.Client.MaxMP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentMP + AddMP > CSocket.Client.MaxMP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, (CSocket.Client.MaxMP - CSocket.Client.CurrentMP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, AddMP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                        }
                        break;
                    }
                case 1001030://Stancher
                    {
                        int AddMP = 1000;
                        if (CSocket.Client.CurrentMP >= CSocket.Client.MaxMP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentMP + AddMP > CSocket.Client.MaxMP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, (CSocket.Client.MaxMP - CSocket.Client.CurrentMP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, AddMP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                        }
                        break;
                    }
                case 1001040://Stancher
                    {
                        int AddMP = 2000;
                        if (CSocket.Client.CurrentMP >= CSocket.Client.MaxMP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentMP + AddMP > CSocket.Client.MaxMP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, (CSocket.Client.MaxMP - CSocket.Client.CurrentMP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, AddMP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                        }
                        break;
                    }
                case 1002030://Stancher
                    {
                        int AddMP = 3000;
                        if (CSocket.Client.CurrentMP >= CSocket.Client.MaxMP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentMP + AddMP > CSocket.Client.MaxMP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, (CSocket.Client.MaxMP - CSocket.Client.CurrentMP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, AddMP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                        }
                        break;
                    }
                case 1002040://Stancher
                    {
                        int AddMP = 4500;
                        if (CSocket.Client.CurrentMP >= CSocket.Client.MaxMP)
                        {
                            Delete = false;
                            break;
                        }
                        else
                        {
                            if (CSocket.Client.CurrentMP + AddMP > CSocket.Client.MaxMP)
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, (CSocket.Client.MaxMP - CSocket.Client.CurrentMP));
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                            else
                            {
                                Interlocked.Add(ref CSocket.Client.CurrentMP, AddMP);
                                CSocket.Send(EudemonPacket.Status(CSocket, 2, CSocket.Client.CurrentMP, Struct.StatusTypes.Mp));
                            }
                        }
                        break;
                    }
                default:
                    {
                        CSocket.Send(EudemonPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "[ERROR] Please report: Unable to handle item ID: " + Item.ItemID, Struct.ChatType.System));
                        Delete = false;
                        break;
                    }
            }
            if (Delete)
            {
                CSocket.Client.Inventory.Remove(Item.UID);
                CSocket.Send(EudemonPacket.ItemUsage(Item.UID, 255, Struct.ItemUsage.RemoveDropItem));
                Database.Database.DeleteItem(Item.UID);
            }
        }