From 5f15989c69b91afdd0241abf01e4229de7818777 Mon Sep 17 00:00:00 2001 From: Zhao Zuohong Date: Fri, 3 Nov 2023 17:56:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=B5=8B=E8=BF=9E=E7=BB=AD=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E5=B9=B6=E9=87=8D=E5=90=AF=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arknights_mower/__main__.py | 2 +- arknights_mower/solvers/base_schedule.py | 10 ++++----- arknights_mower/utils/device/device.py | 6 +++-- arknights_mower/utils/recognize.py | 28 ++++++++++++++++++++++++ arknights_mower/utils/solver.py | 4 ++-- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/arknights_mower/__main__.py b/arknights_mower/__main__.py index 03c1f7bf4..23079ca8e 100644 --- a/arknights_mower/__main__.py +++ b/arknights_mower/__main__.py @@ -362,7 +362,7 @@ def simulate(): if conf["close_simulator_when_idle"]: restart_simulator(conf["simulator"], start=False) elif conf["exit_game_when_idle"]: - base_scheduler.device.exit(base_scheduler.package_name) + base_scheduler.device.exit() body = task_template.render( tasks=[ obj.format(timezone_offset) for obj in base_scheduler.tasks diff --git a/arknights_mower/solvers/base_schedule.py b/arknights_mower/solvers/base_schedule.py index 7f6482c33..b5dc692d5 100644 --- a/arknights_mower/solvers/base_schedule.py +++ b/arknights_mower/solvers/base_schedule.py @@ -258,7 +258,7 @@ def overtake_room(self): def handle_error(self, force=False): if self.scene() == Scene.UNKNOWN: - self.device.exit(self.package_name) + self.device.exit() if self.error or force: # 如果没有任何时间小于当前时间的任务才生成空任务 if find_next_task(self.tasks, datetime.now()) is None: @@ -2347,7 +2347,7 @@ def maa_plan_solver(self, tasks='All', one_time=False): logger.info(hard_stop_msg) self.send_message(hard_stop_msg) time.sleep(180) - self.device.exit(self.package_name) + self.device.exit() elif not one_time: logger.info(f"记录MAA 本次执行时间") self.maa_config['last_execution'] = datetime.now() @@ -2424,7 +2424,7 @@ def maa_plan_solver(self, tasks='All', one_time=False): break else: time.sleep(0) - self.device.exit(self.package_name) + self.device.exit() # 生息演算逻辑 结束 if one_time: if len(self.tasks) > 0: @@ -2446,7 +2446,7 @@ def maa_plan_solver(self, tasks='All', one_time=False): if self.close_simulator_when_idle: restart_simulator(self.simulator, start=False) elif self.exit_game_when_idle: - self.device.exit(self.package_name) + self.device.exit() time.sleep(remaining_time) if self.close_simulator_when_idle: restart_simulator(self.simulator, stop=False) @@ -2454,7 +2454,7 @@ def maa_plan_solver(self, tasks='All', one_time=False): except Exception as e: logger.exception(e) self.MAA = None - self.device.exit(self.package_name) + self.device.exit() self.send_message(str(e), "Maa调用出错!") remaining_time = (self.tasks[0].time - datetime.now()).total_seconds() if remaining_time > 0: diff --git a/arknights_mower/utils/device/device.py b/arknights_mower/utils/device/device.py index ad672c159..ff819d1b4 100644 --- a/arknights_mower/utils/device/device.py +++ b/arknights_mower/utils/device/device.py @@ -80,6 +80,8 @@ def run(self, cmd: str) -> Optional[bytes]: def launch(self) -> None: """ launch the application """ + logger.info("明日方舟,启动!") + tap = config.TAP_TO_LAUNCH["enable"] x = config.TAP_TO_LAUNCH["x"] y = config.TAP_TO_LAUNCH["y"] @@ -89,10 +91,10 @@ def launch(self) -> None: else: self.run(f'am start -n {config.APPNAME}/{config.APP_ACTIVITY_NAME}') - def exit(self, app: str) -> None: + def exit(self) -> None: """ exit the application """ logger.info("退出游戏") - self.run(f'am force-stop {app}') + self.run(f'am force-stop {config.APPNAME}') def send_keyevent(self, keycode: int) -> None: """ send a key event """ diff --git a/arknights_mower/utils/recognize.py b/arknights_mower/utils/recognize.py index 809dad5c9..e2134e903 100644 --- a/arknights_mower/utils/recognize.py +++ b/arknights_mower/utils/recognize.py @@ -24,6 +24,8 @@ class Recognizer(object): def __init__(self, device: Device, screencap: bytes = None) -> None: self.device = device self.start(screencap) + self.loading_time = 0 + self.LOADING_TIME_LIMIT = 5 def start(self, screencap: bytes = None, build: bool = True) -> None: """ init with screencap, build matcher """ @@ -220,6 +222,19 @@ def get_scene(self) -> int: if config.SCREENSHOT_PATH is not None: self.save_screencap(self.scene) logger.info(f'Scene: {self.scene}: {SceneComment[self.scene]}') + + if self.scene == Scene.CONNECTING: + self.loading_time += 1 + if self.loading_time > 1: + logger.debug(f"检测到连续等待{self.loading_time}次") + else: + self.loading_time = 0 + if self.loading_time > self.LOADING_TIME_LIMIT: + logger.info(f"检测到连续等待{self.loading_time}次") + self.device.exit() + time.sleep(3) + self.device.check_current_focus() + return self.scene def get_infra_scene(self)-> int: @@ -265,6 +280,19 @@ def get_infra_scene(self)-> int: if config.SCREENSHOT_PATH is not None: self.save_screencap(self.scene) logger.info(f'Scene: {self.scene}: {SceneComment[self.scene]}') + + if self.scene == Scene.CONNECTING: + self.loading_time += 1 + if self.loading_time > 1: + logger.debug(f"检测到连续等待{self.loading_time}次") + else: + self.loading_time = 0 + if self.loading_time > self.LOADING_TIME_LIMIT: + logger.info(f"检测到连续等待{self.loading_time}次") + self.device.exit() + time.sleep(3) + self.device.check_current_focus() + return self.scene def is_black(self) -> None: diff --git a/arknights_mower/utils/solver.py b/arknights_mower/utils/solver.py index c82b471ee..c373f3f86 100644 --- a/arknights_mower/utils/solver.py +++ b/arknights_mower/utils/solver.py @@ -354,7 +354,7 @@ def back_to_reclamation_algorithm(self): self.recog.update() while self.find('index_terminal') is None: if self.scene() == Scene.UNKNOWN: - self.device.exit('com.hypergryph.arknights') + self.device.exit() self.back_to_index() logger.info('导航至生息演算') self.tap_themed_element('index_terminal') @@ -404,7 +404,7 @@ def waiting_solver(self, scenes, wait_count=20, sleep_time=3): return True wait_count -= 1 logger.warning("同一等待界面等待超时,重启方舟。") - self.device.exit(self.package_name) + self.device.exit() time.sleep(3) self.device.check_current_focus() return False