building.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from evennia.prototypes import spawner
  2. from evennia.utils import inherits_from
  3. from evennia.utils.search import search_object
  4. def create_exit(exit_prototype, location, direction):
  5. x = location.db.x
  6. y = location.db.y
  7. if direction == "north":
  8. x -= 1
  9. if direction == "south":
  10. x += 1
  11. if direction == "west":
  12. y -= 1
  13. if direction == "east":
  14. y += 1
  15. destination_id = location.db.zone.ndb.map[x][y]["room_id"]
  16. if destination_id == -1:
  17. return False
  18. destinations = search_object(destination_id, exact=True)
  19. if not destinations:
  20. raise Exception("create_exit: cannot find room {}".format(destination_id))
  21. destination = destinations[0]
  22. # check if exists a room in the selected direction
  23. exits = search_object(direction, candidates=location.exits)
  24. if exits:
  25. exit_obj = exits[0]
  26. exit_obj.delete()
  27. exit_obj, *rest = spawner.spawn(exit_prototype)
  28. exit_obj.location = location
  29. exit_obj.destination = destination
  30. exit_obj.aliases.add(direction)
  31. if inherits_from(exit_obj, "typeclasses.exits.BaseDoor"):
  32. # a door - create its counterpart
  33. return_exit, *rest = spawner.spawn(exit_prototype)
  34. return_exit.location = destination
  35. return_exit.destination = location
  36. return_exit.aliases.add(direction)
  37. exit_obj.db.return_exit = return_exit
  38. return_exit.db.return_exit = exit_obj
  39. return exit_obj