def iterator(): """Iterate over all :class:`players.entity.Player` objects.""" # Loop through all players on the server for edict in PlayerGenerator(): # Yield the Player instance for the current edict yield Player(index_from_edict(edict))
def create_player(self, recording, replay_bot_name=None, adjust=True): """Create a new player for the given recording. :param Recording recording: The recording to play. :param str replay_bot_name: The name that should be used for the replay bot. If ``None`` a name is generated. :param bool adjust: If ``True`` the bot's location, angle and velocity is adjusted if it differs too much from the recorded state. :raise ValueError: Raised if the recording is not playable, no replay bot could be created or the controller couldn't be retrieved. """ if not recording.is_playable(): raise ValueError('Recording is not playable.') if replay_bot_name is None: replay_bot_name = self.create_replay_bot_name(recording) replay_bot_edict = bot_manager.create_bot(replay_bot_name) if replay_bot_edict is None: raise ValueError('Failed to create a replay bot.') controller = bot_manager.get_bot_controller(replay_bot_edict) if controller is None: raise ValueError('Failed to get the bot controller.') replay_bot = SPPlayer(index_from_edict(replay_bot_edict)) player = self.players[replay_bot.index] = Player( recording, controller, replay_bot, adjust) return player
def on_rup(command_info): teams = {"RED":2, "BLU": 3} for team_name, team_id in teams.items(): fake_client = engine_server.create_fake_client(f'RUP BOT {team_name}') fake_player = Player(index_from_edict(fake_client)) fake_player.team = team_id fake_player.client_command("tournament_readystate 1", True) fake_player.kick()
def iterator(): """Iterate over all :class:`weapons.entity.Weapon` objects.""" # Import the Weapon class. # This is done here to avoid circular imports from weapons.entity import Weapon # Loop through all entities on the server for edict in EntityGenerator(): # Is the entity a weapon? if edict.classname in weapon_manager: # Yield the Weapon instance for the current edict yield Weapon(index_from_edict(edict))
def has_c4(self): '''Returns whether or not the player is carrying C4''' # Loop through all c4 entities on the server for edict in CEntityGenerator('weapon_c4'): # Get the entity's index index = index_from_edict(edict) # Get the entity's BaseEntity instance entity = BaseEntity(index) # Is the entity's "owner" the player? if entity.owner == self.handle.to_int(): # Return True return True # If no c4 is owned by the player, return False return False
def _return_instance(edict): '''Returns the weapon's BaseEntity instance''' return BaseEntity(index_from_edict(edict), 'weapon')
def iterator(): """Iterate over all :class:`entities.entity.Entity` objects.""" for edict in EntityGenerator(): yield Entity(index_from_edict(edict))
def iterator(): """Iterate over all WCGO player objects.""" for edict in PlayerGenerator(): yield Player(index_from_edict(edict))
def from_edict(cls, edict): return cls(index_from_edict(edict))
def _player_is_on_team(self, edict): """Return whether the player is on the team.""" return playerinfo_from_edict(edict).get_team_index() == self.team # ============================================================================= # >> FILTERS # ============================================================================= # Register the filter functions _player_iter_manager.register_filter('all', lambda edict: True) _player_iter_manager.register_filter( 'bot', lambda edict: playerinfo_from_edict(edict).is_fake_client()) _player_iter_manager.register_filter( 'human', lambda edict: not playerinfo_from_edict(edict).is_fake_client()) _player_iter_manager.register_filter( 'alive', lambda edict: not PlayerEntity(index_from_edict( edict)).dead_flag) _player_iter_manager.register_filter( 'dead', lambda edict: PlayerEntity(index_from_edict( edict)).dead_flag) # Loop through all teams in the game's team file for _team in _game_teams.get('names', {}): # Add the team to the _player_teams dictionary _player_teams[_team] = int(_game_teams['names'][_team]) # Register the filter _player_iter_manager.register_filter( _team, _player_teams[_team]._player_is_on_team) # Loop through all base team names
# Loop through all class names for the generator for check_name in self.class_names: # Does the current class name match part of the edict's class name? if not self.exact_match and check_name in class_name: return True # Does the current class name match exactly the edict's class name? elif self.exact_match and check_name == class_name: return True # If none of the class names returned True, return False return False # ============================================================================= # >> RETURN TYPES # ============================================================================= # Register the return type functions _entity_iter_manager.register_return_type('index', index_from_edict) _entity_iter_manager.register_return_type('edict', lambda edict: edict) _entity_iter_manager.register_return_type( 'basehandle', basehandle_from_edict) _entity_iter_manager.register_return_type( 'inthandle', inthandle_from_edict) _entity_iter_manager.register_return_type('pointer', pointer_from_edict) _entity_iter_manager.register_return_type( 'entity', lambda edict: Entity(index_from_edict(edict))) _entity_iter_manager.register_return_type( 'classname', lambda edict: edict.get_class_name())
def _return_instance(edict): """Return the weapon's WeaponEntity instance.""" from weapons.entity import WeaponEntity return WeaponEntity(index_from_edict(edict))
def _get_entity_indexes(classname=''): result = set() for edict in EntityGenerator(classname, True): result.add(index_from_edict(edict)) return result
def initialize_all_players(): """Creates Player instances for all players on the server.""" for edict in PlayerGenerator(): player_instances[index_from_edict(edict)]