1
0
mirror of https://github.com/TheFunny/ArisuAutoSweeper synced 2026-06-28 08:44:51 +00:00

7 Commits

4 changed files with 52 additions and 58 deletions
+11 -15
View File
@@ -5,7 +5,7 @@ from tasks.base.assets.assets_base_page import LOADING_CHECK
class PopupHandler(ModuleBase): class PopupHandler(ModuleBase):
def handle_loading(self, interval=5) -> bool: def handle_loading(self) -> bool:
""" """
Args: Args:
interval: interval:
@@ -13,7 +13,7 @@ class PopupHandler(ModuleBase):
Returns: Returns:
If handled. If handled.
""" """
if self.appear(LOADING_CHECK, interval=interval): if self.appear(LOADING_CHECK):
timer = Timer(0.5).start() timer = Timer(0.5).start()
while 1: while 1:
if timer.reached_and_reset(): if timer.reached_and_reset():
@@ -27,7 +27,7 @@ class PopupHandler(ModuleBase):
return False return False
def handle_reward(self, interval=5) -> bool: def handle_reward(self) -> bool:
""" """
Args: Args:
interval: interval:
@@ -35,13 +35,11 @@ class PopupHandler(ModuleBase):
Returns: Returns:
If handled. If handled.
""" """
if self.appear_then_click(GET_REWARD, interval=interval): if self.appear(GET_REWARD) or self.match_color(GET_REWARD, threshold=30):
timer = Timer(0.2).start()
while 1: while 1:
if timer.reached_and_reset():
self.device.screenshot() self.device.screenshot()
if self.appear(GET_REWARD): if self.appear(GET_REWARD) or self.match_color(GET_REWARD, threshold=30):
self.device.click(GET_REWARD) self.click_with_interval(GET_REWARD, interval=0.5)
else: else:
break break
return True return True
@@ -52,13 +50,13 @@ class PopupHandler(ModuleBase):
if self.appear_then_click(GET_REWARD_SKIP, interval=interval): if self.appear_then_click(GET_REWARD_SKIP, interval=interval):
return True return True
def handle_daily_news(self, interval=5) -> bool: def handle_daily_news(self, interval=2) -> bool:
if self.appear_then_click(DAILY_NEWS, interval=interval): if self.appear_then_click(DAILY_NEWS, interval=interval):
return True return True
return False return False
def handle_daily_reward(self, interval=5) -> bool: def handle_daily_reward(self, interval=2) -> bool:
if self.appear_then_click(DAILY_REWARD, interval=interval): if self.appear_then_click(DAILY_REWARD, interval=interval):
return True return True
@@ -70,14 +68,12 @@ class PopupHandler(ModuleBase):
return False return False
def handle_affection_level_up(self, interval=5) -> bool: def handle_affection_level_up(self) -> bool:
if self.appear_then_click(AFFECTION_LEVEL_UP, interval=interval): if self.appear_then_click(AFFECTION_LEVEL_UP):
timer = Timer(0.2).start()
while 1: while 1:
if timer.reached_and_reset():
self.device.screenshot() self.device.screenshot()
if self.appear(AFFECTION_LEVEL_UP): if self.appear(AFFECTION_LEVEL_UP):
self.device.click(AFFECTION_LEVEL_UP) self.click_with_interval(AFFECTION_LEVEL_UP, interval=1)
else: else:
break break
return True return True
+32 -34
View File
@@ -71,7 +71,7 @@ class Cafe(UI):
return [point for point in zip(*loc[::-1])] return [point for point in zip(*loc[::-1])]
def _get_clickable_buttons(self, threshold=0.8, offset=(0, 0)): def _get_clickable_buttons(self, threshold=0.8, offset=(0, 0)):
image = cv2.copyMakeBorder(self.device.image, 20, 20, 10, 60, cv2.BORDER_CONSTANT, value=(0, 0, 0)) image = cv2.copyMakeBorder(self.device.image, 20, 20, 10, 80, cv2.BORDER_CONSTANT, value=(0, 0, 0))
image = self._extract_clickable_from_image(image) image = self._extract_clickable_from_image(image)
points = self._match_clickable_points(image, threshold) points = self._match_clickable_points(image, threshold)
points = self.merge_points(points) points = self.merge_points(points)
@@ -133,13 +133,14 @@ class Cafe(UI):
if self.appear_then_click(CHECK_REWARD): if self.appear_then_click(CHECK_REWARD):
return CafeStatus.REWARD return CafeStatus.REWARD
case CafeStatus.REWARD: case CafeStatus.REWARD:
if not self.appear(GET_REWARD_CLOSE):
self.click_with_interval(CHECK_REWARD)
return status
if self.match_color(GOT_REWARD): if self.match_color(GOT_REWARD):
self.device.click(GET_REWARD_CLOSE) self.device.click(GET_REWARD_CLOSE)
return CafeStatus.GOT return CafeStatus.GOT
if not self.appear(GET_REWARD):
return CafeStatus.OCR
if self.match_color(GET_REWARD): if self.match_color(GET_REWARD):
self.device.click(GET_REWARD) self.click_with_interval(GET_REWARD)
case CafeStatus.GOT: case CafeStatus.GOT:
logger.info('Cafe reward have been got') logger.info('Cafe reward have been got')
self.appear_then_click(GET_REWARD_CLOSE) self.appear_then_click(GET_REWARD_CLOSE)
@@ -151,7 +152,7 @@ class Cafe(UI):
logger.attr('Clickable', self.click) logger.attr('Clickable', self.click)
if not buttons: if not buttons:
return CafeStatus.CHECK return CafeStatus.CHECK
self.device.click(buttons[0]) self.click_with_interval(buttons[0], interval=1)
case CafeStatus.CHECK: case CafeStatus.CHECK:
buttons = self._get_clickable_buttons() buttons = self._get_clickable_buttons()
if not self.is_adjust_on: if not self.is_adjust_on:
@@ -193,8 +194,7 @@ class Cafe(UI):
status = CafeStatus.STUDENT_LIST status = CafeStatus.STUDENT_LIST
loading_timer = Timer(2).start() loading_timer = Timer(2).start()
action_timer = Timer(1.5, count=1) # cant be too fast action_timer = Timer(1, count=1) # cant be too fast
check_timer = Timer(1, count=1)
is_list = False is_list = False
is_reset = False is_reset = False
is_second = False is_second = False
@@ -209,6 +209,29 @@ class Cafe(UI):
if self.ui_additional(): if self.ui_additional():
continue continue
if not loading_timer.reached():
continue
if not is_list and status == CafeStatus.STUDENT_LIST and self.appear(STUDENT_LIST):
is_list = True
loading_timer = Timer(3).start()
continue
if not is_reward_on and status == CafeStatus.OCR:
logger.info('Skip reward')
status = CafeStatus.CLICK
continue
if not is_touch_on and status == CafeStatus.CLICK:
logger.info('Skip touch')
status = CafeStatus.FINISHED
continue
if is_touch_on and not is_reset and status == CafeStatus.CLICK:
self._reset_cafe_position('init')
is_reset = True
continue
if is_second_cafe_on and not is_second and status == CafeStatus.FINISHED: if is_second_cafe_on and not is_second and status == CafeStatus.FINISHED:
if not SWITCH_CAFE.appear(main=self): if not SWITCH_CAFE.appear(main=self):
logger.warning('Cafe switch not found') logger.warning('Cafe switch not found')
@@ -225,40 +248,15 @@ class Cafe(UI):
continue continue
case '2': case '2':
logger.info('Cafe second arrived') logger.info('Cafe second arrived')
SWITCH_CAFE.set('off', main=self)
status = CafeStatus.STUDENT_LIST status = CafeStatus.STUDENT_LIST
is_list = False is_list = False
is_second = True is_second = True
self.check = 0 self.check = 0
if not loading_timer.reached():
continue
if not is_list and status == CafeStatus.STUDENT_LIST and self.appear(STUDENT_LIST):
is_list = True
loading_timer = Timer(4).start()
continue
if not is_reward_on and status == CafeStatus.OCR:
logger.info('Skip reward')
status = CafeStatus.CLICK
continue
if not is_touch_on and status == CafeStatus.CLICK:
logger.info('Skip touch')
status = CafeStatus.FINISHED
continue
if is_touch_on and not is_reset and status == CafeStatus.CLICK:
self._reset_cafe_position('init')
is_reset = True
continue
if status == CafeStatus.CHECK and not check_timer.reached_and_reset():
continue
if action_timer.reached_and_reset(): if action_timer.reached_and_reset():
status = self._handle_cafe(status)
logger.attr('Status', status) logger.attr('Status', status)
status = self._handle_cafe(status)
if not is_second_cafe_on: if not is_second_cafe_on:
if status is CafeStatus.FINISHED: if status is CafeStatus.FINISHED:
+1 -1
View File
@@ -47,8 +47,8 @@ class Circle(UI):
status = CircleStatus.GOT status = CircleStatus.GOT
if action_timer.reached_and_reset(): if action_timer.reached_and_reset():
status = self._handle_circle(status)
logger.attr('Status', status) logger.attr('Status', status)
status = self._handle_circle(status)
if status is CircleStatus.FINISHED: if status is CircleStatus.FINISHED:
break break
@@ -146,8 +146,8 @@ class TacticalChallenge(UI):
if not ui_timer.reached(): if not ui_timer.reached():
continue continue
if action_timer.reached_and_reset(): if action_timer.reached_and_reset():
status = self._handle_challenge(status)
logger.attr('Status', status.name) logger.attr('Status', status.name)
status = self._handle_challenge(status)
if status in (TCStatus.FINAL, TCStatus.FINISHED): if status in (TCStatus.FINAL, TCStatus.FINISHED):
break break