private async Task <IEnumerable <Item> > LoadItems(IEnumerable <DestinyItemComponent> itemComponents,
                                                           IDictionary <long, DestinyItemInstanceComponent> itemInstances)
        {
            var items = new List <Item>();

            foreach (var itemComponent in itemComponents)
            {
                var itemDef = await _manifest.LoadInventoryItem(itemComponent.ItemHash);

                var bucket = await _manifest.LoadBucket(itemDef.Inventory.BucketTypeHash);

                if (!ShouldInclude(bucket))
                {
                    continue;
                }

                string iconUrl = null;
                if (itemComponent.OverrideStyleItemHash != null && !_defaultOrnaments.Contains(itemComponent.OverrideStyleItemHash.Value))
                {
                    var overrideIcon = await _manifest.LoadInventoryItem(itemComponent.OverrideStyleItemHash.Value);

                    iconUrl = overrideIcon.DisplayProperties.Icon;
                }

                var watermark = GetWatermarkIcon(itemDef);

                itemInstances.TryGetValue(itemComponent.ItemInstanceId, out DestinyItemInstanceComponent instance);
                items.Add(new Item(_bungie.Value.BaseUrl, itemComponent, itemDef, bucket, instance, iconUrl, watermark));
            }

            return(items);
        }
示例#2
0
        public ManifestCache(IManifest manifest)
        {
            _manifest = manifest;

            _itemDefs           = new Cache <DestinyInventoryItemDefinition>(hash => _manifest.LoadInventoryItem(hash));
            _bucketDefs         = new Cache <DestinyInventoryBucketDefinition>(hash => _manifest.LoadBucket(hash));
            _statDefs           = new CollectionCache <DestinyStatDefinition>(hashes => _manifest.LoadStats(hashes));
            _socketCategoryDefs = new Cache <DestinySocketCategoryDefinition>(hash => _manifest.LoadSocketCategory(hash));
            _itemCategoryDefs   = new CollectionCache <DestinyItemCategoryDefinition>(hashes => _manifest.LoadItemCategories(hashes));
            _socketTypeDefs     = new Cache <DestinySocketTypeDefinition>(hash => _manifest.LoadSocketType(hash));
            _plugDefs           = new Cache <DestinyInventoryItemDefinition>(hash => _manifest.LoadPlug(hash));
        }
示例#3
0
        public async Task <IEnumerable <Item> > GetEngrams(IEnumerable <DestinyItemComponent> inventory,
                                                           IDictionary <long, DestinyItemInstanceComponent> itemInstances)
        {
            var engramItemComponents = inventory.Where(itemComponent => itemComponent.BucketHash == (uint)ItemSlot.SlotHashes.Engrams);
            var bucket = await _manifest.LoadBucket((uint)ItemSlot.SlotHashes.Engrams);

            var tasks = engramItemComponents.Select(async itemComponent =>
            {
                var itemDef = await _manifest.LoadInventoryItem(itemComponent.ItemHash);
                itemInstances.TryGetValue(itemComponent.ItemInstanceId, out DestinyItemInstanceComponent instance);

                return(new Item(_bungie.Value.BaseUrl, itemComponent, itemDef, bucket,
                                instance));
            });

            return(await Task.WhenAll(tasks));
        }
示例#4
0
        private async Task <IDictionary <ItemSlot.SlotHashes, int> > LoadAvailableSeasonPassItems(DestinyProgression seasonPassProgression,
                                                                                                  DestinyProgressionDefinition seasonPassProgressionDef)
        {
            if (seasonPassProgression.RewardItemStates == null)
            {
                return(new Dictionary <ItemSlot.SlotHashes, int>());
            }

            var seasonPassRewards = seasonPassProgression.RewardItemStates.ToArray();

            // Find all of the rewards that are available but unclaimed
            var availableRewards = seasonPassProgressionDef.RewardItems.Where((rewardItem, index) =>
            {
                var state = seasonPassRewards[index];
                if (state.HasFlag(DestinyProgressionRewardItemState.Invisible))
                {
                    return(false);
                }

                if (state.HasFlag(DestinyProgressionRewardItemState.Claimed))
                {
                    return(false);
                }

                return(state.HasFlag(DestinyProgressionRewardItemState.Earned | DestinyProgressionRewardItemState.ClaimAllowed));
            });

            var availableSlots = new Dictionary <ItemSlot.SlotHashes, int>();

            foreach (var reward in availableRewards)
            {
                var itemDef = await _manifest.LoadInventoryItem(reward.ItemHash);

                var slotHash = (ItemSlot.SlotHashes)itemDef.Inventory.BucketTypeHash;
                if (itemDef == null || !_slotHashes.Contains(slotHash))
                {
                    continue;
                }

                availableSlots.TryGetValue(slotHash, out var count);
                availableSlots[slotHash] = count + 1;
            }

            return(availableSlots);
        }
        public async Task <IEnumerable <DestinyInventoryItemDefinition> > GetModsFromInventory(BungieMembershipType type,
                                                                                               long accountId)
        {
            var accessToken = await _contextAccessor.HttpContext.GetTokenAsync("access_token");

            var mods = new List <DestinyInventoryItemDefinition>();

            var inventory = await _destiny2.GetProfile(accessToken, type, accountId,
                                                       DestinyComponentType.ProfileInventories);

            foreach (var item in inventory.ProfileInventory.Data.Items)
            {
                var itemDef = await _manifest.LoadInventoryItem(item.ItemHash);

                if (itemDef.ItemCategoryHashes.Contains(WeaponModsDamageCategoryHash))
                {
                    mods.Add(itemDef);
                }
            }

            return(mods);
        }