Fix background clicks and mirror scene boundaries with run feedback

Browse Source
This commit is contained in:
Codex Agent
2026-10-02 20:58:56 +08:00
parent 9d3902ebe9
commit 6523f648fd
15 changed files with 1081 additions and 26 deletions
@@ -0,0 +1,36 @@
# 第二局镜牢:运行与修复记录
本局从 2026-10-02 18:13:22(UTC+8)开始计时。计时包括配置、网络等待、用户重启游戏、界面识别错误、代码修复与实际战斗;最终领取奖励并确认返回后才结束。`run.json` 是当前完成状态的依据,尚未结算时不能称为通关。
用户在第五层玫瑰标牌战斗中接管,执行器已终止,停止自动按键。记录接管时累计用时 9738.9 秒(2 小时 42 分 19 秒);不代表通关用时,未记录最终领取完成。这次执行明显未达到速通目标。
## 已核对的配置和进度
- 星之恩惠 1、3、10,未强化;起始荆棘套索、荧光灯;入层三级三选一取得标准负载电池。
- 第一层“宅邸的副产物”取得成捆的符咒,第二层选择地狱鸡,第三层沉迷的色欲,第四层堕落的忧郁。前四层均未选择二号线。
- 二层奖励没有足够符合不加生命/防御的选项,用户明确选择最低增幅的锐利(体力上限 +5%、攻击等级 +1)。三层同类情况选体力增幅最低且不加防御的两项,已向用户说明。
- 第二层特殊商店错误离开;第三层商店补做符咒 ++,实际经费从 1375 降至 1225,强化后文字与数值已核对。
- 第四层特殊商店用非核心 III+II+II 合成得到快感,消耗 5 星芒祈愿;随后支付 300 经费直接强化至 ++(1360→1060),实际库存与效果已核对。证据为 `thrill_acquired.png` 和 `thrill_enhanced.png`。
- 第四层奖励全部增加体力,用户明确选第 1+2 项:体力增幅较低,接受第二项防御等级+2。不是全局放宽选择规则。
- 第五层三次刷新未出现二号线,刷新归零后使用卡包观测,支付 20 星芒将首个候选替换为二号线并下拉进入。`floor5_line2.png` 是实际五层地图证据。
- 本局 Jev 接入检查返回 HTTP 429,使用已告知用户的固定候选回退;不能把回退决策记录为 Jev 成功调用。
## 真实问题与修复
1. 开局游戏无响应,用户约 18:31 重启。继续原局,没有重置计时。
2. 紫色事件/商店节点识别遗漏。结合当前可达箭头检测与节点模板,增加紫色商店回归场景。
3. 18:58 特殊商店未识别为商店,跳过核心强化及可替换技能。识别同时支持“商店”和“特殊商店”,并测试核心未强化及仍有可用技能时不能直接离开。截图 `special_shop_missed.png` 是错误发生时的真实画面。
4. 单张额外饰品与多张层末苦难共用“拒绝饰品”。只允许自动拒绝明确的单张非核心额外奖励,保留核心及多卡场景。
5. 重复动作候选删除后,未知场景计时变量仍为 None,导致 TypeError。改为候选删除后再更新计时,实际恢复运行成功。
6. 噬梦浊流事件选择了“拔出荧光灯”,引入额外遭遇战。补识别“触发遭遇战”等结果,不能将其当免费奖励;后续应按事件笔记优先较低门槛判定。
7. 事件结果页显示“开始战斗”,连续回车无效。新增结果页开始战斗按钮识别,实际点击后恢复。
8. 战中切入“选择一位罪人来进行判定”时仍发送 P+回车,造成数分钟无效输入。扩大战斗退出边界并同步候选识别;新增实际宏执行回归测试,要求判定出现后立即返回、不再继续发键。首次进入判定的准确时间未保留,不能把整段宏耗时都断言为卡住时间。
9. 后台点击按住时间太短,Unity 有时只显示悬停。修复为后台消息按下/抬起各留 120ms,不移动系统鼠标。第一版错误使用 WindowMoveInput 私有方法,实际 BackgroundInput 调用报错;已改用真实公开接口,测试 mock 限制同样的接口,随后实际合成与强化点击成功。
10. 商店离开弹窗和层末奖励确认改用回车;回车未生效再点击按钮。层末实测连续回车进入第五层卡包界面。
11. 第五层卡包刷新期间游戏再次无响应,用户约 20:31 重启。继续原存档,计时保持连续。
## 验证与证据限制
64 项 unittest 全套通过;随后回车确认策略修改后,40 项控制器测试再次通过。覆盖战中判定中断、特殊商店、后台点击、紫色节点、奖励拒绝边界及最终领取确认。动作日志只包含执行器已完成并写出的动作;主助手手动恢复点击及用户接管时被中断批次未计入按键统计。游戏仅保留最近 30 张截图,已删除的画面无法恢复。
本目录不包含 API 密钥、MCP 令牌、完整本地配置或聊天记录。代码变更在仓库 `scripts/jev_mirror_agent.py` 与 `tests/test_jev_mirror_agent.py`;运行中的状态快照不能代替最终通关证据。
File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

@@ -0,0 +1,5 @@
{
"state": "user_takeover",
"reason": "User took control; controller terminated and no further game input will be sent.",
"at": "2026-10-02T20:55:40.9011624+08:00"
}
@@ -0,0 +1 @@
{"refresh_used": 0, "floor": 5, "symbol_upgraded": true, "battery_obtained": true, "thrill_obtained": true, "thrill_upgraded": true}
@@ -0,0 +1,10 @@
{
"action_records": 409,
"battle_batches": 51,
"sent_p_enter_pairs": 1080,
"jev_successful_decisions": 0,
"limitations": [
"Only executed actions are logged; manual recovery inputs are documented in README.",
"Recent screenshots rotate; missing captures are not reconstructed."
]
}
@@ -0,0 +1,169 @@
# 镜牢速通:破裂黎明/黑兽纯 P
记录日期:2026-10-01;用户规则更新至 2026-10-02。
目标:尽快完成整局,按楼层推进;保留关键强化与换技能,减少无关运营。
## 开局固定配置(用户明确指定)
1. 星之恩惠选 :**起始之星、星际旅行、全面的可能性**。
2. **恩惠保持基础等级,不强化**;不要点击单项或全部强化按钮。
3. E.G.O. 饰品选**破裂**组的**荆棘套索、荧光灯**。
4. **不需要额外观测饰品**;进入额外 E.G.O. 饰品观测页面后,直接选择**拒绝饰品**。
5. **入层三级饰品选择“标准负载电池”**(简称“电池”)。
注意:不强化的是开局星之恩惠;二层的**符纸 ++**仍然必须做。
**饰品只能在商店强化**;地图饰品窗口的 +/++ 是效果预览。二层遇商店优先把成捆的符咒强化到 ++,以实际强化标识确认。
## 楼层推进顺序
**符纸的游戏内名称为“成捆的符咒”**(用户截图确认):Ⅰ级破裂饰品,图标是黑色底板上的两张折叠符纸,带红色符文和黄色纸边。按此名称与图标识别卡包奖励。
| 楼层 | 优先操作 | 有余力再做 |
| --- | --- | --- |
| 1F | 优先选通关奖励含**符纸**的卡包,取得符纸;遇商店按下表换技能。 | — |
| 2F | **符纸强化到 ++**;优先选 **Hell's Chicken**,主动获取**鸡胸**以维持破裂层数;按下表换技能。 | — |
| 3F | 菲辛的换技能目标改为 **1 → 3**;按当前头目和路线选择可纯 P、战斗较短的卡包。旧称 Bearable 尚未对应正式名称,不作为固定首选。 | 制作**快感**并强化至 ++。 |
| 4F | 继续推进、按下表换技能。 | 补缺失的相关饰品。 |
| 5F | **必选“2号线”卡包,第一至第四层禁止选择它**;优先换技能并通关,不必专门做斩击四级饰品。 | 卡包刷新次数为零时允许卡包观测;顺路高级饰品。 |
没拿到鸡胸也继续推进,**不要因此重开**。饰品与换技能竞争资源时,优先关键技能;符纸 ++ 的优先级保留。
## 快感合成:先区分普通/特殊商店
用户补充(2026-10-02):**取得快感后,必须在商店强化到二级(++)再继续。** 在强化界面选择 ++,支付实际报价并确认库存名称为“快感++”;只看到 ++ 效果预览不算完成强化。
快感属于普通合成池的四级破裂饰品,不是固定材料配方。商店选择“合成饰品”并指定破裂,用非核心材料达到当前商店的四级门槛;以界面显示的产物等级和关键词预览为准,不能把出四级理解为必出快感。
| 商店 | 四级门槛 | 可用材料等级组合 |
| --- | --- | --- |
| 普通商店 | 总点数 ≥25 | 332=26;重合可用 431=28、422=27 |
| 特殊商店 | 总点数 ≥22 | 322=22、331=23;重合可用 421=24 |
材料点数:Ⅰ=3、Ⅱ=6、Ⅲ=10、Ⅳ=15。普通商店的 322/331 只出三级,在特殊商店才可出四级;**特殊商店的 411 仅21点,仍不够四级**。特殊商店最多放5件材料;2222=24点也可出四级,具体组合按非核心库存和词条成功率选择,不为了凑固定数字消耗核心饰品。
2/3/4–5件材料命中指定词条的基础概率为60%/90%/99%;每次花5星芒祈愿可提高为90%/99%/99.99%。这是词条概率,不是快感本身的概率。没出快感时,先按商店类型重新计算点数,不照搬普通商店组合。符咒++、电池、鸡胸等核心保留。
核对日期:2026-10-02。[名与蛛之镜:合成规则](https://limbuscompany.huijiwiki.com/wiki/名与蛛之镜)。
本局实测:四层特殊商店用非核心Ⅲ+Ⅱ+Ⅱ,预览四级破裂;消耗5星芒祈愿(2826→2821),实际合成“快感”。材料点击选入,不拖拽。一次成功不代表此组合必出快感。
本局强化实测:快感从基础直接选择 ++,支付300经费(1360→1060);库存名称已确认为“快感++”,回合开始施加6强度、3层破裂,回合结束最多计算10层。费用以当次界面报价为准。
## 技能替换速查
箭头表示“用左侧技能换成右侧技能”。
| 人格 | 1–2F | 3–5F |
| --- | --- | --- |
| 菲辛 | **1 → 2** | **1 → 3** |
| 黑兽奥 | **2 → 3** | **2 → 3** |
| 其他人格 | **1 → 3** | **1 → 3** |
看到符合上表的替换通常直接换,少做反复比较。
用户补充(2026-10-02):商店没有出战角色可替换技能时,允许刷新,**每个商店至多 4 次**。有出战角色可换时按技能表执行;达到上限即继续推进。
刷新后出现 CONNECTING 时,旧库存仍可见;必须等加载结束,禁止据旧库存再次刷新或退出。有未购买的出战角色技能替换时先完成替换,不能直接离开。快捷键一次未生效即点击当前对应按钮。
特殊商店同样执行强化与换技能;标题识别必须包含“特殊商店”。2026-10-02 实际漏识导致二层提前退出,已修复并增加回归测试。二层起符咒未确认 ++ 时禁止自动离开。
用户补充:离开商店时直接按回车快速退出,不再额外检查、观察或询问;只有回车未生效时才点击弹窗确认。
## 层末苦难
- 除必需饰品外,选择**不加敌方血量、不加防御等级**的选项。不要漏选后让系统随机分配苦难;
- 层末必须先选择苦难再直接推进,不能把此界面误当额外饰品观测而默认拒绝。
- 用户补充:每层选完奖励后直接连续回车确认并进入下一层,不再额外检查、观察或询问;未生效才点击对应按钮。
## 场景执行表(优先减少重复步骤)
| 当前画面 | 固定操作 | 到哪里再重新决策 |
| --- | --- | --- |
| 进入镜牢确认弹窗 | 直接 Enter;未生效立即点击确认 | 开局或恢复的当前界面 |
| CONNECTING/加载 | 等待,不购买、不刷新、不退出 | 新画面加载完成 |
| 上层确认弹窗 | 只操作弹窗按钮 | 弹窗关闭 |
| 地图节点/关卡编队 | 方向+Enter;编队界面再 Enter | 战斗或下一个选择界面 |
| 战斗 | 持续 P → Enter,不分析拼点、不逐按钮调用模型 | 结算、奖励、地图或事件 |
| 事件对话 | SKIP;再用 Enter 推进 | 选项或罪人判定出现 |
| 事件选项 | 已有无需战斗/判定的直接领取分支就选,避免反复滚动 | 下一处分支或结果 |
| 事件结果 | Enter 推进;可见“继续”且按键无效就直接点击 | 返回地图 |
| 商店 | 可换出战技能先换;无可换技能再刷新,最多 4 次 | 新库存;不根据加载旧库存继续操作 |
| 层末多卡奖励/苦难 | 先选饰品和苦难,再确认推进 | 下一层;不能按“额外观测”默认拒绝 |
| 最终结算 | 点击“领取” → Enter 确认;无效就点确认 | 返回主界面,结束执行 |
无变化判断比较界面标题、选项、按钮状态,忽略录像计时和战斗动画中的数字。快捷键一次未生效就回退按钮;不重新核对已确定的编队、路线或技能表。卡包详情已读过的结论应保留,不能关闭后再次从零观测同一卡包。
## 执行原则
- 战斗循环按 **P → 回车**,直到结束;不逐回合截图分析,只在检查是否已结算时查看画面。
- **事件判定先点击 SKIP 跳过对话**,再选择事件选项、罪人或进行判定;SKIP 可用时不提前处理判定。其他对话也优先 SKIP,可用回车加快。
- 事件对话跳过后,继续按回车直到出现罪人选择界面;判定结果出现后快速连按回车结束事件。固定推进不逐按钮请求模型。
- **回车**可触发对话及其他按钮;有明确的确认、继续按钮时,优先使用快捷键。
- 路线优先选择可直接结束的事件、商店等非战斗节点,避免为小奖励增加复杂判定。
- 商店保留符纸 ++、关键维持饰品和快速换技能;略过无关采购、合成与反复比较。
- 困难镜牢与视频条件未全部核对,按当前画面修正,不能把视频用时直接套到当前局。
- 电脑操作优先使用用户安装的 limbus MCP 后台接口;只运行一个执行器,不抢前台焦点。用户要求快速执行,战斗使用有界 P+回车宏;需要选项的界面核对当前画面。
## 事件选择与可复用 skill
- 按**整局用时**选择:优先核心符咒/鸡胸,其次即时恢复、经费或直接结束;避免额外战斗、多段判定和无关奖励。大量理智损失可能拖慢后续纯 P。
- **炸鸡对决选第一项**,直接获得鸡胸与鸡翅;第三项也给鸡胸,第二项仅鸡翅。
- 当前游戏译名:鸡胸为**干巴柴涩鸡胸肉**,鸡腿为**火热多汁琵琶腿**。
- 商店符咒强化可直接选 **++**,本局一次支付 **150 经费**完成;以当前报价为准。
- 可复用 skill:[$limbus-mirror-speedrun]({user_home}/.codex/skills/limbus-mirror-speedrun/SKILL.md)。[事件速查表]({user_home}/.codex/skills/limbus-mirror-speedrun/references/event-choices.md)按名称查询,以当前选项文字核对编号。
## 游戏内快捷键(用户操作指南截图)
- **P → Enter**:胜率/伤害按键后开始战斗/行动。
- **Enter/Space**:弹窗确认、故事跳对话、提取跳动画、选项事件加载下一段文本;对话也可直接点 SKIP。
- **战斗 Space=暂停/继续**,不加入战斗循环。
- **关卡/商店:方向选中后直接按 Enter 进入,无需再次确认**(用户补充);执行器将选方向+回车合并为一个动作。
- 进入关卡后的编队界面继续按 **Enter** 开战,不再次检查编队;沿用原队伍。
- **快捷键未生效时立即改用鼠标点按钮**,不反复尝试(用户补充)。
- **地图 ↑/↓/→ 或 W/S/D**:移至下个节点后直接回车进入;**←/A**:取消节点选择;**Q/E**:地图左右平移。
- 战斗 **方向键/WASD** 移动视角,**滚轮/Q/E** 缩放,**Tab** 显示拼点箭头。
- **F1** 打开操作指南;**Esc** 随界面关闭弹窗、取消、返回或退出。完整表见 [快捷键速查]({user_home}/.codex/skills/limbus-mirror-speedrun/references/shortcuts.md)。
## Jev 接入(用户授权)
- 已实测 `jev-1.13-free` 决策接口返回 HTTP 200,耗时约 1.3–1.5 秒;端点为 `https://opencode.ai/zen/v1/systemone`。
- 客户端:[jev_decision_client.mjs]({runtime}/jev_decision_client.mjs)。凭据由环境变量或未跟踪的本地配置提供,上传源码与反馈时排除凭据和配置文件。
- 用户更新(2026-10-02):固定场景、路线与常规动作均交给 Jev;仅在它返回 `requires_analysis` 或具体接口故障时由主助手排查。执行器只执行已核对的候选动作,不运行模型任意代码。
- 最新战斗指令:开战后仅 P+回车循环到结算,不逐批请求 Jev。批次末只识别是否已结束,战斗特写没有 OCR 文字也继续;结算后交回 Jev。
## 本局实测与待验证
2026-10-02 已看到第五层“探索完成”;点击领取后由用户完成回车确认,随后观察到主界面。此局包含人工纠正,不能记成全自动速通成功。商店加载保护、层末苦难选择和完整自动领取流程已修改并做回归检查,下一局仍需确认实际效果;12 分钟目标尚未复现。
## 2026-10-02 第二局实测(用户接管,未通关)
- 本局计时从 14:19:55.538 接管开始,到 17:33:45 记录用户接管,共 3 小时 13 分 49 秒。包含开局配置、接口等待、修复和全部操作停顿;这是交接前耗时,不是通关用时。
- 入层三级饰品被执行器误当额外观测拒绝,未取得标准负载电池;这是执行错误,不能作为后续默认流程。
- 三、四层所有苦难均增加敌方体力,无法完全遵守“不加血量”;本局选了不加防御等级的组合。拒绝层末奖励会随机附加苦难,不能用它规避负面。
- 2 号线被第四层选用,第五层观测列表显示无法选择。用户明确纠正:**第一至第四层禁止选择二号线,只留到第五层**;本局第五层刷新用尽后观测并选择“时间杀人时间”。
- Jev 遇 HTTP 429,临时使用现有规则的确定性执行器;不能记为 Jev 全程决策成功。
- 本轮修复包括:饰品伤害文字误判战斗、选项中的判定成功误判结果、事件后续推进、加载 OCR 容错、奖励双卡位置、商店技能列定位及服务器错误弹窗优先重试。47 项仓库回归检查通过;本局第五层头目纯 P 团灭一次,死亡重试画面未被战斗循环识别为结束,此处仍需修复。测试通过不能代表整局通关。
- 用户允许最后头目手动拼点/治疗 E.G.O 后,又明确接管。自动执行器已停止。随后用户报告已完成镜牢并领取奖励,记为用户接管后完成,不能记录为自动通关;实际领取时刻未知,交接前耗时不等于总通关用时。
## 2026-10-02 机制核对与电池修复
- 开局三级三选一是“全面的可能性”的奖励,与额外观测分开。**必须选标准负载电池并确认**,不得拒绝;领取后一次核对库存,不每场重复查看。核心符咒、电池、鸡胸不出售、不合成。
- 日志确认第二局 14:34:59 执行了“拒绝饰品”;决策提示漏写电池且通用按钮开放了拒绝。这是执行错误,不是用户没有配置。
- 本地及仓库执行器已补必选电池规则、按卡名选取及确认候选;未知三选一不暴露拒绝,只有明确额外观测才允许拒绝。新增三选一选择/确认、未知卡名禁止拒绝、额外观测及事件结果不误判等回归检查,当前共 **51 项通过**。尚未重新实机验证电池领取,也没有恢复用户接管的游戏。
- 2 号线固定事件、事件、商店、玫瑰标牌,共 4 节点;仍按用户要求只留第五层。拒绝层末奖励不能规避随机苦难。符咒 ++ 的低伤害门槛与斩击补层数是必需强化原因。
- 其余鸡胸当前触发限制、最后商店恢复、替代头目与版本差异见 [机制参考]({user_home}/.codex/skills/limbus-mirror-speedrun/references/mechanics.md)。速度判断属于流程推断,未实测为更短整局用时。
## 第二至第四层选包优先级(初步,未逐包计时)
- 第二层缺鸡胸时优先地狱鸡;地狱鸡只在第二层出现,不在三四层反复寻找。已有鸡胸或当前没出现时,从现有候选比较纯 P 可通过性、战斗与头目耗时,不为无关奖励运营。
- 第三、四层核心齐全且长度相同时,初步优先考察 Addicting Lust(因而无人哭泣/长腿精灵)和 Degraded Gloom(悲泣蟾蜍/无头鱼)。两者没有实测固定先后,仅作为机制筛选候选组。
- 压抑的暴怒、空转的怠惰作为次选比较,不能因为上局打过就自动列首选。多波、阶段复杂、未验证纯 P 可通过的头目降低优先级;四节点长线包不自动优于普通包。
- 旧笔记中的 Bearable 尚未对应当前正式卡包名称,暂停作为第三层固定首选。当前 Wiki 卡包总表与旧赛季表存在楼层/头目差异,以当前难度的可用卡包及游戏详情为准。完整条件表见 [楼层规划]({user_home}/.codex/skills/limbus-mirror-speedrun/references/rupture-route.md)。
- 第一层仍选带符纸的卡包;第一至第四层禁止二号线,第五层按用户要求优先二号线。以上暂定排序不修改游戏或启动执行器。
## 来源
- B 站 UP 绅士丶蚂蚱:[破裂黎明纯 P 周回](https://www.bilibili.com/video/BV1exaV6yELm/)。楼层规划采用其换技能优先策略。
- 原作者 Cabric:[黎明黑兽五层攻略](https://www.youtube.com/watch?v=h5wFVUd2X2c)。卡包、配队与机制补充来自原攻略。
- [边狱公司 Wiki:探索事件](https://limbuscompany.huijiwiki.com/wiki/%E6%8E%A2%E7%B4%A2%E4%BA%8B%E4%BB%B6)。事件结果于 2026-10-01 核对,速通排序为针对当前纯 P 流程的判断。
@@ -0,0 +1,24 @@
{
"run_id": "mirror_20261002_181322",
"start_utc": "2026-10-02T18:13:22+08:00",
"start_local": "2026-10-02T18:13:22+08:00",
"status": "user_takeover",
"start_definition": "Before entering the dungeon; includes setup, API waits, fixes, loading and all delays.",
"end_definition": "Final rewards claimed and confirmed; observe return to dungeon lobby or home.",
"dungeon_completed": false,
"final_reward_claimed": false,
"deviations": [
{
"reason": "Jev connection check returned HTTP 429; deterministic fallback used instead of repeatedly waiting."
},
{
"reason": "Game became unresponsive during starting gift selection; user restarted it at 18:31. Recovered the same run; timer includes the interruption."
},
{
"reason": "18:58:43: special shop missed because classifier only matched exact ordinary shop title; left without upgrading symbol or buying available Gregor/Faust swaps. Fixed classifier and added regression; must upgrade at next available shop."
},
"20:31 用户重启无响应游戏;已恢复前四层通关存档,计时连续。"
],
"takeover_local": "2026-10-02T20:55:40.9011624+08:00",
"elapsed_to_takeover_seconds": 9738.9
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 928 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

+15 -1
View File
@@ -146,7 +146,21 @@ class AalcEngine(Engine):
# ---- 动手 (AALC 输入后端,由 config.yaml 决定后台消息/前台输入) ----
def click(self, x, y, times=1):
self.auto.mouse_click(int(x), int(y), times=int(times))
if not self.cfg.simulator and self.cfg.win_input_type == 'background':
handler = self.auto.input_handler
self.auto.wait_pause()
for _ in range(int(times)):
handler.set_mouse_pos(int(x), int(y))
handler.set_active()
handler.mouse_down(int(x), int(y))
try:
time.sleep(0.12)
finally:
handler.mouse_up(int(x), int(y))
# Let Unity consume the release before another target is selected.
time.sleep(0.12)
else:
self.auto.mouse_click(int(x), int(y), times=int(times))
def keypress(self, key):
k = str(key).lower()
+198 -24
View File
@@ -24,10 +24,11 @@ SYSTEM_RULES = (
'事件当前有“选择后获得”且无需判定、无需战斗的选项时直接选择它,不反复滚动;避开写着战斗胜利后的选项。'
'确定确认/进入/开始战斗直接执行。地图优先可达事件和商店,减少战斗。'
'选好路线直接回车进入,关卡编队界面也直接回车开战;保留原编队,不再检查人员。'
'保留当前编队。成捆的符咒++和鸡胸为核心,略过额外观测;其他苦难避开敌方体力上限和防御等级。'
'保留当前编队。开局三级饰品三选一必须选择标准负载电池,再确认领取;不能当成额外观测拒绝。'
'成捆的符咒++、标准负载电池和鸡胸为核心,保留不可出售或合成;仅略过单独的额外观测。其他苦难避开敌方体力上限和防御等级。'
'3层起辛克莱1换3,黑兽奥提斯2换3,其他出战1换3。只在商店强化饰品。'
'商店没有出战角色可替换技能时允许刷新,当前商店最多4次;有可替换角色先按技能表替换。'
'第五层优先2号线卡包;卡包刷新次数为零时允许使用卡包观测。层末必须选择苦难再推进,不能当额外观测默认拒绝饰品。'
'第一至第四层禁止选择2号线卡包,留到第五层优先选;刷新次数为零时允许使用卡包观测。层末必须选择苦难再推进,不能当额外观测默认拒绝饰品。'
'卡包信息不清先点对应放大镜查看;核心饰品齐全时按通关速度选择现有卡包,不为可选饰品反复刷新。'
'信息不足、重复操作仍无效、苦难无法明确核对,或你判断需要主助手分析时选 requires_analysis。'
)
@@ -37,6 +38,12 @@ def text_items(state):
return state.get('items') or []
def death_retry_screen(texts):
combined = '\n'.join(texts)
return ('全体罪人' in combined and '死亡' in combined
or '当前剩余人员' in combined and '重试关卡' in combined)
def button_enabled(state, item):
try:
from PIL import Image
@@ -73,13 +80,28 @@ def map_candidates(state):
if not (0 < x < rgb.shape[1] and 0 < y < rgb.shape[0]*.82):
continue
radius = int(125 * scale)
# Event and shop nodes remain purple even when reachable. Their
# connecting arrow, rather than node color, indicates availability.
ax, ay = int(bx + 250*scale), int(by + dy*scale/2)
arrow_roi = gray[max(0,ay-radius):min(gray.shape[0],ay+radius),
max(0,ax-radius):min(gray.shape[1],ax+radius)]
arrow_name = {'w':'up','d':'mid','s':'down'}[key]
template = cv2.imread(str(assets / 'road_in_mir' / (arrow_name+'.png')), 0)
template = cv2.resize(template, None, fx=scale, fy=scale, interpolation=cv2.INTER_AREA)
arrow_reachable = False
if arrow_roi.shape[0] >= template.shape[0] and arrow_roi.shape[1] >= template.shape[1]:
_, arrow_score, _, arrow_pos = cv2.minMaxLoc(cv2.matchTemplate(arrow_roi, template, cv2.TM_CCOEFF_NORMED))
sample = arrow_roi[arrow_pos[1]:arrow_pos[1]+template.shape[0],
arrow_pos[0]:arrow_pos[0]+template.shape[1]]
arrow_reachable = arrow_score > .85 and float(np.quantile(sample,.9)) > 90
roi = rgb[max(0,y-radius):min(rgb.shape[0],y+radius), max(0,x-radius):min(rgb.shape[1],x+radius)]
hsv = cv2.cvtColor(roi, cv2.COLOR_RGB2HSV)
red = ((hsv[:,:,0] < 12) | (hsv[:,:,0] > 168)) & (hsv[:,:,1] > 150) & (hsv[:,:,2] > 150)
green = (hsv[:,:,0] > 27) & (hsv[:,:,0] < 85) & (hsv[:,:,1] > 110) & (hsv[:,:,2] > 150)
white = (hsv[:,:,1] < 100) & (hsv[:,:,2] > 175)
colored = int((red | green).sum()) >= 80
if not colored and int(white.sum()) < 80:
cyan = (hsv[:,:,0] >= 80) & (hsv[:,:,0] <= 110) & (hsv[:,:,1] > 110) & (hsv[:,:,2] > 150)
colored = int((red | green | cyan).sum()) >= 80
if not colored and int(white.sum()) < 80 and not arrow_reachable:
continue
target = cv2.resize(cv2.cvtColor(roi, cv2.COLOR_RGB2GRAY), None, fx=2, fy=2)
_, target_desc = orb.detectAndCompute(target, None)
@@ -96,7 +118,7 @@ def map_candidates(state):
score = sum(len(pair) == 2 and pair[0].distance < 0.7*pair[1].distance for pair in matches)
scores.append((score, label))
score, label = max(scores, default=(0, '类型未识别'))
if not colored and score < 8:
if not colored and score < 8 and not arrow_reachable:
continue
if score < 8:
label = '类型未识别'
@@ -122,7 +144,29 @@ def candidates(state, previous_battle=False, refresh_used=0):
}}
# Refresh requests leave the previous stock visible until networking ends.
# Never buy, refresh again, or leave based on that stale inventory.
if any('CONNECTING' in t.upper() for t in texts):
if any(re.search(r'CON+ECTING|LOADING', t.upper()) for t in texts):
return options
if state.get('claim_requested'):
# After claiming, never let the generic Enter action start another run.
if ('探索状态' in texts and '进入' in texts and '探索中' not in texts
or '驾驶席' in texts and '罪人' in texts):
options['run_complete'] = {'description': '奖励领取后已返回大厅,结束本局。',
'action': {'tool': 'run_complete', 'args': {}}}
else:
confirm = next((i for i in items if i['text'].replace(' ', '') in ('确认','继续')
and button_enabled(state, i)), None)
if confirm:
options['modal_confirm'] = {'description': '确认最终领取弹窗。',
'action': {'tool': 'click', 'args': {'x': confirm['x']+confirm['w']//2,
'y': confirm['y']+confirm['h']//2}}}
return options
if death_retry_screen(texts):
return options
if '服务器发生错误' in combined:
retry = next((i for i in items if i['text'].replace(' ', '') == '重试'), None)
if retry:
options['retry_network'] = {'description': '重试当前游戏服务器错误弹窗,不操作背景商店。',
'action': {'tool': 'click', 'args': {'x': retry['x']+retry['w']//2, 'y': retry['y']+retry['h']//2}}}
return options
if '探索完成' in texts:
claim = next((i for i in items if i['text'].replace(' ', '') == '领取'
@@ -134,8 +178,17 @@ def candidates(state, previous_battle=False, refresh_used=0):
'y':claim['y']+claim['h']//2}},
}
return options
if '判定成功' in combined or '判定失败' in combined or '结果' in texts:
continuation = next((i for i in items if i['text'].replace(' ', '') == '继续'
gift_headers = sum(t == '获得E.G.O饰品' for t in texts)
if gift_headers == 1 and '拒绝饰品' in texts and '选择' in texts:
core = any(name in combined for name in ('成捆的符咒','标准负载电池','干巴柴涩鸡胸肉','干松紧致鸡胸肉'))
if core:
return options
target = next(i for i in items if i['text'].replace(' ','') == '拒绝饰品')
options['decline_extra_observation'] = {'description': '拒绝单张无关额外饰品。',
'action': {'tool':'click','args':{'x':target['x']+target['w']//2,'y':target['y']+target['h']//2}}}
return options
if any(t in ('判定成功', '判定失败', '结果') for t in texts):
continuation = next((i for i in items if i['text'].replace(' ', '') in ('继续', '开始战斗')
and button_enabled(state,i)), None)
options['event_finish'] = {
'description': '判定结果已出现,快速连按回车结束事件并返回地图。',
@@ -152,6 +205,9 @@ def candidates(state, previous_battle=False, refresh_used=0):
'y': item['y'] + item['h']//2}},
}
return options
if any('REC' in t.upper() for t in texts) and '选项' not in texts and not any(t in combined for t in ('选择一位罪人', '进行判定', '判定成功', '判定失败', '结果')):
options['event_advance'] = {'description':'事件选项已经确定,按回车快速推进后续文本。', 'action':{'tool':'advance_dialog','args':{'presses':5}}}
return options
if '应该让谁' in combined and '选择一位罪人' not in combined and '进行判定' not in combined:
options['event_advance'] = {
'description': '对话已经跳过,按回车继续到选择罪人的判定界面。',
@@ -193,7 +249,7 @@ def candidates(state, previous_battle=False, refresh_used=0):
target = ('SKILL2', 'SKILL3') if '奥提斯' in header else (
('SKILL1', 'SKILL2') if '辛克莱' in header and state.get('floor', 3) < 3 else ('SKILL1', 'SKILL3'))
target_selected = False
for number, fraction in enumerate((0.235, 0.49, 0.745), 1):
for number, fraction in enumerate((0.244, 0.499, 0.752), 1):
cx = round(width*fraction)
skill_texts = [i for i in items if 'SKILL' in i['text'].upper()
and abs(i['x']+i['w']/2 - (cx + width*.075)) < width*.05
@@ -227,6 +283,11 @@ def candidates(state, previous_battle=False, refresh_used=0):
'y': item['y'] + item['h']//2}},
}
return options
if any('获得E.G.O饰品!' in t or '获得E.G.O饰品!' in t for t in texts):
item=next((i for i in items if i['text'].replace(' ','')=='确认' and width*.4 < i['x']+i['w']/2 < width*.6),None)
if item:
options['modal_confirm']={'description':'按回车快速确认当前获得饰品弹窗。','action':{'tool':'keypress','args':{'key':'enter'}}}
return options
if '追加的苦难' in combined and '获得E.G.O' in combined:
for number, fraction in enumerate((.188, .395, .60, .813), 1):
cx = round(width*fraction)
@@ -242,12 +303,12 @@ def candidates(state, previous_battle=False, refresh_used=0):
if '选择' in item['text'] and '/' in item['text'] and button_enabled(state,item):
options['hardship_confirm'] = {
'description':'选择数量足够后确认层末饰品和苦难,直接前进。',
'action':{'tool':'click','args':{'x':item['x']+item['w']//2,'y':item['y']+item['h']//2}},
'action':{'tool':'keypress','args':{'key':'enter'}},
}
return options
# Nested confirmation/detail windows override the reward/pack behind them.
modal_question = ('确认' in texts and any('取消' in t for t in texts)
and any('吗?' in t or '吗?' in t for t in texts))
and any('吗?' in t or '吗?' in t or '要离开商店吗' in t for t in texts))
pack_detail = '出现头目' in combined and '详细内容' in combined
if modal_question or pack_detail:
buttons = [i for i in items if i['text'].replace(' ', '') == '确认'
@@ -256,11 +317,16 @@ def candidates(state, previous_battle=False, refresh_used=0):
item = min(buttons, key=lambda i: i['y'])
options['modal_confirm'] = {
'description': '确认当前最上层弹窗;不操作背景奖励卡或卡包。',
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w']//2,
'y': item['y'] + item['h']//2}},
'action': ({'tool': 'keypress', 'args': {'key': 'enter'}}
if any('要离开商店吗' in t for t in texts) else
{'tool': 'click', 'args': {'x': item['x'] + item['w']//2,
'y': item['y'] + item['h']//2}}),
}
return options
if any('选择遭遇战奖励卡' in t for t in texts):
for index,item in enumerate(items):
if height*.48 < item['y'] < height*.65 and any(t in item['text'] for t in ('经费', '资源', '体力', '理智')):
options['reward_card_anchor_%d'%index]={'description':'当前奖励卡:'+item['text'], 'action':{'tool':'click','args':{'x':item['x']+item['w']//2,'y':round(item['y']-height*.15)}}}
for number, fraction in enumerate((0.355, 0.514, 0.674), 1):
cx = round(width*fraction)
detail = ';'.join(i['text'] for i in items
@@ -293,6 +359,40 @@ def candidates(state, previous_battle=False, refresh_used=0):
'y': item['y'] + item['h'] // 2}},
}
return options
# The blessing's tier-III choice is not the optional observation. Only
# offer the required Battery, never a generic decline/unchecked confirm.
gift_selection = (any(re.match(r'^(?:选择|可选择)(?:E\.?G\.?O\.?)?饰品', t, re.I) for t in texts)
or '饰品观测' in combined or '拒绝饰品' in texts)
if gift_selection:
battery = next((i for i in items if re.search(r'(标准负载|标准负荷|Standard-duty).*?(电池|Battery)', i['text'], re.I)), None)
unselected = any(re.search(r'(?:选择|可选).*?0/\d', t) for t in texts)
confirm = next((i for i in items if i['text'].replace(' ', '') in ('确认', '选择')
and button_enabled(state, i)), None)
if battery:
if confirm and not unselected:
options['confirm_startup_battery'] = {
'description': '电池选项已可确认,领取开局必需的标准负载电池。',
'action': {'tool': 'click', 'args': {'x': confirm['x']+confirm['w']//2,
'y': confirm['y']+confirm['h']//2}},
}
else:
options['select_startup_battery'] = {
'description': '选择开局必需饰品标准负载电池;此三选一界面不可拒绝。',
'action': {'tool': 'click', 'args': {'x': battery['x']+battery['w']//2,
'y': battery['y']+battery['h']//2}},
}
# Unrecognized choices need analysis; never silently skip a required gift.
# A separately labelled extra observation may still be declined.
elif any(re.search(r'(额外|追加).*观测', t) for t in texts):
refuse = next((i for i in items if i['text'].replace(' ', '') == '拒绝饰品'
and button_enabled(state, i)), None)
if refuse:
options['decline_extra_observation'] = {
'description': '拒绝明确标注的额外观测,不影响开局三级饰品选择。',
'action': {'tool': 'click', 'args': {'x': refuse['x']+refuse['w']//2,
'y': refuse['y']+refuse['h']//2}},
}
return options
if any('选择' in t and '层主题卡包' in t for t in texts):
# This screen has five clipped bags; title OCR anchors each visible bag.
for number, fraction in enumerate((0.17, 0.335, 0.5, 0.665, 0.83), 1):
@@ -311,13 +411,15 @@ def candidates(state, previous_battle=False, refresh_used=0):
'to_x': cx, 'to_y': round(height*.91), 'duration': 1.8}},
}
return options
in_shop = '商店' in texts and '刷新' in texts
in_shop = any(t in ('商店','特殊商店') for t in texts) and '刷新' in texts
party = ('辛克莱', '鸿璐', '希斯克利夫', '奥提斯', '格里高尔', '良秀', '浮士德')
swaps = [(index, item) for index, item in enumerate(items)
if '替换' in item['text'] and any(name in item['text'] for name in party)
and not any('已购买' in sold['text']
and abs(sold['x']+sold['w']/2-item['x']-item['w']/2) < width*.07
and 0 < item['y']-sold['y'] < height*.25 for sold in items)]
if in_shop and state.get('floor', 1) >= 2 and not state.get('symbol_upgraded', False):
return options
if in_shop:
for index, item in swaps:
options['swap_%d' % index] = {
@@ -334,12 +436,12 @@ def candidates(state, previous_battle=False, refresh_used=0):
'y': item['y'] + item['h'] // 2}},
}
end_screen = any(t.upper() in ('VICTORY', 'DEFEAT') or any(m in t for m in
('正在探', '获得E.G.O饰品', '开始战斗', '主题卡包', '应该让谁上前', '选择遭遇战奖励卡')) for t in texts)
battle = any(m in combined.upper() for m in ('WAVE', 'TURN', 'DURANTE', '胜率', '伤害'))
('正在探', '获得E.G.O饰品', '选择E.G.O饰品', '饰品观测', '开始战斗', '主题卡包', '应该让谁', '选择一位罪人', '进行判定', '选择遭遇战奖励卡')) for t in texts)
battle = any(m in combined.upper() for m in ('WAVE', 'TURN', 'DURANTE')) or any(t in ('胜率', '伤害') for t in texts)
if not end_screen and (battle or previous_battle):
options['battle'] = {'description': '仍处于战斗或特写:执行短批次 P→回车,两次后检查结算,不分析拼点。',
'action': {'tool': 'battle', 'args': {'rounds': 2}}}
known_buttons = ('确认', '继续', '进入', '开始战斗', 'SKIP', '进行判定', '拒绝饰品',
known_buttons = ('确认', '继续', '进入', '开始战斗', 'SKIP', '进行判定',
'离开', '下一层', '前往下一层', '领取奖励', '结束探索', 'TOUCHTOSTART', '选择')
for index, item in enumerate(items):
label = item['text'].replace(' ', '')
@@ -423,7 +525,7 @@ def decide(cfg, state, options, recent):
except (OSError, TimeoutError):
if attempt:
raise
time.sleep(0.3)
time.sleep(15)
answer = result.get('answers', {}).get('action', {})
choice = answer.get('choice')
if answer.get('type') != 'choice' or choice not in options:
@@ -431,6 +533,47 @@ def decide(cfg, state, options, recent):
return choice, round((time.monotonic() - start) * 1000)
def fixed_fallback(options):
for key in ('run_complete','select_startup_battery','confirm_startup_battery','decline_extra_observation','retry_network','buy_swap','confirm_swap','confirm_reward','hardship_confirm','modal_confirm','claim_final','close_progress'):
if key in options:
return key
judge=next((k for k in options if k.startswith('button_') and '进行判定' in options[k]['description']),None)
if judge:
return judge
for prefix in ('skill_swap_', 'swap_', 'sinner_card_', 'sinner_'):
keys=[k for k in options if k.startswith(prefix)]
if keys:
return keys[0]
if 'shop_refresh' in options:
return 'shop_refresh'
routes=[k for k in options if k.startswith('route_')]
if routes:
return min(routes,key=lambda k: 0 if '商店' in options[k]['description'] else 1 if '事件' in options[k]['description'] else 3 if '精英' in options[k]['description'] or '集中' in options[k]['description'] else 2)
events=[k for k in options if k.startswith('event_') and k!='event_scroll']
safe=[k for k in events if any(t in options[k]['description'] for t in ('离开','继续走','无视','不理','走开')) and '战斗胜利' not in options[k]['description']]
if safe:
return safe[0]
combat = ('战斗胜利', '进入战斗', '触发遭遇战', '开始战斗')
direct=[k for k in events if not any(t in options[k]['description'] for t in ('判定',)+combat)]
if direct:
return direct[0]
if len(events)==1 and not any(t in options[events[0]]['description'] for t in combat):
return events[0]
if 'event_scroll' in options:
return 'event_scroll'
rewards=[k for k in options if k.startswith('reward_card_')]
if rewards:
return min(rewards,key=lambda k: 0 if '经费' in options[k]['description'] else 1)
buttons=[k for k in options if k.startswith('button_')]
if len(buttons)==1:
return buttons[0]
for text in ('确认','继续','进入','开始战斗','离开'):
match=next((k for k in buttons if text in options[k]['description']),None)
if match:
return match
return 'requires_analysis'
def execute(bridge, action):
if action['tool'] == 'claim_final':
result = bridge.call('click', action['args'])
@@ -473,9 +616,9 @@ def execute(bridge, action):
if not state.get('ok'):
return state
texts = [i['text'].replace(' ', '') for i in text_items(state)]
terminal = any(t.upper() in ('VICTORY', 'DEFEAT') or any(m in t for m in
('正在探', '获得E.G.O饰品', '开始战斗', '主题卡包',
'应该让谁上前', '选择遭遇战奖励卡', '选项事件', '选择苦难')) for t in texts)
terminal = death_retry_screen(texts) or any(t.upper() in ('VICTORY', 'DEFEAT') or any(m in t for m in
('正在探', '获得E.G.O饰品', '选择E.G.O饰品', '饰品观测', '开始战斗', '主题卡包',
'应该让谁', '选择一位罪人', '进行判定', '选择遭遇战奖励卡', '选项事件', '选择苦难', '选项', '结果')) for t in texts)
if terminal:
return {'ok': True, 'pairs': pairs, 'terminal': True, 'screen': state.get('screen')}
return {'ok': True, 'pairs': pairs, 'terminal': False}
@@ -521,6 +664,7 @@ def main():
context = json.loads(context_path.read_text(encoding='utf-8')) if context_path.exists() else {'refresh_used': 0}
stable_since = time.monotonic()
last_fingerprint = None
unknown_since = None
try:
for step in range(args.steps):
if STOP_FILE.exists() or time.monotonic() > deadline:
@@ -531,7 +675,7 @@ def main():
state = {'ok': False, 'items': [{'text': 'MCP 截图暂不可用;游戏窗口可能正在重建。' + str(state.get('error','')),
'x':0,'y':0,'w':0,'h':0,'score':1.0}]}
fingerprint = tuple(item['text'] for item in text_items(state)
if item.get('score', 0) > 0.93 and not item['text'].replace('.', '').isdigit())
if item.get('score', 0) > 0.93 and not item['text'].replace('.', '').isdigit() and not re.fullmatch(r'[0-9:]+', item['text']))
if any('正在探' in i['text'] or '主题卡包' in i['text'] for i in text_items(state)):
context['refresh_used'] = 0
for item in text_items(state):
@@ -540,6 +684,8 @@ def main():
context['floor'] = int(match[1])
context_path.write_text(json.dumps(context), encoding='utf-8')
state['floor'] = context.get('floor', 3)
state['symbol_upgraded'] = context.get('symbol_upgraded', False)
state['claim_requested'] = context.get('claim_requested', False)
options = candidates(state, previous_battle, context['refresh_used'])
if fingerprint != last_fingerprint:
stable_since = time.monotonic()
@@ -561,9 +707,17 @@ def main():
action_id = json.dumps(options[key]['action'], sort_keys=True)
if key not in ('requires_analysis', 'wait', 'battle') and repeats.get((fingerprint, action_id), 0) >= 2:
del options[key]
if len(options) == 2:
unknown_since = unknown_since or time.monotonic()
else:
unknown_since = None
# User explicitly prescribed the complete battle loop. Only scene
# transitions return to Jev; combat does not require new decisions.
if 'event_finish' in options:
if any(re.search(r'CON+ECTING|LOADING', i['text'].upper()) for i in text_items(state)):
choice, latency = 'wait', 0
elif len(options)==2 and time.monotonic() - unknown_since < 10:
choice, latency = 'wait', 0
elif 'event_finish' in options:
choice, latency = 'event_finish', 0
elif 'skip_dialog' in options:
choice, latency = 'skip_dialog', 0
@@ -572,10 +726,27 @@ def main():
elif 'battle' in options:
choice, latency = 'battle', 0
else:
choice, latency = decide(cfg, state, options, recent)
if os.environ.get('LC_FIXED_FALLBACK') == '1':
choice, latency = fixed_fallback(options), 0
else:
choice, latency = decide(cfg, state, options, recent)
action = options[choice]['action']
record = {'step': step, 'choice': choice, 'action': action, 'jev_ms': latency,
'screen': state.get('screen'), 'at': time.strftime('%Y-%m-%dT%H:%M:%S')}
if choice == 'run_complete':
record['state'] = 'completed'
status.write_text(json.dumps(record, ensure_ascii=False), encoding='utf-8')
run_path = RUNTIME_HOME / 'mirror_current_run.json'
if run_path.exists():
from datetime import datetime, timezone
run = json.loads(run_path.read_text(encoding='utf-8'))
now = datetime.now(timezone.utc)
run.update(status='completed', dungeon_completed=True, final_reward_claimed=True,
end_utc=now.isoformat(), elapsed_seconds=(now-datetime.fromisoformat(run['start_utc'])).total_seconds(),
completion_evidence=state.get('screen'))
run_path.write_text(json.dumps(run, ensure_ascii=False, indent=2), encoding='utf-8')
print(json.dumps(record, ensure_ascii=False), flush=True)
return
if choice == 'requires_analysis':
record.update(state='requires_analysis', items=text_items(state))
status.write_text(json.dumps(record, ensure_ascii=False), encoding='utf-8')
@@ -584,6 +755,9 @@ def main():
action_id = json.dumps(action, sort_keys=True)
repeats[(fingerprint, action_id)] = repeats.get((fingerprint, action_id), 0) + 1
result = execute(bridge, action)
if choice == 'claim_final' and result.get('ok'):
context['claim_requested'] = True
context_path.write_text(json.dumps(context), encoding='utf-8')
if choice == 'shop_refresh':
context['refresh_used'] += 1
context_path.write_text(json.dumps(context), encoding='utf-8')
+191 -1
View File
@@ -8,6 +8,153 @@ import jev_mirror_agent as agent
class SceneRegressionTest(unittest.TestCase):
def test_single_extra_gift_decline_preserves_core_and_multi_cards(self):
state = {'items': [{'text':t,'x':100,'y':100,'w':100,'h':40} for t in
('获得E.G.O饰品','石版字符','拒绝饰品','选择')]}
self.assertIn('decline_extra_observation', agent.candidates(state))
state['items'][1]['text'] = '标准负载电池'
self.assertNotIn('decline_extra_observation', agent.candidates(state))
state['items'][1]['text'] = '石版字符'
state['items'].append({'text':'获得E.G.O饰品'})
self.assertNotIn('decline_extra_observation', agent.candidates(state))
def test_special_shop_cannot_leave_before_core_upgrade(self):
state = {'floor':2, 'symbol_upgraded':False, 'items':[
{'text':t, 'x':100,'y':100,'w':100,'h':40} for t in
('特殊商店','刷新','强化饰品','替换格里高尔的技能','替换浮士德的技能','离开')]}
self.assertEqual(set(agent.candidates(state)), {'wait','requires_analysis'})
state['symbol_upgraded'] = True
options = agent.candidates(state)
self.assertTrue(any(k.startswith('swap_') for k in options))
self.assertFalse(any('离开' in v['description'] for v in options.values()))
def test_purple_shop_is_reachable_by_lit_arrow(self):
import numpy as np
from PIL import Image
assets = agent.REPO_ROOT / 'vendor' / 'aalc' / 'assets' / 'images' / 'default' / 'share' / 'mirror'
canvas = Image.new('RGB', (1920,1080))
def place(name, center, purple=False):
with Image.open(assets / name) as im:
im = im.convert('RGB').resize((round(im.width*.75),round(im.height*.75)))
if name.endswith('mid.png'):
from PIL import ImageEnhance
im = ImageEnhance.Brightness(im).enhance(1.8)
if purple:
gray = np.array(im.convert('L'), dtype=float)
im = Image.fromarray(np.stack((gray*.55,gray*.25,gray*.8),axis=2).astype('uint8'))
canvas.paste(im,(center[0]-im.width//2,center[1]-im.height//2))
place('mybus_default_distance.png',(704,396))
place('road_in_mir/mid.png',(895,430))
place('road_in_mir/shop.png',(1079,433),True)
with tempfile.TemporaryDirectory() as folder:
shot = Path(folder) / 'purple_shop.png'
canvas.save(shot)
options = agent.map_candidates({'screen': {'path': str(shot)}})
self.assertEqual(set(options), {'route_d'})
self.assertIn('商店', options['route_d']['description'])
def test_claimed_rewards_stop_at_lobby_without_entering_again(self):
state = {'claim_requested': True, 'items': [{'text': t} for t in ('探索状态','进入','名与蛛之镜')]}
options = agent.candidates(state)
self.assertEqual(set(options), {'wait','requires_analysis','run_complete'})
self.assertEqual(agent.fixed_fallback(options), 'run_complete')
state['items'].append({'text':'探索中'})
self.assertEqual(set(agent.candidates(state)), {'wait','requires_analysis'})
@mock.patch.object(agent, 'button_enabled', return_value=True)
def test_claim_confirmation_only_uses_modal(self, _enabled):
state = {'claim_requested': True, 'items': [
{'text':'确认','x':800,'y':700,'w':100,'h':40}, {'text':'进入'}]}
options = agent.candidates(state)
self.assertEqual(set(options), {'wait','requires_analysis','modal_confirm'})
self.assertEqual(options['modal_confirm']['action']['args'], {'x':850,'y':720})
def test_death_screen_stops_battle_candidates_without_accepting_deaths(self):
state = {'items': [{'text': text} for text in ('参加战斗的全体罪人已经死亡。', '重试关卡')]}
self.assertEqual(set(agent.candidates(state, previous_battle=True)), {'wait', 'requires_analysis'})
self.assertFalse(agent.death_retry_screen(['敌方死亡时增加伤害']))
@mock.patch.object(agent.time, 'sleep')
def test_battle_macro_stops_on_party_death(self, _sleep):
bridge = mock.Mock()
bridge.call.side_effect = lambda tool, args=None: ({'ok': True, 'items': [{'text': '参加战斗的全体罪人已经死亡。'}]}
if tool == 'get_state' else {'ok': True})
with mock.patch.object(agent, 'STOP_FILE') as stop:
stop.exists.return_value = False
result = agent.execute(bridge, {'tool': 'battle', 'args': {}})
self.assertTrue(result['terminal'])
self.assertEqual(result['pairs'], 2)
@mock.patch.object(agent, 'button_enabled', return_value=True)
def test_startup_three_gifts_selects_battery_and_cannot_decline(self, _enabled):
state = {'items': [{'text': text, 'x': x, 'y': y, 'w': 100, 'h': 40}
for text, x, y in [('选择E.G.O饰品', 700, 80), ('可选择0/1', 1300, 80),
('标准负载电池', 800, 480), ('拒绝饰品', 1400, 850),
('确认', 1500, 950)]]}
options = agent.candidates(state, previous_battle=True)
self.assertEqual(set(options), {'wait', 'requires_analysis', 'select_startup_battery'})
self.assertEqual(options['select_startup_battery']['action']['args'], {'x': 850, 'y': 500})
self.assertEqual(agent.fixed_fallback(options), 'select_startup_battery')
state['items'][1]['text'] = '可选择1/1'
options = agent.candidates(state)
self.assertEqual(set(options), {'wait', 'requires_analysis', 'confirm_startup_battery'})
self.assertEqual(options['confirm_startup_battery']['action']['args'], {'x': 1550, 'y': 970})
@mock.patch.object(agent, 'button_enabled', return_value=True)
def test_unrecognized_gift_choice_is_never_declined(self, _enabled):
state = {'items': [{'text': text, 'x': 100, 'y': 100, 'w': 100, 'h': 40}
for text in ('选择E.G.O饰品', '可选择0/1', '拒绝饰品', '确认')]}
self.assertEqual(set(agent.candidates(state)), {'wait', 'requires_analysis'})
state['items'] = [state['items'][2]]
self.assertEqual(set(agent.candidates(state)), {'wait', 'requires_analysis'})
@mock.patch.object(agent, 'button_enabled', return_value=True)
def test_explicit_extra_observation_can_be_declined(self, _enabled):
state = {'items': [{'text': text, 'x': 100, 'y': 100, 'w': 100, 'h': 40}
for text in ('额外E.G.O饰品观测', '拒绝饰品')]}
self.assertEqual(set(agent.candidates(state)), {'wait', 'requires_analysis', 'decline_extra_observation'})
def test_event_gift_outcome_does_not_become_startup_selection(self):
state = {'items': [{'text': '选项', 'x': 20, 'y': 20, 'w': 100, 'h': 40},
{'text': '按下闪电形状的按钮', 'x': 1200, 'y': 330, 'w': 350, 'h': 40, 'score': 1},
{'text': '选择后获得破裂饰品', 'x': 1200, 'y': 380, 'w': 350, 'h': 40, 'score': 1}]}
self.assertIn('event_1', agent.candidates(state))
def test_server_error_blocks_shop_and_retries_modal(self):
state = {'items': [
{'text': '商店'}, {'text': '刷新'}, {'text': '服务器发生错误。'},
{'text': '重试', 'x': 1069, 'y': 681, 'w': 74, 'h': 41},
{'text': '离开', 'x': 1642, 'y': 938, 'w': 116, 'h': 66}]}
options = agent.candidates(state)
self.assertEqual(set(options), {'wait', 'requires_analysis', 'retry_network'})
self.assertEqual(agent.fixed_fallback(options), 'retry_network')
self.assertEqual(options['retry_network']['action']['args'], {'x': 1106, 'y': 701})
def test_gift_damage_description_is_not_battle(self):
state = {'items': [{'text': '使用技能造成12点伤害时增加破裂强度', 'x': 400, 'y': 200, 'w': 800, 'h': 40}]}
self.assertNotIn('battle', agent.candidates(state))
def test_success_condition_in_event_option_is_not_result(self):
state = {'items': [{'text': '判定成功时获得饰品', 'x': 400, 'y': 200, 'w': 800, 'h': 40}]}
self.assertNotIn('event_finish', agent.candidates(state))
def test_loading_ocr_missing_n_blocks_input(self):
state = {'items': [{'text': 'CONECTING'}, {'text': '商店'}, {'text': '刷新'}]}
self.assertEqual(set(agent.candidates(state)), {'wait', 'requires_analysis'})
def test_fallback_judgement_precedes_reselecting_sinner(self):
options = {'sinner_card_1': {'description': '极高'},
'button_2': {'description': '进行判定'}}
self.assertEqual(agent.fixed_fallback(options), 'button_2')
def test_two_card_reward_uses_observed_anchor(self):
state = {'screen': {'w': 1920, 'h': 1080}, 'items': [
{'text': '选择遭遇战奖励卡', 'x': 800, 'y': 80, 'w': 300, 'h': 40},
{'text': '获得经费', 'x': 1120, 'y': 560, 'w': 100, 'h': 40}]}
options = agent.candidates(state)
self.assertEqual(options['reward_card_anchor_1']['action']['args'], {'x': 1170, 'y': 398})
self.assertEqual(agent.fixed_fallback(options), 'reward_card_anchor_1')
@mock.patch.object(agent.time, 'sleep')
def test_final_claim_click_is_followed_by_enter(self, _sleep):
bridge = mock.Mock()
@@ -116,7 +263,7 @@ class SceneRegressionTest(unittest.TestCase):
options = agent.candidates({'items': items}, previous_battle=True)
self.assertEqual(set(options), {'wait', 'requires_analysis', 'modal_confirm'})
self.assertEqual(options['modal_confirm']['action'],
{'tool': 'click', 'args': {'x': 1140, 'y': 620}})
{'tool': 'keypress', 'args': {'key': 'enter'}})
@mock.patch.object(agent, 'button_enabled', return_value=True)
def test_nested_reward_confirmation_excludes_background_cards(self, _enabled):
@@ -129,6 +276,17 @@ class SceneRegressionTest(unittest.TestCase):
self.assertEqual(set(options), {'wait', 'requires_analysis', 'modal_confirm'})
self.assertEqual(options['modal_confirm']['action']['args']['y'], 699)
@mock.patch.object(agent, 'button_enabled', return_value=True)
def test_shop_leave_modal_without_ocr_question_mark(self, _enabled):
state = {'symbol_upgraded': True, 'items': [
{'text': t, 'x': x, 'y': y, 'w': 100, 'h': 40}
for t,x,y in [('特殊商店',307,162), ('刷新',1496,167),
('要离开商店吗',854,505), ('×取消',721,722),
('确认',1140,723), ('离开',1642,938)]]}
options = agent.candidates(state, refresh_used=4)
self.assertEqual(set(options), {'wait','requires_analysis','modal_confirm'})
self.assertEqual(options['modal_confirm']['action'], {'tool':'keypress','args':{'key':'enter'}})
@mock.patch.object(agent, 'button_enabled', return_value=True)
def test_event_result_uses_visible_continue_button(self, _enabled):
state = {'items':[{'text':t,'x':x,'y':y,'w':80,'h':40}
@@ -143,6 +301,21 @@ class SceneRegressionTest(unittest.TestCase):
options = agent.candidates(state)
self.assertEqual(set(options), {'wait', 'requires_analysis'})
def test_event_fallback_does_not_treat_encounter_trigger_as_free_reward(self):
options = {'event_1': {'description': '拔出荧光灯;触发遭遇战!'},
'event_scroll': {'description': '查看其他选项'},
'wait': {}, 'requires_analysis': {}}
self.assertEqual(agent.fixed_fallback(options), 'event_scroll')
del options['event_scroll']
self.assertEqual(agent.fixed_fallback(options), 'requires_analysis')
@mock.patch.object(agent, 'button_enabled', return_value=True)
def test_event_encounter_result_clicks_start_battle(self, _enabled):
state = {'items': [{'text': t, 'x': x, 'y': y, 'w': 100, 'h': 40}
for t,x,y in [('结果',1088,162), ('开始战斗',1594,943)]]}
self.assertEqual(agent.candidates(state)['event_finish']['action'],
{'tool':'click','args':{'x':1644,'y':963}})
@mock.patch.object(agent, 'button_enabled', return_value=True)
def test_shop_loading_blocks_stale_stock_refresh_and_leave(self, _enabled):
state = {'items': [{'text': text, 'x': 100, 'y': 100, 'w': 100, 'h': 40}
@@ -166,6 +339,23 @@ class SceneRegressionTest(unittest.TestCase):
state = {'items': [{'text': '破裂+5', 'x': 100, 'y': 10, 'w': 80, 'h': 40}]}
self.assertIn('battle', agent.candidates(state, previous_battle=True))
@mock.patch.object(agent, 'button_enabled', return_value=False)
def test_in_battle_judgement_overrides_previous_battle(self, _enabled):
state = {'items': [{'text': t, 'x':100, 'y':100, 'w':100, 'h':40}
for t in ('选择一位罪人来进行判定', '判定阈值', '12')]}
self.assertNotIn('battle', agent.candidates(state, previous_battle=True))
def test_battle_macro_stops_at_judgement_before_more_inputs(self):
bridge = mock.Mock()
bridge.call.side_effect = ([{'ok': True}] * 4 + [
{'ok': True, 'items': [{'text': '选择一位罪人来进行判定'}]}])
with mock.patch.object(agent, 'STOP_FILE') as stop, mock.patch.object(agent.time, 'sleep'):
stop.exists.return_value = False
result = agent.execute(bridge, {'tool': 'battle', 'args': {}})
self.assertTrue(result['terminal'])
self.assertEqual(result['pairs'], 2)
self.assertEqual(bridge.call.call_count, 5)
def test_reward_stops_battle_candidates(self):
state = {'items': [{'text': text, 'x': 100, 'y': 10, 'w': 80, 'h': 40}
for text in ('获得E.G.O饰品', '造成更多伤害')]}
+23
View File
@@ -156,6 +156,29 @@ class AalcTaskArgsTest(unittest.TestCase):
class RuntimeTest(unittest.TestCase):
def test_background_click_holds_and_releases_without_moving_window(self):
from lc_mcp.aalc_engine import AalcEngine
engine = AalcEngine.__new__(AalcEngine)
engine.cfg = mock.Mock(simulator=False, win_input_type='background')
engine.auto, engine.screen = mock.Mock(), mock.Mock()
handler = mock.Mock(spec=['set_mouse_pos','set_active','mouse_down','mouse_up'])
engine.auto.input_handler = handler
sequence = mock.Mock()
sequence.attach_mock(handler.mouse_down, 'down')
sequence.attach_mock(handler.mouse_up, 'up')
with mock.patch('lc_mcp.aalc_engine.time.sleep') as sleep:
sequence.attach_mock(sleep, 'sleep')
engine.click(100, 200)
self.assertEqual(sequence.mock_calls, [mock.call.down(100, 200),
mock.call.sleep(.12), mock.call.up(100, 200),
mock.call.sleep(.12)])
engine.auto.mouse_click.assert_not_called()
with mock.patch('lc_mcp.aalc_engine.time.sleep', side_effect=RuntimeError('interrupted')):
with self.assertRaises(RuntimeError):
engine.click(100, 200)
self.assertEqual(handler.mouse_up.call_count, 2)
engine.screen.handle.set_window_pos.assert_not_called()
def test_background_keypress_holds_and_releases_on_error(self):
from lc_mcp.aalc_engine import AalcEngine
engine = AalcEngine.__new__(AalcEngine)