diff --git a/src/commands/default/building.py b/src/commands/default/building.py index 61a10d312f..7cafeefceb 100644 --- a/src/commands/default/building.py +++ b/src/commands/default/building.py @@ -919,23 +919,21 @@ class CmdOpen(ObjManipCommand): def create_exit(self, exit_name, location, destination, exit_aliases=None, typeclass=None): """ Helper function to avoid code duplication. - At this point we know destination is a valid location, but - all arguments are strings/lists. + At this point we know destination is a valid location """ caller = self.caller string = "" - # check if this exit object already exists. We need to - # know what the result is before we can decide what to do; - # so we deactivate the automatic error handling. This - # always returns a list. - exit_obj = caller.search(exit_name, ignore_errors=True) + # check if this exit object already exists at the location. + # we need to ignore errors (so no automatic feedback)since we + # have to know the result of the search to decide what to do. + exit_obj = caller.search(exit_name, location=location, ignore_errors=True) if len(exit_obj) > 1: # give error message and return - caller.search(exit_name) + caller.search(exit_name, location=location) return - exit_obj = exit_obj if exit_obj: + exit_obj = exit_obj[0] if not exit_obj.db._destination: # we are trying to link a non-exit string = "'%s' already exists and is not an exit!\nIf you want to convert it " @@ -946,12 +944,15 @@ class CmdOpen(ObjManipCommand): old_destination = exit_obj.db._destination if old_destination: string = "Exit %s already exists." % exit_name - if old_destination != destination: - # reroute the old exit. + if old_destination.id != destination.id: + # reroute the old exit. exit_obj.db._destination = destination exit_obj.aliases = exit_aliases string += " Rerouted its old destination '%s' to '%s' and changed aliases." % \ (old_destination.name, destination.name) + else: + string += " It already points to the correct place." + else: # exit does not exist before. Create a new one. exit_obj = create.create_object(typeclass, key=exit_name, diff --git a/src/objects/manager.py b/src/objects/manager.py index 6d22265a46..db0c2ca42b 100644 --- a/src/objects/manager.py +++ b/src/objects/manager.py @@ -167,7 +167,7 @@ class ObjectManager(TypedObjectManager): @returns_typeclass_list def object_search(self, character, ostring, global_search=False, - attribute_name=None): + attribute_name=None, location=None): """ Search as an object and return results. @@ -177,13 +177,15 @@ class ObjectManager(TypedObjectManager): global_search: Search all objects, not just the current location/inventory attribute_name: (string) Which attribute to search in each object. If None, the default 'key' attribute is used. + location: If None, character.location will be used. """ #ostring = str(ostring).strip() if not ostring or not character: return None - location = character.location + if not location: + location = character.location # Easiest case - dbref matching (always exact) dbref = self.dbref(ostring) diff --git a/src/objects/models.py b/src/objects/models.py index 07d52c71b1..d5b26c1832 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -434,7 +434,7 @@ class ObjectDB(TypedObject): def search(self, ostring, global_search=False, attribute_name=None, - use_nicks=False, + use_nicks=False, location=None, ignore_errors=False): """ Perform a standard object search in the database, handling @@ -451,6 +451,7 @@ class ObjectDB(TypedObject): attribute_name: (string) Which attribute to match (if None, uses default 'name') use_nicks : Use nickname replace (off by default) + location : If None, use caller's current location ignore_errors : Don't display any error messages even if there are none/multiple matches - just return the result as a list. @@ -473,7 +474,8 @@ class ObjectDB(TypedObject): results = ObjectDB.objects.object_search(self, ostring, global_search=global_search, - attribute_name=attribute_name) + attribute_name=attribute_name, + location=location) if ignore_errors: return results