private static EvoCriteria[] GetOriginChain(PKM pk, int maxSpecies, byte maxLevel, byte minLevel, bool hasOriginMet) { if (maxLevel < minLevel) { return(Array.Empty <EvoCriteria>()); } if (hasOriginMet) { return(EvolutionChain.GetValidPreEvolutions(pk, maxSpecies, maxLevel, minLevel)); } // Permit the maximum to be all the way up to Current Level; we'll trim these impossible evolutions out later. var tempMax = pk.CurrentLevel; var chain = EvolutionChain.GetValidPreEvolutions(pk, maxSpecies, tempMax, minLevel); for (var i = 0; i < chain.Length; i++) { chain[i] = chain[i] with { LevelMax = maxLevel, LevelMin = minLevel } } ; return(chain); }
/// <summary> /// Gets an object containing met data properties that might be legal. /// </summary> public static EncounterSuggestionData?GetSuggestedMetInfo(PKM pk) { int loc = GetSuggestedTransferLocation(pk); if (pk.WasEgg) { return(GetSuggestedEncounterEgg(pk, loc)); } var chain = EvolutionChain.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true); var w = EncounterSlotGenerator.GetCaptureLocation(pk, chain); var s = EncounterStaticGenerator.GetStaticLocation(pk, chain); if (w is null) { return(s is null ? null : GetSuggestedEncounter(pk, s, loc)); } if (s is null) { return(GetSuggestedEncounter(pk, w, loc)); } bool isDefinitelySlot = chain.Any(z => z.Species == w.Species && z.Form == w.Form); bool isDefinitelyStatic = chain.Any(z => z.Species == s.Species && z.Form == s.Form); IEncounterable obj = (isDefinitelySlot || !isDefinitelyStatic) ? w : s; return(GetSuggestedEncounter(pk, obj, loc)); }
async static void Pokemon(int pokeID) { EvolutionChain e = await DataFetcher.GetApiObject<EvolutionChain>(pokeID); PokemonSpecies p = await DataFetcher.GetApiObject<PokemonSpecies>(pokeID); Console.WriteLine(e.Chain.Species.Name); foreach (var item in e.Chain.EvolvesTo) { Console.WriteLine(item.Species.Name); } }
public async Task GetEvolutionChainResourceAsyncIntegrationTest() { // assemble PokeApiClient client = new PokeApiClient(); // act EvolutionChain evolutionChain = await client.GetResourceAsync <EvolutionChain>(1); // assert Assert.True(evolutionChain.Id != default(int)); }
/// <summary> /// Extrait la chaîne d'évolution d'un <see cref="Pokemon"/>sous la forme d'une chaîne de caractères. /// </summary> /// <param name="evolutionChain">Contient la chaîne d'évolution.</param> public void FormatEvolutionChain(EvolutionChain evolutionChain) { var evolvesToSpecies = new List <string>(); GetSpecies(evolutionChain.Chain.EvolvesTo); // On obtient la chaîne d'évolution de manière récursive void GetSpecies(List <EvolutionChain.ChainLink> chainLinks) { if (chainLinks.Count > 0) { evolvesToSpecies.Add(chainLinks[0].SpeciesResource.Name); GetSpecies(chainLinks[0].EvolvesTo); } } var speciesJoined = evolvesToSpecies.Count > 0 ? string.Join(", ", evolvesToSpecies) : "aucune chaîne d'évolution"; EvolutionChain = speciesJoined; }
internal static async void Evolving(SocketGuildUser user, SocketTextChannel channel) { int selected = Data.PokemonData.GetSelected(user.Id); string pokeName = Data.PokemonData.GetPokemon(user.Id, selected); int level = Data.PokemonData.GetLevel(user.Id, selected); PokeApiClient pokeClient = new PokeApiClient(); Pokemon poke = await pokeClient.GetResourceAsync <Pokemon>(pokeName); EvolutionChain pokeEvolution = await pokeClient.GetResourceAsync <EvolutionChain>(pokeName); if (pokeEvolution.Chain.EvolvesTo.Count >= 1) { if (level >= pokeEvolution.Chain.EvolvesTo[0].EvolutionDetails[0].MinLevel) { await Data.PokemonData.EvolvePokemon(user.Id, selected, pokeEvolution.Chain.EvolvesTo[0].Species.Name); await channel.SendMessageAsync($"Your {Data.PokemonData.GetPokemon(user.Id, selected)} has evolved into {pokeEvolution.Chain.EvolvesTo[0].Species.Name}"); } } }
public static async Task <EvolutionChain> GetEvolution(string url) { if (cache.Contains(url)) { EvolutionChain evolutionChain = (EvolutionChain)cache.Get(url); return(evolutionChain); } else { using HttpResponseMessage response = await ApiHelper.client.GetAsync(url); if (response.IsSuccessStatusCode) { EvolutionChain evolutionChain = await JsonSerializer.DeserializeAsync <EvolutionChain>(await response.Content.ReadAsStreamAsync()); cache.Add(url, evolutionChain, null); return(evolutionChain); } else { throw new Exception(response.ReasonPhrase); } } }
private async void LoadPokemonEvoInfos() { Pokemon pokemonInfo; EvolutionChain evoChain = await pokeClient.GetResourceAsync <EvolutionChain>(evoId); EvoOneList.Clear(); PokeImageBasis = null; PokeImageEvoOne = null; PokeImageEvoTwo = null; try { BasisHeader = EvolutionLanguage.GetBasisHeader(_language); PokemonSpecies pokemonBasis = await pokeClient.GetResourceAsync <PokemonSpecies>(evoChain.Chain.Species.Name); var tempBasis = _pokeList.First(x => x.PokeNameOriginal == pokemonBasis.Name).PokeName; PokemonBasisName = tempBasis; pokemonInfo = await pokeClient.GetResourceAsync <Pokemon>(pokemonBasis.Id); PokeImageBasis = await LoadPokemonEvoPic(pokemonInfo); } catch { PokemonBasisName = ""; } try { // Some Pokemons have more then one first evolution! // So we load allways in a List for (int i = 0; i < evoChain.Chain.EvolvesTo.Count; i++) { PokemonSpecies pokemonEvoOne = await pokeClient.GetResourceAsync <PokemonSpecies>(evoChain.Chain.EvolvesTo[i].Species.Name); var tempEvoOne = _pokeList.First(x => x.PokeNameOriginal == pokemonEvoOne.Name).PokeName; PokemonEvoOneName = tempEvoOne; pokemonInfo = await pokeClient.GetResourceAsync <Pokemon>(pokemonEvoOne.Id); PokeImageEvoOne = await LoadPokemonEvoPic(pokemonInfo); EvoOneList.Add(new EvolutionModel { Name = PokemonEvoOneName, EvoImage = PokeImageEvoOne } ); } if (EvoOneList.Count > 0) { EvoOneHeader = EvolutionLanguage.GetEvoOneHeader(_language); } } catch { PokemonEvoOneName = ""; } try { PokemonSpecies pokemonEvoTwo = await pokeClient.GetResourceAsync <PokemonSpecies>(evoChain.Chain.EvolvesTo[0].EvolvesTo[0].Species.Name); var tempEvoTwo = _pokeList.First(x => x.PokeNameOriginal == pokemonEvoTwo.Name).PokeName; EvoTwoHeader = EvolutionLanguage.GetEvoTwoHeader(_language); PokemonEvoTwoName = tempEvoTwo; pokemonInfo = await pokeClient.GetResourceAsync <Pokemon>(pokemonEvoTwo.Id); PokeImageEvoTwo = await LoadPokemonEvoPic(pokemonInfo); } catch { PokemonEvoTwoName = ""; } NotifyOfPropertyChange(() => BasisHeader); NotifyOfPropertyChange(() => PokemonBasisName); NotifyOfPropertyChange(() => PokeImageBasis); NotifyOfPropertyChange(() => EvoOneHeader); NotifyOfPropertyChange(() => EvoTwoHeader); NotifyOfPropertyChange(() => PokemonEvoTwoName); NotifyOfPropertyChange(() => PokeImageEvoTwo); ShowEvoOne(); CompareSelectedPokemon(); }
public async Task <ActionResult <DetailedPokemonData> > GetPokemonData(string pokemonName) { DetailedPokemonData cacheValue; //LOOK FOR CACHE KEY. if (!_cache.TryGetValue <DetailedPokemonData>(pokemonName, out cacheValue)) { // Key not in cache, so get data. if (pokemonName == null) { return(BadRequest()); } DetailedPokemonData pokeData = new DetailedPokemonData { EvolutionsNames = new List <string>() }; try { var pokemonData = await pokeClient.GetResourceAsync <Pokemon>(pokemonName); if (pokemonData == null) { return(NotFound()); } PokemonSpecies PokemonSpecies = await pokeClient.GetResourceAsync(pokemonData.Species); if (PokemonSpecies == null) { return(NotFound()); } var queryEngDescription = PokemonSpecies.FlavorTextEntries.First(result => result.Language.Name == "en"); pokeData.Description = queryEngDescription.FlavorText.Replace('\n', ' '); var evolutionChainUrl = PokemonSpecies.EvolutionChain.Url; var evolutionChainID = Int32.Parse(evolutionChainUrl.Split("/")[6]); EvolutionChain evolutionChain = await pokeClient.GetResourceAsync <EvolutionChain>(evolutionChainID); if (evolutionChain == null) { return(NotFound()); } var basePokemon = evolutionChain.Chain.Species.Name; pokeData.EvolutionsNames.Add(basePokemon); try { var FirstLevelEvolution = evolutionChain.Chain.EvolvesTo.Select(x => x.Species.Name); pokeData.EvolutionsNames.AddRange(FirstLevelEvolution); var secondLevelEvolution = evolutionChain.Chain.EvolvesTo[0].EvolvesTo.Select(x => x.Species.Name); pokeData.EvolutionsNames.AddRange(secondLevelEvolution); } catch { System.Diagnostics.Debug.Write("No evolutions for this pokemon"); } cacheValue = pokeData; } catch (Exception) { return(BadRequest()); } //Cache expiration in 3 minutes var cacheEntryOptions = new MemoryCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromMinutes(3)); // Save values in cache for a given key. _cache.Set <DetailedPokemonData>(pokemonName, cacheValue, cacheEntryOptions); } return(Ok(cacheValue)); }
/// <summary> /// Returns whether this evolution chain has only one stage. /// </summary> public static bool IsEmpty(this EvolutionChain evolutionChain) { return(!evolutionChain.Chain.EvolvesTo.Any()); }