from evennia.contrib.ingame_python import typeclasses from evennia.prototypes import spawner from evennia.utils import inherits_from from evennia.utils.search import search_object def create_room(room_prototype, x, y, zone_id): zones = search_object(zone_id, typeclass="typeclasses.rooms.Zone", exact=True) if not zones: raise Exception("create_room: cannot find zone {}".format(zone_id)) zone = zones[0] room, *rest = spawner.spawn(room_prototype) room.db.x = x room.db.y = y zone.add_room(room) return room def create_exit(exit_prototype, location, direction): x = location.db.x y = location.db.y if direction == "north": x -= 1 if direction == "south": x += 1 if direction == "west": y -= 1 if direction == "east": y += 1 destination_id = location.db.zone.ndb.map[x][y]["room_id"] if destination_id == -1: return False destinations = search_object(destination_id, exact=True) if not destinations: raise Exception("create_exit: cannot find room {}".format(destination_id)) destination = destinations[0] # check if exists a room in the selected direction exits = search_object(direction, candidates=location.exits) if exits: exit_obj = exits[0] exit_obj.delete() exit_obj, *rest = spawner.spawn(exit_prototype) exit_obj.location = location exit_obj.destination = destination exit_obj.aliases.add(direction) if inherits_from(exit_obj, "typeclasses.exits.BaseDoor"): # a door - create its counterpart return_exit, *rest = spawner.spawn(exit_prototype) return_exit.location = destination return_exit.destination = location return_exit.aliases.add(direction) exit_obj.db.return_exit = return_exit return_exit.db.return_exit = exit_obj return exit_obj