codekeep 0.9.5 → 0.9.6

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 Xo}from"commander";import{render as Jo}from"ink";import{useState as A,useCallback as ke,useEffect as Ko}from"react";import{Box as ye,Text as y,useApp as Uo,useInput as qo,useStdout as Yo}from"ink";var Xe=5,Je=4,Qt=3,it=5,ea=70,ct=[{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:[]}],Va=["strike","strike","strike","guard","guard","spark","ember","brace","bolster","mend"];function U(e){return ct.find(t=>t.id===e)}var br=[{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 Pe(e){return br.find(t=>t.id===e)}var Ze=[{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}]}],kt={combat:15,elite:30,boss:50},vr=[{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 kr(e,t){return vr.filter(n=>n.npcId===e&&n.tier<=t).flatMap(n=>n.lines)}function La(e,t,a){let n=kr(e,t),r=new Set(a);return n.filter(o=>!r.has(o.id))}import{writeFileSync as ra,readFileSync as eo,mkdirSync as to,existsSync as ga,renameSync as ao,unlinkSync as no}from"fs";import{join as hn,dirname as ro}from"path";import{homedir as oo}from"os";function j(e){let t=e|0;return()=>{t=t+1831565813|0;let a=Math.imul(t^t>>>15,1|t);return a=a+Math.imul(a^a>>>7,61|a)^a,((a^a>>>14)>>>0)/4294967296}}function we(e){let t=0;for(let a=0;a<e.length;a++){let n=e.charCodeAt(a);t=(t<<5)-t+n|0}return t}function Ka(e,t){let a=[...e];for(let n=a.length-1;n>0;n--){let r=Math.floor(t()*(n+1));[a[n],a[r]]=[a[r],a[n]]}return a}var Tr=1;function ut(e){return{instanceId:`card-${Tr++}`,defId:e,upgraded:!1}}function sa(){return Va.map(ut)}function xr(e,t){return Ka(e,t)}function De(e,t,a,n){let r=[],o=[...e],l=[...t];for(let i=0;i<a;i++){if(o.length===0){if(l.length===0)break;o=Ka(l,n),l=[]}r.push(o.shift())}return{drawn:r,newDrawPile:o,newDiscardPile:l}}var _r=[{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,a)=>{let n=e.columns[2];n.enemies.length<3&&n.enemies.push(ia("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,a)=>{if(a>=2)for(let n of e.columns)for(let r of n.enemies){let o=r.statusEffects.find(l=>l.type==="empowered");o?o.stacks+=1:r.statusEffects.push({type:"empowered",stacks:1,duration:99})}}}];function la(e){return _r.find(t=>t.act===e)}function Ir(e,t){let a=0;for(let n=0;n<e.phases.length;n++)t<=e.phases[n].hpThreshold&&(a=n);return a}function Cr(e,t,a,n,r){let o=Ir(e,t);if(e.onPhaseChange&&n&&r){let s=r.bossPhase??0;o>s&&(e.onPhaseChange(n,r,o),r.bossPhase=o)}let l=e.phases[o],i=(a-1)%l.intentPattern.length;return l.intentPattern[i]}function Ua(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 Sr=1;function ia(e,t){let a=Pe(e);if(!a)throw new Error(`Unknown enemy template: ${e}`);return{instanceId:`enemy-${Sr++}`,templateId:e,hp:a.hp,maxHp:a.hp,column:Math.max(0,Math.min(t,Xe-1)),row:0,intent:null,statusEffects:[]}}function ca(e,t,a=1,n=!1,r){let o=Pe(e.templateId);if(!o)return{type:"advance",value:1};let l=la(o.act);if(l&&l.templateId===e.templateId){let s=e.hp/e.maxHp;return Cr(l,s,a,r,e)}let i=t();switch(e.templateId){case"shielder":return i<.3?{type:"shield",value:5}:i<.6?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column};case"flanker":return i<.4?{type:"attack",value:o.damage,targetColumn:e.column}:i<.7?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column};case"breaker":return n?{type:"advance",value:o.speed}:i<.6?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column};case"wraith":return i<.4?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column};case"echo":return i<.3?{type:"buff",value:1}:i<.6?{type:"attack",value:o.damage,targetColumn:e.column}:{type:"advance",value:o.speed};default:return i<.5?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column}}}function Er(e){e.statusEffects=e.statusEffects.map(t=>({...t,duration:t.duration-1})).filter(t=>t.duration>0&&t.stacks>0)}function te(e,t,a,n=2){let r=e.statusEffects.find(o=>o.type===t);r?(r.stacks+=a,r.duration=Math.max(r.duration,n)):e.statusEffects.push({type:t,stacks:a,duration:n})}function ge(e,t){return e.statusEffects.find(n=>n.type===t)?.stacks??0}function qa(e){let t=1,a=ge(e,"vulnerable");a>0&&(t*=1+a*.25);let n=ge(e,"fortified");return n>0&&(t*=Math.max(.25,1-n*.15)),t}function Pr(e){let t=1,a=ge(e,"weak");return a>0&&(t*=Math.max(.25,1-a*.15)),ge(e,"empowered")>0&&(t*=1+ge(e,"empowered")*.25),t}function Rr(e){let t=ge(e,"burn");if(t>0){e.hp-=t;let a=e.statusEffects.find(n=>n.type==="burn");return a&&(a.stacks=Math.max(0,a.stacks-1)),t}return 0}function Ar(e,t,a,n=0){if(a<0||a>=e.columns.length||e.columns[a].emplacement||!t.emplaceHp||!t.emplaceEffects)return!1;let r=t.emplaceHp+n;return e.columns[a].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:a}}),!0}function Ya(e){let t=e.columns.filter(a=>a.emplacement).length;for(let a of e.columns){if(!a.emplacement)continue;for(let l of a.emplacement.effects)Mr(e,a.index,l);let n=a.index>0&&e.columns[a.index-1].emplacement,r=a.index<e.columns.length-1&&e.columns[a.index+1].emplacement,o=(n?1:0)+(r?1:0);if(o>0)for(let l of a.emplacement.effects){if(l.type==="damage")for(let i of a.enemies)xt(i,o);l.type==="block"&&(e.gateBlock+=o)}e.events.push({type:"emplacement_triggered",turn:e.turn,data:{column:a.index,cardId:a.emplacement.cardDefId,adjacencyBonus:o}})}t>=3&&(e.gateBlock+=t)}function xt(e,t){let a=qa(e);e.hp-=Math.max(0,Math.floor(t*a))}function Mr(e,t,a){let n=e.columns[t];switch(a.type){case"damage":{if(a.target==="column")for(let r of n.enemies)xt(r,a.value);else if(a.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)xt(o,a.value);else for(let r of n.enemies)xt(r,a.value);break}case"block":e.gateBlock+=a.value;break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+a.value);break;case"weak":for(let r of n.enemies){let o=r.statusEffects.find(l=>l.type==="weak");o?o.stacks+=a.value:r.statusEffects.push({type:"weak",stacks:a.value,duration:2})}break;case"vulnerable":for(let r of n.enemies){let o=r.statusEffects.find(l=>l.type==="vulnerable");o?o.stacks+=a.value:r.statusEffects.push({type:"vulnerable",stacks:a.value,duration:2})}break}}function Dr(e,t,a){let n=e.columns[t];if(!n.emplacement||!a.emplaceHp||!a.emplaceEffects)return!1;n.emplacement.hp+=Math.floor(a.emplaceHp/2),n.emplacement.maxHp+=Math.floor(a.emplaceHp/2);for(let r of a.emplaceEffects){let o=n.emplacement.effects.find(l=>l.type===r.type&&l.target===r.target);o?o.value+=Math.floor(r.value/2):n.emplacement.effects.push({...r,value:Math.floor(r.value/2)})}return e.events.push({type:"emplacement_placed",turn:e.turn,data:{cardId:a.id,column:t,reinforced:!0}}),!0}var za=[{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 za.find(t=>t.id===e)}function ja(e,t,a=3){let n=za.filter(l=>!t.includes(l.id)),r=[],o=[...n];for(let l=0;l<a&&o.length>0;l++){let i=Math.floor(e()*o.length);r.push(o[i]),o.splice(i,1)}return r}function dt(e,t,a,n){for(let r of t){let o=_t(r);if(!(!o||o.trigger!==a))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:i,newDrawPile:s,newDiscardPile:f}=l(e.drawPile,e.discardPile,o.effect.value,Br(e));e.hand.push(...i),e.drawPile=s,e.discardPile=f;break}case"deal_damage_all":{for(let l of e.columns)for(let i of l.enemies)i.hp-=o.effect.value;break}case"deal_damage_column":{let l=n?.column;if(l!==void 0){let i=e.columns[l];if(i)for(let s of i.enemies)s.hp-=o.effect.value}break}case"heal":{if(a==="on_card_play"){let l=n?.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 i of l.enemies)te(i,"vulnerable",o.effect.value,3);break}case"apply_weak_all":{for(let l of e.columns)for(let i of l.enemies)te(i,"weak",o.effect.value,3);break}case"burn_on_kill":{if(n?.diedFromBurn)for(let i of e.columns)for(let s of i.enemies)te(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 Br(e){return Hr(e.seed+e.turn*7+13)}function Hr(e){let t=e>>>0;return()=>{t=t+1831565813|0;let a=Math.imul(t^t>>>15,1|t);return a=a+Math.imul(a^a>>>7,61|a)^a,((a^a>>>14)>>>0)/4294967296}}function Nr(){return{drawCards(e,t,a,n){let r=[],o=[...e],l=[...t];for(let i=0;i<a;i++){if(o.length===0){if(l.length===0)break;for(let s=l.length-1;s>0;s--){let f=Math.floor(n()*(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 Gr(e){let t=0;for(let a of e){let n=_t(a);n&&n.effect.type==="emplace_hp_bonus"&&(t+=n.effect.value)}return t}function Wr(e){let t=0;for(let a of e){let n=_t(a);n&&n.effect.type==="max_resolve_bonus"&&(t+=n.effect.value)}return t}function da(e){return e.some(t=>{let a=_t(t);return a&&a.effect.type==="first_card_free"})}function Xa(e,t,a=ea,n=ea,r=[{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"needle",column:2}],o=[],l){let i=j(t),s=xr(e,i),f=Wr(o),h=(l?.reducedMaxResolve?Qt-1:Qt)+f,k=l?.reducedHandSize?it-1:it,E=Array.from({length:Xe},(M,T)=>({index:T,enemies:[],emplacement:null}));for(let M of r){let T=ia(M.templateId,M.column);l?.enemyHpMult&&l.enemyHpMult!==1&&(T.hp=Math.ceil(T.hp*l.enemyHpMult),T.maxHp=Math.ceil(T.maxHp*l.enemyHpMult)),l?.enemyBlitz&&(T.row=1),l?.enemyStartFortified&&te(T,"fortified",1,99),E[T.column].enemies.push(T)}let{drawn:I,newDrawPile:re,newDiscardPile:m}=De(s,[],k,i),g={columns:E,hand:I,drawPile:re,discardPile:m,exhaustPile:[],gateHp:a,gateMaxHp:n,gateBlock:0,resolve:h,maxResolve:h,turn:1,phase:"player",outcome:"undecided",events:[],seed:t,killsThisCombat:0,relics:o,difficulty:l};dt(g,o,"on_combat_start");for(let M of E)for(let T of M.enemies){let w=M.emplacement!==null;T.intent=ca(T,i,1,w,g)}return q(g,"turn_start",{turn:1}),g}function q(e,t,a){e.events.push({type:t,turn:e.turn,data:a}),e.events.length>100&&(e.events=e.events.slice(-100))}function Ja(e,t,a,n=!1){if(e.phase!=="player")return e;let r=e.hand[t];if(!r)return e;let o=U(r.defId);if(!o)return e;let l=!e.events.some(s=>s.type==="card_played"&&s.turn===e.turn),i=da(e.relics)&&l;if(n&&o.type==="emplace"&&o.emplaceCost!==void 0){let s=i?0:o.emplaceCost;if(s>e.resolve)return e;let f=a??0,h=Gr(e.relics);if(!(Ar(e,o,f,h)||Dr(e,f,o)))return e;e.resolve-=s,e.hand.splice(t,1),e.exhaustPile.push(r),dt(e,e.relics,"on_emplace")}else{let s=i?0:o.cost;if(s>e.resolve)return e;e.resolve-=s,e.hand.splice(t,1);let f=!1;for(let h of o.effects){if(h.type==="exhaust_self"){f=!0;continue}Za(e,h,a??0)}aa(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,q(e,"card_played",{cardId:r.defId,targetColumn:a,asEmplace:n}),na(e),e}function Za(e,t,a){switch(t.type){case"damage":{if(t.target==="all")for(let n of e.columns)for(let r of n.enemies)Ce(e,r,t.value);else if(t.target==="column"){let n=e.columns[a];if(n)for(let r of n.enemies)Ce(e,r,t.value)}else{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((o,l)=>o.row>=l.row?o:l);Ce(e,r,t.value)}}break}case"block":e.gateBlock+=t.value,q(e,"block_gained",{value:t.value});break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+t.value);break;case"draw":{let{drawn:n,newDrawPile:r,newDiscardPile:o}=De(e.drawPile,e.discardPile,t.value,j(e.seed+e.turn));e.hand.push(...n),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 n of e.columns)for(let r of n.enemies)te(r,"vulnerable",t.value,3);else if(t.target==="column"){let n=e.columns[a];if(n)for(let r of n.enemies)te(r,"vulnerable",t.value,3)}else{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((o,l)=>o.row>=l.row?o:l);te(r,"vulnerable",t.value,3)}}q(e,"status_applied",{type:"vulnerable",value:t.value,column:a});break}case"weak":{if(t.target==="all")for(let n of e.columns)for(let r of n.enemies)te(r,"weak",t.value,3);else if(t.target==="column"){let n=e.columns[a];if(n)for(let r of n.enemies)te(r,"weak",t.value,3)}else{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((o,l)=>o.row>=l.row?o:l);te(r,"weak",t.value,3)}}q(e,"status_applied",{type:"weak",value:t.value,column:a});break}case"burn":{if(t.target==="all")for(let n of e.columns)for(let r of n.enemies)te(r,"burn",t.value,99);else if(t.target==="column"){let n=e.columns[a];if(n)for(let r of n.enemies)te(r,"burn",t.value,99)}else{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((o,l)=>o.row>=l.row?o:l);te(r,"burn",t.value,99)}}break}case"self_damage":{e.gateHp-=t.value,q(e,"gate_hit",{self:!0,damage:t.value});break}case"fortify":break;case"trigger_emplacements":{Ya(e);break}case"damage_per_burn":{for(let n of e.columns)for(let r of n.enemies){let o=ge(r,"burn");o>0&&Ce(e,r,t.value*o)}break}case"damage_equal_block":{let n=e.gateBlock,r=e.columns[a];if(r&&r.enemies.length>0){let o=r.enemies.reduce((l,i)=>l.row>=i.row?l:i);Ce(e,o,n)}break}case"draw_per_kills":{let n=e.killsThisCombat*t.value;if(n>0){let{drawn:r,newDrawPile:o,newDiscardPile:l}=De(e.drawPile,e.discardPile,n,j(e.seed+e.turn+3));e.hand.push(...r),e.drawPile=o,e.discardPile=l}break}case"damage_if_vulnerable":{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((f,h)=>f.row>=h.row?f:h),l=ge(r,"vulnerable")>0?t.value*2:t.value,i=ge(r,"fortified")>0?Math.max(.25,1-ge(r,"fortified")*.15):1,s=Math.max(0,Math.floor(l*i));r.hp-=s,q(e,"damage_dealt",{targetId:r.instanceId,damage:s})}break}case"damage_per_kill_this_action":{let n=Fr(e);if(n>0){let r=t.value*n;for(let o of e.columns)for(let l of o.enemies)Ce(e,l,r)}break}case"exhaust_draw":{if(e.hand.length>0){let l=e.hand.shift();e.exhaustPile.push(l)}let{drawn:n,newDrawPile:r,newDiscardPile:o}=De(e.drawPile,e.discardPile,t.value,j(e.seed+e.turn+5));e.hand.push(...n),e.drawPile=r,e.discardPile=o;break}case"burn_if_burning":{let n=!1;for(let o of e.columns){for(let l of o.enemies)if(ge(l,"burn")>0){n=!0;break}if(n)break}let r=n?t.value+2:t.value;for(let o of e.columns)for(let l of o.enemies)te(l,"burn",r,99);break}case"damage_plus_block":{let n=Math.min(e.gateBlock,10),r=t.value+n,o=e.columns[a];if(o&&o.enemies.length>0){let l=o.enemies.reduce((i,s)=>i.row>=s.row?i:s);Ce(e,l,r)}break}case"replay_last":{if(e.lastCardPlayed&&e.lastCardPlayed!=="pale_echo"){let n=U(e.lastCardPlayed);if(n)for(let r of n.effects)r.type!=="exhaust_self"&&r.type!=="replay_last"&&Za(e,r,a)}break}case"damage_if_emplaced":{let n=e.columns[a];if(n){let r=n.emplacement?Math.floor(t.value*1.5):t.value;for(let o of n.enemies)Ce(e,o,r)}break}case"damage_if_low_hp":{let r=e.gateHp<e.gateMaxHp*.5?t.value*2:t.value,o=e.columns[a];if(o&&o.enemies.length>0){let l=o.enemies.reduce((i,s)=>i.row>=s.row?i:s);Ce(e,l,r)}break}case"damage_per_emplace":{let n=e.columns.filter(r=>r.emplacement!==null).length;if(n>0){let r=t.value*n;for(let o of e.columns)for(let l of o.enemies)Ce(e,l,r)}break}case"draw_per_empty_potions":{let{drawn:r,newDrawPile:o,newDiscardPile:l}=De(e.drawPile,e.discardPile,2,j(e.seed+e.turn+9));e.hand.push(...r),e.drawPile=o,e.discardPile=l;break}case"exhaust_self":break}}function Fr(e){let t=0;for(let a of e.columns)for(let n of a.enemies)n.hp<=0&&t++;return t}function Ce(e,t,a){let n=qa(t),r=Math.floor(a*n);t.hp-=r,q(e,"damage_dealt",{targetId:t.instanceId,damage:r})}function aa(e){for(let t of e.columns)t.enemies=t.enemies.filter(a=>{if(a.hp<=0){e.killsThisCombat++,q(e,"enemy_killed",{enemyId:a.instanceId,templateId:a.templateId});let n=ge(a,"burn")>0;return dt(e,e.relics,"on_enemy_kill",{column:t.index,diedFromBurn:n,templateId:a.templateId}),!1}return!0})}function Qa(e){return e.phase!=="player"||(q(e,"turn_end",{turn:e.turn}),e.phase="enemy",$r(e)),e}function $r(e){let t=j(e.seed+e.turn*31),a=e.columns.flatMap(i=>i.enemies.map(s=>({enemy:s,intent:s.intent??{type:"advance",value:1}})));for(let{enemy:i,intent:s}of a)i.hp<=0||Vr(e,i,s,t);if(aa(e),na(e),e.outcome!=="undecided"||(e.turn++,e.phase="player",e.resolve=e.maxResolve,e.gateBlock=0,Ya(e),aa(e),na(e),e.outcome!=="undecided"))return;dt(e,e.relics,"on_turn_start"),e.discardPile.push(...e.hand),e.hand=[];let n=e.difficulty?.reducedHandSize?it-1:it,{drawn:r,newDrawPile:o,newDiscardPile:l}=De(e.drawPile,e.discardPile,n,t);e.hand=r,e.drawPile=o,e.discardPile=l;for(let i of e.columns)for(let s of i.enemies){let f=i.emplacement!==null;s.intent=ca(s,t,e.turn,f,e)}q(e,"turn_start",{turn:e.turn})}function Vr(e,t,a,n){let r=Pe(t.templateId),o=Pr(t),l=e.difficulty?.enemyDamageMult??1;if(Rr(t),Er(t),!(t.hp<=0))switch(a.type){case"advance":{if(t.templateId==="breaker"){let i=e.columns[t.column];if(i.emplacement&&t.row>=Je-2){let s=(r?.damage??10)*2;i.emplacement.hp-=s,i.emplacement.hp<=0&&(q(e,"emplacement_destroyed",{column:t.column}),i.emplacement=null);break}}if(t.row=Math.min(Je-1,t.row+(r?.speed??1)),q(e,"enemy_advance",{enemyId:t.instanceId,row:t.row}),t.row>=Je-1)if(t.templateId==="wraith"){let i=Math.floor((r?.damage??7)*o*l),s=Math.min(e.gateBlock,i);e.gateBlock-=s,e.gateHp-=i-s,q(e,"gate_hit",{enemyId:t.instanceId,damage:i-s,blocked:s})}else{let i=e.columns[t.column];if(i.emplacement){let s=Math.floor((r?.damage??4)*o*l);i.emplacement.hp-=s,i.emplacement.hp<=0&&(q(e,"emplacement_destroyed",{column:t.column}),i.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,q(e,"gate_hit",{enemyId:t.instanceId,damage:s-f,blocked:f})}}break}case"attack":{if(t.templateId==="flanker"){let f=n()<.5?-1:1,h=t.column,k=Math.max(0,Math.min(Xe-1,t.column+f));if(k!==h){let E=e.columns[h];E.enemies=E.enemies.filter(I=>I.instanceId!==t.instanceId),t.column=k,e.columns[k].enemies.push(t)}}let i=Math.floor((r?.damage??4)*o*l),s=Math.min(e.gateBlock,i);e.gateBlock-=s,e.gateHp-=i-s,q(e,"gate_hit",{enemyId:t.instanceId,damage:i-s,blocked:s});break}case"buff":te(t,"empowered",a.value,3);break;case"debuff":{e.gateBlock=Math.max(0,e.gateBlock-a.value*2);break}case"shield":{for(let i=Math.max(0,t.column-1);i<=Math.min(Xe-1,t.column+1);i++)for(let s of e.columns[i].enemies)te(s,"fortified",a.value,2);break}case"summon":{let i=e.columns.findIndex(s=>s.enemies.length===0);if(i>=0){let s=ia("wisp",i);e.columns[i].enemies.push(s),s.intent=ca(s,j(e.seed+e.turn*97),e.turn,!1,e)}break}}}function na(e){if(e.gateHp<=0){e.gateHp=0,e.outcome="lose",e.phase="ended",q(e,"combat_end",{outcome:"lose"});return}e.columns.reduce((a,n)=>a+n.enemies.length,0)===0&&(e.outcome="win",e.phase="ended",q(e,"combat_end",{outcome:"win"}))}function It(e,t=3,a=[]){let n=new Set(["strike","guard","bolster","brace","mend",...a]),o=ct.filter(s=>!n.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=[],i=new Set;for(let s=0;s<t&&o.length>0;s++){let f=o.filter(I=>!i.has(I.card.id));if(f.length===0)break;let h=f.reduce((I,re)=>I+re.weight,0),k=e()*h,E=!1;for(let I of f)if(k-=I.weight,k<=0){l.push(I.card),i.add(I.card.id),E=!0;break}E||(l.push(f[f.length-1].card),i.add(f[f.length-1].card.id))}return l}var Lr=[{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}]}],Or=[{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}]}],Kr=[{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}]}],Ur=[{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}]}],qr=[{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}]}],Yr=[{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 en(e,t,a=!1){let n;if(a)switch(e){case 2:n=Kr;break;case 3:n=Ur;break;default:n=Or;break}else switch(e){case 2:n=qr;break;case 3:n=Yr;break;default:n=Lr;break}let r=Math.floor(t()*n.length);return{...n[r],isElite:a}}var Tt=12,Oa=4;function zr(e,t,a){if(e===0)return"combat";if(e===t-1)return"boss";let n=a();return e===Math.floor(t/2)?n<.5?"rest":"shop":n<.5?"combat":n<.65?"elite":n<.78?"event":n<.88?"rest":"shop"}function tn(e,t){let a=j(t),n=[],r=[];for(let o=0;o<Tt;o++){let l=[],i=o===0||o===Tt-1?1:Math.floor(a()*2)+2,s=new Set;for(;s.size<i;)s.add(Math.floor(a()*Oa));for(let f=0;f<Oa;f++)if(s.has(f)){let h=zr(o,Tt,a),k={id:`node-${e}-${o}-${f}`,type:h,row:o,column:f,connections:[],visited:!1};l.push(k),n.push(k)}else l.push(null);r.push(l)}for(let o=0;o<Tt-1;o++){let l=r[o].filter(s=>s!==null),i=r[o+1].filter(s=>s!==null);if(i.length!==0){for(let s of l){let f=i.map(h=>({node:h,dist:Math.abs(h.column-s.column)})).sort((h,k)=>h.dist-k.dist);s.connections.push(f[0].node.id),f.length>1&&a()<.4&&s.connections.push(f[1].node.id)}for(let s of i)!l.some(h=>h.connections.includes(s.id))&&l.length>0&&l.map(k=>({node:k,dist:Math.abs(k.column-s.column)})).sort((k,E)=>k.dist-E.dist)[0].node.connections.push(s.id)}}return{act:e,nodes:n}}function mt(e,t){return e.nodes.find(a=>a.id===t)}function an(e,t){if(!t)return e.nodes.filter(n=>n.row===0);let a=mt(e,t);return a?a.connections.map(n=>mt(e,n)).filter(n=>!!n):[]}function Ct(e,t=0){let a={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&&(a.enemyHpMult+=.2,a.enemyDamageMult+=.15),e>=3&&(a.enemyHpMult+=.3,a.enemyDamageMult+=.25),t>=1&&(a.enemyHpMult+=.1),t>=2&&(a.enemyDamageMult+=.1),t>=3&&(a.startWithCurse=!0),t>=4&&(a.healMult-=.25),t>=5&&(a.startingGateHp-=10),t>=6&&(a.enemyBlitz=!0),t>=7&&(a.extraEnemies+=1),t>=8&&(a.reducedRewards=!0),t>=9&&(a.enemyStartFortified=!0),t>=10&&(a.shopCostMult+=.25),t>=11&&(a.voidColumns=1),t>=12&&(a.paleHunger=!0),t>=13&&(a.bossExtraMinions=2),t>=14&&(a.reducedHandSize=!0),t>=15&&(a.reducedMaxResolve=!0),a}function nn(e,t=0){let a=we(e),n=tn(1,a),r=Ct(1,t),o=sa();return r.startWithCurse&&o.push(ut("pale_curse")),{id:`run-${Date.now()}-${a}`,seed:e,act:1,map:n,currentNodeId:null,deck:o,gateHp:r.startingGateHp,gateMaxHp:r.startingGateHp,fragments:0,potions:[null,null,null],relics:[],ascensionLevel:t,combat:null}}function ma(e,t){return{...e,deck:[...e.deck,t]}}function ua(e,t){return{...e,deck:e.deck.filter(a=>a.instanceId!==t)}}function rn(e,t){let a=e.map.nodes.map(n=>n.id===t?{...n,visited:!0}:n);return{...e,currentNodeId:t,map:{...e.map,nodes:a}}}function St(e,t){return{...e,gateHp:Math.min(e.gateMaxHp,e.gateHp+t)}}function on(e,t){return e.fragments<t?null:{...e,fragments:e.fragments-t}}function pt(e,t){return{...e,fragments:e.fragments+t}}function sn(e,t){let a=e.potions.indexOf(null);if(a===-1)return null;let n=[...e.potions];return n[a]=t,{...e,potions:n}}function ln(e,t){if(t<0||t>=e.potions.length)return null;let a=e.potions[t];if(!a)return null;let n=[...e.potions];return n[t]=null,{run:{...e,potions:n},potionId:a}}function pa(e){let t=e.act+1,a=we(e.seed+`-act${t}`),n=tn(t,a);return{...e,act:t,map:n,currentNodeId:null}}function cn(e){let t=[],a=ct.filter(o=>o.rarity!=="common"||o.id==="slash"||o.id==="flare"),n=new Set;for(let o=0;o<5&&n.size<5;o++){let l=a[Math.floor(e()*a.length)];if(n.has(l.id)){o--;continue}n.add(l.id);let i=l.rarity==="rare"?75:l.rarity==="uncommon"?50:30;t.push({type:"card",cardDef:l,cost:i})}let r=Ze[Math.floor(e()*Ze.length)];return t.push({type:"potion",potionDef:r,cost:25}),t.push({type:"card_remove",cost:50}),t}var jr=[{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"}}]}],Xr=[{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"}}]}],Jr=[{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"}}]}],Zr=[{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"}}]}],ta=[{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"}}]}],Qr=[{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 dn(e,t,a){let n;switch(e){case 2:n=Xr;break;case 3:n=Qr;break;default:n=jr;break}let r=a==="cracks"||a==="truth"||a==="true_ending";if((a==="truth"||a==="true_ending")&&e===3&&ta.length>0&&t()<.4)return ta[Math.floor(t()*ta.length)];if(r){let l=null;if(e===1?l=Jr:e===2&&(l=Zr),l&&l.length>0&&t()<.4)return l[Math.floor(t()*l.length)]}return n[Math.floor(t()*n.length)]}var Qe=[{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 et(e,t){return e.structures[t]??0}function mn(e,t){let a=Qe.find(o=>o.id===t);if(!a)return null;let n=et(e,t);if(n>=a.maxLevel)return null;let r=a.upgradeCost(n+1);return e.echoes<r?null:{...e,echoes:e.echoes-r,structures:{...e.structures,[t]:n+1}}}function fa(){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 ha(e,t,a){return(e?10+t*5:3)+Math.floor(a*.5)}function un(e,t){return t>=15?"true_ending":e>=30?"truth":e>=15?"cracks":"surface"}function pn(e,t){let a=t.npcs.find(r=>r.id===e);if(!a)return null;let n=La(e,a.tier,a.dialoguesSeen);return n.length===0?null:{speaker:n[0].speaker,text:n[0].text,dialogueId:n[0].id}}function fn(e,t,a){let n=e.npcs.findIndex(l=>l.id===t);if(n===-1)return e;let r=[...e.npcs],o={...r[n]};return o.dialoguesSeen=[...o.dialoguesSeen,a],r[n]=o,{...e,npcs:r}}var oa=2;function so(){return hn(oo(),".config","codekeep")}function ya(){return hn(so(),"game.json")}function lo(){return{structures:{},npcs:[],echoes:0,highestAscension:0,totalRuns:0,totalWins:0,unlockedCardIds:[],achievements:[],narrativeFlags:[]}}function gn(e){return{schemaVersion:oa,savedAtUnixMs:Date.now(),playerName:e,keep:lo(),activeRun:null}}function Se(e){let t=ya(),a=ro(t);ga(a)||to(a,{recursive:!0});let n=t+".tmp",r=JSON.stringify({...e,savedAtUnixMs:Date.now()},null,2);ra(n,r,"utf-8"),ao(n,t)}function tt(){let e=ya();if(!ga(e))return null;let t;try{t=eo(e,"utf-8")}catch{return null}let a;try{a=JSON.parse(t)}catch{let n=e+".bak";try{ra(n,t,"utf-8")}catch{}return process.stderr.write(`[codekeep] Corrupted save backed up to ${n}
3
- `),null}if(a.schemaVersion!==oa){let n=e+`.v${a.schemaVersion}.bak`;try{ra(n,t,"utf-8")}catch{}return process.stderr.write(`[codekeep] Save version mismatch (got ${a.schemaVersion}, need ${oa}), backed up to ${n}
4
- `),null}return a}function yn(){let e=ya();if(!ga(e))return!1;try{return no(e),!0}catch{return!1}}import po from"react";import{Box as fo,Text as Q}from"ink";import{writeFileSync as io,mkdirSync as co,existsSync as mo}from"fs";import{join as wn}from"path";import{homedir as uo}from"os";var wa=wn(uo(),".config","codekeep","crashes");function bn(e,t){if((e instanceof Error?e.message:String(e)).includes("Raw mode is not supported"))return"";mo(wa)||co(wa,{recursive:!0});let n={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=wn(wa,r);return io(o,JSON.stringify(n,null,2),"utf-8"),o}function vn(e){let t=encodeURIComponent(`[Crash]: ${e.error.slice(0,80)}`),a=encodeURIComponent(`## Crash Report
2
+ import{Command as Zo}from"commander";import{render as es}from"ink";import{useState as M,useCallback as _e,useEffect as Yo}from"react";import{Box as we,Text as g,useApp as zo,useInput as jo,useStdout as Xo}from"ink";var Qe=5,Ze=4,ta=3,dt=5,aa=70,mt=[{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:[]}],Oa=["strike","strike","strike","guard","guard","spark","ember","brace","bolster","mend"];function Y(e){return mt.find(t=>t.id===e)}var vr=[{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 Be(e){return vr.find(t=>t.id===e)}var et=[{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},kr=[{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 xr(e,t){return kr.filter(n=>n.npcId===e&&n.tier<=t).flatMap(n=>n.lines)}function Ka(e,t,a){let n=xr(e,t),r=new Set(a);return n.filter(o=>!r.has(o.id))}import{writeFileSync as sa,readFileSync as to,mkdirSync as ao,existsSync as ba,renameSync as no,unlinkSync as ro}from"fs";import{join as yn,dirname as oo}from"path";import{homedir as so}from"os";function Q(e){let t=e|0;return()=>{t=t+1831565813|0;let a=Math.imul(t^t>>>15,1|t);return a=a+Math.imul(a^a>>>7,61|a)^a,((a^a>>>14)>>>0)/4294967296}}function ve(e){let t=0;for(let a=0;a<e.length;a++){let n=e.charCodeAt(a);t=(t<<5)-t+n|0}return t}function qa(e,t){let a=[...e];for(let n=a.length-1;n>0;n--){let r=Math.floor(t()*(n+1));[a[n],a[r]]=[a[r],a[n]]}return a}var Tr=1;function ft(e){return{instanceId:`card-${Tr++}`,defId:e,upgraded:!1}}function ia(){return Oa.map(ft)}function _r(e,t){return qa(e,t)}function Ne(e,t,a,n){let r=[],o=[...e],l=[...t];for(let i=0;i<a;i++){if(o.length===0){if(l.length===0)break;o=qa(l,n),l=[]}r.push(o.shift())}return{drawn:r,newDrawPile:o,newDiscardPile:l}}var Ir=[{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,a)=>{let n=e.columns[2];n.enemies.length<3&&n.enemies.push(da("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,a)=>{if(a>=2)for(let n of e.columns)for(let r of n.enemies){let o=r.statusEffects.find(l=>l.type==="empowered");o?o.stacks+=1:r.statusEffects.push({type:"empowered",stacks:1,duration:99})}}}];function ca(e){return Ir.find(t=>t.act===e)}function Cr(e,t){let a=0;for(let n=0;n<e.phases.length;n++)t<=e.phases[n].hpThreshold&&(a=n);return a}function Sr(e,t,a,n,r){let o=Cr(e,t);if(e.onPhaseChange&&n&&r){let s=r.bossPhase??0;o>s&&(e.onPhaseChange(n,r,o),r.bossPhase=o)}let l=e.phases[o],i=(a-1)%l.intentPattern.length;return l.intentPattern[i]}function Ya(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 Er=1;function da(e,t){let a=Be(e);if(!a)throw new Error(`Unknown enemy template: ${e}`);return{instanceId:`enemy-${Er++}`,templateId:e,hp:a.hp,maxHp:a.hp,column:Math.max(0,Math.min(t,Qe-1)),row:0,intent:null,statusEffects:[]}}function ma(e,t,a=1,n=!1,r){let o=Be(e.templateId);if(!o)return{type:"advance",value:1};let l=ca(o.act);if(l&&l.templateId===e.templateId){let s=e.hp/e.maxHp;return Sr(l,s,a,r,e)}let i=t();switch(e.templateId){case"shielder":return i<.3?{type:"shield",value:5}:i<.6?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column};case"flanker":return i<.4?{type:"attack",value:o.damage,targetColumn:e.column}:i<.7?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column};case"breaker":return n?{type:"advance",value:o.speed}:i<.6?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column};case"wraith":return i<.4?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column};case"echo":return i<.3?{type:"buff",value:1}:i<.6?{type:"attack",value:o.damage,targetColumn:e.column}:{type:"advance",value:o.speed};default:return i<.5?{type:"advance",value:o.speed}:{type:"attack",value:o.damage,targetColumn:e.column}}}function Pr(e){e.statusEffects=e.statusEffects.map(t=>({...t,duration:t.duration-1})).filter(t=>t.duration>0&&t.stacks>0)}function re(e,t,a,n=2){let r=e.statusEffects.find(o=>o.type===t);r?(r.stacks+=a,r.duration=Math.max(r.duration,n)):e.statusEffects.push({type:t,stacks:a,duration:n})}function be(e,t){return e.statusEffects.find(n=>n.type===t)?.stacks??0}function za(e){let t=1,a=be(e,"vulnerable");a>0&&(t*=1+a*.25);let n=be(e,"fortified");return n>0&&(t*=Math.max(.25,1-n*.15)),t}function Rr(e){let t=1,a=be(e,"weak");return a>0&&(t*=Math.max(.25,1-a*.15)),be(e,"empowered")>0&&(t*=1+be(e,"empowered")*.25),t}function Ar(e){let t=be(e,"burn");if(t>0){e.hp-=t;let a=e.statusEffects.find(n=>n.type==="burn");return a&&(a.stacks=Math.max(0,a.stacks-1)),t}return 0}function Mr(e,t,a,n=0){if(a<0||a>=e.columns.length||e.columns[a].emplacement||!t.emplaceHp||!t.emplaceEffects)return!1;let r=t.emplaceHp+n;return e.columns[a].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:a}}),!0}function ja(e){let t=e.columns.filter(a=>a.emplacement).length;for(let a of e.columns){if(!a.emplacement)continue;for(let l of a.emplacement.effects)Dr(e,a.index,l);let n=a.index>0&&e.columns[a.index-1].emplacement,r=a.index<e.columns.length-1&&e.columns[a.index+1].emplacement,o=(n?1:0)+(r?1:0);if(o>0)for(let l of a.emplacement.effects){if(l.type==="damage")for(let i of a.enemies)It(i,o);l.type==="block"&&(e.gateBlock+=o)}e.events.push({type:"emplacement_triggered",turn:e.turn,data:{column:a.index,cardId:a.emplacement.cardDefId,adjacencyBonus:o}})}t>=3&&(e.gateBlock+=t)}function It(e,t){let a=za(e);e.hp-=Math.max(0,Math.floor(t*a))}function Dr(e,t,a){let n=e.columns[t];switch(a.type){case"damage":{if(a.target==="column")for(let r of n.enemies)It(r,a.value);else if(a.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)It(o,a.value);else for(let r of n.enemies)It(r,a.value);break}case"block":e.gateBlock+=a.value;break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+a.value);break;case"weak":for(let r of n.enemies){let o=r.statusEffects.find(l=>l.type==="weak");o?o.stacks+=a.value:r.statusEffects.push({type:"weak",stacks:a.value,duration:2})}break;case"vulnerable":for(let r of n.enemies){let o=r.statusEffects.find(l=>l.type==="vulnerable");o?o.stacks+=a.value:r.statusEffects.push({type:"vulnerable",stacks:a.value,duration:2})}break}}function Br(e,t,a){let n=e.columns[t];if(!n.emplacement||!a.emplaceHp||!a.emplaceEffects)return!1;n.emplacement.hp+=Math.floor(a.emplaceHp/2),n.emplacement.maxHp+=Math.floor(a.emplaceHp/2);for(let r of a.emplaceEffects){let o=n.emplacement.effects.find(l=>l.type===r.type&&l.target===r.target);o?o.value+=Math.floor(r.value/2):n.emplacement.effects.push({...r,value:Math.floor(r.value/2)})}return e.events.push({type:"emplacement_placed",turn:e.turn,data:{cardId:a.id,column:t,reinforced:!0}}),!0}var Xa=[{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 Ct(e){return Xa.find(t=>t.id===e)}function Ja(e,t,a=3){let n=Xa.filter(l=>!t.includes(l.id)),r=[],o=[...n];for(let l=0;l<a&&o.length>0;l++){let i=Math.floor(e()*o.length);r.push(o[i]),o.splice(i,1)}return r}function ut(e,t,a,n){for(let r of t){let o=Ct(r);if(!(!o||o.trigger!==a))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}=Gr(),{drawn:i,newDrawPile:s,newDiscardPile:f}=l(e.drawPile,e.discardPile,o.effect.value,Hr(e));e.hand.push(...i),e.drawPile=s,e.discardPile=f;break}case"deal_damage_all":{for(let l of e.columns)for(let i of l.enemies)i.hp-=o.effect.value;break}case"deal_damage_column":{let l=n?.column;if(l!==void 0){let i=e.columns[l];if(i)for(let s of i.enemies)s.hp-=o.effect.value}break}case"heal":{if(a==="on_card_play"){let l=n?.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 i of l.enemies)re(i,"vulnerable",o.effect.value,3);break}case"apply_weak_all":{for(let l of e.columns)for(let i of l.enemies)re(i,"weak",o.effect.value,3);break}case"burn_on_kill":{if(n?.diedFromBurn)for(let i of e.columns)for(let s of i.enemies)re(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 Hr(e){return Nr(e.seed+e.turn*7+13)}function Nr(e){let t=e>>>0;return()=>{t=t+1831565813|0;let a=Math.imul(t^t>>>15,1|t);return a=a+Math.imul(a^a>>>7,61|a)^a,((a^a>>>14)>>>0)/4294967296}}function Gr(){return{drawCards(e,t,a,n){let r=[],o=[...e],l=[...t];for(let i=0;i<a;i++){if(o.length===0){if(l.length===0)break;for(let s=l.length-1;s>0;s--){let f=Math.floor(n()*(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 Wr(e){let t=0;for(let a of e){let n=Ct(a);n&&n.effect.type==="emplace_hp_bonus"&&(t+=n.effect.value)}return t}function Fr(e){let t=0;for(let a of e){let n=Ct(a);n&&n.effect.type==="max_resolve_bonus"&&(t+=n.effect.value)}return t}function ua(e){return e.some(t=>{let a=Ct(t);return a&&a.effect.type==="first_card_free"})}function Qa(e,t,a=aa,n=aa,r=[{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"needle",column:2}],o=[],l){let i=Q(t),s=_r(e,i),f=Fr(o),y=(l?.reducedMaxResolve?ta-1:ta)+f,k=l?.reducedHandSize?dt-1:dt,E=Array.from({length:Qe},(B,T)=>({index:T,enemies:[],emplacement:null}));for(let B of r){let T=da(B.templateId,B.column);l?.enemyHpMult&&l.enemyHpMult!==1&&(T.hp=Math.ceil(T.hp*l.enemyHpMult),T.maxHp=Math.ceil(T.maxHp*l.enemyHpMult)),l?.enemyBlitz&&(T.row=1),l?.enemyStartFortified&&re(T,"fortified",1,99),E[T.column].enemies.push(T)}let{drawn:S,newDrawPile:D,newDiscardPile:m}=Ne(s,[],k,i),h={columns:E,hand:S,drawPile:D,discardPile:m,exhaustPile:[],gateHp:a,gateMaxHp:n,gateBlock:0,resolve:y,maxResolve:y,turn:1,phase:"player",outcome:"undecided",events:[],seed:t,killsThisCombat:0,relics:o,difficulty:l};ut(h,o,"on_combat_start");for(let B of E)for(let T of B.enemies){let G=B.emplacement!==null;T.intent=ma(T,i,1,G,h)}return z(h,"turn_start",{turn:1}),h}function z(e,t,a){e.events.push({type:t,turn:e.turn,data:a}),e.events.length>100&&(e.events=e.events.slice(-100))}function Za(e,t,a,n=!1){if(e.phase!=="player")return e;let r=e.hand[t];if(!r)return e;let o=Y(r.defId);if(!o)return e;let l=!e.events.some(s=>s.type==="card_played"&&s.turn===e.turn),i=ua(e.relics)&&l;if(n&&o.type==="emplace"&&o.emplaceCost!==void 0){let s=i?0:o.emplaceCost;if(s>e.resolve)return e;let f=a??0,y=Wr(e.relics);if(!(Mr(e,o,f,y)||Br(e,f,o)))return e;e.resolve-=s,e.hand.splice(t,1),e.exhaustPile.push(r),ut(e,e.relics,"on_emplace")}else{let s=i?0:o.cost;if(s>e.resolve)return e;e.resolve-=s,e.hand.splice(t,1);let f=!1;for(let y of o.effects){if(y.type==="exhaust_self"){f=!0;continue}en(e,y,a??0)}ra(e),f?e.exhaustPile.push(r):e.discardPile.push(r),ut(e,e.relics,"on_card_play",{cardCost:o.cost,cardId:o.id})}return e.lastCardPlayed=r.defId,z(e,"card_played",{cardId:r.defId,targetColumn:a,asEmplace:n}),oa(e),e}function en(e,t,a){switch(t.type){case"damage":{if(t.target==="all")for(let n of e.columns)for(let r of n.enemies)Pe(e,r,t.value);else if(t.target==="column"){let n=e.columns[a];if(n)for(let r of n.enemies)Pe(e,r,t.value)}else{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((o,l)=>o.row>=l.row?o:l);Pe(e,r,t.value)}}break}case"block":e.gateBlock+=t.value,z(e,"block_gained",{value:t.value});break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+t.value);break;case"draw":{let{drawn:n,newDrawPile:r,newDiscardPile:o}=Ne(e.drawPile,e.discardPile,t.value,Q(e.seed+e.turn));e.hand.push(...n),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 n of e.columns)for(let r of n.enemies)re(r,"vulnerable",t.value,3);else if(t.target==="column"){let n=e.columns[a];if(n)for(let r of n.enemies)re(r,"vulnerable",t.value,3)}else{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((o,l)=>o.row>=l.row?o:l);re(r,"vulnerable",t.value,3)}}z(e,"status_applied",{type:"vulnerable",value:t.value,column:a});break}case"weak":{if(t.target==="all")for(let n of e.columns)for(let r of n.enemies)re(r,"weak",t.value,3);else if(t.target==="column"){let n=e.columns[a];if(n)for(let r of n.enemies)re(r,"weak",t.value,3)}else{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((o,l)=>o.row>=l.row?o:l);re(r,"weak",t.value,3)}}z(e,"status_applied",{type:"weak",value:t.value,column:a});break}case"burn":{if(t.target==="all")for(let n of e.columns)for(let r of n.enemies)re(r,"burn",t.value,99);else if(t.target==="column"){let n=e.columns[a];if(n)for(let r of n.enemies)re(r,"burn",t.value,99)}else{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((o,l)=>o.row>=l.row?o:l);re(r,"burn",t.value,99)}}break}case"self_damage":{e.gateHp-=t.value,z(e,"gate_hit",{self:!0,damage:t.value});break}case"fortify":break;case"trigger_emplacements":{ja(e);break}case"damage_per_burn":{for(let n of e.columns)for(let r of n.enemies){let o=be(r,"burn");o>0&&Pe(e,r,t.value*o)}break}case"damage_equal_block":{let n=e.gateBlock,r=e.columns[a];if(r&&r.enemies.length>0){let o=r.enemies.reduce((l,i)=>l.row>=i.row?l:i);Pe(e,o,n)}break}case"draw_per_kills":{let n=e.killsThisCombat*t.value;if(n>0){let{drawn:r,newDrawPile:o,newDiscardPile:l}=Ne(e.drawPile,e.discardPile,n,Q(e.seed+e.turn+3));e.hand.push(...r),e.drawPile=o,e.discardPile=l}break}case"damage_if_vulnerable":{let n=e.columns[a];if(n&&n.enemies.length>0){let r=n.enemies.reduce((f,y)=>f.row>=y.row?f:y),l=be(r,"vulnerable")>0?t.value*2:t.value,i=be(r,"fortified")>0?Math.max(.25,1-be(r,"fortified")*.15):1,s=Math.max(0,Math.floor(l*i));r.hp-=s,z(e,"damage_dealt",{targetId:r.instanceId,damage:s})}break}case"damage_per_kill_this_action":{let n=$r(e);if(n>0){let r=t.value*n;for(let o of e.columns)for(let l of o.enemies)Pe(e,l,r)}break}case"exhaust_draw":{if(e.hand.length>0){let l=e.hand.shift();e.exhaustPile.push(l)}let{drawn:n,newDrawPile:r,newDiscardPile:o}=Ne(e.drawPile,e.discardPile,t.value,Q(e.seed+e.turn+5));e.hand.push(...n),e.drawPile=r,e.discardPile=o;break}case"burn_if_burning":{let n=!1;for(let o of e.columns){for(let l of o.enemies)if(be(l,"burn")>0){n=!0;break}if(n)break}let r=n?t.value+2:t.value;for(let o of e.columns)for(let l of o.enemies)re(l,"burn",r,99);break}case"damage_plus_block":{let n=Math.min(e.gateBlock,10),r=t.value+n,o=e.columns[a];if(o&&o.enemies.length>0){let l=o.enemies.reduce((i,s)=>i.row>=s.row?i:s);Pe(e,l,r)}break}case"replay_last":{if(e.lastCardPlayed&&e.lastCardPlayed!=="pale_echo"){let n=Y(e.lastCardPlayed);if(n)for(let r of n.effects)r.type!=="exhaust_self"&&r.type!=="replay_last"&&en(e,r,a)}break}case"damage_if_emplaced":{let n=e.columns[a];if(n){let r=n.emplacement?Math.floor(t.value*1.5):t.value;for(let o of n.enemies)Pe(e,o,r)}break}case"damage_if_low_hp":{let r=e.gateHp<e.gateMaxHp*.5?t.value*2:t.value,o=e.columns[a];if(o&&o.enemies.length>0){let l=o.enemies.reduce((i,s)=>i.row>=s.row?i:s);Pe(e,l,r)}break}case"damage_per_emplace":{let n=e.columns.filter(r=>r.emplacement!==null).length;if(n>0){let r=t.value*n;for(let o of e.columns)for(let l of o.enemies)Pe(e,l,r)}break}case"draw_per_empty_potions":{let{drawn:r,newDrawPile:o,newDiscardPile:l}=Ne(e.drawPile,e.discardPile,2,Q(e.seed+e.turn+9));e.hand.push(...r),e.drawPile=o,e.discardPile=l;break}case"exhaust_self":break}}function $r(e){let t=0;for(let a of e.columns)for(let n of a.enemies)n.hp<=0&&t++;return t}function Pe(e,t,a){let n=za(t),r=Math.floor(a*n);t.hp-=r,z(e,"damage_dealt",{targetId:t.instanceId,damage:r})}function ra(e){for(let t of e.columns)t.enemies=t.enemies.filter(a=>{if(a.hp<=0){e.killsThisCombat++,z(e,"enemy_killed",{enemyId:a.instanceId,templateId:a.templateId});let n=be(a,"burn")>0;return ut(e,e.relics,"on_enemy_kill",{column:t.index,diedFromBurn:n,templateId:a.templateId}),!1}return!0})}function tn(e){return e.phase!=="player"||(z(e,"turn_end",{turn:e.turn}),e.phase="enemy",Vr(e)),e}function Vr(e){let t=Q(e.seed+e.turn*31),a=e.columns.flatMap(i=>i.enemies.map(s=>({enemy:s,intent:s.intent??{type:"advance",value:1}})));for(let{enemy:i,intent:s}of a)i.hp<=0||Lr(e,i,s,t);if(ra(e),oa(e),e.outcome!=="undecided"||(e.turn++,e.phase="player",e.resolve=e.maxResolve,e.gateBlock=0,ja(e),ra(e),oa(e),e.outcome!=="undecided"))return;ut(e,e.relics,"on_turn_start"),e.discardPile.push(...e.hand),e.hand=[];let n=e.difficulty?.reducedHandSize?dt-1:dt,{drawn:r,newDrawPile:o,newDiscardPile:l}=Ne(e.drawPile,e.discardPile,n,t);e.hand=r,e.drawPile=o,e.discardPile=l;for(let i of e.columns)for(let s of i.enemies){let f=i.emplacement!==null;s.intent=ma(s,t,e.turn,f,e)}z(e,"turn_start",{turn:e.turn})}function Lr(e,t,a,n){let r=Be(t.templateId),o=Rr(t),l=e.difficulty?.enemyDamageMult??1;if(Ar(t),Pr(t),!(t.hp<=0))switch(a.type){case"advance":{if(t.templateId==="breaker"){let i=e.columns[t.column];if(i.emplacement&&t.row>=Ze-2){let s=(r?.damage??10)*2;i.emplacement.hp-=s,i.emplacement.hp<=0&&(z(e,"emplacement_destroyed",{column:t.column}),i.emplacement=null);break}}if(t.row=Math.min(Ze-1,t.row+(r?.speed??1)),z(e,"enemy_advance",{enemyId:t.instanceId,row:t.row}),t.row>=Ze-1)if(t.templateId==="wraith"){let i=Math.floor((r?.damage??7)*o*l),s=Math.min(e.gateBlock,i);e.gateBlock-=s,e.gateHp-=i-s,z(e,"gate_hit",{enemyId:t.instanceId,damage:i-s,blocked:s})}else{let i=e.columns[t.column];if(i.emplacement){let s=Math.floor((r?.damage??4)*o*l);i.emplacement.hp-=s,i.emplacement.hp<=0&&(z(e,"emplacement_destroyed",{column:t.column}),i.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,z(e,"gate_hit",{enemyId:t.instanceId,damage:s-f,blocked:f})}}break}case"attack":{if(t.templateId==="flanker"){let f=n()<.5?-1:1,y=t.column,k=Math.max(0,Math.min(Qe-1,t.column+f));if(k!==y){let E=e.columns[y];E.enemies=E.enemies.filter(S=>S.instanceId!==t.instanceId),t.column=k,e.columns[k].enemies.push(t)}}let i=Math.floor((r?.damage??4)*o*l),s=Math.min(e.gateBlock,i);e.gateBlock-=s,e.gateHp-=i-s,z(e,"gate_hit",{enemyId:t.instanceId,damage:i-s,blocked:s});break}case"buff":re(t,"empowered",a.value,3);break;case"debuff":{e.gateBlock=Math.max(0,e.gateBlock-a.value*2);break}case"shield":{for(let i=Math.max(0,t.column-1);i<=Math.min(Qe-1,t.column+1);i++)for(let s of e.columns[i].enemies)re(s,"fortified",a.value,2);break}case"summon":{let i=e.columns.findIndex(s=>s.enemies.length===0);if(i>=0){let s=da("wisp",i);e.columns[i].enemies.push(s),s.intent=ma(s,Q(e.seed+e.turn*97),e.turn,!1,e)}break}}}function oa(e){if(e.gateHp<=0){e.gateHp=0,e.outcome="lose",e.phase="ended",z(e,"combat_end",{outcome:"lose"});return}e.columns.reduce((a,n)=>a+n.enemies.length,0)===0&&(e.outcome="win",e.phase="ended",z(e,"combat_end",{outcome:"win"}))}function St(e,t=3,a=[]){let n=new Set(["strike","guard","bolster","brace","mend",...a]),o=mt.filter(s=>!n.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=[],i=new Set;for(let s=0;s<t&&o.length>0;s++){let f=o.filter(S=>!i.has(S.card.id));if(f.length===0)break;let y=f.reduce((S,D)=>S+D.weight,0),k=e()*y,E=!1;for(let S of f)if(k-=S.weight,k<=0){l.push(S.card),i.add(S.card.id),E=!0;break}E||(l.push(f[f.length-1].card),i.add(f[f.length-1].card.id))}return l}var Or=[{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}]}],Kr=[{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}]}],qr=[{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}]}],Yr=[{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}]}],zr=[{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 an(e,t,a=!1){let n;if(a)switch(e){case 2:n=Ur;break;case 3:n=qr;break;default:n=Kr;break}else switch(e){case 2:n=Yr;break;case 3:n=zr;break;default:n=Or;break}let r=Math.floor(t()*n.length);return{...n[r],isElite:a}}var _t=12,Ua=4;function jr(e,t,a){if(e===0)return"combat";if(e===t-1)return"boss";let n=a();return e===Math.floor(t/2)?n<.5?"rest":"shop":n<.5?"combat":n<.65?"elite":n<.78?"event":n<.88?"rest":"shop"}function nn(e,t){let a=Q(t),n=[],r=[];for(let o=0;o<_t;o++){let l=[],i=o===0||o===_t-1?1:Math.floor(a()*2)+2,s=new Set;for(;s.size<i;)s.add(Math.floor(a()*Ua));for(let f=0;f<Ua;f++)if(s.has(f)){let y=jr(o,_t,a),k={id:`node-${e}-${o}-${f}`,type:y,row:o,column:f,connections:[],visited:!1};l.push(k),n.push(k)}else l.push(null);r.push(l)}for(let o=0;o<_t-1;o++){let l=r[o].filter(s=>s!==null),i=r[o+1].filter(s=>s!==null);if(i.length!==0){for(let s of l){let f=i.map(y=>({node:y,dist:Math.abs(y.column-s.column)})).sort((y,k)=>y.dist-k.dist);s.connections.push(f[0].node.id),f.length>1&&a()<.4&&s.connections.push(f[1].node.id)}for(let s of i)!l.some(y=>y.connections.includes(s.id))&&l.length>0&&l.map(k=>({node:k,dist:Math.abs(k.column-s.column)})).sort((k,E)=>k.dist-E.dist)[0].node.connections.push(s.id)}}return{act:e,nodes:n}}function pt(e,t){return e.nodes.find(a=>a.id===t)}function rn(e,t){if(!t)return e.nodes.filter(n=>n.row===0);let a=pt(e,t);return a?a.connections.map(n=>pt(e,n)).filter(n=>!!n):[]}function Et(e,t=0){let a={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&&(a.enemyHpMult+=.2,a.enemyDamageMult+=.15),e>=3&&(a.enemyHpMult+=.3,a.enemyDamageMult+=.25),t>=1&&(a.enemyHpMult+=.1),t>=2&&(a.enemyDamageMult+=.1),t>=3&&(a.startWithCurse=!0),t>=4&&(a.healMult-=.25),t>=5&&(a.startingGateHp-=10),t>=6&&(a.enemyBlitz=!0),t>=7&&(a.extraEnemies+=1),t>=8&&(a.reducedRewards=!0),t>=9&&(a.enemyStartFortified=!0),t>=10&&(a.shopCostMult+=.25),t>=11&&(a.voidColumns=1),t>=12&&(a.paleHunger=!0),t>=13&&(a.bossExtraMinions=2),t>=14&&(a.reducedHandSize=!0),t>=15&&(a.reducedMaxResolve=!0),a}function on(e,t=0){let a=ve(e),n=nn(1,a),r=Et(1,t),o=ia();return r.startWithCurse&&o.push(ft("pale_curse")),{id:`run-${Date.now()}-${a}`,seed:e,act:1,map:n,currentNodeId:null,deck:o,gateHp:r.startingGateHp,gateMaxHp:r.startingGateHp,fragments:0,potions:[null,null,null],relics:[],ascensionLevel:t,combat:null}}function pa(e,t){return{...e,deck:[...e.deck,t]}}function fa(e,t){return{...e,deck:e.deck.filter(a=>a.instanceId!==t)}}function sn(e,t){let a=e.map.nodes.map(n=>n.id===t?{...n,visited:!0}:n);return{...e,currentNodeId:t,map:{...e.map,nodes:a}}}function Pt(e,t){return{...e,gateHp:Math.min(e.gateMaxHp,e.gateHp+t)}}function ln(e,t){return e.fragments<t?null:{...e,fragments:e.fragments-t}}function ht(e,t){return{...e,fragments:e.fragments+t}}function cn(e,t){let a=e.potions.indexOf(null);if(a===-1)return null;let n=[...e.potions];return n[a]=t,{...e,potions:n}}function dn(e,t){if(t<0||t>=e.potions.length)return null;let a=e.potions[t];if(!a)return null;let n=[...e.potions];return n[t]=null,{run:{...e,potions:n},potionId:a}}function ha(e){let t=e.act+1,a=ve(e.seed+`-act${t}`),n=nn(t,a);return{...e,act:t,map:n,currentNodeId:null}}function mn(e){let t=[],a=mt.filter(o=>o.rarity!=="common"||o.id==="slash"||o.id==="flare"),n=new Set;for(let o=0;o<5&&n.size<5;o++){let l=a[Math.floor(e()*a.length)];if(n.has(l.id)){o--;continue}n.add(l.id);let i=l.rarity==="rare"?75:l.rarity==="uncommon"?50:30;t.push({type:"card",cardDef:l,cost:i})}let r=et[Math.floor(e()*et.length)];return t.push({type:"potion",potionDef:r,cost:25}),t.push({type:"card_remove",cost:50}),t}var Xr=[{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"}}]}],Jr=[{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"}}]}],Qr=[{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"}}]}],Zr=[{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"}}]}],na=[{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"}}]}],eo=[{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 un(e,t,a){let n;switch(e){case 2:n=Jr;break;case 3:n=eo;break;default:n=Xr;break}let r=a==="cracks"||a==="truth"||a==="true_ending";if((a==="truth"||a==="true_ending")&&e===3&&na.length>0&&t()<.4)return na[Math.floor(t()*na.length)];if(r){let l=null;if(e===1?l=Qr:e===2&&(l=Zr),l&&l.length>0&&t()<.4)return l[Math.floor(t()*l.length)]}return n[Math.floor(t()*n.length)]}var tt=[{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 at(e,t){return e.structures[t]??0}function pn(e,t){let a=tt.find(o=>o.id===t);if(!a)return null;let n=at(e,t);if(n>=a.maxLevel)return null;let r=a.upgradeCost(n+1);return e.echoes<r?null:{...e,echoes:e.echoes-r,structures:{...e.structures,[t]:n+1}}}function ga(){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 ya(e,t,a){return(e?10+t*5:3)+Math.floor(a*.5)}function fn(e,t){return t>=15?"true_ending":e>=30?"truth":e>=15?"cracks":"surface"}function hn(e,t){let a=t.npcs.find(r=>r.id===e);if(!a)return null;let n=Ka(e,a.tier,a.dialoguesSeen);return n.length===0?null:{speaker:n[0].speaker,text:n[0].text,dialogueId:n[0].id}}function gn(e,t,a){let n=e.npcs.findIndex(l=>l.id===t);if(n===-1)return e;let r=[...e.npcs],o={...r[n]};return o.dialoguesSeen=[...o.dialoguesSeen,a],r[n]=o,{...e,npcs:r}}var la=2;function lo(){return yn(so(),".config","codekeep")}function wa(){return yn(lo(),"game.json")}function io(){return{structures:{},npcs:[],echoes:0,highestAscension:0,totalRuns:0,totalWins:0,unlockedCardIds:[],achievements:[],narrativeFlags:[]}}function bn(e){return{schemaVersion:la,savedAtUnixMs:Date.now(),playerName:e,keep:io(),activeRun:null}}function Re(e){let t=wa(),a=oo(t);ba(a)||ao(a,{recursive:!0});let n=t+".tmp",r=JSON.stringify({...e,savedAtUnixMs:Date.now()},null,2);sa(n,r,"utf-8"),no(n,t)}function nt(){let e=wa();if(!ba(e))return null;let t;try{t=to(e,"utf-8")}catch{return null}let a;try{a=JSON.parse(t)}catch{let n=e+".bak";try{sa(n,t,"utf-8")}catch{}return process.stderr.write(`[codekeep] Corrupted save backed up to ${n}
3
+ `),null}if(a.schemaVersion!==la){let n=e+`.v${a.schemaVersion}.bak`;try{sa(n,t,"utf-8")}catch{}return process.stderr.write(`[codekeep] Save version mismatch (got ${a.schemaVersion}, need ${la}), backed up to ${n}
4
+ `),null}return a}function wn(){let e=wa();if(!ba(e))return!1;try{return ro(e),!0}catch{return!1}}import fo from"react";import{Box as ho,Text as ae}from"ink";import{writeFileSync as co,mkdirSync as mo,existsSync as uo}from"fs";import{join as vn}from"path";import{homedir as po}from"os";var va=vn(po(),".config","codekeep","crashes");function kn(e,t){if((e instanceof Error?e.message:String(e)).includes("Raw mode is not supported"))return"";uo(va)||mo(va,{recursive:!0});let n={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=vn(va,r);return co(o,JSON.stringify(n,null,2),"utf-8"),o}function xn(e){let t=encodeURIComponent(`[Crash]: ${e.error.slice(0,80)}`),a=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=${a}&labels=bug,crash`}import{Fragment as kn,jsx as ue,jsxs as $e}from"react/jsx-runtime";var Et=class extends po.Component{constructor(t){super(t),this.state={error:null,crashFilePath:null,issueUrl:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){try{let a=bn(t),n={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=vn(n);this.setState({crashFilePath:a,issueUrl:r})}catch{}}render(){return this.state.error?$e(fo,{flexDirection:"column",padding:1,children:[ue(Q,{bold:!0,color:"red",children:"\u25C6 CodeKeep \u2014 Something went wrong"}),ue(Q,{children:" "}),ue(Q,{color:"red",children:this.state.error.message}),ue(Q,{children:" "}),ue(Q,{dimColor:!0,children:"Your save file is at:"}),$e(Q,{children:[" ","~/.config/codekeep/game.json"]}),ue(Q,{children:" "}),this.state.crashFilePath&&$e(kn,{children:[ue(Q,{dimColor:!0,children:"Crash report saved to:"}),$e(Q,{children:[" ",this.state.crashFilePath]}),ue(Q,{children:" "})]}),this.state.issueUrl&&$e(kn,{children:[ue(Q,{dimColor:!0,children:"Report this bug:"}),$e(Q,{color:"cyan",children:[" ",this.state.issueUrl]}),ue(Q,{children:" "})]}),ue(Q,{dimColor:!0,children:"If the game won't start, try:"}),$e(Q,{bold:!0,children:[" ","codekeep --tutorial"]}),ue(Q,{children:" "}),ue(Q,{dimColor:!0,children:"Press Ctrl+C to exit"})]}):this.props.children}};import{Box as Rt,Text as de}from"ink";import ba from"react";import{Box as Tn,Text as X}from"ink";import{jsx as oe,jsxs as Be}from"react/jsx-runtime";function ho(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 go(e){let t=[];for(let a of e.statusEffects)switch(a.type){case"vulnerable":t.push(`V${a.stacks}`);break;case"weak":t.push(`W${a.stacks}`);break;case"burn":t.push(`B${a.stacks}`);break;case"empowered":t.push(`E${a.stacks}`);break;case"fortified":t.push(`F${a.stacks}`);break}return t.join("")}function yo(e,t,a){let n=Math.max(0,Math.min(a,Math.round(e/t*a)));return"\u2588".repeat(n)+"\u2591".repeat(Math.max(0,a-n))}function wo(e){return`${Pe(e.templateId)?.symbol??"?"}${e.hp}`}function xn({columns:e,targetColumn:t,showTarget:a,gateHp:n,gateMaxHp:r,gateBlock:o}){let i=e.length,s=14*i+(i-1),f=r>0?Math.round(n/r*100):0,h=f>60?"green":f>30?"yellow":"red",k="t h e p a l e",E=s+2,I=Math.floor((E-k.length)/2),re=E-I-k.length,m="\xB7 ".repeat(40),g=m.slice(0,I)+k+m.slice(0,re),M="\u250C"+Array.from({length:i},(G,H)=>"\u2500".repeat(14)+(H<i-1?"\u252C":"")).join("")+"\u2510",T="\u255E"+Array.from({length:i},(G,H)=>"\u2550".repeat(14)+(H<i-1?"\u256A":"")).join("")+"\u2561",w="\u2558"+Array.from({length:i},(G,H)=>"\u2550".repeat(14)+(H<i-1?"\u2567":"")).join("")+"\u255B",v=` \u25C6 GATE ${yo(n,r,20)} ${n}/${r}`,S=o>0?` \u25C7${o}`:"";return Be(Tn,{flexDirection:"column",children:[oe(X,{dimColor:!0,children:g}),oe(X,{dimColor:!0,children:M}),a&&Be(X,{children:[oe(X,{dimColor:!0,children:"\u2502"}),e.map((G,H)=>{let C=H===t,N=C?"\u25BC":"",D=N.padStart(Math.ceil((14+N.length)/2)).padEnd(14);return Be(ba.Fragment,{children:[oe(X,{color:C?"yellow":void 0,bold:C,children:D}),oe(X,{dimColor:!0,children:"\u2502"})]},H)})]}),Array.from({length:Je},(G,H)=>Be(X,{children:[oe(X,{dimColor:!0,children:"\u2502"}),e.map((C,N)=>{let D=C.enemies.filter(Me=>Me.row===H),F;D.length===0?F="\xB7".padStart(Math.floor(15/2)).padEnd(14):F=D.map(he=>{let ee=ho(he.intent),B=go(he),z=wo(he);return ee&&(z+=` ${ee}`),B&&(z+=` ${B}`),z}).join(" ").slice(0,14).padEnd(14);let Te=a&&N===t;return Be(ba.Fragment,{children:[oe(X,{color:Te&&D.length>0?"yellow":void 0,children:F}),oe(X,{dimColor:!0,children:"\u2502"})]},N)})]},H)),oe(X,{children:T}),Be(X,{children:[oe(X,{dimColor:!0,children:"\u2502"}),e.map((G,H)=>{let C;return G.emplacement?C=` \u25C7${U(G.emplacement.cardDefId)?.name??"Wall"} ${G.emplacement.hp}hp `.padEnd(14).slice(0,14):C=" ".repeat(14),Be(ba.Fragment,{children:[oe(X,{color:G.emplacement?"cyan":void 0,children:C}),oe(X,{dimColor:!0,children:"\u2502"})]},H)})]}),oe(X,{children:w}),Be(Tn,{paddingX:1,children:[oe(X,{bold:!0,color:h,children:v}),o>0&&oe(X,{color:"cyan",children:S})]})]})}import{Box as _n,Text as Re}from"ink";import{jsx as Pt,jsxs as Ve}from"react/jsx-runtime";function bo(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function vo(e){switch(e){case"armament":return"\u2694";case"fortification":return"\u25C7";case"edict":return"\u2726";case"wild":return"\u25C8";default:return"\xB7"}}function ko(e,t){let a=[];for(let n=0;n<e;n++)a.push(Pt(Re,{color:n<t?"cyan":"red",bold:!0,children:"\u25C6"},n));return a}function In({hand:e,selectedIndex:t,resolve:a}){return e.length===0?Ve(Re,{dimColor:!0,children:[" ","No cards in hand."]}):Ve(_n,{flexDirection:"column",children:[Pt(Re,{dimColor:!0,children:"\u2500\u2500\u2500 Hand ("+e.length+") \u2500\u2500\u2500"}),e.map((n,r)=>{let o=U(n.defId);if(!o)return null;let l=r===t,i=o.cost<=a;return Ve(_n,{flexDirection:"column",children:[Ve(Re,{children:[Pt(Re,{bold:l,color:l?"yellow":"white",children:l?" \u25B6 ":" "}),Ve(Re,{color:i?bo(o.rarity):"gray",bold:l,children:[vo(o.category)," ",o.name]}),Pt(Re,{children:" "}),ko(o.cost,a),l&&o.type==="emplace"&&Ve(Re,{color:"cyan",children:[" ","[emplaceable]"]})]}),l&&Ve(Re,{dimColor:!0,children:[" ",o.description]})]},n.instanceId)})]})}import{jsx as pe,jsxs as Le}from"react/jsx-runtime";function To(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 ${U(e.data.cardId)?.name??e.data.cardId}`;case"turn_start":return`\u2500 Turn ${e.data.turn} \u2500`;default:return""}}function Cn({combat:e,selectedCard:t,targetColumn:a,needsTarget:n,message:r}){let o=e.columns.reduce((l,i)=>l+i.enemies.length,0);return Le(Rt,{flexDirection:"column",children:[Le(Rt,{justifyContent:"space-between",children:[pe(de,{bold:!0,color:"yellow",children:"\u25C6 The Pale"}),Le(de,{children:["Turn ",pe(de,{bold:!0,color:"white",children:e.turn})," ",pe(de,{color:"cyan",children:"\u25C6".repeat(Math.max(0,e.resolve))}),pe(de,{dimColor:!0,children:"\u25C7".repeat(Math.max(0,e.maxResolve-e.resolve))})," ","Enemies ",pe(de,{bold:!0,color:"red",children:o})," ","Draw ",pe(de,{dimColor:!0,children:e.drawPile.length})," / ","Discard ",pe(de,{dimColor:!0,children:e.discardPile.length})]})]}),pe(xn,{columns:e.columns,targetColumn:a,showTarget:n&&t>=0,gateHp:e.gateHp,gateMaxHp:e.gateMaxHp,gateBlock:e.gateBlock}),pe(In,{hand:e.hand,selectedIndex:t,resolve:e.resolve}),(()=>{let l=e.events.filter(i=>i.turn>=e.turn-1).slice(-5);return l.length===0?null:Le(Rt,{flexDirection:"column",marginTop:0,children:[pe(de,{dimColor:!0,children:"\u2500\u2500\u2500 Log \u2500\u2500\u2500"}),l.map((i,s)=>{let f=To(i);if(!f)return null;let h=i.type==="turn_start";return pe(de,{dimColor:!h,color:h?"white":void 0,children:f},s)})]})})(),r&&Le(de,{color:"yellow",bold:!0,children:[" ",r]}),e.phase==="player"&&Le(de,{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"&&Le(Rt,{flexDirection:"column",marginTop:1,paddingX:1,children:[pe(de,{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."}),pe(de,{dimColor:!0,children:"Press Enter to continue."})]})]})}import{Box as Sn,Text as me}from"ink";import{jsx as Ae,jsxs as Oe}from"react/jsx-runtime";function En(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function xo(e){switch(e){case"uncommon":return"\u25C7 uncommon";case"rare":return"\u25C6 rare";case"legendary":return"\u2605 legendary";default:return"\xB7 common"}}function _o(e){switch(e){case"armament":return"\u2694";case"fortification":return"\u25C7";case"edict":return"\u2726";case"wild":return"\u25C8";default:return"\xB7"}}function Pn({cards:e,selectedIndex:t}){let a=t>=e.length;return Oe(Sn,{flexDirection:"column",padding:1,children:[Ae(me,{bold:!0,color:"yellow",children:"\u25C6 Card Reward"}),Ae(me,{dimColor:!0,children:"\u2500".repeat(36)}),Ae(me,{dimColor:!0,italic:!0,children:"Choose a card to add to your deck."}),Ae(me,{children:" "}),e.map((n,r)=>{let o=r===t;return Oe(Sn,{flexDirection:"column",marginBottom:0,children:[Oe(me,{children:[Ae(me,{bold:o,color:o?"yellow":"white",children:o?" \u25B6 ":" "}),Oe(me,{color:En(n.rarity),bold:o,children:[_o(n.category)," ",n.name]}),Oe(me,{dimColor:!0,children:[" ","[",n.cost,"]"," "]}),Ae(me,{color:En(n.rarity),dimColor:!0,children:xo(n.rarity)})]}),o&&Oe(me,{dimColor:!0,children:[" ",n.description]})]},n.id)}),Ae(me,{children:" "}),Oe(me,{bold:a,color:a?"yellow":"white",children:[a?" \u25B6 ":" ","Skip"]}),Ae(me,{children:" "}),Ae(me,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]})}import{Box as Io,Text as ft}from"ink";import{jsx as ka,jsxs as va}from"react/jsx-runtime";function Co(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function Rn({deck:e}){let t=new Map;for(let n of e)t.set(n.defId,(t.get(n.defId)??0)+1);let a=[...t.entries()].map(([n,r])=>({def:U(n),count:r})).filter(n=>n.def).sort((n,r)=>{let o={common:0,uncommon:1,rare:2,legendary:3},l=o[n.def.rarity]??0,i=o[r.def.rarity]??0;return l!==i?l-i:n.def.name.localeCompare(r.def.name)});return va(Io,{flexDirection:"column",padding:1,children:[va(ft,{bold:!0,color:"yellow",children:["\u25C6 Your Deck"," (",e.length," cards)"]}),ka(ft,{children:" "}),a.map(({def:n,count:r})=>va(ft,{color:Co(n.rarity),children:[r>1?`${r}x `:" ",n.name," [",n.cost,"] \u2014 ",n.description]},n.id)),ka(ft,{children:" "}),ka(ft,{dimColor:!0,children:"Press q or Esc to go back."})]})}import So from"react";import{Box as An,Text as se}from"ink";import{jsx as le,jsxs as Ta}from"react/jsx-runtime";var Mn=6,Eo=4,At=(Eo-1)*Mn+6;function xa(e){return e*Mn+3}function Po(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 Ro(e,t,a,n){if(n)return"cyan";if(a)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 Ao(e,t,a,n){let r=[],o=0,l=[...e].sort((i,s)=>i.column-s.column);for(let i of l){let s=xa(i.column),f=Po(i.type),h=i.id===t,k=i.id===a,E=h?`[${f}]`:k?`(${f})`:` ${f} `,I=s-Math.floor(E.length/2);I>o&&r.push({text:" ".repeat(I-o)}),r.push({text:E,color:Ro(i,n.has(i.id),h,k),bold:h||k,dim:i.visited&&!k&&!h}),o=I+E.length}return r}function Mo(e,t){let a=Array(At).fill(" "),n=new Map;function r(o,l){o<0||o>=At||(n.has(o)||n.set(o,new Set),n.get(o).add(l))}for(let o of e){let l=xa(o.column);for(let i of o.connections){let s=t.find(h=>h.id===i);if(!s)continue;let f=xa(s.column);l===f?r(l,"\u2502"):r(Math.round((l+f)/2),f>l?"\u2572":"\u2571")}}for(let[o,l]of n)l.has("\u2572")&&l.has("\u2571")?a[o]="\u2573":l.has("\u2502")?a[o]="\u2502":l.has("\u2572")?a[o]="\u2572":l.has("\u2571")&&(a[o]="\u2571");return a.join("")}function Dn({map:e,currentNodeId:t,reachableIds:a,selectedNodeId:n}){let r=new Set(a),o=Math.max(...e.nodes.map(i=>i.row)),l=[];for(let i=0;i<=o;i++)l.push(e.nodes.filter(s=>s.row===i).sort((s,f)=>s.column-f.column));return Ta(An,{flexDirection:"column",padding:1,children:[le(se,{bold:!0,color:"yellow",children:"\u25C6 Act "+e.act+" \u2014 Choose your path"}),le(se,{dimColor:!0,children:"\u2500".repeat(At)}),le(se,{children:" "}),l.map((i,s)=>{let f=Ao(i,n,t,r);return Ta(So.Fragment,{children:[le(se,{children:f.map((h,k)=>le(se,{color:h.color,bold:h.bold,dimColor:h.dim,children:h.text},k))}),s<o&&le(se,{dimColor:!0,children:Mo(i,l[s+1]??[])})]},s)}),le(se,{children:" "}),le(se,{dimColor:!0,children:"\u2500".repeat(At)}),Ta(An,{gap:2,children:[le(se,{dimColor:!0,children:"\u2694 fight"}),le(se,{dimColor:!0,color:"red",children:"\u2605 elite"}),le(se,{dimColor:!0,color:"green",children:"\u25B3 rest"}),le(se,{dimColor:!0,color:"yellow",children:"$ shop"}),le(se,{dimColor:!0,color:"magenta",children:"? event"}),le(se,{dimColor:!0,color:"red",children:"\u25C6 boss"})]}),le(se,{dimColor:!0,children:"\u2191\u2193 select Enter proceed d deck q quit"})]})}import{Box as Do,Text as He}from"ink";import{jsx as at,jsxs as _a}from"react/jsx-runtime";function Bn({items:e,selectedIndex:t,fragments:a,message:n}){return _a(Do,{flexDirection:"column",padding:1,children:[_a(He,{bold:!0,color:"yellow",children:["\u25C6 Shop \u2014 ",a," fragments"]}),at(He,{dimColor:!0,children:"\u2500".repeat(36)}),at(He,{children:" "}),e.map((r,o)=>{let l=o===t,i=a>=r.cost,s="",f="";return r.type==="card"&&r.cardDef?(f="[Card]",s=`${r.cardDef.name} (${r.cardDef.rarity}) \u2014 ${r.cardDef.description}`):r.type==="potion"&&r.potionDef?(f="[Potion]",s=`${r.potionDef.name} \u2014 ${r.potionDef.description}`):r.type==="card_remove"&&(f="[Service]",s="Remove a card from your deck"),_a(He,{bold:l,color:l?"yellow":i?"white":"gray",children:[l?"\u25B6 ":" ",f," ",s," [",r.cost,"f]"]},o)}),e.length===0&&at(He,{dimColor:!0,children:" (Shop is empty)"}),at(He,{children:" "}),n&&at(He,{color:"red",children:n}),at(He,{dimColor:!0,children:"\u2191\u2193 navigate Enter buy q leave"})]})}import{Box as Bo,Text as Ke}from"ink";import{jsx as ht,jsxs as Ia}from"react/jsx-runtime";function Hn({event:e,selectedChoice:t}){return Ia(Bo,{flexDirection:"column",padding:1,children:[Ia(Ke,{bold:!0,color:"magenta",children:["\u25C6 ",e.name]}),ht(Ke,{children:" "}),ht(Ke,{children:e.description}),ht(Ke,{children:" "}),e.choices.map((a,n)=>Ia(Ke,{bold:n===t,color:n===t?"yellow":"white",children:[n===t?"\u25B6 ":" ",n+1,". ",a.label]},n)),ht(Ke,{children:" "}),ht(Ke,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as Nn,Text as fe}from"ink";import{jsx as be,jsxs as Mt}from"react/jsx-runtime";function Gn({gateHp:e,gateMaxHp:t,selectedChoice:a,deckSize:n}){let r=Math.floor(t*.3),o=Math.min(t,e+r),l=n>5,i=[{label:"Rest",detail:`Heal ${r} Gate HP (${e} \u2192 ${o}/${t})`,color:"green",available:!0},{label:"Thin",detail:l?`Remove a card from your deck (${n} cards)`:`Minimum deck size reached (${n} cards)`,color:"cyan",available:l},{label:"Leave",detail:"Continue without resting",color:"white",available:!0}];return Mt(Nn,{flexDirection:"column",padding:1,children:[be(fe,{bold:!0,color:"green",children:"\u25C6 Rest Site"}),be(fe,{dimColor:!0,children:"\u2500".repeat(36)}),be(fe,{children:" "}),be(fe,{dimColor:!0,italic:!0,children:"The campfire crackles against the encroaching Pale."}),be(fe,{dimColor:!0,italic:!0,children:"A moment of warmth in the endless grey."}),be(fe,{children:" "}),i.map(({label:s,detail:f,color:h,available:k},E)=>{let I=E===a;return Mt(Nn,{flexDirection:"column",children:[Mt(fe,{children:[be(fe,{bold:I,color:I?"yellow":"white",children:I?" \u25B6 ":" "}),be(fe,{color:k?I?h:"white":"gray",bold:I,dimColor:!k,children:s}),!k&&be(fe,{dimColor:!0,children:" (unavailable)"})]}),I&&Mt(fe,{dimColor:!0,children:[" ",f]})]},E)}),be(fe,{children:" "}),be(fe,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as nt,Text as Z}from"ink";import{jsx as ne,jsxs as Ne}from"react/jsx-runtime";var Ln=[{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:"+"}],On=[{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:"?"}],Ho={type:"gate",id:"gate",name:"The Gate",symbol:">"},Ue=[...Ln,...On,Ho],No={wren:"Wren, the Steward",sable:"Sable, the Archivist",duskmar:"Duskmar, First Wall",mott:"Mott, the Salvager",pale_visitor:"The Pale Visitor"},Go={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"},Wn=17,Fn=56,ae=1,J=15,L=3,Y=52,Wo={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}},Fo={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 Ca(e,t){return e>=t?"green":e>=2?"cyan":e>=1?"yellow":"white"}function $n(e){return e>=4?"magenta":e>=2?"cyan":e>=1?"yellow":"white"}function Vn(e,t,a){let n=[];for(let r=0;r<t;r++)n.push(r<e?ne(Z,{color:a,bold:!0,children:"\u25C6"},r):ne(Z,{dimColor:!0,children:"\u25C7"},r));return n}function Kn({keep:e,selectedId:t,message:a,isFirstVisit:n}){let r=[],o=[];for(let m=0;m<Wn;m++){let g=[],M=[];for(let T=0;T<Fn;T++)g.push((m+T)%2===0?"~":" "),M.push({color:"white",bold:!1,dim:!0});r.push(g),o.push(M)}let l="the pale",i=Math.floor((Fn-l.length)/2);for(let m=0;m<l.length;m++)r[0][i+m]=l[m],r[Wn-1][i+m]=l[m];r[ae][L]="\u2554",r[ae][Y]="\u2557",r[J][L]="\u255A",r[J][Y]="\u255D";for(let m=L+1;m<Y;m++)r[ae][m]="\u2550",r[J][m]="\u2550",o[ae][m]={color:"white",bold:!1,dim:!0},o[J][m]={color:"white",bold:!1,dim:!0};for(let m=ae+1;m<J;m++)r[m][L]="\u2551",r[m][Y]="\u2551",o[m][L]={color:"white",bold:!1,dim:!0},o[m][Y]={color:"white",bold:!1,dim:!0};for(let m of[[ae,L],[ae,Y],[J,L],[J,Y]])o[m[0]][m[1]]={color:"white",bold:!1,dim:!0};for(let m of[L+1,8,14,38,44,Y-1])m>L&&m<Y&&(r[ae][m]="\u25B2",o[ae][m]={color:"white",bold:!0,dim:!1});for(let m of[L+1,8,14,42,48,Y-1])m>L&&m<Y&&r[J][m]==="\u2550"&&(r[J][m]="\u25B2",o[J][m]={color:"white",bold:!0,dim:!1});let s=" THE KEEP ",f=L+1+Math.floor((Y-L-1-s.length)/2);for(let m=0;m<s.length;m++)r[ae][f+m]=s[m],o[ae][f+m]={color:"yellow",bold:!0,dim:!1};for(let m=ae+1;m<J;m++)for(let g=L+1;g<Y;g++)r[m][g]=" ",o[m][g]={color:"white",bold:!1,dim:!1};for(let[m,g]of[[ae+1,L+1],[ae+1,Y-1],[J-1,L+1],[J-1,Y-1]])r[m][g]="*",o[m][g]={color:"yellow",bold:!0,dim:!1};for(let m=L+2;m<Y-1;m++)r[8][m]===" "&&(r[8][m]="\xB7",o[8][m]={color:"white",bold:!1,dim:!0});for(let m of[11,25,39])for(let g=6;g<=(m===39?8:10);g++)r[g][m]===" "&&(r[g][m]="\xB7",o[g][m]={color:"white",bold:!1,dim:!0});for(let m=9;m<J;m++)r[m][28]===" "&&(r[m][28]="\xB7",o[m][28]={color:"white",bold:!1,dim:!0});for(let[m,g]of[[7,16],[7,34],[7,48],[9,8],[9,18],[9,36],[13,8],[13,18],[13,36]])m>ae&&m<J&&r[m][g]===" "&&(r[m][g]="\xB7",o[m][g]={color:"white",bold:!1,dim:!0});for(let m of Ln){let g=Wo[m.id];if(!g)continue;let M=Qe.find(B=>B.id===m.id),T=et(e,m.id),w=M?.maxLevel??3,v=m.id===t,S=v?"yellow":Ca(T,w),G=v||T>=w,H=!v&&T===0,C=g.row,N=g.col,D=g.width,F=D-2,Te=Math.ceil((F-m.name.length)/2),Me=F-m.name.length-Te;r[C][N]=v?"\u250F":"\u250C";let he=N+1;for(let B=0;B<Te;B++)r[C][he]=v?"\u2501":"\u2500",he++;for(let B=0;B<m.name.length;B++)r[C][he]=m.name[B],he++;for(let B=0;B<Me;B++)r[C][he]=v?"\u2501":"\u2500",he++;r[C][N+D-1]=v?"\u2513":"\u2510",r[C+1][N]=v?"\u2503":"\u2502";for(let B=1;B<D-1;B++)r[C+1][N+B]=" ";r[C+1][N+Math.floor(D/2)]=m.symbol,r[C+1][N+D-1]=v?"\u2503":"\u2502",r[C+2][N]=v?"\u2517":"\u2514";for(let B=1;B<D-1;B++)r[C+2][N+B]=v?"\u2501":"\u2500";r[C+2][N+D-1]=v?"\u251B":"\u2518";for(let B=0;B<3;B++)for(let z=0;z<D;z++)o[C+B][N+z]={color:S,bold:G,dim:H};let ee=C+3;if(ee>ae&&ee<J){let B=N+Math.floor((D-w)/2);for(let z=0;z<w;z++)r[ee][B+z]=z<T?"\u25C6":"\u25C7",o[ee][B+z]={color:z<T?v?"yellow":Ca(T,w):"white",bold:z<T,dim:z>=T}}}for(let m of On){let g=Fo[m.id];if(!g)continue;let T=e.npcs.find(S=>S.id===m.id)?.tier??0,w=m.id===t,v=w?"yellow":$n(T);w&&(g.col-1>L&&(r[g.row][g.col-1]="[",o[g.row][g.col-1]={color:"yellow",bold:!0,dim:!1}),g.col+1<Y&&(r[g.row][g.col+1]="]",o[g.row][g.col+1]={color:"yellow",bold:!0,dim:!1})),r[g.row][g.col]=m.symbol,o[g.row][g.col]={color:v,bold:w||T>=3,dim:!1}}{let m=t==="gate",g=m?"\u2524 ENTER THE PALE \u251C":"\u2561 ENTER THE PALE \u255E",M=L+1+Math.floor((Y-L-1-g.length)/2);for(let T=0;T<g.length;T++)r[J][M+T]=g[T],o[J][M+T]={color:m?"yellow":"green",bold:!0,dim:!1}}for(let m=11;m<=14;m++)for(let g=48;g<Y;g++)(r[m][g]===" "||r[m][g]==="\xB7")&&(r[m][g]="~",o[m][g]={color:"white",bold:!1,dim:!0});let h=Ue.find(m=>m.id===t),k="",E="",I="cyan",re=null;if(h)if(h.type==="structure"){let m=Qe.find(T=>T.id===h.id),g=et(e,h.id),M=m?.maxLevel??3;if(I=Ca(g,M),k=h.name,g>=M)E=`${m?.description??""} (fully upgraded)`;else{let T=m?.upgradeCost(g+1)??0;E=`${m?.description??""} \u2014 ${T} Echoes to upgrade`}re=Ne(Z,{children:[" ",Vn(g,M,I)]})}else if(h.type==="npc"){let g=e.npcs.find(M=>M.id===h.id)?.tier??0;I=$n(g),k=No[h.id]??h.id,E=Go[h.id]??"",re=Ne(Z,{children:[" ",Vn(g,5,I)]})}else h.type==="gate"&&(I="green",k="The Gate",E="Step beyond the walls. Face the Pale.");return Ne(nt,{flexDirection:"column",children:[Ne(nt,{justifyContent:"space-between",paddingX:1,children:[ne(Z,{bold:!0,color:"yellow",children:"\u25C6 The Keep"}),Ne(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(nt,{flexDirection:"column",children:r.map((m,g)=>ne(Z,{children:m.map((M,T)=>{let w=o[g][T];return ne(Z,{color:w.color,bold:w.bold,dimColor:w.dim,children:M},T)})},g))}),Ne(nt,{flexDirection:"column",paddingX:1,children:[h?Ne(nt,{flexDirection:"column",children:[Ne(nt,{children:[ne(Z,{bold:!0,color:I,children:k}),re]}),ne(Z,{dimColor:!0,children:E})]}):ne(Z,{dimColor:!0,italic:!0,children:"Select a building or NPC."}),n&&!a&&ne(Z,{color:"green",children:"TIP: Upgrade buildings with Echoes. Talk to NPCs. Enter the Gate to start a run."}),a?ne(Z,{color:"yellow",bold:!0,children:a}):null,ne(Z,{dimColor:!0,children:"\u2191\u2193/\u2190\u2192 select Enter interact q back"})]})]})}import{Box as Un,Text as Ge}from"ink";import{jsx as rt,jsxs as Dt}from"react/jsx-runtime";var qn=[{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 $o(e,t,a){let n=Math.max(0,Math.min(a,Math.round(e/t*a)));return"\u2588".repeat(n)+"\u2591".repeat(Math.max(0,a-n))}function Yn({page:e,totalPages:t}){let a=qn[e];return a?Dt(Un,{flexDirection:"column",padding:1,children:[Dt(Ge,{bold:!0,color:"yellow",children:["\u25C6 Tutorial \u2014 ",a.title]}),rt(Ge,{dimColor:!0,children:"\u2500".repeat(44)}),rt(Ge,{children:" "}),a.lines.map((n,r)=>rt(Ge,{children:n||" "},r)),rt(Ge,{children:" "}),rt(Ge,{dimColor:!0,children:"\u2500".repeat(44)}),Dt(Un,{children:[Dt(Ge,{dimColor:!0,children:[$o(e+1,t,20)," ",e+1,"/",t," "]}),rt(Ge,{dimColor:!0,children:e<t-1?"\u2190 prev \u2192 next q close":"\u2190 prev Enter start q close"})]})]}):null}var gt=qn.length;import{Box as Bt,Text as ie}from"ink";import{Fragment as zn,jsx as ve,jsxs as Ee}from"react/jsx-runtime";var jn={asciiMode:!1,showTutorialHints:!0,combatLogSize:4};function Xn({settings:e,selectedIndex:t,saveInfo:a,confirmingReset:n,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 Ee(Bt,{flexDirection:"column",padding:1,children:[ve(ie,{bold:!0,color:"yellow",children:"\u25C6 Settings"}),ve(ie,{children:" "}),ve(Bt,{paddingX:1,children:Ee(Bt,{flexDirection:"column",width:40,children:[ve(ie,{bold:!0,dimColor:!0,children:"Save Info"}),Ee(ie,{dimColor:!0,children:["Runs: ",a.totalRuns," Wins: ",a.totalWins," Echoes: ",a.echoes]}),Ee(ie,{dimColor:!0,children:["Highest Ascension: ",a.highestAscension]}),Ee(ie,{dimColor:!0,children:["Save: ",a.hasSave?"~/.config/codekeep/game.json":"None"]})]})}),ve(ie,{children:" "}),o.map((l,i)=>{let s=i===t;return Ee(Bt,{children:[Ee(ie,{bold:s,color:s?l.id==="reset"?"red":"yellow":void 0,children:[s?"\u25B6 ":" ",l.label]}),s&&l.description?Ee(ie,{dimColor:!0,children:[" \u2014 ",l.description]}):null]},l.id)}),n&&Ee(zn,{children:[ve(ie,{children:" "}),ve(ie,{bold:!0,color:"red",children:"Are you sure? This deletes ALL progress. Press Enter again to confirm, Esc to cancel."})]}),r&&Ee(zn,{children:[ve(ie,{children:" "}),ve(ie,{color:"cyan",bold:!0,children:r})]}),ve(ie,{children:" "}),ve(ie,{dimColor:!0,children:"\u2191\u2193 navigate Enter toggle/select q back"})]})}import{Box as Vo,Text as P}from"ink";import{jsx as R,jsxs as Lo}from"react/jsx-runtime";function Jn(){return Lo(Vo,{flexDirection:"column",padding:1,children:[R(P,{bold:!0,color:"yellow",children:"\u25C6 Controls Reference"}),R(P,{dimColor:!0,children:"\u2500".repeat(36)}),R(P,{children:" "}),R(P,{bold:!0,children:"Global"}),R(P,{children:" \u2191\u2193 Navigate menus"}),R(P,{children:" Enter Confirm / select"}),R(P,{children:" Esc Cancel / go back"}),R(P,{children:" q Quit / back to menu"}),R(P,{children:" "}),R(P,{bold:!0,children:"Combat"}),R(P,{children:" 1-9 Select card from hand"}),R(P,{children:" \u2190\u2192 Target column"}),R(P,{children:" Enter Play selected card"}),R(P,{children:" Space End your turn"}),R(P,{children:" e Toggle emplace mode"}),R(P,{children:" p Use potion"}),R(P,{children:" i Inspect enemies"}),R(P,{children:" d View deck"}),R(P,{children:" "}),R(P,{bold:!0,children:"Map"}),R(P,{children:" \u2191\u2193 Select next node"}),R(P,{children:" Enter Enter node"}),R(P,{children:" d View deck"}),R(P,{children:" "}),R(P,{bold:!0,children:"The Keep"}),R(P,{children:" \u2190\u2192 Select building / NPC"}),R(P,{children:" Enter Interact"}),R(P,{children:" "}),R(P,{bold:!0,children:"Inspect Mode (i in combat)"}),R(P,{children:" \u2190\u2192 Switch column"}),R(P,{children:" \u2191\u2193 Switch enemy"}),R(P,{children:" i / Esc Close inspect"}),R(P,{children:" "}),R(P,{dimColor:!0,children:"Press q or Esc to go back"})]})}import{useState as yt,useCallback as qe,useRef as Oo}from"react";function Zn(){let[e,t]=yt(null),[a,n]=yt(-1),[r,o]=yt(2),[l,i]=yt(""),[s,f]=yt(!1),h=Oo(null),k=qe((w,v,S,G,H,C,N)=>{let D=w??sa(),F=v??Math.floor(Math.random()*2147483647),Te=Xa(D,F,S,G,H,C??[],N);h.current=Te,t({...Te}),n(-1),o(2),f(!1),i("Your turn. Select a card (1-5) and a column (\u2190\u2192).")},[]),E=(()=>{if(a<0||!e)return!1;let w=e.hand[a];if(!w)return!1;let v=U(w.defId);if(!v)return!1;let S=new Set(["damage","damage_if_vulnerable","damage_equal_block","damage_if_emplaced","damage_plus_block","damage_if_low_hp","vulnerable","weak","burn"]);return v.effects.some(G=>S.has(G.type)&&(G.target==="single"||G.target==="column"))})(),I=qe(w=>{if(!h.current||h.current.phase!=="player"||w<0||w>=h.current.hand.length)return;let v=h.current.hand[w],S=U(v.defId);if(!S)return;let G=!h.current.events.some(F=>F.type==="card_played"&&F.turn===h.current.turn);if((da(h.current.relics)&&G?0:S.cost)>h.current.resolve){i(`Not enough Resolve for ${S.name} (costs ${S.cost}).`);return}n(w);let N=new Set(["damage","damage_if_vulnerable","damage_equal_block","damage_if_emplaced","damage_plus_block","damage_if_low_hp","vulnerable","weak","burn"]),D=S.effects.some(F=>N.has(F.type)&&(F.target==="single"||F.target==="column"));i(D?`${S.name} selected. Choose column (\u2190\u2192), Enter to play.`:`${S.name} selected. Enter to play.`)},[]),re=qe(w=>{w>=0&&w<5&&o(w)},[]),m=qe(()=>{let w=h.current;if(!w||w.phase!=="player"||a<0)return;let v=w.hand[a];if(!v)return;let S=U(v.defId);if(!S)return;let G=w.events.length;if(Ja(w,a,r,s),w.events.length===G){i(`Cannot play ${S.name}. Not enough Resolve.`);return}h.current=w,t({...w}),n(-1),f(!1),w.outcome==="win"?i("Victory! The Pale recedes."):w.outcome==="lose"?i("The Gate has fallen..."):i(`${s?"Emplaced":"Played"} ${S.name}. ${w.resolve} Resolve left.`)},[a,r,s]),g=qe(()=>{if(a<0||!h.current)return;let w=h.current.hand[a];if(!w)return;let v=U(w.defId);if(!v||v.type!=="emplace"){i("This card cannot be emplaced.");return}f(S=>!S),i(s?`${v.name}: cast mode`:`${v.name}: EMPLACE mode \u2014 place in a column`)},[a,s]),M=qe(()=>{let w=h.current;!w||w.phase!=="player"||(Qa(w),h.current=w,t({...w}),n(-1),w.outcome==="win"?i("Victory! The Pale recedes."):w.outcome==="lose"?i("The Gate has fallen..."):i(`Turn ${w.turn}. Your move.`))},[]),T=qe(w=>{let v=h.current;if(!(!v||!w)){for(let S of w.effects)switch(S.type){case"heal":v.gateHp=Math.min(v.gateMaxHp,v.gateHp+S.value);break;case"block":v.gateBlock+=S.value;break;case"damage":{let G=r;if(S.target==="column"){let H=v.columns[G];if(H)for(let C of H.enemies)C.hp-=S.value}else if(S.target==="all")for(let H of v.columns)for(let C of H.enemies)C.hp-=S.value;break}case"draw":{let G=j(v.seed+v.turn*53),{drawn:H,newDrawPile:C,newDiscardPile:N}=De(v.drawPile,v.discardPile,S.value,G);v.hand.push(...H),v.drawPile=C,v.discardPile=N;break}case"resolve":v.resolve=Math.min(v.maxResolve+5,v.resolve+S.value);break}h.current=v,t({...v}),i(`Used ${w.name}.`)}},[r]);return{combat:e,selectedCard:a,targetColumn:r,message:l,emplaceMode:s,selectCard:I,selectTarget:re,confirmPlay:m,endTurn:M,toggleEmplace:g,startCombat:k,applyPotion:T,needsTarget:E}}import{Fragment as Sa,jsx as b,jsxs as _}from"react/jsx-runtime";var Qn=60,er=18;function zo(){let{stdout:e}=Yo(),[t,a]=A({columns:e?.columns??process.stdout.columns??80,rows:e?.rows??process.stdout.rows??24});return Ko(()=>{let n=e??process.stdout,r=()=>a({columns:n.columns,rows:n.rows});return n.on("resize",r),()=>{n.off("resize",r)}},[e]),t}function jo({dryRun:e}){let{exit:t}=Uo(),{columns:a,rows:n}=zo(),[r,o]=A("menu"),[l,i]=A(0),[s,f]=A(null),[h,k]=A(0),[E,I]=A([]),[re,m]=A(0),[g,M]=A([]),[T,w]=A(0),[v,S]=A(null),[G,H]=A(0),[C,N]=A(0),[D,F]=A(null),[Te,Me]=A(0),[he,ee]=A(""),[B,z]=A(!1),[We,rr]=A([]),[Ye,Ht]=A(0),[Nt,Fe]=A(0),Gt=Zn(),{combat:V,selectedCard:wt,targetColumn:Wt,message:or,emplaceMode:Qo,selectCard:Ea,selectTarget:Pa,confirmPlay:sr,endTurn:lr,toggleEmplace:ir,startCombat:Ft,applyPotion:es,needsTarget:cr}=Gt,[$t,Vt]=A(!1),[bt,Lt]=A(0),[dr,Ot]=A(0),[Kt,Ra]=A(null),[Aa,ze]=A(0),[Ut,qt]=A("new_game"),[mr,Ma]=A("map"),[ur,Da]=A(""),[Ba,Yt]=A(!1),[ot,zt]=A(jn),[Ha,jt]=A(0),[pr,vt]=A(""),[Na,je]=A(!1),[ce,xe]=A(()=>tt()),Xt=!ce||ce.keep.totalRuns<=1,st=ce?un(ce.keep.totalRuns,ce.keep.highestAscension):"surface",fr=a<Qn||n<er,_e=ke(()=>{let u=ce??tt();return u?ce||(u.keep.npcs.length===0&&(u.keep.npcs=fa()),xe(u)):(u=gn("Warden"),u.keep.npcs.length===0&&(u.keep.npcs=fa()),Se(u),xe(u)),JSON.parse(JSON.stringify(u))},[ce]),$=ke(u=>{if(e)return;let d=_e();d.activeRun=u,D&&(d.keep=D),Se(d),xe(d)},[e,D,_e]),Jt=ke(()=>{let u=_e();if(u.keep.totalRuns===0){u.keep.totalRuns++,Se(u),xe(u),F(u.keep),ze(0),qt("new_game"),o("tutorial");return}let d=`run-${Date.now()}`,c=nn(d,u.keep.highestAscension);f(c),k(0),u.activeRun=c,u.keep.totalRuns++,F(u.keep),Se(u),xe(u),o("map")},[_e]),hr=ke(()=>{let u=tt();u?.activeRun&&(f(u.activeRun),F(u.keep),k(0),o("map"))},[]),Ga=ke(()=>{let u=_e();xe(u),F(u.keep),Me(0),ee(""),o("keep")},[_e]),Wa=ke(()=>s?an(s.map,s.currentNodeId):[],[s]),gr=ke(u=>{if(!s)return;let d=rn(s,u.id);if(u.type==="combat"||u.type==="elite"){let c=we(s.seed+u.id),p=j(c),x=en(s.act,p,u.type==="elite");Ft(d.deck,c,d.gateHp,d.gateMaxHp,x.enemies,d.relics,Ct(s.act,s.ascensionLevel)),f(d),o("combat")}else if(u.type==="boss"){let c=we(s.seed+"-boss-"+s.act),p=Ua(s.act);Ft(d.deck,c,d.gateHp,d.gateMaxHp,p,d.relics,Ct(s.act,s.ascensionLevel));let x=la(s.act);if(x?.dialogue){let W=x.dialogue.find(Ie=>Ie.storyLayer===st)??x.dialogue[0];W&&Ra(W.onAppear)}f(d),o("combat")}else if(u.type==="shop"){let c=j(we(s.seed+u.id));M(cn(c)),w(0),f(d),o("shop")}else if(u.type==="event"){let c=j(we(s.seed+u.id));S(dn(s.act,c,st)),H(0),f(d),o("event")}else u.type==="rest"&&(N(0),f(d),o("rest"));$(d)},[s,Ft,$]),lt=ke((u,d)=>{z(d),f(u);let c=_e(),p=ha(d,u.act,u.ascensionLevel);c.keep.echoes+=p,d&&(c.keep.totalWins++,u.ascensionLevel>=c.keep.highestAscension&&(c.keep.highestAscension=u.ascensionLevel+1)),c.activeRun=null,F(c.keep),Se(c),xe(c),o("result")},[_e]),yr=ke(()=>{if(!V||!s)return;let u={...s,gateHp:V.gateHp};if(V.outcome==="lose"){lt(u,!1);return}let d=s.currentNodeId?mt(s.map,s.currentNodeId):null,c=d?.type==="elite"?kt.elite:d?.type==="boss"?kt.boss:kt.combat;if(u=pt(u,c),u.relics.includes("mending_stone")&&(u=St(u,5)),u.relics.includes("fragment_magnet")&&(u=pt(u,5)),d?.type==="elite"||d?.type==="boss"){let x=j(we(s.seed+(s.currentNodeId??"")+"-relic")),W=ja(x,u.relics,3);if(W.length>0){rr(W),Ht(0),f(u),$(u),o("relic_reward");return}}if(d?.type==="boss"){s.act<3?(u=pa(u),f(u),$(u),k(0),o("map")):lt(u,!0);return}let p=j(we(s.seed+(s.currentNodeId??"")+"-reward"));I(It(p)),m(0),f(u),$(u),o("reward")},[V,s,$,lt]),Fa=ke(u=>{if(!s)return;let d=s;u&&(d=ma(d,ut(u.id))),f(d),$(d),k(0),o("map")},[s,$]),$a=ke(u=>{if(!s)return;let d=s;if(u&&(d={...d,relics:[...d.relics,u.id]}),f(d),$(d),(s.currentNodeId?mt(s.map,s.currentNodeId):null)?.type==="boss")s.act<3?(d=pa(d),f(d),$(d),k(0),o("map")):lt(d,!0);else{let p=j(we(s.seed+(s.currentNodeId??"")+"-reward"));I(It(p)),m(0),o("reward")}},[s,$,lt]),Zt=[{label:"The Keep",action:"keep"},{label:"New Run",action:"new"},...ce?.activeRun?[{label:"Resume Run",action:"resume"}]:[],{label:"Tutorial",action:"tutorial"},{label:"Settings",action:"settings"},{label:"Quit",action:"quit"}];if(qo((u,d)=>{if(r==="tutorial"){d.rightArrow?ze(c=>Math.min(gt-1,c+1)):d.leftArrow?ze(c=>Math.max(0,c-1)):d.return?Aa===gt-1?Ut==="new_game"?Jt():o(Ut==="settings"?"settings":"menu"):ze(c=>Math.min(gt-1,c+1)):(u==="q"||d.escape)&&o(Ut==="settings"?"settings":"menu");return}if(r==="controls"){(u==="q"||d.escape)&&o("settings");return}if(r==="settings"){let c=["ascii","hints","log","tutorial","controls","reset","back"];if(d.upArrow)jt(p=>Math.max(0,p-1)),je(!1);else if(d.downArrow)jt(p=>Math.min(c.length-1,p+1)),je(!1);else if(u==="q"||d.escape)o("menu"),je(!1);else if(d.return){let p=c[Ha];p==="ascii"?(zt(x=>({...x,asciiMode:!x.asciiMode})),vt("ASCII mode "+(ot.asciiMode?"disabled":"enabled"))):p==="hints"?(zt(x=>({...x,showTutorialHints:!x.showTutorialHints})),vt("Tutorial hints "+(ot.showTutorialHints?"disabled":"enabled"))):p==="log"?zt(x=>({...x,combatLogSize:x.combatLogSize>=8?0:x.combatLogSize+2})):p==="tutorial"?(ze(0),qt("settings"),o("tutorial")):p==="controls"?o("controls"):p==="reset"?Na?(yn(),xe(null),F(null),f(null),je(!1),vt("Save data deleted. Starting fresh.")):je(!0):p==="back"&&o("menu")}return}if(r==="relic_reward"){d.upArrow?Ht(c=>Math.max(0,c-1)):d.downArrow?Ht(c=>Math.min(We.length,c+1)):u==="s"?$a(null):d.return&&$a(Ye<We.length?We[Ye]:null);return}if(r==="menu"){if(d.upArrow)i(c=>Math.max(0,c-1));else if(d.downArrow)i(c=>Math.min(Zt.length-1,c+1));else if(d.return){let c=Zt[l]?.action;c==="keep"?Ga():c==="new"?Jt():c==="resume"?hr():c==="tutorial"?(ze(0),qt("menu"),o("tutorial")):c==="settings"?(jt(0),vt(""),je(!1),o("settings")):t()}else u==="q"&&t();return}if(r==="deck"){(u==="q"||d.escape)&&o(mr);return}if(r==="map"&&s){let c=Wa();d.upArrow?k(p=>Math.max(0,p-1)):d.downArrow?k(p=>Math.min(c.length-1,p+1)):d.return&&c[h]?gr(c[h]):u==="d"?(Ma("map"),o("deck")):u==="q"&&($(s),o("menu"));return}if(r==="reward"){let c=E.length;d.upArrow?m(p=>Math.max(0,p-1)):d.downArrow?m(p=>Math.min(c,p+1)):u==="s"?Fa(null):d.return&&Fa(re<E.length?E[re]:null);return}if(r==="shop"&&s){if(d.upArrow)w(c=>Math.max(0,c-1));else if(d.downArrow)w(c=>Math.min(g.length-1,c+1));else if(u==="q"||d.escape)k(0),o("map");else if(d.return){let c=g[T];if(c&&s.fragments<c.cost){Da(`Not enough fragments (need ${c.cost}, have ${s.fragments}).`);return}if(Da(""),c&&s.fragments>=c.cost){let p=on(s,c.cost);if(!p)return;if(c.type==="card"&&c.cardDef)p=ma(p,ut(c.cardDef.id)),f(p),$(p),M(x=>x.filter((W,Ie)=>Ie!==T)),w(0);else if(c.type==="potion"&&c.potionDef){let x=sn(p,c.potionDef.id);x&&(p=x),f(p),$(p),M(W=>W.filter((Ie,wr)=>wr!==T)),w(0)}else c.type==="card_remove"&&(f(p),$(p),Fe(0),M(x=>x.filter((W,Ie)=>Ie!==T)),o("shop_remove"))}}return}if(r==="event"&&v&&s){if(d.upArrow)H(c=>Math.max(0,c-1));else if(d.downArrow)H(c=>Math.min(v.choices.length-1,c+1));else if(d.return){let c=v.choices[G],p=s;switch(c.effect.type){case"heal":p=St(p,c.effect.value);break;case"damage":{p={...p,gateHp:Math.max(1,p.gateHp-c.effect.value)};let x=c.label.match(/(\d+)\s*fragments/i);x&&(p=pt(p,parseInt(x[1])));break}case"fragments":p=pt(p,c.effect.value);break;case"max_hp":p={...p,gateMaxHp:p.gateMaxHp+c.effect.value};break;case"card_reward":{let x=c.label.match(/lose\s+(\d+)\s*hp/i);x&&(p={...p,gateHp:Math.max(1,p.gateHp-parseInt(x[1]))});let W=j(we(s.seed+(v?.id??"")));I(It(W)),m(0),f(p),$(p),o("reward");return}case"remove_card":{f(p),$(p),Fe(0),o("deck_remove");return}case"nothing":break}f(p),$(p),k(0),o("map")}return}if(r==="rest"&&s){if(d.upArrow)N(c=>Math.max(0,c-1));else if(d.downArrow)N(c=>Math.min(2,c+1));else if(d.return){let c=s;C===0?(c=St(c,Math.floor(c.gateMaxHp*.3)),f(c),$(c),k(0),o("map")):C===1&&c.deck.length>5?(f(c),Fe(0),o("deck_remove")):(f(c),$(c),k(0),o("map"))}return}if(r==="deck_remove"&&s){if(d.upArrow)Fe(c=>Math.max(0,c-1));else if(d.downArrow)Fe(c=>Math.min(s.deck.length-1,c+1));else if(d.escape||u==="q")k(0),o("map");else if(d.return&&s.deck.length>5){let c=s.deck[Nt];if(c){let p=ua(s,c.instanceId);f(p),$(p)}k(0),o("map")}return}if(r==="shop_remove"&&s){if(d.upArrow)Fe(c=>Math.max(0,c-1));else if(d.downArrow)Fe(c=>Math.min(s.deck.length-1,c+1));else if(d.escape||u==="q")o("shop");else if(d.return&&s.deck.length>5){let c=s.deck[Nt];if(c){let p=ua(s,c.instanceId);f(p),$(p)}o("shop")}return}if(r==="keep"&&D){if(d.leftArrow||d.upArrow)Me(c=>(c-1+Ue.length)%Ue.length),ee("");else if(d.rightArrow||d.downArrow)Me(c=>(c+1)%Ue.length),ee("");else if(u==="q")o("menu");else if(d.return){let c=Ue[Te];if(!c)return;if(c.type==="structure"){let p=Qe.find(W=>W.id===c.id);if(!p)return;let x=mn(D,p.id);if(x){F(x);let W=_e();W.keep=x,Se(W),xe(W),ee(`Upgraded ${p.name}!`)}else et(D,p.id)>=p.maxLevel?ee(`${p.name} is already max level.`):ee(`Not enough Echoes to upgrade ${p.name}.`)}else if(c.type==="npc"){let p=D.npcs.find(W=>W.id===c.id);if(!p)return;let x=pn(p.id,D);if(x){let W=fn(D,p.id,x.dialogueId);F(W);let Ie=_e();Ie.keep=W,Se(Ie),xe(Ie),ee(`${x.speaker}: "${x.text}"`)}else ee("(No new dialogue)")}else c.type==="gate"&&Jt()}return}if(r==="result"){d.return||u===" "?Ga():u==="q"&&o("menu");return}if(r==="combat"&&V){if(V.outcome!=="undecided"){(d.return||u===" ")&&yr();return}if(Kt&&V.turn>1&&Ra(null),u==="i"){$t?Vt(!1):(Vt(!0),Lt(0),Ot(0));return}if($t){if(d.leftArrow)Lt(c=>Math.max(0,c-1));else if(d.rightArrow)Lt(c=>Math.min(4,c+1));else if(d.upArrow)Ot(c=>Math.max(0,c-1));else if(d.downArrow){let c=(V.columns[bt]?.enemies.length??1)-1;Ot(p=>Math.min(Math.max(0,c),p+1))}else d.escape&&Vt(!1);return}if(u==="q"){o("menu");return}if(u==="d"&&s){Ma("combat"),o("deck");return}if(u==="e"){ir();return}if(u==="p"&&s){let c=s.potions.findIndex(p=>p!==null);if(c>=0){let p=ln(s,c);if(p&&Gt.combat){let x=Ze.find(W=>W.id===p.potionId);f(p.run),$(p.run),Gt.applyPotion(x??null)}}return}if(u>="1"&&u<="9"){Yt(!1),Ea(parseInt(u)-1);return}if(d.leftArrow){Pa(Math.max(0,Wt-1));return}if(d.rightArrow){Pa(Math.min(4,Wt+1));return}if(d.return&&wt>=0){sr();return}if(u===" "){if(V.resolve>0&&V.hand.some(c=>{let p=U(c.defId);return p&&p.cost<=V.resolve})&&!Ba){Yt(!0);return}Yt(!1),lr();return}if(d.escape){Ea(-1);return}}}),fr)return _(ye,{flexDirection:"column",padding:1,children:[b(y,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),_(y,{color:"red",children:["Terminal too small (",a,"x",n,", need ",Qn,"x",er,")"]})]});if(r==="menu")return _(ye,{flexDirection:"column",padding:1,children:[b(y,{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"}),b(y,{bold:!0,color:"yellow",children:"\u2502 \u25C6 CodeKeep \u2014 The Pale \u2502"}),b(y,{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"}),b(y,{children:" "}),(st==="true_ending"?["The fortress. The Pale. You can no longer tell which side you're on."]:st==="truth"?["The fortress stands. The Pale stands. The line between them blurs."]:st==="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((d,c)=>b(y,{dimColor:!0,italic:!0,children:d},c)),b(y,{children:" "}),Zt.map((d,c)=>{let p=c===l;return _(y,{bold:p,color:p?"yellow":"white",children:[p?" \u25B6 ":" ",d.label]},d.action)}),b(y,{children:" "}),b(y,{dimColor:!0,children:"\u2191\u2193 navigate Enter select q exit"})]});if(r==="tutorial")return b(Yn,{page:Aa,totalPages:gt});if(r==="controls")return b(Jn,{});if(r==="settings"){let u={totalRuns:ce?.keep.totalRuns??0,totalWins:ce?.keep.totalWins??0,highestAscension:ce?.keep.highestAscension??0,echoes:ce?.keep.echoes??0,hasSave:!!ce};return b(Xn,{settings:ot,selectedIndex:Ha,saveInfo:u,confirmingReset:Na,message:pr})}if(r==="deck"&&s)return b(Rn,{deck:s.deck});if(r==="keep"&&D)return b(Kn,{keep:D,selectedId:Ue[Te]?.id??"forge",message:he,isFirstVisit:Xt});if((r==="deck_remove"||r==="shop_remove")&&s)return _(ye,{flexDirection:"column",padding:1,children:[b(y,{bold:!0,color:"red",children:"\u25C6 Remove a Card"}),_(y,{dimColor:!0,children:["Choose a card to remove from your deck (",s.deck.length," cards)."]}),b(y,{children:" "}),s.deck.map((u,d)=>{let c=U(u.defId),p=d===Nt;return _(y,{bold:p,color:p?"yellow":"white",children:[p?"\u25B6 ":" ",c?.name??u.defId," (",c?.rarity,") \u2014 ",c?.description??""]},u.instanceId)}),b(y,{children:" "}),b(y,{dimColor:!0,children:"\u2191\u2193 navigate Enter remove Esc cancel"})]});if(r==="map"&&s){let u=Wa();return _(ye,{flexDirection:"column",children:[_(ye,{justifyContent:"space-between",paddingX:1,children:[_(y,{children:["Gate ",_(y,{bold:!0,color:s.gateHp>40?"green":s.gateHp>20?"yellow":"red",children:[s.gateHp,"/",s.gateMaxHp]})]}),_(y,{children:["Fragments ",b(y,{bold:!0,color:"yellow",children:s.fragments})]}),s.potions.filter(d=>d!==null).length>0&&_(y,{children:["Potions ",b(y,{color:"magenta",children:s.potions.filter(d=>d!==null).length})]}),s.relics.length>0&&_(y,{children:["Relics ",_(y,{color:"magenta",children:["\u2605",s.relics.length]})]}),_(y,{children:["Deck ",b(y,{dimColor:!0,children:s.deck.length})]})]}),Xt&&ot.showTutorialHints&&!s.currentNodeId&&b(y,{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."}),b(Dn,{map:s.map,currentNodeId:s.currentNodeId,reachableIds:u.map(d=>d.id),selectedNodeId:u[h]?.id??null})]})}if(r==="reward")return b(Pn,{cards:E,selectedIndex:re});if(r==="relic_reward")return _(ye,{flexDirection:"column",padding:1,children:[b(y,{bold:!0,color:"magenta",children:"\u25C6 Relic Reward"}),b(y,{dimColor:!0,children:"\u2500".repeat(36)}),b(y,{dimColor:!0,italic:!0,children:"An artifact resonates from the defeated foe."}),b(y,{children:" "}),We.map((u,d)=>{let c=d===Ye;return _(ye,{flexDirection:"column",children:[_(y,{children:[b(y,{bold:c,color:c?"yellow":"white",children:c?" \u25B6 ":" "}),_(y,{color:c?"magenta":"white",bold:c,children:["\u2605 ",u.name]})]}),c&&_(y,{dimColor:!0,children:[" ",u.description]})]},u.id)}),b(y,{children:" "}),_(y,{bold:Ye===We.length,color:Ye===We.length?"yellow":"white",children:[Ye===We.length?" \u25B6 ":" ","Skip"]}),b(y,{children:" "}),s&&s.relics.length>0&&_(ye,{children:[b(y,{dimColor:!0,children:"Relics: "}),b(y,{color:"magenta",children:s.relics.join(" \xB7 ")})]}),b(y,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]});if(r==="shop"&&s)return b(Bn,{items:g,selectedIndex:T,fragments:s.fragments,message:ur});if(r==="event"&&v)return b(Hn,{event:v,selectedChoice:G});if(r==="rest"&&s)return b(Gn,{gateHp:s.gateHp,gateMaxHp:s.gateMaxHp,selectedChoice:C,deckSize:s.deck.length});if(r==="result"){let u=s?ha(B,s.act,s.ascensionLevel):0;return _(ye,{flexDirection:"column",padding:1,children:[B?_(Sa,{children:[b(y,{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"}),b(y,{bold:!0,color:"green",children:"\u2502 \u2605 RUN COMPLETE \u2502"}),b(y,{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"}),b(y,{children:" "}),b(y,{italic:!0,children:"The Pale recedes. The Keep endures."}),b(y,{italic:!0,dimColor:!0,children:"Another dawn. Another day of resistance."})]}):_(Sa,{children:[b(y,{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"}),b(y,{bold:!0,color:"red",children:"\u2502 \u2717 DEFEAT \u2502"}),b(y,{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"}),b(y,{children:" "}),b(y,{italic:!0,children:"The Gate has fallen. The Pale consumes all."}),b(y,{italic:!0,dimColor:!0,children:"But the Keep remembers. It always remembers."})]}),b(y,{children:" "}),s&&_(Sa,{children:[b(y,{dimColor:!0,children:"\u2500".repeat(32)}),_(y,{children:[" ","Act ",b(y,{bold:!0,children:s.act})," ","Deck ",_(y,{dimColor:!0,children:[s.deck.length," cards"]})," ","Fragments ",b(y,{dimColor:!0,children:s.fragments})]}),_(y,{children:[" ","Echoes earned ",_(y,{bold:!0,color:"cyan",children:["+",u]})]}),b(y,{dimColor:!0,children:"\u2500".repeat(32)})]}),b(y,{children:" "}),b(y,{dimColor:!0,children:"Enter \u2192 The Keep | q \u2192 menu"})]})}if(r==="combat"&&V&&s){let u=Xt&&ot.showTutorialHints&&V.turn<=3?V.turn===1&&wt<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&&wt>=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 _(ye,{flexDirection:"column",paddingX:1,children:[_(y,{dimColor:!0,children:["Act ",s.act," | Gate ",s.gateHp,"/",s.gateMaxHp," | Fragments ",s.fragments,s.potions.filter(d=>d!==null).length>0&&` | Potions ${s.potions.filter(d=>d!==null).map(d=>Ze.find(p=>p.id===d)?.name??d).join(", ")}`,s.relics.length>0&&` | \u2605 ${s.relics.length}`," | d=deck i=inspect"]}),u&&b(y,{color:"green",bold:!0,children:u}),Kt&&b(ye,{borderStyle:"single",borderColor:"magenta",paddingX:1,marginBottom:1,children:_(y,{color:"magenta",italic:!0,children:['"',Kt,'"']})}),b(Cn,{combat:V,selectedCard:wt,targetColumn:Wt,needsTarget:cr,message:Ba?`End turn with ${V.resolve} Resolve remaining? Press Space again to confirm.`:or}),$t&&(()=>{let c=V.columns[bt]?.enemies[dr];if(!c)return _(y,{dimColor:!0,children:["No enemy in column ",bt+1,". \u2190\u2192 to navigate."]});let p=Pe(c.templateId);return _(ye,{flexDirection:"column",borderStyle:"single",borderColor:"cyan",paddingX:1,children:[_(y,{bold:!0,color:"cyan",children:["Inspecting: ",p?.name??c.templateId," (Col ",bt+1,")"]}),_(y,{children:["HP: ",c.hp,"/",c.maxHp," Row: ",c.row]}),b(y,{dimColor:!0,children:p?.description??""}),c.statusEffects.length>0&&_(y,{children:["Status: ",c.statusEffects.map(x=>`${x.type}(${x.stacks}x, ${x.duration}t)`).join(", ")]}),_(y,{children:["Intent: ",c.intent?`${c.intent.type} ${c.intent.value}`:"unknown"]}),b(y,{dimColor:!0,children:"\u2190\u2192 column \u2191\u2193 enemy i/Esc close"})]})})()]})}return b(y,{children:"Loading..."})}function tr(e){return b(Et,{children:b(jo,{...e})})}import{jsx as Zo}from"react/jsx-runtime";var ar="0.5.0";globalThis.__CODEKEEP_VERSION=ar;var nr=new Xo;nr.name("codekeep").description("CodeKeep: The Pale \u2014 deck-building tactical roguelike in your terminal").version(ar).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=${t}&body=${a}&labels=bug,crash`}import{Fragment as Tn,jsx as he,jsxs as Ke}from"react/jsx-runtime";var Rt=class extends fo.Component{constructor(t){super(t),this.state={error:null,crashFilePath:null,issueUrl:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){try{let a=kn(t),n={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=xn(n);this.setState({crashFilePath:a,issueUrl:r})}catch{}}render(){return this.state.error?Ke(ho,{flexDirection:"column",padding:1,children:[he(ae,{bold:!0,color:"red",children:"\u25C6 CodeKeep \u2014 Something went wrong"}),he(ae,{children:" "}),he(ae,{color:"red",children:this.state.error.message}),he(ae,{children:" "}),he(ae,{dimColor:!0,children:"Your save file is at:"}),Ke(ae,{children:[" ","~/.config/codekeep/game.json"]}),he(ae,{children:" "}),this.state.crashFilePath&&Ke(Tn,{children:[he(ae,{dimColor:!0,children:"Crash report saved to:"}),Ke(ae,{children:[" ",this.state.crashFilePath]}),he(ae,{children:" "})]}),this.state.issueUrl&&Ke(Tn,{children:[he(ae,{dimColor:!0,children:"Report this bug:"}),Ke(ae,{color:"cyan",children:[" ",this.state.issueUrl]}),he(ae,{children:" "})]}),he(ae,{dimColor:!0,children:"If the game won't start, try:"}),Ke(ae,{bold:!0,children:[" ","codekeep --tutorial"]}),he(ae,{children:" "}),he(ae,{dimColor:!0,children:"Press Ctrl+C to exit"})]}):this.props.children}};import{Box as Dt,Text as ie}from"ink";import At from"react";import{Box as _n,Text as $}from"ink";import{jsx as j,jsxs as ke}from"react/jsx-runtime";function go(e){if(!e)return{text:"",color:"white"};switch(e.type){case"advance":return{text:"\u2193Mv",color:"white"};case"attack":return{text:`\u2694${e.value}`,color:"red"};case"buff":return{text:"\u25B2Buff",color:"magenta"};case"debuff":return{text:"\u25BCHex",color:"magenta"};case"shield":return{text:"\u25C8Shd",color:"blue"};case"summon":return{text:"+Call",color:"magenta"};default:return{text:"",color:"white"}}}function yo(e){let t=[];for(let a of e.statusEffects)switch(a.type){case"vulnerable":t.push({text:`vul${a.stacks}`,color:"yellow"});break;case"weak":t.push({text:`wk${a.stacks}`,color:"green"});break;case"burn":t.push({text:`\u{1F525}${a.stacks}`,color:"red"});break;case"empowered":t.push({text:`pwr${a.stacks}`,color:"magenta"});break;case"fortified":t.push({text:`frt${a.stacks}`,color:"blue"});break}return t}function bo(e,t,a){let n=Math.max(0,Math.min(a,Math.round(e/t*a)));return"\u2588".repeat(n)+"\u2591".repeat(Math.max(0,a-n))}function In({columns:e,targetColumn:t,showTarget:a,gateHp:n,gateMaxHp:r,gateBlock:o}){let i=e.length,s=14*i+(i-1),f=r>0?Math.round(n/r*100):0,y=f>60?"green":f>30?"yellow":"red",k="t h e p a l e",E=s+2,S=Math.floor((E-k.length)/2),D=E-S-k.length,m="\xB7 ".repeat(40),h=m.slice(0,S)+k+m.slice(0,D),B="\u250C"+Array.from({length:i},(ne,w)=>"\u2500".repeat(14)+(w<i-1?"\u252C":"")).join("")+"\u2510",T="\u255E"+Array.from({length:i},(ne,w)=>"\u2550".repeat(14)+(w<i-1?"\u256A":"")).join("")+"\u2561",G="\u2558"+Array.from({length:i},(ne,w)=>"\u2550".repeat(14)+(w<i-1?"\u2567":"")).join("")+"\u255B",N=` \u25C6 GATE ${bo(n,r,20)} ${n}/${r}`,De=o>0?` \u25C7${o}`:"";return ke(_n,{flexDirection:"column",children:[j($,{dimColor:!0,children:h}),j($,{dimColor:!0,children:B}),a&&ke($,{children:[j($,{dimColor:!0,children:"\u2502"}),e.map((ne,w)=>{let b=w===t,x=b?"\u25BC":"",_=x.padStart(Math.ceil((14+x.length)/2)).padEnd(14);return ke(At.Fragment,{children:[j($,{color:b?"yellow":void 0,bold:b,children:_}),j($,{dimColor:!0,children:"\u2502"})]},w)})]}),Array.from({length:Ze},(ne,w)=>ke($,{children:[j($,{dimColor:!0,children:"\u2502"}),e.map((b,x)=>{let _=b.enemies.filter(le=>le.row===w),H=a&&x===t;if(_.length===0){let le="\xB7".padStart(Math.floor(7.5)).padEnd(14);return ke(At.Fragment,{children:[j($,{children:le}),j($,{dimColor:!0,children:"\u2502"})]},x)}let L=_[0],ue=Be(L.templateId)?.symbol??"?",J=go(L.intent),W=yo(L),P=`${L.hp}`,te=ue.length+P.length+1+(J.text?J.text.length+1:0),Ie=W.reduce((le,Le)=>le+Le.text.length+1,0),wt=te+Ie<=14;return ke(At.Fragment,{children:[j($,{color:H?"yellow":"red",bold:!0,children:ue}),j($,{color:H?"yellow":"white",children:P}),J.text?ke($,{color:J.color,children:[" ",J.text]}):null,wt&&W.map((le,Le)=>ke($,{color:le.color,children:[" ",le.text]},Le)),j($,{children:" ".repeat(Math.max(0,14-te-(wt?Ie:0)))}),j($,{dimColor:!0,children:"\u2502"})]},x)})]},w)),j($,{children:T}),ke($,{children:[j($,{dimColor:!0,children:"\u2502"}),e.map((ne,w)=>{let b;return ne.emplacement?b=` \u25C7${Y(ne.emplacement.cardDefId)?.name??"Wall"} ${ne.emplacement.hp}hp `.padEnd(14).slice(0,14):b=" ".repeat(14),ke(At.Fragment,{children:[j($,{color:ne.emplacement?"cyan":void 0,children:b}),j($,{dimColor:!0,children:"\u2502"})]},w)})]}),j($,{children:G}),ke(_n,{paddingX:1,children:[j($,{bold:!0,color:y,children:N}),o>0&&j($,{color:"cyan",children:De})]})]})}import{Box as Cn,Text as Ae}from"ink";import{jsx as Mt,jsxs as Ge}from"react/jsx-runtime";function wo(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function vo(e){switch(e){case"armament":return"\u2694";case"fortification":return"\u25C7";case"edict":return"\u2726";case"wild":return"\u25C8";default:return"\xB7"}}function ko(e,t){let a=[];for(let n=0;n<e;n++)a.push(Mt(Ae,{color:n<t?"cyan":"red",bold:!0,children:"\u25C6"},n));return a}function xo(e){let t=[];for(let a of e.effects)switch(a.type){case"damage":t.push(`${a.value} dmg${a.target==="all"?" ALL":a.target==="column"?" col":""}`);break;case"block":t.push(`${a.value} blk`);break;case"draw":t.push(`+${a.value} draw`);break;case"heal":t.push(`${a.value} heal`);break;case"resolve":t.push(`+${a.value} res`);break;case"burn":t.push(`${a.value} burn`);break;case"vulnerable":t.push(`${a.value} vuln`);break;case"weak":t.push(`${a.value} weak`);break;case"self_damage":t.push(`${a.value} self-dmg`);break;case"damage_if_vulnerable":t.push(`${a.value} dmg (\xD72 if vuln)`);break;case"damage_equal_block":t.push("dmg=blk");break;case"damage_per_burn":t.push(`${a.value}\xD7burn dmg`);break;case"trigger_emplacements":t.push("trigger walls");break;case"damage_plus_block":t.push(`${a.value} dmg+blk`);break;case"exhaust_draw":t.push(`exile+${a.value} draw`);break;case"damage_if_emplaced":t.push(`${a.value} dmg if wall`);break;case"damage_per_emplace":t.push(`${a.value}\xD7wall dmg`);break;default:break}return t.join(", ")}function Sn({hand:e,selectedIndex:t,resolve:a}){return e.length===0?Ge(Ae,{dimColor:!0,children:[" ","No cards in hand."]}):Ge(Cn,{flexDirection:"column",children:[Mt(Ae,{dimColor:!0,children:"\u2500\u2500\u2500 Hand ("+e.length+") \u2500\u2500\u2500"}),e.map((n,r)=>{let o=Y(n.defId);if(!o)return null;let l=r===t,i=o.cost<=a,s=xo(o);return Ge(Cn,{flexDirection:"column",children:[Ge(Ae,{children:[Mt(Ae,{bold:l,color:l?"yellow":"white",children:l?" \u25B6 ":" "}),Ge(Ae,{color:i?wo(o.rarity):"gray",bold:l,children:[vo(o.category)," ",o.name]}),Mt(Ae,{children:" "}),ko(o.cost,a),Ge(Ae,{dimColor:!0,children:[" ",s]}),l&&o.type==="emplace"&&Ge(Ae,{color:"cyan",children:[" ","[emplaceable]"]})]}),l&&Ge(Ae,{dimColor:!0,children:[" ",o.description]})]},n.instanceId)})]})}import{jsx as ge,jsxs as We}from"react/jsx-runtime";function To(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 ${Y(e.data.cardId)?.name??e.data.cardId}`;case"turn_start":return`\u2500 Turn ${e.data.turn} \u2500`;default:return""}}function En({combat:e,selectedCard:t,targetColumn:a,needsTarget:n,message:r,animating:o=!1}){let l=e.columns.reduce((i,s)=>i+s.enemies.length,0);return We(Dt,{flexDirection:"column",children:[We(Dt,{justifyContent:"space-between",children:[ge(ie,{bold:!0,color:"yellow",children:"\u25C6 The Pale"}),We(ie,{children:["Turn ",ge(ie,{bold:!0,color:"white",children:e.turn})," ",ge(ie,{color:"cyan",children:"\u25C6".repeat(Math.max(0,e.resolve))}),ge(ie,{dimColor:!0,children:"\u25C7".repeat(Math.max(0,e.maxResolve-e.resolve))})," ","Enemies ",ge(ie,{bold:!0,color:"red",children:l})," ","Draw ",ge(ie,{dimColor:!0,children:e.drawPile.length})," / ","Discard ",ge(ie,{dimColor:!0,children:e.discardPile.length})]})]}),ge(In,{columns:e.columns,targetColumn:a,showTarget:n&&t>=0,gateHp:e.gateHp,gateMaxHp:e.gateMaxHp,gateBlock:e.gateBlock}),ge(Sn,{hand:e.hand,selectedIndex:t,resolve:e.resolve}),(()=>{let i=e.events.filter(s=>s.turn>=e.turn-1).slice(-5);return i.length===0?null:We(Dt,{flexDirection:"column",marginTop:0,children:[ge(ie,{dimColor:!0,children:"\u2500\u2500\u2500 Log \u2500\u2500\u2500"}),i.map((s,f)=>{let y=To(s);if(!y)return null;let k=s.type==="turn_start";return ge(ie,{dimColor:!k,color:k?"white":void 0,children:y},f)})]})})(),r&&We(ie,{color:o?"red":"yellow",bold:!0,children:[" ",o?"\u26A1 ":"",r]}),e.phase==="player"&&!o&&We(ie,{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"]}),o&&We(ie,{dimColor:!0,children:[" ","Resolving enemy actions..."]}),e.outcome!=="undecided"&&We(Dt,{flexDirection:"column",marginTop:1,paddingX:1,children:[ge(ie,{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."}),ge(ie,{dimColor:!0,children:"Press Enter to continue."})]})]})}import{Box as Pn,Text as fe}from"ink";import{jsx as He,jsxs as Ue}from"react/jsx-runtime";function Rn(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function _o(e){switch(e){case"uncommon":return"\u25C7 uncommon";case"rare":return"\u25C6 rare";case"legendary":return"\u2605 legendary";default:return"\xB7 common"}}function Io(e){switch(e){case"armament":return"\u2694";case"fortification":return"\u25C7";case"edict":return"\u2726";case"wild":return"\u25C8";default:return"\xB7"}}function An({cards:e,selectedIndex:t}){let a=t>=e.length;return Ue(Pn,{flexDirection:"column",padding:1,children:[He(fe,{bold:!0,color:"yellow",children:"\u25C6 Card Reward"}),He(fe,{dimColor:!0,children:"\u2500".repeat(36)}),He(fe,{dimColor:!0,italic:!0,children:"Choose a card to add to your deck."}),He(fe,{children:" "}),e.map((n,r)=>{let o=r===t;return Ue(Pn,{flexDirection:"column",marginBottom:0,children:[Ue(fe,{children:[He(fe,{bold:o,color:o?"yellow":"white",children:o?" \u25B6 ":" "}),Ue(fe,{color:Rn(n.rarity),bold:o,children:[Io(n.category)," ",n.name]}),Ue(fe,{dimColor:!0,children:[" ","[",n.cost,"]"," "]}),He(fe,{color:Rn(n.rarity),dimColor:!0,children:_o(n.rarity)})]}),o&&Ue(fe,{dimColor:!0,children:[" ",n.description]})]},n.id)}),He(fe,{children:" "}),Ue(fe,{bold:a,color:a?"yellow":"white",children:[a?" \u25B6 ":" ","Skip"]}),He(fe,{children:" "}),He(fe,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]})}import{Box as Co,Text as gt}from"ink";import{jsx as xa,jsxs as ka}from"react/jsx-runtime";function So(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function Mn({deck:e}){let t=new Map;for(let n of e)t.set(n.defId,(t.get(n.defId)??0)+1);let a=[...t.entries()].map(([n,r])=>({def:Y(n),count:r})).filter(n=>n.def).sort((n,r)=>{let o={common:0,uncommon:1,rare:2,legendary:3},l=o[n.def.rarity]??0,i=o[r.def.rarity]??0;return l!==i?l-i:n.def.name.localeCompare(r.def.name)});return ka(Co,{flexDirection:"column",padding:1,children:[ka(gt,{bold:!0,color:"yellow",children:["\u25C6 Your Deck"," (",e.length," cards)"]}),xa(gt,{children:" "}),a.map(({def:n,count:r})=>ka(gt,{color:So(n.rarity),children:[r>1?`${r}x `:" ",n.name," [",n.cost,"] \u2014 ",n.description]},n.id)),xa(gt,{children:" "}),xa(gt,{dimColor:!0,children:"Press q or Esc to go back."})]})}import Eo from"react";import{Box as Dn,Text as ce}from"ink";import{jsx as de,jsxs as Ta}from"react/jsx-runtime";var Bn=6,Po=4,Bt=(Po-1)*Bn+6;function _a(e){return e*Bn+3}function Ro(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 Ao(e,t,a,n){if(n)return"cyan";if(a)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 Mo(e,t,a,n){let r=[],o=0,l=[...e].sort((i,s)=>i.column-s.column);for(let i of l){let s=_a(i.column),f=Ro(i.type),y=i.id===t,k=i.id===a,E=y?`[${f}]`:k?`(${f})`:` ${f} `,S=s-Math.floor(E.length/2);S>o&&r.push({text:" ".repeat(S-o)}),r.push({text:E,color:Ao(i,n.has(i.id),y,k),bold:y||k,dim:i.visited&&!k&&!y}),o=S+E.length}return r}function Do(e,t){let a=Array(Bt).fill(" "),n=new Map;function r(o,l){o<0||o>=Bt||(n.has(o)||n.set(o,new Set),n.get(o).add(l))}for(let o of e){let l=_a(o.column);for(let i of o.connections){let s=t.find(y=>y.id===i);if(!s)continue;let f=_a(s.column);l===f?r(l,"\u2502"):r(Math.round((l+f)/2),f>l?"\u2572":"\u2571")}}for(let[o,l]of n)l.has("\u2572")&&l.has("\u2571")?a[o]="\u2573":l.has("\u2502")?a[o]="\u2502":l.has("\u2572")?a[o]="\u2572":l.has("\u2571")&&(a[o]="\u2571");return a.join("")}function Hn({map:e,currentNodeId:t,reachableIds:a,selectedNodeId:n}){let r=new Set(a),o=Math.max(...e.nodes.map(i=>i.row)),l=[];for(let i=0;i<=o;i++)l.push(e.nodes.filter(s=>s.row===i).sort((s,f)=>s.column-f.column));return Ta(Dn,{flexDirection:"column",padding:1,children:[de(ce,{bold:!0,color:"yellow",children:"\u25C6 Act "+e.act+" \u2014 Choose your path"}),de(ce,{dimColor:!0,children:"\u2500".repeat(Bt)}),de(ce,{children:" "}),l.map((i,s)=>{let f=Mo(i,n,t,r);return Ta(Eo.Fragment,{children:[de(ce,{children:f.map((y,k)=>de(ce,{color:y.color,bold:y.bold,dimColor:y.dim,children:y.text},k))}),s<o&&de(ce,{dimColor:!0,children:Do(i,l[s+1]??[])})]},s)}),de(ce,{children:" "}),de(ce,{dimColor:!0,children:"\u2500".repeat(Bt)}),Ta(Dn,{gap:2,children:[de(ce,{dimColor:!0,children:"\u2694 fight"}),de(ce,{dimColor:!0,color:"red",children:"\u2605 elite"}),de(ce,{dimColor:!0,color:"green",children:"\u25B3 rest"}),de(ce,{dimColor:!0,color:"yellow",children:"$ shop"}),de(ce,{dimColor:!0,color:"magenta",children:"? event"}),de(ce,{dimColor:!0,color:"red",children:"\u25C6 boss"})]}),de(ce,{dimColor:!0,children:"\u2191\u2193 select Enter proceed d deck q quit"})]})}import{Box as Bo,Text as Fe}from"ink";import{jsx as rt,jsxs as Ia}from"react/jsx-runtime";function Nn({items:e,selectedIndex:t,fragments:a,message:n}){return Ia(Bo,{flexDirection:"column",padding:1,children:[Ia(Fe,{bold:!0,color:"yellow",children:["\u25C6 Shop \u2014 ",a," fragments"]}),rt(Fe,{dimColor:!0,children:"\u2500".repeat(36)}),rt(Fe,{children:" "}),e.map((r,o)=>{let l=o===t,i=a>=r.cost,s="",f="";return r.type==="card"&&r.cardDef?(f="[Card]",s=`${r.cardDef.name} (${r.cardDef.rarity}) \u2014 ${r.cardDef.description}`):r.type==="potion"&&r.potionDef?(f="[Potion]",s=`${r.potionDef.name} \u2014 ${r.potionDef.description}`):r.type==="card_remove"&&(f="[Service]",s="Remove a card from your deck"),Ia(Fe,{bold:l,color:l?"yellow":i?"white":"gray",children:[l?"\u25B6 ":" ",f," ",s," [",r.cost,"f]"]},o)}),e.length===0&&rt(Fe,{dimColor:!0,children:" (Shop is empty)"}),rt(Fe,{children:" "}),n&&rt(Fe,{color:"red",children:n}),rt(Fe,{dimColor:!0,children:"\u2191\u2193 navigate Enter buy q leave"})]})}import{Box as Ho,Text as qe}from"ink";import{jsx as yt,jsxs as Ca}from"react/jsx-runtime";function Gn({event:e,selectedChoice:t}){return Ca(Ho,{flexDirection:"column",padding:1,children:[Ca(qe,{bold:!0,color:"magenta",children:["\u25C6 ",e.name]}),yt(qe,{children:" "}),yt(qe,{children:e.description}),yt(qe,{children:" "}),e.choices.map((a,n)=>Ca(qe,{bold:n===t,color:n===t?"yellow":"white",children:[n===t?"\u25B6 ":" ",n+1,". ",a.label]},n)),yt(qe,{children:" "}),yt(qe,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as Wn,Text as ye}from"ink";import{jsx as xe,jsxs as Ht}from"react/jsx-runtime";function Fn({gateHp:e,gateMaxHp:t,selectedChoice:a,deckSize:n}){let r=Math.floor(t*.3),o=Math.min(t,e+r),l=n>5,i=[{label:"Rest",detail:`Heal ${r} Gate HP (${e} \u2192 ${o}/${t})`,color:"green",available:!0},{label:"Thin",detail:l?`Remove a card from your deck (${n} cards)`:`Minimum deck size reached (${n} cards)`,color:"cyan",available:l},{label:"Leave",detail:"Continue without resting",color:"white",available:!0}];return Ht(Wn,{flexDirection:"column",padding:1,children:[xe(ye,{bold:!0,color:"green",children:"\u25C6 Rest Site"}),xe(ye,{dimColor:!0,children:"\u2500".repeat(36)}),xe(ye,{children:" "}),xe(ye,{dimColor:!0,italic:!0,children:"The campfire crackles against the encroaching Pale."}),xe(ye,{dimColor:!0,italic:!0,children:"A moment of warmth in the endless grey."}),xe(ye,{children:" "}),i.map(({label:s,detail:f,color:y,available:k},E)=>{let S=E===a;return Ht(Wn,{flexDirection:"column",children:[Ht(ye,{children:[xe(ye,{bold:S,color:S?"yellow":"white",children:S?" \u25B6 ":" "}),xe(ye,{color:k?S?y:"white":"gray",bold:S,dimColor:!k,children:s}),!k&&xe(ye,{dimColor:!0,children:" (unavailable)"})]}),S&&Ht(ye,{dimColor:!0,children:[" ",f]})]},E)}),xe(ye,{children:" "}),xe(ye,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as ot,Text as ee}from"ink";import{jsx as se,jsxs as $e}from"react/jsx-runtime";var Kn=[{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:"+"}],Un=[{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:"?"}],No={type:"gate",id:"gate",name:"The Gate",symbol:">"},Ye=[...Kn,...Un,No],Go={wren:"Wren, the Steward",sable:"Sable, the Archivist",duskmar:"Duskmar, First Wall",mott:"Mott, the Salvager",pale_visitor:"The Pale Visitor"},Wo={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"},$n=17,Vn=56,oe=1,Z=15,K=3,X=52,Fo={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}},$o={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 Sa(e,t){return e>=t?"green":e>=2?"cyan":e>=1?"yellow":"white"}function Ln(e){return e>=4?"magenta":e>=2?"cyan":e>=1?"yellow":"white"}function On(e,t,a){let n=[];for(let r=0;r<t;r++)n.push(r<e?se(ee,{color:a,bold:!0,children:"\u25C6"},r):se(ee,{dimColor:!0,children:"\u25C7"},r));return n}function qn({keep:e,selectedId:t,message:a,isFirstVisit:n}){let r=[],o=[];for(let m=0;m<$n;m++){let h=[],B=[];for(let T=0;T<Vn;T++)h.push((m+T)%2===0?"~":" "),B.push({color:"white",bold:!1,dim:!0});r.push(h),o.push(B)}let l="the pale",i=Math.floor((Vn-l.length)/2);for(let m=0;m<l.length;m++)r[0][i+m]=l[m],r[$n-1][i+m]=l[m];r[oe][K]="\u2554",r[oe][X]="\u2557",r[Z][K]="\u255A",r[Z][X]="\u255D";for(let m=K+1;m<X;m++)r[oe][m]="\u2550",r[Z][m]="\u2550",o[oe][m]={color:"white",bold:!1,dim:!0},o[Z][m]={color:"white",bold:!1,dim:!0};for(let m=oe+1;m<Z;m++)r[m][K]="\u2551",r[m][X]="\u2551",o[m][K]={color:"white",bold:!1,dim:!0},o[m][X]={color:"white",bold:!1,dim:!0};for(let m of[[oe,K],[oe,X],[Z,K],[Z,X]])o[m[0]][m[1]]={color:"white",bold:!1,dim:!0};for(let m of[K+1,8,14,38,44,X-1])m>K&&m<X&&(r[oe][m]="\u25B2",o[oe][m]={color:"white",bold:!0,dim:!1});for(let m of[K+1,8,14,42,48,X-1])m>K&&m<X&&r[Z][m]==="\u2550"&&(r[Z][m]="\u25B2",o[Z][m]={color:"white",bold:!0,dim:!1});let s=" THE KEEP ",f=K+1+Math.floor((X-K-1-s.length)/2);for(let m=0;m<s.length;m++)r[oe][f+m]=s[m],o[oe][f+m]={color:"yellow",bold:!0,dim:!1};for(let m=oe+1;m<Z;m++)for(let h=K+1;h<X;h++)r[m][h]=" ",o[m][h]={color:"white",bold:!1,dim:!1};for(let[m,h]of[[oe+1,K+1],[oe+1,X-1],[Z-1,K+1],[Z-1,X-1]])r[m][h]="*",o[m][h]={color:"yellow",bold:!0,dim:!1};for(let m=K+2;m<X-1;m++)r[8][m]===" "&&(r[8][m]="\xB7",o[8][m]={color:"white",bold:!1,dim:!0});for(let m of[11,25,39])for(let h=6;h<=(m===39?8:10);h++)r[h][m]===" "&&(r[h][m]="\xB7",o[h][m]={color:"white",bold:!1,dim:!0});for(let m=9;m<Z;m++)r[m][28]===" "&&(r[m][28]="\xB7",o[m][28]={color:"white",bold:!1,dim:!0});for(let[m,h]of[[7,16],[7,34],[7,48],[9,8],[9,18],[9,36],[13,8],[13,18],[13,36]])m>oe&&m<Z&&r[m][h]===" "&&(r[m][h]="\xB7",o[m][h]={color:"white",bold:!1,dim:!0});for(let m of Kn){let h=Fo[m.id];if(!h)continue;let B=tt.find(P=>P.id===m.id),T=at(e,m.id),G=B?.maxLevel??3,N=m.id===t,De=N?"yellow":Sa(T,G),ne=N||T>=G,w=!N&&T===0,b=h.row,x=h.col,_=h.width,H=_-2,L=Math.ceil((H-m.name.length)/2),ue=H-m.name.length-L;r[b][x]=N?"\u250F":"\u250C";let J=x+1;for(let P=0;P<L;P++)r[b][J]=N?"\u2501":"\u2500",J++;for(let P=0;P<m.name.length;P++)r[b][J]=m.name[P],J++;for(let P=0;P<ue;P++)r[b][J]=N?"\u2501":"\u2500",J++;r[b][x+_-1]=N?"\u2513":"\u2510",r[b+1][x]=N?"\u2503":"\u2502";for(let P=1;P<_-1;P++)r[b+1][x+P]=" ";r[b+1][x+Math.floor(_/2)]=m.symbol,r[b+1][x+_-1]=N?"\u2503":"\u2502",r[b+2][x]=N?"\u2517":"\u2514";for(let P=1;P<_-1;P++)r[b+2][x+P]=N?"\u2501":"\u2500";r[b+2][x+_-1]=N?"\u251B":"\u2518";for(let P=0;P<3;P++)for(let te=0;te<_;te++)o[b+P][x+te]={color:De,bold:ne,dim:w};let W=b+3;if(W>oe&&W<Z){let P=x+Math.floor((_-G)/2);for(let te=0;te<G;te++)r[W][P+te]=te<T?"\u25C6":"\u25C7",o[W][P+te]={color:te<T?N?"yellow":Sa(T,G):"white",bold:te<T,dim:te>=T}}}for(let m of Un){let h=$o[m.id];if(!h)continue;let T=e.npcs.find(De=>De.id===m.id)?.tier??0,G=m.id===t,N=G?"yellow":Ln(T);G&&(h.col-1>K&&(r[h.row][h.col-1]="[",o[h.row][h.col-1]={color:"yellow",bold:!0,dim:!1}),h.col+1<X&&(r[h.row][h.col+1]="]",o[h.row][h.col+1]={color:"yellow",bold:!0,dim:!1})),r[h.row][h.col]=m.symbol,o[h.row][h.col]={color:N,bold:G||T>=3,dim:!1}}{let m=t==="gate",h=m?"\u2524 ENTER THE PALE \u251C":"\u2561 ENTER THE PALE \u255E",B=K+1+Math.floor((X-K-1-h.length)/2);for(let T=0;T<h.length;T++)r[Z][B+T]=h[T],o[Z][B+T]={color:m?"yellow":"green",bold:!0,dim:!1}}for(let m=11;m<=14;m++)for(let h=48;h<X;h++)(r[m][h]===" "||r[m][h]==="\xB7")&&(r[m][h]="~",o[m][h]={color:"white",bold:!1,dim:!0});let y=Ye.find(m=>m.id===t),k="",E="",S="cyan",D=null;if(y)if(y.type==="structure"){let m=tt.find(T=>T.id===y.id),h=at(e,y.id),B=m?.maxLevel??3;if(S=Sa(h,B),k=y.name,h>=B)E=`${m?.description??""} (fully upgraded)`;else{let T=m?.upgradeCost(h+1)??0;E=`${m?.description??""} \u2014 ${T} Echoes to upgrade`}D=$e(ee,{children:[" ",On(h,B,S)]})}else if(y.type==="npc"){let h=e.npcs.find(B=>B.id===y.id)?.tier??0;S=Ln(h),k=Go[y.id]??y.id,E=Wo[y.id]??"",D=$e(ee,{children:[" ",On(h,5,S)]})}else y.type==="gate"&&(S="green",k="The Gate",E="Step beyond the walls. Face the Pale.");return $e(ot,{flexDirection:"column",children:[$e(ot,{justifyContent:"space-between",paddingX:1,children:[se(ee,{bold:!0,color:"yellow",children:"\u25C6 The Keep"}),$e(ee,{children:["Echoes ",se(ee,{bold:!0,color:"cyan",children:e.echoes})," ","Runs ",se(ee,{dimColor:!0,children:e.totalRuns})," ","Wins ",se(ee,{dimColor:!0,children:e.totalWins})," ","Ascension ",se(ee,{dimColor:!0,children:e.highestAscension})]})]}),se(ot,{flexDirection:"column",children:r.map((m,h)=>se(ee,{children:m.map((B,T)=>{let G=o[h][T];return se(ee,{color:G.color,bold:G.bold,dimColor:G.dim,children:B},T)})},h))}),$e(ot,{flexDirection:"column",paddingX:1,children:[y?$e(ot,{flexDirection:"column",children:[$e(ot,{children:[se(ee,{bold:!0,color:S,children:k}),D]}),se(ee,{dimColor:!0,children:E})]}):se(ee,{dimColor:!0,italic:!0,children:"Select a building or NPC."}),n&&!a&&se(ee,{color:"green",children:"TIP: Upgrade buildings with Echoes. Talk to NPCs. Enter the Gate to start a run."}),a?se(ee,{color:"yellow",bold:!0,children:a}):null,se(ee,{dimColor:!0,children:"\u2191\u2193/\u2190\u2192 select Enter interact q back"})]})]})}import{Box as Yn,Text as Ve}from"ink";import{jsx as st,jsxs as Nt}from"react/jsx-runtime";var zn=[{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 Vo(e,t,a){let n=Math.max(0,Math.min(a,Math.round(e/t*a)));return"\u2588".repeat(n)+"\u2591".repeat(Math.max(0,a-n))}function jn({page:e,totalPages:t}){let a=zn[e];return a?Nt(Yn,{flexDirection:"column",padding:1,children:[Nt(Ve,{bold:!0,color:"yellow",children:["\u25C6 Tutorial \u2014 ",a.title]}),st(Ve,{dimColor:!0,children:"\u2500".repeat(44)}),st(Ve,{children:" "}),a.lines.map((n,r)=>st(Ve,{children:n||" "},r)),st(Ve,{children:" "}),st(Ve,{dimColor:!0,children:"\u2500".repeat(44)}),Nt(Yn,{children:[Nt(Ve,{dimColor:!0,children:[Vo(e+1,t,20)," ",e+1,"/",t," "]}),st(Ve,{dimColor:!0,children:e<t-1?"\u2190 prev \u2192 next q close":"\u2190 prev Enter start q close"})]})]}):null}var bt=zn.length;import{Box as Gt,Text as me}from"ink";import{Fragment as Xn,jsx as Te,jsxs as Me}from"react/jsx-runtime";var Jn={asciiMode:!1,showTutorialHints:!0,combatLogSize:4};function Qn({settings:e,selectedIndex:t,saveInfo:a,confirmingReset:n,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 Me(Gt,{flexDirection:"column",padding:1,children:[Te(me,{bold:!0,color:"yellow",children:"\u25C6 Settings"}),Te(me,{children:" "}),Te(Gt,{paddingX:1,children:Me(Gt,{flexDirection:"column",width:40,children:[Te(me,{bold:!0,dimColor:!0,children:"Save Info"}),Me(me,{dimColor:!0,children:["Runs: ",a.totalRuns," Wins: ",a.totalWins," Echoes: ",a.echoes]}),Me(me,{dimColor:!0,children:["Highest Ascension: ",a.highestAscension]}),Me(me,{dimColor:!0,children:["Save: ",a.hasSave?"~/.config/codekeep/game.json":"None"]})]})}),Te(me,{children:" "}),o.map((l,i)=>{let s=i===t;return Me(Gt,{children:[Me(me,{bold:s,color:s?l.id==="reset"?"red":"yellow":void 0,children:[s?"\u25B6 ":" ",l.label]}),s&&l.description?Me(me,{dimColor:!0,children:[" \u2014 ",l.description]}):null]},l.id)}),n&&Me(Xn,{children:[Te(me,{children:" "}),Te(me,{bold:!0,color:"red",children:"Are you sure? This deletes ALL progress. Press Enter again to confirm, Esc to cancel."})]}),r&&Me(Xn,{children:[Te(me,{children:" "}),Te(me,{color:"cyan",bold:!0,children:r})]}),Te(me,{children:" "}),Te(me,{dimColor:!0,children:"\u2191\u2193 navigate Enter toggle/select q back"})]})}import{Box as Lo,Text as R}from"ink";import{jsx as A,jsxs as Oo}from"react/jsx-runtime";function Zn(){return Oo(Lo,{flexDirection:"column",padding:1,children:[A(R,{bold:!0,color:"yellow",children:"\u25C6 Controls Reference"}),A(R,{dimColor:!0,children:"\u2500".repeat(36)}),A(R,{children:" "}),A(R,{bold:!0,children:"Global"}),A(R,{children:" \u2191\u2193 Navigate menus"}),A(R,{children:" Enter Confirm / select"}),A(R,{children:" Esc Cancel / go back"}),A(R,{children:" q Quit / back to menu"}),A(R,{children:" "}),A(R,{bold:!0,children:"Combat"}),A(R,{children:" 1-9 Select card from hand"}),A(R,{children:" \u2190\u2192 Target column"}),A(R,{children:" Enter Play selected card"}),A(R,{children:" Space End your turn"}),A(R,{children:" e Toggle emplace mode"}),A(R,{children:" p Use potion"}),A(R,{children:" i Inspect enemies"}),A(R,{children:" d View deck"}),A(R,{children:" "}),A(R,{bold:!0,children:"Map"}),A(R,{children:" \u2191\u2193 Select next node"}),A(R,{children:" Enter Enter node"}),A(R,{children:" d View deck"}),A(R,{children:" "}),A(R,{bold:!0,children:"The Keep"}),A(R,{children:" \u2190\u2192 Select building / NPC"}),A(R,{children:" Enter Interact"}),A(R,{children:" "}),A(R,{bold:!0,children:"Inspect Mode (i in combat)"}),A(R,{children:" \u2190\u2192 Switch column"}),A(R,{children:" \u2191\u2193 Switch enemy"}),A(R,{children:" i / Esc Close inspect"}),A(R,{children:" "}),A(R,{dimColor:!0,children:"Press q or Esc to go back"})]})}import{useState as ze,useCallback as je,useRef as Ko,useEffect as Uo}from"react";function qo(e){switch(e.type){case"enemy_advance":return`Enemy advances to row ${e.data.row}`;case"gate_hit":{let t=e.data.blocked?` (${e.data.blocked} blocked)`:"";return e.data.self?`Gate takes ${e.data.damage} self-damage`:`Enemy hits gate for ${e.data.damage}${t}!`}case"enemy_killed":return"An enemy is destroyed!";case"emplacement_destroyed":return`Emplacement in column ${e.data.column+1} destroyed!`;case"emplacement_triggered":return`Emplacement fires in column ${e.data.column+1}`;case"status_applied":return`${e.data.type} applied (${e.data.value} stacks)`;case"damage_dealt":return`${e.data.damage} damage dealt`;case"block_gained":return`+${e.data.value} Block`;default:return null}}function er(){let[e,t]=ze(null),[a,n]=ze(-1),[r,o]=ze(2),[l,i]=ze(""),[s,f]=ze(!1),[y,k]=ze(!1),[E,S]=ze([]),D=Ko(null);Uo(()=>{if(!y||E.length===0)return;let w=setTimeout(()=>{let[b,...x]=E;if(i(b),x.length===0){k(!1);let _=D.current;_&&(_.outcome==="win"?i("Victory! The Pale recedes."):_.outcome==="lose"?i("The Gate has fallen..."):i(`Turn ${_.turn}. Your move.`))}else S(x)},350);return()=>clearTimeout(w)},[y,E]);let m=je((w,b,x,_,H,L,ue)=>{let J=w??ia(),W=b??Math.floor(Math.random()*2147483647),P=Qa(J,W,x,_,H,L??[],ue);D.current=P,t({...P}),n(-1),o(2),f(!1),i("Your turn. Select a card (1-5) and a column (\u2190\u2192).")},[]),h=(()=>{if(a<0||!e)return!1;let w=e.hand[a];if(!w)return!1;let b=Y(w.defId);if(!b)return!1;let x=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(_=>x.has(_.type)&&(_.target==="single"||_.target==="column"))})(),B=je(w=>{if(!D.current||D.current.phase!=="player"||w<0||w>=D.current.hand.length)return;let b=D.current.hand[w],x=Y(b.defId);if(!x)return;let _=!D.current.events.some(W=>W.type==="card_played"&&W.turn===D.current.turn);if((ua(D.current.relics)&&_?0:x.cost)>D.current.resolve){i(`Not enough Resolve for ${x.name} (costs ${x.cost}).`);return}n(w);let ue=new Set(["damage","damage_if_vulnerable","damage_equal_block","damage_if_emplaced","damage_plus_block","damage_if_low_hp","vulnerable","weak","burn"]),J=x.effects.some(W=>ue.has(W.type)&&(W.target==="single"||W.target==="column"));i(J?`${x.name} selected. Choose column (\u2190\u2192), Enter to play.`:`${x.name} selected. Enter to play.`)},[]),T=je(w=>{w>=0&&w<5&&o(w)},[]),G=je(()=>{let w=D.current;if(!w||w.phase!=="player"||a<0)return;let b=w.hand[a];if(!b)return;let x=Y(b.defId);if(!x)return;let _=w.events.length;if(Za(w,a,r,s),w.events.length===_){i(`Cannot play ${x.name}. Not enough Resolve.`);return}D.current=w,t({...w}),n(-1),f(!1),w.outcome==="win"?i("Victory! The Pale recedes."):w.outcome==="lose"?i("The Gate has fallen..."):i(`${s?"Emplaced":"Played"} ${x.name}. ${w.resolve} Resolve left.`)},[a,r,s]),N=je(()=>{if(a<0||!D.current)return;let w=D.current.hand[a];if(!w)return;let b=Y(w.defId);if(!b||b.type!=="emplace"){i("This card cannot be emplaced.");return}f(x=>!x),i(s?`${b.name}: cast mode`:`${b.name}: EMPLACE mode \u2014 place in a column`)},[a,s]),De=je(()=>{let w=D.current;if(!w||w.phase!=="player"||y)return;let b=w.events.length;tn(w),D.current=w,t({...w}),n(-1);let x=w.events.slice(b),_=[];for(let H of x){let L=qo(H);L&&_.push(L)}_.length>0?(k(!0),i("\u26A1 Enemy turn..."),S(_)):w.outcome==="win"?i("Victory! The Pale recedes."):w.outcome==="lose"?i("The Gate has fallen..."):i(`Turn ${w.turn}. Your move.`)},[y]),ne=je(w=>{let b=D.current;if(!(!b||!w)){for(let x of w.effects)switch(x.type){case"heal":b.gateHp=Math.min(b.gateMaxHp,b.gateHp+x.value);break;case"block":b.gateBlock+=x.value;break;case"damage":{let _=r;if(x.target==="column"){let H=b.columns[_];if(H)for(let L of H.enemies)L.hp-=x.value}else if(x.target==="all")for(let H of b.columns)for(let L of H.enemies)L.hp-=x.value;break}case"draw":{let _=Q(b.seed+b.turn*53),{drawn:H,newDrawPile:L,newDiscardPile:ue}=Ne(b.drawPile,b.discardPile,x.value,_);b.hand.push(...H),b.drawPile=L,b.discardPile=ue;break}case"resolve":b.resolve=Math.min(b.maxResolve+5,b.resolve+x.value);break}D.current=b,t({...b}),i(`Used ${w.name}.`)}},[r]);return{combat:e,selectedCard:a,targetColumn:r,message:l,emplaceMode:s,animating:y,selectCard:B,selectTarget:T,confirmPlay:G,endTurn:De,toggleEmplace:N,startCombat:m,applyPotion:ne,needsTarget:h}}import{Fragment as Ea,jsx as v,jsxs as C}from"react/jsx-runtime";var tr=60,ar=18;function Jo(){let{stdout:e}=Xo(),[t,a]=M({columns:e?.columns??process.stdout.columns??80,rows:e?.rows??process.stdout.rows??24});return Yo(()=>{let n=e??process.stdout,r=()=>a({columns:n.columns,rows:n.rows});return n.on("resize",r),()=>{n.off("resize",r)}},[e]),t}function Qo({dryRun:e}){let{exit:t}=zo(),{columns:a,rows:n}=Jo(),[r,o]=M("menu"),[l,i]=M(0),[s,f]=M(null),[y,k]=M(0),[E,S]=M([]),[D,m]=M(0),[h,B]=M([]),[T,G]=M(0),[N,De]=M(null),[ne,w]=M(0),[b,x]=M(0),[_,H]=M(null),[L,ue]=M(0),[J,W]=M(""),[P,te]=M(!1),[Ie,wt]=M([]),[le,Le]=M(0),[Wt,Oe]=M(0),Ft=er(),{combat:O,selectedCard:vt,targetColumn:$t,message:sr,emplaceMode:as,animating:Pa,selectCard:Ra,selectTarget:Aa,confirmPlay:lr,endTurn:ir,toggleEmplace:cr,startCombat:Vt,applyPotion:ns,needsTarget:dr}=Ft,[Lt,Ot]=M(!1),[kt,Kt]=M(0),[mr,Ut]=M(0),[qt,Ma]=M(null),[Da,Xe]=M(0),[Yt,zt]=M("new_game"),[ur,Ba]=M("map"),[pr,Ha]=M(""),[Na,jt]=M(!1),[lt,Xt]=M(Jn),[Ga,Jt]=M(0),[fr,xt]=M(""),[Wa,Je]=M(!1),[pe,Ce]=M(()=>nt()),Qt=!pe||pe.keep.totalRuns<=1,it=pe?fn(pe.keep.totalRuns,pe.keep.highestAscension):"surface",hr=a<tr||n<ar,Se=_e(()=>{let u=pe??nt();return u?pe||(u.keep.npcs.length===0&&(u.keep.npcs=ga()),Ce(u)):(u=bn("Warden"),u.keep.npcs.length===0&&(u.keep.npcs=ga()),Re(u),Ce(u)),JSON.parse(JSON.stringify(u))},[pe]),V=_e(u=>{if(e)return;let d=Se();d.activeRun=u,_&&(d.keep=_),Re(d),Ce(d)},[e,_,Se]),Zt=_e(()=>{let u=Se();if(u.keep.totalRuns===0){u.keep.totalRuns++,Re(u),Ce(u),H(u.keep),Xe(0),zt("new_game"),o("tutorial");return}let d=`run-${Date.now()}`,c=on(d,u.keep.highestAscension);f(c),k(0),u.activeRun=c,u.keep.totalRuns++,H(u.keep),Re(u),Ce(u),o("map")},[Se]),gr=_e(()=>{let u=nt();u?.activeRun&&(f(u.activeRun),H(u.keep),k(0),o("map"))},[]),Fa=_e(()=>{let u=Se();Ce(u),H(u.keep),ue(0),W(""),o("keep")},[Se]),$a=_e(()=>s?rn(s.map,s.currentNodeId):[],[s]),yr=_e(u=>{if(!s)return;let d=sn(s,u.id);if(u.type==="combat"||u.type==="elite"){let c=ve(s.seed+u.id),p=Q(c),I=an(s.act,p,u.type==="elite");Vt(d.deck,c,d.gateHp,d.gateMaxHp,I.enemies,d.relics,Et(s.act,s.ascensionLevel)),f(d),o("combat")}else if(u.type==="boss"){let c=ve(s.seed+"-boss-"+s.act),p=Ya(s.act);Vt(d.deck,c,d.gateHp,d.gateMaxHp,p,d.relics,Et(s.act,s.ascensionLevel));let I=ca(s.act);if(I?.dialogue){let F=I.dialogue.find(Ee=>Ee.storyLayer===it)??I.dialogue[0];F&&Ma(F.onAppear)}f(d),o("combat")}else if(u.type==="shop"){let c=Q(ve(s.seed+u.id));B(mn(c)),G(0),f(d),o("shop")}else if(u.type==="event"){let c=Q(ve(s.seed+u.id));De(un(s.act,c,it)),w(0),f(d),o("event")}else u.type==="rest"&&(x(0),f(d),o("rest"));V(d)},[s,Vt,V]),ct=_e((u,d)=>{te(d),f(u);let c=Se(),p=ya(d,u.act,u.ascensionLevel);c.keep.echoes+=p,d&&(c.keep.totalWins++,u.ascensionLevel>=c.keep.highestAscension&&(c.keep.highestAscension=u.ascensionLevel+1)),c.activeRun=null,H(c.keep),Re(c),Ce(c),o("result")},[Se]),br=_e(()=>{if(!O||!s)return;let u={...s,gateHp:O.gateHp};if(O.outcome==="lose"){ct(u,!1);return}let d=s.currentNodeId?pt(s.map,s.currentNodeId):null,c=d?.type==="elite"?Tt.elite:d?.type==="boss"?Tt.boss:Tt.combat;if(u=ht(u,c),u.relics.includes("mending_stone")&&(u=Pt(u,5)),u.relics.includes("fragment_magnet")&&(u=ht(u,5)),d?.type==="elite"||d?.type==="boss"){let I=Q(ve(s.seed+(s.currentNodeId??"")+"-relic")),F=Ja(I,u.relics,3);if(F.length>0){wt(F),Le(0),f(u),V(u),o("relic_reward");return}}if(d?.type==="boss"){s.act<3?(u=ha(u),f(u),V(u),k(0),o("map")):ct(u,!0);return}let p=Q(ve(s.seed+(s.currentNodeId??"")+"-reward"));S(St(p)),m(0),f(u),V(u),o("reward")},[O,s,V,ct]),Va=_e(u=>{if(!s)return;let d=s;u&&(d=pa(d,ft(u.id))),f(d),V(d),k(0),o("map")},[s,V]),La=_e(u=>{if(!s)return;let d=s;if(u&&(d={...d,relics:[...d.relics,u.id]}),f(d),V(d),(s.currentNodeId?pt(s.map,s.currentNodeId):null)?.type==="boss")s.act<3?(d=ha(d),f(d),V(d),k(0),o("map")):ct(d,!0);else{let p=Q(ve(s.seed+(s.currentNodeId??"")+"-reward"));S(St(p)),m(0),o("reward")}},[s,V,ct]),ea=[{label:"The Keep",action:"keep"},{label:"New Run",action:"new"},...pe?.activeRun?[{label:"Resume Run",action:"resume"}]:[],{label:"Tutorial",action:"tutorial"},{label:"Settings",action:"settings"},{label:"Quit",action:"quit"}];if(jo((u,d)=>{if(r==="tutorial"){d.rightArrow?Xe(c=>Math.min(bt-1,c+1)):d.leftArrow?Xe(c=>Math.max(0,c-1)):d.return?Da===bt-1?Yt==="new_game"?Zt():o(Yt==="settings"?"settings":"menu"):Xe(c=>Math.min(bt-1,c+1)):(u==="q"||d.escape)&&o(Yt==="settings"?"settings":"menu");return}if(r==="controls"){(u==="q"||d.escape)&&o("settings");return}if(r==="settings"){let c=["ascii","hints","log","tutorial","controls","reset","back"];if(d.upArrow)Jt(p=>Math.max(0,p-1)),Je(!1);else if(d.downArrow)Jt(p=>Math.min(c.length-1,p+1)),Je(!1);else if(u==="q"||d.escape)o("menu"),Je(!1);else if(d.return){let p=c[Ga];p==="ascii"?(Xt(I=>({...I,asciiMode:!I.asciiMode})),xt("ASCII mode "+(lt.asciiMode?"disabled":"enabled"))):p==="hints"?(Xt(I=>({...I,showTutorialHints:!I.showTutorialHints})),xt("Tutorial hints "+(lt.showTutorialHints?"disabled":"enabled"))):p==="log"?Xt(I=>({...I,combatLogSize:I.combatLogSize>=8?0:I.combatLogSize+2})):p==="tutorial"?(Xe(0),zt("settings"),o("tutorial")):p==="controls"?o("controls"):p==="reset"?Wa?(wn(),Ce(null),H(null),f(null),Je(!1),xt("Save data deleted. Starting fresh.")):Je(!0):p==="back"&&o("menu")}return}if(r==="relic_reward"){d.upArrow?Le(c=>Math.max(0,c-1)):d.downArrow?Le(c=>Math.min(Ie.length,c+1)):u==="s"?La(null):d.return&&La(le<Ie.length?Ie[le]:null);return}if(r==="menu"){if(d.upArrow)i(c=>Math.max(0,c-1));else if(d.downArrow)i(c=>Math.min(ea.length-1,c+1));else if(d.return){let c=ea[l]?.action;c==="keep"?Fa():c==="new"?Zt():c==="resume"?gr():c==="tutorial"?(Xe(0),zt("menu"),o("tutorial")):c==="settings"?(Jt(0),xt(""),Je(!1),o("settings")):t()}else u==="q"&&t();return}if(r==="deck"){(u==="q"||d.escape)&&o(ur);return}if(r==="map"&&s){let c=$a();d.upArrow?k(p=>Math.max(0,p-1)):d.downArrow?k(p=>Math.min(c.length-1,p+1)):d.return&&c[y]?yr(c[y]):u==="d"?(Ba("map"),o("deck")):u==="q"&&(V(s),o("menu"));return}if(r==="reward"){let c=E.length;d.upArrow?m(p=>Math.max(0,p-1)):d.downArrow?m(p=>Math.min(c,p+1)):u==="s"?Va(null):d.return&&Va(D<E.length?E[D]:null);return}if(r==="shop"&&s){if(d.upArrow)G(c=>Math.max(0,c-1));else if(d.downArrow)G(c=>Math.min(h.length-1,c+1));else if(u==="q"||d.escape)k(0),o("map");else if(d.return){let c=h[T];if(c&&s.fragments<c.cost){Ha(`Not enough fragments (need ${c.cost}, have ${s.fragments}).`);return}if(Ha(""),c&&s.fragments>=c.cost){let p=ln(s,c.cost);if(!p)return;if(c.type==="card"&&c.cardDef)p=pa(p,ft(c.cardDef.id)),f(p),V(p),B(I=>I.filter((F,Ee)=>Ee!==T)),G(0);else if(c.type==="potion"&&c.potionDef){let I=cn(p,c.potionDef.id);I&&(p=I),f(p),V(p),B(F=>F.filter((Ee,wr)=>wr!==T)),G(0)}else c.type==="card_remove"&&(f(p),V(p),Oe(0),B(I=>I.filter((F,Ee)=>Ee!==T)),o("shop_remove"))}}return}if(r==="event"&&N&&s){if(d.upArrow)w(c=>Math.max(0,c-1));else if(d.downArrow)w(c=>Math.min(N.choices.length-1,c+1));else if(d.return){let c=N.choices[ne],p=s;switch(c.effect.type){case"heal":p=Pt(p,c.effect.value);break;case"damage":{p={...p,gateHp:Math.max(1,p.gateHp-c.effect.value)};let I=c.label.match(/(\d+)\s*fragments/i);I&&(p=ht(p,parseInt(I[1])));break}case"fragments":p=ht(p,c.effect.value);break;case"max_hp":p={...p,gateMaxHp:p.gateMaxHp+c.effect.value};break;case"card_reward":{let I=c.label.match(/lose\s+(\d+)\s*hp/i);I&&(p={...p,gateHp:Math.max(1,p.gateHp-parseInt(I[1]))});let F=Q(ve(s.seed+(N?.id??"")));S(St(F)),m(0),f(p),V(p),o("reward");return}case"remove_card":{f(p),V(p),Oe(0),o("deck_remove");return}case"nothing":break}f(p),V(p),k(0),o("map")}return}if(r==="rest"&&s){if(d.upArrow)x(c=>Math.max(0,c-1));else if(d.downArrow)x(c=>Math.min(2,c+1));else if(d.return){let c=s;b===0?(c=Pt(c,Math.floor(c.gateMaxHp*.3)),f(c),V(c),k(0),o("map")):b===1&&c.deck.length>5?(f(c),Oe(0),o("deck_remove")):(f(c),V(c),k(0),o("map"))}return}if(r==="deck_remove"&&s){if(d.upArrow)Oe(c=>Math.max(0,c-1));else if(d.downArrow)Oe(c=>Math.min(s.deck.length-1,c+1));else if(d.escape||u==="q")k(0),o("map");else if(d.return&&s.deck.length>5){let c=s.deck[Wt];if(c){let p=fa(s,c.instanceId);f(p),V(p)}k(0),o("map")}return}if(r==="shop_remove"&&s){if(d.upArrow)Oe(c=>Math.max(0,c-1));else if(d.downArrow)Oe(c=>Math.min(s.deck.length-1,c+1));else if(d.escape||u==="q")o("shop");else if(d.return&&s.deck.length>5){let c=s.deck[Wt];if(c){let p=fa(s,c.instanceId);f(p),V(p)}o("shop")}return}if(r==="keep"&&_){if(d.leftArrow||d.upArrow)ue(c=>(c-1+Ye.length)%Ye.length),W("");else if(d.rightArrow||d.downArrow)ue(c=>(c+1)%Ye.length),W("");else if(u==="q")o("menu");else if(d.return){let c=Ye[L];if(!c)return;if(c.type==="structure"){let p=tt.find(F=>F.id===c.id);if(!p)return;let I=pn(_,p.id);if(I){H(I);let F=Se();F.keep=I,Re(F),Ce(F),W(`Upgraded ${p.name}!`)}else at(_,p.id)>=p.maxLevel?W(`${p.name} is already max level.`):W(`Not enough Echoes to upgrade ${p.name}.`)}else if(c.type==="npc"){let p=_.npcs.find(F=>F.id===c.id);if(!p)return;let I=hn(p.id,_);if(I){let F=gn(_,p.id,I.dialogueId);H(F);let Ee=Se();Ee.keep=F,Re(Ee),Ce(Ee),W(`${I.speaker}: "${I.text}"`)}else W("(No new dialogue)")}else c.type==="gate"&&Zt()}return}if(r==="result"){d.return||u===" "?Fa():u==="q"&&o("menu");return}if(r==="combat"&&O){if(Pa)return;if(O.outcome!=="undecided"){(d.return||u===" ")&&br();return}if(qt&&O.turn>1&&Ma(null),u==="i"){Lt?Ot(!1):(Ot(!0),Kt(0),Ut(0));return}if(Lt){if(d.leftArrow)Kt(c=>Math.max(0,c-1));else if(d.rightArrow)Kt(c=>Math.min(4,c+1));else if(d.upArrow)Ut(c=>Math.max(0,c-1));else if(d.downArrow){let c=(O.columns[kt]?.enemies.length??1)-1;Ut(p=>Math.min(Math.max(0,c),p+1))}else d.escape&&Ot(!1);return}if(u==="q"){o("menu");return}if(u==="d"&&s){Ba("combat"),o("deck");return}if(u==="e"){cr();return}if(u==="p"&&s){let c=s.potions.findIndex(p=>p!==null);if(c>=0){let p=dn(s,c);if(p&&Ft.combat){let I=et.find(F=>F.id===p.potionId);f(p.run),V(p.run),Ft.applyPotion(I??null)}}return}if(u>="1"&&u<="9"){jt(!1),Ra(parseInt(u)-1);return}if(d.leftArrow){Aa(Math.max(0,$t-1));return}if(d.rightArrow){Aa(Math.min(4,$t+1));return}if(d.return&&vt>=0){lr();return}if(u===" "){if(O.resolve>0&&O.hand.some(c=>{let p=Y(c.defId);return p&&p.cost<=O.resolve})&&!Na){jt(!0);return}jt(!1),ir();return}if(d.escape){Ra(-1);return}}}),hr)return C(we,{flexDirection:"column",padding:1,children:[v(g,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),C(g,{color:"red",children:["Terminal too small (",a,"x",n,", need ",tr,"x",ar,")"]})]});if(r==="menu")return C(we,{flexDirection:"column",padding:1,children:[v(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"}),v(g,{bold:!0,color:"yellow",children:"\u2502 \u25C6 CodeKeep \u2014 The Pale \u2502"}),v(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"}),v(g,{children:" "}),(it==="true_ending"?["The fortress. The Pale. You can no longer tell which side you're on."]:it==="truth"?["The fortress stands. The Pale stands. The line between them blurs."]:it==="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((d,c)=>v(g,{dimColor:!0,italic:!0,children:d},c)),v(g,{children:" "}),ea.map((d,c)=>{let p=c===l;return C(g,{bold:p,color:p?"yellow":"white",children:[p?" \u25B6 ":" ",d.label]},d.action)}),v(g,{children:" "}),v(g,{dimColor:!0,children:"\u2191\u2193 navigate Enter select q exit"})]});if(r==="tutorial")return v(jn,{page:Da,totalPages:bt});if(r==="controls")return v(Zn,{});if(r==="settings"){let u={totalRuns:pe?.keep.totalRuns??0,totalWins:pe?.keep.totalWins??0,highestAscension:pe?.keep.highestAscension??0,echoes:pe?.keep.echoes??0,hasSave:!!pe};return v(Qn,{settings:lt,selectedIndex:Ga,saveInfo:u,confirmingReset:Wa,message:fr})}if(r==="deck"&&s)return v(Mn,{deck:s.deck});if(r==="keep"&&_)return v(qn,{keep:_,selectedId:Ye[L]?.id??"forge",message:J,isFirstVisit:Qt});if((r==="deck_remove"||r==="shop_remove")&&s)return C(we,{flexDirection:"column",padding:1,children:[v(g,{bold:!0,color:"red",children:"\u25C6 Remove a Card"}),C(g,{dimColor:!0,children:["Choose a card to remove from your deck (",s.deck.length," cards)."]}),v(g,{children:" "}),s.deck.map((u,d)=>{let c=Y(u.defId),p=d===Wt;return C(g,{bold:p,color:p?"yellow":"white",children:[p?"\u25B6 ":" ",c?.name??u.defId," (",c?.rarity,") \u2014 ",c?.description??""]},u.instanceId)}),v(g,{children:" "}),v(g,{dimColor:!0,children:"\u2191\u2193 navigate Enter remove Esc cancel"})]});if(r==="map"&&s){let u=$a();return C(we,{flexDirection:"column",children:[C(we,{justifyContent:"space-between",paddingX:1,children:[C(g,{children:["Gate ",C(g,{bold:!0,color:s.gateHp>40?"green":s.gateHp>20?"yellow":"red",children:[s.gateHp,"/",s.gateMaxHp]})]}),C(g,{children:["Fragments ",v(g,{bold:!0,color:"yellow",children:s.fragments})]}),s.potions.filter(d=>d!==null).length>0&&C(g,{children:["Potions ",v(g,{color:"magenta",children:s.potions.filter(d=>d!==null).length})]}),s.relics.length>0&&C(g,{children:["Relics ",C(g,{color:"magenta",children:["\u2605",s.relics.length]})]}),C(g,{children:["Deck ",v(g,{dimColor:!0,children:s.deck.length})]})]}),Qt&&lt.showTutorialHints&&!s.currentNodeId&&v(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."}),v(Hn,{map:s.map,currentNodeId:s.currentNodeId,reachableIds:u.map(d=>d.id),selectedNodeId:u[y]?.id??null})]})}if(r==="reward")return v(An,{cards:E,selectedIndex:D});if(r==="relic_reward")return C(we,{flexDirection:"column",padding:1,children:[v(g,{bold:!0,color:"magenta",children:"\u25C6 Relic Reward"}),v(g,{dimColor:!0,children:"\u2500".repeat(36)}),v(g,{dimColor:!0,italic:!0,children:"An artifact resonates from the defeated foe."}),v(g,{children:" "}),Ie.map((u,d)=>{let c=d===le;return C(we,{flexDirection:"column",children:[C(g,{children:[v(g,{bold:c,color:c?"yellow":"white",children:c?" \u25B6 ":" "}),C(g,{color:c?"magenta":"white",bold:c,children:["\u2605 ",u.name]})]}),c&&C(g,{dimColor:!0,children:[" ",u.description]})]},u.id)}),v(g,{children:" "}),C(g,{bold:le===Ie.length,color:le===Ie.length?"yellow":"white",children:[le===Ie.length?" \u25B6 ":" ","Skip"]}),v(g,{children:" "}),s&&s.relics.length>0&&C(we,{children:[v(g,{dimColor:!0,children:"Relics: "}),v(g,{color:"magenta",children:s.relics.join(" \xB7 ")})]}),v(g,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]});if(r==="shop"&&s)return v(Nn,{items:h,selectedIndex:T,fragments:s.fragments,message:pr});if(r==="event"&&N)return v(Gn,{event:N,selectedChoice:ne});if(r==="rest"&&s)return v(Fn,{gateHp:s.gateHp,gateMaxHp:s.gateMaxHp,selectedChoice:b,deckSize:s.deck.length});if(r==="result"){let u=s?ya(P,s.act,s.ascensionLevel):0;return C(we,{flexDirection:"column",padding:1,children:[P?C(Ea,{children:[v(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"}),v(g,{bold:!0,color:"green",children:"\u2502 \u2605 RUN COMPLETE \u2502"}),v(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"}),v(g,{children:" "}),v(g,{italic:!0,children:"The Pale recedes. The Keep endures."}),v(g,{italic:!0,dimColor:!0,children:"Another dawn. Another day of resistance."})]}):C(Ea,{children:[v(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"}),v(g,{bold:!0,color:"red",children:"\u2502 \u2717 DEFEAT \u2502"}),v(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"}),v(g,{children:" "}),v(g,{italic:!0,children:"The Gate has fallen. The Pale consumes all."}),v(g,{italic:!0,dimColor:!0,children:"But the Keep remembers. It always remembers."})]}),v(g,{children:" "}),s&&C(Ea,{children:[v(g,{dimColor:!0,children:"\u2500".repeat(32)}),C(g,{children:[" ","Act ",v(g,{bold:!0,children:s.act})," ","Deck ",C(g,{dimColor:!0,children:[s.deck.length," cards"]})," ","Fragments ",v(g,{dimColor:!0,children:s.fragments})]}),C(g,{children:[" ","Echoes earned ",C(g,{bold:!0,color:"cyan",children:["+",u]})]}),v(g,{dimColor:!0,children:"\u2500".repeat(32)})]}),v(g,{children:" "}),v(g,{dimColor:!0,children:"Enter \u2192 The Keep | q \u2192 menu"})]})}if(r==="combat"&&O&&s){let u=Qt&&lt.showTutorialHints&&O.turn<=3?O.turn===1&&vt<0?"TIP: Press 1-5 to select a card. \u2190\u2192 to target a column. Enter to play. Space to end turn.":O.turn===1&&vt>=0?"TIP: Arrow keys choose which column to target. Press Enter to play the card.":O.turn===2?"TIP: Enemies with \u2694 will attack your Gate. \u2193 means they advance. Block reduces damage. Press i to inspect enemies.":O.turn===3?'TIP: Cards with type "emplace" can become structures! Select one, press e to toggle emplace mode, then Enter.':null:null;return C(we,{flexDirection:"column",paddingX:1,children:[C(g,{dimColor:!0,children:["Act ",s.act," | Gate ",s.gateHp,"/",s.gateMaxHp," | Fragments ",s.fragments,s.potions.filter(d=>d!==null).length>0&&` | Potions ${s.potions.filter(d=>d!==null).map(d=>et.find(p=>p.id===d)?.name??d).join(", ")}`,s.relics.length>0&&` | \u2605 ${s.relics.length}`," | d=deck i=inspect"]}),u&&v(g,{color:"green",bold:!0,children:u}),qt&&v(we,{borderStyle:"single",borderColor:"magenta",paddingX:1,marginBottom:1,children:C(g,{color:"magenta",italic:!0,children:['"',qt,'"']})}),v(En,{combat:O,selectedCard:vt,targetColumn:$t,needsTarget:dr,message:Na?`End turn with ${O.resolve} Resolve remaining? Press Space again to confirm.`:sr,animating:Pa}),Lt&&(()=>{let c=O.columns[kt]?.enemies[mr];if(!c)return C(g,{dimColor:!0,children:["No enemy in column ",kt+1,". \u2190\u2192 to navigate."]});let p=Be(c.templateId);return C(we,{flexDirection:"column",borderStyle:"single",borderColor:"cyan",paddingX:1,children:[C(g,{bold:!0,color:"cyan",children:["Inspecting: ",p?.name??c.templateId," (Col ",kt+1,")"]}),C(g,{children:["HP: ",c.hp,"/",c.maxHp," Row: ",c.row]}),v(g,{dimColor:!0,children:p?.description??""}),c.statusEffects.length>0&&C(g,{children:["Status: ",c.statusEffects.map(I=>`${I.type}(${I.stacks}x, ${I.duration}t)`).join(", ")]}),C(g,{children:["Intent: ",c.intent?`${c.intent.type} ${c.intent.value}`:"unknown"]}),v(g,{dimColor:!0,children:"\u2190\u2192 column \u2191\u2193 enemy i/Esc close"})]})})()]})}return v(g,{children:"Loading..."})}function nr(e){return v(Rt,{children:v(Qo,{...e})})}import{jsx as ts}from"react/jsx-runtime";var rr="0.5.0";globalThis.__CODEKEEP_VERSION=rr;var or=new Zo;or.name("codekeep").description("CodeKeep: The Pale \u2014 deck-building tactical roguelike in your terminal").version(rr).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:a}=Jo(Zo(tr,{asciiMode:e.ascii??!1,compact:e.compact??!1,forceTutorial:e.tutorial??!1,dryRun:e.save===!1}),{exitOnCtrlC:!1}),n=!1;function r(){if(!n){if(n=!0,e.save!==!1){process.stderr.write(`
21
+ `),process.exit(1));let{waitUntilExit:t,unmount:a}=es(ts(nr,{asciiMode:e.ascii??!1,compact:e.compact??!1,forceTutorial:e.tutorial??!1,dryRun:e.save===!1}),{exitOnCtrlC:!1}),n=!1;function r(){if(!n){if(n=!0,e.save!==!1){process.stderr.write(`
22
22
  Saving...
23
- `);try{let o=tt();o&&Se(o)}catch{}}a()}}process.on("SIGINT",r),process.on("SIGTERM",r),process.on("SIGHUP",r),t().then(()=>{process.exit(0)}).catch(()=>{process.exit(1)})});nr.parse();export{ar as CLI_VERSION};
23
+ `);try{let o=nt();o&&Re(o)}catch{}}a()}}process.on("SIGINT",r),process.on("SIGTERM",r),process.on("SIGHUP",r),t().then(()=>{process.exit(0)}).catch(()=>{process.exit(1)})});or.parse();export{rr as CLI_VERSION};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codekeep",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "type": "module",
5
5
  "description": "CodeKeep: The Pale — deck-building tactical roguelike in your terminal",
6
6
  "license": "MIT",