コード例 #1
0
 /// <summary>
 /// </summary>
 /// <param name="parameter">MapPokemonWrapper containing the Pokemon that we're trying to capture</param>
 /// <param name="mode"></param>
 /// <param name="suspensionState"></param>
 /// <returns></returns>
 public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState)
 {
     if (suspensionState.Any())
     {
         // Recovering the state
         CurrentEncounter     = new EncounterResponse();
         CurrentLureEncounter = new DiskEncounterResponse();
         CurrentCaptureAward  = new CaptureAward();
         SelectedCaptureItem  = new ItemData();
         CurrentPokemon       = JsonConvert.DeserializeObject <IMapPokemon>((string)suspensionState[nameof(CurrentPokemon)]);
         CurrentEncounter.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentEncounter)]).CreateCodedInput());
         CurrentLureEncounter.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentLureEncounter)]).CreateCodedInput());
         CurrentCaptureAward.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentCaptureAward)]).CreateCodedInput());
         SelectedCaptureItem.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(SelectedCaptureItem)]).CreateCodedInput());
         RaisePropertyChanged(() => CurrentEncounter);
         RaisePropertyChanged(() => CurrentLureEncounter);
         RaisePropertyChanged(() => CurrentCaptureAward);
         RaisePropertyChanged(() => SelectedCaptureItem);
     }
     else
     {
         // Navigating from game page, so we need to actually load the encounter
         CurrentPokemon = (IMapPokemon)NavigationHelper.NavigationState[nameof(CurrentPokemon)];
         Busy.SetBusy(true, string.Format(Resources.CodeResources.GetString("LoadingEncounterText"), Resources.Pokemon.GetString(CurrentPokemon.PokemonId.ToString())));
         NavigationHelper.NavigationState.Remove(nameof(CurrentPokemon));
         Logger.Write($"Catching {CurrentPokemon.PokemonId}");
         await HandleEncounter();
     }
 }
コード例 #2
0
        private ItemId GetPokeball(DiskEncounterResponse encounter)
        {
            var pokemonCp = encounter?.PokemonData?.Cp;
            var iV        = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.PokemonData));
            var proba     = encounter?.CaptureProbability?.CaptureProbability_.First();

            var pokeBallsCount   = _inventory.GetItemAmountByType(ItemId.ItemPokeBall);
            var greatBallsCount  = _inventory.GetItemAmountByType(ItemId.ItemGreatBall);
            var ultraBallsCount  = _inventory.GetItemAmountByType(ItemId.ItemUltraBall);
            var masterBallsCount = _inventory.GetItemAmountByType(ItemId.ItemMasterBall);

            if (masterBallsCount > 0 && pokemonCp >= 1200)
            {
                return(ItemId.ItemMasterBall);
            }
            if (ultraBallsCount > 0 && pokemonCp >= 1000)
            {
                return(ItemId.ItemUltraBall);
            }
            if (greatBallsCount > 0 && pokemonCp >= 750)
            {
                return(ItemId.ItemGreatBall);
            }

            if (ultraBallsCount > 0 && iV >= _logicSettings.KeepMinIvPercentage && proba < 0.40)
            {
                return(ItemId.ItemUltraBall);
            }

            if (greatBallsCount > 0 && iV >= _logicSettings.KeepMinIvPercentage && proba < 0.50)
            {
                return(ItemId.ItemGreatBall);
            }

            if (greatBallsCount > 0 && pokemonCp >= 300)
            {
                return(ItemId.ItemGreatBall);
            }

            if (pokeBallsCount > 0)
            {
                return(ItemId.ItemPokeBall);
            }
            if (greatBallsCount > 0)
            {
                return(ItemId.ItemGreatBall);
            }
            if (ultraBallsCount > 0)
            {
                return(ItemId.ItemUltraBall);
            }
            if (masterBallsCount > 0)
            {
                return(ItemId.ItemMasterBall);
            }

            return(ItemId.ItemUnknown);
        }
コード例 #3
0
 public async Task CatchPokemon(ulong encounterId, string id, DiskEncounterResponse encounter, PokemonId pokemonId)
 {
     CatchPokemonResponse caughtPokemonResponse;
     var attempts = 0;
     do
     {
         var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
         var pokeball = GetPokeball(encounter);
         caughtPokemonResponse =
             await _apiEncounter.CatchPokemon(encounterId, id, pokeball);
         logger.Info($"[{caughtPokemonResponse.Status} - {attempts}] {pokemonId} encountered. {PokemonInfo.CalculatePokemonPerfection(encounter?.PokemonData)}% perfect. {encounter?.PokemonData?.Cp} CP. Probabilty: {probability}");
         attempts++;
     } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
              caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
 }
