This website requires JavaScript.
0
Issues
Pull Requests
Milestones
Explore
0
Create…
New Repository
New Migration
New Organization
public
Signed in as
public
Profile
Starred
Subscriptions
Settings
Help
Sign Out
yws
/
lc-mcp
Watch
1
Star
0
Fork
0
Code
Issues
Pull Requests
Actions
Packages
Projects
Releases
Wiki
Activity
Files
lc-mcp
/
lc_mcp
/
or
Cancel
Edit File
Preview
Preview Changes
Spaces
Tabs
2
4
8
Wrap
No wrap
# -*- coding: utf-8 -*- """子进程入口: 跑 AALC 现成的任务流程。 用法: python -m lc_mcp.aalc_task <task> [json_params] python -m lc_mcp.aalc_task --restore <file> 写回被强杀任务临时覆盖的配置 放在子进程里跑, 停止 = 杀进程树; 不会像 QThread.terminate 那样留下被占用的锁。 """ import json import os import sys from . import killswitch, preflight from .aalc_engine import bootstrap from .aalc_patches import (WindowGuard, driver_click_tasks, install_exact_team_match, install_robust_set_foreground, stop_driver_click) # 任务 -> {参数名: AALC 配置项}; 参数只在本次运行内生效 TASKS = { 'all': {}, # 完全按 config.yaml 里勾选的任务跑, 等价于 AALC 界面点"开始" 'daily': {'exp': 'set_EXP_count', 'thread': 'set_thread_count'}, 'reward': {}, 'enkephalin': {'times': 'set_lunacy_to_enkephalin'}, 'mirror': {'count': 'set_mirror_count'}, } RESTORE_ENV = 'LCP_RESTORE_FILE' PREFLIGHT_EXIT = 3 def log(msg): print(msg, flush=True) 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} 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)) return originals def restore(cfg, originals, restore_path=None): for key, value in originals.items(): cfg.set_value(key, value) if originals: cfg.flush() if restore_path and os.path.exists(restore_path): os.remove(restore_path) def restore_file(path, cfg=None): with open(path, encoding='utf-8') as f: originals = json.load(f) if cfg is None: bootstrap() from module.config import cfg restore(cfg, originals, path) def run(task, params): bootstrap() from module.automation import auto from module.config import cfg from module.game_and_screen import screen from tasks.base import script_task_scheme as scheme from tasks.base.retry_monitor import retry_monitor from tasks.battle import battle 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, 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 install_exact_team_match(auto, log) install_robust_set_foreground(screen, log=log) guard = WindowGuard(screen, cfg, log=log) 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): try: if task == 'all': scheme.script_task() return 0 # 与 script_task() 相同的前置步骤 scheme.init_game() path_manager.initialize_paths() auto.clear_img_cache() 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): if len(argv) == 3 and argv[1] == '--restore': restore_file(argv[2]) print('[lc_mcp] restored config from %s' % argv[2], flush=True) return 0 if len(argv) < 2 or argv[1] not in TASKS: print('usage: python -m lc_mcp.aalc_task <%s> [json]' % '|'.join(TASKS), file=sys.stderr) return 2 task = argv[1] params = json.loads(argv[2]) if len(argv) > 2 else {} unknown = set(params) - set(TASKS[task]) if unknown: print('unknown params for %s: %s' % (task, ', '.join(sorted(unknown))), file=sys.stderr) return 2 print('[lc_mcp] task %s start %s' % (task, json.dumps(params)), flush=True) code = run(task, params) if code: print('[lc_mcp] task %s aborted (exit %s)' % (task, code), flush=True) return code print('[lc_mcp] task %s done' % task, flush=True) return 0 if __name__ == '__main__': sys.exit(main(sys.argv))
Commit Changes
Add a Signed-off-by trailer by the committer at the end of the commit log message.
Commit directly to the
codex/local-wip-20261022
branch.
Create a
new branch
for this commit and start a pull request.
Commit Changes
Cancel