// The Death Creation Step: the one place minions leave play. // // Damage and destroy effects only mark a minion (0 or less Health, or pending // destroy). It stays in play, and keeps triggering, until the outermost Phase // ends. Then this step removes every marked minion at once. import type { Event } from "./event"; import type { EntityId, World } from "./world"; /** * Remove every mortally wounded or pending-destroy minion from play, simultaneously. * Returns their Death Events in order of play; empty if nothing died. */ export function deathCreationStep(world: World): Event[] { const dying = world.minionsInPlay().filter((id) => world.isDoomed(id)); // Every neighbour is read before anything moves: removal is simultaneous. Each Death // Event remembers where its minion stood as a handle, the minion that stays to its // right, not as a board index: an index goes stale as soon as a minion further left // leaves play in the same step (Module 1: hold handles, not indexes). const deaths = dying.map((id) => ({ type: "Destroyed" as const, id, before: survivorToTheRight(world, id) })); for (const { id, before } of deaths) world.kill(id, before); return deaths; } /** The nearest minion to the right of `id` on its board that is not leaving play in this step, if any. */ function survivorToTheRight(world: World, id: EntityId): EntityId | undefined { const board = world.zone(world.ownerOf(id), "board"); return board.slice(board.indexOf(id) + 1).find((other) => !world.isDoomed(other)); }