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)
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)
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)
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)
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)
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)
def actorEmoted(self, receiver, event): targetName = event.attributes["data"]["target"] playerList = filter(lambda player: player != event.attributes["data"]["emoter"], receiver.attributes["players"]) target = None if targetName != None and targetName != "": targetList = filter( lambda player: player.attributes["name"].lower().startswith(targetName.lower()), playerList ) 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." emoter.receiveEvent(feedbackEvent) return event.attributes["data"]["target"] = target for player in receiver.attributes["players"]: player.receiveEvent(event)
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 have that.' feedbackEvent.attributes['data']['actor'] = event.attributes['data']['actor'] Engine.ActorEngine.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)
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)
def handleEvent(self, event): receiver = event.attributes['receiver'] if event.attributes['data']['target'] == receiver: description = ['There is nothing interesting about this object.'] descArray = receiver.attributes['description'] if descArray != None and len(descArray) != 0: description = descArray observer = event.attributes['data']['observer'] describeEvent = Event() describeEvent.attributes['signature'] = 'entity_described_self' describeEvent.attributes['data']['description'] = description describeEvent.attributes['data']['observer'] = observer room = Engine.RoomEngine.getRoom(observer.attributes['roomID']) Engine.ActorEngine.emitEvent(describeEvent)
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)
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)
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)
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)
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)
def __init__(self): threading.Thread.__init__(self) EventEmitter.__init__(self, None) tickEvent = Event() tickEvent.attributes['signature'] = 'game_tick' self.tickEvent = tickEvent TickDriver.instance = self
def wasObserved(self, receiver, event): observer = event.attributes['data']['observer'] description = receiver.attributes['description'][:] describeEvent = Event() describeEvent.attributes['signature'] = 'entity_described_self' describeEvent.attributes['data']['description'] = description observer.receiveEvent(describeEvent)
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)
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)
def playerLogin(self, receiver, event): player = event.attributes['data']['player'] roomID = player.attributes['roomID'] room = receiver.getRoom(roomID) playerInEvent = Event() playerInEvent.attributes['signature'] = 'player_entered' playerInEvent.attributes['data']['player'] = player room.receiveEvent(playerInEvent)
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 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)
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 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 ActorEngine.playerExists(playerInput) == True: player = ActorEngine.loadPlayer(playerInput) connection = Connection(clientsocket, player) loginEvent = Event() player.attributes['connection'] = connection loginEvent.attributes['signature'] = 'player_login' loginEvent.attributes['data']['player'] = player ActorEngine.receiveEvent(loginEvent) ConnectionEngine.receiveEvent(loginEvent) else: clientsocket.send('\n\rPlayer not found.\n\rEnter your name:') playerInput = '' else: playerInput = '' sleep(2)
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)
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)
def handleEvent(self, event): receiver = event.attributes['receiver'] target = event.attributes['data']['target'] if target == receiver: describeEvent = Event() describeEvent.attributes['signature'] = 'entity_described_self' describeEvent.attributes['data']['room'] = receiver.attributes['roomID'] describeEvent.attributes['data']['observer'] = event.attributes['data']['observer'] describeEvent.attributes['data']['description'] = receiver.getDescription() Engine.ActorEngine.emitEvent(describeEvent)
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)
def playerLogout(self, receiver, event): 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 room.receiveEvent(logoutEvent)
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)
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)
def broadcastToAllPlayers(self, receiver, event): receiver.attributes['playerSetSemaphore'].acquire(); message = event.attributes['data']['message'] notificationEvent = Event() notificationEvent.attributes['signature'] = 'received_notification' notificationEvent.attributes['data']['message'] = message for player in receiver.attributes['playerList']: player.receiveEvent(notificationEvent) receiver.attributes['playerSetSemaphore'].release();
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)
def transition(self, event): receiver = event.attributes['receiver'] room = Engine.RoomEngine.getRoom(receiver.attributes['roomID']) exitList = filter(lambda exit : exit.attributes['name'] == self.attributes['direction'], room.attributes['exits']) if len(exitList) > 0: commandEvent = Event() commandEvent.attributes['signature'] = 'execute_command' commandEvent.attributes['data']['command'] = 'go' commandEvent.attributes['data']['args'] = [exitList[0]] commandEvent.attributes['data']['source'] = receiver Engine.ActorEngine.emitEvent(commandEvent)
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();
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)
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)
def processInput(self, player, inputStr): parsedInput = inputStr.split(' ') if len(parsedInput) > 0: cmd = parsedInput[0] args = parsedInput[1:] commandEvent = Event() commandEvent.attributes['signature'] = 'execute_command' commandEvent.attributes['data']['command'] = cmd commandEvent.attributes['data']['args'] = args commandEvent.attributes['data']['source'] = player CommandEngine.receiveEvent(commandEvent)
def playerExited(self, receiver, event): actor = event.attributes["data"]["actor"] receiver.removePlayer(actor) message = event.attributes["data"]["exitMessage"] if message != None and message != "": for p in receiver.attributes["players"]: feedbackEvent = Event() feedbackEvent.attributes["signature"] = "received_feedback" feedbackEvent.attributes["data"]["feedback"] = message p.receiveEvent(feedbackEvent)
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)
def handleEvent(self, event): receiver = event.attributes['receiver'] if random.random() < receiver.attributes['spawnRate']: newNPC = Engine.ActorEngine.loadNPC(receiver.attributes['npcID']) newNPC.attributes['roomID'] = receiver.attributes[ 'room'].attributes['roomID'] spawnEvent = Event() spawnEvent.attributes['signature'] = 'actor_added_to_room' spawnEvent.attributes['data']['room'] = receiver.attributes['room'] spawnEvent.attributes['data']['actor'] = newNPC receiver.attributes['room'].addEventSubscriber(newNPC) Engine.RoomEngine.emitEvent(spawnEvent) receiver.attributes['npcs'].append(newNPC)
def handleEvent(self, event): receiver = event.attributes['receiver'] actor = receiver.attributes['owner'] equipString = ' nothing' equipment = receiver.listEquipment() if len(equipment) != 0: equipString = '' for line in equipment: equipString = '{}\n{}'.format(equipString, line) feedbackEvent = Event() feedbackEvent.attributes['signature'] = 'received_feedback' feedbackEvent.attributes['data']['feedback'] = 'You are wearing:{}\n'.format(equipString) feedbackEvent.attributes['data']['actor'] = actor Engine.ActorEngine.emitEvent(feedbackEvent)
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)
def removeClosedConnections(self): Engine.ConnectionEngine.lock('closedConnectionSemaphore') for connection in Engine.ConnectionEngine.attribute('closedConnections'): Engine.ConnectionEngine.attribute('connectionList').remove(connection) connection.attributes['socket'].close() player = connection.attributes['player'] playerName = player.attributes['name'] logoutNotificationEvent = Event() logoutNotificationEvent.attributes['signature'] = 'broadcast_to_all_players' logoutNotificationEvent.attributes['data']['message'] = '{} logged off.'.format(playerName) self.emitEvent(logoutNotificationEvent) Engine.ConnectionEngine.setAttribute('closedConnections', []) Engine.ConnectionEngine.release('closedConnectionSemaphore')
def handleEvent(self, event): receiver = event.attributes['receiver'] option = event.attributes['data']['option'] validOptions = receiver.attributes['options'] player = receiver.attributes['player'] if validOptions.has_key(option): tuple = validOptions[option] function = tuple[1] function() else: feedbackEvent = Event() feedbackEvent.attributes['signature'] = 'received_feedback' feedbackEvent.attributes['data']['feedback'] = ANSI.yellow( 'Invalid option!') feedbackEvent.attributes['data']['actor'] = player Engine.ActorEngine.emitEvent(feedbackEvent)
def handleEvent(self, event): receiver = event.attributes['receiver'] itemName = event.attributes['data']['itemName'] args = event.attributes['data']['args'] itemNumber = 0 equipment = filter(lambda element: element != None and element.attributes['name'].lower().startswith(itemName.lower()), [receiver.attributes['equipment']['Head'], receiver.attributes['equipment']['Ears'], receiver.attributes['equipment']['Eyes'], receiver.attributes['equipment']['Face'], receiver.attributes['equipment']['Neck'][0], receiver.attributes['equipment']['Neck'][1], receiver.attributes['equipment']['Body'], receiver.attributes['equipment']['Arms'], receiver.attributes['equipment']['Wrist'][0], receiver.attributes['equipment']['Wrist'][1], receiver.attributes['equipment']['Hands'], receiver.attributes['equipment']['Finger'][0], receiver.attributes['equipment']['Finger'][1], receiver.attributes['equipment']['Waist'], receiver.attributes['equipment']['Legs'], receiver.attributes['equipment']['Feet'], receiver.attributes['equipment']['Shield'], receiver.attributes['equipment']['Wielded']]) 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(equipment): event.attributes['data']['item'] = equipment[itemNumber] receiver.emitEvent(event) else: feedbackEvent = Event() feedbackEvent.attributes['signature'] = 'received_feedback' feedbackEvent.attributes['data']['actor'] = event.attributes['data']['actor'] feedbackEvent.attributes['data']['feedback'] = 'Remove what?' Engine.ActorEngine.emitEvent(feedbackEvent)
def execute(self, source, args): equipEvent = Event() equipEvent.attributes['data']['actor'] = source if args == None or len(args) == 0: equipEvent.attributes['signature'] = 'received_feedback' equipEvent.attributes['data']['feedback'] = 'Wear what?' else: if len(args) == 1: args.append('') equipEvent.attributes['signature'] = 'actor_attempted_item_equip' equipEvent.attributes['data']['itemName'] = args[0] equipEvent.attributes['data']['args'] = args[1:] equipEvent.attributes['data']['command'] = 'wear' Engine.ActorEngine.emitEvent(equipEvent)
def execute(self, source, args): emoteEvent = Event() emoter = source roomID = emoter.attributes['roomID'] room = Engine.RoomEngine.getRoom(roomID) eventData = None if args == None or len(args) == 0: eventData = self.eventTemplate['untargeted'].copy() eventData['target'] = None else: eventData = self.eventTemplate['targeted'].copy() eventData['target'] = args[0] eventData['emoter'] = emoter eventData['room'] = room eventData['command'] = 'emote' emoteEvent.attributes['signature'] = 'actor_emoted' emoteEvent.attributes['data'] = eventData Engine.RoomEngine.emitEvent(emoteEvent)
def execute(self): emoteEvent = Event() eventData = None source = self.attributes['source'] target = self.attributes['target'] roomID = source.attributes['roomID'] room = Engine.RoomEngine.getRoom(roomID) if target == source: eventData = self.attributes['template']['untargeted'].copy() eventData['target'] = None else: eventData = self.attributes['template']['targeted'].copy() eventData['target'] = target.attributes['name'] eventData['emoter'] = source emoteEvent.attributes['signature'] = 'actor_emoted' emoteEvent.attributes['data'] = eventData emoteEvent.attributes['data']['room'] = room Engine.RoomEngine.emitEvent(emoteEvent)
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)
def handleEvent(self, event): receiver = event.attributes['receiver'] cmdName = event.attributes['data']['command'] if cmdName == 'quit': player = event.attributes['data']['source'] connection = player.attributes['connection'] logoutEvent = Event() logoutEvent.attributes['signature'] = 'player_logout' logoutEvent.attributes['data']['connection'] = connection receiver.emitEvent(logoutEvent) else: commandList = receiver.attributes['commandList'] command = commandList['select'] source = event.attributes['data']['source'] if commandList.has_key(cmdName): command = commandList[cmdName] args = event.attributes['data']['args'] else: args = [cmdName] command.execute(source, args)
def execute(self, source, args): removeEvent = Event() removeEvent.attributes['data']['actor'] = source if args == None or len(args) == 0: removeEvent.attributes['signature'] = 'received_feedback' removeEvent.attributes['data']['feedback'] = 'Remove what?' else: if len(args) == 1: args.append('') removeEvent.attributes[ 'signature'] = 'actor_attempted_item_removal' removeEvent.attributes['data']['itemName'] = args[0] removeEvent.attributes['data']['args'] = args[1:] Engine.ActorEngine.emitEvent(removeEvent)