コード例 #4
0
        private async Task CatchEncounter(DiskEncounterResponse encounter, PokemonData pokemon, ulong encounterId, string locationGUID)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;

            do
            {
                //var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();

                var pokeball = ItemId.ItemPokeBall;
                if (pokeball == ItemId.ItemUnknown)
                {
                    Logger.Write(
                        $"No Pokeballs - We missed a {pokemon.PokemonId} with CP {pokemon.Cp}",
                        LogLevel.Caught);
                    return;
                }

                caughtPokemonResponse =
                    await
                    _client.CatchPokemon(encounterId, locationGUID, pokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (var xp in caughtPokemonResponse.CaptureAward.Xp)
                    {
                        _stats.AddExperience(xp);
                    }
                    _stats.IncreasePokemons();
                    var profile = await _client.GetPlayer();

                    _stats.GetStardust(profile.PlayerData.Currencies.ToArray()[1].Amount);
                }
                _stats.UpdateConsoleTitle(_inventory);

                var catchStatus = attemptCounter > 1
                                                ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}"
                                                : $"{caughtPokemonResponse.Status}";
                Logger.Write(
                    $"(LURED {catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(pokemon)} ({pokemon?.Cp}/{PokemonInfo.CalculateMaxCP(pokemon)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(pokemon)).ToString("0.00")}% perfect)", LogLevel.Caught);

                attemptCounter++;
                await Task.Delay(2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
コード例 #5
0
        private async Task TryCatchLuredPokemon(FortData pokeStop)
        {
            if (pokeStop.LureInfo == null)
            {
                return;
            }

            Logger.Write($"Found lured Pokemon: {pokeStop.LureInfo.ActivePokemonId}. Attempting to encounter.");

            DiskEncounterResponse response = await _client.EncounterLuredPokemon(pokeStop.LureInfo.EncounterId, pokeStop.Id);

            //Check the encounter if it was valid
            if (response.Result != DiskEncounterResponse.Types.Result.Success)
            {
                Logger.Write($"Failed to encounter lured pokemon. Reason: {response.Result}.");
                return;
            }

            Logger.Write($"Encountered a lured pokemon.");

            //It's successful so now we should try to capture it
            await CatchEncounter(response, response.PokemonData, pokeStop.LureInfo.EncounterId, pokeStop.Id);
        }
コード例 #6
0
        //Catch lured pokemon
        private async Task <MethodResult> CatchPokemon(FortData fortData)
        {
            if (!_client.LoggedIn)
            {
                MethodResult result = await AcLogin();

                if (!result.Success)
                {
                    return(result);
                }
            }

            if (!CatchDisabled)
            {
                if (RemainingPokeballs() < 1)
                {
                    LogCaller(new LoggerEventArgs("You don't have any pokeball catching (Lure) pokemon will be disabled during " + UserSettings.DisableCatchDelay.ToString(CultureInfo.InvariantCulture) + " minutes.", LoggerTypes.Info));
                    CatchDisabled = true;
                    TimeAutoCatch = DateTime.Now.AddMinutes(UserSettings.DisableCatchDelay);
                    return(new MethodResult());
                }
            }
            else
            {
                return(new MethodResult());
            }

            if (fortData.LureInfo == null || fortData.LureInfo.ActivePokemonId == PokemonId.Missingno)
            {
                return(new MethodResult());
            }

            if (LastedEncountersIds.Contains(fortData.LureInfo.EncounterId))
            {
                return(new MethodResult());
            }

            var response = await _client.ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request
            {
                RequestType    = RequestType.DiskEncounter,
                RequestMessage = new DiskEncounterMessage
                {
                    EncounterId     = fortData.LureInfo.EncounterId,
                    FortId          = fortData.Id,
                    GymLatDegrees   = fortData.Latitude,
                    GymLngDegrees   = fortData.Longitude,
                    PlayerLatitude  = _client.ClientSession.Player.Latitude,
                    PlayerLongitude = _client.ClientSession.Player.Longitude
                }.ToByteString()
            });

            if (response == null)
            {
                return(new MethodResult());
            }

            DiskEncounterResponse eResponse = DiskEncounterResponse.Parser.ParseFrom(response);

            switch (eResponse.Result)
            {
            case DiskEncounterResponse.Types.Result.Success:
                if (LastedEncountersIds.Count > 30)
                {
                    LastedEncountersIds.Clear();
                }

                LastedEncountersIds.Add(eResponse.PokemonData.Id);

                CatchPokemonResponse catchPokemonResponse = null;
                int attemptCount = 1;
                var berryUsed    = false;

                if (eResponse.PokemonData == null || eResponse.PokemonData.PokemonId == PokemonId.Missingno)
                {
                    return(new MethodResult());
                }

                do
                {
                    if (!CatchDisabled)
                    {
                        if (RemainingPokeballs() < 1)
                        {
                            LogCaller(new LoggerEventArgs("You don't have any pokeball catching (Lure) pokemon will be disabled during " + UserSettings.DisableCatchDelay.ToString(CultureInfo.InvariantCulture) + " minutes.", LoggerTypes.Info));
                            CatchDisabled = true;
                            TimeAutoCatch = DateTime.Now.AddMinutes(UserSettings.DisableCatchDelay);
                            return(new MethodResult());
                        }
                    }
                    else
                    {
                        return(new MethodResult());
                    }

                    //Uses lowest capture probability
                    float  probability = eResponse.CaptureProbability.CaptureProbability_[0];
                    ItemId pokeBall    = GetBestBall(eResponse.PokemonData);

                    if (UserSettings.UseBerries)
                    {
                        bool isLowProbability = probability < 0.35;
                        bool isHighCp         = eResponse.PokemonData.Cp > 700;
                        bool isHighPerfection = CalculateIVPerfection(eResponse.PokemonData) > 90;

                        if (!berryUsed)
                        {
                            if ((isLowProbability && isHighCp) || isHighPerfection)
                            {
                                await UseBerry(fortData.LureInfo.EncounterId, fortData.Id, ItemId.ItemRazzBerry);

                                berryUsed = true;
                            }
                            else
                            {
                                bool isHighProbability = probability > 0.65;
                                var  catchSettings     = UserSettings.CatchSettings.FirstOrDefault(x => x.Id == eResponse.PokemonData.PokemonId);
                                if (isHighProbability && catchSettings.UsePinap)
                                {
                                    await UseBerry(fortData.LureInfo.EncounterId, fortData.Id, ItemId.ItemPinapBerry);

                                    berryUsed = true;
                                }
                                else if (new Random().Next(0, 100) < 50)
                                {
                                    // IF we dont use razz neither use pinap, then we will use nanab randomly the 50% of times.
                                    await UseBerry(fortData.LureInfo.EncounterId, fortData.Id, ItemId.ItemNanabBerry);

                                    berryUsed = true;
                                }
                            }
                        }
                    }

                    double reticuleSize      = 1.95;
                    bool   hitInsideReticule = true;

                    //Humanization
                    if (UserSettings.EnableHumanization)
                    {
                        reticuleSize      = (double)_rand.Next(10, 195) / 100;
                        hitInsideReticule = HitInsideReticle();
                    }

                    //End humanization
                    var arPlusValues = new ARPlusEncounterValues();
                    if (UserSettings.GetArBonus)
                    {
                        LogCaller(new LoggerEventArgs("Using AR Bonus Values", LoggerTypes.Debug));
                        arPlusValues.Awareness         = (float)UserSettings.ARBonusAwareness;
                        arPlusValues.Proximity         = (float)UserSettings.ARBonusProximity;
                        arPlusValues.PokemonFrightened = false;
                    }

                    if (!_client.LoggedIn)
                    {
                        MethodResult result = await AcLogin();

                        if (!result.Success)
                        {
                            return(result);
                        }
                    }

                    var catchresponse = await _client.ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request
                    {
                        RequestType    = RequestType.CatchPokemon,
                        RequestMessage = new CatchPokemonMessage
                        {
                            ArPlusValues          = arPlusValues,
                            EncounterId           = fortData.LureInfo.EncounterId,
                            HitPokemon            = hitInsideReticule,
                            NormalizedHitPosition = 1,
                            NormalizedReticleSize = reticuleSize,
                            Pokeball     = pokeBall,
                            SpawnPointId = fortData.Id,
                            SpinModifier = 1
                        }.ToByteString()
                    });

                    if (catchresponse == null)
                    {
                        return(new MethodResult());
                    }

                    catchPokemonResponse = CatchPokemonResponse.Parser.ParseFrom(catchresponse);
                    string pokemon      = String.Format("Name: {0}, CP: {1}, IV: {2:0.00}%", fortData.LureInfo.ActivePokemonId, eResponse.PokemonData.Cp, CalculateIVPerfection(eResponse.PokemonData));
                    string pokeBallName = pokeBall.ToString().Replace("Item", "");

                    switch (catchPokemonResponse.Status)
                    {
                    case CatchPokemonResponse.Types.CatchStatus.CatchError:
                        LogCaller(new LoggerEventArgs(String.Format("Unknown Error. {0}. Attempt #{1}. Status: {2}", pokemon, attemptCount, catchPokemonResponse.Status), LoggerTypes.Warning));
                        continue;

                    case CatchPokemonResponse.Types.CatchStatus.CatchEscape:
                        //If we get this response, means we're good
                        _fleeingPokemonResponses = 0;
                        _potentialPokemonBan     = false;

                        if (AccountState == AccountState.SoftBan || AccountState == AccountState.HashIssues)
                        {
                            AccountState = AccountState.Good;

                            LogCaller(new LoggerEventArgs("Pokemon ban was lifted", LoggerTypes.Info));
                        }

                        LogCaller(new LoggerEventArgs(String.Format("Escaped ball. {0}. Attempt #{1}. Ball: {2}", pokemon, attemptCount, pokeBallName), LoggerTypes.PokemonEscape));
                        continue;

                    case CatchPokemonResponse.Types.CatchStatus.CatchFlee:
                        ++_fleeingPokemonResponses;
                        LogCaller(new LoggerEventArgs(String.Format("Pokemon fled. {0}. Attempt #{1}. Ball: {2}", pokemon, attemptCount, pokeBallName), LoggerTypes.PokemonFlee));
                        continue;

                    case CatchPokemonResponse.Types.CatchStatus.CatchMissed:
                        LogCaller(new LoggerEventArgs(String.Format("Missed. {0}. Attempt #{1}. Status: {2}", pokemon, attemptCount, catchPokemonResponse.Status), LoggerTypes.Warning));
                        continue;

                    case CatchPokemonResponse.Types.CatchStatus.CatchSuccess:
                        int expGained   = catchPokemonResponse.CaptureAward.Xp.Sum();
                        int candyGained = catchPokemonResponse.CaptureAward.Candy.Sum();

                        Tracker.AddValues(1, 0);

                        ExpIncrease(expGained);

                        //_expGained += expGained;

                        fortData.LureInfo = null;

                        LogCaller(new LoggerEventArgs(String.Format("[Lured] Pokemon Caught. {0}. Exp {1}. Candy {2}. Attempt #{3}. Ball: {4}", pokemon, expGained, candyGained, attemptCount, pokeBallName), LoggerTypes.Success));

                        //Auto favorit shiny
                        if (UserSettings.AutoFavoritShiny && eResponse.PokemonData.PokemonDisplay.Shiny)
                        {
                            LogCaller(new LoggerEventArgs(String.Format("[{0}] Pokemon shiny. Auto favorit this pokemon.", eResponse.PokemonData.PokemonId.ToString()), LoggerTypes.Info));
                            await FavoritePokemon(new List <PokemonData> {
                                eResponse.PokemonData
                            }, true);

                            await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom));
                        }

                        //Pokemon.Add(eResponse.PokemonData);
                        UpdateInventory(InventoryRefresh.Pokemon);

                        return(new MethodResult
                        {
                            Message = "Pokemon caught",
                            Success = true
                        });
                    }
                    ++attemptCount;

                    await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom));
                } while (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
                return(new MethodResult());

            case DiskEncounterResponse.Types.Result.EncounterAlreadyFinished:
                break;

            case DiskEncounterResponse.Types.Result.NotAvailable:
                break;

            case DiskEncounterResponse.Types.Result.NotInRange:
                break;

            case DiskEncounterResponse.Types.Result.PokemonInventoryFull:
                break;

            case DiskEncounterResponse.Types.Result.Unknown:
                break;
            }

            if (LastedEncountersIds.Count > 30)
            {
                LastedEncountersIds.Clear();
            }

            LastedEncountersIds.Add(fortData.LureInfo.EncounterId);

            LogCaller(new LoggerEventArgs(String.Format("Faill cath lure on pokestop {0}. {1}.", fortData.Id, eResponse.Result), LoggerTypes.Warning));
            return(new MethodResult());
        }
