From e41ceff0be9c017b3ecd25175fa61108dd786b33 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Thu, 28 May 2026 23:20:33 -0400 Subject: [PATCH] refactor(pack): clarify gacha-point leader detection and drop unused grants injection --- .../Services/GachaPointService.cs | 73 +++++++++++-------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/SVSim.EmulatedEntrypoint/Services/GachaPointService.cs b/SVSim.EmulatedEntrypoint/Services/GachaPointService.cs index 2697dca..c273b93 100644 --- a/SVSim.EmulatedEntrypoint/Services/GachaPointService.cs +++ b/SVSim.EmulatedEntrypoint/Services/GachaPointService.cs @@ -2,7 +2,6 @@ using Microsoft.EntityFrameworkCore; using SVSim.Database; using SVSim.Database.Enums; using SVSim.Database.Models; -using SVSim.Database.Services; using SVSim.EmulatedEntrypoint.Models.Dtos; namespace SVSim.EmulatedEntrypoint.Services; @@ -11,13 +10,11 @@ public sealed class GachaPointService : IGachaPointService { private readonly SVSimDbContext _db; private readonly ICardPoolProvider _pools; - private readonly RewardGrantService _grants; - public GachaPointService(SVSimDbContext db, ICardPoolProvider pools, RewardGrantService grants) + public GachaPointService(SVSimDbContext db, ICardPoolProvider pools) { _db = db; _pools = pools; - _grants = grants; } public async Task> GetRewardsAsync(int packId, long viewerId) @@ -27,6 +24,7 @@ public sealed class GachaPointService : IGachaPointService var pool = _pools.GetPool(pack); + // EF Core 8 has no ToHashSetAsync on IQueryable — materialize via ToListAsync then hash. var receivedCardIds = (await _db.Viewers .Where(v => v.Id == viewerId) .SelectMany(v => v.GachaPointReceived) @@ -53,6 +51,7 @@ public sealed class GachaPointService : IGachaPointService foreach (var card in pool .Where(c => c.Rarity == Rarity.Legendary && !c.IsFoil) + // Neutral cards have Class=null; client wire-encodes them as class_id="0". .OrderBy(c => c.Class?.Id ?? 0).ThenBy(c => c.Id)) { if (!cosmeticLookup.TryGetValue(card.Id, out var cosmetics)) continue; @@ -63,7 +62,35 @@ public sealed class GachaPointService : IGachaPointService var classId = (card.Class?.Id ?? 0).ToString(); var isReceived = receivedCardIds.Contains(card.Id); - if (skin is null) + if (IsLeaderCard(skin)) + { + // Leader card — 3 entries in capture order: Sleeve/Card-cosmetic (type 6), + // Skin (type 10), Emblem (type 7). The reward_type=6 entry's detail id is the + // card_id itself, mirroring the prod capture exactly (no Sleeve cosmetic row + // is required — synthesizing from card.Id is robust to missing rows). + leader.Add(new GachaPointRewardDto + { + ClassId = classId, CardId = card.Id, IsReceived = isReceived, + RewardList = + { + new GachaPointRewardDetailEntry + { + RewardType = (int)UserGoodsType.Sleeve, RewardDetailId = card.Id, RewardNumber = 1, + }, + new GachaPointRewardDetailEntry + { + RewardType = (int)UserGoodsType.Skin, + RewardDetailId = skin!.CosmeticId, RewardNumber = 1, + }, + new GachaPointRewardDetailEntry + { + RewardType = (int)UserGoodsType.Emblem, + RewardDetailId = emblem.CosmeticId, RewardNumber = 1, + }, + }, + }); + } + else { standard.Add(new GachaPointRewardDto { @@ -79,33 +106,6 @@ public sealed class GachaPointService : IGachaPointService }, }); } - else - { - // Leader card — 3 entries in capture order: Sleeve/Card-cosmetic (type 6), - // Skin (type 10), Emblem (type 7). The reward_type=6 entry's detail id is the - // card_id itself, mirroring the prod capture exactly. - leader.Add(new GachaPointRewardDto - { - ClassId = classId, CardId = card.Id, IsReceived = isReceived, - RewardList = - { - new GachaPointRewardDetailEntry - { - RewardType = (int)UserGoodsType.Sleeve, RewardDetailId = card.Id, RewardNumber = 1, - }, - new GachaPointRewardDetailEntry - { - RewardType = (int)UserGoodsType.Skin, - RewardDetailId = skin.CosmeticId, RewardNumber = 1, - }, - new GachaPointRewardDetailEntry - { - RewardType = (int)UserGoodsType.Emblem, - RewardDetailId = emblem.CosmeticId, RewardNumber = 1, - }, - }, - }); - } } // Standard first, then leader — matches the prod capture order for pack 10008. @@ -113,6 +113,15 @@ public sealed class GachaPointService : IGachaPointService return standard; } + /// + /// Leader cards are identified purely by the data shape: a (non-foil legendary) card with + /// a cosmetic-reward row is a leader card. There is no + /// is_leader flag, no card-id pattern, no other signal — the presence of the Skin row is + /// the entire heuristic. Callers must have already filtered to Rarity.Legendary && + /// !IsFoil before invoking this. + /// + private static bool IsLeaderCard(CardCosmeticReward? skin) => skin is not null; + public void Accrue(Viewer viewer, PackConfigEntry pack, PackChildGachaEntry child, int packNumber) => throw new NotImplementedException();