Skip to content

Commit

Permalink
Add: GemsFarming hard mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sui-feng-cb committed Jan 12, 2025
1 parent 3995010 commit 97bde6f
Show file tree
Hide file tree
Showing 15 changed files with 510 additions and 309 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/FLEET_DETAIL_ENTER_HARD_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/FLEET_DETAIL_ENTER_HARD_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/FLEET_ENTER_HARD_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/FLEET_ENTER_HARD_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/retire/DOCK_SHIP_DOWN.BUTTON.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/retire/DOCK_SHIP_DOWN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions config/gg_handler/gg_data_alas.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alas
gg_on=False
gg_enable=False
gg_auto=False
324 changes: 15 additions & 309 deletions module/campaign/gems_farming.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
from typing import Dict
from module.campaign.campaign_base import CampaignBase
from module.campaign.gems_shipchange import ShipChange, NormalShipChange, HardShipChange
from module.campaign.run import CampaignRun
from module.combat.assets import BATTLE_PREPARATION
from module.equipment.assets import *
from module.equipment.fleet_equipment import FleetEquipment
from module.exception import CampaignEnd, ScriptError
from module.exception import CampaignEnd
from module.handler.assets import AUTO_SEARCH_MAP_OPTION_OFF
from module.logger import logger
from module.map.assets import FLEET_PREPARATION, MAP_PREPARATION
from module.retire.assets import (
DOCK_CHECK,
TEMPLATE_BOGUE, TEMPLATE_HERMES, TEMPLATE_LANGLEY, TEMPLATE_RANGER,
TEMPLATE_CASSIN_1, TEMPLATE_CASSIN_2, TEMPLATE_DOWNES_1, TEMPLATE_DOWNES_2,
TEMPLATE_AULICK, TEMPLATE_FOOTE
)

from module.retire.dock import Dock
from module.retire.scanner import ShipScanner
from module.ui.assets import BACK_ARROW
from module.ui.page import page_fleet

SIM_VALUE = 0.92


class GemsCampaignOverride(CampaignBase):
Expand Down Expand Up @@ -67,7 +55,7 @@ def handle_combat_low_emotion(self):
raise CampaignEnd('Emotion withdraw')


class GemsFarming(CampaignRun, FleetEquipment, Dock):
class GemsFarming(CampaignRun):

def load_campaign(self, name, folder='campaign_main'):
super().load_campaign(name, folder)
Expand All @@ -83,300 +71,13 @@ class GemsCampaign(GemsCampaignOverride, self.module.Campaign):
def change_flagship(self):
return 'ship' in self.config.GemsFarming_ChangeFlagship

@property
def change_flagship_equip(self):
return 'equip' in self.config.GemsFarming_ChangeFlagship

@property
def change_vanguard(self):
return 'ship' in self.config.GemsFarming_ChangeVanguard

@property
def change_vanguard_equip(self):
return 'equip' in self.config.GemsFarming_ChangeVanguard

@property
def fleet_to_attack(self):
if self.config.Fleet_FleetOrder == 'fleet1_standby_fleet2_all':
return self.config.Fleet_Fleet2
else:
return self.config.Fleet_Fleet1

def flagship_change(self):
"""
Change flagship and flagship's equipment
If config.GemsFarming_CommonCV == 'any', only change auxiliary equipment
Returns:
bool: True if flagship changed.
"""

if self.config.GemsFarming_CommonCV == 'any':
index_list = range(3, 5)
else:
index_list = range(0, 5)
logger.hr('Change flagship', level=1)
logger.attr('ChangeFlagship', self.config.GemsFarming_ChangeFlagship)
self.fleet_enter(self.fleet_to_attack)
if self.change_flagship_equip:
logger.hr('Record flagship equipment', level=2)
self.fleet_enter_ship(FLEET_DETAIL_ENTER_FLAGSHIP)
self.ship_equipment_record_image(index_list=index_list)
self.ship_equipment_take_off()
self.fleet_back()

logger.hr('Change flagship', level=2)
success = self.flagship_change_execute()

if self.change_flagship_equip:
logger.hr('Equip flagship equipment', level=2)
self.fleet_enter_ship(FLEET_DETAIL_ENTER_FLAGSHIP)
self.ship_equipment_take_off()
self.ship_equipment_take_on_image(index_list=index_list)
self.fleet_back()

return success

def vanguard_change(self):
"""
Change vanguard and vanguard's equipment
Returns:
bool: True if vanguard changed
"""

logger.hr('Change vanguard', level=1)
logger.attr('ChangeVanguard', self.config.GemsFarming_ChangeVanguard)
self.fleet_enter(self.fleet_to_attack)
if self.change_vanguard_equip:
logger.hr('Record vanguard equipment', level=2)
self.fleet_enter_ship(FLEET_DETAIL_ENTER)
self.ship_equipment_record_image()
self.ship_equipment_take_off()
self.fleet_back()

logger.hr('Change vanguard', level=2)
success = self.vanguard_change_execute()

