add 脱战血量低就地吃面包

This commit is contained in:
王鹏
2026-03-25 10:51:25 +08:00
parent 9b4a9d5ab8
commit 9ab1e8737c
7 changed files with 174 additions and 2 deletions

View File

@@ -305,6 +305,9 @@ class GameLoopWorker(QThread):
record_min_distance=None,
attack_loop_path=None,
skinning_wait_sec=None,
food_key=None,
eat_hp_threshold=None,
eat_max_wait_sec=None,
quest_follow_follow_key=None,
quest_follow_interact_key=None,
quest_follow_interval_sec=None,
@@ -328,6 +331,15 @@ class GameLoopWorker(QThread):
self.record_min_distance = record_min_distance
self.attack_loop_path = attack_loop_path or None
self.skinning_wait_sec = skinning_wait_sec
self.food_key = (food_key or "f1").strip().lower() or "f1"
try:
self.eat_hp_threshold = int(eat_hp_threshold)
except (TypeError, ValueError):
self.eat_hp_threshold = 30
try:
self.eat_max_wait_sec = float(eat_max_wait_sec)
except (TypeError, ValueError):
self.eat_max_wait_sec = 30.0
self.quest_follow_follow_key = (quest_follow_follow_key or "f").strip().lower() or "f"
self.quest_follow_interact_key = (quest_follow_interact_key or "4").strip().lower() or "4"
try:
@@ -355,6 +367,10 @@ class GameLoopWorker(QThread):
vendor_path=self.vendor_path,
attack_loop_path=self.attack_loop_path,
skinning_wait_sec=self.skinning_wait_sec,
food_key=self.food_key,
eat_hp_threshold=self.eat_hp_threshold,
eat_max_wait_sec=self.eat_max_wait_sec,
stop_check=lambda: not self.running,
)
except ImportError as e:
self.log_signal.emit(f"❌ 巡逻打怪依赖加载失败: {e}")
@@ -825,6 +841,23 @@ class WoWMultiKeyGUI(QMainWindow):
self.skinning_wait_spin.setSuffix("")
params_right.addRow("剥皮等待时间:", self.skinning_wait_spin)
self.food_key_edit = QLineEdit()
self.food_key_edit.setPlaceholderText("如 f1")
self.food_key_edit.setMaxLength(16)
self.food_key_edit.setText("f1")
self.eat_hp_threshold_spin = QSpinBox()
self.eat_hp_threshold_spin.setRange(1, 100)
self.eat_hp_threshold_spin.setValue(30)
self.eat_hp_threshold_spin.setSuffix(" %")
self.eat_max_wait_spin = QDoubleSpinBox()
self.eat_max_wait_spin.setRange(1.0, 120.0)
self.eat_max_wait_spin.setSingleStep(1.0)
self.eat_max_wait_spin.setValue(30.0)
self.eat_max_wait_spin.setSuffix("")
params_right.addRow("吃面包按键:", self.food_key_edit)
params_right.addRow("吃面包血量阈值:", self.eat_hp_threshold_spin)
params_right.addRow("吃面包最长等待:", self.eat_max_wait_spin)
self.gs_mount_key = QLineEdit()
self.gs_mount_key.setPlaceholderText("如 x")
self.gs_mount_key.setMaxLength(16)
@@ -886,8 +919,14 @@ class WoWMultiKeyGUI(QMainWindow):
bot_cfg = (self.config or {}).get('bot') or {}
v = bot_cfg.get('skinning_wait_sec', 1.5)
self.skinning_wait_spin.setValue(float(v))
self.food_key_edit.setText(str(bot_cfg.get('food_key', 'f1')).strip() or 'f1')
self.eat_hp_threshold_spin.setValue(int(bot_cfg.get('eat_hp_threshold', 30)))
self.eat_max_wait_spin.setValue(float(bot_cfg.get('eat_max_wait_sec', 30.0)))
except Exception:
self.skinning_wait_spin.setValue(1.5)
self.food_key_edit.setText('f1')
self.eat_hp_threshold_spin.setValue(30)
self.eat_max_wait_spin.setValue(30.0)
def _save_params_config(self):
"""保存「参数配置」界面到 game_state_config.json多分辨率并写入 wow_multikey_qt.jsonbot 参数)"""
@@ -908,6 +947,9 @@ class WoWMultiKeyGUI(QMainWindow):
self.config = self.config or {}
self.config.setdefault('bot', {})
self.config['bot']['skinning_wait_sec'] = float(self.skinning_wait_spin.value())
self.config['bot']['food_key'] = self.food_key_edit.text().strip() or 'f1'
self.config['bot']['eat_hp_threshold'] = int(self.eat_hp_threshold_spin.value())
self.config['bot']['eat_max_wait_sec'] = float(self.eat_max_wait_spin.value())
self._save_main_config()
self.log(f"✅ 参数配置已保存至 {path},并更新 bot 参数")
@@ -1283,11 +1325,26 @@ class WoWMultiKeyGUI(QMainWindow):
skinning_wait_sec = float(((self.config or {}).get('bot') or {}).get('skinning_wait_sec', 1.5))
except Exception:
skinning_wait_sec = 1.5
try:
food_key = str(((self.config or {}).get('bot') or {}).get('food_key', 'f1')).strip() or 'f1'
except Exception:
food_key = 'f1'
try:
eat_hp_threshold = int(((self.config or {}).get('bot') or {}).get('eat_hp_threshold', 30))
except Exception:
eat_hp_threshold = 30
try:
eat_max_wait_sec = float(((self.config or {}).get('bot') or {}).get('eat_max_wait_sec', 30.0))
except Exception:
eat_max_wait_sec = 30.0
self.game_worker = GameLoopWorker(
mode, waypoints_path=waypoints_path, vendor_path=vendor_path,
attack_loop_path=attack_loop_path,
skinning_wait_sec=skinning_wait_sec,
food_key=food_key,
eat_hp_threshold=eat_hp_threshold,
eat_max_wait_sec=eat_max_wait_sec,
quest_follow_follow_key=self.quest_follow_follow_edit.text(),
quest_follow_interact_key=self.quest_follow_interact_edit.text(),
quest_follow_interval_sec=self.quest_follow_interval_spin.value(),
@@ -1355,6 +1412,13 @@ class WoWMultiKeyGUI(QMainWindow):
"""统一停止游戏循环,更新所有相关 UI"""
if self.game_worker:
self.game_worker.running = False
# 额外释放一次移动按键,避免刚好卡在阻塞逻辑里导致按键滞留。
try:
if getattr(self.game_worker, "bot_move", None):
self.game_worker.bot_move.patrol_controller.stop_all()
self.game_worker.bot_move.logistics_manager.is_returning = False
except Exception:
pass
# 不在这里 wait(),避免阻塞 GUI线程会在下一轮循环自然退出
self.game_start_btn.setEnabled(True)
self.game_stop_btn.setEnabled(False)