def parse_match_playing(blob): # MatchGameRoomStateType_Playing import app.mtga_app as mtga_app temp_players = {1: {}, 2: {}} match_id = blob['matchGameRoomStateChangedEvent']['gameRoomInfo'][ 'gameRoomConfig']['matchId'] game_room_info = blob["matchGameRoomStateChangedEvent"]["gameRoomInfo"] game_room_players = game_room_info["players"] for player in game_room_players: temp_players[player["systemSeatId"]]["player_id"] = player["userId"] game_room_config = game_room_info["gameRoomConfig"] reserved_players = game_room_config["reservedPlayers"] for player in reserved_players: temp_players[player["systemSeatId"]]["name"] = player["playerName"] match_config = game_room_config["matchConfig"] if "teams" in match_config: teams = match_config["teams"] for team in teams: players = team["players"] for player in players: player_seat = player["systemSeatId"] temp_players[player_seat]["deck"] = util.card_ids_to_card_list( player["deckCards"]) for player_idx in [1, 2]: if "deck" not in temp_players[player_idx]: temp_players[player_idx]["deck"] = [] # set up shared zones shared_battlefield = Zone("battlefield") shared_exile = Zone("exile") shared_limbo = Zone("limbo") shared_stack = Zone("stack") player1 = Player(temp_players[1]["name"], temp_players[1]["player_id"], 1, shared_battlefield, shared_exile, shared_limbo, shared_stack, temp_players[1]["deck"]) player2 = Player(temp_players[2]["name"], temp_players[2]["player_id"], 2, shared_battlefield, shared_exile, shared_limbo, shared_stack, temp_players[2]["deck"]) with mtga_app.mtga_watch_app.game_lock: if mtga_app.mtga_watch_app.player_id == player1.player_id: hero = player1 opponent = player2 elif mtga_app.mtga_watch_app.player_id == player2.player_id: hero = player2 opponent = player1 else: raise Exception( "Don't know who hero is: player_id: {} / player 1: {} / player 2: {}" .format(mtga_app.mtga_watch_app.player_id, player1.player_id, player2.player_id)) hero.is_hero = True if mtga_app.mtga_watch_app.intend_to_join_game_with: hero.original_deck = mtga_app.mtga_watch_app.intend_to_join_game_with mtga_app.mtga_watch_app.game = Game(match_id, hero, opponent, shared_battlefield, shared_exile, shared_limbo, shared_stack)
def parse_match_playing(blob): # MatchGameRoomStateType_Playing import app.mtga_app as mtga_app temp_players = {1: {}, 2: {}} game_room_info = blob["matchGameRoomStateChangedEvent"]["gameRoomInfo"] event_id = game_room_info['gameRoomConfig']['eventId'] game_room_players = game_room_info["players"] for player in game_room_players: temp_players[player["systemSeatId"]]["player_id"] = player["userId"] game_room_config = game_room_info["gameRoomConfig"] reserved_players = game_room_config["reservedPlayers"] for player in reserved_players: temp_players[player["systemSeatId"]]["name"] = player["playerName"] match_config = game_room_config["matchConfig"] if "teams" in match_config: teams = match_config["teams"] for team in teams: players = team["players"] for player in players: player_seat = player["systemSeatId"] temp_players[player_seat]["deck"] = util.card_ids_to_card_list( player["deckCards"]) for player_idx in [1, 2]: if "deck" not in temp_players[player_idx]: temp_players[player_idx]["deck"] = [] # set up shared zones shared_battlefield = Zone("battlefield") shared_exile = Zone("exile") shared_limbo = Zone("limbo") shared_stack = Zone("stack") player1 = Player(temp_players[1]["name"], temp_players[1]["player_id"], 1, shared_battlefield, shared_exile, shared_limbo, shared_stack, temp_players[1]["deck"]) player2 = Player(temp_players[2]["name"], temp_players[2]["player_id"], 2, shared_battlefield, shared_exile, shared_limbo, shared_stack, temp_players[2]["deck"]) with mtga_app.mtga_watch_app.game_lock: if mtga_app.mtga_watch_app.player_id == player1.player_id: hero = player1 opponent = player2 elif mtga_app.mtga_watch_app.player_id == player2.player_id: hero = player2 opponent = player1 else: raise Exception( "Don't know who hero is: player_id: {} / player 1: {} / player 2: {}" .format(mtga_app.mtga_watch_app.player_id, player1.player_id, player2.player_id)) hero.is_hero = True if mtga_app.mtga_watch_app.intend_to_join_game_with: hero.original_deck = mtga_app.mtga_watch_app.intend_to_join_game_with opponent_rank = "Unknown" if mtga_app.mtga_watch_app.match.opponent_name == opponent.player_name: opponent_rank = mtga_app.mtga_watch_app.match.opponent_rank match_id = game_room_info['gameRoomConfig'][ 'matchId'] + "-game1-{}".format(hero.player_id) hero_text = build_event_text(hero.player_name, "hero") oppo_text = build_event_text(opponent.player_name, "opponent") event_texts = [hero_text, " vs ", oppo_text] queue_obj = {"game_history_event": event_texts} general_output_queue.put(queue_obj) mtga_app.mtga_watch_app.game = Game(match_id, hero, opponent, shared_battlefield, shared_exile, shared_limbo, shared_stack, event_id, opponent_rank) mtga_app.mtga_watch_app.game.events.append( queue_obj["game_history_event"])