Refactor: Set team using next prev buttons instead (#450)
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 9.4 KiB |
@ -50,16 +50,6 @@ TEAM_1_CHECK = ButtonWrapper(
|
||||
button=(391, 29, 424, 56),
|
||||
),
|
||||
)
|
||||
TEAM_1_CLICK = ButtonWrapper(
|
||||
name='TEAM_1_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_1_CLICK.png',
|
||||
area=(395, 32, 421, 54),
|
||||
search=(375, 12, 441, 74),
|
||||
color=(80, 79, 96),
|
||||
button=(395, 32, 421, 54),
|
||||
),
|
||||
)
|
||||
TEAM_2_CHECK = ButtonWrapper(
|
||||
name='TEAM_2_CHECK',
|
||||
share=Button(
|
||||
@ -70,16 +60,6 @@ TEAM_2_CHECK = ButtonWrapper(
|
||||
button=(491, 29, 528, 56),
|
||||
),
|
||||
)
|
||||
TEAM_2_CLICK = ButtonWrapper(
|
||||
name='TEAM_2_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_2_CLICK.png',
|
||||
area=(512, 32, 525, 54),
|
||||
search=(492, 12, 545, 74),
|
||||
color=(86, 89, 108),
|
||||
button=(512, 32, 525, 54),
|
||||
),
|
||||
)
|
||||
TEAM_3_CHECK = ButtonWrapper(
|
||||
name='TEAM_3_CHECK',
|
||||
share=Button(
|
||||
@ -90,16 +70,6 @@ TEAM_3_CHECK = ButtonWrapper(
|
||||
button=(591, 29, 629, 56),
|
||||
),
|
||||
)
|
||||
TEAM_3_CLICK = ButtonWrapper(
|
||||
name='TEAM_3_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_3_CLICK.png',
|
||||
area=(612, 32, 625, 54),
|
||||
search=(592, 12, 645, 74),
|
||||
color=(78, 82, 95),
|
||||
button=(612, 32, 625, 54),
|
||||
),
|
||||
)
|
||||
TEAM_4_CHECK = ButtonWrapper(
|
||||
name='TEAM_4_CHECK',
|
||||
share=Button(
|
||||
@ -110,16 +80,6 @@ TEAM_4_CHECK = ButtonWrapper(
|
||||
button=(691, 29, 730, 56),
|
||||
),
|
||||
)
|
||||
TEAM_4_CLICK = ButtonWrapper(
|
||||
name='TEAM_4_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_4_CLICK.png',
|
||||
area=(712, 32, 726, 54),
|
||||
search=(692, 12, 746, 74),
|
||||
color=(67, 69, 82),
|
||||
button=(712, 32, 726, 54),
|
||||
),
|
||||
)
|
||||
TEAM_5_CHECK = ButtonWrapper(
|
||||
name='TEAM_5_CHECK',
|
||||
share=Button(
|
||||
@ -130,16 +90,6 @@ TEAM_5_CHECK = ButtonWrapper(
|
||||
button=(791, 29, 829, 56),
|
||||
),
|
||||
)
|
||||
TEAM_5_CLICK = ButtonWrapper(
|
||||
name='TEAM_5_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_5_CLICK.png',
|
||||
area=(813, 32, 825, 54),
|
||||
search=(793, 12, 845, 74),
|
||||
color=(83, 83, 93),
|
||||
button=(813, 32, 825, 54),
|
||||
),
|
||||
)
|
||||
TEAM_6_CHECK = ButtonWrapper(
|
||||
name='TEAM_6_CHECK',
|
||||
share=Button(
|
||||
@ -150,16 +100,6 @@ TEAM_6_CHECK = ButtonWrapper(
|
||||
button=(551, 29, 589, 56),
|
||||
),
|
||||
)
|
||||
TEAM_6_CLICK = ButtonWrapper(
|
||||
name='TEAM_6_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_6_CLICK.png',
|
||||
area=(572, 32, 586, 54),
|
||||
search=(552, 12, 606, 74),
|
||||
color=(86, 91, 109),
|
||||
button=(572, 32, 586, 54),
|
||||
),
|
||||
)
|
||||
TEAM_7_CHECK = ButtonWrapper(
|
||||
name='TEAM_7_CHECK',
|
||||
share=Button(
|
||||
@ -170,16 +110,6 @@ TEAM_7_CHECK = ButtonWrapper(
|
||||
button=(651, 29, 689, 56),
|
||||
),
|
||||
)
|
||||
TEAM_7_CLICK = ButtonWrapper(
|
||||
name='TEAM_7_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_7_CLICK.png',
|
||||
area=(673, 32, 685, 54),
|
||||
search=(653, 12, 705, 74),
|
||||
color=(63, 66, 76),
|
||||
button=(673, 32, 685, 54),
|
||||
),
|
||||
)
|
||||
TEAM_8_CHECK = ButtonWrapper(
|
||||
name='TEAM_8_CHECK',
|
||||
share=Button(
|
||||
@ -190,16 +120,6 @@ TEAM_8_CHECK = ButtonWrapper(
|
||||
button=(751, 29, 789, 56),
|
||||
),
|
||||
)
|
||||
TEAM_8_CLICK = ButtonWrapper(
|
||||
name='TEAM_8_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_8_CLICK.png',
|
||||
area=(772, 32, 786, 54),
|
||||
search=(752, 12, 806, 74),
|
||||
color=(92, 92, 100),
|
||||
button=(772, 32, 786, 54),
|
||||
),
|
||||
)
|
||||
TEAM_9_CHECK = ButtonWrapper(
|
||||
name='TEAM_9_CHECK',
|
||||
share=Button(
|
||||
@ -210,14 +130,24 @@ TEAM_9_CHECK = ButtonWrapper(
|
||||
button=(851, 29, 889, 56),
|
||||
),
|
||||
)
|
||||
TEAM_9_CLICK = ButtonWrapper(
|
||||
name='TEAM_9_CLICK',
|
||||
TEAM_NEXT = ButtonWrapper(
|
||||
name='TEAM_NEXT',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_9_CLICK.png',
|
||||
area=(872, 32, 886, 54),
|
||||
search=(852, 12, 906, 74),
|
||||
color=(73, 73, 83),
|
||||
button=(872, 32, 886, 54),
|
||||
file='./assets/share/combat/team/TEAM_NEXT.png',
|
||||
area=(1202, 313, 1234, 375),
|
||||
search=(1182, 293, 1254, 395),
|
||||
color=(52, 56, 77),
|
||||
button=(1202, 313, 1234, 375),
|
||||
),
|
||||
)
|
||||
TEAM_PREV = ButtonWrapper(
|
||||
name='TEAM_PREV',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_PREV.png',
|
||||
area=(46, 314, 78, 375),
|
||||
search=(26, 294, 98, 395),
|
||||
color=(108, 113, 136),
|
||||
button=(46, 314, 78, 375),
|
||||
),
|
||||
)
|
||||
TEAM_SEARCH = ButtonWrapper(
|
||||
|
@ -1,7 +1,6 @@
|
||||
import re
|
||||
|
||||
from module.base.timer import Timer
|
||||
from module.base.utils import random_rectangle_vector_opted
|
||||
from module.logger import logger
|
||||
from tasks.base.ui import UI
|
||||
from tasks.combat.assets.assets_combat_team import *
|
||||
@ -13,74 +12,32 @@ def button_to_index(button: ButtonWrapper) -> int:
|
||||
return int(res.group(1))
|
||||
else:
|
||||
logger.warning(f'Cannot convert team button to index: {button}')
|
||||
return 1
|
||||
|
||||
|
||||
def index_to_button(index: int) -> ButtonWrapper:
|
||||
match index:
|
||||
case 1:
|
||||
return TEAM_1_CLICK
|
||||
case 2:
|
||||
return TEAM_2_CLICK
|
||||
case 3:
|
||||
return TEAM_3_CLICK
|
||||
case 4:
|
||||
return TEAM_4_CLICK
|
||||
case 5:
|
||||
return TEAM_5_CLICK
|
||||
case 6:
|
||||
return TEAM_6_CLICK
|
||||
case 7:
|
||||
return TEAM_7_CLICK
|
||||
case 8:
|
||||
return TEAM_8_CLICK
|
||||
case 9:
|
||||
return TEAM_9_CLICK
|
||||
case _:
|
||||
logger.warning(f'Invalid team index: {index}')
|
||||
return TEAM_1_CLICK
|
||||
return 0
|
||||
|
||||
|
||||
class CombatTeam(UI):
|
||||
def _get_team(self) -> tuple[list[int], int]:
|
||||
def _get_team(self) -> int:
|
||||
"""
|
||||
Returns:
|
||||
list[str]: List of displayed team index.
|
||||
int: Current team index, or None if current team is not insight
|
||||
int: Current team index, or 0 if current team is not insight
|
||||
"""
|
||||
list_team = []
|
||||
for button in [
|
||||
TEAM_1_CLICK, TEAM_2_CLICK, TEAM_3_CLICK, TEAM_4_CLICK, TEAM_5_CLICK,
|
||||
TEAM_6_CLICK, TEAM_7_CLICK, TEAM_8_CLICK, TEAM_9_CLICK
|
||||
]:
|
||||
button.load_search(TEAM_SEARCH.area)
|
||||
if self.appear(button):
|
||||
list_team.append(button_to_index(button))
|
||||
current_team = None
|
||||
team = 0
|
||||
for button in [
|
||||
TEAM_1_CHECK, TEAM_2_CHECK, TEAM_3_CHECK, TEAM_4_CHECK, TEAM_5_CHECK,
|
||||
TEAM_6_CHECK, TEAM_7_CHECK, TEAM_8_CHECK, TEAM_9_CHECK
|
||||
]:
|
||||
button.load_search(TEAM_SEARCH.area)
|
||||
if self.appear(button):
|
||||
current_team = button_to_index(button)
|
||||
list_team.append(button_to_index(button))
|
||||
list_team = list(sorted(list_team))
|
||||
if self.appear(button, similarity=0.92):
|
||||
if self.image_color_count(button.button, color=(255, 234, 191), threshold=180, count=50):
|
||||
team = button_to_index(button)
|
||||
break
|
||||
|
||||
def show(index):
|
||||
if index == current_team:
|
||||
return f'*0{index}*'
|
||||
else:
|
||||
return f'0{index}'
|
||||
return team
|
||||
|
||||
# [Team] 01 02 *03* 04 05 06
|
||||
logger.attr('Team', ' '.join([show(i) for i in list_team]))
|
||||
return list_team, current_team
|
||||
|
||||
def team_set(self, team: int = 1, skip_first_screenshot=True) -> bool:
|
||||
def team_set(self, index: int = 1, skip_first_screenshot=True) -> bool:
|
||||
"""
|
||||
Args:
|
||||
team: Team index, 1 to 9.
|
||||
index: Team index, 1 to 9.
|
||||
skip_first_screenshot:
|
||||
|
||||
Returns:
|
||||
@ -89,7 +46,7 @@ class CombatTeam(UI):
|
||||
Pages:
|
||||
in: page_team
|
||||
"""
|
||||
logger.info(f'Team set: {team}')
|
||||
logger.info(f'Team set: {index}')
|
||||
# Wait teams show up
|
||||
timeout = Timer(1, count=5).start()
|
||||
while 1:
|
||||
@ -102,18 +59,18 @@ class CombatTeam(UI):
|
||||
if timeout.reached():
|
||||
logger.warning('Wait current team timeout')
|
||||
break
|
||||
_, current = self._get_team()
|
||||
if current:
|
||||
if current == team:
|
||||
logger.info(f'Selected to the correct team')
|
||||
current = self._get_team()
|
||||
if current == index:
|
||||
logger.attr('Team', current)
|
||||
logger.info(f'Already selected to the correct team')
|
||||
return False
|
||||
else:
|
||||
break
|
||||
|
||||
# Set team
|
||||
click_interval = Timer(2)
|
||||
swipe_interval = Timer(2)
|
||||
retry = Timer(2, count=10)
|
||||
skip_first_screenshot = True
|
||||
clicked = False
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
@ -121,31 +78,26 @@ class CombatTeam(UI):
|
||||
self.device.screenshot()
|
||||
|
||||
# End
|
||||
list_team, current = self._get_team()
|
||||
if current and current == team:
|
||||
current = self._get_team()
|
||||
logger.attr('Team', current)
|
||||
if current == index:
|
||||
logger.info(f'Selected to the correct team')
|
||||
return True
|
||||
|
||||
return clicked
|
||||
# Click
|
||||
if team in list_team:
|
||||
if click_interval.reached():
|
||||
self.device.click(index_to_button(team))
|
||||
click_interval.reset()
|
||||
if retry.reached():
|
||||
diff = index - current
|
||||
right = diff % 9
|
||||
left = -diff % 9
|
||||
if right <= left:
|
||||
self.device.multi_click(TEAM_NEXT, right)
|
||||
clicked = True
|
||||
else:
|
||||
self.device.multi_click(TEAM_PREV, left)
|
||||
clicked = True
|
||||
retry.reset()
|
||||
continue
|
||||
# At left
|
||||
elif team < min(list_team):
|
||||
if swipe_interval.reached():
|
||||
p1, p2 = random_rectangle_vector_opted(
|
||||
(350, 0), box=TEAM_SEARCH.area, random_range=(-20, -10, 20, 10))
|
||||
self.device.drag(p1, p2, name=f'TEAM_DRAG')
|
||||
swipe_interval.reset()
|
||||
# At right
|
||||
elif team > max(list_team):
|
||||
if swipe_interval.reached():
|
||||
p1, p2 = random_rectangle_vector_opted(
|
||||
(-350, 0), box=TEAM_SEARCH.area, random_range=(-20, -10, 20, 10))
|
||||
self.device.drag(p1, p2, name=f'TEAM_DRAG')
|
||||
swipe_interval.reset()
|
||||
|
||||
return clicked
|
||||
|
||||
def handle_combat_team_prepare(self, team: int = 1) -> bool:
|
||||
"""
|
||||
|