转交与互斥(原未提交改动,合入选队分支后提交): - 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>
606 lines
23 KiB
Python
606 lines
23 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""任务子进程里对 AALC 的运行时补丁。不改 vendor/aalc 的源码。
|
|
|
|
1. 队伍名精确匹配
|
|
AALC 的 find_str_in_text 用子串匹配, "TEAMS #1" 会命中 "TEAMS #10"(中文 "编队#1"
|
|
同理)。账号有 10 个以上预设时就会选中别的(常常是空)队伍, 然后在编队人数检查里
|
|
无限空转——2026-10-05 一次空转了 27 分钟。这里只接管队伍名这一种目标, 要求编号
|
|
完全相同, 其他文本仍走 AALC 原逻辑。
|
|
|
|
2. 窗口比例守护
|
|
RDP 重连改变桌面分辨率后, Unity 会把窗口拉伸成非 16:9。AALC 只在任务开始时校正
|
|
一次, 之后全部模板匹配分数掉到阈值以下, 表现为原地空转、不报错。这里在后台定期
|
|
检查客户区尺寸, 偏离 set_win_size 时调回去。
|
|
"""
|
|
import os
|
|
import re
|
|
import threading
|
|
import time
|
|
from contextlib import contextmanager
|
|
|
|
TEAM_TARGET = re.compile(r'(?:TEAMS|TFAMS|编队)#(\d+)', re.IGNORECASE)
|
|
|
|
|
|
@contextmanager
|
|
def headless_hdr_warning(scheme, log=print):
|
|
"""Acknowledge upstream's GUI-only HDR prompt without a Qt event loop."""
|
|
from PySide6.QtCore import Qt
|
|
|
|
def acknowledge(event):
|
|
try:
|
|
log('[lc_mcp] HDR 已开启,可能影响图像识别;命令行任务继续运行')
|
|
finally:
|
|
event.set()
|
|
|
|
signal = scheme.mediator.hdr_warning
|
|
signal.connect(acknowledge, Qt.ConnectionType.DirectConnection)
|
|
try:
|
|
yield
|
|
finally:
|
|
signal.disconnect(acknowledge)
|
|
|
|
|
|
class MirrorProgress:
|
|
"""AALC 镜牢的实际完成局数。total 为 None 表示本次没有进入镜牢循环。"""
|
|
|
|
def __init__(self):
|
|
self.total = None
|
|
self.finished = 0
|
|
|
|
def record(self, finished, remaining):
|
|
# Mirror_task 开始时发 (0, 总局数), 每完成一局发 (已完成, 剩余)
|
|
if self.total is None:
|
|
self.total = finished + remaining
|
|
self.finished = max(self.finished, finished)
|
|
|
|
|
|
@contextmanager
|
|
def mirror_progress(scheme):
|
|
"""监听 mirror_signal 统计完成局数。
|
|
|
|
AALC 没有可用队伍或队列为空时 Mirror_task 直接跳出循环, 进程仍以 0 退出;
|
|
只看退出码会把"一局没打"报成 succeeded。
|
|
"""
|
|
from PySide6.QtCore import Qt
|
|
|
|
progress = MirrorProgress()
|
|
signal = scheme.mediator.mirror_signal
|
|
signal.connect(progress.record, Qt.ConnectionType.DirectConnection)
|
|
try:
|
|
yield progress
|
|
finally:
|
|
signal.disconnect(progress.record)
|
|
|
|
|
|
def team_number(text):
|
|
"""'TEAMS #12' / 'TFAMS#3' / '编队#1' -> '12' / '3' / '1'; 不是队伍名返回 None。"""
|
|
m = TEAM_TARGET.fullmatch(text.replace(' ', '').strip())
|
|
return m.group(1) if m else None
|
|
|
|
|
|
def find_team_text(want, ocr_dict):
|
|
"""在 OCR 结果里找编号恰好为 want 的队伍名, 返回其坐标或 False。"""
|
|
for text, position in ocr_dict.items():
|
|
for hit in TEAM_TARGET.finditer(text.replace(' ', '')):
|
|
if hit.group(1) == want:
|
|
return position
|
|
return False
|
|
|
|
|
|
def install_exact_team_match(auto, log=print):
|
|
original = auto.find_str_in_text
|
|
|
|
def find_str_in_text(target, ocr_dict):
|
|
want = team_number(str(target))
|
|
if want is None:
|
|
return original(target, ocr_dict)
|
|
return find_team_text(want, ocr_dict)
|
|
|
|
auto.find_str_in_text = find_str_in_text
|
|
log('[lc_mcp] patch: 队伍名改为编号精确匹配')
|
|
|
|
|
|
class WindowGuard(threading.Thread):
|
|
"""后台检查游戏客户区, 不是 set_win_size 对应的 16:9 尺寸就调回去。"""
|
|
|
|
def __init__(self, screen, cfg, interval=15.0, log=print):
|
|
super().__init__(name='lc_mcp-window-guard', daemon=True)
|
|
self.screen, self.cfg, self.interval, self.log = screen, cfg, interval, log
|
|
self.stopped = threading.Event()
|
|
self.fixes = 0
|
|
self._failed = None # 同一尺寸调不回来只报一次, 免得每 15 秒刷一条 ERROR
|
|
|
|
def want(self):
|
|
size = int(self.cfg.set_win_size)
|
|
return int(size * 16 / 9), size
|
|
|
|
def check_position(self):
|
|
"""窗口有一截跑到屏幕外时挪回工作区。
|
|
|
|
背景(2026-10-22 实测): 游戏会恢复自己保存的窗口位置, 出现过 (-8, 39) 这种
|
|
—— 左边 8 像素在屏幕外。前台模式(background_click=false)下 AALC 从**屏幕**
|
|
抓图, 窗口一出界抓到的画面就整体错位, 模板匹配相似度掉到 0.2~0.5, 表现是
|
|
"日志一直在动但几乎不点击"(实测 30 秒只点 1 次, 挪回来立刻恢复)。
|
|
set_win_position=free 时 AALC 不碰位置, 所以这里补上。
|
|
|
|
返回 'ok' / 'fixed' / None(没法判断)。
|
|
"""
|
|
try:
|
|
import win32con
|
|
import win32gui
|
|
except ImportError:
|
|
return None
|
|
handle = self.screen.handle
|
|
hwnd = handle._hwnd
|
|
try:
|
|
left, top, right, bottom = handle.monitor_info["Work"]
|
|
except Exception:
|
|
return None
|
|
try:
|
|
x, y, r, b = win32gui.GetWindowRect(hwnd)
|
|
except Exception:
|
|
return None
|
|
width, height = r - x, b - y
|
|
if width <= 0 or height <= 0:
|
|
return None
|
|
# 已经完整落在工作区内就不动
|
|
if x >= left and y >= top and r <= right and b <= bottom:
|
|
return 'ok'
|
|
new_x = max(left, min(x, right - width))
|
|
new_y = max(top, min(y, bottom - height))
|
|
try:
|
|
win32gui.SetWindowPos(hwnd, 0, new_x, new_y, 0, 0,
|
|
win32con.SWP_NOSIZE | win32con.SWP_NOZORDER |
|
|
win32con.SWP_NOACTIVATE)
|
|
except Exception as e:
|
|
self.log('[lc_mcp] window guard: 挪窗口失败 %s: %s' % (type(e).__name__, e))
|
|
return None
|
|
self.fixes += 1
|
|
self.log('[lc_mcp] window guard: 窗口 (%d,%d) 有部分在屏幕外, 已挪到 (%d,%d)'
|
|
% (x, y, new_x, new_y))
|
|
return 'fixed'
|
|
|
|
def check_once(self):
|
|
"""返回 'ok' / 'fixed' / 'failed' / None(没有可检查的窗口)。"""
|
|
handle = self.screen.handle
|
|
# set_windows 关闭表示用户自己管窗口, AALC 也不调, 这里同样不插手
|
|
if self.cfg.simulator or not self.cfg.set_windows or not handle._hwnd or handle.isMinimized:
|
|
return None
|
|
# 位置先修: 出界会让抓图错位, 那种情况下尺寸检查也没意义
|
|
if self.check_position() == 'fixed':
|
|
time.sleep(0.5)
|
|
current = (handle.width(True), handle.height(True))
|
|
want = self.want()
|
|
if current == want or 0 in current:
|
|
return 'ok' if current == want else None
|
|
self.screen.adjust_win_size(want)
|
|
time.sleep(1)
|
|
after = (handle.width(True), handle.height(True))
|
|
if after == want:
|
|
self.fixes += 1
|
|
self._failed = None
|
|
self.log('[lc_mcp] window guard: 客户区 %sx%s 已调回 %sx%s' % (current + want))
|
|
return 'fixed'
|
|
if after != self._failed:
|
|
self._failed = after
|
|
self.log('[ERROR] [lc_mcp] window guard: 客户区 %sx%s 调整后仍为 %sx%s(目标 %sx%s),'
|
|
' 桌面可能放不下窗口' % (current + after + want))
|
|
return 'failed'
|
|
|
|
def run(self):
|
|
while not self.stopped.wait(self.interval):
|
|
try:
|
|
self.check_once()
|
|
except Exception as e: # 守护线程不能把任务带崩
|
|
self.log('[lc_mcp] window guard: 检查出错 %s: %s' % (type(e).__name__, e))
|
|
|
|
def stop(self):
|
|
self.stopped.set()
|
|
|
|
# ---------------------------------------------------------------- 驱动级点击接管
|
|
|
|
# 新版 AALC 的输入入口带交互门和锁, 重绑时必须保留这些包装。
|
|
REBIND_NAMES = ('mouse_click', 'mouse_click_blank', 'mouse_down', 'mouse_up')
|
|
|
|
|
|
class DriverClickProxy:
|
|
"""把鼠标点击转发到罗技驱动, 其余一律透传给原 handler。
|
|
|
|
⛔ 只接管**点击类**操作。拖拽/滑动/滚轮仍走 AALC 原逻辑 —— 那些在镜牢和日常
|
|
里用得少, 而各自的行为差异(惯性、多点)不好用相对位移复现, 接了反而更容易出错。
|
|
"""
|
|
|
|
def __init__(self, handler, driver, screen, log=print):
|
|
self._handler = handler
|
|
self._driver = driver
|
|
self._screen = screen
|
|
self.log = log
|
|
self.clicks = 0
|
|
self.refused = 0
|
|
|
|
# --- 透传 -------------------------------------------------------------
|
|
def __getattr__(self, name):
|
|
return getattr(self._handler, name)
|
|
|
|
# --- 接管 -------------------------------------------------------------
|
|
def _screen_pos(self, x, y):
|
|
from .driver_input import client_to_screen, foreground_window, is_console_session
|
|
handle = self._screen.handle
|
|
hwnd = handle.hwnd
|
|
if not hwnd or handle.isMinimized or not is_console_session():
|
|
raise OSError('驱动点击需要 console 会话中可见的游戏窗口')
|
|
if foreground_window() != hwnd:
|
|
handle.setForeground()
|
|
if foreground_window() != hwnd:
|
|
raise OSError('无法激活游戏窗口, 未发送驱动输入')
|
|
# 游戏重启后句柄会变; 每次按当前句柄重新绑定, 免得前台校验拿旧句柄拒绝所有点击。
|
|
bind = getattr(self._driver, 'bind_window', None)
|
|
if bind is not None:
|
|
bind(hwnd)
|
|
return client_to_screen(hwnd, x, y)
|
|
|
|
def _trace(self, msg):
|
|
"""排障用的文件追踪: 日志被 AALC 的 logger 吞掉时靠它看真实调用。"""
|
|
path = os.environ.get('LCP_DRIVER_TRACE')
|
|
if not path:
|
|
return
|
|
try:
|
|
with open(path, 'a', encoding='utf-8') as fh:
|
|
fh.write('%s %s\n' % (time.strftime('%H:%M:%S'), msg))
|
|
except OSError:
|
|
pass
|
|
|
|
def mouse_click(self, x, y, times=1, move_back=False):
|
|
from .driver_input import get_cursor
|
|
self._handler.wait_pause()
|
|
self._trace('mouse_click(%s,%s,times=%s)' % (x, y, times))
|
|
original_pos = None
|
|
try:
|
|
sx, sy = self._screen_pos(x, y)
|
|
if move_back:
|
|
original_pos = get_cursor()
|
|
if self._driver.click(sx, sy, times=times):
|
|
self.clicks += 1
|
|
self.log('[driver] 点击客户区(%d,%d) -> 屏幕(%d,%d)' % (x, y, sx, sy))
|
|
return True
|
|
except InterruptedError:
|
|
raise
|
|
except OSError as e:
|
|
self._trace('点击失败: %s' % e)
|
|
self.log('[driver] 点击失败: %s' % e)
|
|
finally:
|
|
if original_pos is not None:
|
|
self._driver.move_to(*original_pos)
|
|
self.refused += 1
|
|
self.log('[driver] 放弃点击客户区(%d,%d): 无法激活或精确定位' % (x, y))
|
|
return False
|
|
|
|
def mouse_click_blank(self, coordinate=(1, 1), times=1, move_back=False):
|
|
return self.mouse_click(*coordinate, times=times, move_back=move_back)
|
|
|
|
def mouse_down(self, x, y):
|
|
self._handler.wait_pause()
|
|
sx, sy = self._screen_pos(x, y)
|
|
if not self._driver.move_to(sx, sy):
|
|
return False
|
|
return self._driver.down(1) is not False
|
|
|
|
def mouse_up(self, x, y):
|
|
try:
|
|
sx, sy = self._screen_pos(x, y)
|
|
self._driver.move_to(sx, sy)
|
|
finally:
|
|
self._driver.up(1)
|
|
return True
|
|
|
|
|
|
def install_driver_click(auto, screen, driver=None, log=print):
|
|
"""如果环境满足, 把 AALC 的鼠标点击切到罗技驱动级输入。
|
|
|
|
返回驱动实例(成功) 或 None(条件不满足, AALC 保持原样)。
|
|
条件不满足时**不改任何东西** —— 宁可继续用原来的注入方式, 也不要半吊子接管。
|
|
"""
|
|
from .driver_input import DriverInput
|
|
|
|
if isinstance(auto.input_handler, DriverClickProxy):
|
|
return auto.input_handler._driver
|
|
drv = driver if driver is not None else DriverInput(log=log)
|
|
ok, why = drv.preflight()
|
|
if not ok:
|
|
log('[lc_mcp] 驱动级输入未启用: %s' % why)
|
|
return None
|
|
# 绑定目标窗口: click() 靠它做句柄级前台校验。
|
|
# 只比矩形是不够的 —— 窗口互相重叠时, 同一个屏幕坐标会同时落在两边,
|
|
# 实测把浏览器切到前台后, 几何校验照样通过(2026-10-23)。
|
|
try:
|
|
drv.bind_window(screen.handle.hwnd)
|
|
except Exception:
|
|
pass
|
|
|
|
proxy = DriverClickProxy(auto.input_handler, drv, screen, log=log)
|
|
trace = os.environ.get('LCP_DRIVER_TRACE')
|
|
if trace:
|
|
try:
|
|
with open(trace, 'a', encoding='utf-8') as fh:
|
|
fh.write('%s install: 原 handler=%s -> proxy\n'
|
|
% (time.strftime('%H:%M:%S'), type(auto.input_handler).__name__))
|
|
fh.write('%s install: auto.mouse_click 原绑定=%r\n'
|
|
% (time.strftime('%H:%M:%S'), getattr(auto, 'mouse_click', None)))
|
|
except OSError:
|
|
pass
|
|
auto.input_handler = proxy
|
|
for name in REBIND_NAMES:
|
|
gate = getattr(auto, '_run_business_interaction', None)
|
|
setattr(auto, name, gate(name) if callable(gate) else getattr(proxy, name))
|
|
log('[lc_mcp] patch: 鼠标点击已切到罗技驱动级输入')
|
|
return drv
|
|
|
|
|
|
def stop_driver_click(auto):
|
|
handler = auto.input_handler
|
|
if isinstance(handler, DriverClickProxy):
|
|
handler._driver.emergency_stop()
|
|
|
|
|
|
@contextmanager
|
|
def driver_click_tasks(scheme, auto, screen, cfg, log=print):
|
|
"""每次游戏初始化完成后接管, 包括 all 任务和故障重启。"""
|
|
if cfg.simulator or os.environ.get('LCP_DRIVER_INPUT', '').strip() != '1':
|
|
yield
|
|
return
|
|
original = scheme.init_game
|
|
|
|
def init_game(*args, **kwargs):
|
|
result = original(*args, **kwargs)
|
|
install_driver_click(auto, screen, log=log)
|
|
return result
|
|
|
|
scheme.init_game = init_game
|
|
try:
|
|
yield
|
|
finally:
|
|
scheme.init_game = original
|
|
|
|
# ---------------------------------------------------------------- 前台窗口健壮化
|
|
|
|
def install_robust_set_foreground(screen, log=print):
|
|
"""把 SetForegroundWindow 换成带 AttachThreadInput 兜底的版本。
|
|
|
|
背景(2026-10-22): cfg.background_click=False 时 screen.py:342 会调
|
|
self.handle.setForeground(), 而原生实现只有一句裸调用
|
|
win32gui.SetForegroundWindow(hwnd)。Windows 不允许非前台进程抢占前台,
|
|
失败时抛 pywintypes.error(0, 'SetForegroundWindow', ...) —— 这个异常在
|
|
set_win() 里没有捕获, 直接把任务带崩(观测: exit code 3 之前的 traceback)。
|
|
|
|
兜底尝试关联当前线程和前台线程的输入队列, 完成后解挂。
|
|
Windows 仍可能拒绝激活; 驱动输入在发送前另行检查游戏是否在前台。
|
|
"""
|
|
handle = getattr(screen, 'handle', None)
|
|
if handle is None or not hasattr(handle, 'setForeground'):
|
|
log('[lc_mcp] 前台窗口补丁跳过: screen.handle 没有 setForeground')
|
|
return None
|
|
|
|
original = handle.setForeground
|
|
|
|
def setForeground():
|
|
hwnd = getattr(handle, 'hwnd', 0)
|
|
if not hwnd:
|
|
return
|
|
try:
|
|
original()
|
|
return
|
|
except Exception:
|
|
pass # 落到下面的 AttachThreadInput 兜底
|
|
try:
|
|
import win32api
|
|
import win32gui
|
|
import win32process
|
|
|
|
foreground = win32gui.GetForegroundWindow()
|
|
thread_fg = win32process.GetWindowThreadProcessId(foreground)[0] if foreground else 0
|
|
thread_me = win32api.GetCurrentThreadId()
|
|
attached = False
|
|
if thread_fg and thread_fg != thread_me:
|
|
# pywin32 成功时返回 None, 失败抛异常, 不能按真假判断。
|
|
win32process.AttachThreadInput(thread_me, thread_fg, True)
|
|
attached = True
|
|
try:
|
|
win32gui.BringWindowToTop(hwnd)
|
|
win32gui.SetForegroundWindow(hwnd)
|
|
finally:
|
|
if attached:
|
|
win32process.AttachThreadInput(thread_me, thread_fg, False)
|
|
except Exception as e:
|
|
log('[lc_mcp] setForeground 兜底也失败: %s: %s' % (type(e).__name__, e))
|
|
|
|
handle.setForeground = setForeground
|
|
log('[lc_mcp] patch: SetForegroundWindow 加 AttachThreadInput 兜底')
|
|
return handle
|
|
|
|
# ---------------------------------------------------------------- 日常本用默认队伍
|
|
|
|
|
|
def install_default_battle_team(scheme, log=print):
|
|
"""日常本不再翻队伍列表, 直接用界面上已经选中的默认队伍。
|
|
|
|
背景(2026-11-06): 这账号的队伍是自定义名字(不是 "编队#N"), 而
|
|
select_battle_team 按名字找队伍, 找不到就来回滑动 10 次(实测 61 秒), 滑完还把
|
|
队伍页留在滚动后的位置; 紧接着 battle.to_battle() 在 15 次循环里都找不到
|
|
"进入战斗" 按钮, 报 "超出最大尝试次数, 未能进入战斗", 整个日常就这样空转。
|
|
|
|
经验本/纽本本来就是用界面默认队伍打的, 跳过选队伍这一步即可。
|
|
"""
|
|
try:
|
|
from tasks.teams import team_formation as tf
|
|
except Exception as e:
|
|
log('[lc_mcp] 默认队伍补丁跳过: 无法导入 team_formation: %s' % e)
|
|
return None
|
|
original = getattr(tf, 'select_battle_team', None)
|
|
if original is None:
|
|
log('[lc_mcp] 默认队伍补丁跳过: 找不到 select_battle_team')
|
|
return None
|
|
|
|
def select_battle_team(*args, **kwargs):
|
|
log('[lc_mcp] patch: 日常本跳过选队伍, 直接用默认队伍')
|
|
return True
|
|
|
|
tf.select_battle_team = select_battle_team
|
|
scheme.select_battle_team = select_battle_team
|
|
log('[lc_mcp] patch: 日常本使用默认队伍')
|
|
return original
|
|
|
|
|
|
# ---------------------------------------------------------------- 镜牢按体系名选队
|
|
|
|
# 这账号把编队按体系命名(流血的队就叫 "流血"), AALC 却只会找 "编队#N" / "TEAMS #N"。
|
|
# 2026-11-14 实测: 列表里是 剧情关卡/斩击/突刺/打击/烧伤/流血/震颤/破裂/沉沦/呼吸法/充能
|
|
# 再接 编队#13..#38, 根本没有 "编队#1" —— AALC 翻满 10 页也找不到, 报 "无法寻得队伍"。
|
|
SYSTEM_TEAM_NAMES = {
|
|
'burn': ('烧伤',),
|
|
'bleed': ('流血',),
|
|
'tremor': ('震颤',),
|
|
'rupture': ('破裂',),
|
|
'poise': ('呼吸法', '呼吸'),
|
|
'sinking': ('沉沦',),
|
|
'charge': ('充能',),
|
|
'slash': ('斩击',),
|
|
'pierce': ('突刺',),
|
|
'blunt': ('打击',),
|
|
}
|
|
|
|
# 左侧编队列表的 OCR 命中范围(客户区像素, 1280x720 实测)
|
|
TEAM_LIST_X_MAX = 260
|
|
TEAM_LIST_Y_MIN = 300
|
|
TEAM_LIST_Y_MAX = 640
|
|
# 顶栏 "编队名" 的位置, 用来确认真的选中了
|
|
TEAM_HEADER = (170, 520, 90, 150)
|
|
|
|
|
|
def _team_ocr(auto):
|
|
"""整屏 OCR, 返回 [(文本, x, y), ...]。用列表而不是 dict: 同名条目(列表里的队名和顶栏队名)
|
|
落在不同位置, dict 会把它们覆盖成一条。不用 my_crop: 裁剪区的坐标系不可靠。"""
|
|
ocr = auto._run_ocr_for_text(my_crop=None)
|
|
result = []
|
|
for text, pos in (ocr or {}).items():
|
|
clean = str(text).replace(' ', '').strip()
|
|
if not clean:
|
|
continue
|
|
try:
|
|
x, y = float(pos[0]), float(pos[1])
|
|
except (TypeError, IndexError, ValueError):
|
|
continue
|
|
result.append((clean, x, y))
|
|
return result
|
|
|
|
|
|
def _in_list(x, y):
|
|
return x < TEAM_LIST_X_MAX and TEAM_LIST_Y_MIN < y < TEAM_LIST_Y_MAX
|
|
|
|
|
|
def _in_header(x, y):
|
|
x1, x2, y1, y2 = TEAM_HEADER
|
|
return x1 < x < x2 and y1 < y < y2
|
|
|
|
|
|
def _scroll_team_list(auto, direction, times=6, distance=250):
|
|
"""direction=+1 向下拖(回到列表顶部), -1 向上拖(往下翻)。"""
|
|
for _ in range(times):
|
|
auto.mouse_swipe_for_team_scroll(130, 430, dy=direction * distance, duration=0.3)
|
|
time.sleep(0.35)
|
|
|
|
|
|
def _header_is(auto, name):
|
|
"""顶栏当前队伍名就是 name。"""
|
|
if auto.take_screenshot() is None:
|
|
return False
|
|
return any(text == name and _in_header(x, y) for text, x, y in _team_ocr(auto))
|
|
|
|
|
|
def _wait_header(auto, name, tries=3, delay=1.2):
|
|
"""点完之后顶栏要过一两帧才刷新, 多等几次。"""
|
|
for _ in range(tries):
|
|
time.sleep(delay)
|
|
if _header_is(auto, name):
|
|
return True
|
|
return False
|
|
|
|
|
|
def _select_team_by_name(auto, names, log=print, rounds=4):
|
|
"""在编队列表里按名字点选。成功返回 True, 没找到返回 False。"""
|
|
if auto.take_screenshot() is None:
|
|
return False
|
|
if not auto.find_element('teams/identify_assets.png'):
|
|
log('[lc_mcp] 不在编队界面, 跳过按名字选队')
|
|
return False
|
|
for name in names: # 已经是这支队就不用动列表
|
|
if _header_is(auto, name):
|
|
log('[lc_mcp] patch: 当前已经是编队 %s, 无需切换' % name)
|
|
return True
|
|
auto.mouse_click(1, 1)
|
|
time.sleep(0.3)
|
|
_scroll_team_list(auto, +1) # 先回到顶部
|
|
for round_index in range(rounds):
|
|
if auto.take_screenshot() is None:
|
|
continue
|
|
items = _team_ocr(auto)
|
|
hit = None
|
|
for name in names:
|
|
for text, x, y in items:
|
|
if text == name and _in_list(x, y):
|
|
hit = (name, x, y)
|
|
break
|
|
if hit:
|
|
break
|
|
if hit:
|
|
name, x, y = hit
|
|
log('[lc_mcp] 编队列表里找到 %s @(%d,%d)' % (name, x, y))
|
|
auto.mouse_action_with_pos([x, y], offset=False)
|
|
if _wait_header(auto, name):
|
|
log('[lc_mcp] patch: 已按体系名选中编队 %s' % name)
|
|
return True
|
|
log('[lc_mcp] 点了 %s 但顶栏没变, 继续往下翻' % name)
|
|
_scroll_team_list(auto, -1, times=3)
|
|
log('[lc_mcp] 编队列表里没找到 %s(共 %d 轮)' % ('/'.join(names), rounds))
|
|
return False
|
|
|
|
|
|
def install_system_team_selection(log=print):
|
|
"""镜牢选队改成"按队伍体系对应的中文名"在列表里点。
|
|
|
|
AALC 原生只认 编队#N; 本账号的编队是自定义名字(流血/斩击/...), 原生逻辑永远选不上。
|
|
"""
|
|
try:
|
|
from tasks.mirror import mirror as mirror_mod
|
|
from module.automation import auto
|
|
except Exception as e:
|
|
log('[lc_mcp] 体系选队补丁跳过: 无法导入 %s' % e)
|
|
return None
|
|
original = getattr(mirror_mod, 'select_battle_team', None)
|
|
if original is None:
|
|
log('[lc_mcp] 体系选队补丁跳过: mirror 模块没有 select_battle_team')
|
|
return None
|
|
wanted = {'names': ()}
|
|
original_init = mirror_mod.Mirror.__init__
|
|
|
|
def __init__(self, team_setting, team_num):
|
|
original_init(self, team_setting, team_num)
|
|
wanted['names'] = SYSTEM_TEAM_NAMES.get(getattr(self, 'system', ''), ())
|
|
log('[lc_mcp] 镜牢体系 %s -> 目标编队 %s'
|
|
% (getattr(self, 'system', '?'), '/'.join(wanted['names']) or '(无配置)'))
|
|
|
|
def select_battle_team(num):
|
|
names = wanted['names']
|
|
if names:
|
|
try:
|
|
if _select_team_by_name(auto, names, log=log):
|
|
return True
|
|
except Exception as e:
|
|
log('[lc_mcp] 按名字选队出错: %s: %s' % (type(e).__name__, e))
|
|
return False
|
|
return original(num)
|
|
|
|
mirror_mod.Mirror.__init__ = __init__
|
|
mirror_mod.select_battle_team = select_battle_team
|
|
log('[lc_mcp] patch: 镜牢按体系名选队')
|
|
return original
|