Example #1
0
        public static void SkillToMobs(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            var map     = client.Metadata["map"] as IMap;
            var mapmobs = (client.Metadata["map"] as IMap).GetSurroundingMobs(client, 3);
            var mobdata = map.GetMobsData;



            var skillid = packet.ReadUShort();
            var unk     = packet.ReadInt();
            var unk1    = packet.ReadByte();
            var unk2    = packet.ReadUShort();
            var unk3    = packet.ReadShort();
            var unk4    = packet.ReadByte();
            var dmg     = packet.ReadUInt();
            var unk5    = packet.ReadByte();
            var unk6    = packet.ReadShort();
            var unk7    = packet.ReadShort();
            var unk8    = packet.ReadShort();
            var unk9    = packet.ReadShort();
            var mobid   = packet.ReadShort();
            var unk11   = packet.ReadByte();
            var unk12   = packet.ReadShort();
            var unk13   = packet.ReadShort();

#if DEBUG
            Log.Notice("SkillID:" + skillid + " SkillSlot:" + unk + " unk1:" + unk1 + " unk2:" + unk2 + " unk3:" + unk3 + " unk4:" + unk4 + " dmg:" + dmg + " unk5:" + unk5 + " unk6:" + unk6 + " unk7:" + unk7 + " unk8:" + unk8 + " unk9:" + unk9 + " MobID:" + mobid + " unk11:" + unk11 + " unk12:" + unk12 + " unk13:" + unk13 + "");
#endif

            //packet.Skip(6);
            var attack = packet.ReadUShort();

            Character character = client.Metadata["fullchar"] as Character;
            uint      hp        = character.stats.curhp;
            uint      mp        = character.stats.curmp;

            SkillLoader s         = new SkillLoader();
            var         skilllist = s.LoadSkillData(skillid);
            var         sid       = skilllist.Find(x => x.ID == skillid);

            var char_atk = (int)client.Metadata["patk"];

            if (sid.Type == 1)
            {
                char_atk = (int)client.Metadata["patk"];
            }
            if (sid.Type == 2)
            {
                char_atk = (int)client.Metadata["matk"];
            }

            var mi = mapmobs.Find(x => x.Id == mobid);
            var md = mobdata[mi.SId];

            uint attack_rate = Convert.ToUInt32(new Random().Next(1, 10));

            var normal_atk = char_atk + (sid.Attack + ((sid.Amp / 100) * sid.Attack));

            var mobdef = new Random().Next(md.Defense, md.DefRate);

            var normal_damage = normal_atk - mobdef;
            var crit_damage   = normal_damage + (normal_damage * sid.Critical);

            var damage = 0;

            var atack_result = 0;

            if (attack_rate <= 5)
            {
                atack_result        = 2;
                damage              = normal_damage;
                character.stats.exp = character.stats.exp + (ulong)damage * 2;
            }
            if (attack_rate == 6)
            {
                atack_result        = 1;
                damage              = crit_damage;
                character.stats.exp = character.stats.exp + (ulong)damage * 2;
            }
            if (attack_rate == 7)
            {
                atack_result = 27;
            }

            if (attack_rate >= 8)
            {
                atack_result = 21;
            }

            //Damage Maked
            if (damage < md.Defense && damage > 0)
            {
                damage = new Random().Next(1, 5);
            }

            if (damage >= mi.CurrentHP && damage > 0)
            {
                damage       = mi.CurrentHP;
                mi.CurrentHP = 0;
                //map.DropItem(mi.CurrentPosX, mi.CurrentPosX, 13, 1,1);
            }
            else
            {
                mi.CurrentHP = mi.CurrentHP - damage;
            }


            var exp      = character.stats.exp;
            var skillexp = character.stats.swordrank + sid.Attack;


            builder.New(0x00AE);
            {
                builder += (ushort)skillid;     //skillid
                builder += hp;                  //Hp
                builder += mp;                  //Mp
                builder += (ushort)0;           //SP
                builder += (ulong)exp;          //Exp
                builder += (ulong)0;            //OXP
                builder += (ulong)skillexp;     //SkillEXP

                builder += new byte[26];

                builder += (uint)0xFFFFFFFF;
                builder += (byte)0;
                builder += hp;
                builder += (uint)0;

                builder += (byte)1;

                builder += (byte)mobid;

                builder += (byte)0;

                builder += (byte)map.ID;
                builder += (byte)2;
                builder += (byte)2;

                builder += (byte)atack_result;

                builder += (int)damage;

                builder += (int)mi.CurrentHP;

                builder += new byte[12];
                builder += (byte)1;
            }

            client.Send(builder, "SkillToMobs");

            if (mi.CurrentHP == 0)
            {
                mi.Spawn = Environment.TickCount + md.Respawn * 10;

                mapmobs.Remove(mi);
            }
        }
