示例#1
0
	def handleEvent(self, event):
		receiver = event.attributes['receiver']
		
		if event.attributes['data']['room'] == receiver:
			observer	= event.attributes['data']['observer']
			target		= event.attributes['data']['target']
			players		= receiver.attributes['players']
			npcs		= receiver.attributes['npcs']
			inventory	= receiver.attributes['inventory']
			items		= inventory.attributes['items']
			permItems	= inventory.attributes['permanent_items']
			hiddenItems = inventory.attributes['hidden_items']
			mergedList	= players + npcs + items + permItems + hiddenItems
			
			if target in set(mergedList):
				lookEvent									= Event()
				lookEvent.attributes['data']['observer']	= observer
				lookEvent.attributes['data']['target']		= target
				lookEvent.attributes['signature']			= 'was_observed'

				receiver.emitEvent(lookEvent)
			else:
				feedbackEvent									= Event()
				feedbackEvent.attributes['signature']			= 'received_feedback'
				feedbackEvent.attributes['data']['feedback']	= 'You don\'t see that here.'
				feedbackEvent.attributes['data']['actor']		= observer

				receiver.emitEvent(feedbackEvent)
示例#2
0
	def handleEvent(self, event):
		receiver	= event.attributes['receiver']
		item		= event.attributes['data']['item']
		actor		= event.attributes['data']['actor']
		slot		= item.attributes['itemClass']
		equipment	= receiver.attributes['equipment']
		slotFull	= (lambda eq, sl: 
							eq[sl] != None and
							(type(eq[sl]) != type([]) or (eq[sl][0] != None and eq[sl][1] != None)))(equipment, slot)
		
		if slotFull:
			feedbackEvent								= Event()
			feedbackEvent.attributes['signature']		= 'received_feedback'
			feedbackEvent.attributes['data']['actor']	= actor
			
			if slot == 'Wielded':
				feedbackEvent.attributes['data']['feedback'] = 'You already have something wielded.'
			else:
				feedbackEvent.attributes['data']['feedback'] = 'You\'re already wearing something on your {}.'.format(slot.lower())

			Engine.ActorEngine.emitEvent(feedbackEvent)
		else:
			if equipment[slot] != None:
				if equipment[slot][0] == None:
					equipment[slot][0] = item
				else:
					equipment[slot][1] = item
			else:
				equipment[slot] = item
			
			receiver.attributes['items'].remove(item)

			receiver.emitEvent(event)
			
			emoteEvent	= Event()
			emoter		= actor
			roomID		= emoter.attributes['roomID']
			room		= Engine.RoomEngine.getRoom(roomID)
			
			emoteEvent.attributes['signature']	= 'actor_emoted'
			emoteEvent.attributes['data']		= {
														'target':None,
														'emoter': actor,
														'room': room,
														"emoterText":"You {} the {}.".format(event.attributes['data']['equipperVerb'], item.attributes['name']),
														"audienceText":"#emoter# {} {} {}.".format(event.attributes['data']['audienceVerb'], item.attributes['adjective'], item.attributes['name'])
			}

			Engine.RoomEngine.emitEvent(emoteEvent)
示例#3
0
    def execute(self, source, args):
        if args == None or len(args) == 0:
            feedbackEvent = Event()
            feedbackEvent.attributes['signature'] = 'received_feedback'
            feedbackEvent.attributes['data'][
                'feedback'] = 'Select which option?'
            feedbackEvent.attributes['data']['actor'] = actor

            Engine.ActorEngine.emitEvent(feedbackEvent)
        else:
            selectEvent = Event()
            selectEvent.attributes['signature'] = 'menu_option_chosen'
            selectEvent.attributes['data']['option'] = args[0]

            source.attributes['menus'][-1].receiveEvent(selectEvent, None)
示例#4
0
    def handleEvent(self, event):
        receiver = event.attributes['receiver']
        target = event.attributes['data']['itemName']
        targetList = filter(
            lambda item: item.attributes['name'].lower().startswith(
                target.lower()), receiver.attributes['items'])

        if len(targetList) == 0:
            feedbackEvent = Event()
            feedbackEvent.attributes['signature'] = 'received_feedback'
            feedbackEvent.attributes['data'][
                'feedback'] = 'You don\'t see that.'
            feedbackEvent.attributes['data']['actor'] = event.attributes[
                'data']['actor']

            event.attributes['data']['room'].emitEvent(feedbackEvent)
        else:
            event.attributes['data']['item'] = targetList[0]
            args = event.attributes['data']['args']

            if len(args) >= 1 and args[0] != '':
                if pattern.match(args[0]) and re.search('[^0-9]',
                                                        args[0]) == None:
                    itemNumber = int(args[0]) - 1

                    if itemNumber < len(targetList):
                        event.attributes['data']['item'] = targetList[
                            itemNumber]

            receiver.emitEvent(event)
