Added the ability of obj.move_to to accept a None location with a keyword to_none. Also changed the @tel command to accept a /tonone switch for putting things' location to None. Resolves Issue 307.

This commit is contained in:
Griatch 2012-10-23 22:31:51 +02:00
parent fc4d7c92f9
commit ce036e07f3
3 changed files with 62 additions and 17 deletions

View file

@ -1876,19 +1876,29 @@ class CmdFind(MuxCommand):
class CmdTeleport(MuxCommand):
"""
teleport
teleport object to another location
Usage:
@tel/switch [<object> =] <location>
@tel/switch [<object> =] <target location>
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, <target location> 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] [<obj> =] <target_loc>|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):