# -*- coding: utf-8 -*- """一轮自动推进: 刷材料 -> 升级最弱人格 -> 同步 -> 报告。 用法: python auto_cycle.py [--rounds N] 退出码: 0 正常完成一轮 / 1 失败 设计: 只做"一轮",不做无限循环——由外层(goal 轮次)负责重复与判断, 避免无人监督地长时间空转。每轮输出结构化报告供上层核对。 """ import json import subprocess import sys import time PY = r'D:\lc-mcp\vendor\aalc\.venv\Scripts\python.exe' HERE = r'D:\lc-mcp\scripts' PROBE = HERE + r'\mcp_probe.py' LEVELUP = HERE + r'\levelup.py' # 导航 BTN_SINNERS = (1130, 805) # 主界面底部 Sinners TAB_ALL_IDENTITIES = (1472, 245) # TEAMS 页 -> All Identities # daily 轮询上限 DAILY_TIMEOUT_S = 45 * 60 def run(cmd): r = subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8', errors='replace') return (r.stdout or '') + (r.stderr or '') def probe(tool, args=None): cmd = [PY, '-X', 'utf8', PROBE, tool] if args is not None: cmd.append(json.dumps(args, ensure_ascii=False)) out = run(cmd) for line in reversed(out.strip().splitlines()): line = line.strip() if line.startswith('{'): try: return json.loads(line) except json.JSONDecodeError: continue return {} def click(x, y): return probe('click', {'x': int(x), 'y': int(y), 'times': 1}) def log(msg): print('[%s] %s' % (time.strftime('%H:%M:%S'), msg), flush=True) def goto_identities(): """从任意位置尽力走到 罪人 -> Identities 网格。 只点 Sinners 按钮, 绝不点左上返回键——主界面上的返回键会进入剧情(Drive), 实测会掉进过场动画, 需要额外恢复。 """ for attempt in range(5): items = probe('get_state').get('items', []) txt = ' | '.join(i.get('text', '') for i in items) if 'IDENTITIES' in txt and 'Facades' in txt: return True if 'TEAMS #1' in txt or 'SIN COST' in txt or 'All Idensities' in txt: click(*TAB_ALL_IDENTITIES) time.sleep(3) continue if 'LUXCAVATION' in txt.upper() or 'MIRROR' in txt.upper(): # 在副本/关卡菜单里, 先回主界面 probe('keypress', {'key': 'esc'}) time.sleep(2) continue click(*BTN_SINNERS) time.sleep(3.5) items = probe('get_state').get('items', []) txt = ' | '.join(i.get('text', '') for i in items) return 'IDENTITIES' in txt and 'Facades' in txt def run_daily(): log('起 daily(经验本x3 + 纽本x3)') r = probe('run_task', {'task': 'daily'}) if not r.get('ok'): return False, 'run_task 失败: %s' % r log('daily 已启动, 开始轮询') t0 = time.time() while time.time() - t0 < DAILY_TIMEOUT_S: time.sleep(60) st = probe('task_status', {'lines': 1}) s = st.get('state') if s != 'running': el = int(time.time() - t0) log('daily 结束: state=%s elapsed=%ds exit=%s' % (s, el, st.get('exit_code'))) return s == 'succeeded', 'state=%s elapsed=%ds' % (s, el) if int(time.time() - t0) % 600 < 60: log(' ...running %ds' % int(time.time() - t0)) probe('stop_task') return False, '超时 %ds' % DAILY_TIMEOUT_S def report_grid(): out = run([PY, '-X', 'utf8', LEVELUP, 'list']) return out.strip() def main(): t_start = time.time() log('=== 一轮开始 ===') ok, info = run_daily() log('刷材料: %s (%s)' % ('OK' if ok else 'FAIL', info)) if not ok: log('=== 本轮失败: 刷材料未成功 ===') return 1 # daily 结束后应回到主界面 time.sleep(8) if not goto_identities(): log('无法进入 Identities 网格, 放弃本轮') return 1 log('已进入 Identities 网格') log('升级前:\n' + report_grid()) log('对队内最低者升级 + 同步') out = run([PY, '-X', 'utf8', LEVELUP, 'weakest', '--uptie']) for line in out.strip().splitlines(): log(' ' + line) time.sleep(5) if not goto_identities(): log('升级后无法回到网格') return 1 log('升级后:\n' + report_grid()) log('=== 一轮结束, 耗时 %ds ===' % int(time.time() - t_start)) return 0 if __name__ == '__main__': raise SystemExit(main())