修复内置流程编队滑动被当成拖拽卡片: 补 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 项通过。
This commit is contained in:
@@ -43,6 +43,10 @@ def bootstrap():
|
|||||||
from module.logger.my_log import Logger
|
from module.logger.my_log import Logger
|
||||||
Logger()
|
Logger()
|
||||||
_booted = d
|
_booted = d
|
||||||
|
# 编队列表滑动: Windows 输入适配器缺队伍拖拽规避, 上游只有模拟器适配器有。
|
||||||
|
# 在导入 AALC 之后立即打补丁, 服务的 MCP 输入与 run_task 子进程都会生效。
|
||||||
|
from . import aalc_input_patch
|
||||||
|
aalc_input_patch.install()
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
# -*- 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
|
||||||
@@ -35,6 +35,22 @@ def tail(path, n):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
ERROR_MARKERS = ('[ERROR]', 'Traceback (most recent call last)')
|
||||||
|
ERROR_SCAN_LINES = 400
|
||||||
|
|
||||||
|
|
||||||
|
def log_errors(path, limit=3):
|
||||||
|
"""挑出日志尾部的报错行。
|
||||||
|
|
||||||
|
AALC 的每日流程在单次战斗失败后会继续跑完并正常退出(exit 0), 只看退出码
|
||||||
|
会把"超出最大尝试次数,未能进入战斗"这类失败当成成功, 所以状态里额外附上
|
||||||
|
日志里的报错行。
|
||||||
|
"""
|
||||||
|
hits = [line for line in tail(path, ERROR_SCAN_LINES)
|
||||||
|
if any(marker in line for marker in ERROR_MARKERS)]
|
||||||
|
return hits[-limit:]
|
||||||
|
|
||||||
|
|
||||||
class TaskRunner:
|
class TaskRunner:
|
||||||
|
|
||||||
def __init__(self, run_dir, argv_factory=default_argv, keep_logs=20, restore_argv=default_restore_argv):
|
def __init__(self, run_dir, argv_factory=default_argv, keep_logs=20, restore_argv=default_restore_argv):
|
||||||
@@ -112,6 +128,9 @@ class TaskRunner:
|
|||||||
'log': self.info['log'], 'log_tail': tail(self.info['log'], max(1, min(int(lines), 200)))}
|
'log': self.info['log'], 'log_tail': tail(self.info['log'], max(1, min(int(lines), 200)))}
|
||||||
if code is not None:
|
if code is not None:
|
||||||
r['exit_code'] = code
|
r['exit_code'] = code
|
||||||
|
errors = log_errors(self.info['log'])
|
||||||
|
if errors:
|
||||||
|
r['errors'] = errors
|
||||||
pending = self._pending_restores()
|
pending = self._pending_restores()
|
||||||
if pending:
|
if pending:
|
||||||
r['pending_restore'] = [os.path.basename(p) for p in pending]
|
r['pending_restore'] = [os.path.basename(p) for p in pending]
|
||||||
|
|||||||
Reference in New Issue
Block a user