示例#5
0
	def handleEvent(self, event):
		receiver = event.attributes['receiver']

		if event.attributes['data']['room'] == receiver:			
			source		= event.attributes['data']['source']
			targetName	= event.attributes['data']['target']
			spell		= event.attributes['data']['spell']
			target		= None
			
			if targetName == None:
				target = source
			else:
				targetList	= filter(lambda actor : 
										actor.attributes['name'].lower().startswith(targetName.lower()), 
									receiver.attributes['players'] + receiver.attributes['npcs'])

				if len(targetList) == 0:
					feedbackEvent									= Event()
					feedbackEvent.attributes['signature']			= 'received_feedback'
					feedbackEvent.attributes['data']['feedback']	= 'You don\'t see that here.'
					feedbackEvent.attributes['data']['actor']		= source

					receiver.emitEvent(feedbackEvent)
				else:
					target = targetList[0]
			
			Engine.AffectEngine.executeAffect(spell, source, target)
示例#6
0
	def handleEvent(self, event):
		receiver = event.attributes['receiver']

		if event.attributes['data']['room'] == receiver:
			targetName	= event.attributes['data']['target']
			target		= None
			actorList	= filter(lambda actor: 
									actor != event.attributes['data']['emoter'],
								receiver.attributes['players'] + receiver.attributes['npcs'])

			if targetName != None and targetName != '':
				targetList	= filter(lambda actor : 
										actor.attributes['name'].lower().startswith(targetName.lower()),
									 actorList)

				if len(targetList) > 0:
					target = targetList[0]
				else:
					emoter											= event.attributes['data']['emoter']
					feedbackEvent									= Event()
					feedbackEvent.attributes['signature']			= 'received_feedback'
					feedbackEvent.attributes['data']['feedback']	= 'You don\'t see that here.'
					feedbackEvent.attributes['data']['actor']		= emoter

					receiver.emitEvent(feedbackEvent)

					return

			event.attributes['data']['target'] = target	

			receiver.emitEvent(event)
示例#7
0
 def _doLogic(self, index):
     lastValue = self._analyseKLine.getDifByIndex(
         index - 1) - self._analyseKLine.getDeaByIndex(index - 1)
     value = self._analyseKLine.getDifByIndex(
         index) - self._analyseKLine.getDeaByIndex(index)
     ret = None
     if lastValue > 0 and value < 0:  # 此处肯定为绿柱的起始点
         dataFragment = self._analyseKLine.getDataFragmentByIndex(index)
         if dataFragment is None:
             raise IndexError
         fragmentIndex = self._analyseKLine.getDataFragments().index(
             dataFragment)
         if fragmentIndex >= 3:  # 至少要有两组红柱,计算逻辑才能产生事件
             dataFragment1 = self._analyseKLine.getDataFragments()[
                 fragmentIndex - 1]
             dataFragment2 = self._analyseKLine.getDataFragments()[
                 fragmentIndex - 3]  # 1和3 为相邻两组红柱
             from Stock.AnalyseKLine import StockPillar
             if dataFragment1.getStockPillar(
             ) == StockPillar.RED and dataFragment2.getStockPillar(
             ) == StockPillar.RED:
                 # 此两组fragment一定为红柱否则整个K线是错误的
                 # print("间隔2个的红柱")
                 if dataFragment1.getMax() < dataFragment2.getMax():
                     ret = Event()
                     ret.setBIndex(index)
                     ret.setEIndex(index)
                     ret.setEventIndex(index)
                     ret.setEventType(EventType.HIGH_TO_LOW)
                     ret.setEventValue(value)
     return ret
示例#8
0
	def execute(self, source, args):
		actor		= source
		words		= args
		roomID		= actor.attributes['roomID']
		room		= Engine.RoomEngine.getRoom(roomID)
		speakEvent	= Event()
		
		speakEvent.attributes['signature']			= 'actor_emoted'
		speakEvent.attributes['data']['emoter']		= actor
		speakEvent.attributes['data']['target']		= None
		speakEvent.attributes['data']['room']		= room
		speakEvent.attributes['data']['command']	= 'say'

		if words == None or len(words) == 0:
			speakEvent.attributes['data']['emoterText']		= 'Say what?'
			speakEvent.attributes['data']['audienceText']	= None		
		else:	
			sentence = ''
		
			for word in words:
				sentence										= '{} {}'.format(sentence, word)
				speakEvent.attributes['data']['emoterText']		= 'You say, "{}".'.format(sentence[1:])
				speakEvent.attributes['data']['audienceText']	= '{} says, "{}".'.format(actor.attributes['name'], sentence[1:])
		
		Engine.RoomEngine.emitEvent(speakEvent)
