Fix: Cache _combat_can_again() as no expected stamina reduce during retry

This commit is contained in:
LmeSzinc 2023-12-18 23:57:33 +08:00
parent 510ef82bdf
commit c8ddc4a25e
2 changed files with 7 additions and 2 deletions

View File

@ -230,6 +230,7 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo
logger.info(f'Done {self.combat_waves} waves at total')
skip_first_screenshot = True
combat_can_again = None
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
@ -248,7 +249,10 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo
# Game client might slow to response COMBAT_AGAIN clicks
if self.appear(COMBAT_AGAIN, interval=5):
add_wave_done()
if self._combat_can_again():
# Cache the result of _combat_can_again() as no expected stamina reduce during retry
if combat_can_again is None:
combat_can_again = self._combat_can_again()
if combat_can_again:
self.device.click(COMBAT_AGAIN)
else:
self.device.click(COMBAT_EXIT)

View File

@ -66,6 +66,7 @@ class CombatPrepare(UI):
in: COMBAT_PREPARE or COMBAT_REPEAT
"""
timeout = Timer(1, count=2).start()
before = self.config.stored.TrailblazePower.value
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
@ -79,7 +80,7 @@ class CombatPrepare(UI):
# Confirm if it is > 240, sometimes just OCR errors
if current > 240 and timeout.reached():
break
if expect_reduce and current >= self.config.stored.TrailblazePower.value:
if expect_reduce and current >= before:
continue
if current <= 240:
break