卡包: 体系分不再把 P 不过去的包抬上来(I-19); 拖拽兜底拆成独立补丁(I-20)

Browse Source
- I-19 用户「老是选择 p 不过去的包」: AALC 表里负分 = Boss 难打/拖时间(绝望骑士、时间杀人魔、卡塞蒂 -5),
  体系分 +6 直接加上去 -5 变 +1, 震颤队每局 3/4 层去打憎恶与绝望/时间杀人时间(3 层 16.7 分钟 vs 同层 8~11)。
  现在卡包在 AALC 的原权重 < THEME_PACK_LIFT_MIN(0) 时体系分只折成 ±0.9 小数, 同档排先后、不跨档;
  0 分及以上照旧加满; 兔子洞路线分不变。权重可能是小数(绝望 -5→-4.4)。
  回放 11-15~11-21 的 61 次选包: 15 次改选(全是 3/4/5 层的憎恶与绝望/时间杀人时间)。
- I-20 fb7a0ec 的拖拽兜底挂在加分补丁里: 加分关掉/没体系时不生效, 且拖完马上截图会把转场中的成功也当失败。
  改成 install_theme_pack_drag_retry 单独装: 3 秒内每 0.5 秒看「刷新」, 消失即确认, 一直在才下移 160(1440 标定)再拖。
- theme_pack_systems.json 说明同步; ISSUES 记 I-19/I-20。

