/// <summary> /// Returns the types of the given Pokemon in past version groups, if any. /// </summary> private async Task <List <WithId <Type[]> > > GetTypes(Pokemon pokemon) { var typesList = new List <WithId <Type[]> >(); if (pokemon.PastTypes.Any()) { // determine which version groups need entries var versionGroups = await VersionGroupService.GetAll(); var generationNames = pokemon.PastTypes.Select(pt => pt.Generation.Name); var relevantVersionGroups = versionGroups.Where(vg => generationNames.Contains(vg.Generation.Name)); // ensure we create an entry for only the last version group in the generation var necessaryVersionGroups = relevantVersionGroups.OrderBy(vg => vg.Id) .GroupBy(vg => vg.Generation.Name) .Select(gr => gr.Last()); foreach (var vg in necessaryVersionGroups) { var types = pokemon.PastTypes.Single(t => t.Generation.Name == vg.Generation.Name); var typeEntries = await MinimiseTypes(types.Types); typesList.Add(new WithId <Type[]>(vg.VersionGroupId, typeEntries.ToArray())); } } // always include the newest types var newestId = await VersionGroupService.GetNewestVersionGroupId(); var newestTypeEntries = await MinimiseTypes(pokemon.Types); typesList.Add(new WithId <Type[]>(newestId, newestTypeEntries.ToArray())); return(typesList); }
/// <summary> /// Returns the IDs of the version groups where the given Pokemon species is valid. /// </summary> private async Task <IEnumerable <int> > GetValidity(PokemonSpecies pokemonSpecies) { var versionGroups = await VersionGroupService.GetAll(); return(versionGroups.Where(vg => IsValid(pokemonSpecies, vg)) .Select(vg => vg.VersionGroupId)); }
/// <summary> /// Returns flavour text entries for the given move, indexed by version group ID. /// </summary> private async Task <IEnumerable <WithId <LocalString[]> > > GetFlavourTextEntries(Move move) { var descriptionsList = new List <WithId <LocalString[]> >(); if (move.FlavorTextEntries.Any()) { foreach (var vg in await VersionGroupService.GetAll()) { var relevantDescriptions = move.FlavorTextEntries.Where(f => f.VersionGroup.Name == vg.Name); if (relevantDescriptions.Any()) { var descriptions = relevantDescriptions.Select(d => new LocalString { Language = d.Language.Name, Value = d.FlavorText }); descriptionsList.Add(new WithId <LocalString[]>(vg.VersionGroupId, descriptions.ToArray())); } } } return(descriptionsList); }
/// <summary> /// Returns the given Pokemon form's validity in all version groups. /// </summary> private async Task <IEnumerable <int> > GetValidity(PokemonForm pokemonForm) { var validityList = new List <int>(); foreach (var vg in await VersionGroupService.GetAll()) { var isValid = await IsValid(pokemonForm, vg); if (isValid) { // form is only valid if the version group's ID is in the list validityList.Add(vg.VersionGroupId); } } return(validityList); }
/// <summary> /// Returns the efficacy of the given type in all version groups. /// </summary> private async Task <EfficacyMap> GetEfficacyMap(Type type) { var efficacy = new EfficacyMap(); var versionGroups = await VersionGroupsService.GetAll(); foreach (var vg in versionGroups) { var efficacySet = new EfficacySet(); // populate damage relations - we can do this with the 'from' relations alone var damageRelations = await GetDamageRelations(type, vg.Key); foreach (var typeFrom in damageRelations.DoubleDamageFrom) { var o = await CacheService.Upsert(typeFrom); efficacySet.Add(o.Id, 2); } foreach (var typeFrom in damageRelations.HalfDamageFrom) { var o = await CacheService.Upsert(typeFrom); efficacySet.Add(o.Id, 0.5); } foreach (var typeFrom in damageRelations.NoDamageFrom) { var o = await CacheService.Upsert(typeFrom); efficacySet.Add(o.Id, 0); } efficacy.SetEfficacySet(vg.Key, efficacySet); } return(efficacy); }