import { world, system } from "@minecraft/server";
import { launchPlayer } from "./../../util/movements.js";
import { cooldowns } from "./../../util/utils.js";

const weaponBoost = new Map([
        ["dagger", 1],
        ["spear", 2.65],
    ])

const ability = {
    name: 'T4',
    display_name: "Taunt",
    button_icon: "textures/items/diamond",
    registry_name: "taunt",
    description: 'Taunts Enemies To attack you',
    indexNum: 22,
    level: "intermediate",
    cooldown: 1000,
    damages: 15,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    coodname: "tntcd",
    filters: ["shield", "dagger"],
    slots: ["ability"],
    horizontal: 0.25,
    vertical: 0,
    execute(player, weaponType, mode, weapon) {
        const cooldown = this.cooldown
        const dist = this.distance
        const launch_power = this.horizontal
        const upwards = this.vertical
        player.runCommand("scoreboard players remove @s exhaust 25")
        launchPlayer(player, launch_power, upwards)
        player.playAnimation(`animation.minced.${weaponType}.ability_taunt`)
        if(charge >= this.maxChargeTime) {
            player.setProperty("aura:color", 2)
            let run = system.runInterval(()=>{
                player.setProperty("aura:color", 0)          
                system.clearRun(run)
            },1000)
            player.runCommand(`execute as @s run damage @e[name=!${player.name},tag=!${player.name},r=${(dist + 5)}] 0 entity_attack`)
        } else{ 
            player.setProperty("aura:color", 2)
            let run = system.runInterval(()=>{
                player.setProperty("aura:color", 0)          
                system.clearRun(run)
            },1000)
            player.runCommand(`execute as @s run damage @e[name=!${player.name},tag=!${player.name},r=${dist}] 0 entity_attack`)
        }
        cooldowns(player,this.name,cooldown, cooldown)
    }, 
    resetStats(player) {
        let statuser = JSON.parse(player.getDynamicProperty("resetingStatus"))
        statuser["Boost"] = statuser.Boost - 0.2
        player.setDynamicProperty("resetingStatus", JSON.stringify(statuser))
        player.setProperty("aura:color", 0)
    }
}

export default ability