Exemplo n.º 1
0
    def on_kill(self, e):
        if e.weapon.weapon_type != ARTILLERY:
            attacker_stats = stat_mgr.get_player_stats(e.attacker)
            victim_stats = stat_mgr.get_player_stats(e.victim)

            if attacker_stats.rank >= 3 and victim_stats.rank <= 1:
                self.results[e.attacker] += 1
Exemplo n.º 2
0
    def _update_place(self):

        # Sort the players by score
        players = model_mgr.get_players(True)
        players.sort(key=lambda p: stat_mgr.get_player_stats(p).score,
                reverse=True)

        # Assign a place value to each player based on index
        last_score = None
        place = None
        for index, player in enumerate(players):
            player_stats = stat_mgr.get_player_stats(player)

            # Check whether the place should be incremented
            if last_score != player_stats.score:
                last_score = player_stats.score
                place = index + 1

            # Update the trend of the player
            if place < player_stats.place:
                player_stats.trend = '+'
            elif place > player_stats.place:
                player_stats.trend = '-'
            else:
                player_stats.trend = '='
            player_stats.place = place
Exemplo n.º 3
0
    def _update_place(self):

        # Sort the players by score
        players = model_mgr.get_players(True)
        players.sort(key=lambda p: stat_mgr.get_player_stats(p).score,
                     reverse=True)

        # Assign a place value to each player based on index
        last_score = None
        place = None
        for index, player in enumerate(players):
            player_stats = stat_mgr.get_player_stats(player)

            # Check whether the place should be incremented
            if last_score != player_stats.score:
                last_score = player_stats.score
                place = index + 1

            # Update the trend of the player
            if place < player_stats.place:
                player_stats.trend = '+'
            elif place > player_stats.place:
                player_stats.trend = '-'
            else:
                player_stats.trend = '='
            player_stats.place = place
Exemplo n.º 4
0
    def on_squad_leader(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)
        old_player_stats = stat_mgr.get_player_stats(e.old_player)

        # Update the associated leader timers
        player_stats.leader_time.start(e.tick)
        old_player_stats.leader_time.stop(e.tick)
Exemplo n.º 5
0
    def on_squad_leader(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)
        old_player_stats = stat_mgr.get_player_stats(e.old_player)

        # Update the associated leader timers
        player_stats.leader_time.start(e.tick)
        old_player_stats.leader_time.stop(e.tick)
Exemplo n.º 6
0
    def on_commander(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)
        old_player_stats = stat_mgr.get_player_stats(e.old_player)

        # Update the associated commander timers
        player_stats.commander_time.start(e.tick)
        player_stats.squad_time.stop(e.tick)
        old_player_stats.commander_time.stop(e.tick)
Exemplo n.º 7
0
    def on_commander(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)
        old_player_stats = stat_mgr.get_player_stats(e.old_player)

        # Update the associated commander timers
        player_stats.commander_time.start(e.tick)
        player_stats.squad_time.stop(e.tick)
        old_player_stats.commander_time.stop(e.tick)
Exemplo n.º 8
0
    def on_revive(self, e):
        receiver_stats = stat_mgr.get_player_stats(e.receiver)
        giver_stats = stat_mgr.get_player_stats(e.giver)

        # Increment revived points for the receiver
        receiver_stats.revived += 1
        receiver_stats.revived_total += 1

        # Increment revive points for the giver
        giver_stats.revives += 1
        giver_stats.revives_total += 1

        # Increment teamwork for the giver
        giver_stats.teamwork += 1
        giver_stats.teamwork_total += 1
Exemplo n.º 9
0
    def on_ammo(self, e):
        receiver_stats = stat_mgr.get_player_stats(e.receiver)
        giver_stats = stat_mgr.get_player_stats(e.giver)

        # Increment supply points for the receiver
        receiver_stats.supplied += 1
        receiver_stats.supplied_total += 1

        # Increment supply points for the giver
        giver_stats.supplies += 1
        giver_stats.supplies_total += 1

        # Increment teamwork for the giver
        giver_stats.teamwork += 1
        giver_stats.teamwork_total += 1
Exemplo n.º 10
0
    def on_heal(self, e):
        receiver_stats = stat_mgr.get_player_stats(e.receiver)
        giver_stats = stat_mgr.get_player_stats(e.giver)

        # Increment healed points for the receiver
        receiver_stats.healed += 1
        receiver_stats.healed_total += 1

        # Increment heal points for the giver
        giver_stats.heals += 1
        giver_stats.heals_total += 1

        # Increment teamwork for the giver
        giver_stats.teamwork += 1
        giver_stats.teamwork_total += 1