Example #2
0
        public static void SkillToUser(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            var clients = (client.Metadata["map"] as IMap).GetSurroundingClients(client, 2);

            Character character = client.Metadata["fullchar"] as Character;
            var       id        = character.id;

            var skill = packet.ReadShort();

            if (skill == 0x014C)
            {
                var unk2 = packet.ReadByte();
                var unk3 = packet.ReadShort();
                var unk4 = packet.ReadInt();

                builder.New(0xAF);
                {
                    builder += skill;
                    builder += (short)0x08;
                    builder += unk3;
                    builder += unk4;
                }

                client.Send(builder, "SkillToUser");

                builder.New(0xDD);
                {
                    builder += skill;
                    builder += id;
                    builder += 0x0D;
                    builder += (short)0x0200;
                    builder += unk3;
                    builder += unk4;
                }

                foreach (var c in clients)
                {
                    c.Send(builder, "NFY_SkillToUser");
                }
            }

            if (skill == 0x00D1)
            {
                var unk2 = packet.ReadByte();
                var x    = packet.ReadShort();
                var y    = packet.ReadShort();

                builder.New(0xAF);
                {
                    builder += skill;
                    builder += 0;
                    builder += (short)0x039C;
                }

                client.Send(builder, "SkillToUser");

                builder.New(0xDD);
                {
                    builder += skill;
                    builder += id;
                    builder += 1;
                    builder += x;
                    builder += y;
                }

                foreach (var c in clients)
                {
                    c.Send(builder, "NFY_SkillToUser");
                }
            }

            if (skill == 0x00D0)
            {
                var unk2 = packet.ReadByte();
                var x    = packet.ReadShort();
                var y    = packet.ReadShort();

                builder.New(0xAF);
                {
                    builder += skill;
                    builder += 0;
                    builder += (short)0x0395;
                }

                client.Send(builder, "SkillToUser");

                builder.New(0xDD);
                {
                    builder += skill;
                    builder += id;
                    builder += 1;
                    builder += x;
                    builder += y;
                }

                foreach (var c in clients)
                {
                    c.Send(builder, "NFY_SkillToUser");
                }
            }
        }
