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))