package pw.hamzantal.bloodmoon.specialattacks

import hazae41.minecraft.kutils.bukkit.schedule
import org.bukkit.entity.Entity
import org.bukkit.entity.Player
import org.bukkit.entity.Zombie
import org.bukkit.util.Vector
import pw.hamzantal.bloodmoon.BloodMoon

val dunking = hashMapOf<Player, Entity>()


class SlamDunk : SpecialAttack<Zombie> {

    private val steps = listOf(
        Vector(0.1, 1.0, 0.1),
        Vector(0.1, 0.8, 0.1),
        Vector(0.1, 0.6, 0.1),
        Vector(0.1, 0.4, 0.1),
        Vector(0.1, 0.1, 0.1),
        Vector(0.1, 0.05, 0.1),
        Vector(0, -1, 0),
        Vector(0, -1, 0)
    )

    override fun spawnAttack(attacker: Zombie, p: Player, pl: BloodMoon) {
        dunking += p to attacker

        var i = 0
        var taskNumber = 0
        attacker.isInvulnerable = true

        taskNumber = BloodMoon.pl.server.scheduler.scheduleSyncRepeatingTask(BloodMoon.pl, {
            p.velocity = steps[i]
            attacker.velocity = steps[i]

            if (++i == steps.size) {
                BloodMoon.pl.server.scheduler.cancelTask(taskNumber)
            }
        }, 0, 4)

        pl.schedule(delay = 4) {
            dunking -= p
            attacker.isInvulnerable = false
        }
    }
}