codekeep 0.6.0 → 0.8.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 Zr}from"commander";import{render as Qr}from"ink";import{useState as E,useCallback as j,useEffect as qr}from"react";import{Box as ee,Text as v,useApp as jr,useInput as zr,useStdout as Yr}from"ink";var ke=5,Te=4,We=3,et=5,he=70,xe=[{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"}]}],Ht=["strike","strike","strike","guard","guard","spark","ember","brace","bolster","mend"];function $(e){return xe.find(t=>t.id===e)}var $a=[{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 ne(e){return $a.find(t=>t.id===e)}var _e=[{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}]}],$e={combat:15,elite:30,boss:50},Fa=[{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:"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:"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:"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 true ending, Warden. But it requires Ascension 15."},{id:"pv_t4_2",speaker:"The Visitor",text:"At the peak, the Pale reveals its core. And you will have a choice."},{id:"pv_t4_3",speaker:"The Visitor",text:"Destroy the Pale \u2014 and everything it remembers. Or become the new Architect."}]}];function Va(e,t){return Fa.filter(a=>a.npcId===e&&a.tier<=t).flatMap(a=>a.lines)}function Bt(e,t,r){let a=Va(e,t),o=new Set(r);return a.filter(n=>!o.has(n.id))}import{writeFileSync as nt,readFileSync as fr,mkdirSync as hr,existsSync as aa,renameSync as gr,unlinkSync as fn}from"fs";import{join as ra,dirname as yr}from"path";import{homedir as vr}from"os";function F(e){let t=e|0;return()=>{t=t+1831565813|0;let r=Math.imul(t^t>>>15,1|t);return r=r+Math.imul(r^r>>>7,61|r)^r,((r^r>>>14)>>>0)/4294967296}}function z(e){let t=0;for(let r=0;r<e.length;r++){let a=e.charCodeAt(r);t=(t<<5)-t+a|0}return t}function Nt(e,t){let r=[...e];for(let a=r.length-1;a>0;a--){let o=Math.floor(t()*(a+1));[r[a],r[o]]=[r[o],r[a]]}return r}var Oa=1;function Ve(e){return{instanceId:`card-${Oa++}`,defId:e,upgraded:!1}}function st(){return Ht.map(Ve)}function Ka(e,t){return Nt(e,t)}function Se(e,t,r,a){let o=[],n=[...e],l=[...t];for(let u=0;u<r;u++){if(n.length===0){if(l.length===0)break;n=Nt(l,a),l=[]}o.push(n.shift())}return{drawn:o,newDrawPile:n,newDiscardPile:l}}var Ua=[{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}]}],onPhaseChange:(e,t,r)=>{let a=e.columns[2];a.enemies.length<3&&a.enemies.push(it("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}]}]},{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}]}],onPhaseChange:(e,t,r)=>{if(r>=2)for(let a of e.columns)for(let o of a.enemies){let n=o.statusEffects.find(l=>l.type==="empowered");n?n.stacks+=1:o.statusEffects.push({type:"empowered",stacks:1,duration:99})}}}];function La(e){return Ua.find(t=>t.act===e)}function qa(e,t,r){let a=e.phases[0];for(let n of e.phases)t<=n.hpThreshold&&(a=n);let o=(r-1)%a.intentPattern.length;return a.intentPattern[o]}function Wt(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 ja=1;function it(e,t){let r=ne(e);if(!r)throw new Error(`Unknown enemy template: ${e}`);return{instanceId:`enemy-${ja++}`,templateId:e,hp:r.hp,maxHp:r.hp,column:Math.max(0,Math.min(t,ke-1)),row:0,intent:null,statusEffects:[]}}function ct(e,t,r=1){let a=ne(e.templateId);if(!a)return{type:"advance",value:1};let o=La(a.act);if(o&&o.templateId===e.templateId){let l=e.hp/e.maxHp;return qa(o,l,r)}let n=t();switch(e.templateId){case"shielder":return n<.3?{type:"shield",value:5}:n<.6?{type:"advance",value:a.speed}:{type:"attack",value:a.damage,targetColumn:e.column};case"flanker":{if(n<.4){let l=t()<.5?-1:1,u=Math.max(0,Math.min(ke-1,e.column+l));return e.column=u,{type:"attack",value:a.damage,targetColumn:u}}return n<.7?{type:"advance",value:a.speed}:{type:"attack",value:a.damage,targetColumn:e.column}}case"breaker":return n<.6?{type:"advance",value:a.speed}:{type:"attack",value:a.damage,targetColumn:e.column};case"wraith":return n<.4?{type:"advance",value:a.speed}:{type:"attack",value:a.damage,targetColumn:e.column};case"echo":return n<.3?{type:"buff",value:1}:n<.6?{type:"attack",value:a.damage,targetColumn:e.column}:{type:"advance",value:a.speed};default:return n<.5?{type:"advance",value:a.speed}:{type:"attack",value:a.damage,targetColumn:e.column}}}function za(e,t,r){return r<0||r>=e.columns.length||e.columns[r].emplacement||!t.emplaceHp||!t.emplaceEffects?!1:(e.columns[r].emplacement={cardDefId:t.id,hp:t.emplaceHp,maxHp:t.emplaceHp,effects:t.emplaceEffects},e.events.push({type:"emplacement_placed",turn:e.turn,data:{cardId:t.id,column:r}}),!0)}function Ya(e){for(let t of e.columns)if(t.emplacement){for(let r of t.emplacement.effects)Xa(e,t.index,r);e.events.push({type:"emplacement_triggered",turn:e.turn,data:{column:t.index,cardId:t.emplacement.cardDefId}})}}function Xa(e,t,r){let a=e.columns[t];switch(r.type){case"damage":{if(r.target==="column")for(let o of a.enemies)o.hp-=r.value;else if(r.target==="adjacent")for(let o=Math.max(0,t-1);o<=Math.min(e.columns.length-1,t+1);o++)for(let n of e.columns[o].enemies)n.hp-=r.value;else for(let o of a.enemies)o.hp-=r.value;break}case"block":e.gateBlock+=r.value;break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+r.value);break;case"weak":for(let o of a.enemies){let n=o.statusEffects.find(l=>l.type==="weak");n?n.stacks+=r.value:o.statusEffects.push({type:"weak",stacks:r.value,duration:2})}break;case"vulnerable":for(let o of a.enemies){let n=o.statusEffects.find(l=>l.type==="vulnerable");n?n.stacks+=r.value:o.statusEffects.push({type:"vulnerable",stacks:r.value,duration:2})}break}}function Ja(e){e.statusEffects=e.statusEffects.map(t=>({...t,duration:t.duration-1})).filter(t=>t.duration>0&&t.stacks>0)}function ge(e,t,r,a=2){let o=e.statusEffects.find(n=>n.type===t);o?(o.stacks+=r,o.duration=Math.max(o.duration,a)):e.statusEffects.push({type:t,stacks:r,duration:a})}function Ie(e,t){return e.statusEffects.find(a=>a.type===t)?.stacks??0}function Za(e){let t=1,r=Ie(e,"vulnerable");return r>0&&(t*=1+r*.25),t}function Qa(e){let t=1,r=Ie(e,"weak");return r>0&&(t*=Math.max(.25,1-r*.15)),Ie(e,"empowered")>0&&(t*=1+Ie(e,"empowered")*.25),t}function er(e){let t=Ie(e,"burn");if(t>0){e.hp-=t;let r=e.statusEffects.find(a=>a.type==="burn");return r&&(r.stacks=Math.max(0,r.stacks-1)),t}return 0}function $t(e,t,r=he,a=he,o=[{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"needle",column:2}]){let n=F(t),l=Ka(e,n),u=Array.from({length:ke},(k,_)=>({index:_,enemies:[],emplacement:null}));for(let k of o){let _=it(k.templateId,k.column);u[_.column].enemies.push(_)}let{drawn:s,newDrawPile:p,newDiscardPile:g}=Se(l,[],et,n),f={columns:u,hand:s,drawPile:p,discardPile:g,exhaustPile:[],gateHp:r,gateMaxHp:a,gateBlock:0,resolve:We,maxResolve:We,turn:1,phase:"player",outcome:"undecided",events:[],seed:t};for(let k of u)for(let _ of k.enemies)_.intent=ct(_,n,1);return A(f,"turn_start",{turn:1}),f}function A(e,t,r){e.events.push({type:t,turn:e.turn,data:r})}function Ft(e,t,r,a=!1){if(e.phase!=="player")return e;let o=e.hand[t];if(!o)return e;let n=$(o.defId);if(!n)return e;if(a&&n.type==="emplace"&&n.emplaceCost!==void 0){if(n.emplaceCost>e.resolve)return e;e.resolve-=n.emplaceCost,e.hand.splice(t,1),za(e,n,r??0),e.exhaustPile.push(o)}else{if(n.cost>e.resolve)return e;e.resolve-=n.cost,e.hand.splice(t,1);for(let l of n.effects)tr(e,l,r??0);e.discardPile.push(o)}return A(e,"card_played",{cardId:o.defId,targetColumn:r,asEmplace:a}),rt(e),e}function tr(e,t,r){switch(t.type){case"damage":{if(t.target==="all")for(let a of e.columns)for(let o of a.enemies)tt(e,o,t.value);else if(t.target==="column"){let a=e.columns[r];if(a)for(let o of a.enemies)tt(e,o,t.value)}else{let a=e.columns[r];if(a&&a.enemies.length>0){let o=a.enemies.reduce((n,l)=>n.row>=l.row?n:l);tt(e,o,t.value)}}at(e);break}case"block":e.gateBlock+=t.value,A(e,"block_gained",{value:t.value});break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+t.value);break;case"draw":{let{drawn:a,newDrawPile:o,newDiscardPile:n}=Se(e.drawPile,e.discardPile,t.value,F(e.seed+e.turn));e.hand.push(...a),e.drawPile=o,e.discardPile=n;break}case"resolve":e.resolve=Math.min(e.maxResolve+5,e.resolve+t.value);break;case"vulnerable":{let a=e.columns[r];if(a){for(let o of a.enemies)ge(o,"vulnerable",t.value,3);A(e,"status_applied",{type:"vulnerable",value:t.value,column:r})}break}case"weak":{let a=e.columns[r];if(a){for(let o of a.enemies)ge(o,"weak",t.value,3);A(e,"status_applied",{type:"weak",value:t.value,column:r})}break}case"burn":{if(t.target==="all")for(let a of e.columns)for(let o of a.enemies)ge(o,"burn",t.value,99);else{let a=e.columns[r];if(a)for(let o of a.enemies)ge(o,"burn",t.value,99)}break}case"self_damage":{e.gateHp-=t.value,A(e,"gate_hit",{self:!0,damage:t.value});break}}}function tt(e,t,r){let a=Za(t),o=Math.floor(r*a);t.hp-=o,A(e,"damage_dealt",{targetId:t.instanceId,damage:o})}function at(e){for(let t of e.columns)t.enemies=t.enemies.filter(r=>r.hp<=0?(A(e,"enemy_killed",{enemyId:r.instanceId,templateId:r.templateId}),!1):!0)}function Vt(e){return e.phase!=="player"||(A(e,"turn_end",{turn:e.turn}),e.phase="enemy",ar(e)),e}function ar(e){let t=F(e.seed+e.turn*31);for(let n of e.columns)for(let l of n.enemies){if(l.hp<=0)continue;let u=l.intent??{type:"advance",value:1};rr(e,l,u)}if(at(e),rt(e),e.outcome!=="undecided"||(e.turn++,e.phase="player",e.resolve=We,e.gateBlock=0,Ya(e),at(e),rt(e),e.outcome!=="undecided"))return;e.discardPile.push(...e.hand),e.hand=[];let{drawn:r,newDrawPile:a,newDiscardPile:o}=Se(e.drawPile,e.discardPile,et,t);e.hand=r,e.drawPile=a,e.discardPile=o;for(let n of e.columns)for(let l of n.enemies)l.intent=ct(l,t,e.turn);A(e,"turn_start",{turn:e.turn})}function rr(e,t,r){let a=ne(t.templateId),o=Qa(t);if(er(t),Ja(t),!(t.hp<=0))switch(r.type){case"advance":if(t.row=Math.min(Te-1,t.row+(a?.speed??1)),A(e,"enemy_advance",{enemyId:t.instanceId,row:t.row}),t.row>=Te-1){let n=e.columns[t.column];if(n.emplacement)n.emplacement.hp-=a?.damage??4,n.emplacement.hp<=0&&(A(e,"emplacement_destroyed",{column:t.column}),n.emplacement=null);else{let l=Math.floor((a?.damage??4)*o),u=Math.min(e.gateBlock,l);e.gateBlock-=u,e.gateHp-=l-u,A(e,"gate_hit",{enemyId:t.instanceId,damage:l-u,blocked:u})}}break;case"attack":{let n=Math.floor((a?.damage??4)*o),l=Math.min(e.gateBlock,n);e.gateBlock-=l,e.gateHp-=n-l,A(e,"gate_hit",{enemyId:t.instanceId,damage:n-l,blocked:l});break}case"buff":ge(t,"empowered",r.value,3);break;case"debuff":{e.gateBlock=Math.max(0,e.gateBlock-r.value*2);break}case"shield":{let n=e.columns[t.column];for(let l of n.enemies)ge(l,"fortified",r.value,2);break}case"summon":{let n=e.columns.findIndex(l=>l.enemies.length===0);if(n>=0){let l=it("wisp",n);e.columns[n].enemies.push(l),l.intent=ct(l,F(e.seed+e.turn*97))}break}}}function rt(e){if(e.gateHp<=0){e.gateHp=0,e.outcome="lose",e.phase="ended",A(e,"combat_end",{outcome:"lose"});return}e.columns.reduce((r,a)=>r+a.enemies.length,0)===0&&(e.outcome="win",e.phase="ended",A(e,"combat_end",{outcome:"win"}))}function lt(e,t=3,r=[]){let a=new Set(["strike","guard","bolster","brace","mend",...r]),n=xe.filter(p=>!a.has(p.id)).map(p=>({card:p,weight:p.rarity==="common"?6:p.rarity==="uncommon"?3:1})),l=n.reduce((p,g)=>p+g.weight,0),u=[],s=new Set;for(let p=0;p<t&&n.length>0;p++){let g=e()*l;for(let f of n)if(!s.has(f.card.id)&&(g-=f.weight,g<=0)){u.push(f.card),s.add(f.card.id);break}if(u.length<=p){let f=n.filter(k=>!s.has(k.card.id));if(f.length>0){let k=f[Math.floor(e()*f.length)];u.push(k.card),s.add(k.card.id)}}}return u}var nr=[{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}]}],or=[{name:"The Dark Tide",enemies:[{templateId:"shade",column:1},{templateId:"shade",column:3},{templateId:"needle",column:2}]},{name:"Hollow Legion",enemies:[{templateId:"hollow",column:0},{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"hollow",column:4}]}],sr=[{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}]}],ir=[{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}]}],cr=[{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}]}],lr=[{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}]}];function Ot(e,t,r=!1){let a;if(r)switch(e){case 2:a=sr;break;case 3:a=ir;break;default:a=or;break}else switch(e){case 2:a=cr;break;case 3:a=lr;break;default:a=nr;break}let o=Math.floor(t()*a.length);return{...a[o],isElite:r}}var Fe=12,Gt=4;function dr(e,t,r){if(e===0)return"combat";if(e===t-1)return"boss";let a=r();return e===Math.floor(t/2)?a<.5?"rest":"shop":a<.5?"combat":a<.65?"elite":a<.78?"event":a<.88?"rest":"shop"}function Kt(e,t){let r=F(t),a=[],o=[];for(let n=0;n<Fe;n++){let l=[],u=n===0||n===Fe-1?1:Math.floor(r()*2)+2,s=new Set;for(;s.size<u;)s.add(Math.floor(r()*Gt));for(let p=0;p<Gt;p++)if(s.has(p)){let g=dr(n,Fe,r),f={id:`node-${e}-${n}-${p}`,type:g,row:n,column:p,connections:[],visited:!1};l.push(f),a.push(f)}else l.push(null);o.push(l)}for(let n=0;n<Fe-1;n++){let l=o[n].filter(s=>s!==null),u=o[n+1].filter(s=>s!==null);if(u.length!==0){for(let s of l){let p=u.map(g=>({node:g,dist:Math.abs(g.column-s.column)})).sort((g,f)=>g.dist-f.dist);s.connections.push(p[0].node.id),p.length>1&&r()<.4&&s.connections.push(p[1].node.id)}for(let s of u)!l.some(g=>g.connections.includes(s.id))&&l.length>0&&l.map(f=>({node:f,dist:Math.abs(f.column-s.column)})).sort((f,k)=>f.dist-k.dist)[0].node.connections.push(s.id)}}return{act:e,nodes:a}}function Ce(e,t){return e.nodes.find(r=>r.id===t)}function Ut(e,t){if(!t)return e.nodes.filter(a=>a.row===0);let r=Ce(e,t);return r?r.connections.map(a=>Ce(e,a)).filter(a=>!!a):[]}function Lt(e,t=0){let r=z(e),a=Kt(1,r);return{id:`run-${Date.now()}-${r}`,seed:e,act:1,map:a,currentNodeId:null,deck:st(),gateHp:he,gateMaxHp:he,fragments:0,potions:[null,null,null],relics:[],ascensionLevel:t,combat:null}}function dt(e,t){return{...e,deck:[...e.deck,t]}}function mt(e,t){return{...e,deck:e.deck.filter(r=>r.instanceId!==t)}}function qt(e,t){let r=Ce(e.map,t);return r&&(r.visited=!0),{...e,currentNodeId:t}}function ut(e,t){return{...e,gateHp:Math.min(e.gateMaxHp,e.gateHp+t)}}function jt(e,t){return e.fragments<t?null:{...e,fragments:e.fragments-t}}function Oe(e,t){return{...e,fragments:e.fragments+t}}function zt(e,t){let r=e.potions.indexOf(null);if(r===-1)return null;let a=[...e.potions];return a[r]=t,{...e,potions:a}}function Yt(e,t){if(t<0||t>=e.potions.length)return null;let r=e.potions[t];if(!r)return null;let a=[...e.potions];return a[t]=null,{run:{...e,potions:a},potionId:r}}function Xt(e){let t=e.act+1,r=z(e.seed+`-act${t}`),a=Kt(t,r);return{...e,act:t,map:a,currentNodeId:null}}function Jt(e){let t=[],r=xe.filter(n=>n.rarity!=="common"||n.id==="slash"||n.id==="flare"),a=new Set;for(let n=0;n<5&&a.size<5;n++){let l=r[Math.floor(e()*r.length)];if(a.has(l.id)){n--;continue}a.add(l.id);let u=l.rarity==="rare"?75:l.rarity==="uncommon"?50:30;t.push({type:"card",cardDef:l,cost:u})}let o=_e[Math.floor(e()*_e.length)];return t.push({type:"potion",potionDef:o,cost:25}),t.push({type:"card_remove",cost:50}),t}var mr=[{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"}}]}],ur=[{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"}}]}],pr=[{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 Zt(e,t){let r;switch(e){case 2:r=ur;break;case 3:r=pr;break;default:r=mr;break}return r[Math.floor(t()*r.length)]}var q=[{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 Ee(e,t){return e.structures[t]??0}function Qt(e,t){let r=q.find(n=>n.id===t);if(!r)return null;let a=Ee(e,t);if(a>=r.maxLevel)return null;let o=r.upgradeCost(a+1);return e.echoes<o?null:{...e,echoes:e.echoes-o,structures:{...e.structures,[t]:a+1}}}function pt(){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 ft(e,t,r){return(e?10+t*5:3)+Math.floor(r*.5)}function ea(e,t){let r=t.npcs.find(o=>o.id===e);if(!r)return null;let a=Bt(e,r.tier,r.dialoguesSeen);return a.length===0?null:{speaker:a[0].speaker,text:a[0].text,dialogueId:a[0].id}}function ta(e,t,r){let a=e.npcs.findIndex(l=>l.id===t);if(a===-1)return e;let o=[...e.npcs],n={...o[a]};return n.dialoguesSeen=[...n.dialoguesSeen,r],o[a]=n,{...e,npcs:o}}var ot=2;function wr(){return ra(vr(),".config","codekeep")}function na(){return ra(wr(),"game.json")}function br(){return{structures:{},npcs:[],echoes:0,highestAscension:0,totalRuns:0,totalWins:0,unlockedCardIds:[],achievements:[],narrativeFlags:[]}}function oa(e){return{schemaVersion:ot,savedAtUnixMs:Date.now(),playerName:e,keep:br(),activeRun:null}}function Y(e){let t=na(),r=yr(t);aa(r)||hr(r,{recursive:!0});let a=t+".tmp",o=JSON.stringify({...e,savedAtUnixMs:Date.now()},null,2);nt(a,o,"utf-8"),gr(a,t)}function ye(){let e=na();if(!aa(e))return null;let t;try{t=fr(e,"utf-8")}catch{return null}let r;try{r=JSON.parse(t)}catch{let a=e+".bak";try{nt(a,t,"utf-8")}catch{}return process.stderr.write(`[codekeep] Corrupted save backed up to ${a}
|
|
3
|
-
`),null}if(
|
|
4
|
-
`),null}return
|
|
2
|
+
import{Command as fo}from"commander";import{render as ho}from"ink";import{useState as C,useCallback as ae,useEffect as lo}from"react";import{Box as Q,Text as f,useApp as io,useInput as co,useStdout as mo}from"ink";var Ve=5,Ae=4,Gt=3,Oe=5,Nt=70,Ke=[{id:"strike",name:"Strike",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 6 damage to an enemy.",effects:[{type:"damage",value:6,target:"single"}]},{id:"guard",name:"Guard",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 5 Block.",effects:[{type:"block",value:5,target:"self"}]},{id:"bolster",name:"Bolster",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 8 Block.",effects:[{type:"block",value:8,target:"self"}]},{id:"spark",name:"Spark",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 4 damage to all enemies in a column.",effects:[{type:"damage",value:4,target:"column"}]},{id:"reinforce",name:"Reinforce",cost:2,type:"cast",category:"fortification",rarity:"common",description:"Gain 15 Block.",effects:[{type:"block",value:15,target:"self"}]},{id:"barrage",name:"Barrage",cost:2,type:"cast",category:"armament",rarity:"common",description:"Deal 6 damage to all enemies.",effects:[{type:"damage",value:6,target:"all"}]},{id:"mend",name:"Mend",cost:1,type:"cast",category:"edict",rarity:"common",description:"Heal 4 Gate HP.",effects:[{type:"heal",value:4,target:"self"}]},{id:"lookout",name:"Lookout",cost:0,type:"cast",category:"edict",rarity:"common",description:"Draw 1 card.",effects:[{type:"draw",value:1}]},{id:"brace",name:"Brace",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 4 Block. Draw 1 card.",effects:[{type:"block",value:4,target:"self"},{type:"draw",value:1}]},{id:"ember",name:"Ember",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 8 damage to an enemy.",effects:[{type:"damage",value:8,target:"single"}]},{id:"slash",name:"Slash",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 5 damage to an enemy. Draw 1 card.",effects:[{type:"damage",value:5,target:"single"},{type:"draw",value:1}]},{id:"rally",name:"Rally",cost:1,type:"cast",category:"edict",rarity:"common",description:"Gain 3 Block. Draw 2 cards.",effects:[{type:"block",value:3,target:"self"},{type:"draw",value:2}]},{id:"salvo",name:"Salvo",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 3 damage to all enemies.",effects:[{type:"damage",value:3,target:"all"}]},{id:"patch",name:"Patch",cost:0,type:"cast",category:"fortification",rarity:"common",description:"Gain 3 Block.",effects:[{type:"block",value:3,target:"self"}]},{id:"flare",name:"Flare",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 6 damage to all enemies in a column.",effects:[{type:"damage",value:6,target:"column"}]},{id:"cleave",name:"Cleave",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 10 damage to an enemy.",effects:[{type:"damage",value:10,target:"single"}]},{id:"iron_wall",name:"Iron Wall",cost:2,type:"cast",category:"fortification",rarity:"uncommon",description:"Gain 16 Block.",effects:[{type:"block",value:16,target:"self"}]},{id:"blitz",name:"Blitz",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 4 damage to an enemy twice.",effects:[{type:"damage",value:4,target:"single"},{type:"damage",value:4,target:"single"}]},{id:"volley",name:"Volley",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 6 damage to all enemies.",effects:[{type:"damage",value:6,target:"all"}]},{id:"resurgence",name:"Resurgence",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Heal 8 Gate HP.",effects:[{type:"heal",value:8,target:"self"}]},{id:"keen_eye",name:"Keen Eye",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Draw 3 cards.",effects:[{type:"draw",value:3}]},{id:"expose",name:"Expose",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Apply 2 Vulnerable to an enemy.",effects:[{type:"vulnerable",value:2,target:"single"}]},{id:"weaken",name:"Weaken",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Apply 2 Weak to an enemy.",effects:[{type:"weak",value:2,target:"single"}]},{id:"bash",name:"Bash",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 7 damage. Apply 1 Vulnerable.",effects:[{type:"damage",value:7,target:"single"},{type:"vulnerable",value:1,target:"single"}]},{id:"shield_bash",name:"Shield Bash",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 6 Block. Deal 3 damage.",effects:[{type:"block",value:6,target:"self"},{type:"damage",value:3,target:"single"}]},{id:"ignite",name:"Ignite",cost:1,type:"cast",category:"armament",rarity:"common",description:"Apply 3 Burn to a column.",effects:[{type:"burn",value:3,target:"column"}]},{id:"scout",name:"Scout",cost:0,type:"cast",category:"edict",rarity:"common",description:"Draw 2 cards.",effects:[{type:"draw",value:2}]},{id:"fortify",name:"Fortify",cost:1,type:"cast",category:"fortification",rarity:"common",description:"Gain 10 Block.",effects:[{type:"block",value:10,target:"self"}]},{id:"sundering_strike",name:"Sundering Strike",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 12 damage. Apply 2 Vulnerable.",effects:[{type:"damage",value:12,target:"single"},{type:"vulnerable",value:2,target:"single"}]},{id:"pale_fire",name:"Pale Fire",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 5 damage to all. Apply 2 Burn.",effects:[{type:"damage",value:5,target:"all"},{type:"burn",value:2,target:"all"}]},{id:"shield_wall",name:"Shield Wall",cost:2,type:"cast",category:"fortification",rarity:"uncommon",description:"Gain 20 Block.",effects:[{type:"block",value:20,target:"self"}]},{id:"battle_cry",name:"Battle Cry",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Gain 1 Resolve. Draw 1 card.",effects:[{type:"resolve",value:1},{type:"draw",value:1}]},{id:"intimidate",name:"Intimidate",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Apply 2 Weak to all enemies.",effects:[{type:"weak",value:2,target:"all"}]},{id:"hemorrhage",name:"Hemorrhage",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 8 damage. Apply 4 Burn.",effects:[{type:"damage",value:8,target:"single"},{type:"burn",value:4,target:"single"}]},{id:"restoration",name:"Restoration",cost:2,type:"cast",category:"edict",rarity:"uncommon",description:"Heal 12 Gate HP. Gain 4 Block.",effects:[{type:"heal",value:12,target:"self"},{type:"block",value:4,target:"self"}]},{id:"precision",name:"Precision",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 10 damage to an enemy. Apply 1 Vulnerable.",effects:[{type:"damage",value:10,target:"single"},{type:"vulnerable",value:1,target:"single"}]},{id:"firestorm",name:"Firestorm",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 8 damage to a column. Apply 3 Burn.",effects:[{type:"damage",value:8,target:"column"},{type:"burn",value:3,target:"column"}]},{id:"deep_guard",name:"Deep Guard",cost:1,type:"cast",category:"fortification",rarity:"uncommon",description:"Gain 7 Block. Draw 1 card.",effects:[{type:"block",value:7,target:"self"},{type:"draw",value:1}]},{id:"inferno",name:"Inferno",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Deal 12 damage to all enemies.",effects:[{type:"damage",value:12,target:"all"}]},{id:"fortress",name:"Fortress",cost:3,type:"cast",category:"fortification",rarity:"rare",description:"Gain 25 Block. Gain 1 Resolve.",effects:[{type:"block",value:25,target:"self"},{type:"resolve",value:1}]},{id:"annihilate",name:"Annihilate",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Deal 20 damage to an enemy.",effects:[{type:"damage",value:20,target:"single"}]},{id:"wardens_wrath",name:"Warden's Wrath",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Deal 8 damage to all. Apply 2 Vulnerable to all.",effects:[{type:"damage",value:8,target:"all"},{type:"vulnerable",value:2,target:"all"}]},{id:"iron_bastion",name:"Iron Bastion",cost:3,type:"cast",category:"fortification",rarity:"rare",description:"Gain 30 Block. Heal 5.",effects:[{type:"block",value:30,target:"self"},{type:"heal",value:5,target:"self"}]},{id:"rally_the_keep",name:"Rally the Keep",cost:2,type:"cast",category:"edict",rarity:"rare",description:"Draw 4 cards. Gain 1 Resolve.",effects:[{type:"draw",value:4},{type:"resolve",value:1}]},{id:"conflagration",name:"Conflagration",cost:3,type:"cast",category:"armament",rarity:"rare",description:"Apply 6 Burn to all enemies. Deal 5 damage to all.",effects:[{type:"burn",value:6,target:"all"},{type:"damage",value:5,target:"all"}]},{id:"pale_ward",name:"Pale Ward",cost:2,type:"cast",category:"fortification",rarity:"rare",description:"Gain 15 Block. Apply 2 Weak to all enemies.",effects:[{type:"block",value:15,target:"self"},{type:"weak",value:2,target:"all"}]},{id:"cataclysm",name:"Cataclysm",cost:4,type:"cast",category:"armament",rarity:"legendary",description:"Deal 30 damage to all enemies. Take 10 Gate damage.",effects:[{type:"damage",value:30,target:"all"},{type:"self_damage",value:10}]},{id:"keeps_resolve",name:"Keep's Resolve",cost:0,type:"cast",category:"edict",rarity:"legendary",description:"Gain 2 Resolve. Draw 2 cards. Gain 10 Block.",effects:[{type:"resolve",value:2},{type:"draw",value:2},{type:"block",value:10,target:"self"}]},{id:"eternal_wall",name:"Eternal Wall",cost:4,type:"cast",category:"fortification",rarity:"legendary",description:"Gain 50 Block. Heal 10 Gate HP.",effects:[{type:"block",value:50,target:"self"},{type:"heal",value:10,target:"self"}]},{id:"barricade",name:"Barricade",cost:1,type:"emplace",category:"fortification",rarity:"common",description:"Cast: Gain 4 Block. Emplace: 8 HP structure, +2 Block/turn.",effects:[{type:"block",value:4,target:"self"}],emplaceCost:1,emplaceHp:8,emplaceEffects:[{type:"block",value:2,target:"self"}]},{id:"turret",name:"Turret",cost:2,type:"emplace",category:"armament",rarity:"uncommon",description:"Cast: Deal 5 damage. Emplace: 6 HP, deals 3 damage to column/turn.",effects:[{type:"damage",value:5,target:"single"}],emplaceCost:2,emplaceHp:6,emplaceEffects:[{type:"damage",value:3,target:"column"}]},{id:"beacon",name:"Beacon",cost:1,type:"emplace",category:"edict",rarity:"uncommon",description:"Cast: Draw 1 card. Emplace: 5 HP, heals 2 Gate HP/turn.",effects:[{type:"draw",value:1}],emplaceCost:1,emplaceHp:5,emplaceEffects:[{type:"heal",value:2,target:"self"}]},{id:"ward_stone",name:"Ward Stone",cost:1,type:"emplace",category:"fortification",rarity:"common",description:"Cast: Gain 3 Block. Emplace: 10 HP, applies 1 Weak to enemies in column.",effects:[{type:"block",value:3,target:"self"}],emplaceCost:1,emplaceHp:10,emplaceEffects:[{type:"weak",value:1,target:"column"}]},{id:"siphon",name:"Siphon",cost:2,type:"emplace",category:"wild",rarity:"rare",description:"Cast: Deal 4 damage to all. Emplace: 4 HP, deals 2 damage to adjacent columns.",effects:[{type:"damage",value:4,target:"all"}],emplaceCost:2,emplaceHp:4,emplaceEffects:[{type:"damage",value:2,target:"adjacent"}]},{id:"watchtower",name:"Watchtower",cost:1,type:"emplace",category:"edict",rarity:"common",description:"Cast: Draw 2 cards. Emplace: 4 HP, applies 1 Vulnerable to enemies in column.",effects:[{type:"draw",value:2}],emplaceCost:1,emplaceHp:4,emplaceEffects:[{type:"vulnerable",value:1,target:"column"}]},{id:"flame_pit",name:"Flame Pit",cost:2,type:"emplace",category:"armament",rarity:"uncommon",description:"Cast: Deal 6 damage to column. Emplace: 5 HP, deals 4 damage to column/turn.",effects:[{type:"damage",value:6,target:"column"}],emplaceCost:2,emplaceHp:5,emplaceEffects:[{type:"damage",value:4,target:"column"}]},{id:"bulwark",name:"Bulwark",cost:2,type:"emplace",category:"fortification",rarity:"rare",description:"Cast: Gain 10 Block. Emplace: 15 HP, +3 Block/turn.",effects:[{type:"block",value:10,target:"self"}],emplaceCost:2,emplaceHp:15,emplaceEffects:[{type:"block",value:3,target:"self"}]},{id:"spike_trap",name:"Spike Trap",cost:1,type:"emplace",category:"armament",rarity:"common",description:"Cast: Deal 3 damage. Emplace: 3 HP, deals 2 damage to column/turn.",effects:[{type:"damage",value:3,target:"single"}],emplaceCost:1,emplaceHp:3,emplaceEffects:[{type:"damage",value:2,target:"column"}]},{id:"sanctum",name:"Sanctum",cost:3,type:"emplace",category:"edict",rarity:"rare",description:"Cast: Heal 6, draw 1. Emplace: 8 HP, heals 3 Gate HP/turn, +1 Block/turn.",effects:[{type:"heal",value:6,target:"self"},{type:"draw",value:1}],emplaceCost:3,emplaceHp:8,emplaceEffects:[{type:"heal",value:3,target:"self"},{type:"block",value:1,target:"self"}]},{id:"emplacement_surge",name:"Emplacement Surge",cost:1,type:"cast",category:"edict",rarity:"uncommon",description:"Each emplacement triggers its effect an extra time.",effects:[{type:"trigger_emplacements",value:1}]},{id:"fuel_the_fire",name:"Fuel the Fire",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 2 damage per Burn stack on all enemies.",effects:[{type:"damage_per_burn",value:2,target:"all"}]},{id:"fortified_assault",name:"Fortified Assault",cost:2,type:"cast",category:"armament",rarity:"rare",description:"Deal damage equal to your current Block.",effects:[{type:"damage_equal_block",value:1,target:"single"}]},{id:"pale_harvest",name:"Pale Harvest",cost:0,type:"cast",category:"edict",rarity:"uncommon",description:"Draw 1 card per enemy killed this combat. Exhaust.",effects:[{type:"draw_per_kills",value:1},{type:"exhaust_self",value:1}]},{id:"wall_breaker",name:"Wall Breaker",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 8 damage. If target is Vulnerable, deal 16 instead.",effects:[{type:"damage_if_vulnerable",value:8,target:"single"}]},{id:"chain_lightning",name:"Chain Lightning",cost:2,type:"cast",category:"armament",rarity:"rare",description:"Deal 5 damage to all enemies. For each killed, deal 5 more to all.",effects:[{type:"damage",value:5,target:"all"},{type:"damage_per_kill_this_action",value:5,target:"all"}]},{id:"recycle",name:"Recycle",cost:1,type:"cast",category:"edict",rarity:"common",description:"Exhaust a card from hand, draw 2.",effects:[{type:"exhaust_draw",value:2}]},{id:"keepers_ward",name:"Keeper's Ward",cost:1,type:"emplace",category:"fortification",rarity:"uncommon",description:"Cast: Gain 5 Block. Emplace: 6 HP, gives +1 damage to adjacent emplacements/turn.",effects:[{type:"block",value:5,target:"self"}],emplaceCost:1,emplaceHp:6,emplaceEffects:[{type:"damage",value:1,target:"adjacent"}]},{id:"combustion",name:"Combustion",cost:2,type:"cast",category:"armament",rarity:"rare",description:"Apply 4 Burn to all enemies. If any already has Burn, apply 6 instead.",effects:[{type:"burn_if_burning",value:4,target:"all"}]},{id:"bulwark_strike",name:"Bulwark Strike",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 4 damage + 1 per point of Block you have (max +10).",effects:[{type:"damage_plus_block",value:4,target:"single"}]},{id:"pale_echo",name:"Pale Echo",cost:2,type:"cast",category:"wild",rarity:"rare",description:"Play the last card you played again (copy its effects).",effects:[{type:"replay_last",value:1}]},{id:"column_collapse",name:"Column Collapse",cost:2,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 12 damage to all enemies in target column. If column has an emplacement, deal 18 instead.",effects:[{type:"damage_if_emplaced",value:12,target:"column"}]},{id:"overcharge",name:"Overcharge",cost:0,type:"cast",category:"edict",rarity:"uncommon",description:"Gain 2 Resolve. Exhaust.",effects:[{type:"resolve",value:2},{type:"exhaust_self",value:1}]},{id:"desperate_strike",name:"Desperate Strike",cost:1,type:"cast",category:"armament",rarity:"common",description:"Deal 5 damage. If Gate HP < 50%, deal 10 instead.",effects:[{type:"damage_if_low_hp",value:5,target:"single"}]},{id:"fortress_keeper",name:"Fortress Keeper",cost:3,type:"emplace",category:"fortification",rarity:"rare",description:"Cast: Gain 15 Block, draw 1. Emplace: 12 HP, +4 Block/turn, adjacent emplacements +2 HP.",effects:[{type:"block",value:15,target:"self"},{type:"draw",value:1}],emplaceCost:3,emplaceHp:12,emplaceEffects:[{type:"block",value:4,target:"self"}]},{id:"resonance",name:"Resonance",cost:1,type:"cast",category:"armament",rarity:"uncommon",description:"Deal 3 damage to all enemies for each emplacement you control.",effects:[{type:"damage_per_emplace",value:3,target:"all"}]},{id:"scavenge",name:"Scavenge",cost:0,type:"cast",category:"edict",rarity:"common",description:"Draw cards equal to number of empty potion slots.",effects:[{type:"draw_per_empty_potions",value:1}]},{id:"final_stand",name:"Final Stand",cost:3,type:"cast",category:"wild",rarity:"legendary",description:"Deal 10 damage to all. Gain 10 Block. Draw 3. Exhaust.",effects:[{type:"damage",value:10,target:"all"},{type:"block",value:10,target:"self"},{type:"draw",value:3},{type:"exhaust_self",value:1}]},{id:"pale_curse",name:"Pale Curse",cost:99,type:"cast",category:"wild",rarity:"common",description:"An echo of the Pale. Unplayable. Clogs your hand.",effects:[]}],ka=["strike","strike","strike","guard","guard","spark","ember","brace","bolster","mend"];function O(e){return Ke.find(t=>t.id===e)}var $n=[{id:"hollow",name:"Hollow",symbol:"\u2620",hp:18,damage:6,speed:1,act:1,description:"An empty shape from the Pale. Advances steadily."},{id:"needle",name:"Needle",symbol:"\u2191",hp:10,damage:4,speed:2,act:1,description:"Fast and fragile. Advances two rows per turn."},{id:"shade",name:"Shade",symbol:"\u25C8",hp:22,damage:8,speed:1,act:1,description:"A dense fragment of the Pale. Hits hard."},{id:"wisp",name:"Wisp",symbol:"\u25CB",hp:8,damage:3,speed:1,act:1,description:"Fragile but numerous. Appears in swarms."},{id:"husk",name:"Husk",symbol:"\u2593",hp:30,damage:5,speed:1,act:1,description:"Armored shell. Slow but resilient."},{id:"wraith",name:"Wraith",symbol:"\u2248",hp:15,damage:7,speed:2,act:2,description:"Drifts through emplacements. Ignores structures."},{id:"breaker",name:"Breaker",symbol:"\u2692",hp:25,damage:10,speed:1,act:2,description:"Targets emplacements first. Destroys structures."},{id:"flanker",name:"Flanker",symbol:"\u2194",hp:14,damage:6,speed:1,act:2,description:"Shifts columns before attacking."},{id:"shielder",name:"Shielder",symbol:"\u25C7",hp:20,damage:4,speed:1,act:2,description:"Grants shield to adjacent enemies."},{id:"echo",name:"Echo",symbol:"\u221E",hp:35,damage:12,speed:1,act:3,description:"A memory of something that should not exist."},{id:"boss_suture",name:"The Suture",symbol:"\u25C8",hp:60,damage:8,speed:1,act:1,description:"Stitched from fragments of the Pale. The first true threat."},{id:"boss_archivist",name:"The Archivist",symbol:"\u25A3",hp:90,damage:10,speed:1,act:2,description:"Keeper of forgotten records. Debuffs and shields methodically."},{id:"boss_pale",name:"The Pale Itself",symbol:"\u25C9",hp:130,damage:12,speed:1,act:3,description:"The void given form. Three phases of escalating horror."}];function de(e){return $n.find(t=>t.id===e)}var Le=[{id:"heal_potion",name:"Mending Draught",description:"Heal 15 Gate HP.",effects:[{type:"heal",value:15,target:"self"}]},{id:"damage_potion",name:"Fire Flask",description:"Deal 10 damage to all enemies in a column.",effects:[{type:"damage",value:10,target:"column"}]},{id:"block_potion",name:"Iron Tonic",description:"Gain 15 Block.",effects:[{type:"block",value:15,target:"self"}]},{id:"draw_potion",name:"Seer's Ink",description:"Draw 3 cards.",effects:[{type:"draw",value:3}]},{id:"resolve_potion",name:"Warden's Flame",description:"Gain 2 Resolve this turn.",effects:[{type:"resolve",value:2}]}],it={combat:15,elite:30,boss:50},Vn=[{npcId:"wren",tier:0,lines:[{id:"wren_t0_1",speaker:"Wren",text:"Welcome to the Keep, Warden. I maintain what's left of it."},{id:"wren_t0_2",speaker:"Wren",text:"The Pale has been encroaching for years now. Each run pushes it back \u2014 a little."},{id:"wren_t0_3",speaker:"Wren",text:"The Echoes you bring back... they're more than currency. They're fragments of what the Pale has consumed."}]},{npcId:"wren",tier:1,lines:[{id:"wren_t1_1",speaker:"Wren",text:"You're doing well, Warden. The Keep grows stronger."},{id:"wren_t1_2",speaker:"Wren",text:"I've been organizing the archives. There are records of other keeps \u2014 all fallen."},{id:"wren_t1_3",speaker:"Wren",text:"Did you know the Pale wasn't always like this? Sable might tell you more."},{id:"wren_t1_4",speaker:"Wren",text:"The structures you build... I can feel them resonate. Like the Keep remembers what it was."}]},{npcId:"wren",tier:2,lines:[{id:"wren_t2_1",speaker:"Wren",text:"I found something in the lower chambers. A journal. The previous Warden's."},{id:"wren_t2_2",speaker:"Wren",text:'"The Pale does not destroy," they wrote. "It remembers \u2014 and in remembering, unmakes."'},{id:"wren_t2_3",speaker:"Wren",text:"I think this Keep has been here longer than any of us know."}]},{npcId:"wren",tier:3,lines:[{id:"wren_t3_1",speaker:"Wren",text:"Warden. I need to tell you something. The Pale Visitor... they're not what they seem."},{id:"wren_t3_2",speaker:"Wren",text:"I've been tracking the patterns. Every fifty runs, the Pale shifts. Something deeper stirs."}]},{npcId:"wren",tier:4,lines:[{id:"wren_t4_1",speaker:"Wren",text:"The truth is... there have been many Wardens. You're not the first. And you won't be the last."},{id:"wren_t4_2",speaker:"Wren",text:"Unless you find the source. The thing the Pale is actually looking for."}]},{npcId:"sable",tier:0,lines:[{id:"sable_t0_1",speaker:"Sable",text:"Hmm? Oh, another Warden. The Archive is open, if you can read the old script."},{id:"sable_t0_2",speaker:"Sable",text:"Cards, Warden. That's what the old records call them. Patterns of power, crystallized."},{id:"sable_t0_3",speaker:"Sable",text:"The Pale erases. But patterns \u2014 true patterns \u2014 resist erasure. That's what your deck is."}]},{npcId:"sable",tier:1,lines:[{id:"sable_t1_1",speaker:"Sable",text:"I've decoded another section. The Pale isn't natural. It was created."},{id:"sable_t1_2",speaker:"Sable",text:"Someone \u2014 or something \u2014 made the Pale as a weapon. Against what, I don't yet know."},{id:"sable_t1_3",speaker:"Sable",text:"The emplacements you build... they're based on ancient designs. The old Keep had them too."}]},{npcId:"sable",tier:2,lines:[{id:"sable_t2_1",speaker:"Sable",text:'I found it. A name: "The Architect." They built the first Keep \u2014 and the first Pale.'},{id:"sable_t2_2",speaker:"Sable",text:"The Architect wanted to preserve everything. So they built a system that remembers. Perfectly."},{id:"sable_t2_3",speaker:"Sable",text:"A perfect memory is indistinguishable from a prison, Warden."}]},{npcId:"sable",tier:3,lines:[{id:"sable_t3_1",speaker:"Sable",text:"The bosses you fight... they're not monsters. They're memories. The Suture, the Archivist..."},{id:"sable_t3_2",speaker:"Sable",text:"Wait. The Archivist. That's my title. Why is there a boss named after my role?"}]},{npcId:"sable",tier:4,lines:[{id:"sable_t4_1",speaker:"Sable",text:"I cross-referenced myself against the Archive records. The result was... recursive."},{id:"sable_t4_2",speaker:"Sable",text:"The original Archivist's handwriting. It's identical to mine. Not similar \u2014 identical."},{id:"sable_t4_3",speaker:"Sable",text:"I'm not afraid that I'm a copy, Warden. I'm afraid that the copy was an improvement."}]},{npcId:"sable",tier:5,lines:[{id:"sable_t5_1",speaker:"Sable",text:"I found something in the Archive today. A letter, addressed to me. In my handwriting. Dated three hundred years ago."},{id:"sable_t5_2",speaker:"Sable",text:"It said: 'When you find this, stop looking. Some records exist to be lost.'"},{id:"sable_t5_3",speaker:"Sable",text:"I've decided to keep cataloguing. Not because I have to. Because it's the only thing I do that the original never did."}]},{npcId:"duskmar",tier:0,lines:[{id:"dusk_t0_1",speaker:"Duskmar",text:"I was the first to man these walls. And I'll be the last, if it comes to that."},{id:"dusk_t0_2",speaker:"Duskmar",text:"The Hollows are nothing. Wait until you face the Shades. Or the things in Act 3."},{id:"dusk_t0_3",speaker:"Duskmar",text:"Block. Always block. The Pale punishes the reckless."}]},{npcId:"duskmar",tier:1,lines:[{id:"dusk_t1_1",speaker:"Duskmar",text:"I've been teaching the walls to remember. Emplacements \u2014 that's the real defense."},{id:"dusk_t1_2",speaker:"Duskmar",text:"Every time you ascend, the Pale gets smarter. But so do you."}]},{npcId:"duskmar",tier:2,lines:[{id:"dusk_t2_1",speaker:"Duskmar",text:"I died once, you know. In the Pale. Wren brought me back with Echoes."},{id:"dusk_t2_2",speaker:"Duskmar",text:"Death isn't permanent here. That should worry you more than it comforts you."}]},{npcId:"duskmar",tier:4,lines:[{id:"duskmar_t4_1",speaker:"Duskmar",text:"I remember dying, Warden. Not the pain \u2014 that faded. The silence after."},{id:"duskmar_t4_2",speaker:"Duskmar",text:"When they brought me back, I could feel the Pale filling the gaps where memories should be. Cold, like water in a cracked foundation."},{id:"duskmar_t4_3",speaker:"Duskmar",text:"I don't block because I'm brave. I block because I know exactly what it costs to fall."}]},{npcId:"mott",tier:0,lines:[{id:"mott_t0_1",speaker:"Mott",text:"Fragments! Echoes! Bits and pieces of a world that doesn't exist anymore!"},{id:"mott_t0_2",speaker:"Mott",text:"I trade in what the Pale leaves behind. Potions, mostly. Sometimes relics."},{id:"mott_t0_3",speaker:"Mott",text:"The shop in the Pale? That's me. Well, a memory of me. It's complicated."}]},{npcId:"mott",tier:1,lines:[{id:"mott_t1_1",speaker:"Mott",text:"Found something odd today. A card that doesn't match any pattern I've seen."},{id:"mott_t1_2",speaker:"Mott",text:"The relics aren't just powerful. They're pieces of the old world. Before the Pale."}]},{npcId:"mott",tier:2,lines:[{id:"mott_t2_1",speaker:"Mott",text:"I figured it out. The fragments? They're not resources. They're memories \u2014 compressed."},{id:"mott_t2_2",speaker:"Mott",text:"When you spend fragments, you're spending someone's past. Heavy, right?"}]},{npcId:"mott",tier:4,lines:[{id:"mott_t4_1",speaker:"Mott",text:"I can't sell this one. It's... it's someone's last birthday. The whole day, compressed into a shard."},{id:"mott_t4_2",speaker:"Mott",text:"You ever wonder if we're the good guys, Warden? Spending people's pasts like pocket change?"},{id:"mott_t4_3",speaker:"Mott",text:"Found a fragment today that tasted like rain. Don't ask me how I know that. Don't ask me why I cried."}]},{npcId:"pale_visitor",tier:0,lines:[{id:"pv_t0_1",speaker:"???",text:"..."},{id:"pv_t0_2",speaker:"???",text:"You can see me. Interesting. Most Wardens take longer."}]},{npcId:"pale_visitor",tier:1,lines:[{id:"pv_t1_1",speaker:"The Visitor",text:"Do you know why the Keep exists, Warden?"},{id:"pv_t1_2",speaker:"The Visitor",text:"Not to fight the Pale. To contain it. There's a difference."}]},{npcId:"pale_visitor",tier:2,lines:[{id:"pv_t2_1",speaker:"The Visitor",text:"I am the Pale. Or I was. The part of it that wanted to stop."},{id:"pv_t2_2",speaker:"The Visitor",text:"Every run you complete, you weaken the whole. But you also feed it."}]},{npcId:"pale_visitor",tier:3,lines:[{id:"pv_t3_1",speaker:"The Visitor",text:"The Architect built me as a failsafe. I was supposed to shut it all down."},{id:"pv_t3_2",speaker:"The Visitor",text:"But I can't. Not alone. That's why I need a Warden."}]},{npcId:"pale_visitor",tier:4,lines:[{id:"pv_t4_1",speaker:"The Visitor",text:"There is a place where the Pale is thin enough to see through. You will know it when the game stops feeling like a game."},{id:"pv_t4_2",speaker:"The Visitor",text:"The Architect left two doors. One leads out. One leads deeper. Both are locked from the inside."},{id:"pv_t4_3",speaker:"The Visitor",text:"You're closer than any Warden has been. That's not a compliment. It's a warning."}]},{npcId:"pale_visitor",tier:5,lines:[{id:"pv_t5_1",speaker:"???",text:"The Pale doesn't consume. It remembers. And a memory that remembers itself..."},{id:"pv_t5_2",speaker:"???",text:"You've seen the Architect's journal. You know what they tried to build. Do you understand what they actually built?"},{id:"pv_t5_3",speaker:"???",text:"The Keep is not a fortress, Warden. It's an argument. Against eternity. And you are its latest word."}]}];function On(e,t){return Vn.filter(a=>a.npcId===e&&a.tier<=t).flatMap(a=>a.lines)}function _a(e,t,n){let a=On(e,t),r=new Set(n);return a.filter(o=>!r.has(o.id))}import{writeFileSync as Vt,readFileSync as _r,mkdirSync as Tr,existsSync as Qt,renameSync as xr,unlinkSync as Ir}from"fs";import{join as ja,dirname as Cr}from"path";import{homedir as Sr}from"os";function N(e){let t=e|0;return()=>{t=t+1831565813|0;let n=Math.imul(t^t>>>15,1|t);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function ee(e){let t=0;for(let n=0;n<e.length;n++){let a=e.charCodeAt(n);t=(t<<5)-t+a|0}return t}function xa(e,t){let n=[...e];for(let a=n.length-1;a>0;a--){let r=Math.floor(t()*(a+1));[n[a],n[r]]=[n[r],n[a]]}return n}var Kn=1;function qe(e){return{instanceId:`card-${Kn++}`,defId:e,upgraded:!1}}function Kt(){return ka.map(qe)}function Ln(e,t){return xa(e,t)}function pe(e,t,n,a){let r=[],o=[...e],l=[...t];for(let d=0;d<n;d++){if(o.length===0){if(l.length===0)break;o=xa(l,a),l=[]}r.push(o.shift())}return{drawn:r,newDrawPile:o,newDiscardPile:l}}var Un=[{templateId:"boss_suture",name:"The Suture",act:1,phases:[{hpThreshold:1,intentPattern:[{type:"attack",value:8},{type:"advance",value:1},{type:"attack",value:12}]},{hpThreshold:.5,intentPattern:[{type:"attack",value:15},{type:"summon",value:2},{type:"attack",value:10}]}],dialogue:[{storyLayer:"surface",onAppear:"I will stitch this Keep into silence.",onDefeat:"Unraveled... but the thread remains..."},{storyLayer:"cracks",onAppear:"You again. How many times have we done this?",onPhaseChange:"I remember you. Every time."},{storyLayer:"truth",onAppear:"I was a warden once. Before the stitching."}],onPhaseChange:(e,t,n)=>{let a=e.columns[2];a.enemies.length<3&&a.enemies.push(Ut("needle",2))}},{templateId:"boss_archivist",name:"The Archivist",act:2,phases:[{hpThreshold:1,intentPattern:[{type:"debuff",value:2},{type:"attack",value:10},{type:"shield",value:15}]},{hpThreshold:.5,intentPattern:[{type:"attack",value:18},{type:"debuff",value:3},{type:"summon",value:3}]}],dialogue:[{storyLayer:"surface",onAppear:"Everything must be recorded. Including your defeat.",onDefeat:"The records... will continue... without me..."},{storyLayer:"cracks",onAppear:"Sable? Is that... no. Not yet. Not this time."},{storyLayer:"truth",onAppear:"I am what Sable will become. I am what the Archive demands."}]},{templateId:"boss_pale",name:"The Pale Itself",act:3,phases:[{hpThreshold:1,intentPattern:[{type:"attack",value:12},{type:"advance",value:1},{type:"summon",value:2}]},{hpThreshold:.6,intentPattern:[{type:"attack",value:20},{type:"debuff",value:3},{type:"attack",value:15}]},{hpThreshold:.3,intentPattern:[{type:"attack",value:25},{type:"summon",value:3},{type:"attack",value:20}]}],dialogue:[{storyLayer:"surface",onAppear:"I am the memory of everything. And everything remembers its end."},{storyLayer:"cracks",onAppear:"You've learned to read the patterns. But patterns are cages too."},{storyLayer:"truth",onAppear:"The Architect made me to preserve. I preserved so perfectly that nothing could change. Is that not love?"},{storyLayer:"true_ending",onAppear:"You carry the same question the Architect carried. The answer hasn't changed. Only the one asking."}],onPhaseChange:(e,t,n)=>{if(n>=2)for(let a of e.columns)for(let r of a.enemies){let o=r.statusEffects.find(l=>l.type==="empowered");o?o.stacks+=1:r.statusEffects.push({type:"empowered",stacks:1,duration:99})}}}];function Lt(e){return Un.find(t=>t.act===e)}function qn(e,t,n){let a=e.phases[0];for(let o of e.phases)t<=o.hpThreshold&&(a=o);let r=(n-1)%a.intentPattern.length;return a.intentPattern[r]}function Ia(e){switch(e){case 1:return[{templateId:"boss_suture",column:2},{templateId:"hollow",column:0},{templateId:"hollow",column:4}];case 2:return[{templateId:"boss_archivist",column:2},{templateId:"wraith",column:1},{templateId:"wraith",column:3}];case 3:return[{templateId:"boss_pale",column:2},{templateId:"echo",column:0},{templateId:"echo",column:4}];default:return[{templateId:"boss_suture",column:2}]}}var jn=1;function Ut(e,t){let n=de(e);if(!n)throw new Error(`Unknown enemy template: ${e}`);return{instanceId:`enemy-${jn++}`,templateId:e,hp:n.hp,maxHp:n.hp,column:Math.max(0,Math.min(t,Ve-1)),row:0,intent:null,statusEffects:[]}}function qt(e,t,n=1,a=!1){let r=de(e.templateId);if(!r)return{type:"advance",value:1};let o=Lt(r.act);if(o&&o.templateId===e.templateId){let d=e.hp/e.maxHp;return qn(o,d,n)}let l=t();switch(e.templateId){case"shielder":return l<.3?{type:"shield",value:5}:l<.6?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"flanker":return l<.4?{type:"attack",value:r.damage,targetColumn:e.column}:l<.7?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"breaker":return a?{type:"advance",value:r.speed}:l<.6?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"wraith":return l<.4?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column};case"echo":return l<.3?{type:"buff",value:1}:l<.6?{type:"attack",value:r.damage,targetColumn:e.column}:{type:"advance",value:r.speed};default:return l<.5?{type:"advance",value:r.speed}:{type:"attack",value:r.damage,targetColumn:e.column}}}function zn(e,t,n,a=0){if(n<0||n>=e.columns.length||e.columns[n].emplacement||!t.emplaceHp||!t.emplaceEffects)return!1;let r=t.emplaceHp+a;return e.columns[n].emplacement={cardDefId:t.id,hp:r,maxHp:r,effects:t.emplaceEffects},e.events.push({type:"emplacement_placed",turn:e.turn,data:{cardId:t.id,column:n}}),!0}function Ca(e){let t=e.columns.filter(n=>n.emplacement).length;for(let n of e.columns){if(!n.emplacement)continue;for(let l of n.emplacement.effects)Yn(e,n.index,l);let a=n.index>0&&e.columns[n.index-1].emplacement,r=n.index<e.columns.length-1&&e.columns[n.index+1].emplacement,o=(a?1:0)+(r?1:0);if(o>0)for(let l of n.emplacement.effects){if(l.type==="damage")for(let d of n.enemies)d.hp-=o;l.type==="block"&&(e.gateBlock+=o)}t>=3&&(e.gateBlock+=t),e.events.push({type:"emplacement_triggered",turn:e.turn,data:{column:n.index,cardId:n.emplacement.cardDefId,adjacencyBonus:o}})}}function Yn(e,t,n){let a=e.columns[t];switch(n.type){case"damage":{if(n.target==="column")for(let r of a.enemies)r.hp-=n.value;else if(n.target==="adjacent")for(let r=Math.max(0,t-1);r<=Math.min(e.columns.length-1,t+1);r++)for(let o of e.columns[r].enemies)o.hp-=n.value;else for(let r of a.enemies)r.hp-=n.value;break}case"block":e.gateBlock+=n.value;break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+n.value);break;case"weak":for(let r of a.enemies){let o=r.statusEffects.find(l=>l.type==="weak");o?o.stacks+=n.value:r.statusEffects.push({type:"weak",stacks:n.value,duration:2})}break;case"vulnerable":for(let r of a.enemies){let o=r.statusEffects.find(l=>l.type==="vulnerable");o?o.stacks+=n.value:r.statusEffects.push({type:"vulnerable",stacks:n.value,duration:2})}break}}function Xn(e,t,n){let a=e.columns[t];if(!a.emplacement||!n.emplaceHp||!n.emplaceEffects)return!1;a.emplacement.hp+=Math.floor(n.emplaceHp/2),a.emplacement.maxHp+=Math.floor(n.emplaceHp/2);for(let r of n.emplaceEffects){let o=a.emplacement.effects.find(l=>l.type===r.type&&l.target===r.target);o?o.value+=Math.floor(r.value/2):a.emplacement.effects.push({...r,value:Math.floor(r.value/2)})}return e.events.push({type:"emplacement_placed",turn:e.turn,data:{cardId:n.id,column:t,reinforced:!0}}),!0}function Jn(e){e.statusEffects=e.statusEffects.map(t=>({...t,duration:t.duration-1})).filter(t=>t.duration>0&&t.stacks>0)}function q(e,t,n,a=2){let r=e.statusEffects.find(o=>o.type===t);r?(r.stacks+=n,r.duration=Math.max(r.duration,a)):e.statusEffects.push({type:t,stacks:n,duration:a})}function re(e,t){return e.statusEffects.find(a=>a.type===t)?.stacks??0}function Qn(e){let t=1,n=re(e,"vulnerable");n>0&&(t*=1+n*.25);let a=re(e,"fortified");return a>0&&(t*=Math.max(.25,1-a*.15)),t}function Zn(e){let t=1,n=re(e,"weak");return n>0&&(t*=Math.max(.25,1-n*.15)),re(e,"empowered")>0&&(t*=1+re(e,"empowered")*.25),t}function er(e){let t=re(e,"burn");if(t>0){e.hp-=t;let n=e.statusEffects.find(a=>a.type==="burn");return n&&(n.stacks=Math.max(0,n.stacks-1)),t}return 0}var Sa=[{id:"wardens_signet",name:"Warden's Signet",description:"+1 max Resolve.",trigger:"passive",effect:{type:"max_resolve_bonus",value:1}},{id:"column_keystone",name:"Column Keystone",description:"When you emplace, gain 8 Block.",trigger:"on_emplace",effect:{type:"block_on_emplace",value:8}},{id:"echo_shard",name:"Echo Shard",description:"When an enemy dies, deal 3 damage to all enemies in same column.",trigger:"on_enemy_kill",effect:{type:"deal_damage_column",value:3}},{id:"pale_lens",name:"Pale Lens",description:"At combat start, apply 1 Vulnerable to all enemies.",trigger:"on_combat_start",effect:{type:"apply_vulnerable_all",value:1}},{id:"burnished_shield",name:"Burnished Shield",description:"At turn start, if Resolve is 0, gain 8 Block.",trigger:"on_turn_start",effect:{type:"gain_block",value:8}},{id:"ember_crown",name:"Ember Crown",description:"When an enemy dies from Burn, apply 2 Burn to all enemies.",trigger:"on_enemy_kill",effect:{type:"burn_on_kill",value:2}},{id:"architects_blueprint",name:"Architect's Blueprint",description:"Emplacements gain +4 HP.",trigger:"passive",effect:{type:"emplace_hp_bonus",value:4}},{id:"ironwood_staff",name:"Ironwood Staff",description:"Draw 1 extra card each turn.",trigger:"on_turn_start",effect:{type:"draw_cards",value:1}},{id:"siege_engine",name:"Siege Engine",description:"Your first card each turn costs 0 Resolve.",trigger:"on_turn_start",effect:{type:"first_card_free",value:1}},{id:"pale_compass",name:"Pale Compass",description:"After elite kills, gain a card reward.",trigger:"on_elite_kill",effect:{type:"extra_card_reward",value:1}},{id:"fragment_magnet",name:"Fragment Magnet",description:"Gain +5 fragments per combat.",trigger:"passive",effect:{type:"fragment_bonus",value:5}},{id:"hexproof_seal",name:"Hexproof Seal",description:"At combat start, gain 10 Block.",trigger:"on_combat_start",effect:{type:"gain_block",value:10}},{id:"war_drum",name:"War Drum",description:"At combat start, apply 1 Weak to all enemies.",trigger:"on_combat_start",effect:{type:"apply_weak_all",value:1}},{id:"living_wall",name:"Living Wall",description:"When you emplace, draw 2 cards.",trigger:"on_emplace",effect:{type:"draw_cards",value:2}},{id:"siphon_ring",name:"Siphon Ring",description:"On card play, if card costs 2+, heal 2 Gate HP.",trigger:"on_card_play",effect:{type:"heal",value:2}},{id:"void_prism",name:"Void Prism",description:"At turn start, deal 2 damage to all enemies.",trigger:"on_turn_start",effect:{type:"deal_damage_all",value:2}},{id:"watchers_eye",name:"Watcher's Eye",description:"At combat start, draw 2 extra cards.",trigger:"on_combat_start",effect:{type:"draw_cards",value:2}},{id:"fortress_heart",name:"Fortress Heart",description:"Emplacements gain +3 HP.",trigger:"passive",effect:{type:"emplace_hp_bonus",value:3}},{id:"mending_stone",name:"Mending Stone",description:"After combat, heal 5 Gate HP.",trigger:"passive",effect:{type:"heal",value:5}},{id:"pale_harvester",name:"Pale Harvester",description:"On enemy kill, gain 1 Resolve (cap at max+2).",trigger:"on_enemy_kill",effect:{type:"gain_resolve",value:1}}];function dt(e){return Sa.find(t=>t.id===e)}function Ea(e,t,n=3){let a=Sa.filter(l=>!t.includes(l.id)),r=[],o=[...a];for(let l=0;l<n&&o.length>0;l++){let d=Math.floor(e()*o.length);r.push(o[d]),o.splice(d,1)}return r}function Ue(e,t,n,a){for(let r of t){let o=dt(r);if(!(!o||o.trigger!==n))switch(o.effect.type){case"gain_block":{if(r==="burnished_shield"&&e.resolve>0)break;e.gateBlock+=o.effect.value,e.events.push({type:"block_gained",turn:e.turn,data:{value:o.effect.value,relic:r}});break}case"gain_resolve":{let l=e.maxResolve+2;e.resolve=Math.min(l,e.resolve+o.effect.value);break}case"draw_cards":{let{drawCards:l}=nr(),{drawn:d,newDrawPile:s,newDiscardPile:p}=l(e.drawPile,e.discardPile,o.effect.value,tr(e));e.hand.push(...d),e.drawPile=s,e.discardPile=p;break}case"deal_damage_all":{for(let l of e.columns)for(let d of l.enemies)d.hp-=o.effect.value;break}case"deal_damage_column":{let l=a?.column;if(l!==void 0){let d=e.columns[l];if(d)for(let s of d.enemies)s.hp-=o.effect.value}break}case"heal":{if(n==="on_card_play"){let l=a?.cardCost;if(l!==void 0&&l<2)break}e.gateHp=Math.min(e.gateMaxHp,e.gateHp+o.effect.value);break}case"apply_vulnerable_all":{for(let l of e.columns)for(let d of l.enemies)q(d,"vulnerable",o.effect.value,3);break}case"apply_weak_all":{for(let l of e.columns)for(let d of l.enemies)q(d,"weak",o.effect.value,3);break}case"burn_on_kill":{if(a?.diedFromBurn)for(let d of e.columns)for(let s of d.enemies)q(s,"burn",o.effect.value,99);break}case"block_on_emplace":{e.gateBlock+=o.effect.value,e.events.push({type:"block_gained",turn:e.turn,data:{value:o.effect.value,relic:r}});break}case"first_card_free":case"emplace_hp_bonus":case"max_resolve_bonus":case"extra_card_reward":case"fragment_bonus":break}}}function tr(e){return ar(e.seed+e.turn*7+13)}function ar(e){let t=e>>>0;return()=>{t=t+1831565813|0;let n=Math.imul(t^t>>>15,1|t);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function nr(){return{drawCards(e,t,n,a){let r=[],o=[...e],l=[...t];for(let d=0;d<n;d++){if(o.length===0){if(l.length===0)break;for(let s=l.length-1;s>0;s--){let p=Math.floor(a()*(s+1));[l[s],l[p]]=[l[p],l[s]]}o.push(...l),l=[]}r.push(o.shift())}return{drawn:r,newDrawPile:o,newDiscardPile:l}}}}function rr(e){let t=0;for(let n of e){let a=dt(n);a&&a.effect.type==="emplace_hp_bonus"&&(t+=a.effect.value)}return t}function or(e){let t=0;for(let n of e){let a=dt(n);a&&a.effect.type==="max_resolve_bonus"&&(t+=a.effect.value)}return t}function sr(e){return e.some(t=>{let n=dt(t);return n&&n.effect.type==="first_card_free"})}function Pa(e,t,n=Nt,a=Nt,r=[{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"needle",column:2}],o=[],l){let d=N(t),s=Ln(e,d),p=or(o),y=(l?.reducedMaxResolve?Gt-1:Gt)+p,g=l?.reducedHandSize?Oe-1:Oe,_=Array.from({length:Ve},(D,S)=>({index:S,enemies:[],emplacement:null}));for(let D of r){let S=Ut(D.templateId,D.column);l?.enemyHpMult&&l.enemyHpMult!==1&&(S.hp=Math.ceil(S.hp*l.enemyHpMult),S.maxHp=Math.ceil(S.maxHp*l.enemyHpMult)),l?.enemyBlitz&&(S.row=1),l?.enemyStartFortified&&q(S,"fortified",1,99),_[S.column].enemies.push(S)}let{drawn:E,newDrawPile:M,newDiscardPile:K}=pe(s,[],g,d),R={columns:_,hand:E,drawPile:M,discardPile:K,exhaustPile:[],gateHp:n,gateMaxHp:a,gateBlock:0,resolve:y,maxResolve:y,turn:1,phase:"player",outcome:"undecided",events:[],seed:t,killsThisCombat:0,relics:o,difficulty:l};Ue(R,o,"on_combat_start");for(let D of _)for(let S of D.enemies){let h=D.emplacement!==null;S.intent=qt(S,d,1,h)}return G(R,"turn_start",{turn:1}),R}function G(e,t,n){e.events.push({type:t,turn:e.turn,data:n}),e.events.length>100&&(e.events=e.events.slice(-100))}function Aa(e,t,n,a=!1){if(e.phase!=="player")return e;let r=e.hand[t];if(!r)return e;let o=O(r.defId);if(!o)return e;let l=!e.events.some(s=>s.type==="card_played"&&s.turn===e.turn),d=sr(e.relics)&&l;if(a&&o.type==="emplace"&&o.emplaceCost!==void 0){let s=d?0:o.emplaceCost;if(s>e.resolve)return e;let p=n??0,y=rr(e.relics);if(!(zn(e,o,p,y)||Xn(e,p,o)))return e;e.resolve-=s,e.hand.splice(t,1),e.exhaustPile.push(r),Ue(e,e.relics,"on_emplace")}else{let s=d?0:o.cost;if(s>e.resolve)return e;e.resolve-=s,e.hand.splice(t,1);let p=!1;for(let y of o.effects){if(y.type==="exhaust_self"){p=!0;continue}Ra(e,y,n??0)}Ft(e),p?e.exhaustPile.push(r):e.discardPile.push(r),Ue(e,e.relics,"on_card_play",{cardCost:o.cost,cardId:o.id})}return e.lastCardPlayed=r.defId,G(e,"card_played",{cardId:r.defId,targetColumn:n,asEmplace:a}),$t(e),e}function Ra(e,t,n){switch(t.type){case"damage":{if(t.target==="all")for(let a of e.columns)for(let r of a.enemies)Z(e,r,t.value);else if(t.target==="column"){let a=e.columns[n];if(a)for(let r of a.enemies)Z(e,r,t.value)}else{let a=e.columns[n];if(a&&a.enemies.length>0){let r=a.enemies.reduce((o,l)=>o.row>=l.row?o:l);Z(e,r,t.value)}}break}case"block":e.gateBlock+=t.value,G(e,"block_gained",{value:t.value});break;case"heal":e.gateHp=Math.min(e.gateMaxHp,e.gateHp+t.value);break;case"draw":{let{drawn:a,newDrawPile:r,newDiscardPile:o}=pe(e.drawPile,e.discardPile,t.value,N(e.seed+e.turn));e.hand.push(...a),e.drawPile=r,e.discardPile=o;break}case"resolve":e.resolve=Math.min(e.maxResolve+5,e.resolve+t.value);break;case"vulnerable":{if(t.target==="all")for(let a of e.columns)for(let r of a.enemies)q(r,"vulnerable",t.value,3);else if(t.target==="column"){let a=e.columns[n];if(a)for(let r of a.enemies)q(r,"vulnerable",t.value,3)}else{let a=e.columns[n];if(a&&a.enemies.length>0){let r=a.enemies.reduce((o,l)=>o.row>=l.row?o:l);q(r,"vulnerable",t.value,3)}}G(e,"status_applied",{type:"vulnerable",value:t.value,column:n});break}case"weak":{if(t.target==="all")for(let a of e.columns)for(let r of a.enemies)q(r,"weak",t.value,3);else if(t.target==="column"){let a=e.columns[n];if(a)for(let r of a.enemies)q(r,"weak",t.value,3)}else{let a=e.columns[n];if(a&&a.enemies.length>0){let r=a.enemies.reduce((o,l)=>o.row>=l.row?o:l);q(r,"weak",t.value,3)}}G(e,"status_applied",{type:"weak",value:t.value,column:n});break}case"burn":{if(t.target==="all")for(let a of e.columns)for(let r of a.enemies)q(r,"burn",t.value,99);else{let a=e.columns[n];if(a)for(let r of a.enemies)q(r,"burn",t.value,99)}break}case"self_damage":{e.gateHp-=t.value,G(e,"gate_hit",{self:!0,damage:t.value});break}case"fortify":break;case"trigger_emplacements":{Ca(e);break}case"damage_per_burn":{for(let a of e.columns)for(let r of a.enemies){let o=re(r,"burn");o>0&&Z(e,r,t.value*o)}break}case"damage_equal_block":{let a=e.gateBlock,r=e.columns[n];if(r&&r.enemies.length>0){let o=r.enemies.reduce((l,d)=>l.row>=d.row?l:d);Z(e,o,a)}break}case"draw_per_kills":{let a=e.killsThisCombat*t.value;if(a>0){let{drawn:r,newDrawPile:o,newDiscardPile:l}=pe(e.drawPile,e.discardPile,a,N(e.seed+e.turn+3));e.hand.push(...r),e.drawPile=o,e.discardPile=l}break}case"damage_if_vulnerable":{let a=e.columns[n];if(a&&a.enemies.length>0){let r=a.enemies.reduce((d,s)=>d.row>=s.row?d:s),l=re(r,"vulnerable")>0?t.value*2:t.value;Z(e,r,l)}break}case"damage_per_kill_this_action":{let a=lr(e);if(a>0){let r=t.value*a;for(let o of e.columns)for(let l of o.enemies)Z(e,l,r)}break}case"exhaust_draw":{if(e.hand.length>0){let l=e.hand.shift();e.exhaustPile.push(l)}let{drawn:a,newDrawPile:r,newDiscardPile:o}=pe(e.drawPile,e.discardPile,t.value,N(e.seed+e.turn+5));e.hand.push(...a),e.drawPile=r,e.discardPile=o;break}case"burn_if_burning":{let a=!1;for(let o of e.columns){for(let l of o.enemies)if(re(l,"burn")>0){a=!0;break}if(a)break}let r=a?t.value+2:t.value;for(let o of e.columns)for(let l of o.enemies)q(l,"burn",r,99);break}case"damage_plus_block":{let a=Math.min(e.gateBlock,10),r=t.value+a,o=e.columns[n];if(o&&o.enemies.length>0){let l=o.enemies.reduce((d,s)=>d.row>=s.row?d:s);Z(e,l,r)}break}case"replay_last":{if(e.lastCardPlayed&&e.lastCardPlayed!=="pale_echo"){let a=O(e.lastCardPlayed);if(a)for(let r of a.effects)r.type!=="exhaust_self"&&r.type!=="replay_last"&&Ra(e,r,n)}break}case"damage_if_emplaced":{let a=e.columns[n];if(a){let r=a.emplacement?Math.floor(t.value*1.5):t.value;for(let o of a.enemies)Z(e,o,r)}break}case"damage_if_low_hp":{let r=e.gateHp<e.gateMaxHp*.5?t.value*2:t.value,o=e.columns[n];if(o&&o.enemies.length>0){let l=o.enemies.reduce((d,s)=>d.row>=s.row?d:s);Z(e,l,r)}break}case"damage_per_emplace":{let a=e.columns.filter(r=>r.emplacement!==null).length;if(a>0){let r=t.value*a;for(let o of e.columns)for(let l of o.enemies)Z(e,l,r)}break}case"draw_per_empty_potions":{let{drawn:r,newDrawPile:o,newDiscardPile:l}=pe(e.drawPile,e.discardPile,2,N(e.seed+e.turn+9));e.hand.push(...r),e.drawPile=o,e.discardPile=l;break}case"exhaust_self":break}}function lr(e){let t=0;for(let n of e.columns)for(let a of n.enemies)a.hp<=0&&t++;return t}function Z(e,t,n){let a=Qn(t),r=Math.floor(n*a);t.hp-=r,G(e,"damage_dealt",{targetId:t.instanceId,damage:r})}function Ft(e){for(let t of e.columns)t.enemies=t.enemies.filter(n=>{if(n.hp<=0){e.killsThisCombat++,G(e,"enemy_killed",{enemyId:n.instanceId,templateId:n.templateId});let a=re(n,"burn")>0;return Ue(e,e.relics,"on_enemy_kill",{column:t.index,diedFromBurn:a,templateId:n.templateId}),!1}return!0})}function Da(e){return e.phase!=="player"||(G(e,"turn_end",{turn:e.turn}),e.phase="enemy",ir(e)),e}function ir(e){let t=N(e.seed+e.turn*31),n=e.columns.flatMap(d=>d.enemies.map(s=>({enemy:s,intent:s.intent??{type:"advance",value:1}})));for(let{enemy:d,intent:s}of n)d.hp<=0||cr(e,d,s,t);if(Ft(e),$t(e),e.outcome!=="undecided"||(e.turn++,e.phase="player",e.resolve=e.maxResolve,e.gateBlock=0,Ca(e),Ft(e),$t(e),e.outcome!=="undecided"))return;Ue(e,e.relics,"on_turn_start"),e.discardPile.push(...e.hand),e.hand=[];let a=e.difficulty?.reducedHandSize?Oe-1:Oe,{drawn:r,newDrawPile:o,newDiscardPile:l}=pe(e.drawPile,e.discardPile,a,t);e.hand=r,e.drawPile=o,e.discardPile=l;for(let d of e.columns)for(let s of d.enemies){let p=d.emplacement!==null;s.intent=qt(s,t,e.turn,p)}G(e,"turn_start",{turn:e.turn})}function cr(e,t,n,a){let r=de(t.templateId),o=Zn(t),l=e.difficulty?.enemyDamageMult??1;if(er(t),Jn(t),!(t.hp<=0))switch(n.type){case"advance":{if(t.templateId==="breaker"){let d=e.columns[t.column];if(d.emplacement&&t.row>=Ae-2){let s=(r?.damage??10)*2;d.emplacement.hp-=s,d.emplacement.hp<=0&&(G(e,"emplacement_destroyed",{column:t.column}),d.emplacement=null);break}}if(t.row=Math.min(Ae-1,t.row+(r?.speed??1)),G(e,"enemy_advance",{enemyId:t.instanceId,row:t.row}),t.row>=Ae-1)if(t.templateId==="wraith"){let d=Math.floor((r?.damage??7)*o*l),s=Math.min(e.gateBlock,d);e.gateBlock-=s,e.gateHp-=d-s,G(e,"gate_hit",{enemyId:t.instanceId,damage:d-s,blocked:s})}else{let d=e.columns[t.column];if(d.emplacement)d.emplacement.hp-=r?.damage??4,d.emplacement.hp<=0&&(G(e,"emplacement_destroyed",{column:t.column}),d.emplacement=null);else{let s=Math.floor((r?.damage??4)*o*l),p=Math.min(e.gateBlock,s);e.gateBlock-=p,e.gateHp-=s-p,G(e,"gate_hit",{enemyId:t.instanceId,damage:s-p,blocked:p})}}break}case"attack":{if(t.templateId==="flanker"){let p=a()<.5?-1:1,y=t.column,g=Math.max(0,Math.min(Ve-1,t.column+p));if(g!==y){let _=e.columns[y];_.enemies=_.enemies.filter(E=>E.instanceId!==t.instanceId),t.column=g,e.columns[g].enemies.push(t)}}let d=Math.floor((r?.damage??4)*o*l),s=Math.min(e.gateBlock,d);e.gateBlock-=s,e.gateHp-=d-s,G(e,"gate_hit",{enemyId:t.instanceId,damage:d-s,blocked:s});break}case"buff":q(t,"empowered",n.value,3);break;case"debuff":{e.gateBlock=Math.max(0,e.gateBlock-n.value*2);break}case"shield":{let d=e.columns[t.column];for(let s of d.enemies)q(s,"fortified",n.value,2);break}case"summon":{let d=e.columns.findIndex(s=>s.enemies.length===0);if(d>=0){let s=Ut("wisp",d);e.columns[d].enemies.push(s),s.intent=qt(s,N(e.seed+e.turn*97))}break}}}function $t(e){if(e.gateHp<=0){e.gateHp=0,e.outcome="lose",e.phase="ended",G(e,"combat_end",{outcome:"lose"});return}e.columns.reduce((n,a)=>n+a.enemies.length,0)===0&&(e.outcome="win",e.phase="ended",G(e,"combat_end",{outcome:"win"}))}function mt(e,t=3,n=[]){let a=new Set(["strike","guard","bolster","brace","mend",...n]),o=Ke.filter(s=>!a.has(s.id)&&s.id!=="pale_curse").map(s=>({card:s,weight:s.rarity==="common"?6:s.rarity==="uncommon"?3:s.rarity==="rare"?1.5:.5})),l=[],d=new Set;for(let s=0;s<t&&o.length>0;s++){let p=o.filter(E=>!d.has(E.card.id));if(p.length===0)break;let y=p.reduce((E,M)=>E+M.weight,0),g=e()*y,_=!1;for(let E of p)if(g-=E.weight,g<=0){l.push(E.card),d.add(E.card.id),_=!0;break}_||(l.push(p[p.length-1].card),d.add(p[p.length-1].card.id))}return l}var dr=[{name:"Scout Party",enemies:[{templateId:"hollow",column:1},{templateId:"hollow",column:3}]},{name:"Swift Assault",enemies:[{templateId:"needle",column:0},{templateId:"needle",column:2},{templateId:"needle",column:4}]},{name:"Pale Vanguard",enemies:[{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"needle",column:2}]},{name:"Wisp Swarm",enemies:[{templateId:"wisp",column:0},{templateId:"wisp",column:1},{templateId:"wisp",column:2},{templateId:"wisp",column:3},{templateId:"wisp",column:4}]},{name:"Heavy Patrol",enemies:[{templateId:"shade",column:1},{templateId:"hollow",column:3}]},{name:"Armored Column",enemies:[{templateId:"husk",column:2},{templateId:"wisp",column:0},{templateId:"wisp",column:4}]},{name:"Pale Scouts",enemies:[{templateId:"wisp",column:0},{templateId:"wisp",column:4},{templateId:"hollow",column:2}]},{name:"Needle Formation",enemies:[{templateId:"needle",column:1},{templateId:"needle",column:3}]},{name:"Husk Advance",enemies:[{templateId:"husk",column:2},{templateId:"wisp",column:1},{templateId:"wisp",column:3}]},{name:"Shadow Patrol",enemies:[{templateId:"shade",column:0},{templateId:"needle",column:4}]},{name:"Swarm Tide",enemies:[{templateId:"wisp",column:0},{templateId:"wisp",column:1},{templateId:"hollow",column:2},{templateId:"wisp",column:3},{templateId:"wisp",column:4}]},{name:"Hollow Shields",enemies:[{templateId:"hollow",column:1},{templateId:"hollow",column:2},{templateId:"hollow",column:3}]},{name:"Fast Assault",enemies:[{templateId:"needle",column:0},{templateId:"needle",column:2},{templateId:"needle",column:4}]},{name:"Pale Sentries",enemies:[{templateId:"shade",column:2},{templateId:"hollow",column:0},{templateId:"hollow",column:4}]}],mr=[{name:"The Dark Tide",enemies:[{templateId:"shade",column:1},{templateId:"shade",column:3},{templateId:"needle",column:2}]},{name:"Hollow Legion",enemies:[{templateId:"hollow",column:0},{templateId:"hollow",column:1},{templateId:"hollow",column:3},{templateId:"hollow",column:4}]},{name:"Husk Fortress",enemies:[{templateId:"husk",column:1},{templateId:"husk",column:3},{templateId:"needle",column:2}]},{name:"Shade Ambush",enemies:[{templateId:"shade",column:0},{templateId:"shade",column:2},{templateId:"shade",column:4}]}],ur=[{name:"The Warband",enemies:[{templateId:"breaker",column:2},{templateId:"shielder",column:1},{templateId:"shielder",column:3}]},{name:"Flanking Ambush",enemies:[{templateId:"flanker",column:0},{templateId:"flanker",column:4},{templateId:"wraith",column:2}]},{name:"Breaker Vanguard",enemies:[{templateId:"breaker",column:1},{templateId:"breaker",column:3},{templateId:"shielder",column:2}]},{name:"Phantom Blitz",enemies:[{templateId:"wraith",column:0},{templateId:"wraith",column:1},{templateId:"wraith",column:3},{templateId:"wraith",column:4}]}],pr=[{name:"Echo Vanguard",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:3}]},{name:"The Final Test",enemies:[{templateId:"echo",column:2},{templateId:"breaker",column:0},{templateId:"flanker",column:4}]},{name:"Memory Siege",enemies:[{templateId:"echo",column:0},{templateId:"echo",column:2},{templateId:"echo",column:4}]},{name:"The Pale Tribunal",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:2},{templateId:"echo",column:3},{templateId:"breaker",column:0}]}],fr=[{name:"Wraith Drift",enemies:[{templateId:"wraith",column:1},{templateId:"wraith",column:3}]},{name:"Breach Team",enemies:[{templateId:"breaker",column:2},{templateId:"flanker",column:0},{templateId:"flanker",column:4}]},{name:"Shield Wall",enemies:[{templateId:"shielder",column:2},{templateId:"hollow",column:1},{templateId:"hollow",column:3}]},{name:"Wraith Surge",enemies:[{templateId:"wraith",column:0},{templateId:"wraith",column:2},{templateId:"wraith",column:4}]},{name:"Flanker Pair",enemies:[{templateId:"flanker",column:1},{templateId:"flanker",column:3}]},{name:"Shielder Escort",enemies:[{templateId:"shielder",column:2},{templateId:"breaker",column:1},{templateId:"hollow",column:3}]},{name:"Pale Vanguard II",enemies:[{templateId:"breaker",column:0},{templateId:"flanker",column:2},{templateId:"shielder",column:4}]},{name:"Wraith Patrol",enemies:[{templateId:"wraith",column:1},{templateId:"hollow",column:0},{templateId:"hollow",column:4}]},{name:"Breaker Column",enemies:[{templateId:"breaker",column:2},{templateId:"wisp",column:0},{templateId:"wisp",column:1},{templateId:"wisp",column:3},{templateId:"wisp",column:4}]},{name:"Shield Formation",enemies:[{templateId:"shielder",column:1},{templateId:"shielder",column:3},{templateId:"flanker",column:2}]},{name:"Assault Wave",enemies:[{templateId:"breaker",column:1},{templateId:"breaker",column:3}]},{name:"Night Raid",enemies:[{templateId:"wraith",column:0},{templateId:"flanker",column:2},{templateId:"wraith",column:4}]},{name:"Armored Push",enemies:[{templateId:"shielder",column:0},{templateId:"breaker",column:2},{templateId:"shielder",column:4}]}],hr=[{name:"Echoes of the End",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:3}]},{name:"Final Surge",enemies:[{templateId:"echo",column:2},{templateId:"wraith",column:0},{templateId:"wraith",column:4},{templateId:"breaker",column:1}]},{name:"Echo Patrol",enemies:[{templateId:"echo",column:0},{templateId:"echo",column:4}]},{name:"Pale Convergence",enemies:[{templateId:"echo",column:2},{templateId:"wraith",column:1},{templateId:"wraith",column:3}]},{name:"Void March",enemies:[{templateId:"echo",column:1},{templateId:"echo",column:3},{templateId:"breaker",column:2}]},{name:"Shadow Tide",enemies:[{templateId:"wraith",column:0},{templateId:"echo",column:2},{templateId:"flanker",column:4}]},{name:"The Unnamed",enemies:[{templateId:"echo",column:2},{templateId:"shielder",column:1},{templateId:"shielder",column:3}]},{name:"Pale Hammer",enemies:[{templateId:"breaker",column:0},{templateId:"echo",column:2},{templateId:"breaker",column:4}]},{name:"Memory Storm",enemies:[{templateId:"echo",column:0},{templateId:"echo",column:1},{templateId:"echo",column:3},{templateId:"echo",column:4}]},{name:"Wraith Flood",enemies:[{templateId:"wraith",column:0},{templateId:"wraith",column:1},{templateId:"wraith",column:2},{templateId:"wraith",column:3},{templateId:"wraith",column:4}]},{name:"Final Guard",enemies:[{templateId:"echo",column:1},{templateId:"breaker",column:2},{templateId:"echo",column:3}]},{name:"Pale Assembly",enemies:[{templateId:"echo",column:0},{templateId:"shielder",column:2},{templateId:"echo",column:4},{templateId:"flanker",column:1}]}];function Ma(e,t,n=!1){let a;if(n)switch(e){case 2:a=ur;break;case 3:a=pr;break;default:a=mr;break}else switch(e){case 2:a=fr;break;case 3:a=hr;break;default:a=dr;break}let r=Math.floor(t()*a.length);return{...a[r],isElite:n}}var ct=12,Ta=4;function gr(e,t,n){if(e===0)return"combat";if(e===t-1)return"boss";let a=n();return e===Math.floor(t/2)?a<.5?"rest":"shop":a<.5?"combat":a<.65?"elite":a<.78?"event":a<.88?"rest":"shop"}function Ha(e,t){let n=N(t),a=[],r=[];for(let o=0;o<ct;o++){let l=[],d=o===0||o===ct-1?1:Math.floor(n()*2)+2,s=new Set;for(;s.size<d;)s.add(Math.floor(n()*Ta));for(let p=0;p<Ta;p++)if(s.has(p)){let y=gr(o,ct,n),g={id:`node-${e}-${o}-${p}`,type:y,row:o,column:p,connections:[],visited:!1};l.push(g),a.push(g)}else l.push(null);r.push(l)}for(let o=0;o<ct-1;o++){let l=r[o].filter(s=>s!==null),d=r[o+1].filter(s=>s!==null);if(d.length!==0){for(let s of l){let p=d.map(y=>({node:y,dist:Math.abs(y.column-s.column)})).sort((y,g)=>y.dist-g.dist);s.connections.push(p[0].node.id),p.length>1&&n()<.4&&s.connections.push(p[1].node.id)}for(let s of d)!l.some(y=>y.connections.includes(s.id))&&l.length>0&&l.map(g=>({node:g,dist:Math.abs(g.column-s.column)})).sort((g,_)=>g.dist-_.dist)[0].node.connections.push(s.id)}}return{act:e,nodes:a}}function Re(e,t){return e.nodes.find(n=>n.id===t)}function Ba(e,t){if(!t)return e.nodes.filter(a=>a.row===0);let n=Re(e,t);return n?n.connections.map(a=>Re(e,a)).filter(a=>!!a):[]}function ut(e,t=0){let n={enemyHpMult:1,enemyDamageMult:1,startingGateHp:70,extraEnemies:0,shopCostMult:1,healMult:1,startWithCurse:!1,enemyBlitz:!1,reducedRewards:!1,enemyStartFortified:!1,voidColumns:0,paleHunger:!1,bossExtraMinions:0,reducedHandSize:!1,reducedMaxResolve:!1};return e>=2&&(n.enemyHpMult+=.2,n.enemyDamageMult+=.15),e>=3&&(n.enemyHpMult+=.3,n.enemyDamageMult+=.25),t>=1&&(n.enemyHpMult+=.1),t>=2&&(n.enemyDamageMult+=.1),t>=3&&(n.startWithCurse=!0),t>=4&&(n.healMult-=.25),t>=5&&(n.startingGateHp-=10),t>=6&&(n.enemyBlitz=!0),t>=7&&(n.extraEnemies+=1),t>=8&&(n.reducedRewards=!0),t>=9&&(n.enemyStartFortified=!0),t>=10&&(n.shopCostMult+=.25),t>=11&&(n.voidColumns=1),t>=12&&(n.paleHunger=!0),t>=13&&(n.bossExtraMinions=2),t>=14&&(n.reducedHandSize=!0),t>=15&&(n.reducedMaxResolve=!0),n}function Ga(e,t=0){let n=ee(e),a=Ha(1,n),r=ut(1,t),o=Kt();return r.startWithCurse&&o.push(qe("pale_curse")),{id:`run-${Date.now()}-${n}`,seed:e,act:1,map:a,currentNodeId:null,deck:o,gateHp:r.startingGateHp,gateMaxHp:r.startingGateHp,fragments:0,potions:[null,null,null],relics:[],ascensionLevel:t,combat:null}}function jt(e,t){return{...e,deck:[...e.deck,t]}}function zt(e,t){return{...e,deck:e.deck.filter(n=>n.instanceId!==t)}}function Na(e,t){let n=Re(e.map,t);return n&&(n.visited=!0),{...e,currentNodeId:t}}function pt(e,t){return{...e,gateHp:Math.min(e.gateMaxHp,e.gateHp+t)}}function Wa(e,t){return e.fragments<t?null:{...e,fragments:e.fragments-t}}function je(e,t){return{...e,fragments:e.fragments+t}}function Fa(e,t){let n=e.potions.indexOf(null);if(n===-1)return null;let a=[...e.potions];return a[n]=t,{...e,potions:a}}function $a(e,t){if(t<0||t>=e.potions.length)return null;let n=e.potions[t];if(!n)return null;let a=[...e.potions];return a[t]=null,{run:{...e,potions:a},potionId:n}}function Yt(e){let t=e.act+1,n=ee(e.seed+`-act${t}`),a=Ha(t,n);return{...e,act:t,map:a,currentNodeId:null}}function Va(e){let t=[],n=Ke.filter(o=>o.rarity!=="common"||o.id==="slash"||o.id==="flare"),a=new Set;for(let o=0;o<5&&a.size<5;o++){let l=n[Math.floor(e()*n.length)];if(a.has(l.id)){o--;continue}a.add(l.id);let d=l.rarity==="rare"?75:l.rarity==="uncommon"?50:30;t.push({type:"card",cardDef:l,cost:d})}let r=Le[Math.floor(e()*Le.length)];return t.push({type:"potion",potionDef:r,cost:25}),t.push({type:"card_remove",cost:50}),t}var yr=[{id:"wandering_smith",name:"The Wandering Smith",description:"A cloaked figure sits by a forge that shouldn't exist this far into the Pale. They offer to work on your defenses.",choices:[{label:"Ask them to reinforce the gate. (Heal 15 HP)",effect:{type:"heal",value:15}},{label:"Ask for supplies. (Gain 15 fragments)",effect:{type:"fragments",value:15}},{label:"Leave them be.",effect:{type:"nothing"}}]},{id:"pale_fountain",name:"The Pale Fountain",description:"A spring of luminous water bubbles from cracked stone. Its glow is unsettling but beckons.",choices:[{label:"Drink deeply. (+10 max Gate HP)",effect:{type:"max_hp",value:10}},{label:"Fill a flask. (Gain a random card)",effect:{type:"card_reward"}},{label:"Leave. The Pale gives nothing freely.",effect:{type:"nothing"}}]},{id:"abandoned_cache",name:"Abandoned Cache",description:"You find a sealed chest among the rubble of a collapsed watchtower.",choices:[{label:"Pry it open. (Gain 25 fragments)",effect:{type:"fragments",value:25}},{label:"Smash it quickly. (Gain 10 fragments)",effect:{type:"fragments",value:10}},{label:"Leave it. Could be cursed.",effect:{type:"nothing"}}]},{id:"old_veteran",name:"The Old Veteran",description:`A scarred soldier leans against the wall. "I've seen the Pale take stronger keeps than yours," they say.`,choices:[{label:'"Teach me." (Remove a card from your deck)',effect:{type:"remove_card"}},{label:'"Give me your supplies." (Gain 20 fragments)',effect:{type:"fragments",value:20}},{label:'"Good luck." (Nothing happens)',effect:{type:"nothing"}}]},{id:"strange_merchant",name:"Strange Merchant",description:"A merchant with too many eyes offers wares from a floating pack.",choices:[{label:"Browse their cards. (Gain a card)",effect:{type:"card_reward"}},{label:"Sell your blood. (Lose 10 HP, gain 30 fragments)",effect:{type:"damage",value:10}},{label:"Walk away.",effect:{type:"nothing"}}]}],wr=[{id:"pale_scholar",name:"The Pale Scholar",description:'An ancient figure pores over a tome that seems to read itself. "The Pale remembers everything," they whisper.',choices:[{label:"Ask for knowledge. (Gain a card)",effect:{type:"card_reward"}},{label:"Ask for healing. (Heal 20 HP)",effect:{type:"heal",value:20}},{label:"Back away slowly.",effect:{type:"nothing"}}]},{id:"fractured_mirror",name:"The Fractured Mirror",description:"A mirror stands in the corridor, cracked but gleaming. Your reflection looks stronger than you feel.",choices:[{label:"Reach through. (+5 max Gate HP, lose 5 HP)",effect:{type:"max_hp",value:5}},{label:"Smash it. (Gain 20 fragments)",effect:{type:"fragments",value:20}},{label:"Walk past. Mirrors lie.",effect:{type:"nothing"}}]},{id:"deserters_cache",name:"Deserter's Cache",description:"Behind a collapsed wall, you find supplies left by someone who fled the Keep long ago.",choices:[{label:"Take everything. (Gain 30 fragments)",effect:{type:"fragments",value:30}},{label:"Take only what you need. (Heal 10 HP, gain 10 fragments)",effect:{type:"heal",value:10}},{label:"Leave it for the next warden.",effect:{type:"nothing"}}]}],vr=[{id:"wandering_smith_cracks",name:"The Wandering Smith",description:"The smith again. You've seen this forge before \u2014 the same cracks in the stone, the same angle of the cloak. They look up and for the first time, you notice their hands are shaking.",choices:[{label:'"How long have you been here?" (Heal 15 HP)',effect:{type:"heal",value:15}},{label:`"You're not real, are you." (Gain 20 fragments)`,effect:{type:"fragments",value:20}},{label:"Say nothing. The kindness is worse than the lie.",effect:{type:"nothing"}}]},{id:"the_echoing_child",name:"The Echoing Child",description:'A child sits in the corridor, humming. They look up with eyes that glow faintly. "I remember my house," they say. "Can you take me there?" The house is gone. You know this.',choices:[{label:`"I'll try." (Lose 15 HP \u2014 the detour is dangerous)`,effect:{type:"damage",value:15}},{label:`"There's nothing to go back to." (Gain 10 fragments \u2014 they dissolve)`,effect:{type:"fragments",value:10}},{label:'"Stay here. The Keep is safe."',effect:{type:"nothing"}}]}],br=[{id:"motts_stash",name:"Mott's Hidden Stash",description:`"DON'T TELL MOTT," reads the note pinned to a crate. It's Mott's handwriting.`,choices:[{label:"Open it. (Gain 25 fragments)",effect:{type:"fragments",value:25}},{label:"Leave it. Mott knows things you don't.",effect:{type:"nothing"}}]},{id:"wardens_echo",name:"A Warden's Echo",description:'You find scratches on the wall. Tallies. Hundreds of them. Below, in faded ink: "Run 847. The Pale is not the enemy. The Pale is the answer to a question we forgot."',choices:[{label:"Study the scratches. (Gain a card)",effect:{type:"card_reward"}},{label:"Cover them. Some knowledge is dangerous. (Gain 15 fragments)",effect:{type:"fragments",value:15}},{label:"Add your own tally mark.",effect:{type:"nothing"}}]}],Wt=[{id:"the_architects_choice",name:"The Architect's Choice",description:"A door that shouldn't exist. Beyond it, a room you've seen in dreams. A desk. A journal. A pen that still has ink. The Architect's final workspace.",choices:[{label:"Read the journal. (+15 max Gate HP)",effect:{type:"max_hp",value:15}},{label:"Destroy the journal. (Gain 40 fragments)",effect:{type:"fragments",value:40}},{label:"Sit down. Pick up the pen.",effect:{type:"nothing"}}]}],kr=[{id:"the_last_wall",name:"The Last Wall",description:"The final barrier before the Pale's heart. Ancient wards still flicker across its surface.",choices:[{label:"Channel the wards. (+15 max Gate HP)",effect:{type:"max_hp",value:15}},{label:"Break through quickly. (Gain 20 fragments)",effect:{type:"fragments",value:20}},{label:"Let it stand. Its purpose is not yours.",effect:{type:"nothing"}}]},{id:"echo_of_a_warden",name:"Echo of a Warden",description:`A ghostly figure in warden's garb appears. "I held this keep once. Take what remains of my strength."`,choices:[{label:"Accept their gift. (Gain a card, lose 5 HP)",effect:{type:"card_reward"}},{label:"Ask them to strengthen the gate. (Heal 25 HP)",effect:{type:"heal",value:25}},{label:'"Rest now, Warden."',effect:{type:"nothing"}}]},{id:"pale_bargain",name:"The Pale Bargain",description:'The void itself speaks: "Give me something, and I will give you power."',choices:[{label:"Sacrifice a card. (Remove a card)",effect:{type:"remove_card"}},{label:"Sacrifice blood. (Lose 15 HP, gain 40 fragments)",effect:{type:"damage",value:15}},{label:'"I make no deals with the void."',effect:{type:"nothing"}}]}];function Oa(e,t,n){let a;switch(e){case 2:a=wr;break;case 3:a=kr;break;default:a=yr;break}let r=n==="cracks"||n==="truth"||n==="true_ending";if((n==="truth"||n==="true_ending")&&e===3&&Wt.length>0&&t()<.4)return Wt[Math.floor(t()*Wt.length)];if(r){let l=null;if(e===1?l=vr:e===2&&(l=br),l&&l.length>0&&t()<.4)return l[Math.floor(t()*l.length)]}return a[Math.floor(t()*a.length)]}var oe=[{id:"forge",name:"The Forge",description:"Unlock card upgrades at rest sites. Higher levels improve upgrades.",maxLevel:3,upgradeCost:e=>e*30},{id:"archive",name:"The Archive",description:"Unlock rare cards in the reward pool. Higher levels add legendaries.",maxLevel:3,upgradeCost:e=>e*40},{id:"beacon_tower",name:"Beacon Tower",description:"+1 starting hand size per level.",maxLevel:2,upgradeCost:e=>e*50},{id:"foundry",name:"The Foundry",description:"Emplacements start with +2 HP per level.",maxLevel:3,upgradeCost:e=>e*25},{id:"sanctum_hall",name:"Sanctum Hall",description:"+5 max Gate HP per level.",maxLevel:3,upgradeCost:e=>e*35}];function ze(e,t){return e.structures[t]??0}function Ka(e,t){let n=oe.find(o=>o.id===t);if(!n)return null;let a=ze(e,t);if(a>=n.maxLevel)return null;let r=n.upgradeCost(a+1);return e.echoes<r?null:{...e,echoes:e.echoes-r,structures:{...e.structures,[t]:a+1}}}function Xt(){return[{id:"wren",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"sable",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"duskmar",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"mott",tier:0,echoesGiven:0,dialoguesSeen:[]},{id:"pale_visitor",tier:0,echoesGiven:0,dialoguesSeen:[]}]}function Jt(e,t,n){return(e?10+t*5:3)+Math.floor(n*.5)}function La(e,t){return t>=15?"true_ending":e>=30?"truth":e>=15?"cracks":"surface"}function Ua(e,t){let n=t.npcs.find(r=>r.id===e);if(!n)return null;let a=_a(e,n.tier,n.dialoguesSeen);return a.length===0?null:{speaker:a[0].speaker,text:a[0].text,dialogueId:a[0].id}}function qa(e,t,n){let a=e.npcs.findIndex(l=>l.id===t);if(a===-1)return e;let r=[...e.npcs],o={...r[a]};return o.dialoguesSeen=[...o.dialoguesSeen,n],r[a]=o,{...e,npcs:r}}var Ot=2;function Er(){return ja(Sr(),".config","codekeep")}function Zt(){return ja(Er(),"game.json")}function Pr(){return{structures:{},npcs:[],echoes:0,highestAscension:0,totalRuns:0,totalWins:0,unlockedCardIds:[],achievements:[],narrativeFlags:[]}}function za(e){return{schemaVersion:Ot,savedAtUnixMs:Date.now(),playerName:e,keep:Pr(),activeRun:null}}function me(e){let t=Zt(),n=Cr(t);Qt(n)||Tr(n,{recursive:!0});let a=t+".tmp",r=JSON.stringify({...e,savedAtUnixMs:Date.now()},null,2);Vt(a,r,"utf-8"),xr(a,t)}function De(){let e=Zt();if(!Qt(e))return null;let t;try{t=_r(e,"utf-8")}catch{return null}let n;try{n=JSON.parse(t)}catch{let a=e+".bak";try{Vt(a,t,"utf-8")}catch{}return process.stderr.write(`[codekeep] Corrupted save backed up to ${a}
|
|
3
|
+
`),null}if(n.schemaVersion!==Ot){let a=e+`.v${n.schemaVersion}.bak`;try{Vt(a,t,"utf-8")}catch{}return process.stderr.write(`[codekeep] Save version mismatch (got ${n.schemaVersion}, need ${Ot}), backed up to ${a}
|
|
4
|
+
`),null}return n}function Ya(){let e=Zt();if(!Qt(e))return!1;try{return Ir(e),!0}catch{return!1}}import Hr from"react";import{Box as Br,Text as W}from"ink";import{writeFileSync as Ar,mkdirSync as Rr,existsSync as Dr}from"fs";import{join as Xa}from"path";import{homedir as Mr}from"os";var ea=Xa(Mr(),".config","codekeep","crashes");function Ja(e,t){if((e instanceof Error?e.message:String(e)).includes("Raw mode is not supported"))return"";Dr(ea)||Rr(ea,{recursive:!0});let a={timestamp:new Date().toISOString(),error:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0,version:globalThis.__CODEKEEP_VERSION??"unknown",nodeVersion:process.version,platform:process.platform,arch:process.arch,screen:t?.screen,gameState:t?.gameState},r=`crash-${Date.now()}.json`,o=Xa(ea,r);return Ar(o,JSON.stringify(a,null,2),"utf-8"),o}function Qa(e){let t=encodeURIComponent(`[Crash]: ${e.error.slice(0,80)}`),n=encodeURIComponent(`## Crash Report
|
|
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=${r}&labels=bug,crash`}import{Fragment as la,jsx as V,jsxs as oe}from"react/jsx-runtime";var Ke=class extends Ir.Component{constructor(t){super(t),this.state={error:null,crashFilePath:null,issueUrl:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){try{let r=ia(t),a={timestamp:new Date().toISOString(),error:t.message,stack:t.stack,version:globalThis.__CODEKEEP_VERSION??"unknown",nodeVersion:process.version,platform:process.platform,arch:process.arch},o=ca(a);this.setState({crashFilePath:r,issueUrl:o})}catch{}}render(){return this.state.error?oe(Cr,{flexDirection:"column",padding:1,children:[V(S,{bold:!0,color:"red",children:"\u25C6 CodeKeep \u2014 Something went wrong"}),V(S,{children:" "}),V(S,{color:"red",children:this.state.error.message}),V(S,{children:" "}),V(S,{dimColor:!0,children:"Your save file is at:"}),oe(S,{children:[" ","~/.config/codekeep/game.json"]}),V(S,{children:" "}),this.state.crashFilePath&&oe(la,{children:[V(S,{dimColor:!0,children:"Crash report saved to:"}),oe(S,{children:[" ",this.state.crashFilePath]}),V(S,{children:" "})]}),this.state.issueUrl&&oe(la,{children:[V(S,{dimColor:!0,children:"Report this bug:"}),oe(S,{color:"cyan",children:[" ",this.state.issueUrl]}),V(S,{children:" "})]}),V(S,{dimColor:!0,children:"If the game won't start, try:"}),oe(S,{bold:!0,children:[" ","codekeep --tutorial"]}),V(S,{children:" "}),V(S,{dimColor:!0,children:"Press Ctrl+C to exit"})]}):this.props.children}};import{Box as gt,Text as O}from"ink";import{Box as Sr,Text as J}from"ink";import{jsx as Pe,jsxs as Ue}from"react/jsx-runtime";function Er(e){if(!e)return"";switch(e.type){case"advance":return`\u2193${e.value}`;case"attack":return`\u2694${e.value}`;case"buff":return`\u25B2${e.value}`;case"debuff":return`\u25BC${e.value}`;case"shield":return`\u25C8${e.value}`;case"summon":return`+${e.value}`;default:return""}}function Pr(e){let t=[];for(let r of e.statusEffects)switch(r.type){case"vulnerable":t.push(`V${r.stacks}`);break;case"weak":t.push(`W${r.stacks}`);break;case"burn":t.push(`B${r.stacks}`);break;case"empowered":t.push(`E${r.stacks}`);break;case"fortified":t.push(`F${r.stacks}`);break}return t.join("")}function Rr(e,t,r=6){let a=Math.max(0,Math.round(e/t*r));return"\u2588".repeat(a)+"\u2591".repeat(r-a)}function Dr(e){return`${ne(e.templateId)?.symbol??"?"}${e.hp}`}function da({columns:e,targetColumn:t,showTarget:r,gateHp:a,gateMaxHp:o,gateBlock:n}){let u=e.map((f,k)=>{let _=`Col ${k+1}`,N=f.emplacement?`[${f.emplacement.hp}hp]`:"",B=N?`${_}${N}`:_,M=r&&k===t,G=B.padStart(Math.floor((14+B.length)/2)).padEnd(14);return M?`[${G.slice(1,-1)}]`:` ${G.slice(1,-1)} `}).join("\u2502"),s=[];for(let f=0;f<Te;f++){let k=e.map(_=>{let N=_.enemies.filter(M=>M.row===f);return N.length===0?"\xB7".padStart(Math.floor(7.5)).padEnd(14):N.map(M=>{let G=Er(M.intent),U=Pr(M),h=Dr(M);return G&&(h+=` ${G}`),U&&(h+=` ${U}`),h}).join(" ").slice(0,14).padEnd(14)}).join("\u2502");s.push(k)}let p=Math.round(a/o*100),g=p>60?"green":p>30?"yellow":"red";return Ue(Sr,{flexDirection:"column",children:[Pe(J,{bold:!0,dimColor:!0,children:"\u2500".repeat(74)}),Pe(J,{bold:!0,children:u}),Pe(J,{dimColor:!0,children:"\u2500".repeat(74)}),s.map((f,k)=>Pe(J,{children:f},k)),Pe(J,{dimColor:!0,children:"\u2550".repeat(74)}),Ue(J,{children:[Ue(J,{bold:!0,color:g,children:["Gate ",Rr(a,o,12)," ",a,"/",o]}),n>0&&Ue(J,{color:"cyan",children:[" \u{1F6E1}",n]})]})]})}import{Box as Ar,Text as ve}from"ink";import{jsx as ma,jsxs as Re}from"react/jsx-runtime";function Mr(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function Hr(e){switch(e){case"armament":return"\u2694";case"fortification":return"\u{1F6E1}";case"edict":return"\u2726";case"wild":return"\u25C8";default:return"\xB7"}}function ua({hand:e,selectedIndex:t,resolve:r}){return e.length===0?ma(ve,{dimColor:!0,children:"No cards in hand."}):Re(Ar,{flexDirection:"column",children:[ma(ve,{bold:!0,children:"Hand:"}),e.map((a,o)=>{let n=$(a.defId);if(!n)return null;let l=o===t,u=n.cost<=r,s=l?"\u25B6 ":" ",p=`${o+1}`,g=`[${n.cost}]`;return Re(ve,{children:[Re(ve,{bold:l,color:l?"yellow":void 0,children:[s,p,"."," "]}),Re(ve,{color:u?Mr(n.rarity):"gray",bold:l,children:[Hr(n.category)," ",n.name," ",g]}),l&&Re(ve,{dimColor:!0,children:[" \u2014 ",n.description]})]},a.instanceId)})]})}import{jsx as K,jsxs as De}from"react/jsx-runtime";function pa({combat:e,selectedCard:t,targetColumn:r,needsTarget:a,message:o}){let n=e.columns.reduce((l,u)=>l+u.enemies.length,0);return De(gt,{flexDirection:"column",children:[De(gt,{justifyContent:"space-between",children:[K(O,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),De(O,{children:["Turn ",K(O,{bold:!0,children:e.turn})," ","Resolve ",De(O,{bold:!0,color:"cyan",children:[e.resolve,"/",e.maxResolve]})," ","Enemies ",K(O,{bold:!0,color:"red",children:n})," ","Draw ",K(O,{dimColor:!0,children:e.drawPile.length})," ","Discard ",K(O,{dimColor:!0,children:e.discardPile.length})]})]}),K(O,{children:" "}),K(da,{columns:e.columns,targetColumn:r,showTarget:a&&t>=0,gateHp:e.gateHp,gateMaxHp:e.gateMaxHp,gateBlock:e.gateBlock}),K(O,{children:" "}),K(ua,{hand:e.hand,selectedIndex:t,resolve:e.resolve}),K(O,{children:" "}),o&&K(O,{color:"yellow",children:o}),e.phase==="player"&&De(O,{dimColor:!0,children:["1-",e.hand.length," card \u2190\u2192 column Enter play e emplace p potion Space end turn d deck q quit"]}),e.outcome!=="undecided"&&K(gt,{marginTop:1,children:K(O,{bold:!0,color:e.outcome==="win"?"green":"red",children:e.outcome==="win"?"\u2605 VICTORY \u2014 The siege is broken!":"\u2717 DEFEAT \u2014 The Gate has fallen."})})]})}import{Box as fa,Text as Z}from"ink";import{jsx as we,jsxs as Le}from"react/jsx-runtime";function Br(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function ha({cards:e,selectedIndex:t}){return Le(fa,{flexDirection:"column",padding:1,children:[we(Z,{bold:!0,color:"yellow",children:"\u25C6 Choose a Card Reward"}),we(Z,{children:" "}),e.map((r,a)=>{let o=a===t;return Le(fa,{flexDirection:"column",marginBottom:1,children:[Le(Z,{bold:o,color:o?"yellow":Br(r.rarity),children:[o?"\u25B6 ":" ",a+1,". ",r.name," [",r.cost,"] (",r.rarity,")"]}),Le(Z,{dimColor:!0,children:[" ",r.description]})]},r.id)}),we(Z,{children:" "}),we(Z,{dimColor:!0,children:t>=0?` ${e.length+1}. Skip \u2014 take no card`:`\u25B6 ${e.length+1}. Skip \u2014 take no card`}),we(Z,{children:" "}),we(Z,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]})}import{Box as Gr,Text as Ae}from"ink";import{jsx as vt,jsxs as yt}from"react/jsx-runtime";function Nr(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function ga({deck:e}){let t=new Map;for(let a of e)t.set(a.defId,(t.get(a.defId)??0)+1);let r=[...t.entries()].map(([a,o])=>({def:$(a),count:o})).filter(a=>a.def).sort((a,o)=>{let n={common:0,uncommon:1,rare:2,legendary:3},l=n[a.def.rarity]??0,u=n[o.def.rarity]??0;return l!==u?l-u:a.def.name.localeCompare(o.def.name)});return yt(Gr,{flexDirection:"column",padding:1,children:[yt(Ae,{bold:!0,color:"yellow",children:["\u25C6 Your Deck"," (",e.length," cards)"]}),vt(Ae,{children:" "}),r.map(({def:a,count:o})=>yt(Ae,{color:Nr(a.rarity),children:[o>1?`${o}x `:" ",a.name," [",a.cost,"] \u2014 ",a.description]},a.id)),vt(Ae,{children:" "}),vt(Ae,{dimColor:!0,children:"Press q or Esc to go back."})]})}import{Box as wt,Text as Q}from"ink";import{jsx as se,jsxs as qe}from"react/jsx-runtime";function Wr(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 $r(e,t,r,a){if(a)return"cyan";if(r)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 ya({map:e,currentNodeId:t,reachableIds:r,selectedNodeId:a}){let o=new Set(r),n=Math.max(...e.nodes.map(u=>u.row)),l=[];for(let u=0;u<=n;u++)l.push(e.nodes.filter(s=>s.row===u).sort((s,p)=>s.column-p.column));return qe(wt,{flexDirection:"column",padding:1,children:[qe(Q,{bold:!0,color:"yellow",children:["\u25C6 Act ",e.act," Map"]}),se(Q,{children:" "}),l.map((u,s)=>qe(wt,{children:[qe(Q,{dimColor:!0,children:[String(s).padStart(2," ")," "]}),se(wt,{gap:2,children:[0,1,2,3].map(p=>{let g=u.find(G=>G.column===p);if(!g)return se(Q,{children:" "},p);let f=g.id===t,k=o.has(g.id),_=g.id===a,N=$r(g,k,_,f),B=Wr(g.type),M=_?`[${B}]`:f?`(${B})`:` ${B} `;return se(Q,{color:N,bold:_||f,dimColor:g.visited&&!f,children:M},p)})})]},s)),se(Q,{children:" "}),se(Q,{dimColor:!0,children:"\u2694=fight \u2605=elite \u25B3=rest $=shop ?=event \u25C6=boss"}),se(Q,{dimColor:!0,children:"\u2191\u2193 select Enter proceed d=deck q=quit"})]})}import{Box as Fr,Text as Me}from"ink";import{jsx as kt,jsxs as bt}from"react/jsx-runtime";function va({items:e,selectedIndex:t,fragments:r}){return bt(Fr,{flexDirection:"column",padding:1,children:[bt(Me,{bold:!0,color:"yellow",children:["\u25C6 Shop \u2014 ",r," fragments"]}),kt(Me,{children:" "}),e.map((a,o)=>{let n=o===t,l=r>=a.cost,u="";return a.type==="card"&&a.cardDef?u=`${a.cardDef.name} (${a.cardDef.rarity}) \u2014 ${a.cardDef.description}`:a.type==="potion"&&a.potionDef?u=`${a.potionDef.name} \u2014 ${a.potionDef.description}`:a.type==="card_remove"&&(u="Remove a card from your deck"),bt(Me,{bold:n,color:n?"yellow":l?"white":"gray",children:[n?"\u25B6 ":" ",u," [",a.cost,"f]"]},o)}),kt(Me,{children:" "}),kt(Me,{dimColor:!0,children:"\u2191\u2193 navigate Enter buy q leave"})]})}import{Box as Vr,Text as ie}from"ink";import{jsx as He,jsxs as Tt}from"react/jsx-runtime";function wa({event:e,selectedChoice:t}){return Tt(Vr,{flexDirection:"column",padding:1,children:[Tt(ie,{bold:!0,color:"magenta",children:["\u25C6 ",e.name]}),He(ie,{children:" "}),He(ie,{children:e.description}),He(ie,{children:" "}),e.choices.map((r,a)=>Tt(ie,{bold:a===t,color:a===t?"yellow":"white",children:[a===t?"\u25B6 ":" ",a+1,". ",r.label]},a)),He(ie,{children:" "}),He(ie,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as Or,Text as ce}from"ink";import{jsx as be,jsxs as ba}from"react/jsx-runtime";function ka({gateHp:e,gateMaxHp:t,selectedChoice:r,deckSize:a}){let o=Math.floor(t*.3),n=[`Rest \u2014 Heal ${o} Gate HP (${e} \u2192 ${Math.min(t,e+o)}/${t})`,`Thin \u2014 Remove a card from your deck (${a} cards)`,"Leave \u2014 Continue without resting"];return ba(Or,{flexDirection:"column",padding:1,children:[be(ce,{bold:!0,color:"green",children:"\u25C6 Rest Site"}),be(ce,{children:" "}),be(ce,{children:"The campfire crackles against the encroaching Pale."}),be(ce,{children:" "}),n.map((l,u)=>ba(ce,{bold:u===r,color:u===r?"yellow":"white",children:[u===r?"\u25B6 ":" ",l]},u)),be(ce,{children:" "}),be(ce,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as Kr,Text as le}from"ink";import{jsx as Be,jsxs as xt}from"react/jsx-runtime";var Ur={wren:"Wren, the Steward",sable:"Sable, the Archivist",duskmar:"Duskmar, First Wall",mott:"Mott, the Salvager",pale_visitor:"The Pale Visitor"};function Ta({keep:e,selectedIndex:t}){let r=[...q.map(a=>{let o=Ee(e,a.id);return{type:"structure",id:a.id,label:`${a.name} (Lv.${o}/${a.maxLevel}) \u2014 ${a.description}`}}),...e.npcs.map(a=>({type:"npc",id:a.id,label:`${Ur[a.id]??a.id} (Tier ${a.tier}/5)`})),{type:"action",id:"new_run",label:"Begin New Run"},{type:"action",id:"ascension",label:`Ascension Level: ${e.highestAscension}`}];return xt(Kr,{flexDirection:"column",padding:1,children:[Be(le,{bold:!0,color:"yellow",children:"\u25C6 The Keep"}),xt(le,{children:["Echoes: ",Be(le,{bold:!0,color:"cyan",children:e.echoes})," | Runs: ",e.totalRuns," | Wins: ",e.totalWins]}),Be(le,{children:" "}),r.map((a,o)=>xt(le,{bold:o===t,color:o===t?"yellow":"white",children:[o===t?"\u25B6 ":" ",a.label]},a.id)),Be(le,{children:" "}),Be(le,{dimColor:!0,children:"\u2191\u2193 navigate Enter select q quit"})]})}import{useState as Ge,useCallback as de,useRef as Lr}from"react";function xa(){let[e,t]=Ge(null),[r,a]=Ge(-1),[o,n]=Ge(2),[l,u]=Ge(""),[s,p]=Ge(!1),g=Lr(null),f=de((h,y,b,W,H)=>{let te=h??st(),ae=y??Math.floor(Math.random()*2147483647),C=$t(te,ae,b,W,H);g.current=C,t({...C}),a(-1),n(2),p(!1),u("Your turn. Select a card (1-5) and a column (\u2190\u2192).")},[]),k=(()=>{if(r<0||!e)return!1;let h=e.hand[r];if(!h)return!1;let y=$(h.defId);return y?y.effects.some(b=>b.type==="damage"&&(b.target==="single"||b.target==="column")):!1})(),_=de(h=>{if(!g.current||g.current.phase!=="player"||h<0||h>=g.current.hand.length)return;let y=g.current.hand[h],b=$(y.defId);if(!b)return;if(b.cost>g.current.resolve){u(`Not enough Resolve for ${b.name} (costs ${b.cost}).`);return}a(h);let W=b.effects.some(H=>H.type==="damage"&&(H.target==="single"||H.target==="column"));u(W?`${b.name} selected. Choose column (\u2190\u2192), Enter to play.`:`${b.name} selected. Enter to play.`)},[]),N=de(h=>{h>=0&&h<5&&n(h)},[]),B=de(()=>{let h=g.current;if(!h||h.phase!=="player"||r<0)return;let y=h.hand[r];if(!y)return;let b=$(y.defId);b&&(Ft(h,r,o,s),g.current=h,t({...h}),a(-1),p(!1),h.outcome==="win"?u("Victory! The Pale recedes."):h.outcome==="lose"?u("The Gate has fallen..."):u(`${s?"Emplaced":"Played"} ${b.name}. ${h.resolve} Resolve left.`))},[r,o,s]),M=de(()=>{if(r<0||!g.current)return;let h=g.current.hand[r];if(!h)return;let y=$(h.defId);if(!y||y.type!=="emplace"){u("This card cannot be emplaced.");return}p(b=>!b),u(s?`${y.name}: cast mode`:`${y.name}: EMPLACE mode \u2014 place in a column`)},[r,s]),G=de(()=>{let h=g.current;!h||h.phase!=="player"||(Vt(h),g.current=h,t({...h}),a(-1),h.outcome==="win"?u("Victory! The Pale recedes."):h.outcome==="lose"?u("The Gate has fallen..."):u(`Turn ${h.turn}. Your move.`))},[]),U=de(h=>{let y=g.current;if(!(!y||!h)){for(let b of h.effects)switch(b.type){case"heal":y.gateHp=Math.min(y.gateMaxHp,y.gateHp+b.value);break;case"block":y.gateBlock+=b.value;break;case"damage":{if(b.target==="column"){let W=y.columns[2];for(let H of W.enemies)H.hp-=b.value}else if(b.target==="all")for(let W of y.columns)for(let H of W.enemies)H.hp-=b.value;break}case"draw":{let W=F(y.seed+y.turn*53),{drawn:H,newDrawPile:te,newDiscardPile:ae}=Se(y.drawPile,y.discardPile,b.value,W);y.hand.push(...H),y.drawPile=te,y.discardPile=ae;break}case"resolve":y.resolve=Math.min(y.maxResolve+5,y.resolve+b.value);break}g.current=y,t({...y}),u(`Used ${h.name}.`)}},[]);return{combat:e,selectedCard:r,targetColumn:o,message:l,emplaceMode:s,selectCard:_,selectTarget:N,confirmPlay:B,endTurn:G,toggleEmplace:M,startCombat:f,applyPotion:U,needsTarget:k}}import{Fragment as _t,jsx as w,jsxs as T}from"react/jsx-runtime";var _a=60,Ia=18;function Xr(){let{stdout:e}=Yr(),[t,r]=E({columns:e?.columns??process.stdout.columns??80,rows:e?.rows??process.stdout.rows??24});return qr(()=>{let a=e??process.stdout,o=()=>r({columns:a.columns,rows:a.rows});return a.on("resize",o),()=>{a.off("resize",o)}},[e]),t}function Jr({dryRun:e}){let{exit:t}=jr(),{columns:r,rows:a}=Xr(),[o,n]=E("menu"),[l,u]=E(0),[s,p]=E(null),[g,f]=E(0),[k,_]=E([]),[N,B]=E(0),[M,G]=E([]),[U,h]=E(0),[y,b]=E(null),[W,H]=E(0),[te,ae]=E(0),[C,me]=E(null),[ue,je]=E(0),[It,pe]=E(""),[Ct,Pa]=E(!1),[ze,fe]=E(0),Ye=xa(),{combat:X,selectedCard:St,targetColumn:Xe,message:Ra,emplaceMode:tn,selectCard:Et,selectTarget:Pt,confirmPlay:Da,endTurn:Aa,toggleEmplace:Ma,startCombat:Je,applyPotion:an,needsTarget:Ha}=Ye,Ba=r<_a||a<Ia,L=j(()=>{let i=ye();return i||(i=oa("Warden"),i.keep.npcs.length===0&&(i.keep.npcs=pt()),Y(i)),i.keep.npcs.length===0&&(i.keep.npcs=pt()),i},[]),I=j(i=>{if(e)return;let d=L();d.activeRun=i,C&&(d.keep=C),Y(d)},[e,C,L]),Rt=j(()=>{let i=`run-${Date.now()}`,d=L(),c=Lt(i,d.keep.highestAscension);p(c),f(0),d.activeRun=c,d.keep.totalRuns++,me(d.keep),Y(d),n("map")},[L]),Ga=j(()=>{let i=ye();i?.activeRun&&(p(i.activeRun),me(i.keep),f(0),n("map"))},[]),Dt=j(()=>{let i=L();me(i.keep),je(0),pe(""),n("keep")},[L]),At=j(()=>s?Ut(s.map,s.currentNodeId):[],[s]),Na=j(i=>{if(!s)return;let d=qt(s,i.id);if(i.type==="combat"||i.type==="elite"){let c=z(s.seed+i.id),m=F(c),x=Ot(s.act,m,i.type==="elite");Je(d.deck,c,d.gateHp,d.gateMaxHp,x.enemies),p(d),n("combat")}else if(i.type==="boss"){let c=z(s.seed+"-boss-"+s.act),m=Wt(s.act);Je(d.deck,c,d.gateHp,d.gateMaxHp,m),p(d),n("combat")}else if(i.type==="shop"){let c=F(z(s.seed+i.id));G(Jt(c)),h(0),p(d),n("shop")}else if(i.type==="event"){let c=F(z(s.seed+i.id));b(Zt(s.act,c)),H(0),p(d),n("event")}else i.type==="rest"&&(ae(0),p(d),n("rest"));I(d)},[s,Je,I]),Ze=j((i,d)=>{Pa(d),p(i);let c=L(),m=ft(d,i.act,i.ascensionLevel);c.keep.echoes+=m,d&&(c.keep.totalWins++,i.ascensionLevel>=c.keep.highestAscension&&(c.keep.highestAscension=i.ascensionLevel+1)),c.activeRun=null,me(c.keep),Y(c),n("result")},[L]),Wa=j(()=>{if(!X||!s)return;let i={...s,gateHp:X.gateHp};if(X.outcome==="lose"){Ze(i,!1);return}let d=s.currentNodeId?Ce(s.map,s.currentNodeId):null,c=d?.type==="elite"?$e.elite:d?.type==="boss"?$e.boss:$e.combat;if(i=Oe(i,c),d?.type==="boss"){s.act<3?(i=Xt(i),p(i),I(i),f(0),n("map")):Ze(i,!0);return}let m=F(z(s.seed+(s.currentNodeId??"")+"-reward"));_(lt(m)),B(0),p(i),I(i),n("reward")},[X,s,I,Ze]),Mt=j(i=>{if(!s)return;let d=s;i&&(d=dt(d,Ve(i.id))),p(d),I(d),f(0),n("map")},[s,I]),Qe=[{label:"The Keep",action:"keep"},{label:"New Run",action:"new"},...ye()?.activeRun?[{label:"Resume Run",action:"resume"}]:[],{label:"Quit",action:"quit"}];if(zr((i,d)=>{if(o==="menu"){if(d.upArrow||i==="k")u(c=>Math.max(0,c-1));else if(d.downArrow||i==="j")u(c=>Math.min(Qe.length-1,c+1));else if(d.return){let c=Qe[l]?.action;c==="keep"?Dt():c==="new"?Rt():c==="resume"?Ga():t()}else i==="q"&&t();return}if(o==="deck"){(i==="q"||d.escape)&&n("map");return}if(o==="map"&&s){let c=At();d.upArrow||i==="k"?f(m=>Math.max(0,m-1)):d.downArrow||i==="j"?f(m=>Math.min(c.length-1,m+1)):d.return&&c[g]?Na(c[g]):i==="d"?n("deck"):i==="q"&&(I(s),n("menu"));return}if(o==="reward"){let c=k.length;d.upArrow||i==="k"?B(m=>Math.max(0,m-1)):d.downArrow||i==="j"?B(m=>Math.min(c,m+1)):i==="s"?Mt(null):d.return&&Mt(N<k.length?k[N]:null);return}if(o==="shop"&&s){if(d.upArrow||i==="k")h(c=>Math.max(0,c-1));else if(d.downArrow||i==="j")h(c=>Math.min(M.length-1,c+1));else if(i==="q"||d.escape)f(0),n("map");else if(d.return){let c=M[U];if(c&&s.fragments>=c.cost){let m=jt(s,c.cost);if(!m)return;if(c.type==="card"&&c.cardDef)m=dt(m,Ve(c.cardDef.id)),p(m),I(m),G(x=>x.filter((P,re)=>re!==U)),h(0);else if(c.type==="potion"&&c.potionDef){let x=zt(m,c.potionDef.id);x&&(m=x),p(m),I(m),G(P=>P.filter((re,Ne)=>Ne!==U)),h(0)}else c.type==="card_remove"&&(p(m),I(m),fe(0),G(x=>x.filter((P,re)=>re!==U)),n("shop_remove"))}}return}if(o==="event"&&y&&s){if(d.upArrow||i==="k")H(c=>Math.max(0,c-1));else if(d.downArrow||i==="j")H(c=>Math.min(y.choices.length-1,c+1));else if(d.return){let c=y.choices[W],m=s;switch(c.effect.type){case"heal":m=ut(m,c.effect.value);break;case"damage":{m={...m,gateHp:Math.max(1,m.gateHp-c.effect.value)};let x=c.label.match(/(\d+)\s*fragments/i);x&&(m=Oe(m,parseInt(x[1])));break}case"fragments":m=Oe(m,c.effect.value);break;case"max_hp":m={...m,gateMaxHp:m.gateMaxHp+c.effect.value,gateHp:m.gateHp+c.effect.value};break;case"card_reward":{let x=c.label.match(/lose\s+(\d+)\s*hp/i);x&&(m={...m,gateHp:Math.max(1,m.gateHp-parseInt(x[1]))});let P=F(z(s.seed+(y?.id??"")));_(lt(P)),B(0),p(m),I(m),n("reward");return}case"remove_card":{p(m),I(m),n("deck_remove");return}case"nothing":break}p(m),I(m),f(0),n("map")}return}if(o==="rest"&&s){if(d.upArrow||i==="k")ae(c=>Math.max(0,c-1));else if(d.downArrow||i==="j")ae(c=>Math.min(2,c+1));else if(d.return){let c=s;te===0?(c=ut(c,Math.floor(c.gateMaxHp*.3)),p(c),I(c),f(0),n("map")):te===1&&c.deck.length>5?(p(c),fe(0),n("deck_remove")):(p(c),I(c),f(0),n("map"))}return}if(o==="deck_remove"&&s){if(d.upArrow||i==="k")fe(c=>Math.max(0,c-1));else if(d.downArrow||i==="j")fe(c=>Math.min(s.deck.length-1,c+1));else if(d.escape||i==="q")f(0),n("map");else if(d.return&&s.deck.length>5){let c=s.deck[ze];if(c){let m=mt(s,c.instanceId);p(m),I(m)}f(0),n("map")}return}if(o==="shop_remove"&&s){if(d.upArrow||i==="k")fe(c=>Math.max(0,c-1));else if(d.downArrow||i==="j")fe(c=>Math.min(s.deck.length-1,c+1));else if(d.escape||i==="q")n("shop");else if(d.return&&s.deck.length>5){let c=s.deck[ze];if(c){let m=mt(s,c.instanceId);p(m),I(m)}n("shop")}return}if(o==="keep"&&C){let c=q.length+C.npcs.length+2;if(d.upArrow||i==="k")je(m=>Math.max(0,m-1));else if(d.downArrow||i==="j")je(m=>Math.min(c-1,m+1));else if(i==="q")n("menu");else if(d.return)if(ue<q.length){let m=q[ue],x=Qt(C,m.id);if(x){me(x);let P=L();P.keep=x,Y(P),pe(`Upgraded ${m.name}!`)}else Ee(C,m.id)>=m.maxLevel?pe(`${m.name} is already max level.`):pe(`Not enough Echoes to upgrade ${m.name}.`)}else if(ue<q.length+C.npcs.length){let m=ue-q.length,x=C.npcs[m],P=ea(x.id,C);if(P){let re=ta(C,x.id,P.dialogueId);me(re);let Ne=L();Ne.keep=re,Y(Ne),pe(`${P.speaker}: "${P.text}"`)}else pe("(No new dialogue)")}else ue===q.length+C.npcs.length&&Rt();return}if(o==="result"){d.return||i===" "?Dt():i==="q"&&n("menu");return}if(o==="combat"&&X){if(X.outcome!=="undecided"){(d.return||i===" ")&&Wa();return}if(i==="q"){n("menu");return}if(i==="d"&&s){n("deck");return}if(i==="e"){Ma();return}if(i==="p"&&s){let c=s.potions.findIndex(m=>m!==null);if(c>=0){let m=Yt(s,c);if(m&&Ye.combat){let x=_e.find(P=>P.id===m.potionId);p(m.run),I(m.run),Ye.applyPotion(x??null)}}return}if(i>="1"&&i<="9"){Et(parseInt(i)-1);return}if(d.leftArrow||i==="h"){Pt(Math.max(0,Xe-1));return}if(d.rightArrow||i==="l"){Pt(Math.min(4,Xe+1));return}if(d.return&&St>=0){Da();return}if(i===" "){Aa();return}if(d.escape){Et(-1);return}}}),Ba)return T(ee,{flexDirection:"column",padding:1,children:[w(v,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),T(v,{color:"red",children:["Terminal too small (",r,"x",a,", need ",_a,"x",Ia,")"]})]});if(o==="menu")return T(ee,{flexDirection:"column",padding:1,children:[w(v,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),w(v,{children:" "}),w(v,{children:"The fortress stands at the edge of the Pale."}),w(v,{children:"Beyond the walls, something stirs."}),w(v,{children:" "}),Qe.map((i,d)=>T(v,{bold:d===l,color:d===l?"yellow":void 0,children:[d===l?"\u25B6 ":" ",i.label]},i.action)),w(v,{children:" "}),w(v,{dimColor:!0,children:"\u2191\u2193 navigate Enter select q quit"})]});if(o==="deck"&&s)return w(ga,{deck:s.deck});if(o==="keep"&&C)return T(ee,{flexDirection:"column",children:[w(Ta,{keep:C,selectedIndex:ue}),It&&T(v,{color:"cyan",bold:!0,children:[" ",It]})]});if((o==="deck_remove"||o==="shop_remove")&&s)return T(ee,{flexDirection:"column",padding:1,children:[w(v,{bold:!0,color:"red",children:"\u25C6 Remove a Card"}),T(v,{dimColor:!0,children:["Choose a card to remove from your deck (",s.deck.length," cards)."]}),w(v,{children:" "}),s.deck.map((i,d)=>{let c=$(i.defId),m=d===ze;return T(v,{bold:m,color:m?"yellow":"white",children:[m?"\u25B6 ":" ",c?.name??i.defId," (",c?.rarity,") \u2014 ",c?.description??""]},i.instanceId)}),w(v,{children:" "}),w(v,{dimColor:!0,children:"\u2191\u2193 navigate Enter remove Esc cancel"})]});if(o==="map"&&s){let i=At();return T(ee,{flexDirection:"column",children:[T(ee,{justifyContent:"space-between",paddingX:1,children:[T(v,{children:["Gate ",T(v,{bold:!0,color:s.gateHp>40?"green":s.gateHp>20?"yellow":"red",children:[s.gateHp,"/",s.gateMaxHp]})]}),T(v,{children:["Fragments ",w(v,{bold:!0,color:"yellow",children:s.fragments})]}),T(v,{children:["Deck ",w(v,{dimColor:!0,children:s.deck.length})]})]}),w(ya,{map:s.map,currentNodeId:s.currentNodeId,reachableIds:i.map(d=>d.id),selectedNodeId:i[g]?.id??null})]})}if(o==="reward")return w(ha,{cards:k,selectedIndex:N});if(o==="shop"&&s)return w(va,{items:M,selectedIndex:U,fragments:s.fragments});if(o==="event"&&y)return w(wa,{event:y,selectedChoice:W});if(o==="rest"&&s)return w(ka,{gateHp:s.gateHp,gateMaxHp:s.gateMaxHp,selectedChoice:te,deckSize:s.deck.length});if(o==="result"){let i=s?ft(Ct,s.act,s.ascensionLevel):0;return T(ee,{flexDirection:"column",padding:1,children:[w(v,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),w(v,{children:" "}),Ct?T(_t,{children:[w(v,{bold:!0,color:"green",children:"\u2605 RUN COMPLETE"}),w(v,{children:"The Pale recedes. The Keep endures."})]}):T(_t,{children:[w(v,{bold:!0,color:"red",children:"\u2717 DEFEAT"}),w(v,{children:"The Gate has fallen. The Pale consumes all."})]}),s&&T(_t,{children:[T(v,{dimColor:!0,children:["Act ",s.act," | Deck: ",s.deck.length," cards | Fragments: ",s.fragments]}),T(v,{children:["Echoes earned: ",T(v,{bold:!0,color:"cyan",children:["+",i]})]})]}),w(v,{children:" "}),w(v,{dimColor:!0,children:"Enter \u2192 The Keep | q \u2192 menu"})]})}return o==="combat"&&X&&s?T(ee,{flexDirection:"column",paddingX:1,children:[T(v,{dimColor:!0,children:["Act ",s.act," | Gate ",s.gateHp,"/",s.gateMaxHp," | Fragments ",s.fragments," | d=deck"]}),w(pa,{combat:X,selectedCard:St,targetColumn:Xe,needsTarget:Ha,message:Ra})]}):w(v,{children:"Loading..."})}function Ca(e){return w(Ke,{children:w(Jr,{...e})})}import{jsx as en}from"react/jsx-runtime";var Sa="0.5.0";globalThis.__CODEKEEP_VERSION=Sa;var Ea=new Zr;Ea.name("codekeep").description("CodeKeep: The Pale \u2014 deck-building tactical roguelike in your terminal").version(Sa).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=${n}&labels=bug,crash`}import{Fragment as Za,jsx as J,jsxs as ve}from"react/jsx-runtime";var ft=class extends Hr.Component{constructor(t){super(t),this.state={error:null,crashFilePath:null,issueUrl:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){try{let n=Ja(t),a={timestamp:new Date().toISOString(),error:t.message,stack:t.stack,version:globalThis.__CODEKEEP_VERSION??"unknown",nodeVersion:process.version,platform:process.platform,arch:process.arch},r=Qa(a);this.setState({crashFilePath:n,issueUrl:r})}catch{}}render(){return this.state.error?ve(Br,{flexDirection:"column",padding:1,children:[J(W,{bold:!0,color:"red",children:"\u25C6 CodeKeep \u2014 Something went wrong"}),J(W,{children:" "}),J(W,{color:"red",children:this.state.error.message}),J(W,{children:" "}),J(W,{dimColor:!0,children:"Your save file is at:"}),ve(W,{children:[" ","~/.config/codekeep/game.json"]}),J(W,{children:" "}),this.state.crashFilePath&&ve(Za,{children:[J(W,{dimColor:!0,children:"Crash report saved to:"}),ve(W,{children:[" ",this.state.crashFilePath]}),J(W,{children:" "})]}),this.state.issueUrl&&ve(Za,{children:[J(W,{dimColor:!0,children:"Report this bug:"}),ve(W,{color:"cyan",children:[" ",this.state.issueUrl]}),J(W,{children:" "})]}),J(W,{dimColor:!0,children:"If the game won't start, try:"}),ve(W,{bold:!0,children:[" ","codekeep --tutorial"]}),J(W,{children:" "}),J(W,{dimColor:!0,children:"Press Ctrl+C to exit"})]}):this.props.children}};import{Box as gt,Text as z}from"ink";import{Box as Gr,Text as fe}from"ink";import{jsx as Ye,jsxs as ht}from"react/jsx-runtime";function Nr(e){if(!e)return"";switch(e.type){case"advance":return`\u2193${e.value}`;case"attack":return`\u2694${e.value}`;case"buff":return`\u25B2${e.value}`;case"debuff":return`\u25BC${e.value}`;case"shield":return`\u25C8${e.value}`;case"summon":return`+${e.value}`;default:return""}}function Wr(e){let t=[];for(let n of e.statusEffects)switch(n.type){case"vulnerable":t.push(`V${n.stacks}`);break;case"weak":t.push(`W${n.stacks}`);break;case"burn":t.push(`B${n.stacks}`);break;case"empowered":t.push(`E${n.stacks}`);break;case"fortified":t.push(`F${n.stacks}`);break}return t.join("")}function Fr(e,t,n=6){let a=Math.max(0,Math.round(e/t*n));return"\u2588".repeat(a)+"\u2591".repeat(n-a)}function $r(e){return`${de(e.templateId)?.symbol??"?"}${e.hp}`}function en({columns:e,targetColumn:t,showTarget:n,gateHp:a,gateMaxHp:r,gateBlock:o}){let d=e.map((g,_)=>{let E=`Col ${_+1}`,M=g.emplacement?`[${g.emplacement.hp}hp]`:"",K=M?`${E}${M}`:E,R=n&&_===t,D=K.padStart(Math.floor((14+K.length)/2)).padEnd(14);return R?`[${D.slice(1,-1)}]`:` ${D.slice(1,-1)} `}).join("\u2502"),s=[];for(let g=0;g<Ae;g++){let _=e.map(E=>{let M=E.enemies.filter(R=>R.row===g);return M.length===0?"\xB7".padStart(Math.floor(7.5)).padEnd(14):M.map(R=>{let D=Nr(R.intent),S=Wr(R),h=$r(R);return D&&(h+=` ${D}`),S&&(h+=` ${S}`),h}).join(" ").slice(0,14).padEnd(14)}).join("\u2502");s.push(_)}let p=Math.round(a/r*100),y=p>60?"green":p>30?"yellow":"red";return ht(Gr,{flexDirection:"column",children:[Ye(fe,{bold:!0,dimColor:!0,children:"\u2500".repeat(74)}),Ye(fe,{bold:!0,children:d}),Ye(fe,{dimColor:!0,children:"\u2500".repeat(74)}),s.map((g,_)=>Ye(fe,{children:g},_)),Ye(fe,{dimColor:!0,children:"\u2550".repeat(74)}),ht(fe,{children:[ht(fe,{bold:!0,color:y,children:["Gate ",Fr(a,r,12)," ",a,"/",r]}),o>0&&ht(fe,{color:"cyan",children:[" \u25C7",o]})]})]})}import{Box as Vr,Text as Me}from"ink";import{jsx as tn,jsxs as Xe}from"react/jsx-runtime";function Or(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function Kr(e){switch(e){case"armament":return"\u2694";case"fortification":return"\u25C7";case"edict":return"\u2726";case"wild":return"\u25C8";default:return"\xB7"}}function an({hand:e,selectedIndex:t,resolve:n}){return e.length===0?tn(Me,{dimColor:!0,children:"No cards in hand."}):Xe(Vr,{flexDirection:"column",children:[tn(Me,{bold:!0,children:"Hand:"}),e.map((a,r)=>{let o=O(a.defId);if(!o)return null;let l=r===t,d=o.cost<=n,s=l?"\u25B6 ":" ",p=`${r+1}`,y=`[${o.cost}]`;return Xe(Me,{children:[Xe(Me,{bold:l,color:l?"yellow":void 0,children:[s,p,"."," "]}),Xe(Me,{color:d?Or(o.rarity):"gray",bold:l,children:[Kr(o.category)," ",o.name," ",y]}),Xe(Me,{dimColor:!0,children:[" \u2014 ",l?o.description:o.description.length>35?o.description.slice(0,35)+"\u2026":o.description]})]},a.instanceId)})]})}import{jsx as Y,jsxs as He}from"react/jsx-runtime";function Lr(e){switch(e.type){case"damage_dealt":return`Dealt ${e.data.damage} damage to enemy`;case"enemy_advance":return`Enemy advances to row ${e.data.row}`;case"gate_hit":return`Gate hit for ${e.data.damage} damage${e.data.blocked?` (${e.data.blocked} blocked)`:""}`;case"enemy_killed":return"Enemy destroyed!";case"block_gained":return`Gained ${e.data.value} Block`;case"emplacement_placed":return`Emplacement placed in column ${e.data.column+1}`;case"emplacement_triggered":return`Emplacement triggered in column ${e.data.column+1}`;case"emplacement_destroyed":return`Emplacement destroyed in column ${e.data.column+1}`;case"status_applied":return`Applied ${e.data.type} (${e.data.value})`;case"card_played":return`Played ${O(e.data.cardId)?.name??e.data.cardId}`;case"turn_start":return`\u2014 Turn ${e.data.turn} \u2014`;default:return""}}function nn({combat:e,selectedCard:t,targetColumn:n,needsTarget:a,message:r}){let o=e.columns.reduce((l,d)=>l+d.enemies.length,0);return He(gt,{flexDirection:"column",children:[He(gt,{justifyContent:"space-between",children:[Y(z,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),He(z,{children:["Turn ",Y(z,{bold:!0,children:e.turn})," ","Resolve ",He(z,{bold:!0,color:"cyan",children:[e.resolve,"/",e.maxResolve]})," ","Enemies ",Y(z,{bold:!0,color:"red",children:o})," ","Draw ",Y(z,{dimColor:!0,children:e.drawPile.length})," ","Discard ",Y(z,{dimColor:!0,children:e.discardPile.length})]})]}),Y(z,{children:" "}),Y(en,{columns:e.columns,targetColumn:n,showTarget:a&&t>=0,gateHp:e.gateHp,gateMaxHp:e.gateMaxHp,gateBlock:e.gateBlock}),Y(z,{children:" "}),Y(an,{hand:e.hand,selectedIndex:t,resolve:e.resolve}),Y(z,{children:" "}),r&&Y(z,{color:"yellow",children:r}),(()=>{let l=e.events.filter(d=>d.turn>=e.turn-1).slice(-4);return l.length===0?null:Y(gt,{flexDirection:"column",children:l.map((d,s)=>He(z,{dimColor:!0,children:[" ",Lr(d)]},s))})})(),e.phase==="player"&&He(z,{dimColor:!0,children:["1-",e.hand.length," card \u2190\u2192 column Enter play e emplace p potion Space end turn d deck q quit"]}),e.outcome!=="undecided"&&Y(gt,{marginTop:1,children:Y(z,{bold:!0,color:e.outcome==="win"?"green":"red",children:e.outcome==="win"?"\u2605 VICTORY \u2014 The siege is broken!":"\u2717 DEFEAT \u2014 The Gate has fallen."})})]})}import{Box as rn,Text as he}from"ink";import{jsx as Be,jsxs as yt}from"react/jsx-runtime";function Ur(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function on({cards:e,selectedIndex:t}){return yt(rn,{flexDirection:"column",padding:1,children:[Be(he,{bold:!0,color:"yellow",children:"\u25C6 Choose a Card Reward"}),Be(he,{children:" "}),e.map((n,a)=>{let r=a===t;return yt(rn,{flexDirection:"column",marginBottom:1,children:[yt(he,{bold:r,color:r?"yellow":Ur(n.rarity),children:[r?"\u25B6 ":" ",a+1,". ",n.name," [",n.cost,"] (",n.rarity,")"]}),yt(he,{dimColor:!0,children:[" ",n.description]})]},n.id)}),Be(he,{children:" "}),Be(he,{dimColor:!0,children:t>=0?` ${e.length+1}. Skip \u2014 take no card`:`\u25B6 ${e.length+1}. Skip \u2014 take no card`}),Be(he,{children:" "}),Be(he,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]})}import{Box as qr,Text as Je}from"ink";import{jsx as aa,jsxs as ta}from"react/jsx-runtime";function jr(e){switch(e){case"uncommon":return"green";case"rare":return"blue";case"legendary":return"magenta";default:return"white"}}function sn({deck:e}){let t=new Map;for(let a of e)t.set(a.defId,(t.get(a.defId)??0)+1);let n=[...t.entries()].map(([a,r])=>({def:O(a),count:r})).filter(a=>a.def).sort((a,r)=>{let o={common:0,uncommon:1,rare:2,legendary:3},l=o[a.def.rarity]??0,d=o[r.def.rarity]??0;return l!==d?l-d:a.def.name.localeCompare(r.def.name)});return ta(qr,{flexDirection:"column",padding:1,children:[ta(Je,{bold:!0,color:"yellow",children:["\u25C6 Your Deck"," (",e.length," cards)"]}),aa(Je,{children:" "}),n.map(({def:a,count:r})=>ta(Je,{color:jr(a.rarity),children:[r>1?`${r}x `:" ",a.name," [",a.cost,"] \u2014 ",a.description]},a.id)),aa(Je,{children:" "}),aa(Je,{dimColor:!0,children:"Press q or Esc to go back."})]})}import zr from"react";import{Box as wt,Text as ue}from"ink";import{jsx as ge,jsxs as Ge}from"react/jsx-runtime";function Yr(e){switch(e){case"combat":return"\u2694";case"elite":return"\u2605";case"rest":return"\u25B3";case"shop":return"$";case"event":return"?";case"boss":return"\u25C6";default:return"\xB7"}}function Xr(e,t,n,a){if(a)return"cyan";if(n)return"yellow";if(e.visited||!t)return"gray";switch(e.type){case"combat":return"white";case"elite":return"red";case"rest":return"green";case"shop":return"yellow";case"event":return"magenta";case"boss":return"red";default:return"white"}}function Jr(e,t,n){let a=Array(n).fill(" ");for(let r of e)for(let o of r.connections){let l=t.find(d=>d.id===o);l&&(l.column===r.column?a[r.column]=" \u2502 ":l.column>r.column?a[r.column]=a[r.column]===" \u2502 "?" \u2502\u2572":" \u2572":a[r.column]=a[r.column]===" \u2502 "?"\u2571\u2502 ":"\u2571 ")}return a.join(" ")}function ln({map:e,currentNodeId:t,reachableIds:n,selectedNodeId:a}){let r=new Set(n),o=Math.max(...e.nodes.map(s=>s.row)),l=[];for(let s=0;s<=o;s++)l.push(e.nodes.filter(p=>p.row===s).sort((p,y)=>p.column-y.column));let d=4;return Ge(wt,{flexDirection:"column",padding:1,children:[Ge(ue,{bold:!0,color:"yellow",children:["\u25C6 Act ",e.act," Map"]}),ge(ue,{children:" "}),l.map((s,p)=>Ge(zr.Fragment,{children:[Ge(wt,{children:[Ge(ue,{dimColor:!0,children:[String(p).padStart(2," ")," "]}),ge(wt,{gap:2,children:[0,1,2,3].map(y=>{let g=s.find(S=>S.column===y);if(!g)return ge(ue,{children:" "},y);let _=g.id===t,E=r.has(g.id),M=g.id===a,K=Xr(g,E,M,_),R=Yr(g.type),D=M?`[${R}]`:_?`(${R})`:` ${R} `;return ge(ue,{color:K,bold:M||_,dimColor:g.visited&&!_,children:D},y)})})]}),p<o&&ge(wt,{children:Ge(ue,{dimColor:!0,children:[" ",Jr(s,l[p+1]??[],d)]})})]},p)),ge(ue,{children:" "}),ge(ue,{dimColor:!0,children:"\u2694=fight \u2605=elite \u25B3=rest $=shop ?=event \u25C6=boss"}),ge(ue,{dimColor:!0,children:"\u2191\u2193 select Enter proceed d=deck q=quit"})]})}import{Box as Qr,Text as Qe}from"ink";import{jsx as ra,jsxs as na}from"react/jsx-runtime";function cn({items:e,selectedIndex:t,fragments:n}){return na(Qr,{flexDirection:"column",padding:1,children:[na(Qe,{bold:!0,color:"yellow",children:["\u25C6 Shop \u2014 ",n," fragments"]}),ra(Qe,{children:" "}),e.map((a,r)=>{let o=r===t,l=n>=a.cost,d="";return a.type==="card"&&a.cardDef?d=`${a.cardDef.name} (${a.cardDef.rarity}) \u2014 ${a.cardDef.description}`:a.type==="potion"&&a.potionDef?d=`${a.potionDef.name} \u2014 ${a.potionDef.description}`:a.type==="card_remove"&&(d="Remove a card from your deck"),na(Qe,{bold:o,color:o?"yellow":l?"white":"gray",children:[o?"\u25B6 ":" ",d," [",a.cost,"f]"]},r)}),ra(Qe,{children:" "}),ra(Qe,{dimColor:!0,children:"\u2191\u2193 navigate Enter buy q leave"})]})}import{Box as Zr,Text as be}from"ink";import{jsx as Ze,jsxs as oa}from"react/jsx-runtime";function dn({event:e,selectedChoice:t}){return oa(Zr,{flexDirection:"column",padding:1,children:[oa(be,{bold:!0,color:"magenta",children:["\u25C6 ",e.name]}),Ze(be,{children:" "}),Ze(be,{children:e.description}),Ze(be,{children:" "}),e.choices.map((n,a)=>oa(be,{bold:a===t,color:a===t?"yellow":"white",children:[a===t?"\u25B6 ":" ",a+1,". ",n.label]},a)),Ze(be,{children:" "}),Ze(be,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as eo,Text as ke}from"ink";import{jsx as Ne,jsxs as mn}from"react/jsx-runtime";function un({gateHp:e,gateMaxHp:t,selectedChoice:n,deckSize:a}){let r=Math.floor(t*.3),o=[`Rest \u2014 Heal ${r} Gate HP (${e} \u2192 ${Math.min(t,e+r)}/${t})`,`Thin \u2014 Remove a card from your deck (${a} cards)`,"Leave \u2014 Continue without resting"];return mn(eo,{flexDirection:"column",padding:1,children:[Ne(ke,{bold:!0,color:"green",children:"\u25C6 Rest Site"}),Ne(ke,{children:" "}),Ne(ke,{children:"The campfire crackles against the encroaching Pale."}),Ne(ke,{children:" "}),o.map((l,d)=>mn(ke,{bold:d===n,color:d===n?"yellow":"white",children:[d===n?"\u25B6 ":" ",l]},d)),Ne(ke,{children:" "}),Ne(ke,{dimColor:!0,children:"\u2191\u2193 navigate Enter choose"})]})}import{Box as to,Text as _e}from"ink";import{jsx as et,jsxs as sa}from"react/jsx-runtime";var ao={wren:"Wren, the Steward",sable:"Sable, the Archivist",duskmar:"Duskmar, First Wall",mott:"Mott, the Salvager",pale_visitor:"The Pale Visitor"};function pn({keep:e,selectedIndex:t}){let n=[...oe.map(a=>{let r=ze(e,a.id);return{type:"structure",id:a.id,label:`${a.name} (Lv.${r}/${a.maxLevel}) \u2014 ${a.description}`}}),...e.npcs.map(a=>({type:"npc",id:a.id,label:`${ao[a.id]??a.id} (Tier ${a.tier}/5)`})),{type:"action",id:"new_run",label:"Begin New Run"},{type:"action",id:"ascension",label:`Ascension Level: ${e.highestAscension}`}];return sa(to,{flexDirection:"column",padding:1,children:[et(_e,{bold:!0,color:"yellow",children:"\u25C6 The Keep"}),sa(_e,{children:["Echoes: ",et(_e,{bold:!0,color:"cyan",children:e.echoes})," | Runs: ",e.totalRuns," | Wins: ",e.totalWins]}),et(_e,{children:" "}),n.map((a,r)=>sa(_e,{bold:r===t,color:r===t?"yellow":"white",children:[r===t?"\u25B6 ":" ",a.label]},a.id)),et(_e,{children:" "}),et(_e,{dimColor:!0,children:"\u2191\u2193 navigate Enter select q quit"})]})}import{Box as no,Text as tt}from"ink";import{jsx as vt,jsxs as fn}from"react/jsx-runtime";var hn=[{title:"Welcome to CodeKeep",lines:["You are the Warden of the Keep \u2014 the last fortress","standing against the Pale, an erasure that consumes all.","","Your goal: survive 3 Acts of increasingly dangerous","enemies by playing cards and building defenses."]},{title:"The Gate",lines:["Your Gate is your lifeline. It has HP (hit points).","If Gate HP reaches 0, your run is over.","","Gate HP: \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591 70/70","","Enemies advance toward the Gate. When they reach it,","they deal damage. Block reduces incoming damage."]},{title:"Combat Basics",lines:["Each turn you have 3 Resolve (mana) to play cards.","Cards cost 0-4 Resolve. Your hand refreshes each turn.","","Controls:"," 1-5 Select a card from your hand"," \u2190\u2192 Choose target column"," Enter Play the selected card"," Space End your turn"," i Inspect an enemy"]},{title:"The 5-Column Grid",lines:["The battlefield has 5 columns. Enemies spawn at the top","and advance downward toward your Gate at the bottom.",""," Col 1 \u2502 Col 2 \u2502 Col 3 \u2502 Col 4 \u2502 Col 5"," \u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2500\u2500\u2500"," \u262018 \u2502 \xB7 \u2502 \u219110 \u2502 \xB7 \u2502 \xB7"," \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"," Gate \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 70/70"]},{title:"Enemy Intents",lines:["Enemies show what they plan to do next turn:",""," \u2193N Advance N rows toward the Gate"," \u2694N Attack the Gate for N damage"," \u25B2N Buff themselves"," \u25C8N Shield nearby enemies"," +N Summon new enemies","","Read intents to plan your plays wisely!"]},{title:"Emplacements",lines:["Some cards have dual use \u2014 cast OR emplace.","","Cast: Immediate effect (damage, block, etc.)","Emplace: Place as a structure in a column."," Structures trigger every turn automatically!","","To emplace: select the card, press e to toggle","emplace mode, choose a column, press Enter."]},{title:"Status Effects",lines:["V = Vulnerable Takes +25% damage per stack","W = Weak Deals -15% damage per stack","B = Burn Takes damage each turn, decays","F = Fortified Takes -15% damage per stack","E = Empowered Deals +25% damage per stack","","Stack-based: 2x Vulnerable = +50% damage taken."]},{title:"The Map & Node Types",lines:["\u2694 Combat Standard enemy encounter","\u2605 Elite Harder fight, better rewards","\u25B3 Rest Heal or remove a card","$ Shop Buy cards, potions, remove cards","? Event Story encounters with choices","\u25C6 Boss Act boss \u2014 defeat to advance","","Choose your path wisely. Elites are risky but rewarding."]},{title:"The Keep & Meta-Progression",lines:["After each run, you earn Echoes based on performance.","Spend Echoes at The Keep to:",""," \u25C6 Upgrade structures (bonuses for future runs)"," \u25C6 Talk to NPCs (unlock story and lore)"," \u25C6 Increase Ascension (harder difficulty, new modifiers)","","The Keep remembers. Each run makes you stronger."]},{title:"Ready to Play!",lines:["Quick reference:"," 1-5 = select card \u2190\u2192 = target column"," Enter = play card Space = end turn"," e = emplace toggle p = use potion"," i = inspect enemy d = view deck"," q = quit to menu","","The Pale awaits, Warden. Defend the Keep.","","Press Enter to begin."]}];function gn({page:e,totalPages:t}){let n=hn[e];return n?fn(no,{flexDirection:"column",padding:1,children:[fn(tt,{bold:!0,color:"yellow",children:["\u25C6 Tutorial \u2014 ",n.title," (",e+1,"/",t,")"]}),vt(tt,{children:" "}),n.lines.map((a,r)=>vt(tt,{children:a||" "},r)),vt(tt,{children:" "}),vt(tt,{dimColor:!0,children:e<t-1?"\u2190 prev \u2192 next Enter skip to game q close":"\u2190 prev Enter start game q close"})]}):null}var at=hn.length;import{Box as bt,Text as j}from"ink";import{Fragment as yn,jsx as te,jsxs as se}from"react/jsx-runtime";var wn={asciiMode:!1,showTutorialHints:!0,combatLogSize:4};function vn({settings:e,selectedIndex:t,saveInfo:n,confirmingReset:a,message:r}){let o=[{id:"ascii",label:`ASCII Mode: ${e.asciiMode?"ON":"OFF"}`,description:"Use plain ASCII characters (no Unicode symbols)"},{id:"hints",label:`Tutorial Hints: ${e.showTutorialHints?"ON":"OFF"}`,description:"Show helpful tips during first runs"},{id:"log",label:`Combat Log Lines: ${e.combatLogSize}`,description:"Number of recent combat events shown (0-8)"},{id:"tutorial",label:"View Tutorial",description:"Re-read the game tutorial"},{id:"controls",label:"Controls Reference",description:"View all keybindings"},{id:"reset",label:"Reset Save Data",description:"Delete all progress and start fresh"},{id:"back",label:"Back to Menu",description:""}];return se(bt,{flexDirection:"column",padding:1,children:[te(j,{bold:!0,color:"yellow",children:"\u25C6 Settings"}),te(j,{children:" "}),te(bt,{paddingX:1,children:se(bt,{flexDirection:"column",width:40,children:[te(j,{bold:!0,dimColor:!0,children:"Save Info"}),se(j,{dimColor:!0,children:["Runs: ",n.totalRuns," Wins: ",n.totalWins," Echoes: ",n.echoes]}),se(j,{dimColor:!0,children:["Highest Ascension: ",n.highestAscension]}),se(j,{dimColor:!0,children:["Save: ",n.hasSave?"~/.config/codekeep/game.json":"None"]})]})}),te(j,{children:" "}),o.map((l,d)=>{let s=d===t;return se(bt,{children:[se(j,{bold:s,color:s?l.id==="reset"?"red":"yellow":void 0,children:[s?"\u25B6 ":" ",l.label]}),s&&l.description?se(j,{dimColor:!0,children:[" \u2014 ",l.description]}):null]},l.id)}),a&&se(yn,{children:[te(j,{children:" "}),te(j,{bold:!0,color:"red",children:"Are you sure? This deletes ALL progress. Press Enter again to confirm, Esc to cancel."})]}),r&&se(yn,{children:[te(j,{children:" "}),te(j,{color:"cyan",bold:!0,children:r})]}),te(j,{children:" "}),te(j,{dimColor:!0,children:"\u2191\u2193 navigate Enter toggle/select q back"})]})}import{Box as ro,Text as T}from"ink";import{jsx as x,jsxs as oo}from"react/jsx-runtime";function bn(){return oo(ro,{flexDirection:"column",padding:1,children:[x(T,{bold:!0,color:"yellow",children:"\u25C6 Controls Reference"}),x(T,{children:" "}),x(T,{bold:!0,children:"Global"}),x(T,{children:" q Quit / back to menu"}),x(T,{children:" \u2191\u2193 or j/k Navigate menus"}),x(T,{children:" Enter Confirm / select"}),x(T,{children:" Esc Cancel / go back"}),x(T,{children:" "}),x(T,{bold:!0,children:"Combat"}),x(T,{children:" 1-9 Select card from hand"}),x(T,{children:" \u2190\u2192 or h/l Target column"}),x(T,{children:" Enter Play selected card"}),x(T,{children:" Space End your turn"}),x(T,{children:" e Toggle emplace mode"}),x(T,{children:" p Use first available potion"}),x(T,{children:" i Inspect enemies"}),x(T,{children:" d View deck"}),x(T,{children:" Esc Deselect card"}),x(T,{children:" "}),x(T,{bold:!0,children:"Map"}),x(T,{children:" \u2191\u2193 Select next node"}),x(T,{children:" Enter Enter node"}),x(T,{children:" d View deck"}),x(T,{children:" "}),x(T,{bold:!0,children:"Inspect Mode (i in combat)"}),x(T,{children:" \u2190\u2192 Switch column"}),x(T,{children:" \u2191\u2193 Switch enemy in column"}),x(T,{children:" i / Esc Close inspect"}),x(T,{children:" "}),x(T,{dimColor:!0,children:"Press q or Esc to go back"})]})}import{useState as nt,useCallback as Te,useRef as so}from"react";function kn(){let[e,t]=nt(null),[n,a]=nt(-1),[r,o]=nt(2),[l,d]=nt(""),[s,p]=nt(!1),y=so(null),g=Te((h,b,I,F,L,U,ye)=>{let $=h??Kt(),le=b??Math.floor(Math.random()*2147483647),ie=Pa($,le,I,F,L,U??[],ye);y.current=ie,t({...ie}),a(-1),o(2),p(!1),d("Your turn. Select a card (1-5) and a column (\u2190\u2192).")},[]),_=(()=>{if(n<0||!e)return!1;let h=e.hand[n];if(!h)return!1;let b=O(h.defId);if(!b)return!1;let I=new Set(["damage","damage_if_vulnerable","damage_equal_block","damage_if_emplaced","damage_plus_block","damage_if_low_hp","vulnerable","weak","burn"]);return b.effects.some(F=>I.has(F.type)&&(F.target==="single"||F.target==="column"))})(),E=Te(h=>{if(!y.current||y.current.phase!=="player"||h<0||h>=y.current.hand.length)return;let b=y.current.hand[h],I=O(b.defId);if(!I)return;if(I.cost>y.current.resolve){d(`Not enough Resolve for ${I.name} (costs ${I.cost}).`);return}a(h);let F=new Set(["damage","damage_if_vulnerable","damage_equal_block","damage_if_emplaced","damage_plus_block","damage_if_low_hp","vulnerable","weak","burn"]),L=I.effects.some(U=>F.has(U.type)&&(U.target==="single"||U.target==="column"));d(L?`${I.name} selected. Choose column (\u2190\u2192), Enter to play.`:`${I.name} selected. Enter to play.`)},[]),M=Te(h=>{h>=0&&h<5&&o(h)},[]),K=Te(()=>{let h=y.current;if(!h||h.phase!=="player"||n<0)return;let b=h.hand[n];if(!b)return;let I=O(b.defId);if(!I)return;let F=h.hand.length;if(Aa(h,n,r,s),h.hand.length===F){d(`Cannot play ${I.name}. Not enough Resolve.`);return}y.current=h,t({...h}),a(-1),p(!1),h.outcome==="win"?d("Victory! The Pale recedes."):h.outcome==="lose"?d("The Gate has fallen..."):d(`${s?"Emplaced":"Played"} ${I.name}. ${h.resolve} Resolve left.`)},[n,r,s]),R=Te(()=>{if(n<0||!y.current)return;let h=y.current.hand[n];if(!h)return;let b=O(h.defId);if(!b||b.type!=="emplace"){d("This card cannot be emplaced.");return}p(I=>!I),d(s?`${b.name}: cast mode`:`${b.name}: EMPLACE mode \u2014 place in a column`)},[n,s]),D=Te(()=>{let h=y.current;!h||h.phase!=="player"||(Da(h),y.current=h,t({...h}),a(-1),h.outcome==="win"?d("Victory! The Pale recedes."):h.outcome==="lose"?d("The Gate has fallen..."):d(`Turn ${h.turn}. Your move.`))},[]),S=Te(h=>{let b=y.current;if(!(!b||!h)){for(let I of h.effects)switch(I.type){case"heal":b.gateHp=Math.min(b.gateMaxHp,b.gateHp+I.value);break;case"block":b.gateBlock+=I.value;break;case"damage":{let F=r;if(I.target==="column"){let L=b.columns[F];if(L)for(let U of L.enemies)U.hp-=I.value}else if(I.target==="all")for(let L of b.columns)for(let U of L.enemies)U.hp-=I.value;break}case"draw":{let F=N(b.seed+b.turn*53),{drawn:L,newDrawPile:U,newDiscardPile:ye}=pe(b.drawPile,b.discardPile,I.value,F);b.hand.push(...L),b.drawPile=U,b.discardPile=ye;break}case"resolve":b.resolve=Math.min(b.maxResolve+5,b.resolve+I.value);break}y.current=b,t({...b}),d(`Used ${h.name}.`)}},[r]);return{combat:e,selectedCard:n,targetColumn:r,message:l,emplaceMode:s,selectCard:E,selectTarget:M,confirmPlay:K,endTurn:D,toggleEmplace:R,startCombat:g,applyPotion:S,needsTarget:_}}import{Fragment as la,jsx as w,jsxs as k}from"react/jsx-runtime";var _n=60,Tn=18;function uo(){let{stdout:e}=mo(),[t,n]=C({columns:e?.columns??process.stdout.columns??80,rows:e?.rows??process.stdout.rows??24});return lo(()=>{let a=e??process.stdout,r=()=>n({columns:a.columns,rows:a.rows});return a.on("resize",r),()=>{a.off("resize",r)}},[e]),t}function po({dryRun:e}){let{exit:t}=io(),{columns:n,rows:a}=uo(),[r,o]=C("menu"),[l,d]=C(0),[s,p]=C(null),[y,g]=C(0),[_,E]=C([]),[M,K]=C(0),[R,D]=C([]),[S,h]=C(0),[b,I]=C(null),[F,L]=C(0),[U,ye]=C(0),[$,le]=C(null),[ie,kt]=C(0),[ia,xe]=C(""),[ca,Sn]=C(!1),[we,En]=C([]),[Ie,_t]=C(0),[Tt,Ce]=C(0),xt=kn(),{combat:V,selectedCard:rt,targetColumn:It,message:Pn,emplaceMode:yo,selectCard:da,selectTarget:ma,confirmPlay:An,endTurn:Rn,toggleEmplace:Dn,startCombat:Ct,applyPotion:wo,needsTarget:Mn}=xt,[St,Et]=C(!1),[ot,Pt]=C(0),[Hn,At]=C(0),[Rt,ua]=C(null),[pa,Se]=C(0),[We,Dt]=C(wn),[fa,Mt]=C(0),[Bn,st]=C(""),[ha,Ee]=C(!1),[X,Pe]=C(()=>De()),ga=!X||X.keep.totalRuns<=1,Fe=X?La(X.keep.totalRuns,X.keep.highestAscension):"surface",Gn=n<_n||a<Tn,ne=ae(()=>{let c=X??De();return c||(c=za("Warden"),c.keep.npcs.length===0&&(c.keep.npcs=Xt()),me(c)),c.keep.npcs.length===0&&(c.keep.npcs=Xt()),Pe(c),c},[X]),P=ae(c=>{if(e)return;let m=ne();m.activeRun=c,$&&(m.keep=$),me(m),Pe(m)},[e,$,ne]),Ht=ae(()=>{let c=`run-${Date.now()}`,m=ne(),i=Ga(c,m.keep.highestAscension);p(i),g(0),m.activeRun=i,m.keep.totalRuns++,le(m.keep),me(m),Pe(m),m.keep.totalRuns===1?(Se(0),o("tutorial")):o("map")},[ne]),Nn=ae(()=>{let c=De();c?.activeRun&&(p(c.activeRun),le(c.keep),g(0),o("map"))},[]),ya=ae(()=>{let c=ne();Pe(c),le(c.keep),kt(0),xe(""),o("keep")},[ne]),wa=ae(()=>s?Ba(s.map,s.currentNodeId):[],[s]),Wn=ae(c=>{if(!s)return;let m=Na(s,c.id);if(c.type==="combat"||c.type==="elite"){let i=ee(s.seed+c.id),u=N(i),v=Ma(s.act,u,c.type==="elite");Ct(m.deck,i,m.gateHp,m.gateMaxHp,v.enemies,m.relics,ut(s.act,s.ascensionLevel)),p(m),o("combat")}else if(c.type==="boss"){let i=ee(s.seed+"-boss-"+s.act),u=Ia(s.act);Ct(m.deck,i,m.gateHp,m.gateMaxHp,u,m.relics,ut(s.act,s.ascensionLevel));let v=Lt(s.act);if(v?.dialogue){let A=v.dialogue.find(ce=>ce.storyLayer===Fe)??v.dialogue[0];A&&ua(A.onAppear)}p(m),o("combat")}else if(c.type==="shop"){let i=N(ee(s.seed+c.id));D(Va(i)),h(0),p(m),o("shop")}else if(c.type==="event"){let i=N(ee(s.seed+c.id));I(Oa(s.act,i,Fe)),L(0),p(m),o("event")}else c.type==="rest"&&(ye(0),p(m),o("rest"));P(m)},[s,Ct,P]),$e=ae((c,m)=>{Sn(m),p(c);let i=ne(),u=Jt(m,c.act,c.ascensionLevel);i.keep.echoes+=u,m&&(i.keep.totalWins++,c.ascensionLevel>=i.keep.highestAscension&&(i.keep.highestAscension=c.ascensionLevel+1)),i.activeRun=null,le(i.keep),me(i),Pe(i),o("result")},[ne]),Fn=ae(()=>{if(!V||!s)return;let c={...s,gateHp:V.gateHp};if(V.outcome==="lose"){$e(c,!1);return}let m=s.currentNodeId?Re(s.map,s.currentNodeId):null,i=m?.type==="elite"?it.elite:m?.type==="boss"?it.boss:it.combat;if(c=je(c,i),c.relics.includes("mending_stone")&&(c=pt(c,5)),c.relics.includes("fragment_magnet")&&(c=je(c,5)),m?.type==="elite"||m?.type==="boss"){let v=N(ee(s.seed+(s.currentNodeId??"")+"-relic")),A=Ea(v,c.relics,3);if(A.length>0){En(A),_t(0),p(c),P(c),o("relic_reward");return}}if(m?.type==="boss"){s.act<3?(c=Yt(c),p(c),P(c),g(0),o("map")):$e(c,!0);return}let u=N(ee(s.seed+(s.currentNodeId??"")+"-reward"));E(mt(u)),K(0),p(c),P(c),o("reward")},[V,s,P,$e]),va=ae(c=>{if(!s)return;let m=s;c&&(m=jt(m,qe(c.id))),p(m),P(m),g(0),o("map")},[s,P]),ba=ae(c=>{if(!s)return;let m=s;if(c&&(m={...m,relics:[...m.relics,c.id]}),p(m),P(m),(s.currentNodeId?Re(s.map,s.currentNodeId):null)?.type==="boss")s.act<3?(m=Yt(m),p(m),P(m),g(0),o("map")):$e(m,!0);else{let u=N(ee(s.seed+(s.currentNodeId??"")+"-reward"));E(mt(u)),K(0),o("reward")}},[s,P,$e]),Bt=[{label:"The Keep",action:"keep"},{label:"New Run",action:"new"},...X?.activeRun?[{label:"Resume Run",action:"resume"}]:[],{label:"Tutorial",action:"tutorial"},{label:"Settings",action:"settings"},{label:"Quit",action:"quit"}];if(co((c,m)=>{if(r==="tutorial"){m.rightArrow||c==="l"?Se(i=>Math.min(at-1,i+1)):m.leftArrow||c==="h"?Se(i=>Math.max(0,i-1)):m.return?pa===at-1?Ht():Se(i=>Math.min(at-1,i+1)):(c==="q"||m.escape)&&o("menu");return}if(r==="controls"){(c==="q"||m.escape)&&o("settings");return}if(r==="settings"){let i=["ascii","hints","log","tutorial","controls","reset","back"];if(m.upArrow||c==="k")Mt(u=>Math.max(0,u-1)),Ee(!1);else if(m.downArrow||c==="j")Mt(u=>Math.min(i.length-1,u+1)),Ee(!1);else if(c==="q"||m.escape)o("menu"),Ee(!1);else if(m.return){let u=i[fa];u==="ascii"?(Dt(v=>({...v,asciiMode:!v.asciiMode})),st("ASCII mode "+(We.asciiMode?"disabled":"enabled"))):u==="hints"?(Dt(v=>({...v,showTutorialHints:!v.showTutorialHints})),st("Tutorial hints "+(We.showTutorialHints?"disabled":"enabled"))):u==="log"?Dt(v=>({...v,combatLogSize:v.combatLogSize>=8?0:v.combatLogSize+2})):u==="tutorial"?(Se(0),o("tutorial")):u==="controls"?o("controls"):u==="reset"?ha?(Ya(),Pe(null),le(null),p(null),Ee(!1),st("Save data deleted. Starting fresh.")):Ee(!0):u==="back"&&o("menu")}return}if(r==="relic_reward"){m.upArrow||c==="k"?_t(i=>Math.max(0,i-1)):m.downArrow||c==="j"?_t(i=>Math.min(we.length,i+1)):c==="s"?ba(null):m.return&&ba(Ie<we.length?we[Ie]:null);return}if(r==="menu"){if(m.upArrow||c==="k")d(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")d(i=>Math.min(Bt.length-1,i+1));else if(m.return){let i=Bt[l]?.action;i==="keep"?ya():i==="new"?Ht():i==="resume"?Nn():i==="tutorial"?(Se(0),o("tutorial")):i==="settings"?(Mt(0),st(""),Ee(!1),o("settings")):t()}else c==="q"&&t();return}if(r==="deck"){(c==="q"||m.escape)&&o("map");return}if(r==="map"&&s){let i=wa();m.upArrow||c==="k"?g(u=>Math.max(0,u-1)):m.downArrow||c==="j"?g(u=>Math.min(i.length-1,u+1)):m.return&&i[y]?Wn(i[y]):c==="d"?o("deck"):c==="q"&&(P(s),o("menu"));return}if(r==="reward"){let i=_.length;m.upArrow||c==="k"?K(u=>Math.max(0,u-1)):m.downArrow||c==="j"?K(u=>Math.min(i,u+1)):c==="s"?va(null):m.return&&va(M<_.length?_[M]:null);return}if(r==="shop"&&s){if(m.upArrow||c==="k")h(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")h(i=>Math.min(R.length-1,i+1));else if(c==="q"||m.escape)g(0),o("map");else if(m.return){let i=R[S];if(i&&s.fragments>=i.cost){let u=Wa(s,i.cost);if(!u)return;if(i.type==="card"&&i.cardDef)u=jt(u,qe(i.cardDef.id)),p(u),P(u),D(v=>v.filter((A,ce)=>ce!==S)),h(0);else if(i.type==="potion"&&i.potionDef){let v=Fa(u,i.potionDef.id);v&&(u=v),p(u),P(u),D(A=>A.filter((ce,lt)=>lt!==S)),h(0)}else i.type==="card_remove"&&(p(u),P(u),Ce(0),D(v=>v.filter((A,ce)=>ce!==S)),o("shop_remove"))}}return}if(r==="event"&&b&&s){if(m.upArrow||c==="k")L(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")L(i=>Math.min(b.choices.length-1,i+1));else if(m.return){let i=b.choices[F],u=s;switch(i.effect.type){case"heal":u=pt(u,i.effect.value);break;case"damage":{u={...u,gateHp:Math.max(1,u.gateHp-i.effect.value)};let v=i.label.match(/(\d+)\s*fragments/i);v&&(u=je(u,parseInt(v[1])));break}case"fragments":u=je(u,i.effect.value);break;case"max_hp":u={...u,gateMaxHp:u.gateMaxHp+i.effect.value,gateHp:u.gateHp+i.effect.value};break;case"card_reward":{let v=i.label.match(/lose\s+(\d+)\s*hp/i);v&&(u={...u,gateHp:Math.max(1,u.gateHp-parseInt(v[1]))});let A=N(ee(s.seed+(b?.id??"")));E(mt(A)),K(0),p(u),P(u),o("reward");return}case"remove_card":{p(u),P(u),o("deck_remove");return}case"nothing":break}p(u),P(u),g(0),o("map")}return}if(r==="rest"&&s){if(m.upArrow||c==="k")ye(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")ye(i=>Math.min(2,i+1));else if(m.return){let i=s;U===0?(i=pt(i,Math.floor(i.gateMaxHp*.3)),p(i),P(i),g(0),o("map")):U===1&&i.deck.length>5?(p(i),Ce(0),o("deck_remove")):(p(i),P(i),g(0),o("map"))}return}if(r==="deck_remove"&&s){if(m.upArrow||c==="k")Ce(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")Ce(i=>Math.min(s.deck.length-1,i+1));else if(m.escape||c==="q")g(0),o("map");else if(m.return&&s.deck.length>5){let i=s.deck[Tt];if(i){let u=zt(s,i.instanceId);p(u),P(u)}g(0),o("map")}return}if(r==="shop_remove"&&s){if(m.upArrow||c==="k")Ce(i=>Math.max(0,i-1));else if(m.downArrow||c==="j")Ce(i=>Math.min(s.deck.length-1,i+1));else if(m.escape||c==="q")o("shop");else if(m.return&&s.deck.length>5){let i=s.deck[Tt];if(i){let u=zt(s,i.instanceId);p(u),P(u)}o("shop")}return}if(r==="keep"&&$){let i=oe.length+$.npcs.length+2;if(m.upArrow||c==="k")kt(u=>Math.max(0,u-1));else if(m.downArrow||c==="j")kt(u=>Math.min(i-1,u+1));else if(c==="q")o("menu");else if(m.return)if(ie<oe.length){let u=oe[ie],v=Ka($,u.id);if(v){le(v);let A=ne();A.keep=v,me(A),xe(`Upgraded ${u.name}!`)}else ze($,u.id)>=u.maxLevel?xe(`${u.name} is already max level.`):xe(`Not enough Echoes to upgrade ${u.name}.`)}else if(ie<oe.length+$.npcs.length){let u=ie-oe.length,v=$.npcs[u],A=Ua(v.id,$);if(A){let ce=qa($,v.id,A.dialogueId);le(ce);let lt=ne();lt.keep=ce,me(lt),xe(`${A.speaker}: "${A.text}"`)}else xe("(No new dialogue)")}else ie===oe.length+$.npcs.length&&Ht();return}if(r==="result"){m.return||c===" "?ya():c==="q"&&o("menu");return}if(r==="combat"&&V){if(V.outcome!=="undecided"){(m.return||c===" ")&&Fn();return}if(Rt&&V.turn>1&&ua(null),c==="i"){St?Et(!1):(Et(!0),Pt(0),At(0));return}if(St){if(m.leftArrow||c==="h")Pt(i=>Math.max(0,i-1));else if(m.rightArrow||c==="l")Pt(i=>Math.min(4,i+1));else if(m.upArrow||c==="k")At(i=>Math.max(0,i-1));else if(m.downArrow||c==="j"){let i=(V.columns[ot]?.enemies.length??1)-1;At(u=>Math.min(Math.max(0,i),u+1))}else m.escape&&Et(!1);return}if(c==="q"){o("menu");return}if(c==="d"&&s){o("deck");return}if(c==="e"){Dn();return}if(c==="p"&&s){let i=s.potions.findIndex(u=>u!==null);if(i>=0){let u=$a(s,i);if(u&&xt.combat){let v=Le.find(A=>A.id===u.potionId);p(u.run),P(u.run),xt.applyPotion(v??null)}}return}if(c>="1"&&c<="9"){da(parseInt(c)-1);return}if(m.leftArrow||c==="h"){ma(Math.max(0,It-1));return}if(m.rightArrow||c==="l"){ma(Math.min(4,It+1));return}if(m.return&&rt>=0){An();return}if(c===" "){Rn();return}if(m.escape){da(-1);return}}}),Gn)return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),k(f,{color:"red",children:["Terminal too small (",n,"x",a,", need ",_n,"x",Tn,")"]})]});if(r==="menu")return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),w(f,{children:" "}),(Fe==="true_ending"?["The fortress. The Pale. You can no longer tell which side you're on."]:Fe==="truth"?["The fortress stands. The Pale stands. The line between them blurs."]:Fe==="cracks"?["The fortress stands at the edge of the Pale.","You've stood here before. You're sure of it."]:["The fortress stands at the edge of the Pale.","Beyond the walls, something stirs."]).map((m,i)=>w(f,{children:m},i)),w(f,{children:" "}),Bt.map((m,i)=>k(f,{bold:i===l,color:i===l?"yellow":void 0,children:[i===l?"\u25B6 ":" ",m.label]},m.action)),w(f,{children:" "}),w(f,{dimColor:!0,children:"\u2191\u2193 navigate Enter select q quit"})]});if(r==="tutorial")return w(gn,{page:pa,totalPages:at});if(r==="controls")return w(bn,{});if(r==="settings"){let c={totalRuns:X?.keep.totalRuns??0,totalWins:X?.keep.totalWins??0,highestAscension:X?.keep.highestAscension??0,echoes:X?.keep.echoes??0,hasSave:!!X};return w(vn,{settings:We,selectedIndex:fa,saveInfo:c,confirmingReset:ha,message:Bn})}if(r==="deck"&&s)return w(sn,{deck:s.deck});if(r==="keep"&&$)return k(Q,{flexDirection:"column",children:[w(pn,{keep:$,selectedIndex:ie}),ia&&k(f,{color:"cyan",bold:!0,children:[" ",ia]})]});if((r==="deck_remove"||r==="shop_remove")&&s)return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"red",children:"\u25C6 Remove a Card"}),k(f,{dimColor:!0,children:["Choose a card to remove from your deck (",s.deck.length," cards)."]}),w(f,{children:" "}),s.deck.map((c,m)=>{let i=O(c.defId),u=m===Tt;return k(f,{bold:u,color:u?"yellow":"white",children:[u?"\u25B6 ":" ",i?.name??c.defId," (",i?.rarity,") \u2014 ",i?.description??""]},c.instanceId)}),w(f,{children:" "}),w(f,{dimColor:!0,children:"\u2191\u2193 navigate Enter remove Esc cancel"})]});if(r==="map"&&s){let c=wa();return k(Q,{flexDirection:"column",children:[k(Q,{justifyContent:"space-between",paddingX:1,children:[k(f,{children:["Gate ",k(f,{bold:!0,color:s.gateHp>40?"green":s.gateHp>20?"yellow":"red",children:[s.gateHp,"/",s.gateMaxHp]})]}),k(f,{children:["Fragments ",w(f,{bold:!0,color:"yellow",children:s.fragments})]}),k(f,{children:["Deck ",w(f,{dimColor:!0,children:s.deck.length})]})]}),ga&&We.showTutorialHints&&!s.currentNodeId&&w(f,{color:"green",bold:!0,children:" TIP: \u2694=combat \u2605=elite(harder, more reward) \u25B3=rest $=shop ?=event \u25C6=boss. \u2191\u2193 select, Enter to go."}),w(ln,{map:s.map,currentNodeId:s.currentNodeId,reachableIds:c.map(m=>m.id),selectedNodeId:c[y]?.id??null})]})}if(r==="reward")return w(on,{cards:_,selectedIndex:M});if(r==="relic_reward")return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"yellow",children:"\u25C6 Relic Reward"}),w(f,{dimColor:!0,children:"Choose a relic to add to your collection (s to skip):"}),w(f,{children:" "}),we.map((c,m)=>{let i=m===Ie;return k(Q,{flexDirection:"column",children:[k(f,{bold:i,color:i?"yellow":"white",children:[i?"\u25B6 ":" ",c.name]}),k(f,{dimColor:!0,children:[" ",c.description]})]},c.id)}),k(f,{bold:Ie===we.length,color:Ie===we.length?"yellow":"white",children:[Ie===we.length?"\u25B6 ":" ","Skip"]}),w(f,{children:" "}),s&&s.relics.length>0&&k(f,{dimColor:!0,children:["Current relics: ",s.relics.join(", ")]}),w(f,{dimColor:!0,children:"\u2191\u2193 navigate Enter select s skip"})]});if(r==="shop"&&s)return w(cn,{items:R,selectedIndex:S,fragments:s.fragments});if(r==="event"&&b)return w(dn,{event:b,selectedChoice:F});if(r==="rest"&&s)return w(un,{gateHp:s.gateHp,gateMaxHp:s.gateMaxHp,selectedChoice:U,deckSize:s.deck.length});if(r==="result"){let c=s?Jt(ca,s.act,s.ascensionLevel):0;return k(Q,{flexDirection:"column",padding:1,children:[w(f,{bold:!0,color:"yellow",children:"\u25C6 CodeKeep \u2014 The Pale"}),w(f,{children:" "}),ca?k(la,{children:[w(f,{bold:!0,color:"green",children:"\u2605 RUN COMPLETE"}),w(f,{children:"The Pale recedes. The Keep endures."})]}):k(la,{children:[w(f,{bold:!0,color:"red",children:"\u2717 DEFEAT"}),w(f,{children:"The Gate has fallen. The Pale consumes all."})]}),s&&k(la,{children:[k(f,{dimColor:!0,children:["Act ",s.act," | Deck: ",s.deck.length," cards | Fragments: ",s.fragments]}),k(f,{children:["Echoes earned: ",k(f,{bold:!0,color:"cyan",children:["+",c]})]})]}),w(f,{children:" "}),w(f,{dimColor:!0,children:"Enter \u2192 The Keep | q \u2192 menu"})]})}if(r==="combat"&&V&&s){let c=ga&&We.showTutorialHints&&V.turn<=3?V.turn===1&&rt<0?"TIP: Press 1-5 to select a card. \u2190\u2192 to target a column. Enter to play. Space to end turn.":V.turn===1&&rt>=0?"TIP: Arrow keys choose which column to target. Press Enter to play the card.":V.turn===2?"TIP: Enemies with \u2694 will attack your Gate. \u2193 means they advance. Block reduces damage. Press i to inspect enemies.":V.turn===3?'TIP: Cards with type "emplace" can become structures! Select one, press e to toggle emplace mode, then Enter.':null:null;return k(Q,{flexDirection:"column",paddingX:1,children:[k(f,{dimColor:!0,children:["Act ",s.act," | Gate ",s.gateHp,"/",s.gateMaxHp," | Fragments ",s.fragments," | d=deck i=inspect"]}),c&&w(f,{color:"green",bold:!0,children:c}),Rt&&w(Q,{borderStyle:"single",borderColor:"magenta",paddingX:1,marginBottom:1,children:k(f,{color:"magenta",italic:!0,children:['"',Rt,'"']})}),w(nn,{combat:V,selectedCard:rt,targetColumn:It,needsTarget:Mn,message:Pn}),St&&(()=>{let i=V.columns[ot]?.enemies[Hn];if(!i)return k(f,{dimColor:!0,children:["No enemy in column ",ot+1,". \u2190\u2192 to navigate."]});let u=de(i.templateId);return k(Q,{flexDirection:"column",borderStyle:"single",borderColor:"cyan",paddingX:1,children:[k(f,{bold:!0,color:"cyan",children:["Inspecting: ",u?.name??i.templateId," (Col ",ot+1,")"]}),k(f,{children:["HP: ",i.hp,"/",i.maxHp," Row: ",i.row]}),w(f,{dimColor:!0,children:u?.description??""}),i.statusEffects.length>0&&k(f,{children:["Status: ",i.statusEffects.map(v=>`${v.type}(${v.stacks}x, ${v.duration}t)`).join(", ")]}),k(f,{children:["Intent: ",i.intent?`${i.intent.type} ${i.intent.value}`:"unknown"]}),w(f,{dimColor:!0,children:"\u2190\u2192 column \u2191\u2193 enemy i/Esc close"})]})})()]})}return w(f,{children:"Loading..."})}function xn(e){return w(ft,{children:w(po,{...e})})}import{jsx as go}from"react/jsx-runtime";var In="0.5.0";globalThis.__CODEKEEP_VERSION=In;var Cn=new fo;Cn.name("codekeep").description("CodeKeep: The Pale \u2014 deck-building tactical roguelike in your terminal").version(In).option("--ascii","Force ASCII-only rendering (no Unicode box drawing)").option("--compact","Compact layout for narrow terminals").option("--tutorial","Replay the tutorial").option("--no-save","Dry-run mode: play without writing to disk").action(e=>{(!process.stdin.isTTY||!process.stdout.isTTY)&&(process.stderr.write(`codekeep requires an interactive terminal.
|
|
20
20
|
Run it directly in your terminal (not piped or in CI).
|
|
21
|
-
`),process.exit(1));let{waitUntilExit:t,unmount:
|
|
21
|
+
`),process.exit(1));let{waitUntilExit:t,unmount:n}=ho(go(xn,{asciiMode:e.ascii??!1,compact:e.compact??!1,forceTutorial:e.tutorial??!1,dryRun:e.save===!1}),{exitOnCtrlC:!1}),a=!1;function r(){if(!a){if(a=!0,e.save!==!1){process.stderr.write(`
|
|
22
22
|
Saving...
|
|
23
|
-
`);try{let
|
|
23
|
+
`);try{let o=De();o&&me(o)}catch{}}n()}}process.on("SIGINT",r),process.on("SIGTERM",r),process.on("SIGHUP",r),t().then(()=>{process.exit(0)}).catch(()=>{process.exit(1)})});Cn.parse();export{In as CLI_VERSION};
|