private static async Task <List <IncubatorUsage> > CheckRememberedIncubators(ISession session, CancellationToken cancellationToken, List <PokemonData> pokemons, string rememberedIncubatorsFilePath) { var rememberedIncubators = GetRememberedIncubators(rememberedIncubatorsFilePath); if (rememberedIncubators == null) { return(new List <IncubatorUsage>()); } foreach (var incubator in rememberedIncubators) { var hatched = pokemons.FirstOrDefault(x => !x.IsEgg && x.Id == incubator.PokemonId); if (hatched == null) { continue; } var pokemonSettings = await session.Inventory.GetPokemonSettings(); var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var setting = pokemonSettings.FirstOrDefault(q => q.PokemonId == hatched.PokemonId); var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId); if (family == null || setting == null) { continue; } session.EventDispatcher.Send(new EggHatchedEvent { Uid = hatched.Id, Id = hatched.PokemonId, Level = hatched.GetLevel(), Cp = hatched.Cp, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(hatched, session.Runtime.CurrentLevel), Perfection = Math.Round(hatched.CalculatePokemonPerfection(), 2), Move1 = hatched.Move1, Move2 = hatched.Move2, Candy = family.Candy_, Family = family.FamilyId, Type1 = setting.Type, Type2 = setting.Type2, Stats = setting.Stats, Stamina = hatched.Stamina, IvSta = hatched.IndividualStamina, PossibleCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(hatched, 40), CandyToEvolve = setting.CandyToEvolve, IvAtk = hatched.IndividualAttack, IvDef = hatched.IndividualDefense, Weight = hatched.WeightKg, Cpm = hatched.CpMultiplier + hatched.AdditionalCpMultiplier, StaminaMax = hatched.StaminaMax, Evolutions = setting.EvolutionIds.ToArray() }); await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken); } return(rememberedIncubators); }
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 async void BuildPokemonList(List <Tuple <PokemonData, double, int> > receivedList) { PokemonList.Clear(); var pokemonFamilies = await Session.Inventory.GetPokemonFamilies(); var pokemonSettings = (await Session.Inventory.GetPokemonSettings()).ToList(); foreach (var pokemon in receivedList) { var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.Item1.PokemonId); var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId); var mon = new PokemonUiData( this, pokemon.Item1.Id, pokemon.Item1.PokemonId, //pokemon.Item1.PokemonId.ToInventorySource(), pokemon.Item1.Nickname == "" ? Session.Translation.GetPokemonName(pokemon.Item1.PokemonId) : pokemon.Item1.Nickname, pokemon.Item1.Cp, pokemon.Item2, family.FamilyId, family.Candy_, pokemon.Item1.CreationTimeMs, pokemon.Item1.Favorite == 1, !string.IsNullOrEmpty(pokemon.Item1.DeployedFortId), PokemonInfo.GetLevel(pokemon.Item1), pokemon.Item1.Move1, pokemon.Item1.Move2, setting.Type, setting.Type2, (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokemon.Item1, Level), PokemonInfo.GetBaseStats(pokemon.Item1.PokemonId), pokemon.Item1.Stamina, pokemon.Item1.StaminaMax, (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokemon.Item1, 40), setting.CandyToEvolve); PokemonList.Add(mon); mon.UpdateTags(Logic); } }
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; }
public static async Task Execute(ISession session, ulong pokemonId, CancellationToken cancellationToken) { if (!await CheckBotStateTask.Execute(session, cancellationToken)) { session.EventDispatcher.Send(new PokemonActionDoneEvent { Uid = pokemonId }); return; } var all = await session.Inventory.GetPokemons(); var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax); var pokemon = pokemons.FirstOrDefault(p => p.Id == pokemonId); if (pokemon == null) { session.EventDispatcher.Send(new PokemonActionDoneEvent { Uid = pokemonId }); return; } if (!await CheckBotStateTask.Execute(session, cancellationToken)) { session.EventDispatcher.Send(new PokemonActionDoneEvent { Uid = pokemonId }); return; } var prevState = session.State; session.State = BotState.Evolve; 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); 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 (family.Candy_ < setting.CandyToEvolve) { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.CandyMiss, session.Translation.GetPokemonName(pokemon.PokemonId), $"{family.Candy_}/{setting.CandyToEvolve}") }); session.State = prevState; session.EventDispatcher.Send(new PokemonActionDoneEvent { Uid = pokemonId }); return; } var isBuddy = pokemonId == session.Profile.PlayerData.BuddyPokemon.Id; var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id); session.EventDispatcher.Send(new PokemonEvolveEvent { Uid = pokemon.Id, Id = pokemon.PokemonId, Exp = evolveResponse.ExperienceAwarded, Result = evolveResponse.Result }); if (evolveResponse.EvolvedPokemonData != null) { family.Candy_ -= (setting.CandyToEvolve - 1); setting = pokemonSettings.Single(q => q.PokemonId == evolveResponse.EvolvedPokemonData.PokemonId); family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId); var evolvedPokemonData = evolveResponse.EvolvedPokemonData; session.EventDispatcher.Send(new PokemonEvolveDoneEvent { Uid = evolvedPokemonData.Id, Id = evolvedPokemonData.PokemonId, Cp = evolvedPokemonData.Cp, Perfection = evolvedPokemonData.CalculatePokemonPerfection(), Family = family.FamilyId, Level = evolvedPokemonData.GetLevel(), Candy = family.Candy_, Type1 = setting.Type, Type2 = setting.Type2, Stats = setting.Stats, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(evolvedPokemonData, session.Runtime.CurrentLevel), Stamina = evolvedPokemonData.Stamina, IvSta = evolvedPokemonData.IndividualStamina, Move1 = evolvedPokemonData.Move1, Move2 = evolvedPokemonData.Move2, PossibleCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(evolvedPokemonData, 40), CandyToEvolve = setting.CandyToEvolve, IvAtk = evolvedPokemonData.IndividualAttack, IvDef = evolvedPokemonData.IndividualDefense, Weight = evolvedPokemonData.WeightKg, Cpm = evolvedPokemonData.CpMultiplier + evolvedPokemonData.AdditionalCpMultiplier, StaminaMax = evolvedPokemonData.StaminaMax, Evolutions = setting.EvolutionIds.ToArray() }); if (isBuddy) { session.BuddyPokemon = evolveResponse.EvolvedPokemonData; //TODO: CHECK THAT, Or should resend that poke as buddy } } session.EventDispatcher.Send(new PokemonActionDoneEvent { Uid = pokemonId }); await DelayingUtils.Delay(session.LogicSettings.DelayEvolvePokemon, 25000); session.State = prevState; }
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(ISession session, ulong pokemonId, CancellationToken cancellationToken) { if (!await CheckBotStateTask.Execute(session, cancellationToken)) { return; } var prevState = session.State; session.State = BotState.Evolve; var all = await session.Inventory.GetPokemons(); var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax); var pokemon = pokemons.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; } var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id); session.EventDispatcher.Send(new PokemonEvolveEvent { Uid = pokemon.Id, Id = pokemon.PokemonId, Exp = evolveResponse.ExperienceAwarded, Result = evolveResponse.Result }); if (evolveResponse.EvolvedPokemonData != null) { var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var pokemonSettings = (await session.Inventory.GetPokemonSettings()).ToList(); var setting = pokemonSettings.Single(q => q.PokemonId == evolveResponse.EvolvedPokemonData.PokemonId); var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId); session.EventDispatcher.Send(new PokemonEvolveDoneEvent { Uid = evolveResponse.EvolvedPokemonData.Id, Id = evolveResponse.EvolvedPokemonData.PokemonId, Cp = evolveResponse.EvolvedPokemonData.Cp, Perfection = evolveResponse.EvolvedPokemonData.CalculatePokemonPerfection(), Family = family.FamilyId, Level = PokemonInfo.GetLevel(evolveResponse.EvolvedPokemonData), Candy = family.Candy_, Type1 = setting.Type, Type2 = setting.Type2, Stats = setting.Stats, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokemon, session.Runtime.CurrentLevel), Stamina = pokemon.Stamina, MaxStamina = pokemon.StaminaMax, Move1 = evolveResponse.EvolvedPokemonData.Move1, Move2 = evolveResponse.EvolvedPokemonData.Move2 }); } await DelayingUtils.Delay(session.LogicSettings.DelayEvolvePokemon, 25000); session.State = prevState; }
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; } var pokemonSettings = await session.Inventory.GetPokemonSettings(); var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var setting = pokemonSettings.FirstOrDefault(q => q.PokemonId == hatched?.PokemonId); var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId); if (family != null && setting != null) { session.EventDispatcher.Send(new EggHatchedEvent { Id = hatched.Id, PokemonId = hatched.PokemonId, Level = PokemonInfo.GetLevel(hatched), Cp = hatched.Cp, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(hatched, session.Runtime.CurrentLevel), Perfection = Math.Round(hatched.CalculatePokemonPerfection(), 2), Move1 = hatched.Move1, Move2 = hatched.Move2, Candy = family.Candy_, Family = family.FamilyId, Type1 = setting.Type, Type2 = setting.Type2, Stats = setting.Stats, Stamina = hatched.Stamina, MaxStamina = hatched.StaminaMax }); } } var newRememberedIncubators = new List <IncubatorUsage>(); foreach (var incubator in incubators.Where(x => x.ItemId == ItemId.ItemIncubatorBasicUnlimited || !session.LogicSettings.UseOnlyUnlimitedIncubator)) { cancellationToken.ThrowIfCancellationRequested(); if (incubator.PokemonId == 0) { // Unlimited incubators prefer short eggs, limited incubators prefer long eggs var egg = (incubator.ItemId == ItemId.ItemIncubatorBasicUnlimited && !session.LogicSettings.AlwaysPrefferLongDistanceEgg) ? unusedEggs.FirstOrDefault() : unusedEggs.LastOrDefault(); if (egg == null) { 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); } }
private static async Task CheckHatchedFromEggList(ISession session, CancellationToken cancellationToken, List <PokemonData> pokemons, ObservableCollection <PokeEgg> eggCollection) { var eggToRemove = new List <PokeEgg>(); foreach (var egg in eggCollection) { var eggExists = pokemons.Any(x => x.Id == egg.EggId); if (!eggExists) { eggToRemove.Add(egg); continue; } var hatched = pokemons.FirstOrDefault(x => !x.IsEgg && x.Id == egg.EggId); if (hatched == null) { continue; } var pokemonSettings = await session.Inventory.GetPokemonSettings(); var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); var setting = pokemonSettings.FirstOrDefault(q => q.PokemonId == hatched.PokemonId); var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId); if (family == null || setting == null) { continue; } session.EventDispatcher.Send(new EggHatchedEvent { Uid = hatched.Id, Id = hatched.PokemonId, Level = hatched.GetLevel(), Cp = hatched.Cp, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(hatched, session.Runtime.CurrentLevel), Perfection = Math.Round(hatched.CalculatePokemonPerfection(), 2), Move1 = hatched.Move1, Move2 = hatched.Move2, Candy = family.Candy_, Family = family.FamilyId, Type1 = setting.Type, Type2 = setting.Type2, Stats = setting.Stats, Stamina = hatched.Stamina, IvSta = hatched.IndividualStamina, PossibleCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(hatched, 40), CandyToEvolve = setting.CandyToEvolve, IvAtk = hatched.IndividualAttack, IvDef = hatched.IndividualDefense, Weight = hatched.WeightKg, Cpm = hatched.CpMultiplier + hatched.AdditionalCpMultiplier, StaminaMax = hatched.StaminaMax, Evolutions = setting.EvolutionIds.ToArray() }); eggToRemove.Add(egg); await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken); } foreach (var egg in eggToRemove) { eggCollection.Remove(egg); } }
public static async Task Execute(ISession session, ulong pokemonId, CancellationToken cancellationToken, string customName = null, bool toDefault = false) { if (customName == null) { return; } if (!await CheckBotStateTask.Execute(session, cancellationToken)) { return; } var id = pokemonId; var all = await session.Inventory.GetPokemons(); var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax); var pokemon = pokemons.FirstOrDefault(p => p.Id == id); if (pokemon == null) { return; } var pokemonDefaultName = session.Translation.GetPokemonName(pokemon.PokemonId); var currentNickname = pokemon.Nickname.Length != 0 ? pokemon.Nickname : session.Translation.GetPokemonName(pokemon.PokemonId); if (toDefault) { customName = pokemonDefaultName; } if (currentNickname == customName) { return; } var resp = await session.Client.Inventory.NicknamePokemon(id, customName); var prevState = session.State; session.State = BotState.Renaming; await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 2000); session.EventDispatcher.Send(new NoticeEvent { Message = session.Translation.GetTranslation(TranslationString.PokemonRename, session.Translation.GetPokemonName(pokemon.PokemonId), pokemon.Id, currentNickname, customName) }); if (resp.Result == NicknamePokemonResponse.Types.Result.Success) { 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 = customName, Uid = pokemonId, Id = pokemon.PokemonId, Family = family.FamilyId, Candy = family.Candy_, Cp = pokemon.Cp, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokemon, session.Runtime.CurrentLevel), Iv = pokemon.CalculatePokemonPerfection(), Favourite = pokemon.Favorite == 1 }); } session.State = prevState; }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var prevState = session.State; session.State = BotState.Evolve; // Refresh inventory so that the player stats are fresh await session.Inventory.RefreshCachedInventory(); var pokemonToEvolveTask = await session.Inventory.GetPokemonToEvolve(session.LogicSettings.PokemonsToEvolve); var pokemonToEvolve = pokemonToEvolveTask.Where(x => string.IsNullOrEmpty(x.DeployedFortId)).ToList(); if (pokemonToEvolve.Any()) { var inventoryContent = await session.Inventory.GetItems(); var luckyEggs = inventoryContent.Where(p => p.ItemId == ItemId.ItemLuckyEgg); var luckyEgg = luckyEggs.FirstOrDefault(); //maybe there can be a warning message as an else condition of luckyEgg checks, like; //"There is no Lucky Egg, so, your UseLuckyEggsMinPokemonAmount setting bypassed." if (session.LogicSettings.UseLuckyEggsWhileEvolving && luckyEgg != null && luckyEgg.Count > 0) { if (pokemonToEvolve.Count >= session.LogicSettings.UseLuckyEggsMinPokemonAmount) { await UseLuckyEgg(session); } else { // Wait until we have enough pokemon session.EventDispatcher.Send(new UseLuckyEggMinPokemonEvent { Diff = session.LogicSettings.UseLuckyEggsMinPokemonAmount - pokemonToEvolve.Count, CurrCount = pokemonToEvolve.Count, MinPokemon = session.LogicSettings.UseLuckyEggsMinPokemonAmount }); return; } } var pokemonFamilies = session.Inventory.GetPokemonFamilies().Result; foreach (var pokemon in pokemonToEvolve) { // no cancellationToken.ThrowIfCancellationRequested here, otherwise the lucky egg would be wasted. var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id); session.EventDispatcher.Send(new PokemonEvolveEvent { Uid = pokemon.Id, Id = pokemon.PokemonId, Exp = evolveResponse.ExperienceAwarded, Result = evolveResponse.Result }); if (evolveResponse.EvolvedPokemonData != null) { var pokemonSettings = session.Inventory.GetPokemonSettings().Result.ToList(); var setting = pokemonSettings.Single(q => q.PokemonId == evolveResponse.EvolvedPokemonData.PokemonId); var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId); session.EventDispatcher.Send(new PokemonEvolveDoneEvent { Uid = evolveResponse.EvolvedPokemonData.Id, Id = evolveResponse.EvolvedPokemonData.PokemonId, Cp = evolveResponse.EvolvedPokemonData.Cp, Perfection = evolveResponse.EvolvedPokemonData.CalculatePokemonPerfection(), Family = family.FamilyId, Candy = family.Candy_, Level = PokemonInfo.GetLevel(pokemon), Move1 = pokemon.Move1, Move2 = pokemon.Move2, Type1 = setting.Type, Type2 = setting.Type2, Stats = setting.Stats, MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokemon, session.Runtime.CurrentLevel), Stamina = pokemon.Stamina, MaxStamina = pokemon.StaminaMax, PossibleCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokemon, 40), CandyToEvolve = setting.CandyToEvolve }); } await DelayingEvolveUtils.Delay(session.LogicSettings.DelayEvolvePokemon, 0, session.LogicSettings.DelayEvolveVariation); } } session.State = prevState; }
public async void BuildPokemonList(List <PokemonData> receivedList) { var pokeInAction = PokemonList.Where(x => x != null && x.InAction).ToList(); PokemonList.Clear(); var pokemonFamilies = await Session.Inventory.GetPokemonFamilies(); var pokemonSettings = (await Session.Inventory.GetPokemonSettings()).ToList(); foreach (var pokemonGroup in receivedList.GroupBy(x => x.PokemonId)) { var setting = pokemonSettings.Single(q => q.PokemonId == pokemonGroup.Key); var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId); foreach (var pokemon in pokemonGroup) { if (PokemonList.Any(x => x.Id == pokemon.Id)) { continue; } var mon = new PokemonUiData( this, pokemon.Id, pokemon.PokemonId, //pokemon.Item1.PokemonId.ToInventorySource(), IsNullOrEmpty(pokemon.Nickname) ? Session.Translation.GetPokemonName(pokemon.PokemonId) : pokemon.Nickname, pokemon.Cp, pokemon.CalculatePokemonPerfection(), family.FamilyId, family.Candy_, pokemon.CreationTimeMs, pokemon.Favorite == 1, !IsNullOrEmpty(pokemon.DeployedFortId), pokemon.GetLevel(), pokemon.Move1, pokemon.Move2, setting.Type, setting.Type2, (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokemon, Level), PokemonInfo.GetBaseStats(pokemon.PokemonId), pokemon.Stamina, pokemon.IndividualStamina, (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokemon, 40), setting.CandyToEvolve, pokemon.IndividualAttack, pokemon.IndividualDefense, pokemon.CpMultiplier + pokemon.AdditionalCpMultiplier, pokemon.WeightKg, pokemon.StaminaMax, setting.EvolutionIds.ToArray(), Session.Profile?.PlayerData?.BuddyPokemon?.Id == pokemon.Id); if (pokeInAction.Any(x => x.Id == mon.Id)) { mon.InAction = true; } PokemonList.Add(mon); mon.UpdateTags(Logic); } } }
public static async Task <bool> Execute(ISession session, dynamic encounter, PokemonCacheItem pokemon, CancellationToken cancellationToken, 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", 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 if (normalizedRecticleSize > 1.95) { normalizedRecticleSize = 1.95; } else if (normalizedRecticleSize < 0.1) { normalizedRecticleSize = 0.1; } 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; Logger.Write(session.Translation.GetTranslation(TranslationString.ThrowPokeball, (Math.Abs(spinModifier - 1) < 0.00001 ? "Spinning " : ""), getThrowType(normalizedRecticleSize), returnRealBallName(pokeball), (hit ? "WILL HIT" : "WILL MISS")), 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 }); //Remove that ball from cache session.Inventory.RemoveItemFromCacheByType(pokeball, 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) { var candy = family.Candy_ == 0 ? 3 : family.Candy_; family.Candy_ += caughtPokemonResponse.CaptureAward.Candy.Sum(); evt.Family = family.FamilyId; evt.FamilyCandies = candy; evt.Evolutions = setting.EvolutionIds.ToArray(); evt.Type1 = setting.Type; evt.Candy = candy; evt.Type2 = setting.Type2; evt.Stats = setting.Stats; evt.CandyToEvolve = setting.CandyToEvolve; PokemonData poke = encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData; if (poke != null) { evt.Stamina = poke.Stamina; evt.IvSta = poke.IndividualStamina; } } else { evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum(); } session.MapCache.PokemonCaught(pokemon); Logger.Write($"[Catch Dump] Caught {pokemon.PokemonId} - Coords[Lat: {lat} - Lng: {lng}]"); } else if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee) { pokemon.Caught = true; } else if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) { canUseBerry = true; } else if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchError) { await session.Inventory.RefreshCachedInventory(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 = pokeData.GetLevel(); evt.Cp = pokeData.Cp; evt.MaxCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokeData, session.Runtime.CurrentLevel); evt.Perfection = Math.Round(pokeData.CalculatePokemonPerfection(), 2); evt.Probability = Math.Round(probability * 100, 2); evt.Move1 = pokeData.Move1; evt.Move2 = pokeData.Move2; evt.IvAtk = pokeData.IndividualAttack; evt.IvDef = pokeData.IndividualDefense; evt.Weight = pokeData.WeightKg; evt.StaminaMax = pokeData.StaminaMax; evt.Cpm = pokeData.CpMultiplier + pokeData.AdditionalCpMultiplier; evt.PossibleCp = (int)PokemonInfo.GetMaxCpAtTrainerLevel(pokeData, 40); } 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, cancellationToken); } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); session.State = prevState; return(true); }