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

@@ -0,0 +1,101 @@
// <copyright file="CastleSiegeScheduleChatCommandPlugIn.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.GameLogic.PlugIns.ChatCommands;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using MUnique.OpenMU.GameLogic.CastleSiege;
using MUnique.OpenMU.GameLogic.PlugIns.PeriodicTasks;
using MUnique.OpenMU.GameLogic.Views;
using MUnique.OpenMU.Interfaces;
using MUnique.OpenMU.PlugIns;
/// <summary>
/// Sets the Castle Siege weekly auto-schedule. GM only. Times are UTC.
/// Usage: <c>/csschedule</c> (show) | <c>/csschedule Sunday 20:00</c> | <c>/csschedule Sunday,Wednesday 20:00</c> | <c>/csschedule clear</c>.
/// </summary>
[Guid("A1B2C3D4-0006-4E5F-9A0B-CA5710000006")]
[PlugIn]
[Display(Name = "Castle Siege Schedule", Description = "GM command: /csschedule [<days> <HH:mm UTC> | clear]")]
[ChatCommandHelp(Command, CharacterStatus.GameMaster)]
public class CastleSiegeScheduleChatCommandPlugIn : IChatCommandPlugIn
{
private const string Command = "/csschedule";
/// <inheritdoc />
public string Key => Command;
/// <inheritdoc/>
public CharacterStatus MinCharacterStatusRequirement => CharacterStatus.GameMaster;
/// <inheritdoc />
public async ValueTask HandleCommandAsync(Player player, string command)
{
var context = CastleSiegeEventPlugIn.TryGetContext(player.GameContext);
if (context is null)
{
await ShowAsync(player, "Castle Siege plugin not active.").ConfigureAwait(false);
return;
}
var parts = command.Split(' ', StringSplitOptions.RemoveEmptyEntries);
// "/csschedule" -> show current schedule.
if (parts.Length == 1)
{
await ShowAsync(player, Describe(context)).ConfigureAwait(false);
return;
}
// "/csschedule clear" -> disable auto-start.
if (parts.Length == 2 && string.Equals(parts[1], "clear", StringComparison.OrdinalIgnoreCase))
{
context.SetSchedule(Array.Empty<DayOfWeek>(), null);
await ShowAsync(player, "Castle Siege auto-schedule cleared (manual start only).").ConfigureAwait(false);
return;
}
if (parts.Length < 3)
{
await ShowAsync(player, "Usage: /csschedule <day[,day...]> <HH:mm UTC> | /csschedule clear").ConfigureAwait(false);
return;
}
var days = new List<DayOfWeek>();
foreach (var token in parts[1].Split(',', StringSplitOptions.RemoveEmptyEntries))
{
if (!Enum.TryParse<DayOfWeek>(token, true, out var day))
{
await ShowAsync(player, $"Unknown day '{token}'. Use e.g. Sunday, Monday, Tuesday...").ConfigureAwait(false);
return;
}
days.Add(day);
}
if (!TimeOnly.TryParse(parts[2], CultureInfo.InvariantCulture, out var time))
{
await ShowAsync(player, $"Invalid time '{parts[2]}'. Use 24h HH:mm (UTC).").ConfigureAwait(false);
return;
}
context.SetSchedule(days, time);
await ShowAsync(player, $"{Describe(context)} Server UTC now: {DateTime.UtcNow:ddd HH:mm}.").ConfigureAwait(false);
}
private static string Describe(CastleSiegeContext context)
{
if (context.ScheduleTime is not { } time || context.ScheduleDays.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.";
}
private static ValueTask ShowAsync(Player player, string text)
=> player.InvokeViewPlugInAsync<IShowMessagePlugIn>(p => p.ShowMessageAsync(text, MessageType.BlueNormal));
}

View File

@@ -75,7 +75,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);
created.RestoreState(config.PersistedOwnerGuildName, config.PersistedPhase, config.PersistedPhaseStartedUtc, config.PersistedRegisteredGuilds, config.PersistedScheduleDays, config.PersistedScheduleTime);
// Announce phase changes to the whole server and, when the siege begins, warp registered members.
created.PhaseChanged += phase => _ = OnPhaseChangedAsync(gc, created, phase);
@@ -150,6 +150,8 @@ 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;