Example #3
0
        public static void EnterWorld(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            if (packet.Size < 14)
            {
                return;
            }
            var id = packet.ReadInt();

            var server     = (int)client.Metadata["server"];
            var syncServer = client.Metadata["syncServer"] as SyncReceiver;

            ServerData[] servers     = GetChannels(syncServer);
            ChannelData  channelData = null;

            foreach (var svr in servers)
            {
                if (svr.id == server)
                {
                    foreach (var chn in svr.channels)
                    {
                        if (chn.id == (int)client.Metadata["channel"])
                        {
                            channelData = chn;
                        }
                    }
                }
            }

            if (channelData == null)
            {
                return;
            }

            var charslot = id % 8;
            var ip       = BitConverter.ToUInt32(Configuration.channelIp.GetAddressBytes(), 0);
            var chport   = Configuration.channelPort;

            if (client.AccountID <= 0)
            {
                client.AccountID = Authentication.GetUser(syncServer, (ulong)client.Metadata["magic"]);
            }


            Character character = CharacterManagement.GetFullCharacter(syncServer, server, client.AccountID, charslot);

            client.Metadata["fullchar"] = character;
            client.Metadata["id"]       = (int)id;

            client.Metadata["map"] = null;

            var equipment = character.equipment.GetEquipment();

            var level = character.level;
            var map   = character.map;
            var x     = (ushort)character.x;
            var y     = (ushort)character.y;

            var matk = (int)(character.stats.matk + (character.stats.int_stat * 1.2));
            var patk = (int)(character.stats.patk + (character.stats.str_stat * 1.2));
            var def  = (int)(character.stats.def + (character.stats.dex_stat * 1.2));

            client.Metadata["dest_x"] = x;
            client.Metadata["dest_y"] = y;

            client.Metadata["matk"] = matk;
            client.Metadata["patk"] = patk;
            client.Metadata["def"]  = def;



            var style = (int)character._class;

            style += (int)character.stats.rank << 3;
            style += (character.face << 8);
            style += (character.colour << 13);
            style += (character.hair << 17);
            style += (!character.gender) ? 0 : (1 << 26);


            client.Metadata["style"]     = style;
            client.Metadata["equipment"] = equipment;


            var ditems = new List <byte[]>();
            var citems = new List <byte[]>();

            foreach (var i in character.inv)
            {
                var di   = (DItem)(i.item.ToStructure <DItem>());
                var slot = i.slot;
                var ci   = (CItem)(di.ToClient(slot));
                var item = ci.ToByteArray();

                if (i.amount != 0)
                {
                    BitConverter.GetBytes(i.amount).CopyTo(item, 12);
                }

                ditems.Add(di.ToByteArray());
                citems.Add(item);
            }

            client.Metadata["inventory"] = ditems;

            builder.New(0x8E, true);
            {
                builder += new byte[58];
                builder += (byte)0x14;
                builder += (byte)server;
                builder += (short)channelData.id;
                builder += new byte[22];
                builder += (byte)255;
                builder += (short)channelData.maxPlayers;
                builder += ip;                                          // channel ip
                builder += (ushort)chport;                              // channel port
                builder += (long)1;
                builder += 0x01002607;
                builder += (int)map;                                    // map
                builder += 0;
                builder += x;                                           // x
                builder += y;                                           // y
                builder += character.stats.exp;                         // exp
                builder += character.stats.alz;                         // alz
                builder += character.stats.wexp;                        // wexp
                builder += level;                                       // level
                builder += 0;
                builder += character.stats.str_stat;                    // str
                builder += character.stats.dex_stat;                    // dex
                builder += character.stats.int_stat;                    // int
                builder += character.stats.pnt_stat;                    // points
                builder += character.stats.swordrank;                   // sword rank
                builder += (byte)0;                                     // magic rank **UNUSED**
                builder += new byte[6];
                builder += (uint)character.stats.maxhp;                 // max hp
                builder += (uint)character.stats.curhp;                 // curr hp
                builder += (uint)character.stats.maxmp;                 // max mp
                builder += (uint)character.stats.curmp;                 // curr mp
                builder += character.stats.maxsp;                       // max sp
                builder += character.stats.cursp;                       // curr sp
                builder += 8;                                           // max rage
                builder += (uint)0;                                     // DP
                builder += (ushort)0x2A30;
                builder += (ushort)0;
                builder += (uint)0;
                builder += (uint)character.stats.magicrank; //SkillExpBars
                builder += (uint)character.stats.swordxp;   //SkillExp
                builder += (uint)character.stats.swordpts;  //SkillPoints
                builder += (ushort)0;                       //Unk 0x33
                builder += (uint)0;                         //Honor Points
                builder += (uint)0;
                builder += (uint)0;
                builder += (uint)0;
                builder += (uint)0;
                builder += (uint)0;
                builder += (ushort)0;
                builder += (ushort)0;
                builder += (uint)0;
                builder += ip;                                          // unk server ip
                builder += (ushort)chport;                              // unk server port
                builder += ip;                                          // unk server ip Possible AuctionServer
                builder += (ushort)chport;                              // unk server port Possible AuctionServer
                builder += ip;                                          // unk server ip
                builder += (ushort)chport;                              // unk server port
                builder += (ushort)0xBBEE;
                builder += new byte[5];
                builder += 0x3FFFFF;                                    // warp codes?
                builder += 0x3FFFFF;                                    // map codes?
                builder += style;                                       // style
                builder += new byte[244];
                builder += (ushort)equipment.Count;                     // equip count
                builder += (ushort)citems.Count;                        // items count
                builder += (ushort)0;
                builder += (ushort)character.skills.Length;             // skills count
                builder += (ushort)character.qslots.Length;             // quickslots count
                builder += new byte[1304];
                builder += 1;
                builder += 0;
                builder += 0;
                builder += 0;
                builder += 0;
                builder += 0;
                builder += 1;
                builder += new byte[79];
                builder += 1;
                builder += new byte[131];
                builder += 0x03E8;                                      // help window..?
                builder += 0;
                builder += new byte[2065];



                /*
                 * builder += new byte[1975];
                 * builder += (int)1;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;                                      // 2 -> Unlimited Warp Active until 2000-00:00:00?
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;                                      // 1 or 0
                 * builder += (int)0;
                 * builder += (int)0;                                      // 0 or 1
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (byte)0;
                 * builder += (byte)0;
                 * builder += (int)0;                                      // My Merit Points (See UI for more accurate perception)
                 * builder += (int)0;                                      // Merit Point (See UI for more accurate perception)
                 * builder += (int)0;                                      // if 15 and the value bellow Force Gems is >2000 then Unlimited Warp Active until 2000-00:00:00?
                 * builder += (int)0;                                      // Force Gems
                 * builder += (int)0;                                      // Unknown Value Max (9999)?
                 */

                /*builder += new byte[2103];
                 * /*builder += (uint)0xFFFFFFFE;
                 * builder += new byte[2059];
                 * builder += (uint)0;                                     // Raise Spirit (millisecs)
                 * builder += new byte[16];
                 * builder += (int)0;                                      // My Merit Points (See UI for more accurate perception)
                 * builder += (int)0;                                      // Merit Point (See UI for more accurate perception)
                 * builder += (int)0;                                      // Unknown
                 * builder += (int)0;                                      // Force Gems
                 * builder += (int)0;                                      // Unknown*/

                builder += (byte)0;                                     // Raise Spirit (millisecs)
                builder += (byte)0;
                builder += (byte)0;
                builder += (int)0;
                builder += (int)0;
                builder += (int)0;
                builder += (int)0;

                builder += (int)0;

                /*
                 * builder += (byte)0;
                 * builder += (byte)0;
                 * builder += (byte)0;
                 * builder += (byte)0;                                     // Unknown MertisSlots*/


                builder += (int)0;                                  // Merit Points Max 50 (See UI for more accurate perception)
                builder += (int)0;                                  // My Merit Points (See UI for more accurate perception)

                builder += (ushort)0;                               // Unknown
                builder += (ushort)0;                               // Unknown

                builder += (int)0;                                  // Force Gems
                builder += (int)0;                                  //Unknown Value Max(9999) ?

                builder += (int)0;                                  // OverlordLevel
                builder += (ulong)0;                                // OverlordEXP

                builder += (byte)0;                                 // Unknown
                builder += (byte)(character.name.Length + 1);       // name length + 1
                builder += character.name;                          // name

                foreach (var e in equipment)
                {
                    builder += e.ToByteArray();
                }

                foreach (var i in citems)
                {
                    builder += i;
                }

                foreach (var s in character.skills)
                {
                    builder += (short)s.skill;                          // Skill ID
                    builder += s.level;                                 // Skill Level
                    builder += s.slot;                                  // Skill Slot
                    builder += (byte)0;
                }

                foreach (var q in character.qslots)
                {
                    builder += (short)q.skill;                          // Skill ID (referenced by Skill Slot)
                    builder += (short)q.slot;                           // Slot (in quickslot bars)
                }
            }

            client.Send(builder, "Initialized");
            events.Warped("world.Initialized", client, map, x, y);
            Authentication.UpdateOnline(syncServer, client.AccountID, true);

            //NewUserList(packet, builder, client, events);
            NewMobsList(packet, builder, client, events);
        }
