예제 #1
0
        private void UpdateSorting()
        {
            switch (CurrentPokemonSortingMode)
            {
            case PokemonSortingModes.Date:
                PokemonInventory = new ObservableCollection <PokemonData>(PokemonInventory.OrderByDescending(pokemon => pokemon.CreationTimeMs));
                break;

            case PokemonSortingModes.Fav:
                PokemonInventory = new ObservableCollection <PokemonData>(PokemonInventory.OrderByDescending(pokemon => pokemon.Favorite));
                break;

            case PokemonSortingModes.Number:
                PokemonInventory = new ObservableCollection <PokemonData>(PokemonInventory.OrderBy(pokemon => pokemon.PokemonId));
                break;

            case PokemonSortingModes.Health:
                PokemonInventory = new ObservableCollection <PokemonData>(PokemonInventory.OrderByDescending(pokemon => pokemon.Stamina));
                break;

            case PokemonSortingModes.Name:
                PokemonInventory =
                    new ObservableCollection <PokemonData>(
                        PokemonInventory.OrderBy(pokemon => pokemon.PokemonId.ToString()));
                break;

            case PokemonSortingModes.Combat:
                PokemonInventory = new ObservableCollection <PokemonData>(PokemonInventory.OrderByDescending(pokemon => pokemon.Cp));
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(CurrentPokemonSortingMode), CurrentPokemonSortingMode, null);
            }
            RaisePropertyChanged(() => PokemonInventory);
        }
        /// <summary>
        /// Sort the PokemonInventory with the CurrentPokemonSortingMode
        /// </summary>
        private void UpdateSorting()
        {
            PokemonInventory =
                new ObservableCollection <PokemonDataWrapper>(PokemonInventory.SortBySortingmode(CurrentPokemonSortingMode));

            RaisePropertyChanged(() => PokemonInventory);
        }
        /// <summary>
        /// </summary>
        /// <param name="parameter"></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
                PokemonInventory          = JsonConvert.DeserializeObject <ObservableCollection <PokemonDataWrapper> >((string)suspensionState[nameof(PokemonInventory)]);
                EggsInventory             = JsonConvert.DeserializeObject <ObservableCollection <PokemonDataWrapper> >((string)suspensionState[nameof(EggsInventory)]);
                CurrentPokemonSortingMode = (PokemonSortingModes)suspensionState[nameof(CurrentPokemonSortingMode)];
                PlayerProfile             = GameClient.PlayerData;
            }
            else
            {
                // Navigating from game page, so we need to actually load the inventory
                // The sorting mode is directly bound to the settings
                PokemonInventory = new ObservableCollection <PokemonDataWrapper>(GameClient.PokemonsInventory
                                                                                 .Select(pokemonData => new PokemonDataWrapper(pokemonData))
                                                                                 .SortBySortingmode(CurrentPokemonSortingMode));

                RaisePropertyChanged(() => PokemonInventory);

                var unincubatedEggs = GameClient.EggsInventory.Where(o => string.IsNullOrEmpty(o.EggIncubatorId))
                                      .OrderBy(c => c.EggKmWalkedTarget);
                var incubatedEggs = GameClient.EggsInventory.Where(o => !string.IsNullOrEmpty(o.EggIncubatorId))
                                    .OrderBy(c => c.EggKmWalkedTarget);
                EggsInventory.Clear();
                // advancedrei: I have verified this is the sort order in the game.
                foreach (var incubatedEgg in incubatedEggs)
                {
                    EggsInventory.Add(new IncubatedEggDataWrapper(GameClient.GetIncubatorFromEgg(incubatedEgg), GameClient.PlayerStats.KmWalked, incubatedEgg));
                }

                foreach (var pokemonData in unincubatedEggs)
                {
                    EggsInventory.Add(new PokemonDataWrapper(pokemonData));
                }

                RaisePropertyChanged(() => TotalPokemonCount);

                PlayerProfile = GameClient.PlayerData;
            }

            // try restoring scrolling position
            if (NavigationHelper.NavigationState.ContainsKey("LastViewedPokemonDetailID"))
            {
                ulong pokemonId = (ulong)NavigationHelper.NavigationState["LastViewedPokemonDetailID"];
                NavigationHelper.NavigationState.Remove("LastViewedPokemonDetailID");
                var pokemon = PokemonInventory.Where(p => p.Id == pokemonId).FirstOrDefault();
                if (pokemon != null)
                {
                    ScrollPokemonToVisibleRequired?.Invoke(pokemon);
                }
            }

            // set the selectioMode to GoToDetail
            currentSelectionMode = SelectionMode.GoToDetail;

            await Task.CompletedTask;
        }
        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;
            }
        }
예제 #6
0
 private void ViewModel_MultiplePokemonSelected(object sender, PokemonDataWrapper e)
 {
     // Show or hide the 'Transfer multiple' button at the bottom of the screen
     if (ViewModel.SelectedPokemons.Count > 0)
     {
         PokemonInventory.SelectPokemon(e);
         ShowMultipleSelectStoryboard.Begin();
         PokemonInventory.ShowHideSortingButton(false);
     }
     else
     {
         PokemonInventory.ClearSelectedPokemons();
         HideMultipleSelectStoryboard.Begin();
         PokemonInventory.ShowHideSortingButton(true);
     }
 }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="parameter"></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
         PokemonInventory          = (ObservableCollection <PokemonData>)suspensionState[nameof(PokemonInventory)];
         CurrentPokemonSortingMode = (PokemonSortingModes)suspensionState[nameof(CurrentPokemonSortingMode)];
     }
     else if (parameter is bool)
     {
         // Navigating from game page, so we need to actually load the inventory and set default sorting mode
         PokemonInventory.AddRange(GameClient.PokemonsInventory);
         CurrentPokemonSortingMode = PokemonSortingModes.Combat;
     }
     await Task.CompletedTask;
 }
예제 #8
0
        public void Load(ulong selectedPokemonId, PokemonSortingModes sortingMode, PokemonDetailPageViewMode viewMode)
        {
            PokemonInventory.Clear();
            SortingMode = sortingMode;
            ViewMode    = viewMode;
            if (viewMode == PokemonDetailPageViewMode.Normal)
            {
                // Navigating from inventory page so we need to load the pokemoninventory and the current pokemon
                PokemonInventory.AddRange(GameClient.PokemonsInventory.Select(pokemonData => new PokemonDataWrapper(pokemonData)).SortBySortingmode(sortingMode));
                SelectedPokemon = PokemonInventory.FirstOrDefault(pokemon => pokemon.Id == selectedPokemonId);
            }
            else
            {
                // Navigating from Capture, Egg hatch or evolve, only show this pokemon
                PokemonInventory.Add(GameClient.PokemonsInventory.Where(pokemon => pokemon.Id == selectedPokemonId).Select(pokemonData => new PokemonDataWrapper(pokemonData)).FirstOrDefault());
                SelectedPokemon = PokemonInventory.First();
            }

            StardustAmount  = GameClient.PlayerProfile.Currencies.FirstOrDefault(item => item.Name.Equals("STARDUST")).Amount;
            PlayerTeamIsSet = GameClient.PlayerProfile.Team != TeamColor.Neutral;
        }