public async Task Dex(CommandContext ctx, [Description("Requested Pokemon name or Dex Id."), RemainingText] string pokemon) { if (string.IsNullOrWhiteSpace(pokemon)) { throw new DiscordMessageException("Invalid entry."); } ExplorersEnitity explorersPokemon = GetPokemon(pokemon); DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); builder.AddField("Types", $"{explorersPokemon.PrimaryType}{(explorersPokemon.SecondaryType == TypeEnum.PokemonType.None ? "" : $", {explorersPokemon.SecondaryType}")}", true);
public static void BuildExplorerPokemonData() { List <ExplorersEnitity> pokemonDatas = new List <ExplorersEnitity>(); List <ExplorersEnitity> evoIndexWaiting = new List <ExplorersEnitity>(); List <string> duplicatePokes = new List <string>(); foreach (string file in Directory.GetFiles(PokemonDataFolder)) { File.Delete(file); } foreach (string file in Directory.GetFiles(Path.Combine(Globals.AppPath, "RawPokemonData"), "*.json")) { try { ExplorersEnitity pokemonData = ExplorersEnitity.FromRawData(JsonConvert.DeserializeObject <Pokemon>(File.ReadAllText(file))); pokemonData.RawIndex = Convert.ToInt32(Regex.Match(Path.GetFileNameWithoutExtension(file), @"[0-9]+").Value.TrimStart('0')); pokemonData.Id = new string(pokemonData.Name.Where(e => !Path.GetInvalidPathChars().Contains(e)).ToArray()).ToLower(); if (pokemonData.Category.ToCharArray().Distinct().Count() == 1 && pokemonData.Category.ToCharArray().Distinct().First() == '?') { Console.WriteLine($"Skipped special npc entity {pokemonData.Name}"); continue; } if (pokemonData.DexId == 0) { continue; } bool preEvoFound = false; foreach (GenderEntity pokemonDataGenderEnitity in pokemonData.GenderEnitities) { switch (pokemonDataGenderEnitity.Evolution.Method) { case EvoEnum.EvolutionMethod.CannotEvolve: if (pokemonDataGenderEnitity.Evolution.PreEvoDexId > 0) { Console.WriteLine($"{pokemonData.Name} probably has a special evolution."); } else { preEvoFound = true; continue; } break; } ExplorersEnitity preEvoData = pokemonDatas.FirstOrDefault(e => e.RawIndex == (pokemonDataGenderEnitity.Evolution.PreEvoDexId > 600 ? pokemonDataGenderEnitity.Evolution.PreEvoDexId - 600 : pokemonDataGenderEnitity.Evolution.PreEvoDexId)); if (preEvoData == null) { evoIndexWaiting.Add(pokemonData); preEvoFound = false; break; } pokemonDataGenderEnitity.Evolution.PreEvoDexId = preEvoData.DexId; preEvoFound = true; } if (!preEvoFound) { continue; } if (pokemonDatas.Any(e => e.DexId == pokemonData.DexId)) { ExplorersEnitity similarEntity = pokemonDatas.Find(e => e.DexId == pokemonData.DexId); if (!similarEntity.Id.Contains("-base")) { File.Move(Path.Combine(PokemonDataFolder, $"{similarEntity.Id}.json"), Path.Combine(PokemonDataFolder, $"{similarEntity.Id}-base.json")); similarEntity.Id += "-base"; duplicatePokes.Add(similarEntity.Id); } if (pokemonData.PrimaryType == similarEntity.PrimaryType) { if (pokemonData.SecondaryType == similarEntity.SecondaryType) { if (pokemonData.GenderEnitities.Select(e => e.Gender).SequenceEqual(similarEntity.GenderEnitities.Select(e => e.Gender))) { pokemonData.Id += $"-{pokemonData.RawIndex}"; } else { pokemonData.Id = $"-{pokemonData.GenderEnitities.First().Gender}"; } } else { pokemonData.Id += $"-{pokemonData.SecondaryType}"; } } else { pokemonData.Id += $"-{pokemonData.PrimaryType}"; } pokemonData.Id = pokemonData.Id.ToLower(); duplicatePokes.Add(pokemonData.Id); } pokemonDatas.Add(pokemonData); File.WriteAllText(Path.Combine(PokemonDataFolder, $"{pokemonData.Id}.json"), JsonConvert.SerializeObject(pokemonData, Formatting.Indented)); } catch (Exception e) { if (e.ToString().Contains("DashingWanderer.Data.Pokedex.RawData.Learn[]")) { File.WriteAllText(file, Regex.Replace(File.ReadAllText(file), @"""Learn"": (?<class>\{[^}]+\})", match => $"\"Learn\": [{match.Groups["class"].Captures[0].Value}]", RegexOptions.Singleline)); Console.WriteLine($"Failed on file {file}.\n{e}\nAttempted to implement Learn fix."); continue; } Console.WriteLine($"Failed on file {file}.\n{e}"); } } foreach (ExplorersEnitity pokemonData in evoIndexWaiting) { bool preEvoFound = false; foreach (GenderEntity pokemonDataGenderEnitity in pokemonData.GenderEnitities) { if (pokemonDataGenderEnitity.Evolution.Method == EvoEnum.EvolutionMethod.CannotEvolve) { if (pokemonDataGenderEnitity.Evolution.PreEvoDexId > 0) { Console.WriteLine($"{pokemonData.Name} probably has a special evolution."); } else { preEvoFound = true; continue; } } ExplorersEnitity preEvoData = pokemonDatas.FirstOrDefault(e => e.RawIndex == (pokemonDataGenderEnitity.Evolution.PreEvoDexId > 600 ? pokemonDataGenderEnitity.Evolution.PreEvoDexId - 600 : pokemonDataGenderEnitity.Evolution.PreEvoDexId)); if (preEvoData == null) { Console.WriteLine($"Unable to find preEvo DexId for {pokemonData.Name} with preEvoIndex {pokemonDataGenderEnitity.Evolution.PreEvoDexId}!"); preEvoFound = false; break; } pokemonDataGenderEnitity.Evolution.PreEvoDexId = preEvoData.RawIndex; preEvoFound = true; } if (!preEvoFound) { continue; } if (pokemonDatas.Any(e => e.DexId == pokemonData.DexId)) { ExplorersEnitity similarEntity = pokemonDatas.Find(e => e.DexId == pokemonData.DexId); if (!similarEntity.Id.Contains("-base")) { File.Move(Path.Combine(PokemonDataFolder, $"{similarEntity.Id}.json"), Path.Combine(PokemonDataFolder, "Data", $"{similarEntity.Id}-base.json")); similarEntity.Id += "-base"; duplicatePokes.Add(similarEntity.Id); } if (pokemonData.PrimaryType == similarEntity.PrimaryType) { if (pokemonData.SecondaryType == similarEntity.SecondaryType) { if (pokemonData.GenderEnitities.Select(e => e.Gender).SequenceEqual(similarEntity.GenderEnitities.Select(e => e.Gender))) { pokemonData.Id += $"-{pokemonData.RawIndex}"; } else { pokemonData.Id = $"-{pokemonData.GenderEnitities.First().Gender}"; } } else { pokemonData.Id += $"-{pokemonData.SecondaryType}"; } } else { pokemonData.Id += $"-{pokemonData.PrimaryType}"; } pokemonData.Id = pokemonData.Id.ToLower(); duplicatePokes.Add(pokemonData.Id); } else { pokemonDatas.Add(pokemonData); } File.WriteAllText(Path.Combine(PokemonDataFolder, $"{pokemonData.Id}.json"), JsonConvert.SerializeObject(pokemonData, Formatting.Indented)); } File.WriteAllLines(Path.Combine(PokemonDataFolder, "dupes.log"), duplicatePokes); }