Move some item logic from CmdUse to new func use_item
This commit is contained in:
parent
5ce18379c0
commit
91c333e6d3
1 changed files with 32 additions and 25 deletions
|
|
@ -323,6 +323,36 @@ def spend_item_use(item, user):
|
||||||
user.msg("After using %s, you are left with %s." % (item, residue))
|
user.msg("After using %s, you are left with %s." % (item, residue))
|
||||||
item.delete() # Delete the spent item
|
item.delete() # Delete the spent item
|
||||||
|
|
||||||
|
def use_item(user, item, target):
|
||||||
|
"""
|
||||||
|
Performs the action of using an item.
|
||||||
|
"""
|
||||||
|
# Set kwargs to pass to item_func
|
||||||
|
kwargs = {}
|
||||||
|
if item.db.item_kwargs:
|
||||||
|
kwargs = item.db.item_kwargs
|
||||||
|
|
||||||
|
# Match item_func string to function
|
||||||
|
try:
|
||||||
|
item_func = ITEMFUNCS[item.db.item_func]
|
||||||
|
except KeyError:
|
||||||
|
user.msg("ERROR: %s not defined in ITEMFUNCS" % item.db.item_func)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Call the item function - abort if it returns False, indicating an error.
|
||||||
|
# This performs the actual action of using the item.
|
||||||
|
# Regardless of what the function returns (if anything), it's still executed.
|
||||||
|
if item_func(item, user, target, **kwargs) == False:
|
||||||
|
return
|
||||||
|
|
||||||
|
# If we haven't returned yet, we assume the item was used successfully.
|
||||||
|
# Spend one use if item has limited uses
|
||||||
|
spend_item_use(item, user)
|
||||||
|
|
||||||
|
# Spend an action if in combat
|
||||||
|
if is_in_combat(user):
|
||||||
|
spend_action(user, 1, action_name="item")
|
||||||
|
|
||||||
"""
|
"""
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
CHARACTER TYPECLASS
|
CHARACTER TYPECLASS
|
||||||
|
|
@ -815,31 +845,8 @@ class CmdUse(MuxCommand):
|
||||||
self.caller.msg("'%s' has no uses remaining." % item.key.capitalize())
|
self.caller.msg("'%s' has no uses remaining." % item.key.capitalize())
|
||||||
return
|
return
|
||||||
|
|
||||||
# Set kwargs to pass to item_func
|
# If everything checks out, call the use_item function
|
||||||
kwargs = {}
|
use_item(self.caller, item, target)
|
||||||
if item.db.item_kwargs:
|
|
||||||
kwargs = item.db.item_kwargs
|
|
||||||
|
|
||||||
# Match item_func string to function
|
|
||||||
try:
|
|
||||||
item_func = ITEMFUNCS[item.db.item_func]
|
|
||||||
except KeyError:
|
|
||||||
self.caller.msg("ERROR: %s not defined in ITEMFUNCS" % item.db.item_func)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Call the item function - abort if it returns False, indicating an error.
|
|
||||||
# This performs the actual action of using the item.
|
|
||||||
# Regardless of what the function returns (if anything), it's still executed.
|
|
||||||
if item_func(item, self.caller, target, **kwargs) == False:
|
|
||||||
return
|
|
||||||
|
|
||||||
# If we haven't returned yet, we assume the item was used successfully.
|
|
||||||
# Spend one use if item has limited uses
|
|
||||||
spend_item_use(item, self.caller)
|
|
||||||
|
|
||||||
# Spend an action if in combat
|
|
||||||
if is_in_combat(self.caller):
|
|
||||||
spend_action(self.caller, 1, action_name="item")
|
|
||||||
|
|
||||||
|
|
||||||
class BattleCmdSet(default_cmds.CharacterCmdSet):
|
class BattleCmdSet(default_cmds.CharacterCmdSet):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue