def moveActor(self, receiver, event): actor = event.attributes["data"]["source"] direction = event.attributes["data"]["direction"] exit = None if direction != None and direction != "": exitList = filter( lambda e: e.attributes["name"].lower().startswith(direction.lower()), receiver.attributes["exits"] ) if len(exitList) > 0: exit = exitList[0] if exit == None: feedbackEvent = Event() feedbackEvent.attributes["signature"] = "received_feedback" feedbackEvent.attributes["data"]["feedback"] = ANSI.yellow("You can't go that way!") actor.receiveEvent(feedbackEvent) else: currentRoom = receiver.attributes["roomID"] destination = exit.attributes["destination"] moveEvent = Event() moveEvent.attributes["signature"] = "move_actor" moveEvent.attributes["data"]["actor"] = actor moveEvent.attributes["data"]["fromRoomID"] = currentRoom moveEvent.attributes["data"]["toRoomID"] = destination moveEvent.attributes["data"]["exitMessage"] = "{} leaves {}.".format( actor.attributes["name"], exit.attributes["name"] ) from Engine import RoomEngine RoomEngine.receiveEvent(moveEvent)
def execute(self, receiver, event): actor = event.attributes['data']['source'] words = event.attributes['data']['args'] if words == None or len(words) == 0: feedbackEvent = Event() feedbackEvent.attributes['signature'] = 'received_feedback' feedbackEvent.attributes['data']['feedback'] = 'Say what?' actor.receiveEvent(feedbackEvent) else: roomID = actor.attributes['roomID'] room = RoomEngine.getRoom(roomID) speakEvent = Event() sentence = '' for word in words: sentence = '{} {}'.format(sentence, word) speakEvent.attributes['signature'] = 'actor_emoted' speakEvent.attributes['data']['emoter'] = actor speakEvent.attributes['data']['target'] = None speakEvent.attributes['data']['emoterText'] = 'You say, "{}".'.format(sentence[1:]) speakEvent.attributes['data']['audienceText'] = '{} says, "{}".'.format(actor.attributes['name'], sentence[1:]) room.receiveEvent(speakEvent)
def execute(self, receiver, event): cmd = event.attributes['data']['command'] args = event.attributes['data']['args'] actor = event.attributes['data']['source'] roomID = actor.attributes['roomID'] room = RoomEngine.getRoom(roomID) if cmd != 'go': args = [cmd] if args == None or len(args) == 0: feedbackEvent = Event() feedbackEvent.attributes['signature'] = 'received_feedback' feedbackEvent.attributes['data']['feedback'] = 'Go where?' actor.receiveEvent(feedbackEvent) return moveEvent = Event() moveEvent.attributes['signature'] = 'actor_moved' moveEvent.attributes['data']['direction'] = args[0] moveEvent.attributes['data']['source'] = actor room.receiveEvent(moveEvent)
def addNewConnections(self): ConnectionEngine.lock('newConnectionSemaphore') for connection in ConnectionEngine.attribute('newConnections'): player = connection.attributes['player'] loginEvent = Event() loginEvent.attributes['signature'] = 'player_login' loginEvent.attributes['data']['player'] = player RoomEngine.receiveEvent(loginEvent) ConnectionEngine.attribute('connectionList').append(connection) playerName = player.attributes['name'] loginNotificationEvent = Event() loginNotificationEvent.attributes['signature'] = 'broadcast_to_all_players' loginNotificationEvent.attributes['data']['message'] = '{} just logged in.'.format(playerName) ActorEngine.receiveEvent(loginNotificationEvent) ConnectionEngine.setAttribute('newConnections', []) ConnectionEngine.release('newConnectionSemaphore')
def execute(self, receiver, event): args = event.attributes['data']['args'] actor = event.attributes['data']['source'] roomID = actor.attributes['roomID'] room = RoomEngine.getRoom(roomID) lookEvent = Event() lookEvent.attributes['data']['observer'] = actor if args == None or len(args) == 0: lookEvent.attributes['signature'] = 'was_observed' else: lookEvent.attributes['signature'] = 'actor_observed' lookEvent.attributes['data']['target'] = args[0] room.receiveEvent(lookEvent)
def execute(self, receiver, event): emoteEvent = Event() emoter = event.attributes["data"]["source"] args = event.attributes["data"]["args"] roomID = emoter.attributes["roomID"] room = RoomEngine.getRoom(roomID) data = None if args == None or len(args) == 0: data = self.eventTemplate["untargeted"].copy() data["target"] = None else: data = self.eventTemplate["targeted"].copy() data["target"] = args[0] data["emoter"] = emoter emoteEvent.attributes["signature"] = "actor_emoted" emoteEvent.attributes["data"] = data room.receiveEvent(emoteEvent)