예제 #1
0
        /// <summary>
        /// Returns an evolution detail entry for the given evolution detail.
        /// </summary>
        private async Task <EvolutionDetailEntry> CreateEvolutionDetailEntry(EvolutionDetail evolutionDetail)
        {
            var item = await ItemService.Upsert(evolutionDetail.Item);

            var trigger = await EvolutionTriggerService.Upsert(evolutionDetail.Trigger);

            var heldItem = await ItemService.Upsert(evolutionDetail.HeldItem);

            var knownMove = await MoveService.Upsert(evolutionDetail.KnownMove);

            var knownMoveType = await TypeService.Upsert(evolutionDetail.KnownMoveType);

            var location = await LocationService.Upsert(evolutionDetail.Location);

            var partySpecies = await PokemonSpeciesService.Upsert(evolutionDetail.PartySpecies);

            var partyType = await TypeService.Upsert(evolutionDetail.PartyType);

            var tradeSpecies = await PokemonSpeciesService.Upsert(evolutionDetail.TradeSpecies);

            return(new EvolutionDetailEntry
            {
                Item = item?.ForEvolutionChain(),
                Trigger = trigger?.ForEvolutionChain(),
                Gender = evolutionDetail.Gender,
                HeldItem = heldItem?.ForEvolutionChain(),
                KnownMove = knownMove?.ForEvolutionChain(),
                KnownMoveType = knownMoveType?.ForEvolutionChain(),
                Location = location?.ForEvolutionChain(),
                MinLevel = evolutionDetail.MinLevel,
                MinHappiness = evolutionDetail.MinHappiness,
                MinBeauty = evolutionDetail.MinBeauty,
                MinAffection = evolutionDetail.MinAffection,
                NeedsOverworldRain = evolutionDetail.NeedsOverworldRain,
                PartySpecies = partySpecies?.ForEvolutionChain(),
                PartyType = partyType?.ForEvolutionChain(),
                RelativePhysicalStats = evolutionDetail.RelativePhysicalStats,
                TimeOfDay = !string.IsNullOrEmpty(evolutionDetail.TimeOfDay) ? evolutionDetail.TimeOfDay : null,
                TradeSpecies = tradeSpecies?.ForEvolutionChain(),
                TurnUpsideDown = evolutionDetail.TurnUpsideDown
            });
        }
예제 #2
0
        /// <summary>
        /// Returns the moves of the Pokemon with the given ID in the version group with the
        /// given ID from the data store.
        /// </summary>
        public async Task <PokemonMoveContext[]> GetPokemonMoves(int pokemonId, int versionGroupId)
        {
            var resource = await CacheService.Upsert(pokemonId);

            var versionGroup = await VersionGroupService.Upsert(versionGroupId);

            var relevantMoves = resource.Moves.Where(m =>
            {
                var versionGroupNames = m.VersionGroupDetails.Select(d => d.VersionGroup.Name);
                return(versionGroupNames.Contains(versionGroup.Name));
            }).ToArray();

            var moveEntries = await MoveService.UpsertMany(relevantMoves.Select(m => m.Move));

            var entryList = moveEntries.ToList();

            var moveContexts = new List <PokemonMoveContext>();

            for (int i = 0; i < entryList.Count; i++)
            {
                var moveEntry = entryList[i];
                var context   = PokemonMoveContext.From(moveEntry);

                var relevantDetails = relevantMoves[i].VersionGroupDetails
                                      .Where(d => d.VersionGroup.Name == versionGroup.Name);

                var methodList = new List <MoveLearnMethodEntry>();
                foreach (var detail in relevantDetails)
                {
                    var method = await MoveLearnMethodService.Upsert(detail.MoveLearnMethod);

                    if (method.Name == "level-up")
                    {
                        context.Level = detail.LevelLearnedAt;
                    }

                    if (method.Name == "machine")
                    {
                        var machineRefs = moveEntry.Machines.SingleOrDefault(m => m.Id == versionGroupId)?.Data;
                        if (machineRefs.Any())
                        {
                            var machineItems = new List <ItemEntry>();

                            foreach (var m in machineRefs)
                            {
                                var machineEntry = await MachineService.Upsert(m.Id);

                                var machineItem = await ItemService.Upsert(machineEntry.Item.Id);

                                machineItems.Add(machineItem);
                            }

                            context.LearnMachines = machineItems;
                        }
                    }

                    methodList.Add(method);
                }

                context.Methods = methodList;

                moveContexts.Add(context);
            }

            return(moveContexts.ToArray());
        }