コード例 #7
0
        private async Task <MethodResult> CatchPokemon(FortData fortData)
        {
            try
            {
                DiskEncounterResponse eResponse = await _client.Encounter.EncounterLurePokemon(fortData.LureInfo.EncounterId, fortData.Id);

                if (eResponse.Result == DiskEncounterResponse.Types.Result.PokemonInventoryFull)
                {
                    LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning));

                    return(new MethodResult
                    {
                        Message = "Encounter failed. Pokemon inventory full"
                    });
                }
                else if (eResponse.Result != DiskEncounterResponse.Types.Result.Success)
                {
                    if (eResponse.Result == DiskEncounterResponse.Types.Result.NotAvailable)
                    {
                        //Ignore
                        return(new MethodResult
                        {
                            Message = "Encounter not available"
                        });
                    }

                    LogCaller(new LoggerEventArgs(String.Format("Lured encounter failed with response {0}", eResponse.Result), LoggerTypes.Warning));

                    return(new MethodResult
                    {
                        Message = "Encounter failed"
                    });
                }

                CatchPokemonResponse catchPokemonResponse = null;
                int attemptCount = 1;

                do
                {
                    //Uses lowest capture probability
                    float  probability = eResponse.CaptureProbability.CaptureProbability_[0];
                    ItemId pokeBall    = GetBestBall(eResponse.PokemonData);

                    if (pokeBall == ItemId.ItemUnknown)
                    {
                        LogCaller(new LoggerEventArgs("No pokeballs remaining", LoggerTypes.Warning));

                        return(new MethodResult
                        {
                            Message = "No pokeballs remaining"
                        });
                    }

                    bool isLowProbability = probability < 0.35;
                    bool isHighCp         = eResponse.PokemonData.Cp > 700;
                    bool isHighPerfection = CalculateIVPerfection(eResponse.PokemonData).Data > 90;

                    if ((isLowProbability && isHighCp) || isHighPerfection)
                    {
                        await UseBerry(fortData.LureInfo.EncounterId, fortData.Id);
                    }

                    catchPokemonResponse = await _client.Encounter.CatchPokemon(fortData.LureInfo.EncounterId, fortData.Id, pokeBall);

                    string pokemon = String.Format("Name: {0}, CP: {1}, IV: {2:0.00}%", fortData.LureInfo.ActivePokemonId, eResponse.PokemonData.Cp, CalculateIVPerfection(eResponse.PokemonData).Data);

                    if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                    {
                        int expGained = catchPokemonResponse.CaptureAward.Xp.Sum();

                        ExpIncrease(expGained);

                        //_expGained += expGained;

                        LogCaller(new LoggerEventArgs(String.Format("Lured Pokemon Caught. {0}. Exp {1}. Attempt #{2}", pokemon, expGained, attemptCount), LoggerTypes.Success));

                        return(new MethodResult
                        {
                            Message = "Pokemon caught",
                            Success = true
                        });
                    }
                    else if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee)
                    {
                        LogCaller(new LoggerEventArgs(String.Format("Pokemon fled. {0}. Attempt #{1}", pokemon, attemptCount), LoggerTypes.PokemonFlee));
                    }
                    else if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape)
                    {
                        LogCaller(new LoggerEventArgs(String.Format("Escaped ball. {0}. Attempt #{1}.", pokemon, attemptCount), LoggerTypes.PokemonEscape));
                    }
                    else
                    {
                        LogCaller(new LoggerEventArgs(String.Format("Unknown Error. {0}. Attempt #{1}. Status: {2}", pokemon, attemptCount, catchPokemonResponse.Status), LoggerTypes.Warning));
                    }

                    ++attemptCount;

                    await Task.Delay(1000);
                } while (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
            }
            catch (Exception ex)
            {
                LogCaller(new LoggerEventArgs("Failed to catch lured pokemon due to error", LoggerTypes.Exception, ex));

                return(new MethodResult
                {
                    Message = "Failed to catch lured pokemon"
                });
            }

            return(new MethodResult
            {
                Message = "Failed to catch lured pokemon",
                Success = true
            });
        }
