feat(CS): persist owner/phase/registrations across restarts via plugin config JSON
Some checks failed
.NET Core / build (push) Has been cancelled
Some checks failed
.NET Core / build (push) Has been cancelled
Castle Siege state was in-memory, so the castle owner (and thus the P4 hunting-map reward) reset on every server restart/redeploy. Now the context marks itself dirty on any persistable change (phase transition, registration, owner set); the plugin's periodic tick writes a snapshot into its own PlugInConfiguration CustomConfiguration (a JSON blob already stored in PostgreSQL - no schema migration) and restores it on startup. Battle state (defenses/switches/occupier) stays transient. +2 unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -123,6 +123,41 @@ public class CastleSiegeContextTest
|
||||
Assert.That(ctx.OccupierGuildName, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>Tests that restoring persisted state sets phase/owner/registrations without raising PhaseChanged.</summary>
|
||||
[Test]
|
||||
public void RestoreStateSetsStateWithoutFiringPhaseChanged()
|
||||
{
|
||||
var ctx = new CastleSiegeContext(Config());
|
||||
var phaseChangedFired = false;
|
||||
ctx.PhaseChanged += _ => phaseChangedFired = true;
|
||||
|
||||
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(phaseChangedFired, Is.False);
|
||||
Assert.That(ctx.ConsumeDirty(), Is.False, "restore must not mark the state dirty");
|
||||
}
|
||||
|
||||
/// <summary>Tests that state-changing operations flip the dirty flag, which ConsumeDirty reads-and-resets.</summary>
|
||||
[Test]
|
||||
public async Task DirtyFlagTracksPersistableChangesAsync()
|
||||
{
|
||||
var ctx = new CastleSiegeContext(Config());
|
||||
Assert.That(ctx.ConsumeDirty(), Is.False, "a fresh context has nothing to persist");
|
||||
|
||||
await ctx.ForceStartRegistrationAsync(T0); // phase transition -> dirty
|
||||
Assert.That(ctx.ConsumeDirty(), Is.True);
|
||||
Assert.That(ctx.ConsumeDirty(), Is.False, "ConsumeDirty resets the flag");
|
||||
|
||||
ctx.RegisterGuild("Attackers"); // registration -> dirty
|
||||
Assert.That(ctx.ConsumeDirty(), Is.True);
|
||||
|
||||
ctx.SetOwner("Attackers"); // owner change -> dirty
|
||||
Assert.That(ctx.ConsumeDirty(), Is.True);
|
||||
}
|
||||
|
||||
private static CastleSiegeConfiguration Config() => new()
|
||||
{
|
||||
RegistrationDuration = TimeSpan.FromMinutes(5),
|
||||
|
||||
Reference in New Issue
Block a user