fix(abilities): pause/resume ordering and continuation correctness
Issue 1 — ActionGroup AND continuation ordering: The old code prepended `all` (preceding AND-group actions) into ContinuationActionsJson, so resume ran [chosen, preceding, outer] instead of the correct [preceding, chosen, outer]. Fix: add PrecedingActionsJson to PendingActionGroupPick; AND-case stores preceding there (prepending to any inner-group preceding); ResumeActionGroupPick reads it and uses preceding.Concat(chosen).Concat(continuation) for final execution. Nested remaining-group pauses also accumulate preceding correctly. Issue 2 — Effect-level pause terminal contract: Documented as a design constraint: pausing effects (CloneSpiritAsToken TargetTile, ChannelCardFromZone TargetTile/Choice) must be last in their action's Effects list. Remaining effects / remaining targets are silently dropped on pause. No functional change; constraint is now explicit in code. Issue 3 — StackDeck pause loses continuation: PendingRevealChoicePick already had ContinuationActionsJson/RangeJson/ ForceDurationJson fields but StackDeckEffect never populated them and ResumeRevealChoicePick never executed them. Both are now fixed: pause stores ctx.ContinuationActions + ctx.ActivationRange + duration; resume runs ExecuteActions on the stored continuation after ordering the deck. Issue 4 — ResumeTargetPick ActionIndex=0 contract: Added a clear CONTRACT comment: the paused action replays at index 0, so the client must submit targets with ActionIndex=0 in its response. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -920,15 +920,21 @@ public static class AbilitySystem
|
|||||||
forceDuration, continuationActions);
|
forceDuration, continuationActions);
|
||||||
if (childActions is null)
|
if (childActions is null)
|
||||||
{
|
{
|
||||||
// Child emitted PendingActionGroupPick. Patch it to include:
|
// Child emitted PendingActionGroupPick. Patch it:
|
||||||
// - `all` (already-flattened preceding actions) prepended to continuation
|
// - Store preceding actions (all actions resolved so far in this AND group)
|
||||||
// - remaining sibling groups stored so ResumeActionGroupPick can process them
|
// so resume can execute them BEFORE the chosen branch.
|
||||||
|
// - Store remaining sibling groups.
|
||||||
|
// - Leave ContinuationActionsJson untouched (it already carries the outer
|
||||||
|
// continuation that was passed into this recursive call).
|
||||||
if (ctx.State.PendingActionGroupPick is { } pend)
|
if (ctx.State.PendingActionGroupPick is { } pend)
|
||||||
{
|
{
|
||||||
var existingCont = JsonSerializer.Deserialize<Models.Action[]>(
|
// An inner AND group may have already set PrecedingActionsJson.
|
||||||
pend.ContinuationActionsJson, _jsonOpts) ?? [];
|
// Prepend our own `all` to whatever the inner group stored.
|
||||||
pend.ContinuationActionsJson = JsonSerializer.Serialize(
|
var innerPreceding = pend.PrecedingActionsJson is not null
|
||||||
all.Concat(existingCont).ToArray(), _jsonOpts);
|
? JsonSerializer.Deserialize<Models.Action[]>(pend.PrecedingActionsJson, _jsonOpts) ?? []
|
||||||
|
: [];
|
||||||
|
pend.PrecedingActionsJson = JsonSerializer.Serialize(
|
||||||
|
all.Concat(innerPreceding).ToArray(), _jsonOpts);
|
||||||
|
|
||||||
var remaining = ag.Groups.Skip(gi + 1).ToArray();
|
var remaining = ag.Groups.Skip(gi + 1).ToArray();
|
||||||
if (remaining.Length > 0)
|
if (remaining.Length > 0)
|
||||||
@@ -1011,6 +1017,13 @@ public static class AbilitySystem
|
|||||||
var ctx = new AbilityContext { State = state, ActorId = pending.ActorId, Source = source };
|
var ctx = new AbilityContext { State = state, ActorId = pending.ActorId, Source = source };
|
||||||
var continuation = JsonSerializer.Deserialize<Models.Action[]>(
|
var continuation = JsonSerializer.Deserialize<Models.Action[]>(
|
||||||
pending.ContinuationActionsJson, _jsonOpts) ?? [];
|
pending.ContinuationActionsJson, _jsonOpts) ?? [];
|
||||||
|
|
||||||
|
// Actions that ran before the pause in a parent AND group.
|
||||||
|
// These must execute BEFORE the chosen branch to preserve AND-group order.
|
||||||
|
var preceding = pending.PrecedingActionsJson is not null
|
||||||
|
? JsonSerializer.Deserialize<Models.Action[]>(pending.PrecedingActionsJson, _jsonOpts) ?? []
|
||||||
|
: System.Array.Empty<Models.Action>();
|
||||||
|
|
||||||
AbilityRange? range = pending.RangeJson is not null
|
AbilityRange? range = pending.RangeJson is not null
|
||||||
? JsonSerializer.Deserialize<AbilityRange>(pending.RangeJson, _jsonOpts) : null;
|
? JsonSerializer.Deserialize<AbilityRange>(pending.RangeJson, _jsonOpts) : null;
|
||||||
DurationModel? forceDuration = pending.ForceDurationJson is not null
|
DurationModel? forceDuration = pending.ForceDurationJson is not null
|
||||||
@@ -1027,7 +1040,16 @@ public static class AbilitySystem
|
|||||||
abilityIndex: 0, range, forceDuration, continuation);
|
abilityIndex: 0, range, forceDuration, continuation);
|
||||||
if (chosen is null)
|
if (chosen is null)
|
||||||
{
|
{
|
||||||
// Nested group triggered another pick — prepend any chosen-leaf prefix.
|
// Nested group triggered another pick.
|
||||||
|
// Accumulate our preceding into whatever the inner group set.
|
||||||
|
if (ctx.State.PendingActionGroupPick is { } innerPend && preceding.Length > 0)
|
||||||
|
{
|
||||||
|
var innerInner = innerPend.PrecedingActionsJson is not null
|
||||||
|
? JsonSerializer.Deserialize<Models.Action[]>(innerPend.PrecedingActionsJson, _jsonOpts) ?? []
|
||||||
|
: [];
|
||||||
|
innerPend.PrecedingActionsJson = JsonSerializer.Serialize(
|
||||||
|
preceding.Concat(innerInner).ToArray(), _jsonOpts);
|
||||||
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1046,13 +1068,16 @@ public static class AbilitySystem
|
|||||||
abilityIndex: 0, range, forceDuration, continuation);
|
abilityIndex: 0, range, forceDuration, continuation);
|
||||||
if (rgActions is null)
|
if (rgActions is null)
|
||||||
{
|
{
|
||||||
// This remaining group paused — prepend already-resolved actions.
|
// This remaining group paused. Carry forward the full preceding context:
|
||||||
|
// preceding (from parent) + tempList (chosen branch + already-resolved groups)
|
||||||
if (ctx.State.PendingActionGroupPick is { } newPend)
|
if (ctx.State.PendingActionGroupPick is { } newPend)
|
||||||
{
|
{
|
||||||
var existingCont = JsonSerializer.Deserialize<Models.Action[]>(
|
var newInnerPreceding = newPend.PrecedingActionsJson is not null
|
||||||
newPend.ContinuationActionsJson, _jsonOpts) ?? [];
|
? JsonSerializer.Deserialize<Models.Action[]>(newPend.PrecedingActionsJson, _jsonOpts) ?? []
|
||||||
newPend.ContinuationActionsJson = JsonSerializer.Serialize(
|
: [];
|
||||||
tempList.Concat(existingCont).ToArray(), _jsonOpts);
|
newPend.PrecedingActionsJson = JsonSerializer.Serialize(
|
||||||
|
preceding.Concat(tempList).Concat(newInnerPreceding).ToArray(), _jsonOpts);
|
||||||
|
// ContinuationActionsJson is already set by the new pause.
|
||||||
var afterThis = remainingGroups.Skip(rgi + 1).ToArray();
|
var afterThis = remainingGroups.Skip(rgi + 1).ToArray();
|
||||||
newPend.RemainingGroupsJson = afterThis.Length > 0
|
newPend.RemainingGroupsJson = afterThis.Length > 0
|
||||||
? JsonSerializer.Serialize(afterThis, _jsonOpts) : null;
|
? JsonSerializer.Serialize(afterThis, _jsonOpts) : null;
|
||||||
@@ -1064,7 +1089,8 @@ public static class AbilitySystem
|
|||||||
chosen = tempList.ToArray();
|
chosen = tempList.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
var allActions = chosen.Concat(continuation).ToArray();
|
// Correct AND-group order: [preceding] + [chosen/remaining] + [outer continuation].
|
||||||
|
var allActions = preceding.Concat(chosen).Concat(continuation).ToArray();
|
||||||
ExecuteActions(allActions, ctx, clientTargets: null, requireClientTargets: false,
|
ExecuteActions(allActions, ctx, clientTargets: null, requireClientTargets: false,
|
||||||
activationRange: range, forceDuration: forceDuration);
|
activationRange: range, forceDuration: forceDuration);
|
||||||
return state;
|
return state;
|
||||||
@@ -1123,6 +1149,24 @@ public static class AbilitySystem
|
|||||||
ps.Deck.AddRange(top);
|
ps.Deck.AddRange(top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute any continuation actions stored at pause time.
|
||||||
|
var rrcSource = state.Players.Values
|
||||||
|
.SelectMany(p => p.Field).OfType<FieldCard>()
|
||||||
|
.FirstOrDefault(f => f.InstanceId == pending.SourceInstanceId);
|
||||||
|
var rrcCtx = new AbilityContext { State = state, ActorId = pending.ActorId, Source = rrcSource };
|
||||||
|
|
||||||
|
var rrcContinuation = JsonSerializer.Deserialize<Models.Action[]>(
|
||||||
|
pending.ContinuationActionsJson, _jsonOpts) ?? [];
|
||||||
|
if (rrcContinuation.Length > 0)
|
||||||
|
{
|
||||||
|
AbilityRange? rrcRange = pending.RangeJson is not null
|
||||||
|
? JsonSerializer.Deserialize<AbilityRange>(pending.RangeJson, _jsonOpts) : null;
|
||||||
|
DurationModel? rrcForceDuration = pending.ForceDurationJson is not null
|
||||||
|
? JsonSerializer.Deserialize<DurationModel>(pending.ForceDurationJson, _jsonOpts) : null;
|
||||||
|
ExecuteActions(rrcContinuation, rrcCtx, clientTargets: null, activationRange: rrcRange,
|
||||||
|
forceDuration: rrcForceDuration);
|
||||||
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1481,6 +1525,9 @@ public static class AbilitySystem
|
|||||||
? JsonSerializer.Deserialize<DurationModel>(pending.ForceDurationJson, _jsonOpts) : null;
|
? JsonSerializer.Deserialize<DurationModel>(pending.ForceDurationJson, _jsonOpts) : null;
|
||||||
|
|
||||||
// Execute the paused action (now with client targets) then run the continuation.
|
// Execute the paused action (now with client targets) then run the continuation.
|
||||||
|
// CONTRACT: The paused action is placed at index 0 in the replayed slice, so
|
||||||
|
// the client must submit targets using ActionIndex=0 regardless of the original
|
||||||
|
// action index in the ability definition. The prompt payload should reflect this.
|
||||||
var allActions = new[] { action }.Concat(continuation).ToArray();
|
var allActions = new[] { action }.Concat(continuation).ToArray();
|
||||||
ExecuteActions(allActions, ctx, clientTargets, requireClientTargets: true,
|
ExecuteActions(allActions, ctx, clientTargets, requireClientTargets: true,
|
||||||
activationRange: range, forceDuration: forceDuration);
|
activationRange: range, forceDuration: forceDuration);
|
||||||
@@ -1639,6 +1686,12 @@ public static class AbilitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Expose continuation context so effect-level pauses can store it.
|
// Expose continuation context so effect-level pauses can store it.
|
||||||
|
// DESIGN CONSTRAINT: A pausing effect (e.g. CloneSpiritAsToken with TargetTile,
|
||||||
|
// ChannelCardFromZone with TargetTile/Choice) must be the LAST effect in its
|
||||||
|
// action's Effects list. Any effects after a pausing one will be silently skipped
|
||||||
|
// because the outer loop returns on the first HasPendingInteraction() hit.
|
||||||
|
// Similarly, remaining targets in the same action are also dropped.
|
||||||
|
// This is an intentional trade-off: pausing effects are semantically terminal.
|
||||||
ctx.ContinuationActions = continuationActions;
|
ctx.ContinuationActions = continuationActions;
|
||||||
ctx.ActivationRange = activationRange;
|
ctx.ActivationRange = activationRange;
|
||||||
|
|
||||||
@@ -3173,6 +3226,13 @@ public static class AbilitySystem
|
|||||||
RevealedCardsJson = JsonSerializer.Serialize(revealed, _jsonOpts),
|
RevealedCardsJson = JsonSerializer.Serialize(revealed, _jsonOpts),
|
||||||
Count = n,
|
Count = n,
|
||||||
TargetPlayerAccountId = stackPs.AccountId,
|
TargetPlayerAccountId = stackPs.AccountId,
|
||||||
|
// Preserve the rest of the ability sequence so ResumeRevealChoicePick can
|
||||||
|
// continue execution after the chooser submits their ordering.
|
||||||
|
ContinuationActionsJson = JsonSerializer.Serialize(ctx.ContinuationActions, _jsonOpts),
|
||||||
|
RangeJson = ctx.ActivationRange is not null
|
||||||
|
? JsonSerializer.Serialize(ctx.ActivationRange, _jsonOpts) : null,
|
||||||
|
ForceDurationJson = duration is not null
|
||||||
|
? JsonSerializer.Serialize(duration, _jsonOpts) : null,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,14 @@ public sealed class PendingActionGroupPick
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? RemainingGroupsJson { get; set; }
|
public string? RemainingGroupsJson { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// JSON-serialized Action[]? — actions from the parent AND group that were already
|
||||||
|
/// flattened BEFORE the paused child group. These must execute BEFORE the chosen
|
||||||
|
/// branch, so resume computes: preceding + chosen + remaining-groups + continuation.
|
||||||
|
/// Null when there are no such preceding actions.
|
||||||
|
/// </summary>
|
||||||
|
public string? PrecedingActionsJson { get; set; }
|
||||||
|
|
||||||
/// <summary>JSON-serialized AbilityRange? — passed through to ExecuteActions on resume.</summary>
|
/// <summary>JSON-serialized AbilityRange? — passed through to ExecuteActions on resume.</summary>
|
||||||
public string? RangeJson { get; set; }
|
public string? RangeJson { get; set; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user