事件点击改文字中心 + 卡包刷新按 OCR + 运行数据归档

Browse Source
- 事件: 点击点从「选项标记」改成选项文字自己的中心(_option_click_pos)。11-18 实测同一个
  选项被点 10 次还在, 标记常落在行首装饰上
- 事件兜底: LCP_EVENT_FALLBACK=1 时表里没有的事件点第 1 项, 不再被上游「无法解决事件→回主界面」
- 卡包刷新: 改成 OCR 找右上角「刷新」点文字中心(找不到退回模板), 记 decisions theme_pack/refresh_click
- 驱动点击: 点击点必须落在游戏客户区内(否则拒绝), 修「老是打开回收站」(blank 点击点到桌面左上角)
- docs/feedback/runs/2026-11-15_2026-11-21: 20 轮过滤后的日志(1.6MB, 原始 110MB) +
  decisions.jsonl 原样(1868 条) + INDEX.md 汇总

单测: 750 passed。
This commit is contained in:
Codex Agent
2026-11-22 08:54:30 +08:00
parent dc5bcadd16
commit 3ed1749dfe
22 changed files with 2126 additions and 10 deletions
+80 -3
View File
@@ -1185,6 +1185,7 @@ def install_gift_preference(log=print, env=None):
# 选项文字对上表里某个事件就点表里那一项; 对不上交给上游原逻辑。 # 选项文字对上表里某个事件就点表里那一项; 对不上交给上游原逻辑。
# 零协汉化的事件数据没有标题字段, 画面上也不保证有事件名, 所以按同一屏其它选项的原文认事件。 # 零协汉化的事件数据没有标题字段, 画面上也不保证有事件名, 所以按同一屏其它选项的原文认事件。
EVENT_CHOICES_ENV = 'LCP_EVENT_CHOICES' # 0 = 关闭; 文件路径 = 用这张表代替默认表 EVENT_CHOICES_ENV = 'LCP_EVENT_CHOICES' # 0 = 关闭; 文件路径 = 用这张表代替默认表
EVENT_FALLBACK_ENV = 'LCP_EVENT_FALLBACK' # 1 = 表里没有的事件也点第 1 项(默认 0, 交给 AALC)
EVENT_CHOICES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'event_choices.json') EVENT_CHOICES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'event_choices.json')
EVENT_OPTION = 'event/select_first_option_assets.png' # 每个选项框的左边缘, 多目标匹配得到每一项 EVENT_OPTION = 'event/select_first_option_assets.png' # 每个选项框的左边缘, 多目标匹配得到每一项
EVENT_HOOK = 'event/unknown_event.png' # 上游每轮挑选项的第一步 EVENT_HOOK = 'event/unknown_event.png' # 上游每轮挑选项的第一步
@@ -1253,6 +1254,19 @@ def load_event_choices(path=EVENT_CHOICES_FILE):
return rules return rules
def _option_click_pos(raw_lines, text, marker, scale):
"""选项的点击点: 优先用那句话自己的中心。
2026-11-18 实测: 点标记(EVENT_OPTION 模板勾到的行首)事件不推进, 同一选项被点 10 次还在;
标记常落在选项按钮的左侧装饰上, 真正可点的是文字那一行。
"""
target = normalize_event_text(text or '')
if target:
for line, x, y in raw_lines:
norm = normalize_event_text(line)
if norm and len(norm) >= 2 and norm in target:
return (float(x), float(y))
return (float(marker[0]), float(marker[1]))
def event_options(markers, lines, scale): def event_options(markers, lines, scale):
"""选项框左边缘(从上到下)与各自的文字: [(位置, 归一后的文字), ...]。""" """选项框左边缘(从上到下)与各自的文字: [(位置, 归一后的文字), ...]。"""
markers = sorted(markers, key=lambda m: float(m[1])) markers = sorted(markers, key=lambda m: float(m[1]))
@@ -1284,6 +1298,7 @@ def install_event_choices(log=print, env=None):
log('[lc_mcp] 事件选项表已关闭(%s=0), 沿用 AALC 原逻辑' % EVENT_CHOICES_ENV) log('[lc_mcp] 事件选项表已关闭(%s=0), 沿用 AALC 原逻辑' % EVENT_CHOICES_ENV)
return None return None
path = setting or EVENT_CHOICES_FILE path = setting or EVENT_CHOICES_FILE
fallback = (env.get(EVENT_FALLBACK_ENV) or '').strip() == '1'
try: try:
rules = load_event_choices(path) rules = load_event_choices(path)
except (OSError, ValueError) as e: except (OSError, ValueError) as e:
@@ -1310,7 +1325,8 @@ def install_event_choices(log=print, env=None):
markers = auto.find_element(EVENT_OPTION, find_type='image_with_multiple_targets', threshold=0.75) markers = auto.find_element(EVENT_OPTION, find_type='image_with_multiple_targets', threshold=0.75)
if not markers: if not markers:
return None return None
options = event_options(markers, _ocr_lines(auto), cfg.set_win_size / 1440) raw_lines = _ocr_lines(auto)
options = event_options(markers, raw_lines, cfg.set_win_size / 1440)
texts = tuple(text for _, text in options) texts = tuple(text for _, text in options)
shown = ' | '.join('%d=%s' % (i + 1, text or '?') for i, text in enumerate(texts)) shown = ' | '.join('%d=%s' % (i + 1, text or '?') for i, text in enumerate(texts))
@@ -1322,6 +1338,14 @@ def install_event_choices(log=print, env=None):
return True return True
rule, i = choose_event_option(rules, texts) rule, i = choose_event_option(rules, texts)
if rule is None and state['fallback'] and options and texts and texts[0]:
# 2026-11-18: 上游对认不出的事件会「无法解决事件, 尝试回到初始界面」直接回主界面。
# LCP_EVENT_FALLBACK=1 时改成点第 1 项, 至少把事件走过去。
position = _option_click_pos(raw_lines, texts[0], options[0][0], cfg.set_win_size / 1440)
log('[lc_mcp] 事件选项: %s; 表里没有, 兜底点第 1 项「%s」' % (shown, texts[0]))
decisions.record('event', 1, 'fallback_first', options=list(texts))
auto.mouse_click(position[0], position[1])
return position
if rule is None: if rule is None:
if once('[lc_mcp] 事件选项: %s; 表里没有这个事件, 交给 AALC' % shown): if once('[lc_mcp] 事件选项: %s; 表里没有这个事件, 交给 AALC' % shown):
decisions.record('event', None, 'not_in_table', options=list(texts)) decisions.record('event', None, 'not_in_table', options=list(texts))
@@ -1339,12 +1363,13 @@ def install_event_choices(log=print, env=None):
state['clicks'] += 1 state['clicks'] += 1
log('[lc_mcp] 事件 %s: %s; 按表选第 %d 项「%s」' % (rule['name'], shown, i + 1, rule['text'])) log('[lc_mcp] 事件 %s: %s; 按表选第 %d 项「%s」' % (rule['name'], shown, i + 1, rule['text']))
decisions.record('event', i + 1, 'text', event=rule['name'], event_id=rule['id'], options=list(texts)) decisions.record('event', i + 1, 'text', event=rule['name'], event_id=rule['id'], options=list(texts))
position = (float(options[i][0][0]), float(options[i][0][1])) position = _option_click_pos(raw_lines, texts[i], options[i][0], cfg.set_win_size / 1440)
auto.mouse_click(position[0], position[1]) auto.mouse_click(position[0], position[1])
return position return position
def event_handling(self, *args, **kwargs): def event_handling(self, *args, **kwargs):
state = {'clicks': 0, 'logged': set(), 'clicked': None, 'passed': None} state = {'clicks': 0, 'logged': set(), 'clicked': None, 'passed': None,
'fallback': fallback}
real_find, real_click = auto.find_element, auto.mouse_click real_find, real_click = auto.find_element, auto.mouse_click
def find_element(target, *a, **kw): def find_element(target, *a, **kw):
@@ -1767,6 +1792,58 @@ def boost_theme_pack_weights(weights, packs, system, bonus, language='zh_cn', ha
return result, {k: info[k] for k in ordered} return result, {k: info[k] for k in ordered}
# ---------------------------------------------------------------- 卡包刷新按钮
# 2026-11-18 用户反馈: 卡包页按「刷新」没按上(模板 0.90 命中、点下去卡包不变)。
# 上游点的是 mirror/theme_pack/refresh_assets.png 的模板中心, 勾到的可能只是图标; 改成 OCR 找
# 右上角的「刷新 N/3」文字并点它的中心, 找不到再退回模板点击。
THEME_PACK_REFRESH = 'mirror/theme_pack/refresh_assets.png'
THEME_PACK_REFRESH_BOX = (620, 0, 1280, 160) # 只在右上角找, 避开商店的「关键词刷新」
def _refresh_text_pos(auto, box=THEME_PACK_REFRESH_BOX):
"""右上角「刷新」文字的中心坐标; 没有返回 None。"""
x0, y0, x1, y1 = box
for text, x, y in _ocr_lines(auto):
if '刷新' not in str(text):
continue
if x0 <= x <= x1 and y0 <= y <= y1:
return (x, y)
return None
def install_theme_pack_refresh_click(log=print):
"""卡包页刷新改成按 OCR 文字点。返回原 click_element, 未安装返回 None。"""
try:
from module.automation import auto
except Exception as e:
log('[lc_mcp] 卡包刷新补丁跳过: 无法导入 %s' % e)
return None
original = getattr(auto, 'click_element', None)
if original is None:
log('[lc_mcp] 卡包刷新补丁跳过: auto 没有 click_element')
return None
def click_element(target, *args, **kwargs):
if target != THEME_PACK_REFRESH or kwargs.get('click') is False:
return original(target, *args, **kwargs)
try:
pos = _refresh_text_pos(auto)
except Exception as e:
log('[lc_mcp] 找刷新按钮出错(%s: %s), 用模板点击' % (type(e).__name__, e))
pos = None
if pos:
auto.mouse_click(int(pos[0]), int(pos[1]))
log('[lc_mcp] 刷新卡包: 按 OCR 点「刷新」(%d,%d)' % pos)
decisions.record('theme_pack', None, 'refresh_click', pos=list(pos))
return True
return original(target, *args, **kwargs)
click_element.__wrapped__ = original
auto.click_element = click_element
log('[lc_mcp] patch: 卡包刷新按 OCR 点「刷新」文字(找不到再退回模板)')
return original
def install_theme_pack_systems(log=print, env=None, route=None, route_name='路线'): def install_theme_pack_systems(log=print, env=None, route=None, route_name='路线'):
"""镜牢选卡包时按当局体系给卡包加分。返回原 select_theme_pack, 未安装返回 None。 """镜牢选卡包时按当局体系给卡包加分。返回原 select_theme_pack, 未安装返回 None。
+3 -1
View File
@@ -17,7 +17,8 @@ from .aalc_patches import (TaskAbort, WindowGuard, driver_click_tasks, headless_
install_gift_confirm_guard, install_gift_preference, install_image_error_guard, install_key_hold, install_gift_confirm_guard, install_gift_preference, install_image_error_guard, install_key_hold,
install_robust_set_foreground, install_shop_audit, install_shop_by_name, install_robust_set_foreground, install_shop_audit, install_shop_by_name,
install_system_team_selection, install_team_screen_guard, install_system_team_selection, install_team_screen_guard,
install_theme_pack_audit, install_theme_pack_systems, install_typed_keyboard_road, install_theme_pack_audit, install_theme_pack_refresh_click, install_theme_pack_systems,
install_typed_keyboard_road,
mirror_progress, stop_driver_click) mirror_progress, stop_driver_click)
from .decisions import decisions from .decisions import decisions
from .game_lock import GameBusyError, exclusive_game from .game_lock import GameBusyError, exclusive_game
@@ -167,6 +168,7 @@ def _run(task, params):
install_theme_pack_systems(log=log, route=rabbit['theme_packs'], route_name='兔子洞路线') install_theme_pack_systems(log=log, route=rabbit['theme_packs'], route_name='兔子洞路线')
else: else:
install_theme_pack_systems(log=log) install_theme_pack_systems(log=log)
install_theme_pack_refresh_click(log=log) # 刷新卡包按 OCR 点(上游模板点不中)
install_theme_pack_audit(log=log) # 装在加分之后(包在外层), 审计记得到加分 install_theme_pack_audit(log=log) # 装在加分之后(包在外层), 审计记得到加分
if rabbit: if rabbit:
install_rabbit_hole(log=log, config=rabbit) install_rabbit_hole(log=log, config=rabbit)
+31 -3
View File
@@ -320,11 +320,21 @@ def click_point_is_on_foreground(sx, sy, hwnd=None):
if not fg: if not fg:
return False, '当前没有前台窗口(GetForegroundWindow=0)' return False, '当前没有前台窗口(GetForegroundWindow=0)'
if hwnd: if hwnd:
if fg == hwnd or _api('user32', 'IsChild', wintypes.BOOL, if not (fg == hwnd or _api('user32', 'IsChild', wintypes.BOOL,
[wintypes.HWND, wintypes.HWND])(hwnd, fg): [wintypes.HWND, wintypes.HWND])(hwnd, fg)):
return True, 'ok'
return False, ('前台不是目标窗口(前台=%r, 目标=%r) —— 这次点击会打到别的窗口' return False, ('前台不是目标窗口(前台=%r, 目标=%r) —— 这次点击会打到别的窗口'
% (window_title(fg), window_title(hwnd))) % (window_title(fg), window_title(hwnd)))
# 2026-11-18: 前台是游戏也不代表点击点还在游戏里。blank 点击用的是客户区 (1,1),
# 窗口一旦移动/缩放而坐标是旧值时, 屏幕点会落到窗口外的桌面左上角 —— 那里正好是
# 回收站图标, 于是"老是弹出回收站"。这里补一次客户区包含判断。
try:
area = client_area_on_screen(hwnd)
except OSError as e:
return False, str(e)
if not (area[0] <= sx < area[2] and area[1] <= sy < area[3]):
return False, ('点击点(%d,%d)不在游戏客户区 %d,%d-%d,%d 内 —— 会点到桌面/别的窗口'
% (sx, sy, area[0], area[1], area[2], area[3]))
return True, 'ok'
pt = wintypes.POINT(int(sx), int(sy)) pt = wintypes.POINT(int(sx), int(sy))
rect = wintypes.RECT() rect = wintypes.RECT()
get_rect = _api('user32', 'GetWindowRect', wintypes.BOOL, get_rect = _api('user32', 'GetWindowRect', wintypes.BOOL,
@@ -337,6 +347,24 @@ def click_point_is_on_foreground(sx, sy, hwnd=None):
return True, 'ok' return True, 'ok'
def client_area_on_screen(hwnd):
"""游戏客户区在屏幕上的矩形 (left, top, right, bottom)。"""
if not hwnd:
raise OSError('没有游戏窗口句柄')
rect = wintypes.RECT()
fn = _api('user32', 'GetClientRect', wintypes.BOOL,
[wintypes.HWND, ctypes.POINTER(wintypes.RECT)])
if not fn(hwnd, ctypes.byref(rect)):
raise OSError('GetClientRect 失败, 无法确认点击点在游戏内')
tl = wintypes.POINT(rect.left, rect.top)
br = wintypes.POINT(rect.right, rect.bottom)
c2s = _api('user32', 'ClientToScreen', wintypes.BOOL,
[wintypes.HWND, ctypes.POINTER(wintypes.POINT)])
if not c2s(hwnd, ctypes.byref(tl)) or not c2s(hwnd, ctypes.byref(br)):
raise OSError('ClientToScreen 失败, 无法确认点击点在游戏内')
return (tl.x, tl.y, br.x, br.y)
def client_to_screen(hwnd, x, y): def client_to_screen(hwnd, x, y):
"""游戏客户区坐标 -> 屏幕坐标。""" """游戏客户区坐标 -> 屏幕坐标。"""
if not hwnd: if not hwnd: