feat(CS-P1): Castle Siege phase state machine (in-memory, time-injected) + tests
This commit is contained in:
44
src/GameLogic/CastleSiege/CastleSiegeConfiguration.cs
Normal file
44
src/GameLogic/CastleSiege/CastleSiegeConfiguration.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user