Beispiel #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");
        }
Beispiel #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");
        }
Beispiel #3
0
        public async Task Parse(DirectoryInfo directory)
        {
            logger.Information("Parsing monsters data");

            var file = directory.GetFiles().FirstOrDefault(x => x.Name == "monster.dat");

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

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

            var datas          = new List <MonsterDataDTO>();
            var monsterRegions = monsterContent.GetRegions("VNUM");

            foreach (var region in monsterRegions)
            {
                var vnumLine   = region.GetLine("VNUM");
                var levelLine  = region.GetLine("LEVEL");
                var nameLine   = region.GetLine("NAME");
                var hpLine     = region.GetLine("HP/MP");
                var raceLine   = region.GetLine("RACE");
                var preattLine = region.GetLine("PREATT");
                var expLine    = region.GetLine("EXP");
                var attribLine = region.GetLine("ATTRIB");

                var id                = vnumLine.GetValue <int>(1);
                var level             = levelLine.GetValue <int>(1);
                var nameKey           = nameLine.GetValue(1);
                var hp                = hpLine.GetValue <int>(1);
                var mp                = hpLine.GetValue <int>(2);
                var race              = raceLine.GetValue <byte>(1);
                var raceType          = raceLine.GetValue <byte>(2);
                var hostile           = preattLine.GetValue(1) == "1";
                var speed             = preattLine.GetValue <int>(3);
                var seek              = preattLine.GetValue <int>(4);
                var respawn           = preattLine.GetValue <int>(5);
                var experience        = expLine.GetValue <int>(1);
                var jobExperience     = expLine.GetValue <int>(2);
                var element           = attribLine.GetValue <byte>(1);
                var elementPercentage = attribLine.GetValue <int>(2);
                var fireResistance    = attribLine.GetValue <int>(3);
                var waterResistance   = attribLine.GetValue <int>(4);
                var lightResistance   = attribLine.GetValue <int>(5);
                var shadowResistance  = attribLine.GetValue <int>(6);

                datas.Add(new MonsterDataDTO
                {
                    Id                = id,
                    Name              = nameKey,
                    Level             = level,
                    MaxHp             = hp + Hp[level],
                    MaxMp             = mp + Mp[level],
                    Experience        = experience + Experience[level],
                    JobExperience     = jobExperience + JobExperience[level],
                    Race              = GetRace(race, raceType),
                    IsHostile         = hostile,
                    SeekRange         = seek,
                    Speed             = speed,
                    RespawnTime       = respawn,
                    Element           = (Element)element,
                    ElementPercentage = elementPercentage,
                    FireResistance    = fireResistance,
                    WaterResistance   = waterResistance,
                    LightResistance   = lightResistance,
                    ShadowResistance  = shadowResistance
                });
            }

            await monsterDataRepository.SaveAll(datas);

            logger.Information($"Saved {datas.Count} monsters data");
        }
