Add bag full mailbox mailing flow
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import time
|
||||
from hardware_control import hw_ctrl
|
||||
|
||||
@@ -20,6 +21,32 @@ class LogisticsManager:
|
||||
self.bag_full_hearthstone = False # 包满时用炉石回城而非走路修理
|
||||
self.hearthstone_key = "b" # 炉石按键
|
||||
self.hearthstone_cast_sec = 10.0 # 炉石施法等待秒数
|
||||
self.enable_bag_full_mail = False
|
||||
self.mailbox_route_file = os.path.join("recorder", "mailbox.json")
|
||||
self.mailbox_interact_key = "8"
|
||||
self.mail_recipient_key = ""
|
||||
self.mail_send_key = "f8"
|
||||
self.mailbox_open_wait_sec = 2.0
|
||||
self.mail_send_wait_sec = 60.0
|
||||
|
||||
def _resolve_path(self, path):
|
||||
if not path:
|
||||
return ""
|
||||
path = str(path)
|
||||
if os.path.isabs(path):
|
||||
return path
|
||||
cwd_path = os.path.abspath(path)
|
||||
if os.path.exists(cwd_path):
|
||||
return cwd_path
|
||||
return os.path.join(os.path.dirname(os.path.abspath(__file__)), path)
|
||||
|
||||
def _sleep_with_stop(self, seconds, stop_check=None):
|
||||
end_at = time.time() + max(0.0, float(seconds))
|
||||
while time.time() < end_at:
|
||||
if callable(stop_check) and stop_check():
|
||||
return False
|
||||
time.sleep(min(0.1, end_at - time.time()))
|
||||
return True
|
||||
|
||||
def check_logistics(self, state):
|
||||
"""
|
||||
@@ -109,6 +136,83 @@ class LogisticsManager:
|
||||
hw_ctrl.press("4")
|
||||
time.sleep(2)
|
||||
|
||||
def run_bag_full_mail_flow(self, get_state, patrol, stop_check=None):
|
||||
"""
|
||||
包满邮寄第一版流程:
|
||||
炉石 -> 跑到邮箱路线终点 -> 交互打开邮箱 -> 按 MailboxCourier 宏键 -> 等待后停止。
|
||||
Python 不判断邮件是否发完,发送细节交给游戏内插件。
|
||||
"""
|
||||
route_file = self._resolve_path(self.mailbox_route_file)
|
||||
if not route_file or not os.path.exists(route_file):
|
||||
print(f">>> [后勤-邮箱] 邮箱路线不存在,已停止: {route_file}")
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
if callable(stop_check) and stop_check():
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
ok = self.use_hearthstone_and_stop(get_state=get_state)
|
||||
if not ok:
|
||||
print(">>> [后勤-邮箱] 炉石失败,未继续跑邮箱。")
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
try:
|
||||
with open(route_file, "r", encoding="utf-8") as f:
|
||||
path = json.load(f)
|
||||
except Exception as exc:
|
||||
print(f">>> [后勤-邮箱] 邮箱路线读取失败: {exc}")
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
if not path:
|
||||
print(f">>> [后勤-邮箱] 邮箱路线为空,已停止: {route_file}")
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
print(f">>> [后勤-邮箱] 开始跑邮箱路线: {route_file}")
|
||||
old_enable_mount = getattr(patrol, "enable_mount", None)
|
||||
if old_enable_mount is not None:
|
||||
patrol.enable_mount = False
|
||||
try:
|
||||
ok = patrol.navigate_path(get_state, path, forward=True, arrival_threshold=VENDOR_ARRIVAL_THRESHOLD)
|
||||
finally:
|
||||
if old_enable_mount is not None:
|
||||
patrol.enable_mount = old_enable_mount
|
||||
if not ok:
|
||||
print(">>> [后勤-邮箱] 邮箱路线未完成,已停止。")
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
if callable(stop_check) and stop_check():
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
patrol.stop_all()
|
||||
print(f">>> [后勤-邮箱] 到达邮箱附近,按交互键: {self.mailbox_interact_key}")
|
||||
hw_ctrl.press(self.mailbox_interact_key)
|
||||
if not self._sleep_with_stop(self.mailbox_open_wait_sec, stop_check=stop_check):
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
if self.mail_recipient_key:
|
||||
print(f">>> [后勤-邮箱] 触发 MailboxCourier 收件人宏: {self.mail_recipient_key}")
|
||||
hw_ctrl.press(self.mail_recipient_key)
|
||||
if not self._sleep_with_stop(0.5, stop_check=stop_check):
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
print(f">>> [后勤-邮箱] 触发 MailboxCourier 发送宏: {self.mail_send_key}")
|
||||
hw_ctrl.press(self.mail_send_key)
|
||||
if not self._sleep_with_stop(self.mail_send_wait_sec, stop_check=stop_check):
|
||||
self.is_returning = False
|
||||
return False
|
||||
|
||||
print(">>> [后勤-邮箱] 邮寄宏已触发,流程结束。")
|
||||
self.is_returning = False
|
||||
return True
|
||||
|
||||
def run_route1_round(self, get_state, patrol, route_file=None):
|
||||
"""
|
||||
读取 route1.json 路径,先正向走完,执行交互(8、4),再反向走完,然后结束。
|
||||
|
||||
Reference in New Issue
Block a user