def on_game_status(self, e): # Create a status model when a new game starts if e.game.playing: map_obj = model_mgr.get_map(e.game.map_id) self.game = GameState(e.game.id, e.game.map_id, map_obj.name, e.game.clock_limit) self.games[e.game.id] = self.game
def get_map(self, id): ''' Provides details for a specific map based on the given map identifier. Args: id (string): The unique identifier of a map. Returns: map (object): Detailed information for a specific map. ''' # Get the model for the requested map map_obj = model_mgr.get_map(id) if not map_obj: raise cherrypy.HTTPError(404) # Get the stats for the requested map map_stats = stat_mgr.get_map_stats(map_obj) # Build a list of column descriptors columns = [{ 'name': 'Players', 'data': 'player' }, { 'name': 'Score', 'data': 'number', 'sorted': False }, { 'name': 'Kills', 'data': 'number' }, { 'name': 'Deaths', 'data': 'number' }] # Build a list of map statistics rows = list() for player in map_stats.players: if player != models.players.EMPTY: object_stats = map_stats.players[player] player_tuple = { 'id': player.id, 'name': player.name, 'photo': player.photo_s } rows.append([ player_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 { 'id': map_obj.id, 'name': map_obj.name, 'columns': columns, 'rows': rows }
def on_score(self, e): # Get the current map current_game = model_mgr.get_game() current_map = model_mgr.get_map(current_game.map_id) map_stats = stat_mgr.get_map_stats(current_map) # Increment the total map score map_stats.score += e.value # Increment score count for the player if not e.player in map_stats.players: map_stats.players[e.player] = MapItemStats() map_stats.players[e.player].score += e.value
def on_death(self, e): # Get the current map current_game = model_mgr.get_game() current_map = model_mgr.get_map(current_game.map_id) map_stats = stat_mgr.get_map_stats(current_map) # Increment the total map deaths map_stats.deaths += 1 # Increment the player deaths if not e.player in map_stats.players: map_stats.players[e.player] = MapItemStats() map_stats.players[e.player].deaths += 1
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()
def get_game(self, id): ''' Provides details for a specific game based on the given game identifier. Args: id (string): The unique identifier of a game. Returns: game (object): Detailed information for a specific game. ''' # Get the model for the requested game game = model_mgr.get_game(id) if not game: raise cherrypy.HTTPError(404) # Get the stats for the requested game game_stats = stat_mgr.get_game_stats(game) # Build a list of column descriptors columns = [{ 'name': 'Players', 'data': 'player' }, { 'name': 'Score', 'data': 'number', 'sorted': False }, { 'name': 'Help', 'data': 'number' }, { 'name': 'Kills', 'data': 'number' }, { 'name': 'Deaths', 'data': 'number' }] # Build a list of game statistics rows = list() for player in game_stats.players: if player != models.players.EMPTY: object_stats = game_stats.players[player] player_tuple = { 'id': player.id, 'name': player.name, 'photo': player.photo_s } rows.append([player_tuple, object_stats.score, object_stats.teamwork, object_stats.kills, object_stats.deaths]) # Sort the results by score rows.sort(key=lambda r: r[1], reverse=True) map_obj = model_mgr.get_map(game.map_id) return { 'id': game.id, 'name': map_obj.name, 'columns' : columns, 'rows': rows }
def on_kill(self, e): # Ignore suicides and team kills if not e.valid_kill: return # Get the current map current_game = model_mgr.get_game() current_map = model_mgr.get_map(current_game.map_id) map_stats = stat_mgr.get_map_stats(current_map) # Increment the total map kills map_stats.kills += 1 # Increment the attacker kills if not e.attacker in map_stats.players: map_stats.players[e.attacker] = MapItemStats() map_stats.players[e.attacker].kills += 1
def get_games(self): ''' Provides an index of available games. Args: None Returns: games (list): Returns the list of all games. ''' # Build an index of the available games results = list() for game in model_mgr.get_games(): if game.valid: map_obj = model_mgr.get_map(game.map_id) results.append({'id': game.id, 'name': map_obj.name}) # Sort the index by game id results.sort(key=lambda r: int(r['id'])) return results
def get_games(self): ''' Provides an index of available games. Args: None Returns: games (list): Returns the list of all games. ''' # Build an index of the available games results = list() for game in model_mgr.get_games(): if game.valid: map_obj = model_mgr.get_map(game.map_id) results.append({ 'id': game.id, 'name': map_obj.name }) # Sort the index by game id results.sort(key=lambda r: int(r['id'])) return results
def on_death(self, e): player_stats = stat_mgr.get_player_stats(e.player) # Get the last known kit for the player # Player will no longer have an active kit at this point player_kit = event_mgr.get_last_kit(e.player) # Get the team and weapon for the player player_team = model_mgr.get_team(e.player.team_id) player_weapon = model_mgr.get_weapon(e.player.weapon_id) # Get the vehicle used by the player vehicle_id = None if e.player in self.vehicles: vehicle_id = self.vehicles[e.player] del self.vehicles[e.player] player_vehicle = model_mgr.get_vehicle(vehicle_id) # Get the current game and map current_game = model_mgr.get_game() current_map = model_mgr.get_map(current_game.map_id) # Increment death count for the player player_stats.deaths += 1 player_stats.deaths_total += 1 # Update death streaks for the player player_stats.deaths_streak += 1 if player_stats.deaths_streak > player_stats.deaths_streak_max: player_stats.deaths_streak_max = player_stats.deaths_streak player_stats.kills_streak = 0 # Update kill ratio for the player player_stats.kills_ratio = round( float(player_stats.kills) / float(player_stats.deaths), 2) player_stats.kills_ratio_max = round( float(player_stats.kills_total) / float(player_stats.deaths_total), 2) # Increment the enemy death count for the player if e.player in self.victims: kill_event = self.victims[e.player] if kill_event and kill_event.valid_kill: if not kill_event.attacker in player_stats.enemies: player_stats.enemies[ kill_event.attacker] = PlayerItemStats() player_stats.enemies[kill_event.attacker].deaths += 1 # Increment the kit death count for the player if not player_kit in player_stats.kits: player_stats.kits[player_kit] = PlayerItemStats() player_stats.kits[player_kit].deaths += 1 # Increment the map death count for the player if not current_map in player_stats.maps: player_stats.maps[current_map] = PlayerItemStats() player_stats.maps[current_map].deaths += 1 # Increment the team death count for the player if not player_team in player_stats.teams: player_stats.teams[player_team] = PlayerItemStats() player_stats.teams[player_team].deaths += 1 # Increment the vehicle death count for the player if not player_vehicle in player_stats.vehicles: player_stats.vehicles[player_vehicle] = PlayerItemStats() player_stats.vehicles[player_vehicle].deaths += 1 # Increment the weapon death count for the player if not player_weapon in player_stats.weapons: player_stats.weapons[player_weapon] = PlayerWeaponStats() player_stats.weapons[player_weapon].deaths += 1 # Reset all the temporary accuracy values self._update_accuracy(e.player) # Stop 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.squad_time.stop(e.tick) # Start the spectator timer player_stats.spec_time.start(e.tick)
def on_kill(self, e): self.victims[e.victim] = e victim_stats = stat_mgr.get_player_stats(e.victim) attacker_stats = stat_mgr.get_player_stats(e.attacker) # Get the last known kit for the attacker # Attacker may be dead and may not have an active kit attacker_kit = event_mgr.get_last_kit(e.attacker) # Get the team and vehicle for the attacker attacker_team = model_mgr.get_team(e.attacker.team_id) attacker_vehicle = model_mgr.get_vehicle(e.attacker.vehicle_id) # Get the current game and map current_game = model_mgr.get_game() current_map = model_mgr.get_map(current_game.map_id) # Check whether the kill was actually a suicide if e.suicide: attacker_stats.suicides += 1 attacker_stats.suicides_total += 1 return # Check whether the kill was actually a teammate if e.team_kill: victim_stats.team_killed += 1 victim_stats.team_killed_total += 1 attacker_stats.team_kills += 1 attacker_stats.team_kills_total += 1 return # Store the vehicle of the victim for future use if e.victim.vehicle_id: self.vehicles[e.victim] = e.victim.vehicle_id # Increment wound count for the victim victim_stats.wounds += 1 victim_stats.wounds_total += 1 # Increment enemy wound count for the victim if not e.attacker in victim_stats.enemies: victim_stats.enemies[e.attacker] = PlayerItemStats() victim_stats.enemies[e.attacker].wounds += 1 # Increment kill count for the attacker attacker_stats.kills += 1 attacker_stats.kills_total += 1 # Update kill streaks for the attacker attacker_stats.kills_streak += 1 if attacker_stats.kills_streak > attacker_stats.kills_streak_max: attacker_stats.kills_streak_max = attacker_stats.kills_streak attacker_stats.deaths_streak = 0 if attacker_stats.kills_streak == 5: attacker_stats.kills_5 += 1 attacker_stats.kills_5_total += 1 elif attacker_stats.kills_streak == 10: attacker_stats.kills_10 += 1 attacker_stats.kills_10_total += 1 # Update kill ratio for the attacker if attacker_stats.deaths == 0: attacker_stats.kills_ratio = 1.0 else: attacker_stats.kills_ratio = round( float(attacker_stats.kills) / float(attacker_stats.deaths), 2) if attacker_stats.deaths_total == 0: attacker_stats.kills_ratio_total = 1.0 else: attacker_stats.kills_ratio_total = round( float(attacker_stats.kills_total) / float(attacker_stats.deaths_total), 2) # Increment the enemy kill count for the attacker if not e.victim in attacker_stats.enemies: attacker_stats.enemies[e.victim] = PlayerItemStats() attacker_stats.enemies[e.victim].kills += 1 # Increment the kit kill count for the attacker if not attacker_kit in attacker_stats.kits: attacker_stats.kits[attacker_kit] = PlayerItemStats() attacker_stats.kits[attacker_kit].kills += 1 # Increment the map kill count for the attacker if not current_map in attacker_stats.maps: attacker_stats.maps[current_map] = PlayerItemStats() attacker_stats.maps[current_map].kills += 1 # Increment the vehicle kill count for the attacker if not attacker_vehicle in attacker_stats.vehicles: attacker_stats.vehicles[attacker_vehicle] = PlayerItemStats() attacker_stats.vehicles[attacker_vehicle].kills += 1 # Increment the team kill count for the attacker if not attacker_team in attacker_stats.teams: attacker_stats.teams[attacker_team] = PlayerItemStats() attacker_stats.teams[attacker_team].kills += 1 # Increment the weapon kill count for the attacker if not e.weapon in attacker_stats.weapons: attacker_stats.weapons[e.weapon] = PlayerWeaponStats() attacker_stats.weapons[e.weapon].kills += 1
def on_death(self, e): player_stats = stat_mgr.get_player_stats(e.player) # Get the last known kit for the player # Player will no longer have an active kit at this point player_kit = event_mgr.get_last_kit(e.player) # Get the team and weapon for the player player_team = model_mgr.get_team(e.player.team_id) player_weapon = model_mgr.get_weapon(e.player.weapon_id) # Get the vehicle used by the player vehicle_id = None if e.player in self.vehicles: vehicle_id = self.vehicles[e.player] del self.vehicles[e.player] player_vehicle = model_mgr.get_vehicle(vehicle_id) # Get the current game and map current_game = model_mgr.get_game() current_map = model_mgr.get_map(current_game.map_id) # Increment death count for the player player_stats.deaths += 1 player_stats.deaths_total += 1 # Update death streaks for the player player_stats.deaths_streak += 1 if player_stats.deaths_streak > player_stats.deaths_streak_max: player_stats.deaths_streak_max = player_stats.deaths_streak player_stats.kills_streak = 0 # Update kill ratio for the player player_stats.kills_ratio = round(float(player_stats.kills) / float(player_stats.deaths), 2) player_stats.kills_ratio_max = round(float(player_stats.kills_total) / float(player_stats.deaths_total), 2) # Increment the enemy death count for the player if e.player in self.victims: kill_event = self.victims[e.player] if kill_event and kill_event.valid_kill: if not kill_event.attacker in player_stats.enemies: player_stats.enemies[kill_event.attacker] = PlayerItemStats() player_stats.enemies[kill_event.attacker].deaths += 1 # Increment the kit death count for the player if not player_kit in player_stats.kits: player_stats.kits[player_kit] = PlayerItemStats() player_stats.kits[player_kit].deaths += 1 # Increment the map death count for the player if not current_map in player_stats.maps: player_stats.maps[current_map] = PlayerItemStats() player_stats.maps[current_map].deaths += 1 # Increment the team death count for the player if not player_team in player_stats.teams: player_stats.teams[player_team] = PlayerItemStats() player_stats.teams[player_team].deaths += 1 # Increment the vehicle death count for the player if not player_vehicle in player_stats.vehicles: player_stats.vehicles[player_vehicle] = PlayerItemStats() player_stats.vehicles[player_vehicle].deaths += 1 # Increment the weapon death count for the player if not player_weapon in player_stats.weapons: player_stats.weapons[player_weapon] = PlayerWeaponStats() player_stats.weapons[player_weapon].deaths += 1 # Reset all the temporary accuracy values self._update_accuracy(e.player) # Stop 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.squad_time.stop(e.tick) # Start the spectator timer player_stats.spec_time.start(e.tick)
def on_kill(self, e): self.victims[e.victim] = e victim_stats = stat_mgr.get_player_stats(e.victim) attacker_stats = stat_mgr.get_player_stats(e.attacker) # Get the last known kit for the attacker # Attacker may be dead and may not have an active kit attacker_kit = event_mgr.get_last_kit(e.attacker) # Get the team and vehicle for the attacker attacker_team = model_mgr.get_team(e.attacker.team_id) attacker_vehicle = model_mgr.get_vehicle(e.attacker.vehicle_id) # Get the current game and map current_game = model_mgr.get_game() current_map = model_mgr.get_map(current_game.map_id) # Check whether the kill was actually a suicide if e.suicide: attacker_stats.suicides += 1 attacker_stats.suicides_total += 1 return # Check whether the kill was actually a teammate if e.team_kill: victim_stats.team_killed += 1 victim_stats.team_killed_total += 1 attacker_stats.team_kills += 1 attacker_stats.team_kills_total += 1 return # Store the vehicle of the victim for future use if e.victim.vehicle_id: self.vehicles[e.victim] = e.victim.vehicle_id # Increment wound count for the victim victim_stats.wounds += 1 victim_stats.wounds_total += 1 # Increment enemy wound count for the victim if not e.attacker in victim_stats.enemies: victim_stats.enemies[e.attacker] = PlayerItemStats() victim_stats.enemies[e.attacker].wounds += 1 # Increment kill count for the attacker attacker_stats.kills += 1 attacker_stats.kills_total += 1 # Update kill streaks for the attacker attacker_stats.kills_streak += 1 if attacker_stats.kills_streak > attacker_stats.kills_streak_max: attacker_stats.kills_streak_max = attacker_stats.kills_streak attacker_stats.deaths_streak = 0 if attacker_stats.kills_streak == 5: attacker_stats.kills_5 += 1 attacker_stats.kills_5_total += 1 elif attacker_stats.kills_streak == 10: attacker_stats.kills_10 += 1 attacker_stats.kills_10_total += 1 # Update kill ratio for the attacker if attacker_stats.deaths == 0: attacker_stats.kills_ratio = 1.0 else: attacker_stats.kills_ratio = round(float(attacker_stats.kills) / float(attacker_stats.deaths), 2) if attacker_stats.deaths_total == 0: attacker_stats.kills_ratio_total = 1.0 else: attacker_stats.kills_ratio_total = round(float(attacker_stats.kills_total) / float(attacker_stats.deaths_total), 2) # Increment the enemy kill count for the attacker if not e.victim in attacker_stats.enemies: attacker_stats.enemies[e.victim] = PlayerItemStats() attacker_stats.enemies[e.victim].kills += 1 # Increment the kit kill count for the attacker if not attacker_kit in attacker_stats.kits: attacker_stats.kits[attacker_kit] = PlayerItemStats() attacker_stats.kits[attacker_kit].kills += 1 # Increment the map kill count for the attacker if not current_map in attacker_stats.maps: attacker_stats.maps[current_map] = PlayerItemStats() attacker_stats.maps[current_map].kills += 1 # Increment the vehicle kill count for the attacker if not attacker_vehicle in attacker_stats.vehicles: attacker_stats.vehicles[attacker_vehicle] = PlayerItemStats() attacker_stats.vehicles[attacker_vehicle].kills += 1 # Increment the team kill count for the attacker if not attacker_team in attacker_stats.teams: attacker_stats.teams[attacker_team] = PlayerItemStats() attacker_stats.teams[attacker_team].kills += 1 # Increment the weapon kill count for the attacker if not e.weapon in attacker_stats.weapons: attacker_stats.weapons[e.weapon] = PlayerWeaponStats() attacker_stats.weapons[e.weapon].kills += 1