Exemplo n.º 1
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);

            // 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 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);
        }
Exemplo n.º 2
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;
        }