---
name: cross-act-events
description: Replace forgettable one-off random "?" events in roguelike games with a 3-layer cross-act chained event architecture: a 3-act delayed state machine (chain_flags with Act 1 hook, Act 2 temptation cash-out fork setting flag=9, and Act 3 doubled payoff), guaranteed next-act priority queue injection (active_chain_continuations + seen_events deduplication so quests never sink into the RNG pool), and SCENE_ALIASES art reuse (mapping 10 story acts across 4 chains onto 4 shared scene assets to save 60% illustration cost).
---

# Cross-Act Chained "?" Events Contract

90% of roguelike "?" nodes feel like disposable slot machines: players mash Skip by their second run because choices leave zero memory across acts. Great roguelike events turn a single click into **cross-act foreshadowing and payoff**.

## 1. The 3 Mandatory Architecture Layers

1. **Layer 01 — Three-Act Delayed State Machine (`chain_flags`)**:
   - Persist a lightweight serializable integer dictionary on the run state: `run.chain_flags: Record<string, number>` (`0` = unstarted, `1` = Act 1 hook planted, `2` = Act 2 temptation resisted, `3` = Act 3 climax completed, `9` = permanently terminated/cashed out).
   - **Act 1 (Hook, `0 -> 1`)**: Ask for a small real sacrifice (e.g., `-15 Gold`) for an item with **zero immediate combat power** (e.g., Raw Cold Iron).
   - **Act 2 (Temptation Fork, `1 -> 9` or `1 -> 2`)**: Offer a juicy immediate cash-out (e.g., `+22 Gold + Common Relic`) that writes `flag = 9` (terminating the chain) versus resisting for a modest temper bonus (`+1 Upgrade`, `flag = 2`).
   - **Act 3 (Doubled Payoff, `2 -> 3`)**: Reward restraint with a signature Rare Relic + free upgrade.
2. **Layer 02 — Guaranteed Priority Queue Injection (`active_chain_continuations` + `seen_events`)**:
   - **Never shuffle active chain continuations back into the regular random "?" pool** — in a 12-event pool across 3 "?" nodes per act, Act 2 reach collapses to ~25% and full Act 3 completion collapses below 10% (>90% abandoned stories!).
   - Before rolling from the regular shuffled pool, compute `active_chain_continuations(currentAct, run.chain_flags)` filtered by `!run.seen_events.includes(id)`.
   - If non-empty, pop the continuation with **100% priority** on the first "?" node of the new act, and record every served event ID in `seen_events` so no filler repeats within a run.
3. **Layer 03 — Scene Asset Aliasing (`SCENE_ALIASES`, 10 Acts -> 4 Scenes)**:
   - Map multi-act story IDs to shared backdrop asset keys via a static dictionary (`SCENE_ALIASES`), e.g.:
     - `cold_iron_1 / cold_iron_2 / cold_iron_3 -> scene_smithy`
     - `meteor_iron_1 / meteor_iron_2 / meteor_iron_3 -> scene_foundry`
     - `demon_spring_1 / demon_spring_2 -> scene_demon_spring`
     - `old_board_1 / old_board_2 -> scene_old_board`
   - Result: **4 cross-act chains (10 distinct narrative acts) reuse 4 master scene illustrations**, cutting event art production cost by **60%** while giving solo devs serialized worldbuilding.

## 2. Verification Checklist
- [ ] Choosing the Act 2 temptation cash-out writes `flag = 9` and guarantees Act 3 continuation never spawns.
- [ ] Choosing Act 1 hook (`flag = 1`) + Act 2 resist (`flag = 2`) achieves **100% Act 2 and Act 3 delivery** across 200 simulated runs when `priorityQueue` is enabled.
- [ ] Regular filler events never repeat within the same run (`seen_events` deduplication).
- [ ] Every chained event ID resolves through `SCENE_ALIASES` to a valid shared backdrop key with `>= 50%` asset reuse savings.
