fix(action_manager): use items, closes #111
This commit is contained in:
@@ -55,20 +55,19 @@ func _get_event_to_queue(
|
||||
or combine_with):
|
||||
# or (combine_with && action in combine_with.node.combine_when_selected_action_is_in)):
|
||||
|
||||
# Check if object must be in inventory to be used
|
||||
if target.node.use_from_inventory_only:
|
||||
if escoria.inventory_manager.inventory_has(target.global_id):
|
||||
# Player has item in inventory, we check the element to use on
|
||||
if combine_with:
|
||||
var do_combine = true
|
||||
if combine_with.node is ESCItem \
|
||||
and combine_with.node.use_from_inventory_only\
|
||||
and not escoria.inventory_manager.inventory_has(
|
||||
combine_with.global_id
|
||||
):
|
||||
do_combine = false
|
||||
# Check if object is in inventory or is not required to be in inventory to be used
|
||||
if escoria.inventory_manager.inventory_has(target.global_id) or not target.node.use_from_inventory_only:
|
||||
# Player has item in inventory, we check the element to use on
|
||||
if combine_with:
|
||||
var do_combine = true
|
||||
if combine_with.node is ESCItem \
|
||||
and combine_with.node.use_from_inventory_only\
|
||||
and not escoria.inventory_manager.inventory_has(
|
||||
combine_with.global_id
|
||||
):
|
||||
do_combine = false
|
||||
|
||||
if do_combine:
|
||||
if do_combine:
|
||||
# var target_event = "%s %s" % [
|
||||
# action,
|
||||
# combine_with.global_id
|
||||
@@ -78,60 +77,60 @@ func _get_event_to_queue(
|
||||
# target.global_id
|
||||
# ]
|
||||
|
||||
if _has_event_with_target(target.events, action, combine_with.global_id):
|
||||
#if target.events.has(target_event):
|
||||
#event_to_return = target.events[target_event]
|
||||
event_to_return = target.events[action]
|
||||
#elif combine_with.events.has(combine_with_event)\
|
||||
elif _has_event_with_target(combine_with.events, action, target.global_id)\
|
||||
and not combine_with.node.combine_is_one_way:
|
||||
if _has_event_with_target(target.events, action, combine_with.global_id):
|
||||
#if target.events.has(target_event):
|
||||
#event_to_return = target.events[target_event]
|
||||
event_to_return = target.events[action]
|
||||
#elif combine_with.events.has(combine_with_event)\
|
||||
elif _has_event_with_target(combine_with.events, action, target.global_id)\
|
||||
and not combine_with.node.combine_is_one_way:
|
||||
|
||||
#event_to_return = combine_with.events[combine_with_event]
|
||||
event_to_return = combine_with.events[action]
|
||||
else:
|
||||
# Check to see if there isn't a "fallback" action to
|
||||
# run before we declare this a failure.
|
||||
if escoria.action_default_script \
|
||||
and escoria.action_default_script.events.has(action):
|
||||
|
||||
event_to_return = escoria.action_default_script.events[action]
|
||||
else:
|
||||
var errors = [
|
||||
"Attempted to execute action '%s' between item %s and item %s" % [
|
||||
action,
|
||||
target.global_id,
|
||||
combine_with.global_id
|
||||
],
|
||||
"Check that action ':%s %s' exists in the script of item '%s'" % [
|
||||
action,
|
||||
target.global_id,
|
||||
combine_with.global_id
|
||||
]
|
||||
]
|
||||
|
||||
if combine_with.node.combine_is_one_way:
|
||||
errors.append(
|
||||
("Reason: %s's item interaction " + \
|
||||
"is one-way.") % combine_with.global_id
|
||||
)
|
||||
|
||||
escoria.logger.warn(
|
||||
self,
|
||||
"Invalid action: " + str(errors)
|
||||
)
|
||||
#event_to_return = combine_with.events[combine_with_event]
|
||||
event_to_return = combine_with.events[action]
|
||||
else:
|
||||
escoria.logger.warn(
|
||||
self,
|
||||
"Invalid action on item: " +
|
||||
(
|
||||
"Trying to combine object %s with %s, "+
|
||||
"but %s is not in inventory."
|
||||
) % [
|
||||
# Check to see if there isn't a "fallback" action to
|
||||
# run before we declare this a failure.
|
||||
if escoria.action_default_script \
|
||||
and escoria.action_default_script.events.has(action):
|
||||
|
||||
event_to_return = escoria.action_default_script.events[action]
|
||||
else:
|
||||
var errors = [
|
||||
"Attempted to execute action '%s' between item %s and item %s" % [
|
||||
action,
|
||||
target.global_id,
|
||||
combine_with.global_id
|
||||
],
|
||||
"Check that action ':%s %s' exists in the script of item '%s'" % [
|
||||
action,
|
||||
target.global_id,
|
||||
combine_with.global_id,
|
||||
combine_with.global_id
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
if combine_with.node.combine_is_one_way:
|
||||
errors.append(
|
||||
("Reason: %s's item interaction " + \
|
||||
"is one-way.") % combine_with.global_id
|
||||
)
|
||||
|
||||
escoria.logger.warn(
|
||||
self,
|
||||
"Invalid action: " + str(errors)
|
||||
)
|
||||
else:
|
||||
escoria.logger.warn(
|
||||
self,
|
||||
"Invalid action on item: " +
|
||||
(
|
||||
"Trying to combine object %s with %s, "+
|
||||
"but %s is not in inventory."
|
||||
) % [
|
||||
target.global_id,
|
||||
combine_with.global_id,
|
||||
combine_with.global_id
|
||||
]
|
||||
)
|
||||
else:
|
||||
escoria.logger.warn(
|
||||
self,
|
||||
@@ -256,18 +255,12 @@ func perform_inputevent_on_object(
|
||||
# If clicked object needs a combination, and current target is set, then perform the combination.
|
||||
if need_combine and current_target:
|
||||
event_to_queue = _get_event_to_queue(current_action, current_tool, current_target)
|
||||
# If clicked object needs a combination but can only be used from inventory, then we need to wait
|
||||
# for the target.
|
||||
elif obj.node.use_from_inventory_only \
|
||||
and escoria.inventory_manager.inventory_has(obj.global_id) \
|
||||
and need_combine:
|
||||
current_tool = obj
|
||||
set_action_input_state(ACTION_INPUT_STATE.AWAITING_TARGET_ITEM)
|
||||
return
|
||||
# If clicked object needs a combination and doesn't require to be in inventory,
|
||||
# then we need to wait for the target.
|
||||
# If clicked object needs a combination then we need to wait for the target.
|
||||
elif need_combine:
|
||||
set_action_input_state(ACTION_INPUT_STATE.AWAITING_TARGET_ITEM)
|
||||
# If object is in inventory make it current tool.
|
||||
if escoria.inventory_manager.inventory_has(obj.global_id):
|
||||
current_tool = obj
|
||||
# If clicked object doesn't need a combination, then we simply run the action.
|
||||
else:
|
||||
event_to_queue = _get_event_to_queue(current_action, obj)
|
||||
@@ -276,7 +269,8 @@ func perform_inputevent_on_object(
|
||||
# Note that `event_to_queue` may still be null, but we do need to start the
|
||||
# player walking towards the destination.
|
||||
if current_action and not event_to_queue:
|
||||
clear_current_action()
|
||||
# MODIFIED FOR RETURN TO MONKEY UI
|
||||
# clear_current_action()
|
||||
action_finished.emit()
|
||||
return
|
||||
|
||||
|
||||
@@ -5,4 +5,4 @@ func set_cursor(texture: Texture) -> void:
|
||||
|
||||
func clear_cursor():
|
||||
Input.set_custom_mouse_cursor(null)
|
||||
escoria.action_manager.clear_current_tool()
|
||||
# escoria.action_manager.clear_current_tool()
|
||||
|
||||
Reference in New Issue
Block a user