Пример #1
0
        internal static void Process()
        {
            LoadWorld();
            LoadFields();
            if (DumpMonsterAndCharacterDat.MonsterData?.IsEmpty ?? true)
            {
                DumpMonsterAndCharacterDat.LoadMonsters(); //load all the monsters.
            }
            using (StreamWriter csvFile = new StreamWriter(new FileStream("BattleEncounters.csv", FileMode.Create, FileAccess.Write, FileShare.ReadWrite), System.Text.Encoding.UTF8))
            {
                string header =
                    $"{nameof(Battle.Encounter.ID)}{Ls}" +
                    $"{nameof(Battle.Encounter.Filename)}{Ls}" +
                    $"{nameof(BattleStageNames)}{Ls}" +
                    $"{nameof(Battle.Encounter.BEnemies)}{Ls}" +
                    $"{nameof(Fields)}{Ls}";
                csvFile.WriteLine(header);
                foreach (Battle.Encounter e in Memory.Encounters)
                {
                    //wip
                    string data =
                        $"{e.ID}{Ls}" +
                        $"{e.Filename}{Ls}" +
                        $"\"{BattleStageNames[e.Scenario]}\"{Ls}";
                    string             enemies = "\"";
                    IEnumerable <byte> unique  = e.UniqueMonstersList;
                    IEnumerable <KeyValuePair <byte, int> > counts = e.UniqueMonstersList.Select(x => new KeyValuePair <byte, int>(x, e.EnabledMonsters.Count(y => y.Value == x)));
                    unique.ForEach(x =>
                    {
                        string name = "<unknown>";
                        if (DumpMonsterAndCharacterDat.MonsterData.TryGetValue(x, out Debug_battleDat battleDat) && battleDat != null)
                        {
                            name  = battleDat.information.name.Value_str.Trim();
                            name += $" ({battleDat.fileName})";
                        }

                        Debug.Assert(enemies != null, nameof(enemies) + " != null");
                        enemies += $"{counts.First(y => y.Key == x).Value} × {name}{Ls} ";
                    });
                    enemies = enemies.TrimEnd(Ls[0], ' ') + "\"";
                    data   += $"{enemies}{Ls}";
                    //check encounters in fields and confirm encounter rate is above 0.
                    IEnumerable <string> fieldMatches = FieldData.Where(x => x.Value.MrtRat != null && (x.Value.MrtRat.Any(y => y.Key == e.ID && y.Value > 0))).Select(x => x.Value.FileName);
                    IEnumerable <string> second       = _fieldsWithBattleScripts.Where(x => x.Value == e.ID).Select(x => x.Key);
                    if (second.Any())
                    {
                        if (fieldMatches.Any())
                        {
                            fieldMatches = fieldMatches.Concat(second).Distinct();
                        }
                        else
                        {
                            fieldMatches = second;
                        }
                    }

                    if (fieldMatches.Any())
                    {
                        data += $"\"{string.Join($"{Ls} ", fieldMatches).TrimEnd(Ls[0], ' ')}\"{Ls}";
                    }
                    else if (_worldEncounters.Any(x => x == e.ID))
                    {
                        data += $"\"World Map\"{Ls}";
                    }
                    else if (WorldEncountersLunar.Any(x => x == e.ID))
                    {
                        data += $"\"World Map - Lunar Cry\"{Ls}";
                    }
                    else
                    {
                        data += Ls;
                    }
                    csvFile.WriteLine(data);
                }
            }
        }
Пример #2
0
        internal static async Task Process()
        {
            await Task.WhenAll(Task.Run(() => LoadWorld()), LoadFields(),
                               DumpMonsterAndCharacterDat.LoadMonsters() //load all the monsters.
                               );

            using (var csvFile = new StreamWriter(new FileStream("BattleEncounters.csv", FileMode.Create, FileAccess.Write, FileShare.ReadWrite), System.Text.Encoding.UTF8))
            {
                var header =
                    $"{nameof(Encounter.ID)}{Ls}" +
                    $"{nameof(Encounter.Filename)}{Ls}" +
                    $"{nameof(BattleStageNames)}{Ls}" +
                    $"{nameof(Encounter.BEnemies)}{Ls}" +
                    $"{nameof(Fields)}{Ls}";
                csvFile.WriteLine(header);
                foreach (var e in Memory.Encounters)
                {
                    //wip
                    var data =
                        $"{e.ID}{Ls}" +
                        $"{e.Filename}{Ls}" +
                        $"\"{BattleStageNames[e.Scenario]}\"{Ls}";
                    var enemies = "\"";
                    var unique  = e.UniqueMonstersList;
                    var counts  = e.UniqueMonstersList.Select(x => new KeyValuePair <byte, int>(x, e.EnabledMonsters.Count(y => y.Value == x)));
                    unique.ForEach(x =>
                    {
                        var name = "<unknown>";
                        if (DumpMonsterAndCharacterDat.MonsterData.TryGetValue(x, out var battleDat) && battleDat != null)
                        {
                            name  = battleDat.Information.Name.Value_str.Trim();
                            name += $" ({battleDat.FileName})";
                        }

                        Debug.Assert(enemies != null, nameof(enemies) + " != null");
                        enemies += $"{counts.First(y => y.Key == x).Value} × {name}{Ls} ";
                    });
                    enemies = enemies.TrimEnd(Ls[0], ' ') + "\"";
                    data   += $"{enemies}{Ls}";
                    //check encounters in fields and confirm encounter rate is above 0.
                    if (FieldData != null)
                    {
                        var fieldMatches = FieldData.Where(x => x.Value.MrtRat != null && (x.Value.MrtRat.Any(y => y.Key == e.ID && y.Value > 0))).Select(x => x.Value.FileName);
                        if (_fieldsWithBattleScripts != null)
                        {
                            var second = _fieldsWithBattleScripts.Where(x => x.Value == e.ID).Select(x => x.Key);
                            if (second.Any())
                            {
                                fieldMatches = fieldMatches.Any() ? fieldMatches.Concat(second).Distinct() : second;
                            }
                        }

                        if (fieldMatches.Any())
                        {
                            data += $"\"{string.Join($"{Ls} ", fieldMatches).TrimEnd(Ls[0], ' ')}\"{Ls}";
                        }
                        else if (_worldEncounters.Any(x => x == e.ID))
                        {
                            data += $"\"World Map\"{Ls}";
                        }
                        else if (WorldEncountersLunar.Any(x => x == e.ID))
                        {
                            data += $"\"World Map - Lunar Cry\"{Ls}";
                        }
                        else
                        {
                            data += Ls;
                        }
                    }

                    csvFile.WriteLine(data);
                }
            }
        }