Example #1
0
        public void Parse(DirectoryInfo input, DirectoryInfo output)
        {
            FileInfo skillDat = input.GetFiles().FirstOrDefault(x => x.Name.Equals("Skill.dat", StringComparison.InvariantCultureIgnoreCase));

            if (skillDat == null)
            {
                Logger.Warn("Can't found Skill.dat file, skipping skills parsing");
                return;
            }

            TextContent content = TextReader.FromFile(skillDat)
                                  .SkipCommentedLines("#")
                                  .SkipEmptyLines()
                                  .SplitLineContent('\t')
                                  .TrimLines()
                                  .GetContent();

            IEnumerable <TextRegion> regions = content.GetRegions("VNUM");

            var skills = new Dictionary <int, SkillData>();

            foreach (TextRegion region in regions)
            {
                TextLine vnumLine   = region.GetLine(x => x.StartWith("VNUM"));
                TextLine nameLine   = region.GetLine(x => x.StartWith("NAME"));
                TextLine typeLine   = region.GetLine(x => x.StartWith("TYPE"));
                TextLine dataLine   = region.GetLine(x => x.StartWith("DATA"));
                TextLine targetLine = region.GetLine(x => x.StartWith("TARGET"));

                int gameKey = vnumLine.GetValue <int>(1);

                skills[gameKey] = new SkillData
                {
                    NameKey   = nameLine.GetValue(1),
                    Category  = (SkillCategory)typeLine.GetValue <int>(1),
                    CastId    = typeLine.GetValue <int>(2),
                    CastTime  = dataLine.GetValue <int>(5),
                    Cooldown  = dataLine.GetValue <int>(6),
                    MpCost    = dataLine.GetValue <int>(7),
                    Target    = (SkillTarget)targetLine.GetValue <int>(1),
                    HitType   = (HitType)targetLine.GetValue <int>(2),
                    Range     = targetLine.GetValue <short>(3),
                    ZoneRange = targetLine.GetValue <short>(4),
                    SkillType = (SkillType)targetLine.GetValue <int>(5)
                };
            }

            using (StreamWriter file = File.CreateText(Path.Combine(output.FullName, "skills.json")))
            {
                serializer.Serialize(file, skills);
            }

            Logger.Info($"Successfully parsed {skills.Count} skills");
        }
Example #2
0
        public void Parse(DirectoryInfo input, DirectoryInfo output)
        {
            FileInfo monsterDat = input.GetFiles().FirstOrDefault(x => x.Name.Equals("Monster.dat", StringComparison.InvariantCultureIgnoreCase));

            if (monsterDat == null)
            {
                Logger.Warn("Can't found Monster.dat file, skipping monsters parsing");
                return;
            }

            TextContent content = TextReader.FromFile(monsterDat)
                                  .SkipCommentedLines("#")
                                  .SkipEmptyLines()
                                  .SplitLineContent('\t')
                                  .TrimLines()
                                  .GetContent();

            IEnumerable <TextRegion> regions = content.GetRegions("VNUM");

            var monsters = new Dictionary <int, MonsterData>();

            foreach (TextRegion region in regions)
            {
                int    gameKey = region.GetLine("VNUM").GetValue <int>(1);
                int    level   = region.GetLine("LEVEL").GetValue <int>(1);
                string nameKey = region.GetLine("NAME").GetValue(1);

                monsters[gameKey] = new MonsterData
                {
                    NameKey = nameKey,
                    Level   = level
                };
            }

            using (StreamWriter file = File.CreateText(Path.Combine(output.FullName, "monsters.json")))
            {
                serializer.Serialize(file, monsters);
            }

            Logger.Info($"Successfully parsed {monsters.Count} monsters");
        }
Example #3
0
        public void Parse(DirectoryInfo input, DirectoryInfo output)
        {
            DirectoryInfo mapDirectory = input.GetDirectories().FirstOrDefault(x => x.Name == "Maps");

            if (mapDirectory == null)
            {
                Logger.Warn("Can't found Maps directory, skipping map parsing");
                return;
            }

            IEnumerable <FileInfo> mapFiles = mapDirectory.EnumerateFiles("*.bin");

            if (!mapFiles.Any())
            {
                Logger.Warn("Can't found any map file in Maps directory, skipping map parsing");
                return;
            }

            FileInfo mapIdData = input.GetFiles().FirstOrDefault(x => x.Name == "MapIDData.dat");

            if (mapIdData == null)
            {
                Logger.Warn("Can't found MapIDData.dat file, skipping map parsing");
                return;
            }

            TextContent content = TextReader.FromFile(mapIdData)
                                  .SkipLines(x => x.StartsWith("DATA"))
                                  .SkipCommentedLines("#")
                                  .SkipEmptyLines()
                                  .SplitLineContent(' ')
                                  .TrimLines()
                                  .GetContent();

            var mapNameKeys = new Dictionary <int, string>();

            foreach (TextLine line in content.Lines)
            {
                int    firstMapId  = line.GetValue <int>(0);
                int    secondMapId = line.GetValue <int>(1);
                string nameKey     = line.GetValue(4);

                for (int i = firstMapId; i <= secondMapId; i++)
                {
                    mapNameKeys[i] = nameKey;
                }
            }

            var maps = new Dictionary <int, MapData>();

            foreach (FileInfo mapFile in mapFiles)
            {
                int mapId = int.Parse(Path.GetFileNameWithoutExtension(mapFile.Name));
                maps[mapId] = new MapData
                {
                    NameKey = mapNameKeys.GetValueOrDefault(mapId, "UNDEFINED"),
                    Grid    = File.ReadAllBytes(mapFile.FullName)
                };
            }

            using (StreamWriter file = File.CreateText(Path.Combine(output.FullName, "maps.json")))
            {
                serializer.Serialize(file, maps);
            }

            Logger.Info($"Successfully parsed {maps.Count} maps");
        }