public void LevelUp()
 {
     if (PlayerData.Level == 255)
     {
         ChatMessagePacketHandler.SendSystemMessage(Owner, "You are at max level!");
         return;
     }
     SetLevel((byte)(PlayerData.Level + 1), true);
 }
Exemple #2
0
        public static void RecievePacket(ClientState client, byte[] packet)
        {
            if (packet.Length < 3)
            {
                return;
            }
            if (!((packet[2] == 188 && packet[8] == 22) || packet[2] == 5))  // Don't print position or keep alive packets
            {
                Console.WriteLine("[World] client -> server [id={0}]: (length={1}) {2}", client.Id, packet.Length, Util.ReadableBytes(packet));
            }

            byte packetId = packet[2];

            switch (packetId)
            {
            case 191:
                byte nameLength = packet[34];
                if (nameLength <= 0)
                {
                    return;
                }
                string name     = Encoding.ASCII.GetString(packet, 35, nameLength);
                string username = Encoding.ASCII.GetString(packet, 17, 16).Trim((char)0).Trim();
                client.Username = username;

                ChatMessagePacketHandler.SendSystemMessage(client, "Welcome, " + name + ". Type !h for server commands.");

                client.PlayerData       = SqlHelper.GetPlayerDataFromName(username, name);
                client.PlayerData.MapId = 84;
                client.PlayerData.PosX  = 63;
                client.PlayerData.PosY  = 30;
                client.LoadMap(client.PlayerData.MapId);

                SendPacket(client, new PlayerObject(null, 10, new PlayerData()
                {
                    Name      = "player2",
                    PosX      = 67,
                    PosY      = 32,
                    Direction = 2
                }).SpawnPlayerPacket(false, false));

                //client.PlayerObject.ActivePet = new PetObject(0, 1, 61, 30, 2);
                //SendPacket(client, client.PlayerObject.ActivePet.SpawnPetPacket(false));

                //SendPacket(state, new byte[] { 11, 0, 195, 0, 0, 0, 0, 0, 1, (byte) WorldServer.ClientList.Count, 0, 1, 0 }); // Num players on server
                //SendPacket(state, new byte[] { 9, 0, 195, 0, 0, 0, 0, 0, 6, (byte) WorldServer.ClientList.Count, 0 }); // Num players on map

                //SendPacket(state, new byte[] { 13, 0, 191, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }); // Sets player id to 0

                //SendPacket(state, new byte[] { 15, 0, 176, 0, 0, 0, 0, 0, 17, 19, 7, 0, 0, 0, 0, 0, 0 }); // Sets map
                //SendMap(state, 84, 63, 30);

                // Spawns player
                //SendPacket(state, new byte[] { 45, 0, 177, 0, 0, 0, 0, 0, 1,
                //    0, 0, 0, 20, 0, 0, 0, 0,
                //    0, 0, 0, 0, 0, 0, 20, 2,
                //    0, 0, 63, 0, 30, 0, 0, 0,
                //    0, 0, 0, 0, 0, 0, 3, 3,
                //    65, 66, 67, 68, 69, 70
                //});

                //SendPlayerStats(state);

                //SendSkillList(state, 15, 25, 35, 45);
                //SendQuestList(state, 1, 2, 3, 4);

                //SendPlayerInventory(state, 0,
                //    new Item(500, 1),
                //    new Item(501, 1),
                //    new Item(502, 1)
                //);

                //SendPlayerInventory(state, 1,
                //    new Item(1190, 1),
                //    new Item(1191, 1),
                //    new Item(1192, 1),
                //    new Item(1250, 1),
                //    new Item(1201, 1),
                //    new Item(1202, 1),
                //    new Item(536, 1)
                //);

                //SendPlayerInventory(state, 2,
                //    new Item(6, 1),
                //    new Item(7, 1),
                //    new Item(8, 1)
                //);

                //Item[] items = new Item[255];
                //for (int i = 0; i < items.Length; i++) items[i] = new Item((short) (i + 500), 1);
                //SendPlayerInventory(state, 0, items);

                //SendPickedUpItem(state, new Item(1193, 2));

                //SendPacket(state, new byte[] { 7, 0, 176, 0, 0, 0, 0, 0, 19 }); // loads map

                //SendPacket(state, new byte[] {        // attack target
                //    26, 0, 181, 0, 0, 0, 0, 0,
                //    177,    // packet id
                //    1,      // obj type (player)
                //    0, 0,      // obj id
                //    1,      // target type
                //    0, 0,   // target id
                //    0, 1,   // attack speed
                //    2, 2, 0,    // number of attacks = 2 + 2 (0 is ?)
                //    3, 0, 4, 0, // damage of each attach
                //    7, 0, 8, 0
                //});

                break;

            case 186:     // Typed in chat box
                ChatMessagePacketHandler.HandleChatMessage(client, packet);
                break;

            case 188:
                switch (packet[8])
                {
                case 17:         // Sit
                    if (client.PlayerObject.Stance == 0)
                    {
                        client.PlayerObject.SetStance(1);
                    }
                    break;

                case 18:         // Stand
                    if (client.PlayerObject.Stance == 1)
                    {
                        client.PlayerObject.SetStance(0);
                    }
                    break;

                case 21:         // Change direction
                    client.PlayerObject.SetDirection(packet[9]);
                    break;

                case 22:         // Set position
                    client.PlayerObject.SetPosition(BitConverter.ToInt16(packet, 9), BitConverter.ToInt16(packet, 11));
                    break;

                case 23:         // attack
                    byte  targetType = packet[9];
                    short targetId   = BitConverter.ToInt16(packet, 10);
                    SendPacket(client, client.PlayerObject.DamageTargetPacket(targetType, targetId, 1));
                    break;

                case 25:         // Show emote
                    byte emoteId = packet[9];
                    client.PlayerObject.ShowEmoticon(emoteId);
                    break;

                case 35:         // Equip item
                    byte slotId = packet[9];
                    SendEquippedItem(client, slotId, Item.FromBytes(packet.Skip(10).Take(8).ToArray()));
                    break;

                case 41:         // Equip mslot
                    SendEquippedMSlot(client, BitConverter.ToInt16(packet, 9));
                    break;

                case 42:         // Equip cosmetic
                    slotId = packet[9];
                    SendEquippedItem(client, slotId, Item.FromBytes(packet.Skip(10).Take(8).ToArray()), true);
                    break;

                case 54:         // Delete quest
                    short quest = BitConverter.ToInt16(packet, 9);
                    RemoveQuest(client, quest);
                    break;

                case 65:         // Add skill point
                    client.PlayerData.AddSkillPoint(client, (Skill)packet[9]);
                    break;
                }
                break;

            case 187:     // open shop
                short map = World.MapList[World.MapList.Keys.ElementAt(++i)].Id;
                client.LoadMap(map);
                Console.WriteLine("[World] Set map: " + map);
                break;

            case 176:     // quit game
                SendPacket(client, new byte[] { 8, 0, 3, 0, 0, 0, 0, 0, 255, 15 });
                client.Close();
                break;

            case 196:
                break;

            case 5:     // Keep alive packet
                client.IsAlive = true;
                break;
            }
        }