普通镜牢转交 AALC,核对镜牢实际完成局数,合成与任务互斥
转交与互斥(原未提交改动,合入选队分支后提交): - MCP 初始化说明和工具描述引导常规日常/领奖/普通镜牢走 task_status -> run_task -> 轮询;jev_mirror_agent 默认转交 AALC, 明确的速通配置、决策模型或未完成速通局仍走逐步模式。 - 新增 ~/lc_mcp/game.lock:run_task 子进程与模块合成脚本互斥, 合成脚本另查 task_status,状态不明时不接管游戏。 - all 任务的 HDR 提示无 GUI 时直接确认并记录;预检按窗口位置 决定是否计标题栏,set_windows=false 跳过;levelup card/weakest 同步失败返回非零。急停提示改为 End 键。 镜牢结果(对接文档指出的缺口): - 预检拒绝空队列和没有适用当前难度队伍的配置:AALC 会一局不打 就以 0 退出。可用判定与 Mirror_task 的固定用途规则一致。 - 监听 mirror_signal 统计实际完成局数;少于应打局数记 [ERROR] 并以退出码 4 结束,task_status 为 failed。 - mirror 指定 count 时临时关闭 infinite_dungeons(否则次数变成 9999),原值写入恢复文件,结束或强杀后写回。 验证:Linux / Python 3.12 全套 507 项通过;git diff --check 通过。 用上游真实 Mirror_task 回放了无可用队伍和正常完成两种情况; Windows 实机仍需回归。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+46
-10
@@ -11,9 +11,11 @@ import sys
|
||||
|
||||
from . import killswitch, preflight
|
||||
from .aalc_engine import bootstrap
|
||||
from .aalc_patches import (WindowGuard, driver_click_tasks, install_default_battle_team,
|
||||
install_exact_team_match, install_robust_set_foreground,
|
||||
install_system_team_selection, stop_driver_click)
|
||||
from .aalc_patches import (WindowGuard, driver_click_tasks, headless_hdr_warning,
|
||||
install_default_battle_team, install_exact_team_match,
|
||||
install_robust_set_foreground, install_system_team_selection,
|
||||
mirror_progress, stop_driver_click)
|
||||
from .game_lock import GameBusyError, exclusive_game
|
||||
|
||||
# 任务 -> {参数名: AALC 配置项}; 参数只在本次运行内生效
|
||||
TASKS = {
|
||||
@@ -23,8 +25,11 @@ TASKS = {
|
||||
'enkephalin': {'times': 'set_lunacy_to_enkephalin'},
|
||||
'mirror': {'count': 'set_mirror_count'},
|
||||
}
|
||||
# 用户给了镜牢次数时一并临时关闭的配置: 开着无限刷牢, AALC 会把次数改成 9999
|
||||
EXPLICIT_COUNT_OVERRIDES = {'mirror': {'count': {'infinite_dungeons': False}}}
|
||||
RESTORE_ENV = 'LCP_RESTORE_FILE'
|
||||
PREFLIGHT_EXIT = 3
|
||||
INCOMPLETE_EXIT = 4 # AALC 正常返回, 但镜牢完成局数少于应打局数
|
||||
|
||||
|
||||
def log(msg):
|
||||
@@ -37,17 +42,37 @@ def apply_overrides(cfg, task, params, restore_path=None):
|
||||
AALC 运行中会整份保存配置(如镜牢后 rotate_team_queue), 覆盖值会被写进 config.yaml。
|
||||
所以先把原值落盘: 进程被 stop_task 强杀、finally 来不及执行时, TaskRunner 据此写回。
|
||||
"""
|
||||
originals = {TASKS[task][name]: cfg.get_value(TASKS[task][name]) for name in params}
|
||||
overrides = {TASKS[task][name]: int(value) for name, value in params.items()}
|
||||
for name in params:
|
||||
overrides.update(EXPLICIT_COUNT_OVERRIDES.get(task, {}).get(name, {}))
|
||||
originals = {key: cfg.get_value(key) for key in overrides}
|
||||
if originals and restore_path:
|
||||
tmp = restore_path + '.tmp'
|
||||
with open(tmp, 'w', encoding='utf-8') as f:
|
||||
json.dump(originals, f, ensure_ascii=False)
|
||||
os.replace(tmp, restore_path)
|
||||
for name, value in params.items():
|
||||
cfg.unsaved_set_value(TASKS[task][name], int(value))
|
||||
for key, value in overrides.items():
|
||||
if key == 'infinite_dungeons' and originals.get(key):
|
||||
log('[lc_mcp] 本次按指定次数运行镜牢, 临时关闭无限刷牢, 结束后恢复')
|
||||
cfg.unsaved_set_value(key, value)
|
||||
return originals
|
||||
|
||||
|
||||
def mirror_result(task, progress):
|
||||
"""按 AALC 实际完成局数给出退出码; 退出码 0 不再代表"一局没打"。"""
|
||||
if progress.total is None:
|
||||
if task != 'mirror':
|
||||
return 0 # all 没勾选镜牢
|
||||
log('[ERROR] [lc_mcp] 镜牢任务结束, 但没收到 AALC 的镜牢进度, 不能确认完成局数')
|
||||
return INCOMPLETE_EXIT
|
||||
log('[lc_mcp] 镜牢完成 %d/%d 局' % (progress.finished, progress.total))
|
||||
if progress.finished < progress.total:
|
||||
log('[ERROR] [lc_mcp] 镜牢只完成 %d/%d 局: AALC 正常返回, 但没有打完'
|
||||
'(常见原因: 没有适用当前难度的队伍、队列为空)' % (progress.finished, progress.total))
|
||||
return INCOMPLETE_EXIT
|
||||
return 0
|
||||
|
||||
|
||||
def restore(cfg, originals, restore_path=None):
|
||||
for key, value in originals.items():
|
||||
cfg.set_value(key, value)
|
||||
@@ -67,6 +92,15 @@ def restore_file(path, cfg=None):
|
||||
|
||||
|
||||
def run(task, params):
|
||||
try:
|
||||
with exclusive_game():
|
||||
return _run(task, params)
|
||||
except GameBusyError as e:
|
||||
log('[ERROR] [lc_mcp] %s' % e)
|
||||
return PREFLIGHT_EXIT
|
||||
|
||||
|
||||
def _run(task, params):
|
||||
bootstrap()
|
||||
from module.automation import auto
|
||||
from module.config import cfg
|
||||
@@ -97,11 +131,13 @@ def run(task, params):
|
||||
guard.start()
|
||||
restore_path = os.environ.get(RESTORE_ENV)
|
||||
originals = apply_overrides(cfg, task, params, restore_path)
|
||||
with driver_click_tasks(scheme, auto, screen, cfg, log=log):
|
||||
with driver_click_tasks(scheme, auto, screen, cfg, log=log), \
|
||||
mirror_progress(scheme) as progress:
|
||||
try:
|
||||
if task == 'all':
|
||||
scheme.script_task()
|
||||
return 0
|
||||
with headless_hdr_warning(scheme, log=log):
|
||||
scheme.script_task()
|
||||
return mirror_result(task, progress)
|
||||
# 与 script_task() 相同的前置步骤
|
||||
scheme.init_game()
|
||||
path_manager.initialize_paths()
|
||||
@@ -117,7 +153,7 @@ def run(task, params):
|
||||
'enkephalin': scheme.Buy_enkephalin,
|
||||
'mirror': scheme.Mirror_task,
|
||||
}[task]()
|
||||
return 0
|
||||
return mirror_result(task, progress)
|
||||
finally:
|
||||
guard.stop()
|
||||
retry_monitor.stop()
|
||||
|
||||
Reference in New Issue
Block a user