refactor(login-bonus): migrate LoginBonusService to IGameCalendarService
IsDue() collapses from the JST DayKey comparison boilerplate to a single _calendar.ResetReady(viewer.LastLoginBonusClaimedAt) call. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -11,21 +11,17 @@ public class LoginBonusService : ILoginBonusService
|
|||||||
{
|
{
|
||||||
private readonly IGameConfigService _config;
|
private readonly IGameConfigService _config;
|
||||||
private readonly TimeProvider _time;
|
private readonly TimeProvider _time;
|
||||||
|
private readonly IGameCalendarService _calendar;
|
||||||
|
|
||||||
public LoginBonusService(IGameConfigService config, TimeProvider time)
|
public LoginBonusService(IGameConfigService config, TimeProvider time, IGameCalendarService calendar)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_time = time;
|
_time = time;
|
||||||
|
_calendar = calendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsDue(Viewer viewer)
|
public bool IsDue(Viewer viewer) =>
|
||||||
{
|
_calendar.ResetReady(viewer.LastLoginBonusClaimedAt);
|
||||||
if (viewer.LastLoginBonusClaimedAt is null) return true;
|
|
||||||
var now = _time.GetUtcNow();
|
|
||||||
var lastClaim = new DateTimeOffset(
|
|
||||||
DateTime.SpecifyKind(viewer.LastLoginBonusClaimedAt.Value, DateTimeKind.Utc));
|
|
||||||
return JstPeriod.DayKey(lastClaim) != JstPeriod.DayKey(now);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<DailyLoginBonus?> GrantIfDueAsync(IInventoryTransaction tx, CancellationToken ct = default)
|
public async Task<DailyLoginBonus?> GrantIfDueAsync(IInventoryTransaction tx, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user