diff --git a/assets/cn/assignment/dispatch/ASSIGNMENT_START.png b/assets/cn/assignment/dispatch/ASSIGNMENT_START.png new file mode 100644 index 000000000..efd15ed00 Binary files /dev/null and b/assets/cn/assignment/dispatch/ASSIGNMENT_START.png differ diff --git a/tasks/assignment/assets/assets_assignment_dispatch.py b/tasks/assignment/assets/assets_assignment_dispatch.py index ebe491149..50a13ac89 100644 --- a/tasks/assignment/assets/assets_assignment_dispatch.py +++ b/tasks/assignment/assets/assets_assignment_dispatch.py @@ -3,6 +3,16 @@ from module.base.button import Button, ButtonWrapper # This file was auto-generated, do not modify it manually. To generate: # ``` python -m dev_tools.button_extract ``` +ASSIGNMENT_START = ButtonWrapper( + name='ASSIGNMENT_START', + cn=Button( + file='./assets/cn/assignment/dispatch/ASSIGNMENT_START.png', + area=(581, 321, 699, 349), + search=(561, 301, 719, 369), + color=(93, 84, 66), + button=(581, 321, 699, 349), + ), +) ASSIGNMENT_STARTED_CHECK = ButtonWrapper( name='ASSIGNMENT_STARTED_CHECK', share=Button( diff --git a/tasks/assignment/claim.py b/tasks/assignment/claim.py index e70e39044..7d3c30cd5 100644 --- a/tasks/assignment/claim.py +++ b/tasks/assignment/claim.py @@ -1,6 +1,7 @@ from datetime import datetime, timedelta from module.base.timer import Timer +from module.logger import logger from module.ocr.ocr import Duration from tasks.assignment.assets.assets_assignment_claim import * from tasks.assignment.assets.assets_assignment_dispatch import EMPTY_SLOT @@ -22,36 +23,63 @@ class AssignmentClaim(AssignmentDispatch): out: DISPATCHED or EMPTY_SLOT """ redispatched = False + self._wait_for_report() + if should_redispatch: + redispatched = self._is_duration_expected(duration_expected) + self._exit_report(redispatched) + if redispatched: + self._wait_until_assignment_started() + self.dispatched[assignment] = datetime.now( + ) + timedelta(hours=duration_expected) + elif should_redispatch: + # Re-select duration and dispatch + self.dispatch(assignment, duration_expected) + + def _wait_for_report(self): + """ + Pages: + in: CLAIM + out: REDISPATCH + """ skip_first_screenshot = True - counter = Timer(1, count=4).start() while 1: if skip_first_screenshot: skip_first_screenshot = False else: self.device.screenshot() # End - if self.appear(EMPTY_SLOT) or self.appear(DISPATCHED): - if counter.reached(): - break - continue - # Claim reward - if self.appear(CLAIM, interval=2): - self.device.click(CLAIM) - counter.reset() - continue if self.appear(REDISPATCH): - redispatched = should_redispatch and self._is_duration_expected( - duration_expected) - if redispatched: - self._confirm_assignment(REDISPATCH) - self.dispatched[assignment] = datetime.now( - ) + timedelta(hours=duration_expected) - else: - self.device.click(CLOSE_REPORT) + logger.info('Assignment report appears') + break + # Claim rewards + if self.appear_then_click(CLAIM, interval=2): + continue + + def _exit_report(self, should_redispatch: bool): + """ + Args: + should_redispatch (bool): determined by user config and duration in report + + Pages: + in: CLOSE_REPORT and REDISPATCH + out: EMPTY_SLOT or DISPATCHED + """ + click_button, check_button = CLOSE_REPORT, EMPTY_SLOT + if should_redispatch: + click_button, check_button = REDISPATCH, DISPATCHED + skip_first_screenshot = True + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + # End + if self.appear(check_button): + logger.info('Assignment report is closed') + break + # Close report + if self.appear_then_click(click_button, interval=2): continue - # Re-select duration and dispatch - if should_redispatch and not redispatched: - self.dispatch(assignment, duration_expected) def _is_duration_expected(self, duration: int) -> bool: """ diff --git a/tasks/assignment/dispatch.py b/tasks/assignment/dispatch.py index 6c089f9c2..851c9a2d0 100644 --- a/tasks/assignment/dispatch.py +++ b/tasks/assignment/dispatch.py @@ -35,7 +35,8 @@ class AssignmentDispatch(AssignmentUI): """ self._select_characters() self._select_duration(duration) - self._confirm_assignment(CONFIRM_ASSIGNMENT) + self._confirm_assignment() + self._wait_until_assignment_started() self.dispatched[assignment] = datetime.now() + \ timedelta(hours=duration) @@ -73,31 +74,54 @@ class AssignmentDispatch(AssignmentUI): duration = 20 ASSIGNMENT_DURATION_SWITCH.set(str(duration), self) - def _confirm_assignment(self, dispatch_button: ButtonWrapper) -> bool: + def _confirm_assignment(self): """ - Args: - dispatch_button (ButtonWrapper): - Button to be clicked, CONFIRM_ASSIGNMENT or REDISPATCH - Pages: - in: CONFIRM_ASSIGNMENT or REDISPATCH + in: CONFIRM_ASSIGNMENT out: DISPATCHED """ skip_first_screenshot = True - counter = Timer(1, count=3).start() while 1: if skip_first_screenshot: skip_first_screenshot = False else: self.device.screenshot() # End - if self.appear(DISPATCHED) and self.appear(ASSIGNMENT_STARTED_CHECK): - if counter.reached(): - logger.info(f'Assignment started') - break - continue + if self.appear(DISPATCHED): + logger.info(f'Assignment dispatched') + break # Click - if self.appear(dispatch_button, interval=2): - self.device.click(dispatch_button) - counter.reset() + if self.appear_then_click(CONFIRM_ASSIGNMENT, interval=2): continue + + def _wait_until_assignment_started(self): + """ + Pages: + in: DISPATCHED + out: ASSIGNMENT_STARTED_CHECK + """ + skip_first_screenshot = True + timeout = Timer(2, count=4).start() + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + # End + if self.appear(ASSIGNMENT_START): + logger.info('Assignment start') + break + # Timeout + if timeout.reached(): + logger.warning('Wait for assignment start timeout') + break + skip_first_screenshot = True + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + # End + if self.appear(ASSIGNMENT_STARTED_CHECK): + logger.info('Assignment started') + break