More features
This commit is contained in:
@@ -14,12 +14,29 @@ namespace SVSim.EmulatedEntrypoint.Controllers;
|
||||
|
||||
public class LoadController : SVSimController
|
||||
{
|
||||
// Per-format rank entries the wire expects (5 entries, in deck_format discriminator order).
|
||||
// Hard-coded until viewer rank-state is persisted (see audit §6 #1).
|
||||
private static readonly Format[] RankFormats =
|
||||
{
|
||||
Format.Rotation, Format.Unlimited, Format.MyRotation, Format.Avatar, Format.Crossover
|
||||
};
|
||||
|
||||
// Until ShadowverseCardSetEntry is seeded by CardImport, hard-code a stub so the client
|
||||
// doesn't crash on RotationCardSetList[1] / [Count-1] (LoadDetail.cs:184).
|
||||
private static readonly List<CardSetIdentifier> StubRotationSets = new()
|
||||
{
|
||||
new CardSetIdentifier { SetId = 10000 },
|
||||
new CardSetIdentifier { SetId = 10005 },
|
||||
new CardSetIdentifier { SetId = 10010 }
|
||||
};
|
||||
|
||||
private readonly IViewerRepository _viewerRepository;
|
||||
private readonly ICardRepository _cardRepository;
|
||||
private readonly ICollectionRepository _collectionRepository;
|
||||
private readonly IGlobalsRepository _globalsRepository;
|
||||
|
||||
public LoadController(IViewerRepository viewerRepository, ICardRepository cardRepository, ICollectionRepository collectionRepository, IGlobalsRepository globalsRepository)
|
||||
public LoadController(IViewerRepository viewerRepository, ICardRepository cardRepository,
|
||||
ICollectionRepository collectionRepository, IGlobalsRepository globalsRepository)
|
||||
{
|
||||
_viewerRepository = viewerRepository;
|
||||
_cardRepository = cardRepository;
|
||||
@@ -30,29 +47,30 @@ public class LoadController : SVSimController
|
||||
[HttpPost("index")]
|
||||
public async Task<ActionResult<IndexResponse>> Index(IndexRequest request)
|
||||
{
|
||||
Viewer? viewer = await _viewerRepository.GetViewerByShortUdid(long.Parse(User.Claims
|
||||
.FirstOrDefault(claim => claim.Type == ShadowverseClaimTypes.ShortUdidClaim).Value));
|
||||
|
||||
if (viewer == null)
|
||||
var shortUdidClaim = User.Claims.FirstOrDefault(c => c.Type == ShadowverseClaimTypes.ShortUdidClaim)?.Value;
|
||||
if (shortUdidClaim is null || !long.TryParse(shortUdidClaim, out long shortUdid))
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
Viewer? viewer = await _viewerRepository.GetViewerByShortUdid(shortUdid);
|
||||
if (viewer is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// Cards. Empty until CardImport lands (audit §3 — user_card_list is blocked).
|
||||
List<ShadowverseCardEntry> allCollectibleCards = await _cardRepository.GetAll(true);
|
||||
List<ShadowverseCardEntry> allBasicCards = await _cardRepository.GetAllBasic();
|
||||
List<OwnedCardEntry> ownedCards = viewer.Cards;
|
||||
List<OwnedCardEntry> allCardsAsOwned = allCollectibleCards.GroupJoin(ownedCards, card => card.Id,
|
||||
List<OwnedCardEntry> allCardsAsOwned = allCollectibleCards.GroupJoin(ownedCards,
|
||||
card => card.Id,
|
||||
ownedCard => ownedCard.Card.Id,
|
||||
(card, foundOwnedCards) =>
|
||||
(card, foundOwnedCards) => foundOwnedCards.DefaultIfEmpty().FirstOrDefault() ?? new OwnedCardEntry
|
||||
{
|
||||
OwnedCardEntry ownedCard = foundOwnedCards.DefaultIfEmpty().FirstOrDefault() ?? new OwnedCardEntry
|
||||
{
|
||||
Card = card,
|
||||
Count = 0,
|
||||
IsProtected = false
|
||||
};
|
||||
|
||||
return ownedCard;
|
||||
Card = card,
|
||||
Count = 0,
|
||||
IsProtected = false
|
||||
}).ToList();
|
||||
allCardsAsOwned = allCardsAsOwned.Union(allBasicCards.Select(bc => new OwnedCardEntry
|
||||
{
|
||||
@@ -60,14 +78,11 @@ public class LoadController : SVSimController
|
||||
Count = 3,
|
||||
IsProtected = true
|
||||
})).ToList();
|
||||
|
||||
List<LeaderSkinEntry> allLeaderSkins = await _collectionRepository.GetLeaderSkins();
|
||||
|
||||
Dictionary<string, ClassExp> classExp = new Dictionary<string, ClassExp>();
|
||||
List<LeaderSkinEntry> allLeaderSkins = await _collectionRepository.GetLeaderSkins();
|
||||
var classExpCurve = await _globalsRepository.GetClassExpCurve();
|
||||
|
||||
List<ClassExp> classExps = new List<ClassExp>();
|
||||
|
||||
List<ClassExp> classExps = new();
|
||||
int accumulateExp = 0;
|
||||
int? prevNecessaryExp = null;
|
||||
foreach (var entry in classExpCurve)
|
||||
@@ -75,7 +90,7 @@ public class LoadController : SVSimController
|
||||
accumulateExp += entry.NecessaryExp;
|
||||
classExps.Add(new ClassExp
|
||||
{
|
||||
Level = entry.Id, // You need to specify the level value based on your logic
|
||||
Level = entry.Id,
|
||||
NecessaryExp = entry.NecessaryExp,
|
||||
DiffExp = prevNecessaryExp.HasValue ? entry.NecessaryExp - prevNecessaryExp.Value : entry.NecessaryExp,
|
||||
AccumulateExp = accumulateExp
|
||||
@@ -83,37 +98,53 @@ public class LoadController : SVSimController
|
||||
prevNecessaryExp = entry.NecessaryExp;
|
||||
}
|
||||
|
||||
List<CardSetIdentifier> rotationSets = (await _cardRepository.GetCardSets(true))
|
||||
.Select(set => new CardSetIdentifier { SetId = set.Id })
|
||||
.ToList();
|
||||
if (rotationSets.Count < 2)
|
||||
{
|
||||
rotationSets = StubRotationSets;
|
||||
}
|
||||
|
||||
var deviceHeader = Request.Headers["DEVICE"].FirstOrDefault();
|
||||
int deviceType = int.TryParse(deviceHeader, out int parsed) ? parsed : 0;
|
||||
|
||||
return new IndexResponse
|
||||
{
|
||||
UserTutorial = new UserTutorial
|
||||
{
|
||||
TutorialStep = viewer.MissionData.TutorialState
|
||||
},
|
||||
UserInfo = new UserInfo(int.Parse(Request.Headers["DEVICE"].FirstOrDefault()), viewer),
|
||||
UserInfo = new UserInfo(deviceType, viewer),
|
||||
UserCurrency = new UserCurrency(viewer),
|
||||
UserItems = viewer.Items.Select(item => new UserItem(item)).ToList(),
|
||||
UserRotationDecks = new UserFormatDeckInfo
|
||||
{
|
||||
UserDecks = viewer.Decks.Where(deck => deck.Format == Format.Rotation).Select(deck => new UserDeck(deck)).ToList()
|
||||
UserDecks = viewer.Decks.Where(d => d.Format == Format.Rotation)
|
||||
.Select(d => new UserDeck(d)).ToList()
|
||||
},
|
||||
UserUnlimitedDecks = new UserFormatDeckInfo
|
||||
{
|
||||
UserDecks = viewer.Decks.Where(deck => deck.Format == Format.Unlimited).Select(deck => new UserDeck(deck)).ToList()
|
||||
UserDecks = viewer.Decks.Where(d => d.Format == Format.Unlimited)
|
||||
.Select(d => new UserDeck(d)).ToList()
|
||||
},
|
||||
UserMyRotationDecks = new UserFormatDeckInfo
|
||||
{
|
||||
UserDecks = viewer.Decks.Where(deck => deck.Format == Format.MyRotation).Select(deck => new UserDeck(deck)).ToList()
|
||||
UserDecks = viewer.Decks.Where(d => d.Format == Format.MyRotation)
|
||||
.Select(d => new UserDeck(d)).ToList()
|
||||
},
|
||||
UserCards = allCardsAsOwned.Select(card => new UserCard(card)).ToList(),
|
||||
UserClasses = viewer.Classes.Select(viewerClass => new UserClass(viewerClass)).ToList(),
|
||||
Sleeves = viewer.Sleeves.ToDictionary(sleeve => sleeve.Id.ToString(), sleeve => new SleeveIdentifier { SleeveId = sleeve.Id }),
|
||||
UserEmblems = viewer.Emblems.Select(emblem => new EmblemIdentifier { EmblemId = emblem.Id }).ToList(),
|
||||
UserDegrees = viewer.Degrees.Select(degree => new DegreeIdentifier { DegreeId = degree.Id }).ToList(),
|
||||
LeaderSkins = allLeaderSkins.ToDictionary(skin => skin.Id.ToString(), skin => new UserLeaderSkin(skin, viewer.LeaderSkins.Any(vs => vs.Id == skin.Id))),
|
||||
MyPageBackgrounds = viewer.MyPageBackgrounds.Select(mpbg => mpbg.Id).ToList(),
|
||||
UserClasses = viewer.Classes.Select(vc => new UserClass(vc)).ToList(),
|
||||
Sleeves = viewer.Sleeves.Select(s => new SleeveIdentifier { SleeveId = s.Id }).ToList(),
|
||||
UserEmblems = viewer.Emblems.Select(e => new EmblemIdentifier { EmblemId = e.Id }).ToList(),
|
||||
UserDegrees = viewer.Degrees.Select(d => new DegreeIdentifier { DegreeId = d.Id }).ToList(),
|
||||
LeaderSkins = allLeaderSkins
|
||||
.Select(skin => new UserLeaderSkin(skin, viewer.LeaderSkins.Any(vs => vs.Id == skin.Id)))
|
||||
.ToList(),
|
||||
MyPageBackgrounds = viewer.MyPageBackgrounds.Select(mpbg => mpbg.Id.ToString()).ToList(),
|
||||
LootBoxRegulations = new LootBoxRegulations(),
|
||||
GatheringInfo = new GatheringInfo(),
|
||||
IsBattlePassPeriod = false,
|
||||
IsBattlePassPeriod = 0,
|
||||
BattlePassLevelInfo = null,
|
||||
SpecialCrystalInfos = new List<SpecialCrystalInfo>(),
|
||||
AvatarRotationInfo = null,
|
||||
@@ -121,22 +152,35 @@ public class LoadController : SVSimController
|
||||
FeatureMaintenances = new List<FeatureMaintenance>(),
|
||||
PreReleaseInfo = null,
|
||||
SpotCards = new Dictionary<string, int>(),
|
||||
ReprintedCards = new Dictionary<string, long>(),
|
||||
ReprintedCards = new List<long>(),
|
||||
UnlimitedBanList = new Dictionary<string, int>(),
|
||||
LoadingTipCardExclusions = new List<long>(),
|
||||
MaintenanceCards = new List<CardIdentifier>(),
|
||||
MaintenanceCards = new List<long>(),
|
||||
RedEtherOverrides = new List<RedEtherOverride>(),
|
||||
DailyLoginBonus = new DailyLoginBonus(),
|
||||
UserRankedMatches = new List<UserRankedMatches>(),
|
||||
UserRankInfo = new Dictionary<string, UserRankInfo>(),
|
||||
UserRankInfo = RankFormats.Select(f => new UserRankInfo
|
||||
{
|
||||
DeckFormat = (int)f,
|
||||
Rank = 1,
|
||||
BattlePoints = 0,
|
||||
WinStreak = 0,
|
||||
IsPromotion = 0,
|
||||
IsMasterRank = 0,
|
||||
IsGrandMasterRank = 0,
|
||||
MasterPoints = 0
|
||||
}).ToList(),
|
||||
ArenaConfig = new ArenaConfig(),
|
||||
ArenaInfos = new List<ArenaInfo>(),
|
||||
RotationSets = (await _cardRepository.GetCardSets(true)).Select(set => new CardSetIdentifier { SetId = set.Id }).ToList(),
|
||||
RotationSets = rotationSets,
|
||||
UserConfig = new UserConfig(),
|
||||
OpenBattlefieldIds = (await _globalsRepository.GetBattlefields(true)).ToDictionary(bf => bf.Id.ToString(), bf => bf.Id),
|
||||
OpenBattlefieldIds = (await _globalsRepository.GetBattlefields(true))
|
||||
.Select(bf => bf.Id.ToString()).ToList(),
|
||||
DefaultSettings = new DefaultSettings(await _globalsRepository.GetGameConfiguration("default")),
|
||||
ClassExp = classExps.ToDictionary(kv => kv.Level.ToString(), kv => kv),
|
||||
RankInfo = (await _globalsRepository.GetRankInfo()).Select(ri => new RankInfo(ri)).ToDictionary(ri => ri.RankId.ToString(), ri => ri)
|
||||
ClassExp = classExps,
|
||||
RankInfo = (await _globalsRepository.GetRankInfo()).Select(ri => new RankInfo(ri)).ToList(),
|
||||
DeckFormat = 1,
|
||||
CardSetIdForResourceDlView = rotationSets.Last().SetId
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user