@champions-digital-game/mod-sdk 0.54.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +3 -3
  2. package/dist/build.js +1 -1
  3. package/dist/chunks/{chunk-DX44O32N.js → chunk-MRZL7PHD.js} +1 -1
  4. package/dist/chunks/{chunk-S3JH4WL4.js → chunk-N2HMNYPQ.js} +1 -1
  5. package/dist/chunks/{chunk-ACT4TJXC.js → chunk-NHQRL3H2.js} +3 -3
  6. package/dist/chunks/{chunk-3SR23UJ7.js → chunk-PHTEP3BC.js} +1 -1
  7. package/dist/chunks/{chunk-WFEXO5DU.js → chunk-RBTO2IFX.js} +1 -1
  8. package/dist/chunks/chunk-SCRIASBU.js +1 -0
  9. package/dist/chunks/{chunk-7NRC6TLV.js → chunk-SG4DMEG6.js} +1 -1
  10. package/dist/import.js +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/mc-pack.js +2 -2
  13. package/dist/testing.js +1 -1
  14. package/package.json +1 -1
  15. package/types/cards/src/dsl/abilities.d.ts +6 -3
  16. package/types/cards/src/dsl/effects.d.ts +22 -2
  17. package/types/cards/src/dsl/values.d.ts +11 -0
  18. package/types/cards/src/index.d.ts +3 -2
  19. package/types/cards/src/testing/driver.d.ts +16 -1
  20. package/types/cards/src/wave10/competitive.d.ts +49 -0
  21. package/types/cards/src/wave10/cw/competitive/leader-cards.d.ts +5 -7
  22. package/types/cards/src/wave10/cw/competitive/standard-pvp.d.ts +3 -3
  23. package/types/cards/src/wave10/cw/leaders/captain-marvel.d.ts +4 -2
  24. package/types/cards/src/wave10/cw/modular/dangerous-recruits.d.ts +0 -29
  25. package/types/cards/src/wave10/cw/modular/secret-avengers.d.ts +3 -4
  26. package/types/cards/src/wave10/cw/modular/the-initiative.d.ts +0 -31
  27. package/types/cards/src/wave10/index.d.ts +2 -0
  28. package/types/cards/src/wave10/setup.d.ts +7 -0
  29. package/types/cards/src/wave10/synthezoid/competitive/leader-cards.d.ts +22 -11
  30. package/types/cards/src/wave9/index.d.ts +1 -1
  31. package/types/cards/src/wave9/setup.d.ts +20 -1
  32. package/types/content/src/index.d.ts +1 -1
  33. package/types/engine/src/actions.d.ts +5 -0
  34. package/types/engine/src/commands.d.ts +53 -1
  35. package/types/engine/src/competitive-outcome.d.ts +159 -0
  36. package/types/engine/src/competitive-setup.d.ts +73 -0
  37. package/types/engine/src/effects.d.ts +32 -6
  38. package/types/engine/src/errors.d.ts +18 -2
  39. package/types/engine/src/event-sides.d.ts +21 -0
  40. package/types/engine/src/events.d.ts +127 -3
  41. package/types/engine/src/flow.d.ts +1 -1
  42. package/types/engine/src/game-fingerprint.d.ts +2 -2
  43. package/types/engine/src/index.d.ts +12 -4
  44. package/types/engine/src/lasting.d.ts +6 -1
  45. package/types/engine/src/pod-commands.d.ts +81 -0
  46. package/types/engine/src/pod-coordinator.d.ts +136 -0
  47. package/types/engine/src/pod.d.ts +276 -2
  48. package/types/engine/src/query.d.ts +7 -0
  49. package/types/engine/src/resolve/pod.d.ts +67 -1
  50. package/types/engine/src/resolve/triggers.d.ts +11 -0
  51. package/types/engine/src/select.d.ts +27 -7
  52. package/types/engine/src/setup-steps.d.ts +8 -0
  53. package/types/engine/src/setup.d.ts +10 -2
  54. package/types/engine/src/spec.d.ts +83 -10
  55. package/types/engine/src/state.d.ts +120 -2
  56. package/types/engine/src/team-phases.d.ts +106 -0
  57. package/types/engine/src/team.d.ts +34 -0
  58. package/types/engine/src/trigger-events.d.ts +50 -3
  59. package/types/engine/src/villain/authority.d.ts +16 -3
  60. package/types/engine/src/villain-phase-begun.d.ts +24 -0
  61. package/dist/chunks/chunk-3YMCANI3.js +0 -1
@@ -1,11 +1,12 @@
1
1
  import type { AbilityId, CardId, CoreAspect, EvidenceCombination, Trait, VillainSideLetter } from "../../content/src/index.js";
2
+ import type { CompetitiveClose, CompetitiveTrigger } from "./competitive-outcome.js";
2
3
  import type { CampaignCardFace, CampaignWindow, LogWrite } from "./campaign.js";
3
4
  import type { RulesCardType } from "./card-types.js";
4
- import type { ChoiceId, EncounterDeckId, FrameId, GameAreaId, InstanceId, PlayerId } from "./ids.js";
5
+ import type { ChoiceId, EncounterDeckId, FrameId, GameAreaId, InstanceId, PlayerId, TeamId } from "./ids.js";
5
6
  import type { CardPosition, ChoiceBehalf, PendingChoice, UnavailableOptions } from "./choices.js";
