From bfbeaa36b5cd2b0bc3fe277971e91c7c2bd34619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=B9=8F?= Date: Mon, 20 Apr 2026 18:54:32 +0800 Subject: [PATCH] Use combat error signals for recovery actions --- auto_bot.py | 43 +++++++++++++++++---------------------- auto_bot_move.py | 53 +++++++++++++++++++----------------------------- 2 files changed, 40 insertions(+), 56 deletions(-) diff --git a/auto_bot.py b/auto_bot.py index 9d8a53a..206b289 100644 --- a/auto_bot.py +++ b/auto_bot.py @@ -214,12 +214,9 @@ class AutoBot: self.skinning_wait_sec = float(skinning_wait_sec) if skinning_wait_sec is not None else 1.5 self.enable_mouse_loot = enable_mouse_loot self.cursor_mgr = CursorManager() - self.last_target_damage_time = None - self.last_attack_scan_time = 0.0 - self.attack_stall_scan_threshold = 2.0 - self.attack_scan_retry_sec = 2.0 - self.attack_stall_s_hold_sec = 0.5 - self.min_effective_target_damage_pct = 5 + self.last_turn_signal_time = 0.0 + self.combat_signal_retry_sec = 1.0 + self.turn_error_hold_sec = 0.8 self._last_mouse_path_scale_signature = None def execute_disengage_loot(self): @@ -495,6 +492,7 @@ class AutoBot: def execute_logic(self, state): current_time = time.time() target_hp = state.get('target_hp', 0) + combat_error_signal = int(state.get('combat_error_signal', 255) or 255) effective_target = bool(state['target'] and target_hp > 0) in_combat_or_target = bool(state['combat'] or effective_target) @@ -515,25 +513,22 @@ class AutoBot: hw_ctrl.keyUp('s') self._has_braked_for_target = True - # 2. 只有超过 5% 的明显掉血才算“新的有效掉血” - hp_drop_amount = max(0, self.last_target_hp - target_hp) - significant_hp_dropped = ( - self.last_target_hp > 0 - and hp_drop_amount > self.min_effective_target_damage_pct - ) - if is_new_target or significant_hp_dropped or self.last_target_damage_time is None: - self.last_target_damage_time = current_time + # 2. 根据战斗信号执行纠偏动作 + if ( + combat_error_signal == 100 + and (current_time - self.last_interaction_time) >= self.combat_signal_retry_sec + ): + hw_ctrl.press(KEY_LOOT) + self.last_interaction_time = current_time if ( - state['combat'] - and self.last_target_damage_time is not None - and (current_time - self.last_target_damage_time) >= self.attack_stall_scan_threshold - and (current_time - self.last_attack_scan_time) >= self.attack_scan_retry_sec + combat_error_signal == 50 + and (current_time - self.last_turn_signal_time) >= self.combat_signal_retry_sec ): hw_ctrl.keyDown('s') - time.sleep(self.attack_stall_s_hold_sec) + time.sleep(self.turn_error_hold_sec) hw_ctrl.keyUp('s') - self.last_attack_scan_time = current_time + self.last_turn_signal_time = current_time self.last_target_hp = target_hp if state['combat']: self.execute_combat_logic(state) @@ -546,15 +541,15 @@ class AutoBot: self._was_in_combat_or_target = False self.last_tab_time = current_time + 1.0 self.last_target_hp = 0 - self.last_target_damage_time = None - self.last_attack_scan_time = 0.0 + self.last_turn_signal_time = 0.0 + self.last_interaction_time = 0.0 self._has_braked_for_target = False return self._was_in_combat_or_target = False self.last_target_hp = 0 - self.last_target_damage_time = None - self.last_attack_scan_time = 0.0 + self.last_turn_signal_time = 0.0 + self.last_interaction_time = 0.0 self._has_braked_for_target = False self.tab_no_target_count = min(self.tab_no_target_count, 5) diff --git a/auto_bot_move.py b/auto_bot_move.py index c10d41b..5e5f98d 100644 --- a/auto_bot_move.py +++ b/auto_bot_move.py @@ -269,12 +269,9 @@ class AutoBotMove: self.attack_loop_config = load_attack_loop(attack_loop_path) self._prev_death_state = 0 self._eating_started_at = None - self.last_target_damage_time = None - self.last_attack_scan_time = 0.0 - self.attack_stall_scan_threshold = 2.0 - self.attack_scan_retry_sec = 2.0 - self.attack_stall_s_hold_sec = 0.5 - self.min_effective_target_damage_pct = 5 + self.last_turn_signal_time = 0.0 + self.combat_signal_retry_sec = 1.0 + self.turn_error_hold_sec = 0.8 self._last_mouse_path_scale_signature = None # stop_check: 返回 True 表示需要立即停止(用于中断阻塞中的后勤/路线导航) self._stop_check = stop_check if callable(stop_check) else (lambda: False) @@ -633,6 +630,7 @@ class AutoBotMove: self.is_moving = False return + combat_error_signal = int(state.get('combat_error_signal', 255) or 255) death = state.get('death_state', 0) if self._prev_death_state in (1, 2) and death == 0: self.death_manager.reset_when_alive() @@ -700,31 +698,22 @@ class AutoBotMove: hw_ctrl.keyUp('s') self._has_braked_for_target = True - # 2. 只有超过 5% 的明显掉血才算“新的有效掉血” - hp_drop_amount = max(0, self.last_target_hp - target_hp) - significant_hp_dropped = ( - self.last_target_hp > 0 - and hp_drop_amount > self.min_effective_target_damage_pct - ) - if is_new_target or significant_hp_dropped or self.last_target_damage_time is None: - self.last_target_damage_time = now - - # 目标血量100%且超过2秒没掉血,按交互键尝试选中/攻击 - if target_hp >= 100 and self.last_target_damage_time is not None: - if (now - self.last_target_damage_time) >= 2.0: - hw_ctrl.press(KEY_LOOT) - self.last_target_damage_time = now + # 根据战斗信号执行纠偏动作 + if ( + combat_error_signal == 100 + and (now - self.last_interaction_time) >= self.combat_signal_retry_sec + ): + hw_ctrl.press(KEY_LOOT) + self.last_interaction_time = now if ( - state['combat'] - and self.last_target_damage_time is not None - and (now - self.last_target_damage_time) >= self.attack_stall_scan_threshold - and (now - self.last_attack_scan_time) >= self.attack_scan_retry_sec + combat_error_signal == 50 + and (now - self.last_turn_signal_time) >= self.combat_signal_retry_sec ): hw_ctrl.keyDown('s') - time.sleep(self.attack_stall_s_hold_sec) + time.sleep(self.turn_error_hold_sec) hw_ctrl.keyUp('s') - self.last_attack_scan_time = now + self.last_turn_signal_time = now self.last_target_hp = target_hp # 执行正常的攻击循环 @@ -732,8 +721,8 @@ class AutoBotMove: else: # 目标已死亡但还在战斗中,按 Tab 找下一个目标 self.last_target_hp = 0 - self.last_target_damage_time = None - self.last_attack_scan_time = 0.0 + self.last_turn_signal_time = 0.0 + self.last_interaction_time = 0.0 self._has_braked_for_target = False if state['combat']: hw_ctrl.press(KEY_TAB) @@ -750,14 +739,14 @@ class AutoBotMove: # 扫尾动作执行完后,本 tick 强制结束,防止立即按下 Tab self._was_in_combat_or_target = False self.target_acquired_time = None - self.last_target_damage_time = None - self.last_attack_scan_time = 0.0 + self.last_turn_signal_time = 0.0 + self.last_interaction_time = 0.0 self.last_tab_time = time.time() + 1.0 # 给找怪增加 1 秒额外冷却 return self.target_acquired_time = None - self.last_target_damage_time = None - self.last_attack_scan_time = 0.0 + self.last_turn_signal_time = 0.0 + self.last_interaction_time = 0.0 self._was_in_combat_or_target = False # 4. 脱战低血量:就地吃面包(最多等待 30 秒或回满)