コード例 #8
0
        private ItemId GetPokeball(DiskEncounterResponse encounter)
        {
            var pokemonCp = encounter?.PokemonData?.Cp;
            var iV = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.PokemonData));
            var proba = encounter?.CaptureProbability?.CaptureProbability_.First();

            var pokeBallsCount = _inventory.GetItemAmountByType(ItemId.ItemPokeBall);
            var greatBallsCount = _inventory.GetItemAmountByType(ItemId.ItemGreatBall);
            var ultraBallsCount = _inventory.GetItemAmountByType(ItemId.ItemUltraBall);
            var masterBallsCount = _inventory.GetItemAmountByType(ItemId.ItemMasterBall);

            if (masterBallsCount > 0 && pokemonCp >= 1200)
                return ItemId.ItemMasterBall;
            if (ultraBallsCount > 0 && pokemonCp >= 1000)
                return ItemId.ItemUltraBall;
            if (greatBallsCount > 0 && pokemonCp >= 750)
                return ItemId.ItemGreatBall;

            if (ultraBallsCount > 0 && iV >= _logicSettings.KeepMinIvPercentage && proba < 0.40)
                return ItemId.ItemUltraBall;

            if (greatBallsCount > 0 && iV >= _logicSettings.KeepMinIvPercentage && proba < 0.50)
                return ItemId.ItemGreatBall;

            if (greatBallsCount > 0 && pokemonCp >= 300)
                return ItemId.ItemGreatBall;

            if (pokeBallsCount > 0)
                return ItemId.ItemPokeBall;
            if (greatBallsCount > 0)
                return ItemId.ItemGreatBall;
            if (ultraBallsCount > 0)
                return ItemId.ItemUltraBall;
            if (masterBallsCount > 0)
                return ItemId.ItemMasterBall;

            return ItemId.ItemUnknown;
        }
