From d5797cb1532e780027c39d81986df5176a206903 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sat, 11 Mar 2023 23:46:47 +0800 Subject: [PATCH 1/3] Fix: Handle AUTO_SEARCH_REWARD when switching fleet lock --- module/os_handler/map_event.py | 11 ++++++++++- module/ui/switch.py | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/module/os_handler/map_event.py b/module/os_handler/map_event.py index e347219102..40679cb349 100644 --- a/module/os_handler/map_event.py +++ b/module/os_handler/map_event.py @@ -9,7 +9,16 @@ from module.statistics.azurstats import DropImage from module.ui.switch import Switch -fleet_lock = Switch('Fleet_Lock', offset=(10, 120)) + +class FleetLockSwitch(Switch): + def handle_additional(self, main): + # A game bug that AUTO_SEARCH_REWARD from the last cleared zone popups + if main.appear_then_click(AUTO_SEARCH_REWARD, offset=(50, 50), interval=3): + return True + return False + + +fleet_lock = FleetLockSwitch('Fleet_Lock', offset=(10, 120)) fleet_lock.add_status('on', check_button=OS_FLEET_LOCKED) fleet_lock.add_status('off', check_button=OS_FLEET_UNLOCKED) diff --git a/module/ui/switch.py b/module/ui/switch.py index 301bbc344a..a72b9f366a 100644 --- a/module/ui/switch.py +++ b/module/ui/switch.py @@ -96,6 +96,16 @@ def get_data(self, status): logger.warning(f'Switch {self.name} received an invalid status {status}') raise ScriptError(f'Switch {self.name} received an invalid status {status}') + def handle_additional(self, main): + """ + Args: + main (ModuleBase): + + Returns: + bool: If handled + """ + return False + def set(self, status, main, skip_first_screenshot=True): """ Args: @@ -122,6 +132,10 @@ def set(self, status, main, skip_first_screenshot=True): current = self.get(main=main) logger.attr(self.name, current) + # Handle additional popups + if self.handle_additional(main=main): + continue + # End if current == status: return changed From 3a12b9e95e00259e6d6962bffd871d71efb22320 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sun, 12 Mar 2023 01:10:35 +0800 Subject: [PATCH 2/3] Fix: Handle AUTO_SEARCH_REWARD in question_goto() --- module/os/fleet.py | 5 +++++ module/os_handler/map_event.py | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/module/os/fleet.py b/module/os/fleet.py index 26a41e4fb7..7fed196cff 100644 --- a/module/os/fleet.py +++ b/module/os/fleet.py @@ -528,6 +528,11 @@ def go_month_boss_room(self, is_normal=True): def question_goto(self, has_fleet_step=False): logger.hr('Question goto') while 1: + # A game bug that AUTO_SEARCH_REWARD from the last cleared zone popups + if self.appear_then_click(AUTO_SEARCH_REWARD, offset=(50, 50), interval=3): + self.device.screenshot() + continue + # Update local view # Not screenshots taking, reuse the old one self.update_os() diff --git a/module/os_handler/map_event.py b/module/os_handler/map_event.py index 40679cb349..3e909d5317 100644 --- a/module/os_handler/map_event.py +++ b/module/os_handler/map_event.py @@ -169,11 +169,14 @@ def handle_os_in_map(self): self._os_in_map_confirm_timer.reset() return False - def ensure_no_map_event(self): + def ensure_no_map_event(self, skip_first_screenshot=True): self._os_in_map_confirm_timer.reset() while 1: - self.device.screenshot() + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() if self.handle_map_event(): continue From 9e4bb4b064fb74f83c6b306cfb40568af1d843fd Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:42:29 +0800 Subject: [PATCH 3/3] Opt: Show tips if MaaEmulator.MaaPath is not configured --- submodule/AlasMaaBridge/maa.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/submodule/AlasMaaBridge/maa.py b/submodule/AlasMaaBridge/maa.py index 79bb10f1ec..fdc8e7675b 100644 --- a/submodule/AlasMaaBridge/maa.py +++ b/submodule/AlasMaaBridge/maa.py @@ -49,6 +49,11 @@ def asst(self): self.config.task_stop() logger.info(f'MAA安装路径:{self.config.MaaEmulator_MaaPath}') + if not os.path.exists(self.config.MaaEmulator_MaaPath): + logger.critical( + f'未找到路径 {self.config.MaaEmulator_MaaPath},请确认MAA已安装在该路径。' + f'如果你是第一次使用MAA插件,需要自选安装MAA,并在 "MAA设置" - "MAA安装路径" 中填入MAA的安装路径') + raise RequestHumanTakeover try: incremental_path = [os.path.join(self.config.MaaEmulator_MaaPath, './cache')] if self.config.MaaEmulator_PackageName in ["YoStarEN", "YoStarJP", "YoStarKR", "txwy"]: @@ -63,7 +68,17 @@ def asst(self): AssistantHandler.load(self.config.MaaEmulator_MaaPath, incremental_path) except ModuleNotFoundError: logger.critical('找不到MAA,请检查安装路径是否正确') - exit(1) + raise RequestHumanTakeover + except OSError as e: + # OSError: [WinError 126] 找不到指定的模块。 + if '[WinError 126]' in str(e): + logger.exception(e) + logger.critical( + f'无法导入MAA,请确认MAA已正确安装在 {self.config.MaaEmulator_MaaPath}' + ) + raise RequestHumanTakeover + else: + raise @AssistantHandler.Asst.CallBackType def callback(msg, details, arg):