Exemplo n.º 1
0
    def __init__(self, pid, slot_data, detail_data, attribute_data):
        #: The player's unique in-game player id
        self.pid = int(pid)

        #: The player's replay.initData slot data
        self.slot_data = slot_data

        #: The replay.details data on this player
        self.detail_data = detail_data

        #: The replay.attributes.events data on this player
        self.attribute_data = attribute_data

        #: The player result, one of "Win", "Loss", or None
        self.result = None
        if detail_data['result'] == 1:
            self.result = "Win"
        elif detail_data['result'] == 2:
            self.result = "Loss"

        #: A reference to the player's :class:`Team` object
        self.team = None

        #: The race the player picked prior to the game starting.
        #: One of Protoss, Terran, Zerg, Random
        self.pick_race = attribute_data.get('Race', 'Unknown')

        #: The difficulty setting for the player. Always Medium for human players.
        #: Very Easy, Easy, Medium, Hard, Harder, Very hard, Elite, Insane,
        #: Cheater 2 (Resources), Cheater 1 (Vision)
        self.difficulty = attribute_data.get('Difficulty', 'Unknown')

        #: The race the player played the game with.
        #: One of Protoss, Terran, Zerg
        self.play_race = LOCALIZED_RACES.get(detail_data['race'], detail_data['race'])

        #: The co-op commander the player picked
        self.commander = slot_data['commander'].decode('utf8')

        #: A reference to a :class:`~sc2reader.utils.Color` object representing the player's color
        self.color = utils.Color(**detail_data['color'])

        #: A list of references to the :class:`~sc2reader.data.Unit` objects the player had this game
        self.units = list()

        #: A list of references to the :class:`~sc2reader.data.Unit` objects that the player killed this game
        self.killed_units = list()

        #: The Battle.net region the entity is registered to
        self.region = GATEWAY_LOOKUP[detail_data['bnet']['region']]

        #: The Battle.net subregion the entity is registered to
        self.subregion = detail_data['bnet']['subregion']

        #: The Battle.net acount identifier. Used to construct the
        #: bnet profile url. This value can be zero for games
        #: played offline when a user was not logged in to battle.net.
        self.toon_id = detail_data['bnet']['uid']
Exemplo n.º 2
0
        def createPlayer(pid, pdata, attributes):
            # make sure to strip the clan tag out of the name
            # in newer replays, the clan tag can be separated from the
            # player name with a <sp/> symbol. It should also be stripped.
            name = pdata.name.split("]", 1)[-1].split(">", 1)[-1]
            player = Player(pid, name)

            # In some beta patches attribute information is missing
            # Just assign them to team 2 to keep the issue from being fatal
            team_number = int(
                attributes.get('Teams' + self.type, "Team 2")[5:])

            if not team_number in self.team:
                self.team[team_number] = Team(team_number)
                self.teams.append(self.team[team_number])
            self.team[team_number].players.append(player)
            player.team = self.team[team_number]

            # Do basic win/loss processing from details data
            if pdata.result == 1:
                player.team.result = "Win"
                self.winner = player.team
            elif pdata.result == 2:
                player.team.result = "Loss"
            else:
                player.team.result = None

            player.pick_race = attributes.get('Race', 'Unknown')
            player.play_race = LOCALIZED_RACES.get(pdata.race, pdata.race)
            player.difficulty = attributes.get('Difficulty', 'Unknown')
            player.is_human = (attributes.get('Controller',
                                              'Computer') == 'User')
            player.uid = pdata.bnet.uid
            player.subregion = pdata.bnet.subregion
            player.gateway = GATEWAY_LOOKUP[pdata.bnet.gateway]
            player.handicap = pdata.handicap
            player.color = utils.Color(**pdata.color._asdict())
            return player
