Fix background Unity input and shop boundaries; record login failure

Browse Source
This commit is contained in:
Codex Agent
2026-10-03 16:52:49 +08:00
parent 6cd0b2742a
commit 073e407346
13 changed files with 850 additions and 29 deletions
+43 -12
View File
@@ -26,6 +26,7 @@ SYSTEM_RULES = (
'遇到事件判定先点SKIP跳过对话,跳完后再选择事件选项、罪人或进行判定;剧情同样优先SKIP。' '遇到事件判定先点SKIP跳过对话,跳完后再选择事件选项、罪人或进行判定;剧情同样优先SKIP。'
'事件当前有“选择后获得”且无需判定、无需战斗的选项时直接选择它,不反复滚动;避开写着战斗胜利后的选项。' '事件当前有“选择后获得”且无需判定、无需战斗的选项时直接选择它,不反复滚动;避开写着战斗胜利后的选项。'
'确定确认/进入/开始战斗直接执行。地图优先可达事件和商店,减少战斗。' '确定确认/进入/开始战斗直接执行。地图优先可达事件和商店,减少战斗。'
'战斗奖励优先经费,纯P无需囤积E.G.O资源;可附带破裂合成材料的经费奖励优先。'
'选好路线直接回车进入,关卡编队界面也直接回车开战;保留原编队,不再检查人员。' '选好路线直接回车进入,关卡编队界面也直接回车开战;保留原编队,不再检查人员。'
'候选路线已由程序核对可达和节点类型,无需再确认已完成的开局配置。多个同类型节点都可达时默认正前方,不因没有事件节点而要求分析。' '候选路线已由程序核对可达和节点类型,无需再确认已完成的开局配置。多个同类型节点都可达时默认正前方,不因没有事件节点而要求分析。'
'保留当前编队。开局三级饰品三选一必须选择标准负载电池,再确认领取;不能当成额外观测拒绝。' '保留当前编队。开局三级饰品三选一必须选择标准负载电池,再确认领取;不能当成额外观测拒绝。'
@@ -79,6 +80,28 @@ def button_enabled(state, item):
return False return False
def purchased_slot(state, item):
"""OCR may omit the orange Purchased badge above a bought skill slot."""
try:
import cv2
import numpy as np
template_path = REPO_ROOT / 'assets' / 'ui' / 'purchased_english.png'
template = np.array(screen_image(template_path, 'L'))
width = state['screen'].get('w', 1920)
height = state['screen'].get('h', 1080)
if width != 1920:
template = cv2.resize(template, None, fx=width/1920, fy=width/1920)
cx = item['x'] + item['w']/2
area = np.array(screen_image(state['screen']['path'], 'L').crop(
(round(cx-width*.075), round(item['y']-height*.2),
round(cx+width*.075), round(item['y']-height*.09))))
if area.shape[0] < template.shape[0] or area.shape[1] < template.shape[1]:
return False
return float(cv2.matchTemplate(area, template, cv2.TM_CCOEFF_NORMED).max()) >= .9
except (OSError, KeyError, ImportError):
return False
@functools.lru_cache(maxsize=64) @functools.lru_cache(maxsize=64)
def _map_template(kind, name, scale): def _map_template(kind, name, scale):
"""地图识别模板, 按截图比例缩放; 窗口尺寸不变时每帧复用, 不再重复读盘和计算特征点。 """地图识别模板, 按截图比例缩放; 窗口尺寸不变时每帧复用, 不再重复读盘和计算特征点。
@@ -275,11 +298,12 @@ def candidates(state, previous_battle=False, refresh_used=0):
('SKILL1', 'SKILL2') if '辛克莱' in header and state.get('floor', 3) < 3 else ('SKILL1', 'SKILL3')) ('SKILL1', 'SKILL2') if '辛克莱' in header and state.get('floor', 3) < 3 else ('SKILL1', 'SKILL3'))
if tuple(i['text'].replace(' ', '') for i in skills) == target: if tuple(i['text'].replace(' ', '') for i in skills) == target:
for item in items: for item in items:
if item['text'] == '购买': if item['text'] in ('购买', '确认') and button_enabled(state, item):
options['buy_swap'] = { options['buy_swap'] = {
'description': '已核对本层所需技能替换 %s→%s,点击购买完成。' % target, 'description': '已核对本层所需技能替换 %s→%s,点击购买完成。' % target,
'action': {'tool': 'click', 'args': {'x': item['x']+item['w']//2, 'action': {'tool': 'keypress', 'args': {'key': 'enter'}},
'y': item['y']+item['h']//2}}, 'fallback_action': {'tool': 'click', 'args': {'x': item['x']+item['w']//2,
'y': item['y']+item['h']//2}},
} }
return options return options
if any('当前持有技能' in t for t in texts): if any('当前持有技能' in t for t in texts):
@@ -481,6 +505,7 @@ def candidates(state, previous_battle=False, refresh_used=0):
party = ('辛克莱', '鸿璐', '希斯克利夫', '奥提斯', '格里高尔', '良秀', '浮士德') party = ('辛克莱', '鸿璐', '希斯克利夫', '奥提斯', '格里高尔', '良秀', '浮士德')
swaps = [(index, item) for index, item in enumerate(items) swaps = [(index, item) for index, item in enumerate(items)
if '替换' in item['text'] and any(name in item['text'] for name in party) if '替换' in item['text'] and any(name in item['text'] for name in party)
and not purchased_slot(state, item)
and not any('已购买' in sold['text'] and not any('已购买' in sold['text']
and abs(sold['x']+sold['w']/2-item['x']-item['w']/2) < width*.07 and abs(sold['x']+sold['w']/2-item['x']-item['w']/2) < width*.07
and 0 < item['y']-sold['y'] < height*.25 for sold in items)] and 0 < item['y']-sold['y'] < height*.25 for sold in items)]
@@ -503,13 +528,17 @@ def candidates(state, previous_battle=False, refresh_used=0):
'y': max(0, item['y'] - round(height*.095))}}, 'y': max(0, item['y'] - round(height*.095))}},
} }
if not swaps and refresh_used < 4: if not swaps and refresh_used < 4:
for index, item in enumerate(items): refreshes = [item for item in items if item['text'].replace(' ', '') == '刷新'
if item['text'].replace(' ', '') == '刷新' and button_enabled(state, item): and button_enabled(state, item)]
options['shop_refresh'] = { if refreshes:
'description': '没有出战角色可替换技能,刷新商店;本店已刷新%d/4次。' % refresh_used, # The keyword panel has another Refresh further right.
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w'] // 2, # Refresh stock, never overwrite this with keyword Refresh.
'y': item['y'] + item['h'] // 2}}, item = min(refreshes, key=lambda value: value['x'])
} options['shop_refresh'] = {
'description': '没有出战角色可替换技能,刷新商店;本店已刷新%d/4次。' % refresh_used,
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w'] // 2,
'y': item['y'] + item['h'] // 2}},
}
end_screen = battle_is_terminal(state) end_screen = battle_is_terminal(state)
battle = battle_is_visible(state) battle = battle_is_visible(state)
if not end_screen and (battle or previous_battle): if not end_screen and (battle or previous_battle):
@@ -525,7 +554,7 @@ def candidates(state, previous_battle=False, refresh_used=0):
options['button_%d' % index] = { options['button_%d' % index] = {
'description': '当前可见且非灰色按钮:%s;点击 OCR 中心。' % label, 'description': '当前可见且非灰色按钮:%s;点击 OCR 中心。' % label,
# 直接点已核对过的这一项: 重新按文字搜索要多一次截图+OCR, 还可能命中背景里的同名按钮 # 直接点已核对过的这一项: 重新按文字搜索要多一次截图+OCR, 还可能命中背景里的同名按钮
'action': ({'tool': 'keypress', 'args': {'key': 'enter'}} if label in ('进入', '开始战斗', '进行判定') 'action': ({'tool': 'keypress', 'args': {'key': 'enter'}} if label in ('进入', '开始战斗', '进行判定', '离开')
else {'tool': 'click', 'args': {'x': item['x'] + item['w']//2, else {'tool': 'click', 'args': {'x': item['x'] + item['w']//2,
'y': item['y'] + item['h']//2}}), 'y': item['y'] + item['h']//2}}),
} }
@@ -635,9 +664,11 @@ def unambiguous_routine(options):
key = actions[0] key = actions[0]
safe = ('modal_confirm', 'select_startup_battery', 'confirm_startup_battery', safe = ('modal_confirm', 'select_startup_battery', 'confirm_startup_battery',
'confirm_thunderbranch', 'confirm_reward', 'hardship_confirm', 'confirm_thunderbranch', 'confirm_reward', 'hardship_confirm',
'confirm_swap', 'buy_swap', 'claim_final', 'run_complete', 'retry_network') 'confirm_swap', 'buy_swap', 'claim_final', 'run_complete', 'retry_network', 'shop_refresh')
if key in safe: if key in safe:
return key return key
if key.startswith('skill_swap_'):
return key
if key.startswith('button_') and options[key]['action']['tool'] in ('click', 'keypress'): if key.startswith('button_') and options[key]['action']['tool'] in ('click', 'keypress'):
description = options[key]['description'] description = options[key]['description']
if any(label in description for label in ('确认', '继续', '进入', '开始战斗', '离开', '下一层', '进行判定')): if any(label in description for label in ('确认', '继续', '进入', '开始战斗', '离开', '下一层', '进行判定')):
+19 -3
View File
@@ -11,7 +11,7 @@ LABELS = {
'result':'结果', 'options':'选项', 'choices':'选项', 'veryhigh':'极高', 'result':'结果', 'options':'选项', 'choices':'选项', 'veryhigh':'极高',
'high':'高', 'shop':'商店', 'specialshop':'特殊商店', 'refresh':'刷新', 'high':'高', 'shop':'商店', 'specialshop':'特殊商店', 'refresh':'刷新',
'enhancegifts':'强化饰品', 'enhancee.g.ogifts':'强化饰品', 'purchase':'购买', 'enhancegifts':'强化饰品', 'enhancee.g.ogifts':'强化饰品', 'purchase':'购买',
'buy':'购买', 'purchased':'已购买', 'currentownedskills':'当前持有技能', 'buy':'购买', 'purchased':'已购买', 'currentownedskills':'当前持有技能', 'skillsowned':'当前持有技能',
'thunderbranch':'雷枝', '雷击木':'雷枝', 'talismanbundle':'成捆的符咒', 'thunderbranch':'雷枝', '雷击木':'雷枝', 'talismanbundle':'成捆的符咒',
'standard-dutybattery':'标准负载电池', 'standarddutybattery':'标准负载电池', 'standard-dutybattery':'标准负载电池', 'standarddutybattery':'标准负载电池',
'thrill':'快感', 'selecte.g.ogifts':'选择E.G.O饰品', 'thrill':'快感', 'selecte.g.ogifts':'选择E.G.O饰品',
@@ -35,12 +35,25 @@ def normalize(state):
if state.get('_lc_labels_normalized'): if state.get('_lc_labels_normalized'):
return state return state
rate_items = [] rate_items = []
for item in state.get('items') or []: source_items = state.get('items') or []
for item in source_items:
raw = item['text'] raw = item['text']
compact = re.sub(r'\s+', '', raw).lower().lstrip('×x') compact = re.sub(r'\s+', '', raw).lower().lstrip('×x')
compact = compact.replace('e.g.0', 'e.g.o') compact = compact.replace('e.g.0', 'e.g.o')
text = LABELS.get(compact, raw) text = LABELS.get(compact, raw)
if compact == 'enhance' and any(re.sub(r'\s+', '', other['text']).lower() == 'gifts'
and abs(other['x'] - item['x']) < 80 and 0 < other['y'] - item['y'] < 70
for other in source_items):
text = '强化饰品'
if text == raw: if text == raw:
if compact.startswith('aservererrorhasoccurred'):
text = '服务器发生错误'
elif re.fullmatch(r'retry(?:\d+|[>→»]+)?', compact):
text = '重试'
elif re.match(r'gain[0-9~〜+\-]+cost', compact):
text = '经费 ' + raw
elif re.match(r'e\.?g\.?o\.?resource', compact):
text = '资源 ' + raw
match = re.search(r'select(?:the)?(?:floor)?(\d+)(?:st|nd|rd|th)?floorthemepack', compact) match = re.search(r'select(?:the)?(?:floor)?(\d+)(?:st|nd|rd|th)?floorthemepack', compact)
if not match: if not match:
match = re.search(r'selectfloorthemepack(?:for)?floor(\d+)', compact) match = re.search(r'selectfloorthemepack(?:for)?floor(\d+)', compact)
@@ -64,8 +77,11 @@ def normalize(state):
text = '选择一位罪人' text = '选择一位罪人'
elif re.match(r'who(?:will|should)', compact): elif re.match(r'who(?:will|should)', compact):
text = '应该让谁 ' + raw text = '应该让谁 ' + raw
elif compact.startswith('skillreplacement') or compact.startswith('replaceskill'): elif (compact.startswith('skillreplacement') or compact.startswith('replaceskill')
or re.match(r'(?:replace|change).*skil', compact)):
text = '技能替换 ' + raw text = '技能替换 ' + raw
elif 'spend' in compact and 'replac' in compact and 'skil' in compact:
text = '是否消耗 技能替换 ' + raw
# English OCR sometimes merges several adjacent probability labels. # English OCR sometimes merges several adjacent probability labels.
# Keep each explicit Very High span as a separate observed candidate. # Keep each explicit Very High span as a separate observed candidate.
if item.get('y', 0) > state.get('screen', {}).get('h', 1080) * .8 and 'veryhigh' in compact: if item.get('y', 0) > state.get('screen', {}).get('h', 1080) * .8 and 'veryhigh' in compact: