Exemple #1
0
        public static Npc CreateNpc(SpawnTemplate spawnTemplate)
        {
            var npc = new Npc
            {
                NpcId = spawnTemplate.NpcId,
                SpawnTemplate = spawnTemplate,
                NpcTemplate = Data.Data.NpcTemplates[spawnTemplate.Type][spawnTemplate.NpcId],

                Position = new WorldPosition
                {
                    MapId = spawnTemplate.MapId,
                    X = spawnTemplate.X,
                    Y = spawnTemplate.Y,
                    Z =
                        spawnTemplate.Z +
                        ((spawnTemplate.FullId == 6301151 ||
                          spawnTemplate.FullId == 6301152 ||
                          spawnTemplate.FullId == 6301153)
                             ? 0
                             : 25),
                    Heading = spawnTemplate.Heading,
                }
            };

            npc.BindPoint = npc.Position.Clone();

            npc.GameStats = CreatureLogic.InitGameStats(npc);
            CreatureLogic.UpdateCreatureStats(npc);

            AiLogic.InitAi(npc);

            return npc;
        }
Exemple #2
0
        public static Npc CreateNpc(SpawnTemplate spawnTemplate)
        {
            NpcTemplate npcTemplate = (Data.Data.NpcTemplates.ContainsKey(spawnTemplate.NpcId))
                ? Data.Data.NpcTemplates[spawnTemplate.NpcId]
                : new NpcTemplate();

            var npc = new Npc
            {
                NpcId = spawnTemplate.NpcId,
                SpawnTemplate = spawnTemplate,
                NpcTemplate = npcTemplate,

                Position = new WorldPosition
                {
                    MapId = spawnTemplate.MapId,
                    X = spawnTemplate.X,
                    Y = spawnTemplate.Y,
                    Z = spawnTemplate.Z,
                },
            };

            npc.BindPoint = npc.Position.Clone();

            npc.GameStats = CreatureLogic.InitGameStats(npc);
            CreatureLogic.UpdateCreatureStats(npc);

            AiLogic.InitAi(npc);

            return npc;
        }
Exemple #3
0
        private void Run(object sender, RoutedEventArgs e)
        {
            short spNpcInfoOpCode = Packet.GetPacketOpcode(MainWindow, "SpNpcInfo");
            short spBindOpCode = Packet.GetPacketOpcode(MainWindow, "SpCharacterBind");

            Dictionary<int, Dictionary<long, byte[]>> npcs = new Dictionary<int, Dictionary<long, byte[]>>();

            int mapId = 0;

            /*if (File.Exists("data/spawn/7001_spawn.dat"))
            {
                npcs.Add(7001, new Dictionary<long, byte[]>());
                using (stream = File.Open("data/spawn/7001_spawn.dat",FileMode.Open))
                {
                    using (BinaryReader r = new BinaryReader(stream))
                    {
                        int counter = r.ReadInt32();

                        for (int i = 0; i < counter; i++)
                        {
                            long uid = r.ReadInt64();
                            int datalen = r.ReadInt32();
                            byte[] datas = r.ReadBytes(datalen);
                            npcs[7001].Add(uid, datas);
                        }
                    }
                }
            }*/

            foreach (Packet packet in MainWindow.Packets)
            {
                if (packet.OpCode == spBindOpCode)
                {
                    mapId = BitConverter.ToInt32(packet.Data, 4);
                    if (!npcs.ContainsKey(mapId))
                        npcs.Add(mapId, new Dictionary<long, byte[]>());
                    continue;
                }

                if (packet.OpCode != spNpcInfoOpCode)
                    continue;

                long id = BitConverter.ToInt64(packet.Data, 10);

                if (npcs[mapId].ContainsKey(id))
                    continue;

                byte[] data = new byte[packet.Data.Length - 8];
                Buffer.BlockCopy(packet.Data, 8, data, 0, data.Length);

                npcs[mapId].Add(id, data);
            }

            int count = 0;

            if (!Directory.Exists("data"))
                Directory.CreateDirectory("data");

            if (!Directory.Exists("data/spawn"))
                Directory.CreateDirectory("data/spawn");

            foreach (int mapid in npcs.Keys)
            {
                using (FileStream stream = File.Create("data/spawn/" + mapid + "_spawn.bin"))
                {
                    foreach (KeyValuePair<long, byte[]> keyValuePair in npcs[mapid])
                    {
                        SpawnTemplate spawnTemplate = new SpawnTemplate
                                                          {
                                                              NpcId = BitConverter.ToInt32(keyValuePair.Value, 36),
                                                              Type = BitConverter.ToInt16(keyValuePair.Value, 40),
                                                              MapId = mapid,
                                                              X = BitConverter.ToSingle(keyValuePair.Value, 18),
                                                              Y = BitConverter.ToSingle(keyValuePair.Value, 22),
                                                              Z = BitConverter.ToSingle(keyValuePair.Value, 26),
                                                              Heading = BitConverter.ToInt16(keyValuePair.Value, 30)
                                                          };

                        Serializer.SerializeWithLengthPrefix(stream, spawnTemplate, PrefixStyle.Fixed32);

                        count++;
                    }
                }
            }

            MainWindow.SetText("Finded " + count + " npcs in " + npcs.Count + " maps!");
        }
Exemple #4
0
        private static void SpawnTemplateExport()
        {
            List<SpawnTemplate> templates = new List<SpawnTemplate>();

            using (var entity = new PublicDbEntities())
            {
                var list = entity.TBL_XWWL_NPC_SL.ToList();
                foreach (var data in list)
                {
                    SpawnTemplate spawn = new SpawnTemplate()
                    {
                        NpcId = data.FLD_PID,
                        Type = (short)data.FLD_NPC,
                        MapId = data.FLD_MID,
                        X = (float)data.FLD_X,
                        Y = (float)data.FLD_Y,
                        Z = (float)data.FLD_Z,
                        Face1 = (float)data.FLD_FACE0,
                        Face2 = (float)data.FLD_FACE,
                    };
                    templates.Add(spawn);
                    Log.Debug("Npc SL NpcId = {0} Map = {1}", spawn.NpcId, spawn.MapId);
                }

                var list2 = entity.TBL_XWWL_NPC.ToList();
                foreach (var data in list2)
                {
                    SpawnTemplate spawn = new SpawnTemplate()
                    {
                        NpcId = data.FLD_PID,
                        Type = (short)data.FLD_NPC,
                        MapId = data.FLD_MID,
                        X = (float)data.FLD_X,
                        Y = (float)data.FLD_Y,
                        Z = (float)data.FLD_Z,
                        Face1 = (float)data.FLD_FACE0,
                        Face2 = (float)data.FLD_FACE,
                    };
                    templates.Add(spawn);
                    Log.Debug("Npc NpcId = {0} Map = {1}", spawn.NpcId, spawn.MapId);
                }

                using (var file = File.Create("Data/spawns.bin"))
                {
                    Serializer.SerializeWithLengthPrefix<List<SpawnTemplate>>(file, templates, PrefixStyle.Fixed32);
                }
            }
        }