diff --git a/module/handler/auto_search.py b/module/handler/auto_search.py index e62f46f32..5e16c185e 100644 --- a/module/handler/auto_search.py +++ b/module/handler/auto_search.py @@ -2,6 +2,7 @@ import numpy as np from module.base.button import ButtonGrid from module.base.decorator import Config +from module.base.timer import Timer from module.handler.assets import * from module.handler.enemy_searching import EnemySearchingHandler from module.logger import logger @@ -49,21 +50,14 @@ class AutoSearchHandler(EnemySearchingHandler): origin=(1185, 155 + offset), delta=(0, 111), button_shape=(53, 104), grid_shape=(1, 3), name='FLEET_SIDEBAR') - def _fleet_preparation_sidebar_click(self, index): + def _fleet_preparation_get(self): """ - Args: - index (int): + Returns: + int: 1 for formation 2 for meowfficers 3 for auto search setting - - Returns: - bool: If changed. """ - if index <= 0 or index > 3: - logger.warning(f'Sidebar index cannot be clicked, {index}, limit to 1 through 5 only') - return False - current = 0 total = 0 sidebar = self._fleet_sidebar() @@ -81,46 +75,38 @@ class AutoSearchHandler(EnemySearchingHandler): if not current: logger.warning('No fleet sidebar active.') logger.attr('Fleet_sidebar', f'{current}/{total}') - if current == index: - return False + return current - self.device.click(sidebar[0, index - 1]) - return True - - def fleet_preparation_sidebar_ensure(self, index, skip_first_screenshot=True): + def fleet_preparation_sidebar_ensure(self, index): """ Args: index (int): 1 for formation 2 for meowfficers 3 for auto search setting - skip_first_screenshot (bool): - Returns: - bool: whether sidebar could be ensured - at most 3 attempts are made before - return False otherwise True + Returns: + bool: whether sidebar could be ensured + at most 3 attempts are made before + return False otherwise True """ if index <= 0 or index > 5: logger.warning(f'Sidebar index cannot be ensured, {index}, limit 1 through 5 only') return False - counter = 0 - while 1: - if skip_first_screenshot: - skip_first_screenshot = False - else: - self.device.screenshot() - - if self._fleet_preparation_sidebar_click(index): - if counter >= 2: - logger.warning('Sidebar could not be ensured') - return False - counter += 1 - self.device.sleep((0.3, 0.5)) - continue - else: + interval = Timer(1, count=2) + sidebar = self._fleet_sidebar() + for _ in self.loop(timeout=3): + current = self._fleet_preparation_get() + if current == index: return True + if interval.reached(): + self.device.click(sidebar[0, index - 1]) + interval.reset() + continue + else: + logger.warning('Sidebar could not be ensured') + return False def _auto_search_set_click(self, setting): """ diff --git a/module/minigame/minigame.py b/module/minigame/minigame.py index 6537dc1de..7af152045 100644 --- a/module/minigame/minigame.py +++ b/module/minigame/minigame.py @@ -3,8 +3,8 @@ from module.combat.assets import GET_ITEMS_1 from module.logger import logger from module.minigame.assets import * from module.ocr.ocr import Digit -from module.ui.assets import GAME_ROOM_CHECK -from module.ui.page import page_game_room +from module.ui.assets import ACADEMY_GOTO_GAME_ROOM, GAME_ROOM_CHECK +from module.ui.page import page_academy, page_game_room from module.ui.scroll import Scroll from module.ui.ui import UI @@ -131,6 +131,7 @@ class Minigame(UI): in: page_game_room main_page/choose_game_page out: page_game_room main_page """ + logger.info('minigame go_to_main_page') while 1: if skip_first_screenshot: skip_first_screenshot = False @@ -183,8 +184,19 @@ class Minigame(UI): in: Any page out: page_game_room """ + # TEMP: 2026.02.18 separate self.ui_ensure(page_game_room) into 2 steps + # EN has different page_academy detection, to use ui_ensure(page_game_room), + # ui_goto must use `if self.ui_page_appear(page)` instead of `if self.appear(page.check_button)` + # But that would cause page_main/page_main_white clicking a static switch button + self.ui_ensure(page_academy) + # page_academy -> page_game_room + for _ in self.loop(): + if self.ui_page_appear(page_game_room): + break + if self.ui_page_appear(page_academy, interval=5): + self.device.click(ACADEMY_GOTO_GAME_ROOM) + continue - self.ui_ensure(page_game_room) # game room and choose game have same header, go to game room first self.go_to_main_page() coin_collected = False diff --git a/module/os/map_operation.py b/module/os/map_operation.py index 64104acd6..103a28c4b 100644 --- a/module/os/map_operation.py +++ b/module/os/map_operation.py @@ -57,7 +57,7 @@ class OSMapOperation(MapOrderHandler, MissionHandler, PortHandler, StorageHandle name = ocr.ocr(self.device.image) name = "".join(name.split()) name = name.lower() - name = name.strip('\\/-') + name = name.strip('\\/-—–-') if '-' in name: name = name.split('-')[0] if 'é' in name: # Méditerranée name maps @@ -90,7 +90,7 @@ class OSMapOperation(MapOrderHandler, MissionHandler, PortHandler, StorageHandle # For JP only ocr = Ocr(MAP_NAME, lang='jp', letter=(157, 173, 192), threshold=127, name='OCR_OS_MAP_NAME') name = ocr.ocr(self.device.image) - name = name.strip('\\/-') + name = name.strip('\\/-—–-') self.is_zone_name_hidden = '安全' in name # Remove punctuations for char in '・': @@ -119,7 +119,7 @@ class OSMapOperation(MapOrderHandler, MissionHandler, PortHandler, StorageHandle # For TW only ocr = Ocr(MAP_NAME, lang='tw', letter=(198, 215, 239), threshold=127, name='OCR_OS_MAP_NAME') name = ocr.ocr(self.device.image) - name = name.strip('\\/-') + name = name.strip('\\/-—–-') self.is_zone_name_hidden = '安全' in name # Remove '塞壬要塞海域' if '塞' in name: @@ -133,7 +133,7 @@ class OSMapOperation(MapOrderHandler, MissionHandler, PortHandler, StorageHandle # For CN only ocr = Ocr(MAP_NAME, lang='cnocr', letter=(214, 231, 255), threshold=127, name='OCR_OS_MAP_NAME') name = ocr.ocr(self.device.image) - name = name.strip('\\/-') + name = name.strip('\\/-—–-') self.is_zone_name_hidden = '安全' in name if '-' in name: name = name.split('-')[0] diff --git a/module/raid/raid.py b/module/raid/raid.py index 5218895f7..401c3ccac 100644 --- a/module/raid/raid.py +++ b/module/raid/raid.py @@ -15,6 +15,15 @@ from module.ui.assets import BACK_ARROW, RAID_CHECK from module.ui.page import page_rpg_stage +class RaidCounterPostMixin(DigitCounter): + def after_process(self, result): + # fix result like "915/", "1515" + result = result.strip('/') + if result.isdigit() and len(result) > 2 and result.endswith('15'): + result = f'{result[:-2]}/15' + return result + + class RaidCounter(DigitCounter): def pre_process(self, image): image = super().pre_process(image) @@ -165,7 +174,7 @@ def raid_ocr(raid, mode): if mode == 'ex': return Digit(button, letter=(255, 239, 215), threshold=128) else: - return DigitCounter(button, lang='cnocr', letter=(154, 148, 133), threshold=128) + return RaidCounterPostMixin(button, lang='cnocr', letter=(154, 148, 133), threshold=128) def pt_ocr(raid): diff --git a/module/raid/run.py b/module/raid/run.py index 2149b9891..d9a26050b 100644 --- a/module/raid/run.py +++ b/module/raid/run.py @@ -95,7 +95,7 @@ class RaidRun(Raid, CampaignEvent): # UI switches if not self._raid_has_oil_icon: - self.ui_goto(page_campaign_menu) + self.ui_ensure(page_campaign_menu) if self.triggered_stop_condition(oil_check=True, coin_check=True): break diff --git a/module/storage/storage.py b/module/storage/storage.py index a18423c6a..62be757ff 100644 --- a/module/storage/storage.py +++ b/module/storage/storage.py @@ -45,8 +45,12 @@ class StorageHandler(StorageUI): def _handle_use_box_amount(self, amount): """ + Args: + amount (int): Expected amount to set + Returns: - bool: if clicked + int: Actual amount set in the UI. + May be less than expected if not enough boxes available. Pages: in: SHOP_BUY_CONFIRM_AMOUNT @@ -84,6 +88,7 @@ class StorageHandler(StorageUI): logger.info(f'Set box amount: {amount}') skip_first = True retry = Timer(1, count=2) + click_count = 0 for _ in self.loop(): if skip_first: skip_first = False @@ -92,13 +97,19 @@ class StorageHandler(StorageUI): diff = amount - current if diff == 0: break + if click_count >= 2: + logger.warning(f'Box amount stuck at {current}, ' + f'requested {amount} but only {current} available') + break if retry.reached(): button = AMOUNT_PLUS if diff > 0 else AMOUNT_MINUS self.device.multi_click(button, n=abs(diff), interval=(0.1, 0.2)) + click_count += 1 retry.reset() - return True + logger.info(f'Box amount set to {current}') + return current def _storage_use_one_box(self, button, amount=1): """ @@ -155,10 +166,10 @@ class StorageHandler(StorageUI): # use match_template_color on BOX_AMOUNT_CONFIRM # a long animation that opens a box, will be on the top of BOX_AMOUNT_CONFIRM if self.match_template_color(BOX_AMOUNT_CONFIRM, offset=(20, 20), interval=5): - self._handle_use_box_amount(amount) + actual = self._handle_use_box_amount(amount) self.device.click(BOX_AMOUNT_CONFIRM) self.interval_reset(BOX_AMOUNT_CONFIRM) - used = amount + used = actual continue if self.appear_then_click(EQUIP_CONFIRM, offset=(20, 20), interval=5): self.interval_reset(MATERIAL_CHECK)