Exemplo n.º 3
0
    def load_players(self):
        for index, struct in enumerate(self.parts[0][3]):
            if not struct[0] or not struct[0][1]:
                continue  # Slot is closed

            player = PlayerSummary(struct[0][0])
            stats = self.player_stats.get(index, dict())
            settings = self.player_settings[index]
            player.is_ai = not isinstance(struct[0][1], dict)
            if not player.is_ai:
                player.gateway = self.gateway
                player.subregion = struct[0][1][0][2]
                player.region = REGIONS[player.gateway].get(
                    player.subregion, 'Unknown')
                player.bnetid = struct[0][1][0][3]
                player.unknown1 = struct[0][1][0]
                player.unknown2 = struct[0][1][1]

            # Either a referee or a spectator, nothing else to do
            if settings.get('Participant Role', '') != 'Participant':
                self.observers.append(player)
                continue

            player.play_race = LOBBY_PROPERTIES[0xBB9][1].get(struct[2], None)

            player.is_winner = isinstance(struct[1],
                                          dict) and struct[1][0] == 0
            if player.is_winner:
                self.winners.append(player.pid)

            team_id = int(settings['Team'].split(' ')[1])
            if team_id not in self.team:
                self.team[team_id] = Team(team_id)
                self.teams.append(self.team[team_id])

            player.team = self.team[team_id]
            self.team[team_id].players.append(player)

            # We can just copy these settings right over
            player.color = utils.Color(name=settings.get('Color', None))
            player.pick_race = settings.get('Race', None)
            player.handicap = settings.get('Handicap', None)

            # Overview Tab
            player.resource_score = stats.get('Resources', None)
            player.structure_score = stats.get('Structures', None)
            player.unit_score = stats.get('Units', None)
            player.overview_score = stats.get('Overview', None)

            # Units Tab
            player.units_killed = stats.get('Killed Unit Count', None)
            player.structures_built = stats.get('Structures Built', None)
            player.units_trained = stats.get('Units Trained', None)
            player.structures_razed = stats.get('Structures Razed Count', None)

            # Graphs Tab
            # Keep income_graph for backwards compatibility
            player.army_graph = stats.get('Army Value')
            player.resource_collection_graph = stats.get(
                'Resource Collection Rate', None)
            player.income_graph = player.resource_collection_graph

            # HotS Stats
            player.upgrade_spending_graph = stats.get('Upgrade Spending', None)
            player.workers_active_graph = stats.get('Workers Active', None)
            player.enemies_destroyed = stats.get('Enemies Destroyed:', None)
            player.time_supply_capped = stats.get('Time Supply Capped', None)
            player.idle_production_time = stats.get('Idle Production Time',
                                                    None)
            player.resources_spent = stats.get('Resources Spent:', None)
            player.apm = stats.get('APM', None)

            # Economic Breakdown Tab
            if isinstance(player.income_graph, Graph):
                values = player.income_graph.values
                player.resource_collection_rate = int(
                    sum(values) / len(values))
            else:
                # In old s2gs files the field with this name was actually a number not a graph
                player.resource_collection_rate = player.income_graph
                player.resource_collection_graph = None
                player.income_graph = None

            player.avg_unspent_resources = stats.get(
                'Average Unspent Resources', None)
            player.workers_created = stats.get('Workers Created', None)

            # Build Orders Tab
            player.build_order = self.build_orders.get(index, None)

            self.players.append(player)
            self.player[player.pid] = player
    def __init__(self, pid, slot_data, detail_data, attribute_data):
        #: The player's unique in-game player id
        self.pid = int(pid)

        #: The player's replay.initData slot data
        self.slot_data = slot_data

        #: The replay.details data on this player
        self.detail_data = detail_data

        #: The replay.attributes.events data on this player
        self.attribute_data = attribute_data

        #: The player result, one of "Win", "Loss", or None
        self.result = None
        if detail_data["result"] == 1:
            self.result = "Win"
        elif detail_data["result"] == 2:
            self.result = "Loss"

        #: A reference to the player's :class:`Team` object
        self.team = None

        #: The race the player picked prior to the game starting.
        #: One of Protoss, Terran, Zerg, Random
        self.pick_race = attribute_data.get("Race", "Unknown")

        #: The difficulty setting for the player. Always Medium for human players.
        #: Very Easy, Easy, Medium, Hard, Harder, Very hard, Elite, Insane,
        #: Cheater 2 (Resources), Cheater 1 (Vision)
        self.difficulty = attribute_data.get("Difficulty", "Unknown")

        #: The race the player played the game with.
        #: One of Protoss, Terran, Zerg
        self.play_race = LOCALIZED_RACES.get(detail_data["race"], detail_data["race"])

        #: The co-op commander the player picked
        #: Kerrigan, Raynor, etc.
        self.commander = slot_data["commander"]
        if self.commander is not None:
            self.commander = self.commander.decode("utf8")

        #: The level of the co-op commander
        #: 1-15 or None
        self.commander_level = slot_data["commander_level"]

        #: The mastery level of the co-op commander
        #: >0 or None
        self.commander_mastery_level = slot_data["commander_mastery_talents"]

        #: Trophy ID
        #: >0 or None
        self.trophy_id = slot_data["trophy_id"]

        #: The mastery talents picked for the co-op commander
        #: list of longs of length 6, each between 0 and 30
        self.commander_mastery_talents = slot_data["commander_mastery_talents"]

        #: A reference to a :class:`~sc2reader.utils.Color` object representing the player's color
        self.color = utils.Color(**detail_data["color"])

        #: A list of references to the :class:`~sc2reader.data.Unit` objects the player had this game
        self.units = list()

        #: A list of references to the :class:`~sc2reader.data.Unit` objects that the player killed this game
        self.killed_units = list()

        #: The Battle.net region the entity is registered to
        self.region = GATEWAY_LOOKUP[detail_data["bnet"]["region"]]

        #: The Battle.net subregion the entity is registered to
        self.subregion = detail_data["bnet"]["subregion"]

        #: The Battle.net account identifier. Used to construct the
        #: bnet profile url. This value can be zero for games
        #: played offline when a user was not logged in to battle.net.
        self.toon_id = detail_data["bnet"]["uid"]