Fix: Get SimUni points at double event

This commit is contained in:
LmeSzinc 2023-09-17 09:34:17 +08:00
parent 1f47d63af8
commit 0279a8dc4d
7 changed files with 66 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -28,6 +28,9 @@ class Button(Resource):
def button(self):
return area_offset(self._button, self._button_offset)
def load_offset(self, button):
self._button_offset = button._button_offset
def clear_offset(self):
self._button_offset = (0, 0)
@ -209,6 +212,22 @@ class ButtonWrapper(Resource):
def height(self) -> int:
return area_size(self.area)[1]
def load_offset(self, button):
"""
Load offset from another button.
Args:
button (Button, ButtonWrapper):
"""
if isinstance(button, ButtonWrapper):
button = button.matched_button
for b in self.buttons:
b.load_offset(button)
def clear_offset(self):
for b in self.buttons:
b.clear_offset()
class ClickButton:
def __init__(self, button, name='CLICK_BUTTON'):

View File

@ -117,10 +117,11 @@ class Ocr:
logger.attr(f'{self.name} {attr}', f'{before} -> {after}')
return after
def ocr_single_line(self, image):
def ocr_single_line(self, image, direct_ocr=False):
# pre process
start_time = time.time()
image = crop(image, self.button.area)
if not direct_ocr:
image = crop(image, self.button.area)
image = self.pre_process(image)
# ocr
result, _ = self.model.ocr_single_line(image)

View File

@ -63,6 +63,16 @@ OCR_SIMUNI_POINT = ButtonWrapper(
button=(580, 237, 820, 277),
),
)
OCR_SIMUNI_POINT_OFFSET = ButtonWrapper(
name='OCR_SIMUNI_POINT_OFFSET',
share=Button(
file='./assets/share/dungeon/ui/OCR_SIMUNI_POINT_OFFSET.png',
area=(685, 250, 717, 273),
search=(583, 187, 883, 387),
color=(199, 200, 250),
button=(685, 250, 717, 273),
),
)
OPERATION_BRIEFING_CHECK = ButtonWrapper(
name='OPERATION_BRIEFING_CHECK',
share=Button(

View File

@ -144,9 +144,6 @@ class Dungeon(DungeonUI, DungeonEvent, Combat):
with self.config.multi_set():
self.config.stored.DungeonDouble.calyx = calyx
self.config.stored.DungeonDouble.relic = relic
# Update SimulatedUniverse points
logger.info('Get simulated universe points')
self.dungeon_get_simuni_point()
# Run double events
ran_calyx_golden = False

View File

@ -75,7 +75,10 @@ class OcrDungeonList(Ocr):
class OcrSimUniPoint(DigitCounter):
merge_thres_x = 50
def after_process(self, result):
result = super().after_process(result)
result = result.replace('O', '0').replace('o', '0')
return result
class OcrDungeonListLimitEntrance(OcrDungeonList):
@ -228,15 +231,24 @@ class DungeonUI(UI):
Page:
in: page_guide, Survival_Index, Simulated_Universe
"""
logger.info('Get simulated universe points')
_ = self.appear(OCR_SIMUNI_POINT_OFFSET)
OCR_SIMUNI_POINT.load_offset(OCR_SIMUNI_POINT_OFFSET)
area = (
OCR_SIMUNI_POINT.area[0],
OCR_SIMUNI_POINT.button[1],
OCR_SIMUNI_POINT.area[2],
OCR_SIMUNI_POINT.button[3],
)
ocr = OcrSimUniPoint(OCR_SIMUNI_POINT)
value, _, total = ocr.ocr_single_line(self.device.image)
value, _, total = ocr.ocr_single_line(self.image_crop(area), direct_ocr=True)
if total and value <= total:
logger.attr('SimulatedUniverse', f'{value}/{total}')
self.config.stored.SimulatedUniverse.set(value, total)
return value
else:
logger.warning(f'Invalid SimulatedUniverse points: {value}/{total}')
self.config.stored.SimulatedUniverse.set(0, 0)
return 0
def _dungeon_nav_goto(self, dungeon: DungeonList, skip_first_screenshot=True):
@ -261,10 +273,28 @@ class DungeonUI(UI):
if DUNGEON_NAV_LIST.cur_buttons:
break
# Wait first row selected
timeout = Timer(0.5, count=2).start()
skip_first_screenshot = True
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if timeout.reached():
logger.info('DUNGEON_NAV_LIST not selected')
break
if button := DUNGEON_NAV_LIST.get_selected_row(main=self):
logger.info(f'DUNGEON_NAV_LIST selected at {button}')
break
# Check if it's at the first page.
if DUNGEON_NAV_LIST.keyword2button(KEYWORDS_DUNGEON_NAV.Simulated_Universe, show_warning=False):
if button := DUNGEON_NAV_LIST.keyword2button(KEYWORDS_DUNGEON_NAV.Simulated_Universe, show_warning=False):
# Going to use a faster method to navigate but can only start from list top
logger.info('DUNGEON_NAV_LIST at top')
# Update points if possible
if DUNGEON_NAV_LIST.is_row_selected(button, main=self):
self.dungeon_get_simuni_point()
else:
# To start from any list states.
logger.info('DUNGEON_NAV_LIST not at top')