Opt: Reduce dunplcate clicks at CAN_GET_REWARD

This commit is contained in:
LmeSzinc 2023-10-16 18:40:49 +08:00
parent 8f1813733a
commit a720a70f66
2 changed files with 59 additions and 46 deletions

View File

@ -1,18 +1,26 @@
from module.base.base import ModuleBase from module.base.base import ModuleBase
from module.logger import logger
from tasks.base.assets.assets_base_popup import * from tasks.base.assets.assets_base_popup import *
class PopupHandler(ModuleBase): class PopupHandler(ModuleBase):
def handle_reward(self, interval=5) -> bool: def handle_reward(self, interval=5, click_button=None) -> bool:
""" """
Args: Args:
interval: interval:
click_button: Set a button to click
Returns: Returns:
If handled. If handled.
""" """
if self.appear_then_click(GET_REWARD, interval=interval): if click_button is None:
return True if self.appear_then_click(GET_REWARD, interval=interval):
return True
else:
if self.appear(GET_REWARD, interval=interval):
logger.info(f'{GET_REWARD} -> {click_button}')
self.device.click(click_button)
return True
return False return False

View File

@ -1,27 +1,30 @@
from module.base.timer import Timer
from module.logger import logger from module.logger import logger
from tasks.base.assets.assets_base_page import CLOSE, MENU_CHECK
from tasks.base.assets.assets_base_popup import GET_REWARD
from tasks.base.page import page_menu from tasks.base.page import page_menu
from tasks.base.ui import UI from tasks.base.ui import UI
from tasks.base.assets.assets_base_page import CLOSE,MENU_CHECK from tasks.freebies.assets.assets_freebies_support_reward import (
from tasks.base.assets.assets_base_popup import GET_REWARD CAN_GET_REWARD,
from tasks.freebies.assets.assets_freebies_support_reward import MENU_TO_PROFILE, PROFILE, IN_PROFILE,CAN_GET_REWARD, CLICKING_REWARD IN_PROFILE,
MENU_TO_PROFILE,
PROFILE
)
class SupportReward(UI): class SupportReward(UI):
def run(self): def run(self):
""" """
Run get support reward task Run get support reward task
""" """
self._get_support_reward() logger.hr('Support reward', level=1)
def _get_support_reward(self):
self.ui_ensure(page_menu) self.ui_ensure(page_menu)
self._goto_profile() self._goto_profile()
self._get_reward() self._get_reward()
self._goto_menu() self._goto_menu()
self.ui_ensure(page_menu)
def _goto_profile(self): def _goto_profile(self):
""" """
Pages: Pages:
@ -35,54 +38,52 @@ class SupportReward(UI):
skip_first_screenshot = False skip_first_screenshot = False
else: else:
self.device.screenshot() self.device.screenshot()
if self.appear(IN_PROFILE): if self.appear(IN_PROFILE):
logger.info('Successfully in profile') logger.info('Successfully in profile')
return True return True
if self.appear_then_click(MENU_TO_PROFILE): if self.appear_then_click(MENU_TO_PROFILE):
continue continue
if self.appear_then_click(PROFILE): if self.appear_then_click(PROFILE):
continue continue
def _get_reward(self): def _get_reward(self, skip_first_screenshot=True):
""" """
Pages: Pages:
in: PROFILE in: PROFILE
out: PROFILE out: GET_REWARD
""" """
skip_first_screenshot = False
logger.info('Getting reward') logger.info('Getting reward')
has_reward = False claimed = False
empty = Timer(0.3, count=1).start()
timeout = Timer(5).start()
while 1: while 1:
if skip_first_screenshot: if skip_first_screenshot:
skip_first_screenshot = False skip_first_screenshot = False
else: else:
self.device.screenshot() self.device.screenshot()
if not claimed and empty.reached():
logger.info('No reward')
break
if self.appear(GET_REWARD): if self.appear(GET_REWARD):
self.device.click(MENU_CHECK) # Avoid clicking on some other buttons logger.info('Got reward')
break
if timeout.reached():
logger.warning('Get support reward timeout')
break
if self.appear_then_click(CAN_GET_REWARD, similarity=0.70, interval=2):
claimed = True
timeout.reset()
continue continue
if self.match_template_color(CLICKING_REWARD, similarity=0.70):
logger.info('Clicking reward')
continue
if self.match_template_color(CAN_GET_REWARD, similarity=0.70):
logger.info('Can get reward')
self.device.click(CAN_GET_REWARD)
has_reward = True
continue
if self.appear(IN_PROFILE): # and not self.appear(CAN_GET_REWARD):
logger.info('Successfully got reward') if has_reward else logger.info('No reward')
return True
def _goto_menu(self): def _goto_menu(self):
""" """
Pages: Pages:
in: PROFILE in: PROFILE or GET_REWARD
out: MENU out: MENU
""" """
skip_first_screenshot = False skip_first_screenshot = False
@ -92,16 +93,20 @@ class SupportReward(UI):
skip_first_screenshot = False skip_first_screenshot = False
else: else:
self.device.screenshot() self.device.screenshot()
if self.appear(MENU_CHECK): if self.appear(MENU_CHECK):
return True return True
if self.appear(IN_PROFILE): if self.appear(IN_PROFILE, interval=2):
logger.info(f'{IN_PROFILE} -> {CLOSE}')
self.device.click(CLOSE) self.device.click(CLOSE)
continue continue
if self.handle_reward(click_button=CAN_GET_REWARD):
# # Avoid clicking on some other buttons
continue
if __name__ == '__main__': if __name__ == '__main__':
self = SupportReward('src') self = SupportReward('src')
self.device.screenshot() self.device.screenshot()
self._get_support_reward() self.run()