Files
lc-mcp/scripts/lc_ui.py
T
ywsandClaude Opus 5.5 6b129ddba3 修复复核发现的问题: 坐标缩放、升级/同步判定、看门狗诊断、卡死检测
- scripts/lc_ui.py: 脚本坐标按 1600x900 书写, OCR 结果与点击/拖动按实际客户区换算; 去掉写死的 D:\lc-mcp 路径
- levelup.py: 升级以详情页等级/经验条变化判定成功; 同步先判断弹窗是否仍在, 无过场时不再多按 ESC、不再盲点取消
- auto_cycle.py: task_status 连续报 stall 即停任务; exit 0 但有 errors 判失败
- tasks.py: 运行中日志尾部"配队人数OCR得到"刷屏时返回 stall 字段
- keep_display.ps1: tscon 改用 -EncodedCommand 并记录退出码; 会话号自动取游戏所在会话
- 更正 10-05 README 选队结论、summary 卡死①统计、PITFALLS 坑 13 根因

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 03:03:49 +00:00

97 lines
2.8 KiB
Python

# -*- coding: utf-8 -*-
"""levelup.py / auto_cycle.py 共用的 MCP 调用与坐标换算。
脚本里的坐标都是在 1600x900 客户区上实测的。实际客户区随 set_win_size
和桌面分辨率变化(720/900/1080 都出现过), 所以:
- get_state 返回的 OCR 坐标先换算到 1600x900 再交给脚本逻辑;
- click/drag 的坐标从 1600x900 换算回当前客户区再发出。
脚本内部因此只需要面对一套坐标。
"""
import json
import os
import subprocess
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
# 默认用运行本脚本的解释器(AALC 的 venv); 需要时用 LC_PY 指定
PY = os.environ.get('LC_PY') or sys.executable
PROBE = os.path.join(HERE, 'mcp_probe.py')
BASE_W, BASE_H = 1600, 900
_scale = None
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, quiet=True):
cmd = [PY, '-X', 'utf8', PROBE, tool]
if args is not None:
cmd.append(json.dumps(args, ensure_ascii=False))
out = run(cmd).strip()
for line in reversed(out.splitlines()):
line = line.strip()
if line.startswith('{'):
try:
return json.loads(line)
except json.JSONDecodeError:
continue
if not quiet:
print('[warn] probe %s 无 JSON 输出: %r' % (tool, out[:200]))
return {}
def state():
"""get_state, 并把 OCR 坐标换算到 1600x900。"""
global _scale
r = probe('get_state', quiet=False)
screen = r.get('screen') or {}
if screen.get('w') and screen.get('h'):
if abs(screen['w'] / screen['h'] - BASE_W / BASE_H) > 0.02:
print('[warn] 客户区 %sx%s 不是 16:9, 坐标会偏' % (screen['w'], screen['h']))
_scale = screen['w'] / BASE_W
s = _scale or 1.0
for it in r.get('items', []):
for k in ('x', 'y', 'w', 'h'):
if k in it:
it[k] = round(it[k] / s)
return r
def items():
return state().get('items', [])
def screen_text(its):
return ' | '.join(i.get('text', '') for i in its)
def _to_client(x, y):
if _scale is None:
state()
s = _scale or 1.0
return int(round(x * s)), int(round(y * s))
def click(x, y, times=1):
cx, cy = _to_client(x, y)
return probe('click', {'x': cx, 'y': cy, 'times': times})
def drag(from_x, from_y, to_x, to_y):
fx, fy = _to_client(from_x, from_y)
tx, ty = _to_client(to_x, to_y)
return probe('drag', {'from_x': fx, 'from_y': fy, 'to_x': tx, 'to_y': ty})
def long_press(x, y):
"""drag 起点==终点 即长按(实测可打开人格详情)。"""
return drag(x, y, x, y)
def keypress(key):
return probe('keypress', {'key': key})