private void getPokemons(Boolean Iv = false) { List <PokemonListe> pokemonlist = new List <PokemonListe>(); List <PokemonData> Pokemons = pokemonDisplay.Liste; if (Pokemons == null) { return; } List <POGOProtos.Inventory.Candy> myPokemonFamilies = pokemonDisplay.FamilieListe; IEnumerable <POGOProtos.Settings.Master.PokemonSettings> myPokeSettings = pokemonDisplay.PokeSettingListe; foreach (var Poke in Pokemons) { PokemonListe pok = new PokemonListe(); pok.setCp(Poke.Cp, PokemonInfo.CalculateMaxCp(Poke)); pok.setId(Poke.Id); string pfad = pokemonNameToId[Poke.PokemonId.ToString()].ToString(); pok.setIcon("Images/Models/" + pfad + ".png"); pok.Name = session.Translation.GetPokemonTranslation(Poke.PokemonId).ToString(); pok.Move1 = session.Translation.GetPokemonMovesetTranslation(Poke.Move1).ToString(); pok.Move2 = session.Translation.GetPokemonMovesetTranslation(Poke.Move2).ToString(); pok.setIv(PokemonInfo.CalculatePokemonPerfection(Poke)); pok.Bonbon = PokemonInfo.GetCandy(Poke, myPokemonFamilies, myPokeSettings).ToString(); pokemonlist.Add(pok); } GraphicalInterface.PokemonList = pokemonlist; }
private async Task DisplayHighests() { Logger.Write("====== DisplayHighestsCP ======", LogLevel.Info, ConsoleColor.Yellow); var highestsPokemonCp = await Inventory.GetHighestsCp(15); string space = " "; foreach (var pokemon in highestsPokemonCp) { if (PokemonInfo.CalculatePokemonPerfection(pokemon) > 100) { space = "\t"; } Logger.Write( $"# CP {pokemon.Cp.ToString().PadLeft(4, ' ')}/{PokemonInfo.CalculateMaxCp(pokemon).ToString().PadLeft(4, ' ')} | ({PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect){space}| Lvl {PokemonInfo.GetLevel(pokemon).ToString("00")}\t NAME: '{pokemon.PokemonId}'", LogLevel.Info, ConsoleColor.Yellow); } Logger.Write("====== DisplayHighestsPerfect ======", LogLevel.Info, ConsoleColor.Yellow); var highestsPokemonPerfect = await Inventory.GetHighestsIv(15); foreach (var pokemon in highestsPokemonPerfect) { if (PokemonInfo.CalculatePokemonPerfection(pokemon) > 100) { space = "\t"; } Logger.Write( $"# CP {pokemon.Cp.ToString().PadLeft(4, ' ')}/{PokemonInfo.CalculateMaxCp(pokemon).ToString().PadLeft(4, ' ')} | ({PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect){space}| Lvl {PokemonInfo.GetLevel(pokemon).ToString("00")}\t NAME: '{pokemon.PokemonId}'", LogLevel.Info, ConsoleColor.Yellow); } }
private static async Task <List <IncubatorUsage> > CheckForHatchedEggs(ISession session) { _logger.Debug("Checking for previously hatched eggs..."); // Check if eggs in remembered incubator usages have since hatched // (instead of calling session.Client.Inventory.GetHatchedEgg(), which doesn't seem to work properly) List <IncubatorUsage> rememberedIncubators = GetRememberedIncubators(_rememberedIncubatorsFilePath); List <PokemonData> pokemons = (await session.Inventory.GetPokemons()).ToList(); foreach (IncubatorUsage incubatorUsage in rememberedIncubators) { PokemonData hatchedPkmn = pokemons.FirstOrDefault(pkmn => !pkmn.IsEgg && pkmn.Id == incubatorUsage.PokemonId); if (hatchedPkmn == null) { _logger.Trace("Incubator {0}. Previously remembered pokemon {1} has not hatched yet.", incubatorUsage.IncubatorId, incubatorUsage.PokemonId); continue; } session.EventDispatcher.Send(new EggHatchedEvent { Id = hatchedPkmn.Id, PokemonId = hatchedPkmn.PokemonId, Level = PokemonInfo.GetLevel(hatchedPkmn), Cp = hatchedPkmn.Cp, MaxCp = PokemonInfo.CalculateMaxCp(hatchedPkmn), Perfection = Math.Round(PokemonInfo.CalculatePokemonPerfection(hatchedPkmn), 2) }); } return(rememberedIncubators); }
public static async Task Execute() { await Inventory.GetCachedInventory(true); var pokemonToEvolve = await Inventory.GetPokemonToEvolve(Logic._client.Settings.PrioritizeIVOverCP, Logic._client.Settings.PokemonsToEvolve); if (pokemonToEvolve == null || !pokemonToEvolve.Any()) { return; } Logger.Write($"Found {pokemonToEvolve.Count()} Pokemon for Evolve:", LogLevel.Debug); foreach (var pokemon in pokemonToEvolve) { var evolvePokemonOutProto = await Logic._client.Inventory.EvolvePokemon(pokemon.Id); await Inventory.GetCachedInventory(true); Logger.Write(evolvePokemonOutProto.Result == EvolvePokemonResponse.Types.Result.Success ? $"{pokemon.PokemonId} [CP: {pokemon.Cp}/{PokemonInfo.CalculateMaxCp(pokemon)} | IV: { PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect] | received XP {evolvePokemonOutProto.ExperienceAwarded}" : $"Failed: {pokemon.PokemonId}. EvolvePokemonOutProto.Result was {evolvePokemonOutProto.Result}, stopping evolving {pokemon.PokemonId}" , LogLevel.Evolve); if (evolvePokemonOutProto.Result == EvolvePokemonResponse.Types.Result.Success) { BotStats.ExperienceThisSession += evolvePokemonOutProto.ExperienceAwarded; } } await BotStats.GetPokeDexCount(); BotStats.UpdateConsoleTitle(); }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { if (await session.Inventory.GetStarDust() <= session.LogicSettings.GetMinStarDustForLevelUp) { return; } var upgradablePokemon = await session.Inventory.GetPokemonToUpgrade(); if (upgradablePokemon.Count == 0) { return; } var myPokemonSettings = await session.Inventory.GetPokemonSettings(); var pokemonSettings = myPokemonSettings.ToList(); var myPokemonFamilies = await session.Inventory.GetPokemonFamilies(); var pokemonFamilies = myPokemonFamilies.ToArray(); var upgradedNumber = 0; foreach (var pokemon in upgradablePokemon) { if (PokemonInfo.CalculateMaxCp(pokemon) == pokemon.Cp) { continue; } var settings = pokemonSettings.Single(x => x.PokemonId == pokemon.PokemonId); var familyCandy = pokemonFamilies.Single(x => settings.FamilyId == x.FamilyId); if (familyCandy.Candy_ <= 0) { continue; } var upgradeResult = await session.Inventory.UpgradePokemon(pokemon.Id); if (upgradeResult.Result.ToString().ToLower().Contains("success")) { Logger.Write("Pokemon Upgraded:" + session.Translation.GetPokemonTranslation(upgradeResult.UpgradedPokemon.PokemonId) + ":" + upgradeResult.UpgradedPokemon.Cp); upgradedNumber++; } if (upgradedNumber >= session.LogicSettings.AmountOfTimesToUpgradeLoop) { break; } } }
public static async Task Execute() { await Inventory.GetCachedInventory(true); var pokemonToTransfer = await Inventory.GetPokemonToTransfer(Logic._clientSettings.NotTransferPokemonsThatCanEvolve, Logic._clientSettings.PrioritizeIVOverCP, Logic._clientSettings.PokemonsToNotTransfer); if (pokemonToTransfer == null || !pokemonToTransfer.Any()) { return; } Logger.Write($"Found {pokemonToTransfer.Count()} Pokemon for Transfer:", LogLevel.Debug); foreach (var pokemon in pokemonToTransfer) { await Logic._client.Inventory.TransferPokemon(pokemon.Id); await Inventory.GetCachedInventory(true); var myPokemonSettings = await Inventory.GetPokemonSettings(); var pokemonSettings = myPokemonSettings.ToList(); var myPokemonFamilies = await Inventory.GetPokemonFamilies(); var pokemonFamilies = myPokemonFamilies.ToArray(); var settings = pokemonSettings.Single(x => x.PokemonId == pokemon.PokemonId); var familyCandy = pokemonFamilies.Single(x => settings.FamilyId == x.FamilyId); var familyCandies = $"{familyCandy.Candy_}"; BotStats.PokemonTransferedThisSession += 1; var bestPokemonOfType = Logic._client.Settings.PrioritizeIVOverCP ? await Inventory.GetHighestPokemonOfTypeByIv(pokemon) : await Inventory.GetHighestPokemonOfTypeByCp(pokemon); var bestPokemonInfo = "NONE"; if (bestPokemonOfType != null) { bestPokemonInfo = $"CP: {bestPokemonOfType.Cp}/{PokemonInfo.CalculateMaxCp(bestPokemonOfType)} | IV: {PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType).ToString("0.00")}% perfect"; } Logger.Write($"{pokemon.PokemonId} [CP: {pokemon.Cp}/{PokemonInfo.CalculateMaxCp(pokemon)} | IV: { PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect] | Best: [{bestPokemonInfo}] | Family Candies: {familyCandies}", LogLevel.Transfer); } await BotStats.GetPokemonCount(); BotStats.UpdateConsoleTitle(); }
private async Task TransferPokemon() { await Inventory.GetCachedInventory(_client, true); Inventory inventory = new Inventory(_client); var myPokemon = inventory.GetPokemons().Result; var pokemonToTransfer = await _inventory.GetPokemonToTransfer(myPokemon, _client.Settings, _clientSettings.NotTransferPokemonsThatCanEvolve, _clientSettings.PrioritizeIVOverCP, _clientSettings.PokemonsToNotTransfer); if (pokemonToTransfer != null && pokemonToTransfer.Any()) { Logger.Write($"Found {pokemonToTransfer.Count()} Pokemon for Transfer:", LogLevel.Info); } foreach (var pokemon in pokemonToTransfer) { await _client.TransferPokemon(pokemon.Id); await Inventory.GetCachedInventory(_client, true); var myPokemonSettings = await _inventory.GetPokemonSettings(); var pokemonSettings = myPokemonSettings.ToList(); var myPokemonFamilies = await _inventory.GetPokemonFamilies(); var pokemonFamilies = myPokemonFamilies.ToArray(); var settings = pokemonSettings.Single(x => x.PokemonId == pokemon.PokemonId); var familyCandy = pokemonFamilies.Single(x => settings.FamilyId == x.FamilyId); var familyCandies = $"{familyCandy.Candy}"; _stats.IncreasePokemonsTransfered(); _stats.UpdateConsoleTitle(_client, _inventory); var bestPokemonOfType = _client.Settings.PrioritizeIVOverCP ? await _inventory.GetHighestPokemonOfTypeByIv(pokemon) : await _inventory.GetHighestPokemonOfTypeByCp(pokemon); var bestPokemonInfo = "NONE"; if (bestPokemonOfType != null) { bestPokemonInfo = $"CP: {bestPokemonOfType.Cp}/{PokemonInfo.CalculateMaxCp(bestPokemonOfType)} | IV: {PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType).ToString("0.00")}% perfect"; } Logger.Write($"{pokemon.PokemonId} [CP {pokemon.Cp}/{PokemonInfo.CalculateMaxCp(pokemon)} | IV: { PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect] | Best: [{bestPokemonInfo}] | Family Candies: {familyCandies}", LogLevel.Transfer); } }
private static async Task DoUpgrade(ISession session, PokemonData pokemon) { var upgradeResult = await session.Inventory.UpgradePokemon(pokemon.Id); if (upgradeResult.Result == POGOProtos.Networking.Responses.UpgradePokemonResponse.Types.Result.Success) { session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeSuccess, session.Translation.GetPokemonName(upgradeResult.UpgradedPokemon.PokemonId), upgradeResult.UpgradedPokemon.Cp) }); var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var pokemonSettings = (await session.Inventory.GetPokemonSettings()).ToList(); var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.PokemonId); var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId); session.EventDispatcher.Send(new PokemonStatsChangedEvent { Name = !string.IsNullOrEmpty(pokemon.Nickname) ? pokemon.Nickname : session.Translation.GetPokemonName(pokemon.PokemonId), Uid = pokemon.Id, Id = pokemon.PokemonId, Family = family.FamilyId, Candy = family.Candy_, Cp = upgradeResult.UpgradedPokemon.Cp, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(upgradeResult.UpgradedPokemon, session.Runtime.CurrentLevel), Iv = upgradeResult.UpgradedPokemon.CalculatePokemonPerfection(), Favourite = pokemon.Favorite == 1 }); } else if (upgradeResult.Result == POGOProtos.Networking.Responses.UpgradePokemonResponse.Types.Result.ErrorInsufficientResources) { session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeFailed) }); } // pokemon max level else if (upgradeResult.Result == POGOProtos.Networking.Responses.UpgradePokemonResponse.Types.Result.ErrorUpgradeNotAvailable) { session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeUnavailable, session.Translation.GetPokemonName(pokemon.PokemonId), pokemon.Cp, PokemonInfo.CalculateMaxCp(pokemon)) }); } else { session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeFailedError, session.Translation.GetPokemonName(pokemon.PokemonId)) }); } }
public static async Task CatchFromService(ISession session, CancellationToken cancellationToken, EncounterInfo encounterId) { //default to excellent throw var normalizedRecticleSize = 1.95; //default spin var spinModifier = 1.0; //round to 2 decimals normalizedRecticleSize = Math.Round(normalizedRecticleSize, 2); CatchPokemonResponse caughtPokemonResponse; double lat = session.Client.CurrentLatitude; double lon = session.Client.CurrentLongitude; CatchPokemonResponse.Types.CatchStatus lastThrow = CatchPokemonResponse.Types.CatchStatus.CatchSuccess; CatchPokemonTask.AmountOfBerries = 0; do { cancellationToken.ThrowIfCancellationRequested(); await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(encounterId.Latitude, encounterId.Longitude, session.Client.CurrentAltitude), 0); // Speed set to 0 for random speed. await Task.Delay(1000, cancellationToken); var encounter = await session.Client.Encounter.EncounterPokemon(encounterId.EncounterId, encounterId.SpawnPointId); await Task.Delay(1000, cancellationToken); await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(lat, lon, session.Client.CurrentAltitude), 0); // Speed set to 0 for random speed. float probability = encounter.CaptureProbability.CaptureProbability_[0]; int cp = encounter.WildPokemon.PokemonData.Cp; int maxcp = PokemonInfo.CalculateMaxCp(encounter.WildPokemon.PokemonData); double lvl = PokemonInfo.GetLevel(encounter.WildPokemon.PokemonData); PokemonData encounteredPokemon; // Catch if it's a WildPokemon (MSniping not allowed for Incense pokemons) if (encounter is EncounterResponse && (encounter?.Status == EncounterResponse.Types.Status.EncounterSuccess)) { encounteredPokemon = encounter.WildPokemon?.PokemonData; } else { return; // No success to work with } var bestBall = await CatchPokemonTask.GetBestBall(session, encounteredPokemon, probability); if (((session.LogicSettings.UseBerriesOperator.ToLower().Equals("and") && encounterId.Iv >= session.LogicSettings.UseBerriesMinIv && cp >= session.LogicSettings.UseBerriesMinCp && probability < session.LogicSettings.UseBerriesBelowCatchProbability) || (session.LogicSettings.UseBerriesOperator.ToLower().Equals("or") && ( encounterId.Iv >= session.LogicSettings.UseBerriesMinIv || cp >= session.LogicSettings.UseBerriesMinCp || probability < session.LogicSettings.UseBerriesBelowCatchProbability))) && lastThrow != CatchPokemonResponse.Types.CatchStatus.CatchMissed) // if last throw is a miss, no double berry { CatchPokemonTask.AmountOfBerries++; if (CatchPokemonTask.AmountOfBerries <= session.LogicSettings.MaxBerriesToUsePerPokemon) { await CatchPokemonTask.UseBerry(session, encounter.WildPokemon.EncounterId, encounter.WildPokemon.SpawnPointId); } } caughtPokemonResponse = await session.Client.Encounter.CatchPokemon(encounterId.EncounterId, encounterId.SpawnPointId, bestBall, normalizedRecticleSize, spinModifier, true); Logger.Write($"({caughtPokemonResponse.Status.ToString()}) {encounterId.PokemonId.ToString()} IV: {encounterId.Iv}% Lvl: {lvl} CP: ({cp}/{maxcp})", LogLevel.Service, caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? ConsoleColor.Green : ConsoleColor.Red); //CatchPokemonTask.AmountOfBerries await Task.Delay(1000, cancellationToken); lastThrow = caughtPokemonResponse.Status; } while (lastThrow == CatchPokemonResponse.Types.CatchStatus.CatchMissed || lastThrow == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
public async Task ExportPokemonToCsv(Profile player, string filename = "PokeList.csv") { if (player == null) { return; } var stats = await GetPlayerStats(); var stat = stats.FirstOrDefault(); if (stat == null) { return; } if (!Directory.Exists(_exportPath)) { Directory.CreateDirectory(_exportPath); } if (Directory.Exists(_exportPath)) { try { var pokelistFile = Path.Combine(_exportPath, $"Profile_{player.Username}_{filename}"); if (File.Exists(pokelistFile)) { File.Delete(pokelistFile); } var ls = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; const string header = "PokemonID,Name,NickName,Level,CP / MaxCP,IV Perfection in %,Attack 1,Attack 2,HP,Attk,Def,Stamina,Familie Candies,IsInGym,IsFavorite,previewLink"; File.WriteAllText(pokelistFile, $"{header.Replace(",", $"{ls}")}"); var allPokemon = await GetHighestsPerfect(); var myPokemonSettings = await GetPokemonSettings(); var pokemonSettings = myPokemonSettings.ToList(); var myPokemonFamilies = await GetPokemonFamilies(); var pokemonFamilies = myPokemonFamilies.ToArray(); var trainerLevel = stat.Level; var expReq = new[] { 0, 1000, 3000, 6000, 10000, 15000, 21000, 28000, 36000, 45000, 55000, 65000, 75000, 85000, 100000, 120000, 140000, 160000, 185000, 210000, 260000, 335000, 435000, 560000, 710000, 900000, 1100000, 1350000, 1650000, 2000000, 2500000, 3000000, 3750000, 4750000, 6000000, 7500000, 9500000, 12000000, 15000000, 20000000 }; var expReqAtLevel = expReq[stat.Level - 1]; using (var w = File.AppendText(pokelistFile)) { w.WriteLine(""); foreach (var pokemon in allPokemon) { var toEncode = $"{(int)pokemon.PokemonId}" + "," + trainerLevel + "," + PokemonInfo.GetLevel(pokemon) + "," + pokemon.Cp + "," + pokemon.Stamina; //Generate base64 code to make it viewable here http://poke.isitin.org/#MTUwLDIzLDE3LDE5MDIsMTE4 var encoded = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(toEncode)); var isInGym = string.Empty; //var isInGym = pokemon.DeployedFortId == 0 ? "Yes" : "No"; var isFavorite = pokemon.Favorite != 0 ? "Yes" : "No"; var settings = pokemonSettings.Single(x => x.PokemonId == pokemon.PokemonId); var familiecandies = pokemonFamilies.Single(x => settings.FamilyId == x.FamilyId).Candy; var perfection = PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00"); perfection = perfection.Replace(",", ls == "," ? "." : ","); string contentPart1 = $"\"{(int)pokemon.PokemonId}\",\"{pokemon.PokemonId}\",\"{pokemon.Nickname}\","; string contentPart2 = $",\"{pokemon.Cp} / {PokemonInfo.CalculateMaxCp(pokemon)}\","; string contentPart3 = $",\"{pokemon.Move1}\",\"{pokemon.Move2}\",\"{pokemon.Stamina}\",\"{pokemon.IndividualAttack}\",\"{pokemon.IndividualDefense}\",\"{pokemon.IndividualStamina}\",\"{familiecandies}\",\"{isInGym}\",\"{isFavorite}\",http://poke.isitin.org/#{encoded}"; string content = $"{contentPart1.Replace(",", $"{ls}")}\"{PokemonInfo.GetLevel(pokemon)}\"{contentPart2.Replace(",", $"{ls}")}\"{perfection}\"{contentPart3.Replace(",", $"{ls}")}"; w.WriteLine($"{content}"); } w.Close(); } Logger.Write($"Export Player Infos and all Pokemon to \"\\Export\\Profile_{player.Username}_{filename}\"", LogLevel.Info); } catch { Logger.Write("Export Player Infos and all Pokemons to CSV not possible. File seems be in use!", LogLevel.Warning); } } }
public static async Task Execute(ISession session) { var myPokemonFamilies = await session.Inventory.GetPokemonFamilies(); var myPokeSettings = await session.Inventory.GetPokemonSettings(); var highestsPokemonCp = await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart); var highestsPokemonCpForUpgrade = await session.Inventory.GetHighestsCp(50); var highestsPokemonIvForUpgrade = await session.Inventory.GetHighestsPerfect(50); var pokemonPairedWithStatsCp = highestsPokemonCp.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon), PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList(); var pokemonPairedWithStatsCpForUpgrade = highestsPokemonCpForUpgrade.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList(); var highestsPokemonPerfect = await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart); var pokemonPairedWithStatsIv = highestsPokemonPerfect.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon), PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList(); var pokemonPairedWithStatsIvForUpgrade = highestsPokemonIvForUpgrade.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList(); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "CP", PokemonList = pokemonPairedWithStatsCp }); await Task.Delay(500); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "IV", PokemonList = pokemonPairedWithStatsIv }); foreach (var pokemon in pokemonPairedWithStatsIvForUpgrade) { var dgdfs = pokemon.ToString(); var tokens = dgdfs.Split(new[] { "id" }, StringSplitOptions.None); var splitone = tokens[1].Split('"'); var iv = session.Inventory.GetPerfect(pokemon.Item1); if (iv >= session.LogicSettings.UpgradePokemonIvMinimum) { PokemonId.Add(ulong.Parse(splitone[2])); } } foreach (var t in pokemonPairedWithStatsCpForUpgrade) { var dgdfs = t.ToString(); var tokens = dgdfs.Split(new[] { "id" }, StringSplitOptions.None); var splitone = tokens[1].Split('"'); var tokensSplit = tokens[1].Split(new[] { "cp" }, StringSplitOptions.None); var tokenSplitAgain = tokensSplit[1].Split(' '); var tokenSplitAgain2 = tokenSplitAgain[1].Split(','); if (float.Parse(tokenSplitAgain2[0]) >= session.LogicSettings.UpgradePokemonCpMinimum) { PokemonIdcp.Add(ulong.Parse(splitone[2])); } } var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp ? await session.Inventory.GetHighestsPerfect(1000) : await session.Inventory.GetHighestsCp(1000); if (session.LogicSettings.DumpPokemonStats) { const string dumpFileName = "PokeBagStats"; Dumper.ClearDumpFile(session, dumpFileName); Dumper.Dump(session, "pokemonid,pokemonlevel,cp,perfection,stamina,staminamax,move1,move2,candy,ownername,origin,heightm,weightkg,individualattack,individualdefense,individualstamina,cpmultiplier,battlesattacked,battlesdefended,creationtimems,numupgrades,additionalcpmultiplier,favorite,nickname", dumpFileName); foreach (var pokemon in allPokemonInBag) { Dumper.Dump(session, $"{pokemon.PokemonId},{PokemonInfo.GetLevel(pokemon)},{pokemon.Cp},{PokemonInfo.CalculatePokemonPerfection(pokemon)},{pokemon.Stamina},{pokemon.StaminaMax},{pokemon.Move1},{pokemon.Move2},{PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings)},{pokemon.OwnerName},{pokemon.Origin},{pokemon.HeightM},{pokemon.WeightKg},{pokemon.IndividualAttack},{pokemon.IndividualDefense},{pokemon.IndividualStamina},{pokemon.CpMultiplier},{pokemon.BattlesAttacked},{pokemon.BattlesDefended},{pokemon.CreationTimeMs},{pokemon.NumUpgrades},{pokemon.AdditionalCpMultiplier},{pokemon.Favorite},{pokemon.Nickname}", dumpFileName); } } await Task.Delay(500); }
public static async Task Execute(ISession session) { var myPokemonFamilies = await session.Inventory.GetPokemonFamilies(); var myPokeSettings = await session.Inventory.GetPokemonSettings(); var highestsPokemonCp = await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart); var pokemonPairedWithStatsCp = highestsPokemonCp.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon), PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList(); var highestsPokemonPerfect = await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart); var pokemonPairedWithStatsIv = highestsPokemonPerfect.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon), PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList(); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "CP", PokemonList = pokemonPairedWithStatsCp }); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "IV", PokemonList = pokemonPairedWithStatsIv }); var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp ? await session.Inventory.GetHighestsPerfect(1000) : await session.Inventory.GetHighestsCp(1000); if (session.LogicSettings.DumpPokemonStats) { const string dumpFileName = "PokeBagStats"; try { Dumper.ClearDumpFile(session, dumpFileName); Dumper.Dump(session, "pokemonid,pokemonlevel,cp,perfection,stamina,staminamax,move1,move2,candy,ownername,origin,heightm,weightkg,individualattack,individualdefense,individualstamina,cpmultiplier,battlesattacked,battlesdefended,creationtimems,numupgrades,additionalcpmultiplier,favorite,nickname", dumpFileName); foreach (var pokemon in allPokemonInBag) { Dumper.Dump(session, $"{session.Translation.GetPokemonTranslation(pokemon.PokemonId)},{PokemonInfo.GetLevel(pokemon)},{pokemon.Cp},{PokemonInfo.CalculatePokemonPerfection(pokemon)},{pokemon.Stamina},{pokemon.StaminaMax},{pokemon.Move1},{pokemon.Move2},{PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings)},{pokemon.OwnerName},{pokemon.Origin},{pokemon.HeightM},{pokemon.WeightKg},{pokemon.IndividualAttack},{pokemon.IndividualDefense},{pokemon.IndividualStamina},{pokemon.CpMultiplier},{pokemon.BattlesAttacked},{pokemon.BattlesDefended},{pokemon.CreationTimeMs},{pokemon.NumUpgrades},{pokemon.AdditionalCpMultiplier},{pokemon.Favorite},{pokemon.Nickname}", dumpFileName); } } catch (IOException) { session.EventDispatcher.Send(new ErrorEvent { Message = $"Could not write {dumpFileName} dump file." }); } } }
public static async Task Execute(ISession session, dynamic encounter, MapPokemon pokemon, FortData currentFortData = null, ulong encounterId = 0) { if (encounter is EncounterResponse && pokemon == null) { throw new ArgumentException("Parameter pokemon must be set, if encounter is of type EncounterResponse", "pokemon"); } CatchPokemonResponse caughtPokemonResponse; var attemptCounter = 1; do { if (session.LogicSettings.MaxPokeballsPerPokemon > 0 && attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon) { break; } float probability = encounter?.CaptureProbability?.CaptureProbability_[0]; var pokeball = await GetBestBall(session, encounter, probability); if (pokeball == ItemId.ItemUnknown) { session.EventDispatcher.Send(new NoPokeballEvent { Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId, Cp = (encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter?.PokemonData?.Cp) ?? 0 }); return; } var isLowProbability = probability < session.LogicSettings.UseBerryBelowCatchProbability; var isHighCp = encounter != null && (encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter.PokemonData?.Cp) > session.LogicSettings.UseBerryMinCp; var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData) >= session.LogicSettings.UseBerryMinIv; if (isLowProbability && ((session.LogicSettings.PrioritizeIvOverCp && isHighPerfection) || isHighCp)) { await UseBerry(session, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData?.Id); } var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude); double normalizedRecticleSize, spinModifier; if (session.LogicSettings.HumanizeThrows) { normalizedRecticleSize = Rng.NextInRange(session.LogicSettings.ThrowAccuracyMin, session.LogicSettings.ThrowAccuracyMax) * 1.85 + 0.1; // 0.1..1.95 spinModifier = Rng.NextDouble() > session.LogicSettings.ThrowSpinFrequency ? 0.0 : 1.0; } else { normalizedRecticleSize = 1.95; spinModifier = 1.00; } caughtPokemonResponse = await session.Client.Encounter.CatchPokemon( encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData.Id, pokeball, normalizedRecticleSize, spinModifier); var lat = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude; var lng = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude; var evt = new PokemonCaptureEvent { Status = caughtPokemonResponse.Status, Latitude = lat, Longitude = lng }; if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { var totalExp = 0; foreach (var xp in caughtPokemonResponse.CaptureAward.Xp) { totalExp += xp; } var profile = await session.Client.Player.GetPlayer(); evt.Exp = totalExp; evt.Stardust = profile.PlayerData.Currencies.ToArray()[1].Amount; var pokemonSettings = await session.Inventory.GetPokemonSettings(); var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var setting = pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == pokemon.PokemonId); var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId); if (family != null) { family.Candy_ += caughtPokemonResponse.CaptureAward.Candy.Sum(); evt.FamilyCandies = family.Candy_; } else { evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum(); } } evt.CatchType = encounter is EncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeNormal) : encounter is DiskEncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeLure) : session.Translation.GetTranslation(TranslationString.CatchTypeIncense); evt.Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId; evt.Level = PokemonInfo.GetLevel(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); evt.Cp = encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter?.PokemonData?.Cp ?? 0; evt.MaxCp = PokemonInfo.CalculateMaxCp(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); evt.Perfection = Math.Round( PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData), 2); evt.Probability = Math.Round(probability * 100, 2); evt.Distance = distance; evt.Pokeball = pokeball; evt.Attempt = attemptCounter; await session.Inventory.RefreshCachedInventory(); evt.BallAmount = await session.Inventory.GetItemAmountByType(pokeball); session.EventDispatcher.Send(evt); attemptCounter++; if (session.LogicSettings.Teleport) { await Task.Delay(session.LogicSettings.DelayCatchPokemon); } else { await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPokemonCatch, 2000); } } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
public static async Task Execute(ISession session, ulong pokemonId, CancellationToken cancellationToken, bool toMax = false) { try { if (!await CheckBotStateTask.Execute(session, cancellationToken)) { return; } } catch (TaskCanceledException) { //ignore } catch (Exception ex) { Logger.Write($"[MANUAL TASAK FAIL] ERROR: {ex.Message}"); } var prevState = session.State; session.State = BotState.LevelPoke; var all = await session.Inventory.GetPokemons(); var pokemon = all.FirstOrDefault(p => p.Id == pokemonId); if (pokemon == null) { session.State = prevState; session.EventDispatcher.Send(new PokemonActionDoneEvent { Uid = pokemonId }); return; } if (!string.IsNullOrEmpty(pokemon.DeployedFortId)) { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.PokeInGym, string.IsNullOrEmpty(pokemon.Nickname) ? pokemon.PokemonId.ToString() : pokemon.Nickname) }); session.State = prevState; session.EventDispatcher.Send(new PokemonActionDoneEvent { Uid = pokemonId }); return; } if (pokemon.GetLevel() >= session.Runtime.CurrentLevel + 1.5) { session.State = prevState; session.EventDispatcher.Send(new PokemonActionDoneEvent { Uid = pokemonId }); return; } bool success; var max = false; UpgradePokemonResponse latestSuccessResponse = null; do { success = false; var upgradeResult = await session.Inventory.UpgradePokemon(pokemon.Id); await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 2000); switch (upgradeResult.Result) { case UpgradePokemonResponse.Types.Result.Success: success = true; latestSuccessResponse = upgradeResult; session.EventDispatcher.Send(new NoticeEvent { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeSuccess, session.Translation.GetPokemonName(upgradeResult.UpgradedPokemon.PokemonId), upgradeResult.UpgradedPokemon.Cp) }); if (upgradeResult.UpgradedPokemon.GetLevel() >= session.Runtime.CurrentLevel + 1.5) { max = true; } break; case UpgradePokemonResponse.Types.Result.ErrorInsufficientResources: session.EventDispatcher.Send(new NoticeEvent { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeFailed) }); break; case UpgradePokemonResponse.Types.Result.ErrorUpgradeNotAvailable: session.EventDispatcher.Send(new NoticeEvent { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeUnavailable, session.Translation.GetPokemonName(pokemon.PokemonId), pokemon.Cp, PokemonInfo.CalculateMaxCp(pokemon)) }); break; default: session.EventDispatcher.Send(new NoticeEvent { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeFailedError, session.Translation.GetPokemonName(pokemon.PokemonId)) }); break; } } while (success && toMax && !cancellationToken.IsCancellationRequested && !max); if (latestSuccessResponse != null && !cancellationToken.IsCancellationRequested) { var mon = latestSuccessResponse.UpgradedPokemon; var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var pokemonSettings = (await session.Inventory.GetPokemonSettings()).ToList(); var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.PokemonId); var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId); session.EventDispatcher.Send(new PokemonStatsChangedEvent { Name = !string.IsNullOrEmpty(mon.Nickname) ? mon.Nickname : session.Translation.GetPokemonName(mon.PokemonId), Uid = pokemonId, Id = mon.PokemonId, Family = family.FamilyId, Candy = family.Candy_, Cp = mon.Cp, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(mon, session.Runtime.CurrentLevel), Iv = mon.CalculatePokemonPerfection(), Favourite = mon.Favorite == 1, Weight = mon.WeightKg, Cpm = mon.CpMultiplier + mon.AdditionalCpMultiplier, Level = mon.GetLevel(), IvDef = mon.IndividualDefense, IvAtk = mon.IndividualAttack, Stamina = mon.Stamina, StaminaMax = mon.StaminaMax }); session.EventDispatcher.Send(new PokemonActionDoneEvent { Uid = pokemonId }); } session.State = prevState; }
/// <summary> /// Because this function sometime being called inside loop, return true it mean we don't want break look, false it mean not need to call this , break a loop from caller function /// </summary> /// <param name="session"></param> /// <param name="cancellationToken"></param> /// <param name="encounter"></param> /// <param name="pokemon"></param> /// <param name="currentFortData"></param> /// <param name="sessionAllowTransfer"></param> /// <returns></returns> public static async Task <bool> Execute(ISession session, CancellationToken cancellationToken, dynamic encounter, MapPokemon pokemon, FortData currentFortData, bool sessionAllowTransfer) { var manager = TinyIoCContainer.Current.Resolve <MultiAccountManager>(); manager.ThrowIfSwitchAccountRequested(); // If the encounter is null nothing will work below, so exit now if (encounter == null) { return(true); } 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 < BALL_REQUIRED_TO_BYPASS_CATCHFLEE) { return(false); } // Exit if user defined max limits reached if (session.Stats.CatchThresholdExceeds(session)) { if (manager.AllowMultipleBot() && session.LogicSettings.MultipleBotConfig.SwitchOnCatchLimit && TinyIoCContainer.Current.Resolve <MultiAccountManager>().AllowSwitch()) { throw new ActiveSwitchByRuleException() { MatchedRule = SwitchRules.CatchLimitReached, ReachedValue = session.LogicSettings.CatchPokemonLimit }; } return(false); } using (var block = new BlockableScope(session, BotActions.Catch)) { if (!await block.WaitToRun().ConfigureAwait(false)) { return(true); } AmountOfBerries = new Dictionary <ItemId, int>(); cancellationToken.ThrowIfCancellationRequested(); float probability = encounter.CaptureProbability?.CaptureProbability_[0]; PokemonData encounteredPokemon; long unixTimeStamp; ulong _encounterId; string _spawnPointId; // Calling from CatchNearbyPokemonTask and SnipePokemonTask if (encounter is EncounterResponse && (encounter?.Status == EncounterResponse.Types.Status.EncounterSuccess)) { encounteredPokemon = encounter.WildPokemon?.PokemonData; unixTimeStamp = encounter.WildPokemon?.LastModifiedTimestampMs + encounter.WildPokemon?.TimeTillHiddenMs; _spawnPointId = encounter.WildPokemon?.SpawnPointId; _encounterId = encounter.WildPokemon?.EncounterId; } // Calling from CatchIncensePokemonTask else if (encounter is IncenseEncounterResponse && (encounter?.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess)) { encounteredPokemon = encounter?.PokemonData; unixTimeStamp = pokemon.ExpirationTimestampMs; _spawnPointId = pokemon.SpawnPointId; _encounterId = pokemon.EncounterId; } // Calling from CatchLurePokemon else if (encounter is DiskEncounterResponse && encounter?.Result == DiskEncounterResponse.Types.Result.Success && !(currentFortData == null)) { encounteredPokemon = encounter?.PokemonData; unixTimeStamp = currentFortData.LureInfo.LureExpiresTimestampMs; _spawnPointId = currentFortData.Id; _encounterId = currentFortData.LureInfo.EncounterId; } else { return(true); // No success to work with, exit } // Check for pokeballs before proceeding var pokeball = await GetBestBall(session, encounteredPokemon, probability).ConfigureAwait(false); if (pokeball == ItemId.ItemUnknown) { Logger.Write(session.Translation.GetTranslation(TranslationString.ZeroPokeballInv)); return(false); } // Calculate CP and IV var pokemonCp = encounteredPokemon?.Cp; var pokemonIv = PokemonInfo.CalculatePokemonPerfection(encounteredPokemon); var lv = PokemonInfo.GetLevel(encounteredPokemon); // Calculate distance away var latitude = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude; var longitude = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude; var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, latitude, longitude); if (session.LogicSettings.ActivateMSniper) { var newdata = new MSniperServiceTask.EncounterInfo() { EncounterId = _encounterId.ToString(), Iv = Math.Round(pokemonIv, 2), Latitude = latitude.ToString("G17", CultureInfo.InvariantCulture), Longitude = longitude.ToString("G17", CultureInfo.InvariantCulture), PokemonId = (int)(encounteredPokemon?.PokemonId ?? 0), PokemonName = encounteredPokemon?.PokemonId.ToString(), SpawnPointId = _spawnPointId, Move1 = PokemonInfo.GetPokemonMove1(encounteredPokemon).ToString(), Move2 = PokemonInfo.GetPokemonMove2(encounteredPokemon).ToString(), Expiration = unixTimeStamp }; session.EventDispatcher.Send(newdata); } DateTime expiredDate = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(Convert.ToDouble(unixTimeStamp)); var encounterEV = new EncounteredEvent() { Latitude = latitude, Longitude = longitude, PokemonId = encounteredPokemon.PokemonId, IV = pokemonIv, Level = (int)lv, Expires = expiredDate.ToUniversalTime(), ExpireTimestamp = unixTimeStamp, SpawnPointId = _spawnPointId, EncounterId = _encounterId.ToString(), Move1 = PokemonInfo.GetPokemonMove1(encounteredPokemon).ToString(), Move2 = PokemonInfo.GetPokemonMove2(encounteredPokemon).ToString(), }; //add catch to avoid snipe duplicate string uniqueCacheKey = CatchPokemonTask.GetUsernameGeoLocationCacheKey(session.Settings.Username, encounterEV.PokemonId, encounterEV.Latitude, encounterEV.Longitude); session.Cache.Add(uniqueCacheKey, encounterEV, DateTime.Now.AddMinutes(30)); session.EventDispatcher.Send(encounterEV); if (IsNotMetWithCatchCriteria(session, encounteredPokemon, pokemonIv, lv, pokemonCp)) { session.EventDispatcher.Send(new NoticeEvent { Message = session.Translation.GetTranslation(TranslationString.PokemonSkipped, encounteredPokemon.PokemonId) }); session.Cache.Add(CatchPokemonTask.GetEncounterCacheKey(_encounterId), encounteredPokemon, expiredDate); Logger.Write( $"Filter catch not met. {encounteredPokemon.PokemonId.ToString()} IV {pokemonIv} lv {lv} {pokemonCp} move1 {PokemonInfo.GetPokemonMove1(encounteredPokemon)} move 2 {PokemonInfo.GetPokemonMove2(encounteredPokemon)}"); return(true); } CatchPokemonResponse caughtPokemonResponse = null; var lastThrow = CatchPokemonResponse.Types.CatchStatus.CatchSuccess; // Initializing lastThrow var attemptCounter = 1; // Main CatchPokemon-loop do { if (session.LogicSettings.UseHumanlikeDelays) { await DelayingUtils.DelayAsync(session.LogicSettings.BeforeCatchDelay, 0, session.CancellationTokenSource.Token).ConfigureAwait(false); } if ((session.LogicSettings.MaxPokeballsPerPokemon > 0 && attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon)) { break; } pokeball = await GetBestBall(session, encounteredPokemon, probability).ConfigureAwait(false); if (pokeball == ItemId.ItemUnknown) { session.EventDispatcher.Send(new NoPokeballEvent { Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId, Cp = encounteredPokemon.Cp }); return(false); } // Determine whether to use berries or not if (lastThrow != CatchPokemonResponse.Types.CatchStatus.CatchMissed) { //AmountOfBerries++; //if (AmountOfBerries <= session.LogicSettings.MaxBerriesToUsePerPokemon) await UseBerry(session, encounterEV.PokemonId, _encounterId, _spawnPointId, pokemonIv, pokemonCp ?? 10000, //unknown CP pokemon, want to use berry encounterEV.Level, probability, cancellationToken).ConfigureAwait(false); } bool hitPokemon = true; //default to excellent throw var normalizedRecticleSize = 1.95; //default spin var spinModifier = 1.0; //Humanized throws if (session.LogicSettings.EnableHumanizedThrows) { //thresholds: https://gist.github.com/anonymous/077d6dea82d58b8febde54ae9729b1bf var spinTxt = "Curve"; var hitTxt = "Excellent"; if (pokemonCp > session.LogicSettings.ForceExcellentThrowOverCp || pokemonIv > session.LogicSettings.ForceExcellentThrowOverIv) { normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.7) + 1.7; } else if (pokemonCp >= session.LogicSettings.ForceGreatThrowOverCp || pokemonIv >= session.LogicSettings.ForceGreatThrowOverIv) { normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.3) + 1.3; hitTxt = "Great"; } else { var regularThrow = 100 - (session.LogicSettings.ExcellentThrowChance + session.LogicSettings.GreatThrowChance + session.LogicSettings.NiceThrowChance); var rnd = Random.Next(1, 101); if (rnd <= regularThrow) { normalizedRecticleSize = Random.NextDouble() * (1 - 0.1) + 0.1; hitTxt = "Ordinary"; } else if (rnd <= regularThrow + session.LogicSettings.NiceThrowChance) { normalizedRecticleSize = Random.NextDouble() * (1.3 - 1) + 1; hitTxt = "Nice"; } else if (rnd <= regularThrow + session.LogicSettings.NiceThrowChance + session.LogicSettings.GreatThrowChance) { normalizedRecticleSize = Random.NextDouble() * (1.7 - 1.3) + 1.3; hitTxt = "Great"; } if (Random.NextDouble() * 100 > session.LogicSettings.CurveThrowChance) { spinModifier = 0.0; spinTxt = "Straight"; } } // Round to 2 decimals normalizedRecticleSize = Math.Round(normalizedRecticleSize, 2); // Missed throw check int missChance = Random.Next(1, 101); if (missChance <= session.LogicSettings.ThrowMissPercentage && session.LogicSettings.EnableMissedThrows) { hitPokemon = false; } Logger.Write($"(Threw ball) {hitTxt} throw, {spinTxt}-ball, HitPokemon = {hitPokemon}...", LogLevel.Debug); } if (CatchFleeContinuouslyCount >= 3 && session.LogicSettings.ByPassCatchFlee) { MSniperServiceTask.BlockSnipe(); if (totalBalls <= BALL_REQUIRED_TO_BYPASS_CATCHFLEE) { Logger.Write("You don't have enough balls to bypass catchflee"); return(false); } List <ItemId> ballToByPass = new List <ItemId>(); var numPokeBalls = await session.Inventory.GetItemAmountByType(ItemId.ItemPokeBall).ConfigureAwait(false); for (int i = 0; i < numPokeBalls - 1; i++) { ballToByPass.Add(ItemId.ItemPokeBall); } var numGreatBalls = await session.Inventory.GetItemAmountByType(ItemId.ItemGreatBall).ConfigureAwait(false); for (int i = 0; i < numGreatBalls - 1; i++) { ballToByPass.Add(ItemId.ItemGreatBall); } var numUltraBalls = await session.Inventory.GetItemAmountByType(ItemId.ItemUltraBall).ConfigureAwait(false); for (int i = 0; i < numUltraBalls - 1; i++) { ballToByPass.Add(ItemId.ItemUltraBall); } bool catchMissed = true; Random r = new Random(); for (int i = 0; i < ballToByPass.Count - 1; i++) { if (i > 130 && r.Next(0, 100) <= 30) { catchMissed = false; } else { catchMissed = true; } caughtPokemonResponse = await session.Client.Encounter.CatchPokemon( encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : _encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData.Id, ballToByPass[i], 1.0, 1.0, !catchMissed).ConfigureAwait(false); await session.Inventory.UpdateInventoryItem(ballToByPass[i]).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); Logger.Write($"CatchFlee By pass : {ballToByPass[i].ToString()} , Attempt {i}, result {caughtPokemonResponse.Status}"); if (caughtPokemonResponse.Status != CatchPokemonResponse.Types.CatchStatus.CatchMissed) { session.SaveBallForByPassCatchFlee = false; CatchFleeContinuouslyCount = 0; break; } } } else { caughtPokemonResponse = await session.Client.Encounter.CatchPokemon( encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : _encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData.Id, pokeball, normalizedRecticleSize, spinModifier, hitPokemon).ConfigureAwait(false); await session.Inventory.UpdateInventoryItem(pokeball).ConfigureAwait(false); } var evt = new PokemonCaptureEvent() { Status = caughtPokemonResponse.Status, CaptureReason = caughtPokemonResponse.CaptureReason, Latitude = latitude, Longitude = longitude }; lastThrow = caughtPokemonResponse.Status; // sets lastThrow status if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { evt.Shiny = (await session.Inventory.GetPokemons().ConfigureAwait(false)).First(x => x.Id == caughtPokemonResponse.CapturedPokemonId).PokemonDisplay.Shiny ? "Yes" : "No"; evt.Form = (await session.Inventory.GetPokemons().ConfigureAwait(false)).First(x => x.Id == caughtPokemonResponse.CapturedPokemonId).PokemonDisplay.Form.ToString().Replace("Unown", "").Replace("Unset", "Normal"); evt.Costume = (await session.Inventory.GetPokemons().ConfigureAwait(false)).First(x => x.Id == caughtPokemonResponse.CapturedPokemonId).PokemonDisplay.Costume.ToString().Replace("Unset", "Regular"); evt.Gender = (await session.Inventory.GetPokemons().ConfigureAwait(false)).First(x => x.Id == caughtPokemonResponse.CapturedPokemonId).PokemonDisplay.Gender.ToString(); var totalExp = 0; var stardust = caughtPokemonResponse.CaptureAward.Stardust.Sum(); var totalStarDust = session.Inventory.UpdateStarDust(stardust); var CaptuerXP = caughtPokemonResponse.CaptureAward.Xp.Sum(); if (encounteredPokemon != null) { encounteredPokemon.Id = caughtPokemonResponse.CapturedPokemonId; } foreach (var xp in caughtPokemonResponse.CaptureAward.Xp) { totalExp += xp; } //This accounts for XP for CatchFlee if (totalExp < 1) { totalExp = 25; } evt.Exp = totalExp; evt.Stardust = stardust; evt.UniqueId = caughtPokemonResponse.CapturedPokemonId; evt.Candy = await session.Inventory.GetCandyFamily(pokemon.PokemonId).ConfigureAwait(false); evt.totalStarDust = totalStarDust; if (session.LogicSettings.AutoFavoriteShinyOnCatch) { if (evt.Shiny == "Yes") { await FavoritePokemonTask.Execute(session, encounteredPokemon.Id, true); Logger.Write($"You've caught a Shiny Pokemon ({encounteredPokemon.Nickname}) and it has been Favorited."); } } } if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee) { // Also count catch flee against the catch limit if (session.LogicSettings.UseCatchLimit) { session.Stats.AddPokemonTimestamp(DateTime.Now.Ticks); session.EventDispatcher.Send(new CatchLimitUpdate(session.Stats.GetNumPokemonsInLast24Hours(), session.LogicSettings.CatchPokemonLimit)); } } evt.CatchType = encounter is EncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeNormal) : encounter is DiskEncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeLure) : session.Translation.GetTranslation(TranslationString.CatchTypeIncense); evt.CatchTypeText = encounter is EncounterResponse ? "normal" : encounter is DiskEncounterResponse ? "lure" : "incense"; evt.Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId; evt.EncounterId = _encounterId; evt.Move1 = PokemonInfo.GetPokemonMove1(encounteredPokemon); evt.Move2 = PokemonInfo.GetPokemonMove2(encounteredPokemon); evt.Expires = pokemon?.ExpirationTimestampMs ?? 0; evt.SpawnPointId = _spawnPointId; evt.Level = PokemonInfo.GetLevel(encounteredPokemon); evt.Cp = encounteredPokemon.Cp; evt.MaxCp = PokemonInfo.CalculateMaxCp(encounteredPokemon.PokemonId); evt.Perfection = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounteredPokemon), 2); evt.Probability = Math.Round(probability * 100, 2); evt.Distance = distance; evt.Pokeball = pokeball; evt.Attempt = attemptCounter; //await session.Inventory.RefreshCachedInventory().ConfigureAwait(false); evt.BallAmount = await session.Inventory.GetItemAmountByType(pokeball).ConfigureAwait(false); evt.Rarity = PokemonGradeHelper.GetPokemonGrade(evt.Id).ToString(); session.EventDispatcher.Send(evt); attemptCounter++; // If Humanlike delays are used if (session.LogicSettings.UseHumanlikeDelays) { switch (caughtPokemonResponse.Status) { case CatchPokemonResponse.Types.CatchStatus.CatchError: await DelayingUtils.DelayAsync(session.LogicSettings.CatchErrorDelay, 0, session.CancellationTokenSource.Token).ConfigureAwait(false); break; case CatchPokemonResponse.Types.CatchStatus.CatchSuccess: await DelayingUtils.DelayAsync(session.LogicSettings.CatchSuccessDelay, 0, session.CancellationTokenSource.Token).ConfigureAwait(false); break; case CatchPokemonResponse.Types.CatchStatus.CatchEscape: await DelayingUtils.DelayAsync(session.LogicSettings.CatchEscapeDelay, 0, session.CancellationTokenSource.Token).ConfigureAwait(false); break; case CatchPokemonResponse.Types.CatchStatus.CatchFlee: await DelayingUtils.DelayAsync(session.LogicSettings.CatchFleeDelay, 0, session.CancellationTokenSource.Token).ConfigureAwait(false); break; case CatchPokemonResponse.Types.CatchStatus.CatchMissed: await DelayingUtils.DelayAsync(session.LogicSettings.CatchMissedDelay, 0, session.CancellationTokenSource.Token).ConfigureAwait(false); break; default: break; } } else { await DelayingUtils.DelayAsync(session.LogicSettings.DelayBetweenPlayerActions, 0, session.CancellationTokenSource.Token).ConfigureAwait(false); } } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee) { CatchFleeContinuouslyCount++; if (CatchFleeContinuouslyCount >= 3 && session.LogicSettings.ByPassCatchFlee) { session.SaveBallForByPassCatchFlee = true; Logger.Write("Seem that bot has been catch flee softban, Bot will start save 100 balls to by pass it."); } if (manager.AllowMultipleBot() && !session.LogicSettings.ByPassCatchFlee) { if (CatchFleeContinuouslyCount > session.LogicSettings.MultipleBotConfig.CatchFleeCount && TinyIoCContainer.Current.Resolve <MultiAccountManager>().AllowSwitch()) { CatchFleeContinuouslyCount = 0; session.SaveBallForByPassCatchFlee = false; throw new ActiveSwitchByRuleException() { MatchedRule = SwitchRules.CatchFlee, ReachedValue = session.LogicSettings.MultipleBotConfig.CatchFleeCount }; } } } else { //reset if not catch flee. if (caughtPokemonResponse.Status != CatchPokemonResponse.Types.CatchStatus.CatchMissed) { CatchFleeContinuouslyCount = 0; MSniperServiceTask.UnblockSnipe(); } } session.Actions.RemoveAll(x => x == BotActions.Catch); if (MultipleBotConfig.IsMultiBotActive(session.LogicSettings, manager)) { ExecuteSwitcher(session, encounterEV); } if (session.LogicSettings.TransferDuplicatePokemonOnCapture && session.LogicSettings.TransferDuplicatePokemon && sessionAllowTransfer && caughtPokemonResponse != null && caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { if (session.LogicSettings.UseNearActionRandom) { await HumanRandomActionTask.TransferRandom(session, cancellationToken).ConfigureAwait(false); } else { await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false); } } } return(true); }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested(); try { var playerStats = (await session.Inventory.GetPlayerStats().ConfigureAwait(false)).FirstOrDefault(); if (playerStats == null) { return; } var kmWalked = playerStats.KmWalked; var incubators = (await session.Inventory.GetEggIncubators().ConfigureAwait(false)) .Where(x => x.UsesRemaining > 0 || x.ItemId == ItemId.ItemIncubatorBasicUnlimited) .OrderByDescending(x => x.ItemId == ItemId.ItemIncubatorBasicUnlimited) .ToList(); var unusedEggs = (await session.Inventory.GetEggs().ConfigureAwait(false)) .Where(x => string.IsNullOrEmpty(x.EggIncubatorId)) .OrderBy(x => x.EggKmWalkedTarget - x.EggKmWalkedStart) .ToList(); var rememberedIncubatorsFilePath = Path.Combine(session.LogicSettings.ProfilePath, "temp", "incubators.json"); var rememberedIncubators = GetRememberedIncubators(rememberedIncubatorsFilePath); var pokemons = (await session.Inventory.GetPokemons().ConfigureAwait(false)).ToList(); // Check if eggs in remembered incubator usages have since hatched // (instead of calling session.Client.Inventory.GetHatchedEgg(), which doesn't seem to work properly) foreach (var incubator in rememberedIncubators) { var hatched = pokemons.FirstOrDefault(x => !x.IsEgg && x.Id == incubator.PokemonId); if (hatched == null) { continue; } //Still Needs some work(TheWizard1328) var stats = session.RuntimeStatistics; var KMs = playerStats.KmWalked - hatched.EggKmWalkedStart; var stardust1 = session.Inventory.GetStarDust(); var stardust2 = stats.TotalStardust; var ExpAwarded1 = playerStats.Experience; // Total Player Exp var ExpAwarded2 = stats.TotalExperience; // Session Exp var TotCandy = session.Inventory.GetCandyCount(hatched.PokemonId); Logger.Write($"Hatch: KM Walked: {KMs}, kmWalked: {kmWalked}, KmToWalk: {KmToWalk} | " + "XP1: {ExpAwarded1} | XP2: {ExpAwarded2} | " + "SD1: {stardust1}, SD2: {stardust2}", LogLevel.Egg); session.EventDispatcher.Send(new EggHatchedEvent { Dist = kmWalked - KmToWalk, //Still working on this(TheWizard1328) Id = hatched.Id, PokemonId = hatched.PokemonId, Level = PokemonInfo.GetLevel(hatched), Cp = hatched.Cp, MaxCp = PokemonInfo.CalculateMaxCp(hatched.PokemonId), Perfection = Math.Round(PokemonInfo.CalculatePokemonPerfection(hatched), 2), HXP = ExpAwarded1, HSD = stardust2, HCandy = await TotCandy, }); } var newRememberedIncubators = new List <IncubatorUsage>(); foreach (var incubator in incubators) { cancellationToken.ThrowIfCancellationRequested(); TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested(); if (incubator.PokemonId == 0) { // Unlimited incubators prefer short eggs, limited incubators prefer long eggs // Special case: If only one incubator is available at all, it will prefer long eggs var egg = (incubator.ItemId == ItemId.ItemIncubatorBasicUnlimited && incubators.Count > 1) ? unusedEggs.FirstOrDefault() : unusedEggs.LastOrDefault(); if (egg == null) { continue; } // Skip (save) limited incubators depending on user choice in config if (!session.LogicSettings.UseLimitedEggIncubators && incubator.ItemId != ItemId.ItemIncubatorBasicUnlimited) { continue; } var response = await session.Client.Inventory.UseItemEggIncubator(incubator.Id, egg.Id).ConfigureAwait(false); unusedEggs.Remove(egg); newRememberedIncubators.Add(new IncubatorUsage { IncubatorId = incubator.Id, PokemonId = egg.Id }); session.EventDispatcher.Send(new EggIncubatorStatusEvent { IncubatorId = incubator.Id, WasAddedNow = true, PokemonId = egg.Id, KmToWalk = egg.EggKmWalkedTarget, KmRemaining = response.EggIncubator.TargetKmWalked - kmWalked }); } else { newRememberedIncubators.Add(new IncubatorUsage { IncubatorId = incubator.Id, PokemonId = incubator.PokemonId }); session.EventDispatcher.Send(new EggIncubatorStatusEvent { IncubatorId = incubator.Id, PokemonId = incubator.PokemonId, KmToWalk = incubator.TargetKmWalked - incubator.StartKmWalked, KmRemaining = incubator.TargetKmWalked - kmWalked }); } } if (!newRememberedIncubators.SequenceEqual(rememberedIncubators)) { SaveRememberedIncubators(newRememberedIncubators, rememberedIncubatorsFilePath); } } catch (Exception) { } }
public static async Task Execute(ISession session, ulong pokemonId, CancellationToken cancellationToken, bool toMax = false) { if (!await CheckBotStateTask.Execute(session, cancellationToken)) { return; } var prevState = session.State; session.State = BotState.LevelPoke; var all = await session.Inventory.GetPokemons(); var pokemon = all.FirstOrDefault(p => p.Id == pokemonId); if (pokemon == null) { return; } if (!string.IsNullOrEmpty(pokemon.DeployedFortId)) { session.EventDispatcher.Send(new WarnEvent() { Message = $"Pokemon {(string.IsNullOrEmpty(pokemon.Nickname) ? pokemon.PokemonId.ToString() : pokemon.Nickname)} is signed to defend a GYM!" }); return; } bool success; UpgradePokemonResponse latestSuccessResponse = null; do { success = false; var upgradeResult = await session.Inventory.UpgradePokemon(pokemon.Id); switch (upgradeResult.Result) { case UpgradePokemonResponse.Types.Result.Success: success = true; latestSuccessResponse = upgradeResult; session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeSuccess, session.Translation.GetPokemonName(upgradeResult.UpgradedPokemon.PokemonId), upgradeResult.UpgradedPokemon.Cp) }); break; case UpgradePokemonResponse.Types.Result.ErrorInsufficientResources: session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeFailed) }); break; case UpgradePokemonResponse.Types.Result.ErrorUpgradeNotAvailable: session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeUnavailable, session.Translation.GetPokemonName(pokemon.PokemonId), pokemon.Cp, PokemonInfo.CalculateMaxCp(pokemon)) }); break; default: session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeFailedError, session.Translation.GetPokemonName(pokemon.PokemonId)) }); break; } await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 2000); } while (success && toMax); if (latestSuccessResponse != null) { var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var pokemonSettings = (await session.Inventory.GetPokemonSettings()).ToList(); var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.PokemonId); var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId); session.EventDispatcher.Send(new PokemonStatsChangedEvent { Name = !string.IsNullOrEmpty(pokemon.Nickname) ? pokemon.Nickname : session.Translation.GetPokemonName(pokemon.PokemonId), Uid = pokemonId, Id = pokemon.PokemonId, Family = family.FamilyId, Candy = family.Candy_, Cp = latestSuccessResponse.UpgradedPokemon.Cp, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(latestSuccessResponse.UpgradedPokemon, session.Runtime.CurrentLevel), Iv = latestSuccessResponse.UpgradedPokemon.CalculatePokemonPerfection(), Favourite = pokemon.Favorite == 1 }); } session.State = prevState; }
public static async Task Execute(dynamic encounter, MapPokemon pokemon, FortData currentFortData = null, ulong encounterId = 0) { // If the encounter is null nothing will work below, so exit now if (encounter == null) { return; } float probability = encounter.CaptureProbability?.CaptureProbability_[0]; var catchType = encounter is EncounterResponse ? "Normal" : encounter is DiskEncounterResponse ? "Lure" : "Incense"; var Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId; var Level = PokemonInfo.GetLevel(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); var Cp = encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter?.PokemonData?.Cp ?? 0; var MaxCp = PokemonInfo.CalculateMaxCp(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); var Iv = PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); var Probability = Math.Round(probability * 100, 2); var distance = LocationUtils.CalculateDistanceInMeters(Logic._client.CurrentLatitude, Logic._client.CurrentLongitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude); if (!float.IsNaN(probability) && probability < 0.35) { await UseBerry(encounter is EncounterResponse || encounter is IncenseEncounterResponse?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse?pokemon.SpawnPointId : currentFortData?.Id); } CatchPokemonResponse caughtPokemonResponse; var attemptCounter = 1; do { var pokeball = await GetBestBall(encounter, probability); if (pokeball == ItemId.ItemUnknown) { Logger.Write($"You don't own any Pokeballs :( - We missed a {Id} with CP {Cp}", LogLevel.Warning); return; } caughtPokemonResponse = await Logic._client.Encounter.CatchPokemon( encounter is EncounterResponse || encounter is IncenseEncounterResponse?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse?pokemon.SpawnPointId : currentFortData.Id, pokeball); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { BotStats.ExperienceThisSession += caughtPokemonResponse.CaptureAward.Xp.Sum(); BotStats.PokemonCaughtThisSession += 1; await BotStats.GetPokeDexCount(); await BotStats.GetPokemonCount(); var profile = await Logic._client.Player.GetPlayer(); BotStats.TotalStardust = profile.PlayerData.Currencies.ToArray()[1].Amount; BotStats.UpdateConsoleTitle(); } 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 receivedXp = caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"and received XP {caughtPokemonResponse.CaptureAward.Xp.Sum()}" : $""; await Inventory.GetCachedInventory(true); var BallAmount = await Inventory.GetItemAmountByType(pokeball); Logger.Write($"({catchStatus} / {catchType}) | {Id} - Lvl {Level} [CP {Cp}/{MaxCp} | IV: {Iv.ToString("0.00")}% perfect] | Chance: {Probability} | {distance:0.##}m dist | with a {returnRealBallName(pokeball)}Ball [Remaining: {BallAmount}] {receivedXp}", LogLevel.Pokemon); } attemptCounter++; }while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
public static async Task Execute(ISession session, dynamic encounter, MapPokemon pokemon, FortData currentFortData = null, ulong encounterId = 0) { CatchPokemonResponse caughtPokemonResponse; var attemptCounter = 1; do { if (session.LogicSettings.MaxPokeballsPerPokemon > 0 && attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon) { break; } float probability = encounter?.CaptureProbability?.CaptureProbability_[0]; var pokeball = await GetBestBall(session, encounter, probability); if (pokeball == ItemId.ItemUnknown) { session.EventDispatcher.Send(new NoPokeballEvent { Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId, Cp = (encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter?.PokemonData?.Cp) ?? 0 }); return; } var isLowProbability = probability < 0.35; var isHighCp = encounter != null && (encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter.PokemonData?.Cp) > 400; var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData) >= session.LogicSettings.KeepMinIvPercentage; if ((isLowProbability && isHighCp) || isHighPerfection) { await UseBerry(session, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData?.Id); } var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude); caughtPokemonResponse = await session.Client.Encounter.CatchPokemon( encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData.Id, pokeball); 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 = await session.Client.Player.GetPlayer(); evt.Exp = totalExp; evt.Stardust = profile.PlayerData.Currencies.ToArray()[1].Amount; var pokemonSettings = await session.Inventory.GetPokemonSettings(); var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var setting = pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == pokemon.PokemonId); var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId); if (family != null) { family.Candy_ += caughtPokemonResponse.CaptureAward.Candy.Sum(); evt.FamilyCandies = family.Candy_; } else { evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum(); } } evt.CatchType = encounter is EncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeNormal) : encounter is DiskEncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeLure) : session.Translation.GetTranslation(TranslationString.CatchTypeIncense); evt.Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId; evt.Level = PokemonInfo.GetLevel(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); evt.Cp = encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter?.PokemonData?.Cp ?? 0; evt.MaxCp = PokemonInfo.CalculateMaxCp(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); evt.Perfection = Math.Round( PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData)); evt.Probability = Math.Round(probability * 100, 2); evt.Distance = distance; evt.Pokeball = pokeball; evt.Attempt = attemptCounter; await session.Inventory.RefreshCachedInventory(); evt.BallAmount = await session.Inventory.GetItemAmountByType(pokeball); session.EventDispatcher.Send(evt); attemptCounter++; DelayingUtils.Delay(session.LogicSettings.DelayBetweenPokemonCatch, 2000); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
public static async Task Execute(ISession session) { var highestsPokemonCp = await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart).ConfigureAwait(false); var pokemonPairedWithStatsCp = highestsPokemonCp.Select( pokemon => Tuple.Create( pokemon, PokemonInfo.CalculateMaxCp(pokemon.PokemonId), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon), PokemonInfo.GetCandy(session, pokemon).Result ) ) .ToList(); var highestsPokemonPerfect = await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart).ConfigureAwait(false); var pokemonPairedWithStatsIv = highestsPokemonPerfect.Select( pokemon => Tuple.Create( pokemon, PokemonInfo.CalculateMaxCp(pokemon.PokemonId), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon), PokemonInfo.GetCandy(session, pokemon).Result ) ) .ToList(); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "CP", PokemonList = pokemonPairedWithStatsCp }); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "IV", PokemonList = pokemonPairedWithStatsIv }); var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp ? await session.Inventory.GetHighestsPerfect(1000).ConfigureAwait(false) : await session.Inventory.GetHighestsCp(1000).ConfigureAwait(false); if (session.LogicSettings.DumpPokemonStats) { _MultiAccountManager = new MultiAccountManager(); var account = _MultiAccountManager.GetCurrentAccount(); string dumpFileName = account.Nickname; // "-PokeBagStats"; //If user dump file exists then cancel file dump if (File.Exists(Path.Combine(Path.Combine(session.LogicSettings.ProfilePath, "Dumps"), $"{dumpFileName}-NecroBot2 DumpFile.csv"))) { return; } try { Dumper.ClearDumpFile(session, dumpFileName); string[] data = { "Pokemon", "Candies", "Slashed", "Nickname", "Level", "CP", "IV", "Power Ups", "Favorite", "Stamina", "Stamina Max", "Move1", "Move2", "Owner Name", "Origin", "Height(M)", "Weight(KG)", "Attack", "Defense", "Stamina", "CP Multi", "Gyms Attacked", "Gyms Defended", "Creationtimems", "Add CP Multi" }; Dumper.Dump(session, data, dumpFileName); // set culture to OS default CultureInfo prevCulture = Thread.CurrentThread.CurrentCulture; CultureInfo culture = CultureInfo.CurrentUICulture; Thread.CurrentThread.CurrentCulture = culture; foreach (var pokemon in allPokemonInBag) { string[] pokemonData = { session.Translation.GetPokemonTranslation(pokemon.PokemonId).Replace(' ', '_'), session.Inventory.GetCandyCount(pokemon.PokemonId).ToString(), // PokemonInfo.GetCandy(session, pokemon.PokemonId).ToString(), pokemon.IsBad.ToString(), pokemon.Nickname.Replace(' ', '_'), PokemonInfo.GetLevel(pokemon).ToString(), pokemon.Cp.ToString(), PokemonInfo.CalculatePokemonPerfection(pokemon).ToString(), pokemon.NumUpgrades.ToString(), pokemon.Favorite.ToString(), pokemon.Stamina.ToString(), pokemon.StaminaMax.ToString(), pokemon.Move1.ToString(), pokemon.Move2.ToString(), pokemon.OwnerName, pokemon.Origin.ToString(), pokemon.HeightM.ToString(), pokemon.WeightKg.ToString(), pokemon.IndividualAttack.ToString(), pokemon.IndividualDefense.ToString(), pokemon.IndividualStamina.ToString(), pokemon.CpMultiplier.ToString(), pokemon.BattlesAttacked.ToString(), pokemon.BattlesDefended.ToString(), pokemon.CreationTimeMs.ToString(), pokemon.AdditionalCpMultiplier.ToString() }; Dumper.Dump(session, pokemonData, dumpFileName); } // restore culture Thread.CurrentThread.CurrentCulture = prevCulture; } catch (IOException) { session.EventDispatcher.Send( new ErrorEvent { Message = $"Could not write {dumpFileName} dump file." } ); } } }
public static async Task <bool> Snipe(ISession session, IEnumerable <PokemonId> pokemonIds, double latitude, double longitude, CancellationToken cancellationToken) { //if (LocsVisited.Contains(new PokemonLocation(latitude, longitude))) // return; var currentLatitude = session.Client.CurrentLatitude; var currentLongitude = session.Client.CurrentLongitude; var catchedPokemon = false; session.EventDispatcher.Send(new SnipeModeEvent { Active = true }); List <MapPokemon> catchablePokemon; int retry = 3; bool isCaptchaShow = false; try { do { retry--; LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(latitude, longitude, 10d), 0); // Set speed to 0 for random speed. latitude += 0.00000001; longitude += 0.00000001; session.EventDispatcher.Send(new UpdatePositionEvent { Longitude = longitude, Latitude = latitude }); var mapObjects = await session.Client.Map.GetMapObjects(true); catchablePokemon = mapObjects.MapCells.SelectMany(q => q.CatchablePokemons) .Where(q => pokemonIds.Contains(q.PokemonId)) .OrderByDescending(pokemon => PokemonInfo.CalculateMaxCp(pokemon.PokemonId)) .ToList(); } while (catchablePokemon.Count == 0 && retry > 0); } catch (HasherException ex) { throw ex; } catch (CaptchaException ex) { throw ex; } catch (Exception e) { Logger.Write($"Error: {e.Message}", LogLevel.Error); throw e; } finally { //if(!isCaptchaShow) LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude), 0); // Set speed to 0 for random speed. } if (catchablePokemon.Count == 0) { // Pokemon not found but we still add to the locations visited, so we don't keep sniping // locations with no pokemon. if (!LocsVisited.Contains(new PokemonLocation(latitude, longitude))) { LocsVisited.Add(new PokemonLocation(latitude, longitude)); } session.EventDispatcher.Send(new SnipeEvent { Message = session.Translation.GetTranslation(TranslationString.NoPokemonToSnipe), }); session.EventDispatcher.Send(new SnipeFailedEvent { Latitude = latitude, Longitude = longitude, PokemonId = pokemonIds.FirstOrDefault() }); return(false); } isCaptchaShow = false; foreach (var pokemon in catchablePokemon) { EncounterResponse encounter; try { LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(latitude, longitude, session.Client.CurrentAltitude), 0); // Set speed to 0 for random speed. encounter = session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId).Result; } catch (HasherException ex) { throw ex; } catch (CaptchaException ex) { isCaptchaShow = true; throw ex; } finally { if (!isCaptchaShow) { LocationUtils.UpdatePlayerLocationWithAltitude(session, // Set speed to 0 for random speed. new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude), 0); } } switch (encounter.Status) { case EncounterResponse.Types.Status.EncounterSuccess: if (!LocsVisited.Contains(new PokemonLocation(latitude, longitude))) { LocsVisited.Add(new PokemonLocation(latitude, longitude)); } //Also add exact pokemon location to LocsVisited, some times the server one differ a little. if (!LocsVisited.Contains(new PokemonLocation(pokemon.Latitude, pokemon.Longitude))) { LocsVisited.Add(new PokemonLocation(pokemon.Latitude, pokemon.Longitude)); } session.EventDispatcher.Send(new UpdatePositionEvent { Latitude = currentLatitude, Longitude = currentLongitude }); catchedPokemon = await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon, currentFortData : null, sessionAllowTransfer : true); break; case EncounterResponse.Types.Status.PokemonInventoryFull: if (session.LogicSettings.TransferDuplicatePokemon) { await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } else { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually) }); } return(false); default: session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation( TranslationString.EncounterProblem, encounter.Status) }); break; } if (!Equals(catchablePokemon.ElementAtOrDefault(catchablePokemon.Count - 1), pokemon)) { await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken); } } _lastSnipe = DateTime.Now; if (catchedPokemon) { session.Stats.SnipeCount++; session.Stats.LastSnipeTime = _lastSnipe; } session.EventDispatcher.Send(new SnipeModeEvent { Active = false }); return(true); //await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken); }
public static async Task Execute(PlayerData player, string filename = "PokeList.csv") { if (player == null) { return; } var stats = await Inventory.GetPlayerStats(); var stat = stats.FirstOrDefault(); if (stat == null) { return; } if (!Directory.Exists(_exportPath)) { Directory.CreateDirectory(_exportPath); } if (Directory.Exists(_exportPath)) { try { var pokelistFile = Path.Combine(_exportPath, $"Profile_{player.Username}_{filename}"); if (File.Exists(pokelistFile)) { File.Delete(pokelistFile); } CsvExport myExport = new CsvExport(); var allPokemon = await Inventory.GetHighestsIv(); var myPokemonSettings = await Inventory.GetPokemonSettings(); var pokemonSettings = myPokemonSettings.ToList(); var myPokemonFamilies = await Inventory.GetPokemonFamilies(); var pokemonFamilies = myPokemonFamilies.ToArray(); var trainerLevel = stat.Level; foreach (var pokemon in allPokemon) { var toEncode = $"{(int)pokemon.PokemonId}" + "," + trainerLevel + "," + PokemonInfo.GetLevel(pokemon) + "," + pokemon.Cp + "," + pokemon.Stamina; //Generate base64 code to make it viewable here http://poke.isitin.org/#MTUwLDIzLDE3LDE5MDIsMTE4 var encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(toEncode)); var settings = pokemonSettings.Single(x => x.PokemonId == pokemon.PokemonId); var familiecandies = pokemonFamilies.Single(x => settings.FamilyId == x.FamilyId).Candy_; myExport.AddRow(); myExport["PokemonID"] = (int)pokemon.PokemonId; myExport["Name"] = pokemon.PokemonId; myExport["NickName"] = pokemon.Nickname; myExport["Level"] = PokemonInfo.GetLevel(pokemon).ToString("0.0"); myExport["CP"] = pokemon.Cp; myExport["MaxCP"] = PokemonInfo.CalculateMaxCp(pokemon); myExport["IV Perfection in %"] = PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00"); myExport["Attack 1"] = pokemon.Move1; myExport["Attack 2"] = pokemon.Move2; myExport["HP"] = pokemon.Stamina; myExport["Attk"] = pokemon.IndividualAttack; myExport["Def"] = pokemon.IndividualDefense; myExport["Stamina"] = pokemon.IndividualStamina; myExport["Familie Candies"] = familiecandies; myExport["IsInGym"] = pokemon.DeployedFortId != string.Empty ? "Yes" : "No"; myExport["IsFavorite"] = pokemon.Favorite != 0 ? "Yes" : "No"; myExport["previewLink"] = $"http://poke.isitin.org/#{encoded}"; } myExport.ExportToFile(pokelistFile); Logger.Write($"Export Player Infos and all Pokemon to \"\\Export\\Profile_{player.Username}_{filename}\"", LogLevel.Info); } catch { Logger.Write("Export Player Infos and all Pokemons to CSV not possible. File seems be in use!", LogLevel.Warning); } _lastExportTime = DateTime.Now; Logger.Write($"Next Export in {Logic._client.Settings.CSVExportInMinutes} Minutes", LogLevel.Info); } }
private static async Task DoUpgrade(ISession session, PokemonData pokemon) { var upgradeResult = await session.Inventory.UpgradePokemon(pokemon.Id); if (upgradeResult.Result == POGOProtos.Networking.Responses.UpgradePokemonResponse.Types.Result.Success) { session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeSuccess, session.Translation.GetPokemonName(upgradeResult.UpgradedPokemon.PokemonId), upgradeResult.UpgradedPokemon.Cp) }); } else if (upgradeResult.Result == POGOProtos.Networking.Responses.UpgradePokemonResponse.Types.Result.ErrorInsufficientResources) { session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeFailed) }); } // pokemon max level else if (upgradeResult.Result == POGOProtos.Networking.Responses.UpgradePokemonResponse.Types.Result.ErrorUpgradeNotAvailable) { session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeUnavailable, session.Translation.GetPokemonName(pokemon.PokemonId), pokemon.Cp, PokemonInfo.CalculateMaxCp(pokemon)) }); } else { session.EventDispatcher.Send(new NoticeEvent() { Message = session.Translation.GetTranslation(TranslationString.PokemonUpgradeFailedError, session.Translation.GetPokemonName(pokemon.PokemonId)) }); } }
public static async Task <bool> Execute(ISession session, dynamic encounter, PokemonCacheItem pokemon, CancellationToken cancellationToken, FortData currentFortData = null, ulong encounterId = 0) { if (!await CheckBotStateTask.Execute(session, cancellationToken)) { return(false); } if (encounter is EncounterResponse && pokemon == null) { throw new ArgumentException("Parameter pokemon must be set, if encounter is of type EncounterResponse", nameof(pokemon)); } var prevState = session.State; session.State = BotState.Catch; var canUseBerry = true; CatchPokemonResponse caughtPokemonResponse; var attemptCounter = 1; do { if (session.LogicSettings.MaxPokeballsPerPokemon > 0 && attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon) { break; } float probability = encounter?.CaptureProbability?.CaptureProbability_[0]; ItemId pokeball = await GetBestBall(session, encounter, probability); if (pokeball == ItemId.ItemUnknown) { session.EventDispatcher.Send(new NoPokeballEvent { Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId, Cp = (encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter?.PokemonData?.Cp) ?? 0 }); session.State = prevState; return(false); } var useBerryBelowCatchProbability = session.LogicSettings.UseBerryBelowCatchProbability > 1 ? session.LogicSettings.UseBerryBelowCatchProbability / 100 : session.LogicSettings.UseBerryBelowCatchProbability; var isLowProbability = probability < useBerryBelowCatchProbability; var isHighCp = encounter != null && (encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter.PokemonData?.Cp) > session.LogicSettings.UseBerryMinCp; var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData) >= session.LogicSettings.UseBerryMinIv; if (isLowProbability && ((session.LogicSettings.PrioritizeIvOverCp && isHighPerfection) || isHighCp) && canUseBerry) { await UseBerry(session, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData?.Id); canUseBerry = false; await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 1000); } var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude); double normalizedRecticleSize, spinModifier; if (session.LogicSettings.HumanizeThrows) { normalizedRecticleSize = Rng.NextInRange(session.LogicSettings.ThrowAccuracyMin, session.LogicSettings.ThrowAccuracyMax) * 1.85 + 0.1; // 0.1..1.95 spinModifier = Rng.NextDouble() > session.LogicSettings.ThrowSpinFrequency ? 0.0 : 1.0; } else { normalizedRecticleSize = 1.95; spinModifier = 1.00; } Func <ItemId, string> returnRealBallName = a => { switch (a) { case ItemId.ItemPokeBall: return(session.Translation.GetTranslation(TranslationString.Pokeball)); case ItemId.ItemGreatBall: return(session.Translation.GetTranslation(TranslationString.GreatPokeball)); case ItemId.ItemUltraBall: return(session.Translation.GetTranslation(TranslationString.UltraPokeball)); case ItemId.ItemMasterBall: return(session.Translation.GetTranslation(TranslationString.MasterPokeball)); default: return(session.Translation.GetTranslation(TranslationString.CommonWordUnknown)); } }; Func <double, string> getThrowType = a => { if (a < 1.0) { return("Normal "); } if (a < 1.3) { return("Nice! "); } if (a < 1.7) { return("Great! "); } return(a > 1.6 ? "Excellent! " : "unknown "); }; var hit = Rng.NextDouble() > session.LogicSettings.MissChance; Logging.Logger.Write($"Throwing {(Math.Abs(spinModifier - 1) < 0.00001 ?"Spinning " : "" )}{getThrowType(normalizedRecticleSize)}{returnRealBallName(pokeball)} - {(hit ? "WILL HIT" : "WILL MISS")}", Logging.LogLevel.Caught, session: session); caughtPokemonResponse = await session.Client.Encounter.CatchPokemon( encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData.Id, pokeball, normalizedRecticleSize, spinModifier, hitPokemon : hit); session.EventDispatcher.Send(new ItemLostEvent { Id = pokeball, Count = 1 }); var lat = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude; var lng = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude; var evt = new PokemonCaptureEvent { Status = caughtPokemonResponse.Status, Latitude = lat, Longitude = lng }; if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { if (pokemon != null) { pokemon.Caught = true; } evt.Uid = caughtPokemonResponse.CapturedPokemonId; var totalExp = caughtPokemonResponse.CaptureAward.Xp.Sum(); var profile = await session.Client.Player.GetPlayer(); evt.Exp = totalExp; evt.Stardust = profile.PlayerData.Currencies.ToArray()[1].Amount; var pokemonSettings = await session.Inventory.GetPokemonSettings(); var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var setting = pokemonSettings.FirstOrDefault(q => q.PokemonId == pokemon?.PokemonId); var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId); if (family != null) { family.Candy_ += caughtPokemonResponse.CaptureAward.Candy.Sum(); evt.Family = family.FamilyId; evt.FamilyCandies = family.Candy_; } else { evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum(); } session.MapCache.PokemonCaught(pokemon); } else if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee) { pokemon.Caught = true; } else if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) { canUseBerry = true; } evt.CatchType = encounter is EncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeNormal) : encounter is DiskEncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeLure) : session.Translation.GetTranslation(TranslationString.CatchTypeIncense); evt.Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId; var pokeData = (encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData) as PokemonData; if (pokeData != null) { evt.Level = PokemonInfo.GetLevel(pokeData); evt.Cp = pokeData.Cp; evt.MaxCp = PokemonInfo.CalculateMaxCp(pokeData); evt.Perfection = Math.Round(pokeData.CalculatePokemonPerfection(), 2); evt.Probability = Math.Round(probability * 100, 2); evt.Move1 = pokeData.Move1; evt.Move2 = pokeData.Move2; } evt.Distance = distance; evt.Pokeball = pokeball; evt.Attempt = attemptCounter; await session.Inventory.RefreshCachedInventory(); evt.BallAmount = await session.Inventory.GetItemAmountByType(pokeball); session.EventDispatcher.Send(evt); attemptCounter++; await Task.Delay(session.LogicSettings.DelayCatchPokemon); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); session.State = prevState; return(true); }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // Refresh inventory so that the player stats are fresh //TODO - Need more test to make sure not break anything. //await session.Inventory.RefreshCachedInventory(); try { var playerStats = (await session.Inventory.GetPlayerStats()).FirstOrDefault(); if (playerStats == null) { return; } var kmWalked = playerStats.KmWalked; var incubators = (await session.Inventory.GetEggIncubators()) .Where(x => x.UsesRemaining > 0 || x.ItemId == ItemId.ItemIncubatorBasicUnlimited) .OrderByDescending(x => x.ItemId == ItemId.ItemIncubatorBasicUnlimited) .ToList(); var unusedEggs = (await session.Inventory.GetEggs()) .Where(x => string.IsNullOrEmpty(x.EggIncubatorId)) .OrderBy(x => x.EggKmWalkedTarget - x.EggKmWalkedStart) .ToList(); var rememberedIncubatorsFilePath = Path.Combine(session.LogicSettings.ProfilePath, "temp", "incubators.json"); var rememberedIncubators = GetRememberedIncubators(rememberedIncubatorsFilePath); var pokemons = (await session.Inventory.GetPokemons()).ToList(); // Check if eggs in remembered incubator usages have since hatched // (instead of calling session.Client.Inventory.GetHatchedEgg(), which doesn't seem to work properly) foreach (var incubator in rememberedIncubators) { var hatched = pokemons.FirstOrDefault(x => !x.IsEgg && x.Id == incubator.PokemonId); if (hatched == null) { continue; } session.EventDispatcher.Send(new EggHatchedEvent { Id = hatched.Id, PokemonId = hatched.PokemonId, Level = PokemonInfo.GetLevel(hatched), Cp = hatched.Cp, MaxCp = PokemonInfo.CalculateMaxCp(hatched), Perfection = Math.Round(PokemonInfo.CalculatePokemonPerfection(hatched), 2) }); } var newRememberedIncubators = new List <IncubatorUsage>(); foreach (var incubator in incubators) { cancellationToken.ThrowIfCancellationRequested(); if (incubator.PokemonId == 0) { // Unlimited incubators prefer short eggs, limited incubators prefer long eggs // Special case: If only one incubator is available at all, it will prefer long eggs var egg = (incubator.ItemId == ItemId.ItemIncubatorBasicUnlimited && incubators.Count > 1) ? unusedEggs.FirstOrDefault() : unusedEggs.LastOrDefault(); if (egg == null) { continue; } // Skip (save) limited incubators depending on user choice in config if (!session.LogicSettings.UseLimitedEggIncubators && incubator.ItemId != ItemId.ItemIncubatorBasicUnlimited) { continue; } var response = await session.Client.Inventory.UseItemEggIncubator(incubator.Id, egg.Id); unusedEggs.Remove(egg); newRememberedIncubators.Add(new IncubatorUsage { IncubatorId = incubator.Id, PokemonId = egg.Id }); session.EventDispatcher.Send(new EggIncubatorStatusEvent { IncubatorId = incubator.Id, WasAddedNow = true, PokemonId = egg.Id, KmToWalk = egg.EggKmWalkedTarget, KmRemaining = response.EggIncubator.TargetKmWalked - kmWalked }); } else { newRememberedIncubators.Add(new IncubatorUsage { IncubatorId = incubator.Id, PokemonId = incubator.PokemonId }); session.EventDispatcher.Send(new EggIncubatorStatusEvent { IncubatorId = incubator.Id, PokemonId = incubator.PokemonId, KmToWalk = incubator.TargetKmWalked - incubator.StartKmWalked, KmRemaining = incubator.TargetKmWalked - kmWalked }); } } if (!newRememberedIncubators.SequenceEqual(rememberedIncubators)) { SaveRememberedIncubators(newRememberedIncubators, rememberedIncubatorsFilePath); } } catch (Exception) { } }
public static async Task Execute(ISession session) { var myPokemonFamilies = await session.Inventory.GetPokemonFamilies(); var myPokeSettings = await session.Inventory.GetPokemonSettings(); var highestsPokemonCp = await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart); var pokemonPairedWithStatsCp = highestsPokemonCp.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon), PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList(); var highestsPokemonPerfect = await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart); var pokemonPairedWithStatsIv = highestsPokemonPerfect.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon), PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList(); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "CP", PokemonList = pokemonPairedWithStatsCp }); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "IV", PokemonList = pokemonPairedWithStatsIv }); var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp ? await session.Inventory.GetHighestsPerfect(1000) : await session.Inventory.GetHighestsCp(1000); if (session.LogicSettings.DumpPokemonStats) { const string dumpFileName = "PokeBagStats"; try { Dumper.ClearDumpFile(session, dumpFileName); string[] data = { "pokemonid", "pokemonlevel", "cp", "perfection", "stamina", "staminamax", "move1", "move2", "candy", "ownername", "origin", "heightm", "weightkg", "individualattack", "individualdefense", "individualstamina", "cpmultiplier", "battlesattacked", "battlesdefended", "creationtimems", "numupgrades", "additionalcpmultiplier", "favorite", "nickname" }; Dumper.Dump(session, data, dumpFileName); // set culture to OS default CultureInfo prevCulture = Thread.CurrentThread.CurrentCulture; CultureInfo culture = CultureInfo.CurrentUICulture; Thread.CurrentThread.CurrentCulture = culture; foreach (var pokemon in allPokemonInBag) { string[] pokemonData = { session.Translation.GetPokemonTranslation(pokemon.PokemonId), PokemonInfo.GetLevel(pokemon).ToString(), pokemon.Cp.ToString(), PokemonInfo.CalculatePokemonPerfection(pokemon).ToString(), pokemon.Stamina.ToString(), pokemon.StaminaMax.ToString(), pokemon.Move1.ToString(), pokemon.Move2.ToString(), PokemonInfo.GetCandy(pokemon, myPokemonFamilies,myPokeSettings).ToString(), pokemon.OwnerName, pokemon.Origin.ToString(), pokemon.HeightM.ToString(), pokemon.WeightKg.ToString(), pokemon.IndividualAttack.ToString(), pokemon.IndividualDefense.ToString(), pokemon.IndividualStamina.ToString(), pokemon.CpMultiplier.ToString(), pokemon.BattlesAttacked.ToString(), pokemon.BattlesDefended.ToString(), pokemon.CreationTimeMs.ToString(), pokemon.NumUpgrades.ToString(), pokemon.AdditionalCpMultiplier.ToString(), pokemon.Favorite.ToString(), pokemon.Nickname }; Dumper.Dump(session, pokemonData, dumpFileName); } // restore culture Thread.CurrentThread.CurrentCulture = prevCulture; } catch (System.IO.IOException) { session.EventDispatcher.Send(new ErrorEvent { Message = $"Could not write {dumpFileName} dump file." }); } } }
public static async Task Execute(ISession session, CancellationToken cancellationToken, dynamic encounter, MapPokemon pokemon, FortData currentFortData = null, ulong encounterId = 0, bool sessionAllowTransfer = true) { AmountOfBerries = 0; cancellationToken.ThrowIfCancellationRequested(); // If the encounter is null nothing will work below, so exit now if (encounter == null) { return; } if (CatchThresholdExceeds(session)) { return; } float probability = encounter.CaptureProbability?.CaptureProbability_[0]; // Check for pokeballs before proceeding var pokeball = await GetBestBall(session, encounter, probability); if (pokeball == ItemId.ItemUnknown) { return; } //Calculate CP and IV var pokemonCp = (encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter.PokemonData?.Cp); var pokemonIv = PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); // Calculate distance away var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude, encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude); CatchPokemonResponse caughtPokemonResponse; var lastThrow = CatchPokemonResponse.Types.CatchStatus.CatchSuccess; // Initializing lastThrow var attemptCounter = 1; do { if ((session.LogicSettings.MaxPokeballsPerPokemon > 0 && attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon)) { break; } pokeball = await GetBestBall(session, encounter, probability); if (pokeball == ItemId.ItemUnknown) { session.EventDispatcher.Send(new NoPokeballEvent { Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId, Cp = (encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter?.PokemonData?.Cp) ?? 0 }); return; } // Determine whether to use berries or not if (((session.LogicSettings.UseBerriesOperator.ToLower().Equals("and") && pokemonIv >= session.LogicSettings.UseBerriesMinIv && pokemonCp >= session.LogicSettings.UseBerriesMinCp && probability < session.LogicSettings.UseBerriesBelowCatchProbability) || (session.LogicSettings.UseBerriesOperator.ToLower().Equals("or") && ( pokemonIv >= session.LogicSettings.UseBerriesMinIv || pokemonCp >= session.LogicSettings.UseBerriesMinCp || probability < session.LogicSettings.UseBerriesBelowCatchProbability))) && lastThrow != CatchPokemonResponse.Types.CatchStatus.CatchMissed) // if last throw is a miss, no double berry { AmountOfBerries++; if (AmountOfBerries <= session.LogicSettings.MaxBerriesToUsePerPokemon) { await UseBerry(session, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData?.Id); } } bool hitPokemon = true; //default to excellent throw var normalizedRecticleSize = 1.95; //default spin var spinModifier = 1.0; //Humanized throws if (session.LogicSettings.EnableHumanizedThrows) { //thresholds: https://gist.github.com/anonymous/077d6dea82d58b8febde54ae9729b1bf var spinTxt = "Curve"; var hitTxt = "Excellent"; if (pokemonCp > session.LogicSettings.ForceExcellentThrowOverCp || pokemonIv > session.LogicSettings.ForceExcellentThrowOverIv) { normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.7) + 1.7; } else if (pokemonCp >= session.LogicSettings.ForceGreatThrowOverCp || pokemonIv >= session.LogicSettings.ForceGreatThrowOverIv) { normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.3) + 1.3; hitTxt = "Great"; } else { var regularThrow = 100 - (session.LogicSettings.ExcellentThrowChance + session.LogicSettings.GreatThrowChance + session.LogicSettings.NiceThrowChance); var rnd = Random.Next(1, 101); if (rnd <= regularThrow) { normalizedRecticleSize = Random.NextDouble() * (1 - 0.1) + 0.1; hitTxt = "Ordinary"; } else if (rnd <= regularThrow + session.LogicSettings.NiceThrowChance) { normalizedRecticleSize = Random.NextDouble() * (1.3 - 1) + 1; hitTxt = "Nice"; } else if (rnd <= regularThrow + session.LogicSettings.NiceThrowChance + session.LogicSettings.GreatThrowChance) { normalizedRecticleSize = Random.NextDouble() * (1.7 - 1.3) + 1.3; hitTxt = "Great"; } if (Random.NextDouble() * 100 > session.LogicSettings.CurveThrowChance) { spinModifier = 0.0; spinTxt = "Straight"; } } //round to 2 decimals normalizedRecticleSize = Math.Round(normalizedRecticleSize, 2); // Missed throw check int missChance = Random.Next(1, 101); if (missChance <= session.LogicSettings.ThrowMissPercentage && session.LogicSettings.EnableMissedThrows) { hitPokemon = false; } Logger.Write($"(Threw ball) {hitTxt} throw, {spinTxt}-ball, HitPokemon = {hitPokemon}...", LogLevel.Debug); } caughtPokemonResponse = await session.Client.Encounter.CatchPokemon( encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData.Id, pokeball, normalizedRecticleSize, spinModifier, hitPokemon); var lat = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude; var lng = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude; var evt = new PokemonCaptureEvent() { Status = caughtPokemonResponse.Status, Latitude = lat, Longitude = lng }; lastThrow = caughtPokemonResponse.Status; // sets lastThrow status if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { var totalExp = 0; foreach (var xp in caughtPokemonResponse.CaptureAward.Xp) { totalExp += xp; } var profile = await session.Client.Player.GetPlayer(); evt.Exp = totalExp; evt.Stardust = profile.PlayerData.Currencies.ToArray()[1].Amount; evt.UniqueId = caughtPokemonResponse.CapturedPokemonId; var pokemonSettings = await session.Inventory.GetPokemonSettings(); var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var setting = pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == pokemon.PokemonId); var family = pokemonFamilies.FirstOrDefault(q => setting != null && 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 (session.LogicSettings.UseCatchLimit) { session.Stats.PokemonTimestamps.Add(DateTime.Now.Ticks); UpdateTimeStampsPokemon?.Invoke(); Logger.Write($"(CATCH LIMIT) {session.Stats.PokemonTimestamps.Count}/{session.LogicSettings.CatchPokemonLimit}", LogLevel.Info, ConsoleColor.Yellow); } } evt.CatchType = encounter is EncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeNormal) : encounter is DiskEncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeLure) : session.Translation.GetTranslation(TranslationString.CatchTypeIncense); evt.CatchTypeText = encounter is EncounterResponse ? "normal" : encounter is DiskEncounterResponse ? "lure" : "incense"; evt.Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId; evt.EncounterId = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.EncounterId : encounterId; evt.Move1 = PokemonInfo.GetPokemonMove1(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); evt.Move2 = PokemonInfo.GetPokemonMove2(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); evt.Expires = pokemon?.ExpirationTimestampMs ?? 0; evt.SpawnPointId = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.SpawnPointId : currentFortData?.Id; evt.Level = PokemonInfo.GetLevel(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); evt.Cp = encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter?.PokemonData?.Cp ?? 0; evt.MaxCp = PokemonInfo.CalculateMaxCp(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData); evt.Perfection = Math.Round( PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData)); evt.Probability = Math.Round(probability * 100, 2); evt.Distance = distance; evt.Pokeball = pokeball; evt.Attempt = attemptCounter; await session.Inventory.RefreshCachedInventory(); evt.BallAmount = await session.Inventory.GetItemAmountByType(pokeball); evt.Rarity = PokemonGradeHelper.GetPokemonGrade(evt.Id).ToString(); session.EventDispatcher.Send(evt); attemptCounter++; DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0); if (session.LogicSettings.TransferDuplicatePokemonOnCapture && session.LogicSettings.TransferDuplicatePokemon && sessionAllowTransfer && caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { if (session.LogicSettings.UseNearActionRandom) { await HumanRandomActionTask.TransferRandom(session, cancellationToken); } else { await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } } } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // Refresh inventory so that the player stats are fresh await session.Inventory.RefreshCachedInventory(); var playerStats = (await session.Inventory.GetPlayerStats()).FirstOrDefault(); if (playerStats == null) { return; } var kmWalked = playerStats.KmWalked; var incubators = (await session.Inventory.GetEggIncubators()) .Where(x => x.UsesRemaining > 0 || x.ItemId == ItemId.ItemIncubatorBasicUnlimited) .OrderByDescending(x => x.ItemId == ItemId.ItemIncubatorBasicUnlimited) .ToList(); var unusedEggs = (await session.Inventory.GetEggs()) .Where(x => string.IsNullOrEmpty(x.EggIncubatorId)) .OrderBy(x => x.EggKmWalkedTarget - x.EggKmWalkedStart) .ToList(); var rememberedIncubatorsFilePath = Path.Combine(session.LogicSettings.ProfilePath, "temp", "incubators.json"); var rememberedIncubators = GetRememberedIncubators(rememberedIncubatorsFilePath); var pokemons = (await session.Inventory.GetPokemons()).ToList(); // Check if eggs in remembered incubator usages have since hatched // (instead of calling session.Client.Inventory.GetHatchedEgg(), which doesn't seem to work properly) foreach (var incubator in rememberedIncubators) { var hatched = pokemons.FirstOrDefault(x => !x.IsEgg && x.Id == incubator.PokemonId); if (hatched == null) { continue; } session.EventDispatcher.Send(new EggHatchedEvent { Id = hatched.Id, PokemonId = hatched.PokemonId, Level = PokemonInfo.GetLevel(hatched), Cp = hatched.Cp, MaxCp = PokemonInfo.CalculateMaxCp(hatched), Perfection = Math.Round(PokemonInfo.CalculatePokemonPerfection(hatched), 2) }); } var newRememberedIncubators = new List <IncubatorUsage>(); // Find out if there are only 10km-eggs (special case) var only10kmEggs = false; var testIfOnly10kmEggs = unusedEggs.FirstOrDefault(x => x.EggKmWalkedTarget < 10); if (testIfOnly10kmEggs == null) { only10kmEggs = true; } foreach (var incubator in incubators) { cancellationToken.ThrowIfCancellationRequested(); if (incubator.PokemonId == 0) { // Unlimited incubators prefer short eggs, limited incubators prefer long eggs // Special case: If only one incubator is available at all, it will prefer long eggs var egg = (incubator.ItemId == ItemId.ItemIncubatorBasicUnlimited && incubators.Count > 1) ? unusedEggs.FirstOrDefault() : unusedEggs.LastOrDefault(); if (egg == null) { continue; } // Avoid using 10 km egg until you are level 20 in order to get higher // initial CP on the high IV 10 km Pokémons (unless you ONLY have 10km-eggs) if (egg.EggKmWalkedTarget == 10 && playerStats.Level < 20 && !only10kmEggs) { Logger.Write("Player below level 20, saving this 10 km Egg for later.", LogLevel.Egg); continue; } // Avoid using 2/5 km eggs with limited incubator - IF setting is 10! if (egg.EggKmWalkedTarget < session.LogicSettings.UseEggIncubatorMinKm && incubator.ItemId != ItemId.ItemIncubatorBasicUnlimited) { continue; } var response = await session.Client.Inventory.UseItemEggIncubator(incubator.Id, egg.Id); unusedEggs.Remove(egg); newRememberedIncubators.Add(new IncubatorUsage { IncubatorId = incubator.Id, PokemonId = egg.Id }); session.EventDispatcher.Send(new EggIncubatorStatusEvent { IncubatorId = incubator.Id, WasAddedNow = true, PokemonId = egg.Id, KmToWalk = egg.EggKmWalkedTarget, KmRemaining = response.EggIncubator.TargetKmWalked - kmWalked }); } else { newRememberedIncubators.Add(new IncubatorUsage { IncubatorId = incubator.Id, PokemonId = incubator.PokemonId }); session.EventDispatcher.Send(new EggIncubatorStatusEvent { IncubatorId = incubator.Id, PokemonId = incubator.PokemonId, KmToWalk = incubator.TargetKmWalked - incubator.StartKmWalked, KmRemaining = incubator.TargetKmWalked - kmWalked }); } } if (!newRememberedIncubators.SequenceEqual(rememberedIncubators)) { SaveRememberedIncubators(newRememberedIncubators, rememberedIncubatorsFilePath); } }
public static async Task Execute(ISession session) { var highestsPokemonCp = await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart); var highestsPokemonCpForUpgrade = await session.Inventory.GetHighestsCp(50); var highestsPokemonIvForUpgrade = await session.Inventory.GetHighestsPerfect(50); var pokemonPairedWithStatsCp = highestsPokemonCp.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList(); var pokemonPairedWithStatsCpForUpgrade = highestsPokemonCpForUpgrade.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList(); var highestsPokemonPerfect = await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart); var pokemonPairedWithStatsIv = highestsPokemonPerfect.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList(); var pokemonPairedWithStatsIvForUpgrade = highestsPokemonIvForUpgrade.Select( pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon), PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList(); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "CP", PokemonList = pokemonPairedWithStatsCp }); await Task.Delay(500); session.EventDispatcher.Send( new DisplayHighestsPokemonEvent { SortedBy = "IV", PokemonList = pokemonPairedWithStatsIv }); foreach (var pokemon in pokemonPairedWithStatsIvForUpgrade) { var dgdfs = pokemon.ToString(); var tokens = dgdfs.Split(new[] { "id" }, StringSplitOptions.None); var splitone = tokens[1].Split('"'); var iv = session.Inventory.GetPerfect(pokemon.Item1); if (iv >= session.LogicSettings.UpgradePokemonIvMinimum) { PokemonId.Add(ulong.Parse(splitone[2])); } } foreach (var t in pokemonPairedWithStatsCpForUpgrade) { var dgdfs = t.ToString(); var tokens = dgdfs.Split(new[] { "id" }, StringSplitOptions.None); var splitone = tokens[1].Split('"'); var tokensSplit = tokens[1].Split(new[] { "cp" }, StringSplitOptions.None); var tokenSplitAgain = tokensSplit[1].Split(' '); var tokenSplitAgain2 = tokenSplitAgain[1].Split(','); if (float.Parse(tokenSplitAgain2[0]) >= session.LogicSettings.UpgradePokemonCpMinimum) { PokemonIdcp.Add(ulong.Parse(splitone[2])); } } var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp ? await session.Inventory.GetHighestsPerfect(1000) : await session.Inventory.GetHighestsCp(1000); if (session.LogicSettings.DumpPokemonStats) { const string dumpFileName = "PokeBagStats"; Dumper.ClearDumpFile(session, dumpFileName); foreach (var pokemon in allPokemonInBag) { Dumper.Dump(session, $"NAME: {pokemon.PokemonId.ToString().PadRight(16, ' ')}Lvl: {PokemonInfo.GetLevel(pokemon).ToString("00")}\t\tCP: {pokemon.Cp.ToString().PadRight(8, ' ')}\t\t IV: {PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}%\t\t\tMOVE1: {pokemon.Move1}\t\t\tMOVE2: {pokemon.Move2}", dumpFileName); } } await Task.Delay(500); }
/// <summary> /// Because this function sometime being called inside loop, return true it mean we don't want break look, false it mean not need to call this , break a loop from caller function /// </summary> /// <param name="session"></param> /// <param name="cancellationToken"></param> /// <param name="encounter"></param> /// <param name="pokemon"></param> /// <param name="currentFortData"></param> /// <param name="sessionAllowTransfer"></param> /// <returns></returns> public static async Task <bool> Execute(ISession session, CancellationToken cancellationToken, dynamic encounter, MapPokemon pokemon, FortData currentFortData, bool sessionAllowTransfer) { // If the encounter is null nothing will work below, so exit now if (encounter == null) { return(true); } // Exit if user defined max limits reached if (session.Stats.CatchThresholdExceeds(session)) { if (session.LogicSettings.AllowMultipleBot && session.LogicSettings.MultipleBotConfig.SwitchOnCatchLimit) { throw new ActiveSwitchByRuleException() { MatchedRule = SwitchRules.CatchLimitReached, ReachedValue = session.LogicSettings.CatchPokemonLimit }; } return(false); } using (var block = new BlockableScope(session, BotActions.Catch)) { if (!await block.WaitToRun()) { return(true); } AmountOfBerries = 0; cancellationToken.ThrowIfCancellationRequested(); float probability = encounter.CaptureProbability?.CaptureProbability_[0]; PokemonData encounteredPokemon; long unixTimeStamp; ulong _encounterId; string _spawnPointId; // Calling from CatchNearbyPokemonTask and SnipePokemonTask if (encounter is EncounterResponse && (encounter?.Status == EncounterResponse.Types.Status.EncounterSuccess)) { encounteredPokemon = encounter.WildPokemon?.PokemonData; unixTimeStamp = encounter.WildPokemon?.LastModifiedTimestampMs + encounter.WildPokemon?.TimeTillHiddenMs; _spawnPointId = encounter.WildPokemon?.SpawnPointId; _encounterId = encounter.WildPokemon?.EncounterId; } // Calling from CatchIncensePokemonTask else if (encounter is IncenseEncounterResponse && (encounter?.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess)) { encounteredPokemon = encounter?.PokemonData; unixTimeStamp = pokemon.ExpirationTimestampMs; _spawnPointId = pokemon.SpawnPointId; _encounterId = pokemon.EncounterId; } // Calling from CatchLurePokemon else if (encounter is DiskEncounterResponse && encounter?.Result == DiskEncounterResponse.Types.Result.Success && !(currentFortData == null)) { encounteredPokemon = encounter?.PokemonData; unixTimeStamp = currentFortData.LureInfo.LureExpiresTimestampMs; _spawnPointId = currentFortData.Id; _encounterId = currentFortData.LureInfo.EncounterId; } else { return(true); // No success to work with, exit } // Check for pokeballs before proceeding var pokeball = await GetBestBall(session, encounteredPokemon, probability); if (pokeball == ItemId.ItemUnknown) { Logger.Write(session.Translation.GetTranslation(TranslationString.ZeroPokeballInv)); return(false); } // Calculate CP and IV var pokemonCp = encounteredPokemon?.Cp; var pokemonIv = PokemonInfo.CalculatePokemonPerfection(encounteredPokemon); var lv = PokemonInfo.GetLevel(encounteredPokemon); // Calculate distance away var latitude = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude; var longitude = encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude; var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, latitude, longitude); if (session.LogicSettings.ActivateMSniper) { var newdata = new MSniperServiceTask.EncounterInfo(); newdata.EncounterId = _encounterId.ToString(); newdata.Iv = Math.Round(pokemonIv, 2); newdata.Latitude = latitude.ToString("G17", CultureInfo.InvariantCulture); newdata.Longitude = longitude.ToString("G17", CultureInfo.InvariantCulture); newdata.PokemonId = (int)(encounteredPokemon?.PokemonId ?? 0); newdata.PokemonName = encounteredPokemon?.PokemonId.ToString(); newdata.SpawnPointId = _spawnPointId; newdata.Move1 = PokemonInfo.GetPokemonMove1(encounteredPokemon).ToString(); newdata.Move2 = PokemonInfo.GetPokemonMove2(encounteredPokemon).ToString(); newdata.Expiration = unixTimeStamp; session.EventDispatcher.Send(newdata); } DateTime expiredDate = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(Convert.ToDouble(unixTimeStamp)); var encounterEV = new EncounteredEvent() { Latitude = latitude, Longitude = longitude, PokemonId = encounteredPokemon.PokemonId, IV = pokemonIv, Level = (int)lv, Expires = expiredDate.ToUniversalTime(), ExpireTimestamp = unixTimeStamp, SpawnPointId = _spawnPointId, EncounterId = _encounterId.ToString(), Move1 = PokemonInfo.GetPokemonMove1(encounteredPokemon).ToString(), Move2 = PokemonInfo.GetPokemonMove2(encounteredPokemon).ToString(), }; //add catch to avoid snipe duplicate string uniqueCacheKey = $"{session.Settings.PtcUsername}{session.Settings.GoogleUsername}{Math.Round(encounterEV.Latitude, 6)}{encounterEV.PokemonId}{Math.Round(encounterEV.Longitude, 6)}"; session.Cache.Add(uniqueCacheKey, encounterEV, DateTime.Now.AddMinutes(15)); session.EventDispatcher.Send(encounterEV); if (IsNotMetWithCatchCriteria(session, encounteredPokemon, pokemonIv, lv, pokemonCp)) { session.EventDispatcher.Send(new NoticeEvent { Message = session.Translation.GetTranslation(TranslationString.PokemonSkipped, encounteredPokemon.PokemonId) }); session.Cache.Add(_encounterId.ToString(), encounteredPokemon, expiredDate); Logger.Write( $"Filter catch not met. {encounteredPokemon.PokemonId.ToString()} IV {pokemonIv} lv {lv} {pokemonCp} move1 {PokemonInfo.GetPokemonMove1(encounteredPokemon)} move 2 {PokemonInfo.GetPokemonMove2(encounteredPokemon)}"); return(true); } CatchPokemonResponse caughtPokemonResponse = null; var lastThrow = CatchPokemonResponse.Types.CatchStatus.CatchSuccess; // Initializing lastThrow var attemptCounter = 1; // Main CatchPokemon-loop do { if ((session.LogicSettings.MaxPokeballsPerPokemon > 0 && attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon)) { break; } pokeball = await GetBestBall(session, encounteredPokemon, probability); if (pokeball == ItemId.ItemUnknown) { session.EventDispatcher.Send(new NoPokeballEvent { Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId, Cp = encounteredPokemon.Cp }); return(false); } // Determine whether to use berries or not if (((session.LogicSettings.UseBerriesOperator.ToLower().Equals("and") && pokemonIv >= session.LogicSettings.UseBerriesMinIv && pokemonCp >= session.LogicSettings.UseBerriesMinCp && probability < session.LogicSettings.UseBerriesBelowCatchProbability) || (session.LogicSettings.UseBerriesOperator.ToLower().Equals("or") && ( pokemonIv >= session.LogicSettings.UseBerriesMinIv || pokemonCp >= session.LogicSettings.UseBerriesMinCp || probability < session.LogicSettings.UseBerriesBelowCatchProbability))) && // if last throw is a miss, no double berry lastThrow != CatchPokemonResponse.Types.CatchStatus.CatchMissed) { AmountOfBerries++; if (AmountOfBerries <= session.LogicSettings.MaxBerriesToUsePerPokemon) { await UseBerry(session, _encounterId, _spawnPointId, cancellationToken); } } bool hitPokemon = true; //default to excellent throw var normalizedRecticleSize = 1.95; //default spin var spinModifier = 1.0; //Humanized throws if (session.LogicSettings.EnableHumanizedThrows) { //thresholds: https://gist.github.com/anonymous/077d6dea82d58b8febde54ae9729b1bf var spinTxt = "Curve"; var hitTxt = "Excellent"; if (pokemonCp > session.LogicSettings.ForceExcellentThrowOverCp || pokemonIv > session.LogicSettings.ForceExcellentThrowOverIv) { normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.7) + 1.7; } else if (pokemonCp >= session.LogicSettings.ForceGreatThrowOverCp || pokemonIv >= session.LogicSettings.ForceGreatThrowOverIv) { normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.3) + 1.3; hitTxt = "Great"; } else { var regularThrow = 100 - (session.LogicSettings.ExcellentThrowChance + session.LogicSettings.GreatThrowChance + session.LogicSettings.NiceThrowChance); var rnd = Random.Next(1, 101); if (rnd <= regularThrow) { normalizedRecticleSize = Random.NextDouble() * (1 - 0.1) + 0.1; hitTxt = "Ordinary"; } else if (rnd <= regularThrow + session.LogicSettings.NiceThrowChance) { normalizedRecticleSize = Random.NextDouble() * (1.3 - 1) + 1; hitTxt = "Nice"; } else if (rnd <= regularThrow + session.LogicSettings.NiceThrowChance + session.LogicSettings.GreatThrowChance) { normalizedRecticleSize = Random.NextDouble() * (1.7 - 1.3) + 1.3; hitTxt = "Great"; } if (Random.NextDouble() * 100 > session.LogicSettings.CurveThrowChance) { spinModifier = 0.0; spinTxt = "Straight"; } } // Round to 2 decimals normalizedRecticleSize = Math.Round(normalizedRecticleSize, 2); // Missed throw check int missChance = Random.Next(1, 101); if (missChance <= session.LogicSettings.ThrowMissPercentage && session.LogicSettings.EnableMissedThrows) { hitPokemon = false; } Logger.Write($"(Threw ball) {hitTxt} throw, {spinTxt}-ball, HitPokemon = {hitPokemon}...", LogLevel.Debug); } caughtPokemonResponse = await session.Client.Encounter.CatchPokemon( encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.EncounterId : _encounterId, encounter is EncounterResponse || encounter is IncenseEncounterResponse ?pokemon.SpawnPointId : currentFortData.Id, pokeball, normalizedRecticleSize, spinModifier, hitPokemon); await session.Inventory.UpdateInventoryItem(pokeball, -1); var evt = new PokemonCaptureEvent() { Status = caughtPokemonResponse.Status, Latitude = latitude, Longitude = longitude }; lastThrow = caughtPokemonResponse.Status; // sets lastThrow status if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { var totalExp = 0; var totalStartDust = caughtPokemonResponse.CaptureAward.Stardust.Sum(); if (encounteredPokemon != null) { encounteredPokemon.Id = caughtPokemonResponse.CapturedPokemonId; await session.Inventory.AddPokemonToCache(encounteredPokemon); } foreach (var xp in caughtPokemonResponse.CaptureAward.Xp) { totalExp += xp; } var stardust = session.Inventory.UpdateStartDust(totalStartDust); evt.Exp = totalExp; evt.Stardust = stardust; evt.UniqueId = caughtPokemonResponse.CapturedPokemonId; var pokemonSettings = await session.Inventory.GetPokemonSettings(); var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var setting = pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == pokemon.PokemonId); var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId); if (family != null) { await session.Inventory.UpdateCandy(family, caughtPokemonResponse.CaptureAward.Candy.Sum()); family.Candy_ += caughtPokemonResponse.CaptureAward.Candy.Sum(); evt.FamilyCandies = family.Candy_; } else { evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum(); } if (session.LogicSettings.UseCatchLimit) { session.Stats.AddPokemonTimestamp(DateTime.Now.Ticks); Logger.Write( $"(CATCH LIMIT) {session.Stats.GetNumPokemonsInLast24Hours()}/{session.LogicSettings.CatchPokemonLimit}", LogLevel.Info, ConsoleColor.Yellow); } } evt.CatchType = encounter is EncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeNormal) : encounter is DiskEncounterResponse ? session.Translation.GetTranslation(TranslationString.CatchTypeLure) : session.Translation.GetTranslation(TranslationString.CatchTypeIncense); evt.CatchTypeText = encounter is EncounterResponse ? "normal" : encounter is DiskEncounterResponse ? "lure" : "incense"; evt.Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId; evt.EncounterId = _encounterId; evt.Move1 = PokemonInfo.GetPokemonMove1(encounteredPokemon); evt.Move2 = PokemonInfo.GetPokemonMove2(encounteredPokemon); evt.Expires = pokemon?.ExpirationTimestampMs ?? 0; evt.SpawnPointId = _spawnPointId; evt.Level = PokemonInfo.GetLevel(encounteredPokemon); evt.Cp = encounteredPokemon.Cp; evt.MaxCp = PokemonInfo.CalculateMaxCp(encounteredPokemon); evt.Perfection = Math.Round(PokemonInfo.CalculatePokemonPerfection(encounteredPokemon)); evt.Probability = Math.Round(probability * 100, 2); evt.Distance = distance; evt.Pokeball = pokeball; evt.Attempt = attemptCounter; //await session.Inventory.RefreshCachedInventory(); evt.BallAmount = await session.Inventory.GetItemAmountByType(pokeball); evt.Rarity = PokemonGradeHelper.GetPokemonGrade(evt.Id).ToString(); session.EventDispatcher.Send(evt); attemptCounter++; DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); if (session.LogicSettings.AllowMultipleBot) { if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee) { CatchFleeContinuouslyCount++; if (CatchFleeContinuouslyCount > session.LogicSettings.MultipleBotConfig.CatchFleeCount) { CatchFleeContinuouslyCount = 0; throw new ActiveSwitchByRuleException() { MatchedRule = SwitchRules.CatchFlee, ReachedValue = session.LogicSettings.MultipleBotConfig.CatchFleeCount }; } } else { //reset if not catch flee. CatchFleeContinuouslyCount = 0; MSniperServiceTask.UnblockSnipe(); } } session.Actions.RemoveAll(x => x == BotActions.Catch); if (MultipleBotConfig.IsMultiBotActive(session.LogicSettings)) { ExecuteSwitcher(session, encounterEV); } if (session.LogicSettings.TransferDuplicatePokemonOnCapture && session.LogicSettings.TransferDuplicatePokemon && sessionAllowTransfer && caughtPokemonResponse != null && caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { if (session.LogicSettings.UseNearActionRandom) { await HumanRandomActionTask.TransferRandom(session, cancellationToken); } else { await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } } } return(true); }