Skip to content

Commit

Permalink
Fix: Retry obtain_parse (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
LmeSzinc committed Oct 5, 2024
1 parent 8449170 commit 02a59aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
26 changes: 25 additions & 1 deletion tasks/combat/obtain.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,30 @@ def _obtain_parse(self) -> ObtainedAmmount | None:
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:
Expand Down Expand Up @@ -227,7 +251,7 @@ def obtain_get(self, dungeon=None, skip_first_screenshot=True) -> list[ObtainedA
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')
Expand Down
6 changes: 3 additions & 3 deletions tasks/item/synthesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,20 @@ def obtain_end():
# 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)
Expand Down

0 comments on commit 02a59aa

Please sign in to comment.