def __see_through_portal(self, character_id: str, portal_id: str, direction: str): character = self._character_manager.get_character(character_id) portal = self._portal_manager.get_portal(portal_id) old_room = self._room_manager.get_room(character.room_id) path = portal.find_path_from(old_room.id, direction) new_room = self._room_manager.get_room(path.end_room_id) old_region = self._region_manager.get_region(old_room.region_id) new_region = self._region_manager.get_region(new_room.region_id) changing_regions = (old_region.id != new_region.id) # Ask permission if changing_regions: action = Action('canseeregion', character_id=character.id, region_id=old_region.id) if old_region.do_action(action): return if character.do_action(action): return action = Action('canseeroom', character_id=character.id, room_id=new_room.id) if new_room.do_action(action): return if character.do_action(action): return if portal.do_action(Action('canenterportal', character_id=character.id, data={'direction': direction})): return # Perform actions action = Action('remoteseeroom', character_id=character.id, room_id=new_room.id, portal_id=portal, data={'path': path}) portal.do_action(action) character.do_action(action) new_room.do_action(action) old_room.do_action(action)
def execute(self, character: Character, param_string: str): command_manager = CommandManager() cmd_name = param_string.lower().strip() if command_manager.valid_command(cmd_name): if not character.has_command(cmd_name): character.add_command(cmd_name) character.do_action( Action( 'announce', data={ 'msg': 'You can now use the "{0}" command!<$nl>'.format( cmd_name) })) logging.info('{0} granted self command: {1}'.format( character.name, cmd_name)) else: character.do_action( Action('error', data={'msg': 'You already have that command!<$nl>'})) else: character.do_action( Action( 'error', data={'msg': 'Invalid command: {0}<$nl>'.format(cmd_name)}))
def enter(self): character = self._character_manager.get_character(self._character_id) character.add_existing_logic( TelnetReporter(self._character_id, self._connection)) self._game_manager.do_action( Action('enterrealm', character_id=self._character_id)) character.do_action( Action('seeroom', character_id=self._character_id, room_id=character.room_id))
def execute(self, character: Character, param_string: str): game_manager = GameManager() game_manager.add_action_absolute( 0, Action('chat', character_id=character.id, data={'msg': param_string}))
def execute(self, character: Character, param_string: str): msg = '<$nl>----------<$nl>' msg = msg + 'ID: <$green>{0}<$nl>'.format(character.id) msg = msg + 'Name: <$green>{0}<$nl>'.format(character.name) msg = msg + 'Logged in? <$green>{0}<$nl>'.format(character.logged_in) msg = msg + 'Current room: {0}<$nl>'.format(character.room_id) msg = msg + '----------<$nl>' character.do_action(Action('announce', data={'msg': msg}))
def execute(self, character: Character, param_string: str): if not param_string: character.do_action( Action('seeroom', character_id=character.id, room_id=character.room_id)) else: room_manager = RoomManager() room = room_manager.get_room(character.room_id) direction = string_utils.parse_word(param_string) portal = room.find_portal(direction) game_manager = GameManager() game_manager.add_action_absolute( 0, Action('attemptseethroughportal', character_id=character.id, portal_id=portal.id, data={'direction': direction}))
def execute(self, character: Character, param_string: str): game_manager = GameManager() connected_characters = game_manager.get_connected_characters() msg = 'Players<$nl>----------<$nl>' for connected_character in connected_characters: msg = msg + '<$cyan>{0}<$reset><$nl>'.format( connected_character.name) character.do_action(Action('announce', data={'msg': msg}))
def execute(self, character: Character, param_string: str): if not param_string: character.do_action( Action('error', data={'msg': 'Please specify a direction!<$nl>'})) return room_manager = RoomManager() room = room_manager.get_room(character.room_id) portal = room.find_portal(param_string) game_manager = GameManager() game_manager.add_action_absolute( 0, Action('attemptenterportal', character_id=character.id, portal_id=portal.id, data={'direction': param_string}))
def __say(self, character_id, msg): character = self._character_manager.get_character(character_id) room = self._room_manager.get_room(character.room_id) region = self._region_manager.get_region(room.region_id) # ask permission action = Action('cansay', character_id=character.id, data={msg: msg}) if character.do_action(action): return if room.do_action(action): return if region.do_action(action): return # Event notifications action = Action('say', character_id=character.id, data={msg: msg}) self.__action_to_room_characters(action, room.id) room.do_action(action) region.do_action(action)
def __do_command(self, character_id: str, cmd_string: str): character = self._character_manager.get_character(character_id) cmd_name = string_utils.parse_word(cmd_string) params = string_utils.remove_word(cmd_string) # logging.info('{0} is attempting to execute \'{1}\' with parameters \'{2}\''.format(character.name, cmd_name, params)) full_command_name = character.find_command(cmd_name) if full_command_name: command = self._command_manager.get(full_command_name) command.execute(character, params) else: character.do_action(Action("error", data={'msg': 'Unrecognized command: {0}<$nl>'.format(cmd_name)}))
def __logout(self, character_id): character = self._character_manager.get_character(character_id) room = self._room_manager.get_room(character.room_id) region = self._region_manager.get_region(room.region_id) self.__action_to_room_items(Action('leaveroom', character_id=character.id), room.id) self.__action_to_room_characters(Action('leaveroom', character_id=character.id), room.id) room.do_action(Action('leaveroom', character_id=character.id)) character.do_action(Action('leaveregion', character_id=character.id)) region.do_action(Action('leaveregion', character_id=character.id)) self.__action_to_realm_players(Action('leaverealm', character_id=character.id)) room.remove_character(character) region.remove_character(character) self._connected_characters.remove(character) character.logged_in = False
def __login(self, character_id): character = self._character_manager.get_character(character_id) room = self._room_manager.get_room(character.room_id) region = self._region_manager.get_region(room.region_id) character.logged_in = True self._connected_characters.append(character) room.add_character(character_id) region.add_character(character_id) self.__action_to_realm_players(Action('enterrealm', character_id=character.id)) region.do_action(Action('enterregion', character_id=character.id)) character.do_action(Action('enterregion', character_id=character.id)) room.do_action(Action('enterroom', character_id=character.id)) self.__action_to_room_characters(Action('enterroom', character_id=character.id), room.id) self.__action_to_room_items(Action('enterroom', character_id=character.id), room.id)
def do_action_helper(self, action_type, entities, data_string): action = Action(action_type, entities, data_string) self.do_action(action)
def execute(self, character: Character, param_string: str): game_manager = GameManager() game_manager.do_action(Action('leaverealm', character_id=character.id)) character.do_action(Action('leave', character_id=character.id))
def __enter_portal(self, character_id, portal_id, direction: str): character = self._character_manager.get_character(character_id) portal = self._portal_manager.get_portal(portal_id) old_room = self._room_manager.get_room(character.room_id) path = portal.find_path_from(old_room.id, direction) new_room = self._room_manager.get_room(path.end_room_id) old_region = self._region_manager.get_region(old_room.region_id) new_region = self._region_manager.get_region(new_room.region_id) changing_regions = (old_region.id != new_region.id) # Ask permission if changing_regions: action = Action('canleaveregion', character_id=character.id, region_id=old_region.id) if old_region.do_action(action): return if character.do_action(action): return action = Action('canenterregion', character_id=character.id, region_id=old_region.id) if new_region.do_action(action): return if character.do_action(action): return action = Action('canleaveroom', character_id=character.id, room_id=old_room.id) if old_room.do_action(action): return if character.do_action(action): return action = Action('canenterroom', character_id=character.id, room_id=new_room.id) if new_room.do_action(action): return if character.do_action(action): return if portal.do_action(Action('canenterportal', character_id=character.id, data={'direction': direction})): return # tell the room that the player is leaving if changing_regions: action = Action('leaveregion', character_id=character.id, region_id=old_region.id) old_region.do_action(action) character.do_action(action) action = Action('leaveroom', character_id=character.id, portal_id=portal.id, room_id=old_room.id, data={'path': path}) self.__action_to_room_characters(action, old_room.id) self.__action_to_room_items(action, old_room.id) old_room.do_action(action) # tell the portal that the player has actually entered action = Action('enterportal', character_id=character.id, portal_id=portal) portal.do_action(action) character.do_action(action) # actually move the character if changing_regions: old_region.remove_character(character.id) character.region_id = new_region.id new_region.add_character(character.id) old_room.remove_character(character.id) character.room_id = new_room.id new_room.add_character(character.id) # tell everyone in the room that the player has entered if changing_regions: action = Action('enterregion', character_id=character.id, region_id=new_region.id) new_region.do_action(action) character.do_action(action) action = Action('enterroom', character_id=character.id, portal_id=portal.id, room_id=new_room.id, data={'path': path}) new_room.do_action(action) self.__action_to_room_characters(action, new_room.id) self.__action_to_room_items(action, new_room.id)
def handle(self, cmd_string): self._game_manager.do_action( Action('command', character_id=self._character_id, data={'cmd': cmd_string.strip()}))
def __transport(self, character_id, room_id, force=False): character = self._character_manager.get_character(character_id) old_room = self._room_manager.get_room(character.room_id) new_room = self._room_manager.get_room(room_id) old_region = self._region_manager.get_region(old_room.region_id) new_region = self._region_manager.get_region(new_room.region_id) changing_regions = old_region.id != new_region.id # "ask permission" from the actors to perform the actions if not force: if changing_regions: if old_region.do_action(Action('canleaveregion', character_id=character.id)): return if new_region.do_action(Action('canenterregion', character_id=character.id)): return if character.do_action(Action('canleaveregion', region_id=old_region.id)): return if character.do_action(Action('canenterregion', region_id=new_region.id)): return if old_room.do_action(Action('canleaveroom', character_id=character.id)): return if new_room.do_action(Action('canenterroom', character_id=character.id)): return if character.do_action(Action('canleaveroom', room_id=old_room.id)): return if character.do_action(Action('canenterroom', room_id=new_room.id)): return # Move the character if changing_regions: old_region.remove_character(character.id) character.region_id = new_region.id new_region.add_character(character.id) old_room.remove_character(character.id) character.room_id = new_room.id new_room.add_character(character.id) # Notify actors that the event is complete if changing_regions: old_region.do_action(Action('leaveregion', character_id=character.id)) character.do_action(Action('leaveregion', region_id=old_region.id)) action = Action('leaveroom', character_id=character.id, room_id=old_room.id) old_room.do_action(action) character.do_action(action) self.__action_to_room_characters(action, old_room.id) self.__action_to_room_items(action, old_room.id) if changing_regions: action = Action('enterregion', character_id=character.id, room_id=new_region.id) new_region.do_action(action) character.do_action(action) action = Action('enterroom', character_id=character.id, room_id=new_room.id) new_room.do_action(action) self.__action_to_room_characters(action, new_room.id) self.__action_to_room_items(action, new_room.id)