def __init__(self, tick, values): BaseEvent.__init__(self, tick, values, 3) self.player = model_mgr.get_player_by_name(values[0]) self.player_pos = event_mgr.parse_pos(values[1]) self.weapon = model_mgr.get_weapon(values[2]) event_mgr.get_history(self.player).add_event(self) event_mgr.get_history(self.weapon).add_event(self)
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
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 }
def __init__(self, tick, values): BaseEvent.__init__(self, tick, values, 4) self.player = model_mgr.get_player_by_name(values[0]) self.weapon = model_mgr.get_weapon(values[1]) self.bullets_hit = int(values[2]) self.bullets_fired = int(values[3]) event_mgr.get_history(self.player).add_event(self) event_mgr.get_history(self.weapon).add_event(self)
def on_kill(self, e): # Ignore suicides and team kills if not e.valid_kill: return vWeapon = model_mgr.get_weapon(e.victim.weapon_id) if e.weapon == weapons.EMPTY or vWeapon == weapons.EMPTY: return if self.ranks[e.weapon.weapon_type] < self.ranks[vWeapon.weapon_type]: self.results[e.attacker] += 1
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
def __init__(self, tick, values): BaseEvent.__init__(self, tick, values, 6) self.victim = model_mgr.get_player_by_name(values[0]) self.victim_pos = event_mgr.parse_pos(values[1]) self.attacker = model_mgr.get_player_by_name(values[2]) self.attacker_pos = event_mgr.parse_pos(values[3]) self.weapon = model_mgr.get_weapon(values[4]) self.vehicle = model_mgr.get_vehicle(values[5]) self.suicide = (self.victim == self.attacker) self.team_kill = ((self.suicide == False) and (self.victim.team_id == self.attacker.team_id)) self.valid_kill = (self.suicide == False and self.team_kill == False) event_mgr.get_history(self.victim).add_event(self) event_mgr.get_history(self.attacker).add_event(self) event_mgr.get_history(self.weapon).add_event(self)
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 }
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_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)