Files
lc-mcp/lc_mcp/aalc_input_patch.py
T
DSH 66418dce22 修复内置流程编队滑动被当成拖拽卡片: 补 Windows 队伍滑动手势并暴露任务日志报错
- aalc_input_patch: 上游只有 MuMu 适配器覆盖 mouse_swipe_for_team_scroll,
  Windows 前台/后台适配器用普通列表手势(30px/0.01s escape), 在编队列表里
  会被当成拖动罪人卡: 队伍被拖乱, 缺人时后续 battle.py 报'未能进入战斗'。
  按 MuMu 参数(缩放 60px escape/保持 0.1s/分段/停稳 0.5s)补等价实现, 不改 AALC 源码。
- tasks: 退出码 0 但日志里有 [ERROR]/异常时, task_status 增加 errors 字段
  (AALC 单次战斗失败后仍会正常退出, 只看 succeeded 会被误导)。
- 新增 7 项回归测试, 全套 101 项通过。
2026-10-03 11:24:15 +08:00

152 lines
5.7 KiB
Python

# -*- coding: utf-8 -*-
"""编队列表滑动补丁: 给 Windows 输入适配器补上队伍拖拽规避。
AALC 基类注释说明 ``mouse_swipe_for_team_scroll`` 需要适配器覆盖以"规避队伍
拖拽判定", 但上游只有 MuMu 模拟器适配器覆盖了它; Windows 的前台(Input)与后台
(BackgroundInput)适配器仍在用普通列表滚动手势 ``build_windows_scroll_swipe_plan``:
按下后只 escape 30px / 0.01s。在游戏的编队列表里这不足以脱离"按住罪人卡"的
判定, 滑动会被当成拖动卡片 —— 队伍顺序被拖乱, 编队人数不足时还会让后续的
"进入战斗"失败(battle.py 报"未能进入战斗")。
这里按 MuMu 的参数(按 set_win_size 缩放的 60px escape、保持 0.1s、分段走完、
松手前停稳 0.5s)在 Windows 适配器上补一份等价实现, 不改 AALC 源码。
"""
import time
from math import hypot
# 与 MuMu 覆盖实现保持一致的量级
ESCAPE_AT_1080P = 60
ESCAPE_HOLD_SECONDS = 0.1
SETTLE_SECONDS = 0.5
POINT_SPACING_AT_1080P = 8
MIN_SEGMENT_DURATION = 0.05
def team_scroll_plan(x, y, dx, dy, duration, escape_distance):
"""编队列表滑动的几何路径(纯函数, 便于单测)。
返回 ``(start, escape, end, duration)``; ``distance == 0`` 时返回 None。
向下滑动(dy > 0)时把起点沿反向偏移 escape, 终点沿正向多走 escape,
这样手指/指针能落在可见行内, 同时保持总位移不变。
"""
distance = hypot(dx, dy)
if distance == 0:
return None
unit_x, unit_y = dx / distance, dy / distance
if dy > 0:
start = (x - unit_x * escape_distance, y - unit_y * escape_distance)
else:
start = (float(x), float(y))
end = (start[0] + dx + unit_x * escape_distance,
start[1] + dy + unit_y * escape_distance)
escape = (start[0] + unit_x * escape_distance,
start[1] + unit_y * escape_distance)
return start, escape, end, max(0.0, float(duration))
def _scaled_escape():
from module.config import cfg
return ESCAPE_AT_1080P * cfg.set_win_size / 1080
def _segment_steps(escape_point, end):
"""把 escape 之后的剩余位移切成小段, 返回 (段数, 位移x, 位移y)。"""
from module.config import cfg
move_x = end[0] - escape_point[0]
move_y = end[1] - escape_point[1]
distance = hypot(move_x, move_y)
if distance == 0:
return 0, 0.0, 0.0
spacing = POINT_SPACING_AT_1080P * cfg.set_win_size / 1080
steps = max(int(distance / max(spacing, 1.0)), 1)
return steps, move_x, move_y
def _foreground_team_scroll(self, x, y, duration=0.3, dx=0, dy=0, move_back=True):
"""前台输入(pyautogui)下的编队列表滑动。"""
import pyautogui
plan = team_scroll_plan(x, y, dx, dy, duration, _scaled_escape())
if plan is None:
return
start, escape, end, total_duration = plan
restore = self.get_mouse_position() if move_back else None
sx, sy = self.pos_offset(*start)
ex, ey = self.pos_offset(*escape)
fx, fy = self.pos_offset(*end)
pyautogui.moveTo(sx, sy)
pyautogui.mouseDown(sx, sy)
try:
pyautogui.moveTo(ex, ey, duration=MIN_SEGMENT_DURATION)
# 让游戏渲染一帧, 确认这是滚动而不是按住卡片。
time.sleep(ESCAPE_HOLD_SECONDS)
steps, move_x, move_y = _segment_steps(escape, end)
if steps:
step_duration = max(total_duration, MIN_SEGMENT_DURATION) / steps
for index in range(1, steps + 1):
ratio = index / steps
pyautogui.moveTo(ex + move_x * ratio, ey + move_y * ratio,
duration=step_duration)
time.sleep(SETTLE_SECONDS)
finally:
pyautogui.mouseUp(fx, fy)
if restore:
self.mouse_move(restore)
def _adapter_team_scroll(self, x, y, duration=0.3, dx=0, dy=0, move_back=True):
"""后台/其它 Windows 适配器下的编队列表滑动(走适配器自身的原语)。"""
plan = team_scroll_plan(x, y, dx, dy, duration, _scaled_escape())
if plan is None:
return
start, escape, end, total_duration = plan
restore = self.get_mouse_position() if move_back else None
self.set_active()
self.set_mouse_pos(*start)
self.mouse_down(*start)
try:
self.set_mouse_pos(*escape, duration=MIN_SEGMENT_DURATION)
time.sleep(ESCAPE_HOLD_SECONDS)
steps, move_x, move_y = _segment_steps(escape, end)
if steps:
step_duration = max(total_duration, MIN_SEGMENT_DURATION) / steps
for index in range(1, steps + 1):
ratio = index / steps
self.set_mouse_pos(escape[0] + move_x * ratio,
escape[1] + move_y * ratio,
duration=step_duration)
time.sleep(SETTLE_SECONDS)
finally:
self.mouse_up(*end)
if restore:
self.mouse_move(restore)
def install():
"""给 AALC 的 Windows 输入适配器装上队伍安全滑动。幂等。"""
from module.automation.input_handlers import input as input_module
patched = []
cls = getattr(input_module, 'Input', None)
if cls is not None and getattr(cls, 'mouse_swipe_for_team_scroll', None) \
is not _foreground_team_scroll:
cls.mouse_swipe_for_team_scroll = _foreground_team_scroll
patched.append('Input')
for name in ('BackgroundInput', 'WindowMoveInput'):
cls = getattr(input_module, name, None)
if cls is None or not hasattr(cls, 'set_mouse_pos'):
continue
if getattr(cls, 'mouse_swipe_for_team_scroll', None) is _adapter_team_scroll:
continue
cls.mouse_swipe_for_team_scroll = _adapter_team_scroll
patched.append(name)
return patched