refactor(CS): schedule + periods are config-owned, AdminPanel-editable
Some checks failed
.NET Core / build (push) Has been cancelled
Some checks failed
.NET Core / build (push) Has been cancelled
Move the auto-schedule from context-owned state to the plugin config (single source of truth): RegistrationOpenDays + RegistrationOpenTimes + Registration/Preparation/ SiegeDuration are all editable in the AdminPanel plugin config and take effect live (context refreshes its config reference each tick via UpdateConfiguration). /csschedule now writes the config. Removed the duplicate Persisted schedule fields. 12 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -88,12 +88,15 @@ public class CastleSiegeScheduleChatCommandPlugIn : IChatCommandPlugIn
|
||||
|
||||
private static string Describe(CastleSiegeContext context)
|
||||
{
|
||||
if (context.ScheduleTime is not { } time || context.ScheduleDays.Count == 0)
|
||||
var config = context.Configuration;
|
||||
if (config.RegistrationOpenTimes.Count == 0)
|
||||
{
|
||||
return "Castle Siege auto-schedule: (none). Set with /csschedule <days> <HH:mm UTC>.";
|
||||
}
|
||||
|
||||
return $"Castle Siege auto-schedule: {string.Join(",", context.ScheduleDays)} at {time:HH:mm} UTC.";
|
||||
var days = config.RegistrationOpenDays.Count > 0 ? string.Join(",", config.RegistrationOpenDays) : "every day";
|
||||
var times = string.Join(",", config.RegistrationOpenTimes.Select(t => t.ToString("HH\\:mm")));
|
||||
return $"Castle Siege auto-schedule: {days} at {times} UTC (reg {config.RegistrationDuration:g} -> prep {config.PreparationDuration:g} -> war {config.SiegeDuration:g}).";
|
||||
}
|
||||
|
||||
private static ValueTask ShowAsync(Player player, string text)
|
||||
|
||||
@@ -92,7 +92,7 @@ public sealed class CastleSiegeEventPlugIn : IPeriodicTaskPlugIn, ISupportCustom
|
||||
|
||||
// Restore state persisted before the last restart (owner/phase/registrations) BEFORE subscribing,
|
||||
// so restoring doesn't announce phases or re-spawn defenses.
|
||||
created.RestoreState(config.PersistedOwnerGuildName, config.PersistedPhase, config.PersistedPhaseStartedUtc, config.PersistedRegisteredGuilds, config.PersistedScheduleDays, config.PersistedScheduleTime);
|
||||
created.RestoreState(config.PersistedOwnerGuildName, config.PersistedPhase, config.PersistedPhaseStartedUtc, config.PersistedRegisteredGuilds);
|
||||
|
||||
// Announce phase changes to the whole server and, when the siege begins, warp registered members.
|
||||
created.PhaseChanged += phase => _ = OnPhaseChangedAsync(gc, created, phase);
|
||||
@@ -100,6 +100,12 @@ public sealed class CastleSiegeEventPlugIn : IPeriodicTaskPlugIn, ISupportCustom
|
||||
return created;
|
||||
});
|
||||
|
||||
// Point the context at the current (possibly AdminPanel-edited) config so schedule/durations are live.
|
||||
if (this.Configuration is { } liveConfig)
|
||||
{
|
||||
context.UpdateConfiguration(liveConfig);
|
||||
}
|
||||
|
||||
await context.TickAsync(DateTime.UtcNow).ConfigureAwait(false);
|
||||
|
||||
// During the siege, evaluate the Crown Switches (held by standing on them) and the throne capture every tick.
|
||||
@@ -177,8 +183,6 @@ public sealed class CastleSiegeEventPlugIn : IPeriodicTaskPlugIn, ISupportCustom
|
||||
config.PersistedPhase = context.Phase;
|
||||
config.PersistedPhaseStartedUtc = context.PhaseStartedUtc;
|
||||
config.PersistedRegisteredGuilds = context.RegisteredGuilds.ToList();
|
||||
config.PersistedScheduleDays = context.ScheduleDays.ToList();
|
||||
config.PersistedScheduleTime = context.ScheduleTime;
|
||||
|
||||
// Find our plugin-configuration row via the in-memory config graph to get its id.
|
||||
var pluginTypeId = typeof(CastleSiegeEventPlugIn).GUID;
|
||||
|
||||
Reference in New Issue
Block a user