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; } }
public void DamagedMissingItemCommand() { var db = DataRepository.GetDataRepository; Assert.NotNull(db); var user = db.Load <UserDetail>("steph"); var userManager = new UserManager(db); UserManager.GetUserManager.LoginUser(user); // construction expects a valid user Assert.NotNull(UserManager.GetUserManager.CurrentUser()); var damagedCmd = new DamagedMissingItemCommand(DamageMissingEventType.Damage); var missingCmd = new DamagedMissingItemCommand(DamageMissingEventType.Missing); var item = db.Load <ItemInstance>(SampleItemInstance); Assert.NotNull(item); Assert.That(item.status.name, Is.EqualTo("Available")); Assert.IsTrue(damagedCmd.CanExecute(item)); Assert.IsTrue(missingCmd.CanExecute(item)); damagedCmd.Execute(item); Assert.IsFalse(damagedCmd.CanExecute(item)); Assert.IsTrue(missingCmd.CanExecute(item)); missingCmd.Execute(item); Assert.IsFalse(damagedCmd.CanExecute(item)); Assert.IsFalse(missingCmd.CanExecute(item)); // restore status var returnToInventoryCmd = new ReturnToInventoryCommand(); returnToInventoryCmd.Execute(item); Assert.That(item.status.name, Is.EqualTo("Available")); Assert.IsTrue(damagedCmd.CanExecute(item)); Assert.IsTrue(missingCmd.CanExecute(item)); }
public void ReturnItemCommand() { var cmd = new ReturnToInventoryCommand(); var db = DataRepository.GetDataRepository; Assert.NotNull(db); var available = db.ReferenceData[nameof(ItemStatus)].ByName <ItemStatus>("Available"); var missing = db.ReferenceData[nameof(ItemStatus)].ByName <ItemStatus>("Missing"); var item = db.Load <ItemInstance>(SampleItemInstance); Assert.NotNull(item); Assert.That(item.status, Is.EqualTo(available)); Assert.IsFalse(cmd.CanExecute(item)); item.status = missing; Assert.IsTrue(cmd.CanExecute(item)); cmd.Execute(item); Assert.That(item.status, Is.EqualTo(available)); }