extends "res://src/Spell.gd"

var Fireball = preload("res://src/Fireball.gd")

var UTIL = preload("res://src/Utility.gd")

var sound_fire = preload("res://sound/fire-0.wav")

var asp # audio player

func _ready():
  castingTime = 1.5
  asp = AudioStreamPlayer.new()
  self.add_child(asp)
  
func effect1():
  var player = $"/root/World/ys/player"
  var pos = player.position + player.spr.offset
  var dir = player.dir
  var fb = Fireball.new()
  fb.initialize(pos + dir * Vector2(30, 30) - Vector2(0, 20), dir)
  $"/root/World/ys".add_child(fb)
  if not asp.is_playing():
    asp.set_volume_db(-10)
    asp.stream = sound_fire
    asp.play()

func effect2():
  var player = $"/root/World/ys/player"
  var pos = player.position
  for idx in [0, 1, 7]:
    var dir = UTIL.rotatedDir(player.dir, idx)
    var fb = Fireball.new()
    fb.initialize(pos + dir * Vector2(30, 30) - Vector2(0, 20), dir)
    $"/root/World/ys".add_child(fb)
    if not asp.is_playing():
      asp.set_volume_db(0)
      asp.stream = sound_fire
      asp.play()