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)); }
public async Task <IActionResult> Dashboard(BungieMembershipType type, long id) { _logger.LogInformation($"{type}/{id}/dashboard"); var accessToken = await _contextAccessor.HttpContext.GetTokenAsync("access_token"); // TODO: Add CharacterProgressions to DestinyProfileResponse var profile = await _destiny.GetProfile(accessToken, type, id, DestinyComponentType.ProfileInventories, DestinyComponentType.Characters, DestinyComponentType.CharacterInventories, DestinyComponentType.CharacterEquipment, DestinyComponentType.ItemInstances, DestinyComponentType.ProfileProgression, DestinyComponentType.CharacterProgressions); var equipped = profile.CharacterEquipment.Data.Values .SelectMany(items => items.Items); var inventory = profile.CharacterInventories.Data.Values .SelectMany(items => items.Items); var maxGear = await _maxPower.ComputeMaxPower(profile.Characters.Data, 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 recomendationInfo = maxGear.ToDictionary(item => item.Key, item => new CharacterRecomendationInfo { Items = maxGear[item.Key].Values, PowerLevel = _maxPower.ComputePower(maxGear[item.Key].Values), Progressions = profile.CharacterProgressions.Data[item.Key].Progressions }); var recommendations = await _recommendations.GetRecommendations(recomendationInfo); var viewModels = profile.Characters.Data.ToDictionary(item => item.Key, item => { var charMaxGear = maxGear[item.Key]; var lowestItems = _maxPower.FindLowestItems(charMaxGear.Values); var basePower = _maxPower.ComputePower(charMaxGear.Values); return(new CharacterViewModel { Type = type, AccountId = id, Id = item.Key, Items = charMaxGear.Values, LowestItems = lowestItems.ToList(), BasePower = basePower, BonusPower = profile.ProfileProgression.Data.SeasonalArtifact.PowerBonus, Recommendations = recommendations[item.Key], Engrams = _recommendations.GetEngramPowerLevels(basePower), EmblemPath = _bungie.Value.BaseUrl + item.Value.EmblemPath, EmblemBackgroundPath = _bungie.Value.BaseUrl + item.Value.EmblemBackgroundPath, ItemsPerRow = 1 }); }); foreach (var item in maxGear) { var lowestItems = _maxPower.FindLowestItems(item.Value.Values).ToList(); viewModels[item.Key].LowestItems = lowestItems; } await LoadClasses(profile.Characters.Data, viewModels); return(View(viewModels.Values)); }