feat(inventory): BackfillCardCosmeticsAsync
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user