def on_win(self, e): # Get the commander of the team that won commander = model_mgr.get_player(e.team.commander_id) # Give a point to the commander self.results[commander] += 1
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
def on_loss(self, e): # Get the commander of the team that lost commander = model_mgr.get_player(e.team.commander_id) # Give a point to the commander self.results[commander] += 1
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
def on_death(self, e): # Get the commander for the player's team team = model_mgr.get_team(e.player.team_id) commander = model_mgr.get_player(team.commander_id) # Give a point to the commander self.results[commander] += 1
def on_death(self, e): # Get the leader for the player's squad squad = model_mgr.get_squad(e.player.squad_id) leader = model_mgr.get_player(squad.leader_id) # Give a point to the squad leader self.results[leader] += 1
def __init__(self, tick, values): BaseEvent.__init__(self, tick, values, 2) # Pre-process - Make sure the squad model exists in the manager self.squad = model_mgr.add_squad(values[0]) self.player = model_mgr.get_player_by_name(values[1]) self.old_player = model_mgr.get_player(self.squad.leader_id) event_mgr.get_history(self.player).add_event(self)
def __init__(self, tick, values): BaseEvent.__init__(self, tick, values, 2) self.team = model_mgr.get_team(values[0]) self.player = model_mgr.get_player_by_name(values[1]) self.old_player = model_mgr.get_player(self.team.commander_id) event_mgr.get_history(self.team).add_event(self) event_mgr.get_history(self.player).add_event(self)
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}
def on_kill(self, e): # Ignore team kills and suicides if not e.valid_kill: return # Get the commander for the attacker's team team = model_mgr.get_team(e.attacker.team_id) commander = model_mgr.get_player(team.commander_id) # Give a point to the commander self.results[commander] += 1
def on_kill(self, e): # Ignore team kills and suicides if not e.valid_kill: return # Get the leader for the attacker's squad squad = model_mgr.get_squad(e.attacker.squad_id) leader = model_mgr.get_player(squad.leader_id) # Give a point to the squad leader self.results[leader] += 1
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}
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}
def post_process(self): # Get a list of all the award processors processors = stat_mgr.get_processors('awards') # Skip the current award processors.remove(self) for processor in processors: results = processor.get_results() if len(results) > 0: player_id = results[0][0]['id'] gold = model_mgr.get_player( player_id ) self.results[gold] += 1 if len(results) > 1: player_id = results[1][0]['id'] silver = model_mgr.get_player( player_id ) self.results[silver] += 1 if len(results) > 2: player_id = results[2][0]['id'] bronze = model_mgr.get_player( player_id ) self.results[bronze] += 1
def on_squad_leader(self, e): # Remove the squad leader flag from the previous player if e.squad.leader_id: old_player = model_mgr.get_player(e.squad.leader_id) if old_player: old_player.leader = False # Update the leader for the squad if e.player == models.players.EMPTY: e.squad.leader_id = None else: e.squad.leader_id = e.player.id # Add the squad leader flag to the new player e.player.leader = True
def _update_commander(self, player, team): # Remove the commander flag from the previous player if team.commander_id: old_player = model_mgr.get_player(team.commander_id) if old_player: old_player.commander = False # Update the commander for the team if player == models.players.EMPTY or team == models.teams.EMPTY: team.commander_id = None else: team.commander_id = player.id # Update the commander flag for the player if team == models.teams.EMPTY: player.commander = False else: player.commander = True
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 }
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 }
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 }