package pw.hamzantal.bloodmoon.specialattacks

import org.bukkit.entity.Player
import org.bukkit.entity.TippedArrow
import org.bukkit.entity.Zombie
import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffectType
import org.bukkit.util.Vector
import pw.hamzantal.bloodmoon.BloodMoon

class ArrowBarrage : SpecialAttack<Zombie> {
    override fun spawnAttack(attacker: Zombie, p: Player, pl: BloodMoon) {
        pl.server.scheduler.scheduleSyncDelayedTask(pl, {
            val loc = attacker.location
            val direction = loc.direction
            val baseSpawnLocation = loc.add(direction.clone().multiply(7)).apply { y -= 1 }
            val vector = direction.clone().multiply(Vector(-1.0, 0.1, -1.0))

            p.world.spawnArrow(baseSpawnLocation, vector, 1f, 0f, TippedArrow::class.java).apply {
                addCustomEffect(PotionEffect(PotionEffectType.BLINDNESS, 60, 2), true)
                addCustomEffect(PotionEffect(PotionEffectType.SLOW, 80, 1), true)
                addCustomEffect(PotionEffect(PotionEffectType.HEAL, 5, 1), true)
                knockbackStrength = 2
            }
        }, 8)

    }
}