Example #4
0
        public static void MessageEvent(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            Character character = client.Metadata["fullchar"] as Character;
            var       name      = character.name;
            var       x         = (ushort)character.x;
            var       y         = (ushort)character.y;
            var       id        = character.id;
            var       map       = client.Metadata["map"] as IMap;
            var       clients   = map.GetSurroundingClients(client, 1);

            int unk = packet.ReadInt();

            packet.Skip(4);
            int size = packet.ReadShort() - 3;

            packet.Skip(2);
            var type = packet.ReadByte();
            var msg  = packet.ReadString(size);

            var smsg = msg.Split(' ');

            if (msg == "/quit")
            {
                CharacterManagement.UpdatePosition(client.Metadata["syncServer"] as SyncReceiver, (int)client.Metadata["server"], client.AccountID, character.slot, character.map, character.x, character.y);

                client.Disconnect();
                return;
            }

            #region DebugCommands
#if DEBUG
            if (smsg.Length > 1 && string.IsNullOrEmpty(smsg[0]) == false)
            {
                switch (smsg[0])
                {
                case "_drop":
                    int itemid = 0;

                    if (int.TryParse(smsg[1], out itemid))
                    {
                        map.DropItem(x, y, itemid, (uint)id, (uint)id);
                    }

                    break;

                case "_slm":
                    Unknown_86C(packet, builder, client, events);
                    break;

                case "_warp":
                    ushort mapid = 0;
                    ushort curx  = 0;
                    ushort cury  = 0;

                    if (!ushort.TryParse(smsg[1], out mapid))
                    {
                        return;
                    }

                    if (!ushort.TryParse(smsg[2], out curx))
                    {
                        return;
                    }

                    if (!ushort.TryParse(smsg[3], out cury))
                    {
                        return;
                    }

                    var p = client.CreatePacket("PC_WarpCommand", mapid, curx, cury, client);

                    events.Warped("world.Initialized", client, mapid, curx, cury);

                    client.Send(p, "PC_WarpCommand");

                    break;

                case "_levelup":
                    ushort level = 0;

                    var exp = character.stats.exp;

                    if (!ushort.TryParse(smsg[1], out level))
                    {
                        return;
                    }

                    character.stats.exp = 0;


                    /*
                     * builder.New(0x011F); // 3: Increase Hp, 4: Increase Mp, 5: SP, 8: Party Exp Bonus, 9:
                     * {
                     *  builder += (byte)9;
                     *  builder += (uint)0x5;
                     * }*/

                    //client.Send(builder, "LevelUp1");

                    builder.New(0x0120);
                    {
                        builder += (byte)level;
                        builder += character.id;
                    }

                    character.level += 1;

                    client.Send(builder, "LevelUp");

                    NFY_ChargeInfo(packet, builder, client, events);

                    Unknown9D6(packet, builder, client, events);

                    Unknown9E0(packet, builder, client, events);

                    builder.New(0x03F0);
                    {
                        builder += (byte)4;
                        builder += (uint)1428;
                        builder += (uint)1431;
                        builder += (uint)1430;
                        builder += (uint)1429;
                    }

                    client.Send(builder, "Unk3F0");

                    break;

                case "_spawn":
                    ushort mobid  = 0;
                    ushort specid = 0;

                    if (!ushort.TryParse(smsg[1], out mobid))
                    {
                        return;
                    }

                    if (!ushort.TryParse(smsg[2], out specid))
                    {
                        return;
                    }

                    var p1 = client.CreatePacket("MobSpawned", mobid, specid);

                    client.Send(p1, "MobSpawned");

                    break;

                case "/Partytime":
                    uint pid = 1337;

                    foreach (var c in clients)
                    {
                        builder.New(0xC9);
                        {
                            builder += (int)pid;
                            builder += (byte)12;

                            //b = builder.Data;
                        }

                        var timestamp = (uint)c.Metadata["timestamp"];
                        var style     = (uint)c.Metadata["style"];

                        c.Send(builder, "NFY_DelUserList");

                        builder.New(0xC8);
                        {
                            builder += (short)0x3101;
                            builder += (int)pid++;
                            builder += (short)0x000D;
                            builder += (short)0x0100;
                            builder += 1;
                            builder += Environment.TickCount - (int)timestamp;
                            builder += (short)(x + 1);
                            builder += (short)y;
                            builder += (short)(x + 1);
                            builder += (short)y;
                            builder += (byte)0;
                            builder += 0;
                            builder += (short)0;
                            builder += (int)style;
                            builder += (byte)1;
                            builder += (byte)0;
                            builder += 0;
                            builder += 0;
                            builder += (byte)0;

                            var equipment = (List <CItem>)c.Metadata["equipment"];

                            builder += (byte)(equipment.Count);
                            builder += (short)0;
                            builder += (byte)0;
                            builder += 0;

                            name = "PARTY TIME!!";

                            builder += (byte)(name.Length + 1);
                            builder += name;
                            builder += (byte)0;

                            foreach (var e in equipment)
                            {
                                builder += (short)e.ID;
                                builder += e.Slot;
                            }
                        }

                        c.Send(builder, "NFY_NewUserList");
                    }
                    return;
                }
            }
#endif
            #endregion

            builder.New(0xD9);
            {
                builder += id;
                builder += (byte)0;
                builder += (byte)unk;
                builder += (byte)0;
                builder += (byte)(msg.Length + 3);
                builder += (byte)0;
                builder += (byte)254;
                builder += (byte)254;
                builder += type;
                builder += msg;
                builder += new byte[3];
            }

            foreach (var c in clients)
            {
                c.Send(builder, "NFY_MessageEvnt");
            }

            events.SaidLocal("world.MessageEvnt", id, name, msg);
        }