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 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))
# Input: 100 seats, lab, name BE # Expected output: (100, 1, BE) r1 = Room(100, True, 'BE') r1.print_room() # Input: 150 seats, lab, no name # Expected output: (150, 1, None) r1 = Room(150, True) r1.print_room() # Test setting the ID # Input: 1 # Expected output: 1 r1.id = 1 print r1.get_id() # Test default constructor's data population # Input: just call Room() # Expected output: TypeError (Insufficient data to print) r2 = Room() try: r2.print_room() except TypeError: print "Exception caught: TypeError; test successful" # Test manipulation functions # Input: 200 seats, lab, name Baskin # Expected output: (200, 1, Baskin) r2.add_seats(200)