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