合并前复核:补齐急停释放、整轮中止和计划任务时限

Browse Source
This commit is contained in:
yws
2026-10-22 07:32:58 +00:00
parent 8a9495b185
commit a74fda07e2
14 changed files with 324 additions and 111 deletions
+39 -43
View File
@@ -9,11 +9,10 @@ import json
import os import os
import sys import sys
from . import preflight from . import killswitch, preflight
from .aalc_engine import bootstrap from .aalc_engine import bootstrap
from . import killswitch
from .aalc_patches import (WindowGuard, driver_click_tasks, install_exact_team_match, from .aalc_patches import (WindowGuard, driver_click_tasks, install_exact_team_match,
install_robust_set_foreground) install_robust_set_foreground, stop_driver_click)
# 任务 -> {参数名: AALC 配置项}; 参数只在本次运行内生效 # 任务 -> {参数名: AALC 配置项}; 参数只在本次运行内生效
TASKS = { TASKS = {
@@ -76,48 +75,45 @@ def run(task, params):
from tasks.battle import battle from tasks.battle import battle
from utils.path_manager import path_manager from utils.path_manager import path_manager
# 急停热键: 装得越早越好。驱动级点击期间鼠标被人和程序抢来抢去, with killswitch.listening(log=log, on_stop=lambda: stop_driver_click(auto)):
# 用户没法用鼠标点停止按钮, 键盘是唯一可靠的中断手段。 problems = preflight.check(preflight.collect(cfg), task,
kill_listener = killswitch.install(log=log) desktop=None if cfg.simulator else preflight.desktop_size())
if problems:
for p in problems:
log('[ERROR] [lc_mcp] preflight: %s' % p)
return PREFLIGHT_EXIT
problems = preflight.check(preflight.collect(cfg), task, install_exact_team_match(auto, log)
desktop=None if cfg.simulator else preflight.desktop_size()) install_robust_set_foreground(screen, log=log)
if problems: guard = WindowGuard(screen, cfg, log=log)
for p in problems: guard.start()
log('[ERROR] [lc_mcp] preflight: %s' % p) restore_path = os.environ.get(RESTORE_ENV)
return PREFLIGHT_EXIT originals = apply_overrides(cfg, task, params, restore_path)
with driver_click_tasks(scheme, auto, screen, cfg, log=log):
install_exact_team_match(auto, log) try:
install_robust_set_foreground(screen, log=log) if task == 'all':
guard = WindowGuard(screen, cfg, log=log) scheme.script_task()
guard.start() return 0
restore_path = os.environ.get(RESTORE_ENV) # 与 script_task() 相同的前置步骤
originals = apply_overrides(cfg, task, params, restore_path) scheme.init_game()
with driver_click_tasks(scheme, auto, screen, cfg, log=log): path_manager.initialize_paths()
try: auto.clear_img_cache()
if task == 'all': retry_monitor.start()
scheme.script_task() get_reward = None
if auto.click_element('battle/turn_assets.png', take_screenshot=True):
print('[lc_mcp] 检测到正在战斗, 先打完', flush=True)
get_reward = battle.fight()
{
'daily': scheme.Daily_task_wrapper(get_reward=get_reward),
'reward': scheme.to_get_reward,
'enkephalin': scheme.Buy_enkephalin,
'mirror': scheme.Mirror_task,
}[task]()
return 0 return 0
# 与 script_task() 相同的前置步骤 finally:
scheme.init_game() guard.stop()
path_manager.initialize_paths() retry_monitor.stop()
auto.clear_img_cache() restore(cfg, originals, restore_path)
retry_monitor.start()
get_reward = None
if auto.click_element('battle/turn_assets.png', take_screenshot=True):
print('[lc_mcp] 检测到正在战斗, 先打完', flush=True)
get_reward = battle.fight()
{
'daily': scheme.Daily_task_wrapper(get_reward=get_reward),
'reward': scheme.to_get_reward,
'enkephalin': scheme.Buy_enkephalin,
'mirror': scheme.Mirror_task,
}[task]()
return 0
finally:
guard.stop()
retry_monitor.stop()
restore(cfg, originals, restore_path)
def main(argv): def main(argv):