public async Task GenerateLegacyMovesJson() { var json = await PokemonGoGameMasterFileManager.ReadFileAsync(PokemonGoGameMasterFileManager.GameMasterJsonPath); dynamic gameMaster = JsonConvert.DeserializeObject <dynamic>(json); var regex = new Regex(@"^COMBAT_V\d+_MOVE_"); var templates = ((IEnumerable <dynamic>)gameMaster.itemTemplates).Where(t => regex.IsMatch((string)t.templateId)); var moves = new Dictionary <string, bool>(); foreach (dynamic template in templates) { string moveId = (string)template.combatMove.uniqueId; moves.Add(moveId.Replace("_FAST", String.Empty), moveId.EndsWith("_FAST")); } var pvpokeJson = await PvPokeGameMasterFileManager.ReadFileAsync(PvPokeGameMasterFileManager.ActualPvPokeGameMasterJsonPath); var pvpokeGameMaster = JsonConvert.DeserializeObject <PvPokeGameMasterFileManager.GameMasterFile>(pvpokeJson); var legacyMoveCollection = new LegacyMoveCollection(); foreach (var pokemon in pvpokeGameMaster.Pokemon) { var pokemonWithLegacyMoves = new LegacyMoveCollection.PokemonWithLegacyMoves { SpeciesId = pokemon.SpeciesId.Replace("_normal", String.Empty) }; if (pokemon.LegacyMoves != null) { foreach (string legacyMove in pokemon.LegacyMoves) { if (legacyMove.StartsWith("HIDDEN_POWER_") || moves[legacyMove]) { pokemonWithLegacyMoves.LegacyFastMoves.Add(legacyMove); } else { pokemonWithLegacyMoves.LegacyChargeMoves.Add(legacyMove); } } } legacyMoveCollection.Pokemon.Add(pokemonWithLegacyMoves); } string legacyMovesJson = JsonConvert.SerializeObject(legacyMoveCollection, GlobalJsonSerializerSettings.Shared); await FileManager.SaveFileAsync(legacyMovesJson, PokemonGoGameMasterFileManager.LegacyMovesJsonPath); _output.WriteLine(legacyMovesJson); }
public async Task RefreshAllFiles() { await PokemonGoGameMasterFileManager.FetchAndSaveFileAsync(); await PvPokeGameMasterFileManager.FetchAndSaveFileAsync(); await GenerateLegacyMovesJson(); await GenerateDefaultIVsJson(); await GeneratePvPokeGameMasterJson(); foreach (string filePath in Directory.EnumerateFiles(PokemonGoGameMasterFileManager.DataPath).Where(f => f.EndsWith(".json"))) { var json = await FileManager.ReadFileAsync(filePath); var jsonObject = JsonConvert.DeserializeObject <dynamic>(json); var formattedJson = JsonConvert.SerializeObject(jsonObject, GlobalJsonSerializerSettings.Shared); await FileManager.SaveFileAsync(formattedJson, filePath); } }
public async Task GenerateChargeMovesCsv() { var pvpokeJson = await PvPokeGameMasterFileManager.ReadFileAsync(PvPokeGameMasterFileManager.GeneratedPvPokeGameMasterJsonPath); var pvpokeGameMaster = JsonConvert.DeserializeObject <PvPokeGameMasterFileManager.GameMasterFile>(pvpokeJson); using (var writer = new StringWriter()) using (var csv = new CsvWriter(writer)) { var chargeMoves = pvpokeGameMaster.Moves.Where(m => m.Energy > 0).Select(m => new { Move = m.Name, m.Power, m.Energy, Type = m.Type.ToUpperFirstCharacter() }); csv.WriteRecords(chargeMoves); _output.WriteLine(writer.ToString()); } }
public async Task RoundTripPvPokeJson() { PvPokeGameMasterFileManager.GameMasterFile file = await PvPokeGameMasterFileManager.LoadFileAsync(PvPokeGameMasterFileManager.GeneratedPvPokeGameMasterJsonPath); foreach (var pokemonProperty in file.Pokemon) { pokemonProperty.FastMoves = pokemonProperty.FastMoves.OrderBy(m => m).ToList(); pokemonProperty.ChargedMoves = pokemonProperty.ChargedMoves.OrderBy(m => m).ToList(); if (pokemonProperty.LegacyMoves != null) { pokemonProperty.LegacyMoves = pokemonProperty.LegacyMoves.OrderBy(m => m).ToList(); } } file.Pokemon = file.Pokemon.OrderBy(p => p.Dex).ThenBy(p => p.SpeciesId); file.Moves = file.Moves.OrderBy(m => m.Name); string serializedFile = file.ToJson(); _output.WriteLine(serializedFile); //Assert.Equal(json, serializedFile); }
public async Task GenerateDefaultIVsJson() { var pvpokeJson = await PvPokeGameMasterFileManager.ReadFileAsync(PvPokeGameMasterFileManager.ActualPvPokeGameMasterJsonPath); var pvpokeGameMaster = JsonConvert.DeserializeObject <PvPokeGameMasterFileManager.GameMasterFile>(pvpokeJson); var pokemonDefaultIVs = new DefaultIVsCollection(); foreach (PvPokeGameMasterFileManager.GameMasterFile.PokemonProperty pokemon in pvpokeGameMaster.Pokemon) { string speciesId = pokemon.SpeciesId.Replace("_normal", String.Empty); pokemonDefaultIVs.Pokemon[speciesId] = new Dictionary <string, List <decimal> >(); foreach (KeyValuePair <string, List <decimal> > pokemonDefaultIV in pokemon.DefaultIVs) { pokemonDefaultIVs.Pokemon[speciesId][pokemonDefaultIV.Key] = pokemon.DefaultIVs[pokemonDefaultIV.Key]; } } string defaultIVsJson = JsonConvert.SerializeObject(pokemonDefaultIVs, GlobalJsonSerializerSettings.Shared); await FileManager.SaveFileAsync(defaultIVsJson, PokemonGoGameMasterFileManager.DefaultIVsJsonPath); _output.WriteLine(defaultIVsJson); }