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:
parent
fc4d7c92f9
commit
ce036e07f3
3 changed files with 62 additions and 17 deletions
|
|
@ -1876,19 +1876,29 @@ class CmdFind(MuxCommand):
|
||||||
|
|
||||||
class CmdTeleport(MuxCommand):
|
class CmdTeleport(MuxCommand):
|
||||||
"""
|
"""
|
||||||
teleport
|
teleport object to another location
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@tel/switch [<object> =] <location>
|
@tel/switch [<object> =] <target location>
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
@tel Limbo
|
||||||
|
@tel/quiet box Limbo
|
||||||
|
@tel/tonone box
|
||||||
|
|
||||||
Switches:
|
Switches:
|
||||||
quiet - don't echo leave/arrive messages to the source/target
|
quiet - don't echo leave/arrive messages to the source/target
|
||||||
locations for the move.
|
locations for the move.
|
||||||
intoexit - if target is an exit, teleport INTO
|
intoexit - if target is an exit, teleport INTO
|
||||||
the exit object instead of to its destination
|
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"
|
key = "@tel"
|
||||||
aliases = "@teleport"
|
aliases = "@teleport"
|
||||||
locks = "cmd:perm(teleport) or perm(Builders)"
|
locks = "cmd:perm(teleport) or perm(Builders)"
|
||||||
|
|
@ -1902,39 +1912,65 @@ class CmdTeleport(MuxCommand):
|
||||||
lhs, rhs = self.lhs, self.rhs
|
lhs, rhs = self.lhs, self.rhs
|
||||||
switches = self.switches
|
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")
|
caller.msg("Usage: teleport[/switches] [<obj> =] <target_loc>|home")
|
||||||
return
|
return
|
||||||
# The quiet switch suppresses leaving and arrival messages.
|
|
||||||
if "quiet" in switches:
|
|
||||||
tel_quietly = True
|
|
||||||
else:
|
|
||||||
tel_quietly = False
|
|
||||||
|
|
||||||
if rhs:
|
if rhs:
|
||||||
obj_to_teleport = caller.search(lhs, global_search=True)
|
obj_to_teleport = caller.search(lhs, global_search=True)
|
||||||
destination = caller.search(rhs, global_search=True)
|
destination = caller.search(rhs, global_search=True)
|
||||||
else:
|
else:
|
||||||
obj_to_teleport = caller
|
obj_to_teleport = caller
|
||||||
destination = caller.search(args, global_search=True)
|
destination = caller.search(lhs, global_search=True)
|
||||||
if not obj_to_teleport:
|
if not obj_to_teleport:
|
||||||
caller.msg("Did not find object to teleport.")
|
caller.msg("Did not find object to teleport.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not destination:
|
if not destination:
|
||||||
caller.msg("Destination not found.")
|
caller.msg("Destination not found.")
|
||||||
return
|
return
|
||||||
if obj_to_teleport == destination:
|
if obj_to_teleport == destination:
|
||||||
caller.msg("You can't teleport an object inside of itself!")
|
caller.msg("You can't teleport an object inside of itself!")
|
||||||
return
|
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
|
use_destination = True
|
||||||
if "intoexit" in self.switches:
|
if "intoexit" in self.switches:
|
||||||
use_destination = False
|
use_destination = False
|
||||||
|
|
||||||
# try the teleport
|
# 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:
|
if obj_to_teleport == caller:
|
||||||
caller.msg("Teleported to %s." % destination.key)
|
caller.msg("Teleported to %s." % destination)
|
||||||
else:
|
else:
|
||||||
caller.msg("Teleported %s -> %s." % (obj_to_teleport, destination.key))
|
caller.msg("Teleported %s -> %s." % (obj_to_teleport, destination))
|
||||||
|
|
||||||
|
|
||||||
class CmdScript(MuxCommand):
|
class CmdScript(MuxCommand):
|
||||||
|
|
|
||||||
|
|
@ -690,7 +690,7 @@ class ObjectDB(TypedObject):
|
||||||
self.msg_contents(message, exclude=exclude, from_obj=from_obj, data=data)
|
self.msg_contents(message, exclude=exclude, from_obj=from_obj, data=data)
|
||||||
|
|
||||||
def move_to(self, destination, quiet=False,
|
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.
|
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
|
use_destination (bool): Default is for objects to use the "destination" property
|
||||||
of destinations as the target to move to. Turning off this
|
of destinations as the target to move to. Turning off this
|
||||||
keyword allows objects to move "inside" exit objects.
|
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
|
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.
|
may also return various error messages to the emit_to_obj.
|
||||||
|
|
@ -723,6 +725,11 @@ class ObjectDB(TypedObject):
|
||||||
emit_to_obj = self
|
emit_to_obj = self
|
||||||
|
|
||||||
if not destination:
|
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."))
|
emit_to_obj.msg(_("The destination doesn't exist."))
|
||||||
return
|
return
|
||||||
if destination.destination and use_destination:
|
if destination.destination and use_destination:
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class Object(TypeClass):
|
||||||
execute_cmd(raw_string)
|
execute_cmd(raw_string)
|
||||||
msg(message, from_obj=None, data=None)
|
msg(message, from_obj=None, data=None)
|
||||||
msg_contents(message, exclude=None, 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)
|
copy(new_key=None)
|
||||||
delete()
|
delete()
|
||||||
is_typeclass(typeclass, exact=False)
|
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)
|
self.dbobj.msg_contents(message, exclude=exclude, from_obj=from_obj, data=data)
|
||||||
|
|
||||||
def move_to(self, destination, quiet=False,
|
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 <destination> is an
|
Moves this object to a new location. Note that if <destination> is an
|
||||||
exit object (i.e. it has "destination"!=None), the move_to will
|
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
|
use_destination (bool): Default is for objects to use the "destination" property
|
||||||
of destinations as the target to move to. Turning off this
|
of destinations as the target to move to. Turning off this
|
||||||
keyword allows objects to move "inside" exit objects.
|
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
|
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.
|
may also return various error messages to the emit_to_obj.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue