Fix: Re-check all timeout timer

- Fix tactical class get stuck when skill level reach to max.
This commit is contained in:
LmeSzinc 2020-06-03 05:06:51 +08:00
parent 9353ae1707
commit 30e11c6caf
7 changed files with 18 additions and 16 deletions

View File

@ -96,6 +96,9 @@ class Timer:
def start(self): def start(self):
if not self.started(): if not self.started():
self._current = time.time() self._current = time.time()
self._reach_count = 0
return self
def started(self): def started(self):
return bool(self._current) return bool(self._current)

View File

@ -27,11 +27,6 @@ class Equipment(InfoHandler):
self.device.screenshot() self.device.screenshot()
if SWIPE_CHECK.match(self.device.image): if SWIPE_CHECK.match(self.device.image):
if swipe_timer.reached():
import time
from PIL import Image
self.device.image.save(f'{int(time.time() * 1000)}.png')
Image.fromarray(SWIPE_CHECK.image).save(f'{int(time.time() * 1000)}.png')
continue continue
if self.appear(check_button, offset=(30, 30)) and not SWIPE_CHECK.match(self.device.image): if self.appear(check_button, offset=(30, 30)) and not SWIPE_CHECK.match(self.device.image):

View File

@ -32,8 +32,7 @@ class ExerciseCombat(HpDaemon, OpponentChoose, ExerciseEquipment):
bool: True if wins. False if quit. bool: True if wins. False if quit.
""" """
logger.info('Combat execute') logger.info('Combat execute')
self.low_hp_confirm_timer = Timer(self.config.LOW_HP_CONFIRM_WAIT, count=2) self.low_hp_confirm_timer = Timer(self.config.LOW_HP_CONFIRM_WAIT, count=2).start()
self.low_hp_confirm_timer.start()
show_hp_timer = Timer(5) show_hp_timer = Timer(5)
success = True success = True
end = False end = False

View File

@ -110,8 +110,7 @@ class InfoHandler(ModuleBase):
def ensure_no_story(self, skip_first_screenshot=True): def ensure_no_story(self, skip_first_screenshot=True):
logger.info('Ensure no story') logger.info('Ensure no story')
story_timer = Timer(5, count=4) story_timer = Timer(5, count=10).start()
story_timer.start()
while 1: while 1:
if skip_first_screenshot: if skip_first_screenshot:
skip_first_screenshot = False skip_first_screenshot = False

View File

@ -9,7 +9,7 @@ class LoginHandler(Combat):
def handle_app_login(self): def handle_app_login(self):
logger.hr('App login') logger.hr('App login')
confirm_timer = Timer(1.5, count=4) confirm_timer = Timer(1.5, count=4).start()
while 1: while 1:
self.device.screenshot() self.device.screenshot()

View File

@ -52,9 +52,8 @@ class Reward(RewardCommission, RewardTacticalClass):
logger.hr('Reward receive') logger.hr('Reward receive')
reward = False reward = False
exit_timer = Timer(1, count=3) exit_timer = Timer(1, count=3).start()
click_timer = Timer(1) click_timer = Timer(1)
exit_timer.start()
btn = [] btn = []
if self.config.ENABLE_REWARD: if self.config.ENABLE_REWARD:
btn.append(REWARD_3) btn.append(REWARD_3)

View File

@ -148,8 +148,6 @@ class BookGroup:
class RewardTacticalClass(UI, InfoHandler): class RewardTacticalClass(UI, InfoHandler):
tactical_animation_timer = Timer(2, count=3)
def _tactical_animation_running(self): def _tactical_animation_running(self):
""" """
Returns: Returns:
@ -208,6 +206,8 @@ class RewardTacticalClass(UI, InfoHandler):
return False return False
logger.hr('Tactical class receive') logger.hr('Tactical class receive')
tactical_class_timout = Timer(10, count=10).start()
tactical_animation_timer = Timer(2, count=3).start()
while 1: while 1:
if skip_first_screenshot: if skip_first_screenshot:
skip_first_screenshot = False skip_first_screenshot = False
@ -215,11 +215,14 @@ class RewardTacticalClass(UI, InfoHandler):
self.device.screenshot() self.device.screenshot()
if self.appear_then_click(REWARD_2, interval=1): if self.appear_then_click(REWARD_2, interval=1):
tactical_class_timout.reset()
continue continue
if self.handle_popup_confirm(): if self.handle_popup_confirm():
tactical_class_timout.reset()
continue continue
if self.handle_urgent_commission(save_get_items=False): if self.handle_urgent_commission(save_get_items=False):
# Only one button in the middle, when skill reach max level. # Only one button in the middle, when skill reach max level.
tactical_class_timout.reset()
continue continue
if self.appear(TACTICAL_CLASS_CANCEL, offset=(30, 30), interval=2) \ if self.appear(TACTICAL_CLASS_CANCEL, offset=(30, 30), interval=2) \
and self.appear(TACTICAL_CLASS_START, offset=(30, 30)): and self.appear(TACTICAL_CLASS_START, offset=(30, 30)):
@ -228,17 +231,21 @@ class RewardTacticalClass(UI, InfoHandler):
self._tactical_books_choose() self._tactical_books_choose()
self.device.click(TACTICAL_CLASS_START) self.device.click(TACTICAL_CLASS_START)
self.interval_reset(TACTICAL_CLASS_CANCEL) self.interval_reset(TACTICAL_CLASS_CANCEL)
tactical_class_timout.reset()
continue continue
# End # End
if self.appear(TACTICAL_CHECK, offset=(20, 20)): if self.appear(TACTICAL_CHECK, offset=(20, 20)):
self.ui_current = page_tactical self.ui_current = page_tactical
if not self._tactical_animation_running(): if not self._tactical_animation_running():
if self.tactical_animation_timer.reached(): if tactical_animation_timer.reached():
logger.info('Tactical reward end.') logger.info('Tactical reward end.')
break break
else: else:
self.tactical_animation_timer.reset() tactical_animation_timer.reset()
if tactical_class_timout.reached():
logger.info('Tactical reward timeout.')
break
self.ui_goto(page_reward, skip_first_screenshot=True) self.ui_goto(page_reward, skip_first_screenshot=True)
return True return True