示例#9
0
    def execute(self):
        healEvent = Event()
        healEvent.attributes['signature'] = 'gained_health'
        healEvent.attributes['data']['target'] = self.attributes['target']
        healEvent.attributes['data']['amount'] = self.attributes['amount']

        Engine.ActorEngine.emitEvent(healEvent)
示例#10
0
    def sendUnknownAffectFeedbackEvent(self, actor):
        feedbackEvent = Event()
        feedbackEvent.attributes['signature'] = 'received_feedback'
        feedbackEvent.attributes['data']['feedback'] = 'Cast what?'
        feedbackEvent.attributes['data']['actor'] = actor

        Engine.ActorEngine.emitEvent(feedbackEvent)
示例#11
0
	def handleEvent(self, event):
		receiver	= event.attributes['receiver']
		observer	= event.attributes['data']['observer']
		target		= event.attributes['data']['target']
		items		= receiver.attributes['items']
		equipment	= receiver.attributes['equipment']
		equipped	= []
		
		for key in equipment.keys():
			equippedItem = equipment[key]
			
			if key == 'Neck' or key == 'Wrist' or key == 'Finger':
				for item in equippedItem:
					if item != None:
						equipped.append(item)
			else:
				if equippedItem != None:
					equipped.append(equippedItem)
		
		if target != None and target in set(items + equipped):
			lookEvent									= Event()
			lookEvent.attributes['data']['observer']	= observer
			lookEvent.attributes['data']['target']		= target
			lookEvent.attributes['signature']			= 'was_observed'

			receiver.emitEvent(lookEvent)
		else:
			#The actor meant to look at the room, or something in it
			if target == None:
				event.attributes['signature'] = 'was_observed'
			
			Engine.RoomEngine.emitEvent(event)
示例#12
0
	def handleEvent(self, event):
		receiver	= event.attributes['receiver']
		item		= event.attributes['data']['item']
		actor		= event.attributes['data']['actor']
		slot		= item.attributes['itemClass']
		equipment	= receiver.attributes['equipment']
		
		if type(equipment[slot]) == type([]):
			if equipment[slot][0] == item:
				equipment[slot][0] = None
			else:
				equipment[slot][1] = None
		else:
			equipment[slot] = None
			
		receiver.attributes['items'].append(item)
		
		receiver.emitEvent(event)
		
		emoteEvent	= Event()
		emoter		= actor
		roomID		= emoter.attributes['roomID']
		room		= Engine.RoomEngine.getRoom(roomID)
		
		emoteEvent.attributes['signature']		= 'actor_emoted'
		emoteEvent.attributes['data']			= {
														'target'		: None,
														'emoter'		: actor,
														'room'			: room,
														"emoterText"	: "You removed the {}.".format(item.attributes['name']),
														"audienceText"	: "#emoter# removed {} {}.".format(item.attributes['adjective'], item.attributes['name'])
			}

		Engine.RoomEngine.emitEvent(emoteEvent)
示例#13
0
    def execute(self, source, args):
        feedbackEvent = Event()
        feedbackEvent.attributes['signature'] = 'received_feedback'
        feedbackEvent.attributes['data'][
            'feedback'] = Engine.ActorEngine.getPlayerList()
        feedbackEvent.attributes['data']['actor'] = source

        Engine.ActorEngine.emitEvent(feedbackEvent)
示例#14
0
	def __init__(self):
		threading.Thread.__init__(self)
		EventEmitter.__init__(self, None)
		
		tickEvent				= Event()
		tickEvent.attributes['signature']	= 'game_tick'
		self.tickEvent				= tickEvent
		TickDriver.instance			= self
示例#15
0
    def execute(self, source, args):
        feedbackEvent = Event()
        feedbackEvent.attributes['signature'] = 'received_feedback'
        feedbackEvent.attributes['data']['feedback'] = source.attributes[
            'inventory'].listItems()
        feedbackEvent.attributes['data']['actor'] = source

        Engine.ActorEngine.emitEvent(feedbackEvent)
