コード例 #1
0
        private async Task <ServiceResponse> AddResolvePokemonOrLevelAsync(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, string gymName, string pokemonNameOrLevel, TimeSpan timeSpan, int interactiveLimit, FenceConfiguration[] fences)
        {
            if (int.TryParse(pokemonNameOrLevel, out int raidLevel))
            {
                if (raidLevel < 1)
                {
                    return(new ServiceResponse(false, LocalizationService.Get(textResource, "Raids_Errors_LevelToLow")));
                }
                if (raidLevel > 5)
                {
                    return(new ServiceResponse(false, LocalizationService.Get(textResource, "Raids_Errors_LevelToHigh")));
                }
                return(await AddResolveGymAsync(textResource, requestStartInUtc, userZone, gymName, Convert.ToByte(raidLevel), null, null, timeSpan, interactiveLimit, fences));
            }

            var pokemonResponse = await PokemonService.GetPokemonAndRaidbossAsync(textResource, pokemonNameOrLevel, interactiveLimit, (selectedPokemonName) => AddResolvePokemonOrLevelAsync(textResource, requestStartInUtc, userZone, gymName, selectedPokemonName, timeSpan, interactiveLimit, fences));

            if (!pokemonResponse.IsSuccess)
            {
                return(pokemonResponse);
            }

            var pokemonAndRaidboss = pokemonResponse.Result;
            var pokemon            = pokemonAndRaidboss.Pokemon;
            var raidboss           = pokemonAndRaidboss.Raidboss;

            return(await AddResolveGymAsync(textResource, requestStartInUtc, userZone, gymName, Convert.ToByte(raidboss.Level), pokemon, raidboss, timeSpan, interactiveLimit, fences));
        }
コード例 #2
0
        public async Task <ServiceResponse> HatchAsync(Type textResource, string gymName, string pokemonName, int interactiveLimit, FenceConfiguration[] fences)
        {
            var pokemonResponse = await PokemonService.GetPokemonAndRaidbossAsync(textResource, pokemonName, interactiveLimit, (selectedPokemonName) => HatchAsync(textResource, gymName, selectedPokemonName, interactiveLimit, fences));

            if (!pokemonResponse.IsSuccess)
            {
                return(pokemonResponse);
            }

            var pokemonAndRaidboss = pokemonResponse.Result;
            var pokemon            = pokemonAndRaidboss.Pokemon;
            var raidboss           = pokemonAndRaidboss.Raidboss;

            return(await HatchResolveGymAsync(textResource, gymName, pokemon, raidboss, interactiveLimit, fences));
        }
コード例 #3
0
        private async Task <OcrResult <RaidbossPokemon> > GetPokemon(Image <Rgba32> imageFragment, RaidImageConfiguration imageConfiguration, int interactiveLimit)
        {
            imageFragment = imageConfiguration.PreProcessPokemonNameFragment(imageFragment);

            var ocrResult = await GetOcrResultAsync(imageFragment);

            if (!(ocrResult.Value > 0))
            {
                return(new OcrResult <RaidbossPokemon>(false, ocrResult.Key));
            }
            var similarPokemon = PokemonService.GetSimilarRaidbossByNameAsync(ocrResult.Key, interactiveLimit * 2).Result;

            if (similarPokemon.Count == 0)
            {
                return(new OcrResult <RaidbossPokemon>(false, ocrResult.Key));
            }
            var results = similarPokemon.Select(kvp => new KeyValuePair <RaidbossPokemon, double>(kvp.Key, kvp.Value)).ToArray();

            return(new OcrResult <RaidbossPokemon> (true, ocrResult.Key, results));
        }
コード例 #4
0
        public async Task <ServiceResponse> GetRaidList(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, string pokemonNameOrLevel, FenceConfiguration[] fences, string orderType, int interactiveLimit, Func <RaidListInfo, string> formatResult)
        {
            var order     = GetRaidListOrder(orderType);
            var startTime = Instant.FromDateTimeUtc(new DateTime(2018, 5, 1, 0, 0, 0).ToUniversalTime()).ToUnixTimeSeconds();

            if (int.TryParse(pokemonNameOrLevel, out int raidLevel))
            {
                if (raidLevel < 1)
                {
                    return(new ServiceResponse <RaidListInfo>(false, LocalizationService.Get(textResource, "Raids_Errors_LevelToLow"), null));
                }
                if (raidLevel > 5)
                {
                    return(new ServiceResponse <RaidListInfo>(false, LocalizationService.Get(textResource, "Raids_Errors_LevelToHigh"), null));
                }

                // Query Level
                var raids = await RaidRepository.FindAllWithGymsAsync(e => e.TimeSpawn > startTime && e.Level == raidLevel);

                return(await GetListResult(raidLevel, null, raids, order, formatResult));
            }
            else
            {
                var pokemonResponse = await PokemonService.GetPokemonAndRaidbossAsync(textResource, pokemonNameOrLevel,
                                                                                      interactiveLimit,
                                                                                      (selectedPokemonName) =>
                                                                                      GetRaidList(textResource, requestStartInUtc, userZone, selectedPokemonName, fences, orderType, interactiveLimit, formatResult));

                if (!pokemonResponse.IsSuccess)
                {
                    return(pokemonResponse);
                }

                var pokemonAndRaidboss = pokemonResponse.Result;
                var raidboss           = pokemonAndRaidboss.Raidboss;
                // Query Raidboss
                var raids = await RaidRepository.FindAllWithGymsAsync(e => e.TimeSpawn > startTime && e.PokemonId == raidboss.Id);

                return(await GetListResult(raidboss.Level, pokemonAndRaidboss, raids, order, formatResult));
            }
        }