if self.change_vanguard_equip:
logger.hr('Equip vanguard equipment', level=2)
self.fleet_enter_ship(FLEET_DETAIL_ENTER)
self.ship_equipment_take_off()
self.ship_equipment_take_on_image()
self.fleet_back()

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()

def _ship_change_confirm(self, button):
self.dock_select_one(button)
self._dock_reset()
self.dock_select_confirm(check_button=page_fleet.check_button)

def get_common_rarity_cv(self):
"""
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')

scanner = ShipScanner(level=(1, 31), emotion=(10, 150),
fleet=self.fleet_to_attack, status='free')
scanner.disable('rarity')

if self.config.GemsFarming_CommonCV == 'any':

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)

else:
template = {
'BOGUE': TEMPLATE_BOGUE,
'HERMES': TEMPLATE_HERMES,
'LANGLEY': TEMPLATE_LANGLEY,
'RANGER': TEMPLATE_RANGER
}[f'{self.config.GemsFarming_CommonCV.upper()}']

ships = scanner.scan(self.device.image)
if ships:
# Don't need to change current
return ships

scanner.set_limitation(fleet=0)
candidates = [ship for ship in scanner.scan(self.device.image, output=False)
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(True)

candidates = [ship for ship in scanner.scan(self.device.image)
if template.match(self.image_crop(ship.button, copy=False), similarity=SIM_VALUE)]

return candidates

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']:
max_level = 100
else:
max_level = 70

scanner = ShipScanner(level=(max_level, max_level), emotion=(10, 150),
fleet=self.fleet_to_attack, status='free')
scanner.disable('rarity')

ships = scanner.scan(self.device.image)
if ships:
# Don't need to change current
return ships

scanner.set_limitation(fleet=0)
if self.config.GemsFarming_CommonDD in ['any', 'favourite', 'z20_or_z21']:
# Change to any ship
return scanner.scan(self.device.image, output=False)

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):
"""
Find candidates based on template matching using a scanner.
"""
candidates = []
for item in template:
candidates = [ship for ship in scanner.scan(self.device.image, output=False)
if item.match(self.image_crop(ship.button, copy=False), similarity=SIM_VALUE)]
if candidates:
break
return candidates

@staticmethod
def get_templates(common_dd):
"""
Returns the corresponding template list based on CommonDD
"""
if common_dd == 'aulick_or_foote':
return [
TEMPLATE_AULICK,
TEMPLATE_FOOTE
]
elif common_dd == 'cassin_or_downes':
return [
TEMPLATE_CASSIN_1, TEMPLATE_CASSIN_2,
TEMPLATE_DOWNES_1, TEMPLATE_DOWNES_2
]
else:
logger.error(f'Invalid CommonDD setting: {common_dd}')
raise ScriptError(f'Invalid CommonDD setting: {common_dd}')

def flagship_change_execute(self):
"""
Returns:
bool: If success.
Pages:
in: page_fleet
out: page_fleet
"""
self.ui_click(FLEET_ENTER_FLAGSHIP,
appear_button=page_fleet.check_button, check_button=DOCK_CHECK, skip_first_screenshot=True)

ship = self.get_common_rarity_cv()
if ship:
self._ship_change_confirm(min(ship, key=lambda s: (s.level, -s.emotion)).button)

logger.info('Change flagship success')
return True
else:
logger.info('Change flagship failed, no CV in common rarity.')
self._dock_reset()
self.ui_back(check_button=page_fleet.check_button)
return False

def vanguard_change_execute(self):
"""
Returns:
bool: If success.
Pages:
in: page_fleet
out: page_fleet
"""
self.ui_click(FLEET_ENTER,
appear_button=page_fleet.check_button, check_button=DOCK_CHECK, skip_first_screenshot=True)

ship = self.get_common_rarity_dd()
if ship:
self._ship_change_confirm(max(ship, key=lambda s: s.emotion).button)

logger.info('Change vanguard ship success')
return True
else:
logger.info('Change vanguard ship failed, no DD in common rarity.')
self._dock_reset()
self.ui_back(check_button=page_fleet.check_button)
return False
def ship_change_method(self):
return self.campaign.config.Campaign_Mode

_trigger_lv32 = False
_trigger_emotion = False
Expand Down Expand Up @@ -420,10 +121,15 @@ def run(self, name, folder='campaign_main', mode='normal', total=0):
# End
if self._trigger_lv32 or self._trigger_emotion:
success = True
self.ship_change: Dict[str, ShipChange] = {
'normal': NormalShipChange(config=self.config, device=self.device),
'hard': HardShipChange(config=self.config, device=self.device,
campaign=self.campaign, stage=self.stage)
}
if self.change_flagship:
success = self.flagship_change()
success = self.ship_change[self.ship_change_method].flagship_change()
if self.change_vanguard:
success = success and self.vanguard_change()
success = success and self.ship_change[self.ship_change_method].vanguard_change()

if is_limit and self.config.StopCondition_RunCount <= 0:
logger.hr('Triggered stop condition: Run count')
Expand All @@ -447,4 +153,4 @@ def run(self, name, folder='campaign_main', mode='normal', total=0):

continue
else:
break
break
Loading

0 comments on commit 97bde6f

Please sign in to comment.