From 02a59aa069f68ea8b127e72c4a20f2537d9323e4 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sat, 5 Oct 2024 19:28:00 +0800 Subject: [PATCH] Fix: Retry obtain_parse (#642) --- tasks/combat/obtain.py | 26 +++++++++++++++++++++++++- tasks/item/synthesize.py | 6 +++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tasks/combat/obtain.py b/tasks/combat/obtain.py index cd2f32dec..bb0fbc84f 100644 --- a/tasks/combat/obtain.py +++ b/tasks/combat/obtain.py @@ -180,6 +180,30 @@ class CombatObtain(PlannerMixin): value=amount, ) + def obtain_parse(self, skip_first_screenshot=True) -> ObtainedAmmount | None: + """ + Parse obtain item with retry + + Pages: + in: ITEM_CLOSE + """ + timeout = Timer(1, count=3).start() + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + if timeout.reached(): + logger.error('obtain_parse timeout') + return None + + obtain = self._obtain_parse() + if obtain is not None: + return obtain + else: + self.screenshot_tracking_add() + def obtain_get(self, dungeon=None, skip_first_screenshot=True) -> list[ObtainedAmmount]: """ Args: @@ -227,7 +251,7 @@ class CombatObtain(PlannerMixin): break self._obtain_enter(entry, appear_button=COMBAT_PREPARE) - item = self._obtain_parse() + item = self.obtain_parse() if item is not None: if item.item == KEYWORDS_ITEM_CURRENCY.Trailblaze_EXP: logger.warning('Trailblaze_EXP is in obtain list, OBTAIN_TRAILBLAZE_EXP may need to verify') diff --git a/tasks/item/synthesize.py b/tasks/item/synthesize.py index 1e7e3a3a4..8257ac8fb 100644 --- a/tasks/item/synthesize.py +++ b/tasks/item/synthesize.py @@ -238,20 +238,20 @@ class Synthesize(CombatObtain, ItemUI): # Purple self.synthesize_rarity_set('blue') self._obtain_enter(ENTRY_ITEM_TO, appear_button=page_synthesize.check_button) - item = self._obtain_parse() + item = self.obtain_parse() if item is not None: items.append(item) self._obtain_close(check_button=obtain_end) # Blue self._obtain_enter(ENTRY_ITEM_FROM, appear_button=page_synthesize.check_button) - item = self._obtain_parse() + item = self.obtain_parse() if item is not None: items.append(item) self._obtain_close(check_button=obtain_end) # Green self.synthesize_rarity_set('green') self._obtain_enter(ENTRY_ITEM_FROM, appear_button=page_synthesize.check_button) - item = self._obtain_parse() + item = self.obtain_parse() if item is not None: items.append(item) self._obtain_close(check_button=obtain_end)