codekeep 0.8.0 → 0.9.1

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 (2) hide show
  1. package/dist/index.js +6 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import{Command as fo}from"commander";import{render as ho}from"ink";import{useState as C,useCallback as ae,useEffect as lo}from"react";import{Box as Q,Text as f,useApp as io,useInput as co,useStdout as mo}from"ink";var Ve=5,Ae=4,Gt=3,Oe=5,Nt=70,Ke=[{id:"strike",name:"Strike",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 6 damage to an enemy.",effects:[{type:"damage",value:6,target:"single"}]},{id:"guard",name:"Guard",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 5 Block.",effects:[{type:"block",value:5,target:"self"}]},{id:"bolster",name:"Bolster",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 8 Block.",effects:[{type:"block",value:8,target:"self"}]},{id:"spark",name:"Spark",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 4 damage to all enemies in a column.",effects:[{type:"damage",value:4,target:"column"}]},{id:"reinforce",name:"Reinforce",cost:2,type:"cast",category:"fortification",rarity:"common",description:"Gain 15 Block.",effects:[{type:"block",value:15,target:"self"}]},{id:"barrage",name:"Barrage",cost:2,type:"cast",category:"armament",rarity:"common",description:"Deal 6 damage to all enemies.",effects:[{type:"damage",value:6,target:"all"}]},{id:"mend",name:"Mend",cost:1,type:"cast",category:"edict",rarity:"common",description:"Heal 4 Gate HP.",effects:[{type:"heal",value:4,target:"self"}]},{id:"lookout",name:"Lookout",cost:0,type:"cast",category:"edict",rarity:"common",description:"Draw 1 card.",effects:[{type:"draw",value:1}]},{id:"brace",name:"Brace",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 4 Block. Draw 1 card.",effects:[{type:"block",value:4,target:"self"},{type:"draw",value:1}]},{id:"ember",name:"Ember",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 8 damage to an enemy.",effects:[{type:"damage",value:8,target:"single"}]},{id:"slash",name:"Slash",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 5 damage to an enemy. Draw 1 card.",effects:[{type:"damage",value:5,target:"single"},{type:"draw",value:1}]},{id:"rally",name:"Rally",cost:1,type:"cast",category:"edict",rarity:"common",description:"Gain 3 Block. Draw 2 cards.",effects:[{type:"block",value:3,target:"self"},{type:"draw",value:2}]},{id:"salvo",name:"Salvo",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 3 damage to all enemies.",effects:[{type:"damage",value:3,target:"all"}]},{id:"patch",name:"Patch",cost:0,type:"cast",category:"fortification",rarity:"common",description:"Gain 3 Block.",effects:[{type:"block",value:3,target:"self"}]},{id:"flare",name:"Flare",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 6 damage to all enemies in a column.",effects:[{type:"damage",value:6,target:"column"}]},{id:"cleave",name:"Cleave",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 10 damage to an enemy.",effects:[{type:"damage",value:10,target:"single"}]},{id:"iron_wall",name:"Iron Wall",cost:2,type:"cast",category:"fortification",rarity:"uncommon",description:"Gain 16 Block.",effects:[{type:"block",value:16,target:"self"}]},{id:"blitz",name:"Blitz",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 4 damage to an enemy twice.",effects:[{type:"damage",value:4,target:"single"},{type:"damage",value:4,target:"single"}]},{id:"volley",name:"Volley",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 6 damage to all enemies.",effects:[{type:"damage",value:6,target:"all"}]},{id:"resurgence",name:"Resurgence",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Heal 8 Gate HP.",effects:[{type:"heal",value:8,target:"self"}]},{id:"keen_eye",name:"Keen Eye",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Draw 3 cards.",effects:[{type:"draw",value:3}]},{id:"expose",name:"Expose",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Apply 2 Vulnerable to an enemy.",effects:[{type:"vulnerable",value:2,target:"single"}]},{id:"weaken",name:"Weaken",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Apply 2 Weak to an enemy.",effects:[{type:"weak",value:2,target:"single"}]},{id:"bash",name:"Bash",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 7 damage. Apply 1 Vulnerable.",effects:[{type:"damage",value:7,target:"single"},{type:"vulnerable",value:1,target:"single"}]},{id:"shield_bash",name:"Shield Bash",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 6 Block. Deal 3 damage.",effects:[{type:"block",value:6,target:"self"},{type:"damage",value:3,target:"single"}]},{id:"ignite",name:"Ignite",cost:1,type:"cast",category:"armament",rarity:"common",description:"Apply 3 Burn to a column.",effects:[{type:"burn",value:3,target:"column"}]},{id:"scout",name:"Scout",cost:0,type:"cast",category:"edict",rarity:"common",description:"Draw 2 cards.",effects:[{type:"draw",value:2}]},{id:"fortify",name:"Fortify",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 10 Block.",effects:[{type:"block",value:10,target:"self"}]},{id:"sundering_strike",name:"Sundering Strike",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 12 damage. Apply 2 Vulnerable.",effects:[{type:"damage",value:12,target:"single"},{type:"vulnerable",value:2,target:"single"}]},{id:"pale_fire",name:"Pale Fire",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 5 damage to all. Apply 2 Burn.",effects:[{type:"damage",value:5,target:"all"},{type:"burn",value:2,target:"all"}]},{id:"shield_wall",name:"Shield Wall",cost:2,type:"cast",category:"fortification",rarity:"uncommon",description:"Gain 20 Block.",effects:[{type:"block",value:20,target:"self"}]},{id:"battle_cry",name:"Battle Cry",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Gain 1 Resolve. Draw 1 card.",effects:[{type:"resolve",value:1},{type:"draw",value:1}]},{id:"intimidate",name:"Intimidate",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Apply 2 Weak to all enemies.",effects:[{type:"weak",value:2,target:"all"}]},{id:"hemorrhage",name:"Hemorrhage",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 8 damage. Apply 4 Burn.",effects:[{type:"damage",value:8,target:"single"},{type:"burn",value:4,target:"single"}]},{id:"restoration",name:"Restoration",cost:2,type:"cast",category:"edict",rarity:"uncommon",description:"Heal 12 Gate HP. Gain 4 Block.",effects:[{type:"heal",value:12,target:"self"},{type:"block",value:4,target:"self"}]},{id:"precision",name:"Precision",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 10 damage to an enemy. Apply 1 Vulnerable.",effects:[{type:"damage",value:10,target:"single"},{type:"vulnerable",value:1,target:"single"}]},{id:"firestorm",name:"Firestorm",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 8 damage to a column. Apply 3 Burn.",effects:[{type:"damage",value:8,target:"column"},{type:"burn",value:3,target:"column"}]},{id:"deep_guard",name:"Deep Guard",cost:1,type:"cast",category:"fortification",rarity:"uncommon",description:"Gain 7 Block. Draw 1 card.",effects:[{type:"block",value:7,target:"self"},{type:"draw",value:1}]},{id:"inferno",name:"Inferno",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Deal 12 damage to all enemies.",effects:[{type:"damage",value:12,target:"all"}]},{id:"fortress",name:"Fortress",cost:3,type:"cast",category:"fortification",rarity:"rare",description:"Gain 25 Block. Gain 1 Resolve.",effects:[{type:"block",value:25,target:"self"},{type:"resolve",value:1}]},{id:"annihilate",name:"Annihilate",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Deal 20 damage to an enemy.",effects:[{type:"damage",value:20,target:"single"}]},{id:"wardens_wrath",name:"Warden's Wrath",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Deal 8 damage to all. Apply 2 Vulnerable to all.",effects:[{type:"damage",value:8,target:"all"},{type:"vulnerable",value:2,target:"all"}]},{id:"iron_bastion",name:"Iron Bastion",cost:3,type:"cast",category:"fortification",rarity:"rare",description:"Gain 30 Block. Heal 5.",effects:[{type:"block",value:30,target:"self"},{type:"heal",value:5,target:"self"}]},{id:"rally_the_keep",name:"Rally the Keep",cost:2,type:"cast",category:"edict",rarity:"rare",description:"Draw 4 cards. Gain 1 Resolve.",effects:[{type:"draw",value:4},{type:"resolve",value:1}]},{id:"conflagration",name:"Conflagration",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Apply 6 Burn to all enemies. Deal 5 damage to all.",effects:[{type:"burn",value:6,target:"all"},{type:"damage",value:5,target:"all"}]},{id:"pale_ward",name:"Pale Ward",cost:2,type:"cast",category:"fortification",rarity:"rare",description:"Gain 15 Block. Apply 2 Weak to all enemies.",effects:[{type:"block",value:15,target:"self"},{type:"weak",value:2,target:"all"}]},{id:"cataclysm",name:"Cataclysm",cost:4,type:"cast",category:"armament",rarity:"legendary",description:"Deal 30 damage to all enemies. Take 10 Gate damage.",effects:[{type:"damage",value:30,target:"all"},{type:"self_damage",value:10}]},{id:"keeps_resolve",name:"Keep's Resolve",cost:0,type:"cast",category:"edict",rarity:"legendary",description:"Gain 2 Resolve. Draw 2 cards. Gain 10 Block.",effects:[{type:"resolve",value:2},{type:"draw",value:2},{type:"block",value:10,target:"self"}]},{id:"eternal_wall",name:"Eternal Wall",cost:4,type:"cast",category:"fortification",rarity:"legendary",description:"Gain 50 Block. Heal 10 Gate HP.",effects:[{type:"block",value:50,target:"self"},{type:"heal",value:10,target:"self"}]},{id:"barricade",name:"Barricade",cost:1,type:"emplace",category:"fortification",rarity:"common",description:"Cast: Gain 4 Block. Emplace: 8 HP structure, +2 Block/turn.",effects:[{type:"block",value:4,target:"self"}],emplaceCost:1,emplaceHp:8,emplaceEffects:[{type:"block",value:2,target:"self"}]},{id:"turret",name:"Turret",cost:2,type:"emplace",category:"armament",rarity:"uncommon",description:"Cast: Deal 5 damage. Emplace: 6 HP, deals 3 damage to column/turn.",effects:[{type:"damage",value:5,target:"single"}],emplaceCost:2,emplaceHp:6,emplaceEffects:[{type:"damage",value:3,target:"column"}]},{id:"beacon",name:"Beacon",cost:1,type:"emplace",category:"edict",rarity:"uncommon",description:"Cast: Draw 1 card. Emplace: 5 HP, heals 2 Gate HP/turn.",effects:[{type:"draw",value:1}],emplaceCost:1,emplaceHp:5,emplaceEffects:[{type:"heal",value:2,target:"self"}]},{id:"ward_stone",name:"Ward Stone",cost:1,type:"emplace",category:"fortification",rarity:"common",description:"Cast: Gain 3 Block. Emplace: 10 HP, applies 1 Weak to enemies in column.",effects:[{type:"block",value:3,target:"self"}],emplaceCost:1,emplaceHp:10,emplaceEffects:[{type:"weak",value:1,target:"column"}]},{id:"siphon",name:"Siphon",cost:2,type:"emplace",category:"wild",rarity:"rare",description:"Cast: Deal 4 damage to all. Emplace: 4 HP, deals 2 damage to adjacent columns.",effects:[{type:"damage",value:4,target:"all"}],emplaceCost:2,emplaceHp:4,emplaceEffects:[{type:"damage",value:2,target:"adjacent"}]},{id:"watchtower",name:"Watchtower",cost:1,type:"emplace",category:"edict",rarity:"common",description:"Cast: Draw 2 cards. Emplace: 4 HP, applies 1 Vulnerable to enemies in column.",effects:[{type:"draw",value:2}],emplaceCost:1,emplaceHp:4,emplaceEffects:[{type:"vulnerable",value:1,target:"column"}]},{id:"flame_pit",name:"Flame Pit",cost:2,type:"emplace",category:"armament",rarity:"uncommon",description:"Cast: Deal 6 damage to column. Emplace: 5 HP, deals 4 damage to column/turn.",effects:[{type:"damage",value:6,target:"column"}],emplaceCost:2,emplaceHp:5,emplaceEffects:[{type:"damage",value:4,target:"column"}]},{id:"bulwark",name:"Bulwark",cost:2,type:"emplace",category:"fortification",rarity:"rare",description:"Cast: Gain 10 Block. Emplace: 15 HP, +3 Block/turn.",effects:[{type:"block",value:10,target:"self"}],emplaceCost:2,emplaceHp:15,emplaceEffects:[{type:"block",value:3,target:"self"}]},{id:"spike_trap",name:"Spike Trap",cost:1,type:"emplace",category:"armament",rarity:"common",description:"Cast: Deal 3 damage. Emplace: 3 HP, deals 2 damage to column/turn.",effects:[{type:"damage",value:3,target:"single"}],emplaceCost:1,emplaceHp:3,emplaceEffects:[{type:"damage",value:2,target:"column"}]},{id:"sanctum",name:"Sanctum",cost:3,type:"emplace",category:"edict",rarity:"rare",description:"Cast: Heal 6, draw 1. Emplace: 8 HP, heals 3 Gate HP/turn, +1 Block/turn.",effects:[{type:"heal",value:6,target:"self"},{type:"draw",value:1}],emplaceCost:3,emplaceHp:8,emplaceEffects:[{type:"heal",value:3,target:"self"},{type:"block",value:1,target:"self"}]},{id:"emplacement_surge",name:"Emplacement Surge",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Each emplacement triggers its effect an extra time.",effects:[{type:"trigger_emplacements",value:1}]},{id:"fuel_the_fire",name:"Fuel the Fire",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 2 damage per Burn stack on all enemies.",effects:[{type:"damage_per_burn",value:2,target:"all"}]},{id:"fortified_assault",name:"Fortified Assault",cost:2,type:"cast",category:"armament",rarity:"rare",description:"Deal damage equal to your current Block.",effects:[{type:"damage_equal_block",value:1,target:"single"}]},{id:"pale_harvest",name:"Pale Harvest",cost:0,type:"cast",category:"edict",rarity:"uncommon",description:"Draw 1 card per enemy killed this combat. Exhaust.",effects:[{type:"draw_per_kills",value:1},{type:"exhaust_self",value:1}]},{id:"wall_breaker",name:"Wall Breaker",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 8 damage. If target is Vulnerable, deal 16 instead.",effects:[{type:"damage_if_vulnerable",value:8,target:"single"}]},{id:"chain_lightning",name:"Chain Lightning",cost:2,type:"cast",category:"armament",rarity:"rare",description:"Deal 5 damage to all enemies. For each killed, deal 5 more to all.",effects:[{type:"damage",value:5,target:"all"},{type:"damage_per_kill_this_action",value:5,target:"all"}]},{id:"recycle",name:"Recycle",cost:1,type:"cast",category:"edict",rarity:"common",description:"Exhaust a card from hand, draw 2.",effects:[{type:"exhaust_draw",value:2}]},{id:"keepers_ward",name:"Keeper's Ward",cost:1,type:"emplace",category:"fortification",rarity:"uncommon",description:"Cast: Gain 5 Block. Emplace: 6 HP, gives +1 damage to adjacent emplacements/turn.",effects:[{type:"block",value:5,target:"self"}],emplaceCost:1,emplaceHp:6,emplaceEffects:[{type:"damage",value:1,target:"adjacent"}]},{id:"combustion",name:"Combustion",cost:2,type:"cast",category:"armament",rarity:"rare",description:"Apply 4 Burn to all enemies. If any already has Burn, apply 6 instead.",effects:[{type:"burn_if_burning",value:4,target:"all"}]},{id:"bulwark_strike",name:"Bulwark Strike",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 4 damage + 1 per point of Block you have (max +10).",effects:[{type:"damage_plus_block",value:4,target:"single"}]},{id:"pale_echo",name:"Pale Echo",cost:2,type:"cast",category:"wild",rarity:"rare",description:"Play the last card you played again (copy its effects).",effects:[{type:"replay_last",value:1}]},{id:"column_collapse",name:"Column Collapse",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 12 damage to all enemies in target column. If column has an emplacement, deal 18 instead.",effects:[{type:"damage_if_emplaced",value:12,target:"column"}]},{id:"overcharge",name:"Overcharge",cost:0,type:"cast",category:"edict",rarity:"uncommon",description:"Gain 2 Resolve. Exhaust.",effects:[{type:"resolve",value:2},{type:"exhaust_self",value:1}]},{id:"desperate_strike",name:"Desperate Strike",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 5 damage. If Gate HP < 50%, deal 10 instead.",effects:[{type:"damage_if_low_hp",value:5,target:"single"}]},{id:"fortress_keeper",name:"Fortress Keeper",cost:3,type:"emplace",category:"fortification",rarity:"rare",description:"Cast: Gain 15 Block, draw 1. Emplace: 12 HP, +4 Block/turn, adjacent emplacements +2 HP.",effects:[{type:"block",value:15,target:"self"},{type:"draw",value:1}],emplaceCost:3,emplaceHp:12,emplaceEffects:[{type:"block",value:4,target:"self"}]},{id:"resonance",name:"Resonance",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 3 damage to all enemies for each emplacement you control.",effects:[{type:"damage_per_emplace",value:3,target:"all"}]},{id:"scavenge",name:"Scavenge",cost:0,type:"cast",category:"edict",rarity:"common",description:"Draw cards equal to number of empty potion slots.",effects:[{type:"draw_per_empty_potions",value:1}]},{id:"final_stand",name:"Final Stand",cost:3,type:"cast",category:"wild",rarity:"legendary",description:"Deal 10 damage to all. Gain 10 Block. Draw 3. Exhaust.",effects:[{type:"damage",value:10,target:"all"},{type:"block",value:10,target:"self"},{type:"draw",value:3},{type:"exhaust_self",value:1}]},{id:"pale_curse",name:"Pale Curse",cost:99,type:"cast",category:"wild",rarity:"common",description:"An echo of the Pale. Unplayable. Clogs your hand.",effects:[]}],ka=["strike","strike","strike","guard","guard","spark","ember","brace","bolster","mend"];function O(e){return Ke.find(t=>t.id===e)}var $n=[{id:"hollow",name:"Hollow",symbol:"\u2620",hp:18,damage:6,speed:1,act:1,description:"An empty shape from the Pale. Advances steadily."},{id:"needle",name:"Needle",symbol:"\u2191",hp:10,damage:4,speed:2,act:1,description:"Fast and fragile. Advances two rows per turn."},{id:"shade",name:"Shade",symbol:"\u25C8",hp:22,damage:8,speed:1,act:1,description:"A dense fragment of the Pale. Hits hard."},{id:"wisp",name:"Wisp",symbol:"\u25CB",hp:8,damage:3,speed:1,act:1,description:"Fragile but numerous. Appears in swarms."},{id:"husk",name:"Husk",symbol:"\u2593",hp:30,damage:5,speed:1,act:1,description:"Armored shell. Slow but resilient."},{id:"wraith",name:"Wraith",symbol:"\u2248",hp:15,damage:7,speed:2,act:2,description:"Drifts through emplacements. Ignores structures."},{id:"breaker",name:"Breaker",symbol:"\u2692",hp:25,damage:10,speed:1,act:2,description:"Targets emplacements first. Destroys structures."},{id:"flanker",name:"Flanker",symbol:"\u2194",hp:14,damage:6,speed:1,act:2,description:"Shifts columns before attacking."},{id:"shielder",name:"Shielder",symbol:"\u25C7",hp:20,damage:4,speed:1,act:2,description:"Grants shield to adjacent enemies."},{id:"echo",name:"Echo",symbol:"\u221E",hp:35,damage:12,speed:1,act:3,description:"A memory of something that should not exist."},{id:"boss_suture",name:"The Suture",symbol:"\u25C8",hp:60,damage:8,speed:1,act:1,description:"Stitched from fragments of the Pale. The first true threat."},{id:"boss_archivist",name:"The Archivist",symbol:"\u25A3",hp:90,damage:10,speed:1,act:2,description:"Keeper of forgotten records. Debuffs and shields methodically."},{id:"boss_pale",name:"The Pale Itself",symbol:"\u25C9",hp:130,damage:12,speed:1,act:3,description:"The void given form. Three phases of escalating horror."}];function de(e){return $n.find(t=>t.id===e)}var Le=[{id:"heal_potion",name:"Mending Draught",description:"Heal 15 Gate HP.",effects:[{type:"heal",value:15,target:"self"}]},{id:"damage_potion",name:"Fire Flask",description:"Deal 10 damage to all enemies in a column.",effects:[{type:"damage",value:10,target:"column"}]},{id:"block_potion",name:"Iron Tonic",description:"Gain 15 Block.",effects:[{type:"block",value:15,target:"self"}]},{id:"draw_potion",name:"Seer's Ink",description:"Draw 3 cards.",effects:[{type:"draw",value:3}]},{id:"resolve_potion",name:"Warden's Flame",description:"Gain 2 Resolve this turn.",effects:[{type:"resolve",value:2}]}],it={combat:15,elite:30,boss:50},Vn=[{npcId:"wren",tier:0,lines:[{id:"wren_t0_1",speaker:"Wren",text:"Welcome to the Keep, Warden. I maintain what's left of it."},{id:"wren_t0_2",speaker:"Wren",text:"The Pale has been encroaching for years now. Each run pushes it back \u2014 a little."},{id:"wren_t0_3",speaker:"Wren",text:"The Echoes you bring back... they're more than currency. They're fragments of what the Pale has consumed."}]},{npcId:"wren",tier:1,lines:[{id:"wren_t1_1",speaker:"Wren",text:"You're doing well, Warden. The Keep grows stronger."},{id:"wren_t1_2",speaker:"Wren",text:"I've been organizing the archives. There are records of other keeps \u2014 all fallen."},{id:"wren_t1_3",speaker:"Wren",text:"Did you know the Pale wasn't always like this? Sable might tell you more."},{id:"wren_t1_4",speaker:"Wren",text:"The structures you build... I can feel them resonate. Like the Keep remembers what it was."}]},{npcId:"wren",tier:2,lines:[{id:"wren_t2_1",speaker:"Wren",text:"I found something in the lower chambers. A journal. The previous Warden's."},{id:"wren_t2_2",speaker:"Wren",text:'"The Pale does not destroy," they wrote. "It remembers \u2014 and in remembering, unmakes."'},{id:"wren_t2_3",speaker:"Wren",text:"I think this Keep has been here longer than any of us know."}]},{npcId:"wren",tier:3,lines:[{id:"wren_t3_1",speaker:"Wren",text:"Warden. I need to tell you something. The Pale Visitor... they're not what they seem."},{id:"wren_t3_2",speaker:"Wren",text:"I've been tracking the patterns. Every fifty runs, the Pale shifts. Something deeper stirs."}]},{npcId:"wren",tier:4,lines:[{id:"wren_t4_1",speaker:"Wren",text:"The truth is... there have been many Wardens. You're not the first. And you won't be the last."},{id:"wren_t4_2",speaker:"Wren",text:"Unless you find the source. The thing the Pale is actually looking for."}]},{npcId:"sable",tier:0,lines:[{id:"sable_t0_1",speaker:"Sable",text:"Hmm? Oh, another Warden. The Archive is open, if you can read the old script."},{id:"sable_t0_2",speaker:"Sable",text:"Cards, Warden. That's what the old records call them. Patterns of power, crystallized."},{id:"sable_t0_3",speaker:"Sable",text:"The Pale erases. But patterns \u2014 true patterns \u2014 resist erasure. That's what your deck is."}]},{npcId:"sable",tier:1,lines:[{id:"sable_t1_1",speaker:"Sable",text:"I've decoded another section. The Pale isn't natural. It was created."},{id:"sable_t1_2",speaker:"Sable",text:"Someone \u2014 or something \u2014 made the Pale as a weapon. Against what, I don't yet know."},{id:"sable_t1_3",speaker:"Sable",text:"The emplacements you build... they're based on ancient designs. The old Keep had them too."}]},{npcId:"sable",tier:2,lines:[{id:"sable_t2_1",speaker:"Sable",text:'I found it. A name: "The Architect." They built the first Keep \u2014 and the first Pale.'},{id:"sable_t2_2",speaker:"Sable",text:"The Architect wanted to preserve everything. So they built a system that remembers. Perfectly."},{id:"sable_t2_3",speaker:"Sable",text:"A perfect memory is indistinguishable from a prison, Warden."}]},{npcId:"sable",tier:3,lines:[{id:"sable_t3_1",speaker:"Sable",text:"The bosses you fight... they're not monsters. They're memories. The Suture, the Archivist..."},{id:"sable_t3_2",speaker:"Sable",text:"Wait. The Archivist. That's my title. Why is there a boss named after my role?"}]},{npcId:"sable",tier:4,lines:[{id:"sable_t4_1",speaker:"Sable",text:"I cross-referenced myself against the Archive records. The result was... recursive."},{id:"sable_t4_2",speaker:"Sable",text:"The original Archivist's handwriting. It's identical to mine. Not similar \u2014 identical."},{id:"sable_t4_3",speaker:"Sable",text:"I'm not afraid that I'm a copy, Warden. I'm afraid that the copy was an improvement."}]},{npcId:"sable",tier:5,lines:[{id:"sable_t5_1",speaker:"Sable",text:"I found something in the Archive today. A letter, addressed to me. In my handwriting. Dated three hundred years ago."},{id:"sable_t5_2",speaker:"Sable",text:"It said: 'When you find this, stop looking. Some records exist to be lost.'"},{id:"sable_t5_3",speaker:"Sable",text:"I've decided to keep cataloguing. Not because I have to. Because it's the only thing I do that the original never did."}]},{npcId:"duskmar",tier:0,lines:[{id:"dusk_t0_1",speaker:"Duskmar",text:"I was the first to man these walls. And I'll be the last, if it comes to that."},{id:"dusk_t0_2",speaker:"Duskmar",text:"The Hollows are nothing. Wait until you face the Shades. Or the things in Act 3."},{id:"dusk_t0_3",speaker:"Duskmar",text:"Block. Always block. The Pale punishes the reckless."}]},{npcId:"duskmar",tier:1,lines:[{id:"dusk_t1_1",speaker:"Duskmar",text:"I've been teaching the walls to remember. Emplacements \u2014 that's the real defense."},{id:"dusk_t1_2",speaker:"Duskmar",text:"Every time you ascend, the Pale gets smarter. But so do you."}]},{npcId:"duskmar",tier:2,lines:[{id:"dusk_t2_1",speaker:"Duskmar",text:"I died once, you know. In the Pale. Wren brought me back with Echoes."},{id:"dusk_t2_2",speaker:"Duskmar",text:"Death isn't permanent here. That should worry you more than it comforts you."}]},{npcId:"duskmar",tier:4,lines:[{id:"duskmar_t4_1",speaker:"Duskmar",text:"I remember dying, Warden. Not the pain \u2014 that faded. The silence after."},{id:"duskmar_t4_2",speaker:"Duskmar",text:"When they brought me back, I could feel the Pale filling the gaps where memories should be. Cold, like water in a cracked foundation."},{id:"duskmar_t4_3",speaker:"Duskmar",text:"I don't block because I'm brave. I block because I know exactly what it costs to fall."}]},{npcId:"mott",tier:0,lines:[{id:"mott_t0_1",speaker:"Mott",text:"Fragments! Echoes! Bits and pieces of a world that doesn't exist anymore!"},{id:"mott_t0_2",speaker:"Mott",text:"I trade in what the Pale leaves behind. Potions, mostly. Sometimes relics."},{id:"mott_t0_3",speaker:"Mott",text:"The shop in the Pale? That's me. Well, a memory of me. It's complicated."}]},{npcId:"mott",tier:1,lines:[{id:"mott_t1_1",speaker:"Mott",text:"Found something odd today. A card that doesn't match any pattern I've seen."},{id:"mott_t1_2",speaker:"Mott",text:"The relics aren't just powerful. They're pieces of the old world. Before the Pale."}]},{npcId:"mott",tier:2,lines:[{id:"mott_t2_1",speaker:"Mott",text:"I figured it out. The fragments? They're not resources. They're memories \u2014 compressed."},{id:"mott_t2_2",speaker:"Mott",text:"When you spend fragments, you're spending someone's past. Heavy, right?"}]},{npcId:"mott",tier:4,lines:[{id:"mott_t4_1",speaker:"Mott",text:"I can't sell this one. It's... it's someone's last birthday. The whole day, compressed into a shard."},{id:"mott_t4_2",speaker:"Mott",text:"You ever wonder if we're the good guys, Warden? Spending people's pasts like pocket change?"},{id:"mott_t4_3",speaker:"Mott",text:"Found a fragment today that tasted like rain. Don't ask me how I know that. Don't ask me why I cried."}]},{npcId:"pale_visitor",tier:0,lines:[{id:"pv_t0_1",speaker:"???",text:"..."},{id:"pv_t0_2",speaker:"???",text:"You can see me. Interesting. Most Wardens take longer."}]},{npcId:"pale_visitor",tier:1,lines:[{id:"pv_t1_1",speaker:"The Visitor",text:"Do you know why the Keep exists, Warden?"},{id:"pv_t1_2",speaker:"The Visitor",text:"Not to fight the Pale. To contain it. There's a difference."}]},{npcId:"pale_visitor",tier:2,lines:[{id:"pv_t2_1",speaker:"The Visitor",text:"I am the Pale. Or I was. The part of it that wanted to stop."},{id:"pv_t2_2",speaker:"The Visitor",text:"Every run you complete, you weaken the whole. But you also feed it."}]},{npcId:"pale_visitor",tier:3,lines:[{id:"pv_t3_1",speaker:"The Visitor",text:"The Architect built me as a failsafe. I was supposed to shut it all down."},{id:"pv_t3_2",speaker:"The Visitor",text:"But I can't. Not alone. That's why I need a Warden."}]},{npcId:"pale_visitor",tier:4,lines:[{id:"pv_t4_1",speaker:"The Visitor",text:"There is a place where the Pale is thin enough to see through. You will know it when the game stops feeling like a game."},{id:"pv_t4_2",speaker:"The Visitor",text:"The Architect left two doors. One leads out. One leads deeper. Both are locked from the inside."},{id:"pv_t4_3",speaker:"The Visitor",text:"You're closer than any Warden has been. That's not a compliment. It's a warning."}]},{npcId:"pale_visitor",tier:5,lines:[{id:"pv_t5_1",speaker:"???",text:"The Pale doesn't consume. It remembers. And a memory that remembers itself..."},{id:"pv_t5_2",speaker:"???",text:"You've seen the Architect's journal. You know what they tried to build. Do you understand what they actually built?"},{id:"pv_t5_3",speaker:"???",text:"The Keep is not a fortress, Warden. It's an argument. Against eternity. And you are its latest word."}]}];function On(e,t){return Vn.filter(a=>a.npcId===e&&a.tier<=t).flatMap(a=>a.lines)}function _a(e,t,n){let a=On(e,t),r=new Set(n);return a.filter(o=>!r.has(o.id))}import{writeFileSync as Vt,readFileSync as _r,mkdirSync as Tr,existsSync as Qt,renameSync as xr,unlinkSync as Ir}from"fs";import{join as ja,dirname as Cr}from"path";import{homedir as Sr}from"os";function N(e){let t=e|0;return()=>{t=t+1831565813|0;let n=Math.imul(t^t>>>15,1|t);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function ee(e){let t=0;for(let n=0;n<e.length;n++){let a=e.charCodeAt(n);t=(t<<5)-t+a|0}return t}function xa(e,t){let n=[...e];for(let a=n.length-1;a>0;a--){let r=Math.floor(t()*(a+1));[n[a],n[r]]=[n[r],n[a]]}return n}var Kn=1;function qe(e){return{instanceId:`card-${Kn++}`,defId:e,upgraded:!1}}function Kt(){return ka.map(qe)}function Ln(e,t){return xa(e,t)}function pe(e,t,n,a){let r=[],o=[...e],l=[...t];for(let d=0;d<n;d++){if(o.length===0){if(l.length===0)break;o=xa(l,a),l=[]}r.push(o.shift())}return{drawn:r,newDrawPile:o,newDiscardPile:l}}var Un=[{templateId:"boss_suture",name:"The Suture",act:1,phases:[{hpThreshold:1,intentPattern:[{type:"attack",value:8},{type:"advance",value:1},{type:"attack",value:12}]},{hpThreshold:.5,intentPattern:[{type:"attack",value:15},{type:"summon",value:2},{type:"attack",value:10}]}],dialogue:[{storyLayer:"surface",onAppear:"I will stitch this Keep into silence.",onDefeat:"Unraveled... but the thread remains..."},{storyLayer:"cracks",onAppear:"You again. How many times have we done this?",onPhaseChange:"I remember you. Every time."},{storyLayer:"truth",onAppear:"I was a warden once. Before the stitching."}],onPhaseChange:(e,t,n)=>{let a=e.columns[2];a.enemies.length<3&&a.enemies.push(Ut("needle",2))}},{templateId:"boss_archivist",name:"The Archivist",act:2,phases:[{hpThreshold:1,intentPattern:[{type:"debuff",value:2},{type:"attack",value:10},{type:"shield",value:15}]},{hpThreshold:.5,intentPattern:[{type:"attack",value:18},{type:"debuff",value:3},{type:"summon",value:3}]}],dialogue:[{storyLayer:"surface",onAppear:"Everything must be recorded. Including your defeat.",onDefeat:"The records... will continue... without me..."},{storyLayer:"cracks",onAppear:"Sable? Is that... no. Not yet. Not this time."},{storyLayer:"truth",onAppear:"I am what Sable will become. I am what the Archive demands."}]},{templateId:"boss_pale",name:"The Pale Itself",act:3,phases:[{hpThreshold:1,intentPattern:[{type:"attack",value:12},{type:"advance",value:1},{type:"summon",value:2}]},{hpThreshold:.6,intentPattern:[{type:"attack",value:20},{type:"debuff",value:3},{type:"attack",value:15}]},{hpThreshold:.3,intentPattern:[{type:"attack",value:25},{type:"summon",value:3},{type:"attack",value:20}]}],dialogue:[{storyLayer:"surface",onAppear:"I am the memory of everything. And everything remembers its end."},{storyLayer:"cracks",onAppear:"You've learned to read the patterns. But patterns are cages too."},{storyLayer:"truth",onAppear:"The Architect made me to preserve. I preserved so perfectly that nothing could change. Is that not love?"},{storyLayer:"true_ending",onAppear:"You carry the same question the Architect carried. The answer hasn't changed. Only the one asking."}],onPhaseChange:(e,t,n)=>{if(n>=2)for(let a of e.columns)for(let r of a.enemies){let o=r.statusEffects.find(l=>l.type==="empowered");o?o.stacks+=1:r.statusEffects.push({type:"empowered",stacks:1,duration:99})}}}];function Lt(e){return Un.find(t=>t.act===e)}function qn(e,t,n){let a=e.phases[0];for(let o of e.phases)t<=o.hpThreshold&&(a=o);let r=(n-1)%a.intentPattern.length;return a.intentPattern[r]}function Ia(e){switch(e){case 1:return[{templateId:"boss_suture",column:2},{templateId:"hollow",column:0},{templateId:"hollow",column:4}];case 2:return[{templateId:"boss_archivist",column:2},{templateId:"wraith",column:1},{templateId:"wraith",column:3}];case 3:return[{templateId:"boss_pale",column:2},{templateId:"echo",column:0},{templateId:"echo",column:4}];default:return[{templateId:"boss_suture",column:2}]}}var jn=1;function Ut(e,t){let n=de(e);if(!n)throw new Error(`Unknown enemy template: ${e}`);return{instanceId:`enemy-${jn++}`,templateId:e,hp:n.hp,maxHp:n.hp,column:Math.max(0,Math.min(t,Ve-1)),row:0,intent:null,statusEffects:[]}}function qt(e,t,n=1,a=!1){let r=de(e.templateId);if(!r)return{type:"advance",value:1};let o=Lt(r.act);if(o&&o.templateId===e.templateId){let d=e.hp/e.maxHp;return qn(o,d,n)}let l=t();switch(e.templateId){case"shielder":return l<.3?{type:"shield",value:5}:l<.6?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"flanker":return l<.4?{type:"attack",value:r.damage,targetColumn:e.column}:l<.7?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"breaker":return a?{type:"advance",value:r.speed}:l<.6?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"wraith":return l<.4?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"echo":return l<.3?{type:"buff",value:1}:l<.6?{type:"attack",value:r.damage,targetColumn:e.column}:{type:"advance",value:r.speed};default:return l<.5?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column}}}function zn(e,t,n,a=0){if(n<0||n>=e.columns.length||e.columns[n].emplacement||!t.emplaceHp||!t.emplaceEffects)return!1;let r=t.emplaceHp+a;return e.columns[n].emplacement={cardDefId:t.id,hp:r,maxHp:r,effects:t.emplaceEffects},e.events.push({type:"emplacement_placed",turn:e.turn,data:{cardId:t.id,column:n}}),!0}function Ca(e){let t=e.columns.filter(n=>n.emplacement).length;for(let n of e.columns){if(!n.emplacement)continue;for(let l of n.emplacement.effects)Yn(e,n.index,l);let a=n.index>0&&e.columns[n.index-1].emplacement,r=n.index<e.columns.length-1&&e.columns[n.index+1].emplacement,o=(a?1:0)+(r?1:0);if(o>0)for(let l of n.emplacement.effects){if(l.type==="damage")for(let d of n.enemies)d.hp-=o;l.type==="block"&&(e.gateBlock+=o)}t>=3&&(e.gateBlock+=t),e.events.push({type:"emplacement_triggered",turn:e.turn,data:{column:n.index,cardId:n.emplacement.cardDefId,adjacencyBonus:o}})}}function Yn(e,t,n){let a=e.columns[t];switch(n.type){case"damage":{if(n.target==="column")for(let r of a.enemies)r.hp-=n.value;else if(n.target==="adjacent")for(let r=Math.max(0,t-1);r<=Math.min(e.columns.length-1,t+1);r++)for(let o of e.columns[r].enemies)o.hp-=n.value;else for(let r of a.enemies)r.hp-=n.value;break}case"block":e.gateBlock+=n.value;break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+n.value);break;case"weak":for(let r of a.enemies){let o=r.statusEffects.find(l=>l.type==="weak");o?o.stacks+=n.value:r.statusEffects.push({type:"weak",stacks:n.value,duration:2})}break;case"vulnerable":for(let r of a.enemies){let o=r.statusEffects.find(l=>l.type==="vulnerable");o?o.stacks+=n.value:r.statusEffects.push({type:"vulnerable",stacks:n.value,duration:2})}break}}function Xn(e,t,n){let a=e.columns[t];if(!a.emplacement||!n.emplaceHp||!n.emplaceEffects)return!1;a.emplacement.hp+=Math.floor(n.emplaceHp/2),a.emplacement.maxHp+=Math.floor(n.emplaceHp/2);for(let r of n.emplaceEffects){let o=a.emplacement.effects.find(l=>l.type===r.type&&l.target===r.target);o?o.value+=Math.floor(r.value/2):a.emplacement.effects.push({...r,value:Math.floor(r.value/2)})}return e.events.push({type:"emplacement_placed",turn:e.turn,data:{cardId:n.id,column:t,reinforced:!0}}),!0}function Jn(e){e.statusEffects=e.statusEffects.map(t=>({...t,duration:t.duration-1})).filter(t=>t.duration>0&&t.stacks>0)}function q(e,t,n,a=2){let r=e.statusEffects.find(o=>o.type===t);r?(r.stacks+=n,r.duration=Math.max(r.duration,a)):e.statusEffects.push({type:t,stacks:n,duration:a})}function re(e,t){return e.statusEffects.find(a=>a.type===t)?.stacks??0}function Qn(e){let t=1,n=re(e,"vulnerable");n>0&&(t*=1+n*.25);let a=re(e,"fortified");return a>0&&(t*=Math.max(.25,1-a*.15)),t}function Zn(e){let t=1,n=re(e,"weak");return n>0&&(t*=Math.max(.25,1-n*.15)),re(e,"empowered")>0&&(t*=1+re(e,"empowered")*.25),t}function er(e){let t=re(e,"burn");if(t>0){e.hp-=t;let n=e.statusEffects.find(a=>a.type==="burn");return n&&(n.stacks=Math.max(0,n.stacks-1)),t}return 0}var Sa=[{id:"wardens_signet",name:"Warden's Signet",description:"+1 max Resolve.",trigger:"passive",effect:{type:"max_resolve_bonus",value:1}},{id:"column_keystone",name:"Column Keystone",description:"When you emplace, gain 8 Block.",trigger:"on_emplace",effect:{type:"block_on_emplace",value:8}},{id:"echo_shard",name:"Echo Shard",description:"When an enemy dies, deal 3 damage to all enemies in same column.",trigger:"on_enemy_kill",effect:{type:"deal_damage_column",value:3}},{id:"pale_lens",name:"Pale Lens",description:"At combat start, apply 1 Vulnerable to all enemies.",trigger:"on_combat_start",effect:{type:"apply_vulnerable_all",value:1}},{id:"burnished_shield",name:"Burnished Shield",description:"At turn start, if Resolve is 0, gain 8 Block.",trigger:"on_turn_start",effect:{type:"gain_block",value:8}},{id:"ember_crown",name:"Ember Crown",description:"When an enemy dies from Burn, apply 2 Burn to all enemies.",trigger:"on_enemy_kill",effect:{type:"burn_on_kill",value:2}},{id:"architects_blueprint",name:"Architect's Blueprint",description:"Emplacements gain +4 HP.",trigger:"passive",effect:{type:"emplace_hp_bonus",value:4}},{id:"ironwood_staff",name:"Ironwood Staff",description:"Draw 1 extra card each turn.",trigger:"on_turn_start",effect:{type:"draw_cards",value:1}},{id:"siege_engine",name:"Siege Engine",description:"Your first card each turn costs 0 Resolve.",trigger:"on_turn_start",effect:{type:"first_card_free",value:1}},{id:"pale_compass",name:"Pale Compass",description:"After elite kills, gain a card reward.",trigger:"on_elite_kill",effect:{type:"extra_card_reward",value:1}},{id:"fragment_magnet",name:"Fragment Magnet",description:"Gain +5 fragments per combat.",trigger:"passive",effect:{type:"fragment_bonus",value:5}},{id:"hexproof_seal",name:"Hexproof Seal",description:"At combat start, gain 10 Block.",trigger:"on_combat_start",effect:{type:"gain_block",value:10}},{id:"war_drum",name:"War Drum",description:"At combat start, apply 1 Weak to all enemies.",trigger:"on_combat_start",effect:{type:"apply_weak_all",value:1}},{id:"living_wall",name:"Living Wall",description:"When you emplace, draw 2 cards.",trigger:"on_emplace",effect:{type:"draw_cards",value:2}},{id:"siphon_ring",name:"Siphon Ring",description:"On card play, if card costs 2+, heal 2 Gate HP.",trigger:"on_card_play",effect:{type:"heal",value:2}},{id:"void_prism",name:"Void Prism",description:"At turn start, deal 2 damage to all enemies.",trigger:"on_turn_start",effect:{type:"deal_damage_all",value:2}},{id:"watchers_eye",name:"Watcher's Eye",description:"At combat start, draw 2 extra cards.",trigger:"on_combat_start",effect:{type:"draw_cards",value:2}},{id:"fortress_heart",name:"Fortress Heart",description:"Emplacements gain +3 HP.",trigger:"passive",effect:{type:"emplace_hp_bonus",value:3}},{id:"mending_stone",name:"Mending Stone",description:"After combat, heal 5 Gate HP.",trigger:"passive",effect:{type:"heal",value:5}},{id:"pale_harvester",name:"Pale Harvester",description:"On enemy kill, gain 1 Resolve (cap at max+2).",trigger:"on_enemy_kill",effect:{type:"gain_resolve",value:1}}];function dt(e){return Sa.find(t=>t.id===e)}function Ea(e,t,n=3){let a=Sa.filter(l=>!t.includes(l.id)),r=[],o=[...a];for(let l=0;l<n&&o.length>0;l++){let d=Math.floor(e()*o.length);r.push(o[d]),o.splice(d,1)}return r}function Ue(e,t,n,a){for(let r of t){let o=dt(r);if(!(!o||o.trigger!==n))switch(o.effect.type){case"gain_block":{if(r==="burnished_shield"&&e.resolve>0)break;e.gateBlock+=o.effect.value,e.events.push({type:"block_gained",turn:e.turn,data:{value:o.effect.value,relic:r}});break}case"gain_resolve":{let l=e.maxResolve+2;e.resolve=Math.min(l,e.resolve+o.effect.value);break}case"draw_cards":{let{drawCards:l}=nr(),{drawn:d,newDrawPile:s,newDiscardPile:p}=l(e.drawPile,e.discardPile,o.effect.value,tr(e));e.hand.push(...d),e.drawPile=s,e.discardPile=p;break}case"deal_damage_all":{for(let l of e.columns)for(let d of l.enemies)d.hp-=o.effect.value;break}case"deal_damage_column":{let l=a?.column;if(l!==void 0){let d=e.columns[l];if(d)for(let s of d.enemies)s.hp-=o.effect.value}break}case"heal":{if(n==="on_card_play"){let l=a?.cardCost;if(l!==void 0&&l<2)break}e.gateHp=Math.min(e.gateMaxHp,e.gateHp+o.effect.value);break}case"apply_vulnerable_all":{for(let l of e.columns)for(let d of l.enemies)q(d,"vulnerable",o.effect.value,3);break}case"apply_weak_all":{for(let l of e.columns)for(let d of l.enemies)q(d,"weak",o.effect.value,3);break}case"burn_on_kill":{if(a?.diedFromBurn)for(let d of e.columns)for(let s of d.enemies)q(s,"burn",o.effect.value,99);break}case"block_on_emplace":{e.gateBlock+=o.effect.value,e.events.push({type:"block_gained",turn:e.turn,data:{value:o.effect.value,relic:r}});break}case"first_card_free":case"emplace_hp_bonus":case"max_resolve_bonus":case"extra_card_reward":case"fragment_bonus":break}}}function tr(e){return ar(e.seed+e.turn*7+13)}function ar(e){let t=e>>>0;return()=>{t=t+1831565813|0;let n=Math.imul(t^t>>>15,1|t);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function nr(){return{drawCards(e,t,n,a){let r=[],o=[...e],l=[...t];for(let d=0;d<n;d++){if(o.length===0){if(l.length===0)break;for(let s=l.length-1;s>0;s--){let p=Math.floor(a()*(s+1));[l[s],l[p]]=[l[p],l[s]]}o.push(...l),l=[]}r.push(o.shift())}return{drawn:r,newDrawPile:o,newDiscardPile:l}}}}function rr(e){let t=0;for(let n of e){let a=dt(n);a&&a.effect.type==="emplace_hp_bonus"&&(t+=a.effect.value)}return t}function or(e){let t=0;for(let n of e){let a=dt(n);a&&a.effect.type==="max_resolve_bonus"&&(t+=a.effect.value)}return t}function sr(e){return e.some(t=>{let n=dt(t);return n&&n.effect.type==="first_card_free"})}function Pa(e,t,n=Nt,a=Nt,r=[{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"needle",column:2}],o=[],l){let d=N(t),s=Ln(e,d),p=or(o),y=(l?.reducedMaxResolve?Gt-1:Gt)+p,g=l?.reducedHandSize?Oe-1:Oe,_=Array.from({length:Ve},(D,S)=>({index:S,enemies:[],emplacement:null}));for(let D of r){let S=Ut(D.templateId,D.column);l?.enemyHpMult&&l.enemyHpMult!==1&&(S.hp=Math.ceil(S.hp*l.enemyHpMult),S.maxHp=Math.ceil(S.maxHp*l.enemyHpMult)),l?.enemyBlitz&&(S.row=1),l?.enemyStartFortified&&q(S,"fortified",1,99),_[S.column].enemies.push(S)}let{drawn:E,newDrawPile:M,newDiscardPile:K}=pe(s,[],g,d),R={columns:_,hand:E,drawPile:M,discardPile:K,exhaustPile:[],gateHp:n,gateMaxHp:a,gateBlock:0,resolve:y,maxResolve:y,turn:1,phase:"player",outcome:"undecided",events:[],seed:t,killsThisCombat:0,relics:o,difficulty:l};Ue(R,o,"on_combat_start");for(let D of _)for(let S of D.enemies){let h=D.emplacement!==null;S.intent=qt(S,d,1,h)}return G(R,"turn_start",{turn:1}),R}function G(e,t,n){e.events.push({type:t,turn:e.turn,data:n}),e.events.length>100&&(e.events=e.events.slice(-100))}function Aa(e,t,n,a=!1){if(e.phase!=="player")return e;let r=e.hand[t];if(!r)return e;let o=O(r.defId);if(!o)return e;let l=!e.events.some(s=>s.type==="card_played"&&s.turn===e.turn),d=sr(e.relics)&&l;if(a&&o.type==="emplace"&&o.emplaceCost!==void 0){let s=d?0:o.emplaceCost;if(s>e.resolve)return e;let p=n??0,y=rr(e.relics);if(!(zn(e,o,p,y)||Xn(e,p,o)))return e;e.resolve-=s,e.hand.splice(t,1),e.exhaustPile.push(r),Ue(e,e.relics,"on_emplace")}else{let s=d?0:o.cost;if(s>e.resolve)return e;e.resolve-=s,e.hand.splice(t,1);let p=!1;for(let y of o.effects){if(y.type==="exhaust_self"){p=!0;continue}Ra(e,y,n??0)}Ft(e),p?e.exhaustPile.push(r):e.discardPile.push(r),Ue(e,e.relics,"on_card_play",{cardCost:o.cost,cardId:o.id})}return e.lastCardPlayed=r.defId,G(e,"card_played",{cardId:r.defId,targetColumn:n,asEmplace:a}),$t(e),e}function Ra(e,t,n){switch(t.type){case"damage":{if(t.target==="all")for(let a of e.columns)for(let r of a.enemies)Z(e,r,t.value);else if(t.target==="column"){let a=e.columns[n];if(a)for(let r of a.enemies)Z(e,r,t.value)}else{let a=e.columns[n];if(a&&a.enemies.length>0){let r=a.enemies.reduce((o,l)=>o.row>=l.row?o:l);Z(e,r,t.value)}}break}case"block":e.gateBlock+=t.value,G(e,"block_gained",{value:t.value});break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+t.value);break;case"draw":{let{drawn:a,newDrawPile:r,newDiscardPile:o}=pe(e.drawPile,e.discardPile,t.value,N(e.seed+e.turn));e.hand.push(...a),e.drawPile=r,e.discardPile=o;break}case"resolve":e.resolve=Math.min(e.maxResolve+5,e.resolve+t.value);break;case"vulnerable":{if(t.target==="all")for(let a of e.columns)for(let r of a.enemies)q(r,"vulnerable",t.value,3);else if(t.target==="column"){let a=e.columns[n];if(a)for(let r of a.enemies)q(r,"vulnerable",t.value,3)}else{let a=e.columns[n];if(a&&a.enemies.length>0){let r=a.enemies.reduce((o,l)=>o.row>=l.row?o:l);q(r,"vulnerable",t.value,3)}}G(e,"status_applied",{type:"vulnerable",value:t.value,column:n});break}case"weak":{if(t.target==="all")for(let a of e.columns)for(let r of a.enemies)q(r,"weak",t.value,3);else if(t.target==="column"){let a=e.columns[n];if(a)for(let r of a.enemies)q(r,"weak",t.value,3)}else{let a=e.columns[n];if(a&&a.enemies.length>0){let r=a.enemies.reduce((o,l)=>o.row>=l.row?o:l);q(r,"weak",t.value,3)}}G(e,"status_applied",{type:"weak",value:t.value,column:n});break}case"burn":{if(t.target==="all")for(let a of e.columns)for(let r of a.enemies)q(r,"burn",t.value,99);else{let a=e.columns[n];if(a)for(let r of a.enemies)q(r,"burn",t.value,99)}break}case"self_damage":{e.gateHp-=t.value,G(e,"gate_hit",{self:!0,damage:t.value});break}case"fortify":break;case"trigger_emplacements":{Ca(e);break}case"damage_per_burn":{for(let a of e.columns)for(let r of a.enemies){let o=re(r,"burn");o>0&&Z(e,r,t.value*o)}break}case"damage_equal_block":{let a=e.gateBlock,r=e.columns[n];if(r&&r.enemies.length>0){let o=r.enemies.reduce((l,d)=>l.row>=d.row?l:d);Z(e,o,a)}break}case"draw_per_kills":{let a=e.killsThisCombat*t.value;if(a>0){let{drawn:r,newDrawPile:o,newDiscardPile:l}=pe(e.drawPile,e.discardPile,a,N(e.seed+e.turn+3));e.hand.push(...r),e.drawPile=o,e.discardPile=l}break}case"damage_if_vulnerable":{let a=e.columns[n];if(a&&a.enemies.length>0){let r=a.enemies.reduce((d,s)=>d.row>=s.row?d:s),l=re(r,"vulnerable")>0?t.value*2:t.value;Z(e,r,l)}break}case"damage_per_kill_this_action":{let a=lr(e);if(a>0){let r=t.value*a;for(let o of e.columns)for(let l of o.enemies)Z(e,l,r)}break}case"exhaust_draw":{if(e.hand.length>0){let l=e.hand.shift();e.exhaustPile.push(l)}let{drawn:a,newDrawPile:r,newDiscardPile:o}=pe(e.drawPile,e.discardPile,t.value,N(e.seed+e.turn+5));e.hand.push(...a),e.drawPile=r,e.discardPile=o;break}case"burn_if_burning":{let a=!1;for(let o of e.columns){for(let l of o.enemies)if(re(l,"burn")>0){a=!0;break}if(a)break}let r=a?t.value+2:t.value;for(let o of e.columns)for(let l of o.enemies)q(l,"burn",r,99);break}case"damage_plus_block":{let a=Math.min(e.gateBlock,10),r=t.value+a,o=e.columns[n];if(o&&o.enemies.length>0){let l=o.enemies.reduce((d,s)=>d.row>=s.row?d:s);Z(e,l,r)}break}case"replay_last":{if(e.lastCardPlayed&&e.lastCardPlayed!=="pale_echo"){let a=O(e.lastCardPlayed);if(a)for(let r of a.effects)r.type!=="exhaust_self"&&r.type!=="replay_last"&&Ra(e,r,n)}break}case"damage_if_emplaced":{let a=e.columns[n];if(a){let r=a.emplacement?Math.floor(t.value*1.5):t.value;for(let o of a.enemies)Z(e,o,r)}break}case"damage_if_low_hp":{let r=e.gateHp<e.gateMaxHp*.5?t.value*2:t.value,o=e.columns[n];if(o&&o.enemies.length>0){let l=o.enemies.reduce((d,s)=>d.row>=s.row?d:s);Z(e,l,r)}break}case"damage_per_emplace":{let a=e.columns.filter(r=>r.emplacement!==null).length;if(a>0){let r=t.value*a;for(let o of e.columns)for(let l of o.enemies)Z(e,l,r)}break}case"draw_per_empty_potions":{let{drawn:r,newDrawPile:o,newDiscardPile:l}=pe(e.drawPile,e.discardPile,2,N(e.seed+e.turn+9));e.hand.push(...r),e.drawPile=o,e.discardPile=l;break}case"exhaust_self":break}}function lr(e){let t=0;for(let n of e.columns)for(let a of n.enemies)a.hp<=0&&t++;return t}function Z(e,t,n){let a=Qn(t),r=Math.floor(n*a);t.hp-=r,G(e,"damage_dealt",{targetId:t.instanceId,damage:r})}function Ft(e){for(let t of e.columns)t.enemies=t.enemies.filter(n=>{if(n.hp<=0){e.killsThisCombat++,G(e,"enemy_killed",{enemyId:n.instanceId,templateId:n.templateId});let a=re(n,"burn")>0;return Ue(e,e.relics,"on_enemy_kill",{column:t.index,diedFromBurn:a,templateId:n.templateId}),!1}return!0})}function Da(e){return e.phase!=="player"||(G(e,"turn_end",{turn:e.turn}),e.phase="enemy",ir(e)),e}function ir(e){let t=N(e.seed+e.turn*31),n=e.columns.flatMap(d=>d.enemies.map(s=>({enemy:s,intent:s.intent??{type:"advance",value:1}})));for(let{enemy:d,intent:s}of n)d.hp<=0||cr(e,d,s,t);if(Ft(e),$t(e),e.outcome!=="undecided"||(e.turn++,e.phase="player",e.resolve=e.maxResolve,e.gateBlock=0,Ca(e),Ft(e),$t(e),e.outcome!=="undecided"))return;Ue(e,e.relics,"on_turn_start"),e.discardPile.push(...e.hand),e.hand=[];let a=e.difficulty?.reducedHandSize?Oe-1:Oe,{drawn:r,newDrawPile:o,newDiscardPile:l}=pe(e.drawPile,e.discardPile,a,t);e.hand=r,e.drawPile=o,e.discardPile=l;for(let d of e.columns)for(let s of d.enemies){let p=d.emplacement!==null;s.intent=qt(s,t,e.turn,p)}G(e,"turn_start",{turn:e.turn})}function cr(e,t,n,a){let r=de(t.templateId),o=Zn(t),l=e.difficulty?.enemyDamageMult??1;if(er(t),Jn(t),!(t.hp<=0))switch(n.type){case"advance":{if(t.templateId==="breaker"){let d=e.columns[t.column];if(d.emplacement&&t.row>=Ae-2){let s=(r?.damage??10)*2;d.emplacement.hp-=s,d.emplacement.hp<=0&&(G(e,"emplacement_destroyed",{column:t.column}),d.emplacement=null);break}}if(t.row=Math.min(Ae-1,t.row+(r?.speed??1)),G(e,"enemy_advance",{enemyId:t.instanceId,row:t.row}),t.row>=Ae-1)if(t.templateId==="wraith"){let d=Math.floor((r?.damage??7)*o*l),s=Math.min(e.gateBlock,d);e.gateBlock-=s,e.gateHp-=d-s,G(e,"gate_hit",{enemyId:t.instanceId,damage:d-s,blocked:s})}else{let d=e.columns[t.column];if(d.emplacement)d.emplacement.hp-=r?.damage??4,d.emplacement.hp<=0&&(G(e,"emplacement_destroyed",{column:t.column}),d.emplacement=null);else{let s=Math.floor((r?.damage??4)*o*l),p=Math.min(e.gateBlock,s);e.gateBlock-=p,e.gateHp-=s-p,G(e,"gate_hit",{enemyId:t.instanceId,damage:s-p,blocked:p})}}break}case"attack":{if(t.templateId==="flanker"){let p=a()<.5?-1:1,y=t.column,g=Math.max(0,Math.min(Ve-1,t.column+p));if(g!==y){let _=e.columns[y];_.enemies=_.enemies.filter(E=>E.instanceId!==t.instanceId),t.column=g,e.columns[g].enemies.push(t)}}let d=Math.floor((r?.damage??4)*o*l),s=Math.min(e.gateBlock,d);e.gateBlock-=s,e.gateHp-=d-s,G(e,"gate_hit",{enemyId:t.instanceId,damage:d-s,blocked:s});break}case"buff":q(t,"empowered",n.value,3);break;case"debuff":{e.gateBlock=Math.max(0,e.gateBlock-n.value*2);break}case"shield":{let d=e.columns[t.column];for(let s of d.enemies)q(s,"fortified",n.value,2);break}case"summon":{let d=e.columns.findIndex(s=>s.enemies.length===0);if(d>=0){let s=Ut("wisp",d);e.columns[d].enemies.push(s),s.intent=qt(s,N(e.seed+e.turn*97))}break}}}function $t(e){if(e.gateHp<=0){e.gateHp=0,e.outcome="lose",e.phase="ended",G(e,"combat_end",{outcome:"lose"});return}e.columns.reduce((n,a)=>n+a.enemies.length,0)===0&&(e.outcome="win",e.phase="ended",G(e,"combat_end",{outcome:"win"}))}function mt(e,t=3,n=[]){let a=new Set(["strike","guard","bolster","brace","mend",...n]),o=Ke.filter(s=>!a.has(s.id)&&s.id!=="pale_curse").map(s=>({card:s,weight:s.rarity==="common"?6:s.rarity==="uncommon"?3:s.rarity==="rare"?1.5:.5})),l=[],d=new Set;for(let s=0;s<t&&o.length>0;s++){let p=o.filter(E=>!d.has(E.card.id));if(p.length===0)break;let y=p.reduce((E,M)=>E+M.weight,0),g=e()*y,_=!1;for(let E of p)if(g-=E.weight,g<=0){l.push(E.card),d.add(E.card.id),_=!0;break}_||(l.push(p[p.length-1].card),d.add(p[p.length-1].card.id))}return l}var dr=[{name:"Scout Party",enemies:[{templateId:"hollow",column:1},{templateId:"hollow",column:3}]},{name:"Swift Assault",enemies:[{templateId:"needle",column:0},{templateId:"needle",column:2},{templateId:"needle",column:4}]},{name:"Pale Vanguard",enemies:[{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"needle",column:2}]},{name:"Wisp Swarm",enemies:[{templateId:"wisp",column:0},{templateId:"wisp",column:1},{templateId:"wisp",column:2},{templateId:"wisp",column:3},{templateId:"wisp",column:4}]},{name:"Heavy Patrol",enemies:[{templateId:"shade",column:1},{templateId:"hollow",column:3}]},{name:"Armored Column",enemies:[{templateId:"husk",column:2},{templateId:"wisp",column:0},{templateId:"wisp",column:4}]},{name:"Pale Scouts",enemies:[{templateId:"wisp",column:0},{templateId:"wisp",column:4},{templateId:"hollow",column:2}]},{name:"Needle Formation",enemies:[{templateId:"needle",column:1},{templateId:"needle",column:3}]},{name:"Husk Advance",enemies:[{templateId:"husk",column:2},{templateId:"wisp",column:1},{templateId:"wisp",column:3}]},{name:"Shadow Patrol",enemies:[{templateId:"shade",column:0},{templateId:"needle",column:4}]},{name:"Swarm Tide",enemies:[{templateId:"wisp",column:0},{templateId:"wisp",column:1},{templateId:"hollow",column:2},{templateId:"wisp",column:3},{templateId:"wisp",column:4}]},{name:"Hollow Shields",enemies:[{templateId:"hollow",column:1},{templateId:"hollow",column:2},{templateId:"hollow",column:3}]},{name:"Fast Assault",enemies:[{templateId:"needle",column:0},{templateId:"needle",column:2},{templateId:"needle",column:4}]},{name:"Pale Sentries",enemies:[{templateId:"shade",column:2},{templateId:"hollow",column:0},{templateId:"hollow",column:4}]}],mr=[{name:"The Dark Tide",enemies:[{templateId:"shade",column:1},{templateId:"shade",column:3},{templateId:"needle",column:2}]},{name:"Hollow Legion",enemies:[{templateId:"hollow",column:0},{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"hollow",column:4}]},{name:"Husk Fortress",enemies:[{templateId:"husk",column:1},{templateId:"husk",column:3},{templateId:"needle",column:2}]},{name:"Shade Ambush",enemies:[{templateId:"shade",column:0},{templateId:"shade",column:2},{templateId:"shade",column:4}]}],ur=[{name:"The Warband",enemies:[{templateId:"breaker",column:2},{templateId:"shielder",column:1},{templateId:"shielder",column:3}]},{name:"Flanking Ambush",enemies:[{templateId:"flanker",column:0},{templateId:"flanker",column:4},{templateId:"wraith",column:2}]},{name:"Breaker Vanguard",enemies:[{templateId:"breaker",column:1},{templateId:"breaker",column:3},{templateId:"shielder",column:2}]},{name:"Phantom Blitz",enemies:[{templateId:"wraith",column:0},{templateId:"wraith",column:1},{templateId:"wraith",column:3},{templateId:"wraith",column:4}]}],pr=[{name:"Echo Vanguard",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:3}]},{name:"The Final Test",enemies:[{templateId:"echo",column:2},{templateId:"breaker",column:0},{templateId:"flanker",column:4}]},{name:"Memory Siege",enemies:[{templateId:"echo",column:0},{templateId:"echo",column:2},{templateId:"echo",column:4}]},{name:"The Pale Tribunal",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:2},{templateId:"echo",column:3},{templateId:"breaker",column:0}]}],fr=[{name:"Wraith Drift",enemies:[{templateId:"wraith",column:1},{templateId:"wraith",column:3}]},{name:"Breach Team",enemies:[{templateId:"breaker",column:2},{templateId:"flanker",column:0},{templateId:"flanker",column:4}]},{name:"Shield Wall",enemies:[{templateId:"shielder",column:2},{templateId:"hollow",column:1},{templateId:"hollow",column:3}]},{name:"Wraith Surge",enemies:[{templateId:"wraith",column:0},{templateId:"wraith",column:2},{templateId:"wraith",column:4}]},{name:"Flanker Pair",enemies:[{templateId:"flanker",column:1},{templateId:"flanker",column:3}]},{name:"Shielder Escort",enemies:[{templateId:"shielder",column:2},{templateId:"breaker",column:1},{templateId:"hollow",column:3}]},{name:"Pale Vanguard II",enemies:[{templateId:"breaker",column:0},{templateId:"flanker",column:2},{templateId:"shielder",column:4}]},{name:"Wraith Patrol",enemies:[{templateId:"wraith",column:1},{templateId:"hollow",column:0},{templateId:"hollow",column:4}]},{name:"Breaker Column",enemies:[{templateId:"breaker",column:2},{templateId:"wisp",column:0},{templateId:"wisp",column:1},{templateId:"wisp",column:3},{templateId:"wisp",column:4}]},{name:"Shield Formation",enemies:[{templateId:"shielder",column:1},{templateId:"shielder",column:3},{templateId:"flanker",column:2}]},{name:"Assault Wave",enemies:[{templateId:"breaker",column:1},{templateId:"breaker",column:3}]},{name:"Night Raid",enemies:[{templateId:"wraith",column:0},{templateId:"flanker",column:2},{templateId:"wraith",column:4}]},{name:"Armored Push",enemies:[{templateId:"shielder",column:0},{templateId:"breaker",column:2},{templateId:"shielder",column:4}]}],hr=[{name:"Echoes of the End",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:3}]},{name:"Final Surge",enemies:[{templateId:"echo",column:2},{templateId:"wraith",column:0},{templateId:"wraith",column:4},{templateId:"breaker",column:1}]},{name:"Echo Patrol",enemies:[{templateId:"echo",column:0},{templateId:"echo",column:4}]},{name:"Pale Convergence",enemies:[{templateId:"echo",column:2},{templateId:"wraith",column:1},{templateId:"wraith",column:3}]},{name:"Void March",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:3},{templateId:"breaker",column:2}]},{name:"Shadow Tide",enemies:[{templateId:"wraith",column:0},{templateId:"echo",column:2},{templateId:"flanker",column:4}]},{name:"The Unnamed",enemies:[{templateId:"echo",column:2},{templateId:"shielder",column:1},{templateId:"shielder",column:3}]},{name:"Pale Hammer",enemies:[{templateId:"breaker",column:0},{templateId:"echo",column:2},{templateId:"breaker",column:4}]},{name:"Memory Storm",enemies:[{templateId:"echo",column:0},{templateId:"echo",column:1},{templateId:"echo",column:3},{templateId:"echo",column:4}]},{name:"Wraith Flood",enemies:[{templateId:"wraith",column:0},{templateId:"wraith",column:1},{templateId:"wraith",column:2},{templateId:"wraith",column:3},{templateId:"wraith",column:4}]},{name:"Final Guard",enemies:[{templateId:"echo",column:1},{templateId:"breaker",column:2},{templateId:"echo",column:3}]},{name:"Pale Assembly",enemies:[{templateId:"echo",column:0},{templateId:"shielder",column:2},{templateId:"echo",column:4},{templateId:"flanker",column:1}]}];function Ma(e,t,n=!1){let a;if(n)switch(e){case 2:a=ur;break;case 3:a=pr;break;default:a=mr;break}else switch(e){case 2:a=fr;break;case 3:a=hr;break;default:a=dr;break}let r=Math.floor(t()*a.length);return{...a[r],isElite:n}}var ct=12,Ta=4;function gr(e,t,n){if(e===0)return"combat";if(e===t-1)return"boss";let a=n();return e===Math.floor(t/2)?a<.5?"rest":"shop":a<.5?"combat":a<.65?"elite":a<.78?"event":a<.88?"rest":"shop"}function Ha(e,t){let n=N(t),a=[],r=[];for(let o=0;o<ct;o++){let l=[],d=o===0||o===ct-1?1:Math.floor(n()*2)+2,s=new Set;for(;s.size<d;)s.add(Math.floor(n()*Ta));for(let p=0;p<Ta;p++)if(s.has(p)){let y=gr(o,ct,n),g={id:`node-${e}-${o}-${p}`,type:y,row:o,column:p,connections:[],visited:!1};l.push(g),a.push(g)}else l.push(null);r.push(l)}for(let o=0;o<ct-1;o++){let l=r[o].filter(s=>s!==null),d=r[o+1].filter(s=>s!==null);if(d.length!==0){for(let s of l){let p=d.map(y=>({node:y,dist:Math.abs(y.column-s.column)})).sort((y,g)=>y.dist-g.dist);s.connections.push(p[0].node.id),p.length>1&&n()<.4&&s.connections.push(p[1].node.id)}for(let s of d)!l.some(y=>y.connections.includes(s.id))&&l.length>0&&l.map(g=>({node:g,dist:Math.abs(g.column-s.column)})).sort((g,_)=>g.dist-_.dist)[0].node.connections.push(s.id)}}return{act:e,nodes:a}}function Re(e,t){return e.nodes.find(n=>n.id===t)}function Ba(e,t){if(!t)return e.nodes.filter(a=>a.row===0);let n=Re(e,t);return n?n.connections.map(a=>Re(e,a)).filter(a=>!!a):[]}function ut(e,t=0){let n={enemyHpMult:1,enemyDamageMult:1,startingGateHp:70,extraEnemies:0,shopCostMult:1,healMult:1,startWithCurse:!1,enemyBlitz:!1,reducedRewards:!1,enemyStartFortified:!1,voidColumns:0,paleHunger:!1,bossExtraMinions:0,reducedHandSize:!1,reducedMaxResolve:!1};return e>=2&&(n.enemyHpMult+=.2,n.enemyDamageMult+=.15),e>=3&&(n.enemyHpMult+=.3,n.enemyDamageMult+=.25),t>=1&&(n.enemyHpMult+=.1),t>=2&&(n.enemyDamageMult+=.1),t>=3&&(n.startWithCurse=!0),t>=4&&(n.healMult-=.25),t>=5&&(n.startingGateHp-=10),t>=6&&(n.enemyBlitz=!0),t>=7&&(n.extraEnemies+=1),t>=8&&(n.reducedRewards=!0),t>=9&&(n.enemyStartFortified=!0),t>=10&&(n.shopCostMult+=.25),t>=11&&(n.voidColumns=1),t>=12&&(n.paleHunger=!0),t>=13&&(n.bossExtraMinions=2),t>=14&&(n.reducedHandSize=!0),t>=15&&(n.reducedMaxResolve=!0),n}function Ga(e,t=0){let n=ee(e),a=Ha(1,n),r=ut(1,t),o=Kt();return r.startWithCurse&&o.push(qe("pale_curse")),{id:`run-${Date.now()}-${n}`,seed:e,act:1,map:a,currentNodeId:null,deck:o,gateHp:r.startingGateHp,gateMaxHp:r.startingGateHp,fragments:0,potions:[null,null,null],relics:[],ascensionLevel:t,combat:null}}function jt(e,t){return{...e,deck:[...e.deck,t]}}function zt(e,t){return{...e,deck:e.deck.filter(n=>n.instanceId!==t)}}function Na(e,t){let n=Re(e.map,t);return n&&(n.visited=!0),{...e,currentNodeId:t}}function pt(e,t){return{...e,gateHp:Math.min(e.gateMaxHp,e.gateHp+t)}}function Wa(e,t){return e.fragments<t?null:{...e,fragments:e.fragments-t}}function je(e,t){return{...e,fragments:e.fragments+t}}function Fa(e,t){let n=e.potions.indexOf(null);if(n===-1)return null;let a=[...e.potions];return a[n]=t,{...e,potions:a}}function $a(e,t){if(t<0||t>=e.potions.length)return null;let n=e.potions[t];if(!n)return null;let a=[...e.potions];return a[t]=null,{run:{...e,potions:a},potionId:n}}function Yt(e){let t=e.act+1,n=ee(e.seed+`-act${t}`),a=Ha(t,n);return{...e,act:t,map:a,currentNodeId:null}}function Va(e){let t=[],n=Ke.filter(o=>o.rarity!=="common"||o.id==="slash"||o.id==="flare"),a=new Set;for(let o=0;o<5&&a.size<5;o++){let l=n[Math.floor(e()*n.length)];if(a.has(l.id)){o--;continue}a.add(l.id);let d=l.rarity==="rare"?75:l.rarity==="uncommon"?50:30;t.push({type:"card",cardDef:l,cost:d})}let r=Le[Math.floor(e()*Le.length)];return t.push({type:"potion",potionDef:r,cost:25}),t.push({type:"card_remove",cost:50}),t}var yr=[{id:"wandering_smith",name:"The Wandering Smith",description:"A cloaked figure sits by a forge that shouldn't exist this far into the Pale. They offer to work on your defenses.",choices:[{label:"Ask them to reinforce the gate. (Heal 15 HP)",effect:{type:"heal",value:15}},{label:"Ask for supplies. (Gain 15 fragments)",effect:{type:"fragments",value:15}},{label:"Leave them be.",effect:{type:"nothing"}}]},{id:"pale_fountain",name:"The Pale Fountain",description:"A spring of luminous water bubbles from cracked stone. Its glow is unsettling but beckons.",choices:[{label:"Drink deeply. (+10 max Gate HP)",effect:{type:"max_hp",value:10}},{label:"Fill a flask. (Gain a random card)",effect:{type:"card_reward"}},{label:"Leave. The Pale gives nothing freely.",effect:{type:"nothing"}}]},{id:"abandoned_cache",name:"Abandoned Cache",description:"You find a sealed chest among the rubble of a collapsed watchtower.",choices:[{label:"Pry it open. (Gain 25 fragments)",effect:{type:"fragments",value:25}},{label:"Smash it quickly. (Gain 10 fragments)",effect:{type:"fragments",value:10}},{label:"Leave it. Could be cursed.",effect:{type:"nothing"}}]},{id:"old_veteran",name:"The Old Veteran",description:`A scarred soldier leans against the wall. "I've seen the Pale take stronger keeps than yours," they say.`,choices:[{label:'"Teach me." (Remove a card from your deck)',effect:{type:"remove_card"}},{label:'"Give me your supplies." (Gain 20 fragments)',effect:{type:"fragments",value:20}},{label:'"Good luck." (Nothing happens)',effect:{type:"nothing"}}]},{id:"strange_merchant",name:"Strange Merchant",description:"A merchant with too many eyes offers wares from a floating pack.",choices:[{label:"Browse their cards. (Gain a card)",effect:{type:"card_reward"}},{label:"Sell your blood. (Lose 10 HP, gain 30 fragments)",effect:{type:"damage",value:10}},{label:"Walk away.",effect:{type:"nothing"}}]}],wr=[{id:"pale_scholar",name:"The Pale Scholar",description:'An ancient figure pores over a tome that seems to read itself. "The Pale remembers everything," they whisper.',choices:[{label:"Ask for knowledge. (Gain a card)",effect:{type:"card_reward"}},{label:"Ask for healing. (Heal 20 HP)",effect:{type:"heal",value:20}},{label:"Back away slowly.",effect:{type:"nothing"}}]},{id:"fractured_mirror",name:"The Fractured Mirror",description:"A mirror stands in the corridor, cracked but gleaming. Your reflection looks stronger than you feel.",choices:[{label:"Reach through. (+5 max Gate HP, lose 5 HP)",effect:{type:"max_hp",value:5}},{label:"Smash it. (Gain 20 fragments)",effect:{type:"fragments",value:20}},{label:"Walk past. Mirrors lie.",effect:{type:"nothing"}}]},{id:"deserters_cache",name:"Deserter's Cache",description:"Behind a collapsed wall, you find supplies left by someone who fled the Keep long ago.",choices:[{label:"Take everything. (Gain 30 fragments)",effect:{type:"fragments",value:30}},{label:"Take only what you need. (Heal 10 HP, gain 10 fragments)",effect:{type:"heal",value:10}},{label:"Leave it for the next warden.",effect:{type:"nothing"}}]}],vr=[{id:"wandering_smith_cracks",name:"The Wandering Smith",description:"The smith again. You've seen this forge before \u2014 the same cracks in the stone, the same angle of the cloak. They look up and for the first time, you notice their hands are shaking.",choices:[{label:'"How long have you been here?" (Heal 15 HP)',effect:{type:"heal",value:15}},{label:`"You're not real, are you." (Gain 20 fragments)`,effect:{type:"fragments",value:20}},{label:"Say nothing. The kindness is worse than the lie.",effect:{type:"nothing"}}]},{id:"the_echoing_child",name:"The Echoing Child",description:'A child sits in the corridor, humming. They look up with eyes that glow faintly. "I remember my house," they say. "Can you take me there?" The house is gone. You know this.',choices:[{label:`"I'll try." (Lose 15 HP \u2014 the detour is dangerous)`,effect:{type:"damage",value:15}},{label:`"There's nothing to go back to." (Gain 10 fragments \u2014 they dissolve)`,effect:{type:"fragments",value:10}},{label:'"Stay here. The Keep is safe."',effect:{type:"nothing"}}]}],br=[{id:"motts_stash",name:"Mott's Hidden Stash",description:`"DON'T TELL MOTT," reads the note pinned to a crate. It's Mott's handwriting.`,choices:[{label:"Open it. (Gain 25 fragments)",effect:{type:"fragments",value:25}},{label:"Leave it. Mott knows things you don't.",effect:{type:"nothing"}}]},{id:"wardens_echo",name:"A Warden's Echo",description:'You find scratches on the wall. Tallies. Hundreds of them. Below, in faded ink: "Run 847. The Pale is not the enemy. The Pale is the answer to a question we forgot."',choices:[{label:"Study the scratches. (Gain a card)",effect:{type:"card_reward"}},{label:"Cover them. Some knowledge is dangerous. (Gain 15 fragments)",effect:{type:"fragments",value:15}},{label:"Add your own tally mark.",effect:{type:"nothing"}}]}],Wt=[{id:"the_architects_choice",name:"The Architect's Choice",description:"A door that shouldn't exist. Beyond it, a room you've seen in dreams. A desk. A journal. A pen that still has ink. The Architect's final workspace.",choices:[{label:"Read the journal. (+15 max Gate HP)",effect:{type:"max_hp",value:15}},{label:"Destroy the journal. (Gain 40 fragments)",effect:{type:"fragments",value:40}},{label:"Sit down. Pick up the pen.",effect:{type:"nothing"}}]}],kr=[{id:"the_last_wall",name:"The Last Wall",description:"The final barrier before the Pale's heart. Ancient wards still flicker across its surface.",choices:[{label:"Channel the wards. (+15 max Gate HP)",effect:{type:"max_hp",value:15}},{label:"Break through quickly. (Gain 20 fragments)",effect:{type:"fragments",value:20}},{label:"Let it stand. Its purpose is not yours.",effect:{type:"nothing"}}]},{id:"echo_of_a_warden",name:"Echo of a Warden",description:`A ghostly figure in warden's garb appears. "I held this keep once. Take what remains of my strength."`,choices:[{label:"Accept their gift. (Gain a card, lose 5 HP)",effect:{type:"card_reward"}},{label:"Ask them to strengthen the gate. (Heal 25 HP)",effect:{type:"heal",value:25}},{label:'"Rest now, Warden."',effect:{type:"nothing"}}]},{id:"pale_bargain",name:"The Pale Bargain",description:'The void itself speaks: "Give me something, and I will give you power."',choices:[{label:"Sacrifice a card. (Remove a card)",effect:{type:"remove_card"}},{label:"Sacrifice blood. (Lose 15 HP, gain 40 fragments)",effect:{type:"damage",value:15}},{label:'"I make no deals with the void."',effect:{type:"nothing"}}]}];function Oa(e,t,n){let a;switch(e){case 2:a=wr;break;case 3:a=kr;break;default:a=yr;break}let r=n==="cracks"||n==="truth"||n==="true_ending";if((n==="truth"||n==="true_ending")&&e===3&&Wt.length>0&&t()<.4)return Wt[Math.floor(t()*Wt.length)];if(r){let l=null;if(e===1?l=vr:e===2&&(l=br),l&&l.length>0&&t()<.4)return l[Math.floor(t()*l.length)]}return a[Math.floor(t()*a.length)]}var oe=[{id:"forge",name:"The Forge",description:"Unlock card upgrades at rest sites. Higher levels improve upgrades.",maxLevel:3,upgradeCost:e=>e*30},{id:"archive",name:"The Archive",description:"Unlock rare cards in the reward pool. Higher levels add legendaries.",maxLevel:3,upgradeCost:e=>e*40},{id:"beacon_tower",name:"Beacon Tower",description:"+1 starting hand size per level.",maxLevel:2,upgradeCost:e=>e*50},{id:"foundry",name:"The Foundry",description:"Emplacements start with +2 HP per level.",maxLevel:3,upgradeCost:e=>e*25},{id:"sanctum_hall",name:"Sanctum Hall",description:"+5 max Gate HP per level.",maxLevel:3,upgradeCost:e=>e*35}];function ze(e,t){return e.structures[t]??0}function Ka(e,t){let n=oe.find(o=>o.id===t);if(!n)return null;let a=ze(e,t);if(a>=n.maxLevel)return null;let r=n.upgradeCost(a+1);return e.echoes<r?null:{...e,echoes:e.echoes-r,structures:{...e.structures,[t]:a+1}}}function Xt(){return[{id:"wren",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"sable",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"duskmar",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"mott",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"pale_visitor",tier:0,echoesGiven:0,dialoguesSeen:[]}]}function Jt(e,t,n){return(e?10+t*5:3)+Math.floor(n*.5)}function La(e,t){return t>=15?"true_ending":e>=30?"truth":e>=15?"cracks":"surface"}function Ua(e,t){let n=t.npcs.find(r=>r.id===e);if(!n)return null;let a=_a(e,n.tier,n.dialoguesSeen);return a.length===0?null:{speaker:a[0].speaker,text:a[0].text,dialogueId:a[0].id}}function qa(e,t,n){let a=e.npcs.findIndex(l=>l.id===t);if(a===-1)return e;let r=[...e.npcs],o={...r[a]};return o.dialoguesSeen=[...o.dialoguesSeen,n],r[a]=o,{...e,npcs:r}}var Ot=2;function Er(){return ja(Sr(),".config","codekeep")}function Zt(){return ja(Er(),"game.json")}function Pr(){return{structures:{},npcs:[],echoes:0,highestAscension:0,totalRuns:0,totalWins:0,unlockedCardIds:[],achievements:[],narrativeFlags:[]}}function za(e){return{schemaVersion:Ot,savedAtUnixMs:Date.now(),playerName:e,keep:Pr(),activeRun:null}}function me(e){let t=Zt(),n=Cr(t);Qt(n)||Tr(n,{recursive:!0});let a=t+".tmp",r=JSON.stringify({...e,savedAtUnixMs:Date.now()},null,2);Vt(a,r,"utf-8"),xr(a,t)}function De(){let e=Zt();if(!Qt(e))return null;let t;try{t=_r(e,"utf-8")}catch{return null}let n;try{n=JSON.parse(t)}catch{let a=e+".bak";try{Vt(a,t,"utf-8")}catch{}return process.stderr.write(`[codekeep] Corrupted save backed up to ${a}
3
- `),null}if(n.schemaVersion!==Ot){let a=e+`.v${n.schemaVersion}.bak`;try{Vt(a,t,"utf-8")}catch{}return process.stderr.write(`[codekeep] Save version mismatch (got ${n.schemaVersion}, need ${Ot}), backed up to ${a}
4
- `),null}return n}function Ya(){let e=Zt();if(!Qt(e))return!1;try{return Ir(e),!0}catch{return!1}}import Hr from"react";import{Box as Br,Text as W}from"ink";import{writeFileSync as Ar,mkdirSync as Rr,existsSync as Dr}from"fs";import{join as Xa}from"path";import{homedir as Mr}from"os";var ea=Xa(Mr(),".config","codekeep","crashes");function Ja(e,t){if((e instanceof Error?e.message:String(e)).includes("Raw mode is not supported"))return"";Dr(ea)||Rr(ea,{recursive:!0});let a={timestamp:new Date().toISOString(),error:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0,version:globalThis.__CODEKEEP_VERSION??"unknown",nodeVersion:process.version,platform:process.platform,arch:process.arch,screen:t?.screen,gameState:t?.gameState},r=`crash-${Date.now()}.json`,o=Xa(ea,r);return Ar(o,JSON.stringify(a,null,2),"utf-8"),o}function Qa(e){let t=encodeURIComponent(`[Crash]: ${e.error.slice(0,80)}`),n=encodeURIComponent(`## Crash Report
2
+ import{Command as Wo}from"commander";import{render as Fo}from"ink";import{useState as B,useCallback as we,useEffect as Do}from"react";import{Box as pe,Text as g,useApp as Mo,useInput as Bo,useStdout as Ho}from"ink";var st=5,ze=4,jt=3,lt=5,Xt=70,it=[{id:"strike",name:"Strike",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 6 damage to an enemy.",effects:[{type:"damage",value:6,target:"single"}]},{id:"guard",name:"Guard",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 5 Block.",effects:[{type:"block",value:5,target:"self"}]},{id:"bolster",name:"Bolster",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 8 Block.",effects:[{type:"block",value:8,target:"self"}]},{id:"spark",name:"Spark",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 4 damage to all enemies in a column.",effects:[{type:"damage",value:4,target:"column"}]},{id:"reinforce",name:"Reinforce",cost:2,type:"cast",category:"fortification",rarity:"common",description:"Gain 15 Block.",effects:[{type:"block",value:15,target:"self"}]},{id:"barrage",name:"Barrage",cost:2,type:"cast",category:"armament",rarity:"common",description:"Deal 6 damage to all enemies.",effects:[{type:"damage",value:6,target:"all"}]},{id:"mend",name:"Mend",cost:1,type:"cast",category:"edict",rarity:"common",description:"Heal 4 Gate HP.",effects:[{type:"heal",value:4,target:"self"}]},{id:"lookout",name:"Lookout",cost:0,type:"cast",category:"edict",rarity:"common",description:"Draw 1 card.",effects:[{type:"draw",value:1}]},{id:"brace",name:"Brace",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 4 Block. Draw 1 card.",effects:[{type:"block",value:4,target:"self"},{type:"draw",value:1}]},{id:"ember",name:"Ember",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 8 damage to an enemy.",effects:[{type:"damage",value:8,target:"single"}]},{id:"slash",name:"Slash",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 5 damage to an enemy. Draw 1 card.",effects:[{type:"damage",value:5,target:"single"},{type:"draw",value:1}]},{id:"rally",name:"Rally",cost:1,type:"cast",category:"edict",rarity:"common",description:"Gain 3 Block. Draw 2 cards.",effects:[{type:"block",value:3,target:"self"},{type:"draw",value:2}]},{id:"salvo",name:"Salvo",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 3 damage to all enemies.",effects:[{type:"damage",value:3,target:"all"}]},{id:"patch",name:"Patch",cost:0,type:"cast",category:"fortification",rarity:"common",description:"Gain 3 Block.",effects:[{type:"block",value:3,target:"self"}]},{id:"flare",name:"Flare",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 6 damage to all enemies in a column.",effects:[{type:"damage",value:6,target:"column"}]},{id:"cleave",name:"Cleave",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 10 damage to an enemy.",effects:[{type:"damage",value:10,target:"single"}]},{id:"iron_wall",name:"Iron Wall",cost:2,type:"cast",category:"fortification",rarity:"uncommon",description:"Gain 16 Block.",effects:[{type:"block",value:16,target:"self"}]},{id:"blitz",name:"Blitz",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 4 damage to an enemy twice.",effects:[{type:"damage",value:4,target:"single"},{type:"damage",value:4,target:"single"}]},{id:"volley",name:"Volley",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 6 damage to all enemies.",effects:[{type:"damage",value:6,target:"all"}]},{id:"resurgence",name:"Resurgence",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Heal 8 Gate HP.",effects:[{type:"heal",value:8,target:"self"}]},{id:"keen_eye",name:"Keen Eye",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Draw 3 cards.",effects:[{type:"draw",value:3}]},{id:"expose",name:"Expose",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Apply 2 Vulnerable to an enemy.",effects:[{type:"vulnerable",value:2,target:"single"}]},{id:"weaken",name:"Weaken",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Apply 2 Weak to an enemy.",effects:[{type:"weak",value:2,target:"single"}]},{id:"bash",name:"Bash",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 7 damage. Apply 1 Vulnerable.",effects:[{type:"damage",value:7,target:"single"},{type:"vulnerable",value:1,target:"single"}]},{id:"shield_bash",name:"Shield Bash",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 6 Block. Deal 3 damage.",effects:[{type:"block",value:6,target:"self"},{type:"damage",value:3,target:"single"}]},{id:"ignite",name:"Ignite",cost:1,type:"cast",category:"armament",rarity:"common",description:"Apply 3 Burn to a column.",effects:[{type:"burn",value:3,target:"column"}]},{id:"scout",name:"Scout",cost:0,type:"cast",category:"edict",rarity:"common",description:"Draw 2 cards.",effects:[{type:"draw",value:2}]},{id:"fortify",name:"Fortify",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 10 Block.",effects:[{type:"block",value:10,target:"self"}]},{id:"sundering_strike",name:"Sundering Strike",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 12 damage. Apply 2 Vulnerable.",effects:[{type:"damage",value:12,target:"single"},{type:"vulnerable",value:2,target:"single"}]},{id:"pale_fire",name:"Pale Fire",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 5 damage to all. Apply 2 Burn.",effects:[{type:"damage",value:5,target:"all"},{type:"burn",value:2,target:"all"}]},{id:"shield_wall",name:"Shield Wall",cost:2,type:"cast",category:"fortification",rarity:"uncommon",description:"Gain 20 Block.",effects:[{type:"block",value:20,target:"self"}]},{id:"battle_cry",name:"Battle Cry",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Gain 1 Resolve. Draw 1 card.",effects:[{type:"resolve",value:1},{type:"draw",value:1}]},{id:"intimidate",name:"Intimidate",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Apply 2 Weak to all enemies.",effects:[{type:"weak",value:2,target:"all"}]},{id:"hemorrhage",name:"Hemorrhage",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 8 damage. Apply 4 Burn.",effects:[{type:"damage",value:8,target:"single"},{type:"burn",value:4,target:"single"}]},{id:"restoration",name:"Restoration",cost:2,type:"cast",category:"edict",rarity:"uncommon",description:"Heal 12 Gate HP. Gain 4 Block.",effects:[{type:"heal",value:12,target:"self"},{type:"block",value:4,target:"self"}]},{id:"precision",name:"Precision",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 10 damage to an enemy. Apply 1 Vulnerable.",effects:[{type:"damage",value:10,target:"single"},{type:"vulnerable",value:1,target:"single"}]},{id:"firestorm",name:"Firestorm",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 8 damage to a column. Apply 3 Burn.",effects:[{type:"damage",value:8,target:"column"},{type:"burn",value:3,target:"column"}]},{id:"deep_guard",name:"Deep Guard",cost:1,type:"cast",category:"fortification",rarity:"uncommon",description:"Gain 7 Block. Draw 1 card.",effects:[{type:"block",value:7,target:"self"},{type:"draw",value:1}]},{id:"inferno",name:"Inferno",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Deal 12 damage to all enemies.",effects:[{type:"damage",value:12,target:"all"}]},{id:"fortress",name:"Fortress",cost:3,type:"cast",category:"fortification",rarity:"rare",description:"Gain 25 Block. Gain 1 Resolve.",effects:[{type:"block",value:25,target:"self"},{type:"resolve",value:1}]},{id:"annihilate",name:"Annihilate",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Deal 20 damage to an enemy.",effects:[{type:"damage",value:20,target:"single"}]},{id:"wardens_wrath",name:"Warden's Wrath",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Deal 8 damage to all. Apply 2 Vulnerable to all.",effects:[{type:"damage",value:8,target:"all"},{type:"vulnerable",value:2,target:"all"}]},{id:"iron_bastion",name:"Iron Bastion",cost:3,type:"cast",category:"fortification",rarity:"rare",description:"Gain 30 Block. Heal 5.",effects:[{type:"block",value:30,target:"self"},{type:"heal",value:5,target:"self"}]},{id:"rally_the_keep",name:"Rally the Keep",cost:2,type:"cast",category:"edict",rarity:"rare",description:"Draw 4 cards. Gain 1 Resolve.",effects:[{type:"draw",value:4},{type:"resolve",value:1}]},{id:"conflagration",name:"Conflagration",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Apply 6 Burn to all enemies. Deal 5 damage to all.",effects:[{type:"burn",value:6,target:"all"},{type:"damage",value:5,target:"all"}]},{id:"pale_ward",name:"Pale Ward",cost:2,type:"cast",category:"fortification",rarity:"rare",description:"Gain 15 Block. Apply 2 Weak to all enemies.",effects:[{type:"block",value:15,target:"self"},{type:"weak",value:2,target:"all"}]},{id:"cataclysm",name:"Cataclysm",cost:4,type:"cast",category:"armament",rarity:"legendary",description:"Deal 30 damage to all enemies. Take 10 Gate damage.",effects:[{type:"damage",value:30,target:"all"},{type:"self_damage",value:10}]},{id:"keeps_resolve",name:"Keep's Resolve",cost:0,type:"cast",category:"edict",rarity:"legendary",description:"Gain 2 Resolve. Draw 2 cards. Gain 10 Block.",effects:[{type:"resolve",value:2},{type:"draw",value:2},{type:"block",value:10,target:"self"}]},{id:"eternal_wall",name:"Eternal Wall",cost:4,type:"cast",category:"fortification",rarity:"legendary",description:"Gain 50 Block. Heal 10 Gate HP.",effects:[{type:"block",value:50,target:"self"},{type:"heal",value:10,target:"self"}]},{id:"barricade",name:"Barricade",cost:1,type:"emplace",category:"fortification",rarity:"common",description:"Cast: Gain 4 Block. Emplace: 8 HP structure, +2 Block/turn.",effects:[{type:"block",value:4,target:"self"}],emplaceCost:1,emplaceHp:8,emplaceEffects:[{type:"block",value:2,target:"self"}]},{id:"turret",name:"Turret",cost:2,type:"emplace",category:"armament",rarity:"uncommon",description:"Cast: Deal 5 damage. Emplace: 6 HP, deals 3 damage to column/turn.",effects:[{type:"damage",value:5,target:"single"}],emplaceCost:2,emplaceHp:6,emplaceEffects:[{type:"damage",value:3,target:"column"}]},{id:"beacon",name:"Beacon",cost:1,type:"emplace",category:"edict",rarity:"uncommon",description:"Cast: Draw 1 card. Emplace: 5 HP, heals 2 Gate HP/turn.",effects:[{type:"draw",value:1}],emplaceCost:1,emplaceHp:5,emplaceEffects:[{type:"heal",value:2,target:"self"}]},{id:"ward_stone",name:"Ward Stone",cost:1,type:"emplace",category:"fortification",rarity:"common",description:"Cast: Gain 3 Block. Emplace: 10 HP, applies 1 Weak to enemies in column.",effects:[{type:"block",value:3,target:"self"}],emplaceCost:1,emplaceHp:10,emplaceEffects:[{type:"weak",value:1,target:"column"}]},{id:"siphon",name:"Siphon",cost:2,type:"emplace",category:"wild",rarity:"rare",description:"Cast: Deal 4 damage to all. Emplace: 4 HP, deals 2 damage to adjacent columns.",effects:[{type:"damage",value:4,target:"all"}],emplaceCost:2,emplaceHp:4,emplaceEffects:[{type:"damage",value:2,target:"adjacent"}]},{id:"watchtower",name:"Watchtower",cost:1,type:"emplace",category:"edict",rarity:"common",description:"Cast: Draw 2 cards. Emplace: 4 HP, applies 1 Vulnerable to enemies in column.",effects:[{type:"draw",value:2}],emplaceCost:1,emplaceHp:4,emplaceEffects:[{type:"vulnerable",value:1,target:"column"}]},{id:"flame_pit",name:"Flame Pit",cost:2,type:"emplace",category:"armament",rarity:"uncommon",description:"Cast: Deal 6 damage to column. Emplace: 5 HP, deals 4 damage to column/turn.",effects:[{type:"damage",value:6,target:"column"}],emplaceCost:2,emplaceHp:5,emplaceEffects:[{type:"damage",value:4,target:"column"}]},{id:"bulwark",name:"Bulwark",cost:2,type:"emplace",category:"fortification",rarity:"rare",description:"Cast: Gain 10 Block. Emplace: 15 HP, +3 Block/turn.",effects:[{type:"block",value:10,target:"self"}],emplaceCost:2,emplaceHp:15,emplaceEffects:[{type:"block",value:3,target:"self"}]},{id:"spike_trap",name:"Spike Trap",cost:1,type:"emplace",category:"armament",rarity:"common",description:"Cast: Deal 3 damage. Emplace: 3 HP, deals 2 damage to column/turn.",effects:[{type:"damage",value:3,target:"single"}],emplaceCost:1,emplaceHp:3,emplaceEffects:[{type:"damage",value:2,target:"column"}]},{id:"sanctum",name:"Sanctum",cost:3,type:"emplace",category:"edict",rarity:"rare",description:"Cast: Heal 6, draw 1. Emplace: 8 HP, heals 3 Gate HP/turn, +1 Block/turn.",effects:[{type:"heal",value:6,target:"self"},{type:"draw",value:1}],emplaceCost:3,emplaceHp:8,emplaceEffects:[{type:"heal",value:3,target:"self"},{type:"block",value:1,target:"self"}]},{id:"emplacement_surge",name:"Emplacement Surge",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Each emplacement triggers its effect an extra time.",effects:[{type:"trigger_emplacements",value:1}]},{id:"fuel_the_fire",name:"Fuel the Fire",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 2 damage per Burn stack on all enemies.",effects:[{type:"damage_per_burn",value:2,target:"all"}]},{id:"fortified_assault",name:"Fortified Assault",cost:2,type:"cast",category:"armament",rarity:"rare",description:"Deal damage equal to your current Block.",effects:[{type:"damage_equal_block",value:1,target:"single"}]},{id:"pale_harvest",name:"Pale Harvest",cost:0,type:"cast",category:"edict",rarity:"uncommon",description:"Draw 1 card per enemy killed this combat. Exhaust.",effects:[{type:"draw_per_kills",value:1},{type:"exhaust_self",value:1}]},{id:"wall_breaker",name:"Wall Breaker",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 8 damage. If target is Vulnerable, deal 16 instead.",effects:[{type:"damage_if_vulnerable",value:8,target:"single"}]},{id:"chain_lightning",name:"Chain Lightning",cost:2,type:"cast",category:"armament",rarity:"rare",description:"Deal 5 damage to all enemies. For each killed, deal 5 more to all.",effects:[{type:"damage",value:5,target:"all"},{type:"damage_per_kill_this_action",value:5,target:"all"}]},{id:"recycle",name:"Recycle",cost:1,type:"cast",category:"edict",rarity:"common",description:"Exhaust a card from hand, draw 2.",effects:[{type:"exhaust_draw",value:2}]},{id:"keepers_ward",name:"Keeper's Ward",cost:1,type:"emplace",category:"fortification",rarity:"uncommon",description:"Cast: Gain 5 Block. Emplace: 6 HP, gives +1 damage to adjacent emplacements/turn.",effects:[{type:"block",value:5,target:"self"}],emplaceCost:1,emplaceHp:6,emplaceEffects:[{type:"damage",value:1,target:"adjacent"}]},{id:"combustion",name:"Combustion",cost:2,type:"cast",category:"armament",rarity:"rare",description:"Apply 4 Burn to all enemies. If any already has Burn, apply 6 instead.",effects:[{type:"burn_if_burning",value:4,target:"all"}]},{id:"bulwark_strike",name:"Bulwark Strike",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 4 damage + 1 per point of Block you have (max +10).",effects:[{type:"damage_plus_block",value:4,target:"single"}]},{id:"pale_echo",name:"Pale Echo",cost:2,type:"cast",category:"wild",rarity:"rare",description:"Play the last card you played again (copy its effects).",effects:[{type:"replay_last",value:1}]},{id:"column_collapse",name:"Column Collapse",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 12 damage to all enemies in target column. If column has an emplacement, deal 18 instead.",effects:[{type:"damage_if_emplaced",value:12,target:"column"}]},{id:"overcharge",name:"Overcharge",cost:0,type:"cast",category:"edict",rarity:"uncommon",description:"Gain 2 Resolve. Exhaust.",effects:[{type:"resolve",value:2},{type:"exhaust_self",value:1}]},{id:"desperate_strike",name:"Desperate Strike",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 5 damage. If Gate HP < 50%, deal 10 instead.",effects:[{type:"damage_if_low_hp",value:5,target:"single"}]},{id:"fortress_keeper",name:"Fortress Keeper",cost:3,type:"emplace",category:"fortification",rarity:"rare",description:"Cast: Gain 15 Block, draw 1. Emplace: 12 HP, +4 Block/turn, adjacent emplacements +2 HP.",effects:[{type:"block",value:15,target:"self"},{type:"draw",value:1}],emplaceCost:3,emplaceHp:12,emplaceEffects:[{type:"block",value:4,target:"self"}]},{id:"resonance",name:"Resonance",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 3 damage to all enemies for each emplacement you control.",effects:[{type:"damage_per_emplace",value:3,target:"all"}]},{id:"scavenge",name:"Scavenge",cost:0,type:"cast",category:"edict",rarity:"common",description:"Draw cards equal to number of empty potion slots.",effects:[{type:"draw_per_empty_potions",value:1}]},{id:"final_stand",name:"Final Stand",cost:3,type:"cast",category:"wild",rarity:"legendary",description:"Deal 10 damage to all. Gain 10 Block. Draw 3. Exhaust.",effects:[{type:"damage",value:10,target:"all"},{type:"block",value:10,target:"self"},{type:"draw",value:3},{type:"exhaust_self",value:1}]},{id:"pale_curse",name:"Pale Curse",cost:99,type:"cast",category:"wild",rarity:"common",description:"An echo of the Pale. Unplayable. Clogs your hand.",effects:[]}],Ma=["strike","strike","strike","guard","guard","spark","ember","brace","bolster","mend"];function J(e){return it.find(a=>a.id===e)}var ir=[{id:"hollow",name:"Hollow",symbol:"\u2620",hp:18,damage:6,speed:1,act:1,description:"An empty shape from the Pale. Advances steadily."},{id:"needle",name:"Needle",symbol:"\u2191",hp:10,damage:4,speed:2,act:1,description:"Fast and fragile. Advances two rows per turn."},{id:"shade",name:"Shade",symbol:"\u25C8",hp:22,damage:8,speed:1,act:1,description:"A dense fragment of the Pale. Hits hard."},{id:"wisp",name:"Wisp",symbol:"\u25CB",hp:8,damage:3,speed:1,act:1,description:"Fragile but numerous. Appears in swarms."},{id:"husk",name:"Husk",symbol:"\u2593",hp:30,damage:5,speed:1,act:1,description:"Armored shell. Slow but resilient."},{id:"wraith",name:"Wraith",symbol:"\u2248",hp:15,damage:7,speed:2,act:2,description:"Drifts through emplacements. Ignores structures."},{id:"breaker",name:"Breaker",symbol:"\u2692",hp:25,damage:10,speed:1,act:2,description:"Targets emplacements first. Destroys structures."},{id:"flanker",name:"Flanker",symbol:"\u2194",hp:14,damage:6,speed:1,act:2,description:"Shifts columns before attacking."},{id:"shielder",name:"Shielder",symbol:"\u25C7",hp:20,damage:4,speed:1,act:2,description:"Grants shield to adjacent enemies."},{id:"echo",name:"Echo",symbol:"\u221E",hp:35,damage:12,speed:1,act:3,description:"A memory of something that should not exist."},{id:"boss_suture",name:"The Suture",symbol:"\u25C8",hp:60,damage:8,speed:1,act:1,description:"Stitched from fragments of the Pale. The first true threat."},{id:"boss_archivist",name:"The Archivist",symbol:"\u25A3",hp:90,damage:10,speed:1,act:2,description:"Keeper of forgotten records. Debuffs and shields methodically."},{id:"boss_pale",name:"The Pale Itself",symbol:"\u25C9",hp:130,damage:12,speed:1,act:3,description:"The void given form. Three phases of escalating horror."}];function Ce(e){return ir.find(a=>a.id===e)}var ct=[{id:"heal_potion",name:"Mending Draught",description:"Heal 15 Gate HP.",effects:[{type:"heal",value:15,target:"self"}]},{id:"damage_potion",name:"Fire Flask",description:"Deal 10 damage to all enemies in a column.",effects:[{type:"damage",value:10,target:"column"}]},{id:"block_potion",name:"Iron Tonic",description:"Gain 15 Block.",effects:[{type:"block",value:15,target:"self"}]},{id:"draw_potion",name:"Seer's Ink",description:"Draw 3 cards.",effects:[{type:"draw",value:3}]},{id:"resolve_potion",name:"Warden's Flame",description:"Gain 2 Resolve this turn.",effects:[{type:"resolve",value:2}]}],Tt={combat:15,elite:30,boss:50},cr=[{npcId:"wren",tier:0,lines:[{id:"wren_t0_1",speaker:"Wren",text:"Welcome to the Keep, Warden. I maintain what's left of it."},{id:"wren_t0_2",speaker:"Wren",text:"The Pale has been encroaching for years now. Each run pushes it back \u2014 a little."},{id:"wren_t0_3",speaker:"Wren",text:"The Echoes you bring back... they're more than currency. They're fragments of what the Pale has consumed."}]},{npcId:"wren",tier:1,lines:[{id:"wren_t1_1",speaker:"Wren",text:"You're doing well, Warden. The Keep grows stronger."},{id:"wren_t1_2",speaker:"Wren",text:"I've been organizing the archives. There are records of other keeps \u2014 all fallen."},{id:"wren_t1_3",speaker:"Wren",text:"Did you know the Pale wasn't always like this? Sable might tell you more."},{id:"wren_t1_4",speaker:"Wren",text:"The structures you build... I can feel them resonate. Like the Keep remembers what it was."}]},{npcId:"wren",tier:2,lines:[{id:"wren_t2_1",speaker:"Wren",text:"I found something in the lower chambers. A journal. The previous Warden's."},{id:"wren_t2_2",speaker:"Wren",text:'"The Pale does not destroy," they wrote. "It remembers \u2014 and in remembering, unmakes."'},{id:"wren_t2_3",speaker:"Wren",text:"I think this Keep has been here longer than any of us know."}]},{npcId:"wren",tier:3,lines:[{id:"wren_t3_1",speaker:"Wren",text:"Warden. I need to tell you something. The Pale Visitor... they're not what they seem."},{id:"wren_t3_2",speaker:"Wren",text:"I've been tracking the patterns. Every fifty runs, the Pale shifts. Something deeper stirs."}]},{npcId:"wren",tier:4,lines:[{id:"wren_t4_1",speaker:"Wren",text:"The truth is... there have been many Wardens. You're not the first. And you won't be the last."},{id:"wren_t4_2",speaker:"Wren",text:"Unless you find the source. The thing the Pale is actually looking for."}]},{npcId:"sable",tier:0,lines:[{id:"sable_t0_1",speaker:"Sable",text:"Hmm? Oh, another Warden. The Archive is open, if you can read the old script."},{id:"sable_t0_2",speaker:"Sable",text:"Cards, Warden. That's what the old records call them. Patterns of power, crystallized."},{id:"sable_t0_3",speaker:"Sable",text:"The Pale erases. But patterns \u2014 true patterns \u2014 resist erasure. That's what your deck is."}]},{npcId:"sable",tier:1,lines:[{id:"sable_t1_1",speaker:"Sable",text:"I've decoded another section. The Pale isn't natural. It was created."},{id:"sable_t1_2",speaker:"Sable",text:"Someone \u2014 or something \u2014 made the Pale as a weapon. Against what, I don't yet know."},{id:"sable_t1_3",speaker:"Sable",text:"The emplacements you build... they're based on ancient designs. The old Keep had them too."}]},{npcId:"sable",tier:2,lines:[{id:"sable_t2_1",speaker:"Sable",text:'I found it. A name: "The Architect." They built the first Keep \u2014 and the first Pale.'},{id:"sable_t2_2",speaker:"Sable",text:"The Architect wanted to preserve everything. So they built a system that remembers. Perfectly."},{id:"sable_t2_3",speaker:"Sable",text:"A perfect memory is indistinguishable from a prison, Warden."}]},{npcId:"sable",tier:3,lines:[{id:"sable_t3_1",speaker:"Sable",text:"The bosses you fight... they're not monsters. They're memories. The Suture, the Archivist..."},{id:"sable_t3_2",speaker:"Sable",text:"Wait. The Archivist. That's my title. Why is there a boss named after my role?"}]},{npcId:"sable",tier:4,lines:[{id:"sable_t4_1",speaker:"Sable",text:"I cross-referenced myself against the Archive records. The result was... recursive."},{id:"sable_t4_2",speaker:"Sable",text:"The original Archivist's handwriting. It's identical to mine. Not similar \u2014 identical."},{id:"sable_t4_3",speaker:"Sable",text:"I'm not afraid that I'm a copy, Warden. I'm afraid that the copy was an improvement."}]},{npcId:"sable",tier:5,lines:[{id:"sable_t5_1",speaker:"Sable",text:"I found something in the Archive today. A letter, addressed to me. In my handwriting. Dated three hundred years ago."},{id:"sable_t5_2",speaker:"Sable",text:"It said: 'When you find this, stop looking. Some records exist to be lost.'"},{id:"sable_t5_3",speaker:"Sable",text:"I've decided to keep cataloguing. Not because I have to. Because it's the only thing I do that the original never did."}]},{npcId:"duskmar",tier:0,lines:[{id:"dusk_t0_1",speaker:"Duskmar",text:"I was the first to man these walls. And I'll be the last, if it comes to that."},{id:"dusk_t0_2",speaker:"Duskmar",text:"The Hollows are nothing. Wait until you face the Shades. Or the things in Act 3."},{id:"dusk_t0_3",speaker:"Duskmar",text:"Block. Always block. The Pale punishes the reckless."}]},{npcId:"duskmar",tier:1,lines:[{id:"dusk_t1_1",speaker:"Duskmar",text:"I've been teaching the walls to remember. Emplacements \u2014 that's the real defense."},{id:"dusk_t1_2",speaker:"Duskmar",text:"Every time you ascend, the Pale gets smarter. But so do you."}]},{npcId:"duskmar",tier:2,lines:[{id:"dusk_t2_1",speaker:"Duskmar",text:"I died once, you know. In the Pale. Wren brought me back with Echoes."},{id:"dusk_t2_2",speaker:"Duskmar",text:"Death isn't permanent here. That should worry you more than it comforts you."}]},{npcId:"duskmar",tier:4,lines:[{id:"duskmar_t4_1",speaker:"Duskmar",text:"I remember dying, Warden. Not the pain \u2014 that faded. The silence after."},{id:"duskmar_t4_2",speaker:"Duskmar",text:"When they brought me back, I could feel the Pale filling the gaps where memories should be. Cold, like water in a cracked foundation."},{id:"duskmar_t4_3",speaker:"Duskmar",text:"I don't block because I'm brave. I block because I know exactly what it costs to fall."}]},{npcId:"mott",tier:0,lines:[{id:"mott_t0_1",speaker:"Mott",text:"Fragments! Echoes! Bits and pieces of a world that doesn't exist anymore!"},{id:"mott_t0_2",speaker:"Mott",text:"I trade in what the Pale leaves behind. Potions, mostly. Sometimes relics."},{id:"mott_t0_3",speaker:"Mott",text:"The shop in the Pale? That's me. Well, a memory of me. It's complicated."}]},{npcId:"mott",tier:1,lines:[{id:"mott_t1_1",speaker:"Mott",text:"Found something odd today. A card that doesn't match any pattern I've seen."},{id:"mott_t1_2",speaker:"Mott",text:"The relics aren't just powerful. They're pieces of the old world. Before the Pale."}]},{npcId:"mott",tier:2,lines:[{id:"mott_t2_1",speaker:"Mott",text:"I figured it out. The fragments? They're not resources. They're memories \u2014 compressed."},{id:"mott_t2_2",speaker:"Mott",text:"When you spend fragments, you're spending someone's past. Heavy, right?"}]},{npcId:"mott",tier:4,lines:[{id:"mott_t4_1",speaker:"Mott",text:"I can't sell this one. It's... it's someone's last birthday. The whole day, compressed into a shard."},{id:"mott_t4_2",speaker:"Mott",text:"You ever wonder if we're the good guys, Warden? Spending people's pasts like pocket change?"},{id:"mott_t4_3",speaker:"Mott",text:"Found a fragment today that tasted like rain. Don't ask me how I know that. Don't ask me why I cried."}]},{npcId:"pale_visitor",tier:0,lines:[{id:"pv_t0_1",speaker:"???",text:"..."},{id:"pv_t0_2",speaker:"???",text:"You can see me. Interesting. Most Wardens take longer."}]},{npcId:"pale_visitor",tier:1,lines:[{id:"pv_t1_1",speaker:"The Visitor",text:"Do you know why the Keep exists, Warden?"},{id:"pv_t1_2",speaker:"The Visitor",text:"Not to fight the Pale. To contain it. There's a difference."}]},{npcId:"pale_visitor",tier:2,lines:[{id:"pv_t2_1",speaker:"The Visitor",text:"I am the Pale. Or I was. The part of it that wanted to stop."},{id:"pv_t2_2",speaker:"The Visitor",text:"Every run you complete, you weaken the whole. But you also feed it."}]},{npcId:"pale_visitor",tier:3,lines:[{id:"pv_t3_1",speaker:"The Visitor",text:"The Architect built me as a failsafe. I was supposed to shut it all down."},{id:"pv_t3_2",speaker:"The Visitor",text:"But I can't. Not alone. That's why I need a Warden."}]},{npcId:"pale_visitor",tier:4,lines:[{id:"pv_t4_1",speaker:"The Visitor",text:"There is a place where the Pale is thin enough to see through. You will know it when the game stops feeling like a game."},{id:"pv_t4_2",speaker:"The Visitor",text:"The Architect left two doors. One leads out. One leads deeper. Both are locked from the inside."},{id:"pv_t4_3",speaker:"The Visitor",text:"You're closer than any Warden has been. That's not a compliment. It's a warning."}]},{npcId:"pale_visitor",tier:5,lines:[{id:"pv_t5_1",speaker:"???",text:"The Pale doesn't consume. It remembers. And a memory that remembers itself..."},{id:"pv_t5_2",speaker:"???",text:"You've seen the Architect's journal. You know what they tried to build. Do you understand what they actually built?"},{id:"pv_t5_3",speaker:"???",text:"The Keep is not a fortress, Warden. It's an argument. Against eternity. And you are its latest word."}]}];function dr(e,a){return cr.filter(t=>t.npcId===e&&t.tier<=a).flatMap(t=>t.lines)}function Ba(e,a,n){let t=dr(e,a),r=new Set(n);return t.filter(o=>!r.has(o.id))}import{writeFileSync as ea,readFileSync as Kr,mkdirSync as Ur,existsSync as ma,renameSync as qr,unlinkSync as Yr}from"fs";import{join as on,dirname as zr}from"path";import{homedir as jr}from"os";function K(e){let a=e|0;return()=>{a=a+1831565813|0;let n=Math.imul(a^a>>>15,1|a);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function he(e){let a=0;for(let n=0;n<e.length;n++){let t=e.charCodeAt(n);a=(a<<5)-a+t|0}return a}function Na(e,a){let n=[...e];for(let t=n.length-1;t>0;t--){let r=Math.floor(a()*(t+1));[n[t],n[r]]=[n[r],n[t]]}return n}var mr=1;function mt(e){return{instanceId:`card-${mr++}`,defId:e,upgraded:!1}}function aa(){return Ma.map(mt)}function ur(e,a){return Na(e,a)}function De(e,a,n,t){let r=[],o=[...e],l=[...a];for(let c=0;c<n;c++){if(o.length===0){if(l.length===0)break;o=Na(l,t),l=[]}r.push(o.shift())}return{drawn:r,newDrawPile:o,newDiscardPile:l}}var pr=[{templateId:"boss_suture",name:"The Suture",act:1,phases:[{hpThreshold:1,intentPattern:[{type:"attack",value:8},{type:"advance",value:1},{type:"attack",value:12}]},{hpThreshold:.5,intentPattern:[{type:"attack",value:15},{type:"summon",value:2},{type:"attack",value:10}]}],dialogue:[{storyLayer:"surface",onAppear:"I will stitch this Keep into silence.",onDefeat:"Unraveled... but the thread remains..."},{storyLayer:"cracks",onAppear:"You again. How many times have we done this?",onPhaseChange:"I remember you. Every time."},{storyLayer:"truth",onAppear:"I was a warden once. Before the stitching."}],onPhaseChange:(e,a,n)=>{let t=e.columns[2];t.enemies.length<3&&t.enemies.push(ra("needle",2))}},{templateId:"boss_archivist",name:"The Archivist",act:2,phases:[{hpThreshold:1,intentPattern:[{type:"debuff",value:2},{type:"attack",value:10},{type:"shield",value:15}]},{hpThreshold:.5,intentPattern:[{type:"attack",value:18},{type:"debuff",value:3},{type:"summon",value:3}]}],dialogue:[{storyLayer:"surface",onAppear:"Everything must be recorded. Including your defeat.",onDefeat:"The records... will continue... without me..."},{storyLayer:"cracks",onAppear:"Sable? Is that... no. Not yet. Not this time."},{storyLayer:"truth",onAppear:"I am what Sable will become. I am what the Archive demands."}]},{templateId:"boss_pale",name:"The Pale Itself",act:3,phases:[{hpThreshold:1,intentPattern:[{type:"attack",value:12},{type:"advance",value:1},{type:"summon",value:2}]},{hpThreshold:.6,intentPattern:[{type:"attack",value:20},{type:"debuff",value:3},{type:"attack",value:15}]},{hpThreshold:.3,intentPattern:[{type:"attack",value:25},{type:"summon",value:3},{type:"attack",value:20}]}],dialogue:[{storyLayer:"surface",onAppear:"I am the memory of everything. And everything remembers its end."},{storyLayer:"cracks",onAppear:"You've learned to read the patterns. But patterns are cages too."},{storyLayer:"truth",onAppear:"The Architect made me to preserve. I preserved so perfectly that nothing could change. Is that not love?"},{storyLayer:"true_ending",onAppear:"You carry the same question the Architect carried. The answer hasn't changed. Only the one asking."}],onPhaseChange:(e,a,n)=>{if(n>=2)for(let t of e.columns)for(let r of t.enemies){let o=r.statusEffects.find(l=>l.type==="empowered");o?o.stacks+=1:r.statusEffects.push({type:"empowered",stacks:1,duration:99})}}}];function na(e){return pr.find(a=>a.act===e)}function fr(e,a,n){let t=e.phases[0];for(let o of e.phases)a<=o.hpThreshold&&(t=o);let r=(n-1)%t.intentPattern.length;return t.intentPattern[r]}function Ga(e){switch(e){case 1:return[{templateId:"boss_suture",column:2},{templateId:"hollow",column:0},{templateId:"hollow",column:4}];case 2:return[{templateId:"boss_archivist",column:2},{templateId:"wraith",column:1},{templateId:"wraith",column:3}];case 3:return[{templateId:"boss_pale",column:2},{templateId:"echo",column:0},{templateId:"echo",column:4}];default:return[{templateId:"boss_suture",column:2}]}}var hr=1;function ra(e,a){let n=Ce(e);if(!n)throw new Error(`Unknown enemy template: ${e}`);return{instanceId:`enemy-${hr++}`,templateId:e,hp:n.hp,maxHp:n.hp,column:Math.max(0,Math.min(a,st-1)),row:0,intent:null,statusEffects:[]}}function oa(e,a,n=1,t=!1){let r=Ce(e.templateId);if(!r)return{type:"advance",value:1};let o=na(r.act);if(o&&o.templateId===e.templateId){let c=e.hp/e.maxHp;return fr(o,c,n)}let l=a();switch(e.templateId){case"shielder":return l<.3?{type:"shield",value:5}:l<.6?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"flanker":return l<.4?{type:"attack",value:r.damage,targetColumn:e.column}:l<.7?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"breaker":return t?{type:"advance",value:r.speed}:l<.6?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"wraith":return l<.4?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"echo":return l<.3?{type:"buff",value:1}:l<.6?{type:"attack",value:r.damage,targetColumn:e.column}:{type:"advance",value:r.speed};default:return l<.5?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column}}}function gr(e,a,n,t=0){if(n<0||n>=e.columns.length||e.columns[n].emplacement||!a.emplaceHp||!a.emplaceEffects)return!1;let r=a.emplaceHp+t;return e.columns[n].emplacement={cardDefId:a.id,hp:r,maxHp:r,effects:a.emplaceEffects},e.events.push({type:"emplacement_placed",turn:e.turn,data:{cardId:a.id,column:n}}),!0}function Wa(e){let a=e.columns.filter(n=>n.emplacement).length;for(let n of e.columns){if(!n.emplacement)continue;for(let l of n.emplacement.effects)yr(e,n.index,l);let t=n.index>0&&e.columns[n.index-1].emplacement,r=n.index<e.columns.length-1&&e.columns[n.index+1].emplacement,o=(t?1:0)+(r?1:0);if(o>0)for(let l of n.emplacement.effects){if(l.type==="damage")for(let c of n.enemies)c.hp-=o;l.type==="block"&&(e.gateBlock+=o)}a>=3&&(e.gateBlock+=a),e.events.push({type:"emplacement_triggered",turn:e.turn,data:{column:n.index,cardId:n.emplacement.cardDefId,adjacencyBonus:o}})}}function yr(e,a,n){let t=e.columns[a];switch(n.type){case"damage":{if(n.target==="column")for(let r of t.enemies)r.hp-=n.value;else if(n.target==="adjacent")for(let r=Math.max(0,a-1);r<=Math.min(e.columns.length-1,a+1);r++)for(let o of e.columns[r].enemies)o.hp-=n.value;else for(let r of t.enemies)r.hp-=n.value;break}case"block":e.gateBlock+=n.value;break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+n.value);break;case"weak":for(let r of t.enemies){let o=r.statusEffects.find(l=>l.type==="weak");o?o.stacks+=n.value:r.statusEffects.push({type:"weak",stacks:n.value,duration:2})}break;case"vulnerable":for(let r of t.enemies){let o=r.statusEffects.find(l=>l.type==="vulnerable");o?o.stacks+=n.value:r.statusEffects.push({type:"vulnerable",stacks:n.value,duration:2})}break}}function wr(e,a,n){let t=e.columns[a];if(!t.emplacement||!n.emplaceHp||!n.emplaceEffects)return!1;t.emplacement.hp+=Math.floor(n.emplaceHp/2),t.emplacement.maxHp+=Math.floor(n.emplaceHp/2);for(let r of n.emplaceEffects){let o=t.emplacement.effects.find(l=>l.type===r.type&&l.target===r.target);o?o.value+=Math.floor(r.value/2):t.emplacement.effects.push({...r,value:Math.floor(r.value/2)})}return e.events.push({type:"emplacement_placed",turn:e.turn,data:{cardId:n.id,column:a,reinforced:!0}}),!0}function br(e){e.statusEffects=e.statusEffects.map(a=>({...a,duration:a.duration-1})).filter(a=>a.duration>0&&a.stacks>0)}function ae(e,a,n,t=2){let r=e.statusEffects.find(o=>o.type===a);r?(r.stacks+=n,r.duration=Math.max(r.duration,t)):e.statusEffects.push({type:a,stacks:n,duration:t})}function Te(e,a){return e.statusEffects.find(t=>t.type===a)?.stacks??0}function vr(e){let a=1,n=Te(e,"vulnerable");n>0&&(a*=1+n*.25);let t=Te(e,"fortified");return t>0&&(a*=Math.max(.25,1-t*.15)),a}function kr(e){let a=1,n=Te(e,"weak");return n>0&&(a*=Math.max(.25,1-n*.15)),Te(e,"empowered")>0&&(a*=1+Te(e,"empowered")*.25),a}function Tr(e){let a=Te(e,"burn");if(a>0){e.hp-=a;let n=e.statusEffects.find(t=>t.type==="burn");return n&&(n.stacks=Math.max(0,n.stacks-1)),a}return 0}var Fa=[{id:"wardens_signet",name:"Warden's Signet",description:"+1 max Resolve.",trigger:"passive",effect:{type:"max_resolve_bonus",value:1}},{id:"column_keystone",name:"Column Keystone",description:"When you emplace, gain 8 Block.",trigger:"on_emplace",effect:{type:"block_on_emplace",value:8}},{id:"echo_shard",name:"Echo Shard",description:"When an enemy dies, deal 3 damage to all enemies in same column.",trigger:"on_enemy_kill",effect:{type:"deal_damage_column",value:3}},{id:"pale_lens",name:"Pale Lens",description:"At combat start, apply 1 Vulnerable to all enemies.",trigger:"on_combat_start",effect:{type:"apply_vulnerable_all",value:1}},{id:"burnished_shield",name:"Burnished Shield",description:"At turn start, if Resolve is 0, gain 8 Block.",trigger:"on_turn_start",effect:{type:"gain_block",value:8}},{id:"ember_crown",name:"Ember Crown",description:"When an enemy dies from Burn, apply 2 Burn to all enemies.",trigger:"on_enemy_kill",effect:{type:"burn_on_kill",value:2}},{id:"architects_blueprint",name:"Architect's Blueprint",description:"Emplacements gain +4 HP.",trigger:"passive",effect:{type:"emplace_hp_bonus",value:4}},{id:"ironwood_staff",name:"Ironwood Staff",description:"Draw 1 extra card each turn.",trigger:"on_turn_start",effect:{type:"draw_cards",value:1}},{id:"siege_engine",name:"Siege Engine",description:"Your first card each turn costs 0 Resolve.",trigger:"on_turn_start",effect:{type:"first_card_free",value:1}},{id:"pale_compass",name:"Pale Compass",description:"After elite kills, gain a card reward.",trigger:"on_elite_kill",effect:{type:"extra_card_reward",value:1}},{id:"fragment_magnet",name:"Fragment Magnet",description:"Gain +5 fragments per combat.",trigger:"passive",effect:{type:"fragment_bonus",value:5}},{id:"hexproof_seal",name:"Hexproof Seal",description:"At combat start, gain 10 Block.",trigger:"on_combat_start",effect:{type:"gain_block",value:10}},{id:"war_drum",name:"War Drum",description:"At combat start, apply 1 Weak to all enemies.",trigger:"on_combat_start",effect:{type:"apply_weak_all",value:1}},{id:"living_wall",name:"Living Wall",description:"When you emplace, draw 2 cards.",trigger:"on_emplace",effect:{type:"draw_cards",value:2}},{id:"siphon_ring",name:"Siphon Ring",description:"On card play, if card costs 2+, heal 2 Gate HP.",trigger:"on_card_play",effect:{type:"heal",value:2}},{id:"void_prism",name:"Void Prism",description:"At turn start, deal 2 damage to all enemies.",trigger:"on_turn_start",effect:{type:"deal_damage_all",value:2}},{id:"watchers_eye",name:"Watcher's Eye",description:"At combat start, draw 2 extra cards.",trigger:"on_combat_start",effect:{type:"draw_cards",value:2}},{id:"fortress_heart",name:"Fortress Heart",description:"Emplacements gain +3 HP.",trigger:"passive",effect:{type:"emplace_hp_bonus",value:3}},{id:"mending_stone",name:"Mending Stone",description:"After combat, heal 5 Gate HP.",trigger:"passive",effect:{type:"heal",value:5}},{id:"pale_harvester",name:"Pale Harvester",description:"On enemy kill, gain 1 Resolve (cap at max+2).",trigger:"on_enemy_kill",effect:{type:"gain_resolve",value:1}}];function _t(e){return Fa.find(a=>a.id===e)}function $a(e,a,n=3){let t=Fa.filter(l=>!a.includes(l.id)),r=[],o=[...t];for(let l=0;l<n&&o.length>0;l++){let c=Math.floor(e()*o.length);r.push(o[c]),o.splice(c,1)}return r}function dt(e,a,n,t){for(let r of a){let o=_t(r);if(!(!o||o.trigger!==n))switch(o.effect.type){case"gain_block":{if(r==="burnished_shield"&&e.resolve>0)break;e.gateBlock+=o.effect.value,e.events.push({type:"block_gained",turn:e.turn,data:{value:o.effect.value,relic:r}});break}case"gain_resolve":{let l=e.maxResolve+2;e.resolve=Math.min(l,e.resolve+o.effect.value);break}case"draw_cards":{let{drawCards:l}=Ir(),{drawn:c,newDrawPile:s,newDiscardPile:f}=l(e.drawPile,e.discardPile,o.effect.value,xr(e));e.hand.push(...c),e.drawPile=s,e.discardPile=f;break}case"deal_damage_all":{for(let l of e.columns)for(let c of l.enemies)c.hp-=o.effect.value;break}case"deal_damage_column":{let l=t?.column;if(l!==void 0){let c=e.columns[l];if(c)for(let s of c.enemies)s.hp-=o.effect.value}break}case"heal":{if(n==="on_card_play"){let l=t?.cardCost;if(l!==void 0&&l<2)break}e.gateHp=Math.min(e.gateMaxHp,e.gateHp+o.effect.value);break}case"apply_vulnerable_all":{for(let l of e.columns)for(let c of l.enemies)ae(c,"vulnerable",o.effect.value,3);break}case"apply_weak_all":{for(let l of e.columns)for(let c of l.enemies)ae(c,"weak",o.effect.value,3);break}case"burn_on_kill":{if(t?.diedFromBurn)for(let c of e.columns)for(let s of c.enemies)ae(s,"burn",o.effect.value,99);break}case"block_on_emplace":{e.gateBlock+=o.effect.value,e.events.push({type:"block_gained",turn:e.turn,data:{value:o.effect.value,relic:r}});break}case"first_card_free":case"emplace_hp_bonus":case"max_resolve_bonus":case"extra_card_reward":case"fragment_bonus":break}}}function xr(e){return _r(e.seed+e.turn*7+13)}function _r(e){let a=e>>>0;return()=>{a=a+1831565813|0;let n=Math.imul(a^a>>>15,1|a);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function Ir(){return{drawCards(e,a,n,t){let r=[],o=[...e],l=[...a];for(let c=0;c<n;c++){if(o.length===0){if(l.length===0)break;for(let s=l.length-1;s>0;s--){let f=Math.floor(t()*(s+1));[l[s],l[f]]=[l[f],l[s]]}o.push(...l),l=[]}r.push(o.shift())}return{drawn:r,newDrawPile:o,newDiscardPile:l}}}}function Cr(e){let a=0;for(let n of e){let t=_t(n);t&&t.effect.type==="emplace_hp_bonus"&&(a+=t.effect.value)}return a}function Sr(e){let a=0;for(let n of e){let t=_t(n);t&&t.effect.type==="max_resolve_bonus"&&(a+=t.effect.value)}return a}function Er(e){return e.some(a=>{let n=_t(a);return n&&n.effect.type==="first_card_free"})}function Va(e,a,n=Xt,t=Xt,r=[{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"needle",column:2}],o=[],l){let c=K(a),s=ur(e,c),f=Sr(o),b=(l?.reducedMaxResolve?jt-1:jt)+f,v=l?.reducedHandSize?lt-1:lt,I=Array.from({length:st},(T,_)=>({index:_,enemies:[],emplacement:null}));for(let T of r){let _=ra(T.templateId,T.column);l?.enemyHpMult&&l.enemyHpMult!==1&&(_.hp=Math.ceil(_.hp*l.enemyHpMult),_.maxHp=Math.ceil(_.maxHp*l.enemyHpMult)),l?.enemyBlitz&&(_.row=1),l?.enemyStartFortified&&ae(_,"fortified",1,99),I[_.column].enemies.push(_)}let{drawn:C,newDrawPile:d,newDiscardPile:h}=De(s,[],v,c),E={columns:I,hand:C,drawPile:d,discardPile:h,exhaustPile:[],gateHp:n,gateMaxHp:t,gateBlock:0,resolve:b,maxResolve:b,turn:1,phase:"player",outcome:"undecided",events:[],seed:a,killsThisCombat:0,relics:o,difficulty:l};dt(E,o,"on_combat_start");for(let T of I)for(let _ of T.enemies){let y=T.emplacement!==null;_.intent=oa(_,c,1,y)}return O(E,"turn_start",{turn:1}),E}function O(e,a,n){e.events.push({type:a,turn:e.turn,data:n}),e.events.length>100&&(e.events=e.events.slice(-100))}function La(e,a,n,t=!1){if(e.phase!=="player")return e;let r=e.hand[a];if(!r)return e;let o=J(r.defId);if(!o)return e;let l=!e.events.some(s=>s.type==="card_played"&&s.turn===e.turn),c=Er(e.relics)&&l;if(t&&o.type==="emplace"&&o.emplaceCost!==void 0){let s=c?0:o.emplaceCost;if(s>e.resolve)return e;let f=n??0,b=Cr(e.relics);if(!(gr(e,o,f,b)||wr(e,f,o)))return e;e.resolve-=s,e.hand.splice(a,1),e.exhaustPile.push(r),dt(e,e.relics,"on_emplace")}else{let s=c?0:o.cost;if(s>e.resolve)return e;e.resolve-=s,e.hand.splice(a,1);let f=!1;for(let b of o.effects){if(b.type==="exhaust_self"){f=!0;continue}Oa(e,b,n??0)}Zt(e),f?e.exhaustPile.push(r):e.discardPile.push(r),dt(e,e.relics,"on_card_play",{cardCost:o.cost,cardId:o.id})}return e.lastCardPlayed=r.defId,O(e,"card_played",{cardId:r.defId,targetColumn:n,asEmplace:t}),Qt(e),e}function Oa(e,a,n){switch(a.type){case"damage":{if(a.target==="all")for(let t of e.columns)for(let r of t.enemies)fe(e,r,a.value);else if(a.target==="column"){let t=e.columns[n];if(t)for(let r of t.enemies)fe(e,r,a.value)}else{let t=e.columns[n];if(t&&t.enemies.length>0){let r=t.enemies.reduce((o,l)=>o.row>=l.row?o:l);fe(e,r,a.value)}}break}case"block":e.gateBlock+=a.value,O(e,"block_gained",{value:a.value});break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+a.value);break;case"draw":{let{drawn:t,newDrawPile:r,newDiscardPile:o}=De(e.drawPile,e.discardPile,a.value,K(e.seed+e.turn));e.hand.push(...t),e.drawPile=r,e.discardPile=o;break}case"resolve":e.resolve=Math.min(e.maxResolve+5,e.resolve+a.value);break;case"vulnerable":{if(a.target==="all")for(let t of e.columns)for(let r of t.enemies)ae(r,"vulnerable",a.value,3);else if(a.target==="column"){let t=e.columns[n];if(t)for(let r of t.enemies)ae(r,"vulnerable",a.value,3)}else{let t=e.columns[n];if(t&&t.enemies.length>0){let r=t.enemies.reduce((o,l)=>o.row>=l.row?o:l);ae(r,"vulnerable",a.value,3)}}O(e,"status_applied",{type:"vulnerable",value:a.value,column:n});break}case"weak":{if(a.target==="all")for(let t of e.columns)for(let r of t.enemies)ae(r,"weak",a.value,3);else if(a.target==="column"){let t=e.columns[n];if(t)for(let r of t.enemies)ae(r,"weak",a.value,3)}else{let t=e.columns[n];if(t&&t.enemies.length>0){let r=t.enemies.reduce((o,l)=>o.row>=l.row?o:l);ae(r,"weak",a.value,3)}}O(e,"status_applied",{type:"weak",value:a.value,column:n});break}case"burn":{if(a.target==="all")for(let t of e.columns)for(let r of t.enemies)ae(r,"burn",a.value,99);else{let t=e.columns[n];if(t)for(let r of t.enemies)ae(r,"burn",a.value,99)}break}case"self_damage":{e.gateHp-=a.value,O(e,"gate_hit",{self:!0,damage:a.value});break}case"fortify":break;case"trigger_emplacements":{Wa(e);break}case"damage_per_burn":{for(let t of e.columns)for(let r of t.enemies){let o=Te(r,"burn");o>0&&fe(e,r,a.value*o)}break}case"damage_equal_block":{let t=e.gateBlock,r=e.columns[n];if(r&&r.enemies.length>0){let o=r.enemies.reduce((l,c)=>l.row>=c.row?l:c);fe(e,o,t)}break}case"draw_per_kills":{let t=e.killsThisCombat*a.value;if(t>0){let{drawn:r,newDrawPile:o,newDiscardPile:l}=De(e.drawPile,e.discardPile,t,K(e.seed+e.turn+3));e.hand.push(...r),e.drawPile=o,e.discardPile=l}break}case"damage_if_vulnerable":{let t=e.columns[n];if(t&&t.enemies.length>0){let r=t.enemies.reduce((c,s)=>c.row>=s.row?c:s),l=Te(r,"vulnerable")>0?a.value*2:a.value;fe(e,r,l)}break}case"damage_per_kill_this_action":{let t=Pr(e);if(t>0){let r=a.value*t;for(let o of e.columns)for(let l of o.enemies)fe(e,l,r)}break}case"exhaust_draw":{if(e.hand.length>0){let l=e.hand.shift();e.exhaustPile.push(l)}let{drawn:t,newDrawPile:r,newDiscardPile:o}=De(e.drawPile,e.discardPile,a.value,K(e.seed+e.turn+5));e.hand.push(...t),e.drawPile=r,e.discardPile=o;break}case"burn_if_burning":{let t=!1;for(let o of e.columns){for(let l of o.enemies)if(Te(l,"burn")>0){t=!0;break}if(t)break}let r=t?a.value+2:a.value;for(let o of e.columns)for(let l of o.enemies)ae(l,"burn",r,99);break}case"damage_plus_block":{let t=Math.min(e.gateBlock,10),r=a.value+t,o=e.columns[n];if(o&&o.enemies.length>0){let l=o.enemies.reduce((c,s)=>c.row>=s.row?c:s);fe(e,l,r)}break}case"replay_last":{if(e.lastCardPlayed&&e.lastCardPlayed!=="pale_echo"){let t=J(e.lastCardPlayed);if(t)for(let r of t.effects)r.type!=="exhaust_self"&&r.type!=="replay_last"&&Oa(e,r,n)}break}case"damage_if_emplaced":{let t=e.columns[n];if(t){let r=t.emplacement?Math.floor(a.value*1.5):a.value;for(let o of t.enemies)fe(e,o,r)}break}case"damage_if_low_hp":{let r=e.gateHp<e.gateMaxHp*.5?a.value*2:a.value,o=e.columns[n];if(o&&o.enemies.length>0){let l=o.enemies.reduce((c,s)=>c.row>=s.row?c:s);fe(e,l,r)}break}case"damage_per_emplace":{let t=e.columns.filter(r=>r.emplacement!==null).length;if(t>0){let r=a.value*t;for(let o of e.columns)for(let l of o.enemies)fe(e,l,r)}break}case"draw_per_empty_potions":{let{drawn:r,newDrawPile:o,newDiscardPile:l}=De(e.drawPile,e.discardPile,2,K(e.seed+e.turn+9));e.hand.push(...r),e.drawPile=o,e.discardPile=l;break}case"exhaust_self":break}}function Pr(e){let a=0;for(let n of e.columns)for(let t of n.enemies)t.hp<=0&&a++;return a}function fe(e,a,n){let t=vr(a),r=Math.floor(n*t);a.hp-=r,O(e,"damage_dealt",{targetId:a.instanceId,damage:r})}function Zt(e){for(let a of e.columns)a.enemies=a.enemies.filter(n=>{if(n.hp<=0){e.killsThisCombat++,O(e,"enemy_killed",{enemyId:n.instanceId,templateId:n.templateId});let t=Te(n,"burn")>0;return dt(e,e.relics,"on_enemy_kill",{column:a.index,diedFromBurn:t,templateId:n.templateId}),!1}return!0})}function Ka(e){return e.phase!=="player"||(O(e,"turn_end",{turn:e.turn}),e.phase="enemy",Rr(e)),e}function Rr(e){let a=K(e.seed+e.turn*31),n=e.columns.flatMap(c=>c.enemies.map(s=>({enemy:s,intent:s.intent??{type:"advance",value:1}})));for(let{enemy:c,intent:s}of n)c.hp<=0||Ar(e,c,s,a);if(Zt(e),Qt(e),e.outcome!=="undecided"||(e.turn++,e.phase="player",e.resolve=e.maxResolve,e.gateBlock=0,Wa(e),Zt(e),Qt(e),e.outcome!=="undecided"))return;dt(e,e.relics,"on_turn_start"),e.discardPile.push(...e.hand),e.hand=[];let t=e.difficulty?.reducedHandSize?lt-1:lt,{drawn:r,newDrawPile:o,newDiscardPile:l}=De(e.drawPile,e.discardPile,t,a);e.hand=r,e.drawPile=o,e.discardPile=l;for(let c of e.columns)for(let s of c.enemies){let f=c.emplacement!==null;s.intent=oa(s,a,e.turn,f)}O(e,"turn_start",{turn:e.turn})}function Ar(e,a,n,t){let r=Ce(a.templateId),o=kr(a),l=e.difficulty?.enemyDamageMult??1;if(Tr(a),br(a),!(a.hp<=0))switch(n.type){case"advance":{if(a.templateId==="breaker"){let c=e.columns[a.column];if(c.emplacement&&a.row>=ze-2){let s=(r?.damage??10)*2;c.emplacement.hp-=s,c.emplacement.hp<=0&&(O(e,"emplacement_destroyed",{column:a.column}),c.emplacement=null);break}}if(a.row=Math.min(ze-1,a.row+(r?.speed??1)),O(e,"enemy_advance",{enemyId:a.instanceId,row:a.row}),a.row>=ze-1)if(a.templateId==="wraith"){let c=Math.floor((r?.damage??7)*o*l),s=Math.min(e.gateBlock,c);e.gateBlock-=s,e.gateHp-=c-s,O(e,"gate_hit",{enemyId:a.instanceId,damage:c-s,blocked:s})}else{let c=e.columns[a.column];if(c.emplacement)c.emplacement.hp-=r?.damage??4,c.emplacement.hp<=0&&(O(e,"emplacement_destroyed",{column:a.column}),c.emplacement=null);else{let s=Math.floor((r?.damage??4)*o*l),f=Math.min(e.gateBlock,s);e.gateBlock-=f,e.gateHp-=s-f,O(e,"gate_hit",{enemyId:a.instanceId,damage:s-f,blocked:f})}}break}case"attack":{if(a.templateId==="flanker"){let f=t()<.5?-1:1,b=a.column,v=Math.max(0,Math.min(st-1,a.column+f));if(v!==b){let I=e.columns[b];I.enemies=I.enemies.filter(C=>C.instanceId!==a.instanceId),a.column=v,e.columns[v].enemies.push(a)}}let c=Math.floor((r?.damage??4)*o*l),s=Math.min(e.gateBlock,c);e.gateBlock-=s,e.gateHp-=c-s,O(e,"gate_hit",{enemyId:a.instanceId,damage:c-s,blocked:s});break}case"buff":ae(a,"empowered",n.value,3);break;case"debuff":{e.gateBlock=Math.max(0,e.gateBlock-n.value*2);break}case"shield":{let c=e.columns[a.column];for(let s of c.enemies)ae(s,"fortified",n.value,2);break}case"summon":{let c=e.columns.findIndex(s=>s.enemies.length===0);if(c>=0){let s=ra("wisp",c);e.columns[c].enemies.push(s),s.intent=oa(s,K(e.seed+e.turn*97))}break}}}function Qt(e){if(e.gateHp<=0){e.gateHp=0,e.outcome="lose",e.phase="ended",O(e,"combat_end",{outcome:"lose"});return}e.columns.reduce((n,t)=>n+t.enemies.length,0)===0&&(e.outcome="win",e.phase="ended",O(e,"combat_end",{outcome:"win"}))}function It(e,a=3,n=[]){let t=new Set(["strike","guard","bolster","brace","mend",...n]),o=it.filter(s=>!t.has(s.id)&&s.id!=="pale_curse").map(s=>({card:s,weight:s.rarity==="common"?6:s.rarity==="uncommon"?3:s.rarity==="rare"?1.5:.5})),l=[],c=new Set;for(let s=0;s<a&&o.length>0;s++){let f=o.filter(C=>!c.has(C.card.id));if(f.length===0)break;let b=f.reduce((C,d)=>C+d.weight,0),v=e()*b,I=!1;for(let C of f)if(v-=C.weight,v<=0){l.push(C.card),c.add(C.card.id),I=!0;break}I||(l.push(f[f.length-1].card),c.add(f[f.length-1].card.id))}return l}var Dr=[{name:"Scout Party",enemies:[{templateId:"hollow",column:1},{templateId:"hollow",column:3}]},{name:"Swift Assault",enemies:[{templateId:"needle",column:0},{templateId:"needle",column:2},{templateId:"needle",column:4}]},{name:"Pale Vanguard",enemies:[{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"needle",column:2}]},{name:"Wisp Swarm",enemies:[{templateId:"wisp",column:0},{templateId:"wisp",column:1},{templateId:"wisp",column:2},{templateId:"wisp",column:3},{templateId:"wisp",column:4}]},{name:"Heavy Patrol",enemies:[{templateId:"shade",column:1},{templateId:"hollow",column:3}]},{name:"Armored Column",enemies:[{templateId:"husk",column:2},{templateId:"wisp",column:0},{templateId:"wisp",column:4}]},{name:"Pale Scouts",enemies:[{templateId:"wisp",column:0},{templateId:"wisp",column:4},{templateId:"hollow",column:2}]},{name:"Needle Formation",enemies:[{templateId:"needle",column:1},{templateId:"needle",column:3}]},{name:"Husk Advance",enemies:[{templateId:"husk",column:2},{templateId:"wisp",column:1},{templateId:"wisp",column:3}]},{name:"Shadow Patrol",enemies:[{templateId:"shade",column:0},{templateId:"needle",column:4}]},{name:"Swarm Tide",enemies:[{templateId:"wisp",column:0},{templateId:"wisp",column:1},{templateId:"hollow",column:2},{templateId:"wisp",column:3},{templateId:"wisp",column:4}]},{name:"Hollow Shields",enemies:[{templateId:"hollow",column:1},{templateId:"hollow",column:2},{templateId:"hollow",column:3}]},{name:"Fast Assault",enemies:[{templateId:"needle",column:0},{templateId:"needle",column:2},{templateId:"needle",column:4}]},{name:"Pale Sentries",enemies:[{templateId:"shade",column:2},{templateId:"hollow",column:0},{templateId:"hollow",column:4}]}],Mr=[{name:"The Dark Tide",enemies:[{templateId:"shade",column:1},{templateId:"shade",column:3},{templateId:"needle",column:2}]},{name:"Hollow Legion",enemies:[{templateId:"hollow",column:0},{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"hollow",column:4}]},{name:"Husk Fortress",enemies:[{templateId:"husk",column:1},{templateId:"husk",column:3},{templateId:"needle",column:2}]},{name:"Shade Ambush",enemies:[{templateId:"shade",column:0},{templateId:"shade",column:2},{templateId:"shade",column:4}]}],Br=[{name:"The Warband",enemies:[{templateId:"breaker",column:2},{templateId:"shielder",column:1},{templateId:"shielder",column:3}]},{name:"Flanking Ambush",enemies:[{templateId:"flanker",column:0},{templateId:"flanker",column:4},{templateId:"wraith",column:2}]},{name:"Breaker Vanguard",enemies:[{templateId:"breaker",column:1},{templateId:"breaker",column:3},{templateId:"shielder",column:2}]},{name:"Phantom Blitz",enemies:[{templateId:"wraith",column:0},{templateId:"wraith",column:1},{templateId:"wraith",column:3},{templateId:"wraith",column:4}]}],Hr=[{name:"Echo Vanguard",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:3}]},{name:"The Final Test",enemies:[{templateId:"echo",column:2},{templateId:"breaker",column:0},{templateId:"flanker",column:4}]},{name:"Memory Siege",enemies:[{templateId:"echo",column:0},{templateId:"echo",column:2},{templateId:"echo",column:4}]},{name:"The Pale Tribunal",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:2},{templateId:"echo",column:3},{templateId:"breaker",column:0}]}],Nr=[{name:"Wraith Drift",enemies:[{templateId:"wraith",column:1},{templateId:"wraith",column:3}]},{name:"Breach Team",enemies:[{templateId:"breaker",column:2},{templateId:"flanker",column:0},{templateId:"flanker",column:4}]},{name:"Shield Wall",enemies:[{templateId:"shielder",column:2},{templateId:"hollow",column:1},{templateId:"hollow",column:3}]},{name:"Wraith Surge",enemies:[{templateId:"wraith",column:0},{templateId:"wraith",column:2},{templateId:"wraith",column:4}]},{name:"Flanker Pair",enemies:[{templateId:"flanker",column:1},{templateId:"flanker",column:3}]},{name:"Shielder Escort",enemies:[{templateId:"shielder",column:2},{templateId:"breaker",column:1},{templateId:"hollow",column:3}]},{name:"Pale Vanguard II",enemies:[{templateId:"breaker",column:0},{templateId:"flanker",column:2},{templateId:"shielder",column:4}]},{name:"Wraith Patrol",enemies:[{templateId:"wraith",column:1},{templateId:"hollow",column:0},{templateId:"hollow",column:4}]},{name:"Breaker Column",enemies:[{templateId:"breaker",column:2},{templateId:"wisp",column:0},{templateId:"wisp",column:1},{templateId:"wisp",column:3},{templateId:"wisp",column:4}]},{name:"Shield Formation",enemies:[{templateId:"shielder",column:1},{templateId:"shielder",column:3},{templateId:"flanker",column:2}]},{name:"Assault Wave",enemies:[{templateId:"breaker",column:1},{templateId:"breaker",column:3}]},{name:"Night Raid",enemies:[{templateId:"wraith",column:0},{templateId:"flanker",column:2},{templateId:"wraith",column:4}]},{name:"Armored Push",enemies:[{templateId:"shielder",column:0},{templateId:"breaker",column:2},{templateId:"shielder",column:4}]}],Gr=[{name:"Echoes of the End",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:3}]},{name:"Final Surge",enemies:[{templateId:"echo",column:2},{templateId:"wraith",column:0},{templateId:"wraith",column:4},{templateId:"breaker",column:1}]},{name:"Echo Patrol",enemies:[{templateId:"echo",column:0},{templateId:"echo",column:4}]},{name:"Pale Convergence",enemies:[{templateId:"echo",column:2},{templateId:"wraith",column:1},{templateId:"wraith",column:3}]},{name:"Void March",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:3},{templateId:"breaker",column:2}]},{name:"Shadow Tide",enemies:[{templateId:"wraith",column:0},{templateId:"echo",column:2},{templateId:"flanker",column:4}]},{name:"The Unnamed",enemies:[{templateId:"echo",column:2},{templateId:"shielder",column:1},{templateId:"shielder",column:3}]},{name:"Pale Hammer",enemies:[{templateId:"breaker",column:0},{templateId:"echo",column:2},{templateId:"breaker",column:4}]},{name:"Memory Storm",enemies:[{templateId:"echo",column:0},{templateId:"echo",column:1},{templateId:"echo",column:3},{templateId:"echo",column:4}]},{name:"Wraith Flood",enemies:[{templateId:"wraith",column:0},{templateId:"wraith",column:1},{templateId:"wraith",column:2},{templateId:"wraith",column:3},{templateId:"wraith",column:4}]},{name:"Final Guard",enemies:[{templateId:"echo",column:1},{templateId:"breaker",column:2},{templateId:"echo",column:3}]},{name:"Pale Assembly",enemies:[{templateId:"echo",column:0},{templateId:"shielder",column:2},{templateId:"echo",column:4},{templateId:"flanker",column:1}]}];function Ua(e,a,n=!1){let t;if(n)switch(e){case 2:t=Br;break;case 3:t=Hr;break;default:t=Mr;break}else switch(e){case 2:t=Nr;break;case 3:t=Gr;break;default:t=Dr;break}let r=Math.floor(a()*t.length);return{...t[r],isElite:n}}var xt=12,Ha=4;function Wr(e,a,n){if(e===0)return"combat";if(e===a-1)return"boss";let t=n();return e===Math.floor(a/2)?t<.5?"rest":"shop":t<.5?"combat":t<.65?"elite":t<.78?"event":t<.88?"rest":"shop"}function qa(e,a){let n=K(a),t=[],r=[];for(let o=0;o<xt;o++){let l=[],c=o===0||o===xt-1?1:Math.floor(n()*2)+2,s=new Set;for(;s.size<c;)s.add(Math.floor(n()*Ha));for(let f=0;f<Ha;f++)if(s.has(f)){let b=Wr(o,xt,n),v={id:`node-${e}-${o}-${f}`,type:b,row:o,column:f,connections:[],visited:!1};l.push(v),t.push(v)}else l.push(null);r.push(l)}for(let o=0;o<xt-1;o++){let l=r[o].filter(s=>s!==null),c=r[o+1].filter(s=>s!==null);if(c.length!==0){for(let s of l){let f=c.map(b=>({node:b,dist:Math.abs(b.column-s.column)})).sort((b,v)=>b.dist-v.dist);s.connections.push(f[0].node.id),f.length>1&&n()<.4&&s.connections.push(f[1].node.id)}for(let s of c)!l.some(b=>b.connections.includes(s.id))&&l.length>0&&l.map(v=>({node:v,dist:Math.abs(v.column-s.column)})).sort((v,I)=>v.dist-I.dist)[0].node.connections.push(s.id)}}return{act:e,nodes:t}}function je(e,a){return e.nodes.find(n=>n.id===a)}function Ya(e,a){if(!a)return e.nodes.filter(t=>t.row===0);let n=je(e,a);return n?n.connections.map(t=>je(e,t)).filter(t=>!!t):[]}function Ct(e,a=0){let n={enemyHpMult:1,enemyDamageMult:1,startingGateHp:70,extraEnemies:0,shopCostMult:1,healMult:1,startWithCurse:!1,enemyBlitz:!1,reducedRewards:!1,enemyStartFortified:!1,voidColumns:0,paleHunger:!1,bossExtraMinions:0,reducedHandSize:!1,reducedMaxResolve:!1};return e>=2&&(n.enemyHpMult+=.2,n.enemyDamageMult+=.15),e>=3&&(n.enemyHpMult+=.3,n.enemyDamageMult+=.25),a>=1&&(n.enemyHpMult+=.1),a>=2&&(n.enemyDamageMult+=.1),a>=3&&(n.startWithCurse=!0),a>=4&&(n.healMult-=.25),a>=5&&(n.startingGateHp-=10),a>=6&&(n.enemyBlitz=!0),a>=7&&(n.extraEnemies+=1),a>=8&&(n.reducedRewards=!0),a>=9&&(n.enemyStartFortified=!0),a>=10&&(n.shopCostMult+=.25),a>=11&&(n.voidColumns=1),a>=12&&(n.paleHunger=!0),a>=13&&(n.bossExtraMinions=2),a>=14&&(n.reducedHandSize=!0),a>=15&&(n.reducedMaxResolve=!0),n}function za(e,a=0){let n=he(e),t=qa(1,n),r=Ct(1,a),o=aa();return r.startWithCurse&&o.push(mt("pale_curse")),{id:`run-${Date.now()}-${n}`,seed:e,act:1,map:t,currentNodeId:null,deck:o,gateHp:r.startingGateHp,gateMaxHp:r.startingGateHp,fragments:0,potions:[null,null,null],relics:[],ascensionLevel:a,combat:null}}function sa(e,a){return{...e,deck:[...e.deck,a]}}function la(e,a){return{...e,deck:e.deck.filter(n=>n.instanceId!==a)}}function ja(e,a){let n=je(e.map,a);return n&&(n.visited=!0),{...e,currentNodeId:a}}function St(e,a){return{...e,gateHp:Math.min(e.gateMaxHp,e.gateHp+a)}}function Xa(e,a){return e.fragments<a?null:{...e,fragments:e.fragments-a}}function ut(e,a){return{...e,fragments:e.fragments+a}}function Ja(e,a){let n=e.potions.indexOf(null);if(n===-1)return null;let t=[...e.potions];return t[n]=a,{...e,potions:t}}function Za(e,a){if(a<0||a>=e.potions.length)return null;let n=e.potions[a];if(!n)return null;let t=[...e.potions];return t[a]=null,{run:{...e,potions:t},potionId:n}}function ia(e){let a=e.act+1,n=he(e.seed+`-act${a}`),t=qa(a,n);return{...e,act:a,map:t,currentNodeId:null}}function Qa(e){let a=[],n=it.filter(o=>o.rarity!=="common"||o.id==="slash"||o.id==="flare"),t=new Set;for(let o=0;o<5&&t.size<5;o++){let l=n[Math.floor(e()*n.length)];if(t.has(l.id)){o--;continue}t.add(l.id);let c=l.rarity==="rare"?75:l.rarity==="uncommon"?50:30;a.push({type:"card",cardDef:l,cost:c})}let r=ct[Math.floor(e()*ct.length)];return a.push({type:"potion",potionDef:r,cost:25}),a.push({type:"card_remove",cost:50}),a}var Fr=[{id:"wandering_smith",name:"The Wandering Smith",description:"A cloaked figure sits by a forge that shouldn't exist this far into the Pale. They offer to work on your defenses.",choices:[{label:"Ask them to reinforce the gate. (Heal 15 HP)",effect:{type:"heal",value:15}},{label:"Ask for supplies. (Gain 15 fragments)",effect:{type:"fragments",value:15}},{label:"Leave them be.",effect:{type:"nothing"}}]},{id:"pale_fountain",name:"The Pale Fountain",description:"A spring of luminous water bubbles from cracked stone. Its glow is unsettling but beckons.",choices:[{label:"Drink deeply. (+10 max Gate HP)",effect:{type:"max_hp",value:10}},{label:"Fill a flask. (Gain a random card)",effect:{type:"card_reward"}},{label:"Leave. The Pale gives nothing freely.",effect:{type:"nothing"}}]},{id:"abandoned_cache",name:"Abandoned Cache",description:"You find a sealed chest among the rubble of a collapsed watchtower.",choices:[{label:"Pry it open. (Gain 25 fragments)",effect:{type:"fragments",value:25}},{label:"Smash it quickly. (Gain 10 fragments)",effect:{type:"fragments",value:10}},{label:"Leave it. Could be cursed.",effect:{type:"nothing"}}]},{id:"old_veteran",name:"The Old Veteran",description:`A scarred soldier leans against the wall. "I've seen the Pale take stronger keeps than yours," they say.`,choices:[{label:'"Teach me." (Remove a card from your deck)',effect:{type:"remove_card"}},{label:'"Give me your supplies." (Gain 20 fragments)',effect:{type:"fragments",value:20}},{label:'"Good luck." (Nothing happens)',effect:{type:"nothing"}}]},{id:"strange_merchant",name:"Strange Merchant",description:"A merchant with too many eyes offers wares from a floating pack.",choices:[{label:"Browse their cards. (Gain a card)",effect:{type:"card_reward"}},{label:"Sell your blood. (Lose 10 HP, gain 30 fragments)",effect:{type:"damage",value:10}},{label:"Walk away.",effect:{type:"nothing"}}]}],$r=[{id:"pale_scholar",name:"The Pale Scholar",description:'An ancient figure pores over a tome that seems to read itself. "The Pale remembers everything," they whisper.',choices:[{label:"Ask for knowledge. (Gain a card)",effect:{type:"card_reward"}},{label:"Ask for healing. (Heal 20 HP)",effect:{type:"heal",value:20}},{label:"Back away slowly.",effect:{type:"nothing"}}]},{id:"fractured_mirror",name:"The Fractured Mirror",description:"A mirror stands in the corridor, cracked but gleaming. Your reflection looks stronger than you feel.",choices:[{label:"Reach through. (+5 max Gate HP, lose 5 HP)",effect:{type:"max_hp",value:5}},{label:"Smash it. (Gain 20 fragments)",effect:{type:"fragments",value:20}},{label:"Walk past. Mirrors lie.",effect:{type:"nothing"}}]},{id:"deserters_cache",name:"Deserter's Cache",description:"Behind a collapsed wall, you find supplies left by someone who fled the Keep long ago.",choices:[{label:"Take everything. (Gain 30 fragments)",effect:{type:"fragments",value:30}},{label:"Take only what you need. (Heal 10 HP, gain 10 fragments)",effect:{type:"heal",value:10}},{label:"Leave it for the next warden.",effect:{type:"nothing"}}]}],Vr=[{id:"wandering_smith_cracks",name:"The Wandering Smith",description:"The smith again. You've seen this forge before \u2014 the same cracks in the stone, the same angle of the cloak. They look up and for the first time, you notice their hands are shaking.",choices:[{label:'"How long have you been here?" (Heal 15 HP)',effect:{type:"heal",value:15}},{label:`"You're not real, are you." (Gain 20 fragments)`,effect:{type:"fragments",value:20}},{label:"Say nothing. The kindness is worse than the lie.",effect:{type:"nothing"}}]},{id:"the_echoing_child",name:"The Echoing Child",description:'A child sits in the corridor, humming. They look up with eyes that glow faintly. "I remember my house," they say. "Can you take me there?" The house is gone. You know this.',choices:[{label:`"I'll try." (Lose 15 HP \u2014 the detour is dangerous)`,effect:{type:"damage",value:15}},{label:`"There's nothing to go back to." (Gain 10 fragments \u2014 they dissolve)`,effect:{type:"fragments",value:10}},{label:'"Stay here. The Keep is safe."',effect:{type:"nothing"}}]}],Lr=[{id:"motts_stash",name:"Mott's Hidden Stash",description:`"DON'T TELL MOTT," reads the note pinned to a crate. It's Mott's handwriting.`,choices:[{label:"Open it. (Gain 25 fragments)",effect:{type:"fragments",value:25}},{label:"Leave it. Mott knows things you don't.",effect:{type:"nothing"}}]},{id:"wardens_echo",name:"A Warden's Echo",description:'You find scratches on the wall. Tallies. Hundreds of them. Below, in faded ink: "Run 847. The Pale is not the enemy. The Pale is the answer to a question we forgot."',choices:[{label:"Study the scratches. (Gain a card)",effect:{type:"card_reward"}},{label:"Cover them. Some knowledge is dangerous. (Gain 15 fragments)",effect:{type:"fragments",value:15}},{label:"Add your own tally mark.",effect:{type:"nothing"}}]}],Jt=[{id:"the_architects_choice",name:"The Architect's Choice",description:"A door that shouldn't exist. Beyond it, a room you've seen in dreams. A desk. A journal. A pen that still has ink. The Architect's final workspace.",choices:[{label:"Read the journal. (+15 max Gate HP)",effect:{type:"max_hp",value:15}},{label:"Destroy the journal. (Gain 40 fragments)",effect:{type:"fragments",value:40}},{label:"Sit down. Pick up the pen.",effect:{type:"nothing"}}]}],Or=[{id:"the_last_wall",name:"The Last Wall",description:"The final barrier before the Pale's heart. Ancient wards still flicker across its surface.",choices:[{label:"Channel the wards. (+15 max Gate HP)",effect:{type:"max_hp",value:15}},{label:"Break through quickly. (Gain 20 fragments)",effect:{type:"fragments",value:20}},{label:"Let it stand. Its purpose is not yours.",effect:{type:"nothing"}}]},{id:"echo_of_a_warden",name:"Echo of a Warden",description:`A ghostly figure in warden's garb appears. "I held this keep once. Take what remains of my strength."`,choices:[{label:"Accept their gift. (Gain a card, lose 5 HP)",effect:{type:"card_reward"}},{label:"Ask them to strengthen the gate. (Heal 25 HP)",effect:{type:"heal",value:25}},{label:'"Rest now, Warden."',effect:{type:"nothing"}}]},{id:"pale_bargain",name:"The Pale Bargain",description:'The void itself speaks: "Give me something, and I will give you power."',choices:[{label:"Sacrifice a card. (Remove a card)",effect:{type:"remove_card"}},{label:"Sacrifice blood. (Lose 15 HP, gain 40 fragments)",effect:{type:"damage",value:15}},{label:'"I make no deals with the void."',effect:{type:"nothing"}}]}];function en(e,a,n){let t;switch(e){case 2:t=$r;break;case 3:t=Or;break;default:t=Fr;break}let r=n==="cracks"||n==="truth"||n==="true_ending";if((n==="truth"||n==="true_ending")&&e===3&&Jt.length>0&&a()<.4)return Jt[Math.floor(a()*Jt.length)];if(r){let l=null;if(e===1?l=Vr:e===2&&(l=Lr),l&&l.length>0&&a()<.4)return l[Math.floor(a()*l.length)]}return t[Math.floor(a()*t.length)]}var Xe=[{id:"forge",name:"The Forge",description:"Unlock card upgrades at rest sites. Higher levels improve upgrades.",maxLevel:3,upgradeCost:e=>e*30},{id:"archive",name:"The Archive",description:"Unlock rare cards in the reward pool. Higher levels add legendaries.",maxLevel:3,upgradeCost:e=>e*40},{id:"beacon_tower",name:"Beacon Tower",description:"+1 starting hand size per level.",maxLevel:2,upgradeCost:e=>e*50},{id:"foundry",name:"The Foundry",description:"Emplacements start with +2 HP per level.",maxLevel:3,upgradeCost:e=>e*25},{id:"sanctum_hall",name:"Sanctum Hall",description:"+5 max Gate HP per level.",maxLevel:3,upgradeCost:e=>e*35}];function Je(e,a){return e.structures[a]??0}function tn(e,a){let n=Xe.find(o=>o.id===a);if(!n)return null;let t=Je(e,a);if(t>=n.maxLevel)return null;let r=n.upgradeCost(t+1);return e.echoes<r?null:{...e,echoes:e.echoes-r,structures:{...e.structures,[a]:t+1}}}function ca(){return[{id:"wren",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"sable",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"duskmar",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"mott",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"pale_visitor",tier:0,echoesGiven:0,dialoguesSeen:[]}]}function da(e,a,n){return(e?10+a*5:3)+Math.floor(n*.5)}function an(e,a){return a>=15?"true_ending":e>=30?"truth":e>=15?"cracks":"surface"}function nn(e,a){let n=a.npcs.find(r=>r.id===e);if(!n)return null;let t=Ba(e,n.tier,n.dialoguesSeen);return t.length===0?null:{speaker:t[0].speaker,text:t[0].text,dialogueId:t[0].id}}function rn(e,a,n){let t=e.npcs.findIndex(l=>l.id===a);if(t===-1)return e;let r=[...e.npcs],o={...r[t]};return o.dialoguesSeen=[...o.dialoguesSeen,n],r[t]=o,{...e,npcs:r}}var ta=2;function Xr(){return on(jr(),".config","codekeep")}function ua(){return on(Xr(),"game.json")}function Jr(){return{structures:{},npcs:[],echoes:0,highestAscension:0,totalRuns:0,totalWins:0,unlockedCardIds:[],achievements:[],narrativeFlags:[]}}function sn(e){return{schemaVersion:ta,savedAtUnixMs:Date.now(),playerName:e,keep:Jr(),activeRun:null}}function Se(e){let a=ua(),n=zr(a);ma(n)||Ur(n,{recursive:!0});let t=a+".tmp",r=JSON.stringify({...e,savedAtUnixMs:Date.now()},null,2);ea(t,r,"utf-8"),qr(t,a)}function Ze(){let e=ua();if(!ma(e))return null;let a;try{a=Kr(e,"utf-8")}catch{return null}let n;try{n=JSON.parse(a)}catch{let t=e+".bak";try{ea(t,a,"utf-8")}catch{}return process.stderr.write(`[codekeep] Corrupted save backed up to ${t}
3
+ `),null}if(n.schemaVersion!==ta){let t=e+`.v${n.schemaVersion}.bak`;try{ea(t,a,"utf-8")}catch{}return process.stderr.write(`[codekeep] Save version mismatch (got ${n.schemaVersion}, need ${ta}), backed up to ${t}
4
+ `),null}return n}function ln(){let e=ua();if(!ma(e))return!1;try{return Yr(e),!0}catch{return!1}}import ao from"react";import{Box as no,Text as Y}from"ink";import{writeFileSync as Zr,mkdirSync as Qr,existsSync as eo}from"fs";import{join as cn}from"path";import{homedir as to}from"os";var pa=cn(to(),".config","codekeep","crashes");function dn(e,a){if((e instanceof Error?e.message:String(e)).includes("Raw mode is not supported"))return"";eo(pa)||Qr(pa,{recursive:!0});let t={timestamp:new Date().toISOString(),error:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0,version:globalThis.__CODEKEEP_VERSION??"unknown",nodeVersion:process.version,platform:process.platform,arch:process.arch,screen:a?.screen,gameState:a?.gameState},r=`crash-${Date.now()}.json`,o=cn(pa,r);return Zr(o,JSON.stringify(t,null,2),"utf-8"),o}function mn(e){let a=encodeURIComponent(`[Crash]: ${e.error.slice(0,80)}`),n=encodeURIComponent(`## Crash Report
5
5
 
6
6
  **Error:** ${e.error}
7
7
 
@@ -16,8 +16,8 @@ ${e.stack??"N/A"}
16
16
  - OS: ${e.platform} ${e.arch}
17
17
  - Screen: ${e.screen??"unknown"}
18
18
  - Time: ${e.timestamp}
19
- `);return`https://github.com/tooyipjee/codekeep/issues/new?title=${t}&body=${n}&labels=bug,crash`}import{Fragment as Za,jsx as J,jsxs as ve}from"react/jsx-runtime";var ft=class extends Hr.Component{constructor(t){super(t),this.state={error:null,crashFilePath:null,issueUrl:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){try{let n=Ja(t),a={timestamp:new Date().toISOString(),error:t.message,stack:t.stack,version:globalThis.__CODEKEEP_VERSION??"unknown",nodeVersion:process.version,platform:process.platform,arch:process.arch},r=Qa(a);this.setState({crashFilePath:n,issueUrl:r})}catch{}}render(){return this.state.error?ve(Br,{flexDirection:"column",padding:1,children:[J(W,{bold:!0,color:"red",children:"\u25C6 CodeKeep \u2014 Something went wrong"}),J(W,{children:" "}),J(W,{color:"red",children:this.state.error.message}),J(W,{children:" "}),J(W,{dimColor:!0,children:"Your save file is at:"}),ve(W,{children:[" ","~/.config/codekeep/game.json"]}),J(W,{children:" "}),this.state.crashFilePath&&ve(Za,{children:[J(W,{dimColor:!0,children:"Crash report saved to:"}),ve(W,{children:[" ",this.state.crashFilePath]}),J(W,{children:" "})]}),this.state.issueUrl&&ve(Za,{children:[J(W,{dimColor:!0,children:"Report this bug:"}),ve(W,{color:"cyan",children:[" ",this.state.issueUrl]}),J(W,{children:" "})]}),J(W,{dimColor:!0,children:"If the game won't start, try:"}),ve(W,{bold:!0,children:[" ","codekeep --tutorial"]}),J(W,{children:" "}),J(W,{dimColor:!0,children:"Press Ctrl+C to exit"})]}):this.props.children}};import{Box as gt,Text as z}from"ink";import{Box as Gr,Text as fe}from"ink";import{jsx as Ye,jsxs as ht}from"react/jsx-runtime";function Nr(e){if(!e)return"";switch(e.type){case"advance":return`\u2193${e.value}`;case"attack":return`\u2694${e.value}`;case"buff":return`\u25B2${e.value}`;case"debuff":return`\u25BC${e.value}`;case"shield":return`\u25C8${e.value}`;case"summon":return`+${e.value}`;default:return""}}function Wr(e){let t=[];for(let n of e.statusEffects)switch(n.type){case"vulnerable":t.push(`V${n.stacks}`);break;case"weak":t.push(`W${n.stacks}`);break;case"burn":t.push(`B${n.stacks}`);break;case"empowered":t.push(`E${n.stacks}`);break;case"fortified":t.push(`F${n.stacks}`);break}return t.join("")}function Fr(e,t,n=6){let a=Math.max(0,Math.round(e/t*n));return"\u2588".repeat(a)+"\u2591".repeat(n-a)}function $r(e){return`${de(e.templateId)?.symbol??"?"}${e.hp}`}function en({columns:e,targetColumn:t,showTarget:n,gateHp:a,gateMaxHp:r,gateBlock:o}){let d=e.map((g,_)=>{let E=`Col ${_+1}`,M=g.emplacement?`[${g.emplacement.hp}hp]`:"",K=M?`${E}${M}`:E,R=n&&_===t,D=K.padStart(Math.floor((14+K.length)/2)).padEnd(14);return R?`[${D.slice(1,-1)}]`:` ${D.slice(1,-1)} `}).join("\u2502"),s=[];for(let g=0;g<Ae;g++){let _=e.map(E=>{let M=E.enemies.filter(R=>R.row===g);return M.length===0?"\xB7".padStart(Math.floor(7.5)).padEnd(14):M.map(R=>{let D=Nr(R.intent),S=Wr(R),h=$r(R);return D&&(h+=` ${D}`),S&&(h+=` ${S}`),h}).join(" ").slice(0,14).padEnd(14)}).join("\u2502");s.push(_)}let p=Math.round(a/r*100),y=p>60?"green":p>30?"yellow":"red";return ht(Gr,{flexDirection:"column",children:[Ye(fe,{bold:!0,dimColor:!0,children:"\u2500".repeat(74)}),Ye(fe,{bold:!0,children:d}),Ye(fe,{dimColor:!0,children:"\u2500".repeat(74)}),s.map((g,_)=>Ye(fe,{children:g},_)),Ye(fe,{dimColor:!0,children:"\u2550".repeat(74)}),ht(fe,{children:[ht(fe,{bold:!0,color:y,children:["Gate ",Fr(a,r,12)," ",a,"/",r]}),o>0&&ht(fe,{color:"cyan",children:[" \u25C7",o]})]})]})}import{Box as Vr,Text as Me}from"ink";import{jsx as tn,jsxs as Xe}from"react/jsx-runtime";function Or(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function Kr(e){switch(e){case"armament":return"\u2694";case"fortification":return"\u25C7";case"edict":return"\u2726";case"wild":return"\u25C8";default:return"\xB7"}}function an({hand:e,selectedIndex:t,resolve:n}){return e.length===0?tn(Me,{dimColor:!0,children:"No cards in hand."}):Xe(Vr,{flexDirection:"column",children:[tn(Me,{bold:!0,children:"Hand:"}),e.map((a,r)=>{let o=O(a.defId);if(!o)return null;let l=r===t,d=o.cost<=n,s=l?"\u25B6 ":" ",p=`${r+1}`,y=`[${o.cost}]`;return Xe(Me,{children:[Xe(Me,{bold:l,color:l?"yellow":void 0,children:[s,p,"."," "]}),Xe(Me,{color:d?Or(o.rarity):"gray",bold:l,children:[Kr(o.category)," ",o.name," ",y]}),Xe(Me,{dimColor:!0,children:[" \u2014 ",l?o.description:o.description.length>35?o.description.slice(0,35)+"\u2026":o.description]})]},a.instanceId)})]})}import{jsx as Y,jsxs as He}from"react/jsx-runtime";function Lr(e){switch(e.type){case"damage_dealt":return`Dealt ${e.data.damage} damage to enemy`;case"enemy_advance":return`Enemy advances to row ${e.data.row}`;case"gate_hit":return`Gate hit for ${e.data.damage} damage${e.data.blocked?` (${e.data.blocked} blocked)`:""}`;case"enemy_killed":return"Enemy destroyed!";case"block_gained":return`Gained ${e.data.value} Block`;case"emplacement_placed":return`Emplacement placed in column ${e.data.column+1}`;case"emplacement_triggered":return`Emplacement triggered in column ${e.data.column+1}`;case"emplacement_destroyed":return`Emplacement destroyed in column ${e.data.column+1}`;case"status_applied":return`Applied ${e.data.type} (${e.data.value})`;case"card_played":return`Played ${O(e.data.cardId)?.name??e.data.cardId}`;case"turn_start":return`\u2014 Turn ${e.data.turn} \u2014`;default:return""}}function nn({combat:e,selectedCard:t,targetColumn:n,needsTarget:a,message:r}){let o=e.columns.reduce((l,d)=>l+d.enemies.length,0);return He(gt,{flexDirection:"column",children:[He(gt,{justifyContent:"space-between",children:[Y(z,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),He(z,{children:["Turn ",Y(z,{bold:!0,children:e.turn})," ","Resolve ",He(z,{bold:!0,color:"cyan",children:[e.resolve,"/",e.maxResolve]})," ","Enemies ",Y(z,{bold:!0,color:"red",children:o})," ","Draw ",Y(z,{dimColor:!0,children:e.drawPile.length})," ","Discard ",Y(z,{dimColor:!0,children:e.discardPile.length})]})]}),Y(z,{children:" "}),Y(en,{columns:e.columns,targetColumn:n,showTarget:a&&t>=0,gateHp:e.gateHp,gateMaxHp:e.gateMaxHp,gateBlock:e.gateBlock}),Y(z,{children:" "}),Y(an,{hand:e.hand,selectedIndex:t,resolve:e.resolve}),Y(z,{children:" "}),r&&Y(z,{color:"yellow",children:r}),(()=>{let l=e.events.filter(d=>d.turn>=e.turn-1).slice(-4);return l.length===0?null:Y(gt,{flexDirection:"column",children:l.map((d,s)=>He(z,{dimColor:!0,children:[" ",Lr(d)]},s))})})(),e.phase==="player"&&He(z,{dimColor:!0,children:["1-",e.hand.length," card \u2190\u2192 column Enter play e emplace p potion Space end turn d deck q quit"]}),e.outcome!=="undecided"&&Y(gt,{marginTop:1,children:Y(z,{bold:!0,color:e.outcome==="win"?"green":"red",children:e.outcome==="win"?"\u2605 VICTORY \u2014 The siege is broken!":"\u2717 DEFEAT \u2014 The Gate has fallen."})})]})}import{Box as rn,Text as he}from"ink";import{jsx as Be,jsxs as yt}from"react/jsx-runtime";function Ur(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function on({cards:e,selectedIndex:t}){return yt(rn,{flexDirection:"column",padding:1,children:[Be(he,{bold:!0,color:"yellow",children:"\u25C6 Choose a Card Reward"}),Be(he,{children:" "}),e.map((n,a)=>{let r=a===t;return yt(rn,{flexDirection:"column",marginBottom:1,children:[yt(he,{bold:r,color:r?"yellow":Ur(n.rarity),children:[r?"\u25B6 ":" ",a+1,". ",n.name," [",n.cost,"] (",n.rarity,")"]}),yt(he,{dimColor:!0,children:[" ",n.description]})]},n.id)}),Be(he,{children:" "}),Be(he,{dimColor:!0,children:t>=0?` ${e.length+1}. Skip \u2014 take no card`:`\u25B6 ${e.length+1}. Skip \u2014 take no card`}),Be(he,{children:" "}),Be(he,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]})}import{Box as qr,Text as Je}from"ink";import{jsx as aa,jsxs as ta}from"react/jsx-runtime";function jr(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function sn({deck:e}){let t=new Map;for(let a of e)t.set(a.defId,(t.get(a.defId)??0)+1);let n=[...t.entries()].map(([a,r])=>({def:O(a),count:r})).filter(a=>a.def).sort((a,r)=>{let o={common:0,uncommon:1,rare:2,legendary:3},l=o[a.def.rarity]??0,d=o[r.def.rarity]??0;return l!==d?l-d:a.def.name.localeCompare(r.def.name)});return ta(qr,{flexDirection:"column",padding:1,children:[ta(Je,{bold:!0,color:"yellow",children:["\u25C6 Your Deck"," (",e.length," cards)"]}),aa(Je,{children:" "}),n.map(({def:a,count:r})=>ta(Je,{color:jr(a.rarity),children:[r>1?`${r}x `:" ",a.name," [",a.cost,"] \u2014 ",a.description]},a.id)),aa(Je,{children:" "}),aa(Je,{dimColor:!0,children:"Press q or Esc to go back."})]})}import zr from"react";import{Box as wt,Text as ue}from"ink";import{jsx as ge,jsxs as Ge}from"react/jsx-runtime";function Yr(e){switch(e){case"combat":return"\u2694";case"elite":return"\u2605";case"rest":return"\u25B3";case"shop":return"$";case"event":return"?";case"boss":return"\u25C6";default:return"\xB7"}}function Xr(e,t,n,a){if(a)return"cyan";if(n)return"yellow";if(e.visited||!t)return"gray";switch(e.type){case"combat":return"white";case"elite":return"red";case"rest":return"green";case"shop":return"yellow";case"event":return"magenta";case"boss":return"red";default:return"white"}}function Jr(e,t,n){let a=Array(n).fill(" ");for(let r of e)for(let o of r.connections){let l=t.find(d=>d.id===o);l&&(l.column===r.column?a[r.column]=" \u2502 ":l.column>r.column?a[r.column]=a[r.column]===" \u2502 "?" \u2502\u2572":" \u2572":a[r.column]=a[r.column]===" \u2502 "?"\u2571\u2502 ":"\u2571 ")}return a.join(" ")}function ln({map:e,currentNodeId:t,reachableIds:n,selectedNodeId:a}){let r=new Set(n),o=Math.max(...e.nodes.map(s=>s.row)),l=[];for(let s=0;s<=o;s++)l.push(e.nodes.filter(p=>p.row===s).sort((p,y)=>p.column-y.column));let d=4;return Ge(wt,{flexDirection:"column",padding:1,children:[Ge(ue,{bold:!0,color:"yellow",children:["\u25C6 Act ",e.act," Map"]}),ge(ue,{children:" "}),l.map((s,p)=>Ge(zr.Fragment,{children:[Ge(wt,{children:[Ge(ue,{dimColor:!0,children:[String(p).padStart(2," ")," "]}),ge(wt,{gap:2,children:[0,1,2,3].map(y=>{let g=s.find(S=>S.column===y);if(!g)return ge(ue,{children:" "},y);let _=g.id===t,E=r.has(g.id),M=g.id===a,K=Xr(g,E,M,_),R=Yr(g.type),D=M?`[${R}]`:_?`(${R})`:` ${R} `;return ge(ue,{color:K,bold:M||_,dimColor:g.visited&&!_,children:D},y)})})]}),p<o&&ge(wt,{children:Ge(ue,{dimColor:!0,children:[" ",Jr(s,l[p+1]??[],d)]})})]},p)),ge(ue,{children:" "}),ge(ue,{dimColor:!0,children:"\u2694=fight \u2605=elite \u25B3=rest $=shop ?=event \u25C6=boss"}),ge(ue,{dimColor:!0,children:"\u2191\u2193 select Enter proceed d=deck q=quit"})]})}import{Box as Qr,Text as Qe}from"ink";import{jsx as ra,jsxs as na}from"react/jsx-runtime";function cn({items:e,selectedIndex:t,fragments:n}){return na(Qr,{flexDirection:"column",padding:1,children:[na(Qe,{bold:!0,color:"yellow",children:["\u25C6 Shop \u2014 ",n," fragments"]}),ra(Qe,{children:" "}),e.map((a,r)=>{let o=r===t,l=n>=a.cost,d="";return a.type==="card"&&a.cardDef?d=`${a.cardDef.name} (${a.cardDef.rarity}) \u2014 ${a.cardDef.description}`:a.type==="potion"&&a.potionDef?d=`${a.potionDef.name} \u2014 ${a.potionDef.description}`:a.type==="card_remove"&&(d="Remove a card from your deck"),na(Qe,{bold:o,color:o?"yellow":l?"white":"gray",children:[o?"\u25B6 ":" ",d," [",a.cost,"f]"]},r)}),ra(Qe,{children:" "}),ra(Qe,{dimColor:!0,children:"\u2191\u2193 navigate Enter buy q leave"})]})}import{Box as Zr,Text as be}from"ink";import{jsx as Ze,jsxs as oa}from"react/jsx-runtime";function dn({event:e,selectedChoice:t}){return oa(Zr,{flexDirection:"column",padding:1,children:[oa(be,{bold:!0,color:"magenta",children:["\u25C6 ",e.name]}),Ze(be,{children:" "}),Ze(be,{children:e.description}),Ze(be,{children:" "}),e.choices.map((n,a)=>oa(be,{bold:a===t,color:a===t?"yellow":"white",children:[a===t?"\u25B6 ":" ",a+1,". ",n.label]},a)),Ze(be,{children:" "}),Ze(be,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as eo,Text as ke}from"ink";import{jsx as Ne,jsxs as mn}from"react/jsx-runtime";function un({gateHp:e,gateMaxHp:t,selectedChoice:n,deckSize:a}){let r=Math.floor(t*.3),o=[`Rest \u2014 Heal ${r} Gate HP (${e} \u2192 ${Math.min(t,e+r)}/${t})`,`Thin \u2014 Remove a card from your deck (${a} cards)`,"Leave \u2014 Continue without resting"];return mn(eo,{flexDirection:"column",padding:1,children:[Ne(ke,{bold:!0,color:"green",children:"\u25C6 Rest Site"}),Ne(ke,{children:" "}),Ne(ke,{children:"The campfire crackles against the encroaching Pale."}),Ne(ke,{children:" "}),o.map((l,d)=>mn(ke,{bold:d===n,color:d===n?"yellow":"white",children:[d===n?"\u25B6 ":" ",l]},d)),Ne(ke,{children:" "}),Ne(ke,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as to,Text as _e}from"ink";import{jsx as et,jsxs as sa}from"react/jsx-runtime";var ao={wren:"Wren, the Steward",sable:"Sable, the Archivist",duskmar:"Duskmar, First Wall",mott:"Mott, the Salvager",pale_visitor:"The Pale Visitor"};function pn({keep:e,selectedIndex:t}){let n=[...oe.map(a=>{let r=ze(e,a.id);return{type:"structure",id:a.id,label:`${a.name} (Lv.${r}/${a.maxLevel}) \u2014 ${a.description}`}}),...e.npcs.map(a=>({type:"npc",id:a.id,label:`${ao[a.id]??a.id} (Tier ${a.tier}/5)`})),{type:"action",id:"new_run",label:"Begin New Run"},{type:"action",id:"ascension",label:`Ascension Level: ${e.highestAscension}`}];return sa(to,{flexDirection:"column",padding:1,children:[et(_e,{bold:!0,color:"yellow",children:"\u25C6 The Keep"}),sa(_e,{children:["Echoes: ",et(_e,{bold:!0,color:"cyan",children:e.echoes})," | Runs: ",e.totalRuns," | Wins: ",e.totalWins]}),et(_e,{children:" "}),n.map((a,r)=>sa(_e,{bold:r===t,color:r===t?"yellow":"white",children:[r===t?"\u25B6 ":" ",a.label]},a.id)),et(_e,{children:" "}),et(_e,{dimColor:!0,children:"\u2191\u2193 navigate Enter select q quit"})]})}import{Box as no,Text as tt}from"ink";import{jsx as vt,jsxs as fn}from"react/jsx-runtime";var hn=[{title:"Welcome to CodeKeep",lines:["You are the Warden of the Keep \u2014 the last fortress","standing against the Pale, an erasure that consumes all.","","Your goal: survive 3 Acts of increasingly dangerous","enemies by playing cards and building defenses."]},{title:"The Gate",lines:["Your Gate is your lifeline. It has HP (hit points).","If Gate HP reaches 0, your run is over.","","Gate HP: \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591 70/70","","Enemies advance toward the Gate. When they reach it,","they deal damage. Block reduces incoming damage."]},{title:"Combat Basics",lines:["Each turn you have 3 Resolve (mana) to play cards.","Cards cost 0-4 Resolve. Your hand refreshes each turn.","","Controls:"," 1-5 Select a card from your hand"," \u2190\u2192 Choose target column"," Enter Play the selected card"," Space End your turn"," i Inspect an enemy"]},{title:"The 5-Column Grid",lines:["The battlefield has 5 columns. Enemies spawn at the top","and advance downward toward your Gate at the bottom.",""," Col 1 \u2502 Col 2 \u2502 Col 3 \u2502 Col 4 \u2502 Col 5"," \u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2500\u2500\u2500"," \u262018 \u2502 \xB7 \u2502 \u219110 \u2502 \xB7 \u2502 \xB7"," \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"," Gate \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 70/70"]},{title:"Enemy Intents",lines:["Enemies show what they plan to do next turn:",""," \u2193N Advance N rows toward the Gate"," \u2694N Attack the Gate for N damage"," \u25B2N Buff themselves"," \u25C8N Shield nearby enemies"," +N Summon new enemies","","Read intents to plan your plays wisely!"]},{title:"Emplacements",lines:["Some cards have dual use \u2014 cast OR emplace.","","Cast: Immediate effect (damage, block, etc.)","Emplace: Place as a structure in a column."," Structures trigger every turn automatically!","","To emplace: select the card, press e to toggle","emplace mode, choose a column, press Enter."]},{title:"Status Effects",lines:["V = Vulnerable Takes +25% damage per stack","W = Weak Deals -15% damage per stack","B = Burn Takes damage each turn, decays","F = Fortified Takes -15% damage per stack","E = Empowered Deals +25% damage per stack","","Stack-based: 2x Vulnerable = +50% damage taken."]},{title:"The Map & Node Types",lines:["\u2694 Combat Standard enemy encounter","\u2605 Elite Harder fight, better rewards","\u25B3 Rest Heal or remove a card","$ Shop Buy cards, potions, remove cards","? Event Story encounters with choices","\u25C6 Boss Act boss \u2014 defeat to advance","","Choose your path wisely. Elites are risky but rewarding."]},{title:"The Keep & Meta-Progression",lines:["After each run, you earn Echoes based on performance.","Spend Echoes at The Keep to:",""," \u25C6 Upgrade structures (bonuses for future runs)"," \u25C6 Talk to NPCs (unlock story and lore)"," \u25C6 Increase Ascension (harder difficulty, new modifiers)","","The Keep remembers. Each run makes you stronger."]},{title:"Ready to Play!",lines:["Quick reference:"," 1-5 = select card \u2190\u2192 = target column"," Enter = play card Space = end turn"," e = emplace toggle p = use potion"," i = inspect enemy d = view deck"," q = quit to menu","","The Pale awaits, Warden. Defend the Keep.","","Press Enter to begin."]}];function gn({page:e,totalPages:t}){let n=hn[e];return n?fn(no,{flexDirection:"column",padding:1,children:[fn(tt,{bold:!0,color:"yellow",children:["\u25C6 Tutorial \u2014 ",n.title," (",e+1,"/",t,")"]}),vt(tt,{children:" "}),n.lines.map((a,r)=>vt(tt,{children:a||" "},r)),vt(tt,{children:" "}),vt(tt,{dimColor:!0,children:e<t-1?"\u2190 prev \u2192 next Enter skip to game q close":"\u2190 prev Enter start game q close"})]}):null}var at=hn.length;import{Box as bt,Text as j}from"ink";import{Fragment as yn,jsx as te,jsxs as se}from"react/jsx-runtime";var wn={asciiMode:!1,showTutorialHints:!0,combatLogSize:4};function vn({settings:e,selectedIndex:t,saveInfo:n,confirmingReset:a,message:r}){let o=[{id:"ascii",label:`ASCII Mode: ${e.asciiMode?"ON":"OFF"}`,description:"Use plain ASCII characters (no Unicode symbols)"},{id:"hints",label:`Tutorial Hints: ${e.showTutorialHints?"ON":"OFF"}`,description:"Show helpful tips during first runs"},{id:"log",label:`Combat Log Lines: ${e.combatLogSize}`,description:"Number of recent combat events shown (0-8)"},{id:"tutorial",label:"View Tutorial",description:"Re-read the game tutorial"},{id:"controls",label:"Controls Reference",description:"View all keybindings"},{id:"reset",label:"Reset Save Data",description:"Delete all progress and start fresh"},{id:"back",label:"Back to Menu",description:""}];return se(bt,{flexDirection:"column",padding:1,children:[te(j,{bold:!0,color:"yellow",children:"\u25C6 Settings"}),te(j,{children:" "}),te(bt,{paddingX:1,children:se(bt,{flexDirection:"column",width:40,children:[te(j,{bold:!0,dimColor:!0,children:"Save Info"}),se(j,{dimColor:!0,children:["Runs: ",n.totalRuns," Wins: ",n.totalWins," Echoes: ",n.echoes]}),se(j,{dimColor:!0,children:["Highest Ascension: ",n.highestAscension]}),se(j,{dimColor:!0,children:["Save: ",n.hasSave?"~/.config/codekeep/game.json":"None"]})]})}),te(j,{children:" "}),o.map((l,d)=>{let s=d===t;return se(bt,{children:[se(j,{bold:s,color:s?l.id==="reset"?"red":"yellow":void 0,children:[s?"\u25B6 ":" ",l.label]}),s&&l.description?se(j,{dimColor:!0,children:[" \u2014 ",l.description]}):null]},l.id)}),a&&se(yn,{children:[te(j,{children:" "}),te(j,{bold:!0,color:"red",children:"Are you sure? This deletes ALL progress. Press Enter again to confirm, Esc to cancel."})]}),r&&se(yn,{children:[te(j,{children:" "}),te(j,{color:"cyan",bold:!0,children:r})]}),te(j,{children:" "}),te(j,{dimColor:!0,children:"\u2191\u2193 navigate Enter toggle/select q back"})]})}import{Box as ro,Text as T}from"ink";import{jsx as x,jsxs as oo}from"react/jsx-runtime";function bn(){return oo(ro,{flexDirection:"column",padding:1,children:[x(T,{bold:!0,color:"yellow",children:"\u25C6 Controls Reference"}),x(T,{children:" "}),x(T,{bold:!0,children:"Global"}),x(T,{children:" q Quit / back to menu"}),x(T,{children:" \u2191\u2193 or j/k Navigate menus"}),x(T,{children:" Enter Confirm / select"}),x(T,{children:" Esc Cancel / go back"}),x(T,{children:" "}),x(T,{bold:!0,children:"Combat"}),x(T,{children:" 1-9 Select card from hand"}),x(T,{children:" \u2190\u2192 or h/l Target column"}),x(T,{children:" Enter Play selected card"}),x(T,{children:" Space End your turn"}),x(T,{children:" e Toggle emplace mode"}),x(T,{children:" p Use first available potion"}),x(T,{children:" i Inspect enemies"}),x(T,{children:" d View deck"}),x(T,{children:" Esc Deselect card"}),x(T,{children:" "}),x(T,{bold:!0,children:"Map"}),x(T,{children:" \u2191\u2193 Select next node"}),x(T,{children:" Enter Enter node"}),x(T,{children:" d View deck"}),x(T,{children:" "}),x(T,{bold:!0,children:"Inspect Mode (i in combat)"}),x(T,{children:" \u2190\u2192 Switch column"}),x(T,{children:" \u2191\u2193 Switch enemy in column"}),x(T,{children:" i / Esc Close inspect"}),x(T,{children:" "}),x(T,{dimColor:!0,children:"Press q or Esc to go back"})]})}import{useState as nt,useCallback as Te,useRef as so}from"react";function kn(){let[e,t]=nt(null),[n,a]=nt(-1),[r,o]=nt(2),[l,d]=nt(""),[s,p]=nt(!1),y=so(null),g=Te((h,b,I,F,L,U,ye)=>{let $=h??Kt(),le=b??Math.floor(Math.random()*2147483647),ie=Pa($,le,I,F,L,U??[],ye);y.current=ie,t({...ie}),a(-1),o(2),p(!1),d("Your turn. Select a card (1-5) and a column (\u2190\u2192).")},[]),_=(()=>{if(n<0||!e)return!1;let h=e.hand[n];if(!h)return!1;let b=O(h.defId);if(!b)return!1;let I=new Set(["damage","damage_if_vulnerable","damage_equal_block","damage_if_emplaced","damage_plus_block","damage_if_low_hp","vulnerable","weak","burn"]);return b.effects.some(F=>I.has(F.type)&&(F.target==="single"||F.target==="column"))})(),E=Te(h=>{if(!y.current||y.current.phase!=="player"||h<0||h>=y.current.hand.length)return;let b=y.current.hand[h],I=O(b.defId);if(!I)return;if(I.cost>y.current.resolve){d(`Not enough Resolve for ${I.name} (costs ${I.cost}).`);return}a(h);let F=new Set(["damage","damage_if_vulnerable","damage_equal_block","damage_if_emplaced","damage_plus_block","damage_if_low_hp","vulnerable","weak","burn"]),L=I.effects.some(U=>F.has(U.type)&&(U.target==="single"||U.target==="column"));d(L?`${I.name} selected. Choose column (\u2190\u2192), Enter to play.`:`${I.name} selected. Enter to play.`)},[]),M=Te(h=>{h>=0&&h<5&&o(h)},[]),K=Te(()=>{let h=y.current;if(!h||h.phase!=="player"||n<0)return;let b=h.hand[n];if(!b)return;let I=O(b.defId);if(!I)return;let F=h.hand.length;if(Aa(h,n,r,s),h.hand.length===F){d(`Cannot play ${I.name}. Not enough Resolve.`);return}y.current=h,t({...h}),a(-1),p(!1),h.outcome==="win"?d("Victory! The Pale recedes."):h.outcome==="lose"?d("The Gate has fallen..."):d(`${s?"Emplaced":"Played"} ${I.name}. ${h.resolve} Resolve left.`)},[n,r,s]),R=Te(()=>{if(n<0||!y.current)return;let h=y.current.hand[n];if(!h)return;let b=O(h.defId);if(!b||b.type!=="emplace"){d("This card cannot be emplaced.");return}p(I=>!I),d(s?`${b.name}: cast mode`:`${b.name}: EMPLACE mode \u2014 place in a column`)},[n,s]),D=Te(()=>{let h=y.current;!h||h.phase!=="player"||(Da(h),y.current=h,t({...h}),a(-1),h.outcome==="win"?d("Victory! The Pale recedes."):h.outcome==="lose"?d("The Gate has fallen..."):d(`Turn ${h.turn}. Your move.`))},[]),S=Te(h=>{let b=y.current;if(!(!b||!h)){for(let I of h.effects)switch(I.type){case"heal":b.gateHp=Math.min(b.gateMaxHp,b.gateHp+I.value);break;case"block":b.gateBlock+=I.value;break;case"damage":{let F=r;if(I.target==="column"){let L=b.columns[F];if(L)for(let U of L.enemies)U.hp-=I.value}else if(I.target==="all")for(let L of b.columns)for(let U of L.enemies)U.hp-=I.value;break}case"draw":{let F=N(b.seed+b.turn*53),{drawn:L,newDrawPile:U,newDiscardPile:ye}=pe(b.drawPile,b.discardPile,I.value,F);b.hand.push(...L),b.drawPile=U,b.discardPile=ye;break}case"resolve":b.resolve=Math.min(b.maxResolve+5,b.resolve+I.value);break}y.current=b,t({...b}),d(`Used ${h.name}.`)}},[r]);return{combat:e,selectedCard:n,targetColumn:r,message:l,emplaceMode:s,selectCard:E,selectTarget:M,confirmPlay:K,endTurn:D,toggleEmplace:R,startCombat:g,applyPotion:S,needsTarget:_}}import{Fragment as la,jsx as w,jsxs as k}from"react/jsx-runtime";var _n=60,Tn=18;function uo(){let{stdout:e}=mo(),[t,n]=C({columns:e?.columns??process.stdout.columns??80,rows:e?.rows??process.stdout.rows??24});return lo(()=>{let a=e??process.stdout,r=()=>n({columns:a.columns,rows:a.rows});return a.on("resize",r),()=>{a.off("resize",r)}},[e]),t}function po({dryRun:e}){let{exit:t}=io(),{columns:n,rows:a}=uo(),[r,o]=C("menu"),[l,d]=C(0),[s,p]=C(null),[y,g]=C(0),[_,E]=C([]),[M,K]=C(0),[R,D]=C([]),[S,h]=C(0),[b,I]=C(null),[F,L]=C(0),[U,ye]=C(0),[$,le]=C(null),[ie,kt]=C(0),[ia,xe]=C(""),[ca,Sn]=C(!1),[we,En]=C([]),[Ie,_t]=C(0),[Tt,Ce]=C(0),xt=kn(),{combat:V,selectedCard:rt,targetColumn:It,message:Pn,emplaceMode:yo,selectCard:da,selectTarget:ma,confirmPlay:An,endTurn:Rn,toggleEmplace:Dn,startCombat:Ct,applyPotion:wo,needsTarget:Mn}=xt,[St,Et]=C(!1),[ot,Pt]=C(0),[Hn,At]=C(0),[Rt,ua]=C(null),[pa,Se]=C(0),[We,Dt]=C(wn),[fa,Mt]=C(0),[Bn,st]=C(""),[ha,Ee]=C(!1),[X,Pe]=C(()=>De()),ga=!X||X.keep.totalRuns<=1,Fe=X?La(X.keep.totalRuns,X.keep.highestAscension):"surface",Gn=n<_n||a<Tn,ne=ae(()=>{let c=X??De();return c||(c=za("Warden"),c.keep.npcs.length===0&&(c.keep.npcs=Xt()),me(c)),c.keep.npcs.length===0&&(c.keep.npcs=Xt()),Pe(c),c},[X]),P=ae(c=>{if(e)return;let m=ne();m.activeRun=c,$&&(m.keep=$),me(m),Pe(m)},[e,$,ne]),Ht=ae(()=>{let c=`run-${Date.now()}`,m=ne(),i=Ga(c,m.keep.highestAscension);p(i),g(0),m.activeRun=i,m.keep.totalRuns++,le(m.keep),me(m),Pe(m),m.keep.totalRuns===1?(Se(0),o("tutorial")):o("map")},[ne]),Nn=ae(()=>{let c=De();c?.activeRun&&(p(c.activeRun),le(c.keep),g(0),o("map"))},[]),ya=ae(()=>{let c=ne();Pe(c),le(c.keep),kt(0),xe(""),o("keep")},[ne]),wa=ae(()=>s?Ba(s.map,s.currentNodeId):[],[s]),Wn=ae(c=>{if(!s)return;let m=Na(s,c.id);if(c.type==="combat"||c.type==="elite"){let i=ee(s.seed+c.id),u=N(i),v=Ma(s.act,u,c.type==="elite");Ct(m.deck,i,m.gateHp,m.gateMaxHp,v.enemies,m.relics,ut(s.act,s.ascensionLevel)),p(m),o("combat")}else if(c.type==="boss"){let i=ee(s.seed+"-boss-"+s.act),u=Ia(s.act);Ct(m.deck,i,m.gateHp,m.gateMaxHp,u,m.relics,ut(s.act,s.ascensionLevel));let v=Lt(s.act);if(v?.dialogue){let A=v.dialogue.find(ce=>ce.storyLayer===Fe)??v.dialogue[0];A&&ua(A.onAppear)}p(m),o("combat")}else if(c.type==="shop"){let i=N(ee(s.seed+c.id));D(Va(i)),h(0),p(m),o("shop")}else if(c.type==="event"){let i=N(ee(s.seed+c.id));I(Oa(s.act,i,Fe)),L(0),p(m),o("event")}else c.type==="rest"&&(ye(0),p(m),o("rest"));P(m)},[s,Ct,P]),$e=ae((c,m)=>{Sn(m),p(c);let i=ne(),u=Jt(m,c.act,c.ascensionLevel);i.keep.echoes+=u,m&&(i.keep.totalWins++,c.ascensionLevel>=i.keep.highestAscension&&(i.keep.highestAscension=c.ascensionLevel+1)),i.activeRun=null,le(i.keep),me(i),Pe(i),o("result")},[ne]),Fn=ae(()=>{if(!V||!s)return;let c={...s,gateHp:V.gateHp};if(V.outcome==="lose"){$e(c,!1);return}let m=s.currentNodeId?Re(s.map,s.currentNodeId):null,i=m?.type==="elite"?it.elite:m?.type==="boss"?it.boss:it.combat;if(c=je(c,i),c.relics.includes("mending_stone")&&(c=pt(c,5)),c.relics.includes("fragment_magnet")&&(c=je(c,5)),m?.type==="elite"||m?.type==="boss"){let v=N(ee(s.seed+(s.currentNodeId??"")+"-relic")),A=Ea(v,c.relics,3);if(A.length>0){En(A),_t(0),p(c),P(c),o("relic_reward");return}}if(m?.type==="boss"){s.act<3?(c=Yt(c),p(c),P(c),g(0),o("map")):$e(c,!0);return}let u=N(ee(s.seed+(s.currentNodeId??"")+"-reward"));E(mt(u)),K(0),p(c),P(c),o("reward")},[V,s,P,$e]),va=ae(c=>{if(!s)return;let m=s;c&&(m=jt(m,qe(c.id))),p(m),P(m),g(0),o("map")},[s,P]),ba=ae(c=>{if(!s)return;let m=s;if(c&&(m={...m,relics:[...m.relics,c.id]}),p(m),P(m),(s.currentNodeId?Re(s.map,s.currentNodeId):null)?.type==="boss")s.act<3?(m=Yt(m),p(m),P(m),g(0),o("map")):$e(m,!0);else{let u=N(ee(s.seed+(s.currentNodeId??"")+"-reward"));E(mt(u)),K(0),o("reward")}},[s,P,$e]),Bt=[{label:"The Keep",action:"keep"},{label:"New Run",action:"new"},...X?.activeRun?[{label:"Resume Run",action:"resume"}]:[],{label:"Tutorial",action:"tutorial"},{label:"Settings",action:"settings"},{label:"Quit",action:"quit"}];if(co((c,m)=>{if(r==="tutorial"){m.rightArrow||c==="l"?Se(i=>Math.min(at-1,i+1)):m.leftArrow||c==="h"?Se(i=>Math.max(0,i-1)):m.return?pa===at-1?Ht():Se(i=>Math.min(at-1,i+1)):(c==="q"||m.escape)&&o("menu");return}if(r==="controls"){(c==="q"||m.escape)&&o("settings");return}if(r==="settings"){let i=["ascii","hints","log","tutorial","controls","reset","back"];if(m.upArrow||c==="k")Mt(u=>Math.max(0,u-1)),Ee(!1);else if(m.downArrow||c==="j")Mt(u=>Math.min(i.length-1,u+1)),Ee(!1);else if(c==="q"||m.escape)o("menu"),Ee(!1);else if(m.return){let u=i[fa];u==="ascii"?(Dt(v=>({...v,asciiMode:!v.asciiMode})),st("ASCII mode "+(We.asciiMode?"disabled":"enabled"))):u==="hints"?(Dt(v=>({...v,showTutorialHints:!v.showTutorialHints})),st("Tutorial hints "+(We.showTutorialHints?"disabled":"enabled"))):u==="log"?Dt(v=>({...v,combatLogSize:v.combatLogSize>=8?0:v.combatLogSize+2})):u==="tutorial"?(Se(0),o("tutorial")):u==="controls"?o("controls"):u==="reset"?ha?(Ya(),Pe(null),le(null),p(null),Ee(!1),st("Save data deleted. Starting fresh.")):Ee(!0):u==="back"&&o("menu")}return}if(r==="relic_reward"){m.upArrow||c==="k"?_t(i=>Math.max(0,i-1)):m.downArrow||c==="j"?_t(i=>Math.min(we.length,i+1)):c==="s"?ba(null):m.return&&ba(Ie<we.length?we[Ie]:null);return}if(r==="menu"){if(m.upArrow||c==="k")d(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")d(i=>Math.min(Bt.length-1,i+1));else if(m.return){let i=Bt[l]?.action;i==="keep"?ya():i==="new"?Ht():i==="resume"?Nn():i==="tutorial"?(Se(0),o("tutorial")):i==="settings"?(Mt(0),st(""),Ee(!1),o("settings")):t()}else c==="q"&&t();return}if(r==="deck"){(c==="q"||m.escape)&&o("map");return}if(r==="map"&&s){let i=wa();m.upArrow||c==="k"?g(u=>Math.max(0,u-1)):m.downArrow||c==="j"?g(u=>Math.min(i.length-1,u+1)):m.return&&i[y]?Wn(i[y]):c==="d"?o("deck"):c==="q"&&(P(s),o("menu"));return}if(r==="reward"){let i=_.length;m.upArrow||c==="k"?K(u=>Math.max(0,u-1)):m.downArrow||c==="j"?K(u=>Math.min(i,u+1)):c==="s"?va(null):m.return&&va(M<_.length?_[M]:null);return}if(r==="shop"&&s){if(m.upArrow||c==="k")h(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")h(i=>Math.min(R.length-1,i+1));else if(c==="q"||m.escape)g(0),o("map");else if(m.return){let i=R[S];if(i&&s.fragments>=i.cost){let u=Wa(s,i.cost);if(!u)return;if(i.type==="card"&&i.cardDef)u=jt(u,qe(i.cardDef.id)),p(u),P(u),D(v=>v.filter((A,ce)=>ce!==S)),h(0);else if(i.type==="potion"&&i.potionDef){let v=Fa(u,i.potionDef.id);v&&(u=v),p(u),P(u),D(A=>A.filter((ce,lt)=>lt!==S)),h(0)}else i.type==="card_remove"&&(p(u),P(u),Ce(0),D(v=>v.filter((A,ce)=>ce!==S)),o("shop_remove"))}}return}if(r==="event"&&b&&s){if(m.upArrow||c==="k")L(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")L(i=>Math.min(b.choices.length-1,i+1));else if(m.return){let i=b.choices[F],u=s;switch(i.effect.type){case"heal":u=pt(u,i.effect.value);break;case"damage":{u={...u,gateHp:Math.max(1,u.gateHp-i.effect.value)};let v=i.label.match(/(\d+)\s*fragments/i);v&&(u=je(u,parseInt(v[1])));break}case"fragments":u=je(u,i.effect.value);break;case"max_hp":u={...u,gateMaxHp:u.gateMaxHp+i.effect.value,gateHp:u.gateHp+i.effect.value};break;case"card_reward":{let v=i.label.match(/lose\s+(\d+)\s*hp/i);v&&(u={...u,gateHp:Math.max(1,u.gateHp-parseInt(v[1]))});let A=N(ee(s.seed+(b?.id??"")));E(mt(A)),K(0),p(u),P(u),o("reward");return}case"remove_card":{p(u),P(u),o("deck_remove");return}case"nothing":break}p(u),P(u),g(0),o("map")}return}if(r==="rest"&&s){if(m.upArrow||c==="k")ye(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")ye(i=>Math.min(2,i+1));else if(m.return){let i=s;U===0?(i=pt(i,Math.floor(i.gateMaxHp*.3)),p(i),P(i),g(0),o("map")):U===1&&i.deck.length>5?(p(i),Ce(0),o("deck_remove")):(p(i),P(i),g(0),o("map"))}return}if(r==="deck_remove"&&s){if(m.upArrow||c==="k")Ce(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")Ce(i=>Math.min(s.deck.length-1,i+1));else if(m.escape||c==="q")g(0),o("map");else if(m.return&&s.deck.length>5){let i=s.deck[Tt];if(i){let u=zt(s,i.instanceId);p(u),P(u)}g(0),o("map")}return}if(r==="shop_remove"&&s){if(m.upArrow||c==="k")Ce(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")Ce(i=>Math.min(s.deck.length-1,i+1));else if(m.escape||c==="q")o("shop");else if(m.return&&s.deck.length>5){let i=s.deck[Tt];if(i){let u=zt(s,i.instanceId);p(u),P(u)}o("shop")}return}if(r==="keep"&&$){let i=oe.length+$.npcs.length+2;if(m.upArrow||c==="k")kt(u=>Math.max(0,u-1));else if(m.downArrow||c==="j")kt(u=>Math.min(i-1,u+1));else if(c==="q")o("menu");else if(m.return)if(ie<oe.length){let u=oe[ie],v=Ka($,u.id);if(v){le(v);let A=ne();A.keep=v,me(A),xe(`Upgraded ${u.name}!`)}else ze($,u.id)>=u.maxLevel?xe(`${u.name} is already max level.`):xe(`Not enough Echoes to upgrade ${u.name}.`)}else if(ie<oe.length+$.npcs.length){let u=ie-oe.length,v=$.npcs[u],A=Ua(v.id,$);if(A){let ce=qa($,v.id,A.dialogueId);le(ce);let lt=ne();lt.keep=ce,me(lt),xe(`${A.speaker}: "${A.text}"`)}else xe("(No new dialogue)")}else ie===oe.length+$.npcs.length&&Ht();return}if(r==="result"){m.return||c===" "?ya():c==="q"&&o("menu");return}if(r==="combat"&&V){if(V.outcome!=="undecided"){(m.return||c===" ")&&Fn();return}if(Rt&&V.turn>1&&ua(null),c==="i"){St?Et(!1):(Et(!0),Pt(0),At(0));return}if(St){if(m.leftArrow||c==="h")Pt(i=>Math.max(0,i-1));else if(m.rightArrow||c==="l")Pt(i=>Math.min(4,i+1));else if(m.upArrow||c==="k")At(i=>Math.max(0,i-1));else if(m.downArrow||c==="j"){let i=(V.columns[ot]?.enemies.length??1)-1;At(u=>Math.min(Math.max(0,i),u+1))}else m.escape&&Et(!1);return}if(c==="q"){o("menu");return}if(c==="d"&&s){o("deck");return}if(c==="e"){Dn();return}if(c==="p"&&s){let i=s.potions.findIndex(u=>u!==null);if(i>=0){let u=$a(s,i);if(u&&xt.combat){let v=Le.find(A=>A.id===u.potionId);p(u.run),P(u.run),xt.applyPotion(v??null)}}return}if(c>="1"&&c<="9"){da(parseInt(c)-1);return}if(m.leftArrow||c==="h"){ma(Math.max(0,It-1));return}if(m.rightArrow||c==="l"){ma(Math.min(4,It+1));return}if(m.return&&rt>=0){An();return}if(c===" "){Rn();return}if(m.escape){da(-1);return}}}),Gn)return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),k(f,{color:"red",children:["Terminal too small (",n,"x",a,", need ",_n,"x",Tn,")"]})]});if(r==="menu")return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),w(f,{children:" "}),(Fe==="true_ending"?["The fortress. The Pale. You can no longer tell which side you're on."]:Fe==="truth"?["The fortress stands. The Pale stands. The line between them blurs."]:Fe==="cracks"?["The fortress stands at the edge of the Pale.","You've stood here before. You're sure of it."]:["The fortress stands at the edge of the Pale.","Beyond the walls, something stirs."]).map((m,i)=>w(f,{children:m},i)),w(f,{children:" "}),Bt.map((m,i)=>k(f,{bold:i===l,color:i===l?"yellow":void 0,children:[i===l?"\u25B6 ":" ",m.label]},m.action)),w(f,{children:" "}),w(f,{dimColor:!0,children:"\u2191\u2193 navigate Enter select q quit"})]});if(r==="tutorial")return w(gn,{page:pa,totalPages:at});if(r==="controls")return w(bn,{});if(r==="settings"){let c={totalRuns:X?.keep.totalRuns??0,totalWins:X?.keep.totalWins??0,highestAscension:X?.keep.highestAscension??0,echoes:X?.keep.echoes??0,hasSave:!!X};return w(vn,{settings:We,selectedIndex:fa,saveInfo:c,confirmingReset:ha,message:Bn})}if(r==="deck"&&s)return w(sn,{deck:s.deck});if(r==="keep"&&$)return k(Q,{flexDirection:"column",children:[w(pn,{keep:$,selectedIndex:ie}),ia&&k(f,{color:"cyan",bold:!0,children:[" ",ia]})]});if((r==="deck_remove"||r==="shop_remove")&&s)return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"red",children:"\u25C6 Remove a Card"}),k(f,{dimColor:!0,children:["Choose a card to remove from your deck (",s.deck.length," cards)."]}),w(f,{children:" "}),s.deck.map((c,m)=>{let i=O(c.defId),u=m===Tt;return k(f,{bold:u,color:u?"yellow":"white",children:[u?"\u25B6 ":" ",i?.name??c.defId," (",i?.rarity,") \u2014 ",i?.description??""]},c.instanceId)}),w(f,{children:" "}),w(f,{dimColor:!0,children:"\u2191\u2193 navigate Enter remove Esc cancel"})]});if(r==="map"&&s){let c=wa();return k(Q,{flexDirection:"column",children:[k(Q,{justifyContent:"space-between",paddingX:1,children:[k(f,{children:["Gate ",k(f,{bold:!0,color:s.gateHp>40?"green":s.gateHp>20?"yellow":"red",children:[s.gateHp,"/",s.gateMaxHp]})]}),k(f,{children:["Fragments ",w(f,{bold:!0,color:"yellow",children:s.fragments})]}),k(f,{children:["Deck ",w(f,{dimColor:!0,children:s.deck.length})]})]}),ga&&We.showTutorialHints&&!s.currentNodeId&&w(f,{color:"green",bold:!0,children:" TIP: \u2694=combat \u2605=elite(harder, more reward) \u25B3=rest $=shop ?=event \u25C6=boss. \u2191\u2193 select, Enter to go."}),w(ln,{map:s.map,currentNodeId:s.currentNodeId,reachableIds:c.map(m=>m.id),selectedNodeId:c[y]?.id??null})]})}if(r==="reward")return w(on,{cards:_,selectedIndex:M});if(r==="relic_reward")return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"yellow",children:"\u25C6 Relic Reward"}),w(f,{dimColor:!0,children:"Choose a relic to add to your collection (s to skip):"}),w(f,{children:" "}),we.map((c,m)=>{let i=m===Ie;return k(Q,{flexDirection:"column",children:[k(f,{bold:i,color:i?"yellow":"white",children:[i?"\u25B6 ":" ",c.name]}),k(f,{dimColor:!0,children:[" ",c.description]})]},c.id)}),k(f,{bold:Ie===we.length,color:Ie===we.length?"yellow":"white",children:[Ie===we.length?"\u25B6 ":" ","Skip"]}),w(f,{children:" "}),s&&s.relics.length>0&&k(f,{dimColor:!0,children:["Current relics: ",s.relics.join(", ")]}),w(f,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]});if(r==="shop"&&s)return w(cn,{items:R,selectedIndex:S,fragments:s.fragments});if(r==="event"&&b)return w(dn,{event:b,selectedChoice:F});if(r==="rest"&&s)return w(un,{gateHp:s.gateHp,gateMaxHp:s.gateMaxHp,selectedChoice:U,deckSize:s.deck.length});if(r==="result"){let c=s?Jt(ca,s.act,s.ascensionLevel):0;return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),w(f,{children:" "}),ca?k(la,{children:[w(f,{bold:!0,color:"green",children:"\u2605 RUN COMPLETE"}),w(f,{children:"The Pale recedes. The Keep endures."})]}):k(la,{children:[w(f,{bold:!0,color:"red",children:"\u2717 DEFEAT"}),w(f,{children:"The Gate has fallen. The Pale consumes all."})]}),s&&k(la,{children:[k(f,{dimColor:!0,children:["Act ",s.act," | Deck: ",s.deck.length," cards | Fragments: ",s.fragments]}),k(f,{children:["Echoes earned: ",k(f,{bold:!0,color:"cyan",children:["+",c]})]})]}),w(f,{children:" "}),w(f,{dimColor:!0,children:"Enter \u2192 The Keep | q \u2192 menu"})]})}if(r==="combat"&&V&&s){let c=ga&&We.showTutorialHints&&V.turn<=3?V.turn===1&&rt<0?"TIP: Press 1-5 to select a card. \u2190\u2192 to target a column. Enter to play. Space to end turn.":V.turn===1&&rt>=0?"TIP: Arrow keys choose which column to target. Press Enter to play the card.":V.turn===2?"TIP: Enemies with \u2694 will attack your Gate. \u2193 means they advance. Block reduces damage. Press i to inspect enemies.":V.turn===3?'TIP: Cards with type "emplace" can become structures! Select one, press e to toggle emplace mode, then Enter.':null:null;return k(Q,{flexDirection:"column",paddingX:1,children:[k(f,{dimColor:!0,children:["Act ",s.act," | Gate ",s.gateHp,"/",s.gateMaxHp," | Fragments ",s.fragments," | d=deck i=inspect"]}),c&&w(f,{color:"green",bold:!0,children:c}),Rt&&w(Q,{borderStyle:"single",borderColor:"magenta",paddingX:1,marginBottom:1,children:k(f,{color:"magenta",italic:!0,children:['"',Rt,'"']})}),w(nn,{combat:V,selectedCard:rt,targetColumn:It,needsTarget:Mn,message:Pn}),St&&(()=>{let i=V.columns[ot]?.enemies[Hn];if(!i)return k(f,{dimColor:!0,children:["No enemy in column ",ot+1,". \u2190\u2192 to navigate."]});let u=de(i.templateId);return k(Q,{flexDirection:"column",borderStyle:"single",borderColor:"cyan",paddingX:1,children:[k(f,{bold:!0,color:"cyan",children:["Inspecting: ",u?.name??i.templateId," (Col ",ot+1,")"]}),k(f,{children:["HP: ",i.hp,"/",i.maxHp," Row: ",i.row]}),w(f,{dimColor:!0,children:u?.description??""}),i.statusEffects.length>0&&k(f,{children:["Status: ",i.statusEffects.map(v=>`${v.type}(${v.stacks}x, ${v.duration}t)`).join(", ")]}),k(f,{children:["Intent: ",i.intent?`${i.intent.type} ${i.intent.value}`:"unknown"]}),w(f,{dimColor:!0,children:"\u2190\u2192 column \u2191\u2193 enemy i/Esc close"})]})})()]})}return w(f,{children:"Loading..."})}function xn(e){return w(ft,{children:w(po,{...e})})}import{jsx as go}from"react/jsx-runtime";var In="0.5.0";globalThis.__CODEKEEP_VERSION=In;var Cn=new fo;Cn.name("codekeep").description("CodeKeep: The Pale \u2014 deck-building tactical roguelike in your terminal").version(In).option("--ascii","Force ASCII-only rendering (no Unicode box drawing)").option("--compact","Compact layout for narrow terminals").option("--tutorial","Replay the tutorial").option("--no-save","Dry-run mode: play without writing to disk").action(e=>{(!process.stdin.isTTY||!process.stdout.isTTY)&&(process.stderr.write(`codekeep requires an interactive terminal.
19
+ `);return`https://github.com/tooyipjee/codekeep/issues/new?title=${a}&body=${n}&labels=bug,crash`}import{Fragment as un,jsx as ie,jsxs as Ge}from"react/jsx-runtime";var Et=class extends ao.Component{constructor(a){super(a),this.state={error:null,crashFilePath:null,issueUrl:null}}static getDerivedStateFromError(a){return{error:a}}componentDidCatch(a){try{let n=dn(a),t={timestamp:new Date().toISOString(),error:a.message,stack:a.stack,version:globalThis.__CODEKEEP_VERSION??"unknown",nodeVersion:process.version,platform:process.platform,arch:process.arch},r=mn(t);this.setState({crashFilePath:n,issueUrl:r})}catch{}}render(){return this.state.error?Ge(no,{flexDirection:"column",padding:1,children:[ie(Y,{bold:!0,color:"red",children:"\u25C6 CodeKeep \u2014 Something went wrong"}),ie(Y,{children:" "}),ie(Y,{color:"red",children:this.state.error.message}),ie(Y,{children:" "}),ie(Y,{dimColor:!0,children:"Your save file is at:"}),Ge(Y,{children:[" ","~/.config/codekeep/game.json"]}),ie(Y,{children:" "}),this.state.crashFilePath&&Ge(un,{children:[ie(Y,{dimColor:!0,children:"Crash report saved to:"}),Ge(Y,{children:[" ",this.state.crashFilePath]}),ie(Y,{children:" "})]}),this.state.issueUrl&&Ge(un,{children:[ie(Y,{dimColor:!0,children:"Report this bug:"}),Ge(Y,{color:"cyan",children:[" ",this.state.issueUrl]}),ie(Y,{children:" "})]}),ie(Y,{dimColor:!0,children:"If the game won't start, try:"}),Ge(Y,{bold:!0,children:[" ","codekeep --tutorial"]}),ie(Y,{children:" "}),ie(Y,{dimColor:!0,children:"Press Ctrl+C to exit"})]}):this.props.children}};import{Box as Rt,Text as ce}from"ink";import fa from"react";import{Box as pn,Text as Z}from"ink";import{jsx as ge,jsxs as xe}from"react/jsx-runtime";function ro(e){if(!e)return"";switch(e.type){case"advance":return`\u2193${e.value}`;case"attack":return`\u2694${e.value}`;case"buff":return`\u25B2${e.value}`;case"debuff":return`\u25BC${e.value}`;case"shield":return`\u25C8${e.value}`;case"summon":return`+${e.value}`;default:return""}}function oo(e){let a=[];for(let n of e.statusEffects)switch(n.type){case"vulnerable":a.push(`V${n.stacks}`);break;case"weak":a.push(`W${n.stacks}`);break;case"burn":a.push(`B${n.stacks}`);break;case"empowered":a.push(`E${n.stacks}`);break;case"fortified":a.push(`F${n.stacks}`);break}return a.join("")}function so(e,a,n){let t=Math.max(0,Math.min(n,Math.round(e/a*n)));return"\u2588".repeat(t)+"\u2591".repeat(Math.max(0,n-t))}function lo(e){return`${Ce(e.templateId)?.symbol??"?"}${e.hp}`}function fn({columns:e,targetColumn:a,showTarget:n,gateHp:t,gateMaxHp:r,gateBlock:o}){let c=e.length,s=r>0?Math.round(t/r*100):0,f=s>60?"green":s>30?"yellow":"red",b=I=>e.map((C,d)=>{let h=` Col ${d+1} `,E=14-h.length;return"\u2500".repeat(Math.max(0,Math.floor(E/2)))+h+"\u2500".repeat(Math.max(0,Math.ceil(E/2)))}).join(I),v="\u2514"+e.map((I,C)=>"\u2500".repeat(14)+(C<c-1?"\u2534":"")).join("")+"\u2518";return xe(pn,{flexDirection:"column",children:[ge(Z,{dimColor:!0,children:"\u250C"+b("\u252C")+"\u2510"}),n&&xe(Z,{children:[ge(Z,{dimColor:!0,children:"\u2502"}),e.map((I,C)=>{let d=C===a,h=d?" \u25BC TARGET \u25BC ":"";return xe(fa.Fragment,{children:[ge(Z,{color:d?"yellow":void 0,bold:d,children:h.padEnd(14).slice(0,14)}),ge(Z,{dimColor:!0,children:"\u2502"})]},C)})]}),Array.from({length:ze},(I,C)=>xe(Z,{children:[ge(Z,{dimColor:!0,children:"\u2502"}),e.map((d,h)=>{let E=d.enemies.filter(y=>y.row===C),T;E.length===0?T="\xB7".padStart(Math.floor(15/2)).padEnd(14):T=E.map(k=>{let R=ro(k.intent),W=oo(k),A=lo(k);return R&&(A+=` ${R}`),W&&(A+=` ${W}`),A}).join(" ").slice(0,14).padEnd(14);let _=n&&h===a;return xe(fa.Fragment,{children:[ge(Z,{color:_&&E.length>0?"yellow":void 0,children:T}),ge(Z,{dimColor:!0,children:"\u2502"})]},h)})]},C)),xe(Z,{children:[ge(Z,{dimColor:!0,children:"\u2502"}),e.map((I,C)=>{let d=I.emplacement?` \u25C7${I.emplacement.hp}hp `.padEnd(14).slice(0,14):" ".repeat(14);return xe(fa.Fragment,{children:[ge(Z,{color:I.emplacement?"cyan":void 0,children:d}),ge(Z,{dimColor:!0,children:"\u2502"})]},C)})]}),ge(Z,{dimColor:!0,children:v}),xe(pn,{paddingX:1,children:[xe(Z,{bold:!0,color:f,children:["\u25C6 Gate ",so(t,r,20),` ${t}/${r}`]}),o>0&&xe(Z,{color:"cyan",children:[" \u25C7",o]})]})]})}import{Box as hn,Text as Ee}from"ink";import{jsx as Pt,jsxs as We}from"react/jsx-runtime";function io(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function co(e){switch(e){case"armament":return"\u2694";case"fortification":return"\u25C7";case"edict":return"\u2726";case"wild":return"\u25C8";default:return"\xB7"}}function mo(e,a){let n=[];for(let t=0;t<e;t++)n.push(Pt(Ee,{color:t<a?"cyan":"red",bold:!0,children:"\u25C6"},t));return n}function gn({hand:e,selectedIndex:a,resolve:n}){return e.length===0?We(Ee,{dimColor:!0,children:[" ","No cards in hand."]}):We(hn,{flexDirection:"column",children:[Pt(Ee,{dimColor:!0,children:"\u2500\u2500\u2500 Hand ("+e.length+") \u2500\u2500\u2500"}),e.map((t,r)=>{let o=J(t.defId);if(!o)return null;let l=r===a,c=o.cost<=n;return We(hn,{flexDirection:"column",children:[We(Ee,{children:[Pt(Ee,{bold:l,color:l?"yellow":"white",children:l?" \u25B6 ":" "}),We(Ee,{color:c?io(o.rarity):"gray",bold:l,children:[co(o.category)," ",o.name]}),Pt(Ee,{children:" "}),mo(o.cost,n),l&&o.type==="emplace"&&We(Ee,{color:"cyan",children:[" ","[emplaceable]"]})]}),l&&We(Ee,{dimColor:!0,children:[" ",o.description]})]},t.instanceId)})]})}import{jsx as de,jsxs as Qe}from"react/jsx-runtime";function uo(e){switch(e.type){case"damage_dealt":return` dealt ${e.data.damage} damage`;case"enemy_advance":return` enemy advances to row ${e.data.row}`;case"gate_hit":return` gate hit for ${e.data.damage}${e.data.blocked?` (${e.data.blocked} blocked)`:""}`;case"enemy_killed":return" enemy destroyed";case"block_gained":return` +${e.data.value} Block`;case"emplacement_placed":return` emplacement placed in col ${e.data.column+1}`;case"emplacement_triggered":return` emplacement triggered in col ${e.data.column+1}`;case"emplacement_destroyed":return` emplacement destroyed in col ${e.data.column+1}`;case"status_applied":return` applied ${e.data.type} (${e.data.value})`;case"card_played":return` played ${J(e.data.cardId)?.name??e.data.cardId}`;case"turn_start":return`\u2500 Turn ${e.data.turn} \u2500`;default:return""}}function yn({combat:e,selectedCard:a,targetColumn:n,needsTarget:t,message:r}){let o=e.columns.reduce((l,c)=>l+c.enemies.length,0);return Qe(Rt,{flexDirection:"column",children:[Qe(Rt,{justifyContent:"space-between",children:[de(ce,{bold:!0,color:"yellow",children:"\u25C6 The Pale"}),Qe(ce,{children:["Turn ",de(ce,{bold:!0,color:"white",children:e.turn})," ",de(ce,{color:"cyan",children:"\u25C6".repeat(Math.max(0,e.resolve))}),de(ce,{dimColor:!0,children:"\u25C7".repeat(Math.max(0,e.maxResolve-e.resolve))})," ","Enemies ",de(ce,{bold:!0,color:"red",children:o})," ","Draw ",de(ce,{dimColor:!0,children:e.drawPile.length})," / ","Discard ",de(ce,{dimColor:!0,children:e.discardPile.length})]})]}),de(fn,{columns:e.columns,targetColumn:n,showTarget:t&&a>=0,gateHp:e.gateHp,gateMaxHp:e.gateMaxHp,gateBlock:e.gateBlock}),de(gn,{hand:e.hand,selectedIndex:a,resolve:e.resolve}),(()=>{let l=e.events.filter(c=>c.turn>=e.turn-1).slice(-5);return l.length===0?null:Qe(Rt,{flexDirection:"column",marginTop:0,children:[de(ce,{dimColor:!0,children:"\u2500\u2500\u2500 Log \u2500\u2500\u2500"}),l.map((c,s)=>{let f=uo(c);if(!f)return null;let b=c.type==="turn_start";return de(ce,{dimColor:!b,color:b?"white":void 0,children:f},s)})]})})(),r&&Qe(ce,{color:"yellow",bold:!0,children:[" ",r]}),e.phase==="player"&&Qe(ce,{dimColor:!0,children:[" ",e.hand.length>0?`1-${e.hand.length} card `:"","\u2190\u2192 column Enter play e emplace p potion Space end d deck q quit"]}),e.outcome!=="undecided"&&de(Rt,{marginTop:1,paddingX:1,children:de(ce,{bold:!0,color:e.outcome==="win"?"green":"red",children:e.outcome==="win"?"\u2605 VICTORY \u2014 The siege is broken!":"\u2717 DEFEAT \u2014 The Gate has fallen."})})]})}import{Box as wn,Text as oe}from"ink";import{jsx as Pe,jsxs as Fe}from"react/jsx-runtime";function bn(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function po(e){switch(e){case"uncommon":return"\u25C7 uncommon";case"rare":return"\u25C6 rare";case"legendary":return"\u2605 legendary";default:return"\xB7 common"}}function fo(e){switch(e){case"armament":return"\u2694";case"fortification":return"\u25C7";case"edict":return"\u2726";case"wild":return"\u25C8";default:return"\xB7"}}function vn({cards:e,selectedIndex:a}){let n=a>=e.length;return Fe(wn,{flexDirection:"column",padding:1,children:[Pe(oe,{bold:!0,color:"yellow",children:"\u25C6 Card Reward"}),Pe(oe,{dimColor:!0,children:"\u2500".repeat(36)}),Pe(oe,{dimColor:!0,italic:!0,children:"Choose a card to add to your deck."}),Pe(oe,{children:" "}),e.map((t,r)=>{let o=r===a;return Fe(wn,{flexDirection:"column",marginBottom:0,children:[Fe(oe,{children:[Pe(oe,{bold:o,color:o?"yellow":"white",children:o?" \u25B6 ":" "}),Fe(oe,{color:bn(t.rarity),bold:o,children:[fo(t.category)," ",t.name]}),Fe(oe,{dimColor:!0,children:[" ","[",t.cost,"]"," "]}),Pe(oe,{color:bn(t.rarity),dimColor:!0,children:po(t.rarity)})]}),o&&Fe(oe,{dimColor:!0,children:[" ",t.description]})]},t.id)}),Pe(oe,{children:" "}),Fe(oe,{bold:n,color:n?"yellow":"white",children:[n?" \u25B6 ":" ","Skip"]}),Pe(oe,{children:" "}),Pe(oe,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]})}import{Box as ho,Text as pt}from"ink";import{jsx as ga,jsxs as ha}from"react/jsx-runtime";function go(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function kn({deck:e}){let a=new Map;for(let t of e)a.set(t.defId,(a.get(t.defId)??0)+1);let n=[...a.entries()].map(([t,r])=>({def:J(t),count:r})).filter(t=>t.def).sort((t,r)=>{let o={common:0,uncommon:1,rare:2,legendary:3},l=o[t.def.rarity]??0,c=o[r.def.rarity]??0;return l!==c?l-c:t.def.name.localeCompare(r.def.name)});return ha(ho,{flexDirection:"column",padding:1,children:[ha(pt,{bold:!0,color:"yellow",children:["\u25C6 Your Deck"," (",e.length," cards)"]}),ga(pt,{children:" "}),n.map(({def:t,count:r})=>ha(pt,{color:go(t.rarity),children:[r>1?`${r}x `:" ",t.name," [",t.cost,"] \u2014 ",t.description]},t.id)),ga(pt,{children:" "}),ga(pt,{dimColor:!0,children:"Press q or Esc to go back."})]})}import yo from"react";import{Box as Tn,Text as Q}from"ink";import{jsx as se,jsxs as ft}from"react/jsx-runtime";var Re=5,At=" ",et=4;function wo(e){switch(e){case"combat":return"\u2694";case"elite":return"\u2605";case"rest":return"\u25B3";case"shop":return"$";case"event":return"?";case"boss":return"\u25C6";default:return"\xB7"}}function bo(e,a,n,t){if(t)return"cyan";if(n)return"yellow";if(e.visited||!a)return"gray";switch(e.type){case"combat":return"white";case"elite":return"red";case"rest":return"green";case"shop":return"yellow";case"event":return"magenta";case"boss":return"red";default:return"white"}}function vo(e,a){let n={};for(let r of e){n[r.column]||(n[r.column]={straight:!1,left:!1,right:!1});for(let o of r.connections){let l=a.find(c=>c.id===o);l&&(l.column===r.column?n[r.column].straight=!0:l.column>r.column?n[r.column].right=!0:n[r.column].left=!0)}}let t=[];for(let r=0;r<et;r++){let o=n[r];if(!o){t.push(" ".repeat(Re));continue}o.left&&o.straight&&o.right?t.push(" \u2571\u2502\u2572 "):o.left&&o.right?t.push(" \u2571 \u2572 "):o.left&&o.straight?t.push(" \u2571\u2502 "):o.straight&&o.right?t.push(" \u2502\u2572 "):o.left?t.push(" \u2571 "):o.right?t.push(" \u2572 "):o.straight?t.push(" \u2502 "):t.push(" ".repeat(Re))}return t.join(At)}function xn({map:e,currentNodeId:a,reachableIds:n,selectedNodeId:t}){let r=new Set(n),o=Math.max(...e.nodes.map(c=>c.row)),l=[];for(let c=0;c<=o;c++)l.push(e.nodes.filter(s=>s.row===c).sort((s,f)=>s.column-f.column));return ft(Tn,{flexDirection:"column",padding:1,children:[se(Q,{bold:!0,color:"yellow",children:"\u25C6 Act "+e.act+" \u2014 Choose your path"}),se(Q,{dimColor:!0,children:"\u2500".repeat(Re*et+At.length*(et-1))}),se(Q,{children:" "}),l.map((c,s)=>ft(yo.Fragment,{children:[se(Q,{children:Array.from({length:et},(f,b)=>{let v=c.find(k=>k.column===b),I=b>0?At:"";if(!v)return ft(Q,{children:[I," ".repeat(Re)]},b);let C=v.id===a,d=r.has(v.id),h=v.id===t,E=bo(v,d,h,C),T=wo(v.type),_=h?`[${T}]`:C?`(${T})`:` ${T} `,y=_.length>=Re?_.slice(0,Re):_.padStart(Math.ceil((Re+_.length)/2)).padEnd(Re);return ft(Q,{color:E,bold:h||C,dimColor:v.visited&&!C,children:[I,y]},b)})}),s<o&&se(Q,{dimColor:!0,children:vo(c,l[s+1]??[])})]},s)),se(Q,{children:" "}),se(Q,{dimColor:!0,children:"\u2500".repeat(Re*et+At.length*(et-1))}),ft(Tn,{gap:2,children:[se(Q,{dimColor:!0,children:"\u2694 fight"}),se(Q,{dimColor:!0,color:"red",children:"\u2605 elite"}),se(Q,{dimColor:!0,color:"green",children:"\u25B3 rest"}),se(Q,{dimColor:!0,color:"yellow",children:"$ shop"}),se(Q,{dimColor:!0,color:"magenta",children:"? event"}),se(Q,{dimColor:!0,color:"red",children:"\u25C6 boss"})]}),se(Q,{dimColor:!0,children:"\u2191\u2193 select Enter proceed d deck q quit"})]})}import{Box as ko,Text as ht}from"ink";import{jsx as wa,jsxs as ya}from"react/jsx-runtime";function _n({items:e,selectedIndex:a,fragments:n}){return ya(ko,{flexDirection:"column",padding:1,children:[ya(ht,{bold:!0,color:"yellow",children:["\u25C6 Shop \u2014 ",n," fragments"]}),wa(ht,{children:" "}),e.map((t,r)=>{let o=r===a,l=n>=t.cost,c="";return t.type==="card"&&t.cardDef?c=`${t.cardDef.name} (${t.cardDef.rarity}) \u2014 ${t.cardDef.description}`:t.type==="potion"&&t.potionDef?c=`${t.potionDef.name} \u2014 ${t.potionDef.description}`:t.type==="card_remove"&&(c="Remove a card from your deck"),ya(ht,{bold:o,color:o?"yellow":l?"white":"gray",children:[o?"\u25B6 ":" ",c," [",t.cost,"f]"]},r)}),wa(ht,{children:" "}),wa(ht,{dimColor:!0,children:"\u2191\u2193 navigate Enter buy q leave"})]})}import{Box as To,Text as $e}from"ink";import{jsx as gt,jsxs as ba}from"react/jsx-runtime";function In({event:e,selectedChoice:a}){return ba(To,{flexDirection:"column",padding:1,children:[ba($e,{bold:!0,color:"magenta",children:["\u25C6 ",e.name]}),gt($e,{children:" "}),gt($e,{children:e.description}),gt($e,{children:" "}),e.choices.map((n,t)=>ba($e,{bold:t===a,color:t===a?"yellow":"white",children:[t===a?"\u25B6 ":" ",t+1,". ",n.label]},t)),gt($e,{children:" "}),gt($e,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as Cn,Text as ue}from"ink";import{jsx as _e,jsxs as Dt}from"react/jsx-runtime";function Sn({gateHp:e,gateMaxHp:a,selectedChoice:n,deckSize:t}){let r=Math.floor(a*.3),o=Math.min(a,e+r),l=[{label:"Rest",detail:`Heal ${r} Gate HP (${e} \u2192 ${o}/${a})`,color:"green"},{label:"Thin",detail:`Remove a card from your deck (${t} cards)`,color:"cyan"},{label:"Leave",detail:"Continue without resting",color:"white"}];return Dt(Cn,{flexDirection:"column",padding:1,children:[_e(ue,{bold:!0,color:"green",children:"\u25C6 Rest Site"}),_e(ue,{dimColor:!0,children:"\u2500".repeat(36)}),_e(ue,{children:" "}),_e(ue,{dimColor:!0,italic:!0,children:"The campfire crackles against the encroaching Pale."}),_e(ue,{dimColor:!0,italic:!0,children:"A moment of warmth in the endless grey."}),_e(ue,{children:" "}),l.map(({label:c,detail:s,color:f},b)=>{let v=b===n;return Dt(Cn,{flexDirection:"column",children:[Dt(ue,{children:[_e(ue,{bold:v,color:v?"yellow":"white",children:v?" \u25B6 ":" "}),_e(ue,{color:v?f:"white",bold:v,children:c})]}),v&&Dt(ue,{dimColor:!0,children:[" ",s]})]},b)}),_e(ue,{children:" "}),_e(ue,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as tt,Text as z}from"ink";import{jsx as ne,jsxs as Me}from"react/jsx-runtime";var Dn=[{type:"structure",id:"forge",name:"Forge",symbol:"#"},{type:"structure",id:"archive",name:"Archive",symbol:"%"},{type:"structure",id:"foundry",name:"Foundry",symbol:"&"},{type:"structure",id:"beacon_tower",name:"Beacon",symbol:"^"},{type:"structure",id:"sanctum_hall",name:"Sanctum",symbol:"+"}],Mn=[{type:"npc",id:"wren",name:"Wren",symbol:"W"},{type:"npc",id:"sable",name:"Sable",symbol:"S"},{type:"npc",id:"duskmar",name:"Duskmar",symbol:"D"},{type:"npc",id:"mott",name:"Mott",symbol:"M"},{type:"npc",id:"pale_visitor",name:"Pale Visitor",symbol:"?"}],xo={type:"gate",id:"gate",name:"The Gate",symbol:">"},Ve=[...Dn,...Mn,xo],_o={wren:"Wren, the Steward",sable:"Sable, the Archivist",duskmar:"Duskmar, First Wall",mott:"Mott, the Salvager",pale_visitor:"The Pale Visitor"},Io={wren:"Tends the Keep with quiet devotion",sable:"Remembers what the Pale erases",duskmar:"The wall that never fell",mott:"Finds treasure in the wreckage",pale_visitor:"Speaks in riddles from beyond"},En=17,Pn=56,ee=1,U=15,F=3,L=52,Co={forge:{row:3,col:6,width:11},archive:{row:3,col:20,width:11},foundry:{row:3,col:34,width:11},beacon_tower:{row:10,col:6,width:11},sanctum_hall:{row:10,col:20,width:11}},So={wren:{row:8,col:11},sable:{row:8,col:25},duskmar:{row:8,col:39},mott:{row:9,col:44},pale_visitor:{row:13,col:46}};function va(e,a){return e>=a?"green":e>=2?"cyan":e>=1?"yellow":"white"}function Rn(e){return e>=4?"magenta":e>=2?"cyan":e>=1?"yellow":"white"}function An(e,a,n){let t=[];for(let r=0;r<a;r++)t.push(r<e?ne(z,{color:n,bold:!0,children:"\u25C6"},r):ne(z,{dimColor:!0,children:"\u25C7"},r));return t}function Bn({keep:e,selectedId:a,message:n}){let t=[],r=[];for(let d=0;d<En;d++){let h=[],E=[];for(let T=0;T<Pn;T++)h.push((d+T)%2===0?"~":" "),E.push({color:"white",bold:!1,dim:!0});t.push(h),r.push(E)}let o="the pale",l=Math.floor((Pn-o.length)/2);for(let d=0;d<o.length;d++)t[0][l+d]=o[d],t[En-1][l+d]=o[d];t[ee][F]="\u2554",t[ee][L]="\u2557",t[U][F]="\u255A",t[U][L]="\u255D";for(let d=F+1;d<L;d++)t[ee][d]="\u2550",t[U][d]="\u2550",r[ee][d]={color:"white",bold:!1,dim:!0},r[U][d]={color:"white",bold:!1,dim:!0};for(let d=ee+1;d<U;d++)t[d][F]="\u2551",t[d][L]="\u2551",r[d][F]={color:"white",bold:!1,dim:!0},r[d][L]={color:"white",bold:!1,dim:!0};for(let d of[[ee,F],[ee,L],[U,F],[U,L]])r[d[0]][d[1]]={color:"white",bold:!1,dim:!0};for(let d of[F+1,8,14,38,44,L-1])d>F&&d<L&&(t[ee][d]="\u25B2",r[ee][d]={color:"white",bold:!0,dim:!1});for(let d of[F+1,8,14,42,48,L-1])d>F&&d<L&&t[U][d]==="\u2550"&&(t[U][d]="\u25B2",r[U][d]={color:"white",bold:!0,dim:!1});let c=" THE KEEP ",s=F+1+Math.floor((L-F-1-c.length)/2);for(let d=0;d<c.length;d++)t[ee][s+d]=c[d],r[ee][s+d]={color:"yellow",bold:!0,dim:!1};for(let d=ee+1;d<U;d++)for(let h=F+1;h<L;h++)t[d][h]=" ",r[d][h]={color:"white",bold:!1,dim:!1};for(let[d,h]of[[ee+1,F+1],[ee+1,L-1],[U-1,F+1],[U-1,L-1]])t[d][h]="*",r[d][h]={color:"yellow",bold:!0,dim:!1};for(let d=F+2;d<L-1;d++)t[8][d]===" "&&(t[8][d]="\xB7",r[8][d]={color:"white",bold:!1,dim:!0});for(let d of[11,25,39])for(let h=6;h<=(d===39?8:10);h++)t[h][d]===" "&&(t[h][d]="\xB7",r[h][d]={color:"white",bold:!1,dim:!0});for(let d=9;d<U;d++)t[d][28]===" "&&(t[d][28]="\xB7",r[d][28]={color:"white",bold:!1,dim:!0});for(let[d,h]of[[7,16],[7,34],[7,48],[9,8],[9,18],[9,36],[13,8],[13,18],[13,36]])d>ee&&d<U&&t[d][h]===" "&&(t[d][h]="\xB7",r[d][h]={color:"white",bold:!1,dim:!0});for(let d of Dn){let h=Co[d.id];if(!h)continue;let E=Xe.find(P=>P.id===d.id),T=Je(e,d.id),_=E?.maxLevel??3,y=d.id===a,k=y?"yellow":va(T,_),R=y||T>=_,W=!y&&T===0,A=h.row,H=h.col,q=h.width,j=q-2,me=Math.ceil((j-d.name.length)/2),He=j-d.name.length-me;t[A][H]=y?"\u250F":"\u250C";let be=H+1;for(let P=0;P<me;P++)t[A][be]=y?"\u2501":"\u2500",be++;for(let P=0;P<d.name.length;P++)t[A][be]=d.name[P],be++;for(let P=0;P<He;P++)t[A][be]=y?"\u2501":"\u2500",be++;t[A][H+q-1]=y?"\u2513":"\u2510",t[A+1][H]=y?"\u2503":"\u2502";for(let P=1;P<q-1;P++)t[A+1][H+P]=" ";t[A+1][H+Math.floor(q/2)]=d.symbol,t[A+1][H+q-1]=y?"\u2503":"\u2502",t[A+2][H]=y?"\u2517":"\u2514";for(let P=1;P<q-1;P++)t[A+2][H+P]=y?"\u2501":"\u2500";t[A+2][H+q-1]=y?"\u251B":"\u2518";for(let P=0;P<3;P++)for(let te=0;te<q;te++)r[A+P][H+te]={color:k,bold:R,dim:W};let Oe=A+3;if(Oe>ee&&Oe<U){let P=H+Math.floor((q-_)/2);for(let te=0;te<_;te++)t[Oe][P+te]=te<T?"\u25C6":"\u25C7",r[Oe][P+te]={color:te<T?y?"yellow":va(T,_):"white",bold:te<T,dim:te>=T}}}for(let d of Mn){let h=So[d.id];if(!h)continue;let T=e.npcs.find(k=>k.id===d.id)?.tier??0,_=d.id===a,y=_?"yellow":Rn(T);_&&(h.col-1>F&&(t[h.row][h.col-1]="[",r[h.row][h.col-1]={color:"yellow",bold:!0,dim:!1}),h.col+1<L&&(t[h.row][h.col+1]="]",r[h.row][h.col+1]={color:"yellow",bold:!0,dim:!1})),t[h.row][h.col]=d.symbol,r[h.row][h.col]={color:y,bold:_||T>=3,dim:!1}}{let d=a==="gate",h=d?"\u2524 ENTER THE PALE \u251C":"\u2561 ENTER THE PALE \u255E",E=F+1+Math.floor((L-F-1-h.length)/2);for(let T=0;T<h.length;T++)t[U][E+T]=h[T],r[U][E+T]={color:d?"yellow":"green",bold:!0,dim:!1}}for(let d=11;d<=14;d++)for(let h=48;h<L;h++)(t[d][h]===" "||t[d][h]==="\xB7")&&(t[d][h]="~",r[d][h]={color:"white",bold:!1,dim:!0});let f=Ve.find(d=>d.id===a),b="",v="",I="cyan",C=null;if(f)if(f.type==="structure"){let d=Xe.find(T=>T.id===f.id),h=Je(e,f.id),E=d?.maxLevel??3;if(I=va(h,E),b=f.name,h>=E)v=`${d?.description??""} (fully upgraded)`;else{let T=d?.upgradeCost(h+1)??0;v=`${d?.description??""} \u2014 ${T} Echoes to upgrade`}C=Me(z,{children:[" ",An(h,E,I)]})}else if(f.type==="npc"){let h=e.npcs.find(E=>E.id===f.id)?.tier??0;I=Rn(h),b=_o[f.id]??f.id,v=Io[f.id]??"",C=Me(z,{children:[" ",An(h,5,I)]})}else f.type==="gate"&&(I="green",b="The Gate",v="Step beyond the walls. Face the Pale.");return Me(tt,{flexDirection:"column",children:[Me(tt,{justifyContent:"space-between",paddingX:1,children:[ne(z,{bold:!0,color:"yellow",children:"\u25C6 The Keep"}),Me(z,{children:["Echoes ",ne(z,{bold:!0,color:"cyan",children:e.echoes})," ","Runs ",ne(z,{dimColor:!0,children:e.totalRuns})," ","Wins ",ne(z,{dimColor:!0,children:e.totalWins})," ","Ascension ",ne(z,{dimColor:!0,children:e.highestAscension})]})]}),ne(tt,{flexDirection:"column",children:t.map((d,h)=>ne(z,{children:d.map((E,T)=>{let _=r[h][T];return ne(z,{color:_.color,bold:_.bold,dimColor:_.dim,children:E},T)})},h))}),Me(tt,{flexDirection:"column",paddingX:1,children:[f?Me(tt,{flexDirection:"column",children:[Me(tt,{children:[ne(z,{bold:!0,color:I,children:b}),C]}),ne(z,{dimColor:!0,children:v})]}):ne(z,{dimColor:!0,italic:!0,children:"Select a building or NPC."}),n?ne(z,{color:"yellow",bold:!0,children:n}):null,ne(z,{dimColor:!0,children:"\u2190\u2192 select Enter interact q menu"})]})]})}import{Box as Hn,Text as Be}from"ink";import{jsx as at,jsxs as Mt}from"react/jsx-runtime";var Nn=[{title:"Welcome to CodeKeep",lines:["You are the Warden of the Keep \u2014 the last fortress","standing against the Pale, an erasure that consumes all.","","Your goal: survive 3 Acts of increasingly dangerous","enemies by playing cards and building defenses."]},{title:"The Gate",lines:["Your Gate is your lifeline. It has HP (hit points).","If Gate HP reaches 0, your run is over.",""," \u25C6 Gate \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 70/70","","Enemies advance toward the Gate. When they reach it,","they deal damage. Block reduces incoming damage."]},{title:"Combat Basics",lines:["Each turn you have 3 Resolve (mana) to play cards.","Cards cost 0-4 Resolve. Your hand refreshes each turn.",""," 1-5 .... Select a card from your hand"," \u2190\u2192 .... Choose target column"," Enter .. Play the selected card"," Space .. End your turn"," i ...... Inspect an enemy"]},{title:"The 5-Column Grid",lines:["The battlefield has 5 columns. Enemies spawn at the top","and advance downward toward your Gate at the bottom.",""," \u250C\u2500\u2500Col 1\u2500\u2500\u252C\u2500\u2500Col 2\u2500\u2500\u252C\u2500\u2500Col 3\u2500\u2500\u2510"," \u2502 \u262018 \u2502 \xB7 \u2502 \u219110 \u2502"," \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"," \u25C6 Gate \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 70/70"]},{title:"Enemy Intents",lines:["Enemies show what they plan to do next turn:",""," \u2193N .. Advance N rows toward the Gate"," \u2694N .. Attack the Gate for N damage"," \u25B2N .. Buff themselves"," \u25C8N .. Shield nearby enemies"," +N .. Summon new enemies","","Read intents to plan your plays wisely!"]},{title:"Emplacements",lines:["Some cards have dual use \u2014 cast OR emplace.",""," Cast: Immediate effect (damage, block, etc.)"," Emplace: Place as a structure in a column."," Triggers automatically every turn!","","Press e to toggle emplace mode, pick a column,","then press Enter to place it."]},{title:"Status Effects",lines:[" V Vulnerable ... +25% damage taken per stack"," W Weak ......... -15% damage dealt per stack"," B Burn ......... Takes damage each turn, decays"," F Fortified .... -15% damage taken per stack"," E Empowered .... +25% damage dealt per stack","","Effects stack: 2x Vulnerable = +50% damage taken."]},{title:"The Map",lines:[" \u2694 Combat ... Standard enemy encounter"," \u2605 Elite .... Harder fight, better rewards"," \u25B3 Rest ..... Heal or remove a card"," $ Shop ..... Buy cards, potions, remove cards"," ? Event .... Story encounters with choices"," \u25C6 Boss ..... Act boss \u2014 defeat to advance","","Choose your path wisely. Elites are risky but rewarding."]},{title:"The Keep",lines:["After each run, you earn Echoes based on performance.","Explore the Keep to:",""," \u25C6 Upgrade structures (bonuses for future runs)"," \u25C6 Talk to NPCs (unlock story and lore)"," \u25C6 Increase Ascension (harder + new modifiers)","","The Keep remembers. Each run makes you stronger."]},{title:"Ready to Play!",lines:[" 1-5 = card \u2190\u2192 = column Enter = play"," Space = end e = emplace p = potion"," i = inspect d = deck q = menu","","The Pale awaits, Warden. Defend the Keep.","","Press Enter to begin."]}];function Eo(e,a,n){let t=Math.max(0,Math.min(n,Math.round(e/a*n)));return"\u2588".repeat(t)+"\u2591".repeat(Math.max(0,n-t))}function Gn({page:e,totalPages:a}){let n=Nn[e];return n?Mt(Hn,{flexDirection:"column",padding:1,children:[Mt(Be,{bold:!0,color:"yellow",children:["\u25C6 Tutorial \u2014 ",n.title]}),at(Be,{dimColor:!0,children:"\u2500".repeat(44)}),at(Be,{children:" "}),n.lines.map((t,r)=>at(Be,{children:t||" "},r)),at(Be,{children:" "}),at(Be,{dimColor:!0,children:"\u2500".repeat(44)}),Mt(Hn,{children:[Mt(Be,{dimColor:!0,children:[Eo(e+1,a,20)," ",e+1,"/",a," "]}),at(Be,{dimColor:!0,children:e<a-1?"\u2190 prev \u2192 next q close":"\u2190 prev Enter start q close"})]})]}):null}var yt=Nn.length;import{Box as Bt,Text as re}from"ink";import{Fragment as Wn,jsx as ye,jsxs as Ie}from"react/jsx-runtime";var Fn={asciiMode:!1,showTutorialHints:!0,combatLogSize:4};function $n({settings:e,selectedIndex:a,saveInfo:n,confirmingReset:t,message:r}){let o=[{id:"ascii",label:`ASCII Mode: ${e.asciiMode?"ON":"OFF"}`,description:"Use plain ASCII characters (no Unicode symbols)"},{id:"hints",label:`Tutorial Hints: ${e.showTutorialHints?"ON":"OFF"}`,description:"Show helpful tips during first runs"},{id:"log",label:`Combat Log Lines: ${e.combatLogSize}`,description:"Number of recent combat events shown (0-8)"},{id:"tutorial",label:"View Tutorial",description:"Re-read the game tutorial"},{id:"controls",label:"Controls Reference",description:"View all keybindings"},{id:"reset",label:"Reset Save Data",description:"Delete all progress and start fresh"},{id:"back",label:"Back to Menu",description:""}];return Ie(Bt,{flexDirection:"column",padding:1,children:[ye(re,{bold:!0,color:"yellow",children:"\u25C6 Settings"}),ye(re,{children:" "}),ye(Bt,{paddingX:1,children:Ie(Bt,{flexDirection:"column",width:40,children:[ye(re,{bold:!0,dimColor:!0,children:"Save Info"}),Ie(re,{dimColor:!0,children:["Runs: ",n.totalRuns," Wins: ",n.totalWins," Echoes: ",n.echoes]}),Ie(re,{dimColor:!0,children:["Highest Ascension: ",n.highestAscension]}),Ie(re,{dimColor:!0,children:["Save: ",n.hasSave?"~/.config/codekeep/game.json":"None"]})]})}),ye(re,{children:" "}),o.map((l,c)=>{let s=c===a;return Ie(Bt,{children:[Ie(re,{bold:s,color:s?l.id==="reset"?"red":"yellow":void 0,children:[s?"\u25B6 ":" ",l.label]}),s&&l.description?Ie(re,{dimColor:!0,children:[" \u2014 ",l.description]}):null]},l.id)}),t&&Ie(Wn,{children:[ye(re,{children:" "}),ye(re,{bold:!0,color:"red",children:"Are you sure? This deletes ALL progress. Press Enter again to confirm, Esc to cancel."})]}),r&&Ie(Wn,{children:[ye(re,{children:" "}),ye(re,{color:"cyan",bold:!0,children:r})]}),ye(re,{children:" "}),ye(re,{dimColor:!0,children:"\u2191\u2193 navigate Enter toggle/select q back"})]})}import{Box as Po,Text as D}from"ink";import{jsx as M,jsxs as Ro}from"react/jsx-runtime";function Vn(){return Ro(Po,{flexDirection:"column",padding:1,children:[M(D,{bold:!0,color:"yellow",children:"\u25C6 Controls Reference"}),M(D,{dimColor:!0,children:"\u2500".repeat(36)}),M(D,{children:" "}),M(D,{bold:!0,children:"Global"}),M(D,{children:" \u2191\u2193 Navigate menus"}),M(D,{children:" Enter Confirm / select"}),M(D,{children:" Esc Cancel / go back"}),M(D,{children:" q Quit / back to menu"}),M(D,{children:" "}),M(D,{bold:!0,children:"Combat"}),M(D,{children:" 1-9 Select card from hand"}),M(D,{children:" \u2190\u2192 Target column"}),M(D,{children:" Enter Play selected card"}),M(D,{children:" Space End your turn"}),M(D,{children:" e Toggle emplace mode"}),M(D,{children:" p Use potion"}),M(D,{children:" i Inspect enemies"}),M(D,{children:" d View deck"}),M(D,{children:" "}),M(D,{bold:!0,children:"Map"}),M(D,{children:" \u2191\u2193 Select next node"}),M(D,{children:" Enter Enter node"}),M(D,{children:" d View deck"}),M(D,{children:" "}),M(D,{bold:!0,children:"The Keep"}),M(D,{children:" \u2190\u2192 Select building / NPC"}),M(D,{children:" Enter Interact"}),M(D,{children:" "}),M(D,{bold:!0,children:"Inspect Mode (i in combat)"}),M(D,{children:" \u2190\u2192 Switch column"}),M(D,{children:" \u2191\u2193 Switch enemy"}),M(D,{children:" i / Esc Close inspect"}),M(D,{children:" "}),M(D,{dimColor:!0,children:"Press q or Esc to go back"})]})}import{useState as wt,useCallback as Le,useRef as Ao}from"react";function Ln(){let[e,a]=wt(null),[n,t]=wt(-1),[r,o]=wt(2),[l,c]=wt(""),[s,f]=wt(!1),b=Ao(null),v=Le((y,k,R,W,A,H,q)=>{let j=y??aa(),me=k??Math.floor(Math.random()*2147483647),He=Va(j,me,R,W,A,H??[],q);b.current=He,a({...He}),t(-1),o(2),f(!1),c("Your turn. Select a card (1-5) and a column (\u2190\u2192).")},[]),I=(()=>{if(n<0||!e)return!1;let y=e.hand[n];if(!y)return!1;let k=J(y.defId);if(!k)return!1;let R=new Set(["damage","damage_if_vulnerable","damage_equal_block","damage_if_emplaced","damage_plus_block","damage_if_low_hp","vulnerable","weak","burn"]);return k.effects.some(W=>R.has(W.type)&&(W.target==="single"||W.target==="column"))})(),C=Le(y=>{if(!b.current||b.current.phase!=="player"||y<0||y>=b.current.hand.length)return;let k=b.current.hand[y],R=J(k.defId);if(!R)return;if(R.cost>b.current.resolve){c(`Not enough Resolve for ${R.name} (costs ${R.cost}).`);return}t(y);let W=new Set(["damage","damage_if_vulnerable","damage_equal_block","damage_if_emplaced","damage_plus_block","damage_if_low_hp","vulnerable","weak","burn"]),A=R.effects.some(H=>W.has(H.type)&&(H.target==="single"||H.target==="column"));c(A?`${R.name} selected. Choose column (\u2190\u2192), Enter to play.`:`${R.name} selected. Enter to play.`)},[]),d=Le(y=>{y>=0&&y<5&&o(y)},[]),h=Le(()=>{let y=b.current;if(!y||y.phase!=="player"||n<0)return;let k=y.hand[n];if(!k)return;let R=J(k.defId);if(!R)return;let W=y.hand.length;if(La(y,n,r,s),y.hand.length===W){c(`Cannot play ${R.name}. Not enough Resolve.`);return}b.current=y,a({...y}),t(-1),f(!1),y.outcome==="win"?c("Victory! The Pale recedes."):y.outcome==="lose"?c("The Gate has fallen..."):c(`${s?"Emplaced":"Played"} ${R.name}. ${y.resolve} Resolve left.`)},[n,r,s]),E=Le(()=>{if(n<0||!b.current)return;let y=b.current.hand[n];if(!y)return;let k=J(y.defId);if(!k||k.type!=="emplace"){c("This card cannot be emplaced.");return}f(R=>!R),c(s?`${k.name}: cast mode`:`${k.name}: EMPLACE mode \u2014 place in a column`)},[n,s]),T=Le(()=>{let y=b.current;!y||y.phase!=="player"||(Ka(y),b.current=y,a({...y}),t(-1),y.outcome==="win"?c("Victory! The Pale recedes."):y.outcome==="lose"?c("The Gate has fallen..."):c(`Turn ${y.turn}. Your move.`))},[]),_=Le(y=>{let k=b.current;if(!(!k||!y)){for(let R of y.effects)switch(R.type){case"heal":k.gateHp=Math.min(k.gateMaxHp,k.gateHp+R.value);break;case"block":k.gateBlock+=R.value;break;case"damage":{let W=r;if(R.target==="column"){let A=k.columns[W];if(A)for(let H of A.enemies)H.hp-=R.value}else if(R.target==="all")for(let A of k.columns)for(let H of A.enemies)H.hp-=R.value;break}case"draw":{let W=K(k.seed+k.turn*53),{drawn:A,newDrawPile:H,newDiscardPile:q}=De(k.drawPile,k.discardPile,R.value,W);k.hand.push(...A),k.drawPile=H,k.discardPile=q;break}case"resolve":k.resolve=Math.min(k.maxResolve+5,k.resolve+R.value);break}b.current=k,a({...k}),c(`Used ${y.name}.`)}},[r]);return{combat:e,selectedCard:n,targetColumn:r,message:l,emplaceMode:s,selectCard:C,selectTarget:d,confirmPlay:h,endTurn:T,toggleEmplace:E,startCombat:v,applyPotion:_,needsTarget:I}}import{Fragment as ka,jsx as w,jsxs as S}from"react/jsx-runtime";var On=60,Kn=18;function No(){let{stdout:e}=Ho(),[a,n]=B({columns:e?.columns??process.stdout.columns??80,rows:e?.rows??process.stdout.rows??24});return Do(()=>{let t=e??process.stdout,r=()=>n({columns:t.columns,rows:t.rows});return t.on("resize",r),()=>{t.off("resize",r)}},[e]),a}function Go({dryRun:e}){let{exit:a}=Mo(),{columns:n,rows:t}=No(),[r,o]=B("menu"),[l,c]=B(0),[s,f]=B(null),[b,v]=B(0),[I,C]=B([]),[d,h]=B(0),[E,T]=B([]),[_,y]=B(0),[k,R]=B(null),[W,A]=B(0),[H,q]=B(0),[j,me]=B(null),[He,be]=B(0),[Oe,P]=B(""),[te,zn]=B(!1),[Ne,jn]=B([]),[Ke,Ht]=B(0),[Nt,Ue]=B(0),Gt=Ln(),{combat:X,selectedCard:bt,targetColumn:Wt,message:Xn,emplaceMode:Vo,selectCard:Ta,selectTarget:xa,confirmPlay:Jn,endTurn:Zn,toggleEmplace:Qn,startCombat:Ft,applyPotion:Lo,needsTarget:er}=Gt,[$t,Vt]=B(!1),[vt,Lt]=B(0),[tr,Ot]=B(0),[Kt,_a]=B(null),[Ia,qe]=B(0),[nt,Ut]=B(Fn),[Ca,qt]=B(0),[ar,kt]=B(""),[Sa,Ye]=B(!1),[le,Ae]=B(()=>Ze()),Ea=!le||le.keep.totalRuns<=1,rt=le?an(le.keep.totalRuns,le.keep.highestAscension):"surface",nr=n<On||t<Kn,ve=we(()=>{let u=le??Ze();return u||(u=sn("Warden"),u.keep.npcs.length===0&&(u.keep.npcs=ca()),Se(u)),u.keep.npcs.length===0&&(u.keep.npcs=ca()),Ae(u),u},[le]),G=we(u=>{if(e)return;let m=ve();m.activeRun=u,j&&(m.keep=j),Se(m),Ae(m)},[e,j,ve]),Yt=we(()=>{let u=`run-${Date.now()}`,m=ve(),i=za(u,m.keep.highestAscension);f(i),v(0),m.activeRun=i,m.keep.totalRuns++,me(m.keep),Se(m),Ae(m),m.keep.totalRuns===1?(qe(0),o("tutorial")):o("map")},[ve]),rr=we(()=>{let u=Ze();u?.activeRun&&(f(u.activeRun),me(u.keep),v(0),o("map"))},[]),Pa=we(()=>{let u=ve();Ae(u),me(u.keep),be(0),P(""),o("keep")},[ve]),Ra=we(()=>s?Ya(s.map,s.currentNodeId):[],[s]),or=we(u=>{if(!s)return;let m=ja(s,u.id);if(u.type==="combat"||u.type==="elite"){let i=he(s.seed+u.id),p=K(i),x=Ua(s.act,p,u.type==="elite");Ft(m.deck,i,m.gateHp,m.gateMaxHp,x.enemies,m.relics,Ct(s.act,s.ascensionLevel)),f(m),o("combat")}else if(u.type==="boss"){let i=he(s.seed+"-boss-"+s.act),p=Ga(s.act);Ft(m.deck,i,m.gateHp,m.gateMaxHp,p,m.relics,Ct(s.act,s.ascensionLevel));let x=na(s.act);if(x?.dialogue){let N=x.dialogue.find(ke=>ke.storyLayer===rt)??x.dialogue[0];N&&_a(N.onAppear)}f(m),o("combat")}else if(u.type==="shop"){let i=K(he(s.seed+u.id));T(Qa(i)),y(0),f(m),o("shop")}else if(u.type==="event"){let i=K(he(s.seed+u.id));R(en(s.act,i,rt)),A(0),f(m),o("event")}else u.type==="rest"&&(q(0),f(m),o("rest"));G(m)},[s,Ft,G]),ot=we((u,m)=>{zn(m),f(u);let i=ve(),p=da(m,u.act,u.ascensionLevel);i.keep.echoes+=p,m&&(i.keep.totalWins++,u.ascensionLevel>=i.keep.highestAscension&&(i.keep.highestAscension=u.ascensionLevel+1)),i.activeRun=null,me(i.keep),Se(i),Ae(i),o("result")},[ve]),sr=we(()=>{if(!X||!s)return;let u={...s,gateHp:X.gateHp};if(X.outcome==="lose"){ot(u,!1);return}let m=s.currentNodeId?je(s.map,s.currentNodeId):null,i=m?.type==="elite"?Tt.elite:m?.type==="boss"?Tt.boss:Tt.combat;if(u=ut(u,i),u.relics.includes("mending_stone")&&(u=St(u,5)),u.relics.includes("fragment_magnet")&&(u=ut(u,5)),m?.type==="elite"||m?.type==="boss"){let x=K(he(s.seed+(s.currentNodeId??"")+"-relic")),N=$a(x,u.relics,3);if(N.length>0){jn(N),Ht(0),f(u),G(u),o("relic_reward");return}}if(m?.type==="boss"){s.act<3?(u=ia(u),f(u),G(u),v(0),o("map")):ot(u,!0);return}let p=K(he(s.seed+(s.currentNodeId??"")+"-reward"));C(It(p)),h(0),f(u),G(u),o("reward")},[X,s,G,ot]),Aa=we(u=>{if(!s)return;let m=s;u&&(m=sa(m,mt(u.id))),f(m),G(m),v(0),o("map")},[s,G]),Da=we(u=>{if(!s)return;let m=s;if(u&&(m={...m,relics:[...m.relics,u.id]}),f(m),G(m),(s.currentNodeId?je(s.map,s.currentNodeId):null)?.type==="boss")s.act<3?(m=ia(m),f(m),G(m),v(0),o("map")):ot(m,!0);else{let p=K(he(s.seed+(s.currentNodeId??"")+"-reward"));C(It(p)),h(0),o("reward")}},[s,G,ot]),zt=[{label:"The Keep",action:"keep"},{label:"New Run",action:"new"},...le?.activeRun?[{label:"Resume Run",action:"resume"}]:[],{label:"Tutorial",action:"tutorial"},{label:"Settings",action:"settings"},{label:"Quit",action:"quit"}];if(Bo((u,m)=>{if(r==="tutorial"){m.rightArrow?qe(i=>Math.min(yt-1,i+1)):m.leftArrow?qe(i=>Math.max(0,i-1)):m.return?Ia===yt-1?Yt():qe(i=>Math.min(yt-1,i+1)):(u==="q"||m.escape)&&o("menu");return}if(r==="controls"){(u==="q"||m.escape)&&o("settings");return}if(r==="settings"){let i=["ascii","hints","log","tutorial","controls","reset","back"];if(m.upArrow)qt(p=>Math.max(0,p-1)),Ye(!1);else if(m.downArrow)qt(p=>Math.min(i.length-1,p+1)),Ye(!1);else if(u==="q"||m.escape)o("menu"),Ye(!1);else if(m.return){let p=i[Ca];p==="ascii"?(Ut(x=>({...x,asciiMode:!x.asciiMode})),kt("ASCII mode "+(nt.asciiMode?"disabled":"enabled"))):p==="hints"?(Ut(x=>({...x,showTutorialHints:!x.showTutorialHints})),kt("Tutorial hints "+(nt.showTutorialHints?"disabled":"enabled"))):p==="log"?Ut(x=>({...x,combatLogSize:x.combatLogSize>=8?0:x.combatLogSize+2})):p==="tutorial"?(qe(0),o("tutorial")):p==="controls"?o("controls"):p==="reset"?Sa?(ln(),Ae(null),me(null),f(null),Ye(!1),kt("Save data deleted. Starting fresh.")):Ye(!0):p==="back"&&o("menu")}return}if(r==="relic_reward"){m.upArrow?Ht(i=>Math.max(0,i-1)):m.downArrow?Ht(i=>Math.min(Ne.length,i+1)):u==="s"?Da(null):m.return&&Da(Ke<Ne.length?Ne[Ke]:null);return}if(r==="menu"){if(m.upArrow)c(i=>Math.max(0,i-1));else if(m.downArrow)c(i=>Math.min(zt.length-1,i+1));else if(m.return){let i=zt[l]?.action;i==="keep"?Pa():i==="new"?Yt():i==="resume"?rr():i==="tutorial"?(qe(0),o("tutorial")):i==="settings"?(qt(0),kt(""),Ye(!1),o("settings")):a()}else u==="q"&&a();return}if(r==="deck"){(u==="q"||m.escape)&&o("map");return}if(r==="map"&&s){let i=Ra();m.upArrow?v(p=>Math.max(0,p-1)):m.downArrow?v(p=>Math.min(i.length-1,p+1)):m.return&&i[b]?or(i[b]):u==="d"?o("deck"):u==="q"&&(G(s),o("menu"));return}if(r==="reward"){let i=I.length;m.upArrow?h(p=>Math.max(0,p-1)):m.downArrow?h(p=>Math.min(i,p+1)):u==="s"?Aa(null):m.return&&Aa(d<I.length?I[d]:null);return}if(r==="shop"&&s){if(m.upArrow)y(i=>Math.max(0,i-1));else if(m.downArrow)y(i=>Math.min(E.length-1,i+1));else if(u==="q"||m.escape)v(0),o("map");else if(m.return){let i=E[_];if(i&&s.fragments>=i.cost){let p=Xa(s,i.cost);if(!p)return;if(i.type==="card"&&i.cardDef)p=sa(p,mt(i.cardDef.id)),f(p),G(p),T(x=>x.filter((N,ke)=>ke!==_)),y(0);else if(i.type==="potion"&&i.potionDef){let x=Ja(p,i.potionDef.id);x&&(p=x),f(p),G(p),T(N=>N.filter((ke,lr)=>lr!==_)),y(0)}else i.type==="card_remove"&&(f(p),G(p),Ue(0),T(x=>x.filter((N,ke)=>ke!==_)),o("shop_remove"))}}return}if(r==="event"&&k&&s){if(m.upArrow)A(i=>Math.max(0,i-1));else if(m.downArrow)A(i=>Math.min(k.choices.length-1,i+1));else if(m.return){let i=k.choices[W],p=s;switch(i.effect.type){case"heal":p=St(p,i.effect.value);break;case"damage":{p={...p,gateHp:Math.max(1,p.gateHp-i.effect.value)};let x=i.label.match(/(\d+)\s*fragments/i);x&&(p=ut(p,parseInt(x[1])));break}case"fragments":p=ut(p,i.effect.value);break;case"max_hp":p={...p,gateMaxHp:p.gateMaxHp+i.effect.value,gateHp:p.gateHp+i.effect.value};break;case"card_reward":{let x=i.label.match(/lose\s+(\d+)\s*hp/i);x&&(p={...p,gateHp:Math.max(1,p.gateHp-parseInt(x[1]))});let N=K(he(s.seed+(k?.id??"")));C(It(N)),h(0),f(p),G(p),o("reward");return}case"remove_card":{f(p),G(p),o("deck_remove");return}case"nothing":break}f(p),G(p),v(0),o("map")}return}if(r==="rest"&&s){if(m.upArrow)q(i=>Math.max(0,i-1));else if(m.downArrow)q(i=>Math.min(2,i+1));else if(m.return){let i=s;H===0?(i=St(i,Math.floor(i.gateMaxHp*.3)),f(i),G(i),v(0),o("map")):H===1&&i.deck.length>5?(f(i),Ue(0),o("deck_remove")):(f(i),G(i),v(0),o("map"))}return}if(r==="deck_remove"&&s){if(m.upArrow)Ue(i=>Math.max(0,i-1));else if(m.downArrow)Ue(i=>Math.min(s.deck.length-1,i+1));else if(m.escape||u==="q")v(0),o("map");else if(m.return&&s.deck.length>5){let i=s.deck[Nt];if(i){let p=la(s,i.instanceId);f(p),G(p)}v(0),o("map")}return}if(r==="shop_remove"&&s){if(m.upArrow)Ue(i=>Math.max(0,i-1));else if(m.downArrow)Ue(i=>Math.min(s.deck.length-1,i+1));else if(m.escape||u==="q")o("shop");else if(m.return&&s.deck.length>5){let i=s.deck[Nt];if(i){let p=la(s,i.instanceId);f(p),G(p)}o("shop")}return}if(r==="keep"&&j){if(m.leftArrow||m.upArrow)be(i=>(i-1+Ve.length)%Ve.length),P("");else if(m.rightArrow||m.downArrow)be(i=>(i+1)%Ve.length),P("");else if(u==="q")o("menu");else if(m.return){let i=Ve[He];if(!i)return;if(i.type==="structure"){let p=Xe.find(N=>N.id===i.id);if(!p)return;let x=tn(j,p.id);if(x){me(x);let N=ve();N.keep=x,Se(N),Ae(N),P(`Upgraded ${p.name}!`)}else Je(j,p.id)>=p.maxLevel?P(`${p.name} is already max level.`):P(`Not enough Echoes to upgrade ${p.name}.`)}else if(i.type==="npc"){let p=j.npcs.find(N=>N.id===i.id);if(!p)return;let x=nn(p.id,j);if(x){let N=rn(j,p.id,x.dialogueId);me(N);let ke=ve();ke.keep=N,Se(ke),Ae(ke),P(`${x.speaker}: "${x.text}"`)}else P("(No new dialogue)")}else i.type==="gate"&&Yt()}return}if(r==="result"){m.return||u===" "?Pa():u==="q"&&o("menu");return}if(r==="combat"&&X){if(X.outcome!=="undecided"){(m.return||u===" ")&&sr();return}if(Kt&&X.turn>1&&_a(null),u==="i"){$t?Vt(!1):(Vt(!0),Lt(0),Ot(0));return}if($t){if(m.leftArrow)Lt(i=>Math.max(0,i-1));else if(m.rightArrow)Lt(i=>Math.min(4,i+1));else if(m.upArrow)Ot(i=>Math.max(0,i-1));else if(m.downArrow){let i=(X.columns[vt]?.enemies.length??1)-1;Ot(p=>Math.min(Math.max(0,i),p+1))}else m.escape&&Vt(!1);return}if(u==="q"){o("menu");return}if(u==="d"&&s){o("deck");return}if(u==="e"){Qn();return}if(u==="p"&&s){let i=s.potions.findIndex(p=>p!==null);if(i>=0){let p=Za(s,i);if(p&&Gt.combat){let x=ct.find(N=>N.id===p.potionId);f(p.run),G(p.run),Gt.applyPotion(x??null)}}return}if(u>="1"&&u<="9"){Ta(parseInt(u)-1);return}if(m.leftArrow){xa(Math.max(0,Wt-1));return}if(m.rightArrow){xa(Math.min(4,Wt+1));return}if(m.return&&bt>=0){Jn();return}if(u===" "){Zn();return}if(m.escape){Ta(-1);return}}}),nr)return S(pe,{flexDirection:"column",padding:1,children:[w(g,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),S(g,{color:"red",children:["Terminal too small (",n,"x",t,", need ",On,"x",Kn,")"]})]});if(r==="menu")return S(pe,{flexDirection:"column",padding:1,children:[w(g,{bold:!0,color:"yellow",children:"\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"}),w(g,{bold:!0,color:"yellow",children:"\u2502 \u25C6 CodeKeep \u2014 The Pale \u2502"}),w(g,{bold:!0,color:"yellow",children:"\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"}),w(g,{children:" "}),(rt==="true_ending"?["The fortress. The Pale. You can no longer tell which side you're on."]:rt==="truth"?["The fortress stands. The Pale stands. The line between them blurs."]:rt==="cracks"?["The fortress stands at the edge of the Pale.","You've stood here before. You're sure of it."]:["The fortress stands at the edge of the Pale.","Beyond the walls, something stirs."]).map((m,i)=>w(g,{dimColor:!0,italic:!0,children:m},i)),w(g,{children:" "}),zt.map((m,i)=>{let p=i===l;return S(g,{bold:p,color:p?"yellow":"white",children:[p?" \u25B6 ":" ",m.label]},m.action)}),w(g,{children:" "}),w(g,{dimColor:!0,children:"\u2191\u2193 navigate Enter select q quit"})]});if(r==="tutorial")return w(Gn,{page:Ia,totalPages:yt});if(r==="controls")return w(Vn,{});if(r==="settings"){let u={totalRuns:le?.keep.totalRuns??0,totalWins:le?.keep.totalWins??0,highestAscension:le?.keep.highestAscension??0,echoes:le?.keep.echoes??0,hasSave:!!le};return w($n,{settings:nt,selectedIndex:Ca,saveInfo:u,confirmingReset:Sa,message:ar})}if(r==="deck"&&s)return w(kn,{deck:s.deck});if(r==="keep"&&j)return w(Bn,{keep:j,selectedId:Ve[He]?.id??"forge",message:Oe});if((r==="deck_remove"||r==="shop_remove")&&s)return S(pe,{flexDirection:"column",padding:1,children:[w(g,{bold:!0,color:"red",children:"\u25C6 Remove a Card"}),S(g,{dimColor:!0,children:["Choose a card to remove from your deck (",s.deck.length," cards)."]}),w(g,{children:" "}),s.deck.map((u,m)=>{let i=J(u.defId),p=m===Nt;return S(g,{bold:p,color:p?"yellow":"white",children:[p?"\u25B6 ":" ",i?.name??u.defId," (",i?.rarity,") \u2014 ",i?.description??""]},u.instanceId)}),w(g,{children:" "}),w(g,{dimColor:!0,children:"\u2191\u2193 navigate Enter remove Esc cancel"})]});if(r==="map"&&s){let u=Ra();return S(pe,{flexDirection:"column",children:[S(pe,{justifyContent:"space-between",paddingX:1,children:[S(g,{children:["Gate ",S(g,{bold:!0,color:s.gateHp>40?"green":s.gateHp>20?"yellow":"red",children:[s.gateHp,"/",s.gateMaxHp]})]}),S(g,{children:["Fragments ",w(g,{bold:!0,color:"yellow",children:s.fragments})]}),S(g,{children:["Deck ",w(g,{dimColor:!0,children:s.deck.length})]})]}),Ea&&nt.showTutorialHints&&!s.currentNodeId&&w(g,{color:"green",bold:!0,children:" TIP: \u2694=combat \u2605=elite(harder, more reward) \u25B3=rest $=shop ?=event \u25C6=boss. \u2191\u2193 select, Enter to go."}),w(xn,{map:s.map,currentNodeId:s.currentNodeId,reachableIds:u.map(m=>m.id),selectedNodeId:u[b]?.id??null})]})}if(r==="reward")return w(vn,{cards:I,selectedIndex:d});if(r==="relic_reward")return S(pe,{flexDirection:"column",padding:1,children:[w(g,{bold:!0,color:"magenta",children:"\u25C6 Relic Reward"}),w(g,{dimColor:!0,children:"\u2500".repeat(36)}),w(g,{dimColor:!0,italic:!0,children:"An artifact resonates from the defeated foe."}),w(g,{children:" "}),Ne.map((u,m)=>{let i=m===Ke;return S(pe,{flexDirection:"column",children:[S(g,{children:[w(g,{bold:i,color:i?"yellow":"white",children:i?" \u25B6 ":" "}),S(g,{color:i?"magenta":"white",bold:i,children:["\u2605 ",u.name]})]}),i&&S(g,{dimColor:!0,children:[" ",u.description]})]},u.id)}),w(g,{children:" "}),S(g,{bold:Ke===Ne.length,color:Ke===Ne.length?"yellow":"white",children:[Ke===Ne.length?" \u25B6 ":" ","Skip"]}),w(g,{children:" "}),s&&s.relics.length>0&&S(pe,{children:[w(g,{dimColor:!0,children:"Relics: "}),w(g,{color:"magenta",children:s.relics.join(" \xB7 ")})]}),w(g,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]});if(r==="shop"&&s)return w(_n,{items:E,selectedIndex:_,fragments:s.fragments});if(r==="event"&&k)return w(In,{event:k,selectedChoice:W});if(r==="rest"&&s)return w(Sn,{gateHp:s.gateHp,gateMaxHp:s.gateMaxHp,selectedChoice:H,deckSize:s.deck.length});if(r==="result"){let u=s?da(te,s.act,s.ascensionLevel):0;return S(pe,{flexDirection:"column",padding:1,children:[te?S(ka,{children:[w(g,{bold:!0,color:"green",children:"\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"}),w(g,{bold:!0,color:"green",children:"\u2502 \u2605 RUN COMPLETE \u2502"}),w(g,{bold:!0,color:"green",children:"\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"}),w(g,{children:" "}),w(g,{italic:!0,children:"The Pale recedes. The Keep endures."}),w(g,{italic:!0,dimColor:!0,children:"Another dawn. Another day of resistance."})]}):S(ka,{children:[w(g,{bold:!0,color:"red",children:"\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"}),w(g,{bold:!0,color:"red",children:"\u2502 \u2717 DEFEAT \u2502"}),w(g,{bold:!0,color:"red",children:"\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"}),w(g,{children:" "}),w(g,{italic:!0,children:"The Gate has fallen. The Pale consumes all."}),w(g,{italic:!0,dimColor:!0,children:"But the Keep remembers. It always remembers."})]}),w(g,{children:" "}),s&&S(ka,{children:[w(g,{dimColor:!0,children:"\u2500".repeat(32)}),S(g,{children:[" ","Act ",w(g,{bold:!0,children:s.act})," ","Deck ",S(g,{dimColor:!0,children:[s.deck.length," cards"]})," ","Fragments ",w(g,{dimColor:!0,children:s.fragments})]}),S(g,{children:[" ","Echoes earned ",S(g,{bold:!0,color:"cyan",children:["+",u]})]}),w(g,{dimColor:!0,children:"\u2500".repeat(32)})]}),w(g,{children:" "}),w(g,{dimColor:!0,children:"Enter \u2192 The Keep | q \u2192 menu"})]})}if(r==="combat"&&X&&s){let u=Ea&&nt.showTutorialHints&&X.turn<=3?X.turn===1&&bt<0?"TIP: Press 1-5 to select a card. \u2190\u2192 to target a column. Enter to play. Space to end turn.":X.turn===1&&bt>=0?"TIP: Arrow keys choose which column to target. Press Enter to play the card.":X.turn===2?"TIP: Enemies with \u2694 will attack your Gate. \u2193 means they advance. Block reduces damage. Press i to inspect enemies.":X.turn===3?'TIP: Cards with type "emplace" can become structures! Select one, press e to toggle emplace mode, then Enter.':null:null;return S(pe,{flexDirection:"column",paddingX:1,children:[S(g,{dimColor:!0,children:["Act ",s.act," | Gate ",s.gateHp,"/",s.gateMaxHp," | Fragments ",s.fragments," | d=deck i=inspect"]}),u&&w(g,{color:"green",bold:!0,children:u}),Kt&&w(pe,{borderStyle:"single",borderColor:"magenta",paddingX:1,marginBottom:1,children:S(g,{color:"magenta",italic:!0,children:['"',Kt,'"']})}),w(yn,{combat:X,selectedCard:bt,targetColumn:Wt,needsTarget:er,message:Xn}),$t&&(()=>{let i=X.columns[vt]?.enemies[tr];if(!i)return S(g,{dimColor:!0,children:["No enemy in column ",vt+1,". \u2190\u2192 to navigate."]});let p=Ce(i.templateId);return S(pe,{flexDirection:"column",borderStyle:"single",borderColor:"cyan",paddingX:1,children:[S(g,{bold:!0,color:"cyan",children:["Inspecting: ",p?.name??i.templateId," (Col ",vt+1,")"]}),S(g,{children:["HP: ",i.hp,"/",i.maxHp," Row: ",i.row]}),w(g,{dimColor:!0,children:p?.description??""}),i.statusEffects.length>0&&S(g,{children:["Status: ",i.statusEffects.map(x=>`${x.type}(${x.stacks}x, ${x.duration}t)`).join(", ")]}),S(g,{children:["Intent: ",i.intent?`${i.intent.type} ${i.intent.value}`:"unknown"]}),w(g,{dimColor:!0,children:"\u2190\u2192 column \u2191\u2193 enemy i/Esc close"})]})})()]})}return w(g,{children:"Loading..."})}function Un(e){return w(Et,{children:w(Go,{...e})})}import{jsx as $o}from"react/jsx-runtime";var qn="0.5.0";globalThis.__CODEKEEP_VERSION=qn;var Yn=new Wo;Yn.name("codekeep").description("CodeKeep: The Pale \u2014 deck-building tactical roguelike in your terminal").version(qn).option("--ascii","Force ASCII-only rendering (no Unicode box drawing)").option("--compact","Compact layout for narrow terminals").option("--tutorial","Replay the tutorial").option("--no-save","Dry-run mode: play without writing to disk").action(e=>{(!process.stdin.isTTY||!process.stdout.isTTY)&&(process.stderr.write(`codekeep requires an interactive terminal.
20
20
  Run it directly in your terminal (not piped or in CI).
21
- `),process.exit(1));let{waitUntilExit:t,unmount:n}=ho(go(xn,{asciiMode:e.ascii??!1,compact:e.compact??!1,forceTutorial:e.tutorial??!1,dryRun:e.save===!1}),{exitOnCtrlC:!1}),a=!1;function r(){if(!a){if(a=!0,e.save!==!1){process.stderr.write(`
21
+ `),process.exit(1));let{waitUntilExit:a,unmount:n}=Fo($o(Un,{asciiMode:e.ascii??!1,compact:e.compact??!1,forceTutorial:e.tutorial??!1,dryRun:e.save===!1}),{exitOnCtrlC:!1}),t=!1;function r(){if(!t){if(t=!0,e.save!==!1){process.stderr.write(`
22
22
  Saving...
23
- `);try{let o=De();o&&me(o)}catch{}}n()}}process.on("SIGINT",r),process.on("SIGTERM",r),process.on("SIGHUP",r),t().then(()=>{process.exit(0)}).catch(()=>{process.exit(1)})});Cn.parse();export{In as CLI_VERSION};
23
+ `);try{let o=Ze();o&&Se(o)}catch{}}n()}}process.on("SIGINT",r),process.on("SIGTERM",r),process.on("SIGHUP",r),a().then(()=>{process.exit(0)}).catch(()=>{process.exit(1)})});Yn.parse();export{qn as CLI_VERSION};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codekeep",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "type": "module",
5
5
  "description": "CodeKeep: The Pale — deck-building tactical roguelike in your terminal",
6
6
  "license": "MIT",