Added at_before_give, at_before_get, and at_before_drop

Added in new hooks to the default object - at_before_give, at_before_get, and at_before_drop. By default, these hooks do nothing but return True - however, if overloaded, they can be used to execute code before an object is given, gotten, or dropped, and even prevent the action if made to return None or False.
This commit is contained in:
FlutterSprite 2017-09-26 15:04:04 -07:00 committed by Griatch
parent dd8e136cfc
commit 5ab670f3c8

View file

@ -1492,6 +1492,25 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
"""
pass
def at_before_get(self, getter, **kwargs):
"""
Called by the default `get` command before this object has been
picked up.
Args:
getter (Object): The object about to get this object.
**kwargs (dict): Arbitrary, optional arguments for users
overriding the call (unused by default).
Returns:
shouldget (bool): If the object should be gotten or not.
Notes:
If this method returns False/None, the getting is cancelled
before it is even started.
"""
return True
def at_get(self, getter, **kwargs):
"""
Called by the default `get` command when this object has been
@ -1504,11 +1523,32 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
Notes:
This hook cannot stop the pickup from happening. Use
permissions for that.
permissions or the at_before_get() hook for that.
"""
pass
def at_before_give(self, giver, getter, **kwargs):
"""
Called by the default `give` command before this object has been
given.
Args:
giver (Object): The object about to give this object.
getter (Object): The object about to get this object.
**kwargs (dict): Arbitrary, optional arguments for users
overriding the call (unused by default).
Returns:
shouldgive (bool): If the object should be given or not.
Notes:
If this method returns False/None, the giving is cancelled
before it is even started.
"""
return True
def at_give(self, giver, getter, **kwargs):
"""
Called by the default `give` command when this object has been
@ -1522,11 +1562,31 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
Notes:
This hook cannot stop the give from happening. Use
permissions for that.
permissions or the at_before_give() hook for that.
"""
pass
def at_before_drop(self, dropper, **kwargs):
"""
Called by the default `drop` command before this object has been
dropped.
Args:
dropper (Object): The object which will drop this object.
**kwargs (dict): Arbitrary, optional arguments for users
overriding the call (unused by default).
Returns:
shoulddrop (bool): If the object should be dropped or not.
Notes:
If this method returns False/None, the dropping is cancelled
before it is even started.
"""
return True
def at_drop(self, dropper, **kwargs):
"""
Called by the default `drop` command when this object has been
@ -1539,7 +1599,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
Notes:
This hook cannot stop the drop from happening. Use
permissions from that.
permissions or the at_before_drop() hook for that.
"""
pass