Streamline mirror confirmations and enforce updated rupture route
This commit is contained in:
+122
-31
@@ -1,4 +1,4 @@
|
|||||||
"""Jev chooses every scene/action; lc-mcp performs only validated candidates."""
|
"""Validated scene actions for Jev decisions and fixed speedrun macros."""
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
@@ -7,6 +7,7 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -27,8 +28,9 @@ SYSTEM_RULES = (
|
|||||||
'保留当前编队。开局三级饰品三选一必须选择标准负载电池,再确认领取;不能当成额外观测拒绝。'
|
'保留当前编队。开局三级饰品三选一必须选择标准负载电池,再确认领取;不能当成额外观测拒绝。'
|
||||||
'成捆的符咒++、标准负载电池和鸡胸为核心,保留不可出售或合成;仅略过单独的额外观测。其他苦难避开敌方体力上限和防御等级。'
|
'成捆的符咒++、标准负载电池和鸡胸为核心,保留不可出售或合成;仅略过单独的额外观测。其他苦难避开敌方体力上限和防御等级。'
|
||||||
'3层起辛克莱1换3,黑兽奥提斯2换3,其他出战1换3。只在商店强化饰品。'
|
'3层起辛克莱1换3,黑兽奥提斯2换3,其他出战1换3。只在商店强化饰品。'
|
||||||
|
'快感尽量在2、3层商店合成,并当场强化至二级++;4层仅补做。观测允许领取破裂体系雷枝,之后到商店强化,保留核心和技能预算。'
|
||||||
'商店没有出战角色可替换技能时允许刷新,当前商店最多4次;有可替换角色先按技能表替换。'
|
'商店没有出战角色可替换技能时允许刷新,当前商店最多4次;有可替换角色先按技能表替换。'
|
||||||
'第一至第四层禁止选择2号线卡包,留到第五层优先选;刷新次数为零时允许使用卡包观测。层末必须选择苦难再推进,不能当额外观测默认拒绝饰品。'
|
'第一至第四层禁止选择2号线卡包,第五层必选2号线;刷新次数为零时允许使用卡包观测。层末选完奖励连续回车进入下一层。离开商店也用回车;未生效再点当前按钮。'
|
||||||
'卡包信息不清先点对应放大镜查看;核心饰品齐全时按通关速度选择现有卡包,不为可选饰品反复刷新。'
|
'卡包信息不清先点对应放大镜查看;核心饰品齐全时按通关速度选择现有卡包,不为可选饰品反复刷新。'
|
||||||
'信息不足、重复操作仍无效、苦难无法明确核对,或你判断需要主助手分析时选 requires_analysis。'
|
'信息不足、重复操作仍无效、苦难无法明确核对,或你判断需要主助手分析时选 requires_analysis。'
|
||||||
)
|
)
|
||||||
@@ -180,9 +182,10 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
|||||||
return options
|
return options
|
||||||
gift_headers = sum(t == '获得E.G.O饰品' for t in texts)
|
gift_headers = sum(t == '获得E.G.O饰品' for t in texts)
|
||||||
if gift_headers == 1 and '拒绝饰品' in texts and '选择' in texts:
|
if gift_headers == 1 and '拒绝饰品' in texts and '选择' in texts:
|
||||||
core = any(name in combined for name in ('成捆的符咒','标准负载电池','干巴柴涩鸡胸肉','干松紧致鸡胸肉'))
|
core = any(name in combined for name in ('成捆的符咒','标准负载电池','干巴柴涩鸡胸肉','干松紧致鸡胸肉','快感','雷枝'))
|
||||||
if core:
|
if core and '雷枝' not in combined:
|
||||||
return options
|
return options
|
||||||
|
if not core:
|
||||||
target = next(i for i in items if i['text'].replace(' ','') == '拒绝饰品')
|
target = next(i for i in items if i['text'].replace(' ','') == '拒绝饰品')
|
||||||
options['decline_extra_observation'] = {'description': '拒绝单张无关额外饰品。',
|
options['decline_extra_observation'] = {'description': '拒绝单张无关额外饰品。',
|
||||||
'action': {'tool':'click','args':{'x':target['x']+target['w']//2,'y':target['y']+target['h']//2}}}
|
'action': {'tool':'click','args':{'x':target['x']+target['w']//2,'y':target['y']+target['h']//2}}}
|
||||||
@@ -192,10 +195,11 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
|||||||
and button_enabled(state,i)), None)
|
and button_enabled(state,i)), None)
|
||||||
options['event_finish'] = {
|
options['event_finish'] = {
|
||||||
'description': '判定结果已出现,快速连按回车结束事件并返回地图。',
|
'description': '判定结果已出现,快速连按回车结束事件并返回地图。',
|
||||||
'action': ({'tool':'click','args':{'x':continuation['x']+continuation['w']//2,
|
'action': {'tool':'advance_dialog','args':{'presses':5}},
|
||||||
'y':continuation['y']+continuation['h']//2}}
|
|
||||||
if continuation else {'tool': 'advance_dialog', 'args': {'presses': 5}}),
|
|
||||||
}
|
}
|
||||||
|
if continuation:
|
||||||
|
options['event_finish']['fallback_action']={'tool':'click','args':{
|
||||||
|
'x':continuation['x']+continuation['w']//2,'y':continuation['y']+continuation['h']//2}}
|
||||||
return options
|
return options
|
||||||
for index, item in enumerate(items):
|
for index, item in enumerate(items):
|
||||||
if item['text'].replace(' ', '').upper() == 'SKIP' and button_enabled(state, item):
|
if item['text'].replace(' ', '').upper() == 'SKIP' and button_enabled(state, item):
|
||||||
@@ -287,6 +291,7 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
|||||||
item=next((i for i in items if i['text'].replace(' ','')=='确认' and width*.4 < i['x']+i['w']/2 < width*.6),None)
|
item=next((i for i in items if i['text'].replace(' ','')=='确认' and width*.4 < i['x']+i['w']/2 < width*.6),None)
|
||||||
if item:
|
if item:
|
||||||
options['modal_confirm']={'description':'按回车快速确认当前获得饰品弹窗。','action':{'tool':'keypress','args':{'key':'enter'}}}
|
options['modal_confirm']={'description':'按回车快速确认当前获得饰品弹窗。','action':{'tool':'keypress','args':{'key':'enter'}}}
|
||||||
|
options['modal_confirm']['fallback_action']={'tool':'click','args':{'x':item['x']+item['w']//2,'y':item['y']+item['h']//2}}
|
||||||
return options
|
return options
|
||||||
if '追加的苦难' in combined and '获得E.G.O' in combined:
|
if '追加的苦难' in combined and '获得E.G.O' in combined:
|
||||||
for number, fraction in enumerate((.188, .395, .60, .813), 1):
|
for number, fraction in enumerate((.188, .395, .60, .813), 1):
|
||||||
@@ -300,10 +305,13 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
|||||||
'action': {'tool':'click', 'args':{'x':cx, 'y':round(height*.43)}},
|
'action': {'tool':'click', 'args':{'x':cx, 'y':round(height*.43)}},
|
||||||
}
|
}
|
||||||
for item in items:
|
for item in items:
|
||||||
if '选择' in item['text'] and '/' in item['text'] and button_enabled(state,item):
|
count=re.search(r'(\d+)\s*/\s*(\d+)',item['text'])
|
||||||
|
if ('选择' in item['text'] and count and int(count[2])>0
|
||||||
|
and int(count[1])>=int(count[2]) and button_enabled(state,item)):
|
||||||
options['hardship_confirm'] = {
|
options['hardship_confirm'] = {
|
||||||
'description':'选择数量足够后确认层末饰品和苦难,直接前进。',
|
'description':'选择数量足够后确认层末饰品和苦难,直接前进。',
|
||||||
'action':{'tool':'keypress','args':{'key':'enter'}},
|
'action':{'tool':'advance_dialog','args':{'presses':3}},
|
||||||
|
'fallback_action':{'tool':'click','args':{'x':item['x']+item['w']//2,'y':item['y']+item['h']//2}},
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
# Nested confirmation/detail windows override the reward/pack behind them.
|
# Nested confirmation/detail windows override the reward/pack behind them.
|
||||||
@@ -359,12 +367,13 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
|||||||
'y': item['y'] + item['h'] // 2}},
|
'y': item['y'] + item['h'] // 2}},
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
# The blessing's tier-III choice is not the optional observation. Only
|
# The blessing's tier-III Battery choice stays mandatory. Thunderbranch
|
||||||
# offer the required Battery, never a generic decline/unchecked confirm.
|
# is allowed in separate observations, not as a replacement for Battery.
|
||||||
gift_selection = (any(re.match(r'^(?:选择|可选择)(?:E\.?G\.?O\.?)?饰品', t, re.I) for t in texts)
|
gift_selection = (any(re.match(r'^(?:选择|可选择)(?:E\.?G\.?O\.?)?饰品', t, re.I) for t in texts)
|
||||||
or '饰品观测' in combined or '拒绝饰品' in texts)
|
or '饰品观测' in combined or '拒绝饰品' in texts)
|
||||||
if gift_selection:
|
if gift_selection:
|
||||||
battery = next((i for i in items if re.search(r'(标准负载|标准负荷|Standard-duty).*?(电池|Battery)', i['text'], re.I)), None)
|
battery = next((i for i in items if re.search(r'(标准负载|标准负荷|Standard-duty).*?(电池|Battery)', i['text'], re.I)), None)
|
||||||
|
thunder = next((i for i in items if re.fullmatch(r'雷枝(?:\+{1,2})?|Thunderbranch(?:\+{1,2})?', i['text'].replace(' ',''), re.I)), None)
|
||||||
unselected = any(re.search(r'(?:选择|可选).*?0/\d', t) for t in texts)
|
unselected = any(re.search(r'(?:选择|可选).*?0/\d', t) for t in texts)
|
||||||
confirm = next((i for i in items if i['text'].replace(' ', '') in ('确认', '选择')
|
confirm = next((i for i in items if i['text'].replace(' ', '') in ('确认', '选择')
|
||||||
and button_enabled(state, i)), None)
|
and button_enabled(state, i)), None)
|
||||||
@@ -381,6 +390,15 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
|||||||
'action': {'tool': 'click', 'args': {'x': battery['x']+battery['w']//2,
|
'action': {'tool': 'click', 'args': {'x': battery['x']+battery['w']//2,
|
||||||
'y': battery['y']+battery['h']//2}},
|
'y': battery['y']+battery['h']//2}},
|
||||||
}
|
}
|
||||||
|
elif thunder and (gift_headers == 1 or state.get('battery_obtained')
|
||||||
|
or any(re.search(r'(额外|追加).*观测', t) for t in texts)):
|
||||||
|
if confirm and not unselected:
|
||||||
|
options['confirm_thunderbranch'] = {'description':'确认领取用户允许的雷枝,之后在商店强化。',
|
||||||
|
'action':{'tool':'keypress','args':{'key':'enter'}},
|
||||||
|
'fallback_action':{'tool':'click','args':{'x':confirm['x']+confirm['w']//2,'y':confirm['y']+confirm['h']//2}}}
|
||||||
|
else:
|
||||||
|
options['select_thunderbranch'] = {'description':'选择破裂体系雷枝;这是用户允许的观测例外。',
|
||||||
|
'action':{'tool':'click','args':{'x':thunder['x']+thunder['w']//2,'y':thunder['y']+thunder['h']//2}}}
|
||||||
# Unrecognized choices need analysis; never silently skip a required gift.
|
# Unrecognized choices need analysis; never silently skip a required gift.
|
||||||
# A separately labelled extra observation may still be declined.
|
# A separately labelled extra observation may still be declined.
|
||||||
elif any(re.search(r'(额外|追加).*观测', t) for t in texts):
|
elif any(re.search(r'(额外|追加).*观测', t) for t in texts):
|
||||||
@@ -400,6 +418,12 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
|||||||
titles = [i['text'] for i in items if abs(i['x'] + i['w']/2 - cx) < width*.06
|
titles = [i['text'] for i in items if abs(i['x'] + i['w']/2 - cx) < width*.06
|
||||||
and height*.60 < i['y'] < height*.68]
|
and height*.60 < i['y'] < height*.68]
|
||||||
label = '/'.join(titles) or '标题OCR暂未识别'
|
label = '/'.join(titles) or '标题OCR暂未识别'
|
||||||
|
line_two = bool(re.search(r'(?:2|二)号线|LINE\s*2\b', label, re.I))
|
||||||
|
floor = state.get('floor', 1)
|
||||||
|
if floor < 5 and line_two:
|
||||||
|
continue
|
||||||
|
if floor == 5 and not line_two:
|
||||||
|
continue
|
||||||
options['pack_inspect_%d' % number] = {
|
options['pack_inspect_%d' % number] = {
|
||||||
'description': '查看第%d个卡包“%s”的放大镜详情,核对怪物和通关奖励。' % (number, label),
|
'description': '查看第%d个卡包“%s”的放大镜详情,核对怪物和通关奖励。' % (number, label),
|
||||||
'action': {'tool': 'click', 'args': {'x': round(cx + width*.042), 'y': round(height*.303)}},
|
'action': {'tool': 'click', 'args': {'x': round(cx + width*.042), 'y': round(height*.303)}},
|
||||||
@@ -410,6 +434,16 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
|||||||
'action': {'tool': 'drag', 'args': {'from_x': cx, 'from_y': round(height*.45),
|
'action': {'tool': 'drag', 'args': {'from_x': cx, 'from_y': round(height*.45),
|
||||||
'to_x': cx, 'to_y': round(height*.91), 'duration': 1.8}},
|
'to_x': cx, 'to_y': round(height*.91), 'duration': 1.8}},
|
||||||
}
|
}
|
||||||
|
if state.get('floor', 1) == 5:
|
||||||
|
required = next((k for k in options if k.startswith('pack_drag_')), None)
|
||||||
|
if required:
|
||||||
|
options['required_pack'] = options[required]
|
||||||
|
return {k:v for k,v in options.items() if k in ('wait','requires_analysis','required_pack')}
|
||||||
|
refresh = next((i for i in items if '刷新' in i['text'] and button_enabled(state, i)), None)
|
||||||
|
zero = any(re.search(r'0/3', t) for t in texts)
|
||||||
|
if refresh and not zero:
|
||||||
|
options['pack_refresh'] = {'description':'第五层二号线尚未出现,使用剩余卡包刷新。',
|
||||||
|
'action':{'tool':'click','args':{'x':refresh['x']+refresh['w']//2,'y':refresh['y']+refresh['h']//2}}}
|
||||||
return options
|
return options
|
||||||
in_shop = any(t in ('商店','特殊商店') for t in texts) and '刷新' in texts
|
in_shop = any(t in ('商店','特殊商店') for t in texts) and '刷新' in texts
|
||||||
party = ('辛克莱', '鸿璐', '希斯克利夫', '奥提斯', '格里高尔', '良秀', '浮士德')
|
party = ('辛克莱', '鸿璐', '希斯克利夫', '奥提斯', '格里高尔', '良秀', '浮士德')
|
||||||
@@ -421,6 +455,15 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
|||||||
if in_shop and state.get('floor', 1) >= 2 and not state.get('symbol_upgraded', False):
|
if in_shop and state.get('floor', 1) >= 2 and not state.get('symbol_upgraded', False):
|
||||||
return options
|
return options
|
||||||
if in_shop:
|
if in_shop:
|
||||||
|
pending = 'thrill' if state.get('thrill_pending') else 'thunderbranch' if state.get('thunderbranch_pending') else None
|
||||||
|
if pending:
|
||||||
|
name='快感++' if pending=='thrill' else '雷枝'
|
||||||
|
options['requires_analysis']['description']='离开商店前需在强化面板处理%s,付款后核对实际库存;保留符咒++及关键技能预算。' % name
|
||||||
|
item=next((i for i in items if i['text'].replace(' ','')=='强化饰品' and button_enabled(state,i)),None)
|
||||||
|
if item:
|
||||||
|
options['prepare_'+pending]={'description':'打开商店强化面板,处理'+name+'。',
|
||||||
|
'action':{'tool':'click','args':{'x':item['x']+item['w']//2,'y':item['y']+item['h']//2}}}
|
||||||
|
return options
|
||||||
for index, item in swaps:
|
for index, item in swaps:
|
||||||
options['swap_%d' % index] = {
|
options['swap_%d' % index] = {
|
||||||
'description': '商店出战角色技能替换入口:' + item['text'] + ';打开后核对技能表。',
|
'description': '商店出战角色技能替换入口:' + item['text'] + ';打开后核对技能表。',
|
||||||
@@ -522,10 +565,14 @@ def decide(cfg, state, options, recent):
|
|||||||
with urllib.request.urlopen(request, timeout=7) as response:
|
with urllib.request.urlopen(request, timeout=7) as response:
|
||||||
result = json.load(response)
|
result = json.load(response)
|
||||||
break
|
break
|
||||||
|
except urllib.error.HTTPError as error:
|
||||||
|
if error.code in (401,403,429) or attempt:
|
||||||
|
raise
|
||||||
|
time.sleep(.3)
|
||||||
except (OSError, TimeoutError):
|
except (OSError, TimeoutError):
|
||||||
if attempt:
|
if attempt:
|
||||||
raise
|
raise
|
||||||
time.sleep(15)
|
time.sleep(.3)
|
||||||
answer = result.get('answers', {}).get('action', {})
|
answer = result.get('answers', {}).get('action', {})
|
||||||
choice = answer.get('choice')
|
choice = answer.get('choice')
|
||||||
if answer.get('type') != 'choice' or choice not in options:
|
if answer.get('type') != 'choice' or choice not in options:
|
||||||
@@ -534,16 +581,22 @@ def decide(cfg, state, options, recent):
|
|||||||
|
|
||||||
|
|
||||||
def fixed_fallback(options):
|
def fixed_fallback(options):
|
||||||
for key in ('run_complete','select_startup_battery','confirm_startup_battery','decline_extra_observation','retry_network','buy_swap','confirm_swap','confirm_reward','hardship_confirm','modal_confirm','claim_final','close_progress'):
|
for key in ('run_complete','required_pack','pack_refresh','select_startup_battery','confirm_startup_battery','select_thunderbranch','confirm_thunderbranch','prepare_thrill','prepare_thunderbranch','decline_extra_observation','retry_network','buy_swap','confirm_swap','confirm_reward','hardship_confirm','modal_confirm','claim_final','close_progress'):
|
||||||
if key in options:
|
if key in options:
|
||||||
return key
|
return key
|
||||||
judge=next((k for k in options if k.startswith('button_') and '进行判定' in options[k]['description']),None)
|
judge=next((k for k in options if k.startswith('button_') and '进行判定' in options[k]['description']),None)
|
||||||
if judge:
|
if judge:
|
||||||
return judge
|
return judge
|
||||||
for prefix in ('skill_swap_', 'swap_', 'sinner_card_', 'sinner_'):
|
for prefix in ('skill_swap_', 'swap_'):
|
||||||
keys=[k for k in options if k.startswith(prefix)]
|
keys=[k for k in options if k.startswith(prefix)]
|
||||||
if keys:
|
if keys:
|
||||||
return keys[0]
|
return keys[0]
|
||||||
|
sinners=[k for k in options if k.startswith('sinner_') and not k.startswith('sinner_card_')]
|
||||||
|
if sinners:
|
||||||
|
return min(sinners,key=lambda k: 0 if any(t in options[k]['description'] for t in ('极高','非常高')) else 1)
|
||||||
|
cards=[k for k in options if k.startswith('sinner_card_')]
|
||||||
|
if cards:
|
||||||
|
return cards[0]
|
||||||
if 'shop_refresh' in options:
|
if 'shop_refresh' in options:
|
||||||
return 'shop_refresh'
|
return 'shop_refresh'
|
||||||
routes=[k for k in options if k.startswith('route_')]
|
routes=[k for k in options if k.startswith('route_')]
|
||||||
@@ -554,10 +607,12 @@ def fixed_fallback(options):
|
|||||||
if safe:
|
if safe:
|
||||||
return safe[0]
|
return safe[0]
|
||||||
combat = ('战斗胜利', '进入战斗', '触发遭遇战', '开始战斗')
|
combat = ('战斗胜利', '进入战斗', '触发遭遇战', '开始战斗')
|
||||||
direct=[k for k in events if not any(t in options[k]['description'] for t in ('判定',)+combat)]
|
direct=[k for k in events if '结果:' in options[k]['description']
|
||||||
|
and options[k]['description'].split('结果:',1)[1].strip()
|
||||||
|
and not any(t in options[k]['description'] for t in ('判定',)+combat)]
|
||||||
if direct:
|
if direct:
|
||||||
return direct[0]
|
return direct[0]
|
||||||
if len(events)==1 and not any(t in options[events[0]]['description'] for t in combat):
|
if len(events)==1 and '判定' in options[events[0]]['description'] and not any(t in options[events[0]]['description'] for t in combat):
|
||||||
return events[0]
|
return events[0]
|
||||||
if 'event_scroll' in options:
|
if 'event_scroll' in options:
|
||||||
return 'event_scroll'
|
return 'event_scroll'
|
||||||
@@ -575,29 +630,33 @@ def fixed_fallback(options):
|
|||||||
|
|
||||||
|
|
||||||
def execute(bridge, action):
|
def execute(bridge, action):
|
||||||
|
def call(tool, args=None):
|
||||||
|
if STOP_FILE.exists():
|
||||||
|
return {'ok':False,'stopped':True}
|
||||||
|
return bridge.call(tool, args)
|
||||||
if action['tool'] == 'claim_final':
|
if action['tool'] == 'claim_final':
|
||||||
result = bridge.call('click', action['args'])
|
result = call('click', action['args'])
|
||||||
if not result.get('ok'):
|
if not result.get('ok'):
|
||||||
return result
|
return result
|
||||||
time.sleep(.4)
|
time.sleep(.4)
|
||||||
return bridge.call('keypress', {'key':'enter'})
|
return call('keypress', {'key':'enter'})
|
||||||
if action['tool'] == 'advance_dialog':
|
if action['tool'] == 'advance_dialog':
|
||||||
for _ in range(min(5, action.get('args', {}).get('presses', 2))):
|
for _ in range(min(5, action.get('args', {}).get('presses', 2))):
|
||||||
result = bridge.call('keypress', {'key': 'enter'})
|
result = call('keypress', {'key': 'enter'})
|
||||||
if not result.get('ok'):
|
if not result.get('ok'):
|
||||||
return result
|
return result
|
||||||
time.sleep(.2)
|
time.sleep(.2)
|
||||||
return result
|
return result
|
||||||
if action['tool'] == 'route':
|
if action['tool'] == 'route':
|
||||||
result = bridge.call('keypress', {'key': action['args']['key']})
|
result = call('keypress', {'key': action['args']['key']})
|
||||||
if not result.get('ok'):
|
if not result.get('ok'):
|
||||||
return result
|
return result
|
||||||
time.sleep(0.35)
|
time.sleep(0.35)
|
||||||
result = bridge.call('keypress', {'key': 'enter'})
|
result = call('keypress', {'key': 'enter'})
|
||||||
if not result.get('ok'):
|
if not result.get('ok'):
|
||||||
return result
|
return result
|
||||||
time.sleep(0.7)
|
time.sleep(0.7)
|
||||||
return bridge.call('keypress', {'key': 'enter'})
|
return call('keypress', {'key': 'enter'})
|
||||||
if action['tool'] == 'wait':
|
if action['tool'] == 'wait':
|
||||||
time.sleep(0.7)
|
time.sleep(0.7)
|
||||||
return {'ok': True, 'waited': 0.7}
|
return {'ok': True, 'waited': 0.7}
|
||||||
@@ -607,12 +666,13 @@ def execute(bridge, action):
|
|||||||
while time.monotonic() < deadline and not STOP_FILE.exists():
|
while time.monotonic() < deadline and not STOP_FILE.exists():
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
for key in ('p', 'enter'):
|
for key in ('p', 'enter'):
|
||||||
result = bridge.call('keypress', {'key': key})
|
result = call('keypress', {'key': key})
|
||||||
if not result.get('ok'):
|
if not result.get('ok'):
|
||||||
|
result['pairs'] = pairs
|
||||||
return result
|
return result
|
||||||
pairs += 1
|
pairs += 1
|
||||||
time.sleep(0.8)
|
time.sleep(0.8)
|
||||||
state = bridge.call('get_state')
|
state = call('get_state')
|
||||||
if not state.get('ok'):
|
if not state.get('ok'):
|
||||||
return state
|
return state
|
||||||
texts = [i['text'].replace(' ', '') for i in text_items(state)]
|
texts = [i['text'].replace(' ', '') for i in text_items(state)]
|
||||||
@@ -621,8 +681,8 @@ def execute(bridge, action):
|
|||||||
'应该让谁', '选择一位罪人', '进行判定', '选择遭遇战奖励卡', '选项事件', '选择苦难', '选项', '结果')) for t in texts)
|
'应该让谁', '选择一位罪人', '进行判定', '选择遭遇战奖励卡', '选项事件', '选择苦难', '选项', '结果')) for t in texts)
|
||||||
if terminal:
|
if terminal:
|
||||||
return {'ok': True, 'pairs': pairs, 'terminal': True, 'screen': state.get('screen')}
|
return {'ok': True, 'pairs': pairs, 'terminal': True, 'screen': state.get('screen')}
|
||||||
return {'ok': True, 'pairs': pairs, 'terminal': False}
|
return {'ok': not STOP_FILE.exists(), 'stopped':STOP_FILE.exists(), 'pairs': pairs, 'terminal': False}
|
||||||
return bridge.call(action['tool'], action.get('args'))
|
return call(action['tool'], action.get('args'))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -665,12 +725,15 @@ def main():
|
|||||||
stable_since = time.monotonic()
|
stable_since = time.monotonic()
|
||||||
last_fingerprint = None
|
last_fingerprint = None
|
||||||
unknown_since = None
|
unknown_since = None
|
||||||
|
decision_fallback_reason = None
|
||||||
try:
|
try:
|
||||||
for step in range(args.steps):
|
for step in range(args.steps):
|
||||||
if STOP_FILE.exists() or time.monotonic() > deadline:
|
if STOP_FILE.exists() or time.monotonic() > deadline:
|
||||||
status.write_text(json.dumps({'state': 'stopped', 'step': step}), encoding='utf-8')
|
status.write_text(json.dumps({'state': 'stopped', 'step': step}), encoding='utf-8')
|
||||||
return
|
return
|
||||||
|
observation_started = time.monotonic()
|
||||||
state = bridge.call('get_state')
|
state = bridge.call('get_state')
|
||||||
|
observation_ms = round((time.monotonic()-observation_started)*1000)
|
||||||
if not state.get('ok'):
|
if not state.get('ok'):
|
||||||
state = {'ok': False, 'items': [{'text': 'MCP 截图暂不可用;游戏窗口可能正在重建。' + str(state.get('error','')),
|
state = {'ok': False, 'items': [{'text': 'MCP 截图暂不可用;游戏窗口可能正在重建。' + str(state.get('error','')),
|
||||||
'x':0,'y':0,'w':0,'h':0,'score':1.0}]}
|
'x':0,'y':0,'w':0,'h':0,'score':1.0}]}
|
||||||
@@ -685,6 +748,9 @@ def main():
|
|||||||
context_path.write_text(json.dumps(context), encoding='utf-8')
|
context_path.write_text(json.dumps(context), encoding='utf-8')
|
||||||
state['floor'] = context.get('floor', 3)
|
state['floor'] = context.get('floor', 3)
|
||||||
state['symbol_upgraded'] = context.get('symbol_upgraded', False)
|
state['symbol_upgraded'] = context.get('symbol_upgraded', False)
|
||||||
|
state['battery_obtained'] = context.get('battery_obtained', False)
|
||||||
|
state['thunderbranch_pending'] = context.get('thunderbranch_pending',False)
|
||||||
|
state['thrill_pending'] = context.get('thrill_obtained',False) and not context.get('thrill_upgraded',False)
|
||||||
state['claim_requested'] = context.get('claim_requested', False)
|
state['claim_requested'] = context.get('claim_requested', False)
|
||||||
options = candidates(state, previous_battle, context['refresh_used'])
|
options = candidates(state, previous_battle, context['refresh_used'])
|
||||||
if fingerprint != last_fingerprint:
|
if fingerprint != last_fingerprint:
|
||||||
@@ -695,13 +761,15 @@ def main():
|
|||||||
recent.append({'observation':'画面已%d秒没有有效改变,请你判断是否需要主助手排查。' % stable_seconds})
|
recent.append({'observation':'画面已%d秒没有有效改变,请你判断是否需要主助手排查。' % stable_seconds})
|
||||||
for key in list(options):
|
for key in list(options):
|
||||||
action_id = json.dumps(options[key]['action'], sort_keys=True)
|
action_id = json.dumps(options[key]['action'], sort_keys=True)
|
||||||
if (options[key]['action'] == {'tool': 'keypress', 'args': {'key': 'enter'}}
|
if ((options[key]['action'] == {'tool': 'keypress', 'args': {'key': 'enter'}}
|
||||||
|
or options[key]['action']['tool']=='advance_dialog')
|
||||||
and repeats.get((fingerprint, action_id), 0) >= 1):
|
and repeats.get((fingerprint, action_id), 0) >= 1):
|
||||||
|
fallback = options[key].get('fallback_action')
|
||||||
button = next((i for i in text_items(state)
|
button = next((i for i in text_items(state)
|
||||||
if i['text'].replace(' ', '') in ('进入', '开始战斗', '确认', '继续')
|
if i['text'].replace(' ', '') in ('进入', '开始战斗', '确认', '继续')
|
||||||
and button_enabled(state, i)), None)
|
and button_enabled(state, i)), None)
|
||||||
if button:
|
if fallback or button:
|
||||||
options[key]['action'] = {'tool': 'click', 'args': {
|
options[key]['action'] = fallback or {'tool': 'click', 'args': {
|
||||||
'x': button['x'] + button['w']//2, 'y': button['y'] + button['h']//2}}
|
'x': button['x'] + button['w']//2, 'y': button['y'] + button['h']//2}}
|
||||||
options[key]['description'] += ' 回车未生效,改为点击当前按钮。'
|
options[key]['description'] += ' 回车未生效,改为点击当前按钮。'
|
||||||
action_id = json.dumps(options[key]['action'], sort_keys=True)
|
action_id = json.dumps(options[key]['action'], sort_keys=True)
|
||||||
@@ -726,13 +794,21 @@ def main():
|
|||||||
elif 'battle' in options:
|
elif 'battle' in options:
|
||||||
choice, latency = 'battle', 0
|
choice, latency = 'battle', 0
|
||||||
else:
|
else:
|
||||||
if os.environ.get('LC_FIXED_FALLBACK') == '1':
|
if os.environ.get('LC_FIXED_FALLBACK') == '1' or decision_fallback_reason:
|
||||||
choice, latency = fixed_fallback(options), 0
|
choice, latency = fixed_fallback(options), 0
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
choice, latency = decide(cfg, state, options, recent)
|
choice, latency = decide(cfg, state, options, recent)
|
||||||
|
except urllib.error.HTTPError as error:
|
||||||
|
if error.code not in (401,403,429):
|
||||||
|
raise
|
||||||
|
decision_fallback_reason='Jev HTTP %d; deterministic fallback for this session' % error.code
|
||||||
|
choice, latency=fixed_fallback(options),0
|
||||||
action = options[choice]['action']
|
action = options[choice]['action']
|
||||||
record = {'step': step, 'choice': choice, 'action': action, 'jev_ms': latency,
|
record = {'step': step, 'choice': choice, 'action': action, 'jev_ms': latency,
|
||||||
'screen': state.get('screen'), 'at': time.strftime('%Y-%m-%dT%H:%M:%S')}
|
'ocr_ms':observation_ms,'screen': state.get('screen'), 'at': time.strftime('%Y-%m-%dT%H:%M:%S')}
|
||||||
|
if decision_fallback_reason:
|
||||||
|
record['decision_fallback_reason']=decision_fallback_reason
|
||||||
if choice == 'run_complete':
|
if choice == 'run_complete':
|
||||||
record['state'] = 'completed'
|
record['state'] = 'completed'
|
||||||
status.write_text(json.dumps(record, ensure_ascii=False), encoding='utf-8')
|
status.write_text(json.dumps(record, ensure_ascii=False), encoding='utf-8')
|
||||||
@@ -754,10 +830,25 @@ def main():
|
|||||||
return
|
return
|
||||||
action_id = json.dumps(action, sort_keys=True)
|
action_id = json.dumps(action, sort_keys=True)
|
||||||
repeats[(fingerprint, action_id)] = repeats.get((fingerprint, action_id), 0) + 1
|
repeats[(fingerprint, action_id)] = repeats.get((fingerprint, action_id), 0) + 1
|
||||||
|
action_started = time.monotonic()
|
||||||
result = execute(bridge, action)
|
result = execute(bridge, action)
|
||||||
|
record['action_ms'] = round((time.monotonic()-action_started)*1000)
|
||||||
|
record['finished_at'] = time.strftime('%Y-%m-%dT%H:%M:%S')
|
||||||
|
if result.get('stopped'):
|
||||||
|
record.update(result=result,state='stopped',battle_context=previous_battle)
|
||||||
|
with log.open('a',encoding='utf-8') as output:
|
||||||
|
output.write(json.dumps(record,ensure_ascii=False)+'\n')
|
||||||
|
status.write_text(json.dumps(record,ensure_ascii=False),encoding='utf-8')
|
||||||
|
return
|
||||||
if choice == 'claim_final' and result.get('ok'):
|
if choice == 'claim_final' and result.get('ok'):
|
||||||
context['claim_requested'] = True
|
context['claim_requested'] = True
|
||||||
context_path.write_text(json.dumps(context), encoding='utf-8')
|
context_path.write_text(json.dumps(context), encoding='utf-8')
|
||||||
|
if choice in ('confirm_startup_battery','confirm_thunderbranch') and result.get('ok'):
|
||||||
|
context['battery_obtained' if choice == 'confirm_startup_battery' else 'thunderbranch_pending'] = True
|
||||||
|
context_path.write_text(json.dumps(context),encoding='utf-8')
|
||||||
|
if choice=='modal_confirm' and result.get('ok') and any(i['text'].replace(' ','')=='快感' for i in text_items(state)) and any('获得E.G.O' in i['text'].replace(' ','') for i in text_items(state)):
|
||||||
|
context['thrill_obtained']=True
|
||||||
|
context_path.write_text(json.dumps(context),encoding='utf-8')
|
||||||
if choice == 'shop_refresh':
|
if choice == 'shop_refresh':
|
||||||
context['refresh_used'] += 1
|
context['refresh_used'] += 1
|
||||||
context_path.write_text(json.dumps(context), encoding='utf-8')
|
context_path.write_text(json.dumps(context), encoding='utf-8')
|
||||||
|
|||||||
Reference in New Issue
Block a user