Refactor: forgotten_hall.team as standalone file

This commit is contained in:
LmeSzinc 2023-09-22 23:00:10 +08:00
parent 920537a3de
commit 85fbaae4ac
19 changed files with 85 additions and 53 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 97 KiB

View File

Before

Width:  |  Height:  |  Size: 250 KiB

After

Width:  |  Height:  |  Size: 250 KiB

View File

@ -56,7 +56,7 @@ class UseTechniqueUI(MapControlJoystick, ForgottenHallUI):
logger.hr('Use techniques', level=2)
self.stage_goto(KEYWORDS_DUNGEON_LIST.The_Last_Vestiges_of_Towering_Citadel,
KEYWORDS_FORGOTTEN_HALL_STAGE.Stage_1)
self._choose_first_character()
self.team_choose_first()
self._enter_forgotten_hall_dungeon()
self._use_technique(count, skip_first_screenshot=skip_first_screenshot)
self.exit_dungeon()

View File

@ -6,7 +6,7 @@ from module.base.button import Button, ButtonWrapper
DUNGEON_ENTER_CHECKED = ButtonWrapper(
name='DUNGEON_ENTER_CHECKED',
share=Button(
file='./assets/share/forgotten_hall/DUNGEON_ENTER_CHECKED.png',
file='./assets/share/forgotten_hall/ui/DUNGEON_ENTER_CHECKED.png',
area=(29, 242, 43, 251),
search=(9, 222, 63, 271),
color=(173, 173, 173),
@ -16,7 +16,7 @@ DUNGEON_ENTER_CHECKED = ButtonWrapper(
EFFECT_NOTIFICATION = ButtonWrapper(
name='EFFECT_NOTIFICATION',
share=Button(
file='./assets/share/forgotten_hall/EFFECT_NOTIFICATION.png',
file='./assets/share/forgotten_hall/ui/EFFECT_NOTIFICATION.png',
area=(237, 302, 315, 380),
search=(217, 282, 335, 400),
color=(128, 114, 85),
@ -26,7 +26,7 @@ EFFECT_NOTIFICATION = ButtonWrapper(
ENTER_FORGOTTEN_HALL_DUNGEON = ButtonWrapper(
name='ENTER_FORGOTTEN_HALL_DUNGEON',
share=Button(
file='./assets/share/forgotten_hall/ENTER_FORGOTTEN_HALL_DUNGEON.png',
file='./assets/share/forgotten_hall/ui/ENTER_FORGOTTEN_HALL_DUNGEON.png',
area=(989, 649, 1231, 684),
search=(969, 629, 1251, 704),
color=(214, 214, 217),
@ -36,37 +36,17 @@ ENTER_FORGOTTEN_HALL_DUNGEON = ButtonWrapper(
ENTRANCE_CHECKED = ButtonWrapper(
name='ENTRANCE_CHECKED',
share=Button(
file='./assets/share/forgotten_hall/ENTRANCE_CHECKED.png',
file='./assets/share/forgotten_hall/ui/ENTRANCE_CHECKED.png',
area=(55, 632, 71, 650),
search=(35, 612, 91, 670),
color=(156, 156, 157),
button=(55, 632, 71, 650),
),
)
FIRST_CHARACTER = ButtonWrapper(
name='FIRST_CHARACTER',
share=Button(
file='./assets/share/forgotten_hall/FIRST_CHARACTER.png',
area=(54, 100, 150, 212),
search=(34, 80, 170, 232),
color=(145, 125, 103),
button=(54, 100, 150, 212),
),
)
LAST_VERTIGES = ButtonWrapper(
name='LAST_VERTIGES',
share=Button(
file='./assets/share/forgotten_hall/LAST_VERTIGES.png',
area=(1163, 105, 1203, 125),
search=(1143, 85, 1223, 145),
color=(221, 185, 225),
button=(1163, 105, 1203, 125),
),
)
OCR_STAGE = ButtonWrapper(
name='OCR_STAGE',
share=Button(
file='./assets/share/forgotten_hall/OCR_STAGE.png',
file='./assets/share/forgotten_hall/ui/OCR_STAGE.png',
area=(0, 281, 1280, 581),
search=(0, 261, 1280, 601),
color=(29, 48, 92),

View File

@ -0,0 +1,74 @@
import cv2
import numpy as np
from module.base.utils import color_similarity_2d, get_color
from module.logger import logger
from tasks.base.ui import UI
from tasks.forgotten_hall.assets.assets_forgotten_hall_team import *
from tasks.forgotten_hall.assets.assets_forgotten_hall_ui import ENTER_FORGOTTEN_HALL_DUNGEON, ENTRANCE_CHECKED
class ForgottenHallTeam(UI):
def team_prepared(self):
# White button, with a color of (214, 214, 214)
color = get_color(self.device.image, ENTER_FORGOTTEN_HALL_DUNGEON.area)
return np.mean(color) > 180
def team_choose_first(self, skip_first_screenshot=True):
"""
A temporary method used to choose the first character only
"""
logger.info('Team choose first')
self.interval_clear(ENTRANCE_CHECKED)
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if self.team_prepared():
logger.info("First character is chosen")
break
if self.appear(ENTRANCE_CHECKED, interval=2):
self.device.click(CHARACTER_1)
continue
def is_character_chosen(self, button: ButtonWrapper) -> bool:
image = color_similarity_2d(self.image_crop(button), color=(255, 255, 255))
color = cv2.mean(image)[0]
# print(button, color)
# Chosen:
# CHARACTER_1 210.0230034722222
# CHARACTER_2 210.12022569444443
# CHARACTER_3 211.09244791666666
# CHARACTER_4 210.48046875
# Not chosen
# CHARACTER_1 122.38671875
# CHARACTER_2 124.72960069444444
# CHARACTER_3 136.55989583333331
# CHARACTER_4 129.76432291666666
return color > 180
def team_choose_first_4(self, skip_first_screenshot=True):
"""
Choose the first 4 characters in list.
"""
logger.info('Team choose first 4')
self.interval_clear(ENTRANCE_CHECKED)
characters = [CHARACTER_1, CHARACTER_2, CHARACTER_3, CHARACTER_4]
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
chosen_list = [self.is_character_chosen(c) for c in characters]
if all(chosen_list):
logger.info("First 4 characters are chosen")
break
if self.appear(ENTRANCE_CHECKED, interval=2):
for character, chosen in zip(characters, chosen_list):
if not chosen:
self.device.click(character)
# Casual sleep, game may not respond that fast
self.device.sleep((0.1, 0.2))

View File

@ -4,7 +4,7 @@ from pponnxcr.predict_system import BoxedResult
from module.base.base import ModuleBase
from module.base.timer import Timer
from module.base.utils import area_offset, color_similarity_2d, crop, get_color
from module.base.utils import area_offset, color_similarity_2d, crop
from module.logger.logger import logger
from module.ocr.keyword import Keyword
from module.ocr.ocr import Ocr, OcrResultButton
@ -12,8 +12,9 @@ from module.ui.draggable_list import DraggableList
from tasks.base.assets.assets_base_page import FORGOTTEN_HALL_CHECK, MAP_EXIT
from tasks.dungeon.keywords import DungeonList, KEYWORDS_DUNGEON_TAB
from tasks.dungeon.ui import DungeonUI
from tasks.forgotten_hall.assets.assets_forgotten_hall import *
from tasks.forgotten_hall.assets.assets_forgotten_hall_ui import *
from tasks.forgotten_hall.keywords import ForgottenHallStage
from tasks.forgotten_hall.team import ForgottenHallTeam
from tasks.map.control.joystick import MapControlJoystick
@ -103,7 +104,7 @@ STAGE_LIST = DraggableStageList("ForgottenHallStageList", keyword_class=Forgotte
check_row_order=False, drag_direction="right")
class ForgottenHallUI(DungeonUI):
class ForgottenHallUI(DungeonUI, ForgottenHallTeam):
def stage_goto(self, forgotten_hall: DungeonList, stage_keyword: ForgottenHallStage):
"""
Examples:
@ -141,29 +142,6 @@ class ForgottenHallUI(DungeonUI):
if self.handle_popup_confirm():
continue
def _choose_first_character(self, skip_first_screenshot=True):
"""
A temporary method used to choose the first character only
"""
interval = Timer(1)
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if self._forgotten_hall_enter_appear():
logger.info("First character is chosen")
break
if interval.reached():
self.device.click(FIRST_CHARACTER)
interval.reset()
def _forgotten_hall_enter_appear(self):
# White button, with a color of (214, 214, 214)
color = get_color(self.device.image, ENTER_FORGOTTEN_HALL_DUNGEON.area)
return np.mean(color) > 180
def _enter_forgotten_hall_dungeon(self, skip_first_screenshot=True):
"""
called after team is set
@ -185,7 +163,7 @@ class ForgottenHallUI(DungeonUI):
else:
timeout.reset()
if interval.reached() and self._forgotten_hall_enter_appear():
if interval.reached() and self.team_prepared():
self.device.click(ENTER_FORGOTTEN_HALL_DUNGEON)
interval.reset()