/// <summary> /// </summary> /// <param name="parameter">MapPokemonWrapper containing the Pokemon that we're trying to capture</param> /// <param name="mode"></param> /// <param name="suspensionState"></param> /// <returns></returns> public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState) { if (suspensionState.Any()) { // Recovering the state CurrentEncounter = new EncounterResponse(); CurrentLureEncounter = new DiskEncounterResponse(); CurrentCaptureAward = new CaptureAward(); SelectedCaptureItem = new ItemData(); CurrentPokemon = JsonConvert.DeserializeObject <IMapPokemon>((string)suspensionState[nameof(CurrentPokemon)]); CurrentEncounter.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentEncounter)]).CreateCodedInput()); CurrentLureEncounter.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentLureEncounter)]).CreateCodedInput()); CurrentCaptureAward.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentCaptureAward)]).CreateCodedInput()); SelectedCaptureItem.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(SelectedCaptureItem)]).CreateCodedInput()); RaisePropertyChanged(() => CurrentEncounter); RaisePropertyChanged(() => CurrentLureEncounter); RaisePropertyChanged(() => CurrentCaptureAward); RaisePropertyChanged(() => SelectedCaptureItem); } else { // Navigating from game page, so we need to actually load the encounter CurrentPokemon = (IMapPokemon)NavigationHelper.NavigationState[nameof(CurrentPokemon)]; Busy.SetBusy(true, string.Format(Resources.CodeResources.GetString("LoadingEncounterText"), Resources.Pokemon.GetString(CurrentPokemon.PokemonId.ToString()))); NavigationHelper.NavigationState.Remove(nameof(CurrentPokemon)); Logger.Write($"Catching {CurrentPokemon.PokemonId}"); await HandleEncounter(); } }
public override int GetHashCode() { int hash = 1; if (Status != 0) { hash ^= Status.GetHashCode(); } if (MissPercent != 0D) { hash ^= MissPercent.GetHashCode(); } if (CapturedPokemonId != 0UL) { hash ^= CapturedPokemonId.GetHashCode(); } if (captureAward_ != null) { hash ^= CaptureAward.GetHashCode(); } if (CaptureReason != 0) { hash ^= CaptureReason.GetHashCode(); } if (DisplayPokedexId != 0) { hash ^= DisplayPokedexId.GetHashCode(); } if (ThrowsRemaining != 0) { hash ^= ThrowsRemaining.GetHashCode(); } return(hash); }
public void MergeFrom(CatchPokemonResponse other) { if (other == null) { return; } if (other.Status != 0) { Status = other.Status; } if (other.MissPercent != 0D) { MissPercent = other.MissPercent; } if (other.CapturedPokemonId != 0UL) { CapturedPokemonId = other.CapturedPokemonId; } if (other.captureAward_ != null) { if (captureAward_ == null) { captureAward_ = new global::POGOProtos.Data.Capture.CaptureAward(); } CaptureAward.MergeFrom(other.CaptureAward); } if (other.CaptureReason != 0) { CaptureReason = other.CaptureReason; } if (other.DisplayPokedexId != 0) { DisplayPokedexId = other.DisplayPokedexId; } }
public void MergeFrom(CatchPokemonResponse other) { if (other == null) { return; } if (other.Status != 0) { Status = other.Status; } if (other.MissPercent != 0D) { MissPercent = other.MissPercent; } if (other.CapturedPokemonId != 0UL) { CapturedPokemonId = other.CapturedPokemonId; } if (other.captureAward_ != null) { if (captureAward_ == null) { captureAward_ = new global::POGOProtos.Data.Capture.CaptureAward(); } CaptureAward.MergeFrom(other.CaptureAward); } if (other.CaptureReason != 0) { CaptureReason = other.CaptureReason; } if (other.DisplayPokedexId != 0) { DisplayPokedexId = other.DisplayPokedexId; } if (other.ThrowsRemaining != 0) { ThrowsRemaining = other.ThrowsRemaining; } if (other.pokemonDisplay_ != null) { if (pokemonDisplay_ == null) { pokemonDisplay_ = new global::POGOProtos.Data.PokemonDisplay(); } PokemonDisplay.MergeFrom(other.PokemonDisplay); } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
public override int GetHashCode() { int hash = 1; if (Status != 0) { hash ^= Status.GetHashCode(); } if (MissPercent != 0D) { hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(MissPercent); } if (CapturedPokemonId != 0UL) { hash ^= CapturedPokemonId.GetHashCode(); } if (captureAward_ != null) { hash ^= CaptureAward.GetHashCode(); } if (CaptureReason != 0) { hash ^= CaptureReason.GetHashCode(); } if (DisplayPokedexId != 0) { hash ^= DisplayPokedexId.GetHashCode(); } if (ThrowsRemaining != 0) { hash ^= ThrowsRemaining.GetHashCode(); } if (pokemonDisplay_ != null) { hash ^= PokemonDisplay.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Launches the PokeBall for the current encounter, handling the different catch responses /// </summary> /// <returns></returns> private async Task <bool> ThrowPokeball(bool hitPokemon) { // We use to simulate a 5 second wait to get animation going // If server takes too much to reply then we don't use the delay var requestTime = DateTime.Now; // If we have a starter pokemon, send just the pokemonid in a EncounterTutorialComplete request if (CurrentPokemon.EncounterId == 0) { if (!hitPokemon) { SelectedCaptureItem = SelectPokeballType(LastItemUsed) ?? SelectAvailablePokeBall(); //To restore it after UpdateInventory, which overrides it return(false); } var encounterTutorialCompleteResponse = await GameClient.EncounterTutorialComplete(CurrentPokemon.PokemonId); var responseDelay = DateTime.Now - requestTime; if (responseDelay.TotalSeconds < 5 && hitPokemon) { await Task.Delay(TimeSpan.FromSeconds(5 - (int)responseDelay.TotalSeconds)); } //GameClient.UpdateInventory(); SelectedCaptureItem = SelectPokeballType(LastItemUsed) ?? SelectAvailablePokeBall(); //To restore it after UpdateInventory, which overrides it switch (encounterTutorialCompleteResponse.Result) { case EncounterTutorialCompleteResponse.Types.Result.Success: GameClient.CurrentSession.Logger.Info($"We caught {CurrentPokemon.PokemonId}"); CurrentCaptureAward = encounterTutorialCompleteResponse.CaptureAward; CaptureXpToTotalCaptureXpConverter converter = new Utils.CaptureXpToTotalCaptureXpConverter(); GameClient.AddGameXP((int)converter.Convert(CurrentCaptureAward.Xp, typeof(int), null, null)); CatchSuccess?.Invoke(this, null); if (encounterTutorialCompleteResponse.PokemonData != null) { _capturedPokemonId = encounterTutorialCompleteResponse.PokemonData.Id; } return(true); case EncounterTutorialCompleteResponse.Types.Result.Unset: GameClient.CurrentSession.Logger.Info($"We got an 'unset' response for {CurrentPokemon.PokemonId}"); CurrentCaptureAward = new CaptureAward(); CatchSuccess?.Invoke(this, null); _capturedPokemonId = 0; return(true); default: break; } GameClient.CurrentSession.Logger.Info($"{CurrentPokemon.PokemonId} escaped"); CatchEscape?.Invoke(this, null); return(false); } else { var caughtPokemonResponse = await GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId, SelectedCaptureItem.ItemId, hitPokemon); //GameClient.UpdateInventory(); //TODO: Change to delta update inventory, so it doesn't take so long (and offico client does it too) SelectedCaptureItem = SelectPokeballType(LastItemUsed) ?? SelectAvailablePokeBall(); //To restore it after UpdateInventory, which overrides it var responseDelay = DateTime.Now - requestTime; if (responseDelay.TotalSeconds < 5 && hitPokemon) { await Task.Delay(TimeSpan.FromSeconds(5 - (int)responseDelay.TotalSeconds)); } var nearbyPokemon = GameClient.NearbyPokemons.FirstOrDefault(pokemon => pokemon.EncounterId == CurrentPokemon.EncounterId); switch (caughtPokemonResponse.Status) { case CatchPokemonResponse.Types.CatchStatus.CatchError: GameClient.CurrentSession.Logger.Info("CatchError!"); //await GameClient.UpdateInventory(); // TODO: what can we do? break; case CatchPokemonResponse.Types.CatchStatus.CatchSuccess: GameClient.CurrentSession.Logger.Info($"We caught {CurrentPokemon.PokemonId}"); CurrentCaptureAward = caughtPokemonResponse.CaptureAward; CaptureXpToTotalCaptureXpConverter converter = new Utils.CaptureXpToTotalCaptureXpConverter(); GameClient.AddGameXP((int)converter.Convert(CurrentCaptureAward.Xp, typeof(int), null, null)); CatchSuccess?.Invoke(this, null); _capturedPokemonId = caughtPokemonResponse.CapturedPokemonId; //await GameClient.UpdatePlayerStats(); -> This will be done when we return to the game screen, to allow the LevelUp to be shown //await GameClient.UpdateInventory(); if (CurrentPokemon is MapPokemonWrapper) { GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon); } else if (CurrentPokemon is LuredPokemon) { GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon); } else if (CurrentPokemon is IncensePokemon) { GameClient.IncensePokemons.Remove((IncensePokemon)CurrentPokemon); } GameClient.NearbyPokemons.Remove(nearbyPokemon); return(true); case CatchPokemonResponse.Types.CatchStatus.CatchEscape: GameClient.CurrentSession.Logger.Info($"{CurrentPokemon.PokemonId} escaped"); CatchEscape?.Invoke(this, null); _canUseBerry = true; //await GameClient.UpdateInventory(); break; case CatchPokemonResponse.Types.CatchStatus.CatchFlee: GameClient.CurrentSession.Logger.Info($"{CurrentPokemon.PokemonId} fled"); CatchFlee?.Invoke(this, null); //await GameClient.UpdateInventory(); if (CurrentPokemon is MapPokemonWrapper) { GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon); } else if (CurrentPokemon is LuredPokemon) { GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon); } else if (CurrentPokemon is IncensePokemon) { GameClient.IncensePokemons.Remove((IncensePokemon)CurrentPokemon); } GameClient.NearbyPokemons.Remove(nearbyPokemon); // We just go back because there's nothing else to do GameClient.ToggleUpdateTimer(); break; case CatchPokemonResponse.Types.CatchStatus.CatchMissed: GameClient.CurrentSession.Logger.Info($"We missed {CurrentPokemon.PokemonId}"); //await GameClient.UpdateInventory(); break; default: throw new ArgumentOutOfRangeException(); } } return(false); }