/// <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;
        }
Esempio n. 2
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 = JsonConvert.DeserializeObject <ObservableCollection <PokemonDataWrapper> >((string)suspensionState[nameof(PokemonInventory)]);
                EggsInventory    = JsonConvert.DeserializeObject <ObservableCollection <PokemonDataWrapper> >((string)suspensionState[nameof(EggsInventory)]);
                PlayerProfile    = new PlayerData();
                PlayerProfile.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(PlayerProfile)]).CreateCodedInput());
                RaisePropertyChanged(() => PlayerProfile);
            }
            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>(GetSortedPokemonCollection(
                                                                                     GameClient.PokemonsInventory.Select(pokemonData => new PokemonDataWrapper(pokemonData)),
                                                                                     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)
                {
                    var incubatorData = GameClient.UsedIncubatorsInventory.FirstOrDefault(incubator => incubator.Id == incubatedEgg.EggIncubatorId);
                    EggsInventory.Add(new IncubatedEggDataWrapper(incubatorData, GameClient.PlayerStats.KmWalked, incubatedEgg));
                }

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

                if (mode == NavigationMode.Back)
                {
                    ResetView?.Invoke();
                }

                PlayerProfile = GameClient.PlayerProfile;
            }

            await Task.CompletedTask;
        }
Esempio n. 3
0
        /// <summary>
        ///     Updates inventory data
        /// </summary>
        public static async Task UpdateInventory()
        {
            // Get ALL the items
            var response = await GetInventory();

            var fullInventory = response.InventoryDelta?.InventoryItems;

            // Update items
            ItemsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.Item != null)
                                    .GroupBy(item => item.InventoryItemData.Item)
                                    .Select(item => item.First().InventoryItemData.Item), true);
            CatchItemsInventory.AddRange(
                fullInventory.Where(
                    item =>
                    item.InventoryItemData.Item != null && CatchItemIds.Contains(item.InventoryItemData.Item.ItemId))
                .GroupBy(item => item.InventoryItemData.Item)
                .Select(item => item.First().InventoryItemData.Item), true);
            AppliedItems.AddRange(
                fullInventory
                .Where(item => item.InventoryItemData.AppliedItems != null)
                .SelectMany(item => item.InventoryItemData.AppliedItems.Item)
                .Select(item => new AppliedItemWrapper(item)), true);

            // Update incbuators
            IncubatorsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.EggIncubators != null)
                                         .SelectMany(item => item.InventoryItemData.EggIncubators.EggIncubator)
                                         .Where(item => item != null), true);

            // Update Pokedex
            PokedexInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.PokedexEntry != null)
                                      .Select(item => item.InventoryItemData.PokedexEntry), true);

            // Update Pokemons
            PokemonsInventory.AddRange(fullInventory.Select(item => item.InventoryItemData.PokemonData)
                                       .Where(item => item != null && item.PokemonId > 0), true);
            EggsInventory.AddRange(fullInventory.Select(item => item.InventoryItemData.PokemonData)
                                   .Where(item => item != null && item.IsEgg), true);

            // Update candies
            CandyInventory.AddRange(from item in fullInventory
                                    where item.InventoryItemData?.Candy != null
                                    where item.InventoryItemData?.Candy.FamilyId != PokemonFamilyId.FamilyUnset
                                    group item by item.InventoryItemData?.Candy.FamilyId into family
                                    select new Candy
            {
                FamilyId = family.FirstOrDefault().InventoryItemData.Candy.FamilyId,
                Candy_   = family.FirstOrDefault().InventoryItemData.Candy.Candy_
            }, true);
        }
 /// <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)];
         EggsInventory             = (ObservableCollection <PokemonData>)suspensionState[nameof(EggsInventory)];
         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);
         EggsInventory.AddRange(GameClient.EggsInventory);
         CurrentPokemonSortingMode = PokemonSortingModes.Combat;
     }
     await Task.CompletedTask;
 }
Esempio n. 5
0
        /// <summary>
        ///     Updates inventory data
        /// </summary>
        public static async Task UpdateInventory()
        {
            // Get ALL the items
            var fullInventory = (await GetInventory()).InventoryDelta.InventoryItems;

            // Update items
            ItemsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.Item != null)
                                    .GroupBy(item => item.InventoryItemData.Item)
                                    .Select(item => item.First().InventoryItemData.Item), true);
            CatchItemsInventory.AddRange(
                fullInventory.Where(
                    item =>
                    item.InventoryItemData.Item != null && CatchItemIds.Contains(item.InventoryItemData.Item.ItemId))
                .GroupBy(item => item.InventoryItemData.Item)
                .Select(item => item.First().InventoryItemData.Item), true);

            // Update incbuators
            FreeIncubatorsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.EggIncubators != null)
                                             .SelectMany(item => item.InventoryItemData.EggIncubators.EggIncubator)
                                             .Where(item => item != null && item.PokemonId == 0), true);
            UsedIncubatorsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.EggIncubators != null)
                                             .SelectMany(item => item.InventoryItemData.EggIncubators.EggIncubator)
                                             .Where(item => item != null && item.PokemonId != 0), true);

            // Update Pokemons
            PokemonsInventory.AddRange(fullInventory.Select(item => item.InventoryItemData.PokemonData)
                                       .Where(item => item != null && item.PokemonId > 0), true);
            EggsInventory.AddRange(fullInventory.Select(item => item.InventoryItemData.PokemonData)
                                   .Where(item => item != null && item.IsEgg), true);

            // Update Pokedex
            PokedexInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.PokedexEntry != null)
                                      .Select(item => item.InventoryItemData.PokedexEntry), true);

            // Update Player stats
            PlayerStats =
                fullInventory.First(item => item.InventoryItemData.PlayerStats != null).InventoryItemData.PlayerStats;
        }
Esempio n. 6
0
        /// <summary>
        ///     Updates inventory data
        /// </summary>
        public static async Task UpdateInventory()
        {
            // Get ALL the items
            var fullInventory = (await GetInventory()).InventoryDelta.InventoryItems;
            // Update items
            var tmpItemsInventory = fullInventory.Where(item => item.InventoryItemData.Item != null).GroupBy(item => item.InventoryItemData.Item);

            ItemsInventory.Clear();
            foreach (var item in tmpItemsInventory)
            {
                ItemsInventory.Add(item.First().InventoryItemData.Item);
            }
            // Update incbuators
            //var tmpIncubatorsInventory = fullInventory.Where(item => item.InventoryItemData.EggIncubators != null).GroupBy(item => item.InventoryItemData.EggIncubators);
            //IncubatorsInventory.Clear();
            //foreach (var item in tmpIncubatorsInventory)
            //{
            //    IncubatorsInventory.Add(item.First().InventoryItemData.Item);
            //}
            // Update Pokemons
            var tmpPokemonsInventory = fullInventory.Where(item => item.InventoryItemData.PokemonData != null).Select(itemt => itemt.InventoryItemData.PokemonData);

            PokemonsInventory.Clear();
            EggsInventory.Clear();
            foreach (var pokemon in tmpPokemonsInventory)
            {
                if (pokemon.IsEgg)
                {
                    EggsInventory.Add(pokemon);
                }
                else
                {
                    PokemonsInventory.Add(pokemon);
                }
            }
        }