Ejemplo n.º 1
0
        public static void Read(byte[] packet, Client cli)
        {
            PacketReader reader = new PacketReader(packet);
            reader.PopShort(); //magic 0xDFDF
            short pktType = reader.PopShort();
            if (pktType != 0x0005)
            {
                //TextMessage type
                throw new WrongPacketTypeException("Wrong packet type given to VicinityHandler.");
            }
            reader.PopShort(); //unknown
            short packetSize = reader.PopShort();
            UInt32 senderId = reader.PopUInt();
            reader.PopInt(); // Receiver
            int pktId = reader.PopInt(); // Packet ID

            // 3 unknown values
            reader.PopInt();
            reader.PopInt();
            reader.PopInt();

            short msgLen = reader.PopShort();
            string msg = reader.PopString(msgLen);
            byte msgType = reader.PopByte();

#if DEBUG
            Console.WriteLine("Vicinity: " + msg);
#endif
            float range = 0f;
            switch (msgType)
            {
                case 0:
                    // Say
                    range = 10.0f;
                    break;
                case 1:
                    // Whisper
                    range = 1.5f;
                    break;
                case 2:
                    // Shout
                    range = 60.0f;
                    break;
                default:
                    break;
            }

            List<Client> clients = FindClient.GetClientsInRadius(cli, range);
            UInt32[] recvers = new UInt32[clients.Count];
            int index = 0;

            foreach (Client child in clients)
            {
                recvers[index] = (UInt32)child.Character.Id;
                index++;
            }

            ChatCom.SendVicinity(senderId, msgType, recvers, msg);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="client"></param>
        public static void Read(byte[] packet, Client client)
        {
            PacketWriter packetWriter = new PacketWriter();
            PacketReader packetReader = new PacketReader(packet);

            Header header = packetReader.PopHeader();
            byte unknown1 = packetReader.PopByte();
            uint[] nanodelta = { 3, 3, 4, 2 };
            uint[] healdelta = { 3, 3, 2, 4 };

            uint baseIP = 0;
            uint characterLevel;

            characterLevel = client.Character.Stats.Level.StatBaseValue; // 54 = Level

            // Calculate base IP value for character level
            if (characterLevel > 204)
            {
                baseIP += (characterLevel - 204) * 600000;
                characterLevel = 204;
            }
            if (characterLevel > 189)
            {
                baseIP += (characterLevel - 189) * 150000;
                characterLevel = 189;
            }
            if (characterLevel > 149)
            {
                baseIP += (characterLevel - 149) * 80000;
                characterLevel = 149;
            }
            if (characterLevel > 99)
            {
                baseIP += (characterLevel - 99) * 40000;
                characterLevel = 99;
            }
            if (characterLevel > 49)
            {
                baseIP += (characterLevel - 49) * 20000;
                characterLevel = 49;
            }
            if (characterLevel > 14)
            {
                baseIP += (characterLevel - 14) * 10000; // Change 99 => 14 by Wizard
                characterLevel = 14;
            }
            baseIP += 1500 + (characterLevel - 1) * 4000;

            // Prepare reply packet

            packetWriter.PushByte(0xDF);
            packetWriter.PushByte(0xDF);
            packetWriter.PushShort(0x0a);
            packetWriter.PushShort(0x01);
            packetWriter.PushShort(0);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(header.Sender);
            packetWriter.PushInt(0x3e205660);
            packetWriter.PushIdentity(50000, header.Sender);
            packetWriter.PushByte(0);

            int count = packetReader.PopInt();
            uint statval;
            List<int> statlist = new List<int>();
            while (count > 0)
            {
                int statNumber = packetReader.PopInt();
                statval = packetReader.PopUInt();
                client.Character.Stats.SetBaseValue(statNumber, statval);
                statlist.Add(statNumber);
                count--;
            }

            packetReader.Finish();

            statlist.Add(53); // IP
            uint usedIP = baseIP - (uint)Math.Floor(CalculateIP(client));
            client.Character.Stats.IP.StatBaseValue = usedIP;

            // Send the changed stats back to the client
            packetWriter.PushInt(statlist.Count);
            count = 0;
            while (count < statlist.Count)
            {
                statval = client.Character.Stats.GetBaseValue(statlist[count]);
                packetWriter.PushInt(statlist[count]);
                packetWriter.PushUInt(statval);
                count++;
            }

            byte[] reply = packetWriter.Finish();
            client.SendCompressed(reply);

            // and save the changes to the statsdb
            client.Character.WriteStats();
            client.Character.CalculateSkills();
        }