diff --git a/src/commands/default/building.py b/src/commands/default/building.py index 1af8b62259..3b786c2501 100644 --- a/src/commands/default/building.py +++ b/src/commands/default/building.py @@ -1876,19 +1876,29 @@ class CmdFind(MuxCommand): class CmdTeleport(MuxCommand): """ - teleport + teleport object to another location Usage: - @tel/switch [ =] + @tel/switch [ =] + + Examples: + @tel Limbo + @tel/quiet box Limbo + @tel/tonone box Switches: quiet - don't echo leave/arrive messages to the source/target locations for the move. intoexit - if target is an exit, teleport INTO the exit object instead of to its destination + tonone - if set, teleport the object to a None-location. If this + switch is set, is ignored. + Note that the only way to retrieve + an object from a None location is by direct #dbref + reference. - Teleports an object or yourself somewhere. - """ + Teleports an object somewhere. If no object is given, you yourself + is teleported to the target location. """ key = "@tel" aliases = "@teleport" locks = "cmd:perm(teleport) or perm(Builders)" @@ -1902,39 +1912,65 @@ class CmdTeleport(MuxCommand): lhs, rhs = self.lhs, self.rhs switches = self.switches - if not args: + # setting switches + tel_quietly = "quiet" in switches + to_none = "tonone" in switches + + if to_none: + # teleporting to None + if not args: + obj_to_teleport = caller + caller.msg("Teleported to None-location.") + if caller.location and not tel_quietly: + caller.location.msg_contents("%s teleported into nothingness." % caller, exclude=caller) + else: + obj_to_teleport = caller.search(lhs, global_search=True) + if not obj_to_teleport: + caller.msg("Did not find object to teleport.") + return + caller.msg("Teleported %s -> None-location." % obj_to_teleport) + if obj_to_teleport.location and not tel_quietly: + obj_to_teleport.location.msg_contents("%s teleported %s into nothingness." + % (caller, obj_to_teleport), + exclude=caller) + obj_to_teleport.location=None + return + + # not teleporting to None location + if not args and not to_none: caller.msg("Usage: teleport[/switches] [ =] |home") return - # The quiet switch suppresses leaving and arrival messages. - if "quiet" in switches: - tel_quietly = True - else: - tel_quietly = False if rhs: obj_to_teleport = caller.search(lhs, global_search=True) destination = caller.search(rhs, global_search=True) else: obj_to_teleport = caller - destination = caller.search(args, global_search=True) + destination = caller.search(lhs, global_search=True) if not obj_to_teleport: caller.msg("Did not find object to teleport.") return + if not destination: caller.msg("Destination not found.") return if obj_to_teleport == destination: caller.msg("You can't teleport an object inside of itself!") return + if obj_to_teleport.location and obj_to_teleport.location == destination: + caller.msg("%s is already at %s." % (obj_to_teleport, destination)) + return use_destination = True if "intoexit" in self.switches: use_destination = False + # try the teleport - if obj_to_teleport.move_to(destination, quiet=tel_quietly, emit_to_obj=caller, use_destination=use_destination): + if obj_to_teleport.move_to(destination, quiet=tel_quietly, emit_to_obj=caller, + use_destination=use_destination): if obj_to_teleport == caller: - caller.msg("Teleported to %s." % destination.key) + caller.msg("Teleported to %s." % destination) else: - caller.msg("Teleported %s -> %s." % (obj_to_teleport, destination.key)) + caller.msg("Teleported %s -> %s." % (obj_to_teleport, destination)) class CmdScript(MuxCommand): diff --git a/src/objects/models.py b/src/objects/models.py index d0eb225fdd..99118229b4 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -690,7 +690,7 @@ class ObjectDB(TypedObject): self.msg_contents(message, exclude=exclude, from_obj=from_obj, data=data) def move_to(self, destination, quiet=False, - emit_to_obj=None, use_destination=True): + emit_to_obj=None, use_destination=True, to_none=False): """ Moves this object to a new location. @@ -708,6 +708,8 @@ class ObjectDB(TypedObject): use_destination (bool): Default is for objects to use the "destination" property of destinations as the target to move to. Turning off this keyword allows objects to move "inside" exit objects. + to_none - allow destination to be None. Note that no hooks are run when moving + to a None location. If you want to run hooks, run them manually. Returns True/False depending on if there were problems with the move. This method may also return various error messages to the emit_to_obj. @@ -723,6 +725,11 @@ class ObjectDB(TypedObject): emit_to_obj = self if not destination: + if to_none: + # immediately move to None. There can be no hooks called since + # there is no destination to call them with. + self.location = None + return True emit_to_obj.msg(_("The destination doesn't exist.")) return if destination.destination and use_destination: diff --git a/src/objects/objects.py b/src/objects/objects.py index 3436db1719..587f5c3925 100644 --- a/src/objects/objects.py +++ b/src/objects/objects.py @@ -86,7 +86,7 @@ class Object(TypeClass): execute_cmd(raw_string) msg(message, from_obj=None, data=None) msg_contents(message, exclude=None, from_obj=None, data=None) - move_to(destination, quiet=False, emit_to_obj=None, use_destination=True) + move_to(destination, quiet=False, emit_to_obj=None, use_destination=True, to_none=False) copy(new_key=None) delete() is_typeclass(typeclass, exact=False) @@ -231,7 +231,7 @@ class Object(TypeClass): self.dbobj.msg_contents(message, exclude=exclude, from_obj=from_obj, data=data) def move_to(self, destination, quiet=False, - emit_to_obj=None, use_destination=True): + emit_to_obj=None, use_destination=True, to_none=False): """ Moves this object to a new location. Note that if is an exit object (i.e. it has "destination"!=None), the move_to will @@ -247,6 +247,8 @@ class Object(TypeClass): use_destination (bool): Default is for objects to use the "destination" property of destinations as the target to move to. Turning off this keyword allows objects to move "inside" exit objects. + to_none - allow destination to be None. Note that no hooks are run when moving + to a None location. If you want to run hooks, run them manually. Returns True/False depending on if there were problems with the move. This method may also return various error messages to the emit_to_obj.