200~攻击前校验有效目标
This commit is contained in:
Binary file not shown.
@@ -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,6 +268,8 @@ class AutoBotMove:
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
# 只有在“有效目标”成立时才真正执行攻击按键
|
||||
if effective_target:
|
||||
self.execute_combat_logic(state)
|
||||
self._was_in_combat_or_target = True
|
||||
return
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -304,10 +304,11 @@ class CoordinatePatrol:
|
||||
# 2. 距离判断
|
||||
dist = self.get_distance(current_pos, target_pos)
|
||||
if dist < threshold:
|
||||
# 到点后保持平滑过渡:不松开 W,只松开左右修正键
|
||||
# 避免 patrol 连续多点时出现“刹一下再走”的抖动。
|
||||
# 到点后停止前进:松开 W,避免到达后仍持续向前移动
|
||||
# (该函数被 death/logistics 等模块用于“到点就交互/停止”。)
|
||||
pydirectinput.keyUp("a")
|
||||
pydirectinput.keyUp("d")
|
||||
pydirectinput.keyUp("w")
|
||||
self.reset_stuck()
|
||||
return True
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
### `navigate_to_point` 对齐 `navigate` 优化
|
||||
|
||||
- **到点处理**:`coordinate_patrol.py` 的 `navigate_to_point` 到达判定后不再调用 `stop_all()`,改为仅松开左右修正键并保持 `W` 前进,从而实现连续平滑过渡。
|
||||
- **到点处理**:`coordinate_patrol.py` 的 `navigate_to_point` 到达判定后不再调用 `stop_all()`,改为仅松开左右修正键并**松开 `w` 停止前进**,避免到点后仍持续向前移动。(用于 death/logistics 等“到点就交互/停止”场景)
|
||||
- **转向触发逻辑**:`navigate_to_point` 转向决策按 `navigate` 的三档策略调整(死区直行、阈值外脉冲转向、死区与阈值之间不修正),降低航点附近左右抖动。
|
||||
|
||||
### `navigate_path` 对齐 `navigate` 优化
|
||||
@@ -64,3 +64,8 @@
|
||||
- 将项目中所有键盘按键调用(`pyautogui.keyDown/keyUp/press`)替换为对应的 `pydirectinput.keyDown/keyUp/press`
|
||||
- 涉及文件:`coordinate_patrol.py`、`stuck_handler.py`、`death_manager.py`、`player_movement.py`、`combat_engine.py`
|
||||
|
||||
### 攻击前校验有效目标
|
||||
|
||||
- `auto_bot_move.py`:在 `execute_logic` 的战斗/攻击分支中增加对 `state['target']` 的有效性判定,要求 `target_hp` 存在且 `> 0`,避免对无效/已死目标误触发攻击按键
|
||||
- 同步调整:战斗调用 `execute_combat_logic()` 以及脱战阶段的 `Tab` 寻怪条件,均改为基于有效目标 `effective_target`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user