package pw.hamzantal.bloodmoon.listeners

import hazae41.minecraft.kutils.bukkit.schedule
import org.bukkit.entity.Player
import org.bukkit.entity.Zombie
import org.bukkit.event.entity.EntityDamageByEntityEvent
import pw.hamzantal.bloodmoon.BMData
import pw.hamzantal.bloodmoon.BloodMoon
import pw.hamzantal.bloodmoon.specialattacks.dunking
import pw.hamzantal.bloodmoon.specialattacks.zombieAttacks

val cooldown = mutableListOf<Player>()

fun zombieHit(e: EntityDamageByEntityEvent) {
    if (!BMData.running || e.damager !is Zombie || e.entity !is Player
        || BMData.transformed.any { (d, _) -> d.entity == e.damager }
    ) return


    val p = e.entity as Player
    if (e.damager in dunking || p in dunking) {
        e.isCancelled = true
        return
    }

    if (p in cooldown) return
    cooldown += p

    zombieAttacks.random().spawnAttack(e.damager as Zombie, p, BloodMoon.pl)
    BloodMoon.pl.schedule(delay = 4) {
        cooldown -= p
    }
}