/// <summary> /// Launches the PokeBall for the current encounter, handling the different catch responses /// </summary> /// <returns></returns> private async Task ThrowPokeball(bool hitPokemon) { var caughtPokemonResponse = await GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId, SelectedCaptureItem.ItemId, hitPokemon); switch (caughtPokemonResponse.Status) { case CatchPokemonResponse.Types.CatchStatus.CatchError: Logger.Write("CatchError!"); // TODO: what can we do? break; case CatchPokemonResponse.Types.CatchStatus.CatchSuccess: CurrentCaptureAward = caughtPokemonResponse.CaptureAward; Logger.Write($"We caught {CurrentPokemon.PokemonId}"); CatchSuccess?.Invoke(this, null); await GameClient.UpdateInventory(); break; case CatchPokemonResponse.Types.CatchStatus.CatchEscape: Logger.Write($"{CurrentPokemon.PokemonId} escaped"); CatchEscape?.Invoke(this, null); await GameClient.UpdateInventory(); break; case CatchPokemonResponse.Types.CatchStatus.CatchFlee: Logger.Write($"{CurrentPokemon.PokemonId} fleed"); CatchFlee?.Invoke(this, null); await new MessageDialog($"{CurrentPokemon.PokemonId} fleed").ShowAsyncQueue(); await GameClient.UpdateInventory(); ReturnToGameScreen.Execute(); break; case CatchPokemonResponse.Types.CatchStatus.CatchMissed: Logger.Write($"We missed {CurrentPokemon.PokemonId}"); await GameClient.UpdateInventory(); CatchFlee?.Invoke(this, null); break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Launches the PokeBall for the current encounter, handling the different catch responses /// </summary> /// <returns></returns> private async Task ThrowPokeball(bool hitPokemon) { var caughtPokemonResponse = await GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId, SelectedCaptureItem.ItemId, hitPokemon); var nearbyPokemon = GameClient.NearbyPokemons.FirstOrDefault(pokemon => pokemon.EncounterId == CurrentPokemon.EncounterId); switch (caughtPokemonResponse.Status) { case CatchPokemonResponse.Types.CatchStatus.CatchError: Logger.Write("CatchError!"); // TODO: what can we do? break; case CatchPokemonResponse.Types.CatchStatus.CatchSuccess: Logger.Write($"We caught {CurrentPokemon.PokemonId}"); CurrentCaptureAward = caughtPokemonResponse.CaptureAward; CatchSuccess?.Invoke(this, null); GameClient.CatchablePokemons.Remove(CurrentPokemon); GameClient.NearbyPokemons.Remove(nearbyPokemon); break; case CatchPokemonResponse.Types.CatchStatus.CatchEscape: Logger.Write($"{CurrentPokemon.PokemonId} escaped"); CatchEscape?.Invoke(this, null); break; case CatchPokemonResponse.Types.CatchStatus.CatchFlee: Logger.Write($"{CurrentPokemon.PokemonId} fled"); CatchFlee?.Invoke(this, null); GameClient.CatchablePokemons.Remove(CurrentPokemon); GameClient.NearbyPokemons.Remove(nearbyPokemon); // We just go back because there's nothing else to do await GameClient.ToggleUpdateTimer(); break; case CatchPokemonResponse.Types.CatchStatus.CatchMissed: Logger.Write($"We missed {CurrentPokemon.PokemonId}"); break; default: throw new ArgumentOutOfRangeException(); } // We always need to update the inventory await GameClient.UpdateInventory(); }
/// <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; var caughtPokemonResponse = await GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId, SelectedCaptureItem.ItemId, hitPokemon); await 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: Logger.Write("CatchError!"); // TODO: what can we do? break; case CatchPokemonResponse.Types.CatchStatus.CatchSuccess: Logger.Write($"We caught {CurrentPokemon.PokemonId}"); CurrentCaptureAward = caughtPokemonResponse.CaptureAward; CatchSuccess?.Invoke(this, null); _capturedPokemonId = caughtPokemonResponse.CapturedPokemonId; if (CurrentPokemon is MapPokemonWrapper) { GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon); } else { GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon); } GameClient.NearbyPokemons.Remove(nearbyPokemon); return(true); case CatchPokemonResponse.Types.CatchStatus.CatchEscape: Logger.Write($"{CurrentPokemon.PokemonId} escaped"); CatchEscape?.Invoke(this, null); _canUseBerry = true; break; case CatchPokemonResponse.Types.CatchStatus.CatchFlee: Logger.Write($"{CurrentPokemon.PokemonId} fled"); CatchFlee?.Invoke(this, null); if (CurrentPokemon is MapPokemonWrapper) { GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon); } else { GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon); } GameClient.NearbyPokemons.Remove(nearbyPokemon); // We just go back because there's nothing else to do GameClient.ToggleUpdateTimer(); break; case CatchPokemonResponse.Types.CatchStatus.CatchMissed: Logger.Write($"We missed {CurrentPokemon.PokemonId}"); break; default: throw new ArgumentOutOfRangeException(); } return(false); }
/// <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); }
/// <summary> /// Launches the PokeBall for the current encounter, handling the different catch responses /// </summary> /// <returns></returns> private async Task 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; var caughtPokemonResponse = await GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId, SelectedCaptureItem.ItemId, hitPokemon); var responseDelay = DateTime.Now - requestTime; if (responseDelay.TotalSeconds < 5) { 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: Logger.Write("CatchError!"); // TODO: what can we do? break; case CatchPokemonResponse.Types.CatchStatus.CatchSuccess: Logger.Write($"We caught {CurrentPokemon.PokemonId}"); CurrentCaptureAward = caughtPokemonResponse.CaptureAward; CatchSuccess?.Invoke(this, null); if (CurrentPokemon is MapPokemonWrapper) { GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon); } else { GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon); } GameClient.NearbyPokemons.Remove(nearbyPokemon); break; case CatchPokemonResponse.Types.CatchStatus.CatchEscape: Logger.Write($"{CurrentPokemon.PokemonId} escaped"); CatchEscape?.Invoke(this, null); break; case CatchPokemonResponse.Types.CatchStatus.CatchFlee: Logger.Write($"{CurrentPokemon.PokemonId} fled"); CatchFlee?.Invoke(this, null); if (CurrentPokemon is MapPokemonWrapper) { GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon); } else { GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon); } GameClient.NearbyPokemons.Remove(nearbyPokemon); // We just go back because there's nothing else to do GameClient.ToggleUpdateTimer(); break; case CatchPokemonResponse.Types.CatchStatus.CatchMissed: Logger.Write($"We missed {CurrentPokemon.PokemonId}"); break; default: throw new ArgumentOutOfRangeException(); } // We always need to update the inventory await GameClient.UpdateInventory(); SelectStartingBall(true); }