Slay the Spire 完整架构文档(中文)
用途: 本文档描述游戏的所有架构细节,用于指导 CLI 版重构。重构原则:绝不修改游戏逻辑,仅删除/替换纯 GUI 代码,用帧步进模型替代连续渲染循环。
最后更新: 经过 3 个 subagent 独立审查验证。{”>”} 标记为已纠正的错误。
已验证的关键纠正(第二轮审查补充)
| 纠正项 | 原错误 | 纠正 |
|---|---|---|
| update() 中的 switch | 声称有 switch(rs) + switch(screen) | 只有 switch(screen),无 RenderScene switch |
| RoomPhase 初始化 | 声称多房间 phase 为 null | 字节码验证全部构造函数初始化 phase |
| CardRewardScreen 字段名 | discoveryCards/discoveryText 等 | JAR 用 rewardGroup/skippable/discoveryCard |
| getEventId() | 声称有此方法 | 不存在,需反射取 event.ID |
| purchaseCard() | 声称 public | 实际 private |
| ProceedButton | 声称有 proceed() 方法 | 无单独方法,逻辑在 update() 内联 |
| GridCardSelectScreen 自动关闭 | 声称总是 closeCurrentScreen | forUpgrade/Transform/Purge(1张) 转到确认屏幕 |
| lastCombatMetricKey | 不全面 | 也在 getBoss() 中设置,事件战斗不设 |
| isJustForConfirming 回调 | 只写 closeCurrentScreen | 需先遍历 targetGroup,用 FastCardObtainEffect 获得卡牌 |
| Shop purge 流程 | CLI 手动删卡 vs updatePurge 自动 | updatePurge() 自动处理 gridSelectScreen 选择结果 |
| gameLoop 入口 | 伪代码引 CardCrawlGame | CLI 直接调 AbstractDungeon.update() |
| hasFocus 何时变 false | 未说明 | 事件类型不同机制不同,ROOM 事件通过 buttonEffect complete 变为 false |
| 回合计牌 → cardQueue.add | 仅 cardQueue.add | playCard() 加入 queue 后,能量扣减和手牌移除由 actionManager 在后续帧自动处理 |
| 回合结束 | 仅设 endTurnQueued | 必须先加 NewQueueCardAction 到 action bottom |
| Potion use | 仅 use+destroy | 需 canUse() 检查, onUsePotion() 回调所有遗物, metric 记录 |
| Grid 选牌 cardSelectAmount | 声称需反射 | 直接字段访问 this.cardSelectAmount++,非反射 |
| Grid forUpgrade/Transform | 声称自动 close | 进入 confirmScreenUp 需二次确认 |
| Map 节点回调 | nextRoom + nextRoomTransitionStart | 完整的 4-phase 流程: 点击→timer→edge mark→transition start→fade→nextRoomTransition |
| CardRewardScreen stub 字段 | discoveryCards 等 | 缺 discoveryCard/discovery/chooseOne/skippable 字段,需补全 |
目录
- 顶层架构
- 每帧执行顺序(核心)
- RoomPhase 机制
- AbstractDungeon 完全字段与方法
- 房间系统(Room System)
- 战斗系统(Combat System)
- 事件系统(Event System)
- Screen 系统
- 选牌系统
- 营地与商店
- 关键 GUI 组件分析
- SoulGroup 机制
- 重构计划
1. 顶层架构
1.1 游戏启动
main() → DesktopLauncher → LwjglApplication(CardCrawlGame, config)
→ CardCrawlGame.create()
├── 加载 Prefs(save slot, player settings)
├── Settings.initialize(false) — 读取所有配置
├── 加载 LocalizedStrings(从 localization/{lang}/ JSON)
├── 初始化各子系统:MusicMaster, SoundMaster, AbstractCreature,
│ AbstractCard, GameDictionary, ImageMaster, AbstractPower,
│ FontHelper, UnlockTracker, CardLibrary, RelicLibrary,
│ InputHelper, TipTracker, ModHelper, ShaderHelper
├── 创建 SplashScreen
└── mode = GameMode.SPLASH1.2 游戏模式(GameMode 枚举,4 个值)
| 序号 | 反编译名 | 实际含义 |
|---|---|---|
| 0 | CHAR_SELECT | 主菜单 / 角色选择 |
| 1 | GAMEPLAY | 地牢运行中 |
| 2 | DUNGEON_TRANSITION | 幕间过渡(在 GAMEPLAY 中处理) |
| 3 | SPLASH | 启动画面 |
1.3 模式切换流程
SPLASH → splashScreen 更新完毕 → mode=CHAR_SELECT
CHAR_SELECT → mainMenuScreen 淡出 → 创建角色 → mode=GAMEPLAY
GAMEPLAY → dungeon 被打败 → 创建新的 DungeonTransitionScreen
GAMEPLAY → 所有幕完成 → 游戏结束2. 每帧执行顺序
这是整个文档最重要的部分。以下是 GUI 版每帧的完整调用顺序:
2.1 CardCrawlGame.render() → update()
每帧执行顺序(从上到下):
1. cursor.update()
2. screenShake.update(viewport)
3. if (mode != SPLASH): updateFade() // 淡入淡出动画
4. music.update()
5. sound.update()
6. steelSeries.update()
7. Debug 开关处理
8. Steam/CInput 控制器更新
9. InputHelper.updateFirst() // ← 每帧第一次
10. cardPopup.update() (如果打开)
11. relicPopup.update() (如果打开)
12. 弹窗处理(保存鼠标坐标)
13. switch(mode):
★ GAMEPLAY:
if (dungeonTransitionScreen != null):
dungeonTransitionScreen.update()
if (完成): 清除过渡, getDungeon() 加载地牢
else if (dungeon != null):
dungeon.update() ←←← 这是最重要的调用
else: log "Eh-?"
if (isDungeonBeaten && fadeColor.a == 1.0F):
清除 dungeon, 创建下个幕的 transition
SPLASH: splashScreen.update()
CHAR_SELECT: mainMenuScreen.update()
14. updateDebugSwitch()
15. InputHelper.updateLast() // ← 每帧最后一次
16. CInputHelper.updateLast() (如果控制器存在)
17. FPS logger (info 模式)2.2 AbstractDungeon.update() — 地牢每帧更新
重要纠正: update() 中只有 switch(screen),没有 switch(rs)(RenderScene switch 只在 render() 中)。以下是字节码验证后的正确版本:
AbstractDungeon.update() 执行顺序:
1. playtime += deltaTime (如果时钟未停)
2. 屏幕计时器抑制输入
3. topPanel.update() ★★★ 总是最先
├── updateGold()
├── updatePotions() ← 药水点击 → PotionPopUp
├── updateRelics()
├── potionUi.update() ← PotionPopUp 使用/丢弃/目标选择
└── updateButtons()
4. dynamicBanner.update()
5. updateFading() ← 淡入/淡出 + 淡出完成时 nextRoomTransition()
6. room.updateObjects() ← 房间内药水/遗物更新
7. 渐变颜色 lerp
8. ★★★ switch(screen) — 唯一的分派 switch ★★★
★ 屏幕关闭时(2 个 case,通过 ordinal 0/1 映射):
case 0 (原 RenderScene.NORMAL/CAMPFIRE 场景):
dungeonMapScreen.update()
room.update() ← 房间每帧更新
scene.update() ← 场景背景
currMapNode.room.eventControllerInput() ★ 遗漏补充:line 2534
case 1 (原 RenderScene.EVENT 场景):
ftue.update()
InputHelper.justClickedRight = false ★ 遗漏补充:line 2538
InputHelper.justClickedLeft = false ★ 遗漏补充:line 2539
room.update()
★ 各 screen overlay——注意:以下 case 是 CURRENT_SCREEN 枚举值:
GRID:
gridSelectScreen.update()
if (PeekButton.isPeeking): room.update() ★ BOSS_REWARD 和 HAND_SELECT 无条件调 room.update()
CARD_REWARD:
cardRewardScreen.update()
if (PeekButton.isPeeking): room.update()
BOSS_REWARD:
bossRelicScreen.update()
room.update() ★ 无条件
HAND_SELECT:
handCardSelectScreen.update()
room.update() ★ 无条件
COMBAT_REWARD:
combatRewardScreen.update() ★ 不调用 room.update()
SHOP:
shopScreen.update() ★ 不调用 room.update()
MAP:
dungeonMapScreen.update() ★ 不调用 room.update()
其他 screen (SETTINGS, INPUT_SETTINGS, MASTER_DECK_VIEW,
GAME_DECK_VIEW, DISCARD_VIEW, EXHAUST_VIEW,
DEATH, VICTORY, UNLOCK, DOOR_UNLOCK, CREDITS, NEOW_UNLOCK):
只调用对应 screen.update() ★ 不调用 room.update()
9. ★ 效果处理
├── turnPhaseEffectActive = false
├── topLevelEffects 逐个 update(),移除 isDone 的
├── effectList 逐个 update(),检查 PlayerTurnEffect
├── effectsQueue → 排入 effectList
└── topLevelEffectsQueue → 排入 topLevelEffects
10. overlayMenu.update() ★★★ 总是最后
├── energyPanel.update()
├── player.hand.update()
├── combatDeckPanel.updatePositions()
├── discardPilePanel.updatePositions()
├── exhaustPanel.updatePositions()
├── endTurnButton.update()
├── proceedButton.update()
├── cancelButton.update()
├── updateBlackScreen()
├── relic/blight update
└── relicQueue 处理2.3 各 Screen 对房间更新的影响
| Screen | room.update() 调用? | 条件 |
|---|---|---|
| NONE (NORMAL/CAMPFIRE) | ✅ 是 | 无条件 |
| EVENT | ✅ 是 | 无条件 |
| GRID | ✅ 是 | 仅 PeekButton.isPeeking 时 |
| CARD_REWARD | ✅ 是 | 仅 PeekButton.isPeeking 时 |
| BOSS_REWARD | ✅ 是 | 无条件 |
| HAND_SELECT | ✅ 是 | 无条件 |
| COMBAT_REWARD | ❌ 否 | — |
| SHOP | ❌ 否 | — |
| MAP | ❌ 否 | — |
| 其他所有 Screen | ❌ 否 | — |
3. RoomPhase 机制
3.1 RoomPhase 枚举
public enum RoomPhase { COMBAT, EVENT, COMPLETE, INCOMPLETE; }
// 序号: 0, 1, 2, 33.2 Phase 初始化
AbstractRoom 构造函数不初始化 phase。 但所有子类构造函数都初始化 phase(通过字节码验证,JD-Core 反编译工具未能正确反编译子类构造函数):
| 房间类型 | 构造函数设 phase |
|---|---|
| MonsterRoom | RoomPhase.COMBAT |
| MonsterRoomElite | RoomPhase.COMBAT(继承 MonsterRoom) |
| MonsterRoomBoss | RoomPhase.COMBAT(继承 MonsterRoom) |
| EventRoom | RoomPhase.EVENT |
| RestRoom | RoomPhase.INCOMPLETE |
| ShopRoom | RoomPhase.COMPLETE |
| TreasureRoom | RoomPhase.COMPLETE |
| TreasureRoomBoss | RoomPhase.COMPLETE(条件变为 INCOMPLETE) |
| VictoryRoom | RoomPhase.EVENT |
| TrueVictoryRoom | RoomPhase.INCOMPLETE |
| NeowRoom | RoomPhase.EVENT |
没有房间以 null phase 启动。
3.3 Phase 设为 COMBAT 的地方
| 位置 | 文件:行号 | 条件 |
|---|---|---|
| 构造函数 | MonsterRoom 等 | 创建时 |
AbstractEvent.enterCombat() | AbstractEvent:93 | 事件转为战斗 |
AbstractEvent.postCombatLoad() | AbstractEvent:183 | 存档加载战斗事件 |
AbstractImageEvent.enterCombatFromImage() | AbstractImageEvent:70 | 图片事件转为战斗 |
3.4 Phase 转换流程
INCOMPLETE → (房间初始化) → COMBAT 或 EVENT
COMBAT → endBattle() → endBattleTimer 倒计时 → phase = COMPLETE
EVENT → event.waitTimer==0 && !event.hasFocus → phase = COMPLETE(EventRoom.update())
COMPLETE → proceedButton 点击 → 下一个房间4. AbstractDungeon 完全字段与方法
4.1 CurrentScreen 枚举(所有可能的 24 个 overlay)
public enum CurrentScreen {
NONE, MASTER_DECK_VIEW, SETTINGS, INPUT_SETTINGS, GRID, MAP, FTUE,
CHOOSE_ONE, HAND_SELECT, SHOP, COMBAT_REWARD, DISCARD_VIEW, EXHAUST_VIEW,
GAME_DECK_VIEW, BOSS_REWARD, DEATH, CARD_REWARD, TRANSFORM, VICTORY,
UNLOCK, DOOR_UNLOCK, CREDITS, NO_INTERACT, NEOW_UNLOCK;
}4.2 关键静态字段(分类)
玩家与地图
| 字段 | 类型 | 说明 |
|---|---|---|
player | AbstractPlayer | 玩家角色 |
currMapNode | MapRoomNode | 当前房间节点 |
nextRoom | MapRoomNode | 正在切换到的节点 |
map | ArrayList<ArrayList<MapRoomNode>> | 15 行×7 列地图 |
bossKey | String | 当前幕 Boss ID |
Room 状态
| 字段 | 类型 | 说明 |
|---|---|---|
screen | CurrentScreen | 当前活跃 overlay |
isScreenUp | boolean | 是否有 overlay 显示 |
isDungeonBeaten | boolean | 当前幕是否完成 |
isFadingIn/Out | boolean | 淡入淡出中 |
floorNum | int | 当前层数(1-based) |
actNum | int | 当前幕数 |
遭遇池(FIFO 从前端消费)
| 字段 | 消费方式 |
|---|---|
monsterList | remove(0) |
eliteMonsterList | remove(0) |
bossList | remove(0) |
eventList | remove(tmpKey) |
shrineList | remove(tmpKey) |
RNG(全部从 Settings.seed 种子化)
| RNG | 用途 | 重种子时机 |
|---|---|---|
monsterRng | 遭遇选择 | 每幕 |
mapRng | 地图生成 | 每幕 |
eventRng | 事件类型+事件选择 | 每幕 |
merchantRng | 商店物品 | 每幕 |
cardRng | 卡牌奖励稀有度 | 每幕 |
treasureRng | 宝箱掉落 | 每幕 |
relicRng | 遗物掉落 | 每幕 |
potionRng | 药水掉落 | 每幕 |
monsterHpRng | 怪物 HP | 每层 |
aiRng | AI 技能选择 | 每层 |
shuffleRng | 洗牌 | 每层 |
cardRandomRng | 随机卡牌效果 | 每层 |
miscRng | 杂项随机 | 每层 |
Screen 实例(每个创建一次,反复复用)
| 字段 | 类型 |
|---|---|
gridSelectScreen | GridCardSelectScreen |
handCardSelectScreen | HandCardSelectScreen |
cardRewardScreen | CardRewardScreen |
combatRewardScreen | CombatRewardScreen |
bossRelicScreen | BossRelicSelectScreen |
shopScreen | ShopScreen |
dungeonMapScreen | DungeonMapScreen |
效果/行动队列
| 字段 | 类型 |
|---|---|
actionManager | GameActionManager |
effectList | ArrayList<AbstractGameEffect> |
topLevelEffects | ArrayList<AbstractGameEffect> |
effectsQueue | ArrayList<AbstractGameEffect> |
topLevelEffectsQueue | ArrayList<AbstractGameEffect> |
4.3 关键方法
closeCurrentScreen() (line 2857-2976)
关闭当前活跃 screen 的完整逻辑:
PeekButton.isPeeking = false- 根据 screen 类型做特定重置
- 关键:
genericScreenOverlayReset():代码 if (previousScreen == null): if (player.isDead): previousScreen = DEATH else: isScreenUp = false, overlayMenu.hideBlackScreen() if (room.phase == COMBAT && !player.isDead): overlayMenu.showCombatPanels() ★ 恢复抽牌/弃牌/消耗/结束回合按钮 - 如果
previousScreen非 null,恢复上一个 screen
nextRoomTransition() (line 2118-2308)
房间切换的完整流程:
- 从
monsterList/eliteMonsterListremove(0)消费怪物 floorNum++- 重种子化楼层级 RNG(monsterHpRng, aiRng, shuffleRng, cardRandomRng, miscRng)
relic.onEnterRoom()触发所有遗物- 如果是 EventRoom:
EventHelper.roll()决定事件解析为哪种房间(可变为战斗) currMapNode = nextRoomrelic.justEnteredRoom()getCurrRoom().onPlayerEntry()← 触发房间特定逻辑
4.4 怪物池填充(populateMonsterList)
generateWeakEnemies(N) + generateStrongEnemies(M) → 同一个 monsterList
├── weak enemies: populateMonsterList(monsters, N, false)
├── populateFirstStrongEnemy(monsters, generateExclusions()) ← 1 个 strong,避同主题
└── 剩余 strong: populateMonsterList(monsters, M, false)
规则:
- 相邻不可重复
- 不三连(A-B-A)
- 精英相同规则5. 房间系统
5.1 AbstractRoom.update() 完整流程
AbstractRoom.update():
1. ESC → 打开 SettingsScreen(如果没有 overlay、esc 被按下)
2. Debug 模式作弊(药水、充能球、金币)
3. switch(phase):
=== RoomPhase.EVENT ===
this.event.updateDialog() // 对话框动画前进
=== RoomPhase.COMBAT ===
A) this.monsters.update() ★ 怪物每帧更新(包括死亡动画计时器)
B) if (waitTimer > 0):
如果有待处理 action: actionManager.update()
否则: waitTimer -= deltaTime
if (waitTimer <= 0): ★ 战斗开始触发
actionManager.turnHasEnded = true
添加 BattleStartEffect + GainEnergyAndEnableControlsAction
player.applyStartOfCombatPreDrawLogic()
添加 DrawCardAction(handSize) + EnableEndTurnButtonAction
overlayMenu.showCombatPanels()
player.applyStartOfCombatLogic()
player.applyStartOfTurnRelics/PostDrawRelics/Cards/Powers/Orbs
actionManager.useNextCombatActions()
else (waitTimer <= 0): ★ 正常战斗循环
if (!isScreenUp):
actionManager.update() ← 处理行动队列
if (怪物未全死 && 玩家存活):
player.updateInput() ← 卡牌拖拽/目标选择
if (screen != HAND_SELECT):
player.combatUpdate() ← 卡牌inUse/limbo/消耗堆/充能球/姿态
if (player.isEndingTurn):
endTurn()
C) if (isBattleOver && actions.isEmpty()): ★ 战斗结束
endBattleTimer -= deltaTime
if (endBattleTimer < 0):
phase = COMPLETE
发放金币奖励
调用 dropReward() + addPotionToRewards()
if (rewardAllowed): combatRewardScreen.open() ★ 打开奖励屏幕
POST_COMBAT 存档
D) this.monsters.updateAnimations()
E) player.update() ← 生命条/充能球动画/逃跑动画
F) player.updateAnimations()
=== RoomPhase.COMPLETE ===
if (!isScreenUp):
actionManager.update()
if (event != null): event.updateDialog()
if (动作队列空 && 不是淡出中):
rewardPopOutTimer -= deltaTime
if (rewardPopOutTimer < 0):
显示 proceedButton5.2 各房间类关键方法
EventRoom
// onPlayerEntry():
this.event = AbstractDungeon.generateEvent(eventRngDuplicate);
this.event.onEnterRoom();
// update():
super.update();
if (!AbstractDungeon.isScreenUp): this.event.update();
if (event.waitTimer == 0 && !event.hasFocus && phase != COMBAT):
phase = COMPLETE;
event.reopen();Phase COMPLETE 的条件:
event.waitTimer == 0.0F— 事件延迟结束!event.hasFocus— 事件不再等待用户选择phase != COMBAT— 不在战斗中
MonsterRoom
// onPlayerEntry():
if (monsters == null):
monsters = CardCrawlGame.dungeon.getMonsterForRoomCreation();
monsters.init();
waitTimer = 0.1F;
// phase 在此方法中未显式设为 COMBAT(需外部代码)RestRoom
campfireUI.initializeButtons()创建RestOption+SmithOption+ 遗物选项 +RecallOptiono.useOption()是实际触发- 使用后:
campfireUI.somethingSelected = true→hidden = true - 效果完成后:
room.phase = COMPLETE
ShopRoom
- 构造函数设
phase = COMPLETE ShopScreen.init()填充卡牌/遗物/药水- 删除卡牌使用
gridSelectScreen
5.3 房间切换时的消费
nextRoomTransition():
MonsterRoomElite: eliteMonsterList.remove(0) + 可能 re-fill
MonsterRoom: monsterList.remove(0) + 可能 re-fill
如果列表空了:
精英: generateElites(10) 填充
普通: generateStrongEnemies(12) 填充6. 战斗系统
6.1 战斗开始序列 (player.preBattlePrep())
1. actionManager.clear() — 重置 turn=1, phase=WAITING_ON_USER, 清空队列
2. 清空 per-combat 计数器
3. 充能球重置为 masterMaxOrbs
4. drawPile.initializeDeck(masterDeck) ★ 洗牌 + 先天/瓶装牌进手牌
5. hand/discardPile/exhaustPile.clear()
6. energy.prep()
7. powers.clear()
8. monsters.usePreBattleAction()
9. addToBottom(WaitAction(1.0F))
10. applyPreCombatLogic() — relic.atPreBattle()6.2 drawPile.initializeDeck() 先天牌处理
1. 清空 drawPile
2. 创建 masterDeck 的洗牌副本
3. 分离先天/瓶装牌 → 放入手牌
4. 非先天牌 → drawPile(洗牌顺序)
5. 如果先天牌数量 > 手牌上限:
→ preTurnActions.add(DrawCardAction(先天 - 手牌上限))
战斗开始后自动补抽6.3 GameActionManager — 行动优先级队列
public enum Phase { WAITING_ON_USER, EXECUTING_ACTIONS; }update() 流程
if (phase == WAITING_ON_USER): getNextAction(); return
if (phase == EXECUTING_ACTIONS):
if (currentAction != null && !currentAction.isDone):
currentAction.update() ← 执行当前动作
else:
getNextAction()
if (currentAction == null && phase == COMBAT && !usingCard):
phase = WAITING_ON_USER ★ 回到等待用户输入
hasControl = falsegetNextAction() — 优先级
优先级 1: actions 队列 → pop first
优先级 2: preTurnActions 队列 → pop first
优先级 3: cardQueue → 打出排队的卡牌
优先级 4: !monsterAttacksQueued → monsterAttacksQueued=true, queueMonsters()
优先级 5: monsterQueue → 逐个怪物 takeTurn()
优先级 6: turnHasEnded && 怪物未全死 → 新回合开始6.4 回合流程
玩家回合:
1. phase = WAITING_ON_USER (等待打牌)
2. 玩家打牌 → 加入 cardQueue
3. 玩家 endTurn() → turnHasEnded = true
4. getNextAction() 处理剩余 cardQueue
5. monsterAttacksQueued = false → 触发 queueMonsters()
怪物回合:
6. 怪物逐个 takeTurn()
7. monsterQueue 空 → WaitAction(1.5F)
新回合:
8. turnHasEnded && 怪物未死:
- applyEndOfTurnPowers()
- turn++
- 失去格挡 (除非 Barricade/Blur/Calipers)
- 添加 DrawCardAction(handSize)
- 添加 EnableEndTurnButtonAction
- phase → WAITING_ON_USER6.5 AbstractMonster 死亡流程
// die() 方法:
this.isDying = true; ★ 设一次,永不清除
this.deathTimer = 1.8F; // 或其他值
// updateDeathAnimation() (每帧调用):
deathTimer -= Gdx.graphics.getDeltaTime();
if (deathTimer < 1.8F && !tintFadeOutCalled):
tint.fadeOut(); // 淡出效果
if (deathTimer < 0.0F):
this.isDead = true; ★ 标记已死亡
if (所有怪物 dead): endBattle()
dispose()
// 关键字段:
isDying = true ← 永不变回 false
isDead = true ← deathTimer < 0 时设置
areMonstersDead() → 检查 m.isDead || m.escaped
areMonstersBasicallyDead() → 检查 m.isDying || m.isEscaping重要:isDying 永远不会被设回 false。 检查怪物死亡动画时必须使用 m.isDying && !m.isDead。
6.6 AbstractPlayer — 关键状态
| 字段 | 说明 |
|---|---|
masterDeck (MASTER_DECK) | 永久牌组 |
drawPile (DRAW_PILE) | 抽牌堆 |
hand (HAND) | 手牌(上限 10) |
discardPile (DISCARD_PILE) | 弃牌堆 |
exhaustPile (EXHAUST_PILE) | 消耗堆 |
limbo (UNSPECIFIED) | 过渡中的卡牌 |
currentHealth/maxHealth | 生命值 |
currentBlock | 格挡值 |
relics | 遗物列表 |
potions | 药水列表(含 PotionSlot) |
potionSlots | 药水槽数(3,A11+ 时 -1) |
powers | 能力列表 |
energy (EnergyManager) | 能量 |
7. 事件系统
7.1 事件类型
public enum EventType { TEXT, IMAGE, ROOM; }- ROOM: 使用
RoomEventDialog(waitForInput,selectedOption,optionList) - IMAGE: 使用
GenericEventDialog(同上字段名,但非 static)
7.2 GenericEventDialog 关键字段
public static boolean waitForInput; // 等待玩家点击
public static int selectedOption = -1; // 选中的选项
public ArrayList<LargeDialogOptionButton> optionList; // 选项按钮列表
// 流程:
setDialogOption(text) → 创建按钮 → waitForInput = true
玩家点击 → selectedOption = index, waitForInput = false
getSelectedOption() → 返回 index, 重置 waitForInput = true7.3 AbstractImageEvent.update()
public void update() {
if (!this.combatTime) {
this.hasFocus = true;
// 随机粒子效果
if (this.waitTimer > 0.0F) {
this.waitTimer -= delta;
if (this.waitTimer < 0.0F) {
imageEventText.show(title, body);
this.waitTimer = 0.0F;
}
}
if (!GenericEventDialog.waitForInput) {
buttonEffect(GenericEventDialog.getSelectedOption());
}
}
}7.4 事件选择规则
shrineChance(默认 25%)→ shrine 或普通事件- Shrine: 从
shrineList随机,根据条件过滤(act, gold, 生命, 遗物),消费(remove from list) - 普通事件: 从
eventList随机,同样过滤和消费 - 如果一方列表为空,退回到另一方
7.5 事件消耗规则
- 事件/shrine 不会在同幕重复出现
eventList.remove(tmpKey)/shrineList.remove(tmpKey)消费- 第 7 层前不会刷出 act 2/3 的事件
- 有特定条件的事件(如需要特定遗物/金币)会被过滤
8. Screen 系统
8.1 Screen 生命周期
打开: screen = XXX, isScreenUp = true, previousScreen = 旧值
关闭: closeCurrentScreen()
→ genericScreenOverlayReset()
→ 如果 previousScreen 为 null: isScreenUp = false
→ 如果 COMBAT 且玩家活着: overlayMenu.showCombatPanels()
→ 如果 previousScreen 非 null: 恢复它8.2 CardRewardScreen — 三种模式
JAR 实际字段名:
| 字段 | 类型 | 可见性 | 说明 |
|---|---|---|---|
rewardGroup | ArrayList<AbstractCard> | public | 要选择的卡牌列表 |
discoveryCard | AbstractCard | public | 发现模式下选中的卡 |
discovery | boolean | private | 发现模式标记 |
chooseOne | boolean | private | 择一模式标记 |
skippable | boolean | private | 是否可跳过 |
rItem | RewardItem | public | 关联的奖励项 |
注意:JAR 中没有 discoveryCards、discoveryText、discoverySkipable 字段。 当前 main stub 的字段名需要修正以匹配 JAR。
| 模式 | 方法 | discovery | chooseOne | 卡牌去向 |
|---|---|---|---|---|
| 常规奖励 | open(cards, rItem, header) | false | false | deck(acquireCard() → FastCardObtainEffect → masterDeck) |
| 发现 | customCombatOpen(choices, text, skippable) | true | false | hand(discoveryCard → DiscoveryAction → ShowCardAndAddToHandEffect) |
| 择一 | chooseOneOpen(choices) | false | true | hand(onChoseThisOption()) |
customCombatOpen() 设置:discovery=true, chooseOne=false, discoveryCard=null, skippable=param
8.3 CombatRewardScreen — 奖励领取
// setupItemReward():
rewards = new ArrayList<>(room.rewards)
创建卡牌奖励(3 张随机卡)
// rewardViewUpdate():
每个 RewardItem r:
if (r.isDone): r.claimReward()
如果 POTION 且无法获得(槽满): 重置 isDone = false
// 全部领取完后: proceed 按钮出现,点击 → closeCurrentScreen() → 地图8.4 BossRelicSelectScreen — 遗物选择
open(): 显示 3 个 Boss 遗物- 点击:
r.bossObtainLogic()或r.obtain()→relicObtainLogic(r) relicObtainLogic(): 记录 metrics,设isDone = trueisDone触发closeCurrentScreen()+ 房间 phase = COMPLETEskip(): 不选遗物(调用 cancelButton → relicSkipLogic())
9. 选牌系统
9.1 HandCardSelectScreen — 从手牌选
卡牌物理移动: 选中 → hand.removeCard(c) → selectedCards.addToTop(c),取消 → 反向
关键字段:
| 字段 | 说明 |
|---|---|
numCardsToSelect | 要选几张 |
selectedCards (CardGroup) | 已选卡牌(从手牌移入) |
canPickZero | 可不选确认 |
upTo | 最多选 numCardsToSelect 张 |
wereCardsRetrieved | 行动已消费选择 |
selectionReason | 选择原因文本 |
open() 重载:
open(msg, amount, anyNumber, canPickZero, forTransform, forUpgrade, upTo) // 规范
open(msg, amount, anyNumber, canPickZero, forTransform, forUpgrade)
open(msg, amount, anyNumber, canPickZero, forTransform)
open(msg, amount, anyNumber, canPickZero)
open(msg, amount, anyNumber) // 调 4 参数版,canPickZero=false9.2 GridCardSelectScreen — 从牌堆选
卡牌留在原堆: 选中添加到 selectedCards(ArrayList),不移动
关键字段:
| 字段 | 说明 |
|---|---|
targetGroup | 要从中选的 CardGroup(如 masterDeck) |
selectedCards (ArrayList) | 已选卡牌引用 |
forUpgrade | 为了升级 |
forTransform | 为了变化 |
forPurge | 为了删除 |
isJustForConfirming | 仅确认模式(Pandora’s Box 等) |
confirmScreenUp | 确认子屏幕激活 |
anyNumber | 可选任意张 |
open() 重载:
open(group, numCards, anyNumber, msg)
open(group, numCards, tipMsg, forUpgrade, forTransform, canCancel, forPurge)
open(group, numCards, tipMsg, forUpgrade, forRitual)
open(group, numCards, tipMsg, forUpgrade)
openConfirmationGrid(group, tipMsg)9.3 GridCardSelectScreen.update() 完整流程
// 一帧内:
1. updateControllerInput()
2. updatePeekButton()
3. if (PeekButton.isPeeking): return // 正在偷看 → 跳过选择
4. 滚动条更新
5. confirmButton.update()
6. ★ isJustForConfirming 分支:
updateCardPositionsAndHoverLogic()
if (confirmButton clicked):
对所有 targetGroup 卡牌 → FastCardObtainEffect
closeCurrentScreen()
return
7. ★ anyNumber 或 forClarity + confirm 点击:
closeCurrentScreen()
return
8. ★ 正常选择(非 confirmScreenUp):
updateCardPositionsAndHoverLogic()
if (hoveredCard && clicked):
如果未选中:
加入 selectedCards, cardSelectAmount++
如果 numCards == cardSelectAmount:
- forUpgrade: confirmScreenUp = true
- forTransform: confirmScreenUp = true
- forPurge(numCards==1): confirmScreenUp = true
- forPurge(numCards>1): closeCurrentScreen() ← 多张删除直接关闭
- 其他: closeCurrentScreen() ← 自动关闭
如果已选中:
取消选中, cardSelectAmount--
9. ★ confirmScreenUp 分支:
显示升级/变化预览
if (confirmButton clicked):
selectedCards.add(hoveredCard)
closeCurrentScreen()10. 营地与商店
10.1 CampfireUI — 营地
initializeButtons():
1. RestOption() + SmithOption()(如果有可升级卡)
2. 每个遗物: r.addCampfireOption(buttons)
3. RecallOption()(最终幕可用且无红钥匙)
4. 如果没有任何选项可用: room.phase = COMPLETE
update():
每个 o.update()
if (somethingSelected): hideStuffTimer-- → hidden = true关键副作用: Smith/Toke 效果依赖 CampfireUI.hidden = true。使用选项后必须设 hidden = true。
10.2 ShopScreen — 商店
init():
initCards() — 5 张有色牌(根据角色) + 2 张无色牌,价格 = 稀有度 + 随机,1 张打折 50%
initRelics() — 3 个遗物
initPotions() — 3 瓶药水
设置 purge 成本
purchaseCard(card):
检查金币 → 扣除 → FastCardObtainEffect → 记录 metrics
The Courier 遗物:替换购买的卡为新卡
purchasePurge():
打开 gridSelectScreen 选 1 张可删除卡
AbstractDungeon.previousScreen = SHOP11. 关键 GUI 组件分析
11.1 TopPanel — 药水使用流程
updatePotions():
每帧遍历玩家药水:
p.hb.update()
if (hovered && clicked): potionUi.open(slot, potion)
PotionPopUp.open():
显示两个按钮:USE / DISCARD
USE: 如果 potion.canUse():
- 无需目标: potion.use(null) + destroyPotion(slot)
- 需要目标: targetMode = true, 等待点击怪物
DISCARD: 如果 potion.canDiscard(): destroyPotion(slot)11.2 ProceedButton.update()
if (hb.clicked 或 CInputActionSet.proceed):
★ 根据房间和屏幕类型决定行为 ★
A) MonsterRoomBoss → Boss 过渡(双 Boss 或胜利房间)
B) screen == COMBAT_REWARD(非 TreasureRoomBoss):
- MonsterRoomBoss: goToTreasureRoom()
- EventRoom: closeCurrentScreen() + 打开地图
- 其他: closeCurrentScreen() + dungeonMapScreen.open(false)
C) TreasureRoomBoss: goToNextDungeon()
D) 其他: dungeonMapScreen.open(false)11.3 OverlayMenu.update() — 最后调用
energyPanel.update()
player.hand.update() ← 手牌位置/悬停检测
combatDeckPanel.updatePositions()
discardPilePanel.updatePositions()
exhaustPanel.updatePositions()
endTurnButton.update() ← 结束回合按钮
proceedButton.update() ← 继续按钮
cancelButton.update() ← 取消按钮
updateBlackScreen() ← 黑色遮罩淡入
for relics: r.update()
for blights: b.update()
relicQueue 处理11.4 updateFading() — 淡入淡出
淡入中: fadeTimer -= delta, fadeColor.a = fade.apply(0→1)
淡出中: fadeTimer -= delta, fadeColor.a = fade.apply(1→0)
if (淡出完成 && !isDungeonBeaten): nextRoomTransition() ★ 触发房间切换12. SoulGroup 机制
SoulGroup 不是纯视觉效果 — 它实际执行卡牌在不同堆之间的物理移动。
SoulGroup.discard(card): → 把 card 加入 discardPile + 创建飞行动画
SoulGroup.obtain(card): → 把 card 加入 masterDeck + 播放音效
SoulGroup.shuffle(card): → 把 card 加入 drawPile + 动画
SoulGroup.onToDeck(card): → 把 card 加入 drawPile(随机或顶部)+ 动画
SoulGroup.onToBottomOfDeck: → 把 card 加入 drawPile 底部 + 动画
SoulGroup.isActive(): → 是否有动画还在播放结论: 不能简单跳过 SoulGroup。至少需要复现其堆操作逻辑。isActive() 需要在 CLI 的 drain 循环中检查。
13. 重构计划
13.1 帧步进模型
GUI 版的 CardCrawlGame.render() → update() 是一个连续循环,每秒跑 ~60 帧。CLI 版的替代方案:
runFrames(N):
for i = 0 to N:
// 模拟一帧的 AbstractDungeon.update(),排除纯渲染部分
topPanel.update() // 保留(药水点击等逻辑)
updateFading() // 保留(淡入淡出 = 房间切换)
room.updateObjects() // 保留
room.update() // 保留(房间逻辑的核心)
✅ scene.update() // 删除(纯渲染)
✅ dungeonMapScreen.update() // 删除(地图 GUI)
✅ 效果处理 // 删除(纯视觉)
✅ overlayMenu.update() // 大部分可删除,仅保留核心逻辑
if (needInput): break // 需要玩家输入时停止13.2 各场景的 break 条件
| 场景 | 需要输入的条件 |
|---|---|
| 战斗 | actionManager.phase == WAITING_ON_USER AND actions.isEmpty() AND waitTimer <= 0 AND !anyDyingUnresolved AND !isScreenUp AND !SoulGroup.isActive() |
| 事件 | GenericEventDialog.waitForInput OR RoomEventDialog.waitForInput |
| 营地 | room.phase == EVENT AND campfire 选项可见 |
| 商店 | screen == SHOP |
| 地图 | room.phase == COMPLETE AND 奖励全部领取 |
| Grid/Hand select | isScreenUp AND screen 对应类型 |
| Card/Combat reward | isScreenUp AND screen 对应类型 |
| Boss relic | isScreenUp AND screen == BOSS_REWARD |
13.3 GUI 代码处理策略
| 类别 | 操作 |
|---|---|
渲染方法 render(SpriteBatch) | 清空方法体 |
纹理加载 ImageMaster.loadImage() | 设返回值 = null |
音效 SoundMaster.play() | 设为无操作或 null-safe |
视觉特效 effectList 中的所有 update() | 保留(有些 effect 有逻辑副作用,如 FastCardObtainEffect 添加卡牌到 deck) |
| SoulGroup | 保留 isActive() 检查 + 堆操作逻辑 |
输入处理 InputHelper, CInputActionSet | stub 为无操作 |
| Steam/平台集成 | 完全删除 |
| 主菜单/角色选择 | 跳过(CLI 通过代码选择角色) |
13.4 不该在 CLI 中重写的逻辑
- 不要手写行动处理 — 使用
actionManager.update() - 不要手写战斗逻辑 — 使用
room.update() - 不要手写事件解析 — 使用
event.update() - 不要手写卡牌效果 — 使用 JAR 中的 Action 类
- 不要手写 RNG — 使用 JAR 的种子的 RNG
13.5 效果处理 (processEffects)
GUI 版在 AbstractDungeon.update() 中处理三段效果队列。CLI 版需要等效处理:
static void processEffects() {
// topLevelEffects: 主要是 UI 效果,但也包含部分游戏逻辑
Iterator<AbstractGameEffect> it = AbstractDungeon.topLevelEffects.iterator();
while (it.hasNext()) {
AbstractGameEffect e = it.next();
e.update();
if (e.isDone) it.remove();
}
// effectList: 标准效果
it = AbstractDungeon.effectList.iterator();
while (it.hasNext()) {
AbstractGameEffect e = it.next();
e.update();
if (e.isDone) it.remove();
}
// 转移排队的效果
AbstractDungeon.effectList.addAll(AbstractDungeon.effectsQueue);
AbstractDungeon.effectsQueue.clear();
AbstractDungeon.topLevelEffects.addAll(AbstractDungeon.topLevelEffectsQueue);
AbstractDungeon.topLevelEffectsQueue.clear();
}13.6 Room Phase 的初始化问题
MonsterRoom/Elite/Boss 的 phase 设为 COMBAT 需要确认。如果 JAR 代码未显式设置,可能的机制:
onPlayerEntry()内部的actionManager初始化隐式设置- 外部代码(如 AbstractDungeon 或 GameActionManager)触发
- AbstractRoom 的反编译代码缺失了 phase 初始化
必须通过实测验证。 在 CLI 中,我们当前的处理是:进入战斗房间时,如果 monsters != null,设 phase = COMBAT。如果这不对,需要找到正确的设置点。
13.7 room.update() 被调用的条件
在 GUI 版中,room.update() 并非每帧都调用。需要满足以下条件之一:
screen == NONE(RenderScene NORMAL/CAMPFIRE)screen == EVENT(RenderScene EVENT)screen == BOSS_REWARDscreen == HAND_SELECTscreen == GRID && PeekButton.isPeekingscreen == CARD_REWARD && PeekButton.isPeeking
CLI 版必须完全匹配这个规则,避免在 screen 活跃时不当地调用 room.update()。
13.8 最简 CLI 主循环设计
void gameLoop() {
while (gameRunning) {
// ========== 房间进入 ==========
if (!roomEntered) {
room.onPlayerEntry();
roomEntered = true;
}
// ========== 跑帧直到需要输入 ==========
String scene = null;
while (scene == null) {
// 模拟 AbstractDungeon.update() 的一帧:
AbstractDungeon.topPanel.update();
AbstractDungeon.updateFading();
room.updateObjects();
// 根据 screen 决定是否调用 room.update()
if (shouldUpdateRoom()) {
room.update();
}
// 更新活跃 screen(如果有)
updateActiveScreen();
// 处理效果
processEffects();
// 处理 SoulGroup + 其他 OverlayMenu 逻辑
processOverlayLogic();
// 检查是否需要输入
scene = detectScene();
if (scene != null) break;
}
// ========== 序列化状态 / 获取输入 ==========
String json = serializeState(scene);
String action = getInput(json);
// ========== 应用输入 ==========
applyAction(scene, action);
// ========== 检查房间切换 ==========
if (room.phase == COMPLETE) {
AbstractDungeon.dungeonMapScreen.open(false);
roomEntered = false;
}
}
}14. 输入 → JAR 回调对照表(第二轮审查验证版)
每个场景的每个动作对应 JAR 中确定的代码路径。以下所有内容已经通过阅读 backup 原始代码验证。
战斗 "combat"
| 动作 | JAR 回调 | 验证细节(文件:行号) |
|---|---|---|
出牌 p {handIdx} [{targetIdx}] | AbstractDungeon.actionManager.cardQueue.add(new CardQueueItem(card, monster)) | AbstractPlayer.playCard() :1607/1609。仅加入 queue,不扣能量不从手牌移除。能量扣减(energy.use())和手牌移除(hand.removeCard())在后续 useCard() :1704/:1712 中由 action manager 处理 |
结束回合 end | EndTurnButton.disable(true) → 内部: actionManager.addToBottom(NewQueueCardAction) + endTurnQueued = true + releaseCard() | EndTurnButton.disable() :166-182。必须先加 NewQueueCardAction(:168),仅设 endTurnQueued 不够 |
喝药水 pot {idx} [{target}] | pot.use(target) + AbstractDungeon.topPanel.destroyPotion(idx) + 触发 r.onUsePotion() | PotionPopUp.updateInput() :283/:247 + :288/:256。无目标时 use(null);有目标时先设 targetMode=true(:290) → updateTargetMode() → use(hoveredMonster)(:247)。注意: 必须调用 canUse() 检查(:280),使用前记录 metric(:282) |
丢药水 dp {idx} | AbstractDungeon.topPanel.destroyPotion(idx) | PotionPopUp.updateInput() :318。同样需 canDiscard() 检查(:314) |
关于卡牌出牌的重要说明: playCard() 到 useCard() 之间的所有处理由 actionManager.update() → getNextAction() 自动完成,CLI 只需要把卡加入 cardQueue。能量扣减、手牌移除、卡牌效果执行全部由 JAR 处理。
事件 "event"
| 动作 | JAR 回调 | 验证细节 |
|---|---|---|
选选项 0 ~ N (IMAGE) | GenericEventDialog.selectedOption = i; GenericEventDialog.waitForInput = false; | GenericEventDialog.update() :95/:97。实际按钮检测还设 button.pressed = false(:96)。下一帧 AbstractImageEvent.update() :45-46 检测 !waitForInput → 调 buttonEffect(choice) |
选选项 0 ~ N (ROOM) | RoomEventDialog.selectedOption = i; RoomEventDialog.waitForInput = false; | RoomEventDialog.update() :67/:69。同样设 button.pressed = false(:68)。下一帧 AbstractEvent.update() :123-124 检测 → 调 buttonEffect(choice) |
重要: getSelectedOption() 内部会自动重置 waitForInput = true(:135/:85)。CLI 只需按上表设两个字段,下一帧 dungeon.update() → event.update() 自然触发 buttonEffect()。
Grid/Hand Select "grid_select"
HandCardSelectScreen (HAND_SELECT):
| 动作 | JAR 回调 | 验证细节 |
|---|---|---|
选手牌 idx(组合索引) | hand.removeCard(hoveredCard) + selectedCards.addToTop(hoveredCard) + hand.refreshHandLayout() | selectHoveredCard() :422-425, 另外调 setAngle(0.0F)(:424), refreshSelectedCards()(:426), updateMessage()(:428) |
反选 idx(idx < selected.size()) | selectedCards.remove(idx) + hand.addToTop(c) | 同上方法 Case B :430-440 |
| 完成(数量达标) | AbstractDungeon.closeCurrentScreen() | update() :109。如果 forTransform: 调用 AbstractDungeon.srcTransformCard()(:112) 或 transformCard()(:114) |
选零张 -1(canPickZero) | AbstractDungeon.closeCurrentScreen() | :97 |
注意: anyNumber/upTo 时用户直接按 -1 或选够牌后 closeCurrentScreen,不等按钮。
GridCardSelectScreen (GRID):
| 动作 | JAR 回调 | 验证细节 |
|---|---|---|
选牌 idx | this.selectedCards.add(this.hoveredCard) + this.cardSelectAmount++ — 直接字段访问,不需要反射 | update() :155/:160。另调 beginGlowing()(:156),播放 "CARD_SELECT" 音效(:161) |
| 反选 | selectedCards.remove(hoveredCard) + cardSelectAmount-- | :265-266 |
forUpgrade 达到数量 | 进入 confirmScreenUp = true(:164) — 不会自动 close,需要用户二次确认 | 创建 upgradePreviewCard(:167-175),然后等 confirmButton 点击 |
forTransform 达到数量 | 同上 confirmScreenUp = true(:180) | 同上模式 |
forPurge numCards==1 | confirmScreenUp = true(:195) | ~ |
forPurge numCards>1 | 直接 AbstractDungeon.closeCurrentScreen()(:213) | — |
!anyNumber 达到数量 | 直接 AbstractDungeon.closeCurrentScreen()(:221) | — |
anyNumber 确认 f | AbstractDungeon.closeCurrentScreen()(:242) | — |
isJustForConfirming | 遍历 targetGroup 每张卡加 FastCardObtainEffect → closeCurrentScreen() | :128-130 |
confirmScreenUp 确认(upgrade/transform/purge 二次确认):
- 设置
selectedCards.add(this.hoveredCard)(:297) - 调
AbstractDungeon.closeCurrentScreen()(:297)
战斗选牌 "combat_card_select" / Neow 选牌 "neow_card_reward"
| 模式 | 选牌回调 | 验证细节 |
|---|---|---|
| 常规奖励(rItem 非 null) | acquireCard(hoveredCard)(private) → recordMetrics() + FastCardObtainEffect + takeReward() | cardSelectUpdate() :286/:316-318/:351-360 |
| discovery(discovery=true) | 设 this.discoveryCard = hoveredCard(注意:字段名是 discoveryCard (单数),当前 stub 缺此字段) | :281 |
| chooseOne(chooseOne=true) | card.onChoseThisOption() + ExhaustCardEffect | :283-284 |
跳过 leave | —(closeCurrentScreen()) | :292 |
注意: 当前 CLI CardRewardScreen stub 缺少 discoveryCard、discovery、chooseOne、skippable 字段。需要补全。
战斗奖励 "combat_reward"
| 动作 | JAR 回调 | 验证细节 |
|---|---|---|
| 领取任意奖励 | 设 r.isDone = true | RewardItem.update() :270。下一帧 rewardViewUpdate() :140 → r.claimReward() |
claimReward() GOLD | player.gainGold(goldAmt) + 返回 true | :292-298 |
claimReward() POTION | player.obtainPotion(potion) → 成功返回 true,失败返回 false | :312 |
claimReward() RELIC | relic.instantObtain() → 返回 true | :333 |
claimReward() CARD | 开 cardRewardScreen.open() → 返回 false | :352-356 |
药水领取失败时: isDone 被重置为 false(rewardViewUpdate() :146),顶部栏闪红,提示”药水槽满”。
Boss 遗物 "boss_relic"
| 动作 | JAR 回调 | 验证细节 |
|---|---|---|
选遗物 0 ~ N | 点击通过 AbstractRelic.update() :409 → relic.bossObtainLogic() → 内部调 obtain()(:442) + 设 isObtained = true(:444) → BossRelicSelectScreen.update() :111 检测 → relicObtainLogic(r)(:112) → 设 isDone = true(:246) → 屏幕关闭 | 关键链:4 步调用 |
跳过 leave | brs.skip() → relicSkipLogic() → closeCurrentScreen() | :264 |
注意: bossObtainLogic() 调用 obtain() 添加遗物到玩家列表,但不调 onEquip()。onEquip() 在 AbstractRelic.update() :388-389 检测动画完成后调用。特殊遗物(BlackBlood等)跳过 obtain(),由 relicObtainLogic() 调 instantObtain()。
商店 "shop"
| 动作 | JAR 回调 | 访问性 | 验证细节 |
|---|---|---|---|
买卡 bc {n} | ShopScreen.purchaseCard(card) | private | FastCardObtainEffect(:693) + loseGold(price)(:695) + sound。(Courier 遗物自动替换卡) |
买遗物 br {n} | StoreRelic.purchaseRelic() | public | loseGold(:97) + relic.instantObtain()(:101) (调 onEquip) |
买药水 bp {n} | StorePotion.purchasePotion() | public | obtainPotion(:93) + loseGold(:94)。Sozu 遗物阻止购买(:87-90) |
删牌 rm {n} | ShopScreen.purchasePurge() | private | 开 gridSelectScreen(:1203),选完后由 CampfireTokeEffect 或 ShopRoom.updatePurge() 调用 masterDeck.removeCard() |
离开 leave | — | — | 设 shopActive = false,CLI 自维护 |
营地 "rest"
| 动作 | JAR 回调 | 验证细节 |
|---|---|---|
选选项 0 ~ N | o.useOption() + campfireUI.somethingSelected = true | AbstractCampfireOption.update() :61-63。useOption() 仅添加效果(CampfireSleepEffect/SmithEffect 等)到 effectList,实际游戏逻辑在效果 update() 中执行 |
| 等待效果完成 | CampfireUI.hidden = true | CampfireUI.update() :148-153 在 hideStuffTimer 倒计时结束后自动设置 |
| 休息效果 | CampfireSleepEffect.update() :82 → player.heal(amount) | 治疗发生在效果动画中间帧 |
| 锻造效果 | CampfireSmithEffect.update() :57 → c.upgrade() | 升级发生在 gridSelectScreen 关闭后 |
离开 leave | room.phase = COMPLETE → dungeonMapScreen.open(false) | — |
地图 "map"
| Phase | 动作 | 验证细节 |
|---|---|---|
| Phase 1 — 点击检测 | 在 MapRoomNode.update() :284 中检测 hb.hovered && screen==MAP && clicked && animWaitTimer<=0 → 设 clicked=false(:288), clickTimer=0(:289), animWaitTimer=0.25F(:310) | 普通节点和首节点(:343)几乎相同 |
| Phase 2 — Timer 到期 | animWaitTimer < 0 时 | |
— !firstRoomChosen: AbstractDungeon.setCurrMapNode(this)(:223) | ||
— 否则: currMapNode.taken = true(:225), connectedEdge.markAsTaken()(:229) | ||
— nextRoom = this(:234), nextRoomTransitionStart()(:240), fadeOutTempBGM()(:241) | ||
| Phase 3 — 渐黑 | dungeon.update() → updateFading() 倒计时 | JAR 自动处理 |
| Phase 4 — 房间切换 | fadeOut 完成 → nextRoomTransition() → onPlayerEntry() | JAR 自动处理 |
CLI 等价回调(跳过 0.25F 视觉 timer,跳过 MapCircleEffect/FadeWipeParticle 视觉特效):
node.hb.hovered = true;
AbstractDungeon.dungeonMapScreen.clicked = true;
// 然后让 dungeon.update() 跑帧处理 Phase 2-4
// 或直接同步执行 Phase 2:
if (!AbstractDungeon.firstRoomChosen) {
AbstractDungeon.setCurrMapNode(node);
} else {
AbstractDungeon.getCurrMapNode().taken = true;
MapEdge edge = AbstractDungeon.getCurrMapNode().getEdgeConnectedTo(node);
if (edge != null) edge.markAsTaken();
}
AbstractDungeon.nextRoom = node;
AbstractDungeon.pathX.add(node.x); AbstractDungeon.pathY.add(node.y);
CardCrawlGame.metricData.path_taken.add(node.getRoom().getMapSymbol());
if (!AbstractDungeon.isDungeonBeaten) {
AbstractDungeon.nextRoomTransitionStart();
CardCrawlGame.music.fadeOutTempBGM();
}15. CLI 主循环伪代码
void gameLoop() {
while (gameRunning && !player.isDead) {
// ===== 房间进入 =====
if (!roomEntered) {
room.onPlayerEntry();
roomEntered = true;
}
// ===== 跑帧直到需要输入 =====
String scene = null;
while (scene == null) {
dungeon.update(); // ★ 一帧:JAR 处理一切
// 只读检查是否需要停止
scene = detectScene();
}
// ===== 序列化状态 + 获取输入 =====
String json = serializeState(scene);
String action = getInput(json); // pipe 模式读管道,普通模式读 stdin
// ===== 执行 JAR 回调 =====
applyJarCallback(scene, action); // 按上表直接调 JAR 方法
// ===== 检查房间切换 =====
if (room.phase == COMPLETE) {
// 等效于 ProceedButton 点击逻辑:开地图选下一个房间
AbstractDungeon.dungeonMapScreen.open(false);
// 地图节点选择后 → nextRoomTransitionStart() → 淡出 → nextRoomTransition()
roomEntered = false;
}
}
}重要: CLI 直接调用 AbstractDungeon.update()(即 dungeon.update()),不经过 CardCrawlGame.update()。需要跳过 CardCrawlGame.render() 的渲染部分,只保留 update 逻辑。游戏模式(mode)需要提前设为 GAMEPLAY,角色通过代码创建,跳过主菜单。
detectScene() — 只读检查(已验证)
dungeon.update() 后检查:
0. 房间是 null → "map"(游戏结束前)
1. isScreenUp:
screen == GRID || HAND_SELECT → "grid_select"
screen == BOSS_REWARD → "boss_relic"
screen == CARD_REWARD:
room.phase == COMBAT → "combat_card_select"
否则 → "neow_card_reward"
screen == COMBAT_REWARD → "combat_reward"
screen == SHOP && shopActive → "shop"
screen == DEATH / VICTORY → "game_over"
2. room instanceof RestRoom && campfireUI != null && somethingSelected
→ "rest"(营地完成后的 leave 确认)
3. room.phase == COMPLETE || room.isBattleOver
→ "map"
4. room.phase == COMBAT && !room.isBattleOver:
actionManager.phase == WAITING_ON_USER
&& actionManager.actions.isEmpty()
&& waitTimer <= 0.0F
&& !SoulGroup.isActive()
&& !isScreenUp
→ "combat"
(注意:包含 m.isDying && !m.isDead 的 anyDying 守卫,
上限 30 轮后强制 break 避免卡死)
5. room.phase == EVENT:
GenericEventDialog.waitForInput || RoomEventDialog.waitForInput
→ "event"
6. room instanceof ShopRoom && shopActive → "shop"
7. room instanceof RestRoom → "rest"
8. 否则 → null (继续跑帧)关于 anyDying 守卫: 怪物死后 isDying 从不清除(只在 die() 中设为 true,永不变回 false)。必须用 m.isDying && !m.isDead 判断。isDead 在 deathTimer < 0 时设置(AbstractMonster.java line 1162)。守卫上限 30 轮防止卡死。
关于 SoulGroup.isActive(): 保留。卡牌飞行动画期间仍有堆操作在进行,需要等待完成。
applyJarCallback(scene, action) — 按上表调 JAR 方法
每个场景的动作解析 + 回调调用,不模拟 GUI 输入链,直接触发 JAR 方法参数。
16. 调试与作弊功能设计
这些功能用于验证 CLI 实现的正确性、快速测试特定场景、以及在开发过程中跳过不关心的部分。
16.1 设计原则
- 只通过 JAR 公有 API + 反射修改状态,不绕过游戏逻辑
- 修改后状态必须内部一致(不违反不变量)
- 所有修改通过
globalCommand入口(q前缀或其他),pipe + 普通模式统一 - 危险操作需要确认提示(普通模式),pipe 模式直接执行
- SoulGroup 活跃时禁止修改战斗状态(避免并发问题)
- 修改后调用一次
processEffects()处理连锁效果
16.2 命令分类
| 前缀 | 类别 | 说明 |
|---|---|---|
:f | 强制(force) | 替换游戏内容为指定值 |
:s | 设置(set) | 修改玩家/游戏状态 |
:g | 获取(get) | 读取内部状态输出到终端 |
:rng | RNG | 操作随机数生成器 |
:n | 导航(navigate) | 跳过/跳转房间 |
16.3 命令详细设计
A) 强制当前房间为特定事件 :f event {eventId}
作用:替换 room.event 为指定事件,用于测试所有事件类型。
实现:
1. 检查 room instanceof EventRoom(必须)
2. 如果 room.event != null: room.event.dispose()(释放旧事件资源)
3. room.event = EventHelper.getEvent("{eventId}")
4. room.event.onEnterRoom()
5. processEffects()安全约束:
- 只能在 EventRoom 中执行
- 不能在战斗事件(phase==COMBAT)中执行
- 必须等当前事件完全结束后(!event.hasFocus && phase!=EVENT)
- 如果事件有 waitTimer,手动清零让其直接进入交互
风险:EventHelper.getEvent() 可能返回 null(无效 eventId),需要校验。
B) 强制当前战斗的怪物 :f monsters {key1,key2,...}
作用:替换房间怪物组为指定遭遇,用于测试特定战斗。
实现:
1. 检查 room instanceof MonsterRoom(必须)
2. 检查 phase != COMBAT 或 isBattleOver(安全,不在战斗中替换)
3. 如果 room.monsters != null: 调用 dispose()
4. room.monsters = MonsterHelper.getEncounter(key)(逐个添加)
5. room.monsters.init()
6. 如果是正在进入战斗前: 不改变 waitTimer安全约束:
- 不能在战斗进行中替换(会导致状态不一致)
- 必须在
onPlayerEntry()之前或isBattleOver之后 - 怪物 key 必须是合法的(MonsterHelper 能识别)
C) 添加/删除卡牌到牌组 :s deck add {cardId} / :s deck remove {masterDeckIndex}
添加:
1. AbstractCard c = CardLibrary.getCopy(cardId)
2. c.upgrade() 如果指定升级版
3. player.masterDeck.addToTop(c)
4. 如果 in-combat: 不改变其他堆(卡只加入 masterDeck)
5. 记录到 metricData
删除:
1. player.masterDeck.removeCard(player.masterDeck.group.get(idx))
2. 不能删除最后的卡(防止空牌组)
3. 如果卡在 drawPile/hand/discardPile 中,同步删除安全约束:
- 不能删除起始牌组的最后一张卡
- 不能添加诅咒到牌组为 0
- 战斗中添加卡牌只影响 masterDeck(下次战斗洗入)
D) 设置玩家状态 :s hp {amount} / :s gold {amount} / :s energy {amount}
:s hp {amount}:
player.currentHealth = Math.min(amount, player.maxHealth)
if (amount <= 0): player.isDead = true → DeathScreen(游戏结束处理)
:s max_hp {amount}:
player.maxHealth = amount
player.currentHealth = Math.min(player.currentHealth, amount)
:s gold {amount}:
player.gold = Math.max(0, amount)
:s energy {amount}: // 战斗中的能量
player.energy.energy = Math.max(0, amount)安全约束:
- HP 设为 0 会导致游戏结束(这是预期行为,测试死亡流程)
- 能量只能在 Combat phase 设置
- 修改 max_hp 后需更新 UI(topPanel 等)
E) 添加/移除遗物 :s relic add {relicId} / :s relic remove {relicId}
添加:
1. AbstractRelic r = RelicLibrary.getRelic(relicId).makeCopy()
2. r.instantObtain() 或 r.obtain() — 取决于是否需要动画
3. 如果是 onEquip 触发了 sub-screen: processEffects()
移除:
1. player.relics.removeIf(r.relicId == targetId)
2. 注意: boss 遗物不能随便移除(修改了 maxHP/energy 等)
3. 移除后不做反向补偿(保持简单,只用于调试)安全约束:
- 不能移除核心角色遗物(Burning Blood 等起始遗物)
- 使用
instantObtain()跳过动画效果 - 移除遗物时不撤销其效果(简单调试工具,不做完整效果追踪)
F) 添加/移除药水 :s potion add {potionId} / :s potion slot {idx} {potionId} / :s potion clear
添加:
1. AbstractPotion p = PotionHelper.getPotion(potionId).makeCopy()
2. player.obtainPotion(p) — 自动找空槽位
3. 如果槽位满: 不操作(不替换已有药水,避免意外覆盖)
指定槽位:
1. player.potions.set(idx, newPotion)
2. player.potions.get(idx).setAsObtained(idx)
清空:
1. 所有槽位设为 PotionSlot安全约束:
- 不能添加无效药水 ID
- 槽位索引不能超出 potionSlots
G) 强制商店内容 :f shop cards {cardId1,cardId2,...} / :f shop relics {relicId1,...} / :f shop potions {potionId1,...}
替换商店卡牌:
1. 检查 scene == "shop" 或 room instanceof ShopRoom(必须)
2. shopCards.clear()
3. 对每个 cardId: shopCards.add(CardLibrary.getCopy(cardId))
4. 修改 ShopScreen.coloredCards / colorlessCards 列表
5. 重新计算价格(按稀有度 + 随机 jitter)
替换商店遗物/药水:
类似 — 修改 ShopScreen 的对应列表安全约束:
- 必须在商店激活时使用
- 修改后需刷新商店 UI(call showShopUI)
- 价格计算使用 ShopScreen 的原有逻辑
H) 强制地图节点类型 :f node {col} {row} {roomType}
实现:
1. 找到 map.get(row).get(col) 对应的 MapRoomNode
2. 根据 roomType 创建新的房间实例:
"M" → MonsterRoom, "E" → MonsterRoomElite, "?" → EventRoom
"$" → ShopRoom, "R" → RestRoom, "T" → TreasureRoom
3. 调用 node.setRoom(newRoom)
4. 如果节点是 currMapNode: 需要小心处理(当前房间切换)
5. 注意: 只在未进入的节点上操作(!taken)安全约束:
- 不能修改已走过的节点(taken=true)
- 不能修改当前正在其中的节点
- 不能将 boss 行的 RestRoom 改掉
- 注意节点类型与地图规则的冲突(但作为调试工具允许违反规则)
I) RNG 操作 :rng show / :rng set {rngName} {counter}
:rng show:
输出所有 RNG 的当前 counter 值:
monsterRng=X, eventRng=Y, cardRng=Z, ...
:rng set {rngName} {counter}:
通过反射设置 AbstractDungeon.{rngName}.counter = value
支持: monsterRng, mapRng, eventRng, cardRng, treasureRng,
relicRng, potionRng, miscRng, aiRng, shuffleRng,
cardRandomRng, monsterHpRng安全约束:
- RNG counter 只能增不能减(否则可能产生重复随机值)
- 只能在不活跃使用该 RNG 时修改(如 eventRng 在 EventRoom 中可能被读取)
- 主要用于重现特定随机结果
J) 楼层跳转 :n floor {num} / :n act {num}
:n floor {num}:
1. 只有在 room.phase == COMPLETE 时可以操作
2. AbstractDungeon.floorNum = num
3. 重新种子化 floor 级 RNG(aiRng, shuffleRng 等)
4. 注意: 地图节点不变,可能导致楼层号与实际节点不一致
:n act {num}:
1. 触发 nextAct() 跳转到指定幕
2. 只能增加,不能回退(避免状态不一致)
3. AbstractDungeon.actNum = num - 1(nextAct 会 +1)安全约束:
- 只能在房间完成后操作(phase==COMPLETE)
:n act不能跳回已过的幕- 跳转后必须重置 roomEntered
K) 全局状态查看 :g state / :g room / :g event / :g monsters
:g state:
输出当前完整状态快照(终端友好格式):
- Floor: X, Act: Y, Phase: Z, Screen: W
- Player: HP/MaxHP/Gold/Block/Energy
- Hand/Draw/Discard/Exhaust counts
- Potions, Relics list
- Scene 名称
:g room:
输出当前房间详情: class, phase, event, monsters, rewards
:g event:
输出当前事件详情: class, screenName, optionList, waitForInput
:g monsters:
输出怪物详情: name, HP, block, intent, isDying, isDead这是一个纯读操作,不会修改任何状态。
L) 强制打开特定 screen :f screen {screenName}
实现:
1. 根据 screenName 调用对应的 open() 方法
"grid" → AbstractDungeon.gridSelectScreen.open(...)
"hand" → AbstractDungeon.handCardSelectScreen.open(...)
"card_reward" → AbstractDungeon.cardRewardScreen.open(...)
"combat_reward" → AbstractDungeon.combatRewardScreen.open()
"boss_relic" → AbstractDungeon.bossRelicScreen.open(...)
"shop" → 强制 screen=SHOP, isScreenUp=true
2. 对于需要参数的 screen,使用默认参数:
gridSelectScreen: 从 masterDeck 选 1 张
handCardSelectScreen: 选 1 张
cardRewardScreen: 3 张随机卡安全约束:
- 只能在合适的场景强制打开 screen
- 强制开的 screen 可能与当前游戏状态不匹配(用于调试,接受副作用)
16.4 全局命令入口实现
所有 :x 前缀的命令在 tryGlobalCommand(line) 中处理:
static boolean tryGlobalCommand(String line) {
if (line.startsWith(":f event ")) {
forceEvent(line.substring(10).trim());
return true;
}
if (line.startsWith(":f monsters ")) {
forceMonsters(line.substring(14).trim());
return true;
}
if (line.startsWith(":s deck add ")) {
addCardToDeck(line.substring(13).trim());
return true;
}
if (line.startsWith(":s deck remove ")) {
removeCardFromDeck(line.substring(15).trim());
return true;
}
// ... 其他命令
if (line.startsWith(":g ")) {
inspectState(line.substring(3).trim());
return true;
}
return false; // 不是全局命令
}16.5 注意事项
- 这些命令会绕过 snapshot/restore(直接修改 JAR 状态,snapshot 后的还原会覆盖修改)
- pipe 模式下,NN 不会发出这些命令(
:x前缀不在 legal_actions 中),只用于人工调试 - SoulGroup.isActive() 时禁止修改战斗状态,避免堆操作冲突
- 修改后需要
processEffects()处理连锁效果(如卡牌获得触发遗物效果) - 不要依赖这些命令的稳定性——它们用于调试,不保证在所有游戏状态下安全
- 这些命令应该在文档化后标记为
[DEV]在 help 输出中,普通用户不可见或需要--debugflag 启用
17. JSON 输出 Schema(pipe 模式)
17.1 全局字段(所有 scene 共享)
这些字段在每个 JSON 中都会出现,不随 scene 变化:
{
"type": "state",
"game_id": 0,
"scene": "combat",
"floor": 3,
"act": 1,
"player": {
"hp": 72,
"max_hp": 75,
"gold": 99,
"block": 0,
"orbs": [],
"powers": [ {"id": "Strength", "amount": 2}, ... ]
},
"keys": { "ruby": false, "emerald": false, "sapphire": false },
"deck": [
{"id": "Strike_R", "name": "Strike", "type": "attack", "cost": 1, ...},
...
],
"relics": [
{"id": "Burning Blood", "name": "Burning Blood", "counter": 0},
...
],
"potions": [
{"id": "Fruit Juice", "name": "Fruit Juice", "target_required": false},
null, // PotionSlot
null
],
"map": { ... },
"unknown_chances": {
"monster_chance": 0.2,
"shop_chance": 0.06,
"treasure_chance": 0.04,
"event_chance": 0.7
},
"seen": {
"last_normal": "Jaw Worm",
"second_last_normal": "Cultist",
"last_elite": "Gremlin Nob",
"events": ["The Cleric", "Wheel of Change"]
},
"legal_actions": ["p 0 0", "p 1", "end", "pot 0"]
}17.1.1 各全局字段的数据来源
| 字段 | 来源 | 获取方式 |
|---|---|---|
floor | AbstractDungeon.floorNum | 直接读 |
act | AbstractDungeon.actNum | 直接读 |
player.hp | AbstractDungeon.player.currentHealth | 直接读 |
player.max_hp | AbstractDungeon.player.maxHealth | 直接读 |
player.gold | AbstractDungeon.player.gold | 直接读 |
player.block | AbstractDungeon.player.currentBlock | 直接读 |
player.orbs | AbstractDungeon.player.orbs(Defect 有值,其他为空) | 直接读 |
player.powers | AbstractDungeon.player.powers | 遍历,取 pow.ID 和 pow.amount |
keys.ruby | Settings.hasRubyKey | 直接读 |
keys.emerald | Settings.hasEmeraldKey | 直接读 |
keys.sapphire | Settings.hasSapphireKey | 直接读 |
deck | AbstractDungeon.player.masterDeck.group | cardJson(c) 逐张序列化 |
relics | AbstractDungeon.player.relics | 遍历,取 r.relicId, r.name, r.counter |
potions | AbstractDungeon.player.potions | 遍历,PotionSlot → null,否则取 pot.ID, pot.name, pot.isThrown |
map | AbstractDungeon.map | 见 17.2 地图序列化 |
17.1.2 seen 字段来源
| 字段 | 来源 | 记录时机 |
|---|---|---|
last_normal | AbstractDungeon.lastCombatMetricKey | 进入普通战斗后记录(trackEncounter()) |
second_last_normal | 同上,shift 推移 | 同上 |
last_elite | AbstractDungeon.lastCombatMetricKey | 进入精英战斗后记录 |
events | 从 room.event 获取事件标识 | 进入 EventRoom 后记录(trackEncounter()) |
每个字段默认值为 null(未遇到时为 JSON null)。events 默认值为 []。
关于 lastCombatMetricKey:
getMonsterForRoomCreation()设值(line 2343):lastCombatMetricKey = monsterList.get(0)getEliteMonsterForRoomCreation()设值(line 2352):lastCombatMetricKey = eliteMonsterList.get(0)getBoss()设值(line 2499):lastCombatMetricKey = bossKey- 事件战斗(MaskedBandits 等)不设值 — 事件通过
enterCombat()创建怪物,不经过上述方法
关于事件 ID: 备份代码中没有 getEventId() 方法。每个事件类有自己的 public static final String ID(如 Cleric.ID = "The Cleric")。需通过 room.event.getClass().getField("ID").get(null) 反射获取。
17.1.3 unknown_chances 字段来源
ArrayList<Float> chances = EventHelper.getChances();
// 返回 [ELITE_CHANCE, MONSTER_CHANCE, SHOP_CHANCE, TREASURE_CHANCE]
monster_chance = chances.get(1); // 索引 1 = MONSTER
shop_chance = chances.get(2); // 索引 2 = SHOP
treasure_chance = chances.get(3); // 索引 3 = TREASURE
event_chance = 1.0F - monster_chance - shop_chance - treasure_chance;
// elite_chance = chances.get(0),普通模式总是 0,不算入 event_chance17.2 地图序列化
"map": {
"current_x": 3,
"current_y": 7,
"rows": [
{
"y": 0,
"nodes": [
{"x": 0, "y": 0, "type": "M", "edges": [0]},
{"x": 1, "y": 0, "type": "M", "edges": [1]},
...
]
},
...
],
"available": [
{"col": 0, "row": 6} // 可选的下一排节点(0-based 列+行)
]
}type:"M"(Monster),"E"(Elite),"?"(Event),"$"(Shop),"R"(Rest),"T"(Treasure),"B"(Boss)edges: 连接到下一排的列索引数组available: 从getAvailableNodes(map)返回
17.3 卡牌序列化(cardJson)
每张卡输出以下字段:
{
"id": "Strike_R",
"name": "Strike",
"type": "attack",
"cost": 1,
"base_cost": 1,
"upgrades": 0,
"target": "enemy",
"aoe": false,
"x_cost": false,
"damage": 6,
"block": 0,
"magic_number": 0,
"heal": 0,
"innate": false,
"ethereal": false,
"exhaust": false,
"retain": false
}数据来源:AbstractCard 的 cardID, name, type, cost, costForTurn, timesUpgraded, target, isMultiDamage, baseDamage, baseBlock, baseMagicNumber, isInnate, isEthereal, exhaust, retain/selfRetain。
id使用卡牌 ID 字符串(如"Strike_R"),不用数字 indexbase_cost使用costForTurn(当前回合的实际费用),未修改时为原始 costcost使用原始cost(-1 表示 X-cost)- 所有字段始终输出,不随 debugMode 变化
AbstractCard.CardTarget 枚举与 target 字段映射:
| 枚举值 | JSON target 值 | 是否需要目标参数 | 说明 |
|---|---|---|---|
ENEMY | "enemy" | 是(单个怪物) | 需要 {targetIdx} |
ALL_ENEMY | "all" | 否(全体) | AOE,不需要目标索引 |
SELF | "self" | 否 | 对自己 |
NONE | "none" | 否 | 无条件 |
SELF_AND_ENEMY | "self_enemy" | 是(单个怪物) | 需要 {targetIdx} |
ALL | "all" | 否(全体) | AOE+自身 |
legal_actions 生成规则:target == ENEMY || target == SELF_AND_ENEMY → 加 {targetIdx}。其余 → 只加 {handIdx}。
17.4 各场景的附加字段和 legal_actions
17.4.1 "combat" 战斗
附加字段:
{
"hand": [ {...}, ... ], // 手牌,cardJson 数组
"draw_pile": { "count": 5, "cards": [ {...}, ... ] }, // 抽牌堆
"discard_pile": { "count": 3, "cards": [ {...}, ... ] }, // 弃牌堆
"exhaust_pile": { "count": 1, "cards": [ {...}, ... ] }, // 消耗堆
"monsters": [
{
"id": "SlimeBoss", "name": "Slime Boss",
"hp": 50, "max_hp": 140, "block": 10,
"is_gone": false, "half_dead": false,
"intent": { "type": "attack", "damage": 35, "multi_hit": 1 },
"powers": [ {"id": "Weakened", "amount": 2} ]
}
],
"turn": 5,
"energy": 3,
"turn_ended": false
}数据来源:
hand:AbstractDungeon.player.hand.groupdraw_pile:AbstractDungeon.player.drawPile.group+.size()discard_pile:AbstractDungeon.player.discardPile.group+.size()exhaust_pile:AbstractDungeon.player.exhaustPile.group+.size()monsters:AbstractDungeon.getCurrRoom().monsters.monsters,过滤isDeadOrEscaped()monster intent:m.intent→intentStr(m.intent),m.getIntentDmg(),getMultiHit(m)turn:GameActionManager.turnenergy:AbstractDungeon.player.energy.energyturn_ended:AbstractDungeon.actionManager.turnHasEnded
legal_actions:
"p {handIdx}" — 非目标卡牌(hand 索引 0-based)
"p {handIdx} {targetIdx}" — 目标卡牌(target 索引 0-based,活着的怪物)
"end" — 结束回合
"pot {idx}" — 可使用的药水(pot.canUse() && !pot.isThrown)
"pot {idx} {targetIdx}" — 可投掷药水(pot.canUse() && pot.isThrown)
"dp {idx}" — 可丢弃的药水(非 PotionSlot)17.4.2 "event" 事件
附加字段:
{
"event": {
"id": "The Cleric",
"name": "The Cleric",
"body_text": "You come across a wandering cleric..."
},
"options": [
{"index": 0, "label": "Heal 25%", "disabled": false},
{"index": 1, "label": "Remove a card", "disabled": false}
]
}数据来源:
event.id:getEventId(room.event)event.name:getEventTitle(room.event)(来自eventStrings.NAME)event.body_text:getEventBody(room.event)options: 从evt.imageEventText.optionList或RoomEventDialog.optionList遍历label:LargeDialogOptionButton.msg(包含颜色标记,不去除)disabled:LargeDialogOptionButton.disabled(反射读取)- 匹配游戏事件:GremlinMatchGame PLAY 模式特殊处理(
cards+flips_remaining)
legal_actions:
"0" ~ "N-1" — 非 disabled 选项的索引
"pot {idx}" — 战斗中可用的药水(pot.canUse() && phase!=COMBAT 时为战斗外药水)
"dp {idx}" — 只有 KnowingSkull 事件且药水槽满时17.4.3 "shop" 商店
附加字段:
{
"cards_for_sale": [ {...}, ... ],
"relics_for_sale": [ {"id": "Orichalcum"}, ... ],
"potions_for_sale": [ {"id": "Fruit Juice", "price": 52}, ... ],
"purge_cost": 75,
"purge_available": true
}数据来源:
cards_for_sale:shopCards(从 ShopScreen 的 coloredCards + colorlessCards 获取)relics_for_sale: ShopScreen 的 StoreRelic 列表,取relic.relicIdpotions_for_sale: ShopScreen 的 StorePotion 列表,取potion.ID和价格purge_cost:ShopScreen.actualPurgeCostpurge_available:ShopScreen.purgeAvailable
legal_actions:
"bc {n}" — 可买得起的卡牌(price <= playerGold)
"br {n}" — 可买得起的遗物
"bp {n}" — 可买得起的药水
"rm {n}" — 可删除的牌组卡牌索引(masterDeck 中的 purgeable 卡)
"leave" — 离开商店
"pot {idx}" — 战斗中可用的药水
"dp {idx}" — 可丢弃的药水17.4.4 "rest" 营地
附加字段:
{
"options": [
{"type": "rest", "available": true},
{"type": "smith", "available": true, "upgradeable": [ {...}, ... ]},
{"type": "recall", "available": false}
]
}数据来源:
options: 从campfireUI.buttons遍历type: 从按钮的label判断(如含 “Rest” → “rest”)available: 按钮的usable字段upgradeable: smith 选项显示可升级的牌(masterDeck中canUpgrade()的牌)
legal_actions:
"0" ~ "N-1" — 可用选项的索引(usable != false)
"leave" — 离开营地(在 somethingSelected 后出现)
"pot {idx}" — 战斗中可用的药水
"dp {idx}" — 可丢弃的药水17.4.5 "map" 地图
无附加字段(全局字段 + map 已足够)。
legal_actions:
"0" ~ "N-1" — available 节点的索引(0-based,对应 available 数组)17.4.6 "grid_select" 选牌(Grid + Hand)
附加字段:
{
"source": "deck", // "deck"|"hand"|"draw_pile"|"discard_pile"|"exhaust_pile"
"purpose": "RemoveAction", // 选牌原因,见下文
"num_cards": 1,
"any_number": false,
"include_cards": false,
"selectable": [true, false, true, ...], // 每张是否能选
"selected": [2], // 已选索引
// HandCardSelectScreen 额外字段:
"selected_cards": [ {...}, ... ] // 已选卡牌完整信息
}数据来源:
HandCardSelectScreen (screen == HAND_SELECT):
source: 固定"hand"purpose:hcss.selectionReason(如"Exhaust"),为空时"Select"num_cards:hcss.numCardsToSelectany_number:hcss.upToselectable: 全true(所有手牌都可选)selected_cards:hcss.selectedCards.group(已从手牌移出的卡)hand: 当 scene==combat 且 phase==COMBAT 时,先输出完整战斗上下文(hand/draw_pile等),再输出 grid_select 字段
GridCardSelectScreen (screen == GRID):
source: 从gridSourceGroup(targetGroup)推导Java CardGroup srcGroup = gridSourceGroup(targetGroup); // masterDeck → "deck", hand → "hand", drawPile → "draw_pile", // discardPile → "discard_pile", exhaustPile → "exhaust_pile" // 未知 → "unique", include_cards = true(输出完整 cards 数组)purpose: 优先级forUpgrade→"Upgrade"forTransform→"Transform"forPurge→"Remove"gridActionName()→ 如"ExhaustAction","SeekAction"- 以上为空 →
"Select"
num_cards:numCards(反射读取)any_number:anyNumberselectable:sourceCards[i]在targetGroup中 → trueselected:selectedCards中卡在 sourceCards 中的索引
gridSourceGroup() 逻辑:
1. masterDeck.group == targetGroup.group → masterDeck
2. hand.group == targetGroup.group → hand
3. drawPile.group == targetGroup.group → drawPile
4. discardPile.group == targetGroup.group → discardPile
5. exhaustPile.group == targetGroup.group → exhaustPile
6. CardGroup.type 枚举字符串匹配
7. Combat 中:检查第一张卡在哪个堆(hand/draw/discard/exhaust)
8. 非 Combat:检查第一张卡是否在 masterDecklegal_actions:
HandCardSelectScreen:
组合索引方案(匹配 handleHandCardSelectScreen 解析):
"0" ~ "selected.size-1" — 反选已选卡牌
"selected.size" ~ "selected.size+hand.size-1" — 选手牌
"-1" — 选零张(canPickZero 时)GridCardSelectScreen:
"0" ~ "N-1" — source pile 中在 targetGroup 内的卡牌索引
"f" — anyNumber 且已选卡牌 > 0 时确认注意:不含 "c"(取消/确认),NN 不需要撤销操作。
17.4.7 "combat_card_select" 战斗中选牌
附加字段:
{
"cards": [ {...}, {...} ], // discoveryCards,cardJson 数组
"can_skip": false,
// 战斗上下文(完整):
"turn": 5, "energy": 3, "turn_ended": false,
"player": { ... },
"hand": [ ... ],
"draw_pile": { ... },
"discard_pile": { ... },
"exhaust_pile": { ... },
"monsters": [ ... ]
}数据来源:
cards:AbstractDungeon.cardRewardScreen.discoveryCardscan_skip:AbstractDungeon.cardRewardScreen.discoverySkipable- 战斗上下文:同
"combat"场景的附加字段
legal_actions:
"0" ~ "N-1" — discoveryCards 索引
"leave" — discoverySkipable 时跳过17.4.8 "neow_card_reward" Neow 选牌
附加字段:
{
"cards": [ {...}, {...} ],
"can_skip": false
}无战斗上下文(非战斗中,Neow 阶段)。
legal_actions: 同 "combat_card_select"。
17.4.9 "combat_reward" 战斗奖励
附加字段:
{
"gold_rewards": [100],
"card_rewards": [ // 每组卡牌的 List
{ "cards": [ {...}, {...}, {...} ] } // 每组最多 4 张
],
"potion_rewards": [ {"id": "Fruit Juice"}, ... ],
"relic_rewards": [ {"id": "Burning Blood"}, ... ]
}数据来源:
gold_rewards: 遍历AbstractDungeon.combatRewardScreen.rewards,type == GOLD || type == STOLEN_GOLDcard_rewards: 同上,type == CARD,每组一个{ "cards": [...] }potion_rewards: 同上,type == POTIONrelic_rewards: 同上,type == RELIC
过滤 r.isDone == true 的奖励(已领取的不列出)。
legal_actions:
"gold {idx}" — 金币奖励索引(0-based,只计 GOLD/STOLEN_GOLD)
"card {g} {c}" — 第 g 组卡牌的第 c 张
"potion {idx}" — 药水奖励(槽未满时)
"relic {idx}" — 遗物奖励
"pot {idx}" — 战斗中可用的药水
"dp {idx}" — 可丢弃的药水(总是)17.4.10 "boss_relic" Boss 遗物
附加字段:
{
"relics": [ {"id": "Black Blood"}, {"id": "Runic Dome"}, {"id": "Snecko Eye"} ]
}数据来源:AbstractDungeon.bossRelicScreen.relics,取 r.relicId。
legal_actions:
"0" ~ "N-1" — 遗物索引
"leave" — 跳过17.5 legal_actions 设计原则
- 不包含
"c"(取消/撤销) — NN 不需要撤销操作。触发撤销后的状态与不操作相同,NN 会做相同决策。 - 不包含
"f"以外的确认命令 — Grid select 的anyNumber模式下"f"保留,因为多选需要明确终止。 - 只有 1 个合法动作时自动执行 — pipe 模式下不等 NN,直接 apply。
- 药水命令根据
canUse()返回结果 — 战斗外只显示可用的药水(FruitJuice 等)。 dp命令只在合理场景出现 — 战斗 reward 总是可以丢(可能有新药水),事件只在 KnowingSkull 满槽时。- 所有索引 0-based。
17.6 序列化的线程/并发考虑
serializeState() 必须在 dungeon.update() 返回后、DETECT scene 完成后调用。此时所有状态稳定,没有 pending action 在执行。
不要在效果/动画活跃时序列化(SoulGroup.isActive() 时 battle-over 的更新可能不完整)。序列化时机在 detectScene() 返回非 null 后。
17.7 seen 字段的 snapshot 持久性
lastNormal, secondLastNormal, lastElite, seenEvents 是 CLI 的 static 字段。snapshot(CLI.class) 会自动捕获它们,restore() 自动还原。跨 act 不清空 seenEvents(累积全局事件记录),但三个怪物字段在 nextAct() 时清空。
18. 未解决的问题(需实测验证 / 需阅读原始代码)
以下问题无法仅通过反编译代码解决,需要实测验证或查看字节码。
18.1 hasFocus 何时变为 false
AbstractImageEvent.update() 每帧设 hasFocus = true。EventRoom 的 phase 转换条件 !event.hasFocus 因此永远不会满足——除非某个事件子类的 buttonEffect() 中设 hasFocus = false,或者 ROOM 类型事件有不同机制。
验证方式: 在事件循环中打印 event.hasFocus,观察何时变为 false。
18.2 eventControllerInput() 的作用
AbstractDungeon.update() 的 case 0 中调用 currMapNode.room.eventControllerInput()。方法存在但功能未文档化——可能是事件中的手柄输入处理。CLI 中可忽略(无手柄)。
18.3 图形依赖在 update() 中的分布
AbstractDungeon.update() 调用 scene.update()(纯渲染背景)和各个 screen 的 update()。Screen 的 update 方法中混杂了逻辑和渲染:
GridCardSelectScreen.update():包含卡牌选择逻辑(必须保留)+ 卡牌位置/渲染(可删)CombatRewardScreen.rewardViewUpdate():包含奖励领取逻辑(必须保留)+ UI 位置/渲染(可删)
不能简单”删除渲染部分”——需要逐个 Screen 分析其 update() 中哪些是逻辑、哪些是渲染。
18.4 acquireCard() 私有方法的处理
CardRewardScreen 中的 acquireCard() 是 private 方法。作为替代方案:可直接创建 FastCardObtainEffect 并添加到 effectsQueue,然后调用 takeReward()(反射,或改为 public)。
18.5 效果(Effects)的分类——哪些安全、哪些不安全
以下效果有游戏逻辑副作用,必须在 CLI 中处理:
FastCardObtainEffect→ 卡牌加入 masterDeckShowCardAndObtainEffect→ 卡牌加入 masterDeckShowCardAndAddToHandEffect→ 卡牌加入手牌CampfireSmithEffect→ 触发营地锻造CampfireSleepEffect/CampfireTokeEffect等 → 营地效果BattleStartEffect→ 战斗启动动画(可能触发 preBattlePrep?)
以下效果是纯 VFX/音效,stub 或跳过:
CollectorStakeEffect→ 纹理加载,headless 崩溃RainingGoldEffect,GainGoldTextEffect→ 纯视觉PurgeCardEffect,ExhaustCardEffect→ 纯视觉动画CardPoofEffect,CardTrailEffect→ 纯视觉
待确认: BattleStartEffect 是否有逻辑副作用,还是纯动画。
18.6 如何以代码启动游戏
文档未覆盖:如何编程创建角色、生成地牢、将 mode 设为 GAMEPLAY。需要找到以下调用链:
CardCrawlGame.chosenCharacter = IRONCLADCardCrawlGame.startGame()或等效方法- 或直接
new Exordium(player, events)+CardCrawlGame.dungeon = dungeon+CardCrawlGame.mode = GAMEPLAY
18.7 switch(screen) 中 case 0/1 的映射
反编译代码中,两个 case 通过 ordinal 0/1 区分 NORMAL/CAMPFIRE 和 EVENT 场景,但 CurrentScreen.NONE == ordinal 0。这两个 case 如何映射到”无 screen 时”的不同行为,需要通过查看字节码或实测来确认。可能是通过 rs(RenderScene)字段在 case 内部进一步判断。
19. Act 过渡完整流程(已验证:第 2 轮审查)
以下内容通过阅读原始 backup 代码验证,所有行号对应 backup 文件。
19.1 Act 1→2 / Act 2→3 过渡
7 步流程:
| 步骤 | 触发条件 | 执行代码 | 文件:行号 |
|---|---|---|---|
| 1 | Boss 死亡 | endBattle() → phase=COMPLETE → combatRewardScreen.open() | AbstractRoom.java:346-438 |
| 2 | 点击 ProceedButton | goToTreasureRoom() | ProceedButton.java:230-238 |
| 3 | 创建 TreasureRoomBoss | 构造器设 CardCrawlGame.nextDungeon(Exordium→“TheCity”, TheCity→“TheBeyond”), phase=COMPLETE | TreasureRoomBoss.java:30-54 |
| 4 | 进入房间 → 点击宝箱 | BossChest.open() → bossRelicScreen.open(relics) | BossChest.java:50-65 |
| 5 | 选择遗物 | relic.bossObtainLogic() → isDone=true → closeCurrentScreen() → 1s 后 ProceedButton 出现 | BossRelicSelectScreen.java:227-256, AbstractRoom.java:461-478 |
| 6 | 再次点击 ProceedButton | goToNextDungeon() → fadeOut() + isDungeonBeaten = true | ProceedButton.java:283-315 |
| 7 | CardCrawlGame.update() 检测 | isDungeonBeaten && fadeColor.a==1.0F → dungeon=null → 创建 DungeonTransitionScreen | CardCrawlGame.java:882-886 |
第 7 步下一帧: dungeonTransitionScreen.isComplete==true → getDungeon(nextDungeon, player) 创建新 act 地牢。AbstractDungeon 构造器重置 isDungeonBeaten=false。
19.2 GoToTreasureRoom() 完整代码
文件: ProceedButton.java:230-238
private void goToTreasureRoom() {
CardCrawlGame.music.fadeOutTempBGM(); // 纯音效
MapRoomNode node = new MapRoomNode(-1, 15); // 逻辑:创建节点
node.room = new TreasureRoomBoss(); // 逻辑:创建房间(构造器设 nextDungeon)
AbstractDungeon.nextRoom = node; // 逻辑
AbstractDungeon.closeCurrentScreen(); // 逻辑:关闭战斗奖励屏幕
AbstractDungeon.nextRoomTransitionStart(); // 逻辑:开始淡出
hide(); // 纯 GUI
}19.3 GoToNextDungeon() 完整代码
文件: ProceedButton.java:283-315
private void goToNextDungeon(AbstractRoom room) {
if (!((TreasureRoomBoss)room).choseRelic) {
AbstractDungeon.bossRelicScreen.noPick(); // 逻辑:记录跳过遗物
}
// Calling Bell FTUE 检查(可能提前 return 中断过渡)
int relicCount = 0;
for (RewardItem i : AbstractDungeon.combatRewardScreen.rewards) { ... }
if (relicCount == 3 && this.callingBellCheck) { ... return; } // 逻辑:CallingBell 提示
CardCrawlGame.music.fadeOutBGM(); // 纯音效
CardCrawlGame.music.fadeOutTempBGM(); // 纯音效
AbstractDungeon.fadeOut(); // 逻辑:开始 0.8s 渐黑
AbstractDungeon.isDungeonBeaten = true; // 逻辑:标志位
hide(); // 纯 GUI
}19.4 BossChest.open() → BossRelicScreen
文件: BossChest.java:50-65
public void open(boolean bossChest) {
if (actNum < 4 || !Blight Chests mod) {
for (AbstractRelic r : player.relics) r.onChestOpen(true); // 逻辑:遗物 onChestOpen 回调
overlayMenu.proceedButton.setLabel(TEXT[0]); // GUI
CardCrawlGame.sound.play("CHEST_OPEN"); // 纯音效
AbstractDungeon.bossRelicScreen.open(this.relics); // 逻辑:打开遗物选择屏
}
}19.5 DungeonTransitionScreen — 需验证是否为纯 GUI
文件: DungeonTransitionScreen.java
构造函数 :isComplete = true(第 67 行)—— 立即完成!无任何游戏逻辑。它只是一个纯视觉的过场动画。update() 只是更新动画/计时器,不修改游戏状态。
→ 可以安全 stub 为无操作。
19.6 CLI 中需要手动处理的部分
CardCrawlGame.update() 需要被 CLI 调用(替代仅调 dungeon.update()),因为:
- 它包含 act 过渡检测(line 882-886):检测
isDungeonBeaten && fadeColor.a == 1.0F - 它处理
dungeonTransitionScreen.update()→ 创建新 dungeon - 它还处理 GAMEPLAY 外的 mode 切换
需要保留的 CardCrawlGame.update() 子调用:
| 方法 | 纯 GUI? | 处理方式 |
|---|---|---|
cursor.update() | ✅ 纯 GUI | 删除 |
screenShake.update() | ✅ 纯 GUI | 删除 |
updateFading() | ❌ 有逻辑 | 保留(渐黑 → 触达 nextRoomTransition()) |
music.update() | ✅ 纯音效 | 删除(已 stub) |
sound.update() | ✅ 纯音效 | 删除(已 stub) |
InputHelper.updateFirst/Last() | ✅ 纯输入 | 删除 |
cardPopup/relicPopup.update() | ✅ 纯 GUI | 删除 |
| GAMEPLAY mode switch | ❌ 核心逻辑 | 保留 |
dungeonTransitionScreen.update() | ✅ 纯 GUI | 可简化为直接调 getDungeon() |
dungeon.update() | ❌ 核心逻辑 | 保留 |
updateDebugSwitch() | ✅ 调试 GUI | 删除 |
steelSeries | ✅ 外设 | 删除 |
DungeonTransitionScreen 后续处理: 构造函数设 isComplete = true,所以 CardCrawlGame.update() 在下一帧会直接通过 getDungeon() 创建新地牢。在 CLI 中可简化为:检测到 isDungeonBeaten && fadeColor.a >= 1.0F 时直接调用 getDungeon()。
19.7 ProceedButton 的 CLI 等价处理
当 room.phase == COMPLETE 时,CLI 需要模拟 ProceedButton 点击:
| 房间类型 | 屏幕 | 动作 |
|---|---|---|
| MonsterRoomBoss | COMBAT_REWARD | goToTreasureRoom() |
| TreasureRoomBoss(未选遗物) | NONE | 点击宝箱 → BossChest.open() |
| TreasureRoomBoss(已选遗物) | NONE | goToNextDungeon() |
| 其他 | — | dungeonMapScreen.open(false) |