Пример #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);
            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);
        }
Пример #2
0
 /// <summary>
 ///     Gets the incubator used by the given egg
 /// </summary>
 /// <param name="egg"></param>
 /// <returns></returns>
 public static EggIncubator GetIncubatorFromEgg(PokemonData egg)
 {
     return(IncubatorsInventory.FirstOrDefault(item => item.Id == null ? false : item.Id.Equals(egg.EggIncubatorId)));
 }