Exemplo n.º 11
0
    def on_ammo(self, e):
        receiver_stats = stat_mgr.get_player_stats(e.receiver)
        giver_stats = stat_mgr.get_player_stats(e.giver)

        # Increment supply points for the receiver
        receiver_stats.supplied += 1
        receiver_stats.supplied_total += 1

        # Increment supply points for the giver
        giver_stats.supplies += 1
        giver_stats.supplies_total += 1

        # Increment teamwork for the giver
        giver_stats.teamwork += 1
        giver_stats.teamwork_total += 1
Exemplo n.º 12
0
    def on_revive(self, e):
        receiver_stats = stat_mgr.get_player_stats(e.receiver)
        giver_stats = stat_mgr.get_player_stats(e.giver)

        # Increment revived points for the receiver
        receiver_stats.revived += 1
        receiver_stats.revived_total += 1

        # Increment revive points for the giver
        giver_stats.revives += 1
        giver_stats.revives_total += 1

        # Increment teamwork for the giver
        giver_stats.teamwork += 1
        giver_stats.teamwork_total += 1
Exemplo n.º 13
0
    def on_heal(self, e):
        receiver_stats = stat_mgr.get_player_stats(e.receiver)
        giver_stats = stat_mgr.get_player_stats(e.giver)

        # Increment healed points for the receiver
        receiver_stats.healed += 1
        receiver_stats.healed_total += 1

        # Increment heal points for the giver
        giver_stats.heals += 1
        giver_stats.heals_total += 1

        # Increment teamwork for the giver
        giver_stats.teamwork += 1
        giver_stats.teamwork_total += 1
Exemplo n.º 14
0
    def get_player_stats(self, id):
        '''
        Provides a map of various statistics for a specific player based on the
        given player identifier.

        Args:
            id (string): The unique identifier of a player.

        Returns:
            statistics (tuple): Detailed statistics for a specific player.
        '''

        # Get the model for the requested player
        player = model_mgr.get_player(id)
        if not player: raise cherrypy.HTTPError(404)

        # Get the stats for the requested player
        player_stats = stat_mgr.get_player_stats(player)

        # Respond with a summary of the player model and stats
        results = list()
        for key in Handler.MODEL_FIELDS:
            results.append({ 'key': key, 'value': player.__dict__[key] })
        for key in Handler.STATS_FIELDS:
            results.append({ 'key': key, 'value': player_stats.__dict__[key] })
        results.sort(key=lambda r: r['key'])
        return results
Exemplo n.º 15
0
    def on_win(self, e):

        # Increment the win count for all the active players on the team
        for player in model_mgr.get_players(True):
            if player.team_id == e.team.id:
                player_stats = stat_mgr.get_player_stats(player)
                player_stats.wins += 1
Exemplo n.º 16
0
    def on_win(self, e):

        # Update the win count for all the active players on the team
        for player in model_mgr.get_players(True):
            if player.team_id == e.team.id:
                player_stats = stat_mgr.get_player_stats(player)
                self.results[player] = player_stats.wins
Exemplo n.º 17
0
    def on_win(self, e):

        # Increment the win count for all the active players on the team
        for player in model_mgr.get_players(True):
            if player.team_id == e.team.id:
                player_stats = stat_mgr.get_player_stats(player)
                player_stats.wins += 1
Exemplo n.º 18
0
    def get_player_stats(self, id):
        '''
        Provides a map of various statistics for a specific player based on the
        given player identifier.

        Args:
            id (string): The unique identifier of a player.

        Returns:
            statistics (tuple): Detailed statistics for a specific player.
        '''

        # Get the model for the requested player
        player = model_mgr.get_player(id)
        if not player: raise cherrypy.HTTPError(404)

        # Get the stats for the requested player
        player_stats = stat_mgr.get_player_stats(player)

        # Respond with a summary of the player model and stats
        results = list()
        for key in Handler.MODEL_FIELDS:
            results.append({'key': key, 'value': player.__dict__[key]})
        for key in Handler.STATS_FIELDS:
            results.append({'key': key, 'value': player_stats.__dict__[key]})
        results.sort(key=lambda r: r['key'])
        return results
Exemplo n.º 19
0
    def on_loss(self, e):

        # Update the loss count for all the active players on the team
        for player in model_mgr.get_players(True):
            if player.team_id == e.team.id:
                player_stats = stat_mgr.get_player_stats(player)
                self.results[player] = player_stats.losses
Exemplo n.º 20
0
    def _update_accuracy(self, player):
        player_stats = stat_mgr.get_player_stats(player)

        # Use accuracy accumulated in the current game as the new base
        for weapon in player_stats.weapons:
            weapon_stats = player_stats.weapons[weapon]
            weapon_stats._bullets_hit = weapon_stats.bullets_hit
            weapon_stats._bullets_fired = weapon_stats.bullets_fired
