extends Area3D

@export var event_name: StringName = &""
@export var target_group: StringName = &"player"
@export var quest_id_filter: String = ""
@export var one_shot: bool = true

var _triggered := false


func _ready() -> void:
	body_entered.connect(_on_body_entered)


func reset_trigger() -> void:
	_triggered = false
	set_deferred("monitoring", true)


func _on_body_entered(body: Node) -> void:
	if one_shot and _triggered:
		return
	if target_group != StringName() and not body.is_in_group(target_group):
		return
	if event_name == StringName():
		return
	if quest_id_filter.strip_edges() != "":
		if QuestManager == null or QuestManager.get_active_quest_id() != StringName(quest_id_filter):
			return
	if QuestManager:
		QuestManager.emit_event(event_name, {
			"body": body,
			"source": self,
		})
	if one_shot:
		_triggered = true
		set_deferred("monitoring", false)
