@tool
class_name RandomDelay extends DelayDecorator
## DelayDecorator which randomizes the wait time to a normal random sample each time it's run.

## Mean wait time, in seconds.
@export var mean_time := 1.0:
	set(value):
		mean_time = value
		randomize_wait_time()

## Standard deviation of wait time, in seconds.
@export var st_dev_time := 0.1:
	set(value):
		st_dev_time = value
		randomize_wait_time()


func _ready() -> void:
	randomize_wait_time()


func randomize_wait_time() -> void:
	wait_time = maxf(0.0, randfn(mean_time, st_dev_time))


func tick(actor: Node, blackboard: Blackboard) -> int:
	var total_time: float = blackboard.get_value(cache_key, 0.0, str(actor.get_instance_id()))
	if total_time == 0.0:
		randomize_wait_time()

	return super.tick(actor, blackboard)
