def select_fight_option(self): if self._menu_state == BAState.Main: self.move_cursor_to((0, 0)) kc.press_a() self._menu_state = BAState.Moves elif self._menu_state != BAState.Moves: raise Exception('transition not implemented')
def handle_battle(self): print('Battle agent starting battle') tc.activate_speedup() self.wait_for_red_arrow() kc.press_a() self.wait_for_black_arrow() moves = self._active_pokemon.get_move_sequence(10) for move in moves: # use move and check for enemy faint if self.use_move_and_check_faint( self._active_pokemon.get_move_coords(move)): self.on_enemy_fainted() # check level up if self.wait_for_level_up(): self.on_pokemon_leveled() # check move learned if self.wait_for_move_learned(): self.on_move_learned() # check move attempt learn # check evolution tc.deactivate_speedup() pparty.save_party() return else: # handle additional dialogues while not self.wait_for_black_arrow(timeout=0.1): if self.wait_for_red_arrow(timeout=0.1): print('additional dialogue detected') kc.press_a() self.run_from_battle()
def run_from_battle(self): # need to account for failing to escape print('Attempting to run from battle') self.move_cursor_to((1, 1)) kc.press_a() self.wait_for_red_arrow() kc.press_a() tc.deactivate_speedup() pparty.save_party()
def select_index(self, index): self.move_to_index(index) kc.press_a()
def fly_to_city(city_name): _move_to_city(city_name) kc.press_a() tc.activate_speedup() time.sleep(.5) tc.deactivate_speedup()
def select_pokemon_menu(): _selector.move_to_index(1) kc.press_a() time.sleep(.8)
def on_pokemon_leveled(self): print('pokemon leveled') self._active_pokemon.increment_level() for _ in range(3): kc.press_a()
def on_enemy_fainted(self): print('Enemy fainted, concluding battle...') kc.press_a() self.wait_for_red_arrow() kc.press_a()
def use_move(self, move_coords): print('Selecting move: ' + str(move_coords)) self.select_fight_option() self.move_cursor_to(move_coords) kc.press_a() self._menu_state = BAState.Main
def on_move_learned(self): print(self._active_pokemon.get_name() + ' learned move') self.wait_for_red_arrow() kc.press_a()