using Application.Abstractions.Data; using Domain.Entities.Store.ValueObject; using Microsoft.EntityFrameworkCore; namespace Application.Helpers; /// /// 경험치 부스터(ExpBooster) 활성 시 획득 XP 를 2배로. 모든 XP 지급처가 공유하는 공용 헬퍼. /// (현 시점 적용처: 출석. 향후 글/댓글 보상엔진 도입 시 동일 헬퍼 경유.) /// public static class ExpBoostService { public const int Multiplier = 2; public static async Task IsActiveAsync(IAppDbContext db, int memberID, DateTime nowUtc, CancellationToken ct) { var boosters = await db.MemberItem.AsNoTracking() .Where(x => x.MemberID == memberID && x.Kind == ItemKind.ExpBooster && x.UsedAt != null && x.RevokedAt == null) .Select(x => new { x.UsedAt, x.DurationDays }) .ToListAsync(ct); return boosters.Any(b => b.UsedAt!.Value.AddDays(b.DurationDays) > nowUtc); } /// 부스터 활성 시 baseExp × 2, 아니면 baseExp. public static async Task ApplyAsync(IAppDbContext db, int memberID, int baseExp, DateTime nowUtc, CancellationToken ct) { if (baseExp <= 0) { return baseExp; } var active = await IsActiveAsync(db, memberID, nowUtc, ct); return active ? baseExp * Multiplier : baseExp; } }