@tool
class_name PickRandomFromGroup extends ActionLeaf
## Picks a random node in the given group and stores it in the blackboard.
##
## Returns FAILURE if there are no nodes in the given group.

## Blackboard key under which the node will be stored.
@export var blackboard_key := "target"

## Name of the group to pick from.
@export var group: String


func tick(actor: Node, blackboard: Blackboard) -> int:
	var nodes: Array[Node] = actor.get_tree().get_nodes_in_group(group)
	if not nodes:
		return FAILURE
	blackboard.set_value(blackboard_key, nodes.pick_random())
	return SUCCESS
