feat(inventory): read-side methods on IInventoryService + tx
EffectiveBalance/OwnsCard/OwnsCosmetic on the tx are freeplay-aware against the live viewer. EffectiveOwnedCardsAsync/EffectiveCosmeticsAsync on the service mirror today's ViewerEntitlements projections (used by /load/index). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -237,9 +237,37 @@ internal sealed class InventoryTransaction : IInventoryTransaction
|
||||
_ => false,
|
||||
};
|
||||
|
||||
public long EffectiveBalance(SpendCurrency currency) => throw new NotImplementedException();
|
||||
public bool OwnsCard(long cardId) => throw new NotImplementedException();
|
||||
public bool OwnsCosmetic(CosmeticType type, int id) => throw new NotImplementedException();
|
||||
public long EffectiveBalance(SpendCurrency currency)
|
||||
{
|
||||
if (_freeplay.Enabled && currency != SpendCurrency.SpotPoint)
|
||||
return checked((long)_freeplay.CurrencyAmount);
|
||||
|
||||
return currency switch
|
||||
{
|
||||
SpendCurrency.Crystal => (long)Viewer.Currency.Crystals,
|
||||
SpendCurrency.Rupee => (long)Viewer.Currency.Rupees,
|
||||
SpendCurrency.RedEther => (long)Viewer.Currency.RedEther,
|
||||
SpendCurrency.SpotPoint => (long)Viewer.Currency.SpotPoints,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(currency)),
|
||||
};
|
||||
}
|
||||
|
||||
public bool OwnsCard(long cardId)
|
||||
=> _freeplay.Enabled || Viewer.Cards.Any(c => c.Card.Id == cardId && c.Count > 0);
|
||||
|
||||
public bool OwnsCosmetic(CosmeticType type, int id)
|
||||
{
|
||||
if (_freeplay.Enabled) return true;
|
||||
return type switch
|
||||
{
|
||||
CosmeticType.Sleeve => Viewer.Sleeves.Any(s => s.Id == id),
|
||||
CosmeticType.Emblem => Viewer.Emblems.Any(e => e.Id == id),
|
||||
CosmeticType.Degree => Viewer.Degrees.Any(d => d.Id == id),
|
||||
CosmeticType.Skin => Viewer.LeaderSkins.Any(s => s.Id == id),
|
||||
CosmeticType.MyPageBG => Viewer.MyPageBackgrounds.Any(m => m.Id == id),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<InventoryCommitResult> CommitAsync(CancellationToken ct = default)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user