6
7
  import type { Adjustment, DelegableCostPart } from "./commands.js";
7
8
  import type { GroupId } from "./ids.js";
8
- import type { SharedEvent, SharedPodState, SharedResult } from "./pod.js";
9
+ import type { PodInboundEvent, PodOutboundEvent, RemotePower, SharedEvent, SharedPodState, SharedResult } from "./pod.js";
9
10
  import type { AccusationGuess, FacedownRole, Form, GameOutcome, GameStep, MainSchemeAdvancedBy, ZoneId } from "./state.js";
10
11
  import type { BasicPowerName, StatName } from "./spec.js";
11
12
  import type { StackFrameKind, WindowTiming } from "./stack.js";
@@ -107,6 +108,8 @@ export type GameEvent = {
107
108
  readonly round: number;
108
109
  readonly remaining: number;
109
110
  readonly playerPhaseInstead?: true;
111
+ /** With two teams, the team whose villain phase it was (MC56 pp. 16, 20 + N8): `remaining` counts that team's. */
112
+ readonly teamId?: TeamId;
110
113
  } | {
111
114
  readonly type: "turnStarted";
112
115
  readonly playerId: PlayerId;
@@ -929,6 +932,16 @@ export type GameEvent = {
929
932
  readonly unpreventable?: true;
930
933
  /** Consequential damage, and for what (`TriggerEvent dealDamage.consequentialFrom`), so a log can say so. */
931
934
  readonly consequentialFrom?: "attack" | "thwart";
935
+ /**
936
+ * Excess damage (RRG 1.8 "Excess Damage", p. 19; "Overkill", p. 31): the damage `amount` taken beyond the hit
937
+ * points the target had remaining before it, so present only when this damage brought the target to (or past)
938
+ * its hit points. It is the same value overkill spills and every "excess damage" ability counts
939
+ * (`excessDamageOf` in resolve/event.ts): measured on the damage taken, after reductions, caps, tough and
940
+ * preventions, plus any `excessDamageBonus` (Follow Through), and recorded whether or not the attack has
941
+ * overkill or the defeat that follows happens. Absent when there is none. Informational only (achievements);
942
+ * nothing in the engine reads it back.
943
+ */
944
+ readonly excess?: number;
932
945
  } | {
933
946
  readonly type: "damagePrevented";
934
947
  readonly targetInstanceId: InstanceId;
@@ -1007,6 +1020,11 @@ export type GameEvent = {
1007
1020
  readonly type: "damageHealed";
1008
1021
  readonly targetInstanceId: InstanceId;
1009
1022
  readonly amount: number;
1023
+ /**
1024
+ * The card whose ability, cost or basic power healed the damage (`healDamage`'s `sourceInstanceId`), so a log or
1025
+ * an achievement can tell who healed whom. Absent when no card did. Informational only.
1026
+ */
1027
+ readonly sourceInstanceId?: InstanceId;
1010
1028
  }
1011
1029
  /**
1012
1030
  * A heal of damage the target had healed nothing: a `RuleSpec cannotBeHealed` matched it (docs/phase7-wave6.md
@@ -1882,9 +1900,47 @@ export type GameEvent = {
1882
1900
  readonly type: "playerSatOut";
1883
1901
  readonly playerId: PlayerId;
1884
1902
  readonly startingPlayerCount: number;
1885
- } | {
1903
+ }
1904
+ /**
1905
+ * The first player token passed. `teamId`: in a game with two teams, the team whose own token it is (MC56 p. 16:
1906
+ * "each team has its own first player token"); absent in every other game.
1907
+ */
1908
+ | {
1886
1909
  readonly type: "firstPlayerChanged";
1887
1910
  readonly playerId: PlayerId;
1911
+ readonly teamId?: TeamId;
1912
+ }
1913
+ /**
1914
+ * Setup made a game with two teams (docs/competitive-mode-plan.md M1; MC56 pp. 14-15): each team, in team order
1915
+ * (registration first), with its seats, the game area it plays in, the leader, main scheme and encounter deck it
1916
+ * faces (the scenario the other team built), its first player, and its own leader's four basic player cards set
1917
+ * aside. Logged once, right after `gameCreated`.
1918
+ */
1919
+ | {
1920
+ readonly type: "teamsFormed";
1921
+ readonly teams: readonly {
1922
+ readonly teamId: TeamId;
1923
+ readonly side: "registration" | "resistance" | null;
1924
+ readonly playerIds: readonly PlayerId[];
1925
+ readonly areaId: GameAreaId;
1926
+ readonly leaderInstanceId: InstanceId;
1927
+ readonly mainSchemeInstanceId: InstanceId;
1928
+ readonly encounterDeckId: EncounterDeckId;
1929
+ readonly firstPlayerId: PlayerId;
1930
+ readonly leaderCardIds: readonly InstanceId[];
1931
+ }[];
1932
+ }
1933
+ /**
1934
+ * Another team's phase begins (`GameState.activeTeamId`; MC56 p. 16), or, during setup, another team's game area
1935
+ * sets up (`GameStep teamScenarioSetup`). `firstPlayerId` and `activeVillainId` are what `GameState.firstPlayerId`
1936
+ * and `GameState.activeVillainId` read from now on: that team's token holder and the leader it faces.
1937
+ */
1938
+ | {
1939
+ readonly type: "activeTeamChanged";
1940
+ readonly teamId: TeamId;
1941
+ readonly phase: "setup" | "player" | "villain";
1942
+ readonly firstPlayerId: PlayerId;
1943
+ readonly activeVillainId: InstanceId;
1888
1944
  } | {
1889
1945
  readonly type: "choiceRequested";
1890
1946
  readonly choice: PendingChoice;
@@ -2134,6 +2190,8 @@ export type GameEvent = {
2134
2190
  */
2135
2191
  | {
2136
2192
  readonly type: "podEffectRequested";
2193
+ /** This group's outbound number for it (`PodState.outboundSeq`), shared with `sharedEventEmitted`. */
2194
+ readonly seq: number;
2137
2195
  readonly toGroupId: GroupId;
2138
2196
  readonly sourceCardId: CardId;
2139
2197
  readonly abilityId: AbilityId;
@@ -2164,6 +2222,63 @@ export type GameEvent = {
2164
2222
  readonly type: "sharedResultApplied";
2165
2223
  readonly result: SharedResult;
2166
2224
  }
2225
+ /**
2226
+ * An outbound event of the pod other than a shared event (`PodOutboundEvent`; docs/epic-multiplayer-plan.md §4): this
2227
+ * group's status or reachable cards changed, or a remote power was used or resolved. `seq` is this group's next
2228
+ * outbound number, shared with `sharedEventEmitted` and `podEffectRequested`. Only with a remote coordinator.
2229
+ */
2230
+ | {
2231
+ readonly type: "podEventEmitted";
2232
+ readonly seq: number;
2233
+ readonly event: PodOutboundEvent;
2234
+ }
2235
+ /**
2236
+ * `Command externalEvent` was accepted: inbound event `sequence` of the pod's coordinator. A `sharedStateChanged`,
2237
+ * `gameWon` or `gameLost` (and a `stopAfterPhase` in setup) takes effect at once; any other waits for the resolution
2238
+ * in progress to finish and is then logged `podInboundApplied`.
2239
+ */
2240
+ | {
2241
+ readonly type: "podInboundReceived";
2242
+ readonly sequence: number;
2243
+ readonly kind: PodInboundEvent["kind"];
2244
+ }
2245
+ /** A waiting inbound event of the pod is applied, nothing resolving (MC55 p. 20); what it does follows. */
2246
+ | {
2247
+ readonly type: "podInboundApplied";
2248
+ readonly kind: PodInboundEvent["kind"];
2249
+ }
2250
+ /** The group's authority ended a wait for the pod coordinator (`Command podRelease`): shared event `seq` is unanswered. */
2251
+ | {
2252
+ readonly type: "podWaitReleased";
2253
+ readonly seq: number;
2254
+ }
2255
+ /**
2256
+ * A stand-in for another group's card was placed in this group's villain area for a remote basic power (`placed`,
2257
+ * with the group and the card it stands for), or removed once nothing was resolving (`CardInstance.remoteOf`).
2258
+ */
2259
+ | {
2260
+ readonly type: "remoteStandIn";
2261
+ readonly instanceId: InstanceId;
2262
+ readonly placed: boolean;
2263
+ /** Damage or threat removal aimed at it that was not its power's own, so was dealt nowhere (`divertToRemote`). */
2264
+ readonly ignored?: "attack" | "thwart";
2265
+ readonly groupId?: GroupId;
2266
+ readonly remoteInstanceId?: InstanceId;
2267
+ }
2268
+ /**
2269
+ * In the attacker's group: how a remote basic power of one of its players ended in the group whose card it was made
2270
+ * against (inbound `remotePowerSettled`, after `remotePowerResolved`). `defeated`: the attack defeated the card (The
2271
+ * Mangog, 55041) or the thwart cleared it (Door Between Worlds, 55046), read as the card having left play once the hit
2272
+ * and what answered it had resolved there. Informational only (achievements): nothing else changes.
2273
+ */
2274
+ | {
2275
+ readonly type: "remotePowerSettled";
2276
+ readonly fromGroupId: GroupId;
2277
+ readonly playerId: PlayerId;
2278
+ readonly power: RemotePower;
2279
+ readonly cardId: CardId;
2280
+ readonly defeated: boolean;
2281
+ }
2167
2282
  /**
2168
2283
  * Counters that were to be placed on a card and were not, because the card may hold no more of them (`RuleSpec
2169
2284
  * counterLimit`, "Max 1 [per player] synergy counters here"; docs/phase7-wave9.md §3.61). `amount` is the number not
@@ -2690,6 +2805,15 @@ export type GameEvent = {
2690
2805
  } | {
2691
2806
  readonly type: "gameEnded";
2692
2807
  readonly outcome: GameOutcome;
2808
+ }
2809
+ /**
2810
+ * A competitive team met a win condition (MC56 p. 17; `competitive-outcome.ts`): the game goes on to the end of
2811
+ * `closesAfter`, the phase that gives both sides the same number of phases, and then ends.
2812
+ */
2813
+ | {
2814
+ readonly type: "teamResultRecorded";
2815
+ readonly trigger: CompetitiveTrigger;
2816
+ readonly closesAfter: CompetitiveClose;
2693
2817
  };
2694
2818
  export type GameEventType = GameEvent["type"];
2695
2819
  /**
@@ -17,7 +17,7 @@ export declare function beginPlayerPhase(ctx: Ctx): void;
17
17
  * (`phase: "round"`, docs/phase7-wave11-hero-packs.md H3.7), the "at the end of the round" ones too. RRG 1.8 "Delayed Effect" (p. 16):
18
18
  * they resolve "immediately after their specified timing point [...] and before responses to that point".
19
19
  */
20
- export declare function pushPhaseEndDelayed(ctx: Ctx, phase: "player" | "villain" | "round"): void;
20
+ export declare function pushPhaseEndDelayed(ctx: Ctx, phase: "player" | "villain" | "round", roundContinues?: boolean): void;
21
21
  /** Ends `playerId`'s turn if it still is theirs: the `endTurn` command, or its `turnEnding` event applying. */
22
22
  export declare function finishTurn(ctx: Ctx, playerId: PlayerId): void;
23
23
  /** Called by the `endTurn` command once the active player is done. */
@@ -10,8 +10,8 @@ import type { StackFrame } from "./stack.js";
10
10
  * Bookkeeping: the stack and the open choice; the counters that name frames, choices and lasting effects; the
11
11
  * per-ability use counts ("Limit once per round" counts a resolution that did nothing); and the memory of what the
12
12
  * between-frames checks and the log last saw (`stateChecks`, `hitPointsSeen`, `schemeTargetsSeen`,
13
- * `deckTopsAnnounced`, `encounterTopAnnounced`), none of which the game is ever read from. The queues those checks
14
- * drain (`pending…`) are game: a card left play or entered a hand.
13
+ * `deckTopsAnnounced`, `encounterTopAnnounced`, `encounterTopsAnnounced`), none of which the game is ever read from.
14
+ * The queues those checks drain (`pending…`) are game: a card left play or entered a hand.
15
15
  */
16
16
  export declare const PROBE_FIELDS: {
17
17
  readonly [K in keyof Required<GameState>]: "game" | "bookkeeping";
@@ -1,12 +1,20 @@
1
- export declare const ENGINE_VERSION = "0.54.0";
1
+ export declare const ENGINE_VERSION = "1.0.0";
2
2
  export type { PlayerId, InstanceId, ChoiceId, EncounterDeckId, FrameId, GroupId, TeamId } from "./ids.js";
3
3
  export { playerId, instanceId, choiceId, encounterDeckId, frameId, groupId, teamId } from "./ids.js";
4
4
  export type { GroupRef, PodNeutralArea, PodNeutralSetup, PodSetup, PodState, SharedEvent, SharedPodState, SharedResult, SharedThreatCause, } from "./pod.js";
5
5
  export { applySharedEvent, groupVar, POD_MOMENT, podBlocksOf, podGroupIds, podOf, podSetupFault, resolveGroup, sharedLost, SINGLE_GROUP, } from "./pod.js";
6
+ export type { GroupStatus, PodInboundEvent, PodOutbound, PodOutboundEvent, ReachableCard, RemotePower } from "./pod.js";
7
+ export type { CoordinatorErrorCode, CoordinatorGroupState, CoordinatorLogEntry, CoordinatorResult, PodCoordinatorGroupSetup, PodCoordinatorSetup, PodCoordinatorState, PodDelivery, PodInbound, } from "./pod-coordinator.js";
8
+ export { coordinatorGroup, createPodCoordinator, inboundSince, markGroupDropped, podmatesOf, receiveOutbound, replayCoordinator, } from "./pod-coordinator.js";
9
+ export { groupStatusOf, inboundCommand, podOutboundOf } from "./pod-commands.js";
10
+ export { reachableCardsOf, remoteTargetFault } from "./resolve/pod.js";
6
11
  export type { GameMode } from "./game-mode.js";
7
12
  export { COMPETITIVE_MODE_UNAVAILABLE_MESSAGE, gameModeOf } from "./game-mode.js";
8
13
  export type { TeamSide, TeamState } from "./team.js";
9
- export { playersOnTeam, SINGLE_TEAM, teamOf, teamSize, teamsOf } from "./team.js";
14
+ export { activeTeamOf, enemyLeaderOf, enemyTeamOf, inactiveTeamMessage, onInactiveTeam, playersOnTeam, SINGLE_TEAM, teamFirstPlayerOf, teamOf, teamSize, teamsOf, yourLeaderOf, } from "./team.js";
15
+ export { nextClockwiseTeammate, onActiveSide, phasePlayerOrder } from "./team-phases.js";
16
+ export { competitiveOutcome, tieBreakReport, TIE_BREAK_ORDER, type CompetitiveClose, type CompetitiveCondition, type CompetitiveOutcome, type CompetitiveState, type CompetitiveTeamResult, type CompetitiveTrigger, type TieBreakMeasure, type TieBreakReport, } from "./competitive-outcome.js";
17
+ export type { CompetitiveScenarioSetup, CompetitiveSetup, CompetitiveTeamSetup } from "./competitive-setup.js";
10
18
  export type { RngState } from "./rng.js";
11
19
  export { createRng, nextInt, nextUint32, shuffle } from "./rng.js";
12
20
  export type { Accusation, AccusationGuess, AttackRecord, RevealRecord, CardHome, CardInstance, EncounterDeckState, FacedownRole, Form, GameOutcome, GameState, StackedDecks, GameStep, IdentityState, MainSchemeAdvancedBy, MainSchemeState, PlayerState, ScenarioPlayAreaState, ScenarioSetupInstruction, SeparateDeckState, SetAsideUntilCalled, SetupOption, StatusCounts, VillainState, ZoneId, TableRules, } from "./state.js";
@@ -47,7 +55,7 @@ export { printedResources } from "./resources.js";
47
55
  export { pairOfOptionId, pairOptionId, pairSelectionFault, resourceIconsMatch } from "./resolve/pair-cards.js";
48
56
  export { characterTitledAs, identityCardTitledAs } from "./titles.js";
49
57
  export type { CostChoices, CostPartPayers, CostSelection, DelegableCostPart } from "./commands.js";
50
- export { DELEGABLE_COST_PARTS } from "./commands.js";
58
+ export { DELEGABLE_COST_PARTS, isAuthorityCommand } from "./commands.js";
51
59
  export type { DeferredEffects, ReportTarget, Vars } from "./stack.js";
52
60
  export { attackPreventedVars, currentActivationFrameId, PAID_CARDS_SLOT, PAID_IN_PLAY_CARDS_SLOT, READIED_CARDS_SLOT, } from "./stack.js";
53
61
  export { abilityUseKey, BORROWED_BOOST_ICONS_SLOT, DEFAULT_DEPS, fixedResourcesOf, GRANTED_BY_SLOT, inPlayPicksOf, tuckedPickOf, labeledResolvedVar, isResourcesChoice, NO_ABILITIES, playableAsIfInHandOf, resourcesChoiceOf, } from "./abilities.js";
@@ -98,7 +106,7 @@ export { heldBoostCardsOf } from "./resolve/villainous.js";
98
106
  export type { ActiveModifier, ModifiedStat } from "./modifiers.js";
99
107
  export { boostIconsFor, modifiersFor, statBonus } from "./modifiers.js";
100
108
  export type { EffectContext, PlayerCardClassification, QueryExclusion } from "./select.js";
101
- export { abilityIgnored, activeAbilityRefs, gainedAbilities, attackableAsMinion, attackForbiddenBy, canAttack, cardsInPlay, facedownAttachments, isFacedownAttachment, cardTypeOf, categoriesOf, chosenFromList, chosenVar, classificationsOf, consideredRemainingHitPoints, controllerOf, deckTopFaceupPlayers, enemyTeamDecider, encounterTopFaceup, hitPointFloor, ignoredAbilities, explainQuery, handCountTowardHandSize, isCaptiveAlly, isAttackTarget, isHeldMinion, matchesQuery, resolveRef, resolveValue, selectTargets, shownDeckTop, shownEncounterTop, TOGETHER_TARGETS_SLOT, textBoxBlankFor, textBoxBlankedFor, textBoxBlankToPlayer, villainAliasOf, traitsOf, } from "./select.js";
109
+ export { abilityIgnored, activeAbilityRefs, gainedAbilities, attackableAsMinion, attackForbiddenBy, canAttack, cardsInPlay, facedownAttachments, isFacedownAttachment, cardTypeOf, categoriesOf, chosenFromList, chosenVar, classificationsOf, consideredRemainingHitPoints, controllerOf, deckTopFaceupPlayers, enemyTeamDecider, encounterDecksFaceup, encounterTopFaceup, hitPointFloor, ignoredAbilities, explainQuery, handCountTowardHandSize, isCaptiveAlly, isAttackTarget, isHeldMinion, matchesQuery, resolveRef, resolveValue, selectTargets, shownDeckTop, shownEncounterTop, TOGETHER_TARGETS_SLOT, textBoxBlankFor, textBoxBlankedFor, textBoxBlankToPlayer, villainAliasOf, traitsOf, } from "./select.js";
102
110
  export { selfDamageThreshold } from "./damage-threshold.js";
103
111
  /** "Why not the others?" — the cards an open choice left out, each with the clause that excluded it. */
104
112
  export type { ChoiceExclusion, ExclusionCode } from "./why-not.js";
@@ -1,6 +1,6 @@
1
1
  import type { CardId, KeywordInstance, Trait } from "../../content/src/index.js";
2
2
  import type { EventPattern, RuleSpec } from "./abilities.js";
3
- import type { FrameId, InstanceId, PlayerId } from "./ids.js";
3
+ import type { FrameId, InstanceId, PlayerId, TeamId } from "./ids.js";
4
4
  import type { EffectSpec, StatName, TargetQuery, ValueSpec } from "./spec.js";
5
5
  import type { Bindings, Vars } from "./stack.js";
6
6
  import type { GameState } from "./state.js";
@@ -26,9 +26,14 @@ export type LastingDuration =
26
26
  * villain phase, and through the whole player phase after it. RRG 1.8 "Lasting Effects" (p. 26): "A lasting effect
27
27
  * expires as soon as the timing point specified by its duration is reached", so it is gone before anything answers
28
28
  * the villain phase beginning and before step one (`expireNextVillainPhaseEffects`).
29
+ *
30
+ * `teamId`, in a game whose phases a team plays: the team that made it, whose next unskipped villain phase alone ends
31
+ * it (MC56 pp. 16, 20 + N8, 2026-11-20, settled by the rules expert for PR #923; `addLastingEffect` sets it). Absent
32
+ * in every game without teams.
29
33
  */
30
34
  | {
31
35
  readonly kind: "nextVillainPhaseBegins";
36
+ readonly teamId?: TeamId;
32
37
  }
33
38
  /**
34
39
  * "Until the end of the player phase" (Take a Stand, 62015; docs/phase7-wave11-hero-packs.md H3.9): ends as the
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The commands of Epic Multiplayer (docs/epic-multiplayer-plan.md §4 items 1 to 3; docs/phase7-wave9.md §3.68), and
3
+ * what every command of a group with a remote coordinator tells it at its end (`reportPodBoundary`).
4
+ *
5
+ * MC55 p. 11 and 55028b: one Loki, God of Lies and one Worlds Collide per game; pods only scope "your pod" abilities
6
+ * (MC55 pp. 4, 13). A `GameState` is one group; the coordinator (`pod-coordinator.ts`) is outside every group.
7
+ */
8
+ import type { EngineDeps } from "./abilities.js";
9
+ import type { Command } from "./commands.js";
10
+ import { type Ctx } from "./ctx.js";
11
+ import { type EngineError } from "./errors.js";
12
+ import type { GameEvent } from "./events.js";
13
+ import { type GroupStatus, type PodInboundEvent, type PodOutbound } from "./pod.js";
14
+ import type { GameState } from "./state.js";
15
+ /** The `externalEvent` command a host applies for inbound event `sequence` (recorded under the first player). */
16
+ export declare const inboundCommand: (state: GameState, sequence: number, event: PodInboundEvent) => Command;
17
+ /**
18
+ * MC55 p. 21: a group that has stopped play after the shared scheme's completion takes no more actions; what was
19
+ * resolving still finishes (a choice is answered), and the coordinator's verdict still arrives. A group waiting for the
20
+ * coordinator's answer to its shared event (`PodState.awaiting`) takes none until it comes.
21
+ */
22
+ export declare function haltedFault(state: GameState, command: Command): EngineError | null;
23
+ /**
24
+ * `Command externalEvent`. Accepted only with a remote coordinator, from the first player's seat, with the next
25
+ * sequence (one already applied is `external_event_already_applied`, which a host drops; a gap is
26
+ * `external_event_out_of_order`, which it fills). Then:
27
+ * - `sharedStateChanged` and `podReachable` take effect at once (bookkeeping, no draw);
28
+ * - `gameWon` / `gameLost` end the game at once, whatever is resolving (Q6: groups stop at their next command boundary);
29
+ * - `stopAfterPhase` in setup or a mulligan stops the group at once (owner question 1, option A pending; plan §1.8);
30
+ * - everything else waits in `PodState.pendingInbound` for the resolution in progress to finish (MC55 p. 20; M3).
31
+ */
32
+ export declare function externalEvent(ctx: Ctx, command: Command & {
33
+ type: "externalEvent";
34
+ }): EngineError | null;
35
+ /**
36
+ * `Command podRelease`: the group's authority ends a wait for the coordinator's answer (`PodState.awaiting`) after a
37
+ * timeout, when the coordinator is gone and cannot be restored (docs/live-game-rooms.md §10). The group plays on; its
38
+ * unanswered shared event keeps its number and is re-sent when a coordinator returns, whose late `sharedAck` then
39
+ * changes nothing. Refused with nothing to release.
40
+ */
41
+ export declare function podRelease(ctx: Ctx, command: Command & {
42
+ type: "podRelease";
43
+ }): EngineError | null;
44
+ /**
45
+ * `Command remotePower` (plan §1.8 M6): a basic attack or thwart on another group's reachable card.
46
+ *
47
+ * 55041/55046 "as if it were in their game area": a real attack/thwart by the remote character (MC55 insert p.12
48
+ * exception; RRG Attack (Player Ability Type) p.10, Thwart p.44). A stand-in for the card is placed in this group's
49
+ * villain area (`placeStandIn`, no text box here) and the ordinary basic power is made against it: its checks ("cannot
50
+ * attack", "cannot thwart", stunned, confused), its costs, ATK or THW and their modifiers, this group's "when/after a
51
+ * character attacks/thwarts" abilities (Domineering Force 55052, Mounting Resistance 55054, "after you attack a
52
+ * minion"), and an ally's consequential damage. Only the damage or the threat removal aimed at the stand-in is sent,
53
+ * with the attack's keywords (`divertToRemote`); the card's own keywords and statuses apply where it is.
54
+ *
55
+ * Cross-group attack/thwart (55041/55046) is initiated when the owning group's engine accepts it (engine reading: no
56
+ * source orders events across groups, MC55 p.12). No valid target then = not initiated, no cost paid (RRG v1.8
57
+ * Initiating Abilities p.24 step 2; Target p.42; Cost p.13). Target leaves play after that = exhausts, no consequential
58
+ * damage, not considered to have attacked (Consequential Damage p.13).
59
+ *
60
+ * So a refusal from the owning group refunds the exhaust, the consequential damage and the hand cards spent
61
+ * (`PodState.inFlight`), and a stunned attacker or a confused thwarter, whose attempt never reaches the card, keeps the
62
+ * status discard and the exhaust (RRG 1.8 "Stun, Stunned", p. 41; owner answer 2026-11-20). Checked first against this
63
+ * group's copy of the owning group's last report (`PodState.reachable`), so a card known to be gone is refused before
64
+ * anything is paid.
65
+ */
66
+ export declare function remotePower(ctx: Ctx, command: Command & {
67
+ type: "remotePower";
68
+ }): EngineError | null;
69
+ /** This group's status for its coordinator (MC55 p. 21; M4). */
70
+ export declare function groupStatusOf(state: GameState): GroupStatus;
71
+ /**
72
+ * At the end of every command of a group with a remote coordinator: its status (phase, round, halt) and its reachable
73
+ * cards (The Mangog, Door Between Worlds: entered, left, damage or threat), each told once when it changed over the
74
+ * command. Read as a difference of the states before and after, so no step of the engine has to remember to report.
75
+ */
76
+ export declare function reportPodBoundary(ctx: Ctx, before: GameState, deps: EngineDeps): void;
77
+ /**
78
+ * The outbound events of a command, in order, as a host forwards them to the coordinator: every
79
+ * `sharedEventEmitted`, `podEffectRequested` and `podEventEmitted`, numbered by this group.
80
+ */
81
+ export declare function podOutboundOf(state: GameState, events: readonly GameEvent[]): readonly PodOutbound[];
@@ -0,0 +1,136 @@
1
+ /**
2
+ * The pod coordinator of Epic Multiplayer Mode (docs/epic-multiplayer-plan.md §2 option B, §4 item 1; issue #882): a
3
+ * pure, deterministic reducer over the outbound events of every group of the game, with its own log.
4
+ *
5
+ * MC55 p. 11 and 55028b: one Loki, God of Lies and one Worlds Collide per game; pods only scope "your pod" abilities
6
+ * (MC55 pp. 4, 13). So the coordinator is game-wide: it owns the one shared record (the shared villain's hit points and
7
+ * flip, the shared scheme's threat and target, `SharedPodState`) and the game's outcome, and knows which pod each group
8
+ * is in only to route the "your pod" events (a synergy grant, an attack on The Mangog, a thwart of Door Between Worlds).
9
+ *
10
+ * Each group is its own engine with its own log. What a group tells the coordinator (`PodOutboundEvent`) is numbered
11
+ * by the group; the coordinator applies each number once (a re-sent event is a duplicate, a gap is refused so the group
12
+ * re-sends from the first missing one). What the coordinator tells a group (`PodInboundEvent`) is numbered per group
13
+ * and kept, so a reconnecting group can be sent what it missed (`inboundSince`). The group applies an inbound event as
14
+ * a `Command externalEvent`, which its own log records: a group replays alone, with no coordinator.
15
+ *
16
+ * Nothing here reads a `GameState`, draws a random number or names a card.
17
+ */
18
+ import type { GroupId, InstanceId } from "./ids.js";
19
+ import { type GroupStatus, type PodInboundEvent, type PodOutbound, type ReachableCard, type RemotePower, type SharedPodState } from "./pod.js";
20
+ /** One group as the coordinator is set up with it. */
21
+ export interface PodCoordinatorGroupSetup {
22
+ readonly groupId: GroupId;
23
+ /** The pod the organizer put it in (MC55 p. 13). */
24
+ readonly podId: string;
25
+ /** Its players at the start of the scenario. */
26
+ readonly players: number;
27
+ /** Its status as setup left it (`groupStatusOf` of its first state). Absent: setup, round 0, not halted. */
28
+ readonly status?: GroupStatus;
29
+ }
30
+ export interface PodCoordinatorSetup {
31
+ /** Every group of the game, in the order the organizer listed them. */
32
+ readonly groups: readonly PodCoordinatorGroupSetup[];
33
+ /**
34
+ * The shared record as setup made it: every group's engine builds the same one from the game's counts (Q3: Loki's
35
+ * hit points and flip count every player in the game, Worlds Collide's target every group), so any group's
36
+ * `pod.shared` at setup is it.
37
+ */
38
+ readonly shared: SharedPodState;
39
+ }
40
+ /** An inbound event as numbered for its group (`Command externalEvent.sequence`). */
41
+ export interface PodInbound {
42
+ readonly sequence: number;
43
+ readonly event: PodInboundEvent;
44
+ }
45
+ /** An inbound event addressed: what a host relays to the group's authority. */
46
+ export interface PodDelivery extends PodInbound {
47
+ readonly groupId: GroupId;
48
+ }
49
+ export interface CoordinatorGroupState {
50
+ readonly groupId: GroupId;
51
+ readonly podId: string;
52
+ readonly players: number;
53
+ /** The last outbound number applied from this group (0: none yet). */
54
+ readonly received: number;
55
+ /** Every inbound event sent to this group, by sequence from 1. */
56
+ readonly inbound: readonly PodInbound[];
57
+ /** Its last reported status. A group begins in setup. */
58
+ readonly status: GroupStatus;
59
+ /** Its reachable cards as last reported (The Mangog, Door Between Worlds). */
60
+ readonly reachable: readonly ReachableCard[];
61
+ /**
62
+ * The organizer marked it dropped (plan Q-C, default (b) pending the owner): it no longer holds up the stop rule.
63
+ * Its numbers stay (Q2: the per group count is fixed at setup).
64
+ */
65
+ readonly dropped: boolean;
66
+ }
67
+ /** One entry of the coordinator's log, in the order applied. Replaying it rebuilds the state (`replayCoordinator`). */
68
+ export type CoordinatorLogEntry = ({
69
+ readonly kind: "outbound";
70
+ readonly groupId: GroupId;
71
+ } & PodOutbound) | {
72
+ readonly kind: "dropped";
73
+ readonly groupId: GroupId;
74
+ };
75
+ /** A remote power forwarded and not yet answered (`PodCoordinatorState.pending`). */
76
+ export interface PendingRemotePower {
77
+ readonly fromGroupId: GroupId;
78
+ readonly toGroupId: GroupId;
79
+ readonly ref: InstanceId;
80
+ readonly targetInstanceId: InstanceId;
81
+ readonly power: RemotePower;
82
+ }
83
+ export interface PodCoordinatorState {
84
+ readonly shared: SharedPodState;
85
+ /** The game's outcome: every group wins or loses together (MC55 p. 21). */
86
+ readonly outcome: "playing" | "won" | "lost";
87
+ /**
88
+ * Remote powers forwarded to their owning group and not yet answered there: refused back to their group if the owning
89
+ * group drops (`markGroupDropped`). Absent when none.
90
+ */
91
+ readonly pending?: readonly PendingRemotePower[];
92
+ readonly groups: readonly CoordinatorGroupState[];
93
+ readonly log: readonly CoordinatorLogEntry[];
94
+ }
95
+ export type CoordinatorErrorCode = "unknown_group" | "out_of_order" | "invalid_setup";
96
+ export type CoordinatorResult = {
97
+ readonly ok: true;
98
+ readonly state: PodCoordinatorState;
99
+ /** New inbound events, in the order they were made. Empty for a duplicate. */
100
+ readonly delivered: readonly PodDelivery[];
101
+ /** The event was applied before (same group and number): nothing changed. */
102
+ readonly duplicate: boolean;
103
+ } | {
104
+ readonly ok: false;
105
+ readonly error: {
106
+ readonly code: CoordinatorErrorCode;
107
+ readonly message: string;
108
+ };
109
+ };
110
+ /** The coordinator at the start of the game. Throws on a malformed setup (a configuration bug, not a game event). */
111
+ export declare function createPodCoordinator(setup: PodCoordinatorSetup): PodCoordinatorState;
112
+ /** A group of the coordinator, or undefined. */
113
+ export declare const coordinatorGroup: (state: PodCoordinatorState, groupId: GroupId) => CoordinatorGroupState | undefined;
114
+ /**
115
+ * The groups of `groupId`'s pod, it included, in setup order: what "your pod" means for it (Epic Multiplayer Reminder
116
+ * card: groups that began the scenario in that pod (cf. RRG Per Player Icon p. 32)). Dropped groups stay listed.
117
+ */
118
+ export declare const podmatesOf: (state: PodCoordinatorState, groupId: GroupId) => readonly GroupId[];
119
+ /** The inbound events sent to `groupId` after `afterSequence`: what a reconnecting group's host re-sends. */
120
+ export declare const inboundSince: (state: PodCoordinatorState, groupId: GroupId, afterSequence: number) => readonly PodInbound[];
121
+ /**
122
+ * Applies one outbound event of `groupId`, numbered `seq`. A number already applied is a duplicate (no change, nothing
123
+ * delivered); a number past the next one is `out_of_order`, so the group's host re-sends from the first missing.
124
+ */
125
+ export declare function receiveOutbound(state: PodCoordinatorState, groupId: GroupId, outbound: PodOutbound): CoordinatorResult;
126
+ /**
127
+ * The organizer marks a group dropped (plan Q-C; pending the owner, default (b): the game goes on without it). A
128
+ * dropped group no longer holds up the stop rule; its threat on the shared scheme stays and the per group counts do
129
+ * not change (Q2).
130
+ */
131
+ export declare function markGroupDropped(state: PodCoordinatorState, groupId: GroupId): CoordinatorResult;
132
+ /**
133
+ * The coordinator rebuilt from its setup and log: the consistency check of plan §2 ("replay a pod by replaying the
134
+ * coordinator log, which regenerates the inbound events each group must have received").
135
+ */
136
+ export declare function replayCoordinator(setup: PodCoordinatorSetup, log: readonly CoordinatorLogEntry[]): PodCoordinatorState;