public async Task <UpgradePokemonResponse> UpgradePokemon(ulong pokemonId) { var upgradePokemonRequest = new Request { RequestType = RequestType.UpgradePokemon, RequestMessage = ((IMessage) new UpgradePokemonMessage { PokemonId = pokemonId }).ToByteString() }; var request = await GetRequestBuilder().GetRequestEnvelope(CommonRequest.FillRequest(upgradePokemonRequest, Client)).ConfigureAwait(false); Tuple <UpgradePokemonResponse, CheckChallengeResponse, GetHatchedEggsResponse, GetHoloInventoryResponse, CheckAwardedBadgesResponse, DownloadSettingsResponse, GetBuddyWalkedResponse> response = await PostProtoPayload <Request, UpgradePokemonResponse, CheckChallengeResponse, GetHatchedEggsResponse, GetHoloInventoryResponse, CheckAwardedBadgesResponse, DownloadSettingsResponse, GetBuddyWalkedResponse>(request).ConfigureAwait(false); CheckChallengeResponse checkChallengeResponse = response.Item2; CommonRequest.ProcessCheckChallengeResponse(Client, checkChallengeResponse); GetHoloInventoryResponse getHoloInventoryResponse = response.Item4; CommonRequest.ProcessGetHoloInventoryResponse(Client, getHoloInventoryResponse); DownloadSettingsResponse downloadSettingsResponse = response.Item6; CommonRequest.ProcessDownloadSettingsResponse(Client, downloadSettingsResponse); UpgradePokemonResponse upgradePokemonResponse = response.Item1; return(upgradePokemonResponse); }
private async void powerUp(ulong id, bool runUpdate = true) { UpgradePokemonResponse ups = await this._session.Client.Inventory.UpgradePokemon(id); MessageBox.Show($"PowerUp result: {ups.Result}\nCP: {ups.UpgradedPokemon.Cp}", $"PowerUp result for {ups.UpgradedPokemon.PokemonId.ToString()}", MessageBoxButtons.OK, MessageBoxIcon.Information); if (runUpdate) { await this.getPokemons(); } }
private async void maxPowerUp(ulong id, string name) { int i = 0; UpgradePokemonResponse ups = await this._session.Client.Inventory.UpgradePokemon(id); while (ups.Result == UpgradePokemonResponse.Types.Result.Success) { Logger.Write($"POWERUP-MAX {name} run #{i}. Result: {ups.Result}"); i++; DelayingUtils.Delay(this._session.LogicSettings.DelayBetweenPlayerActions, 0); ups = await this._session.Client.Inventory.UpgradePokemon(id); } Logger.Write($"POWERUP-MAX {name} run #{i}. Result: {ups.Result}. Stopping."); await this.getPokemons(); }
public async Task <MethodResult> UpgradePokemon(PokemonData pokemon, int amount) { try { for (int i = 0; i < amount; i++) { UpgradePokemonResponse upgradeResponse = await _client.Inventory.UpgradePokemon(pokemon.Id); if (upgradeResponse.Result != UpgradePokemonResponse.Types.Result.Success) { LogCaller(new LoggerEventArgs(String.Format("Finished upgrading pokemon. End result: {0}", upgradeResponse.Result.ToString().Replace("Error", "")), LoggerTypes.Info)); break; } LogCaller(new LoggerEventArgs(String.Format("Pokemon {0} upgraded. CP: {1} -> {2}", pokemon.PokemonId, pokemon.Cp, upgradeResponse.UpgradedPokemon.Cp), LoggerTypes.Success)); //So people don't complain about it not increasing pokemon.Cp = upgradeResponse.UpgradedPokemon.Cp; await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom)); } await Task.Delay(CalculateDelay(UserSettings.DelayBetweenPlayerActions, UserSettings.PlayerActionDelayRandom)); return(new MethodResult { Success = true }); } catch (Exception ex) { LogCaller(new LoggerEventArgs("Upgrade request failed", LoggerTypes.Exception, ex)); return(new MethodResult()); } }
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; }
protected ByteString GetPlayerPacket(RequestType typ, object msg) { switch (typ) { case RequestType.SetFavoritePokemon: SetFavoritePokemonResponse sfp = new SetFavoritePokemonResponse(); SetFavoritePokemonMessage m = (SetFavoritePokemonMessage)msg; var owned = this.GetPokemonById((ulong)m.PokemonId); if (owned != null) { m.IsFavorite = true; owned.favorite = true; this.Database.OwnedPokemons.Update(owned); sfp.Result = SetFavoritePokemonResponse.Types.Result.Success; } else { sfp.Result = SetFavoritePokemonResponse.Types.Result.ErrorPokemonNotFound; } //this.Log.Dbg($"TypeOfResponseMessage: {nameof(SetFavoritePokemonResponse)}"); return(sfp.ToByteString()); case RequestType.LevelUpRewards: LevelUpRewardsResponse lur = new LevelUpRewardsResponse(); lur.Result = LevelUpRewardsResponse.Types.Result.Success; lur.ItemsAwarded.AddRange(new RepeatedField <ItemAward>() { new ItemAward() { ItemId = ItemId.ItemPokeBall, ItemCount = 2 }, new ItemAward() { ItemId = ItemId.ItemTroyDisk, ItemCount = 2 } }); //this.Log.Dbg($"TypeOfResponseMessage: {nameof(LevelUpRewardsResponse)}"); return(lur.ToByteString()); case RequestType.ReleasePokemon: ReleasePokemonResponse rp = this.ReleasePokemon((ReleasePokemonMessage)msg); //this.Log.Dbg($"TypeOfResponseMessage: {nameof(ReleasePokemonResponse)}"); return(rp.ToByteString()); case RequestType.UpgradePokemon: UpgradePokemonResponse up = new UpgradePokemonResponse(); //UpgradePokemonMessage upm = (UpgradePokemonMessage)msg; //var uptpkmn = brc.GetPokemonById(upm.PokemonId); //if (uptpkmn!=null) //{ //} //else //{ // up.Result = UpgradePokemonResponse.Types.Result.ErrorPokemonNotFound; //} //this.Log.Dbg($"TypeOfResponseMessage: {nameof(UpgradePokemonResponse)}"); return(up.ToByteString()); //https://github.com/msx752/PoGoEmulator/issues/24 case RequestType.GetPlayerProfile: GetPlayerProfileResponse gpp = new GetPlayerProfileResponse(); gpp.Result = GetPlayerProfileResponse.Types.Result.Success; gpp.StartTime = (long)DateTime.Now.ToUnixTime(); gpp.Badges.Add(new POGOProtos.Data.PlayerBadge() { BadgeType = BadgeType.BadgeTravelKm, EndValue = 2674, CurrentValue = 1337 }); return(gpp.ToByteString()); //case RequestType.SetAvatar: // LevelUpRewardsResponse sa = new LevelUpRewardsResponse(); // return sa.ToByteString(); case RequestType.GetPlayer: //this.Log.Dbg($"TypeOfResponseMessage: {nameof(GetPlayerResponse)}"); return(this.GetPlayer()); case RequestType.GetInventory: RepeatedField <InventoryItem> items = new RepeatedField <InventoryItem>(); //ADD ITEMSS GetInventoryResponse gi = new GetInventoryResponse(); gi.Success = true; gi.InventoryDelta = new POGOProtos.Inventory.InventoryDelta() { NewTimestampMs = (long)DateTime.Now.ToUnixTime() }; gi.InventoryDelta.InventoryItems.AddRange(items); //this.Log.Dbg($"TypeOfResponseMessage: {nameof(GetInventoryResponse)}"); return(gi.ToByteString()); case RequestType.GetAssetDigest: var gad = GlobalSettings.GameAssets[this.CurrentPlayer.Platform].Value; //this.Log.Dbg($"TypeOfResponseMessage: {nameof(GetAssetDigestResponse)}"); return(gad.ToByteString()); //case RequestType.NicknamePokemon: // LevelUpRewardsResponse np = new LevelUpRewardsResponse(); // return np.ToByteString(); case RequestType.GetHatchedEggs: GetHatchedEggsResponse ghe = new GetHatchedEggsResponse(); ghe.Success = true; //this.Log.Dbg($"TypeOfResponseMessage: {nameof(GetHatchedEggsResponse)}"); return(ghe.ToByteString()); case RequestType.CheckAwardedBadges: CheckAwardedBadgesResponse cab = new CheckAwardedBadgesResponse(); cab.Success = true; //this.Log.Dbg($"TypeOfResponseMessage: {nameof(CheckAwardedBadgesResponse)}"); return(cab.ToByteString()); //case RequestType.RecycleInventoryItem: // LevelUpRewardsResponse rii = new LevelUpRewardsResponse(); // return rii.ToByteString(); //case RequestType.ClaimCodename: // LevelUpRewardsResponse cc = new LevelUpRewardsResponse(); // return cc.ToByteString(); default: throw new Exception($"unknown (Player) Returns type: {typ}"); } }
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; }
/// <summary> /// Provides a safe way to invoke the <see cref="UpgradePokemonReceived" /> event. /// </summary> /// <param name="value"></param> public void RaiseUpgradePokemonReceived(UpgradePokemonResponse value) => UpgradePokemonReceived?.Invoke(this, value);
public static async Task Execute(ISession session, ulong pokemonId, bool toMax = false) { 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; } 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() { Uid = pokemonId, Id = pokemon.PokemonId, Family = family.FamilyId, Candy = family.Candy_, Cp = latestSuccessResponse.UpgradedPokemon.Cp, Iv = latestSuccessResponse.UpgradedPokemon.CalculatePokemonPerfection() }); } }