From c2b935f94669f56602674e96a08469182a2f6e29 Mon Sep 17 00:00:00 2001 From: Zebartin <16185081+Zebartin@users.noreply.github.com> Date: Wed, 21 Jun 2023 23:50:45 +0800 Subject: [PATCH] Fix: Unreliable use of Timer - https://github.com/LmeSzinc/StarRailCopilot/pull/23#discussion_r1235525692 - https://github.com/LmeSzinc/StarRailCopilot/pull/23#discussion_r1235539035 --- .../assignment/dispatch/ASSIGNMENT_START.png | Bin 0 -> 14977 bytes .../assets/assets_assignment_dispatch.py | 10 +++ tasks/assignment/claim.py | 70 ++++++++++++------ tasks/assignment/dispatch.py | 56 ++++++++++---- 4 files changed, 99 insertions(+), 37 deletions(-) create mode 100644 assets/cn/assignment/dispatch/ASSIGNMENT_START.png diff --git a/assets/cn/assignment/dispatch/ASSIGNMENT_START.png b/assets/cn/assignment/dispatch/ASSIGNMENT_START.png new file mode 100644 index 0000000000000000000000000000000000000000..efd15ed00c7360db20c708d5a61a1beb438498ac GIT binary patch literal 14977 zcmeIZ`B&2E8$M3clrwGCv;eGpSO4W zkFP)d@$O~sSODOsxUZib^gF-=0Ki(!`QrH-2~Z9#vHSSFluuIL6t_dddB{!M?R~uO z*aa0;(ypc__b!tJORV*r6~- zgTDRw+kt&^l5c_WEg5{vp5H3Qw<`G!8T?;EsXEosCtHUBpYUPKz5;jcjgdKNlK61# z=F=P6DjsKCtB^#@BIotxQa5VwGb;O1lj<-hKIlJl-O9?!;fk`X{QUglGB35aZ{Ol$ zsjXgJ@eyO%<;}h+U$W)9A&o>|x60wma|oeFo*S@usN{cU5E}a?a zHZQ)sj%>iUN0pmKnWsM+WnDzvvRqtRs-%Zka|+qOeY@R_&HZ~K)lkhdoaKA!BS}f) z^Qxc&b?YBF@X_w!y4KMb^xUf*e`3J6o;jTyY@(_9$kr%^)QU(AB_W1_qJ1851B`O* zgp+|7IC-K0!Wd4+suM-oY@Vude@Y%{UHT!|7GxedtDz0_Et;?ztr_g!OfJ3DhEF*9 zaNu#9v1}LM%j9td5>@E~O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 zn7h*@T$9z;aTet$ePI=3wV%$xhIobJyn@AWO%)fHP)2m`A*bF5Huq}LX%YJztYl60 z7gM;E4RW&~v8!B)$gf>aj-)#4PPd+^#`c$bmk+IFxU{TgzI&K@!0La45cLx-MQ4Wu ziLZ#OHx-K 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