Class CompositeTaskNode<C>
java.lang.Object
privbot.task.CompositeTaskNode<C>
- Type Parameters:
C- the context type shared across all nodes in the tree
- All Implemented Interfaces:
TaskNode<C>
A task node that holds child nodes and delegates execution using a strategy.
Two strategies are available:
CompositeTaskNode.Strategy.PRIORITY— Evaluates children from highest to lowest priority. The first child whoseTaskNode.shouldExecute(Object)returns true is executed. This is the default and matches how boss phase handlers typically work.CompositeTaskNode.Strategy.SEQUENCE— Runs children in insertion order. Each child runs until complete, then the next child starts. Useful for linear workflows like "bank → walk to spot → fight → loot → repeat".
Disabled children (TaskNode.isEnabled() returning false) are skipped.
Exceptions thrown by children are caught and logged, allowing the tree to continue.
Usage Example (Priority):
CompositeTaskNode<MyContext> root = new CompositeTaskNode<>("Combat", Strategy.PRIORITY);
root.addNode(new EatFoodTask()); // priority 90
root.addNode(new PrayerSwitchTask()); // priority 85
root.addNode(new AttackNpcTask()); // priority 50
// EatFood checked first, then PrayerSwitch, then Attack
Usage Example (Sequence):
CompositeTaskNode<MyContext> root = new CompositeTaskNode<>("Bank Run", Strategy.SEQUENCE);
root.addNode(new WalkToBankTask());
root.addNode(new DepositLootTask());
root.addNode(new WithdrawSuppliesTask());
root.addNode(new WalkToSpotTask());
// Runs in order; each must complete before the next starts
Nesting:
Composites can contain other composites, forming a tree:
CompositeTaskNode<Ctx> root = new CompositeTaskNode<>("Main", Strategy.PRIORITY);
root.addNode(emergencyComposite); // priority 100 — eat/teleport
root.addNode(combatComposite); // priority 50 — fight loop
root.addNode(bankingSequence); // priority 10 — bank run
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumExecution strategy for child nodes. -
Constructor Summary
ConstructorsConstructorDescriptionCompositeTaskNode(String name, CompositeTaskNode.Strategy strategy) Creates a composite task node with default priority (0).CompositeTaskNode(String name, CompositeTaskNode.Strategy strategy, int priority) Creates a composite task node. -
Method Summary
Modifier and TypeMethodDescriptionAdds a child task node.voidcleanup()Propagates cleanup to all children.booleanCompositeTaskNode.Strategy.PRIORITY: runs the highest-priority enabled child that validates; if it throws, the next candidate is tried.Returns the currently active child (the one that last executed), or null.Returns an unmodifiable view of the children.getName()The name given to the constructor.intThe priority given to the constructor (0 by default)."name > activeChildStatus"while a child is active, otherwise the name.booleanisComplete(C ctx) CompositeTaskNode.Strategy.PRIORITY: complete when no enabled child validates.booleanremoveNode(TaskNode<C> child) Removes a child task node.voidreset()Rewinds a sequence to its first child, clears the active node and resets every child.booleanshouldExecute(C ctx) CompositeTaskNode.Strategy.PRIORITY: true when any enabled child validates (checked in insertion order).
-
Constructor Details
-
CompositeTaskNode
Creates a composite task node.- Parameters:
name- human-readable name for logging and overlay displaystrategy- execution strategy for childrenpriority- priority of this composite within its parent
-
CompositeTaskNode
Creates a composite task node with default priority (0).- Parameters:
name- human-readable namestrategy- execution strategy for children
-
-
Method Details
-
addNode
Adds a child task node.- Parameters:
child- the task node to add- Returns:
- this composite, for chaining
-
removeNode
-
getChildren
-
getActiveNode
-
shouldExecute
CompositeTaskNode.Strategy.PRIORITY: true when any enabled child validates (checked in insertion order).CompositeTaskNode.Strategy.SEQUENCE: true while the sequence has children left, without asking them.- Specified by:
shouldExecutein interfaceTaskNode<C>- Parameters:
ctx- the shared context containing state and dependencies- Returns:
- true if the task should execute, false otherwise
-
execute
CompositeTaskNode.Strategy.PRIORITY: runs the highest-priority enabled child that validates; if it throws, the next candidate is tried.CompositeTaskNode.Strategy.SEQUENCE: skips children that reportTaskNode.isComplete(C), then runs the current child if it validates and advances once it is complete. A disabled child in a sequence is skipped. Returns the executed child's result, or false when nothing ran. -
isComplete
CompositeTaskNode.Strategy.PRIORITY: complete when no enabled child validates.CompositeTaskNode.Strategy.SEQUENCE: complete once every child has been passed.- Specified by:
isCompletein interfaceTaskNode<C>- Parameters:
ctx- the shared context- Returns:
- true if the task has completed, false if still in progress
-
reset
-
cleanup
-
getPriority
public int getPriority()The priority given to the constructor (0 by default).- Specified by:
getPriorityin interfaceTaskNode<C>- Returns:
- the task priority (higher = more important). Default is 0.
-
getName
-
getStatus
-