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

const ability = {
    name: 'S7',
    display_name: "Stone Cutter",
    button_icon: "textures/items/diamond",
    registry_name: "stone_cutter",
    description: 'Power Up yourself',
    level: "intermediate",
    cooldown: 12,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    filters: ["katana", "greatsword", "dagger", "pickaxe", "glaive", "sword", "longsword", "saber", "odachi"],
    slots: ["ability"],
    execute(player, weaponType, mode, weapon) {
        const cooldown = this.cooldown
        let playeSkills = JSON.parse(player.getDynamicProperty("entitySkills")).skillList
        let Booster
        playeSkills["cutting"] >= 1 ? Booster = 0.25 : Booster = 0.1
        player.runCommand("scoreboard players remove @s exhaust 40")
        player.playAnimation(`animation.minced.${weaponType}.ability_power_up`)
        let statuser = JSON.parse(player.getDynamicProperty("resetingStatus"))
        statuser["slashBoost"] = statuser.slashBoost + Booster
        statuser["targetNumMod"] = statuser.slashBoost - 3
        player.setDynamicProperty("resetingStatus", JSON.stringify(statuser))
        player.setProperty("aura:color", 2)
        system.runTimeout(()=>{
            player.setProperty("aura:color", 0)         
        },40)
        player.runCommandAsync("tag @s remove attack")
        player.runCommandAsync("inputpermission set @s movement enabled")
        cooldowns(player,this.name,cooldown,10)
    },
    resetStats(player) {
        let playeSkills = JSON.parse(player.getDynamicProperty("entitySkills")).skillList
        let Booster
        playeSkills["cutting"] >= 1 ? Booster = 0.25 : Booster = 0.1
        let statuser = JSON.parse(player.getDynamicProperty("resetingStatus"))
        statuser["slashBoost"] = statuser.slashBoost - Booster
        statuser["targetNumMod"] = statuser.targetNumMod + 3
        player.setDynamicProperty("resetingStatus", JSON.stringify(statuser))
        player.setProperty("aura:color", 0)
    }
}

export default ability