200~攻击前校验有效目标
This commit is contained in:
@@ -123,6 +123,25 @@ class AutoBotMove:
|
||||
vendor_file = vendor_path or get_config_path('vendor.json')
|
||||
self.logistics_manager = LogisticsManager(vendor_file)
|
||||
|
||||
def _is_effective_target(self, state) -> bool:
|
||||
"""
|
||||
判断当前 `state['target']` 是否是“可攻击的有效目标”。
|
||||
主要用 `target` 信号 + `target_hp` 是否为合理值,过滤掉 OCR/像素误判导致的假目标。
|
||||
"""
|
||||
if not state.get('target'):
|
||||
return False
|
||||
target_hp = state.get('target_hp')
|
||||
if target_hp is None:
|
||||
return False
|
||||
try:
|
||||
target_hp = int(target_hp)
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
# 目标血量为 0 基本可以视为无效/已死/不可交互目标
|
||||
if target_hp <= 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _should_stop(self) -> bool:
|
||||
try:
|
||||
return bool(self._stop_check())
|
||||
@@ -224,7 +243,8 @@ class AutoBotMove:
|
||||
return
|
||||
|
||||
# 3. 战斗/有目标:停止移动,执行攻击逻辑;仅在「跑向怪」短窗口内做卡死检测
|
||||
in_combat_or_target = bool(state['combat'] or state['target'])
|
||||
effective_target = self._is_effective_target(state)
|
||||
in_combat_or_target = bool(state['combat'] or effective_target)
|
||||
if in_combat_or_target:
|
||||
# 被动进战时立即打断进食等待,转入正常战斗流程
|
||||
self._eating_started_at = None
|
||||
@@ -236,7 +256,7 @@ class AutoBotMove:
|
||||
self.patrol_controller.reset_stuck()
|
||||
# 跑向怪阶段的卡死检测:只在目标血量为 100% 时认为是在“刚刚开怪、接近怪物”,避免残血目标也触发跑向怪卡死逻辑
|
||||
target_hp = state.get('target_hp')
|
||||
if target_hp is not None and target_hp >= 100:
|
||||
if effective_target and target_hp is not None and target_hp >= 100:
|
||||
try:
|
||||
if self.patrol_controller.stuck_handler.check_stuck(
|
||||
state, self.patrol_controller.last_turn_end_time
|
||||
@@ -248,7 +268,9 @@ class AutoBotMove:
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
self.execute_combat_logic(state)
|
||||
# 只有在“有效目标”成立时才真正执行攻击按键
|
||||
if effective_target:
|
||||
self.execute_combat_logic(state)
|
||||
self._was_in_combat_or_target = True
|
||||
return
|
||||
else:
|
||||
@@ -285,7 +307,7 @@ class AutoBotMove:
|
||||
self.patrol_controller.navigate(state)
|
||||
|
||||
# 5. 顺便每隔几秒按一下 Tab(主动找怪)
|
||||
if not state['target'] and (time.time() - self.last_tab_time > 2.0):
|
||||
if not effective_target and (time.time() - self.last_tab_time > 2.0):
|
||||
pydirectinput.press(KEY_TAB)
|
||||
self.last_tab_time = time.time()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user