diff --git a/lc_mcp/aalc_engine.py b/lc_mcp/aalc_engine.py index 4c85acc..dc45958 100644 --- a/lc_mcp/aalc_engine.py +++ b/lc_mcp/aalc_engine.py @@ -261,7 +261,7 @@ class AalcEngine(Engine): time.sleep(0.12) try: self._background_mouse(win32con.WM_LBUTTONDOWN, x, y, held=True) - time.sleep(0.12) + time.sleep(0.5 if self.cfg.win_input_type == 'window_move' else 0.12) finally: self._background_mouse(win32con.WM_LBUTTONUP, x, y) # Let Unity consume the release before another target is selected. diff --git a/scripts/jev_mirror_agent.py b/scripts/jev_mirror_agent.py index da33aa8..43e337e 100644 --- a/scripts/jev_mirror_agent.py +++ b/scripts/jev_mirror_agent.py @@ -46,6 +46,12 @@ def text_items(state): def scene_fingerprint(state): """Ignore changing clocks and counters when checking failed confirmations.""" + texts = [item['text'].replace(' ', '') for item in text_items(state)] + if any(label in texts for label in ('结果', '判定成功', '判定失败')): + # The video changes OCR line breaks/spelling even on a static result. + # Its result header and actual continuation controls define this scene. + return tuple(text for text in texts + if text in ('结果', '判定成功', '判定失败', '继续', '开始战斗', '确认')) return tuple(item['text'] for item in text_items(state) if item.get('score', 0) > .93 and not re.fullmatch(r'[0-9:.]+', item['text'].replace(' ', ''))) @@ -238,7 +244,7 @@ def candidates(state, previous_battle=False, refresh_used=0): } return options 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 and '追加的苦难' not in combined: core = any(name in combined for name in ('成捆的符咒','标准负载电池','干巴柴涩鸡胸肉','干松紧致鸡胸肉','快感','雷枝')) if core and '雷枝' not in combined: return options @@ -369,6 +375,8 @@ def candidates(state, previous_battle=False, refresh_used=0): 'action':{'tool':'advance_dialog','args':{'presses':3}}, 'fallback_action':{'tool':'click','args':{'x':item['x']+item['w']//2,'y':item['y']+item['h']//2}}, } + if 'hardship_confirm' in options: + return {key: options[key] for key in ('requires_analysis', 'wait', 'hardship_confirm')} return options # Nested confirmation/detail windows override the reward/pack behind them. modal_question = ('确认' in texts and any('取消' in t for t in texts) @@ -511,6 +519,9 @@ def candidates(state, previous_battle=False, refresh_used=0): and 0 < item['y']-sold['y'] < height*.25 for sold in items)] if in_shop and state.get('floor', 1) >= 2 and not state.get('symbol_upgraded', False): return options + if in_shop and state.get('thrill_fusion_due'): + options['requires_analysis']['description'] = '本层商店需检查快感合成:保留核心饰品,按普通/特殊商店预览进行有界尝试;检查完成或材料不足后记录本层已处理,再继续技能替换。' + return options if in_shop: pending = 'thrill' if state.get('thrill_pending') else 'thunderbranch' if state.get('thunderbranch_pending') else None if pending: @@ -797,6 +808,21 @@ def acquire_single_instance(): return lambda: kernel.CloseHandle(lease) +def apply_confirmation_retry(options, last_choice, consecutive_attempts): + """A changing skill description must not hide an unsuccessful Enter.""" + option = options.get(last_choice) + if not option or consecutive_attempts < 1 or not option.get('fallback_action'): + return + action = option['action'] + if action != {'tool': 'keypress', 'args': {'key': 'enter'}} and action['tool'] != 'advance_dialog': + return + if consecutive_attempts >= 3: + del options[last_choice] + return + option['action'] = option['fallback_action'] + option['description'] += ' 上次快捷确认未推进,点击本次已核对的按钮。' + + def main(executor_decider=None): parser = argparse.ArgumentParser() parser.add_argument('config', nargs='?', help='Optional Jev JSON config; omit for execution-model handoff') @@ -820,6 +846,8 @@ def main(executor_decider=None): run = None recent = [] repeats = {} + last_choice = None + consecutive_attempts = 0 context_path = RUNTIME_HOME / 'jev_shop_context.json' stable_since = time.monotonic() last_fingerprint = None @@ -866,11 +894,15 @@ def main(executor_decider=None): 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['thrill_fusion_due'] = (context.get('floor', 1) >= 3 + and not context.get('thrill_obtained', False) + and context.get('thrill_fusion_checked_floor') != context.get('floor')) state['claim_requested'] = claim_is_current(run, context) options = candidates(state, previous_battle, context['refresh_used']) if fingerprint != last_fingerprint: stable_since = time.monotonic() last_fingerprint = fingerprint + repeats.clear() stable_seconds = round(time.monotonic() - stable_since) if stable_seconds > 30: recent.append({'observation':'画面已%d秒没有有效改变,请你判断是否需要主助手排查。' % stable_seconds}) @@ -890,6 +922,7 @@ def main(executor_decider=None): action_id = json.dumps(options[key]['action'], sort_keys=True) if key not in ('requires_analysis', 'wait', 'battle') and repeats.get((fingerprint, action_id), 0) >= 2: del options[key] + apply_confirmation_retry(options, last_choice, consecutive_attempts) if len(options) == 2: unknown_since = unknown_since or time.monotonic() else: @@ -964,6 +997,8 @@ def main(executor_decider=None): repeats[(fingerprint, action_id)] = repeats.get((fingerprint, action_id), 0) + 1 action_started = time.monotonic() result = execute(bridge, action, deadline=deadline) + consecutive_attempts = consecutive_attempts + 1 if choice == last_choice else 1 + last_choice = choice record['action_ms'] = round((time.monotonic()-action_started)*1000) record['finished_at'] = time.strftime('%Y-%m-%dT%H:%M:%S') if result.get('stopped'): diff --git a/scripts/lc_scene_aliases.py b/scripts/lc_scene_aliases.py index 86bd635..f07aec2 100644 --- a/scripts/lc_scene_aliases.py +++ b/scripts/lc_scene_aliases.py @@ -24,6 +24,8 @@ LABELS = { 'e.g.ogiftsearch':'额外观测', 'eg.dgiftsearch':'额外观测', 'nextfloor':'下一层', 'gotonextfloor':'前往下一层', 'proceedtonextfloor':'前往下一层', 'claim':'领取', 'additionalhardship':'追加的苦难', 'additionalhardships':'追加的苦难', + 'mountingtrials':'追加的苦难', 'acquiree.g.ogift':'获得E.G.O饰品', + 'acquiree.g.ogift!':'获得E.G.O饰品!', 'skilsowned':'当前持有技能', 'obtaine.g.ogift':'获得E.G.O饰品', 'obtaine.g.ogifts':'获得E.G.O饰品', 'claimrewards':'领取奖励', 'explorationcomplete':'探索完成', 'explorationcompleted':'探索完成', 'dungeoncomplete':'探索完成', @@ -40,7 +42,17 @@ def normalize(state): raw = item['text'] compact = re.sub(r'\s+', '', raw).lower().lstrip('×x') compact = compact.replace('e.g.0', 'e.g.o') + compact = re.sub(r'fl[o0]{2}r', 'floor', compact) text = LABELS.get(compact, raw) + screen = state.get('screen', {}) + if item.get('x', 0) > screen.get('w', 1920) * .65 and item.get('y', 0) > screen.get('h', 1080) * .5: + if compact in ('winrate', 'damage'): + text = '胜率' if compact == 'winrate' else '伤害' + elif compact == 'win' and any( + re.sub(r'\s+', '', other['text']).lower() in ('rate', 'bate') + and abs(other['x'] - item['x']) < 40 + and 0 < other['y'] - item['y'] < 35 for other in source_items): + text = '胜率' 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): @@ -93,6 +105,13 @@ def normalize(state): ('Heathcliff','希斯克利夫'), ('Outis','奥提斯'), ('Gregor','格里高尔'), ('Ryoshu','良秀'), ('Faust','浮士德')]: text = text.replace(english, chinese) + text = re.sub(r'Max\s*HP', '体力上限', text, flags=re.I) + text = re.sub(r'Defense\s*Level', '防御等级', text, flags=re.I) + if re.fullmatch(r'\d+/\d+', compact) and any( + re.sub(r'\s+', '', other['text']).lower() in ('select', '选择') + and 0 < item['x'] - other['x'] < 150 + and abs(item['y'] - other['y']) < 30 for other in source_items): + text = '选择' + compact if text != raw: item['original_text'] = raw item['text'] = text diff --git a/tests/test_controller_runtime.py b/tests/test_controller_runtime.py index e3d1c7c..05718dd 100644 --- a/tests/test_controller_runtime.py +++ b/tests/test_controller_runtime.py @@ -1,5 +1,6 @@ """Controller lifecycle and battle regressions using mocked MCP only.""" import contextlib +import copy import ctypes import io import json @@ -154,6 +155,21 @@ class AgentRuntimeTest(unittest.TestCase): self.assertTrue(result['stopped']) bridge.call.assert_not_called() + def test_changing_modal_ocr_still_falls_back_from_enter_and_bounds_retries(self): + bridge = mock.Mock() + frames = iter(['skill description A', 'skill description B', 'skill description C', 'skill description D']) + bridge.call.side_effect = lambda tool, args=None: ( + {'ok': True, 'items': [{'text': next(frames), 'score': 1}]} if tool == 'get_state' else {'ok': True}) + options = {'wait': {'action': {'tool': 'wait', 'args': {}}, 'description': 'wait'}, + 'requires_analysis': {'action': {'tool': 'requires_analysis', 'args': {}}, 'description': 'analysis'}, + 'buy_swap': {'description': 'validated skill payment', + 'action': {'tool': 'keypress', 'args': {'key': 'enter'}}, + 'fallback_action': {'tool': 'click', 'args': {'x': 790, 'y': 548}}}} + with mock.patch.object(agent, 'candidates', side_effect=lambda *args: copy.deepcopy(options)): + self.run_agent(bridge, extra_args=('--steps', '4')) + inputs = [call.args[0] for call in bridge.call.call_args_list if call.args[0] != 'get_state'] + self.assertEqual(inputs, ['keypress', 'click', 'click']) + def test_close_error_still_releases_controller_mutex(self): bridge = mock.Mock() bridge.call.return_value = {'ok': True, 'items': []} diff --git a/tests/test_jev_mirror_agent.py b/tests/test_jev_mirror_agent.py index 6c14803..e1fbb1d 100644 --- a/tests/test_jev_mirror_agent.py +++ b/tests/test_jev_mirror_agent.py @@ -77,6 +77,14 @@ class SceneRegressionTest(unittest.TestCase): options['event_2']={'description':'当前事件选项:按下按钮;结果:选择后获得破裂饰品'} self.assertEqual(agent.fixed_fallback(options),'event_2') + @mock.patch.object(agent,'button_enabled',return_value=True) + def test_due_thrill_fusion_prevents_leaving_before_bounded_check(self,_enabled): + state={'symbol_upgraded':True,'floor':3,'thrill_fusion_due':True,'items':[ + {'text':t,'x':100,'y':100,'w':100,'h':40} for t in ('商店','刷新','离开')]} + self.assertEqual(set(agent.candidates(state,refresh_used=4)), {'wait','requires_analysis'}) + state['thrill_fusion_due']=False + self.assertTrue(any(k.startswith('button_') for k in agent.candidates(state,refresh_used=4))) + def test_sinner_very_high_precedes_high_and_generic_gold(self): options={'sinner_1':{'description':'预计成功率高'}, 'sinner_2':{'description':'预计成功率极高'}, diff --git a/tests/test_lc_scene_aliases.py b/tests/test_lc_scene_aliases.py index 4bed7b7..764ef37 100644 --- a/tests/test_lc_scene_aliases.py +++ b/tests/test_lc_scene_aliases.py @@ -87,6 +87,41 @@ class EnglishMirrorBoundaryTest(unittest.TestCase): self.assertNotEqual(agent.scene_fingerprint(observation('00:00:43:02')), agent.scene_fingerprint(observation('00:00:43:02', 'Commence'))) + def test_result_story_ocr_changes_do_not_reset_continue_fallback(self): + def observation(story, clock, button='Continue'): + return normalize({'items': [{'text': text, 'score': score} for text, score in + [('Result', .99), (button, .99), (story, .95), (clock, .98)]]}) + first = observation('You lookaway and continue on your path.', '00:00:10:02') + second = observation('You look away and continue on your path.', '00:00:10:16') + self.assertEqual(agent.scene_fingerprint(first), agent.scene_fingerprint(second)) + self.assertNotEqual(agent.scene_fingerprint(first), + agent.scene_fingerprint(observation('same', '00:00:10:16', 'Battle!'))) + + def test_english_layer_cards_are_not_single_gift_observation(self): + state = {'screen': {'w': 1278, 'h': 731}, 'items': [ + {'text': text, 'x': x, 'y': y, 'w': 90, 'h': 25, 'score': .99} + for text, x, y in [('Acquire E.G.O Gift', 250, 159), ('Mounting Trials', 250, 425), + ('DefenseLevel +1, MaxHP+7.5%', 250, 491), + ('Select', 1080, 572), ('0/2', 1160, 569), ('Refuse Gift', 900, 572)]]} + normalize(state) + self.assertIn('防御等级 +1, 体力上限+7.5%', [item['text'] for item in state['items']]) + with mock.patch.object(agent, 'button_enabled', return_value=True): + options = agent.candidates(state) + self.assertTrue(any(key.startswith('hardship_') for key in options)) + self.assertNotIn('decline_extra_observation', options) + self.assertNotIn('hardship_confirm', options) + state['items'][-2]['text'] = '选择2/2' + with mock.patch.object(agent, 'button_enabled', return_value=True): + options = agent.candidates(state) + self.assertEqual(set(options), {'requires_analysis', 'wait', 'hardship_confirm'}) + + def test_split_win_rate_button_starts_battle_loop_without_wave_label(self): + state = normalize({'screen': {'w': 1278, 'h': 731}, 'items': [ + {'text': text, 'x': 993, 'y': y, 'w': 30, 'h': 16, 'score': .97} + for text, y in [('Win', 542), ('Bate', 554)]]}) + self.assertTrue(agent.battle_is_visible(state)) + self.assertIn('battle', agent.candidates(state)) + def test_commence_and_split_sinner_header_reach_judgement_boundary(self): state = {'screen': {'w': 1920, 'h': 1080}, 'items': [ {'text': text, 'x': 1200, 'y': y, 'w': 200, 'h': 40, 'score': 1}