Exemplo n.º 21
0
    def _update_place_overall(self):

        # Sort the players by total score
        players = model_mgr.get_players()
        players.sort(key=lambda p: stat_mgr.get_player_stats(p).score_total,
                reverse=True)

        # Assign an overall place value to each player based on index
        last_score = None
        place = None
        for index, player in enumerate(players):
            player_stats = stat_mgr.get_player_stats(player)

            if last_score != player_stats.score_total:
                last_score = player_stats.score_total
                place = index + 1
            player_stats.place_overall = place
Exemplo n.º 22
0
    def _update_place_overall(self):

        # Sort the players by total score
        players = model_mgr.get_players()
        players.sort(key=lambda p: stat_mgr.get_player_stats(p).score_total,
                     reverse=True)

        # Assign an overall place value to each player based on index
        last_score = None
        place = None
        for index, player in enumerate(players):
            player_stats = stat_mgr.get_player_stats(player)

            if last_score != player_stats.score_total:
                last_score = player_stats.score_total
                place = index + 1
            player_stats.place_overall = place
Exemplo n.º 23
0
    def _update_accuracy(self, player):
        player_stats = stat_mgr.get_player_stats(player)

        # Use accuracy accumulated in the current game as the new base
        for weapon in player_stats.weapons:
            weapon_stats = player_stats.weapons[weapon]
            weapon_stats._bullets_hit = weapon_stats.bullets_hit
            weapon_stats._bullets_fired = weapon_stats.bullets_fired
Exemplo n.º 24
0
    def on_squad(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Update the squad timer for the player
        if e.player.squader:
            player_stats.squad_time.start(e.tick)
        else:
            player_stats.squad_time.stop(e.tick)
Exemplo n.º 25
0
    def on_squad(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Update the squad timer for the player
        if e.player.squader:
            player_stats.squad_time.start(e.tick)
        else:
            player_stats.squad_time.stop(e.tick)
Exemplo n.º 26
0
    def on_repair(self, e):
        giver_stats = stat_mgr.get_player_stats(e.giver)

        # Increment repair points for the giver
        giver_stats.repairs += 1
        giver_stats.repairs_total += 1

        # Increment teamwork for the giver
        giver_stats.teamwork += 1
        giver_stats.teamwork_total += 1
Exemplo n.º 27
0
    def on_assist(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Increment assist count for the player
        player_stats.assists += 1
        player_stats.assists_total += 1

        # Increment teamwork count for the player
        player_stats.teamwork += 1
        player_stats.teamwork_total += 1

        # Get the last kill event that occurred
        global_history = event_mgr.get_history()
        kill_event = global_history.get_new_event(KillEvent.TYPE)

        # Increment the assisted count for the attacker
        attacker_stats = stat_mgr.get_player_stats(kill_event.attacker)
        attacker_stats.assisted += 1
        attacker_stats.assisted_total += 1
Exemplo n.º 28
0
    def on_repair(self, e):
        giver_stats = stat_mgr.get_player_stats(e.giver)

        # Increment repair points for the giver
        giver_stats.repairs += 1
        giver_stats.repairs_total += 1

        # Increment teamwork for the giver
        giver_stats.teamwork += 1
        giver_stats.teamwork_total += 1
Exemplo n.º 29
0
    def on_assist(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Increment assist count for the player
        player_stats.assists += 1
        player_stats.assists_total += 1

        # Increment teamwork count for the player
        player_stats.teamwork += 1
        player_stats.teamwork_total += 1

        # Get the last kill event that occurred
        global_history = event_mgr.get_history()
        kill_event = global_history.get_new_event(KillEvent.TYPE)

        # Increment the assisted count for the attacker
        attacker_stats = stat_mgr.get_player_stats(kill_event.attacker)
        attacker_stats.assisted += 1
        attacker_stats.assisted_total += 1
Exemplo n.º 30
0
    def on_accuracy(self, e):

        if e.weapon.weapon_type == weapons.COUNTER:
            player_stats = stat_mgr.get_player_stats(e.player)

            counters = 0
            for weapon in model_mgr.get_weapons(weapons.COUNTER):
                if weapon in player_stats.weapons:
                    counters += player_stats.weapons[weapon].bullets_fired
            self.results[e.player] = counters
Exemplo n.º 31
0
    def on_accuracy(self, e):

        if e.weapon.weapon_type == weapons.COUNTER:
            player_stats = stat_mgr.get_player_stats(e.player)

            counters = 0
            for weapon in model_mgr.get_weapons(weapons.COUNTER):
                if weapon in player_stats.weapons:
                    counters += player_stats.weapons[weapon].bullets_fired
            self.results[e.player] = counters
Exemplo n.º 32
0
    def on_accuracy(self, e):

        if e.weapon.id in self.horn_ids:
            player_stats = stat_mgr.get_player_stats(e.player)

            honks = 0
            for horn_id in self.horn_ids:
                weapon = model_mgr.get_weapon(horn_id)
                if weapon in player_stats.weapons:
                    honks += player_stats.weapons[weapon].bullets_fired
            self.results[e.player] = honks
Exemplo n.º 33
0
    def _update_ammo(self, player):
        player_stats = stat_mgr.get_player_stats(player)

        bullets_fired = 0
        bullets_hit = 0
        for weapon in player_stats.weapons:
            weapon_stats = player_stats.weapons[weapon]
            bullets_fired += weapon_stats.bullets_fired
            bullets_hit += weapon_stats.bullets_hit
        player_stats.bullets_fired = bullets_fired
        player_stats.bullets_hit = bullets_hit
Exemplo n.º 34
0
    def get_player_enemies(self, id):
        '''
        Provides enemy details for a specific player based on the given player
        identifier.

        Args:
           id (string): The unique identifier of a player.

        Returns:
            enemies (object): Detailed enemy information for a specific player.
        '''

        # Get the model for the requested player
        player = model_mgr.get_player(id)
        if not player: raise cherrypy.HTTPError(404)

        # Get the stats for the requested player
        player_stats = stat_mgr.get_player_stats(player)

        # Build a list of column descriptors
        columns = [{
            'name': 'Players',
            'data': 'player'
        }, {
            'name': 'Wounds',
            'data': 'number',
            'sorted': False
        }, {
            'name': 'Deaths',
            'data': 'number'
        }, {
            'name': 'Kills',
            'data': 'number'
        }]

        # Build a list of enemy statistics
        rows = list()
        for player in player_stats.enemies:
            if player != models.players.EMPTY:
                object_stats = player_stats.enemies[player]
                player_tuple = {
                    'id': player.id,
                    'name': player.name,
                    'photo': player.photo_s
                }
                rows.append([
                    player_tuple, object_stats.wounds, object_stats.deaths,
                    object_stats.kills
                ])

        # Sort the results by deaths to enemies
        rows.sort(key=lambda r: r[1], reverse=True)

        return {'columns': columns, 'rows': rows}
Exemplo n.º 35
0
    def _update_ammo(self, player):
        player_stats = stat_mgr.get_player_stats(player)

        bullets_fired = 0
        bullets_hit = 0
        for weapon in player_stats.weapons:
            weapon_stats = player_stats.weapons[weapon]
            bullets_fired += weapon_stats.bullets_fired
            bullets_hit += weapon_stats.bullets_hit
        player_stats.bullets_fired = bullets_fired
        player_stats.bullets_hit = bullets_hit
Exemplo n.º 36
0
    def on_accuracy(self, e):

        if e.weapon.id in self.horn_ids:
            player_stats = stat_mgr.get_player_stats(e.player)

            honks = 0
            for horn_id in self.horn_ids:
                weapon = model_mgr.get_weapon(horn_id)
                if weapon in player_stats.weapons:
                    honks += player_stats.weapons[weapon].bullets_fired
            self.results[e.player] = honks
Exemplo n.º 37
0
    def on_disconnect(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Reset all the temporary accuracy values
        self._update_accuracy(e.player)

        # Stop any active timers
        player_stats.commander_time.stop(e.tick)
        player_stats.leader_time.stop(e.tick)
        player_stats.play_time.stop(e.tick)
        player_stats.spec_time.stop(e.tick)
        player_stats.squad_time.stop(e.tick)
Exemplo n.º 38
0
    def on_disconnect(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Reset all the temporary accuracy values
        self._update_accuracy(e.player)

        # Stop any active timers
        player_stats.commander_time.stop(e.tick)
        player_stats.leader_time.stop(e.tick)
        player_stats.play_time.stop(e.tick)
        player_stats.spec_time.stop(e.tick)
        player_stats.squad_time.stop(e.tick)
Exemplo n.º 39
0
    def on_accuracy(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Update the accuracy for the player
        # Note that a base value must be used since accuracy is reset on death
        if not e.weapon in player_stats.weapons:
            player_stats.weapons[e.weapon] = PlayerWeaponStats()
        weapon_stats = player_stats.weapons[e.weapon]
        weapon_stats.bullets_hit = weapon_stats._bullets_hit + e.bullets_hit
        weapon_stats.bullets_fired = weapon_stats._bullets_fired + e.bullets_fired

        # Update ammo used for the player
        self._update_ammo(e.player)
Exemplo n.º 40
0
    def on_accuracy(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Update the accuracy for the player
        # Note that a base value must be used since accuracy is reset on death
        if not e.weapon in player_stats.weapons:
            player_stats.weapons[e.weapon] = PlayerWeaponStats()
        weapon_stats = player_stats.weapons[e.weapon]
        weapon_stats.bullets_hit = weapon_stats._bullets_hit + e.bullets_hit
        weapon_stats.bullets_fired = weapon_stats._bullets_fired + e.bullets_fired

        # Update ammo used for the player
        self._update_ammo(e.player)
Exemplo n.º 41
0
    def get_player_teams(self, id):
        '''
        Provides team details for a specific player based on the given player
        identifier.

        Args:
           id (string): The unique identifier of a player.

        Returns:
            teams (object): Detailed team information for a specific player.
        '''

        # Get the model for the requested player
        player = model_mgr.get_player(id)
        if not player: raise cherrypy.HTTPError(404)

        # Get the stats for the requested player
        player_stats = stat_mgr.get_player_stats(player)

        # Build a list of column descriptors
        columns = [{
            'name': 'Teams',
            'data': 'team'
        }, {
            'name': 'Score',
            'data': 'number',
            'sorted': False
        }, {
            'name': 'Kills',
            'data': 'number'
        }, {
            'name': 'Deaths',
            'data': 'number'
        }]

        # Build a list of team statistics
        rows = list()
        for team in player_stats.teams:
            if team != models.teams.EMPTY:
                object_stats = player_stats.teams[team]
                team_tuple = {'id': team.id, 'name': team.name}
                rows.append([
                    team_tuple, object_stats.score, object_stats.kills,
                    object_stats.deaths
                ])

        # Sort the results by score
        rows.sort(key=lambda r: r[1], reverse=True)

        return {'columns': columns, 'rows': rows}
Exemplo n.º 42
0
    def on_server_status(self, e):

        # Reset all the temporary accuracy values
        for player in model_mgr.get_players(True):
            self._update_accuracy(player)

        # Reset any active timers
        for player in model_mgr.get_players():
            player_stats = stat_mgr.get_player_stats(player)
            player_stats.commander_time.stop(e.tick)
            player_stats.leader_time.stop(e.tick)
            player_stats.play_time.stop(e.tick)
            player_stats.spec_time.stop(e.tick)
            player_stats.squad_time.stop(e.tick)
Exemplo n.º 43
0
    def on_server_status(self, e):

        # Reset all the temporary accuracy values
        for player in model_mgr.get_players(True):
            self._update_accuracy(player)

        # Reset any active timers
        for player in model_mgr.get_players():
            player_stats = stat_mgr.get_player_stats(player)
            player_stats.commander_time.stop(e.tick)
            player_stats.leader_time.stop(e.tick)
            player_stats.play_time.stop(e.tick)
            player_stats.spec_time.stop(e.tick)
            player_stats.squad_time.stop(e.tick)
Exemplo n.º 44
0
    def get_player_weapons(self, id):
        '''
        Provides weapon details for a specific player based on the given player
        identifier.

        Args:
           id (string): The unique identifier of a player.

        Returns:
            weapons (object): Detailed weapon information for a specific player.
        '''

        # Get the model for the requested player
        player = model_mgr.get_player(id)
        if not player: raise cherrypy.HTTPError(404)

        # Get the stats for the requested player
        player_stats = stat_mgr.get_player_stats(player)

        # Build a list of column descriptors
        columns = [{
            'name': 'Weapons',
            'data': 'weapon'
        }, {
            'name': 'Kills',
            'data': 'number',
            'sorted': False
        }, {
            'name': 'Deaths',
            'data': 'number'
        }, {
            'name': 'Accuracy',
            'data': 'percent'
        }]

        # Build a list of weapon statistics
        rows = list()
        for weapon in player_stats.weapons:
            if weapon != models.weapons.EMPTY:
                object_stats = player_stats.weapons[weapon]
                weapon_tuple = {'id': weapon.id, 'name': weapon.name}
                rows.append([
                    weapon_tuple, object_stats.kills, object_stats.deaths,
                    [object_stats.bullets_hit, object_stats.bullets_fired]
                ])

        # Sort the results by kills
        rows.sort(key=lambda r: r[1], reverse=True)

        return {'columns': columns, 'rows': rows}
Exemplo n.º 45
0
    def on_score(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Get the last known kit for the player
        # Player may be dead and would not have a kit
        player_kit = event_mgr.get_last_kit(e.player)

        # Get the current map
        current_game = model_mgr.get_game()
        current_map = model_mgr.get_map(current_game.map_id)

        # Get the team for the player
        player_team = model_mgr.get_team(e.player.team_id)

        # Increment score count for the player
        player_stats.score += e.value
        player_stats.score_total += e.value

        # Calculate the player rank based on score
        if player_stats.score >= 40:
            player_stats.rank = 4
        elif player_stats.score >= 30:
            player_stats.rank = 3
        elif player_stats.score >= 20:
            player_stats.rank = 2
        elif player_stats.score >= 10:
            player_stats.rank = 1

        # Increment the kit score for the player
        if not player_kit in player_stats.kits:
            player_stats.kits[player_kit] = PlayerItemStats()
        player_stats.kits[player_kit].score += e.value

        # Increment the map score for the player
        if not current_map in player_stats.maps:
            player_stats.maps[current_map] = PlayerItemStats()
        player_stats.maps[current_map].score += e.value

        # Increment the team score for the player
        if not player_team in player_stats.teams:
            player_stats.teams[player_team] = PlayerItemStats()
        player_stats.teams[player_team].score += e.value

        # Calculate the overall place of each player
        self._update_place()
        self._update_place_overall()
Exemplo n.º 46
0
    def on_score(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Get the last known kit for the player
        # Player may be dead and would not have a kit
        player_kit = event_mgr.get_last_kit(e.player)

        # Get the current map
        current_game = model_mgr.get_game()
        current_map = model_mgr.get_map(current_game.map_id)

        # Get the team for the player
        player_team = model_mgr.get_team(e.player.team_id)

        # Increment score count for the player
        player_stats.score += e.value
        player_stats.score_total += e.value

        # Calculate the player rank based on score
        if player_stats.score >= 40:
            player_stats.rank = 4
        elif player_stats.score >= 30:
            player_stats.rank = 3
        elif player_stats.score >= 20:
            player_stats.rank = 2
        elif player_stats.score >= 10:
            player_stats.rank = 1

        # Increment the kit score for the player
        if not player_kit in player_stats.kits:
            player_stats.kits[player_kit] = PlayerItemStats()
        player_stats.kits[player_kit].score += e.value

        # Increment the map score for the player
        if not current_map in player_stats.maps:
            player_stats.maps[current_map] = PlayerItemStats()
        player_stats.maps[current_map].score += e.value

        # Increment the team score for the player
        if not player_team in player_stats.teams:
            player_stats.teams[player_team] = PlayerItemStats()
        player_stats.teams[player_team].score += e.value

        # Calculate the overall place of each player
        self._update_place()
        self._update_place_overall()
Exemplo n.º 47
0
    def on_spawn(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Increment the game count when the player first spawns
        if not player_stats.played:
            player_stats.games += 1
            player_stats.played = True

        # Stop the spectator timer
        player_stats.spec_time.stop(e.tick)

        # Start relevant timers
        if e.player.commander:
            player_stats.commander_time.start(e.tick)
        if e.player.leader:
            player_stats.leader_time.start(e.tick)
        player_stats.play_time.start(e.tick)
        if e.player.squader:
            player_stats.squad_time.start(e.tick)
Exemplo n.º 48
0
    def on_spawn(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Increment the game count when the player first spawns
        if not player_stats.played:
            player_stats.games += 1
            player_stats.played = True

        # Stop the spectator timer
        player_stats.spec_time.stop(e.tick)

        # Start relevant timers
        if e.player.commander:
            player_stats.commander_time.start(e.tick)
        if e.player.leader:
            player_stats.leader_time.start(e.tick)
        player_stats.play_time.start(e.tick)
        if e.player.squader:
            player_stats.squad_time.start(e.tick)
Exemplo n.º 49
0
    def get_player_enemies(self, id):
        '''
        Provides enemy details for a specific player based on the given player
        identifier.

        Args:
           id (string): The unique identifier of a player.

        Returns:
            enemies (object): Detailed enemy information for a specific player.
        '''

        # Get the model for the requested player
        player = model_mgr.get_player(id)
        if not player: raise cherrypy.HTTPError(404)

        # Get the stats for the requested player
        player_stats = stat_mgr.get_player_stats(player)

        # Build a list of column descriptors
        columns = [{ 'name': 'Players', 'data': 'player' },
                { 'name': 'Wounds', 'data': 'number', 'sorted': False },
                { 'name': 'Deaths', 'data': 'number' },
                { 'name': 'Kills', 'data': 'number' }]

        # Build a list of enemy statistics
        rows = list()
        for player in player_stats.enemies:
            if player != models.players.EMPTY:
                object_stats = player_stats.enemies[player]
                player_tuple = {
                    'id': player.id,
                    'name': player.name,
                    'photo': player.photo_s
                }
                rows.append([player_tuple, object_stats.wounds,
                        object_stats.deaths, object_stats.kills])

        # Sort the results by deaths to enemies
        rows.sort(key=lambda r: r[1], reverse=True)

        return { 'columns' : columns, 'rows': rows }
Exemplo n.º 50
0
    def on_kill(self, e):

        # Ignore suicides and team kills
        if not e.valid_kill:
            return

        # Make sure a weapon was used
        if e.weapon == weapons.EMPTY:
            return

        player_stats = stat_mgr.get_player_stats(e.attacker)
        weapon_stats = player_stats.weapons[e.weapon]

        if not e.attacker in self.results:
            self.results[e.attacker] = AwardResult(weapon_stats.kills, e.weapon)
        result = self.results[e.attacker]

        if weapon_stats.kills > result.kills:
            result.kills = weapon_stats.kills
            result.weapon = e.weapon
Exemplo n.º 51
0
    def _get_stats_tuple(self, player, attributes=None):
        player_stats = stat_mgr.get_player_stats(player)

        if attributes and len(attributes) > 0:
            stats_tuple = {
                'id': player.id
            }
            for attribute in attributes:
                stats_tuple[attribute] = player_stats.__dict__[attribute]
            return stats_tuple

        return {
            'id': player.id,
            'deaths': player_stats.deaths,
            'kills': player_stats.kills,
            'place': player_stats.place,
            'rank': player_stats.rank,
            'score': player_stats.score,
            'trend': player_stats.trend,
            'teamwork': player_stats.teamwork
        }
Exemplo n.º 52
0
    def on_kill(self, e):

        # Ignore suicides and team kills
        if not e.valid_kill:
            return

        # Make sure a weapon was used
        if e.weapon == weapons.EMPTY:
            return

        player_stats = stat_mgr.get_player_stats(e.attacker)
        weapon_stats = player_stats.weapons[e.weapon]

        if not e.attacker in self.results:
            self.results[e.attacker] = AwardResult(weapon_stats.kills,
                                                   e.weapon)
        result = self.results[e.attacker]

        if weapon_stats.kills > result.kills:
            result.kills = weapon_stats.kills
            result.weapon = e.weapon
Exemplo n.º 53
0
    def GET(self, id=None):
        '''
        Provides statistics that represent the overall performance of all players.

        Args:
           None

        Returns:
            leaders (object): Overall information for all players.
        '''

        # Build a list of columns
        columns = list()
        columns.append({'name': 'Players', 'data': 'player'})
        columns.append({'name': 'Score', 'data': 'number', 'sorted': False})
        columns.append({'name': 'Help', 'data': 'number'})
        columns.append({'name': 'Kills', 'data': 'number'})
        columns.append({'name': 'Deaths', 'data': 'number'})
        columns.append({'name': 'Time', 'data': 'string'})

        # Build a row of statistics for each player
        rows = list()
        for player in model_mgr.get_players():
            player_stats = stat_mgr.get_player_stats(player)
            player_tuple = {
                'id': player.id,
                'name': player.name,
                'photo': player.photo_s
            }
            rows.append([
                player_tuple, player_stats.score_total,
                player_stats.teamwork_total, player_stats.kills_total,
                player_stats.deaths_total, player_stats.play_time
            ])

        # Sort the results by score
        rows.sort(key=lambda r: r[1], reverse=True)
        return {'columns': columns, 'rows': rows}
Exemplo n.º 54
0
    def get_player_weapons(self, id):
        '''
        Provides weapon details for a specific player based on the given player
        identifier.

        Args:
           id (string): The unique identifier of a player.

        Returns:
            weapons (object): Detailed weapon information for a specific player.
        '''

        # Get the model for the requested player
        player = model_mgr.get_player(id)
        if not player: raise cherrypy.HTTPError(404)

        # Get the stats for the requested player
        player_stats = stat_mgr.get_player_stats(player)

        # Build a list of column descriptors
        columns = [{ 'name': 'Weapons', 'data': 'weapon' },
                { 'name': 'Kills', 'data': 'number', 'sorted': False },
                { 'name': 'Deaths', 'data': 'number' },
                { 'name': 'Accuracy', 'data': 'percent' }]

        # Build a list of weapon statistics
        rows = list()
        for weapon in player_stats.weapons:
            if weapon != models.weapons.EMPTY:
                object_stats = player_stats.weapons[weapon]
                weapon_tuple = { 'id': weapon.id, 'name': weapon.name }
                rows.append([weapon_tuple, object_stats.kills, object_stats.deaths,
                        [object_stats.bullets_hit, object_stats.bullets_fired]])

        # Sort the results by kills
        rows.sort(key=lambda r: r[1], reverse=True)

        return { 'columns' : columns, 'rows': rows }
Exemplo n.º 55
0
    def get_player_vehicles(self, id):
        '''
        Provides vehicle details for a specific player based on the given player
        identifier.

        Args:
           id (string): The unique identifier of a player.

        Returns:
            vehicles (object): Detailed vehicle information for a specific
            player.
        '''

        # Get the model for the requested player
        player = model_mgr.get_player(id)
        if not player: raise cherrypy.HTTPError(404)

        # Get the stats for the requested player
        player_stats = stat_mgr.get_player_stats(player)

        # Build a list of column descriptors
        columns = [{ 'name': 'Vehicles', 'data': 'vehicle' },
                { 'name': 'Kills', 'data': 'number', 'sorted': False },
                { 'name': 'Deaths', 'data': 'number' }]

        # Build a list of vehicle statistics
        rows = list()
        for vehicle in player_stats.vehicles:
            if vehicle != models.vehicles.EMPTY:
                object_stats = player_stats.vehicles[vehicle]
                vehicle_tuple = { 'id': vehicle.id, 'name': vehicle.name }
                rows.append([vehicle_tuple, object_stats.kills,
                        object_stats.deaths])

        # Sort the results by kills
        rows.sort(key=lambda r: r[1], reverse=True)

        return { 'columns' : columns, 'rows': rows }
Exemplo n.º 56
0
    def on_flag_action(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Increment flag points for the player
        if e.action_type == FlagActionEvent.CAPTURE:
            player_stats.flag_captures += 1
            player_stats.flag_captures_total += 1
        elif e.action_type == FlagActionEvent.CAPTURE_ASSIST:
            player_stats.flag_capture_assists += 1
            player_stats.flag_capture_assists_total += 1
        elif e.action_type == FlagActionEvent.NEUTRALIZE:
            player_stats.flag_neutralizes += 1
            player_stats.flag_neutralizes_total += 1
        elif e.action_type == FlagActionEvent.NEUTRALIZE_ASSIST:
            player_stats.flag_neutralize_assists += 1
            player_stats.flag_neutralize_assists_total += 1
        elif e.action_type == FlagActionEvent.DEFEND:
            player_stats.flag_defends += 1
            player_stats.flag_defends_total += 1

        # Increment teamwork for the player
        player_stats.teamwork += 1
        player_stats.teamwork_total += 1
Exemplo n.º 57
0
    def on_flag_action(self, e):
        player_stats = stat_mgr.get_player_stats(e.player)

        # Increment flag points for the player
        if e.action_type == FlagActionEvent.CAPTURE:
            player_stats.flag_captures += 1
            player_stats.flag_captures_total += 1
        elif e.action_type == FlagActionEvent.CAPTURE_ASSIST:
            player_stats.flag_capture_assists += 1
            player_stats.flag_capture_assists_total += 1
        elif e.action_type == FlagActionEvent.NEUTRALIZE:
            player_stats.flag_neutralizes += 1
            player_stats.flag_neutralizes_total += 1
        elif e.action_type == FlagActionEvent.NEUTRALIZE_ASSIST:
            player_stats.flag_neutralize_assists += 1
            player_stats.flag_neutralize_assists_total += 1
        elif e.action_type == FlagActionEvent.DEFEND:
            player_stats.flag_defends += 1
            player_stats.flag_defends_total += 1

        # Increment teamwork for the player
        player_stats.teamwork += 1
        player_stats.teamwork_total += 1
Exemplo n.º 58
0
    def GET(self, id=None):
        '''
        Provides statistics that represent the overall performance of all players.

        Args:
           None

        Returns:
            leaders (object): Overall information for all players.
        '''
 
        # Build a list of columns
        columns = list()
        columns.append({ 'name': 'Players', 'data': 'player' })
        columns.append({ 'name': 'Score', 'data': 'number', 'sorted': False })
        columns.append({ 'name': 'Help', 'data': 'number' })
        columns.append({ 'name': 'Kills', 'data': 'number' })
        columns.append({ 'name': 'Deaths', 'data': 'number' })
        columns.append({ 'name': 'Time', 'data': 'string' })

        # Build a row of statistics for each player
        rows = list()
        for player in model_mgr.get_players():
            player_stats = stat_mgr.get_player_stats(player);
            player_tuple = {
                'id': player.id,
                'name': player.name,
                'photo': player.photo_s
            }
            rows.append([player_tuple, player_stats.score_total,
                    player_stats.teamwork_total, player_stats.kills_total,
                    player_stats.deaths_total, player_stats.play_time])

        # Sort the results by score
        rows.sort(key=lambda r: r[1], reverse=True)
        return { 'columns': columns, 'rows': rows }