示例#16
0
    def insertCommand(self, command, args=None):
        commandEvent = Event()

        commandEvent.attributes['signature'] = 'execute_command'
        commandEvent.attributes['data']['command'] = command
        commandEvent.attributes['data']['args'] = args
        commandEvent.attributes['data']['source'] = self

        Engine.ActorEngine.emitEvent(commandEvent)
示例#17
0
    def run(self):
        serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        hostname = socket.gethostname()  #hack to get my host name

        try:
            tokenized = hostname.split('.')
            hostname = '{}.{}.{}.{}'.format(tokenized[3], tokenized[2],
                                            tokenized[1], tokenized[0])
        except:
            hostname = 'localhost'

        print socket.gethostname()
        print hostname

        serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        serversocket.bind((hostname, 8888))
        serversocket.listen(5)

        while True:
            clientsocket = serversocket.accept()[0]

            clientsocket.setblocking(False)

            clientsocket.send('\n\rWelcome! Enter your name:\n\r')

            playerInput = ''

            while playerInput == '':
                try:
                    playerInput = clientsocket.recv(1024)
                except:
                    playerInput = ''

                if len(playerInput) > 0:
                    playerInput = playerInput.strip()

                    if Engine.ActorEngine.playerExists(playerInput) == True:
                        player = Engine.ActorEngine.loadPlayer(playerInput)
                        connection = Connection(clientsocket, player)
                        loginEvent = Event()

                        player.attributes['connection'] = connection
                        loginEvent.attributes['signature'] = 'player_login'
                        loginEvent.attributes['data']['player'] = player

                        self.emitEvent(loginEvent)
                    else:
                        clientsocket.send(
                            '\n\rPlayer not found.\n\rEnter your name:')

                        playerInput = ''
                else:
                    playerInput = ''

            sleep(2)
示例#18
0
文件: NPC.py 项目: longstl/python_mud
    def wander(self):
        from Event.Event import Event
        import Engine.ActorEngine

        commandEvent = Event()
        commandEvent.attributes['signature'] = 'execute_command'
        commandEvent.attributes['data']['command'] = 'go'
        commandEvent.attributes['data']['args'] = 'n'
        commandEvent.attributes['data']['source'] = self

        Engine.ActorEngine.emitEvent(commandEvent)
示例#19
0
    def handleEvent(self, event):
        actor = event.attributes['receiver']
        con = actor.attributes['stats']['constitution']
        focus = actor.attributes['stats']['focus']

        healEvent = Event()
        healEvent.attributes['signature'] = 'gained_health_from_tick'
        healEvent.attributes['data']['hp'] = int(con / 3)
        healEvent.attributes['data']['mana'] = int(focus / 3)
        healEvent.attributes['event_target'] = actor

        Engine.ActorEngine.emitEvent(healEvent)
示例#20
0
文件: NPC.py 项目: longstl/python_mud
    def transition(self, event):
        receiver = event.attributes['receiver']
        actor = event.attributes['data']['actor']

        if actor != receiver:
            commandEvent = Event()
            commandEvent.attributes['signature'] = 'execute_command'
            commandEvent.attributes['data']['command'] = 'wave'
            commandEvent.attributes['data']['args'] = actor.attributes['name']
            commandEvent.attributes['data']['source'] = receiver

            Engine.ActorEngine.emitEvent(commandEvent)
示例#21
0
	def handleEvent(self, event):
		receiver = event.attributes['receiver']
		
		if event.attributes['data']['room'] == receiver:
			actor		= event.attributes['data']['source']
			direction	= event.attributes['data']['direction']
		
			if direction != None:
				movedFromEvent								= Event()
				movedFromEvent.attributes['signature']		= 'actor_moved_from_room'
				movedFromEvent.attributes['data']['actor']	= actor
				movedFromEvent.attributes['data']['exit']	= direction
				movedFromEvent.attributes['data']['room']	= receiver
			
				movedToEvent								= Event()
				movedToEvent.attributes['signature']		= 'actor_added_to_room'
				movedToEvent.attributes['data']['actor']	= actor
				movedToEvent.attributes['data']['room']		= Engine.RoomEngine.getRoom(direction.attributes['destination'])
				
				Engine.RoomEngine.emitEvent(movedFromEvent)
				Engine.RoomEngine.emitEvent(movedToEvent)
