feat(CS-P1): Castle Siege phase state machine (in-memory, time-injected) + tests

This commit is contained in:
Acentech Dev
2026-07-14 22:40:24 +03:00
parent c2b495c754
commit 73de807bef
4 changed files with 278 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
// <copyright file="CastleSiegeConfiguration.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.GameLogic.CastleSiege;
/// <summary>
/// Configuration for the Castle Siege cycle timings.
/// Rides on the plugin custom-configuration system (no dedicated database table in P1).
/// </summary>
public class CastleSiegeConfiguration
{
/// <summary>
/// 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.
/// </summary>
public IList<TimeOnly> RegistrationOpenTimes { get; set; } = new List<TimeOnly>();
/// <summary>Gets or sets how long the registration phase lasts.</summary>
public TimeSpan RegistrationDuration { get; set; } = TimeSpan.FromMinutes(5);
/// <summary>Gets or sets how long the preparation phase lasts.</summary>
public TimeSpan PreparationDuration { get; set; } = TimeSpan.FromMinutes(2);
/// <summary>Gets or sets how long the siege phase lasts.</summary>
public TimeSpan SiegeDuration { get; set; } = TimeSpan.FromMinutes(10);
/// <summary>
/// Returns true if <paramref name="now"/> falls within a 5-second window of any configured
/// registration-open time.
/// </summary>
/// <param name="now">The current UTC time.</param>
public bool IsRegistrationOpenTime(DateTime now)
{
if (this.RegistrationOpenTimes.Count == 0)
{
return false;
}
var nowTime = TimeOnly.FromDateTime(now);
var earlier = nowTime.Add(TimeSpan.FromSeconds(-5));
return this.RegistrationOpenTimes.Any(p => p.IsBetween(earlier, nowTime));
}
}