Fix background Unity input and shop boundaries; record login failure
This commit is contained in:
@@ -26,6 +26,7 @@ SYSTEM_RULES = (
|
||||
'遇到事件判定先点SKIP跳过对话,跳完后再选择事件选项、罪人或进行判定;剧情同样优先SKIP。'
|
||||
'事件当前有“选择后获得”且无需判定、无需战斗的选项时直接选择它,不反复滚动;避开写着战斗胜利后的选项。'
|
||||
'确定确认/进入/开始战斗直接执行。地图优先可达事件和商店,减少战斗。'
|
||||
'战斗奖励优先经费,纯P无需囤积E.G.O资源;可附带破裂合成材料的经费奖励优先。'
|
||||
'选好路线直接回车进入,关卡编队界面也直接回车开战;保留原编队,不再检查人员。'
|
||||
'候选路线已由程序核对可达和节点类型,无需再确认已完成的开局配置。多个同类型节点都可达时默认正前方,不因没有事件节点而要求分析。'
|
||||
'保留当前编队。开局三级饰品三选一必须选择标准负载电池,再确认领取;不能当成额外观测拒绝。'
|
||||
@@ -79,6 +80,28 @@ def button_enabled(state, item):
|
||||
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)
|
||||
def _map_template(kind, name, scale):
|
||||
"""地图识别模板, 按截图比例缩放; 窗口尺寸不变时每帧复用, 不再重复读盘和计算特征点。
|
||||
@@ -275,10 +298,11 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
('SKILL1', 'SKILL2') if '辛克莱' in header and state.get('floor', 3) < 3 else ('SKILL1', 'SKILL3'))
|
||||
if tuple(i['text'].replace(' ', '') for i in skills) == target:
|
||||
for item in items:
|
||||
if item['text'] == '购买':
|
||||
if item['text'] in ('购买', '确认') and button_enabled(state, item):
|
||||
options['buy_swap'] = {
|
||||
'description': '已核对本层所需技能替换 %s→%s,点击购买完成。' % target,
|
||||
'action': {'tool': 'click', 'args': {'x': item['x']+item['w']//2,
|
||||
'action': {'tool': 'keypress', 'args': {'key': 'enter'}},
|
||||
'fallback_action': {'tool': 'click', 'args': {'x': item['x']+item['w']//2,
|
||||
'y': item['y']+item['h']//2}},
|
||||
}
|
||||
return options
|
||||
@@ -481,6 +505,7 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
party = ('辛克莱', '鸿璐', '希斯克利夫', '奥提斯', '格里高尔', '良秀', '浮士德')
|
||||
swaps = [(index, item) for index, item in enumerate(items)
|
||||
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 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)]
|
||||
@@ -503,8 +528,12 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
'y': max(0, item['y'] - round(height*.095))}},
|
||||
}
|
||||
if not swaps and refresh_used < 4:
|
||||
for index, item in enumerate(items):
|
||||
if item['text'].replace(' ', '') == '刷新' and button_enabled(state, item):
|
||||
refreshes = [item for item in items if item['text'].replace(' ', '') == '刷新'
|
||||
and button_enabled(state, item)]
|
||||
if refreshes:
|
||||
# The keyword panel has another Refresh further right.
|
||||
# Refresh stock, never overwrite this with keyword Refresh.
|
||||
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,
|
||||
@@ -525,7 +554,7 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
options['button_%d' % index] = {
|
||||
'description': '当前可见且非灰色按钮:%s;点击 OCR 中心。' % label,
|
||||
# 直接点已核对过的这一项: 重新按文字搜索要多一次截图+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,
|
||||
'y': item['y'] + item['h']//2}}),
|
||||
}
|
||||
@@ -635,9 +664,11 @@ def unambiguous_routine(options):
|
||||
key = actions[0]
|
||||
safe = ('modal_confirm', 'select_startup_battery', 'confirm_startup_battery',
|
||||
'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:
|
||||
return key
|
||||
if key.startswith('skill_swap_'):
|
||||
return key
|
||||
if key.startswith('button_') and options[key]['action']['tool'] in ('click', 'keypress'):
|
||||
description = options[key]['description']
|
||||
if any(label in description for label in ('确认', '继续', '进入', '开始战斗', '离开', '下一层', '进行判定')):
|
||||
|
||||
Reference in New Issue
Block a user