示例#22
0
	def adjustEvent(self, event):
		receiver = event.attributes['receiver']
		
		if event.attributes['data']['command'] == 'say':
			event.attributes['signature'] = None
			
			feedbackEvent									= Event()
			feedbackEvent.attributes['signature']			= 'received_feedback'
			feedbackEvent.attributes['data']['feedback']	= 'No sound escapes your lips.'
			feedbackEvent.attributes['data']['actor']		= event.attributes['data']['emoter']
			
			receiver.emitEvent(feedbackEvent)
示例#23
0
    def handleEvent(self, event):
        receiver = event.attributes['receiver']
        player = event.attributes['data']['player']
        roomID = player.attributes['roomID']
        room = receiver.getRoom(roomID)
        playerInEvent = Event()

        playerInEvent.attributes['signature'] = 'actor_added_to_room'
        playerInEvent.attributes['data']['actor'] = player
        playerInEvent.attributes['data']['room'] = room

        receiver.emitEvent(playerInEvent)
示例#24
0
 def _doLogic(self, index):
     ret = None
     difIndex = self._analyseKLine.getDifByIndex(index)
     if self.__difNewHigh < difIndex:
         if index == self._index:
             ret = Event()
             ret.setBIndex(index)
             ret.setEIndex(index)
             ret.setEventIndex(index)
             ret.setEventType(EventType.NEW_HIGH_DIF)
             ret.setEventValue(difIndex)
         self.__difNewHigh = difIndex
     return ret
示例#25
0
    def handleEvent(self, event):
        receiver = event.attributes['receiver']
        connection = event.attributes['data']['connection']
        player = connection.attributes['player']
        roomID = player.attributes['roomID']
        room = receiver.getRoom(roomID)
        logoutEvent = Event()

        logoutEvent.attributes['signature'] = 'player_logout'
        logoutEvent.attributes['data']['actor'] = player
        logoutEvent.attributes['data']['exitMessage'] = None

        receiver.emitEvent(logoutEvent)
示例#26
0
 def _doLogic(self, index):
     lastValue = self._analyseKLine.getDifByIndex(
         index - 1) - self._analyseKLine.getDeaByIndex(index - 1)
     value = self._analyseKLine.getDifByIndex(
         index) - self._analyseKLine.getDeaByIndex(index)
     ret = None
     if lastValue > 0 and value < 0:
         ret = Event()
         ret.setBIndex(index)
         ret.setEIndex(index)
         ret.setEventIndex(index)
         ret.setEventType(EventType.DEAD_FORK)
         ret.setEventValue(value)
     return ret
示例#27
0
	def execute(self, source, args):	
		if args == None or len(args) == 0:
			args = ['']
			
		if len(args) == 1:
			args.append('')
	
		dropEvent									= Event()
		dropEvent.attributes['signature']			= 'actor_attempted_item_drop'
		dropEvent.attributes['data']['itemName']	= args[0]
		dropEvent.attributes['data']['args']		= args[1:]
		dropEvent.attributes['data']['actor']		= source
	
		Engine.ActorEngine.emitEvent(dropEvent)
示例#28
0
	def handleEvent(self, event):
		receiver = event.attributes['receiver']
		
		receiver.attributes['playerSetSemaphore'].acquire();

		message											= event.attributes['data']['message']
		notificationEvent								= Event()
		notificationEvent.attributes['signature']		= 'received_notification'
		notificationEvent.attributes['data']['message'] = message
		notificationEvent.attributes['data']['actor']	= None

		receiver.emitEvent(notificationEvent)
		
		receiver.attributes['playerSetSemaphore'].release();
示例#29
0
	def addNewConnections(self):
		Engine.ConnectionEngine.lock('newConnectionSemaphore')
		
		for connection in Engine.ConnectionEngine.attribute('newConnections'):
			player									= connection.attributes['player']
			loginEvent								= Event()
			loginEvent.attributes['signature']		= 'player_login'
			loginEvent.attributes['data']['player'] = player

			self.emitEvent(loginEvent)
			
			Engine.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)
		
			self.emitEvent(loginNotificationEvent)
		
		Engine.ConnectionEngine.setAttribute('newConnections', [])
		
		Engine.ConnectionEngine.release('newConnectionSemaphore')
示例#30
0
    def execute(self, source, args):
        if args == None or len(args) == 0:
            args = ['']

        if len(args) == 1:
            args.append('')

        getEvent = Event()
        getEvent.attributes['signature'] = 'actor_initiated_item_grab'
        getEvent.attributes['data']['itemName'] = args[0]
        getEvent.attributes['data']['args'] = args[1:]
        getEvent.attributes['data']['actor'] = source

        Engine.ActorEngine.emitEvent(getEvent)