From 473fba5c136f9f5a9b2fe10708b97645f7ea5c42 Mon Sep 17 00:00:00 2001 From: Wendy Wang Date: Thu, 20 Oct 2022 21:30:37 +0200 Subject: [PATCH] Addition of matching_exit() function on DefaultExit to return the exit(s) that pair with it, optionally formatted as list or singular Exit with as_list parameter. --- evennia/objects/objects.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 570398894a..7492cc8831 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -3133,3 +3133,25 @@ class DefaultExit(DefaultObject): """ traversing_object.msg(_("You cannot go there.")) + + def matching_exit(self, as_list=False): + """ + Get the exits that pair with this one in its destination room + (i.e. returns to its location) + + Args: + as_list (bool): Whether to return available results as a + list or single matching exit. + + Returns: + list, exit (Exit), or None: The matching exit(s). + """ + no_match = [] if as_list else None + if not self.destination: + return no_match + matching_exits = [x for x in self.destination.exits if x.destination == self.location] + if not matching_exits: + return no_match + if as_list: + return matching_exits + return matching_exits[0]