feat(inventory): BackfillCardCosmeticsAsync

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-31 16:01:15 -04:00
parent 46d8239d5a
commit 1ba3f57709
2 changed files with 102 additions and 2 deletions

View File

@@ -200,8 +200,42 @@ internal sealed class InventoryTransaction : IInventoryTransaction
}
}
public Task<int> BackfillCardCosmeticsAsync(CancellationToken ct = default)
=> throw new NotImplementedException();
public async Task<int> BackfillCardCosmeticsAsync(CancellationToken ct = default)
{
ThrowIfCommitted();
var lookupIds = Viewer.Cards
.Select(c => c.Card.IsFoil ? c.Card.Id - 1 : c.Card.Id)
.Distinct()
.ToList();
var cascade = await _db.CardCosmeticRewards
.Where(r => lookupIds.Contains(r.CardId))
.ToListAsync(ct);
int granted = 0;
foreach (var reward in cascade)
{
if (AlreadyOwnsCosmetic(reward.Type, reward.CosmeticId)) continue;
if (TryAddCascadeCosmetic(reward, reward.CardId))
{
granted++;
_ops.Add(new GrantOp((UserGoodsType)(int)reward.Type, reward.CosmeticId, 1, 1, true));
}
}
return granted;
}
private bool AlreadyOwnsCosmetic(CosmeticType type, long id) => type switch
{
CosmeticType.Sleeve => Viewer.Sleeves.Any(s => s.Id == id),
CosmeticType.Emblem => Viewer.Emblems.Any(e => e.Id == id),
CosmeticType.Skin => Viewer.LeaderSkins.Any(s => s.Id == id),
CosmeticType.Degree => Viewer.Degrees.Any(d => d.Id == id),
CosmeticType.MyPageBG => Viewer.MyPageBackgrounds.Any(b => b.Id == id),
_ => false,
};
public long EffectiveBalance(SpendCurrency currency) => throw new NotImplementedException();
public bool OwnsCard(long cardId) => throw new NotImplementedException();