Expand description
Last-Known Information (LKI) system.
Mirrors Java’s Game.copyLastState() + Game.lastStateBattlefield.
§Overview
The LKI system maintains two types of snapshots to resolve trigger SVars
(e.g. TriggeredCard$CardPower) using a card’s state at the time it was
last on the battlefield:
-
Periodic snapshots (
GameState.last_state_battlefield):- Captured by
copy_last_state()at key checkpoints (phase transitions, before SBAs, before combat) - Lightweight
CardSnapshotstructs for all battlefield cards - Stale snapshots persist after cards leave (for LKI lookups)
- Captured by
-
Per-card LKI (
Card.lki_power/lki_toughness):- Saved in
action.rs::change_zone()when a card leaves the battlefield - Captures the exact power/toughness at zone-change time
- Primary source for trigger SVars
- Saved in
§Resolution hierarchy
When resolving TriggeredCard$CardPower / TriggeredCard$CardToughness:
- Check
card.lki_power/card.lki_toughness(captured at zone change) - If zero, check periodic snapshot (in case card entered after last checkpoint)
- Fall back to zero if neither source has data
§Lifecycle
Card enters battlefield
→ assign zone timestamp
→ update_lki_snapshot() creates/updates periodic snapshot
Phase transition / SBA check
→ copy_last_state() refreshes all battlefield snapshots
Card leaves battlefield (dies, exiled, etc.)
→ action.rs captures lki_power/lki_toughness
→ periodic snapshot remains (stale but valid for LKI)
Trigger fires (e.g. "When ~ dies, deal damage equal to its power")
→ resolve_lki_power() checks lki_power, then periodic snapshot
→ SpellAbility resolves with correct LKI value§Java equivalents
Game.copyLastState()→GameState::copy_last_state()Game.lastStateBattlefield→GameState.last_state_battlefieldCard.getPower()(during trigger) →resolve_lki_power()
Structs§
- Card
Snapshot - Lightweight snapshot of a card’s state on the battlefield.
Captured by
GameState::copy_last_state()at key checkpoints.
Functions§
- resolve_
lki_ counter_ count - Resolve LKI counter count for a trigger source card.
- resolve_
lki_ power - Resolve LKI power for a trigger source card.
- resolve_
lki_ toughness - Resolve LKI toughness for a trigger source card.
- resolve_
triggered_ card_ lki_ property - resolve_
triggered_ card_ lki_ svar - Resolve SVar properties that explicitly ask for triggered-card LKI.