using Microsoft.AspNetCore.Mvc; using SVSim.Database.Enums; using SVSim.Database.Models; using SVSim.Database.Repositories.Card; using SVSim.Database.Repositories.Collectibles; using SVSim.Database.Repositories.Globals; using SVSim.Database.Repositories.Viewer; using SVSim.EmulatedEntrypoint.Constants; using SVSim.EmulatedEntrypoint.Models.Dtos; using SVSim.EmulatedEntrypoint.Models.Dtos.Requests; using SVSim.EmulatedEntrypoint.Models.Dtos.Responses; namespace SVSim.EmulatedEntrypoint.Controllers; public class LoadController : SVSimController { 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) { _viewerRepository = viewerRepository; _cardRepository = cardRepository; _collectionRepository = collectionRepository; _globalsRepository = globalsRepository; } [HttpPost("index")] public async Task> Index(IndexRequest request) { Viewer? viewer = await _viewerRepository.GetViewerByShortUdid(long.Parse(User.Claims .FirstOrDefault(claim => claim.Type == ShadowverseClaimTypes.ShortUdidClaim).Value)); if (viewer == null) { return NotFound(); } List allCollectibleCards = await _cardRepository.GetAll(true); List allBasicCards = await _cardRepository.GetAllBasic(); List ownedCards = viewer.Cards; List allCardsAsOwned = allCollectibleCards.GroupJoin(ownedCards, card => card.Id, ownedCard => ownedCard.Card.Id, (card, foundOwnedCards) => { OwnedCardEntry ownedCard = foundOwnedCards.DefaultIfEmpty().FirstOrDefault() ?? new OwnedCardEntry { Card = card, Count = 0, IsProtected = false }; return ownedCard; }).ToList(); allCardsAsOwned = allCardsAsOwned.Union(allBasicCards.Select(bc => new OwnedCardEntry { Card = bc, Count = 3, IsProtected = true })).ToList(); List allLeaderSkins = await _collectionRepository.GetLeaderSkins(); Dictionary classExp = new Dictionary(); var classExpCurve = await _globalsRepository.GetClassExpCurve(); List classExps = new List(); int accumulateExp = 0; int? prevNecessaryExp = null; foreach (var entry in classExpCurve) { accumulateExp += entry.NecessaryExp; classExps.Add(new ClassExp { Level = entry.Id, // You need to specify the level value based on your logic NecessaryExp = entry.NecessaryExp, DiffExp = prevNecessaryExp.HasValue ? entry.NecessaryExp - prevNecessaryExp.Value : entry.NecessaryExp, AccumulateExp = accumulateExp }); prevNecessaryExp = entry.NecessaryExp; } return new IndexResponse { UserTutorial = new UserTutorial { TutorialStep = viewer.MissionData.TutorialState }, UserInfo = new UserInfo(int.Parse(Request.Headers["DEVICE"].FirstOrDefault()), 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() }, UserUnlimitedDecks = new UserFormatDeckInfo { UserDecks = viewer.Decks.Where(deck => deck.Format == Format.Unlimited).Select(deck => new UserDeck(deck)).ToList() }, UserMyRotationDecks = new UserFormatDeckInfo { UserDecks = viewer.Decks.Where(deck => deck.Format == Format.MyRotation).Select(deck => new UserDeck(deck)).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(), LootBoxRegulations = new LootBoxRegulations(), GatheringInfo = new GatheringInfo(), IsBattlePassPeriod = false, BattlePassLevelInfo = null, SpecialCrystalInfos = new List(), AvatarRotationInfo = null, MyRotationInfo = null, FeatureMaintenances = new List(), PreReleaseInfo = null, SpotCards = new Dictionary(), ReprintedCards = new Dictionary(), UnlimitedBanList = new Dictionary(), LoadingTipCardExclusions = new List(), MaintenanceCards = new List(), RedEtherOverrides = new List(), DailyLoginBonus = new DailyLoginBonus(), UserRankedMatches = new List(), UserRankInfo = new Dictionary(), ArenaConfig = new ArenaConfig(), ArenaInfos = new List(), RotationSets = (await _cardRepository.GetCardSets(true)).Select(set => new CardSetIdentifier { SetId = set.Id }).ToList(), UserConfig = new UserConfig(), OpenBattlefieldIds = (await _globalsRepository.GetBattlefields(true)).ToDictionary(bf => bf.Id.ToString(), bf => bf.Id), 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) }; } }