- scripts/lc_ui.py: 脚本坐标按 1600x900 书写, OCR 结果与点击/拖动按实际客户区换算; 去掉写死的 D:\lc-mcp 路径 - levelup.py: 升级以详情页等级/经验条变化判定成功; 同步先判断弹窗是否仍在, 无过场时不再多按 ESC、不再盲点取消 - auto_cycle.py: task_status 连续报 stall 即停任务; exit 0 但有 errors 判失败 - tasks.py: 运行中日志尾部"配队人数OCR得到"刷屏时返回 stall 字段 - keep_display.ps1: tscon 改用 -EncodedCommand 并记录退出码; 会话号自动取游戏所在会话 - 更正 10-05 README 选队结论、summary 卡死①统计、PITFALLS 坑 13 根因 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
442 lines
16 KiB
Python
442 lines
16 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""人格升级/同步自动化。
|
|
|
|
流程(全部基于实测坐标,1600x900 客户区):
|
|
罪人界面 IDENTITIES 网格
|
|
-> 长按卡片(drag 起终点相同) 打开人格详情
|
|
-> 点 Level Up
|
|
-> 对每种训练券点 »(全部投入)
|
|
-> Confirm
|
|
-> 关窗
|
|
-> (可选) 点 Uptie -> Uptie -> Confirm -> 关窗
|
|
-> 返回网格
|
|
|
|
用法:
|
|
python levelup.py list 列出网格里队内(SELECTED)人格及等级
|
|
python levelup.py weakest [--uptie] 对队内等级最低者执行升级(可选同步)
|
|
python levelup.py card <col> <row> [--uptie]
|
|
python levelup.py back 返回网格
|
|
|
|
退出码: 0 成功 / 1 失败
|
|
"""
|
|
import sys
|
|
import time
|
|
|
|
from lc_ui import click, keypress, long_press, screen_text, state
|
|
|
|
# 网格布局(1600x900 坐标, 由 lc_ui 换算到实际客户区)。
|
|
# 第 4 行在 y=942, 超出客户区, 需要滚动才能看到, 这里不处理。
|
|
COLS = [335, 508, 681, 853, 1026, 1198]
|
|
ROWS = [260, 487, 715]
|
|
|
|
# 固定控件坐标
|
|
BACK = (85, 75)
|
|
BTN_LEVEL_UP = (1164, 235)
|
|
BTN_UPTIE = (1367, 235)
|
|
TICKET_MAX_X = 1133
|
|
TICKET_ROWS = [383, 490, 598] # IV / III / II
|
|
POWERUP_CONFIRM = (1030, 670)
|
|
POWERUP_CANCEL = (603, 670)
|
|
UPTIE_CONFIRM = (1085, 580)
|
|
UPTIE_DONE_CONFIRM = (772, 661)
|
|
UPTIE_CANCEL = (526, 660)
|
|
|
|
|
|
def near(items, cx, cy, dx=100, dy=115):
|
|
return [i for i in items
|
|
if abs(i.get('x', 0) - cx) < dx and abs(i.get('y', 0) - cy) < dy]
|
|
|
|
|
|
def parse_level(text):
|
|
"""'LV36' / 'Lv.04' / 'Lv-30' -> int;失败返回 None"""
|
|
digits = ''.join(ch for ch in str(text) if ch.isdigit())
|
|
return int(digits) if digits else None
|
|
|
|
|
|
def scan_grid(items):
|
|
"""返回 [(col, row, x, y, level, selected, name)]"""
|
|
cards = []
|
|
for ri, ry in enumerate(ROWS):
|
|
for ci, cx in enumerate(COLS):
|
|
ins = near(items, cx, ry)
|
|
if not ins:
|
|
continue
|
|
lvl = None
|
|
for it in ins:
|
|
t = it.get('text', '')
|
|
if t[:2].lower() == 'lv' and parse_level(t) is not None:
|
|
lvl = parse_level(t)
|
|
break
|
|
if lvl is None:
|
|
continue
|
|
sel = any('SELECTED' in it.get('text', '') for it in ins)
|
|
name = ' '.join(it.get('text', '') for it in ins
|
|
if it.get('y', 0) > ry
|
|
and not it.get('text', '')[:2].lower() == 'lv'
|
|
and 'SELECTED' not in it.get('text', ''))
|
|
cards.append((ci, ri, cx, ry, lvl, sel, name.strip()))
|
|
return cards
|
|
|
|
|
|
def cmd_list():
|
|
items = state().get('items', [])
|
|
cards = scan_grid(items)
|
|
if not cards:
|
|
print('网格为空或不在 IDENTITIES 界面')
|
|
print('当前画面: ' + screen_text(items)[:200])
|
|
return 1
|
|
print('%-4s %-4s %-6s %-9s %s' % ('col', 'row', 'lv', 'inTeam', 'name'))
|
|
for ci, ri, cx, ry, lvl, sel, name in cards:
|
|
print('%-4d %-4d %-6d %-9s %s' % (ci, ri, lvl, 'Y' if sel else '-', name))
|
|
return 0
|
|
|
|
|
|
def ticket_balance():
|
|
"""当前 Power-up 界面上的券余额 -> {tier: owned}
|
|
|
|
不靠券名文字判定档位(OCR 会把 III 认成 lll),改用行的 y 坐标:
|
|
三行固定为 IV / III / II。'Owned:o' 里的 o/O 视作 0。
|
|
"""
|
|
items = state().get('items', [])
|
|
bal = {}
|
|
for it in items:
|
|
t = it.get('text', '')
|
|
if 'Owned' not in t:
|
|
continue
|
|
tail = t.split('Owned')[-1]
|
|
digits = ''.join(ch for ch in tail if ch.isdigit())
|
|
val = int(digits) if digits else 0
|
|
y = it.get('y', 0)
|
|
tier = 'IV' if y < 390 else ('III' if y < 500 else 'II')
|
|
bal[tier] = val
|
|
return bal
|
|
|
|
|
|
def do_level_up(hint=None):
|
|
"""在已打开的人格详情页执行升级。返回 (ok, 描述), ok 为 None 表示没有券可用。
|
|
|
|
成败看详情页的等级/经验条在升级前后是否变化。不能看 'Level Up'/'Uptie'
|
|
字样: 详情页上它们一直都在, 升级失败也会被判成成功。
|
|
"""
|
|
lvl0, _, bar0 = read_detail(hint)
|
|
click(*BTN_LEVEL_UP)
|
|
time.sleep(3.5)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
# Power-up 弹窗独有 'Items' 分页与 'Owned' 字样
|
|
if 'Owned' not in txt or 'Cancel' not in txt:
|
|
return False, '未打开 Power-up 界面: ' + txt[:160]
|
|
before = ticket_balance()
|
|
if not any(v > 0 for v in before.values()):
|
|
click(*POWERUP_CANCEL)
|
|
time.sleep(2)
|
|
return None, '没有可用训练券(余额=%s), 跳过升级' % before
|
|
for y in TICKET_ROWS:
|
|
click(TICKET_MAX_X, y)
|
|
time.sleep(1.2)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
target = None
|
|
for it in items:
|
|
t = it.get('text', '')
|
|
if '▶' in t:
|
|
nums = [parse_level(p) for p in t.split('▶')]
|
|
nums = [n for n in nums if n is not None]
|
|
if len(nums) >= 2:
|
|
target = nums[-1]
|
|
if target is None:
|
|
# OCR 常把 ▶ 认成 · 或丢失, 退而求其次看是否有两段等级
|
|
for it in items:
|
|
t = it.get('text', '')
|
|
nums = [parse_level(p) for p in t.replace('·', '▶').split('▶')]
|
|
nums = [n for n in nums if n is not None]
|
|
if len(nums) >= 2 and nums[-1] > nums[0]:
|
|
target = nums[-1]
|
|
click(*POWERUP_CONFIRM)
|
|
time.sleep(4.5)
|
|
txt = screen_text(state().get('items', []))
|
|
if 'Owned' in txt and 'Cancel' in txt:
|
|
click(*POWERUP_CANCEL)
|
|
time.sleep(2)
|
|
return False, 'Confirm 后 Power-up 窗口仍在, 已取消(券=%s)' % before
|
|
lvl1, _, bar1 = read_detail(hint=target or lvl0 or hint)
|
|
desc = '券=%s 目标=%s 等级 %s->%s 经验 %s->%s' % (before, target, lvl0, lvl1, bar0, bar1)
|
|
if lvl0 is not None and lvl1 is not None and lvl1 > lvl0:
|
|
return True, desc
|
|
if bar0 is not None and bar1 is not None and bar1 != bar0:
|
|
return True, desc
|
|
return False, '升级未确认: ' + desc
|
|
|
|
|
|
def skip_cutscene(press_esc=True):
|
|
"""同步到三阶会解锁人格剧情并自动播放。ESC 会弹"是否跳过", 点 Confirm。
|
|
|
|
press_esc=False 时只处理已经弹出的跳过框, 不主动按 ESC——没有过场时按 ESC
|
|
会关掉当前弹窗或退出详情页。返回 True 表示确实跳过一个过场。
|
|
"""
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
if 'skip' not in txt.lower() and press_esc:
|
|
keypress('esc')
|
|
time.sleep(2)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
if 'skip' in txt.lower():
|
|
conf = None
|
|
for it in items:
|
|
if it.get('text', '').strip().startswith('Confirm'):
|
|
conf = it
|
|
if conf:
|
|
click(conf['x'], conf['y'])
|
|
time.sleep(4)
|
|
return True
|
|
return False
|
|
|
|
|
|
def do_uptie():
|
|
"""在人格详情页执行同步。返回 (ok, 描述)
|
|
|
|
注意: 同步成功会解锁并自动播放"人格剧情", 此时界面既没有 Uptied 字样
|
|
也不是失败——必须先跳过过场再判定, 否则会误报 FAIL。
|
|
"""
|
|
for attempt in range(2):
|
|
click(*BTN_UPTIE)
|
|
time.sleep(4)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
if ('Currency Req' in txt or 'Stats Increased' in txt
|
|
or 'Skills Gained' in txt or 'Skills Upgraded' in txt):
|
|
break
|
|
else:
|
|
return False, '未打开 Uptie 弹窗: ' + txt[:160]
|
|
click(*UPTIE_CONFIRM)
|
|
time.sleep(4.5)
|
|
|
|
txt = screen_text(state().get('items', []))
|
|
# 弹窗还在(仍显示材料需求)说明没同步成。必须先判断这个: 弹窗里本身就有
|
|
# 'Skills Gained', 放在成功判定后面会把失败认成成功。
|
|
if 'Currency Req' in txt or 'Egoshard' in txt:
|
|
click(*UPTIE_CANCEL)
|
|
time.sleep(2)
|
|
return False, '同步未生效(通常缺自我碎片): ' + txt[:160]
|
|
if skip_cutscene(press_esc=False):
|
|
time.sleep(3)
|
|
return True, '同步成功(并跳过了解锁的人格剧情)'
|
|
if 'Uptied' in txt or 'Enhanced' in txt or 'Gained' in txt:
|
|
click(*UPTIE_DONE_CONFIRM)
|
|
time.sleep(2.5)
|
|
return True, '同步成功'
|
|
# 什么都没认出: 可能是剧情已经在播但还没出跳过提示, 这时才按 ESC
|
|
if skip_cutscene(press_esc=True):
|
|
time.sleep(3)
|
|
return True, '同步成功(并跳过了解锁的人格剧情)'
|
|
# 画面未知时不盲点坐标, 交给调用方按网格判断退回
|
|
return False, '同步结果未知: ' + txt[:160]
|
|
|
|
|
|
def cmd_card(ci, ri, uptie=False):
|
|
if not (0 <= ci < len(COLS) and 0 <= ri < len(ROWS)):
|
|
print('坐标越界')
|
|
return 1
|
|
cx, cy = COLS[ci], ROWS[ri]
|
|
print('长按卡片 col=%d row=%d @(%d,%d)' % (ci, ri, cx, cy))
|
|
long_press(cx, cy)
|
|
time.sleep(4)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
if 'Level Up' not in txt and 'Uptie' not in txt:
|
|
print('长按未打开详情页: ' + txt[:200])
|
|
return 1
|
|
print('详情页已打开')
|
|
ok, desc = do_level_up()
|
|
print('升级: %s (%s)' % ('OK' if ok else 'FAIL', desc))
|
|
if uptie:
|
|
ok2, desc2 = do_uptie()
|
|
print('同步: %s (%s)' % ('OK' if ok2 else 'FAIL', desc2))
|
|
click(*BACK)
|
|
time.sleep(2.5)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
# 同步解锁的人格剧情可能在返回途中才弹出, 先跳过再判断
|
|
if 'skip' in txt.lower() or 'LOADING' in txt.upper():
|
|
skip_cutscene()
|
|
time.sleep(3)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
# 只在还不在网格时再退一层——避免多余返回键落到主界面上(那里会进剧情)
|
|
if not ('IDENTITIES' in txt and 'Facades' in txt):
|
|
click(*BACK)
|
|
time.sleep(2.5)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
if not ('IDENTITIES' in txt and 'Facades' in txt):
|
|
print('[warn] 未能回到 Identities 网格, 当前: ' + txt[:160])
|
|
return 0 if ok else 1
|
|
|
|
|
|
# 每级升级所需经验(来源 wiki "EXP per Level" 表)。
|
|
# EXP_NEED[L] = 从 L-1 级升到 L 级所需经验。
|
|
EXP_NEED = {
|
|
2: 10, 3: 12, 4: 15, 5: 20, 6: 27, 7: 40, 8: 59, 9: 88, 10: 125, 11: 168,
|
|
12: 227, 13: 298, 14: 381, 15: 482, 16: 591, 17: 728, 18: 885, 19: 1064,
|
|
20: 1261, 21: 1488, 22: 1739, 23: 2016, 24: 2327, 25: 2674, 26: 3047,
|
|
27: 3456, 28: 3899, 29: 4378, 30: 4899, 31: 3899, 32: 4378, 33: 4899,
|
|
34: 5468, 35: 6075, 36: 4899, 37: 5468, 38: 6075, 39: 6722, 40: 7413,
|
|
41: 6075, 42: 6722, 43: 7413, 44: 8156, 45: 8953, 46: 7413, 47: 7413,
|
|
48: 7413, 49: 7413, 50: 7413, 51: 8156, 52: 8156, 53: 8156, 54: 8156,
|
|
55: 8156, 56: 8953, 57: 8953, 58: 8953, 59: 8953, 60: 8953, 61: 9792,
|
|
62: 9792, 63: 9792, 64: 9792, 65: 9792,
|
|
}
|
|
|
|
|
|
def level_from_bar(cur, need, hint=None):
|
|
"""由详情页 EXP 进度条 "cur/need" 反推等级。
|
|
|
|
进度条分母 = 当前等级升下一级所需经验 = EXP_NEED[L+1]。
|
|
表里数值有重复(如 4899 对应 30/33/36), 用网格读到的等级作 tiebreak。
|
|
"""
|
|
cands = [lv - 1 for lv, v in EXP_NEED.items() if v == need and lv - 1 >= 1]
|
|
if not cands:
|
|
return None
|
|
if hint:
|
|
return min(cands, key=lambda c: abs(c - hint))
|
|
return cands[0]
|
|
|
|
|
|
def read_detail(hint=None):
|
|
"""从已打开的人格详情页读 (真实等级, 名字, 经验条 (cur, need))。
|
|
|
|
网格里的小号艺术字 OCR 极不可靠(实测 LV14->'Lv.1', LV24->'LV2H');
|
|
详情页的大号等级也常被漏认(实测 LCB 罪人页只认出 '547/885')。
|
|
所以以 EXP 进度条反推为主, 直接读到的 LV 值为辅。
|
|
"""
|
|
items = state().get('items', [])
|
|
lv_cands = []
|
|
name = ''
|
|
bar = None
|
|
for it in items:
|
|
t = it.get('text', '').strip()
|
|
y = it.get('y', 0)
|
|
up = t.upper().replace(' ', '')
|
|
if up.startswith('LV') and 140 < y < 340:
|
|
v = parse_level(t)
|
|
if v:
|
|
lv_cands.append(v)
|
|
if 120 < y < 195 and len(t) > 6 and not up.startswith('LV'):
|
|
if not name:
|
|
name = t
|
|
if bar is None and 195 < y < 300 and '/' in t:
|
|
parts = [p for p in t.split('/') if p.strip().isdigit()]
|
|
if len(parts) == 2:
|
|
bar = (int(parts[0]), int(parts[1]))
|
|
|
|
direct = min(lv_cands) if lv_cands else None
|
|
from_bar = level_from_bar(bar[0], bar[1], hint=hint) if bar else None
|
|
|
|
if from_bar is not None and direct is not None:
|
|
# 两者都有时以进度条为准(数字识别比艺术字可靠), 但差异过大时告警
|
|
if abs(from_bar - direct) > 2:
|
|
print(' [warn] 进度条推算 Lv.%d 与直读 Lv.%d 不符, 取进度条'
|
|
% (from_bar, direct))
|
|
return from_bar, name, bar
|
|
if from_bar is not None:
|
|
return from_bar, name, bar
|
|
return direct, name, bar
|
|
|
|
|
|
def cmd_progress(target=34, uptie=True, max_try=6):
|
|
"""按网格等级升序依次打开详情, 以详情页真实等级判断, 升级第一个低于 target 的。
|
|
|
|
网格 OCR 会误读等级, 所以不能只信它——必须逐个打开核实。
|
|
"""
|
|
items = state().get('items', [])
|
|
cards = scan_grid(items)
|
|
team = sorted([c for c in cards if c[5]], key=lambda c: c[4])
|
|
if not team:
|
|
print('未找到队内(SELECTED)人格')
|
|
return 1
|
|
for ci, ri, cx, ry, ocr_lvl, sel, nm in team[:max_try]:
|
|
print('--- 候选 col=%d row=%d (网格读作 Lv.%s %s)' % (ci, ri, ocr_lvl, nm))
|
|
long_press(cx, ry)
|
|
time.sleep(4)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
if 'Level Up' not in txt:
|
|
print(' 长按未打开详情, 跳过')
|
|
continue
|
|
true_lvl, true_name, _ = read_detail(hint=ocr_lvl)
|
|
print(' 详情页: %s 真实等级=%s' % (true_name, true_lvl))
|
|
if true_lvl is None:
|
|
# 详情页读不到时退回网格值——网格会误读, 但总比跳过整张卡好
|
|
print(' 详情页读不到等级, 退回网格值 Lv.%s' % ocr_lvl)
|
|
true_lvl = ocr_lvl
|
|
if true_lvl >= target:
|
|
print(' 已达目标 Lv.%d, 跳过' % target)
|
|
click(*BACK)
|
|
time.sleep(2.5)
|
|
continue
|
|
ok, desc = do_level_up(hint=true_lvl)
|
|
print(' 升级: %s (%s)' % ('OK' if ok else ('SKIP' if ok is None else 'FAIL'), desc))
|
|
if uptie:
|
|
ok2, desc2 = do_uptie()
|
|
print(' 同步: %s (%s)' % ('OK' if ok2 else 'FAIL', desc2))
|
|
click(*BACK)
|
|
time.sleep(2.5)
|
|
items = state().get('items', [])
|
|
txt = screen_text(items)
|
|
if not ('IDENTITIES' in txt and 'Facades' in txt):
|
|
click(*BACK)
|
|
time.sleep(2.5)
|
|
return 0 if ok else 1
|
|
print('前 %d 个候选都不需要升级或无法读取' % max_try)
|
|
return 0
|
|
|
|
|
|
def cmd_weakest(uptie=False):
|
|
items = state().get('items', [])
|
|
cards = scan_grid(items)
|
|
team = [c for c in cards if c[5]]
|
|
if not team:
|
|
print('未找到队内(SELECTED)人格')
|
|
return 1
|
|
team.sort(key=lambda c: c[4])
|
|
ci, ri, cx, ry, lvl, sel, name = team[0]
|
|
print('队内最低: Lv.%d %s (col=%d row=%d)' % (lvl, name, ci, ri))
|
|
return cmd_card(ci, ri, uptie=uptie)
|
|
|
|
|
|
def cmd_back():
|
|
click(*BACK)
|
|
time.sleep(2.5)
|
|
click(*BACK)
|
|
time.sleep(2.5)
|
|
print('已返回')
|
|
return 0
|
|
|
|
|
|
def main():
|
|
args = sys.argv[1:]
|
|
if not args:
|
|
print(__doc__)
|
|
return 2
|
|
if args[0] == 'list':
|
|
return cmd_list()
|
|
if args[0] == 'back':
|
|
return cmd_back()
|
|
if args[0] == 'weakest':
|
|
return cmd_weakest(uptie='--uptie' in args)
|
|
if args[0] == 'progress':
|
|
tgt = 34
|
|
for a in args[1:]:
|
|
if a.isdigit():
|
|
tgt = int(a)
|
|
return cmd_progress(target=tgt, uptie='--uptie' in args)
|
|
if args[0] == 'card' and len(args) >= 3:
|
|
return cmd_card(int(args[1]), int(args[2]), uptie='--uptie' in args)
|
|
print(__doc__)
|
|
return 2
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|