From e5261ca9fb0d041549c09c73a2ab21811f1a7167 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:33:33 +0800 Subject: [PATCH] Fix: salvage_relic should exit to GOTO_SALVAGE if failed --- tasks/item/relics.py | 56 ++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/tasks/item/relics.py b/tasks/item/relics.py index a0b06b3ce..abf7a4617 100644 --- a/tasks/item/relics.py +++ b/tasks/item/relics.py @@ -11,7 +11,43 @@ class RelicsUI(ItemUI): def _is_in_salvage(self) -> bool: return self.appear(ORDER_ASCENDING) or self.appear(ORDER_DESCENDING) + def salvage_exit(self, skip_first_screenshot=True): + """ + Pages: + in: rewards claimed + or _is_in_salvage() + out: GOTO_SALVAGE + """ + interval = Timer(1) + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + if self.appear(GOTO_SALVAGE): + logger.info("Salvage page exited") + break + if self.handle_reward(interval=2): + continue + if interval.reached() and self._is_in_salvage(): + logger.info(f'_is_in_salvage -> {CLOSE}') + self.device.click(CLOSE) + interval.reset() + continue + def salvage_relic(self, skip_first_screenshot=True) -> bool: + """ + Args: + skip_first_screenshot: + + Returns: + bool: If success + + Pages: + in: Any + out: page_item, GOTO_SALVAGE + """ logger.hr('Salvage Relic', level=2) self.item_goto(KEYWORD_ITEM_TAB.Relics, wait_until_stable=False) while 1: # relic tab -> salvage @@ -37,6 +73,7 @@ class RelicsUI(ItemUI): if timeout.reached(): logger.warning('Timeout when selecting first relic') + self.salvage_exit() return False # The first frame entering relic page, SALVAGE is a white button as it's the default state. # At the second frame, SALVAGE is disabled since no items are selected. @@ -67,22 +104,5 @@ class RelicsUI(ItemUI): if self.handle_popup_confirm(): continue - skip_first_screenshot = True - interval = Timer(1) - while 1: # rewards claimed -> relic tab page - if skip_first_screenshot: - skip_first_screenshot = False - else: - self.device.screenshot() - - if self.appear(GOTO_SALVAGE): - logger.info("Salvage page exited") - break - if self.handle_reward(interval=2): - continue - if interval.reached() and self._is_in_salvage(): - logger.info(f'_is_in_salvage -> {CLOSE}') - self.device.click(CLOSE) - interval.reset() - continue + self.salvage_exit() return True