def getDescription(self): description = [ANSI.yellow("You see {} the {}.".format(self.attributes["name"], self.attributes["race"]))] if len(self.attributes["description"]) > 0: for line in self.attributes["description"]: description.append(ANSI.cyan(line)) equipment = self.attributes["inventory"].listEquipment() if len(equipment) > 0: description = description + equipment return description
def getDescription(self): description = [ ANSI.yellow('You see {} the {}.'.format(self.attributes['name'], self.attributes['race'])) ] if len(self.attributes['description']) > 0: for line in self.attributes['description']: description.append(ANSI.cyan(line)) equipment = self.attributes['inventory'].listEquipment() if len(equipment) > 0: description = description + equipment return description
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 listEquipment(self): equipArray = [] equipment = filter(lambda item: item != None, [ self.attributes['equipment']['Head'], self.attributes['equipment']['Ears'], self.attributes['equipment']['Eyes'], self.attributes['equipment']['Face'], self.attributes['equipment']['Neck'][0], self.attributes['equipment']['Neck'][1], self.attributes['equipment']['Body'], self.attributes['equipment']['Arms'], self.attributes['equipment']['Wrist'][0], self.attributes['equipment']['Wrist'][1], self.attributes['equipment']['Hands'], self.attributes['equipment']['Finger'][0], self.attributes['equipment']['Finger'][1], self.attributes['equipment']['Waist'], self.attributes['equipment']['Legs'], self.attributes['equipment']['Feet'], self.attributes['equipment']['Shield'], self.attributes['equipment']['Wielded'] ]) for item in equipment: slot = item.attributes['itemClass'] equipArray.append('{}\t: {} {}'.format( ANSI.yellow(slot), item.attributes['adjective'], item.attributes['name'])) return equipArray
def listEquipment(self): equipArray = [] equipment = filter(lambda item: item != None, [self.attributes['equipment']['Head'], self.attributes['equipment']['Ears'], self.attributes['equipment']['Eyes'], self.attributes['equipment']['Face'], self.attributes['equipment']['Neck'][0], self.attributes['equipment']['Neck'][1], self.attributes['equipment']['Body'], self.attributes['equipment']['Arms'], self.attributes['equipment']['Wrist'][0], self.attributes['equipment']['Wrist'][1], self.attributes['equipment']['Hands'], self.attributes['equipment']['Finger'][0], self.attributes['equipment']['Finger'][1], self.attributes['equipment']['Waist'], self.attributes['equipment']['Legs'], self.attributes['equipment']['Feet'], self.attributes['equipment']['Shield'], self.attributes['equipment']['Wielded']]) for item in equipment: slot = item.attributes['itemClass'] equipArray.append('{}\t: {} {}'.format(ANSI.yellow(slot), item.attributes['adjective'], item.attributes['name'])) return equipArray
def sendFinal(self, message): self.send(message) self.send('\n\r{}\n\r\t{} {}\n\r\t{} {}\n\r\t{}{}\n\r{}: '.format( ANSI.magenta('['), ANSI.yellow('HP:'), ANSI.white(self.attributes['player'].attributes['currentHP']), ANSI.yellow('Mana:'), ANSI.white(self.attributes['player'].attributes['currentMana']), ANSI.yellow('Options:'), self.attributes['player'].attributes['menus'][-1].getOptions(), ANSI.magenta(']')))
def wasObserved(self, receiver, event): player = event.attributes["data"]["observer"] description = [ANSI.red(receiver.attributes["name"]) + "\n\r"] exitList = "Obvious exits:" playerList = filter(lambda p: p != player, receiver.attributes["players"]) for line in receiver.attributes["description"]: description.append(line) for exit in receiver.attributes["exits"]: if exit.attributes["isHidden"] == False: exitList = exitList + " " + exit.attributes["name"] + "," if exitList == "Obvious exits:": exitList = "Obvious exits: none" if exitList.endswith(","): exitList = exitList[0:-1] description.append(ANSI.blue(exitList)) if len(playerList) > 0: playerLine = "Players:" for p in playerList: playerLine = playerLine + " " + p.attributes["name"] + "," if playerLine.endswith(","): playerLine = playerLine[0:-1] description.append(ANSI.green(playerLine)) describeEvent = Event() describeEvent.attributes["signature"] = "entity_described_self" describeEvent.attributes["data"]["description"] = description player.receiveEvent(describeEvent)
def sendFinal(self, message): self.send(message) self.send( ANSI.magenta("\n\r[") + ANSI.yellow("HP: ") + ANSI.white(self.attributes["player"].attributes["currentHP"]) + ANSI.yellow(" Mana: ") + ANSI.white(self.attributes["player"].attributes["currentMana"]) + ANSI.magenta("]: ") )
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'] 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'] if event.attributes['data']['room'] == receiver: player = event.attributes['data']['observer'] description = [ANSI.red(receiver.attributes['name']) + '\n\r'] exitList = 'Obvious exits:' playerList = filter(lambda p: p != player, receiver.attributes['players']) npcList = receiver.attributes['npcs'] for line in receiver.attributes['description']: description.append(line) for exit in receiver.attributes['exits']: if exit.attributes['isHidden'] == False: exitList = exitList + ' ' + exit.attributes['name'] + ',' if exitList == 'Obvious exits:': exitList = 'Obvious exits: none' if exitList.endswith(','): exitList = exitList[0:-1] description.append(ANSI.blue(exitList)) if len(playerList) > 0: playerLine = 'Players:' for p in playerList: playerLine = playerLine + ' ' + p.attributes['name'] + ',' if playerLine.endswith(','): playerLine = playerLine[0:-1] description.append(ANSI.green(playerLine)) if len(npcList) > 0: npcLine = 'NPCs:' listedNPCs = [] for npc in npcList: npcName = npc.attributes['name'] if npcName not in set(listedNPCs): listedNPCs.append(npcName) reducedList = filter(lambda element: element.attributes['name'] == npcName, npcList) adjective = npc.attributes['adjective'] if len(reducedList) > 1: adjective = '{}'.format(len(reducedList)) npcName = npc.attributes['pluralName'] if len(adjective) > 0: npcLine = '{} {} {},'.format(npcLine, adjective, npcName) else: npcLine = '{} {}'.format(npcLine, npcName) if npcLine.endswith(','): npcLine = npcLine[0:-1] description.append(npcLine) inventory = receiver.attributes['inventory'] itemList = inventory.describe() if itemList != '': description.append(itemList) describeEvent = Event() describeEvent.attributes['signature'] = 'entity_described_self' describeEvent.attributes['data']['description'] = description describeEvent.attributes['data']['observer'] = player receiver.emitEvent(describeEvent)