citylimits/addons/beehave/nodes/composites/sequence_star.gd
2023-01-21 04:04:13 -05:00

35 lines
848 B
GDScript

# Special implementation of sequencer who will execute
# successful nodes only once until all nodes were successful
extends Composite
class_name SequenceStarComposite, "../../icons/sequencer_star.svg"
var successful_index = 0
func tick(actor, blackboard):
for c in get_children():
if c.get_index() < successful_index:
continue
var response = c.tick(actor, blackboard)
if c is ConditionLeaf:
blackboard.set("last_condition", c)
blackboard.set("last_condition_status", response)
if response != SUCCESS:
if response == FAILURE:
successful_index = 0
if c is ActionLeaf and response == RUNNING:
blackboard.set("running_action", c)
return response
else:
successful_index += 1
if successful_index == get_child_count():
successful_index = 0
return SUCCESS
else:
successful_index = 0
return FAILURE