1
0
mirror of https://github.com/TheFunny/ArisuAutoSweeper synced 2026-06-09 20:04:52 +00:00

Upload code

This commit is contained in:
2023-11-01 15:33:35 +08:00
commit 6860f2eb72
415 changed files with 50990 additions and 0 deletions
@@ -0,0 +1,145 @@
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 ```
CHALLENGE_LOSE = ButtonWrapper(
name='CHALLENGE_LOSE',
jp=Button(
file='./assets/jp/tactical_challenge/CHALLENGE_LOSE.png',
area=(583, 195, 698, 224),
search=(563, 175, 718, 244),
color=(146, 158, 173),
button=(548, 431, 738, 499),
),
)
CHALLENGE_WIN = ButtonWrapper(
name='CHALLENGE_WIN',
jp=Button(
file='./assets/jp/tactical_challenge/CHALLENGE_WIN.png',
area=(583, 131, 698, 160),
search=(563, 111, 718, 180),
color=(151, 165, 180),
button=(549, 495, 737, 563),
),
)
GET_REWARD_CREDIT = ButtonWrapper(
name='GET_REWARD_CREDIT',
jp=Button(
file='./assets/jp/tactical_challenge/GET_REWARD_CREDIT.png',
area=(308, 360, 397, 415),
search=(288, 340, 417, 435),
color=(215, 193, 61),
button=(308, 360, 397, 415),
),
)
GET_REWARD_DAILY = ButtonWrapper(
name='GET_REWARD_DAILY',
jp=Button(
file='./assets/jp/tactical_challenge/GET_REWARD_DAILY.png',
area=(307, 440, 395, 493),
search=(287, 420, 415, 513),
color=(214, 192, 60),
button=(307, 440, 395, 493),
),
)
GOT_REWARD_CREDIT = ButtonWrapper(
name='GOT_REWARD_CREDIT',
jp=Button(
file='./assets/jp/tactical_challenge/GOT_REWARD_CREDIT.png',
area=(308, 358, 398, 416),
search=(288, 338, 418, 436),
color=(203, 205, 204),
button=(308, 358, 398, 416),
),
)
GOT_REWARD_DAILY = ButtonWrapper(
name='GOT_REWARD_DAILY',
jp=Button(
file='./assets/jp/tactical_challenge/GOT_REWARD_DAILY.png',
area=(307, 439, 397, 494),
search=(287, 419, 417, 514),
color=(203, 203, 204),
button=(307, 439, 397, 494),
),
)
OCR_TICKET = ButtonWrapper(
name='OCR_TICKET',
jp=Button(
file='./assets/jp/tactical_challenge/OCR_TICKET.png',
area=(206, 479, 240, 499),
search=(186, 459, 260, 519),
color=(200, 202, 204),
button=(206, 479, 240, 499),
),
)
PLAYER_SELECT_FIRST = ButtonWrapper(
name='PLAYER_SELECT_FIRST',
jp=Button(
file='./assets/jp/tactical_challenge/PLAYER_SELECT_FIRST.png',
area=(467, 293, 496, 316),
search=(447, 273, 516, 336),
color=(191, 202, 207),
button=(558, 179, 1118, 282),
),
)
PLAYER_SELECT_SECOND = ButtonWrapper(
name='PLAYER_SELECT_SECOND',
jp=Button(
file='./assets/jp/tactical_challenge/PLAYER_SELECT_SECOND.png',
area=(466, 451, 496, 475),
search=(446, 431, 516, 495),
color=(192, 203, 208),
button=(554, 336, 1127, 443),
),
)
PLAYER_SELECT_THIRD = ButtonWrapper(
name='PLAYER_SELECT_THIRD',
jp=Button(
file='./assets/jp/tactical_challenge/PLAYER_SELECT_THIRD.png',
area=(466, 608, 496, 634),
search=(446, 588, 516, 654),
color=(194, 206, 211),
button=(557, 495, 1120, 599),
),
)
PREPARE_CHALLENGE = ButtonWrapper(
name='PREPARE_CHALLENGE',
jp=Button(
file='./assets/jp/tactical_challenge/PREPARE_CHALLENGE.png',
area=(583, 83, 698, 111),
search=(563, 63, 718, 131),
color=(148, 161, 175),
button=(561, 548, 723, 598),
),
)
SKIP_OFF = ButtonWrapper(
name='SKIP_OFF',
jp=Button(
file='./assets/jp/tactical_challenge/SKIP_OFF.png',
area=(1087, 585, 1127, 622),
search=(1067, 565, 1147, 642),
color=(96, 137, 171),
button=(1088, 582, 1250, 626),
),
)
SKIP_ON = ButtonWrapper(
name='SKIP_ON',
jp=Button(
file='./assets/jp/tactical_challenge/SKIP_ON.png',
area=(1096, 591, 1121, 615),
search=(1076, 571, 1141, 635),
color=(99, 177, 212),
button=(1089, 581, 1250, 626),
),
)
START_CHALLENGE = ButtonWrapper(
name='START_CHALLENGE',
jp=Button(
file='./assets/jp/tactical_challenge/START_CHALLENGE.png',
area=(107, 10, 159, 37),
search=(87, 0, 179, 57),
color=(148, 161, 176),
button=(1091, 635, 1246, 704),
),
)
@@ -0,0 +1,157 @@
import random
from enum import Enum
from module.base.timer import Timer
from module.logger import logger
from module.ocr.ocr import DigitCounter
from module.ui.switch import Switch
from tasks.base.page import page_tactical_challenge
from tasks.base.ui import UI
from tasks.tactical_challenge.assets.assets_tactical_challenge import *
SWITCH_SKIP = Switch('Skip_switch')
SWITCH_SKIP.add_state('on', SKIP_ON)
SWITCH_SKIP.add_state('off', SKIP_OFF)
class TCStatus(Enum):
"""
Tactical challenge status
"""
REWARD = 0
OCR = 1
SELECT = 2
PREPARE = 3
SKIP = 4
START = 5
RESULT = 6
WIN = 7
LOSE = 8
FINAL = 9
FINISHED = -1
class TacticalChallenge(UI):
select_players = (PLAYER_SELECT_FIRST, PLAYER_SELECT_SECOND, PLAYER_SELECT_THIRD)
def _get_ticket(self):
"""
Page:
in: page_tactical_challenge
"""
ocr = DigitCounter(OCR_TICKET).ocr_single_line(self.device.image)
# number of tickets remaining
ticket, _, total = ocr
if total == 0:
logger.warning('Invalid ticket')
return False, 5
logger.attr('Ticket', ticket)
return True, ticket
def _get_reward(self):
if self.match_color(GET_REWARD_DAILY):
self.device.click(GET_REWARD_DAILY)
logger.info('Get tc daily reward')
return True
if self.match_color(GET_REWARD_CREDIT):
self.device.click(GET_REWARD_CREDIT)
logger.info('Get tc credit reward')
return True
if self.match_color(GOT_REWARD_DAILY) and self.match_color(GOT_REWARD_CREDIT):
logger.info('Both tc reward got')
return True
return False
def _set_skip(self):
"""
Set skip switch to on
:returns: True if switch is set, False if switch not found
"""
if not SWITCH_SKIP.appear(main=self):
logger.info('Skip switch not found')
return False
SWITCH_SKIP.set('on', main=self)
return True
def _player_select(self, select):
if select:
return random.choice(self.select_players)
else:
return self.select_players[select]
def _handle_challenge(self, status):
match status:
case TCStatus.REWARD:
if self._get_reward():
return TCStatus.OCR
case TCStatus.OCR:
is_valid, ticket = self._get_ticket()
if not is_valid:
return status
if ticket == 0:
return TCStatus.FINISHED
return TCStatus.SELECT
case TCStatus.SELECT:
self.appear_then_click(self.select)
if self.appear(PREPARE_CHALLENGE):
return TCStatus.PREPARE
case TCStatus.PREPARE:
self.appear_then_click(PREPARE_CHALLENGE)
if not self.appear(PREPARE_CHALLENGE):
return TCStatus.SKIP
case TCStatus.SKIP:
if not self._set_skip():
return TCStatus.SKIP
return TCStatus.START
case TCStatus.START:
self.appear_then_click(START_CHALLENGE)
if not self.appear(START_CHALLENGE):
return TCStatus.RESULT
case TCStatus.RESULT:
if self.appear_then_click(CHALLENGE_WIN):
return TCStatus.WIN
if self.appear_then_click(CHALLENGE_LOSE):
return TCStatus.LOSE
case TCStatus.WIN | TCStatus.LOSE:
if self.appear(CHALLENGE_WIN) or self.appear(CHALLENGE_LOSE):
return TCStatus.RESULT
is_valid, ticket = self._get_ticket()
if not is_valid:
return status
if ticket == 0:
return TCStatus.FINISHED
return TCStatus.FINAL
case TCStatus.FINAL | TCStatus.FINISHED:
return status
case _:
logger.warning(f'Invalid status: {status}')
return status
def run(self):
self.ui_ensure(page_tactical_challenge)
self.select = self._player_select(self.config.TacticalChallenge_PlayerSelect)
status = TCStatus.REWARD
action_timer = Timer(1, count=1)
# ensure reward can be clicked
ui_timer = Timer(2).start()
while 1:
self.device.screenshot()
if self.ui_additional():
continue
if not ui_timer.reached():
continue
if action_timer.reached_and_reset():
status = self._handle_challenge(status)
logger.attr('Status', status.name)
if status in (TCStatus.FINAL, TCStatus.FINISHED):
break
if status is TCStatus.FINISHED:
self.config.task_delay(server_update=True)
else:
self.config.task_delay(minute=1)