单测: 795 passed(新增 test_theme_pack_drag_retry 9 例, test_theme_pack_systems +3)。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yws
2026-11-22 09:10:36 +00:00
co-authored by Claude Opus 5.5
parent fb7a0ecfdc
commit 4db3cd2605
6 changed files with 305 additions and 62 deletions
+98 -35
View File
@@ -1733,9 +1733,15 @@ def install_theme_pack_audit(log=print):
# BACKLOG R-01 / ISSUES I-08: theme_pack_list.yaml 几乎全是 0, 所有卡包并列最高分, 每层都拿最左边那个。 # BACKLOG R-01 / ISSUES I-08: theme_pack_list.yaml 几乎全是 0, 所有卡包并列最高分, 每层都拿最左边那个。
# 这里在 AALC 选卡包时把它的权重表临时加上「卡包对当局体系的加分」(lc_mcp/data/theme_pack_systems.json), # 这里在 AALC 选卡包时把它的权重表临时加上「卡包对当局体系的加分」(lc_mcp/data/theme_pack_systems.json),
# 不改配置文件。AALC 拿卡包卡面 OCR 文字按权重表的键做子串匹配、取第一个命中的键, 所以加过分的键排在最前面。 # 不改配置文件。AALC 拿卡包卡面 OCR 文字按权重表的键做子串匹配、取第一个命中的键, 所以加过分的键排在最前面。
#
# ISSUES I-19(2026-11-22 用户「老是选择 p 不过去的包」): AALC 表里的负分就是「Boss 难打 / 拖时间」(绝望骑士、
# 时间杀人魔、卡塞蒂都是 -5)。原来体系分 +6 直接加上去, -5 变 +1, 压过所有 0 分卡包, 震颤队每局 3、4 层都去打
# 憎恶与绝望 / 时间杀人时间(3 层 16.7 分钟 vs 同层 0 分卡包大多 8~11; 4 层 18~20 vs 13~17)。现在先看 AALC 的分(打不打得过),
# 再看体系: 原权重 < THEME_PACK_LIFT_MIN 的卡包, 体系分只折成 ±0.9 以内的小数, 在同一档里排先后, 不跨档。
THEME_PACK_SYSTEMS_ENV = 'LCP_THEME_PACK_SYSTEMS' # 0 = 关闭; 文件路径 = 用这张表代替默认表 THEME_PACK_SYSTEMS_ENV = 'LCP_THEME_PACK_SYSTEMS' # 0 = 关闭; 文件路径 = 用这张表代替默认表
THEME_PACK_THRESHOLD_ENV = 'LCP_THEME_PACK_THRESHOLD' # 优选阈值; 0 = 不动上游(theme_pack_list.yaml 的值) THEME_PACK_THRESHOLD_ENV = 'LCP_THEME_PACK_THRESHOLD' # 优选阈值; 0 = 不动上游(theme_pack_list.yaml 的值)
THEME_PACK_THRESHOLD_DEFAULT = 1 # 最高分低于它先刷新卡包 THEME_PACK_THRESHOLD_DEFAULT = 1 # 最高分低于它先刷新卡包
THEME_PACK_LIFT_MIN = 0 # AALC 原权重不低于它才加满体系分; 想让 -1/-2(挨打但打得过)也加满就改成 -2
THEME_PACK_SYSTEMS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'theme_pack_systems.json') THEME_PACK_SYSTEMS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'theme_pack_systems.json')
THEME_PACK_UNKNOWN_KEYS = ('未知', 'unknown') # AALC 认不出卡包时的兜底权重键, 不当卡包名用 THEME_PACK_UNKNOWN_KEYS = ('未知', 'unknown') # AALC 认不出卡包时的兜底权重键, 不当卡包名用
THEME_PACK_BOOSTED = {} # 本次选卡包加过分的键 → {pack, system, from, to}; 卡包审计记到 decisions 里 THEME_PACK_BOOSTED = {} # 本次选卡包加过分的键 → {pack, system, from, to}; 卡包审计记到 decisions 里
@@ -1782,12 +1788,14 @@ def load_theme_pack_systems(path=THEME_PACK_SYSTEMS_FILE):
return result, list(loaded.values()) return result, list(loaded.values())
def theme_pack_bonus(pack, system, bonus): def theme_pack_bonus(pack, system, bonus, base=0):
"""卡包对体系的加分(可以是负的)。 """卡包对体系的加分(可以是负的、可以是小数)。base 是这个卡包在 AALC 表里的原权重。
体系包给 featured 档, 有这个体系的专属饰品按件数给 unique 档, 社区推荐给 recommend 档, 取最大; 体系包给 featured 档, 有这个体系的专属饰品按件数给 unique 档, 社区推荐给 recommend 档, 取最大;
社区说这个体系走它不划算(avoid 里有这个体系)就不加; 速刷要避开的(avoid 里有 '*')再减 avoid。 社区说这个体系走它不划算(avoid 里有这个体系)就不加; 速刷要避开的(avoid 里有 '*')再减 avoid。
打法指定的路线卡包(pack['route'] 是它的加分, 如兔子洞)最后算, 至少给这么多, 不受体系和 avoid 影响。 AALC 判成难打的卡包(base < THEME_PACK_LIFT_MIN)上面这些只折成 ±0.9 以内的小数: 同是 -5 的几个包里
挑本体系的, 但不会因此压过打得过的卡包(ISSUES I-19)。
打法指定的路线卡包(pack['route'] 是它的加分, 如兔子洞)最后算, 至少给这么多, 不受体系、avoid 和难度档影响。
""" """
score = bonus['featured'] if system in (pack.get('featured') or ()) else 0 score = bonus['featured'] if system in (pack.get('featured') or ()) else 0
count = (pack.get('unique') or {}).get(system, 0) count = (pack.get('unique') or {}).get(system, 0)
@@ -1800,6 +1808,8 @@ def theme_pack_bonus(pack, system, bonus):
score = min(score, 0) score = min(score, 0)
if '*' in avoid: if '*' in avoid:
score -= bonus.get('avoid', 0) score -= bonus.get('avoid', 0)
if score and base < THEME_PACK_LIFT_MIN:
score = round(max(-0.9, min(0.9, score / 10)), 1)
if pack.get('route'): if pack.get('route'):
score = max(score, pack['route']) score = max(score, pack['route'])
return score return score
@@ -1810,6 +1820,12 @@ def _pack_text(text):
return str(text).replace(' ', '').lower() return str(text).replace(' ', '').lower()
def _weight(value):
"""权重去掉浮点尾巴: -5 + 0.6 记成 -4.4, 整数还是整数(日志、审计好读)。"""
value = round(value, 1)
return int(value) if value == int(value) else value
def boost_theme_pack_weights(weights, packs, system, bonus, language='zh_cn', hard_mode=None): def boost_theme_pack_weights(weights, packs, system, bonus, language='zh_cn', hard_mode=None):
"""把体系加分加进 AALC 的卡包权重表。返回 (新表, {键: {packs, system, from, to}})。 """把体系加分加进 AALC 的卡包权重表。返回 (新表, {键: {packs, system, from, to}})。
@@ -1821,14 +1837,22 @@ def boost_theme_pack_weights(weights, packs, system, bonus, language='zh_cn', ha
免得连带改了别的卡包。某个卡包的分没被已有的键表达出来(复刻比原版多、或者 AALC 表里没有它)时, 免得连带改了别的卡包。某个卡包的分没被已有的键表达出来(复刻比原版多、或者 AALC 表里没有它)时,
再用卡包全名做键。原权重: 键在表里就用表里的; 全名键用这个卡包被 AALC 认成的那个键的分, 认不出来按 再用卡包全名做键。原权重: 键在表里就用表里的; 全名键用这个卡包被 AALC 认成的那个键的分, 认不出来按
「未知」。改过分的键按长度从长到短排在最前面: AALC 按表的顺序取第一个命中的键, 全名(更具体)要先于短片段。 「未知」。改过分的键按长度从长到短排在最前面: AALC 按表的顺序取第一个命中的键, 全名(更具体)要先于短片段。
卡包加多少还看它在 AALC 表里的原权重(同样按表顺序第一个命中的键, 认不出按「未知」): 负分的是难打的包,
体系分只当同档里的先后(见 theme_pack_bonus)。
""" """
field = 'en' if language == 'en' else 'zh' field = 'en' if language == 'en' else 'zh'
unknown = next((weights[k] for k in THEME_PACK_UNKNOWN_KEYS if k in weights), -5) unknown = next((weights[k] for k in THEME_PACK_UNKNOWN_KEYS if k in weights), -5)
if hard_mode is not None: if hard_mode is not None:
packs = [pack for pack in packs if pack.get('hard' if hard_mode else 'normal')] packs = [pack for pack in packs if pack.get('hard' if hard_mode else 'normal')]
scored = [(pack, theme_pack_bonus(pack, system, bonus), _pack_text(pack[field])) for pack in packs]
aalc_keys = [k for k in weights if k not in THEME_PACK_UNKNOWN_KEYS and _pack_text(k)] aalc_keys = [k for k in weights if k not in THEME_PACK_UNKNOWN_KEYS and _pack_text(k)]
def base(name):
return next((weights[k] for k in aalc_keys if _pack_text(k) in name), unknown)
scored = [(pack, theme_pack_bonus(pack, system, bonus, base(name)), name)
for pack, name in ((pack, _pack_text(pack[field])) for pack in packs)]
def holders(key): def holders(key):
return [(pack, extra) for pack, extra, name in scored if _pack_text(key) in name] return [(pack, extra) for pack, extra, name in scored if _pack_text(key) in name]
@@ -1843,9 +1867,9 @@ def boost_theme_pack_weights(weights, packs, system, bonus, language='zh_cn', ha
changed, info = {}, {} changed, info = {}, {}
def add(key, start, extra): def add(key, start, extra):
changed[key] = start + extra changed[key] = _weight(start + extra)
info[key] = {'packs': [pack['zh'] for pack, _ in holders(key)], 'system': system, info[key] = {'packs': [pack['zh'] for pack, _ in holders(key)], 'system': system,
'from': start, 'to': start + extra} 'from': start, 'to': changed[key]}
for key in aalc_keys: for key in aalc_keys:
extra = key_bonus(key) extra = key_bonus(key)
@@ -1921,6 +1945,70 @@ def install_theme_pack_refresh_click(log=print):
return original return original
# ---------------------------------------------------------------- 卡包拖拽确认
# 2026-11-22 用户反馈: 5 层选卡包卡了 40 分钟(11-16 08:19 第 3 层 40 秒里连选 3 次「绝望」, 多半也是没拖上)。上游用
# mouse_drag_down(模板匹配点) 把卡包"拉下来"确认, 匹配点常落在卡面的放大镜上, 从那里往下拖不生效。
# 拖完等一会儿还看得到右上角「刷新」(还在选包页)就往下挪 160(1440 标定, 720 下 80px, 落在卡面中部)再拖一次。
# 不能拖完马上看: 卡包落下、转场要一会儿, 那时「刷新」还在, 会把拖成功的也当失败再拖一次。
THEME_PACK_DRAG_RETRY_DY = 160 # 1440 标定
THEME_PACK_DRAG_WAIT = 3.0 # 秒; 上游拖完本来也 sleep(3)
THEME_PACK_DRAG_POLL = 0.5
def _left_theme_pack_page(auto, wait=THEME_PACK_DRAG_WAIT, poll=THEME_PACK_DRAG_POLL):
"""拖完 wait 秒内右上角「刷新」消失 = 已确认; 一直在 = 没拖上。截图/识别出错按已确认算(交给上游下一轮)。"""
deadline = time.monotonic() + wait
while True:
try:
if not auto.find_element(THEME_PACK_REFRESH, take_screenshot=True):
return True
except Exception:
return True
if time.monotonic() >= deadline:
return False
time.sleep(poll)
def install_theme_pack_drag_retry(log=print):
"""卡包拖拽没确认时下移再拖一次。返回原 select_theme_pack, 未安装返回 None。
只在 select_theme_pack 期间换 auto.mouse_drag_down, 每次调用时取当时的绑定(驱动代理、别的补丁换过也跟着走)。
和体系加分分开装: 关掉加分(LCP_THEME_PACK_SYSTEMS=0)或这局没有体系时也要有这个兜底。
"""
try:
from tasks.mirror import mirror as mirror_mod
from module.automation import auto
from module.config import cfg
except Exception as e:
log('[lc_mcp] 卡包拖拽兜底跳过: 无法导入 %s' % e)
return None
original = getattr(mirror_mod, 'select_theme_pack', None)
if original is None or not hasattr(auto, 'mouse_drag_down'):
log('[lc_mcp] 卡包拖拽兜底跳过: 上游没有 select_theme_pack / auto.mouse_drag_down')
return None
def select_theme_pack(*args, **kwargs):
real_drag = auto.mouse_drag_down
def mouse_drag_down(x, y, *a, **kw):
result = real_drag(x, y, *a, **kw)
if _left_theme_pack_page(auto):
return result
dy = THEME_PACK_DRAG_RETRY_DY * cfg.set_win_size / 1440
log('[lc_mcp] 卡包拖拽没确认(%d,%d), 下移 %dpx 再拖一次' % (x, y, dy))
decisions.record('theme_pack', None, 'drag_retry', pos=[int(x), int(y)], dy=int(dy))
return real_drag(x, y + dy, *a, **kw)
with _override(auto, 'mouse_drag_down', mouse_drag_down):
return original(*args, **kwargs)
select_theme_pack.__wrapped__ = original
mirror_mod.select_theme_pack = select_theme_pack
log('[lc_mcp] patch: 卡包拖拽没确认时下移 %dpx 再拖一次' % (THEME_PACK_DRAG_RETRY_DY * cfg.set_win_size / 1440))
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。
@@ -1953,10 +2041,6 @@ def install_theme_pack_systems(log=print, env=None, route=None, route_name='路
except Exception as e: except Exception as e:
log('[lc_mcp] 卡包按体系加分跳过: 无法导入 %s' % e) log('[lc_mcp] 卡包按体系加分跳过: 无法导入 %s' % e)
return None return None
try:
from module.automation import auto
except Exception:
auto = None # 单测没有 automation 模块: 只少「拖拽没确认再拖一次」的兜底
original = getattr(mirror_mod, 'select_theme_pack', None) original = getattr(mirror_mod, 'select_theme_pack', None)
theme_list = getattr(theme_pack_mod, 'theme_list', None) theme_list = getattr(theme_pack_mod, 'theme_list', None)
try: try:
@@ -1995,34 +2079,12 @@ def install_theme_pack_systems(log=print, env=None, route=None, route_name='路
if info: if info:
log('[lc_mcp] 卡包按体系 %s%s 加分: %s' % ( log('[lc_mcp] 卡包按体系 %s%s 加分: %s' % (
system or '(无)', ('+' + route_name) if route else '', ', '.join( system or '(无)', ('+' + route_name) if route else '', ', '.join(
'%s %d→%d' % (key, item['from'], item['to']) for key, item in info.items()))) '%s %s→%s' % (key, item['from'], item['to']) for key, item in info.items())))
THEME_PACK_BOOSTED.update(info) THEME_PACK_BOOSTED.update(info)
return result return result
# 2026-11-22: 5 层选卡包卡了 40 分钟。上游用 mouse_drag_down(pack) 把卡包"拉下来"确认,
# 卡包模板的匹配点常落在放大镜上, 从那里往下拖不生效; 拖完还停在选包页就下移 80px 再拖一次。
real_drag = getattr(auto, 'mouse_drag_down', None) if auto is not None else None
def mouse_drag_down(x, y, *a, **kw):
if real_drag is None:
return None
real_drag(x, y, *a, **kw)
try:
still = auto.find_element(THEME_PACK_REFRESH, take_screenshot=True)
except Exception:
still = None
if still:
log('[lc_mcp] 卡包拖拽没确认, 下移 80px 再拖一次 (%d,%d)' % (x, y + 80))
decisions.record('theme_pack', None, 'drag_retry', pos=[int(x), int(y)])
real_drag(x, y + 80, *a, **kw)
return None
if auto is None:
with _override(theme_list, 'get_effective_theme_pack_list', get_effective_theme_pack_list): with _override(theme_list, 'get_effective_theme_pack_list', get_effective_theme_pack_list):
return original(*args, **kwargs) return original(*args, **kwargs)
with _override(theme_list, 'get_effective_theme_pack_list', get_effective_theme_pack_list), \
_override(auto, 'mouse_drag_down', mouse_drag_down):
return original(*args, **kwargs)
select_theme_pack.__wrapped__ = original select_theme_pack.__wrapped__ = original
mirror_mod.Mirror.__init__ = __init__ mirror_mod.Mirror.__init__ = __init__
@@ -2030,9 +2092,10 @@ def install_theme_pack_systems(log=print, env=None, route=None, route_name='路
# 2026-11-16 用户要求: 卡包均分低就刷新。AALC 只在「最高分 < preferred_thresholds」时刷新, # 2026-11-16 用户要求: 卡包均分低就刷新。AALC 只在「最高分 < preferred_thresholds」时刷新,
# 而主题包表里 preferred_thresholds 是 0 → 0 分也当优选, 永远不刷新。 # 而主题包表里 preferred_thresholds 是 0 → 0 分也当优选, 永远不刷新。
# 这里默认抬到 1(LCP_THEME_PACK_THRESHOLD 可调, 0 = 不动上游), 让"没有本体系卡包"的楼层先刷新 # 这里默认抬到 1(LCP_THEME_PACK_THRESHOLD 可调, 0 = 不动上游), 让"没有打得过的本体系卡包"的楼层先刷新
# (上游最多点 4 次刷新), 刷完仍不达标还是选最高分那一个。只改内存里的值, 不写 theme_pack_list.yaml。 # (上游最多点 4 次刷新), 刷完仍不达标还是选最高分那一个。只改内存里的值, 不写 theme_pack_list.yaml。
# 11-18~11-21 实机就是这样跑的: 0 分楼层点 4 次「刷新」后按 highest_weight 选。 # 11-18~11-21 实机就是这样跑的: 0 分楼层点 4 次「刷新」后按 highest_weight 选。
# 难打的卡包加了体系分也到不了 0(见 I-19), 所以只有它带本体系饰品时同样先刷新, 刷完再在打得过的里取最高。
setting = (env.get(THEME_PACK_THRESHOLD_ENV) or '').strip() setting = (env.get(THEME_PACK_THRESHOLD_ENV) or '').strip()
try: try:
want = int(setting) if setting else THEME_PACK_THRESHOLD_DEFAULT want = int(setting) if setting else THEME_PACK_THRESHOLD_DEFAULT
@@ -2045,7 +2108,7 @@ def install_theme_pack_systems(log=print, env=None, route=None, route_name='路
current = 0 current = 0
if want > current: if want > current:
theme_list.preferred_thresholds = want theme_list.preferred_thresholds = want
log('[lc_mcp] 卡包优选阈值 %d → %d(低于它先刷新卡包, 上游最多刷 3 次)' log('[lc_mcp] 卡包优选阈值 %d → %d(低于它先刷新卡包, 上游最多点 4 次刷新)'
% (current, want)) % (current, want))
log('[lc_mcp] patch: 镜牢卡包按体系加分(%s, %d 个卡包%s)' % ( log('[lc_mcp] patch: 镜牢卡包按体系加分(%s, %d 个卡包%s)' % (