async def start_standard_battle(ps_websocket_client: PSWebsocketClient, pokemon_battle_type): battle, opponent_id, user_json = await initialize_battle_with_tag( ps_websocket_client, set_request_json=False) battle.battle_type = constants.STANDARD_BATTLE battle.generation = pokemon_battle_type[:4] smogon_usage_data = get_standard_battle_sets(pokemon_battle_type) data.pokemon_sets = smogon_usage_data if battle.generation in constants.NO_TEAM_PREVIEW_GENS: await read_messages_until_first_pokemon_is_seen( ps_websocket_client, battle, opponent_id, user_json) else: msg = '' while constants.START_TEAM_PREVIEW not in msg: msg = await ps_websocket_client.receive_message() preview_string_lines = msg.split( constants.START_TEAM_PREVIEW)[-1].split('\n') opponent_pokemon = [] for line in preview_string_lines: if not line: continue split_line = line.split('|') if split_line[1] == constants.TEAM_PREVIEW_POKE and split_line[ 2].strip() == opponent_id: opponent_pokemon.append(split_line[3]) battle.initialize_team_preview(user_json, opponent_pokemon) await handle_team_preview(battle, ps_websocket_client) return battle
def initialize_team_preview(self, user_json, opponent_pokemon, battle_mode): self.user.from_json(user_json, first_turn=True) self.user.reserve.insert(0, self.user.active) self.user.active = None for pkmn_string in opponent_pokemon: pokemon = Pokemon.from_switch_string(pkmn_string) self.opponent.reserve.append(pokemon) smogon_usage_data = get_standard_battle_sets(battle_mode) data.pokemon_sets = smogon_usage_data self.started = True self.rqid = user_json[constants.RQID]