private async void UseRevive(PokemonDataWrapper pokemon, ItemId item) { try { ServerRequestRunning = true; // Use local var to prevent bug when changing selected pokemon during running request var affectingPokemon = SelectedPokemon; // Send revive request var res = await GameClient.UseItemRevive(item, pokemon.Id); switch (res.Result) { case UseItemReviveResponse.Types.Result.Unset: break; case UseItemReviveResponse.Types.Result.Success: // Reload updated data bool selectedPokemonSameAsAffecting = affectingPokemon == SelectedPokemon; PokemonInventory.Remove(affectingPokemon); var affectedPokemon = new PokemonDataWrapper(affectingPokemon.WrappedData); affectedPokemon.SetStamina(res.Stamina); PokemonInventory.SortBySortingmode(CurrentPokemonSortingMode); CurrentUseItem.Count--; // If the affecting pokemon is still showing (not fliped to other), change selected to affected if (selectedPokemonSameAsAffecting) { SelectedPokemon = affectedPokemon; RaisePropertyChanged(nameof(SelectedPokemon)); RaisePropertyChanged(nameof(CurrentUseItem)); } await GameClient.UpdateProfile(); // If nothing of this item is left, remove from inventory manually and return to the inventory overview page if (CurrentUseItem?.Count == 0) { ItemsInventory.Remove(CurrentUseItem); ReturnToInventoryCommand.Execute(); } break; case UseItemReviveResponse.Types.Result.ErrorDeployedToFort: ErrorDeployedToFort?.Invoke(this, null); break; case UseItemReviveResponse.Types.Result.ErrorCannotUse: break; default: throw new ArgumentOutOfRangeException(); } } finally { ServerRequestRunning = false; } }
private async void UsePotion(PokemonDataWrapper pokemon, ItemId item) { try { ServerRequestRunning = true; // Use local var to prevent bug when changing selected pokemon during running request var affectingPokemon = SelectedPokemon; // Send potion request var res = await GameClient.UseItemPotion(item, affectingPokemon.Id); switch (res.Result) { case UseItemPotionResponse.Types.Result.Unset: break; case UseItemPotionResponse.Types.Result.Success: // Reload updated data bool selectedPokemonSameAsAffecting = affectingPokemon == SelectedPokemon; PokemonInventory.Remove(affectingPokemon); var affectedPokemon = new PokemonDataWrapper(affectingPokemon.WrappedData); affectedPokemon.SetStamina(res.Stamina); if (affectedPokemon.Stamina < affectedPokemon.StaminaMax) { PokemonInventory.Add(affectedPokemon); } PokemonInventory.SortBySortingmode(CurrentPokemonSortingMode); CurrentUseItem.Count--; // If the affecting pokemon is still showing (not fliped to other), change selected to affected if (selectedPokemonSameAsAffecting) { SelectedPokemon = affectedPokemon; RaisePropertyChanged(nameof(SelectedPokemon)); RaisePropertyChanged(nameof(CurrentUseItem)); } //GameClient.UpdateInventory(); await GameClient.UpdateProfile(); break; case UseItemPotionResponse.Types.Result.ErrorDeployedToFort: ErrorDeployedToFort?.Invoke(this, null); break; case UseItemPotionResponse.Types.Result.ErrorCannotUse: break; default: throw new ArgumentOutOfRangeException(); } } finally { ServerRequestRunning = false; } }