Beispiel #4
0
        protected override void Process(IEnumerable <TextFile> files)
        {
            TextFile monster = files.First(x => x.Name == "monster.dat");
            TextFile item    = files.First(x => x.Name == "Item.dat");
            TextFile skill   = files.First(x => x.Name == "Skill.dat");
            TextFile map     = files.First(x => x.Name == "MapIDData.dat");
            TextFile card    = files.First(x => x.Name == "Card.dat");

            Log.Information("Generating monsters");
            TextContent monsterContent = TextReader.FromString(Encoding.Default.GetString(monster.Content))
                                         .SkipCommentedLines("#")
                                         .SkipEmptyLines()
                                         .SplitLineContent('\t')
                                         .TrimLines()
                                         .GetContent();

            var monsters = new Dictionary <int, MonsterData>();
            IEnumerable <TextRegion> monsterRegions = monsterContent.GetRegions("VNUM");

            foreach (TextRegion region in monsterRegions)
            {
                TextLine zSkillLine = region.GetLine("ZSKILL");

                int    modelId = region.GetLine("VNUM").GetValue <int>(1);
                int    level   = region.GetLine("LEVEL").GetValue <int>(1);
                string nameKey = region.GetLine("NAME").GetValue(1);

                monsters[modelId] = new MonsterData
                {
                    NameKey             = nameKey,
                    Level               = level,
                    BasicAttackRange    = zSkillLine.GetValue <int>(2),
                    BasicAttackCastTime = zSkillLine.GetValue <int>(4),
                    BasicAttackCooldown = zSkillLine.GetValue <int>(5),
                };
            }

            Log.Information("Generating items");
            TextContent itemContent = TextReader.FromString(Encoding.Default.GetString(item.Content))
                                      .SkipCommentedLines("#")
                                      .SkipEmptyLines()
                                      .SplitLineContent('\t')
                                      .TrimLines()
                                      .GetContent();

            var items = new Dictionary <int, ItemData>();
            IEnumerable <TextRegion> itemRegions = itemContent.GetRegions("VNUM");

            foreach (TextRegion region in itemRegions)
            {
                TextLine indexLine = region.GetLine("INDEX");

                int    gameKey = region.GetLine("VNUM").GetValue <int>(1);
                string nameKey = region.GetLine("NAME").GetValue(1);

                items[gameKey] = new ItemData
                {
                    NameKey       = nameKey,
                    Icon          = indexLine.GetValue <int>(5),
                    InventoryType = indexLine.GetValue <int>(1),
                    Type          = indexLine.GetValue <int>(2),
                    SubType       = indexLine.GetValue <int>(3)
                };
            }

            Log.Information("Generating skills");
            TextContent skillContent = TextReader.FromString(Encoding.Default.GetString(skill.Content))
                                       .SkipCommentedLines("#")
                                       .SkipEmptyLines()
                                       .SplitLineContent('\t')
                                       .TrimLines()
                                       .GetContent();

            var skills = new Dictionary <int, SkillData>();
            IEnumerable <TextRegion> skillRegions = skillContent.GetRegions("VNUM");

            foreach (TextRegion region in skillRegions)
            {
                TextLine vnumLine   = region.GetLine("VNUM");
                TextLine nameLine   = region.GetLine("NAME");
                TextLine typeLine   = region.GetLine("TYPE");
                TextLine dataLine   = region.GetLine("DATA");
                TextLine targetLine = region.GetLine("TARGET");
                TextLine costLine   = region.GetLine("COST");
                TextLine effectLine = region.GetLine("EFFECT");

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

                skills[id] = new SkillData
                {
                    NameKey   = nameLine.GetValue(1),
                    Category  = 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    = targetLine.GetValue <int>(1),
                    HitType   = targetLine.GetValue <int>(2),
                    Range     = targetLine.GetValue <short>(3),
                    ZoneRange = targetLine.GetValue <short>(4),
                    Type      = targetLine.GetValue <int>(5),
                    IsCombo   = costLine.GetValue <int>(3) == 999,
                    Icon      = effectLine.GetValue <int>(1)
                };
            }

            Log.Information("Generating buffs");
            TextContent cardContent = TextReader.FromString(Encoding.Default.GetString(card.Content))
                                      .SkipCommentedLines("#")
                                      .SkipEmptyLines()
                                      .SplitLineContent('\t')
                                      .TrimLines()
                                      .GetContent();

            var buffs = new Dictionary <int, BuffData>();
            IEnumerable <TextRegion> cardRegions = cardContent.GetRegions("VNUM");

            foreach (TextRegion region in cardRegions)
            {
                TextLine vnumLine  = region.GetLine("VNUM");
                TextLine nameLine  = region.GetLine("NAME");
                TextLine groupLine = region.GetLine("GROUP");
                TextLine styleLine = region.GetLine("STYLE");

                int    id      = vnumLine.GetValue <int>(1);
                string nameKey = nameLine.GetValue(1);

                buffs[id] = new BuffData
                {
                    NameKey  = nameKey,
                    GroupId  = groupLine.GetValue <int>(1),
                    Level    = groupLine.GetValue <int>(2),
                    Category = styleLine.GetValue <int>(1),
                    Effect   = styleLine.GetValue <int>(2),
                };
            }

            Log.Information("Generating maps");
            TextContent mapContent = TextReader.FromString(Encoding.Default.GetString(map.Content))
                                     .SkipLines(x => x.StartsWith("DATA"))
                                     .SkipCommentedLines("#")
                                     .SkipEmptyLines()
                                     .SplitLineContent(' ')
                                     .TrimLines()
                                     .GetContent();

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

            foreach (TextLine line in mapContent.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++)
                {
                    maps[i] = new MapData
                    {
                        NameKey = nameKey,
                        Grid    = Array.Empty <byte>()
                    };
                }
            }

            Log.Information($"Saving {monsters.Count} monsters into {Database.MonsterPath}");
            manager.Save(monsters, Database.MonsterPath);

            Log.Information($"Saving {items.Count} items into {Database.ItemPath}");
            manager.Save(items, Database.ItemPath);

            Log.Information($"Saving {skills.Count} skills into {Database.SkillPath}");
            manager.Save(skills, Database.SkillPath);

            Log.Information($"Saving {buffs.Count} buffs into {Database.BuffPath}");
            manager.Save(buffs, Database.BuffPath);

            Log.Information($"Saving {maps.Count} maps into {Database.MapPath}");
            manager.Save(maps, Database.MapPath);
        }