Interface TaskNode<C>
- Type Parameters:
C- the context type shared across all nodes in the tree
- All Known Implementing Classes:
Child,CompositeTaskNode,Parent,SimpleNode
public interface TaskNode<C>
Base interface for all task nodes in the PrivBot task framework.
A task node represents a self-contained, testable unit of automation logic
that can be composed into trees using CompositeTaskNode or grouped
through Parent/Child. Task nodes follow a state machine
pattern with clear entry/exit conditions.
The generic type parameter C is the shared context object that all
tasks in a tree receive. Each plugin defines its own context type containing
the state and dependencies its tasks need (e.g., VerzikContext,
SlayerContext).
For simple single-tick tasks, extend SimpleNode instead of
implementing this interface directly.
Usage Example:
public class EatFoodTask extends SimpleNode<MyContext> {
public EatFoodTask() {
super("Eat Food", 80);
}
@Override
public boolean shouldExecute(MyContext ctx) {
return ctx.combat.isInCombat()
&& ctx.inventory.contains("Shark");
}
@Override
public boolean execute(MyContext ctx) {
return ctx.inventory.eatFirst("Shark");
}
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidcleanup()Cleanup lifecycle hook called when the script shuts down or the tree is torn down.booleanExecutes the task's main logic.getName()Gets a human-readable name for this task.default intGets the numeric priority of this task.default StringGets the current status description for overlay/GUI display.booleanisComplete(C ctx) Checks if the task has completed its current cycle.default booleanReturns whether this task node is enabled.voidreset()Resets the task's internal state.booleanshouldExecute(C ctx) Checks if this task should currently execute.
-
Method Details
-
shouldExecute
Checks if this task should currently execute. This represents the entry condition for the task.- Parameters:
ctx- the shared context containing state and dependencies- Returns:
- true if the task should execute, false otherwise
-
execute
Executes the task's main logic. Called whenshouldExecute(C)returns true.- Parameters:
ctx- the shared context- Returns:
- true if the task performed an action (blocks sibling tasks from executing this tick), false otherwise
-
isComplete
Checks if the task has completed its current cycle. Used for tasks that span multiple ticks (e.g., walking to a destination, waiting for an animation to finish).- Parameters:
ctx- the shared context- Returns:
- true if the task has completed, false if still in progress
-
reset
void reset()Resets the task's internal state. Called when transitioning phases, restarting the script, or when the parent composite node resets. -
getPriority
default int getPriority()Gets the numeric priority of this task. Higher numbers run first. Equal priorities keep registration order.- Returns:
- the task priority (higher = more important). Default is 0.
-
getName
String getName()Gets a human-readable name for this task. Used for debugging, logging, and overlay display.- Returns:
- the task name
-
getStatus
-
isEnabled
default boolean isEnabled()Returns whether this task node is enabled. Disabled nodes are skipped byCompositeTaskNodeduring execution.- Returns:
- true if this node is enabled, false if it should be skipped
-
cleanup
default void cleanup()Cleanup lifecycle hook called when the script shuts down or the tree is torn down. Override to release resources held by this node.
-