private async Task <ServiceResponse> GetListResult(int level, RaidbossPokemon raidbossPokemon, List <IRaid> raids, RaidListOrder order, Func <RaidListInfo, string> formatResult)
        {
            var raidListInfo = new RaidListInfo
            {
                Level           = level,
                RaidbossPokemon = raidbossPokemon,
                Raids           = raids,
                Order           = order
            };

            switch (order)
            {
            case RaidListOrder.StartTime:
                raidListInfo.Raids = raidListInfo.Raids.OrderBy(e => e.TimeSpawn).ToList();
                break;
            }

            var result = formatResult(raidListInfo);

            return(await Task.FromResult(new ServiceResponse <RaidListInfo>(true, result, raidListInfo)));
        }
Esempio n. 2
0
        private async Task <ServiceResponse> InteractiveGymResolve(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, TimeSpan timeLeft, int level, RaidbossPokemon raidbossPokemon, RaidOcrResult raidOcrResult, FenceConfiguration[] fences, int interactiveLimit)
        {
            if (!UseInteractiveMode(raidOcrResult.Gym))
            {
                return(await AddRaidAsync(textResource, requestStartInUtc, userZone, raidOcrResult.Gym.GetFirst().Id, level, raidbossPokemon, timeLeft, raidOcrResult, fences, interactiveLimit));
            }

            if (raidOcrResult.Gym.Results == null || raidOcrResult.Gym.Results.Length == 0)
            {
                return(new ServiceResponse(false, LocalizationService.Get(textResource, "Gyms_Errors_NothingFound", raidOcrResult.Gym.OcrValue)));
            }

            // If the interactive response limit is reached try to select the all gyms with the same name as from the ocr result
            var gyms = raidOcrResult.Gym.Results.Select(e => e.Key).ToList();

            if (gyms.Count > interactiveLimit)
            {
                var ocrString = raidOcrResult.Gym.OcrValue.Trim().ToLowerInvariant();
                gyms = gyms.Where(e => e.Name.Trim().ToLowerInvariant() == ocrString).ToList();
                // If we didn't found any return to the precious state
                if (gyms.Count == 0)
                {
                    gyms = raidOcrResult.Gym.Results.Select(e => e.Key).ToList();
                }
            }

            var gymCallbacks = InteractiveServiceHelper.GenericCreateCallbackAsync(interactiveLimit,
                                                                                   (selectedGym) =>
                                                                                   AddRaidAsync(textResource, requestStartInUtc, userZone, selectedGym, level, raidbossPokemon,
                                                                                                timeLeft, raidOcrResult, fences, interactiveLimit),
                                                                                   gym => gym.Id,
                                                                                   (gym, list) => GymService.GetGymNameWithAdditionAsync(gym, list),
                                                                                   list => LocalizationService.Get(textResource, "Gyms_Errors_ToManyFound", list.Count, raidOcrResult.Gym.OcrValue, interactiveLimit),
                                                                                   list => LocalizationService.Get(textResource, "Gyms_Errors_InteractiveMode", list.Count, raidOcrResult.Gym.OcrValue), gyms);

            return(await gymCallbacks);
        }
Esempio n. 3
0
        private async Task <ServiceResponse> AddRaidAsync(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, int gymId, int level, RaidbossPokemon raidbossPokemon, TimeSpan timeLeft, RaidOcrResult raidOcrResult, FenceConfiguration[] fences, int interactiveLimit)
        {
            IPokemon  pokemon  = null;
            IRaidboss raidboss = null;

            if (raidbossPokemon != null)
            {
                pokemon  = raidbossPokemon.Pokemon;
                raidboss = raidbossPokemon.Raidboss;
            }

            // aka (Unit)TestMode
            if (!SaveDebugImages)
            {
                return(await RaidService.AddResolveGymAsync(textResource, requestStartInUtc, userZone, gymId, (byte)level, pokemon,
                                                            raidboss, timeLeft, interactiveLimit, fences));
            }
            else
            {
                return(await ReturnTestInformation(raidOcrResult));
            }
        }
Esempio n. 4
0
        private async Task <ServiceResponse> InteractiveGymResolve(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, TimeSpan timeLeft, int level, RaidbossPokemon raidbossPokemon, RaidOcrResult raidOcrResult, FenceConfiguration[] fences, int interactiveLimit)
        {
            if (!InteractiveServiceHelper.UseInteractiveMode(raidOcrResult.Gym.Results))
            {
                return(await AddRaidAsync(textResource, requestStartInUtc, userZone, raidOcrResult.Gym.GetFirst().Id, level, raidbossPokemon, timeLeft, raidOcrResult, fences, interactiveLimit));
            }

            if (raidOcrResult.Gym.Results == null || raidOcrResult.Gym.Results.Length == 0)
            {
                return(new ServiceResponse(false, LocalizationService.Get(textResource, "Gyms_Errors_NothingFound", raidOcrResult.Gym.OcrValue)));
            }

            var gymCallbacks = InteractiveServiceHelper.GenericCreateCallbackAsync(interactiveLimit,
                                                                                   (selectedGym) =>
                                                                                   AddRaidAsync(textResource, requestStartInUtc, userZone, selectedGym, level, raidbossPokemon,
                                                                                                timeLeft, raidOcrResult, fences, interactiveLimit),
                                                                                   gym => gym.Id,
                                                                                   (gym, list) => GymService.GetGymNameWithAdditionAsync(gym, list),
                                                                                   list => LocalizationService.Get(textResource, "Gyms_Errors_ToManyFound", list.Count, raidOcrResult.Gym.OcrValue, interactiveLimit),
                                                                                   list => LocalizationService.Get(textResource, "Gyms_Errors_InteractiveMode", list.Count, raidOcrResult.Gym.OcrValue),
                                                                                   raidOcrResult.Gym.Results.Select(e => e.Key).ToList());

            return(await gymCallbacks);
        }