コード例 #9
0
 /// <summary>
 /// Provides a safe way to invoke the <see cref="DiskEncounterReceived" /> event.
 /// </summary>
 /// <param name="value"></param>
 public void RaiseDiskEncounterReceived(DiskEncounterResponse value) => DiskEncounterReceived?.Invoke(this, value);
コード例 #10
0
        //Catch lured pokemon
        private async Task <MethodResult> CatchPokemon(FortData fortData)
        {
            var response = await _client.ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request
            {
                RequestType    = RequestType.DiskEncounter,
                RequestMessage = new DiskEncounterMessage
                {
                    EncounterId     = fortData.LureInfo.EncounterId,
                    FortId          = fortData.Id,
                    GymLatDegrees   = fortData.Latitude,
                    GymLngDegrees   = fortData.Longitude,
                    PlayerLatitude  = _client.ClientSession.Player.Latitude,
                    PlayerLongitude = _client.ClientSession.Player.Longitude
                }.ToByteString()
            });

            if (response == null)
            {
                return(new MethodResult());
            }

            DiskEncounterResponse eResponse = DiskEncounterResponse.Parser.ParseFrom(response);

            switch (eResponse.Result)
            {
            case DiskEncounterResponse.Types.Result.Success:
                CatchPokemonResponse catchPokemonResponse = null;
                int attemptCount = 1;
                var berryUsed    = false;

                do
                {
                    //Uses lowest capture probability
                    float  probability = eResponse.CaptureProbability.CaptureProbability_[0];
                    ItemId pokeBall    = GetBestBall(eResponse.PokemonData);

                    if (pokeBall == ItemId.ItemUnknown)
                    {
                        LogCaller(new LoggerEventArgs("No pokeballs remaining (lure)", LoggerTypes.Warning));

                        return(new MethodResult
                        {
                            Message = "No pokeballs remaining"
                        });
                    }

                    if (UserSettings.UseBerries)
                    {
                        bool isLowProbability = probability < 0.35;
                        bool isHighCp         = eResponse.PokemonData.Cp > 700;
                        bool isHighPerfection = CalculateIVPerfection(eResponse.PokemonData) > 90;

                        if (!berryUsed)
                        {
                            if ((isLowProbability && isHighCp) || isHighPerfection)
                            {
                                await UseBerry(fortData.LureInfo.EncounterId, fortData.Id, ItemId.ItemRazzBerry);

                                berryUsed = true;
                            }
                            else
                            {
                                bool isHighProbability = probability > 0.65;
                                var  catchSettings     = UserSettings.CatchSettings.FirstOrDefault(x => x.Id == eResponse.PokemonData.PokemonId);
                                var  usePinap          = catchSettings != null && catchSettings.UsePinap;
                                if (isHighProbability && usePinap)
                                {
                                    await UseBerry(fortData.LureInfo.EncounterId, fortData.Id, ItemId.ItemPinapBerry);

                                    berryUsed = true;
                                }
                                else if (new Random().Next(0, 100) < 50)
                                {
                                    // IF we dont use razz neither use pinap, then we will use nanab randomly the 50% of times.
                                    await UseBerry(fortData.LureInfo.EncounterId, fortData.Id, ItemId.ItemNanabBerry);

                                    berryUsed = true;
                                }
                            }
                        }
                    }

                    double reticuleSize      = 1.95;
                    bool   hitInsideReticule = true;

                    //Humanization
                    if (UserSettings.EnableHumanization)
                    {
                        reticuleSize      = (double)_rand.Next(10, 195) / 100;
                        hitInsideReticule = HitInsideReticle();
                    }

                    //End humanization
                    var arPlusValues = new ARPlusEncounterValues();
                    if (UserSettings.GetArBonus)
                    {
                        LogCaller(new LoggerEventArgs("Using AR Bonus Values", LoggerTypes.Debug));
                        arPlusValues.Awareness         = (float)UserSettings.ARBonusAwareness;
                        arPlusValues.Proximity         = (float)UserSettings.ARBonusProximity;
                        arPlusValues.PokemonFrightened = false;
                    }

                    var catchresponse = await _client.ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request
                    {
                        RequestType    = RequestType.CatchPokemon,
                        RequestMessage = new CatchPokemonMessage
                        {
                            ArPlusValues          = arPlusValues,
                            EncounterId           = fortData.LureInfo.EncounterId,
                            HitPokemon            = hitInsideReticule,
                            NormalizedHitPosition = 1,
                            NormalizedReticleSize = reticuleSize,
                            Pokeball     = pokeBall,
                            SpawnPointId = fortData.Id,
                            SpinModifier = 1
                        }.ToByteString()
                    });

                    if (catchresponse == null)
                    {
                        return(new MethodResult());
                    }

                    catchPokemonResponse = CatchPokemonResponse.Parser.ParseFrom(catchresponse);
                    string pokemon      = String.Format("Name: {0}, CP: {1}, IV: {2:0.00}%", fortData.LureInfo.ActivePokemonId, eResponse.PokemonData.Cp, CalculateIVPerfection(eResponse.PokemonData));
                    string pokeBallName = pokeBall.ToString().Replace("Item", "");

                    switch (catchPokemonResponse.Status)
                    {
                    case CatchPokemonResponse.Types.CatchStatus.CatchError:
                        LogCaller(new LoggerEventArgs(String.Format("Unknown Error. {0}. Attempt #{1}. Status: {2}", pokemon, attemptCount, catchPokemonResponse.Status), LoggerTypes.Warning));
                        continue;

                    case CatchPokemonResponse.Types.CatchStatus.CatchEscape:
                        LogCaller(new LoggerEventArgs(String.Format("Escaped ball. {0}. Attempt #{1}.", pokemon, attemptCount), LoggerTypes.PokemonEscape));
                        berryUsed = false;
                        continue;

                    case CatchPokemonResponse.Types.CatchStatus.CatchFlee:
                        LogCaller(new LoggerEventArgs(String.Format("Pokemon fled. {0}. Attempt #{1}", pokemon, attemptCount), LoggerTypes.PokemonFlee));
                        continue;

                    case CatchPokemonResponse.Types.CatchStatus.CatchMissed:
                        LogCaller(new LoggerEventArgs(String.Format("Missed. {0}. Attempt #{1}. Status: {2}", pokemon, attemptCount, catchPokemonResponse.Status), LoggerTypes.Warning));
                        continue;

                    case CatchPokemonResponse.Types.CatchStatus.CatchSuccess:
                        int expGained   = catchPokemonResponse.CaptureAward.Xp.Sum();
                        int candyGained = catchPokemonResponse.CaptureAward.Candy.Sum();

                        Tracker.AddValues(1, 0);

                        ExpIncrease(expGained);

                        //_expGained += expGained;

                        fortData.LureInfo = null;

                        LogCaller(new LoggerEventArgs(String.Format("[Lured] Pokemon Caught. {0}. Exp {1}. Candy {2}. Attempt #{3}. Ball: {4}", pokemon, expGained, candyGained, attemptCount, pokeBallName), LoggerTypes.Success));

                        //Pokemon.Add(eResponse.PokemonData);
                        UpdateInventory(InventoryRefresh.Pokemon);

                        return(new MethodResult
                        {
                            Message = "Pokemon caught",
                            Success = true
                        });
                    }
                    ++attemptCount;

                    await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom));
                } while (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
                break;

            case DiskEncounterResponse.Types.Result.EncounterAlreadyFinished:
                return(new MethodResult
                {
                    Message = "Encounter not available"
                });

            case DiskEncounterResponse.Types.Result.NotAvailable:
                return(new MethodResult
                {
                    Message = "Encounter not available"
                });

            case DiskEncounterResponse.Types.Result.NotInRange:
                LogCaller(new LoggerEventArgs(String.Format("Lured encounter failed with response {0}", eResponse.Result), LoggerTypes.Warning));
                return(new MethodResult
                {
                    Message = "Encounter failed"
                });

            case DiskEncounterResponse.Types.Result.PokemonInventoryFull:
                LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning));

                return(new MethodResult
                {
                    Message = "Encounter failed. Pokemon inventory full"
                });

            case DiskEncounterResponse.Types.Result.Unknown:
                LogCaller(new LoggerEventArgs(String.Format("Lured encounter failed with response {0}", eResponse.Result), LoggerTypes.Warning));

                return(new MethodResult
                {
                    Message = "Encounter failed"
                });
            }
            return(new MethodResult());
        }
