def loadRooms(self): import copy rooms = self.db.rooms.find() for i in range(0, rooms.count()): # default is zero newRoom = Room(self, rooms[i]) print newRoom print rooms[i] newRoom.id = rooms[i]['id'] if 'items' in rooms[i]: for item in rooms[i]['items']:# newRoom.items.append(copy.deepcopy(self.items[item])) if 'npcs' in rooms[i]: for mobile in rooms[i]['npcs']: m = Mobile(self.mobile_list[mobile]['name'], self, self.mobile_list[mobile]) m.room = newRoom self.mobiles.append(m) self.rooms.append(newRoom) # have to load all the rooms BEFORE loading the exits for i in range(0, rooms.count()): exits = rooms[i]['exits'] for e in exits: exit = exits[e] target_room = next(room for room in self.rooms if room.id == exit['target']) direction = exit['direction'] self.rooms[i].exits.append(Exit(direction.lower(), target_room))
def registerPlayer(self, client, playerData): playerId = playerData['_id'] # See if playerId is in game. candidatePlayer = self.getPlayerById(playerId) if candidatePlayer: # If candidate is linkdead, reconnect if candidatePlayer.isLinkdead(): print '{name} has reconnected.'.format(name=candidatePlayer.name) candidatePlayer.client = client candidatePlayer.sendToClient('Reconnecting.') candidatePlayer.linkdead = 0 for mobile in [mobile for mobile in self.mobiles if mobile is not candidatePlayer]: mobile.sendToClient('@g{name} has reconnected.@x'.format(name=candidatePlayer.getName(mobile))) # And return candidatePlayer to attach to the browser return candidatePlayer else: return False else: # Make a new mobile name = playerData['name'].capitalize() stats = playerData['stats'] if 'stats' in playerData else {} newMobile = Mobile(name, self, {'stats': stats}) newMobile.client = client newMobile.is_player = True self.mobiles.append(newMobile) newMobile.id = playerId if 'room' in playerData: newMobile.room = self.rooms[playerData['room']] else: newMobile.room = self.rooms[0] if 'stats' in playerData: for stat in playerData['stats']: newMobile.stats[stat] = playerData['stats'][stat] newMobile.sendToClient('@uWelcome to Redemption, {name}@x.'.format(name=newMobile.name)) for mobile in [mobile for mobile in self.mobiles if mobile is not newMobile]: mobile.sendToClient('@g{name} has connected.@x'.format(name=newMobile.getName(mobile))) return newMobile
def registerPlayer(self, client, playerData): playerId = playerData['_id'] # See if playerId is in game. candidatePlayer = self.getPlayerById(playerId) if candidatePlayer: # If candidate is linkdead, reconnect if candidatePlayer.isLinkdead(): print 'Reconnecting to player {name}'.format(name=candidatePlayer.name) candidatePlayer.client = client candidatePlayer.sendToClient('Reconnecting.') candidatePlayer.processCommand('look') candidatePlayer.linkdead = 0 # And return candidatePlayer to attach to the browser return candidatePlayer else: return False else: # Make a new mobile name = playerData['name'] newMobile = Mobile(name, self, {'charClass': 'warrior'}) newMobile.client = client self.mobiles.append(newMobile) newMobile.id = playerId if 'room' in playerData: newMobile.room = self.rooms[playerData['room']] else: newMobile.room = self.rooms[0] if 'stats' in playerData: for stat in playerData['stats']: newMobile.stats[stat] = playerData['stats'][stat] newMobile.sendToClient('@uWelcome to Redemption, {name}@x.'.format(name=newMobile.name)) return newMobile
def loadRooms(self): rooms = self.db.rooms.find() for i in range(0, rooms.count()): # default is zero exists = [r for r in self.rooms if r.id == rooms[i]['id']] if len(exists) > 0: newRoom = exists[0] newRoom.bg = rooms[i]['bg'] if 'bg' in rooms[i] else newRoom.bg newRoom.desc = rooms[i]['description'] if 'description' in rooms[i] else newRoom.desc else: newRoom = Room(self, rooms[i]) newRoom.id = rooms[i]['id'] if newRoom.bg: print "Has a background!", newRoom.bg newRoom.items = [] newRoom.exits = [] if 'items' in rooms[i]: for item in rooms[i]['items']:# newRoom.items.append(Item(self.items[item])) if 'npcs' in rooms[i]: # only respawn if there is NO combat going on in the room to avoid insane duplications! FIX ME currentMobiles = [mobile for mobile in self.mobiles if mobile.room == newRoom and mobile.combat and not mobile.is_player] if not len(currentMobiles) > 0: for mobile in rooms[i]['npcs']: m = Mobile(self.mobile_list[mobile]['name'], self, self.mobile_list[mobile]) m.room = newRoom self.mobiles.append(m) if len(exists) <= 0: self.rooms.append(newRoom) # have to load all the rooms BEFORE loading the exits for i in range(0, rooms.count()): exits = rooms[i]['exits'] for e in exits: exit = exits[e] target_room = next(room for room in self.rooms if room.id == exit['target']) direction = exit['direction'] self.rooms[i].exits.append(Exit(direction.lower(), target_room))