Fix: Refactor team select as having 9 teams now
Before Width: | Height: | Size: 8.6 KiB |
BIN
assets/share/combat/team/TEAM_1_CHECK.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
assets/share/combat/team/TEAM_1_CLICK.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 9.7 KiB |
BIN
assets/share/combat/team/TEAM_2_CHECK.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
assets/share/combat/team/TEAM_2_CLICK.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 9.9 KiB |
BIN
assets/share/combat/team/TEAM_3_CHECK.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/share/combat/team/TEAM_3_CLICK.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 9.0 KiB |
BIN
assets/share/combat/team/TEAM_4_CHECK.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/share/combat/team/TEAM_4_CLICK.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 9.2 KiB |
BIN
assets/share/combat/team/TEAM_5_CHECK.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
assets/share/combat/team/TEAM_5_CLICK.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 9.2 KiB |
BIN
assets/share/combat/team/TEAM_6_CHECK.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
assets/share/combat/team/TEAM_6_CLICK.png
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
assets/share/combat/team/TEAM_7_CHECK.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
assets/share/combat/team/TEAM_7_CLICK.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/share/combat/team/TEAM_8_CHECK.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/share/combat/team/TEAM_8_CLICK.png
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
assets/share/combat/team/TEAM_9_CHECK.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/share/combat/team/TEAM_9_CLICK.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
assets/share/combat/team/TEAM_SEARCH.png
Normal file
After Width: | Height: | Size: 47 KiB |
@ -40,63 +40,193 @@ COMBAT_TEAM_SUPPORT = ButtonWrapper(
|
||||
button=(1123, 477, 1158, 503),
|
||||
),
|
||||
)
|
||||
TEAM_1 = ButtonWrapper(
|
||||
name='TEAM_1',
|
||||
TEAM_1_CHECK = ButtonWrapper(
|
||||
name='TEAM_1_CHECK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_1.png',
|
||||
area=(365, 29, 411, 65),
|
||||
search=(345, 9, 431, 85),
|
||||
color=(113, 109, 117),
|
||||
button=(365, 29, 411, 65),
|
||||
file='./assets/share/combat/team/TEAM_1_CHECK.png',
|
||||
area=(391, 29, 424, 56),
|
||||
search=(371, 9, 444, 76),
|
||||
color=(147, 137, 129),
|
||||
button=(391, 29, 424, 56),
|
||||
),
|
||||
)
|
||||
TEAM_2 = ButtonWrapper(
|
||||
name='TEAM_2',
|
||||
TEAM_1_CLICK = ButtonWrapper(
|
||||
name='TEAM_1_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_2.png',
|
||||
area=(467, 29, 511, 65),
|
||||
search=(447, 9, 531, 85),
|
||||
color=(126, 124, 130),
|
||||
button=(467, 29, 511, 65),
|
||||
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_3 = ButtonWrapper(
|
||||
name='TEAM_3',
|
||||
TEAM_2_CHECK = ButtonWrapper(
|
||||
name='TEAM_2_CHECK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_3.png',
|
||||
area=(567, 28, 614, 66),
|
||||
search=(547, 8, 634, 86),
|
||||
color=(115, 116, 123),
|
||||
button=(567, 28, 614, 66),
|
||||
file='./assets/share/combat/team/TEAM_2_CHECK.png',
|
||||
area=(491, 29, 528, 56),
|
||||
search=(471, 9, 548, 76),
|
||||
color=(151, 143, 135),
|
||||
button=(491, 29, 528, 56),
|
||||
),
|
||||
)
|
||||
TEAM_4 = ButtonWrapper(
|
||||
name='TEAM_4',
|
||||
TEAM_2_CLICK = ButtonWrapper(
|
||||
name='TEAM_2_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_4.png',
|
||||
area=(666, 29, 712, 63),
|
||||
search=(646, 9, 732, 83),
|
||||
color=(106, 103, 98),
|
||||
button=(666, 29, 712, 63),
|
||||
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_5 = ButtonWrapper(
|
||||
name='TEAM_5',
|
||||
TEAM_3_CHECK = ButtonWrapper(
|
||||
name='TEAM_3_CHECK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_5.png',
|
||||
area=(767, 30, 816, 66),
|
||||
search=(747, 10, 836, 86),
|
||||
color=(106, 100, 96),
|
||||
button=(767, 30, 816, 66),
|
||||
file='./assets/share/combat/team/TEAM_3_CHECK.png',
|
||||
area=(591, 29, 629, 56),
|
||||
search=(571, 9, 649, 76),
|
||||
color=(145, 138, 128),
|
||||
button=(591, 29, 629, 56),
|
||||
),
|
||||
)
|
||||
TEAM_6 = ButtonWrapper(
|
||||
name='TEAM_6',
|
||||
TEAM_3_CLICK = ButtonWrapper(
|
||||
name='TEAM_3_CLICK',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_6.png',
|
||||
area=(867, 29, 912, 63),
|
||||
search=(847, 9, 932, 83),
|
||||
color=(113, 106, 101),
|
||||
button=(867, 29, 912, 63),
|
||||
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(
|
||||
file='./assets/share/combat/team/TEAM_4_CHECK.png',
|
||||
area=(691, 29, 730, 56),
|
||||
search=(671, 9, 750, 76),
|
||||
color=(136, 129, 117),
|
||||
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(
|
||||
file='./assets/share/combat/team/TEAM_5_CHECK.png',
|
||||
area=(791, 29, 829, 56),
|
||||
search=(771, 9, 849, 76),
|
||||
color=(145, 135, 121),
|
||||
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(
|
||||
file='./assets/share/combat/team/TEAM_6_CHECK.png',
|
||||
area=(551, 29, 589, 56),
|
||||
search=(531, 9, 609, 76),
|
||||
color=(150, 144, 135),
|
||||
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(
|
||||
file='./assets/share/combat/team/TEAM_7_CHECK.png',
|
||||
area=(651, 29, 689, 56),
|
||||
search=(631, 9, 709, 76),
|
||||
color=(133, 126, 115),
|
||||
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(
|
||||
file='./assets/share/combat/team/TEAM_8_CHECK.png',
|
||||
area=(751, 29, 789, 56),
|
||||
search=(731, 9, 809, 76),
|
||||
color=(156, 145, 129),
|
||||
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(
|
||||
file='./assets/share/combat/team/TEAM_9_CHECK.png',
|
||||
area=(851, 29, 889, 56),
|
||||
search=(831, 9, 909, 76),
|
||||
color=(143, 134, 120),
|
||||
button=(851, 29, 889, 56),
|
||||
),
|
||||
)
|
||||
TEAM_9_CLICK = ButtonWrapper(
|
||||
name='TEAM_9_CLICK',
|
||||
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),
|
||||
),
|
||||
)
|
||||
TEAM_SEARCH = ButtonWrapper(
|
||||
name='TEAM_SEARCH',
|
||||
share=Button(
|
||||
file='./assets/share/combat/team/TEAM_SEARCH.png',
|
||||
area=(349, 12, 927, 72),
|
||||
search=(329, 0, 947, 92),
|
||||
color=(36, 40, 62),
|
||||
button=(349, 12, 927, 72),
|
||||
),
|
||||
)
|
||||
|
@ -1,48 +1,86 @@
|
||||
from module.base.button import ButtonWrapper
|
||||
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 (
|
||||
COMBAT_TEAM_PREPARE,
|
||||
TEAM_1,
|
||||
TEAM_2,
|
||||
TEAM_3,
|
||||
TEAM_4,
|
||||
TEAM_5,
|
||||
TEAM_6
|
||||
)
|
||||
from tasks.combat.assets.assets_combat_team import *
|
||||
|
||||
TEAM_BUTTONS = {
|
||||
1: TEAM_1,
|
||||
2: TEAM_2,
|
||||
3: TEAM_3,
|
||||
4: TEAM_4,
|
||||
5: TEAM_5,
|
||||
6: TEAM_6,
|
||||
}
|
||||
|
||||
def button_to_index(button: ButtonWrapper) -> int:
|
||||
res = re.search(r'(\d)', button.name)
|
||||
if res:
|
||||
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
|
||||
|
||||
|
||||
class CombatTeam(UI):
|
||||
@staticmethod
|
||||
def _team_index_to_button(index: int) -> ButtonWrapper:
|
||||
try:
|
||||
return TEAM_BUTTONS[index]
|
||||
except KeyError:
|
||||
logger.warning(f'Invalid team index: {index}, return team 1 instead')
|
||||
return TEAM_1
|
||||
def _get_team(self) -> tuple[list[int], int]:
|
||||
"""
|
||||
Returns:
|
||||
list[str]: List of displayed team index.
|
||||
int: Current team index, or None 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
|
||||
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))
|
||||
|
||||
def _get_team_selected(self) -> int:
|
||||
for index, button in TEAM_BUTTONS.items():
|
||||
if self.image_color_count(button, color=(255, 234, 191), threshold=221, count=50):
|
||||
return index
|
||||
def show(index):
|
||||
if index == current_team:
|
||||
return f'*0{index}*'
|
||||
else:
|
||||
return f'0{index}'
|
||||
|
||||
# logger.warning(f'No team selected')
|
||||
return 0
|
||||
# [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:
|
||||
"""
|
||||
Args:
|
||||
team: Team index, 1 to 6.
|
||||
team: Team index, 1 to 9.
|
||||
skip_first_screenshot:
|
||||
|
||||
Returns:
|
||||
@ -53,6 +91,7 @@ class CombatTeam(UI):
|
||||
"""
|
||||
logger.info(f'Team set: {team}')
|
||||
# Wait teams show up
|
||||
timeout = Timer(1, count=5).start()
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
@ -60,7 +99,10 @@ class CombatTeam(UI):
|
||||
self.device.screenshot()
|
||||
|
||||
# End
|
||||
current = self._get_team_selected()
|
||||
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')
|
||||
@ -69,7 +111,8 @@ class CombatTeam(UI):
|
||||
break
|
||||
|
||||
# Set team
|
||||
interval = Timer(2)
|
||||
click_interval = Timer(2)
|
||||
swipe_interval = Timer(2)
|
||||
skip_first_screenshot = True
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
@ -78,22 +121,39 @@ class CombatTeam(UI):
|
||||
self.device.screenshot()
|
||||
|
||||
# End
|
||||
current = self._get_team_selected()
|
||||
logger.attr('Team', current)
|
||||
list_team, current = self._get_team()
|
||||
if current and current == team:
|
||||
logger.info(f'Selected to the correct team')
|
||||
return True
|
||||
|
||||
# Click
|
||||
if interval.reached():
|
||||
self.device.click(self._team_index_to_button(team))
|
||||
interval.reset()
|
||||
if team in list_team:
|
||||
if click_interval.reached():
|
||||
self.device.click(index_to_button(team))
|
||||
click_interval.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()
|
||||
|
||||
def handle_combat_team_prepare(self, team: int = 1) -> bool:
|
||||
"""
|
||||
Set team and click prepare before dungeon combat.
|
||||
|
||||
Args:
|
||||
team: Team index, 1 to 9.
|
||||
|
||||
Returns:
|
||||
int: If clicked
|
||||
"""
|
||||
|