Added at_before hooks to CmdGet, CmdGive, CmdDrop

Added in references to at_before hooks for the get, give, and drop commands. If these hooks return 'False' or 'None', the action is canceled.
This commit is contained in:
FlutterSprite 2017-09-26 15:01:52 -07:00 committed by Griatch
parent c3ce2ebcd7
commit dd8e136cfc

View file

@ -266,6 +266,10 @@ class CmdGet(COMMAND_DEFAULT_CLASS):
else:
caller.msg("You can't get that.")
return
# calling at_before_get hook method
if not obj.at_before_get(caller):
return
obj.move_to(caller, quiet=True)
caller.msg("You pick up %s." % obj.name)
@ -273,7 +277,7 @@ class CmdGet(COMMAND_DEFAULT_CLASS):
(caller.name,
obj.name),
exclude=caller)
# calling hook method
# calling at_get hook method
obj.at_get(caller)
@ -307,6 +311,10 @@ class CmdDrop(COMMAND_DEFAULT_CLASS):
multimatch_string="You carry more than one %s:" % self.args)
if not obj:
return
# Call the object script's at_before_drop() method.
if not obj.at_before_drop(caller):
return
obj.move_to(caller.location, quiet=True)
caller.msg("You drop %s." % (obj.name,))
@ -350,6 +358,11 @@ class CmdGive(COMMAND_DEFAULT_CLASS):
if not to_give.location == caller:
caller.msg("You are not holding %s." % to_give.key)
return
# calling at_before_give hook method
if not to_give.at_before_give(caller, target):
return
# give object
caller.msg("You give %s to %s." % (to_give.key, target.key))
to_give.move_to(target, quiet=True)