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),
|
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(
|
TEAM_2_CHECK = ButtonWrapper(
|
||||||
name='TEAM_2_CHECK',
|
name='TEAM_2_CHECK',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -70,16 +60,6 @@ TEAM_2_CHECK = ButtonWrapper(
|
|||||||
button=(491, 29, 528, 56),
|
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(
|
TEAM_3_CHECK = ButtonWrapper(
|
||||||
name='TEAM_3_CHECK',
|
name='TEAM_3_CHECK',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -90,16 +70,6 @@ TEAM_3_CHECK = ButtonWrapper(
|
|||||||
button=(591, 29, 629, 56),
|
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(
|
TEAM_4_CHECK = ButtonWrapper(
|
||||||
name='TEAM_4_CHECK',
|
name='TEAM_4_CHECK',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -110,16 +80,6 @@ TEAM_4_CHECK = ButtonWrapper(
|
|||||||
button=(691, 29, 730, 56),
|
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(
|
TEAM_5_CHECK = ButtonWrapper(
|
||||||
name='TEAM_5_CHECK',
|
name='TEAM_5_CHECK',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -130,16 +90,6 @@ TEAM_5_CHECK = ButtonWrapper(
|
|||||||
button=(791, 29, 829, 56),
|
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(
|
TEAM_6_CHECK = ButtonWrapper(
|
||||||
name='TEAM_6_CHECK',
|
name='TEAM_6_CHECK',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -150,16 +100,6 @@ TEAM_6_CHECK = ButtonWrapper(
|
|||||||
button=(551, 29, 589, 56),
|
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(
|
TEAM_7_CHECK = ButtonWrapper(
|
||||||
name='TEAM_7_CHECK',
|
name='TEAM_7_CHECK',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -170,16 +110,6 @@ TEAM_7_CHECK = ButtonWrapper(
|
|||||||
button=(651, 29, 689, 56),
|
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(
|
TEAM_8_CHECK = ButtonWrapper(
|
||||||
name='TEAM_8_CHECK',
|
name='TEAM_8_CHECK',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -190,16 +120,6 @@ TEAM_8_CHECK = ButtonWrapper(
|
|||||||
button=(751, 29, 789, 56),
|
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(
|
TEAM_9_CHECK = ButtonWrapper(
|
||||||
name='TEAM_9_CHECK',
|
name='TEAM_9_CHECK',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -210,14 +130,24 @@ TEAM_9_CHECK = ButtonWrapper(
|
|||||||
button=(851, 29, 889, 56),
|
button=(851, 29, 889, 56),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
TEAM_9_CLICK = ButtonWrapper(
|
TEAM_NEXT = ButtonWrapper(
|
||||||
name='TEAM_9_CLICK',
|
name='TEAM_NEXT',
|
||||||
share=Button(
|
share=Button(
|
||||||
file='./assets/share/combat/team/TEAM_9_CLICK.png',
|
file='./assets/share/combat/team/TEAM_NEXT.png',
|
||||||
area=(872, 32, 886, 54),
|
area=(1202, 313, 1234, 375),
|
||||||
search=(852, 12, 906, 74),
|
search=(1182, 293, 1254, 395),
|
||||||
color=(73, 73, 83),
|
color=(52, 56, 77),
|
||||||
button=(872, 32, 886, 54),
|
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(
|
TEAM_SEARCH = ButtonWrapper(
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from module.base.timer import Timer
|
from module.base.timer import Timer
|
||||||
from module.base.utils import random_rectangle_vector_opted
|
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from tasks.base.ui import UI
|
from tasks.base.ui import UI
|
||||||
from tasks.combat.assets.assets_combat_team import *
|
from tasks.combat.assets.assets_combat_team import *
|
||||||
@ -13,74 +12,32 @@ def button_to_index(button: ButtonWrapper) -> int:
|
|||||||
return int(res.group(1))
|
return int(res.group(1))
|
||||||
else:
|
else:
|
||||||
logger.warning(f'Cannot convert team button to index: {button}')
|
logger.warning(f'Cannot convert team button to index: {button}')
|
||||||
return 1
|
return 0
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class CombatTeam(UI):
|
class CombatTeam(UI):
|
||||||
def _get_team(self) -> tuple[list[int], int]:
|
def _get_team(self) -> int:
|
||||||
"""
|
"""
|
||||||
Returns:
|
Returns:
|
||||||
list[str]: List of displayed team index.
|
int: Current team index, or 0 if current team is not insight
|
||||||
int: Current team index, or None if current team is not insight
|
|
||||||
"""
|
"""
|
||||||
list_team = []
|
team = 0
|
||||||
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
|
|
||||||
for button in [
|
for button in [
|
||||||
TEAM_1_CHECK, TEAM_2_CHECK, TEAM_3_CHECK, TEAM_4_CHECK, TEAM_5_CHECK,
|
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
|
TEAM_6_CHECK, TEAM_7_CHECK, TEAM_8_CHECK, TEAM_9_CHECK
|
||||||
]:
|
]:
|
||||||
button.load_search(TEAM_SEARCH.area)
|
button.load_search(TEAM_SEARCH.area)
|
||||||
if self.appear(button):
|
if self.appear(button, similarity=0.92):
|
||||||
current_team = button_to_index(button)
|
if self.image_color_count(button.button, color=(255, 234, 191), threshold=180, count=50):
|
||||||
list_team.append(button_to_index(button))
|
team = button_to_index(button)
|
||||||
list_team = list(sorted(list_team))
|
break
|
||||||
|
|
||||||
def show(index):
|
return team
|
||||||
if index == current_team:
|
|
||||||
return f'*0{index}*'
|
|
||||||
else:
|
|
||||||
return f'0{index}'
|
|
||||||
|
|
||||||
# [Team] 01 02 *03* 04 05 06
|
def team_set(self, index: int = 1, skip_first_screenshot=True) -> bool:
|
||||||
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:
|
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
team: Team index, 1 to 9.
|
index: Team index, 1 to 9.
|
||||||
skip_first_screenshot:
|
skip_first_screenshot:
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -89,7 +46,7 @@ class CombatTeam(UI):
|
|||||||
Pages:
|
Pages:
|
||||||
in: page_team
|
in: page_team
|
||||||
"""
|
"""
|
||||||
logger.info(f'Team set: {team}')
|
logger.info(f'Team set: {index}')
|
||||||
# Wait teams show up
|
# Wait teams show up
|
||||||
timeout = Timer(1, count=5).start()
|
timeout = Timer(1, count=5).start()
|
||||||
while 1:
|
while 1:
|
||||||
@ -102,18 +59,18 @@ class CombatTeam(UI):
|
|||||||
if timeout.reached():
|
if timeout.reached():
|
||||||
logger.warning('Wait current team timeout')
|
logger.warning('Wait current team timeout')
|
||||||
break
|
break
|
||||||
_, current = self._get_team()
|
current = self._get_team()
|
||||||
if current:
|
if current == index:
|
||||||
if current == team:
|
logger.attr('Team', current)
|
||||||
logger.info(f'Selected to the correct team')
|
logger.info(f'Already selected to the correct team')
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Set team
|
# Set team
|
||||||
click_interval = Timer(2)
|
retry = Timer(2, count=10)
|
||||||
swipe_interval = Timer(2)
|
|
||||||
skip_first_screenshot = True
|
skip_first_screenshot = True
|
||||||
|
clicked = False
|
||||||
while 1:
|
while 1:
|
||||||
if skip_first_screenshot:
|
if skip_first_screenshot:
|
||||||
skip_first_screenshot = False
|
skip_first_screenshot = False
|
||||||
@ -121,31 +78,26 @@ class CombatTeam(UI):
|
|||||||
self.device.screenshot()
|
self.device.screenshot()
|
||||||
|
|
||||||
# End
|
# End
|
||||||
list_team, current = self._get_team()
|
current = self._get_team()
|
||||||
if current and current == team:
|
logger.attr('Team', current)
|
||||||
|
if current == index:
|
||||||
logger.info(f'Selected to the correct team')
|
logger.info(f'Selected to the correct team')
|
||||||
return True
|
return clicked
|
||||||
|
|
||||||
# Click
|
# Click
|
||||||
if team in list_team:
|
if retry.reached():
|
||||||
if click_interval.reached():
|
diff = index - current
|
||||||
self.device.click(index_to_button(team))
|
right = diff % 9
|
||||||
click_interval.reset()
|
left = -diff % 9
|
||||||
continue
|
if right <= left:
|
||||||
# At left
|
self.device.multi_click(TEAM_NEXT, right)
|
||||||
elif team < min(list_team):
|
clicked = True
|
||||||
if swipe_interval.reached():
|
else:
|
||||||
p1, p2 = random_rectangle_vector_opted(
|
self.device.multi_click(TEAM_PREV, left)
|
||||||
(350, 0), box=TEAM_SEARCH.area, random_range=(-20, -10, 20, 10))
|
clicked = True
|
||||||
self.device.drag(p1, p2, name=f'TEAM_DRAG')
|
retry.reset()
|
||||||
swipe_interval.reset()
|
continue
|
||||||
# At right
|
|
||||||
elif team > max(list_team):
|
return clicked
|
||||||
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()
|
|
||||||
|
|
||||||
def handle_combat_team_prepare(self, team: int = 1) -> bool:
|
def handle_combat_team_prepare(self, team: int = 1) -> bool:
|
||||||
"""
|
"""
|
||||||
|