コード例 #11
0
        //Catch lured pokemon
        private async Task <MethodResult> CatchPokemon(FortData fortData)
        {
            try
            {
                var response = await ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request
                {
                    RequestType    = RequestType.DiskEncounter,
                    RequestMessage = new DiskEncounterMessage
                    {
                        EncounterId     = fortData.LureInfo.EncounterId,
                        FortId          = fortData.Id,
                        GymLatDegrees   = fortData.Latitude,
                        GymLngDegrees   = fortData.Longitude,
                        PlayerLatitude  = ClientSession.Player.Latitude,
                        PlayerLongitude = ClientSession.Player.Longitude
                    }.ToByteString()
                });

                DiskEncounterResponse eResponse = null;

                eResponse = DiskEncounterResponse.Parser.ParseFrom(response);

                if (eResponse.Result == DiskEncounterResponse.Types.Result.PokemonInventoryFull)
                {
                    LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning));

                    return(new MethodResult
                    {
                        Message = "Encounter failed. Pokemon inventory full"
                    });
                }
                else if (eResponse.Result != DiskEncounterResponse.Types.Result.Success)
                {
                    if (eResponse.Result == DiskEncounterResponse.Types.Result.NotAvailable)
                    {
                        //Ignore
                        return(new MethodResult
                        {
                            Message = "Encounter not available"
                        });
                    }

                    LogCaller(new LoggerEventArgs(String.Format("Lured encounter failed with response {0}", eResponse.Result), LoggerTypes.Warning));

                    return(new MethodResult
                    {
                        Message = "Encounter failed"
                    });
                }

                CatchPokemonResponse catchPokemonResponse = null;
                int attemptCount = 1;

                do
                {
                    //Uses lowest capture probability
                    float  probability = eResponse.CaptureProbability.CaptureProbability_[0];
                    ItemId pokeBall    = await GetBestBall(eResponse.PokemonData);

                    if (pokeBall == ItemId.ItemUnknown)
                    {
                        LogCaller(new LoggerEventArgs("No pokeballs remaining (lure)", LoggerTypes.Warning));

                        return(new MethodResult
                        {
                            Message = "No pokeballs remaining"
                        });
                    }

                    bool isLowProbability = probability < 0.35;
                    bool isHighCp         = eResponse.PokemonData.Cp > 700;
                    bool isHighPerfection = CalculateIVPerfection(eResponse.PokemonData).Data > 90;

                    if ((isLowProbability && isHighCp) || isHighPerfection)
                    {
                        await UseBerry(fortData.LureInfo.EncounterId, fortData.Id);
                    }

                    double reticuleSize      = 1.95;
                    bool   hitInsideReticule = true;

                    //Humanization
                    if (UserSettings.EnableHumanization)
                    {
                        reticuleSize      = (double)_rand.Next(10, 195) / 100;
                        hitInsideReticule = HitInsideReticle();
                    }

                    //End humanization
                    var catchresponse = await ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request
                    {
                        RequestType    = RequestType.CatchPokemon,
                        RequestMessage = new CatchPokemonMessage
                        {
                            EncounterId           = fortData.LureInfo.EncounterId,
                            HitPokemon            = hitInsideReticule,
                            NormalizedHitPosition = 1,
                            NormalizedReticleSize = reticuleSize,
                            Pokeball     = pokeBall,
                            SpawnPointId = fortData.Id,
                            SpinModifier = 1
                        }.ToByteString()
                    });

                    catchPokemonResponse = CatchPokemonResponse.Parser.ParseFrom(catchresponse);
                    string pokemon = String.Format("Name: {0}, CP: {1}, IV: {2:0.00}%", fortData.LureInfo.ActivePokemonId, eResponse.PokemonData.Cp, CalculateIVPerfection(eResponse.PokemonData).Data);

                    if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                    {
                        int expGained = catchPokemonResponse.CaptureAward.Xp.Sum();

                        Tracker.AddValues(1, 0);

                        ExpIncrease(expGained);

                        //_expGained += expGained;

                        LogCaller(new LoggerEventArgs(String.Format("Lured Pokemon Caught. {0}. Exp {1}. Attempt #{2}", pokemon, expGained, attemptCount), LoggerTypes.Success));

                        return(new MethodResult
                        {
                            Message = "Pokemon caught",
                            Success = true
                        });
                    }
                    else if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee)
                    {
                        LogCaller(new LoggerEventArgs(String.Format("Pokemon fled. {0}. Attempt #{1}", pokemon, attemptCount), LoggerTypes.PokemonFlee));
                    }
                    else if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape)
                    {
                        LogCaller(new LoggerEventArgs(String.Format("Escaped ball. {0}. Attempt #{1}.", pokemon, attemptCount), LoggerTypes.PokemonEscape));
                    }
                    else
                    {
                        LogCaller(new LoggerEventArgs(String.Format("Unknown Error. {0}. Attempt #{1}. Status: {2}", pokemon, attemptCount, catchPokemonResponse.Status), LoggerTypes.Warning));
                    }

                    ++attemptCount;

                    await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom));
                } while (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
            }
            catch (Exception ex)
            {
                LogCaller(new LoggerEventArgs("Failed to catch lured pokemon due to error", LoggerTypes.Exception, ex));

                return(new MethodResult
                {
                    Message = "Failed to catch lured pokemon"
                });
            }

            return(new MethodResult
            {
                Message = "Failed to catch lured pokemon",
                Success = true
            });
        }
