コード例 #1
0
ファイル: Room.py プロジェクト: DaneBettis/python_mud
    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)
コード例 #2
0
	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')