1
0
mirror of https://github.com/TheFunny/ArisuAutoSweeper synced 2025-12-16 19:55:12 +00:00

Compare commits

...

8 Commits

7 changed files with 191 additions and 11 deletions

View File

@ -1,6 +1,6 @@
<img width="150" height="150" align="left" style="float: left; margin: 0 10px 0 0;" alt="AAS icon" src="docs/resources/aas_icon.svg"/>
# ArisuAutoScript
# ArisuAutoSweeper
**Blue Archive Automation Script**

View File

@ -1,6 +1,6 @@
<img width="150" height="150" align="left" style="float: left; margin: 0 10px 0 0;" alt="AAS icon" src="docs/resources/aas_icon.svg"/>
# ArisuAutoScript
# ArisuAutoSweeper
**蔚蓝档案自动化脚本**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -27,7 +27,7 @@
"help": ""
},
"Circle": {
"name": "Circle",
"name": "Club",
"help": ""
},
"TacticalChallenge": {
@ -196,7 +196,7 @@
},
"Touch": {
"name": "Student Interaction",
"help": "Auto detect intractable student and click"
"help": "Auto detect intractable student and tap"
},
"AutoAdjust": {
"name": "Interface Auto Adjustment",

181
module/ui/stage_list.py Normal file
View File

@ -0,0 +1,181 @@
import cv2
import numpy as np
from module.base.base import ModuleBase
from module.base.button import ButtonWrapper, ClickButton
from module.base.timer import Timer
from module.base.utils import area_pad, area_size, area_offset, random_rectangle_vector_opted
from module.logger import logger
from module.ocr.ocr import Ocr
class StageList:
drag_vector_range = (0.65, 0.85)
def __init__(
self,
name,
area_stage: ButtonWrapper,
area_index: ButtonWrapper,
area_item: ButtonWrapper,
button_enter: ButtonWrapper,
drag_direction: str = "down"
):
self.name = name
self.stage = area_stage
self.index_ocr = Ocr(area_index, lang='en')
self.stage_item = area_item.button
self.enter = button_enter
self.drag_direction = drag_direction
self.current_index_min = 1
self.current_index_max = 1
self.current_indexes = []
def __str__(self):
return f'StageList({self.name})'
__repr__ = __str__
def __eq__(self, other):
return str(self) == str(other)
def __hash__(self):
return hash(self.name)
def _get_indexes(self) -> list[int]:
return list(map(lambda x: int(x.ocr_text), self.current_indexes))
def load_stage_indexes(self, main: ModuleBase):
self.current_indexes = list(
filter(lambda x: x.ocr_text.isdigit(), self.index_ocr.detect_and_ocr(main.device.image))
)
if not self.current_indexes:
logger.warning(f'No valid index in {self.index_ocr.name}')
return
indexes = self._get_indexes()
self.current_index_min = min(indexes)
self.current_index_max = max(indexes)
logger.attr(self.index_ocr.name, f'Index range: {self.current_index_min} - {self.current_index_max}')
def drag_page(self, direction: str, main: ModuleBase, vector_range=None, reverse=False):
"""
Args:
direction: up, down
main:
vector_range (tuple[float, float]):
reverse (bool):
"""
if vector_range is None:
vector_range = self.drag_vector_range
vector = np.random.uniform(*vector_range)
width, height = area_size(self.stage.button)
if direction == 'up':
vector = (0, vector * height)
elif direction == 'down':
vector = (0, -vector * height)
else:
logger.warning(f'Unknown drag direction: {direction}')
return
if reverse:
vector = (-vector[0], -vector[1])
p1, p2 = random_rectangle_vector_opted(vector, box=self.stage.button)
main.device.drag(p1, p2, name=f'{self.name}_DRAG')
def insight_index(self, index: int, main: ModuleBase, skip_first_screenshot=True) -> bool:
"""
Args:
index:
main:
skip_first_screenshot:
Returns:
If success
"""
logger.info(f'Insight index: {index}')
last_indexes: set[int] = set()
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
main.device.screenshot()
self.load_stage_indexes(main=main)
if self.current_index_min <= index <= self.current_index_max:
break
if index < self.current_index_min:
self.drag_page(self.drag_direction, main, reverse=True)
elif index > self.current_index_max:
self.drag_page(self.drag_direction, main)
main.wait_until_stable(
self.stage.button,
timer=Timer(0, 0),
timeout=Timer(1.5, 5)
)
indexes = self._get_indexes()
if indexes and last_indexes == set(indexes):
logger.warning(f'No more index {index}')
return False
last_indexes = set(indexes)
return True
@staticmethod
def _match_clickable_points(image, template, threshold=0.85):
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
template = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
res = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
loc = np.where(res >= threshold)
return [point for point in zip(*loc[::-1])]
def select_index_enter(
self,
index: int,
main: ModuleBase,
insight: bool = True,
skip_first_screenshot: bool = True,
interval: int = 5
) -> bool:
if insight and not self.insight_index(index, main, skip_first_screenshot):
return False
logger.info(f'Select index: {index}')
click_interval = Timer(interval)
load_index_interval = Timer(1)
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
main.device.screenshot()
if load_index_interval.reached_and_reset():
self.load_stage_indexes(main=main)
index_box = next(filter(lambda x: int(x.ocr_text) == index, self.current_indexes), None)
if index_box is None:
logger.warning(f'No index {index} in {self.index_ocr.name}')
return False
stage_item_box = area_pad((0, 0, *area_size(self.stage_item)))
search_box = area_offset(stage_item_box, index_box.box[:2])
search_image = main.image_crop(search_box)
points = self._match_clickable_points(search_image, self.enter.matched_button.image)
if not points:
logger.warning(f'No clickable {self.enter.name}')
return False
point = area_offset((0, 0, *area_size(self.enter.button)), points[0])
click_button = ClickButton(area_offset(point, search_box[:2]), name=self.enter.name)
if click_interval.reached_and_reset():
main.device.click(click_button)
return True

View File

@ -67,10 +67,10 @@ CLICKABLE_TEMPLATE = ButtonWrapper(
name='CLICKABLE_TEMPLATE',
jp=Button(
file='./assets/jp/cafe/CLICKABLE_TEMPLATE.png',
area=(0, 0, 42, 56),
search=(0, 0, 62, 76),
color=(77, 63, 1),
button=(0, 0, 42, 56),
area=(619, 332, 660, 387),
search=(599, 312, 680, 407),
color=(79, 65, 1),
button=(619, 332, 660, 387),
),
)
GET_REWARD = ButtonWrapper(

View File

@ -63,8 +63,7 @@ class Cafe(UI):
def _match_clickable_points(self, image, threshold=0.8):
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
template = self.btn.matched_button.image
template = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
template = cv2.cvtColor(self.btn.matched_button.image, cv2.COLOR_BGR2GRAY)
res = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
loc = np.where(res >= threshold)
@ -73,7 +72,7 @@ class Cafe(UI):
def _get_clickable_buttons(self, threshold=0.8, offset=(0, 0)):
image = self.device.image
h, w = image.shape[:2]
cv2.rectangle(image, (0, 10), (w - 25, h - 10), (0, 0, 0), 50)
image = cv2.rectangle(image, (0, 10), (w - 25, h - 10), (0, 0, 0), 50)
image = self._extract_clickable_from_image(image)
points = self._match_clickable_points(image, threshold)
points = self.merge_points(points)