Example #1
0
        private async Task <IEnumerable <SocketCategory> > IterateOverSockets(DestinyItemSocketBlockDefinition socketDefs,
                                                                              IEnumerable <DestinyItemSocketState> itemSockets,
                                                                              Func <DestinyItemSocketEntryDefinition, DestinySocketTypeDefinition, DestinySocketCategoryDefinition, DestinyItemSocketState, Task <Socket> > func)
        {
            var socketArray   = itemSockets.ToArray();
            var socketEntries = socketDefs.SocketEntries.ToArray();

            var socketCategoryTasks = socketDefs.SocketCategories.Select(async category =>
            {
                var categoryDef = await _cache.GetSocketCategoryDef(category.SocketCategoryHash);

                // Technically this should use the DestinySocketTypeDefinition.PlugWhiteList
                // to match the categories of the perks in a socket. Unfortuantely that
                // doesn't work for weapons - the two columns of perks have the same
                // DestinySocketTypeDefinition and thus the code can't tell them apart. :(
                // Instead, assume that the sockets in the array of DestinyItemSocketState's
                // are in the same order as the sockets in the DestinyItemSocketBlockDefinition
                // and hope for the best.
                var categoryEntries = category.SocketIndexes.Select(index => (entry: socketEntries[index], socket: socketArray[index]))
                                      .Where(item => item.entry.DefaultVisible);

                var socketTasks = categoryEntries.Select(async item =>
                {
                    var socketType = await _cache.GetSocketTypeDef(item.entry.SocketTypeHash);
                    return(await func(item.entry, socketType, categoryDef, item.socket));
                });

                var sockets = await Task.WhenAll(socketTasks);
                return(new SocketCategory(categoryDef, sockets));
            });

            return(await Task.WhenAll(socketCategoryTasks));
        }
Example #2
0
        public async Task <IEnumerable <SocketCategory> > LoadSockets(DestinyItemSocketBlockDefinition socketDefs,
                                                                      IEnumerable <DestinyItemSocketState> itemSockets, IEnumerable <Mod> mods,
                                                                      IEnumerable <Mod> shaders)
        {
            return(await IterateOverSockets(socketDefs, itemSockets, async (socketEntry, socketType, categoryDef, socketState) =>
            {
                var perksTask = _perkFactory.LoadPerks(socketState);
                var socketTypeTask = _cache.GetSocketTypeDef(socketEntry.SocketTypeHash);

                await Task.WhenAll(perksTask, socketTypeTask);

                var socket = await CreateSocket(socketEntry, socketTypeTask.Result, categoryDef,
                                                mods, shaders, perksTask.Result);
                return socket;
            }));
        }
Example #3
0
 public Task <IEnumerable <SocketCategory> > LoadActiveSockets(DestinyItemSocketBlockDefinition socketDefs,
                                                               IEnumerable <DestinyItemSocketState> itemSockets)
 {
     return(IterateOverSockets(socketDefs, itemSockets, CreateSocket));
 }