extends Node2D


# Declare member variables here. Examples:
# var a: int = 2
# var b: String = "text"
export var is_armed = false

var trigger_zone_entered: bool = false


func _ready() -> void:
	if(!is_armed):
		if($HarmfulArea.is_in_group("harmful")):
			$HarmfulArea.remove_from_group("harmful")
		$Sprite/AnimationPlayer.play("unarmed")
	else:
		$HarmfulArea.add_to_group("harmful")
		$Sprite/AnimationPlayer.play("armed")


func _on_Timer_timeout() -> void:
	is_armed = true
	$HarmfulArea.add_to_group("harmful")
	$Sprite/AnimationPlayer.play("arming")


func _on_AnimationPlayer_animation_finished(anim_name: String) -> void:
	if(anim_name == "arming"):
		$Sprite/AnimationPlayer.play("armed")


func _on_DetectionArea_area_exited(area: Area2D) -> void:
	if(area.is_in_group("player") && !$HarmfulArea.is_in_group("harmful")
		&& trigger_zone_entered):
		$Timer.start()
		trigger_zone_entered = false


func _on_HarmfulArea_area_entered(area: Area2D) -> void:
	if(area.is_in_group("player")):
		trigger_zone_entered = true
