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

@ -267,13 +267,17 @@ class CmdGet(COMMAND_DEFAULT_CLASS):
caller.msg("You can't get that.") caller.msg("You can't get that.")
return return
# calling at_before_get hook method
if not obj.at_before_get(caller):
return
obj.move_to(caller, quiet=True) obj.move_to(caller, quiet=True)
caller.msg("You pick up %s." % obj.name) caller.msg("You pick up %s." % obj.name)
caller.location.msg_contents("%s picks up %s." % caller.location.msg_contents("%s picks up %s." %
(caller.name, (caller.name,
obj.name), obj.name),
exclude=caller) exclude=caller)
# calling hook method # calling at_get hook method
obj.at_get(caller) obj.at_get(caller)
@ -308,6 +312,10 @@ class CmdDrop(COMMAND_DEFAULT_CLASS):
if not obj: if not obj:
return 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) obj.move_to(caller.location, quiet=True)
caller.msg("You drop %s." % (obj.name,)) caller.msg("You drop %s." % (obj.name,))
caller.location.msg_contents("%s drops %s." % caller.location.msg_contents("%s drops %s." %
@ -350,6 +358,11 @@ class CmdGive(COMMAND_DEFAULT_CLASS):
if not to_give.location == caller: if not to_give.location == caller:
caller.msg("You are not holding %s." % to_give.key) caller.msg("You are not holding %s." % to_give.key)
return return
# calling at_before_give hook method
if not to_give.at_before_give(caller, target):
return
# 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)