feat(CS): run the siege on ONE designated server (CastleSiegeServerId)
Some checks failed
.NET Core / build (push) Has been cancelled

With multiple game servers each has its own map instances, so the siege ran
independently on all of them - a guild could win uncontested on an empty server's
Valley of Loren. Now the siege (tick/spawn/battle/registration) runs only on the
server whose Id == config.CastleSiegeServerId (AdminPanel-editable). Other servers
skip the siege and just mirror the shared castle owner from config so the hunting-map
gate + castle flag rewards still work everywhere. The Guardsman on non-siege servers
tells players which server to switch to.
This commit is contained in:
Acentech Dev
2026-07-15 19:10:48 +03:00
parent 3e465c016e
commit fbe75d55be
4 changed files with 53 additions and 0 deletions

View File

@@ -83,6 +83,22 @@ public sealed class CastleSiegeEventPlugIn : IPeriodicTaskPlugIn, ISupportCustom
public static CastleSiegeContext? TryGetContext(IGameContext gameContext)
=> Contexts.TryGetValue(gameContext, out var context) ? context : null;
/// <summary>
/// Returns whether the given game context is the designated Castle Siege server (the siege and registration
/// run only there). Non-server contexts (e.g. tests) or an uninitialized context count as the siege server.
/// </summary>
/// <param name="gameContext">The game context.</param>
public static bool IsCastleSiegeServer(IGameContext gameContext)
{
if (gameContext is not IGameServerContext serverContext
|| TryGetContext(gameContext) is not { } context)
{
return true;
}
return serverContext.Id == context.Configuration.CastleSiegeServerId;
}
/// <inheritdoc />
public object CreateDefaultConfig() => new CastleSiegeConfiguration();
@@ -110,6 +126,20 @@ public sealed class CastleSiegeEventPlugIn : IPeriodicTaskPlugIn, ISupportCustom
context.UpdateConfiguration(liveConfig);
}
// With multiple game servers each has its own map instances, so the siege must run on ONE designated
// server (CastleSiegeServerId). Other servers skip the siege entirely — they only mirror the shared
// castle owner from the config so the hunting-map gate + castle flag rewards still work everywhere.
if (!IsCastleSiegeServer(gameContext))
{
context.SyncOwnerFromConfig();
if (DateTime.UtcNow.Second % 15 == 0)
{
await this.BroadcastCastleFlagAsync(gameContext, context).ConfigureAwait(false);
}
return;
}
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.