mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-07 07:07:15 +08:00
Opt: Combine dock filter operations to skip waiting dock loaded
This commit is contained in:
parent
3be9adc485
commit
4a2eb4470c
@ -168,12 +168,11 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
|
||||
return success
|
||||
|
||||
def _dock_reset(self):
|
||||
self.dock_favourite_set(False, wait_loading=False)
|
||||
self.dock_sort_method_dsc_set(wait_loading=False)
|
||||
self.dock_filter_set()
|
||||
self.dock_favourite_set(False)
|
||||
self.dock_sort_method_dsc_set()
|
||||
|
||||
def _ship_change_confirm(self, button):
|
||||
|
||||
self.dock_select_one(button)
|
||||
self._dock_reset()
|
||||
self.dock_select_confirm(check_button=page_fleet.check_button)
|
||||
@ -182,9 +181,16 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
|
||||
"""
|
||||
Get a common rarity cv by config.GemsFarming_CommonCV
|
||||
If config.GemsFarming_CommonCV == 'any', return a common lv1 ~ lv33 cv
|
||||
|
||||
_dock_reset() needs to be called later.
|
||||
|
||||
Returns:
|
||||
Ship:
|
||||
"""
|
||||
self.dock_favourite_set(False, wait_loading=False)
|
||||
self.dock_sort_method_dsc_set(False, wait_loading=False)
|
||||
self.dock_filter_set(
|
||||
index='cv', rarity='common', extra='enhanceable', sort='total')
|
||||
|
||||
logger.hr('FINDING FLAGSHIP')
|
||||
|
||||
@ -194,13 +200,12 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
|
||||
|
||||
if self.config.GemsFarming_CommonCV == 'any':
|
||||
|
||||
self.dock_sort_method_dsc_set(False)
|
||||
|
||||
ships = scanner.scan(self.device.image)
|
||||
if ships:
|
||||
# Don't need to change current
|
||||
return ships
|
||||
|
||||
# Change to any ship
|
||||
scanner.set_limitation(fleet=0)
|
||||
return scanner.scan(self.device.image, output=False)
|
||||
|
||||
@ -212,8 +217,6 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
|
||||
'RANGER': TEMPLATE_RANGER
|
||||
}[f'{self.config.GemsFarming_CommonCV.upper()}']
|
||||
|
||||
self.dock_sort_method_dsc_set()
|
||||
|
||||
ships = scanner.scan(self.device.image)
|
||||
if ships:
|
||||
# Don't need to change current
|
||||
@ -224,10 +227,11 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
|
||||
if template.match(self.image_crop(ship.button, copy=False), similarity=SIM_VALUE)]
|
||||
|
||||
if candidates:
|
||||
# Change to specific ship
|
||||
return candidates
|
||||
|
||||
logger.info('No specific CV was found, try reversed order.')
|
||||
self.dock_sort_method_dsc_set(False)
|
||||
self.dock_sort_method_dsc_set(True)
|
||||
|
||||
candidates = [ship for ship in scanner.scan(self.device.image)
|
||||
if template.match(self.image_crop(ship.button, copy=False), similarity=SIM_VALUE)]
|
||||
@ -237,9 +241,30 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
|
||||
def get_common_rarity_dd(self):
|
||||
"""
|
||||
Get a common rarity dd with level is 100 (70 for servers except CN) and emotion > 10
|
||||
|
||||
_dock_reset() needs to be called later.
|
||||
|
||||
Returns:
|
||||
Ship:
|
||||
"""
|
||||
if self.config.GemsFarming_CommonDD == 'any':
|
||||
faction = ['eagle', 'iron']
|
||||
elif self.config.GemsFarming_CommonDD == 'favourite':
|
||||
faction = 'all'
|
||||
elif self.config.GemsFarming_CommonDD == 'z20_or_z21':
|
||||
faction = 'iron'
|
||||
elif self.config.GemsFarming_CommonDD in ['aulick_or_foote', 'cassin_or_downes']:
|
||||
faction = 'eagle'
|
||||
else:
|
||||
logger.error(f'Invalid CommonDD setting: {self.config.GemsFarming_CommonDD}')
|
||||
raise ScriptError('Invalid GemsFarming_CommonDD')
|
||||
|
||||
favourite = self.config.GemsFarming_CommonDD == 'favourite'
|
||||
self.dock_favourite_set(favourite, wait_loading=False)
|
||||
self.dock_sort_method_dsc_set(True, wait_loading=False)
|
||||
self.dock_filter_set(
|
||||
index='dd', rarity='common', faction=faction, extra='can_limit_break')
|
||||
|
||||
logger.hr('FINDING VANGUARD')
|
||||
|
||||
if self.config.SERVER in ['cn']:
|
||||
@ -251,29 +276,26 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
|
||||
fleet=self.fleet_to_attack, status='free')
|
||||
scanner.disable('rarity')
|
||||
|
||||
self.dock_sort_method_dsc_set()
|
||||
|
||||
ships = scanner.scan(self.device.image)
|
||||
if ships:
|
||||
# Don't need to change current
|
||||
return ships
|
||||
|
||||
scanner.set_limitation(fleet=0)
|
||||
self.dock_favourite_set(self.config.GemsFarming_CommonDD == 'favourite')
|
||||
|
||||
if self.config.GemsFarming_CommonDD in ['any', 'favourite', 'z20_or_z21']:
|
||||
if self.config.GemsFarming_CommonDD in ['any', 'favourite']:
|
||||
# Change to any ship
|
||||
return scanner.scan(self.device.image, output=False)
|
||||
|
||||
candidates = self.find_candidates(self.get_templates(self.config.GemsFarming_CommonDD), scanner)
|
||||
|
||||
candidates = self.find_candidates(self.get_templates(self.config.GemsFarming_CommonDD), scanner)
|
||||
if candidates:
|
||||
# Change to specific ship
|
||||
return candidates
|
||||
|
||||
|
||||
logger.info('No specific DD was found, try reversed order.')
|
||||
self.dock_sort_method_dsc_set(False)
|
||||
|
||||
# Change specific ship
|
||||
candidates = self.find_candidates(self.get_templates(self.config.GemsFarming_CommonDD), scanner)
|
||||
|
||||
return candidates
|
||||
|
||||
def find_candidates(self, template, scanner):
|
||||
@ -319,9 +341,6 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
|
||||
"""
|
||||
self.ui_click(FLEET_ENTER_FLAGSHIP,
|
||||
appear_button=page_fleet.check_button, check_button=DOCK_CHECK, skip_first_screenshot=True)
|
||||
self.dock_filter_set(
|
||||
index='cv', rarity='common', extra='enhanceable', sort='total')
|
||||
self.dock_favourite_set(False)
|
||||
|
||||
ship = self.get_common_rarity_cv()
|
||||
if ship:
|
||||
@ -347,21 +366,6 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
|
||||
self.ui_click(FLEET_ENTER,
|
||||
appear_button=page_fleet.check_button, check_button=DOCK_CHECK, skip_first_screenshot=True)
|
||||
|
||||
if self.config.GemsFarming_CommonDD == 'any':
|
||||
faction = ['eagle', 'iron']
|
||||
elif self.config.GemsFarming_CommonDD == 'favourite':
|
||||
faction = 'all'
|
||||
elif self.config.GemsFarming_CommonDD == 'z20_or_z21':
|
||||
faction = 'iron'
|
||||
elif self.config.GemsFarming_CommonDD in ['aulick_or_foote', 'cassin_or_downes']:
|
||||
faction = 'eagle'
|
||||
else:
|
||||
logger.error(f'Invalid CommonDD setting: {self.config.GemsFarming_CommonDD}')
|
||||
raise ScriptError('Invalid GemsFarming_CommonDD')
|
||||
self.dock_filter_set(
|
||||
index='dd', rarity='common', faction=faction, extra='can_limit_break')
|
||||
self.dock_favourite_set(False)
|
||||
|
||||
ship = self.get_common_rarity_dd()
|
||||
if ship:
|
||||
self._ship_change_confirm(max(ship, key=lambda s: s.emotion).button)
|
||||
|
@ -40,9 +40,15 @@ class Dock(Equipment):
|
||||
self.device.sleep((1, 1.5))
|
||||
self.device.screenshot()
|
||||
|
||||
def dock_favourite_set(self, enable=False):
|
||||
def dock_favourite_set(self, enable=False, wait_loading=True):
|
||||
"""
|
||||
Args:
|
||||
enable: True to filter favourite ships only
|
||||
wait_loading: Default to True, use False on continuous operation
|
||||
"""
|
||||
if DOCK_FAVOURITE.set('on' if enable else 'off', main=self):
|
||||
self.handle_dock_cards_loading()
|
||||
if wait_loading:
|
||||
self.handle_dock_cards_loading()
|
||||
|
||||
def _dock_quit_check_func(self):
|
||||
return not self.appear(DOCK_CHECK, offset=(20, 20))
|
||||
@ -50,15 +56,25 @@ class Dock(Equipment):
|
||||
def dock_quit(self):
|
||||
self.ui_back(check_button=self._dock_quit_check_func, skip_first_screenshot=True)
|
||||
|
||||
def dock_sort_method_dsc_set(self, enable=True):
|
||||
def dock_sort_method_dsc_set(self, enable=True, wait_loading=True):
|
||||
"""
|
||||
Args:
|
||||
enable: True to set descending sorting
|
||||
wait_loading: Default to True, use False on continuous operation
|
||||
"""
|
||||
if DOCK_SORTING.set('Descending' if enable else 'Ascending', main=self):
|
||||
self.handle_dock_cards_loading()
|
||||
if wait_loading:
|
||||
self.handle_dock_cards_loading()
|
||||
|
||||
def dock_filter_enter(self):
|
||||
self.ui_click(DOCK_FILTER, appear_button=DOCK_CHECK, check_button=DOCK_FILTER_CONFIRM,
|
||||
skip_first_screenshot=True)
|
||||
|
||||
def dock_filter_confirm(self, wait_loading=True):
|
||||
"""
|
||||
Args:
|
||||
wait_loading: Default to True, use False on continuous operation
|
||||
"""
|
||||
self.ui_click(DOCK_FILTER_CONFIRM, check_button=DOCK_CHECK, skip_first_screenshot=True)
|
||||
if wait_loading:
|
||||
self.handle_dock_cards_loading()
|
||||
|
@ -43,7 +43,7 @@ class Enhancement(Dock):
|
||||
available to be picked.
|
||||
"""
|
||||
if favourite:
|
||||
self.dock_favourite_set(enable=True)
|
||||
self.dock_favourite_set(enable=True, wait_loading=False)
|
||||
|
||||
if ship_type is not None:
|
||||
ship_type = str(ship_type)
|
||||
@ -65,7 +65,7 @@ class Enhancement(Dock):
|
||||
out: page_dock
|
||||
"""
|
||||
self.ui_back(DOCK_CHECK)
|
||||
self.dock_favourite_set(enable=False)
|
||||
self.dock_favourite_set(enable=False, wait_loading=False)
|
||||
self.dock_filter_set()
|
||||
|
||||
def _enhance_confirm(self, skip_first_screenshot=True):
|
||||
|
@ -175,7 +175,8 @@ class Retirement(Enhancement, QuickRetireSettingHandler):
|
||||
def retire_ships_one_click(self):
|
||||
logger.hr('Retirement')
|
||||
logger.info('Using one click retirement.')
|
||||
self.dock_favourite_set(False)
|
||||
# No need to wait, one-click-retire doesn't need to check dock
|
||||
self.dock_favourite_set(False, wait_loading=False)
|
||||
end = False
|
||||
total = 0
|
||||
|
||||
@ -185,6 +186,7 @@ class Retirement(Enhancement, QuickRetireSettingHandler):
|
||||
while 1:
|
||||
self.handle_info_bar()
|
||||
|
||||
# ONE_CLICK_RETIREMENT -> SHIP_CONFIRM_2 or info_bar_count
|
||||
skip_first_screenshot = True
|
||||
click_count = 0
|
||||
while 1:
|
||||
@ -212,8 +214,10 @@ class Retirement(Enhancement, QuickRetireSettingHandler):
|
||||
click_count += 1
|
||||
continue
|
||||
|
||||
# info_bar_count
|
||||
if end:
|
||||
break
|
||||
# SHIP_CONFIRM_2 -> IN_RETIREMENT_CHECK
|
||||
self._retirement_confirm()
|
||||
total += 10
|
||||
# if total >= amount:
|
||||
@ -248,10 +252,11 @@ class Retirement(Enhancement, QuickRetireSettingHandler):
|
||||
'SSR': 'super_rare'
|
||||
}
|
||||
_rarity = [correspond_name[i] for i in rarity]
|
||||
self.dock_filter_set(sort='level', index='all',
|
||||
faction='all', rarity=_rarity, extra='no_limit')
|
||||
self.dock_sort_method_dsc_set(False)
|
||||
self.dock_favourite_set(False)
|
||||
self.dock_sort_method_dsc_set(False, wait_loading=False)
|
||||
self.dock_favourite_set(False, wait_loading=False)
|
||||
self.dock_filter_set(
|
||||
sort='level', index='all', faction='all', rarity=_rarity, extra='no_limit')
|
||||
|
||||
total = 0
|
||||
|
||||
if self.retire_keep_common_cv:
|
||||
@ -277,7 +282,7 @@ class Retirement(Enhancement, QuickRetireSettingHandler):
|
||||
self.handle_dock_cards_loading()
|
||||
continue
|
||||
|
||||
self.dock_sort_method_dsc_set(True)
|
||||
self.dock_sort_method_dsc_set(True, wait_loading=False)
|
||||
self.dock_filter_set()
|
||||
logger.info(f'Total retired: {total}')
|
||||
return total
|
||||
@ -295,8 +300,8 @@ class Retirement(Enhancement, QuickRetireSettingHandler):
|
||||
logger.info('Not in GemsFarming, skip')
|
||||
return 0
|
||||
|
||||
self.dock_favourite_set(False, wait_loading=False)
|
||||
self.dock_filter_set(index='cv', rarity='common', extra='not_level_max', sort='level')
|
||||
self.dock_favourite_set(False)
|
||||
|
||||
scanner = ShipScanner(
|
||||
rarity='common', fleet=0, status='free', level=(2, 100))
|
||||
@ -334,6 +339,7 @@ class Retirement(Enhancement, QuickRetireSettingHandler):
|
||||
self._retirement_confirm()
|
||||
|
||||
self._have_kept_cv = _
|
||||
# No need to wait, retire finished, just about to exit
|
||||
self.dock_filter_set(wait_loading=False)
|
||||
|
||||
return total
|
||||
@ -410,8 +416,8 @@ class Retirement(Enhancement, QuickRetireSettingHandler):
|
||||
if not total:
|
||||
logger.warning(
|
||||
'No ship retired, trying to reset dock filter and disable favourite, then retire again')
|
||||
self.dock_favourite_set(False, wait_loading=False)
|
||||
self.dock_filter_set()
|
||||
self.dock_favourite_set(False)
|
||||
total = self.retire_ships_one_click()
|
||||
if self.server_support_quick_retire_setting_fallback():
|
||||
# Some users may have already set filter_5='all', try with it first
|
||||
|
@ -606,12 +606,12 @@ class RewardTacticalClass(Dock):
|
||||
def select_suitable_ship(self):
|
||||
logger.hr(f'Select suitable ship')
|
||||
|
||||
# Set if favorite from config
|
||||
self.dock_favourite_set(enable=self.config.AddNewStudent_Favorite, wait_loading=False)
|
||||
|
||||
# reset filter
|
||||
self.dock_filter_set()
|
||||
|
||||
# Set if favorite from config
|
||||
self.dock_favourite_set(enable=self.config.AddNewStudent_Favorite)
|
||||
|
||||
# No ship in dock
|
||||
if self.appear(DOCK_EMPTY, offset=(30, 30)):
|
||||
logger.info('Dock is empty or favorite ships is empty')
|
||||
|
Loading…
Reference in New Issue
Block a user