public async Task CatchPokemon(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; var attempts = 0; do { var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var pokeball = GetPokeball(encounter); if (pokeball == ItemId.ItemUnknown) return; var isLowProbability = probability.HasValue && probability.Value < 0.35; var isHighCp = encounter != null && encounter.WildPokemon?.PokemonData?.Cp > 400; var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _logicSettings.KeepMinIvPercentage; if ((isLowProbability && isHighCp) || isHighPerfection) UseBerry(pokemon.EncounterId, pokemon.SpawnPointId); //var distance = LocationUtils.CalculateDistanceInMeters(_navigation.CurrentLatitude, // _navigation.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _apiEncounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball); logger.Info($"[{caughtPokemonResponse.Status} - {attempts}] {pokemon.PokemonId} encountered. {PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)}% perfect. {encounter?.WildPokemon?.PokemonData?.Cp} CP. Probabilty: {probability}"); attempts++; } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); //if (caughtPokemonResponse.Status != CatchPokemonResponse.Types.CatchStatus.CatchSuccess) // logger.Info($"Dude. I tried. I'm sorry, but {pokemon.PokemonId} left. Reason: {caughtPokemonResponse.Status}"); }
public async Task<CatchPokemonResponse> CatchPokemon(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; var attempts = 0; //var r = new Random((int)DateTime.Now.Ticks); //var waitTime = r.Next(100, 3000); do { var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var pokeball = GetPokeball(encounter); if (pokeball == ItemId.ItemUnknown) return new CatchPokemonResponse(); var isLowProbability = probability.HasValue && probability.Value < 0.35; var isHighCp = encounter != null && encounter.WildPokemon?.PokemonData?.Cp > 400; var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _logicSettings.KeepMinIvPercentage; if ((isLowProbability && isHighCp) || isHighPerfection) UseBerry(pokemon.EncounterId, pokemon.SpawnPointId); //var distance = LocationUtils.CalculateDistanceInMeters(_navigation.CurrentLatitude, // _navigation.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); //lock (lockObject) // Thread.Sleep(waitTime); caughtPokemonResponse = await _apiEncounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball); logger.Info($"[{caughtPokemonResponse.Status} - {attempts}] {pokemon.PokemonId} {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData), 1)}% perfect. {encounter?.WildPokemon?.PokemonData?.Cp} CP. Probabilty: {Math.Round((double)probability * 100, 1)} with ball: {pokeball}"); attempts++; } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); return caughtPokemonResponse; }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; do { var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) || CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _clientSettings.KeepMinIVPercentage) { //Throw berry is we can await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId); } var pokeball = await GetBestBall(encounter?.WildPokemon); var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball); Logger.Write( caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"{pokemon.PokemonId} ({encounter?.WildPokemon?.PokemonData?.Cp} CP) ({Math.Round(CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")}% perfection) | Chance: {encounter?.CaptureProbability.CaptureProbability_.First()} | {Math.Round(distance)}m distance | with {pokeball} " : $"{pokemon.PokemonId} ({encounter?.WildPokemon?.PokemonData?.Cp} CP) Chance: {Math.Round(Convert.ToDouble(encounter?.CaptureProbability?.CaptureProbability_.First()))} | {Math.Round(distance)}m distance {caughtPokemonResponse.Status} | with {pokeball}", LogLevel.Caught); await DisplayPlayerLevelInTitle(true); await Task.Delay(2000); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
/// <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(); } }
public static void AddToList(ISession session, EncounterResponse eresponse) { if ((PokemonGradeHelper.GetPokemonGrade(eresponse.WildPokemon.PokemonData.PokemonId) == PokemonGrades.VeryRare || PokemonGradeHelper.GetPokemonGrade(eresponse.WildPokemon.PokemonData.PokemonId) == PokemonGrades.Epic || PokemonGradeHelper.GetPokemonGrade(eresponse.WildPokemon.PokemonData.PokemonId) == PokemonGrades.Legendary)) { //access for rare pokemons } else if (PokemonInfo.CalculatePokemonPerfection(eresponse.WildPokemon.PokemonData) < minIvPercent) { return; } if (LocationQueue.FirstOrDefault(p => p.EncounterId == eresponse.WildPokemon.EncounterId) != null) { return; } using (var newdata = new EncounterInfo()) { newdata.EncounterId = eresponse.WildPokemon.EncounterId; newdata.LastModifiedTimestampMs = eresponse.WildPokemon.LastModifiedTimestampMs; newdata.SpawnPointId = eresponse.WildPokemon.SpawnPointId; newdata.TimeTillHiddenMs = eresponse.WildPokemon.TimeTillHiddenMs; newdata.PokemonId = eresponse.WildPokemon.PokemonData.PokemonId; newdata.Iv = PokemonInfo.CalculatePokemonPerfection(eresponse.WildPokemon.PokemonData); newdata.Latitude = eresponse.WildPokemon.Latitude; newdata.Longitude = eresponse.WildPokemon.Longitude; newdata.Move1 = eresponse.WildPokemon.PokemonData.Move1; newdata.Move2 = eresponse.WildPokemon.PokemonData.Move2; LocationQueue.Add(newdata); } }
public static void AddToList(ISession session, EncounterResponse eresponse) { if (PokemonInfo.CalculatePokemonPerfection(eresponse.WildPokemon.PokemonData) < minIvPercent || session.LogicSettings.PokemonsNotToCatch.Contains(eresponse.WildPokemon.PokemonData.PokemonId) || LocationQueue.FirstOrDefault(p => p.EncounterId == eresponse.WildPokemon.EncounterId) != null || VisitedEncounterIds.Contains(eresponse.WildPokemon.EncounterId)) { return; } using (var newdata = new EncounterInfo()) { newdata.EncounterId = eresponse.WildPokemon.EncounterId; newdata.LastModifiedTimestampMs = eresponse.WildPokemon.LastModifiedTimestampMs; newdata.SpawnPointId = eresponse.WildPokemon.SpawnPointId; newdata.TimeTillHiddenMs = eresponse.WildPokemon.TimeTillHiddenMs; newdata.PokemonId = eresponse.WildPokemon.PokemonData.PokemonId; newdata.Iv = PokemonInfo.CalculatePokemonPerfection(eresponse.WildPokemon.PokemonData); newdata.Latitude = eresponse.WildPokemon.Latitude; newdata.Longitude = eresponse.WildPokemon.Longitude; newdata.Move1 = eresponse.WildPokemon.PokemonData.Move1; newdata.Move2 = eresponse.WildPokemon.PokemonData.Move2; if (LocationQueue.FirstOrDefault(p => p.EncounterId == newdata.EncounterId && p.SpawnPointId == newdata.SpawnPointId) == null)// check 2x { LocationQueue.Add(newdata); } } }
private ItemId GetPokeball(EncounterResponse encounter) { var pokemonCp = encounter?.WildPokemon?.PokemonData?.Cp; var iV = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.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); }
private async Task <ItemId> GetBestBerry(EncounterResponse encounter) { var pokemonCp = encounter?.WildPokemon?.PokemonData?.Cp; var iV = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)); var proba = encounter?.CaptureProbability?.CaptureProbability_.First(); var items = await _inventory.GetItems(); var berries = items.Where(i => ((ItemId)i.Item_ == ItemId.ItemRazzBerry || (ItemId)i.Item_ == ItemId.ItemBlukBerry || (ItemId)i.Item_ == ItemId.ItemNanabBerry || (ItemId)i.Item_ == ItemId.ItemWeparBerry || (ItemId)i.Item_ == ItemId.ItemPinapBerry) && i.Count > 0).GroupBy(i => ((ItemId)i.Item_)).ToList(); if (berries.Count == 0 || pokemonCp <= 350) { return(ItemId.ItemUnknown); } var razzBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_RAZZ_BERRY); var blukBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_BLUK_BERRY); var nanabBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_NANAB_BERRY); var weparBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_WEPAR_BERRY); var pinapBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_PINAP_BERRY); if (pinapBerryCount > 0 && pokemonCp >= 2000) { return(ItemId.ItemPinapBerry); } if (weparBerryCount > 0 && pokemonCp >= 1500) { return(ItemId.ItemWeparBerry); } if (nanabBerryCount > 0 && (pokemonCp >= 1000 || (iV >= _clientSettings.KeepMinIVPercentage && proba < 0.40))) { return(ItemId.ItemNanabBerry); } if (blukBerryCount > 0 && (pokemonCp >= 500 || (iV >= _clientSettings.KeepMinIVPercentage && proba < 0.50))) { return(ItemId.ItemBlukBerry); } if (razzBerryCount > 0 && pokemonCp >= 150) { return(ItemId.ItemRazzBerry); } return(ItemId.ItemUnknown); //return berries.OrderBy(g => g.Key).First().Key; }
private async Task <MethodResult <EncounterResponse> > EncounterPokemon(MapPokemon mapPokemon) { if (mapPokemon.EncounterId == 0 || mapPokemon.ExpirationTimestampMs >= DateTime.UtcNow.ToUnixTime()) { LogCaller(new LoggerEventArgs("Encounter expired....", LoggerTypes.Warning)); return(new MethodResult <EncounterResponse>()); } var response = await _client.ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request { RequestType = RequestType.Encounter, RequestMessage = new EncounterMessage { EncounterId = mapPokemon.EncounterId, PlayerLatitude = _client.ClientSession.Player.Latitude, PlayerLongitude = _client.ClientSession.Player.Longitude, SpawnPointId = mapPokemon.SpawnPointId }.ToByteString() }); EncounterResponse eResponse = null; try { eResponse = EncounterResponse.Parser.ParseFrom(response); } catch (Exception) { LogCaller(new LoggerEventArgs("Encounter expired....", LoggerTypes.Warning)); return(new MethodResult <EncounterResponse>()); } if (eResponse.Status == EncounterResponse.Types.Status.PokemonInventoryFull) { LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed. Pokemon inventory full" }); } if (eResponse.Status == EncounterResponse.Types.Status.EncounterAlreadyHappened) { } if (eResponse.Status != EncounterResponse.Types.Status.EncounterSuccess) { LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed" }); } return(new MethodResult <EncounterResponse> { Data = eResponse, Success = true, Message = "Success" }); }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon, Client client) { CatchPokemonResponse caughtPokemonResponse; do { if (encounter?.CaptureProbability.CaptureProbability_.First() < 0.40) { _logger.Write("Using berry", LogLevel.INFO); await _pokemonItems.UseBerry(pokemon.EncounterId, pokemon.SpawnPointId, client); } var pokeball = await _pokemonItems.GetBestBall(encounter?.WildPokemon, client.Inventory); await Task.Delay(1000); caughtPokemonResponse = await client.Encounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball); await Task.Delay(500); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { var wildPokemon = encounter?.WildPokemon.PokemonData; if (wildPokemon != null) { OnCatch?.Invoke(wildPokemon); OnExperienceAwarded?.Invoke(caughtPokemonResponse.CaptureAward.Xp.Sum(x => x)); var iv = wildPokemon.IndividualAttack + wildPokemon.IndividualDefense + wildPokemon.IndividualStamina; _logger.Write($"Gotcha! {pokemon.PokemonId} - CP: {wildPokemon.Cp}, " + $"IV {iv}", LogLevel.SUCC); if (_settings.Settings.QuickTransfer) { if (_pokemonHelper.ShouldTranferPokemon(wildPokemon, _settings.Settings.IvPercentageDiscart, _settings.Settings.KeepMinCp, _settings.Settings.IvOverCp)) { await _transferPokemonHandler.TransferPokemon(client, wildPokemon, true); } } } else { _logger.Write($"Caught status: {caughtPokemonResponse.Status}", LogLevel.WARN); } } }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; do { var bestBerry = await GetBestBerry(encounter?.WildPokemon); var inventoryBerries = await _inventory.GetItems(); var berries = inventoryBerries.Where(p => (ItemId)p.Item_ == bestBerry).FirstOrDefault();; var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); if (bestBerry != AllEnum.ItemId.ItemUnknown && probability.HasValue && probability.Value < 0.35) { var useRaspberry = await _client.UseCaptureItem(pokemon.EncounterId, bestBerry, pokemon.SpawnpointId); Logger.Normal($"(BERRY) {bestBerry} used, remaining: {berries.Count}"); await RandomHelper.RandomDelay(500, 1000); } var bestPokeball = await GetBestBall(encounter?.WildPokemon); if (bestPokeball == MiscEnums.Item.ITEM_UNKNOWN) { Logger.Normal($"(POKEBATTLE) You don't own any Pokeballs :( - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}"); return; } var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, bestPokeball); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { foreach (int xp in caughtPokemonResponse.Scores.Xp) { _stats.addExperience(xp); } _stats.increasePokemons(); var profile = await _client.GetProfile(); _stats.getStardust(profile.Profile.Currency.ToArray()[1].Amount); } _stats.updateConsoleTitle(_inventory); Logger.Normal(ConsoleColor.Yellow, caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"(POKEBATTLE) We caught a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} ({CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData).ToString("0.00")}% perfect) and CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()}, used {bestPokeball} and received XP {caughtPokemonResponse.Scores.Xp.Sum()}" : $"(POKEBATTLE) {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} {caughtPokemonResponse.Status} while using a {bestPokeball}.." ); await RandomHelper.RandomDelay(1750, 2250); }while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; int attemptCounter = 1; do {//test var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var pokeball = await GetBestBall(encounter?.WildPokemon); if (pokeball == MiscEnums.Item.ITEM_UNKNOWN) { Logger.Write($"No Pokeballs - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Caught); return; } if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) || PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _clientSettings.KeepMinIVPercentage) { await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId); } var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { foreach (int xp in caughtPokemonResponse.Scores.Xp) _stats.AddExperience(xp); _stats.IncreasePokemons(); var profile = await _client.GetProfile(); _stats.GetStardust(profile.Profile.Currency.ToArray()[1].Amount); } _stats.UpdateConsoleTitle(_inventory); if (encounter?.CaptureProbability?.CaptureProbability_ != null) { string catchStatus = attemptCounter > 1 ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}" : $"{caughtPokemonResponse.Status}"; Logger.Write($"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} ({encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")}% perfect) | Chance: {Math.Round(Convert.ToDouble(encounter?.CaptureProbability?.CaptureProbability_.First()) * 100, 2)}% | {Math.Round(distance)}m dist | with {pokeball}", LogLevel.Caught); } attemptCounter++; await Task.Delay(2000); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
private async Task <MethodResult <EncounterResponse> > EncounterPokemon(MapPokemon mapPokemon) { var response = await ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request { RequestType = RequestType.Encounter, RequestMessage = new EncounterMessage { EncounterId = mapPokemon.EncounterId, PlayerLatitude = ClientSession.Player.Latitude, PlayerLongitude = ClientSession.Player.Longitude, SpawnPointId = mapPokemon.SpawnPointId }.ToByteString() }); EncounterResponse eResponse = null; eResponse = EncounterResponse.Parser.ParseFrom(response); if (eResponse.Status == EncounterResponse.Types.Status.PokemonInventoryFull) { LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed. Pokemon inventory full" }); } else if (eResponse.Status != EncounterResponse.Types.Status.EncounterSuccess) { LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed" }); } return(new MethodResult <EncounterResponse> { Data = eResponse, Success = true, Message = "Success" }); }
private static async Task SearchForPokemon(IEnumerable <POGOProtos.Map.Pokemon.MapPokemon> catchable) { if (catchable.Count() > 0) { //POGOProtos.Map.Pokemon.MapPokemon a = catchable.ElementAt(0); POGOProtos.Map.Pokemon.MapPokemon PokemonRequested = catchable.SelectMany(p => catchable.Where(w => w.PokemonId.ToString() == pokemon.PokemonName)).FirstOrDefault(); //.Where(w => w.Latitude == pokemon.Latitude ) //.Where(w => w.Longitude == pokemon.Longtitude); if (PokemonRequested != null) { //string a = ""; try { var responseDetailsBytes = await session.RpcClient.SendRemoteProcedureCallAsync(new Request { RequestType = RequestType.Encounter, RequestMessage = new EncounterMessage { EncounterId = PokemonRequested.EncounterId, SpawnPointId = PokemonRequested.SpawnPointId, PlayerLatitude = PokemonRequested.Latitude, PlayerLongitude = PokemonRequested.Longitude }.ToByteString() }); EncounterResponse DetailsResponse = EncounterResponse.Parser.ParseFrom(responseDetailsBytes); PokemonData pokemondata = DetailsResponse.WildPokemon.PokemonData; int IvSum = pokemondata.IndividualAttack + pokemondata.IndividualDefense + pokemondata.IndividualStamina; pokemon.IV = System.Math.Round(((double)IvSum / 45), 2) * 100; pokemon.CP = pokemondata.Cp; pokemon.Move1 = pokemondata.Move1.ToString(); pokemon.Move2 = pokemondata.Move2.ToString(); } catch { }; pokemon.EncounterId = PokemonRequested.EncounterId; pokemon.SpawnpointId = PokemonRequested.SpawnPointId; } else { string b = ""; } } }
public async Task <CatchPokemonResponse> CatchPokemon(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; var attempts = 0; //var r = new Random((int)DateTime.Now.Ticks); //var waitTime = r.Next(100, 3000); 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; } var isLowProbability = probability.HasValue && probability.Value < 0.35; var isHighCp = encounter != null && encounter.WildPokemon?.PokemonData?.Cp > 400; var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _logicSettings.KeepMinIvPercentage; if ((isLowProbability && isHighCp) || isHighPerfection) { UseBerry(pokemon.EncounterId, pokemon.SpawnPointId); } //var distance = LocationUtils.CalculateDistanceInMeters(_navigation.CurrentLatitude, // _navigation.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); //lock (lockObject) // Thread.Sleep(waitTime); caughtPokemonResponse = await _apiEncounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball); logger.Info($"[{caughtPokemonResponse.Status} - {attempts}] {pokemon.PokemonId} {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData), 1)}% perfect. {encounter?.WildPokemon?.PokemonData?.Cp} CP. Probabilty: {Math.Round((double)probability * 100, 1)} with ball: {pokeball}"); attempts++; } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); return(caughtPokemonResponse); }
private async Task <MethodResult <EncounterResponse> > EncounterPokemon(MapPokemon mapPokemon) { try { EncounterResponse eResponse = await _client.Encounter.EncounterPokemon(mapPokemon.EncounterId, mapPokemon.SpawnPointId); if (eResponse.Status == EncounterResponse.Types.Status.PokemonInventoryFull) { LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed. Pokemon inventory full" }); } else if (eResponse.Status != EncounterResponse.Types.Status.EncounterSuccess) { LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed" }); } return(new MethodResult <EncounterResponse> { Data = eResponse, Success = true, Message = "Success" }); } catch (Exception ex) { LogCaller(new LoggerEventArgs("Failed to encounter pokemon due to error", LoggerTypes.Exception, ex)); return(new MethodResult <EncounterResponse> { Message = "Failed to encounter pokemon" }); } }
public static void AddToList(ISession session, EncounterResponse eresponse) { if ((PokemonGradeHelper.GetPokemonGrade(eresponse.WildPokemon.PokemonData.PokemonId) == PokemonGrades.VeryRare || PokemonGradeHelper.GetPokemonGrade(eresponse.WildPokemon.PokemonData.PokemonId) == PokemonGrades.Epic || PokemonGradeHelper.GetPokemonGrade(eresponse.WildPokemon.PokemonData.PokemonId) == PokemonGrades.Legendary)) { //access for rare pokemons } else if (PokemonInfo.CalculatePokemonPerfection(eresponse.WildPokemon.PokemonData) < minIvPercent) { return; } if (LocationQueue.FirstOrDefault(p => p.EncounterId == eresponse.WildPokemon.EncounterId.ToString()) != null) { return; } using (var newdata = new EncounterInfo()) { newdata.EncounterId = eresponse.WildPokemon.EncounterId.ToString(); newdata.Iv = Math.Round(PokemonInfo.CalculatePokemonPerfection(eresponse.WildPokemon.PokemonData), 2); newdata.Latitude = eresponse.WildPokemon.Latitude.ToString("G17", CultureInfo.InvariantCulture); newdata.Longitude = eresponse.WildPokemon.Longitude.ToString("G17", CultureInfo.InvariantCulture); newdata.PokemonName = eresponse.WildPokemon.PokemonData.PokemonId.ToString(); newdata.SpawnPointId = eresponse.WildPokemon.SpawnPointId; newdata.Move1 = eresponse.WildPokemon.PokemonData.Move1.ToString(); newdata.Move2 = eresponse.WildPokemon.PokemonData.Move2.ToString(); newdata.TimeTillHiddenMs = eresponse.WildPokemon.TimeTillHiddenMs; if (newdata.TimeTillHiddenMs == 0) { Random rn = new Random(); newdata.TimeTillHiddenMs = rn.Next(450, 481) * 1000; } newdata.Expiration = eresponse.WildPokemon.LastModifiedTimestampMs + newdata.TimeTillHiddenMs; LocationQueue.Add(newdata); } }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; do { if (encounter?.CaptureProbability.CaptureProbability_.First() < 0.35) { //Throw berry is we can await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId); } var pokeball = await GetBestBall(encounter?.WildPokemon); var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball); Logger.Write(caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"We caught a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} and CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} using a {pokeball} in {Math.Round(distance)}m distance" : $"{pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} in {Math.Round(distance)}m distance {caughtPokemonResponse.Status} while using a {pokeball}..", LogLevel.Info); await Task.Delay(2000); }while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
private async Task <MiscEnums.Item> GetBestBall(EncounterResponse encounter) { var pokemonCp = encounter?.WildPokemon?.PokemonData?.Cp; var iV = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)); var proba = encounter?.CaptureProbability?.CaptureProbability_.First(); var items = await _inventory.GetItems(); var balls = items.Where(i => ((MiscEnums.Item)i.Item_ == MiscEnums.Item.ITEM_POKE_BALL || (MiscEnums.Item)i.Item_ == MiscEnums.Item.ITEM_GREAT_BALL || (MiscEnums.Item)i.Item_ == MiscEnums.Item.ITEM_ULTRA_BALL || (MiscEnums.Item)i.Item_ == MiscEnums.Item.ITEM_MASTER_BALL) && i.Count > 0).GroupBy(i => ((MiscEnums.Item)i.Item_)).ToList(); if (balls.Count == 0) { return(MiscEnums.Item.ITEM_UNKNOWN); } var pokeBalls = balls.Any(g => g.Key == MiscEnums.Item.ITEM_POKE_BALL); var greatBalls = balls.Any(g => g.Key == MiscEnums.Item.ITEM_GREAT_BALL); var ultraBalls = balls.Any(g => g.Key == MiscEnums.Item.ITEM_ULTRA_BALL); var masterBalls = balls.Any(g => g.Key == MiscEnums.Item.ITEM_MASTER_BALL); if (masterBalls && pokemonCp >= 1500) { return(MiscEnums.Item.ITEM_MASTER_BALL); } if (ultraBalls && (pokemonCp >= 1000 || (iV >= _clientSettings.KeepMinIVPercentage && proba < 0.40))) { return(MiscEnums.Item.ITEM_ULTRA_BALL); } if (greatBalls && (pokemonCp >= 300 || (iV >= _clientSettings.KeepMinIVPercentage && proba < 0.50))) { return(MiscEnums.Item.ITEM_GREAT_BALL); } return(balls.OrderBy(g => g.Key).First().Key); }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; var attemptCounter = 1; do { var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var bestPokeball = await GetBestBall(encounter); if (bestPokeball == MiscEnums.Item.ITEM_UNKNOWN) { Logger.Write($"You don't own any Pokeballs :( - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Warning); return; } var bestBerry = await GetBestBerry(encounter); var inventoryBerries = await _inventory.GetItems(); var berries = inventoryBerries.Where(p => (ItemId)p.Item_ == bestBerry).FirstOrDefault(); if (bestBerry != ItemId.ItemUnknown && probability.HasValue && probability.Value < 0.35) { await _client.UseCaptureItem(pokemon.EncounterId, bestBerry, pokemon.SpawnpointId); berries.Count--; Logger.Write($"{bestBerry} used, remaining: {berries.Count}", LogLevel.Berry); await RandomHelper.RandomDelay(50, 200); } var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, bestPokeball); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { foreach (var xp in caughtPokemonResponse.Scores.Xp) { _stats.AddExperience(xp); } _stats.IncreasePokemons(); var profile = await _client.GetProfile(); _stats.GetStardust(profile.Profile.Currency.ToArray()[1].Amount); } _stats.UpdateConsoleTitle(_client, _inventory); if (encounter?.CaptureProbability?.CaptureProbability_ != null) { Func <MiscEnums.Item, string> returnRealBallName = a => { switch (a) { case MiscEnums.Item.ITEM_POKE_BALL: return("Poke"); case MiscEnums.Item.ITEM_GREAT_BALL: return("Great"); case MiscEnums.Item.ITEM_ULTRA_BALL: return("Ultra"); case MiscEnums.Item.ITEM_MASTER_BALL: return("Master"); default: return("Unknown"); } }; var catchStatus = attemptCounter > 1 ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}" : $"{caughtPokemonResponse.Status}"; string receivedXP = catchStatus == "CatchSuccess" ? $"and received XP {caughtPokemonResponse.Scores.Xp.Sum()}" : $""; Logger.Write($"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} (CP {encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} | {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")} % perfect) | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} | {Math.Round(distance)}m dist | with a {returnRealBallName(bestPokeball)}Ball {receivedXP}", LogLevel.Pokemon); } attemptCounter++; await RandomHelper.RandomDelay(750, 1250); }while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
public static ulong CatchPokemon(ulong encounterId, string spawnpointId, PokemonId pokeid, double pokeLong = 0, double pokeLat = 0, bool goBack = false, double returnLatitude = -1, double returnLongitude = -1, int luredPoke = 0) { ulong ret = 0; EncounterResponse encounterPokemonResponse; //Offset Miss count here to account for user setting. var missCount = 0; if (GlobalVars.Max_Missed_throws <= 1) { missCount = 2; } if (GlobalVars.Max_Missed_throws == 2) { missCount = 1; } var forceHit = false; try { if (luredPoke == 0) { encounterPokemonResponse = client.Encounter.EncounterPokemon(encounterId, spawnpointId).Result; } else if (luredPoke == 1) { var DiscEncounterPokemonResponse = client.Encounter.EncounterLurePokemon(encounterId, spawnpointId); encounterPokemonResponse = new EncounterResponse(); encounterPokemonResponse.Status = DiskEncounterResultToEncounterStatus(DiscEncounterPokemonResponse.Result); if (DiscEncounterPokemonResponse.Result == DiskEncounterResponse.Types.Result.Success) { encounterPokemonResponse.WildPokemon = new WildPokemon(); encounterPokemonResponse.WildPokemon.EncounterId = encounterId; encounterPokemonResponse.WildPokemon.PokemonData = DiscEncounterPokemonResponse.PokemonData; encounterPokemonResponse.CaptureProbability = new POGOProtos.Data.Capture.CaptureProbability(); encounterPokemonResponse.CaptureProbability.CaptureProbability_.Add(1.0F); } } else { var IncenseEncounterPokemonResponse = client.Encounter.EncounterIncensePokemon(encounterId, spawnpointId); encounterPokemonResponse = new EncounterResponse(); encounterPokemonResponse.Status = IncenseEncounterResultToEncounterStatus(IncenseEncounterPokemonResponse.Result); if (IncenseEncounterPokemonResponse.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess) { encounterPokemonResponse.WildPokemon = new WildPokemon(); encounterPokemonResponse.WildPokemon.EncounterId = encounterId; encounterPokemonResponse.WildPokemon.PokemonData = IncenseEncounterPokemonResponse.PokemonData; encounterPokemonResponse.CaptureProbability = IncenseEncounterPokemonResponse.CaptureProbability; } } } catch (Exception ex) { Logger.ColoredConsoleWrite(ConsoleColor.Red, $"Error: Logic.cs - CatchPokemon - encounter: {ex.Message}"); if (goBack) { Logger.ColoredConsoleWrite(ConsoleColor.Cyan, $"(SNIPING) Go to {returnLatitude} / {returnLongitude} before starting the capture."); Logger.ColoredConsoleWrite(ConsoleColor.Cyan, LocationUtils.FindAddress(returnLatitude, returnLongitude)); LocationUtils.updatePlayerLocation(client, returnLatitude, returnLongitude, GlobalVars.altitude); var tmpMap = client.Map.GetMapObjects(true); } return(ret); } if (goBack) { Logger.ColoredConsoleWrite(ConsoleColor.Cyan, $"(SNIPING) Go to {returnLatitude} / {returnLongitude} before starting the capture."); Logger.ColoredConsoleWrite(ConsoleColor.Cyan, LocationUtils.FindAddress(returnLatitude, returnLongitude)); LocationUtils.updatePlayerLocation(client, returnLatitude, returnLongitude, GlobalVars.altitude); var tmpMap = client.Map.GetMapObjects(true); } if (encounterPokemonResponse.Status == EncounterResponse.Types.Status.EncounterSuccess) { if (SkippedPokemon.Contains(encounterPokemonResponse.WildPokemon.EncounterId)) { Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "Previously Skipped this Pokemon - Skipping Again!"); return(0); } var bestPokeball = GetBestBall(encounterPokemonResponse?.WildPokemon, false); var iv = PokemonGo.RocketAPI.PokemonInfo.CalculatePokemonPerfection(encounterPokemonResponse.WildPokemon.PokemonData); var strIVPerfection = iv.ToString("0.00"); if (bestPokeball == ItemId.ItemUnknown) { Logger.ColoredConsoleWrite(ConsoleColor.Red, $"No Pokeballs! - missed {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}%"); Logger.ColoredConsoleWrite(ConsoleColor.Red, "Detected all balls out of stock - disabling pokemon catch until restock of at least 1 ball type occurs"); Logic.Instance.pokeballoutofstock = true; AllowCatchPokemon = false; return(0); } var inventoryBerries = client.Inventory.GetItems(); var probability = encounterPokemonResponse?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var probability100 = Math.Round(probability.Value * 100); Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"Encountered {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}% Probability {probability100}%"); if (encounterPokemonResponse.WildPokemon.PokemonData != null) { SaveLocations(encounterPokemonResponse.WildPokemon, iv, probability100); } if (encounterPokemonResponse.WildPokemon.PokemonData != null && encounterPokemonResponse.WildPokemon.PokemonData.Cp >= GlobalVars.MinCPtoCatch && probability100 >= GlobalVars.MinProbToCatch && iv >= GlobalVars.MinIVtoCatch) { var usedBerry = false; var escaped = false; CatchPokemonResponse caughtPokemonResponse; var inventory = client.Inventory.GetItems(); var razz = inventory.FirstOrDefault(p => p.ItemId == ItemId.ItemRazzBerry); var pinap = inventory.FirstOrDefault(p => p.ItemId == ItemId.ItemPinapBerry); var nanab = inventory.FirstOrDefault(p => p.ItemId == ItemId.ItemNanabBerry); do { // Check if the best ball is still valid if (bestPokeball == ItemId.ItemUnknown) { Logger.ColoredConsoleWrite(ConsoleColor.Red, $"No Pokeballs! - missed {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}%"); Logger.ColoredConsoleWrite(ConsoleColor.Red, "Detected all balls out of stock - disabling pokemon catch until restock of at least 1 ball type occurs"); Logic.Instance.pokeballoutofstock = true; AllowCatchPokemon = false; return(0); } if (GlobalVars.UseRazzBerry && !usedBerry && (probability.Value < GlobalVars.razzberry_chance)) { if (razz != null && razz.Count > 0) { //Throw berry var useRazzberry = client.Encounter.UseItemEncounter(encounterId, ItemId.ItemRazzBerry, spawnpointId); if (useRazzberry.Status == UseItemEncounterResponse.Types.Status.Success) { razz.Count = razz.Count - 1; Logger.Info($"We used a Razz Berry. Remaining: {razz.Count}."); usedBerry = true; } else { Logger.Info("RazzBerry Status: " + useRazzberry.Status); } RandomHelper.RandomSleep(250); } if (!client.Player.PlayerResponse.PlayerData.TutorialState.Contains(TutorialState.PokemonBerry)) { Logic.Instance.Tutorial.MarkTutorialAsDone(TutorialState.PokemonBerry, client); } } if (GlobalVars.PokemonPinap.Contains(pokeid) && !usedBerry) { try { if (pinap != null && pinap.Count > 0) { // Use a pinap var res = client.Encounter.UseItemEncounter(encounterId, ItemId.ItemPinapBerry, spawnpointId); if (res.Status == UseItemEncounterResponse.Types.Status.Success) { pinap.Count = pinap.Count - 1; Logger.Info($"We used a Pinap Berry. Remaining: {pinap.Count}."); usedBerry = true; } else { Logger.Info("PinapBerry Status: " + res.Status); } RandomHelper.RandomSleep(250); } } catch (Exception ex1) { Logger.Debug("" + ex1); } } var r = new Random(); if (GlobalVars.UseNanabBerry && !usedBerry) { try { var reallyUseIt = (r.Next(0, 100) <= GlobalVars.NanabPercent); if (GlobalVars.NanabPercent == 100 || reallyUseIt) { if (nanab != null && nanab.Count > 0) { var res = client.Encounter.UseItemEncounter(encounterId, ItemId.ItemNanabBerry, spawnpointId); if (res.Status == UseItemEncounterResponse.Types.Status.Success) { nanab.Count = nanab.Count - 1; Logger.Info($"We used a Nabab Berry. Remaining: {nanab.Count}."); usedBerry = true; } else { Logger.Info("Status: " + res.Status); } RandomHelper.RandomSleep(250); } } } catch (Exception ex1) { Logger.Debug("" + ex1); } } // limit number of balls wasted by misses and log for UX because fools be tripin switch (missCount) { case 0: if (bestPokeball == ItemId.ItemMasterBall) { Logger.ColoredConsoleWrite(ConsoleColor.Magenta, "No messing around with your Master Balls! Forcing a hit on target."); forceHit = true; } break; case 1: if (bestPokeball == ItemId.ItemUltraBall) { Logger.ColoredConsoleWrite(ConsoleColor.Magenta, "Not wasting more of your Ultra Balls! Forcing a hit on target."); forceHit = true; } break; case 2: //adding another chance of forcing hit here to improve overall odds after 2 misses var rInt = r.Next(0, 2); forceHit |= rInt == 1; break; default: // default to force hit after 3 wasted balls of any kind. Logger.ColoredConsoleWrite(ConsoleColor.Magenta, "Enough misses! Forcing a hit on target."); forceHit = true; break; } if (missCount > 0) { //adding another chance of forcing hit here to improve overall odds after 1st miss var rInt = r.Next(0, 3); if (rInt == 1) { // lets hit forceHit = true; } } caughtPokemonResponse = CatchPokemonWithRandomVariables(encounterId, spawnpointId, bestPokeball, forceHit); if (caughtPokemonResponse == null) { caughtPokemonResponse = new CatchPokemonResponse(); } if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed) { Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"Missed { pokeid} while using {bestPokeball}"); missCount++; RandomHelper.RandomSleep(1500, 3000); } else if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) { Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"{pokeid} escaped while using {bestPokeball}"); usedBerry = false; escaped = true; //reset forceHit in case we randomly triggered on last throw. forceHit = false; RandomHelper.RandomSleep(1500, 3000); } // Update the best ball to ensure we can still throw bestPokeball = GetBestBall(encounterPokemonResponse?.WildPokemon, escaped); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { ret = caughtPokemonResponse.CapturedPokemonId; if (GlobalVars.ShowPokemons) { Logic.Instance.DeletePokemonFromMap(encounterPokemonResponse.WildPokemon.SpawnPointId); } var curDate = DateTime.Now; Task.Factory.StartNew(() => infoObservable.PushNewHuntStats($"{pokeLat}/{pokeLong};{pokeid};{curDate.Ticks};{curDate}" + Environment.NewLine)); var date = DateTime.Now; if (caughtPokemonResponse.CaptureAward.Xp.Sum() >= 500) { if (GlobalVars.LogPokemons) { File.AppendAllText(GlobalVars.FileForPokemonsCaught, $"[{date}] Caught new {pokeid} (CP: {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} | IV: {strIVPerfection}% | Pokeball used: {bestPokeball} | XP: {caughtPokemonResponse.CaptureAward.Xp.Sum()}) " + Environment.NewLine); } Logger.ColoredConsoleWrite(ConsoleColor.Gray, $"Caught {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}% got {caughtPokemonResponse.CaptureAward.Xp.Sum()} XP | {caughtPokemonResponse.CaptureAward.Candy.Sum()} Candies | {caughtPokemonResponse.CaptureAward.Stardust.Sum()} Stardust"); Setout.pokemonCatchCount++; Setout.SaveSession(); // Wrong: TutorialState.PokemonCapture is not for the first wild pokemon caught. // if (!client.Player.PlayerResponse.PlayerData.TutorialState.Contains(TutorialState.PokemonCapture)) Logic.Instance.Tutorial.MarkTutorialAsDone(TutorialState.PokemonCapture, client, pokeid); } else { if (GlobalVars.LogPokemons) { File.AppendAllText(GlobalVars.FileForPokemonsCaught, $"[{date}] Caught {pokeid} (CP: {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} | IV: {strIVPerfection}% | Pokeball used: {bestPokeball} | XP: {caughtPokemonResponse.CaptureAward.Xp.Sum()}) " + Environment.NewLine); } Logger.ColoredConsoleWrite(ConsoleColor.Gray, $"Caught {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}% got {caughtPokemonResponse.CaptureAward.Xp.Sum()} XP | {caughtPokemonResponse.CaptureAward.Candy.Sum()} Candies | {caughtPokemonResponse.CaptureAward.Stardust.Sum()} Stardust"); Setout.pokemonCatchCount++; Setout.SaveSession(); if (Logic.Instance.Telegram != null) { Logic.Instance.Telegram.sendInformationText(TelegramUtil.TelegramUtilInformationTopics.Catch, pokeid, encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp, strIVPerfection, bestPokeball, caughtPokemonResponse.CaptureAward.Xp.Sum()); } } Logic.Instance.BotStats.AddPokemon(1); Logic.Instance.BotStats.AddExperience(caughtPokemonResponse.CaptureAward.Xp.Sum()); Logic.Instance.BotStats.AddStardust(caughtPokemonResponse.CaptureAward.Stardust.Sum()); Setout.RefreshConsoleTitle(client); RandomHelper.RandomSleep(1500, 2000); } else { Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, $"{pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}% got away while using {bestPokeball}.."); Logic.FailedSoftban++; if (Logic.FailedSoftban > 10) { Logger.ColoredConsoleWrite(ConsoleColor.Red, $"Soft Ban Detected - Stopping Bot to prevent perma-ban. Try again in 4-24 hours and be more careful next time!"); Setout.LimitReached(""); } } } else { Logger.ColoredConsoleWrite(ConsoleColor.Magenta, "Pokemon CP or IV or Prob lower than Configured Min to Catch - Skipping Pokemon"); SkippedPokemon.Add(encounterPokemonResponse.WildPokemon.EncounterId); } } else if (encounterPokemonResponse.Status == EncounterResponse.Types.Status.PokemonInventoryFull) { Logger.Warning("You have no free space for new pokemons...transfer some as soon as possible."); } else { Logger.Debug(encounterPokemonResponse.Status.ToString()); } return(ret); }
private ItemId GetPokeball(EncounterResponse encounter) { var pokemonCp = encounter?.WildPokemon?.PokemonData?.Cp; var iV = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.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; }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; do { PokemonData pokeData = encounter?.WildPokemon?.PokemonData; if (encounter?.CaptureProbability.CaptureProbability_.First() < (UserSettings.BerryProbability / 100)) { if (pokeData != null) { if (BerryList.Contains(pokeData.PokemonId)) { await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId); } } } var pokeball = await GetBestBall(encounter?.WildPokemon); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball); Logger.Write(caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"We caught a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} ({CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData).ToString("0.00")}% perfection) using a {pokeball}" : $"{pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} got away while using a {pokeball}..", LogLevel.Info); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { pokeData = encounter?.WildPokemon?.PokemonData; foreach (int xp in caughtPokemonResponse.Scores.Xp) _stats.addExperience(xp); _stats.increasePokemons(); _stats.updateConsoleTitle(_inventory); await Events.PokemonCaught(encounter?.WildPokemon?.PokemonData); } await Task.Delay(rand.Next(1500, 3000)); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed); }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; do { if (encounter?.CaptureProbability.CaptureProbability_.First() < 0.35) { //Throw berry is we can await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId); } var pokeball = await GetBestBall(encounter?.WildPokemon); var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball); Logger.Write(caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"We caught a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} and CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} using a {pokeball} in {Math.Round(distance)}m distance" : $"{pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} in {Math.Round(distance)}m distance {caughtPokemonResponse.Status} while using a {pokeball}..", LogLevel.Info); await Task.Delay(2000); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) ; }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; int attemptCounter = 1; do { var bestBerry = await GetBestBerry(encounter?.WildPokemon); var inventoryBerries = await _inventory.GetItems(); var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var bestPokeball = await GetBestBall(encounter?.WildPokemon); if (bestPokeball == MiscEnums.Item.ITEM_UNKNOWN) { Logger.Write($"You don't own any Pokeballs :( - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Warning); return; } var berries = inventoryBerries.Where(p => (ItemId)p.Item_ == bestBerry).FirstOrDefault(); if (bestBerry != ItemId.ItemUnknown && probability.HasValue && probability.Value < 0.35 && PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _clientSettings.KeepMinIVPercentage) { var useRaspberry = await _client.UseCaptureItem(pokemon.EncounterId, bestBerry, pokemon.SpawnpointId); Logger.Write($"{bestBerry} used, remaining: {berries.Count}", LogLevel.Berry); await RandomHelper.RandomDelay(50, 200); } var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, bestPokeball); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { foreach (int xp in caughtPokemonResponse.Scores.Xp) _stats.AddExperience(xp); _stats.IncreasePokemons(); var profile = await _client.GetProfile(); _stats.GetStardust(profile.Profile.Currency.ToArray()[1].Amount); } _stats.UpdateConsoleTitle(_inventory); if (encounter?.CaptureProbability?.CaptureProbability_ != null) { string catchStatus = attemptCounter > 1 ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}" : $"{caughtPokemonResponse.Status}"; string receivedXP = catchStatus == "CatchSuccess" ? $"and received XP {caughtPokemonResponse.Scores.Xp.Sum()}" : $""; Logger.Write($"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} (CP {encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} | {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")} % perfect) | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} | {Math.Round(distance)}m dist | with {bestPokeball} {receivedXP}", LogLevel.Pokemon); } attemptCounter++; await RandomHelper.RandomDelay(750, 1250); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
/// <summary> /// Provides a safe way to invoke the <see cref="EncounterReceived" /> event. /// </summary> /// <param name="value"></param> public void RaiseEncounterReceived(EncounterResponse value) => EncounterReceived?.Invoke(this, value);
private async Task<ItemId> GetBestBerry(EncounterResponse encounter) { var pokemonCp = encounter?.WildPokemon?.PokemonData?.Cp; var iV = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)); var proba = encounter?.CaptureProbability?.CaptureProbability_.First(); var items = await _inventory.GetItems(); var berries = items.Where(i => ((ItemId)i.Item_ == ItemId.ItemRazzBerry || (ItemId)i.Item_ == ItemId.ItemBlukBerry || (ItemId)i.Item_ == ItemId.ItemNanabBerry || (ItemId)i.Item_ == ItemId.ItemWeparBerry || (ItemId)i.Item_ == ItemId.ItemPinapBerry) && i.Count > 0).GroupBy(i => ((ItemId)i.Item_)).ToList(); if (berries.Count == 0 || pokemonCp < 150) return ItemId.ItemUnknown; var razzBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_RAZZ_BERRY); var blukBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_BLUK_BERRY); var nanabBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_NANAB_BERRY); var weparBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_WEPAR_BERRY); var pinapBerryCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_PINAP_BERRY); if (pinapBerryCount > 0 && pokemonCp >= 2000) return ItemId.ItemPinapBerry; if (weparBerryCount > 0 && pokemonCp >= 1500) return ItemId.ItemWeparBerry; if (nanabBerryCount > 0 && (pokemonCp >= 1000 || (iV >= _clientSettings.TransferPokemonKeepAboveIVPercentage && proba < 0.40))) return ItemId.ItemNanabBerry; if (blukBerryCount > 0 && (pokemonCp >= 500 || (iV >= _clientSettings.TransferPokemonKeepAboveIVPercentage && proba < 0.50))) return ItemId.ItemBlukBerry; if (razzBerryCount > 0 && pokemonCp >= 150) return ItemId.ItemRazzBerry; //return ItemId.ItemUnknown; return berries.OrderBy(g => g.Key).First().Key; }
private async Task<MiscEnums.Item> GetBestBall(EncounterResponse encounter) { var pokemonCp = encounter?.WildPokemon?.PokemonData?.Cp; var iV = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)); var proba = encounter?.CaptureProbability?.CaptureProbability_.First(); var items = await _inventory.GetItems(); var balls = items.Where(i => ((MiscEnums.Item)i.Item_ == MiscEnums.Item.ITEM_POKE_BALL || (MiscEnums.Item)i.Item_ == MiscEnums.Item.ITEM_GREAT_BALL || (MiscEnums.Item)i.Item_ == MiscEnums.Item.ITEM_ULTRA_BALL || (MiscEnums.Item)i.Item_ == MiscEnums.Item.ITEM_MASTER_BALL) && i.Count > 0).GroupBy(i => ((MiscEnums.Item)i.Item_)).ToList(); if (balls.Count == 0) return MiscEnums.Item.ITEM_UNKNOWN; var pokeBalls = balls.Any(g => g.Key == MiscEnums.Item.ITEM_POKE_BALL); var greatBalls = balls.Any(g => g.Key == MiscEnums.Item.ITEM_GREAT_BALL); var ultraBalls = balls.Any(g => g.Key == MiscEnums.Item.ITEM_ULTRA_BALL); var masterBalls = balls.Any(g => g.Key == MiscEnums.Item.ITEM_MASTER_BALL); if (masterBalls && pokemonCp >= 1500) return MiscEnums.Item.ITEM_MASTER_BALL; if (ultraBalls && (pokemonCp >= 1000 || (iV >= _clientSettings.TransferPokemonKeepAboveIVPercentage && proba < 0.40))) return MiscEnums.Item.ITEM_ULTRA_BALL; if (greatBalls && (pokemonCp >= 300 || (iV >= _clientSettings.TransferPokemonKeepAboveIVPercentage && proba < 0.50))) return MiscEnums.Item.ITEM_GREAT_BALL; return balls.OrderBy(g => g.Key).First().Key; }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; var attemptCounter = 1; do { var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var bestPokeball = await GetBestBall(encounter); if (bestPokeball == MiscEnums.Item.ITEM_UNKNOWN) { Logger.Write($"You don't own any Pokeballs :( - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Warning); return; } var bestBerry = await GetBestBerry(encounter); var inventoryBerries = await _inventory.GetItems(); var berries = inventoryBerries.Where(p => (ItemId)p.Item_ == bestBerry).FirstOrDefault(); if (bestBerry != ItemId.ItemUnknown && probability.HasValue && probability.Value < 0.35) { await _client.UseCaptureItem(pokemon.EncounterId, bestBerry, pokemon.SpawnpointId); berries.Count--; Logger.Write($"{bestBerry} used, remaining: {berries.Count}", LogLevel.Berry); } var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, bestPokeball); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { foreach (var xp in caughtPokemonResponse.Scores.Xp) _stats.AddExperience(xp); _stats.IncreasePokemons(); var profile = await _client.GetProfile(); _stats.GetStardust(profile.Profile.Currency.ToArray()[1].Amount); } _stats.UpdateConsoleTitle(_client, _inventory); if (encounter?.CaptureProbability?.CaptureProbability_ != null) { Func<MiscEnums.Item, string> returnRealBallName = a => { switch (a) { case MiscEnums.Item.ITEM_POKE_BALL: return "Poke"; case MiscEnums.Item.ITEM_GREAT_BALL: return "Great"; case MiscEnums.Item.ITEM_ULTRA_BALL: return "Ultra"; case MiscEnums.Item.ITEM_MASTER_BALL: return "Master"; default: return "Unknown"; } }; var catchStatus = attemptCounter > 1 ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}" : $"{caughtPokemonResponse.Status}"; string receivedXP = catchStatus == "CatchSuccess" ? $"and received XP {caughtPokemonResponse.Scores.Xp.Sum()}" : $""; Logger.Write($"({catchStatus}) | {pokemon.PokemonId} - Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} [CP {encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} | IV: {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")}% perfect] | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} | {distance:0.##}m dist | with a {returnRealBallName(bestPokeball)}Ball {receivedXP}", LogLevel.Pokemon); } attemptCounter++; } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
//Catch encountered pokemon private async Task <MethodResult> CatchPokemon(EncounterResponse eResponse, MapPokemon mapPokemon) { try { CatchPokemonResponse catchPokemonResponse = null; int attemptCount = 1; do { //Uses lowest capture probability float probability = eResponse.CaptureProbability.CaptureProbability_[0]; ItemId pokeBall = GetBestBall(eResponse.WildPokemon.PokemonData); if (pokeBall == ItemId.ItemUnknown) { LogCaller(new LoggerEventArgs("No pokeballs remaining (encounter)", LoggerTypes.Warning)); return(new MethodResult { Message = "No pokeballs remaining" }); } bool isLowProbability = probability < 0.40; bool isHighCp = eResponse.WildPokemon.PokemonData.Cp > 800; bool isHighPerfection = CalculateIVPerfection(eResponse.WildPokemon.PokemonData) > 95; if (UserSettings.UseBerries) { if ((isLowProbability && isHighCp) || isHighPerfection) { await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom)); await UseBerry(mapPokemon, ItemId.ItemRazzBerry); } else { bool isHighProbability = probability > 0.65; if (isHighProbability) { await UseBerry(mapPokemon, ItemId.ItemPinapBerry); } 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(mapPokemon, ItemId.ItemNanabBerry); } } } await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom)); double reticuleSize = 1.95; bool hitInsideReticule = true; //Humanization if (UserSettings.EnableHumanization) { reticuleSize = (double)_rand.Next(10, 195) / 100; hitInsideReticule = HitInsideReticle(); } 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 = mapPokemon.EncounterId, HitPokemon = hitInsideReticule, NormalizedHitPosition = 1, NormalizedReticleSize = reticuleSize, Pokeball = pokeBall, SpawnPointId = mapPokemon.SpawnPointId, SpinModifier = 1 }.ToByteString() }); try { catchPokemonResponse = CatchPokemonResponse.Parser.ParseFrom(catchresponse); } catch (Exception) { LogCaller(new LoggerEventArgs("Encounter expired....", LoggerTypes.Warning)); return(new MethodResult()); } string pokemon = String.Format("Name: {0}, CP: {1}, IV: {2:0.00}%", mapPokemon.PokemonId, eResponse.WildPokemon.PokemonData.Cp, CalculateIVPerfection(eResponse.WildPokemon.PokemonData)); string pokeBallName = pokeBall.ToString().Replace("Item", ""); if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { //Reset data _fleeingPokemonResponses = 0; Tracker.AddValues(1, 0); _potentialPokemonBan = false; int expGained = catchPokemonResponse.CaptureAward.Xp.Sum(); int candyGained = catchPokemonResponse.CaptureAward.Candy.Sum(); ExpIncrease(expGained); //_expGained += expGained; //NOTE: To be sure that we don't repeat this encounter, we will delete it from the cell var cell = _client.ClientSession.Map.Cells.FirstOrDefault(x => x.CatchablePokemons.FirstOrDefault(y => y.EncounterId == mapPokemon.EncounterId) != null); if (cell != null) { var mapPokemonFound = cell.CatchablePokemons.FirstOrDefault(y => y.EncounterId == mapPokemon.EncounterId); if (mapPokemonFound != null) { cell.CatchablePokemons.Remove(mapPokemonFound); } } LogCaller(new LoggerEventArgs(String.Format("Caught. {0}. Exp {1}. Candy: {2}. Attempt #{3}. Ball: {4}", pokemon, expGained, candyGained, attemptCount, pokeBallName), LoggerTypes.Success)); return(new MethodResult { Message = "Pokemon caught", Success = true }); } if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee) { ++_fleeingPokemonResponses; LogCaller(new LoggerEventArgs(String.Format("Pokemon fled. {0}. Attempt #{1}. Ball: {2}", pokemon, attemptCount, pokeBallName), LoggerTypes.PokemonFlee)); } else if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) { //If we get this response, means we're good _fleeingPokemonResponses = 0; _potentialPokemonBan = false; if (AccountState == Enums.AccountState.SoftBan) { AccountState = Enums.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)); } 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 pokemon due to error", LoggerTypes.Exception, ex)); return(new MethodResult { Message = "Failed to catch pokemon", Success = true }); } return(new MethodResult { Message = "Failed to catch pokemon", }); }
private async Task<MiscEnums.Item> GetBestBall(EncounterResponse encounter) { var pokemonCp = encounter?.WildPokemon?.PokemonData?.Cp; var iV = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)); var proba = encounter?.CaptureProbability?.CaptureProbability_.First(); var pokeBallsCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_POKE_BALL); var greatBallsCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_GREAT_BALL); var ultraBallsCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_ULTRA_BALL); var masterBallsCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_MASTER_BALL); if (masterBallsCount > 0 && pokemonCp >= 1200) return MiscEnums.Item.ITEM_MASTER_BALL; if (ultraBallsCount > 0 && pokemonCp >= 1000) return MiscEnums.Item.ITEM_ULTRA_BALL; if (greatBallsCount > 0 && pokemonCp >= 750) return MiscEnums.Item.ITEM_GREAT_BALL; if (ultraBallsCount > 0 && iV >= _clientSettings.KeepMinIVPercentage && proba < 0.40) return MiscEnums.Item.ITEM_ULTRA_BALL; if (greatBallsCount > 0 && iV >= _clientSettings.KeepMinIVPercentage && proba < 0.50) return MiscEnums.Item.ITEM_GREAT_BALL; if (greatBallsCount > 0 && pokemonCp >= 300) return MiscEnums.Item.ITEM_GREAT_BALL; if (pokeBallsCount > 0) return MiscEnums.Item.ITEM_POKE_BALL; if (greatBallsCount > 0) return MiscEnums.Item.ITEM_GREAT_BALL; if (ultraBallsCount > 0) return MiscEnums.Item.ITEM_ULTRA_BALL; if (masterBallsCount > 0) return MiscEnums.Item.ITEM_MASTER_BALL; return MiscEnums.Item.ITEM_UNKNOWN; }
public static void Execute(Context ctx, StateMachine machine, EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; var attemptCounter = 1; do { var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var pokeball = GetBestBall(ctx, encounter); if (pokeball == ItemId.ItemUnknown) { machine.Fire(new NoPokeballEvent { Id = pokemon.PokemonId, Cp = encounter?.WildPokemon?.PokemonData?.Cp ?? 0 }); return; } var isLowProbability = probability.HasValue && probability.Value < 0.35; var isHighCp = encounter != null && encounter.WildPokemon?.PokemonData?.Cp > 400; var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= ctx.LogicSettings.KeepMinIvPercentage; if ((isLowProbability && isHighCp) || isHighPerfection) { UseBerry(ctx, machine, pokemon.EncounterId, pokemon.SpawnPointId); } var distance = LocationUtils.CalculateDistanceInMeters(ctx.Client.CurrentLatitude, ctx.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = ctx.Client.Encounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball).Result; var evt = new PokemonCaptureEvent {Status = caughtPokemonResponse.Status}; if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { var totalExp = 0; foreach (var xp in caughtPokemonResponse.CaptureAward.Xp) { totalExp += xp; } var profile = ctx.Client.Player.GetPlayer().Result; evt.Exp = totalExp; evt.Stardust = profile.PlayerData.Currencies.ToArray()[1].Amount; var pokemonSettings = ctx.Inventory.GetPokemonSettings().Result; var pokemonFamilies = ctx.Inventory.GetPokemonFamilies().Result; var setting = pokemonSettings.FirstOrDefault(q => q.PokemonId == pokemon.PokemonId); var family = pokemonFamilies.FirstOrDefault(q => q.FamilyId == setting.FamilyId); if (family != null) { family.Candy += caughtPokemonResponse.CaptureAward.Candy.Sum(); evt.FamilyCandies = family.Candy; } else { evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum(); } } if (encounter?.CaptureProbability?.CaptureProbability_ != null) { evt.Id = pokemon.PokemonId; evt.Level = PokemonInfo.GetLevel(encounter.WildPokemon?.PokemonData); evt.Cp = encounter.WildPokemon?.PokemonData?.Cp ?? 0; evt.MaxCp = PokemonInfo.CalculateMaxCp(encounter.WildPokemon?.PokemonData); evt.Perfection = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter.WildPokemon?.PokemonData)); evt.Probability = Math.Round(Convert.ToDouble(encounter.CaptureProbability?.CaptureProbability_.First())*100, 2); evt.Distance = distance; evt.Pokeball = pokeball; evt.Attempt = attemptCounter; machine.Fire(evt); } attemptCounter++; Thread.Sleep(2000); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
private async Task <MethodResult> CatchPokemon(EncounterResponse eResponse, MapPokemon mapPokemon) { try { CatchPokemonResponse catchPokemonResponse = null; int attemptCount = 1; do { //Uses lowest capture probability float probability = eResponse.CaptureProbability.CaptureProbability_[0]; ItemId pokeBall = GetBestBall(eResponse.WildPokemon.PokemonData); if (pokeBall == ItemId.ItemUnknown) { LogCaller(new LoggerEventArgs("No pokeballs remaining", LoggerTypes.Warning)); return(new MethodResult { Message = "No pokeballs remaining" }); } bool isLowProbability = probability < 0.40; bool isHighCp = eResponse.WildPokemon.PokemonData.Cp > 800; bool isHighPerfection = CalculateIVPerfection(eResponse.WildPokemon.PokemonData).Data > 95; if ((isLowProbability && isHighCp) || isHighPerfection) { await Task.Delay(200); await UseBerry(mapPokemon); } await Task.Delay(200); catchPokemonResponse = await _client.Encounter.CatchPokemon(mapPokemon.EncounterId, mapPokemon.SpawnPointId, pokeBall); string pokemon = String.Format("Name: {0}, CP: {1}, IV: {2:0.00}%", mapPokemon.PokemonId, eResponse.WildPokemon.PokemonData.Cp, CalculateIVPerfection(eResponse.WildPokemon.PokemonData).Data); string pokeBallName = pokeBall.ToString().Replace("Item", ""); if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { int expGained = catchPokemonResponse.CaptureAward.Xp.Sum(); ExpIncrease(expGained); //_expGained += expGained; LogCaller(new LoggerEventArgs(String.Format("Caught. {0}. Exp {1}. Attempt #{2}. Ball: {3}", pokemon, expGained, attemptCount, pokeBallName), 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}. Ball: {2}", pokemon, attemptCount, pokeBallName), LoggerTypes.PokemonFlee)); } else if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) { LogCaller(new LoggerEventArgs(String.Format("Escaped ball. {0}. Attempt #{1}. Ball: {2}", pokemon, attemptCount, pokeBallName), 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(500); } while (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); } catch (Exception ex) { LogCaller(new LoggerEventArgs("Failed to catch pokemon due to error", LoggerTypes.Exception, ex)); return(new MethodResult { Message = "Failed to catch pokemon" }); } return(new MethodResult { Message = "Failed to catch pokemon", Success = true }); }
private async Task <MethodResult <EncounterResponse> > EncounterPokemon(MapPokemon mapPokemon) { var response = await _client.ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request { RequestType = RequestType.Encounter, RequestMessage = new EncounterMessage { EncounterId = mapPokemon.EncounterId, PlayerLatitude = _client.ClientSession.Player.Latitude, PlayerLongitude = _client.ClientSession.Player.Longitude, SpawnPointId = mapPokemon.SpawnPointId }.ToByteString() }); if (response == null) { return(new MethodResult <EncounterResponse>()); } EncounterResponse eResponse = EncounterResponse.Parser.ParseFrom(response); switch (eResponse.Status) { case EncounterResponse.Types.Status.EncounterAlreadyHappened: return(new MethodResult <EncounterResponse> { Message = "Encounter failed. Pokemon Already Happened" }); case EncounterResponse.Types.Status.EncounterClosed: LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed" }); case EncounterResponse.Types.Status.EncounterError: LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed" }); case EncounterResponse.Types.Status.EncounterNotFound: LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed" }); case EncounterResponse.Types.Status.EncounterNotInRange: LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed" }); case EncounterResponse.Types.Status.EncounterPokemonFled: LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed" }); case EncounterResponse.Types.Status.EncounterSuccess: return(new MethodResult <EncounterResponse> { Data = eResponse, Success = true, Message = "Success" }); case EncounterResponse.Types.Status.PokemonInventoryFull: LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = "Encounter failed. Pokemon inventory full" }); } return(new MethodResult <EncounterResponse>()); }
private async Task <ItemId> GetBestBall(EncounterResponse encounter) { var pokemonCp = encounter?.WildPokemon?.PokemonData?.Cp; var iV = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)); var proba = encounter?.CaptureProbability?.CaptureProbability_.First(); var pokeBallsCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_POKE_BALL); var greatBallsCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_GREAT_BALL); var ultraBallsCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_ULTRA_BALL); var masterBallsCount = await _inventory.GetItemAmountByType(MiscEnums.Item.ITEM_MASTER_BALL); 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 >= _clientSettings.KeepMinIVPercentage && proba < 0.40) { return(ItemId.ItemUltraBall); } if (greatBallsCount > 0 && iV >= _clientSettings.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); }
/// <summary> /// Encounter logic /// </summary> /// <returns></returns> private async Task HandleEncounter() { if (CurrentPokemon is MapPokemonWrapper) { CurrentEncounter = await GameClient.EncounterPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId); switch (CurrentEncounter.Status) { case EncounterResponse.Types.Status.PokemonInventoryFull: await new MessageDialog(string.Format(Resources.CodeResources.GetString("PokemonInventoryFullText"), Resources.Pokemon.GetString($"{CurrentPokemon.PokemonId}"))).ShowAsyncQueue(); ReturnToGameScreen.Execute(); break; case EncounterResponse.Types.Status.EncounterSuccess: break; case EncounterResponse.Types.Status.EncounterError: case EncounterResponse.Types.Status.EncounterNotFound: case EncounterResponse.Types.Status.EncounterClosed: await new MessageDialog(string.Format(Resources.CodeResources.GetString("PokemonEncounterErrorText"), Resources.Pokemon.GetString($"{CurrentPokemon.PokemonId}"))).ShowAsyncQueue(); ReturnToGameScreen.Execute(); break; case EncounterResponse.Types.Status.EncounterNotInRange: await new MessageDialog(string.Format(Resources.CodeResources.GetString("PokemonEncounterNotInRangeText"), Resources.Pokemon.GetString($"{CurrentPokemon.PokemonId}"))).ShowAsyncQueue(); ReturnToGameScreen.Execute(); break; case EncounterResponse.Types.Status.EncounterPokemonFled: case EncounterResponse.Types.Status.EncounterAlreadyHappened: await new MessageDialog(Resources.CodeResources.GetString("PokemonRanAwayText")).ShowAsyncQueue(); ReturnToGameScreen.Execute(); GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon); break; default: throw new ArgumentOutOfRangeException(); } } else { CurrentLureEncounter = await GameClient.EncounterLurePokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId); CurrentEncounter = new EncounterResponse() { Background = EncounterResponse.Types.Background.Park, WildPokemon = new WildPokemon() { PokemonData = CurrentLureEncounter.PokemonData } }; switch (CurrentLureEncounter.Result) { case DiskEncounterResponse.Types.Result.PokemonInventoryFull: await new MessageDialog(string.Format(Resources.CodeResources.GetString("PokemonInventoryFullText"), Resources.Pokemon.GetString($"{CurrentPokemon.PokemonId}"))).ShowAsyncQueue(); ReturnToGameScreen.Execute(); break; case DiskEncounterResponse.Types.Result.Success: break; case DiskEncounterResponse.Types.Result.Unknown: case DiskEncounterResponse.Types.Result.NotAvailable: await new MessageDialog(string.Format(Resources.CodeResources.GetString("PokemonEncounterErrorText"), Resources.Pokemon.GetString($"{CurrentPokemon.PokemonId}"))).ShowAsyncQueue(); ReturnToGameScreen.Execute(); break; case DiskEncounterResponse.Types.Result.NotInRange: await new MessageDialog(string.Format(Resources.CodeResources.GetString("PokemonEncounterNotInRangeText"), Resources.Pokemon.GetString($"{CurrentPokemon.PokemonId}"))).ShowAsyncQueue(); ReturnToGameScreen.Execute(); break; case DiskEncounterResponse.Types.Result.EncounterAlreadyFinished: await new MessageDialog(Resources.CodeResources.GetString("PokemonRanAwayText")).ShowAsyncQueue(); ReturnToGameScreen.Execute(); break; default: throw new ArgumentOutOfRangeException(); } } PokemonExtraData = GameClient.GetExtraDataForPokemon(CurrentPokemon.PokemonId); SelectedCaptureItem = SelectAvailablePokeBall(); Busy.SetBusy(false); }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; do { var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); if (probability.HasValue && probability.Value < 0.35 && encounter?.WildPokemon?.PokemonData?.Cp > 400) { //Throw berry is we can await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId); } var pokeball = await GetBestBall(encounter?.WildPokemon); var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball); Logger.Write(caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"(CATCH) {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} ({CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData).ToString("0.00")}% perfect) and CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} using a {pokeball} in {Math.Round(distance)}m distance" : $"{pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} in {Math.Round(distance)}m distance {caughtPokemonResponse.Status} while using a {pokeball}..", LogLevel.Info); await Task.Delay(2000); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) ; }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; var attemptCounter = 1; do { var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var pokeball = await GetBestBall(encounter); if (pokeball == ItemId.ItemUnknown) { Logger.Write( $"No Pokeballs - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Caught); return; } if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) || PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _clientSettings.KeepMinIVPercentage) { await UseBerry(pokemon.EncounterId, pokemon.SpawnPointId); } var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, 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); if (encounter?.CaptureProbability?.CaptureProbability_ != null) { Func <ItemId, string> returnRealBallName = a => { switch (a) { case ItemId.ItemPokeBall: return("Poke"); case ItemId.ItemGreatBall: return("Great"); case ItemId.ItemUltraBall: return("Ultra"); case ItemId.ItemMasterBall: return("Master"); default: return("Unknown"); } }; var catchStatus = attemptCounter > 1 ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}" : $"{caughtPokemonResponse.Status}"; Logger.Write( $"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter.WildPokemon?.PokemonData)} ({encounter.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter.WildPokemon?.PokemonData)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter.WildPokemon?.PokemonData)).ToString("0.00")}% perfect) | Chance: {Math.Round(Convert.ToDouble(encounter.CaptureProbability?.CaptureProbability_.First())*100, 2)}% | {Math.Round(distance)}m dist | with a {returnRealBallName(pokeball)}Ball.", LogLevel.Caught); } attemptCounter++; await Task.Delay(2000); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
private async Task <MethodResult <EncounterResponse> > EncounterPokemon(MapPokemon mapPokemon) { if (!_client.LoggedIn) { MethodResult result = await AcLogin(); if (!result.Success) { return(new MethodResult <EncounterResponse>()); } } if (mapPokemon == null || mapPokemon.PokemonId == PokemonId.Missingno) { return(new MethodResult <EncounterResponse>()); } if (AlreadySnipped || mapPokemon.EncounterId == _lastPokeSniperId) { return(new MethodResult <EncounterResponse>()); } if (!CatchDisabled) { if (RemainingPokeballs() < 1) { LogCaller(new LoggerEventArgs("You don't have any pokeball catching pokemon will be disabled during " + UserSettings.DisableCatchDelay.ToString(CultureInfo.InvariantCulture) + " minutes.", LoggerTypes.Info)); CatchDisabled = true; TimeAutoCatch = DateTime.Now.AddMinutes(UserSettings.DisableCatchDelay); return(new MethodResult <EncounterResponse>()); } } else { return(new MethodResult <EncounterResponse>()); } var response = await _client.ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request { RequestType = RequestType.Encounter, RequestMessage = new EncounterMessage { EncounterId = mapPokemon.EncounterId, PlayerLatitude = _client.ClientSession.Player.Latitude, PlayerLongitude = _client.ClientSession.Player.Longitude, SpawnPointId = mapPokemon.SpawnPointId }.ToByteString() }); if (response == null) { return(new MethodResult <EncounterResponse>()); } EncounterResponse eResponse = EncounterResponse.Parser.ParseFrom(response); switch (eResponse.Status) { case EncounterResponse.Types.Status.EncounterAlreadyHappened: break; case EncounterResponse.Types.Status.EncounterClosed: break; case EncounterResponse.Types.Status.EncounterError: break; case EncounterResponse.Types.Status.EncounterNotFound: break; case EncounterResponse.Types.Status.EncounterNotInRange: break; case EncounterResponse.Types.Status.EncounterPokemonFled: break; case EncounterResponse.Types.Status.EncounterSuccess: if (LastedEncountersIds.Count > 30) { LastedEncountersIds.Clear(); } LastedEncountersIds.Add(eResponse.WildPokemon.EncounterId); return(new MethodResult <EncounterResponse> { Data = eResponse, Success = true, Message = "Success" }); case EncounterResponse.Types.Status.PokemonInventoryFull: break; } if (LastedEncountersIds.Count > 30) { LastedEncountersIds.Clear(); } LastedEncountersIds.Add(mapPokemon.EncounterId); LogCaller(new LoggerEventArgs(String.Format("Faill encounter pokemon. {0}.", eResponse.Status), LoggerTypes.Warning)); return(new MethodResult <EncounterResponse> { Message = eResponse.Status.ToString() }); }
public static async Task Execute(ISession session, CancellationToken cancellationToken, PokemonId priority = PokemonId.Missingno, bool sessionAllowTransfer = true) { var manager = TinyIoCContainer.Current.Resolve <MultiAccountManager>(); manager.ThrowIfSwitchAccountRequested(); cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.CatchPokemon) { return; } var totalBalls = (await session.Inventory.GetItems().ConfigureAwait(false)).Where(x => x.ItemId == ItemId.ItemPokeBall || x.ItemId == ItemId.ItemGreatBall || x.ItemId == ItemId.ItemUltraBall).Sum(x => x.Count); if (session.SaveBallForByPassCatchFlee && totalBalls < 130) { return; } if (session.Stats.CatchThresholdExceeds(session)) { if (manager.AllowMultipleBot() && session.LogicSettings.MultipleBotConfig.SwitchOnCatchLimit && manager.AllowSwitch() ) { throw new ActiveSwitchByRuleException() { MatchedRule = SwitchRules.CatchLimitReached, ReachedValue = session.LogicSettings.CatchPokemonLimit }; } return; } Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForPokemon), LogLevel.Debug); var nearbyPokemons = await GetNearbyPokemons(session).ConfigureAwait(false); Logger.Write($"There are {nearbyPokemons.Count()} pokemon nearby.", LogLevel.Debug); if (nearbyPokemons == null) { return; } var priorityPokemon = nearbyPokemons.Where(p => p.PokemonId == priority).FirstOrDefault(); var pokemons = nearbyPokemons.Where(p => p.PokemonId != priority).ToList(); //add pokemons to map OnPokemonEncounterEvent(pokemons.ToList()); EncounterResponse encounter = null; //if that is snipe pokemon and inventories if full, execute transfer to get more room for pokemon if (priorityPokemon != null) { pokemons.Insert(0, priorityPokemon); await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(priorityPokemon.Latitude, priorityPokemon.Longitude, session.Client.CurrentAltitude), 0).ConfigureAwait(false); // Set speed to 0 for random speed. encounter = await session.Client.Encounter .EncounterPokemon(priorityPokemon.EncounterId, priorityPokemon.SpawnPointId).ConfigureAwait(false); if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull) { if (session.LogicSettings.TransferDuplicatePokemon) { await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false); } if (session.LogicSettings.TransferWeakPokemon) { await TransferWeakPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false); } if (session.LogicSettings.EvolveAllPokemonAboveIv || session.LogicSettings.EvolveAllPokemonWithEnoughCandy || session.LogicSettings.UseLuckyEggsWhileEvolving || session.LogicSettings.KeepPokemonsThatCanEvolve) { await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false); } } } var allitems = await session.Inventory.GetItems().ConfigureAwait(false); var pokeBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemPokeBall)?.Count; var greatBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemGreatBall)?.Count; var ultraBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemUltraBall)?.Count; var masterBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemMasterBall)?.Count; masterBallsCount = masterBallsCount ?? 0; //return null ATM. need this code to logic check work var PokeBalls = pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount; if (0 < pokemons.Count && PokeBalls >= session.LogicSettings.PokeballsToKeepForSnipe) // Don't display if not enough Pokeballs - TheWizrad1328 { Logger.Write($"Catching {pokemons.Count} Pokemon Nearby...", LogLevel.Info); } foreach (var pokemon in pokemons) { await MSniperServiceTask.Execute(session, cancellationToken).ConfigureAwait(false); /* * if (LocationUtils.CalculateDistanceInMeters(pokemon.Latitude, pokemon.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) > session.Client.GlobalSettings.MapSettings.EncounterRangeMeters) * { * Logger.Debug($"THIS POKEMON IS TOO FAR, {pokemon.Latitude}, {pokemon.Longitude}"); * continue; * } */ cancellationToken.ThrowIfCancellationRequested(); TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested(); if (session.Cache.GetCacheItem(CatchPokemonTask.GetEncounterCacheKey(pokemon.EncounterId)) != null) { continue; //this pokemon has been skipped because not meet with catch criteria before. } if (PokeBalls < session.LogicSettings.PokeballsToKeepForSnipe && session.CatchBlockTime < DateTime.Now) { session.CatchBlockTime = DateTime.Now.AddMinutes(session.LogicSettings.OutOfBallCatchBlockTime); Logger.Write(session.Translation.GetTranslation(TranslationString.CatchPokemonDisable, session.LogicSettings.OutOfBallCatchBlockTime, session.LogicSettings.PokeballsToKeepForSnipe)); return; } if (session.CatchBlockTime > DateTime.Now) { return; } if ((session.LogicSettings.UsePokemonToCatchLocallyListOnly && !session.LogicSettings.PokemonToCatchLocally.Pokemon.Contains(pokemon.PokemonId)) || (session.LogicSettings.UsePokemonToNotCatchFilter && session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))) { Logger.Write(session.Translation.GetTranslation(TranslationString.PokemonSkipped, session.Translation.GetPokemonTranslation(pokemon.PokemonId))); continue; } /* * var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, * session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); * await Task.Delay(distance > 100 ? 500 : 100, cancellationToken).ConfigureAwait(false); */ //to avoid duplicated encounter when snipe priority pokemon if (encounter == null || encounter.Status != EncounterResponse.Types.Status.EncounterSuccess) { await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(pokemon.Latitude, pokemon.Longitude, session.Client.CurrentAltitude), 0).ConfigureAwait(false); // Set speed to 0 for random speed. encounter = await session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId).ConfigureAwait(false); } if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess && session.LogicSettings.CatchPokemon) { // Catch the Pokemon await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon, currentFortData : null, sessionAllowTransfer : sessionAllowTransfer).ConfigureAwait(false); } else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull) { if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon) { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring) }); if (session.LogicSettings.TransferDuplicatePokemon) { await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false); } if (session.LogicSettings.TransferWeakPokemon) { await TransferWeakPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false); } if (session.LogicSettings.EvolveAllPokemonAboveIv || session.LogicSettings.EvolveAllPokemonWithEnoughCandy || session.LogicSettings.UseLuckyEggsWhileEvolving || session.LogicSettings.KeepPokemonsThatCanEvolve) { await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false); } } else { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually) }); } } else { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status) }); } encounter = null; // If pokemon is not last pokemon in list, create delay between catches, else keep moving. if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon)) { await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken).ConfigureAwait(false); } } }
private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon) { CatchPokemonResponse caughtPokemonResponse; var attemptCounter = 1; do { var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault(); var pokeball = await GetBestBall(encounter); if (pokeball == ItemId.ItemUnknown) { Logger.Write( $"No Pokeballs - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Caught); return; } if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) || PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _clientSettings.KeepMinIVPercentage) { await UseBerry(pokemon.EncounterId, pokemon.SpawnPointId); } var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLatitude, _client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); caughtPokemonResponse = await _client.Encounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { foreach (var xp in caughtPokemonResponse.CaptureAward.Xp) { _stats.AddExperience(xp); } _stats.IncreasePokemons(); var profile = await _client.Player.GetPlayer(); _stats.GetStardust(profile.PlayerData.Currencies.ToArray()[1].Amount); } _stats.UpdateConsoleTitle(_inventory); if (encounter?.CaptureProbability?.CaptureProbability_ != null) { Func <ItemId, string> returnRealBallName = a => { switch (a) { case ItemId.ItemPokeBall: return("Poke"); case ItemId.ItemGreatBall: return("Great"); case ItemId.ItemUltraBall: return("Ultra"); case ItemId.ItemMasterBall: return("Master"); default: return("Unknown"); } }; var catchStatus = attemptCounter > 1 ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}" : $"{caughtPokemonResponse.Status}"; var color = ConsoleColor.Green; if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee) { color = ConsoleColor.Red; } Logger.Write( $"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter.WildPokemon?.PokemonData)} ({encounter.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter.WildPokemon?.PokemonData)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter.WildPokemon?.PokemonData)).ToString("0.00")}% perfect) | Chance: {Math.Round(Convert.ToDouble(encounter.CaptureProbability?.CaptureProbability_.First())*100, 2)}% | {Math.Round(distance)}m dist | with a {returnRealBallName(pokeball)}Ball.", LogLevel.Caught, color); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { _caughtInSession.Add(encounter.WildPokemon?.PokemonData); _narrator.Speak($"{pokemon.PokemonId}, {encounter.WildPokemon?.PokemonData?.Cp}"); Statistics.KeptPokemon++; _map.Invoke(new MethodInvoker(delegate() { var pokemonOverlay = _map.Overlays[3]; GMapMarker foundMarker = null; for (int i = 0; i < pokemonOverlay.Markers.Count; i++) { var marker = pokemonOverlay.Markers[i]; if (Math.Round(marker.Position.Lat, 12) == Math.Round(encounter.WildPokemon.Latitude, 12) && Math.Round(marker.Position.Lng, 12) == Math.Round(encounter.WildPokemon.Longitude, 12)) { foundMarker = marker; break; } } var position = new GMap.NET.PointLatLng(Math.Round(encounter.WildPokemon.Latitude, 12), Math.Round(encounter.WildPokemon.Longitude, 12)); _client.Map.CaughtMarkers.Add(new KeyValuePair <int, GMap.NET.PointLatLng>((int)pokemon.PokemonId, position)); if (foundMarker != null) { pokemonOverlay.Markers.Remove(foundMarker); } })); } } attemptCounter++; await Task.Delay(2000); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
public static async Task Execute(ISession session, CancellationToken cancellationToken, PokemonId priority = PokemonId.Missingno, bool sessionAllowTransfer = true) { cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.CatchPokemon) { return; } if (session.Stats.CatchThresholdExceeds(session)) { if (session.LogicSettings.AllowMultipleBot && session.LogicSettings.MultipleBotConfig.SwitchOnCatchLimit) { throw new ActiveSwitchByRuleException() { MatchedRule = SwitchRules.CatchLimitReached, ReachedValue = session.LogicSettings.CatchPokemonLimit }; } return; } Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForPokemon), LogLevel.Debug); var nearbyPokemons = await GetNearbyPokemons(session); var priorityPokemon = nearbyPokemons.Where(p => p.PokemonId == priority).FirstOrDefault(); var pokemons = nearbyPokemons.Where(p => p.PokemonId != priority).ToList(); EncounterResponse encounter = null; //if that is snipe pokemon and inventories if full, execute transfer to get more room for pokemon if (priorityPokemon != null) { pokemons.Insert(0, priorityPokemon); encounter = await session.Client.Encounter .EncounterPokemon(priorityPokemon.EncounterId, priorityPokemon.SpawnPointId); if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull) { await TransferWeakPokemonTask.Execute(session, cancellationToken); await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } } foreach (var pokemon in pokemons) { await MSniperServiceTask.Execute(session, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); string pokemonUniqueKey = $"{pokemon.EncounterId}"; if (session.Cache.GetCacheItem(pokemonUniqueKey) != null) { continue; //this pokemon has been skipped because not meet with catch criteria before. } var allitems = await session.Inventory.GetItems(); var pokeBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemPokeBall)?.Count; var greatBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemGreatBall)?.Count; var ultraBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemUltraBall)?.Count; var masterBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemMasterBall)?.Count; masterBallsCount = masterBallsCount == null ? 0 : masterBallsCount; //return null ATM. need this code to logic check work if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount < session.LogicSettings.PokeballsToKeepForSnipe && session.CatchBlockTime < DateTime.Now) { session.CatchBlockTime = DateTime.Now.AddMinutes(session.LogicSettings.OutOfBallCatchBlockTime); Logger.Write(session.Translation.GetTranslation(TranslationString.CatchPokemonDisable, session.LogicSettings.OutOfBallCatchBlockTime, session.LogicSettings.PokeballsToKeepForSnipe)); return; } if (session.CatchBlockTime > DateTime.Now) { return; } if ((session.LogicSettings.UsePokemonSniperFilterOnly && !session.LogicSettings.PokemonToSnipe.Pokemon.Contains(pokemon.PokemonId)) || (session.LogicSettings.UsePokemonToNotCatchFilter && session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))) { Logger.Write(session.Translation.GetTranslation(TranslationString.PokemonSkipped, session.Translation.GetPokemonTranslation(pokemon.PokemonId))); continue; } var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); await Task.Delay(distance > 100? 500 : 100, cancellationToken); //to avoid duplicated encounter when snipe priority pokemon if (encounter == null || encounter.Status != EncounterResponse.Types.Status.EncounterSuccess) { encounter = await session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId); } if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess && session.LogicSettings.CatchPokemon) { // Catch the Pokemon await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon, currentFortData : null, sessionAllowTransfer : sessionAllowTransfer); } else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull) { if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon) { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring) }); if (session.LogicSettings.TransferDuplicatePokemon) { await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.TransferWeakPokemon) { await TransferWeakPokemonTask.Execute(session, cancellationToken); } } else { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually) }); } } else { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status) }); } encounter = null; // If pokemon is not last pokemon in list, create delay between catches, else keep moving. if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon)) { await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken); } } }
//Catch encountered pokemon private async Task <MethodResult> CatchPokemon(EncounterResponse eResponse, MapPokemon mapPokemon) { try { CatchPokemonResponse catchPokemonResponse = null; int attemptCount = 1; do { //Uses lowest capture probability float probability = eResponse.CaptureProbability.CaptureProbability_[0]; ItemId pokeBall = await GetBestBall(eResponse.WildPokemon.PokemonData); if (pokeBall == ItemId.ItemUnknown) { LogCaller(new LoggerEventArgs("No pokeballs remaining (encounter)", LoggerTypes.Warning)); return(new MethodResult { Message = "No pokeballs remaining" }); } bool isLowProbability = probability < 0.40; bool isHighCp = eResponse.WildPokemon.PokemonData.Cp > 800; bool isHighPerfection = CalculateIVPerfection(eResponse.WildPokemon.PokemonData).Data > 95; if ((isLowProbability && isHighCp) || isHighPerfection) { await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom)); await UseBerry(mapPokemon); } await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom)); double reticuleSize = 1.95; int hitInsideReticule = 1; //Humanization if (UserSettings.EnableHumanization) { reticuleSize = (double)_rand.Next(10, 195) / 100; hitInsideReticule = HitInsideReticle(); } catchPokemonResponse = await _client.Encounter.CatchPokemon(mapPokemon.EncounterId, mapPokemon.SpawnPointId, pokeBall, reticuleSize, 1, hitInsideReticule); string pokemon = String.Format("Name: {0}, CP: {1}, IV: {2:0.00}%", mapPokemon.PokemonId, eResponse.WildPokemon.PokemonData.Cp, CalculateIVPerfection(eResponse.WildPokemon.PokemonData).Data); string pokeBallName = pokeBall.ToString().Replace("Item", ""); if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { //Reset data _fleeingPokemonResponses = 0; ++PokemonCaught; _potentialPokemonBan = false; int expGained = catchPokemonResponse.CaptureAward.Xp.Sum(); ExpIncrease(expGained); //_expGained += expGained; LogCaller(new LoggerEventArgs(String.Format("Caught. {0}. Exp {1}. Attempt #{2}. Ball: {3}", pokemon, expGained, attemptCount, pokeBallName), LoggerTypes.Success)); return(new MethodResult { Message = "Pokemon caught", Success = true }); } else if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee) { ++_fleeingPokemonResponses; LogCaller(new LoggerEventArgs(String.Format("Pokemon fled. {0}. Attempt #{1}. Ball: {2}", pokemon, attemptCount, pokeBallName), LoggerTypes.PokemonFlee)); } else if (catchPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) { //If we get this response, means we're good _fleeingPokemonResponses = 0; _potentialPokemonBan = false; if (AccountState == Enums.AccountState.PokemonBanAndPokestopBanTemp || AccountState == Enums.AccountState.PokemonBanTemp) { if (AccountState == Enums.AccountState.PokemonBanAndPokestopBanTemp) { AccountState = Enums.AccountState.PokestopBanTemp; } else { AccountState = Enums.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)); } 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 pokemon due to error", LoggerTypes.Exception, ex)); return(new MethodResult { Message = "Failed to catch pokemon" }); } return(new MethodResult { Message = "Failed to catch pokemon", Success = true }); }