@tool
class_name GetRandomTarget extends ActionLeaf
## Picks a random navigable point near the actor and writes it to the blackboard.
##
## If the random point is not navigable, will return RUNNING and pick a new point next tick.

## Blackboard key under which to store the random target.
@export var blackboard_key := "target"

## Standard deviation of position in each direction, in game units.
@export var st_dev := Vector3(1, 0, 1)

## Maximum path length considered navigable, in game units.
@export var max_path_len := 16.0


func tick(actor: Node, blackboard: Blackboard) -> int:
	var beast := actor as GrunkBeast

	var target := Vector3(
		randfn(beast.global_position.x, st_dev.x),
		randfn(beast.global_position.y, st_dev.y),
		randfn(beast.global_position.z, st_dev.z)
	)

	if not beast.path_shorter_than(target, max_path_len):
		return RUNNING

	blackboard.set_value(blackboard_key, target)
	return SUCCESS
