def start_stage(self, stage_button, stage_num, farm_shifter_bios=False): """Starts Epic Quests stage. :param ui.UIElement stage_button: rect of button to start stage. :param int stage_num: available stages count. :param bool farm_shifter_bios: should game be restarted if shifter isn't appeared. """ if not wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.START_BUTTON): self.emulator.click_button(stage_button) wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.START_BUTTON) if not self.press_start_button(): logger.error( f"Cannot start Epic Quest stage {self.mode_name}, exiting.") return 0 auto_battle_bot = AutoBattleBot(self.game, self.battle_over_conditions) ally_appeared = auto_battle_bot.wait_until_shifter_appeared( ) if farm_shifter_bios else True if farm_shifter_bios and not ally_appeared: logger.info("No shifter, restarting.") if self.game.restart_game(repeat_while=auto_battle_bot.is_battle): self.game.select_mode(self.mode_name) return stage_num auto_battle_bot.fight() stage_num -= 1 logger.debug(f"{stage_num} stages left to complete.") self.close_mission_notifications() if stage_num > 0: self.press_repeat_button() else: self.press_home_button() return stage_num
def press_start_button(self, check_inventory=True): """Start Co-op mission stage.""" self.player.click_button(self.ui['COOP_START_BUTTON'].button) if wait_until(self.player.is_ui_element_on_screen, timeout=3, ui_element=self.ui['WAITING_FOR_OTHER_PLAYERS']): logger.debug("Waiting for other players.") if wait_until(self.player.is_ui_element_on_screen, timeout=60, condition=False, ui_element=self.ui['WAITING_FOR_OTHER_PLAYERS']): if wait_until(self.player.is_ui_element_on_screen, timeout=3, ui_element=self.ui['DISCONNECT_NEW_OPPONENT']): logger.debug("Got disconnected. Finding new opponent.") self.player.click_button( self.ui['DISCONNECT_NEW_OPPONENT'].button) return self.press_start_button(check_inventory=False) AutoBattleBot(self.game, self.battle_over_conditions, self.disconnect_conditions).fight() r_sleep(2) # wait progress bar animation if self.stages > 0: self.press_repeat_button() else: self.press_home_button() return if check_inventory and wait_until( self.player.is_ui_element_on_screen, timeout=2, ui_element=self.ui['INVENTORY_FULL']): self.player.click_button(self.ui['INVENTORY_FULL'].button) self.stages *= 0 return logger.warning("Something went wrong while waiting for other players.") self.player.click_button(self.ui['WAITING_FOR_OTHER_PLAYERS'].button)
def start_missions(self, times=0, difficulty=15, use_hidden_tickets=False): """Start Dimension Missions. :param times: how many times to complete missions. :param difficulty: name of UI element that contains info about difficulty of stage. :param use_hidden_tickets: use Hidden Tickets or not. """ logger.info(f"Starting Dimensions Missions for {times} times.") if not self.open_dimension_mission(): logger.warning("Can't get in mission lobby.") return self._select_stage_level(level_num=difficulty) if self._get_ready_for_mission(): r_sleep(1) if not self.is_stage_startable(): logger.error( "Cannot start Dimension Mission battle, not enough boost points." ) return while times > 0: if not self.press_start_button( start_button_ui='DM_START_BUTTON', use_hidden_tickets=use_hidden_tickets): logger.error("Cannot start Dimension Mission battle, exiting.") return AutoBattleBot(self.game, self.battle_over_conditions).fight() times -= 1 self.close_mission_notifications() if times > 0: self.press_repeat_button() else: self.press_home_button() self.close_after_mission_notifications() logger.info("No more stages.")
def start_missions(self, times=0, difficulty=15): """Start Dimension Missions. :param times: :param difficulty: name of UI element that contains info about difficulty of stage. """ logger.info(f"Starting Dimensions Missions for {times} times.") if not self.go_to_dm(): logger.warning("Dimension Mission: can't get in mission lobby.") return self.select_stage_level(level_num=difficulty) while times > 0: if self.get_ready(): r_sleep(1) if not self.is_stage_startable(): logger.error( "Cannot start Dimension Mission battle, not enough boost points." ) return if not self.press_start_button( start_button_ui='DM_START_BUTTON'): logger.error( "Cannot start Dimension Mission battle, exiting.") return AutoBattleBot(self.game, self.battle_over_conditions).fight() times -= 1 self.close_mission_notifications() if times > 0: self.press_repeat_button() else: self.press_home_button() self.close_after_mission_notifications() logger.info("No more stages for Dimension Missions.")
def repeat_mission(self, times): """Repeat missions. :param times: how many times to repeat. """ for _ in range(times): if not self.press_start_button(): logger.error( "Cannot start missions while repeating them, exiting.") return AutoBattleBot(self.game, self.battle_over_conditions).fight() self.close_mission_notifications() repeat_button_ui = None if wait_until( self.emulator.is_image_on_screen, timeout=2, ui_element=self.ui['REPEAT_BUTTON_IMAGE_POSITION_2']): repeat_button_ui = 'REPEAT_BUTTON_IMAGE_POSITION_2' else: if wait_until( self.emulator.is_image_on_screen, timeout=2, ui_element=self.ui['REPEAT_BUTTON_IMAGE_POSITION_1']): repeat_button_ui = 'REPEAT_BUTTON_IMAGE_POSITION_1' if repeat_button_ui: self.press_repeat_button(repeat_button_ui)
def start_squad_battle(self, battle_num): """Start selected squad battle. :param battle_num: number of the battle. """ if self.select_squad_battle(squad_battle_ui=self.ui[battle_num]): self.press_start_button() AutoBattleBot(self.game, self.battle_over_conditions).fight() self.close_after_battle_notifications()
def _start_squad_battle(self, battle_name): """Starts selected squad battle. :param str battle_name: number of the battle. """ battle_ui = ui.get_by_name(battle_name) if self._select_squad_battle(squad_battle_ui=battle_ui): if not self.press_start_button(): return self.end_missions() AutoBattleBot(self.game, self.battle_over_conditions).fight() self.close_squad_battle_after_battle_notifications()
def fight(self): """Go to fight screen and fight.""" if wait_until(self.player.is_ui_element_on_screen, timeout=3, ui_element=self.ui['TL_FIGHT_BUTTON']): self.player.click_button(self.ui['TL_FIGHT_BUTTON'].button) AutoBattleBot(self.game, self.battle_over_conditions).fight() self.stages -= 1 if self.stages > 0: self.press_repeat_button(repeat_button_ui='TL_REPEAT_BUTTON', start_button_ui='TL_FIGHT_BUTTON') else: self.press_home_button(home_button='TL_HOME_BUTTON')
def _start_fight(self): """Goes to fight screen and fight.""" if not wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.TL_FIGHT_BUTTON): return logger.error(f"Can't find {ui.TL_FIGHT_BUTTON} button.") logger.debug("Starting the fight.") self.emulator.click_button(ui.TL_FIGHT_BUTTON) AutoBattleBot(self.game, self.battle_over_conditions).fight() r_sleep(1) # Wait for button's animation self.stages -= 1 if self.stages > 0: self.press_repeat_button(repeat_button_ui=ui.TL_REPEAT_BUTTON, start_button_ui=ui.TL_FIGHT_BUTTON) else: self.press_home_button(home_button=ui.TL_HOME_BUTTON)