extends BossAttack

var fireball_scene = preload("res://scenes/nodes/boss/boss_attacks/fireball.tscn")

@export var fireball_directions : Array[Vector2]
@export var fireball_speed = 300
@export var distance_to_player : float = 300.0
@export var perform_timer = 2.0
var _perform_timer = 0.0

func start_prepare():
	if boss_behavior:
		boss_behavior.start_navigation(distance_to_player)

func prepare(_delta : float):
	if boss_behavior:
		boss_behavior.navigate()

func end_prepare():
	if boss_behavior:
		boss_behavior.end_navigation()

func start_perform():
	var fb = fireball_scene.instantiate() as Fireball
	fb.scale = Vector2(0.2, 0.2)
	add_child(fb)
	fb.global_position = get_parent().global_position
	var tween = get_tree().create_tween()
	tween.tween_property(fb, "scale", Vector2(1, 1), 0.5)
	tween.play()
	await tween.finished
	fb.queue_free()
	tween.kill()
	
	_perform_timer = perform_timer
	for direction in fireball_directions:
		var fireball = fireball_scene.instantiate() as Fireball
		add_child(fireball)
		fireball.global_position = get_parent().global_position
		fireball.start(direction, 1, fireball_speed)

func perform(delta : float):
	if boss_behavior:
		boss_behavior.navigate()
	if _perform_timer > 0:
		_perform_timer -= delta
		if _perform_timer <= 0:
			emit_attack_performed()
