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
|
|
@ -189,7 +189,7 @@ class EventCharacter(DefaultCharacter):
|
|||
"""Return the CallbackHandler."""
|
||||
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 while we are still standing in the old
|
||||
|
|
@ -234,9 +234,9 @@ class EventCharacter(DefaultCharacter):
|
|||
if not string:
|
||||
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
|
||||
we are standing in the new location.
|
||||
|
|
@ -292,9 +292,9 @@ class EventCharacter(DefaultCharacter):
|
|||
if not string:
|
||||
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
|
||||
destination.
|
||||
|
|
@ -334,7 +334,7 @@ class EventCharacter(DefaultCharacter):
|
|||
|
||||
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
|
||||
not. Allows changes to the object due to the location it is
|
||||
|
|
@ -644,7 +644,7 @@ class EventExit(DefaultExit):
|
|||
"""Return the CallbackHandler."""
|
||||
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,
|
||||
normally by calling
|
||||
|
|
@ -665,7 +665,7 @@ class EventExit(DefaultExit):
|
|||
if not allow:
|
||||
return
|
||||
|
||||
super().at_traverse(traversing_object, target_location)
|
||||
super().at_traverse(traversing_object, target_location, **kwargs)
|
||||
|
||||
# After traversing
|
||||
if is_character:
|
||||
|
|
@ -732,7 +732,7 @@ class EventObject(DefaultObject):
|
|||
"""Return the CallbackHandler."""
|
||||
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
|
||||
picked up.
|
||||
|
|
@ -745,10 +745,10 @@ class EventObject(DefaultObject):
|
|||
permissions for that.
|
||||
|
||||
"""
|
||||
super().at_get(getter)
|
||||
super().at_get(getter, **kwargs)
|
||||
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
|
||||
dropped.
|
||||
|
|
@ -761,7 +761,7 @@ class EventObject(DefaultObject):
|
|||
permissions from that.
|
||||
|
||||
"""
|
||||
super().at_drop(dropper)
|
||||
super().at_drop(dropper, **kwargs)
|
||||
self.callbacks.call("drop", dropper, self)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ class CmdGiveUp(CmdEvscapeRoom):
|
|||
# manually call move hooks
|
||||
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.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
|
||||
run_evscaperoom_menu(self.caller)
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ class EvscapeRoom(EvscaperoomObject, DefaultRoom):
|
|||
|
||||
# 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
|
||||
sum up the situation, set tags etc.
|
||||
|
|
@ -195,7 +195,7 @@ class EvscapeRoom(EvscaperoomObject, DefaultRoom):
|
|||
self.log(f"JOIN: {moved_obj} joined room")
|
||||
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
|
||||
to clean them up and move them to the menu state.
|
||||
|
|
|
|||
|
|
@ -611,7 +611,7 @@ class CmdDrop(MuxCommand):
|
|||
if obj.db.worn:
|
||||
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.location.msg_contents("%s drops %s." % (caller.name, obj.name), exclude=caller)
|
||||
# Call the object script's at_drop() method.
|
||||
|
|
@ -664,10 +664,10 @@ class CmdGive(MuxCommand):
|
|||
# Remove clothes if they're given.
|
||||
if to_give.db.worn:
|
||||
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
|
||||
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))
|
||||
# Call the object script's at_give() method.
|
||||
to_give.at_give(caller, target)
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class SlowExit(DefaultExit):
|
|||
def move_callback():
|
||||
"This callback will be called by utils.delay after move_delay seconds."
|
||||
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)
|
||||
else:
|
||||
if self.db.err_traverse:
|
||||
|
|
|
|||
|
|
@ -538,7 +538,7 @@ class WildernessRoom(DefaultRoom):
|
|||
# This object wasn't in the wilderness yet. Let's add it.
|
||||
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
|
||||
default Evennia hook.
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ class CmdTutorialGiveUp(default_cmds.MuxCommand):
|
|||
)
|
||||
return
|
||||
|
||||
self.caller.move_to(outro_room)
|
||||
self.caller.move_to(outro_room, move_type="teleport")
|
||||
|
||||
|
||||
class TutorialRoomCmdSet(CmdSet):
|
||||
|
|
@ -259,7 +259,7 @@ class TutorialRoom(DefaultRoom):
|
|||
)
|
||||
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
|
||||
the room about it by trying to call a hook on them. The Mob object
|
||||
|
|
@ -451,7 +451,7 @@ class IntroRoom(TutorialRoom):
|
|||
"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
|
||||
"""
|
||||
|
|
@ -523,7 +523,7 @@ class CmdEast(Command):
|
|||
# Move to the east room.
|
||||
eexit = search_object(self.obj.db.east_exit)
|
||||
if eexit:
|
||||
caller.move_to(eexit[0])
|
||||
caller.move_to(eexit[0], move_type="traverse")
|
||||
else:
|
||||
caller.msg("No east exit was found for this room. Contact an admin.")
|
||||
return
|
||||
|
|
@ -570,7 +570,7 @@ class CmdWest(Command):
|
|||
# Move to the west room.
|
||||
wexit = search_object(self.obj.db.west_exit)
|
||||
if wexit:
|
||||
caller.move_to(wexit[0])
|
||||
caller.move_to(wexit[0], move_type="traverse")
|
||||
else:
|
||||
caller.msg("No west exit was found for this room. Contact an admin.")
|
||||
return
|
||||
|
|
@ -658,7 +658,7 @@ class CmdLookBridge(Command):
|
|||
fall_exit = search_object(self.obj.db.fall_exit)
|
||||
if fall_exit:
|
||||
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
|
||||
self.obj.msg_contents(
|
||||
"A plank gives way under %s's feet and "
|
||||
|
|
@ -770,7 +770,7 @@ class BridgeRoom(WeatherRoom):
|
|||
# send a message most of the time
|
||||
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
|
||||
into this room.
|
||||
|
|
@ -796,7 +796,7 @@ class BridgeRoom(WeatherRoom):
|
|||
character.db.tutorial_bridge_position = 0
|
||||
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.
|
||||
"""
|
||||
|
|
@ -1038,7 +1038,7 @@ class DarkRoom(TutorialRoom):
|
|||
# put players in darkness
|
||||
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.
|
||||
"""
|
||||
|
|
@ -1048,7 +1048,7 @@ class DarkRoom(TutorialRoom):
|
|||
# in case the new guy carries light with them
|
||||
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
|
||||
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_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 room.
|
||||
|
|
@ -1130,7 +1130,7 @@ class TeleportRoom(TutorialRoom):
|
|||
else:
|
||||
character.msg(self.db.failure_teleport_msg)
|
||||
# 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
|
||||
# - this is necessary to make the target dark room aware of an
|
||||
# already carried light.
|
||||
|
|
@ -1167,7 +1167,7 @@ class OutroRoom(TutorialRoom):
|
|||
"character."
|
||||
)
|
||||
|
||||
def at_object_receive(self, character, source_location):
|
||||
def at_object_receive(self, character, source_location, move_type="move", **kwargs):
|
||||
"""
|
||||
Do cleanup.
|
||||
"""
|
||||
|
|
@ -1183,6 +1183,6 @@ class OutroRoom(TutorialRoom):
|
|||
obj.delete()
|
||||
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:
|
||||
character.account.execute_cmd("unquell")
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ class TestTutorialWorldRooms(BaseEvenniaCommandTest):
|
|||
def test_bridgeroom(self):
|
||||
room = create_object(tutrooms.BridgeRoom, key="bridgeroom")
|
||||
room.update_weather()
|
||||
self.char1.move_to(room)
|
||||
self.char1.move_to(room, move_type="teleport")
|
||||
self.call(
|
||||
tutrooms.CmdBridgeHelp(),
|
||||
"",
|
||||
|
|
@ -181,7 +181,7 @@ class TestTutorialWorldRooms(BaseEvenniaCommandTest):
|
|||
|
||||
def test_darkroom(self):
|
||||
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")
|
||||
|
||||
def test_teleportroom(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue