48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
from evennia.prototypes import spawner
|
|
from evennia.utils import inherits_from
|
|
from evennia.utils.search import search_object
|
|
|
|
|
|
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
|