コード例 #12
0
        public async Task <CatchPokemonResponse> CatchPokemon(ulong encounterId, string id, DiskEncounterResponse encounter, PokemonId pokemonId)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attempts = 0;

            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                var pokeball    = GetPokeball(encounter);

                caughtPokemonResponse =
                    await _apiEncounter.CatchPokemon(encounterId, id, pokeball);

                logger.Info($"[{caughtPokemonResponse.Status} - {attempts}] {pokemonId} encountered. {PokemonInfo.CalculatePokemonPerfection(encounter?.PokemonData)}% perfect. {encounter?.PokemonData?.Cp} CP. Probability: {probability}");
                attempts++;
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
            return(caughtPokemonResponse);
        }
コード例 #13
0
        public async Task <CatchPokemonResponse> CatchPokemon(ulong encounterId, string id, DiskEncounterResponse encounter, PokemonId pokemonId)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attempts = 0;

            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                var pokeball    = GetPokeball(encounter);
                if (pokeball == ItemId.ItemUnknown)
                {
                    logger.Error("Catch failed due to no pokeballs.");
                    return(new CatchPokemonResponse());
                }
                else
                {
                    _inventory.PokeballsDictionary[pokeball] = _inventory.PokeballsDictionary[pokeball] - 1;
                }

                caughtPokemonResponse =
                    await _apiEncounter.CatchPokemon(encounterId, id, pokeball);

                logger.Info($"[{caughtPokemonResponse.Status} - {attempts}] {pokemonId} encountered. {PokemonInfo.CalculatePokemonPerfection(encounter?.PokemonData)}% perfect. {encounter?.PokemonData?.Cp} CP. Probability: {probability}");
                attempts++;
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
            return(caughtPokemonResponse);
        }