def _start_manual_bot_for_danger_room(self): """Applies Danger Room's rules to ManualBattleBot and start it.""" manual_bot = ManualBattleBot(self.game, self.battle_over_conditions, self.disconnect_conditions) old_is_battle = manual_bot.is_battle manual_bot.is_battle = lambda: old_is_battle( ) and not self.emulator.is_ui_element_on_screen( ui.DANGER_ROOM_BATTLE_REVIVE) manual_bot.fight(move_around=True)
def start_missions(self, battle=THOR_RAGNAROK, stage=STAGE.BATTLE_1, mode=MODE.NORMAL): """Start Legendary Battle missions.""" logger.info(f"{self.stages} stages available") if self.stages > 0: if not self.open_legendary_battle(): logger.warning("Can't get in battles lobby.") return if not self._select_legendary_battle(battle=battle, mode=mode): logger.error(f"Can't select battle {battle}, exiting.") return if not self._select_stage(stage=stage): logger.error( f"Can't select stage {stage} of the battle, exiting.") return while self.stages > 0: if not self.press_start_button(): return ManualBattleBot(self.game, self.battle_over_conditions).fight() self.stages -= 1 if self.stages > 0: self.press_repeat_button( repeat_button_ui='LB_REPEAT_BUTTON', start_button_ui='LB_START_BUTTON') self.press_home_button(home_button='LB_HOME_BUTTON') logger.info("No more stages.")
def manual_bot_start(self): """Start manual bot for the fight.""" ManualBattleBot(self.game, self.battle_over_conditions, self.disconnect_conditions).fight() if self.player.is_ui_element_on_screen( ui_element=self.ui['INVASION_SLOT_CHEST']): self.player.click_button(self.ui['INVASION_SLOT_CHEST'].button) self._chests += 1 if wait_until(self.player.is_image_on_screen, timeout=2, ui_element=self.ui['INVASION_HOME_BUTTON']): if self._chests < self._max_chests: self.press_repeat_button( repeat_button_ui='INVASION_REPEAT_BUTTON', start_button_ui='INVASION_BOSS_FIGHT_START') else: self.press_home_button(home_button='INVASION_HOME_BUTTON') return # In case we got back from fight by disconnect or something else logger.debug("Any chest after boss fight wasn't acquired.") if wait_until(self.player.is_ui_element_on_screen, timeout=20, ui_element=self.ui['INVASION_BOSS_FIGHT_START']): if self.press_start_button(deploy_characters=False): self.wait_for_players()
def __init__(self, button, game: Game): bot = ManualBattleBot(game, battle_over_conditions=None) @reset_emulator_and_logger(game=game) def fight(*args, **kwargs): return bot.fight(*args, **kwargs) super().__init__(button, fight, {"move_around": False})
def _start_world_boss_battle(self, check_inventory=True): """Starts World Boss battle. :param bool check_inventory: check for full inventory or not. """ self.emulator.click_button(ui.WB_READY_BUTTON) self.close_mission_notifications() self.close_after_mission_notifications() if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.WB_SET_TEAM): self._deploy_characters() self.emulator.click_button(ui.WB_SET_TEAM) if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.WB_UNAVAILABLE_CHARACTER): logger.warning( "Stopping battle because your team has unavailable characters." ) self.emulator.click_button(ui.WB_UNAVAILABLE_CHARACTER) return False if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.WB_LOW_VALOR_OR_ATTACK): self.emulator.click_button(ui.WB_LOW_VALOR_OR_ATTACK) # Second notification about ATK is similar if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.WB_LOW_VALOR_OR_ATTACK): self.emulator.click_button(ui.WB_LOW_VALOR_OR_ATTACK) if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.WB_START_BUTTON): self._deploy_allies() self.emulator.click_button(ui.WB_START_BUTTON) if check_inventory and wait_until( self.emulator.is_ui_element_on_screen, timeout=2, ui_element=ui.INVENTORY_FULL): logger.warning( "Stopping battle because inventory is full.") self.emulator.click_button(ui.INVENTORY_FULL) self.stages *= 0 return False if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.WB_NOT_FULL_ALLY_TEAM): self.emulator.click_button(ui.WB_NOT_FULL_ALLY_TEAM) if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.WB_EXCLUDE_CHARACTERS_FROM_ALLIES): self.emulator.click_button( ui.WB_EXCLUDE_CHARACTERS_FROM_ALLIES) ManualBattleBot( self.game, self.battle_over_conditions).fight(move_around=True) self.close_mission_notifications() return True logger.error(f"Failed to locate {ui.WB_START_BUTTON} button.") return False logger.error("Failed to set team.")
def start_missions(self, times=0, max_rewards=None): """Starts Giant Boss Raid.""" if self.open_giant_boss_raid(): logger.info(f"Starting {times} raid(s).") while times > 0: if not self.press_start_button(max_rewards=max_rewards): return ManualBattleBot(self.game, self.battle_over_conditions, self.disconnect_conditions).fight() times -= 1 r_sleep(5) # Animation for rewards if times > 0: self.press_repeat_button(repeat_button_ui=ui.GBR_REPEAT_BUTTON, start_button_ui=ui.GBR_QUICK_START) else: self.press_home_button(home_button=ui.GBR_HOME_BUTTON) logger.info("No more stages.")
def start_alliance_battle(self, start_button, home_or_next_button): """Start alliance battle. :param start_button: start button UI. :param home_or_next_button: next to extreme button or home button UI. """ if wait_until(self.player.is_ui_element_on_screen, timeout=10, ui_element=self.ui[start_button]): r_sleep(2) self.deploy_characters() self.player.click_button(self.ui[start_button].button) ManualBattleBot(self.game, self.battle_over_conditions).fight() self.close_mission_notifications() self.player.click_button(self.ui[home_or_next_button].button)
def complete_world_event(self): """Completes available stage in World Event.""" self.open_world_event() if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.EVENT_WORLD_LOBBY_READY_BUTTON): logger.debug("Entering into team selection lobby.") self.emulator.click_button(ui.EVENT_WORLD_LOBBY_READY_BUTTON) self._get_ready_to_battle() if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.EVENT_WORLD_BATTLE_START_BUTTON): self.emulator.click_button(ui.EVENT_WORLD_BATTLE_START_BUTTON) ManualBattleBot( self.game, self.battle_over_conditions).fight(move_around=True) self.emulator.click_button(ui.EVENT_WORLD_BATTLE_TOTAL_SCORE) self.game.go_to_main_menu()
def _start_alliance_battle(self, start_button, home_or_next_button): """Start alliance battle. :param start_button: start button UI. :param home_or_next_button: next to extreme button or home button UI. """ if wait_until(self.emulator.is_ui_element_on_screen, timeout=10, ui_element=self.ui[start_button]): r_sleep(2) self._deploy_characters() self.emulator.click_button(self.ui[start_button].button) if wait_until(self.emulator.is_ui_element_on_screen, timeout=3, ui_element=self.ui['AB_NO_CHARACTERS']): logger.warning("No available 3 characters were found. Exiting.") self.emulator.click_button(self.ui['AB_NO_CHARACTERS'].button) return ManualBattleBot(self.game, self.battle_over_conditions).fight() self.close_mission_notifications() self.emulator.click_button(self.ui[home_or_next_button].button) else: logger.warning(f"Cannot find START battle button: {start_button}")
def start_missions(self, times=0, story_mission=None, story_stage=None): """Starts Story mission.""" if self.open_story_missions() and self._open_story_mission( story_mission=story_mission): logger.info(f"Starting Story {times} times.") while times > 0: self._select_story_stage(story_stage=story_stage) if not self.press_start_button(): return ManualBattleBot( self.game, self.battle_over_conditions).fight(move_around=True) times -= 1 if times > 0: self.press_repeat_button( repeat_button_ui=ui.STORY_REPEAT_BUTTON, start_button_ui=ui.STORY_ULTIMATE_START_BUTTON) else: self.press_home_button(home_button=ui.STORY_HOME_BUTTON) logger.info("No more stages.")
def _start_alliance_battle(self, start_button, home_or_next_button): """Starts alliance battle. :param ui.UIElement start_button: start button UI. :param ui.UIElement home_or_next_button: next to extreme button or home button UI. """ if not wait_until(self.emulator.is_ui_element_on_screen, timeout=10, ui_element=start_button): return logger.error( f"Cannot find START battle button: {start_button}") r_sleep(2) self._deploy_characters() self.emulator.click_button(start_button) if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.AB_NO_CHARACTERS): logger.warning("No available 3 characters were found. Exiting.") return self.emulator.click_button(ui.AB_NO_CHARACTERS) ManualBattleBot(self.game, self.battle_over_conditions).fight() self.close_mission_notifications() self.emulator.click_button(home_or_next_button)
def _manual_bot_start(self): """Starts manual bot for the fight.""" ManualBattleBot(self.game, self.battle_over_conditions, self.disconnect_conditions).fight() if wait_until(self.emulator.is_image_on_screen, timeout=2, ui_element=ui.INVASION_HOME_BUTTON): if self._chests < self._max_chests: self.press_repeat_button( repeat_button_ui=ui.INVASION_REPEAT_BUTTON, start_button_ui=ui.INVASION_BOSS_FIGHT_START) else: self.press_home_button(home_button=ui.INVASION_HOME_BUTTON) return # In case we got back from fight by disconnect or something else logger.debug("Any chest after boss fight wasn't acquired.") if wait_until(self.emulator.is_ui_element_on_screen, timeout=20, ui_element=ui.INVASION_BOSS_FIGHT_START): if self.press_start_button(): self._wait_for_players_and_start_fight()
def start_missions(self): """Start Legendary Battle missions.""" logger.info(f"Legendary battles: {self.stages} stages available") if self.stages > 0: if not self.go_to_stages_list(): logger.error("Can't get to Legendary Battle stages, exiting.") return if not self.select_ragnarok_battle(): logger.error("Can't select Ragnarok Battle, exiting.") return if not self.select_stage('LB_BATTLE_STAGE_1'): logger.error("Can't select first stage of the battle, exiting.") return while self.stages > 0: if not self.press_start_button(): logger.error("Cannot start legendary battle, exiting") return ManualBattleBot(self.game, self.battle_over_conditions).fight() self.stages -= 1 if self.stages > 0: self.press_repeat_button(repeat_button_ui='LB_REPEAT_BUTTON', start_button_ui='LB_START_BUTTON') self.press_home_button(home_button='LB_HOME_BUTTON') logger.info("No more stages for legendary battles.")
def start_missions(self, times=0): """Starts Shadowland battles. :param int times: how many Shadowland floors to clear. """ logger.info(f"Starting Shadowland for {self.stages} times.") if not self.open_shadowland(): return logger.error("Can't get into Shadowland.") while times > 0: if not wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.SL_ENTER_SHADOWLAND): return logger.error("Can't enter into Shadowland Floor.") self.emulator.click_button(ui.SL_ENTER_SHADOWLAND) if not wait_until(self._is_floor_open): return logger.error("Can't open Shadowland Floor, exiting.") if not self.select_floor(): return logger.error("Can't select Shadowland Floor, exiting.") if not self.press_start_button(): return logger.error("Failed to start Shadowland Floor battle.") ManualBattleBot(self.game, self.battle_over_conditions).fight() if wait_until(self.emulator.is_ui_element_on_screen, ui_element=ui.SL_BATTLE_LOST): logger.info("Lost Shadowland battle, exiting.") return self.press_home_button( home_button=ui.SL_BATTLE_HOME_BUTTON) times -= 1 logger.debug(f"{times} floors left to complete.") if times > 0: self.press_repeat_button( repeat_button_ui=ui.SL_BATTLE_NEXT_BUTTON, start_button_ui=ui.SL_ENTER_SHADOWLAND) r_sleep(3) # Wait for floor animations else: self.press_home_button(home_button=ui.SL_BATTLE_HOME_BUTTON) self.close_after_mission_notifications()
from lib.players.nox_player import NoxWindow from lib.game.battle_bot import ManualBattleBot from lib.game.game import Game import lib.logger as logging logger = logging.get_logger(__name__) if __name__ == '__main__': nox = NoxWindow("NoxPlayer") game = Game(nox) m = ManualBattleBot(game, battle_over_conditions=None).fight()