コード例 #1
0
        public async Task <IActionResult> Index(int type, long id)
        {
            var membershipType = (BungieMembershipType)type;

            _logger.LogInformation($"{membershipType}/{id}");

            var accessToken = _contextAccessor.HttpContext.GetTokenAsync("access_token");

            var model = new CharactersViewModel(membershipType, id);

            var profileResponse = await _destiny2.GetProfile(await accessToken, membershipType, id, DestinyComponentType.Characters);

            if (profileResponse == null)
            {
                var url = Url.RouteUrl("AccountIndex");
                return(Redirect(url));
            }

            var classDefTasks = profileResponse.Characters.Data.Select(item => _manifest.LoadClass(item.Value.ClassHash));

            var classDefs = await Task.WhenAll(classDefTasks);

            var characters = profileResponse.Characters.Data.Zip(classDefs,
                                                                 (item, classDef) => (id: item.Key, characters: item.Value, classDef: classDef));

            foreach (var(characterId, character, classDef) in characters)
            {
                model.Characters.Add(new Character(characterId, character, classDef, _bungie.BaseUrl));
            }

            return(View(model));
        }
コード例 #2
0
        private async Task <(IEnumerable <Mod> mods, IEnumerable <Mod> shaders)> LoadAllMods(string accessToken, BungieMembershipType type,
                                                                                             long accountId)
        {
            var inventory = await _destiny2.GetProfile(accessToken, type, accountId,
                                                       DestinyComponentType.ProfileInventories);

            return(await _perkFactory.LoadAllMods(inventory.ProfileInventory.Data.Items));
        }
コード例 #3
0
        public async Task <IActionResult> Details(int type, long id)
        {
            _affinitization.SetCookies(Request.Cookies);

            var membershipType = (BungieMembershipType)type;

            _logger.LogInformation($"{membershipType}/{id}");

            var accessToken = await _contextAccessor.HttpContext.GetTokenAsync("access_token");

            var model = new AccountDetailsViewModel(membershipType, id);

            var profileResponse = await _destiny.GetProfile(accessToken, membershipType, id,
                                                            DestinyComponentType.Characters, DestinyComponentType.CharacterProgressions);

            if (profileResponse == null)
            {
                var url = Url.RouteUrl("AccountIndex");
                return(Redirect(url));
            }

            foreach (var item in profileResponse.Characters.Data)
            {
                var classDef = await _manifest.LoadClass(item.Value.ClassHash);

                model.Characters.Add(new Character(item.Key, item.Value, classDef, _bungie.Value.BaseUrl));

                if (model.SeasonPassInfo == null)
                {
                    var characterProgression = await _destiny.GetCharacterInfo(accessToken,
                                                                               membershipType, id, item.Key, DestinyComponentType.CharacterProgressions);

                    model.SeasonPassInfo = await _recommendations.GetSeasonPassInfo(characterProgression.Progressions.Data.Progressions);
                }
            }

            foreach (var cookie in _affinitization.GetCookies())
            {
                Response.Cookies.Append(cookie.name, cookie.value);
            }

            return(View(model));
        }
コード例 #4
0
        public async Task <ILookup <ChargedWithLightType?, ModData> > LoadMods(BungieMembershipType type, long accountId)
        {
            var accessToken = await _contextAccessor.HttpContext.GetTokenAsync("access_token");

            var armorModsTask = LoadArmorMods();
            var profileTask   = _destiny.GetProfile(accessToken, type, accountId,
                                                    DestinyComponentType.Collectibles);

            await Task.WhenAll(armorModsTask, profileTask);

            var modData = await LoadMods(armorModsTask.Result,
                                         profileTask.Result.ProfileCollectibles.Data.Collectibles);

            return(modData.ToLookup(mod => mod.ChargedWithLightType));
        }
