P2-6 镜牢商店必买先按中文名购买, 取消 P2-7

Browse Source
- 商店每一格下面写着饰品中文名(实机截图可见)。install_shop_by_name 在
  buy_gifts 期间往 must_purchase 最前面临时插 3 个占位项, 上游逐个 click_element
  点到占位项时: 以 shop_coins_assets 为锚点在商品格范围内 OCR, 名字完全一致
  (允许 + 后缀)就点上方的图标, 之后购买/确认仍走上游循环; 图标模板在后面兜底。
- 名字表 lc_mcp/data/shop_gifts.json: AALC 5 张必买模板对应的饰品, 中文名按零协
  汉化; 同一名字一次进店最多点 4 次; 没命中的截图不重复 OCR。
- 审计记 shop/name_match; 装在商店审计之后, 购买仍记 purchase_clicked。
- LCP_SHOP_NAMES=0 关闭; 表读不了或上游不再逐个点 must_purchase 时记 [ERROR]。
- 单测执行上游真实的 Shop.buy_gifts, 坐标按截图实测。
- P2-7 观测饰品自动勾选按用户意见不做。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yws
2026-11-14 08:44:09 +00:00
co-authored by Claude Opus 5.5
parent 72d2ca1a5b
commit 40a5af0184
6 changed files with 494 additions and 5 deletions
+136
View File
@@ -992,6 +992,12 @@ def _source_calls(func, method, target):
return re.search(r'\.%s\(\s*["\']%s["\']' % (re.escape(method), re.escape(target)), source) is not None return re.search(r'\.%s\(\s*["\']%s["\']' % (re.escape(method), re.escape(target)), source) is not None
def _source_mentions(func, *needles):
"""上游函数源码里是否都有这些片段; 拿不到源码返回 None。"""
source = _upstream_source(func)
return None if source is None else all(needle in source for needle in needles)
def load_event_choices(path=EVENT_CHOICES_FILE): def load_event_choices(path=EVENT_CHOICES_FILE):
"""读事件表, 返回 [{'name', 'id', 'options', 'text'}]; 格式不对抛 ValueError。 """读事件表, 返回 [{'name', 'id', 'options', 'text'}]; 格式不对抛 ValueError。
@@ -1195,6 +1201,136 @@ def install_shop_audit(log=print):
return original return original
# ---------------------------------------------------------------- 商店按中文名购买
# 上游必买只认 mirror/shop/must_purchase/ 下 5 张图标模板(阈值 0.85)。汉化后商店每一格下面写着饰品中文名
# (docs/feedback/mirror_20261002_181322/special_shop_missed.png), 这里按名字表 OCR, 命中就点那一格的图标;
# 之后的"购买 -> 确认"仍是上游同一段循环, 模板留在后面兜底。
# 挂法: buy_gifts 期间在 must_purchase 最前面临时插几个占位项; 上游 for commodity in must_purchase:
# auto.click_element(commodity, ...) 点到占位项时改成按名字找。
SHOP_NAMES_ENV = 'LCP_SHOP_NAMES' # 0 = 关闭; 文件路径 = 用这张表代替默认表
SHOP_NAMES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'shop_gifts.json')
SHOP_BY_NAME = 'lc_mcp/shop_by_name' # 占位项; 不是图片, 只在补丁里认
SHOP_BY_NAME_SLOTS = 3 # 每轮必买最多按名字买几件
SHOP_NAME_CLICKS = 4 # 一次进店同一个名字最多点几次(钱不够时上游会重点)
SHOP_COINS = 'mirror/shop/shop_coins_assets.png' # 上游 re_sort_points 也拿它当商品格的锚点
SHOP_GRID_BOX = (0, 300, 1250, 900) # 名字行相对金币图标的范围(1440 标定; 实测两行名字在 +409/+716)
SHOP_NAME_TO_ICON = 155 # 名字行中心到图标中心的纵向距离(1440 标定, 1080 截图实测 116)
def load_shop_gifts(path=SHOP_NAMES_FILE):
"""读按名字购买的表, 返回归一后的名字元组(靠前的先买); 格式不对抛 ValueError。"""
with open(path, encoding='utf-8') as f:
raw = json.load(f)
gifts = raw.get('gifts') if isinstance(raw, dict) else None
if not isinstance(gifts, list) or not gifts:
raise ValueError('顶层应是 {"gifts": [{"name": ...}, ...]}')
names = []
for item in gifts:
name = item.get('name') if isinstance(item, dict) else None
if not isinstance(name, str) or not normalize_event_text(name):
raise ValueError('gifts 的每一项应有非空的 name')
if normalize_event_text(name) in names:
raise ValueError('%s 重复' % name)
names.append(normalize_event_text(name))
return tuple(names)
def shop_name_hits(lines, names, coins, scale):
"""商品格里名字对上表的行, 按表里的顺序: [(名字, 图标位置), ...]。
只认金币图标右下方商品格范围内、与名字完全一致的行(允许强化后缀 +); 子串不算, 免得半截名字误买。
"""
left, top, right, bottom = (v * scale for v in SHOP_GRID_BOX)
x0, y0 = float(coins[0]), float(coins[1])
found = {}
for text, x, y in lines:
if not (x0 + left <= x <= x0 + right and y0 + top <= y <= y0 + bottom):
continue
clean = normalize_event_text(text).rstrip('+')
if clean in names and clean not in found:
found[clean] = (x, y - SHOP_NAME_TO_ICON * scale)
return [(name, found[name]) for name in names if name in found]
def install_shop_by_name(log=print, env=None):
"""商店必买先按中文名找。返回原 Shop.buy_gifts, 未安装返回 None。"""
env = os.environ if env is None else env
setting = (env.get(SHOP_NAMES_ENV) or '').strip()
if setting == '0':
log('[lc_mcp] 商店按名字购买已关闭(%s=0), 只用 AALC 的图标模板' % SHOP_NAMES_ENV)
return None
path = setting or SHOP_NAMES_FILE
try:
names = load_shop_gifts(path)
except (OSError, ValueError) as e:
log('[ERROR] [lc_mcp] 商店按名字购买跳过: %s 读不了(%s: %s)' % (path, type(e).__name__, e))
return None
try:
from tasks.mirror import in_shop
from module.automation import auto
from module.config import cfg
except Exception as e:
log('[lc_mcp] 商店按名字购买跳过: 无法导入 %s' % e)
return None
shop_cls, must = getattr(in_shop, 'Shop', None), getattr(in_shop, 'must_purchase', None)
original = getattr(shop_cls, 'buy_gifts', None)
if original is None or not isinstance(must, list):
log('[ERROR] [lc_mcp] 商店按名字购买跳过: 上游没有 Shop.buy_gifts 或 must_purchase 列表')
return None
if _source_calls(original, 'click_element', 'mirror/shop/purchase_assets.png') is False or \
_source_mentions(original, 'for commodity in must_purchase', 'auto.click_element(commodity') is False:
log('[ERROR] [lc_mcp] 商店按名字购买跳过: 上游 Shop.buy_gifts 不再逐个 click_element(must_purchase), 挂不上')
return None
def pick(state, real_find):
"""按名字点一格返回 True; 画面上没有表里的名字返回 False。"""
shot = auto.screenshot
if shot is not None and shot is state['empty_shot']:
return False # 这张截图刚 OCR 过且没有命中, 后面几个占位项不用再跑
coins = real_find(SHOP_COINS)
hits = []
if coins:
scale = cfg.set_win_size / 1440
hits = [(name, pos) for name, pos in shop_name_hits(_ocr_lines(auto), names, coins, scale)
if state['clicks'].get(name, 0) < SHOP_NAME_CLICKS]
if not hits:
state['empty_shot'] = shot
return False
name, (x, y) = hits[0]
state['clicks'][name] = state['clicks'].get(name, 0) + 1
if state['clicks'][name] == 1:
log('[lc_mcp] 商店: 按名字找到「%s」, 点它的图标' % name)
decisions.record('shop', name, 'name_match', on_screen=[n for n, _ in hits])
auto.mouse_click(x, y)
return True
def buy_gifts(self, *args, **kwargs):
state = {'clicks': {}, 'empty_shot': None}
real_find, real_click = auto.find_element, auto.click_element
def click_element(target, *a, **kw):
if target != SHOP_BY_NAME:
return real_click(target, *a, **kw)
try:
return pick(state, real_find)
except Exception as e:
log('[lc_mcp] 商店按名字购买出错(%s: %s), 只用图标模板' % (type(e).__name__, e))
return False
must[0:0] = [SHOP_BY_NAME] * SHOP_BY_NAME_SLOTS
try:
with _override(auto, 'click_element', click_element):
return original(self, *args, **kwargs)
finally:
must[:] = [item for item in must if item != SHOP_BY_NAME]
buy_gifts.__wrapped__ = original # 让后装的补丁查得到上游源码
shop_cls.buy_gifts = buy_gifts
log('[lc_mcp] patch: 商店必买先按中文名找(%s, %d 个名字), 图标模板兜底' % (os.path.basename(path), len(names)))
return original
THEME_PACK_PICK = re.compile(r'此次选择卡包关键词[::]\s*(\S+)') THEME_PACK_PICK = re.compile(r'此次选择卡包关键词[::]\s*(\S+)')
THEME_PACK_WEIGHTS = '当前主题包权重列表' THEME_PACK_WEIGHTS = '当前主题包权重列表'
THEME_PACK_SOURCE = 'select_theme_pack.py' THEME_PACK_SOURCE = 'select_theme_pack.py'
+2 -1
View File
@@ -14,7 +14,7 @@ from .aalc_engine import bootstrap
from .aalc_patches import (WindowGuard, driver_click_tasks, headless_hdr_warning, from .aalc_patches import (WindowGuard, driver_click_tasks, headless_hdr_warning,
install_default_battle_team, install_event_choices, install_exact_team_match, install_default_battle_team, install_event_choices, install_exact_team_match,
install_gift_preference, install_robust_set_foreground, install_shop_audit, install_gift_preference, install_robust_set_foreground, install_shop_audit,
install_system_team_selection, install_theme_pack_audit, install_shop_by_name, install_system_team_selection, install_theme_pack_audit,
install_typed_keyboard_road, mirror_progress, stop_driver_click) install_typed_keyboard_road, 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
@@ -134,6 +134,7 @@ def _run(task, params):
install_gift_preference(log=log) install_gift_preference(log=log)
install_event_choices(log=log) install_event_choices(log=log)
install_shop_audit(log=log) install_shop_audit(log=log)
install_shop_by_name(log=log) # 装在审计之后(包在外层), 审计才看得到按名字点的那一下
install_theme_pack_audit(log=log) install_theme_pack_audit(log=log)
guard = WindowGuard(screen, cfg, log=log) guard = WindowGuard(screen, cfg, log=log)
guard.start() guard.start()
+17
View File
@@ -0,0 +1,17 @@
{
"_说明": [
"镜牢商店按中文名购买(BACKLOG P2-6)。AALC 必买项之前先按这张表 OCR 商店格子下面的名字, 命中就买; 靠前的先买。",
"只认与名字完全一致的格子(去空白、标点, 允许强化后缀 +); AALC 的 5 张必买图标模板仍在后面兜底。整表关闭: 任务环境变量 LCP_SHOP_NAMES=0。",
"默认 5 个就是 AALC 必买模板(assets/images/default/share/mirror/shop/must_purchase/*.png)对应的饰品, 中文名按零协汉化 LLC_zh-CN/EGOgift_MirrorDungeon.json(2026-11-14 核对 LocalizeLimbusCompany@231a8bc)。",
"AALC 日志把必买项叫'回血饰品', 核对描述后只有 采血包/归途/石版字符 是回血; 缘分残片 是全队 +5 级, 卡蜜拉 是每场非集中战先削敌人 20% 体力。",
"顺序是建议: 立即见效的放前面, 再按回血量。可以加别的饰品名, 写零协汉化里的名字原文。",
"饰品名来自零协汉化 LocalizeLimbusCompany(https://github.com/LocalizeLimbusCompany/LocalizeLimbusCompany, CC BY-NC-SA 4.0)。"
],
"gifts": [
{"name": "缘分残片", "id": 9082, "template": "piece_of_relationship.png", "note": "获得时编队所有人格提升 5 级"},
{"name": "卡蜜拉", "id": 9036, "template": "carmilla.png", "note": "非集中遭遇战开始时, 对全体敌人造成体力上限 20% 的固定伤害"},
{"name": "采血包", "id": 9004, "template": "phlebotomy_pack.png", "note": "技能造成伤害时恢复已失去体力的 12.5%(暴怒技能 25%)"},
{"name": "归途", "id": 9039, "template": "homeward.png", "note": "关卡开始时全体恢复体力上限 12% 的体力"},
{"name": "石版字符", "id": 9017, "template": "lithograph.png", "note": "敌人陷入混乱时, 体力最低的人格恢复体力上限 5%(有暴食攻击技能 10%)"}
]
}