Skip to content

Commit 36fd172

Browse files
committed
perf(executor): 开局 0 帧暂停稳定性大幅提升
- _pause_at_battle_start 重写:去掉 BattleOn OCR 等待 + sleep + 颜色检测, 简化为纯 F 轮询 + 单帧 Play.png 确认,while True 覆盖加载期 - farm.json: BattleOn 节点注释,executor 在加载阶段即启动 - 原先 ~1.7s 降至 ~0.4s,0 帧暂停稳定性大幅提升
1 parent 5a9dfd4 commit 36fd172

2 files changed

Lines changed: 30 additions & 38 deletions

File tree

custom/action/executor.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -439,44 +439,36 @@ def _pause_at_battle_start(
439439
ctrl: Controller,
440440
context_tasker_stopping: Callable[[], bool],
441441
) -> bool:
442-
"""开局 0 帧暂停: 等 BattleOfficiallyBegin → 狂按 F → 等 Play.png.
442+
"""开局 0 帧暂停: 持续发 F(→AFA→ESC) 直到 Play.png 出现。
443443
444-
不发 R 验证, 避免 0 帧被推进.
444+
加载期间 ESC 无效;游戏一活立刻被 F→AFA→ESC 停住。
445+
不需要等 BattleOn 或做颜色检测——啥都不等,直接开始按。
445446
"""
446-
# 1. 等 BattleOfficiallyBegin 出现 (战斗加载完成, 可操作)
447-
logger.debug("开局暂停: 等待战斗加载完成")
448-
for _ in range(50):
449-
if context_tasker_stopping():
450-
return False
451-
time.sleep(0.2)
452-
img = self._screenshot(ctrl)
453-
if img is None:
454-
continue
455-
reco = context.run_recognition("Farm@BattleOn", img)
456-
if reco and reco.hit:
457-
logger.debug("开局暂停: 战斗已加载")
458-
break
459-
else:
460-
logger.error("开局暂停: 等待战斗加载超时")
461-
return False
447+
_TIMEOUT_S = 30.0
448+
t0 = time.monotonic()
449+
deadline = t0 + _TIMEOUT_S
450+
i = 0
451+
logger.debug("开局暂停: 持续 ESC(加载期无效,一活即停,超时 %.0fs)", _TIMEOUT_S)
462452

463-
# 2. 狂按 F 直到 Play.png 出现
464-
for i in range(50):
453+
while time.monotonic() < deadline:
465454
if context_tasker_stopping():
466455
return False
456+
i += 1
467457
self._tap_afa(afa_hotkey.VK_F, "F 开局暂停")
468458
self._paused = True
469-
time.sleep(0.03)
470459
img = self._screenshot(ctrl)
471-
if img is None:
472-
continue
473-
reco = context.run_recognition("BattlePaused", img)
474-
if reco and reco.hit:
475-
logger.debug("开局暂停成功 (Play.png 命中), attempt=%d", i + 1)
476-
return True
477-
logger.debug("开局暂停: Play.png 未命中, attempt=%d", i + 1)
460+
if img is not None:
461+
reco = context.run_recognition("BattlePaused", img)
462+
if reco and reco.hit:
463+
t1 = time.monotonic()
464+
logger.info(
465+
"开局暂停成功 | 总计=%.2fs (%d 次 F)",
466+
t1 - t0,
467+
i,
468+
)
469+
return True
478470

479-
logger.error("开局暂停: 按 F 50 次仍未暂停")
471+
logger.error("开局暂停: 超时(%.0fs, %d 次 F)", _TIMEOUT_S, i)
480472
self._paused = False
481473
return False
482474

resource/base/pipeline/farm.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@
9595
]
9696
},
9797
"Farm@BattleOn": {
98-
"desc": "等战斗正式加载",
99-
"recognition": "TemplateMatch",
100-
"roi": [
101-
1186,
102-
18,
103-
60,
104-
60
105-
],
106-
"template": "BattleOfficiallyBegin.png",
98+
// "desc": "等战斗正式加载",
99+
// "recognition": "TemplateMatch",
100+
// "roi": [
101+
// 1186,
102+
// 18,
103+
// 60,
104+
// 60
105+
// ],
106+
// "template": "BattleOfficiallyBegin.png",
107107
"next": [
108108
"Farm@Execute"
109109
]

0 commit comments

Comments
 (0)