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