def ensure_campaign_ui(self, name, mode='normal'): for n in range(20): try: self.campaign_set_chapter(name, mode) self.ENTRANCE = self.campaign_get_entrance(name=name) return True except CampaignNameError: continue logger.warning('Campaign name error') raise ScriptEnd('Campaign name error')
def handle_campaign_ui(self): for n in range(20): try: self.ensure_campaign_ui(name=self.stage, mode=self.config.CAMPAIGN_MODE) self.campaign.ENTRANCE = self.campaign_get_entrance(name=self.stage) return True except CampaignNameError: continue logger.warning('Campaign name error') raise ScriptEnd('Campaign name error')
def battle_default(self): while self.affinity_battle < self.config.C11_AFFINITY_BATTLE_COUNT: logger.attr( 'Affinity_battle', f'{self.affinity_battle}/{self.config.C11_AFFINITY_BATTLE_COUNT}' ) self.goto(C1) self.affinity_battle += 1 self.goto(D1 if np.random.uniform() < 0.7 else B1) # End try: self.withdraw() except CampaignEnd: raise ScriptEnd('Reach condition: Affinity farming battle count')
def check_reduce(self, battle): """ Check emotion before entering a campaign. Args: battle (int): Battles in this campaign Raise: ScriptEnd: Delay current task to prevent emotion control in the future. """ if not self.config.Emotion_CalculateEmotion: return method = self.config.Fleet_FleetOrder if method == 'fleet1_mob_fleet2_boss': battle = (battle - 1, 1) elif method == 'fleet1_boss_fleet2_mob': battle = (1, battle - 1) elif method == 'fleet1_all_fleet2_standby': battle = (battle, 0) elif method == 'fleet1_standby_fleet2_all': battle = (0, battle) else: raise ScriptError(f'Unknown fleet order: {method}') battle = tuple( np.array(battle) * self.reduce_per_battle_before_entering) logger.info(f'Expect emotion reduce: {battle}') self.update() self.record() self.show() recovered = max( [f.get_recovered(b) for f, b in zip(self.fleets, battle)]) if recovered > datetime.now(): logger.info( 'Delay current task to prevent emotion control in the future') self.config.task_delay(target=recovered) raise ScriptEnd('Emotion control')
def enter_map(self, button, mode='normal'): """Enter a campaign. Args: button: Campaign to enter. mode (str): 'normal' or 'hard' or 'cd' """ logger.hr('Enter map') campaign_timer = Timer(5) map_timer = Timer(5) fleet_timer = Timer(5) checked_in_map = False self.stage_entrance = button while 1: self.device.screenshot() if not checked_in_map and self.is_in_map(): logger.info('Already in map, skip enter_map.') return False else: checked_in_map = True # Map preparation if map_timer.reached() and self.handle_map_preparation(): self.map_get_info() self.handle_fast_forward() self.handle_auto_search() if self.triggered_map_stop(): self.enter_map_cancel() raise ScriptEnd( f'Reach condition: {self.config.STOP_IF_MAP_REACH}') self.device.click(MAP_PREPARATION) map_timer.reset() campaign_timer.reset() continue # Fleet preparation if fleet_timer.reached() and self.appear(FLEET_PREPARATION): if self.config.ENABLE_FLEET_CONTROL: if mode == 'normal' or mode == 'hard': self.fleet_preparation() self.handle_auto_search_setting() self.handle_auto_search_emotion_wait() self.device.click(FLEET_PREPARATION) fleet_timer.reset() campaign_timer.reset() continue # Auto search continue if self.handle_auto_search_continue(): campaign_timer.reset() continue # Retire if self.handle_retirement(): continue # Use Data Key if self.handle_use_data_key(): continue # Emotion if self.handle_combat_low_emotion(): continue # Urgent commission if self.handle_urgent_commission(): continue # Story skip if self.handle_story_skip(): campaign_timer.reset() continue # Enter campaign if campaign_timer.reached() and self.appear_then_click(button): campaign_timer.reset() continue # End if self.map_is_auto_search: if self.is_auto_search_running(): break else: if self.handle_in_map_with_enemy_searching(): self.handle_map_after_combat_story() break return True
def enter_map(self, button, mode='normal', skip_first_screenshot=True): """Enter a campaign. Args: button: Campaign to enter. mode (str): 'normal' or 'hard' or 'cd' skip_first_screenshot (bool): """ logger.hr('Enter map') campaign_timer = Timer(5) map_timer = Timer(5) fleet_timer = Timer(5) campaign_click = 0 map_click = 0 fleet_click = 0 checked_in_map = False self.stage_entrance = button with self.stat.new(genre=self.config.campaign_name, save=self.config.DropRecord_SaveCombat, upload=False) as drop: while 1: if skip_first_screenshot: skip_first_screenshot = False else: self.device.screenshot() # Check errors if campaign_click > 5: logger.critical( f"Failed to enter {button}, too many click on {button}" ) logger.critical( "Possible reason #1: You haven't reached the commander level to unlock this stage." ) raise RequestHumanTakeover if fleet_click > 5: logger.critical( f"Failed to enter {button}, too many click on FLEET_PREPARATION" ) logger.critical( "Possible reason #1: " "Your fleets haven't satisfied the stat restrictions of this stage." ) logger.critical( "Possible reason #2: " "This stage can only be farmed once a day, " "but it's the second time that you are entering") raise RequestHumanTakeover # Already in map if not checked_in_map and self.is_in_map(): logger.info('Already in map, skip enter_map.') return False else: checked_in_map = True # Map preparation if map_timer.reached() and self.handle_map_preparation(): self.map_get_info() self.handle_fast_forward() self.handle_auto_search() if self.triggered_map_stop(): self.enter_map_cancel() self.handle_map_stop() raise ScriptEnd( f'Reach condition: {self.config.StopCondition_MapAchievement}' ) self.device.click(MAP_PREPARATION) map_click += 1 map_timer.reset() campaign_timer.reset() continue # Fleet preparation if fleet_timer.reached() and self.appear(FLEET_PREPARATION, offset=(20, 20)): if mode == 'normal' or mode == 'hard': self.handle_2x_book_setting(mode='prep') self.fleet_preparation() self.handle_auto_submarine_call_disable() self.handle_auto_search_setting() self.map_fleet_checked = True self.device.click(FLEET_PREPARATION) fleet_click += 1 fleet_timer.reset() campaign_timer.reset() continue # Auto search continue if self.handle_auto_search_continue(): campaign_timer.reset() continue # Retire if self.handle_retirement(): campaign_timer.reset() map_timer.reset() fleet_timer.reset() continue # Use Data Key if self.handle_use_data_key(): continue # Emotion if self.handle_combat_low_emotion(): continue # Urgent commission if self.handle_urgent_commission(drop=drop): continue # Story skip if self.handle_story_skip(): campaign_timer.reset() continue # Enter campaign if campaign_timer.reached() and self.appear_then_click(button): campaign_click += 1 campaign_timer.reset() continue # End if self.map_is_auto_search: if self.is_auto_search_running(): break else: if self.handle_in_map_with_enemy_searching(): self.handle_map_after_combat_story() break return True
def enter_map(self, button, mode='normal'): """Enter a campaign. Args: button: Campaign to enter. mode (str): 'normal' or 'hard' or 'cd' """ logger.hr('Enter map') campaign_timer = Timer(2) map_timer = Timer(1) fleet_timer = Timer(1) checked_in_map = False while 1: self.device.screenshot() if not checked_in_map and self.is_in_map(): logger.info('Already in map, skip enter_map.') return False else: checked_in_map = True # Map preparation if map_timer.reached() and self.appear(MAP_PREPARATION): self.device.sleep(0.3) # Wait for map information. self.device.screenshot() if self.handle_map_clear_mode_stop(): self.enter_map_cancel() raise ScriptEnd( f'Reach condition: {self.config.CLEAR_MODE_STOP_CONDITION}' ) self.handle_fast_forward() self.device.click(MAP_PREPARATION) map_timer.reset() campaign_timer.reset() continue # Fleet preparation if fleet_timer.reached() and self.appear(FLEET_PREPARATION): if self.config.ENABLE_FLEET_CONTROL: if mode == 'normal' or mode == 'hard': self.fleet_preparation() self.device.click(FLEET_PREPARATION) fleet_timer.reset() campaign_timer.reset() continue # Retire if self.handle_retirement(): continue # Emotion if self.handle_combat_low_emotion(): continue # Urgent commission if self.handle_urgent_commission(): continue # Story skip if self.handle_story_skip(): campaign_timer.reset() continue # Enter campaign if campaign_timer.reached() and self.is_in_stage(): self.device.click(button) campaign_timer.reset() continue # End if self.handle_in_map_with_enemy_searching(): break return True