def test_link_command(self): from shinymud.data import config from shinymud.models.player import Player from shinymud.models.area import Area from shinymud.commands.build_commands import Edit, Link from shinymud.modes.build_mode import BuildMode area = Area.create({'name':'pie'}) room1 = area.new_room() area.builders.append('bob') # Make sure bob is editing a room Edit(self.bob, 'area pie', 'edit').run() Edit(self.bob, 'room %s' % room1.id, 'edit').run() # By passing only a direction, this should create a new room # and link its south exit to the current room's north exit Link(self.bob, 'north', 'link').run() # self.bob.log.debug(self.bob.outq) north = room1.exits.get('north') self.assertTrue(north) self.assertEqual(north.linked_exit, 'south') self.bob.outq = [] # Now we're linking to another room in the same area as the one being # edited room2 = area.new_room() Link(self.bob, 'east exit to room %s' % room2.id, 'link').run() self.bob.world.log.debug(self.bob.outq) east = room1.exits.get('east') self.bob.world.log.debug(east) self.assertTrue(east) self.assertEqual(east.linked_exit, 'west') self.assertEqual(east.to_room, room2) # Now we're linking to another room in a different area as the one # being edited area2 = Area.create({'name':'cake'}) cake_room = area2.new_room() Link(self.bob, 'west exit to room %s from area %s' % (cake_room.id, cake_room.area.name), 'link').run() self.bob.world.log.debug(self.bob.outq) west = room1.exits.get('west') self.assertTrue(west) self.assertEqual(west.linked_exit, 'east') self.assertEqual(west.to_room, cake_room) self.bob.outq = [] # Linking should fail if we try to link to a pre-linked room Link(self.bob, 'west exit to room %s from area %s' % (cake_room.id, cake_room.area.name), 'link').run() self.bob.world.log.debug(self.bob.outq) fail = ("This room's (id: 1) west exit is already linked to room 1, " "area cake.\nYou must unlink it before linking it to a new room.") self.assertTrue(fail in self.bob.outq)
def test_goto_command(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands.commands import Goto blarg_area = Area.create({'name': 'blarg'}) foo_area = Area.create({'name': 'foo'}) blarg_room = blarg_area.new_room() foo_room = foo_area.new_room() bob = Player(('bob', 'bar')) bob.mode = None bob.playerize({'name': 'bob', 'password': '******'}) self.world.player_add(bob) bob.permissions = bob.permissions | config.BUILDER generic_fail = 'Type "help goto" for help with this command.' # We should fail if we only specify a room number when we aren't in # an area Goto(bob, '%s' % foo_room.id, 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(generic_fail in bob.outq) # We should fail if we try to go to a room in an area that doesn't # exist message = 'Area "food" doesn\'t exist.' Goto(bob, '1 food', 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(message in bob.outq) # We should fail if we try to go to a room that doesn't exist (in an # area that does) message = 'Room "4005" doesn\'t exist in area blarg.' Goto(bob, '4005 blarg', 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(message in bob.outq) # We should succeed in going to a room and area that exists Goto(bob, '%s %s' % (foo_room.id, foo_room.area.name), 'goto').run() self.assertEqual(bob.location, foo_room) Goto(bob, '%s %s' % (blarg_room.id, blarg_room.area.name), 'goto').run() self.assertEqual(bob.location, blarg_room) blarg_r2 = blarg_area.new_room() Goto(bob, '%s' % (blarg_r2.id), 'goto').run() self.assertEqual(bob.location, blarg_r2) # We should get a help message if there is only white space given bob.outq = [] Goto(bob, ' ', 'goto').run() fail = 'Type "help goto" for help with this command.' self.assertTrue(fail in bob.outq)
def test_goto_command(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands.commands import Goto blarg_area = Area.create({'name':'blarg'}) foo_area = Area.create({'name':'foo'}) blarg_room = blarg_area.new_room() foo_room = foo_area.new_room() bob = Player(('bob', 'bar')) bob.mode = None bob.playerize({'name':'bob', 'password':'******'}) self.world.player_add(bob) bob.permissions = bob.permissions | config.BUILDER generic_fail = 'Type "help goto" for help with this command.' # We should fail if we only specify a room number when we aren't in # an area Goto(bob, '%s' % foo_room.id, 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(generic_fail in bob.outq) # We should fail if we try to go to a room in an area that doesn't # exist message = 'Area "food" doesn\'t exist.' Goto(bob, '1 food', 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(message in bob.outq) # We should fail if we try to go to a room that doesn't exist (in an # area that does) message = 'Room "4005" doesn\'t exist in area blarg.' Goto(bob, '4005 blarg', 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(message in bob.outq) # We should succeed in going to a room and area that exists Goto(bob, '%s %s' % (foo_room.id, foo_room.area.name), 'goto').run() self.assertEqual(bob.location, foo_room) Goto(bob, '%s %s' % (blarg_room.id, blarg_room.area.name), 'goto').run() self.assertEqual(bob.location, blarg_room) blarg_r2 = blarg_area.new_room() Goto(bob, '%s' % (blarg_r2.id), 'goto').run() self.assertEqual(bob.location, blarg_r2) # We should get a help message if there is only white space given bob.outq = [] Goto(bob, ' ', 'goto').run() fail = 'Type "help goto" for help with this command.' self.assertTrue(fail in bob.outq)
def test_ten_new_rooms(self): from shinymud.models.area import Area from shinymud.models.room import Room area = Area.create({'name': 'foo'}) for i in range(11): area.new_room() self.assertEqual(len(area.rooms.keys()), 11)
def _create_area(self): from shinymud.models.area import Area area = Area.create({'name': 'foo'}) # setup scripts script = area.new_script() script.name = 'bar' script.body = 'say ...' script.save() # setup items item = area.new_item() item.build_set_name('chair') item.build_add_type('furniture') item.item_types['furniture'].capacity = 5 item.save() # setup npcs npc = area.new_npc() npc.name = 'Link' npc.description = 'This little elf-man has some hearts tattooed on his arm.' npc.save() npc.build_add_event("hears 'Gannon' call script 1") # setup rooms rd = {'id': '1', 'name': 'Room 1', 'description': 'Cool room.'} room = area.new_room(rd) room2 = area.new_room() room.link_exits('north', room2) room.build_add_spawn('item 1') room2.build_add_spawn('npc 1') return area
def test_export_command(self): from shinymud.models.area import Area from shinymud.commands.build_commands import Export from shinymud.data.config import AREAS_EXPORT_DIR a = Area.create({'name': 'superlongtestfoo'}) # Make sure we fail if the area doesn't actually exist Export(self.bob, 'area bar', 'export').run() self.world.log.debug(self.bob.outq) self.assertTrue('Area "bar" doesn\'t exist.' in self.bob.outq) # We should fail if the player gives us incorrect syntax error = 'Try: "export <area/player> <name>", or see "help export".' Export(self.bob, 'lol', 'export').run() self.assertTrue(error in self.bob.outq) # Character exporting doesn't exist yet, but make sure the player gets # the correct logic branch if they try it error = 'Invalid type "char". See "help export".' Export(self.bob, 'char bob', 'export').run() self.assertTrue(error in self.bob.outq) # Make sure exporting actually works self.assertTrue(self.world.area_exists('superlongtestfoo')) Export(self.bob, 'area superlongtestfoo', 'export').run() self.world.log.debug(self.bob.outq) self.assertTrue(self.bob.outq[-1].startswith('Export complete!')) # make sure the file got created self.assertTrue(os.path.exists(AREAS_EXPORT_DIR + '/superlongtestfoo_area.shiny_format')) self._clean_test_file(AREAS_EXPORT_DIR + '/superlongtestfoo_area.shiny_format')
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.area import Area self.area = Area.create({'name':'foo'}) self.room = self.area.new_room() self.item = self.area.new_item() self.npc = self.area.new_npc()
def test_edit_command(self): from shinymud.data import config from shinymud.models.player import Player from shinymud.models.area import Area from shinymud.commands.build_commands import Edit from shinymud.modes.build_mode import BuildMode # create an area area = Area.create({'name':'dessert'}) # Make sure that we don't die with no args! Edit(self.bob, '', 'edit').run() empty = 'Type "help edit" to get help using this command.' self.assertTrue(empty in self.bob.outq) # Bob should fail to be able to edit the area, since he's not yet on # the area's builder's list fail = 'You aren\'t allowed to edit someone else\'s area.' Edit(self.bob, 'area dessert', 'edit').run() self.assertTrue(fail in self.bob.outq) # Bob should now succeed in editing the area success = 'Now editing area "dessert".' area.builders.append('bob') Edit(self.bob, 'area dessert', 'edit').run() self.assertEqual(self.bob.mode.edit_area, area) self.assertTrue(success in self.bob.outq)
def test_list_areas(self): from shinymud.models.area import Area from shinymud.lib.sport import export, list_importable from shinymud.data.config import AREAS_EXPORT_DIR, AREAS_IMPORT_DIR a = Area.create({'name': 'supertestred'}) b = Area.create({'name': 'supertestblue'}) export('area', a) export('area', b) self.world.destroy_area('supertestred', 'test') self.world.destroy_area('supertestblue', 'test') txt = list_importable('area') self.assertNotEqual(txt.find('supertestred'), -1) self.assertNotEqual(txt.find('supertestblue'), -1) self.world.log.debug(txt) self._clean_test_file(AREAS_EXPORT_DIR + '/supertestblue_area.shiny_format') self._clean_test_file(AREAS_EXPORT_DIR + '/supertestred_area.shiny_format')
def format(world, raw_data): """Deserialize an area saved in ShinyAreaFormat and adds it to the world. raw_data - the data to be deserialized into a Shiny Area object. world - The World instance """ area = json.loads(_match_shiny_tag('Area', raw_data)) scripts = json.loads(_match_shiny_tag('Scripts', raw_data)) items = json.loads(_match_shiny_tag('Items', raw_data)) itypes = json.loads(_match_shiny_tag('Item Types', raw_data)) npcs = json.loads(_match_shiny_tag('Npcs', raw_data)) npc_events = json.loads(_match_shiny_tag('Npc Events', raw_data)) rooms = json.loads(_match_shiny_tag('Rooms', raw_data)) room_exits = json.loads(_match_shiny_tag('Room Exits', raw_data)) room_spawns = json.loads(_match_shiny_tag('Room Spawns', raw_data)) # Build the area from the assembled dictionary data try: new_area = Area.create(area) for script in scripts: new_area.new_script(script) world.log.debug('Finished Scripts.') for item in items: world.log.debug('In item, %s' % item['id']) new_area.new_item(item) world.log.debug('Finished Items.') for itype in itypes: # Get this itype's item by that item's id my_item = new_area.get_item(itype['item']) my_item.load_type(itype['item_type'], itype) world.log.debug('Finished Item types.') for npc in npcs: new_area.new_npc(npc) for event in npc_events: my_script = new_area.get_script(str(event['script'])) event['script'] = my_script my_npc = new_area.get_npc(event['prototype']) my_npc.new_event(event) for room in rooms: new_room = new_area.new_room(room) my_spawns = room_spawns.get(new_room.id) if my_spawns: new_room.load_spawns(my_spawns) for exit in room_exits: world.log.debug(exit['room']) my_room = new_area.get_room(str(exit['room'])) my_room.new_exit(exit) except Exception as e: # if anything went wrong, make sure we destroy whatever parts of # the area that got created. This way, we won't run into problems # if they try to import it again, and we won't leave orphaned or # erroneous data in the db. world.log.error(traceback.format_exc()) world.destroy_area(area.get('name'), 'SPort Error') raise SportError('There was a horrible error on import! ' 'Aborting! Check logfile for details.') new_area.reset() return '%s has been successfully imported.' % new_area.title
def test_merchant_volatile_items(self): #Merchants can sell items from different areas, which can be #destroyed or re-imported/recreated at random. Make sure that #Merchants can still keep track of items amidst such chaos! from shinymud.models.area import Area #Create our merchant npc = self.area.new_npc() npc.build_add_ai("merchant", self.bob) ai = npc.ai_packs['merchant'] #Create our area, with which we will have our missing 'dead item' area2 = Area.create({'name':'bar'}) item = area2.new_item() item.name = 'trucknuts' item.save() #add item to area, make sure it added correctly message = ai.build_add_item('1 from area bar price 2000') self.assertEqual(message, 'Merchant now sells trucknuts.') self.assertEqual(item, ai.sale_items.verify_item(ai.sale_items.live[0])) self.assertEqual([], ai.sale_items.dead) #Destroy the area, with the item we're selling. self.world.destroy_area('bar', self.bob) self.assertFalse(self.world.area_exists('bar')) #ask for a copy of the merch list, make sure the item is not still #trying to be sold (dead) ai.sale_items.merch_list() # updates live,dead lists self.assertEqual([], ai.sale_items.live) self.assertTrue('trucknuts' in ai.sale_items.dead[0].values()) #Recreate the same area and item area2 = Area.create({'name':'bar'}) item = area2.new_item() item.name = 'trucknuts' item.save() #Update the list. Our item should be resurrected! ai.sale_items.merch_list() self.assertTrue('trucknuts' in ai.sale_items.live[0].values()) self.assertEqual([], ai.sale_items.dead)
def test_create_area(self): from shinymud.models.area import Area area = Area.create({'name': 'foo'}) #make sure that the area exists in the world self.assertTrue(self.world.area_exists('foo')) a = self.world.get_area('foo') #make sure that the area was saved to the database row = self.world.db.select("* from area where name=?", ['foo'])[0] self.assertTrue(row)
def test_merchant_volatile_items(self): #Merchants can sell items from different areas, which can be #destroyed or re-imported/recreated at random. Make sure that #Merchants can still keep track of items amidst such chaos! from shinymud.models.area import Area #Create our merchant npc = self.area.new_npc() npc.build_add_ai("merchant", self.bob) ai = npc.ai_packs['merchant'] #Create our area, with which we will have our missing 'dead item' area2 = Area.create({'name': 'bar'}) item = area2.new_item() item.name = 'trucknuts' item.save() #add item to area, make sure it added correctly message = ai.build_add_item('1 from area bar price 2000') self.assertEqual(message, 'Merchant now sells trucknuts.') self.assertEqual(item, ai.sale_items.verify_item(ai.sale_items.live[0])) self.assertEqual([], ai.sale_items.dead) #Destroy the area, with the item we're selling. self.world.destroy_area('bar', self.bob) self.assertFalse(self.world.area_exists('bar')) #ask for a copy of the merch list, make sure the item is not still #trying to be sold (dead) ai.sale_items.merch_list() # updates live,dead lists self.assertEqual([], ai.sale_items.live) self.assertTrue('trucknuts' in ai.sale_items.dead[0].values()) #Recreate the same area and item area2 = Area.create({'name': 'bar'}) item = area2.new_item() item.name = 'trucknuts' item.save() #Update the list. Our item should be resurrected! ai.sale_items.merch_list() self.assertTrue('trucknuts' in ai.sale_items.live[0].values()) self.assertEqual([], ai.sale_items.dead)
def test_destroy_area(self): from shinymud.models.area import Area area = Area.create({'name': 'foo'}) room = area.new_room() room2 = area.new_room() room3 = area.new_room() item = area.new_item() npc = area.new_npc() self.assertTrue(npc.dbid) script = area.new_script() room.link_exits('north', room2) room.link_exits('south', room3) room.build_add_spawn('for item 1') room2.build_add_spawn('for npc 1') npc.build_add_event('pc_enter call script 1') item.build_add_type('portal') db_spawns = self.world.db.select('* FROM room_spawns') db_exits = self.world.db.select('* from room_exit') db_rooms = self.world.db.select('* from room') db_areas = self.world.db.select('* from area') db_scripts = self.world.db.select('* from script') db_npcs = self.world.db.select('* from npc') db_items = self.world.db.select('* from build_item') db_item_types = self.world.db.select('* from portal') self.assertEqual(len(db_rooms), 3) self.assertEqual(len(db_spawns), 2) self.assertEqual(len(db_exits), 4) self.assertEqual(len(db_rooms), 3) self.assertEqual(len(db_areas), 1) self.assertEqual(len(db_scripts), 1) self.assertEqual(len(db_items), 1) self.assertEqual(len(db_item_types), 1) echo = self.world.destroy_area('foo', 'test') self.assertEqual(echo, 'Area foo was successfully destroyed. I hope you meant to do that.\n') db_spawns = self.world.db.select('* FROM room_spawns') db_exits = self.world.db.select('* from room_exit') db_rooms = self.world.db.select('* from room') db_areas = self.world.db.select('* from area') db_scripts = self.world.db.select('* from script') db_npcs = self.world.db.select('* from npc') db_items = self.world.db.select('* from build_item') db_item_types = self.world.db.select('* from portal') self.assertFalse(self.world.area_exists('foo')) self.assertEqual(len(db_rooms), 0) self.assertEqual(len(db_spawns), 0) self.assertEqual(len(db_exits), 0) self.assertEqual(len(db_areas), 0) self.assertEqual(len(db_scripts), 0) self.assertEqual(len(db_items), 0) self.assertEqual(len(db_item_types), 0)
def test_import_command(self): from shinymud.models.area import Area from shinymud.commands.build_commands import Import, Export from shinymud.data.config import AREAS_EXPORT_DIR, AREAS_IMPORT_DIR Area.create({'name': 'superlongtestbar', 'description': 'superlongtestbar is cool.'}) Area.create({'name': 'superlongtestexistenz'}) Export(self.bob, 'area superlongtestbar', 'import').run() self.assertTrue(os.path.exists(AREAS_EXPORT_DIR + '/superlongtestbar_area.shiny_format')) self.world.destroy_area('superlongtestbar', 'test') self.assertFalse(self.world.area_exists('superlongtestbar')) # Make sure we fail if the area file doesn't actually exist Import(self.bob, 'area superlongtestfoo', 'import').run() self.world.log.debug(self.bob.outq) self.assertTrue('Error: file superlongtestfoo_area.shiny_format does not exist.' in self.bob.outq) # Make sure we fail if the player gives incorrect syntax Import(self.bob, 'superlongtestbar', 'import').run() error = 'Invalid type "superlongtestbar". See "help export".' self.assertTrue(error in self.bob.outq) # Make sure we fail if the area already exists in the MUD Import(self.bob, 'area superlongtestexistenz', 'import').run() error = 'Area "superlongtestexistenz" already exists in your game.' self.assertTrue(error in self.bob.outq) # Make sure the import command actually works Import(self.bob, 'area superlongtestbar', 'import').run() b = self.world.get_area('superlongtestbar') self.world.log.debug(self.bob.outq) self.assertTrue(b) self.assertEqual(b.description, 'superlongtestbar is cool.') self.world.destroy_area('superlongtestbar', 'test') Import(self.bob, 'area superlongtestbar from email', 'import').run() error = 'Cannot find transport: load_email' self.world.log.debug(self.bob.outq) self.assertTrue(error in self.bob.outq) self._clean_test_file(AREAS_EXPORT_DIR + '/superlongtestbar_area.shiny_format')
def test_build_set_title(self): from shinymud.models.area import Area area = Area.create({'name': 'foo'}) title = "Best area ever!" echo = area.build_set_title(title) # Make sure we got a string response back to give to the user self.assertTrue(isinstance(echo, basestring)) # Make sure it was set in memory self.assertEqual(title, area.title) # Make sure it was saved to the db correctly row = self.world.db.select("title from area where name=?", [area.name])[0] self.assertEqual(row['title'], title)
def test_build_set_levelrange(self): from shinymud.models.area import Area area = Area.create({'name': 'foo'}) echo = area.build_set_levelrange('Kittens') # Make sure we got a string response back to give to the user self.assertTrue(isinstance(echo, basestring)) # Make sure it was set in memory self.assertEqual('Kittens', area.level_range) # Make sure it was saved to the db correctly row = self.world.db.select("level_range from area where name=?", [area.name])[0] self.assertEqual(row['level_range'], 'Kittens')
def test_build_add_builder(self): from shinymud.models.area import Area area = Area.create({'name': 'foo'}) echo = area.build_add_builder('bob') # Make sure we got a string response back to give to the user self.assertTrue(isinstance(echo, basestring)) # Make sure it was set in memory self.assertTrue('bob' in area.builders) # Make sure it was saved to the db correctly row = self.world.db.select("builders from area where name=?", [area.name])[0] builders = row['builders'].split(',') self.assertTrue('bob' in builders)
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.player import Player from shinymud.models.npc import Npc from shinymud.models.area import Area from shinymud.models.room import Room from shinymud.modes.build_mode import BuildMode from shinymud.data import config self.PERMS = config.PERMS self.bob = Player(('bob', 'bar')) self.bob.mode = None self.bob.playerize({'name':'bob'}) self.world.player_add(self.bob) self.bob.mode = BuildMode(self.bob) self.bob.permissions = self.bob.permissions | self.PERMS['builder'] self.area = Area.create({'name': 'foo'}) self.room = self.area.new_room() self.area2 = Area.create({'name': 'SimCity'}) self.area2_script = self.area2.new_script()
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.player import Player from shinymud.models.npc import Npc from shinymud.models.area import Area from shinymud.models.room import Room from shinymud.modes.build_mode import BuildMode from shinymud.data import config self.PERMS = config.PERMS self.bob = Player(('bob', 'bar')) self.bob.mode = None self.bob.playerize({'name': 'bob'}) self.world.player_add(self.bob) self.bob.mode = BuildMode(self.bob) self.bob.permissions = self.bob.permissions | self.PERMS['builder'] self.area = Area.create({'name': 'foo'}) self.room = self.area.new_room() self.area2 = Area.create({'name': 'SimCity'}) self.area2_script = self.area2.new_script()
def test_inport_dir(self): from shinymud.models.area import Area from shinymud.lib.sport import export, inport_dir from shinymud.data.config import AREAS_EXPORT_DIR epath = AREAS_EXPORT_DIR + '/test' a = Area.create({'name': 'supertestfooarea'}) b = Area.create({'name': 'supertestbararea'}) c = Area.create({'name': 'supertestbazarea'}) export('area', a, dest_path=epath) export('area', b, dest_path=epath) export('area', c, dest_path=epath) self.world.destroy_area('supertestfooarea', 'test') self.world.destroy_area('supertestbararea', 'test') self.world.destroy_area('supertestbazarea', 'test') txt = inport_dir('area', source_path=epath) self.world.log.debug(txt) self.assertTrue(self.world.area_exists('supertestfooarea')) self.assertTrue(self.world.area_exists('supertestbararea')) self.assertTrue(self.world.area_exists('supertestbazarea')) shutil.rmtree(epath, True)
def test_new_room(self): from shinymud.models.area import Area from shinymud.models.room import Room area = Area.create({'name': 'foo'}) # Test without room args room = area.new_room() self.assertTrue(isinstance(room, Room)) self.assertTrue(room is area.get_room(room.id)) row = self.world.db.select('* from room where area=?', [area.name]) self.assertEqual(len(row), 1) # Test with room args room2 = area.new_room({'name': 'awesome room', 'description': 'food', 'id': '2'}) self.assertTrue(room2 is area.get_room(room2.id)) self.assertEqual(room2.name, 'awesome room') self.assertEqual(room2.description, 'food')
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.player import Player from shinymud.models.area import Area from shinymud.models.room import Room from shinymud.modes.build_mode import BuildMode from shinymud.data import config self.bob = Player(('bob', 'bar')) self.bob.mode = None self.bob.playerize({'name': 'bob'}) self.world.player_add(self.bob) self.bob.mode = BuildMode(self.bob) self.bob.permissions = self.bob.permissions | config.BUILDER self.area = Area.create({'name': 'foo'})
def test_destroy_room(self): from shinymud.models.area import Area area = Area.create({'name': 'foo'}) room = area.new_room() room2 = area.new_room() item = area.new_item() room.link_exits('north', room2) self.assertTrue(room.exits.get('north')) room.build_add_spawn('for item 1') self.assertTrue(room.spawns.get('1')) area.destroy_room(room.id) self.assertFalse(area.get_room(room.id)) db_spawns = self.world.db.select('* FROM room_spawns') self.assertFalse(db_spawns) db_exits = self.world.db.select('* from room_exit') self.assertFalse(db_exits)
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.player import Player from shinymud.models.area import Area from shinymud.models.room import Room from shinymud.modes.build_mode import BuildMode from shinymud.data import config self.bob = Player(("bob", "bar")) self.bob.mode = None self.bob.playerize({"name": "bob"}) self.world.player_add(self.bob) self.bob.mode = BuildMode(self.bob) self.bob.permissions = self.bob.permissions | config.BUILDER self.area = Area.create({"name": "foo"})
def test_unlink_command(self): from shinymud.data import config from shinymud.models.player import Player from shinymud.models.area import Area from shinymud.commands.build_commands import Edit, Link, Unlink from shinymud.modes.build_mode import BuildMode area = Area.create({'name':'pie'}) room1 = area.new_room() area.builders.append('bob') Edit(self.bob, 'area pie', 'edit').run() Edit(self.bob, 'room %s' % room1.id, 'edit').run() Link(self.bob, 'north', 'link').run() room2 = room1.exits.get('north').to_room self.assertTrue(room2.exits['south'].linked_exit) self.assertTrue(room1.exits['north'].linked_exit) Unlink(self.bob, 'north', 'unlink').run() self.assertEqual(room1.exits.get('north'), None) self.assertEqual(room2.exits.get('south'), None)
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.player import Player from shinymud.models.npc import Npc from shinymud.models.area import Area from shinymud.models.room import Room from shinymud.modes.build_mode import BuildMode from shinymud.data import config self.PERMS = config.PERMS #"bob" is created so we can tell build mode functions which player called them. #We probably don't need bob since this functionality is only important when permissions #are concerned in build commands. We'll create and pass him in anyways for now. self.bob = Player(('bob', 'bar')) self.bob.mode = None self.bob.playerize({'name': 'bob'}) self.world.player_add(self.bob) self.bob.mode = BuildMode(self.bob) self.bob.permissions = self.bob.permissions | self.PERMS['builder'] self.area = Area.create({'name': 'foo'})
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.player import Player from shinymud.models.npc import Npc from shinymud.models.area import Area from shinymud.models.room import Room from shinymud.modes.build_mode import BuildMode from shinymud.data import config self.PERMS = config.PERMS #"bob" is created so we can tell build mode functions which player called them. #We probably don't need bob since this functionality is only important when permissions #are concerned in build commands. We'll create and pass him in anyways for now. self.bob = Player(('bob', 'bar')) self.bob.mode = None self.bob.playerize({'name':'bob'}) self.world.player_add(self.bob) self.bob.mode = BuildMode(self.bob) self.bob.permissions = self.bob.permissions | self.PERMS['builder'] self.area = Area.create({'name': 'foo'})
def test_give_command(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands.commands import Give area = Area.create({'name':'blarg'}) room = area.new_room() bob = Player(('bob', 'bar')) bob.mode = None bob.playerize({'name':'bob', 'password':'******'}) alice = Player(('alice', 'bar')) alice.mode = None alice.playerize({'name':'alice', 'password':'******'}) self.world.player_add(bob) self.world.player_add(alice) room.add_char(bob) room.add_char(alice) alice.location = room bob.location = room proto_npc = area.new_npc() npc = proto_npc.load() room.add_char(npc) item = area.new_item() item.build_set_keywords('bauble', bob) item.build_set_name('a bauble', bob) bob.item_add(item.load()) self.assertEqual(len(bob.inventory), 1) Give(bob, 'bauble to alice', 'give').run() self.assertEqual(len(bob.inventory), 0) self.assertEqual(len(alice.inventory), 1) to_alice = 'Bob gives you a bauble.' self.assertTrue(to_alice in alice.outq) to_bob = 'You give a bauble to Alice.' self.assertTrue(to_bob in bob.outq) Give(alice, 'bauble to shiny', 'give').run() self.assertEqual(len(alice.inventory), 0) self.assertEqual(len(npc.inventory), 1) to_alice = 'You give a bauble to %s.' % npc.name alice.world.log.debug(alice.outq) self.assertTrue(to_alice in alice.outq) to_shiny = 'Alice gives you a bauble.' self.assertTrue(to_shiny in npc.actionq) #Test Money bob.currency = 100 com = config.CURRENCY + ' to alice' #Test give one currency unit self.assertEqual(alice.currency, 0) Give(bob, com, 'give').run() self.assertEqual(bob.currency, 99) self.assertEqual(alice.currency, 1) #test give multiple currencies com = '99' + config.CURRENCY + ' to alice' Give(bob, com, 'give').run() self.assertEqual(bob.currency, 0) self.assertEqual(alice.currency, 100) #test give more than bob has com = '1000' + config.CURRENCY + ' to alice' Give(bob, com, 'give').run() self.assertEqual(bob.currency, 0) self.assertEqual(alice.currency, 100)
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.area import Area self.area = Area.create({'name':'boo'})
from shinymud.models.area import Area from shinymud.data.config import * from shinymud.lib.connection_handlers import con_handlers import traceback import datetime initialize_database() world.db.delete( 'from game_item where (owner is null or owner=\'None\') and container is null' ) # load the entities in the world from the database # This should probably happen inside the world itself... for area in world.db.select("* from area"): world.area_add(Area.create(area)) for area in world.areas.values(): area.load() world.default_location = world.get_location(DEFAULT_LOCATION[0], DEFAULT_LOCATION[1]) # Start up all of our connection handlers for port, conn_handler in CONNECTIONS: handler_class = getattr(con_handlers, conn_handler) handler_obj = handler_class(port, HOST, world) handler_obj.start() world.log.info('Started the connection handlers. Now listening for Players.') world.log.debug('The world is about to start turning.')
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.area import Area self.area = Area.create({"name": "blarg"}) self.room = self.area.new_room()
world = World() from shinymud.lib.setup import initialize_database from shinymud.models.area import Area from shinymud.data.config import * from shinymud.lib.connection_handlers import con_handlers import traceback import datetime initialize_database() world.db.delete('from game_item where (owner is null or owner=\'None\') and container is null') # load the entities in the world from the database # This should probably happen inside the world itself... for area in world.db.select("* from area"): world.area_add(Area.create(area)) for area in world.areas.values(): area.load() world.default_location = world.get_location(DEFAULT_LOCATION[0], DEFAULT_LOCATION[1]) # Start up all of our connection handlers for port, conn_handler in CONNECTIONS: handler_class = getattr(con_handlers, conn_handler) handler_obj = handler_class(port, HOST, world) handler_obj.start() world.log.info('Started the connection handlers. Now listening for Players.') world.log.debug('The world is about to start turning.')
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.area import Area self.area = Area.create({'name': 'blarg'}) self.room = self.area.new_room()
def setUp(self): ShinyTestCase.setUp(self) from shinymud.models.area import Area self.area = Area.create({'name': 'boo'})
def test_give_command(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands.commands import Give area = Area.create({'name': 'blarg'}) room = area.new_room() bob = Player(('bob', 'bar')) bob.mode = None bob.playerize({'name': 'bob', 'password': '******'}) alice = Player(('alice', 'bar')) alice.mode = None alice.playerize({'name': 'alice', 'password': '******'}) self.world.player_add(bob) self.world.player_add(alice) room.add_char(bob) room.add_char(alice) alice.location = room bob.location = room proto_npc = area.new_npc() npc = proto_npc.load() room.add_char(npc) item = area.new_item() item.build_set_keywords('bauble', bob) item.build_set_name('a bauble', bob) bob.item_add(item.load()) self.assertEqual(len(bob.inventory), 1) Give(bob, 'bauble to alice', 'give').run() self.assertEqual(len(bob.inventory), 0) self.assertEqual(len(alice.inventory), 1) to_alice = 'Bob gives you a bauble.' self.assertTrue(to_alice in alice.outq) to_bob = 'You give a bauble to Alice.' self.assertTrue(to_bob in bob.outq) Give(alice, 'bauble to shiny', 'give').run() self.assertEqual(len(alice.inventory), 0) self.assertEqual(len(npc.inventory), 1) to_alice = 'You give a bauble to %s.' % npc.name alice.world.log.debug(alice.outq) self.assertTrue(to_alice in alice.outq) to_shiny = 'Alice gives you a bauble.' self.assertTrue(to_shiny in npc.actionq) #Test Money bob.currency = 100 com = config.CURRENCY + ' to alice' #Test give one currency unit self.assertEqual(alice.currency, 0) Give(bob, com, 'give').run() self.assertEqual(bob.currency, 99) self.assertEqual(alice.currency, 1) #test give multiple currencies com = '99' + config.CURRENCY + ' to alice' Give(bob, com, 'give').run() self.assertEqual(bob.currency, 0) self.assertEqual(alice.currency, 100) #test give more than bob has com = '1000' + config.CURRENCY + ' to alice' Give(bob, com, 'give').run() self.assertEqual(bob.currency, 0) self.assertEqual(alice.currency, 100)