mirror of
https://github.com/tonytins/citylimits.git
synced 2025-03-25 16:29:05 +00:00
35 lines
848 B
GDScript
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
|