feat(CS): weekly auto-schedule (day-of-week + UTC time), persisted, /csschedule GM cmd
Some checks failed
.NET Core / build (push) Has been cancelled

The siege can now auto-open registration on scheduled days/time instead of only
manual /csphase. Schedule is context-owned state (like owner), persisted across
restarts via the same config-JSON path. New GM command /csschedule sets/views/clears
it (e.g. /csschedule Sunday 20:00, UTC). +2 unit tests (11 total).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Acentech Dev
2026-07-15 12:47:29 +03:00
parent 05a10d495d
commit ac6700a356
5 changed files with 181 additions and 4 deletions

View File

@@ -131,15 +131,36 @@ public class CastleSiegeContextTest
var phaseChangedFired = false;
ctx.PhaseChanged += _ => phaseChangedFired = true;
ctx.RestoreState("Winners", CastleSiegePhase.Ownership, T0, new[] { "Winners", "Losers" });
ctx.RestoreState("Winners", CastleSiegePhase.Ownership, T0, new[] { "Winners", "Losers" }, new[] { DayOfWeek.Sunday }, new TimeOnly(20, 0));
Assert.That(ctx.Phase, Is.EqualTo(CastleSiegePhase.Ownership));
Assert.That(ctx.OwnerGuildName, Is.EqualTo("Winners"));
Assert.That(ctx.RegisteredGuilds, Is.EquivalentTo(new[] { "Winners", "Losers" }));
Assert.That(ctx.ScheduleDays, Is.EquivalentTo(new[] { DayOfWeek.Sunday }));
Assert.That(ctx.ScheduleTime, Is.EqualTo(new TimeOnly(20, 0)));
Assert.That(phaseChangedFired, Is.False);
Assert.That(ctx.ConsumeDirty(), Is.False, "restore must not mark the state dirty");
}
/// <summary>Tests that the weekly auto-schedule only opens registration on a matching day within the time window.</summary>
[Test]
public void ShouldOpenRegistrationMatchesDayAndTimeWindow()
{
var ctx = new CastleSiegeContext(Config());
ctx.SetSchedule(new[] { DayOfWeek.Sunday }, new TimeOnly(20, 0));
var sunday = new DateTime(2026, 1, 4, 20, 0, 2, DateTimeKind.Utc); // a Sunday, +2s into the window
var sundayLate = new DateTime(2026, 1, 4, 20, 0, 30, DateTimeKind.Utc); // past the 5s window
var monday = new DateTime(2026, 1, 5, 20, 0, 2, DateTimeKind.Utc); // wrong day
Assert.That(ctx.ShouldOpenRegistration(sunday), Is.True);
Assert.That(ctx.ShouldOpenRegistration(sundayLate), Is.False);
Assert.That(ctx.ShouldOpenRegistration(monday), Is.False);
ctx.SetSchedule(Array.Empty<DayOfWeek>(), null); // cleared -> never opens
Assert.That(ctx.ShouldOpenRegistration(sunday), Is.False);
}
/// <summary>Tests that state-changing operations flip the dirty flag, which ConsumeDirty reads-and-resets.</summary>
[Test]
public async Task DirtyFlagTracksPersistableChangesAsync()