コード例 #5
0
        public async Task <DestinyProfileResponse> GetProfile()
        {
            if (currentProfile != null)
            {
                return(currentProfile);
            }

            var account = await GetAccount();

            var profile = await Util.RequestAndRetry(() => destinyApi.GetProfile(oauthManager.currentToken.AccessToken, BungieMembershipType.TigerSteam, account.MembershipId));

            currentProfile = profile;

            return(profile);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public async Task <IActionResult> Details(int type, long id, long characterId)
        {
            _affinitization.SetCookies(Request.Cookies);

            var membershipType = (BungieMembershipType)type;

            _logger.LogInformation($"{membershipType}/{id}/{characterId}");

            var accessToken = await _contextAccessor.HttpContext.GetTokenAsync("access_token");

            var profileTask = _destiny.GetProfile(accessToken, membershipType, id,
                                                  DestinyComponentType.ProfileInventories, DestinyComponentType.Characters,
                                                  DestinyComponentType.CharacterInventories, DestinyComponentType.CharacterEquipment,
                                                  DestinyComponentType.ItemInstances, DestinyComponentType.ProfileProgression);
            var characterProgressionsTask = _destiny.GetCharacterInfo(accessToken, membershipType, id, characterId,
                                                                      DestinyComponentType.Characters, DestinyComponentType.CharacterProgressions);

            await Task.WhenAll(profileTask, characterProgressionsTask);

            var profile = profileTask.Result;
            var characterProgressions = characterProgressionsTask.Result;

            if (!profile.Characters.Data.TryGetValue(characterId, out var character))
            {
                _logger.LogWarning($"Could not find character {characterId}");
                return(null);
            }

            var maxGear = await _maxPower.ComputeMaxPower(character,
                                                          profile.CharacterEquipment.Data.Values,
                                                          profile.CharacterInventories.Data.Values,
                                                          profile.ProfileInventory.Data,
                                                          profile.ItemComponents.Instances.Data);

            if (maxGear == null)
            {
                _logger.LogWarning("Couldn't find max gear. Redirecting to Account Index");
                var url = Url.RouteUrl("AccountIndex");
                return(Redirect(url));
            }

            var inventory = Enumerable.Empty <DestinyItemComponent>();

            if (profile.CharacterInventories.Data.TryGetValue(characterId, out var inventoryComponent))
            {
                inventory = inventoryComponent.Items;
            }
            var engrams = await _itemService.GetEngrams(inventory, profile.ItemComponents.Instances.Data);

            var lowestItems = _maxPower.FindLowestItems(maxGear.Values).ToList();

            var classTask = _manifest.LoadClass(character.ClassHash);

            var maxPower            = _maxPower.ComputePower(maxGear.Values);
            var recommendationsTask = _recommendations.GetRecommendations(new CharacterRecomendationInfo
            {
                Items        = maxGear.Values,
                PowerLevel   = maxPower,
                Progressions = characterProgressions.Progressions.Data.Progressions,
                Engrams      = engrams
            });

            await Task.WhenAll(classTask, recommendationsTask);

            var emblemPath           = string.Empty;
            var emblemBackgroundPath = string.Empty;

            if (character.EmblemBackgroundPath != null)
            {
                emblemPath           = _bungie.Value.BaseUrl + character.EmblemPath;
                emblemBackgroundPath = _bungie.Value.BaseUrl + character.EmblemBackgroundPath;
            }

            var model = new CharacterViewModel()
            {
                Type                 = membershipType,
                AccountId            = id,
                Id                   = characterId,
                Items                = maxGear.Values,
                LowestItems          = lowestItems,
                BasePower            = maxPower,
                BonusPower           = profile.ProfileProgression.Data.SeasonalArtifact.PowerBonus,
                EmblemPath           = emblemPath,
                EmblemBackgroundPath = emblemBackgroundPath,
                Recommendations      = recommendationsTask.Result,
                Engrams              = _recommendations.GetEngramPowerLevels(maxPower),
                ClassName            = classTask.Result.DisplayProperties.Name
            };

            foreach (var cookie in _affinitization.GetCookies())
            {
                Response.Cookies.Append(cookie.name, cookie.value);
            }

            return(View(model));
        }