diff --git a/src/GameLogic/CastleSiege/CastleSiegeConfiguration.cs b/src/GameLogic/CastleSiege/CastleSiegeConfiguration.cs
index 18952e4..f19fdf0 100644
--- a/src/GameLogic/CastleSiege/CastleSiegeConfiguration.cs
+++ b/src/GameLogic/CastleSiege/CastleSiegeConfiguration.cs
@@ -10,19 +10,29 @@ namespace MUnique.OpenMU.GameLogic.CastleSiege;
///
public class CastleSiegeConfiguration
{
+ // --- Schedule & period lengths (editable in the AdminPanel) ---
+ // A cycle runs: Ownership -> Registration -> Preparation -> Siege(war) -> Settlement -> Ownership.
+ // It auto-starts when the current day/time matches RegistrationOpenDays + RegistrationOpenTimes.
+
///
- /// Gets or sets the times of day at which a new cycle opens registration.
- /// Empty by default; admins start cycles manually via chat command in P1.
+ /// Gets or sets the days of week on which registration auto-opens (UTC). Empty = every day
+ /// (still requires a time in ); with no times set, auto-start is off.
+ ///
+ public IList RegistrationOpenDays { get; set; } = new List();
+
+ ///
+ /// Gets or sets the times of day (UTC) at which a new cycle opens registration.
+ /// Empty = no auto-start (admins start cycles manually via chat command).
///
public IList RegistrationOpenTimes { get; set; } = new List();
- /// Gets or sets how long the registration phase lasts.
+ /// Gets or sets how long the registration period lasts (guilds may register).
public TimeSpan RegistrationDuration { get; set; } = TimeSpan.FromMinutes(5);
- /// Gets or sets how long the preparation phase lasts.
+ /// Gets or sets how long the preparation period lasts (between registration close and the war).
public TimeSpan PreparationDuration { get; set; } = TimeSpan.FromMinutes(2);
- /// Gets or sets how long the siege phase lasts.
+ /// Gets or sets how long the war (siege) period lasts.
public TimeSpan SiegeDuration { get; set; } = TimeSpan.FromMinutes(10);
///
@@ -48,15 +58,10 @@ public class CastleSiegeConfiguration
/// Gets or sets the persisted registered guild names for the current cycle.
public IList PersistedRegisteredGuilds { get; set; } = new List();
- /// Gets or sets the persisted auto-schedule days of week (empty = manual start only).
- public IList PersistedScheduleDays { get; set; } = new List();
-
- /// Gets or sets the persisted auto-schedule UTC time of day, or null if unscheduled.
- public TimeOnly? PersistedScheduleTime { get; set; }
-
///
- /// Returns true if falls within a 5-second window of any configured
- /// registration-open time.
+ /// Returns true if (UTC) matches a scheduled registration-open day and falls
+ /// within a 5-second window of a configured open time. When is empty,
+ /// the day is not restricted (every day). When no times are configured, auto-start is disabled.
///
/// The current UTC time.
public bool IsRegistrationOpenTime(DateTime now)
@@ -66,6 +71,11 @@ public class CastleSiegeConfiguration
return false;
}
+ if (this.RegistrationOpenDays.Count > 0 && !this.RegistrationOpenDays.Contains(now.DayOfWeek))
+ {
+ return false;
+ }
+
var nowTime = TimeOnly.FromDateTime(now);
var earlier = nowTime.Add(TimeSpan.FromSeconds(-5));
return this.RegistrationOpenTimes.Any(p => p.IsBetween(earlier, nowTime));
diff --git a/src/GameLogic/CastleSiege/CastleSiegeContext.cs b/src/GameLogic/CastleSiege/CastleSiegeContext.cs
index 6846f54..240a6be 100644
--- a/src/GameLogic/CastleSiege/CastleSiegeContext.cs
+++ b/src/GameLogic/CastleSiege/CastleSiegeContext.cs
@@ -23,8 +23,6 @@ public class CastleSiegeContext
private string? _occupier;
private int _defensesRemaining;
private bool _dirty;
- private List _scheduleDays = new();
- private TimeOnly? _scheduleTime;
/// Initializes a new instance of the class.
/// The cycle timing configuration.
@@ -37,8 +35,13 @@ public class CastleSiegeContext
/// Raised after the phase changes. Argument is the new phase.
public event Action? PhaseChanged;
- /// Gets the configuration.
- public CastleSiegeConfiguration Configuration { get; }
+ /// Gets the configuration (durations + schedule). Refreshed each tick from the live plugin config
+ /// so AdminPanel edits take effect without a restart.
+ public CastleSiegeConfiguration Configuration { get; private set; }
+
+ /// Points the context at the current (possibly AdminPanel-edited) plugin configuration.
+ /// The live configuration.
+ public void UpdateConfiguration(CastleSiegeConfiguration configuration) => this.Configuration = configuration;
/// Gets the current phase.
public CastleSiegePhase Phase { get; private set; }
@@ -58,12 +61,6 @@ public class CastleSiegeContext
/// Gets the guild names registered for the current cycle.
public IReadOnlyList RegisteredGuilds => this._registeredGuilds;
- /// Gets the days of week the siege auto-opens registration (empty = manual start only).
- public IReadOnlyList ScheduleDays => this._scheduleDays;
-
- /// Gets the UTC time of day registration auto-opens on scheduled days, or null if unscheduled.
- public TimeOnly? ScheduleTime => this._scheduleTime;
-
/// Advances the state machine based on the current time.
/// The current UTC time.
public ValueTask TickAsync(DateTime now)
@@ -71,7 +68,7 @@ public class CastleSiegeContext
switch (this.Phase)
{
case CastleSiegePhase.Ownership:
- if (this.ShouldOpenRegistration(now))
+ if (this.Configuration.IsRegistrationOpenTime(now))
{
return this.ForceStartRegistrationAsync(now);
}
@@ -159,40 +156,22 @@ public class CastleSiegeContext
}
///
- /// Sets the weekly auto-schedule (days of week + UTC time) and marks the state dirty for persistence.
- /// Empty days disables auto-start (manual only).
+ /// Sets the weekly auto-schedule (days of week + UTC time) into the configuration and marks the state
+ /// dirty for persistence. Empty days disables auto-start (manual only). The configuration is the single
+ /// source of truth, so this is equivalent to editing the plugin config in the AdminPanel.
///
/// The days of week registration should auto-open.
/// The UTC time of day registration should auto-open, or null to disable.
public void SetSchedule(IEnumerable days, TimeOnly? time)
{
- this._scheduleDays = days.Distinct().OrderBy(d => d).ToList();
- this._scheduleTime = this._scheduleDays.Count > 0 ? time : null;
+ var orderedDays = days.Distinct().OrderBy(d => d).ToList();
+ this.Configuration.RegistrationOpenDays = orderedDays;
+ this.Configuration.RegistrationOpenTimes = orderedDays.Count > 0 && time is { } t
+ ? new List { t }
+ : new List();
this._dirty = true;
}
- ///
- /// Returns whether registration should auto-open now: a scheduled day matches and the current UTC time
- /// falls within a 5-second window at/after the scheduled time. Only meaningful in the ownership phase.
- ///
- /// The current UTC time.
- public bool ShouldOpenRegistration(DateTime nowUtc)
- {
- if (this._scheduleTime is not { } scheduleTime || this._scheduleDays.Count == 0)
- {
- return false;
- }
-
- if (!this._scheduleDays.Contains(nowUtc.DayOfWeek))
- {
- return false;
- }
-
- var nowTime = TimeOnly.FromDateTime(nowUtc);
- var windowEnd = scheduleTime.Add(TimeSpan.FromSeconds(5));
- return scheduleTime <= nowTime && nowTime <= windowEnd;
- }
-
///
/// Returns how much time is left in the running siege battle (the on-map countdown value), or
/// when the siege is not currently running.
@@ -228,9 +207,7 @@ public class CastleSiegeContext
/// The persisted phase.
/// When the persisted phase started (UTC), or null to keep the default.
/// The persisted registered guild names, or null.
- /// The persisted auto-schedule days of week, or null.
- /// The persisted auto-schedule UTC time, or null.
- public void RestoreState(string? owner, CastleSiegePhase phase, DateTime? phaseStartedUtc, IEnumerable? registeredGuilds, IEnumerable? scheduleDays, TimeOnly? scheduleTime)
+ public void RestoreState(string? owner, CastleSiegePhase phase, DateTime? phaseStartedUtc, IEnumerable? registeredGuilds)
{
this.OwnerGuildName = owner;
this.Phase = phase;
@@ -241,8 +218,6 @@ public class CastleSiegeContext
this._registeredGuilds.AddRange(registeredGuilds);
}
- this._scheduleDays = scheduleDays?.Distinct().OrderBy(d => d).ToList() ?? new List();
- this._scheduleTime = this._scheduleDays.Count > 0 ? scheduleTime : null;
this._dirty = false;
}
diff --git a/src/GameLogic/PlugIns/ChatCommands/CastleSiegeScheduleChatCommandPlugIn.cs b/src/GameLogic/PlugIns/ChatCommands/CastleSiegeScheduleChatCommandPlugIn.cs
index 04998e6..f7ffd13 100644
--- a/src/GameLogic/PlugIns/ChatCommands/CastleSiegeScheduleChatCommandPlugIn.cs
+++ b/src/GameLogic/PlugIns/ChatCommands/CastleSiegeScheduleChatCommandPlugIn.cs
@@ -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 .";
}
- 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)
diff --git a/src/GameLogic/PlugIns/PeriodicTasks/CastleSiegeEventPlugIn.cs b/src/GameLogic/PlugIns/PeriodicTasks/CastleSiegeEventPlugIn.cs
index 4973850..94a06cb 100644
--- a/src/GameLogic/PlugIns/PeriodicTasks/CastleSiegeEventPlugIn.cs
+++ b/src/GameLogic/PlugIns/PeriodicTasks/CastleSiegeEventPlugIn.cs
@@ -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;
diff --git a/tests/MUnique.OpenMU.Tests/CastleSiege/CastleSiegeContextTest.cs b/tests/MUnique.OpenMU.Tests/CastleSiege/CastleSiegeContextTest.cs
index 4836fce..f4f7a08 100644
--- a/tests/MUnique.OpenMU.Tests/CastleSiege/CastleSiegeContextTest.cs
+++ b/tests/MUnique.OpenMU.Tests/CastleSiege/CastleSiegeContextTest.cs
@@ -131,34 +131,34 @@ public class CastleSiegeContextTest
var phaseChangedFired = false;
ctx.PhaseChanged += _ => phaseChangedFired = true;
- ctx.RestoreState("Winners", CastleSiegePhase.Ownership, T0, new[] { "Winners", "Losers" }, new[] { DayOfWeek.Sunday }, new TimeOnly(20, 0));
+ ctx.RestoreState("Winners", CastleSiegePhase.Ownership, T0, new[] { "Winners", "Losers" });
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");
}
- /// Tests that the weekly auto-schedule only opens registration on a matching day within the time window.
+ /// Tests that the weekly auto-schedule (stored in config) only fires on a matching day/time window.
[Test]
- public void ShouldOpenRegistrationMatchesDayAndTimeWindow()
+ public void ScheduleFiresOnMatchingDayAndTimeWindow()
{
var ctx = new CastleSiegeContext(Config());
ctx.SetSchedule(new[] { DayOfWeek.Sunday }, new TimeOnly(20, 0));
+ var config = ctx.Configuration;
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);
+ Assert.That(config.IsRegistrationOpenTime(sunday), Is.True);
+ Assert.That(config.IsRegistrationOpenTime(sundayLate), Is.False);
+ Assert.That(config.IsRegistrationOpenTime(monday), Is.False);
+ Assert.That(ctx.ConsumeDirty(), Is.True, "SetSchedule marks the state dirty");
ctx.SetSchedule(Array.Empty(), null); // cleared -> never opens
- Assert.That(ctx.ShouldOpenRegistration(sunday), Is.False);
+ Assert.That(config.IsRegistrationOpenTime(sunday), Is.False);
}
/// Tests that state-changing operations flip the dirty flag, which ConsumeDirty reads-and-resets.