Merge pull request #2803 from volundmush/move_type
Added move_type to obj.move_to and its many hooks and what calls it.
This commit is contained in:
commit
97ccb598ca
13 changed files with 95 additions and 64 deletions
|
|
@ -130,7 +130,7 @@ def menunode_inspect_and_buy(caller, raw_string):
|
||||||
if wealth >= value:
|
if wealth >= value:
|
||||||
rtext = f"You pay {value} gold and purchase {ware.key}!"
|
rtext = f"You pay {value} gold and purchase {ware.key}!"
|
||||||
caller.db.gold -= value
|
caller.db.gold -= value
|
||||||
ware.move_to(caller, quiet=True)
|
ware.move_to(caller, quiet=True, move_type="buy")
|
||||||
else:
|
else:
|
||||||
rtext = f"You cannot afford {value} gold for {ware.key}!"
|
rtext = f"You cannot afford {value} gold for {ware.key}!"
|
||||||
caller.msg(rtext)
|
caller.msg(rtext)
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class CmdEnterTrain(Command):
|
||||||
def func(self):
|
def func(self):
|
||||||
train = self.obj
|
train = self.obj
|
||||||
self.caller.msg("You board the train.")
|
self.caller.msg("You board the train.")
|
||||||
self.caller.move_to(train)
|
self.caller.move_to(train, move_type="board")
|
||||||
|
|
||||||
|
|
||||||
class CmdLeaveTrain(Command):
|
class CmdLeaveTrain(Command):
|
||||||
|
|
@ -107,7 +107,7 @@ class CmdLeaveTrain(Command):
|
||||||
def func(self):
|
def func(self):
|
||||||
train = self.obj
|
train = self.obj
|
||||||
parent = train.location
|
parent = train.location
|
||||||
self.caller.move_to(parent)
|
self.caller.move_to(parent, move_type="disembark")
|
||||||
|
|
||||||
|
|
||||||
class CmdSetTrain(CmdSet):
|
class CmdSetTrain(CmdSet):
|
||||||
|
|
|
||||||
|
|
@ -603,7 +603,7 @@ class CmdCreate(ObjManipCommand):
|
||||||
if "drop" in self.switches:
|
if "drop" in self.switches:
|
||||||
if caller.location:
|
if caller.location:
|
||||||
obj.home = caller.location
|
obj.home = caller.location
|
||||||
obj.move_to(caller.location, quiet=True)
|
obj.move_to(caller.location, quiet=True, move_type="drop")
|
||||||
if string:
|
if string:
|
||||||
caller.msg(string)
|
caller.msg(string)
|
||||||
|
|
||||||
|
|
@ -993,7 +993,7 @@ class CmdDig(ObjManipCommand):
|
||||||
)
|
)
|
||||||
caller.msg("%s%s%s" % (room_string, exit_to_string, exit_back_string))
|
caller.msg("%s%s%s" % (room_string, exit_to_string, exit_back_string))
|
||||||
if new_room and "teleport" in self.switches:
|
if new_room and "teleport" in self.switches:
|
||||||
caller.move_to(new_room)
|
caller.move_to(new_room, move_type="teleport")
|
||||||
|
|
||||||
|
|
||||||
class CmdTunnel(COMMAND_DEFAULT_CLASS):
|
class CmdTunnel(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
@ -3709,6 +3709,7 @@ class CmdTeleport(COMMAND_DEFAULT_CLASS):
|
||||||
quiet="quiet" in self.switches,
|
quiet="quiet" in self.switches,
|
||||||
emit_to_obj=caller,
|
emit_to_obj=caller,
|
||||||
use_destination="intoexit" not in self.switches,
|
use_destination="intoexit" not in self.switches,
|
||||||
|
move_type="teleport"
|
||||||
):
|
):
|
||||||
|
|
||||||
if obj_to_teleport == caller:
|
if obj_to_teleport == caller:
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class CmdHome(COMMAND_DEFAULT_CLASS):
|
||||||
caller.msg("You are already home!")
|
caller.msg("You are already home!")
|
||||||
else:
|
else:
|
||||||
caller.msg("There's no place like home ...")
|
caller.msg("There's no place like home ...")
|
||||||
caller.move_to(home)
|
caller.move_to(home, move_type="teleport")
|
||||||
|
|
||||||
|
|
||||||
class CmdLook(COMMAND_DEFAULT_CLASS):
|
class CmdLook(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
@ -434,7 +434,7 @@ class CmdGet(COMMAND_DEFAULT_CLASS):
|
||||||
if not obj.at_pre_get(caller):
|
if not obj.at_pre_get(caller):
|
||||||
return
|
return
|
||||||
|
|
||||||
success = obj.move_to(caller, quiet=True)
|
success = obj.move_to(caller, quiet=True, move_type="get")
|
||||||
if not success:
|
if not success:
|
||||||
caller.msg("This can't be picked up.")
|
caller.msg("This can't be picked up.")
|
||||||
else:
|
else:
|
||||||
|
|
@ -484,7 +484,7 @@ class CmdDrop(COMMAND_DEFAULT_CLASS):
|
||||||
if not obj.at_pre_drop(caller):
|
if not obj.at_pre_drop(caller):
|
||||||
return
|
return
|
||||||
|
|
||||||
success = obj.move_to(caller.location, quiet=True)
|
success = obj.move_to(caller.location, quiet=True, move_type="drop")
|
||||||
if not success:
|
if not success:
|
||||||
caller.msg("This couldn't be dropped.")
|
caller.msg("This couldn't be dropped.")
|
||||||
else:
|
else:
|
||||||
|
|
@ -538,7 +538,7 @@ class CmdGive(COMMAND_DEFAULT_CLASS):
|
||||||
return
|
return
|
||||||
|
|
||||||
# give object
|
# give object
|
||||||
success = to_give.move_to(target, quiet=True)
|
success = to_give.move_to(target, quiet=True, move_type="get")
|
||||||
if not success:
|
if not success:
|
||||||
caller.msg("This could not be given.")
|
caller.msg("This could not be given.")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ class EventCharacter(DefaultCharacter):
|
||||||
"""Return the CallbackHandler."""
|
"""Return the CallbackHandler."""
|
||||||
return CallbackHandler(self)
|
return CallbackHandler(self)
|
||||||
|
|
||||||
def announce_move_from(self, destination, msg=None, mapping=None):
|
def announce_move_from(self, destination, msg=None, move_type="move", mapping=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called if the move is to be announced. This is
|
Called if the move is to be announced. This is
|
||||||
called while we are still standing in the old
|
called while we are still standing in the old
|
||||||
|
|
@ -234,9 +234,9 @@ class EventCharacter(DefaultCharacter):
|
||||||
if not string:
|
if not string:
|
||||||
return
|
return
|
||||||
|
|
||||||
super().announce_move_from(destination, msg=string, mapping=mapping)
|
super().announce_move_from(destination, msg=string, move_type=move_type, mapping=mapping, **kwargs)
|
||||||
|
|
||||||
def announce_move_to(self, source_location, msg=None, mapping=None):
|
def announce_move_to(self, source_location, msg=None, move_type="move", mapping=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called after the move if the move was not quiet. At this point
|
Called after the move if the move was not quiet. At this point
|
||||||
we are standing in the new location.
|
we are standing in the new location.
|
||||||
|
|
@ -292,9 +292,9 @@ class EventCharacter(DefaultCharacter):
|
||||||
if not string:
|
if not string:
|
||||||
return
|
return
|
||||||
|
|
||||||
super().announce_move_to(source_location, msg=string, mapping=mapping)
|
super().announce_move_to(source_location, msg=string, move_type=move_type, mapping=mapping, **kwargs)
|
||||||
|
|
||||||
def at_pre_move(self, destination):
|
def at_pre_move(self, destination, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called just before starting to move this object to
|
Called just before starting to move this object to
|
||||||
destination.
|
destination.
|
||||||
|
|
@ -334,7 +334,7 @@ class EventCharacter(DefaultCharacter):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def at_post_move(self, source_location):
|
def at_post_move(self, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called after move has completed, regardless of quiet mode or
|
Called after move has completed, regardless of quiet mode or
|
||||||
not. Allows changes to the object due to the location it is
|
not. Allows changes to the object due to the location it is
|
||||||
|
|
@ -644,7 +644,7 @@ class EventExit(DefaultExit):
|
||||||
"""Return the CallbackHandler."""
|
"""Return the CallbackHandler."""
|
||||||
return CallbackHandler(self)
|
return CallbackHandler(self)
|
||||||
|
|
||||||
def at_traverse(self, traversing_object, target_location):
|
def at_traverse(self, traversing_object, target_location, **kwargs):
|
||||||
"""
|
"""
|
||||||
This hook is responsible for handling the actual traversal,
|
This hook is responsible for handling the actual traversal,
|
||||||
normally by calling
|
normally by calling
|
||||||
|
|
@ -665,7 +665,7 @@ class EventExit(DefaultExit):
|
||||||
if not allow:
|
if not allow:
|
||||||
return
|
return
|
||||||
|
|
||||||
super().at_traverse(traversing_object, target_location)
|
super().at_traverse(traversing_object, target_location, **kwargs)
|
||||||
|
|
||||||
# After traversing
|
# After traversing
|
||||||
if is_character:
|
if is_character:
|
||||||
|
|
@ -732,7 +732,7 @@ class EventObject(DefaultObject):
|
||||||
"""Return the CallbackHandler."""
|
"""Return the CallbackHandler."""
|
||||||
return CallbackHandler(self)
|
return CallbackHandler(self)
|
||||||
|
|
||||||
def at_get(self, getter):
|
def at_get(self, getter, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called by the default `get` command when this object has been
|
Called by the default `get` command when this object has been
|
||||||
picked up.
|
picked up.
|
||||||
|
|
@ -745,10 +745,10 @@ class EventObject(DefaultObject):
|
||||||
permissions for that.
|
permissions for that.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
super().at_get(getter)
|
super().at_get(getter, **kwargs)
|
||||||
self.callbacks.call("get", getter, self)
|
self.callbacks.call("get", getter, self)
|
||||||
|
|
||||||
def at_drop(self, dropper):
|
def at_drop(self, dropper, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called by the default `drop` command when this object has been
|
Called by the default `drop` command when this object has been
|
||||||
dropped.
|
dropped.
|
||||||
|
|
@ -761,7 +761,7 @@ class EventObject(DefaultObject):
|
||||||
permissions from that.
|
permissions from that.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
super().at_drop(dropper)
|
super().at_drop(dropper, **kwargs)
|
||||||
self.callbacks.call("drop", dropper, self)
|
self.callbacks.call("drop", dropper, self)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ class CmdGiveUp(CmdEvscapeRoom):
|
||||||
# manually call move hooks
|
# manually call move hooks
|
||||||
self.room.msg_room(self.caller, f"|r{self.caller.key} gave up and was whisked away!|n")
|
self.room.msg_room(self.caller, f"|r{self.caller.key} gave up and was whisked away!|n")
|
||||||
self.room.at_object_leave(self.caller, self.caller.home)
|
self.room.at_object_leave(self.caller, self.caller.home)
|
||||||
self.caller.move_to(self.caller.home, quiet=True, move_hooks=False)
|
self.caller.move_to(self.caller.home, quiet=True, move_hooks=False, move_type="teleport")
|
||||||
|
|
||||||
# back to menu
|
# back to menu
|
||||||
run_evscaperoom_menu(self.caller)
|
run_evscaperoom_menu(self.caller)
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ class EvscapeRoom(EvscaperoomObject, DefaultRoom):
|
||||||
|
|
||||||
# Evennia hooks
|
# Evennia hooks
|
||||||
|
|
||||||
def at_object_receive(self, moved_obj, source_location):
|
def at_object_receive(self, moved_obj, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called when an object arrives in the room. This can be used to
|
Called when an object arrives in the room. This can be used to
|
||||||
sum up the situation, set tags etc.
|
sum up the situation, set tags etc.
|
||||||
|
|
@ -195,7 +195,7 @@ class EvscapeRoom(EvscaperoomObject, DefaultRoom):
|
||||||
self.log(f"JOIN: {moved_obj} joined room")
|
self.log(f"JOIN: {moved_obj} joined room")
|
||||||
self.state.character_enters(moved_obj)
|
self.state.character_enters(moved_obj)
|
||||||
|
|
||||||
def at_object_leave(self, moved_obj, target_location, **kwargs):
|
def at_object_leave(self, moved_obj, target_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called when an object leaves the room; if this is a Character we need
|
Called when an object leaves the room; if this is a Character we need
|
||||||
to clean them up and move them to the menu state.
|
to clean them up and move them to the menu state.
|
||||||
|
|
|
||||||
|
|
@ -611,7 +611,7 @@ class CmdDrop(MuxCommand):
|
||||||
if obj.db.worn:
|
if obj.db.worn:
|
||||||
obj.remove(caller, quiet=True)
|
obj.remove(caller, quiet=True)
|
||||||
|
|
||||||
obj.move_to(caller.location, quiet=True)
|
obj.move_to(caller.location, quiet=True, move_type="drop")
|
||||||
caller.msg("You drop %s." % (obj.name,))
|
caller.msg("You drop %s." % (obj.name,))
|
||||||
caller.location.msg_contents("%s drops %s." % (caller.name, obj.name), exclude=caller)
|
caller.location.msg_contents("%s drops %s." % (caller.name, obj.name), exclude=caller)
|
||||||
# Call the object script's at_drop() method.
|
# Call the object script's at_drop() method.
|
||||||
|
|
@ -664,10 +664,10 @@ class CmdGive(MuxCommand):
|
||||||
# Remove clothes if they're given.
|
# Remove clothes if they're given.
|
||||||
if to_give.db.worn:
|
if to_give.db.worn:
|
||||||
to_give.remove(caller)
|
to_give.remove(caller)
|
||||||
to_give.move_to(caller.location, quiet=True)
|
to_give.move_to(caller.location, quiet=True, move_type="remove")
|
||||||
# give object
|
# give object
|
||||||
caller.msg("You give %s to %s." % (to_give.key, target.key))
|
caller.msg("You give %s to %s." % (to_give.key, target.key))
|
||||||
to_give.move_to(target, quiet=True)
|
to_give.move_to(target, quiet=True, move_type="give")
|
||||||
target.msg("%s gives you %s." % (caller.key, to_give.key))
|
target.msg("%s gives you %s." % (caller.key, to_give.key))
|
||||||
# Call the object script's at_give() method.
|
# Call the object script's at_give() method.
|
||||||
to_give.at_give(caller, target)
|
to_give.at_give(caller, target)
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ class SlowExit(DefaultExit):
|
||||||
def move_callback():
|
def move_callback():
|
||||||
"This callback will be called by utils.delay after move_delay seconds."
|
"This callback will be called by utils.delay after move_delay seconds."
|
||||||
source_location = traversing_object.location
|
source_location = traversing_object.location
|
||||||
if traversing_object.move_to(target_location):
|
if traversing_object.move_to(target_location, move_type="traverse"):
|
||||||
self.at_post_traverse(traversing_object, source_location)
|
self.at_post_traverse(traversing_object, source_location)
|
||||||
else:
|
else:
|
||||||
if self.db.err_traverse:
|
if self.db.err_traverse:
|
||||||
|
|
|
||||||
|
|
@ -538,7 +538,7 @@ class WildernessRoom(DefaultRoom):
|
||||||
# This object wasn't in the wilderness yet. Let's add it.
|
# This object wasn't in the wilderness yet. Let's add it.
|
||||||
itemcoords[moved_obj] = self.coordinates
|
itemcoords[moved_obj] = self.coordinates
|
||||||
|
|
||||||
def at_object_leave(self, moved_obj, target_location):
|
def at_object_leave(self, moved_obj, target_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called just before an object leaves from inside this object. This is a
|
Called just before an object leaves from inside this object. This is a
|
||||||
default Evennia hook.
|
default Evennia hook.
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ class CmdTutorialGiveUp(default_cmds.MuxCommand):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.caller.move_to(outro_room)
|
self.caller.move_to(outro_room, move_type="teleport")
|
||||||
|
|
||||||
|
|
||||||
class TutorialRoomCmdSet(CmdSet):
|
class TutorialRoomCmdSet(CmdSet):
|
||||||
|
|
@ -259,7 +259,7 @@ class TutorialRoom(DefaultRoom):
|
||||||
)
|
)
|
||||||
self.cmdset.add_default(TutorialRoomCmdSet)
|
self.cmdset.add_default(TutorialRoomCmdSet)
|
||||||
|
|
||||||
def at_object_receive(self, new_arrival, source_location):
|
def at_object_receive(self, new_arrival, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
When an object enter a tutorial room we tell other objects in
|
When an object enter a tutorial room we tell other objects in
|
||||||
the room about it by trying to call a hook on them. The Mob object
|
the room about it by trying to call a hook on them. The Mob object
|
||||||
|
|
@ -451,7 +451,7 @@ class IntroRoom(TutorialRoom):
|
||||||
"the account."
|
"the account."
|
||||||
)
|
)
|
||||||
|
|
||||||
def at_object_receive(self, character, source_location):
|
def at_object_receive(self, character, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Assign properties on characters
|
Assign properties on characters
|
||||||
"""
|
"""
|
||||||
|
|
@ -523,7 +523,7 @@ class CmdEast(Command):
|
||||||
# Move to the east room.
|
# Move to the east room.
|
||||||
eexit = search_object(self.obj.db.east_exit)
|
eexit = search_object(self.obj.db.east_exit)
|
||||||
if eexit:
|
if eexit:
|
||||||
caller.move_to(eexit[0])
|
caller.move_to(eexit[0], move_type="traverse")
|
||||||
else:
|
else:
|
||||||
caller.msg("No east exit was found for this room. Contact an admin.")
|
caller.msg("No east exit was found for this room. Contact an admin.")
|
||||||
return
|
return
|
||||||
|
|
@ -570,7 +570,7 @@ class CmdWest(Command):
|
||||||
# Move to the west room.
|
# Move to the west room.
|
||||||
wexit = search_object(self.obj.db.west_exit)
|
wexit = search_object(self.obj.db.west_exit)
|
||||||
if wexit:
|
if wexit:
|
||||||
caller.move_to(wexit[0])
|
caller.move_to(wexit[0], move_type="traverse")
|
||||||
else:
|
else:
|
||||||
caller.msg("No west exit was found for this room. Contact an admin.")
|
caller.msg("No west exit was found for this room. Contact an admin.")
|
||||||
return
|
return
|
||||||
|
|
@ -658,7 +658,7 @@ class CmdLookBridge(Command):
|
||||||
fall_exit = search_object(self.obj.db.fall_exit)
|
fall_exit = search_object(self.obj.db.fall_exit)
|
||||||
if fall_exit:
|
if fall_exit:
|
||||||
self.caller.msg("|r%s|n" % FALL_MESSAGE)
|
self.caller.msg("|r%s|n" % FALL_MESSAGE)
|
||||||
self.caller.move_to(fall_exit[0], quiet=True)
|
self.caller.move_to(fall_exit[0], quiet=True, move_type="fall")
|
||||||
# inform others on the bridge
|
# inform others on the bridge
|
||||||
self.obj.msg_contents(
|
self.obj.msg_contents(
|
||||||
"A plank gives way under %s's feet and "
|
"A plank gives way under %s's feet and "
|
||||||
|
|
@ -770,7 +770,7 @@ class BridgeRoom(WeatherRoom):
|
||||||
# send a message most of the time
|
# send a message most of the time
|
||||||
self.msg_contents("|w%s|n" % random.choice(BRIDGE_WEATHER))
|
self.msg_contents("|w%s|n" % random.choice(BRIDGE_WEATHER))
|
||||||
|
|
||||||
def at_object_receive(self, character, source_location):
|
def at_object_receive(self, character, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
This hook is called by the engine whenever the player is moved
|
This hook is called by the engine whenever the player is moved
|
||||||
into this room.
|
into this room.
|
||||||
|
|
@ -796,7 +796,7 @@ class BridgeRoom(WeatherRoom):
|
||||||
character.db.tutorial_bridge_position = 0
|
character.db.tutorial_bridge_position = 0
|
||||||
character.execute_cmd("look")
|
character.execute_cmd("look")
|
||||||
|
|
||||||
def at_object_leave(self, character, target_location):
|
def at_object_leave(self, character, target_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
This is triggered when the player leaves the bridge room.
|
This is triggered when the player leaves the bridge room.
|
||||||
"""
|
"""
|
||||||
|
|
@ -1038,7 +1038,7 @@ class DarkRoom(TutorialRoom):
|
||||||
# put players in darkness
|
# put players in darkness
|
||||||
char.msg("The room is completely dark.")
|
char.msg("The room is completely dark.")
|
||||||
|
|
||||||
def at_object_receive(self, obj, source_location):
|
def at_object_receive(self, obj, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called when an object enters the room.
|
Called when an object enters the room.
|
||||||
"""
|
"""
|
||||||
|
|
@ -1048,7 +1048,7 @@ class DarkRoom(TutorialRoom):
|
||||||
# in case the new guy carries light with them
|
# in case the new guy carries light with them
|
||||||
self.check_light_state()
|
self.check_light_state()
|
||||||
|
|
||||||
def at_object_leave(self, obj, target_location):
|
def at_object_leave(self, obj, target_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
In case people leave with the light, we make sure to clear the
|
In case people leave with the light, we make sure to clear the
|
||||||
DarkCmdSet if necessary. This also works if they are
|
DarkCmdSet if necessary. This also works if they are
|
||||||
|
|
@ -1103,7 +1103,7 @@ class TeleportRoom(TutorialRoom):
|
||||||
self.db.failure_teleport_msg = "You fail!"
|
self.db.failure_teleport_msg = "You fail!"
|
||||||
self.db.failure_teleport_to = "dark cell"
|
self.db.failure_teleport_to = "dark cell"
|
||||||
|
|
||||||
def at_object_receive(self, character, source_location):
|
def at_object_receive(self, character, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
This hook is called by the engine whenever the player is moved into
|
This hook is called by the engine whenever the player is moved into
|
||||||
this room.
|
this room.
|
||||||
|
|
@ -1130,7 +1130,7 @@ class TeleportRoom(TutorialRoom):
|
||||||
else:
|
else:
|
||||||
character.msg(self.db.failure_teleport_msg)
|
character.msg(self.db.failure_teleport_msg)
|
||||||
# teleport quietly to the new place
|
# teleport quietly to the new place
|
||||||
character.move_to(results[0], quiet=True, move_hooks=False)
|
character.move_to(results[0], quiet=True, move_hooks=False, move_type="teleport")
|
||||||
# we have to call this manually since we turn off move_hooks
|
# we have to call this manually since we turn off move_hooks
|
||||||
# - this is necessary to make the target dark room aware of an
|
# - this is necessary to make the target dark room aware of an
|
||||||
# already carried light.
|
# already carried light.
|
||||||
|
|
@ -1167,7 +1167,7 @@ class OutroRoom(TutorialRoom):
|
||||||
"character."
|
"character."
|
||||||
)
|
)
|
||||||
|
|
||||||
def at_object_receive(self, character, source_location):
|
def at_object_receive(self, character, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Do cleanup.
|
Do cleanup.
|
||||||
"""
|
"""
|
||||||
|
|
@ -1183,6 +1183,6 @@ class OutroRoom(TutorialRoom):
|
||||||
obj.delete()
|
obj.delete()
|
||||||
character.tags.clear(category="tutorial_world")
|
character.tags.clear(category="tutorial_world")
|
||||||
|
|
||||||
def at_object_leave(self, character, destination):
|
def at_object_leave(self, character, destination, move_type="move", **kwargs):
|
||||||
if character.account:
|
if character.account:
|
||||||
character.account.execute_cmd("unquell")
|
character.account.execute_cmd("unquell")
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ class TestTutorialWorldRooms(BaseEvenniaCommandTest):
|
||||||
def test_bridgeroom(self):
|
def test_bridgeroom(self):
|
||||||
room = create_object(tutrooms.BridgeRoom, key="bridgeroom")
|
room = create_object(tutrooms.BridgeRoom, key="bridgeroom")
|
||||||
room.update_weather()
|
room.update_weather()
|
||||||
self.char1.move_to(room)
|
self.char1.move_to(room, move_type="teleport")
|
||||||
self.call(
|
self.call(
|
||||||
tutrooms.CmdBridgeHelp(),
|
tutrooms.CmdBridgeHelp(),
|
||||||
"",
|
"",
|
||||||
|
|
@ -181,7 +181,7 @@ class TestTutorialWorldRooms(BaseEvenniaCommandTest):
|
||||||
|
|
||||||
def test_darkroom(self):
|
def test_darkroom(self):
|
||||||
room = create_object(tutrooms.DarkRoom, key="darkroom")
|
room = create_object(tutrooms.DarkRoom, key="darkroom")
|
||||||
self.char1.move_to(room)
|
self.char1.move_to(room, move_type="teleport")
|
||||||
self.call(tutrooms.CmdDarkHelp(), "", "Can't help you until")
|
self.call(tutrooms.CmdDarkHelp(), "", "Can't help you until")
|
||||||
|
|
||||||
def test_teleportroom(self):
|
def test_teleportroom(self):
|
||||||
|
|
|
||||||
|
|
@ -836,6 +836,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
use_destination=True,
|
use_destination=True,
|
||||||
to_none=False,
|
to_none=False,
|
||||||
move_hooks=True,
|
move_hooks=True,
|
||||||
|
move_type="move",
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
|
@ -857,6 +858,11 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
move_hooks (bool): If False, turn off the calling of move-related hooks
|
move_hooks (bool): If False, turn off the calling of move-related hooks
|
||||||
(at_pre/post_move etc) with quiet=True, this is as quiet a move
|
(at_pre/post_move etc) with quiet=True, this is as quiet a move
|
||||||
as can be done.
|
as can be done.
|
||||||
|
move_type (str): The "kind of move" being performed, such as "teleport", "traverse",
|
||||||
|
"get", "give", or "drop". The value can be arbitrary. By default, it only affects
|
||||||
|
the text message generated by announce_move_to and announce_move_from by defining
|
||||||
|
their {"type": move_type} for outgoing text. This can be used for altering
|
||||||
|
messages and/or overloaded hook behaviors.
|
||||||
|
|
||||||
Keyword Args:
|
Keyword Args:
|
||||||
Passed on to announce_move_to and announce_move_from hooks.
|
Passed on to announce_move_to and announce_move_from hooks.
|
||||||
|
|
@ -906,7 +912,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# Before the move, call eventual pre-commands.
|
# Before the move, call eventual pre-commands.
|
||||||
if move_hooks:
|
if move_hooks:
|
||||||
try:
|
try:
|
||||||
if not self.at_pre_move(destination, **kwargs):
|
if not self.at_pre_move(destination, move_type=move_type, **kwargs):
|
||||||
return False
|
return False
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logerr(errtxt.format(err="at_pre_move()"), err)
|
logerr(errtxt.format(err="at_pre_move()"), err)
|
||||||
|
|
@ -918,7 +924,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# Call hook on source location
|
# Call hook on source location
|
||||||
if move_hooks and source_location:
|
if move_hooks and source_location:
|
||||||
try:
|
try:
|
||||||
source_location.at_object_leave(self, destination, **kwargs)
|
source_location.at_object_leave(self, destination, move_type=move_type, **kwargs)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logerr(errtxt.format(err="at_object_leave()"), err)
|
logerr(errtxt.format(err="at_object_leave()"), err)
|
||||||
return False
|
return False
|
||||||
|
|
@ -926,7 +932,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
# tell the old room we are leaving
|
# tell the old room we are leaving
|
||||||
try:
|
try:
|
||||||
self.announce_move_from(destination, **kwargs)
|
self.announce_move_from(destination, move_type=move_type, **kwargs)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logerr(errtxt.format(err="announce_move_from()"), err)
|
logerr(errtxt.format(err="announce_move_from()"), err)
|
||||||
return False
|
return False
|
||||||
|
|
@ -941,7 +947,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
# Tell the new room we are there.
|
# Tell the new room we are there.
|
||||||
try:
|
try:
|
||||||
self.announce_move_to(source_location, **kwargs)
|
self.announce_move_to(source_location, move_type=move_type, **kwargs)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logerr(errtxt.format(err="announce_move_to()"), err)
|
logerr(errtxt.format(err="announce_move_to()"), err)
|
||||||
return False
|
return False
|
||||||
|
|
@ -950,7 +956,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# Perform eventual extra commands on the receiving location
|
# Perform eventual extra commands on the receiving location
|
||||||
# (the object has already arrived at this point)
|
# (the object has already arrived at this point)
|
||||||
try:
|
try:
|
||||||
destination.at_object_receive(self, source_location, **kwargs)
|
destination.at_object_receive(self, source_location, move_type=move_type, **kwargs)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logerr(errtxt.format(err="at_object_receive()"), err)
|
logerr(errtxt.format(err="at_object_receive()"), err)
|
||||||
return False
|
return False
|
||||||
|
|
@ -959,7 +965,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# (usually calling 'look')
|
# (usually calling 'look')
|
||||||
if move_hooks:
|
if move_hooks:
|
||||||
try:
|
try:
|
||||||
self.at_post_move(source_location, **kwargs)
|
self.at_post_move(source_location, move_type=move_type, **kwargs)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logerr(errtxt.format(err="at_post_move"), err)
|
logerr(errtxt.format(err="at_post_move"), err)
|
||||||
return False
|
return False
|
||||||
|
|
@ -1020,7 +1026,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# Famous last words: The account should never see this.
|
# Famous last words: The account should never see this.
|
||||||
string = "This place should not exist ... contact an admin."
|
string = "This place should not exist ... contact an admin."
|
||||||
obj.msg(_(string))
|
obj.msg(_(string))
|
||||||
obj.move_to(home)
|
obj.move_to(home, move_type="teleport")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, key, account=None, **kwargs):
|
def create(cls, key, account=None, **kwargs):
|
||||||
|
|
@ -1472,13 +1478,17 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
# hooks called when moving the object
|
# hooks called when moving the object
|
||||||
|
|
||||||
def at_pre_move(self, destination, **kwargs):
|
def at_pre_move(self, destination, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called just before starting to move this object to
|
Called just before starting to move this object to
|
||||||
destination.
|
destination.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
destination (Object): The object we are moving to
|
destination (Object): The object we are moving to
|
||||||
|
move_type (str): The type of move. "give", "traverse", etc.
|
||||||
|
This is an arbitrary string provided to obj.move_to().
|
||||||
|
Useful for altering messages or altering logic depending
|
||||||
|
on the kind of movement.
|
||||||
**kwargs (dict): Arbitrary, optional arguments for users
|
**kwargs (dict): Arbitrary, optional arguments for users
|
||||||
overriding the call (unused by default).
|
overriding the call (unused by default).
|
||||||
|
|
||||||
|
|
@ -1496,7 +1506,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# deprecated alias
|
# deprecated alias
|
||||||
at_before_move = at_pre_move
|
at_before_move = at_pre_move
|
||||||
|
|
||||||
def announce_move_from(self, destination, msg=None, mapping=None, **kwargs):
|
def announce_move_from(self, destination, msg=None, mapping=None, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called if the move is to be announced. This is
|
Called if the move is to be announced. This is
|
||||||
called while we are still standing in the old
|
called while we are still standing in the old
|
||||||
|
|
@ -1506,6 +1516,10 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
destination (Object): The place we are going to.
|
destination (Object): The place we are going to.
|
||||||
msg (str, optional): a replacement message.
|
msg (str, optional): a replacement message.
|
||||||
mapping (dict, optional): additional mapping objects.
|
mapping (dict, optional): additional mapping objects.
|
||||||
|
move_type (str): The type of move. "give", "traverse", etc.
|
||||||
|
This is an arbitrary string provided to obj.move_to().
|
||||||
|
Useful for altering messages or altering logic depending
|
||||||
|
on the kind of movement.
|
||||||
**kwargs (dict): Arbitrary, optional arguments for users
|
**kwargs (dict): Arbitrary, optional arguments for users
|
||||||
overriding the call (unused by default).
|
overriding the call (unused by default).
|
||||||
|
|
||||||
|
|
@ -1541,9 +1555,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
location.msg_contents(string, exclude=(self,), from_obj=self, mapping=mapping)
|
location.msg_contents((string, {"type": move_type}), exclude=(self,), from_obj=self, mapping=mapping)
|
||||||
|
|
||||||
def announce_move_to(self, source_location, msg=None, mapping=None, **kwargs):
|
def announce_move_to(self, source_location, msg=None, mapping=None, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called after the move if the move was not quiet. At this point
|
Called after the move if the move was not quiet. At this point
|
||||||
we are standing in the new location.
|
we are standing in the new location.
|
||||||
|
|
@ -1552,6 +1566,10 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
source_location (Object): The place we came from
|
source_location (Object): The place we came from
|
||||||
msg (str, optional): the replacement message if location.
|
msg (str, optional): the replacement message if location.
|
||||||
mapping (dict, optional): additional mapping objects.
|
mapping (dict, optional): additional mapping objects.
|
||||||
|
move_type (str): The type of move. "give", "traverse", etc.
|
||||||
|
This is an arbitrary string provided to obj.move_to().
|
||||||
|
Useful for altering messages or altering logic depending
|
||||||
|
on the kind of movement.
|
||||||
**kwargs (dict): Arbitrary, optional arguments for users
|
**kwargs (dict): Arbitrary, optional arguments for users
|
||||||
overriding the call (unused by default).
|
overriding the call (unused by default).
|
||||||
|
|
||||||
|
|
@ -1605,9 +1623,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
destination.msg_contents(string, exclude=(self,), from_obj=self, mapping=mapping)
|
destination.msg_contents((string, {"type": move_type}), exclude=(self,), from_obj=self, mapping=mapping)
|
||||||
|
|
||||||
def at_post_move(self, source_location, **kwargs):
|
def at_post_move(self, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called after move has completed, regardless of quiet mode or
|
Called after move has completed, regardless of quiet mode or
|
||||||
not. Allows changes to the object due to the location it is
|
not. Allows changes to the object due to the location it is
|
||||||
|
|
@ -1615,6 +1633,10 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
source_location (Object): Wwhere we came from. This may be `None`.
|
source_location (Object): Wwhere we came from. This may be `None`.
|
||||||
|
move_type (str): The type of move. "give", "traverse", etc.
|
||||||
|
This is an arbitrary string provided to obj.move_to().
|
||||||
|
Useful for altering messages or altering logic depending
|
||||||
|
on the kind of movement.
|
||||||
**kwargs (dict): Arbitrary, optional arguments for users
|
**kwargs (dict): Arbitrary, optional arguments for users
|
||||||
overriding the call (unused by default).
|
overriding the call (unused by default).
|
||||||
|
|
||||||
|
|
@ -1624,20 +1646,24 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# deprecated
|
# deprecated
|
||||||
at_after_move = at_post_move
|
at_after_move = at_post_move
|
||||||
|
|
||||||
def at_object_leave(self, moved_obj, target_location, **kwargs):
|
def at_object_leave(self, moved_obj, target_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called just before an object leaves from inside this object
|
Called just before an object leaves from inside this object
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
moved_obj (Object): The object leaving
|
moved_obj (Object): The object leaving
|
||||||
target_location (Object): Where `moved_obj` is going.
|
target_location (Object): Where `moved_obj` is going.
|
||||||
|
move_type (str): The type of move. "give", "traverse", etc.
|
||||||
|
This is an arbitrary string provided to obj.move_to().
|
||||||
|
Useful for altering messages or altering logic depending
|
||||||
|
on the kind of movement.
|
||||||
**kwargs (dict): Arbitrary, optional arguments for users
|
**kwargs (dict): Arbitrary, optional arguments for users
|
||||||
overriding the call (unused by default).
|
overriding the call (unused by default).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def at_object_receive(self, moved_obj, source_location, **kwargs):
|
def at_object_receive(self, moved_obj, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
Called after an object has been moved into this object.
|
Called after an object has been moved into this object.
|
||||||
|
|
||||||
|
|
@ -1645,6 +1671,10 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
moved_obj (Object): The object moved into this one
|
moved_obj (Object): The object moved into this one
|
||||||
source_location (Object): Where `moved_object` came from.
|
source_location (Object): Where `moved_object` came from.
|
||||||
Note that this could be `None`.
|
Note that this could be `None`.
|
||||||
|
move_type (str): The type of move. "give", "traverse", etc.
|
||||||
|
This is an arbitrary string provided to obj.move_to().
|
||||||
|
Useful for altering messages or altering logic depending
|
||||||
|
on the kind of movement.
|
||||||
**kwargs (dict): Arbitrary, optional arguments for users
|
**kwargs (dict): Arbitrary, optional arguments for users
|
||||||
overriding the call (unused by default).
|
overriding the call (unused by default).
|
||||||
|
|
||||||
|
|
@ -2381,7 +2411,7 @@ class DefaultCharacter(DefaultObject):
|
||||||
# add the default cmdset
|
# add the default cmdset
|
||||||
self.cmdset.add_default(settings.CMDSET_CHARACTER, persistent=True)
|
self.cmdset.add_default(settings.CMDSET_CHARACTER, persistent=True)
|
||||||
|
|
||||||
def at_post_move(self, source_location, **kwargs):
|
def at_post_move(self, source_location, move_type="move", **kwargs):
|
||||||
"""
|
"""
|
||||||
We make sure to look around after a move.
|
We make sure to look around after a move.
|
||||||
|
|
||||||
|
|
@ -2648,9 +2678,9 @@ class ExitCommand(_COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.obj.destination:
|
if self.obj.destination:
|
||||||
return " (exit to %s)" % self.obj.destination.get_display_name(caller)
|
return " (exit to %s)" % self.obj.destination.get_display_name(caller, **kwargs)
|
||||||
else:
|
else:
|
||||||
return " (%s)" % self.obj.get_display_name(caller)
|
return " (%s)" % self.obj.get_display_name(caller, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -2859,7 +2889,7 @@ class DefaultExit(DefaultObject):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
source_location = traversing_object.location
|
source_location = traversing_object.location
|
||||||
if traversing_object.move_to(target_location):
|
if traversing_object.move_to(target_location, move_type="traverse"):
|
||||||
self.at_post_traverse(traversing_object, source_location)
|
self.at_post_traverse(traversing_object, source_location)
|
||||||
else:
|
else:
|
||||||
if self.db.err_traverse:
|
if self.db.err_traverse:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue