Esempio n. 1
0
    def get_weapon(self, id):
        '''
        Provides details for a specific weapon based on the given weapon
        identifier.

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

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

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

        # Get the stats for the requested weapon
        weapon_stats = stat_mgr.get_weapon_stats(weapon)

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

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

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

        return {
            'id': weapon.id,
            'name': weapon.name,
            'columns': columns,
            'rows': rows
        }
Esempio n. 2
0
    def on_death(self, e):

        # Get the weapon for the player
        player_weapon = model_mgr.get_weapon(e.player.weapon_id)
        weapon_stats = stat_mgr.get_weapon_stats(player_weapon)

        # Increment the total weapon deaths
        weapon_stats.deaths += 1

        # Increment the player deaths
        if not e.player in weapon_stats.players:
            weapon_stats.players[e.player] = WeaponItemStats()
        weapon_stats.players[e.player].deaths += 1
Esempio n. 3
0
    def on_death(self, e):

        # Get the weapon for the player
        player_weapon = model_mgr.get_weapon(e.player.weapon_id)
        weapon_stats = stat_mgr.get_weapon_stats(player_weapon)

        # Increment the total weapon deaths
        weapon_stats.deaths += 1

        # Increment the player deaths
        if not e.player in weapon_stats.players:
            weapon_stats.players[e.player] = WeaponItemStats()
        weapon_stats.players[e.player].deaths += 1
Esempio n. 4
0
    def on_kill(self, e):

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

        # Increment the total weapon kills
        weapon_stats = stat_mgr.get_weapon_stats(e.weapon)
        weapon_stats.kills += 1

        # Increment the attacker kills
        if not e.attacker in weapon_stats.players:
            weapon_stats.players[e.attacker] = WeaponItemStats()
        weapon_stats.players[e.attacker].kills += 1
Esempio n. 5
0
    def on_kill(self, e):

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

        # Increment the total weapon kills
        weapon_stats = stat_mgr.get_weapon_stats(e.weapon)
        weapon_stats.kills += 1

        # Increment the attacker kills
        if not e.attacker in weapon_stats.players:
            weapon_stats.players[e.attacker] = WeaponItemStats()
        weapon_stats.players[e.attacker].kills += 1
Esempio n. 6
0
    def get_weapon(self, id):
        '''
        Provides details for a specific weapon based on the given weapon
        identifier.

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

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

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

        # Get the stats for the requested weapon
        weapon_stats = stat_mgr.get_weapon_stats(weapon)

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

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

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

        return { 'id': weapon.id, 'name': weapon.name, 'columns' : columns,
                'rows': rows }