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

const weaponBoost = new Map([
        ["glaive", 1],
        ["rapier", 3],
    ])

const ability = {
    name: 'D1',
    display_name: "Despair",
    button_icon: "textures/items/diamond",
    registry_name: "despair",
    description: 'Use your pain to boost your slash attacks',
    indexNum: 30,
    level: "intermediate",
    cooldown: 30,
    damages: 10,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : true,
    filters: ["greatsword"],
    slots: ["ultimate", "ability"],
    coodname: "D1",
    horizontal: 0 ,
    vertical: 0,
    execute(player, weaponType, mode, weapon) {
        const cooldown = this.cooldown
        switch(mode) {
            case "ultimate":{
                player.runCommand("scoreboard players remove @s exhaust 40")
                player.playAnimation(`animation.minced.greatsword.strenght_style.ultimate_despair`, {
                    stopExpression: "q.all_animations_finished"
                })
                let cameras = [
                    {
                        times: 2,
                        timeStamp: "fade",
                        posX: 2.0,
                        posY: 1.0,
                        posZ: -3.5,
                        cameraType: "minecraft:free",
                        easing: 0.1,
                        transitionType: "Linear",
                        facing: ""
                    },
                    {
                        times: 7,
                        timeStamp: "default",
                        posX: -2.0,
                        posY: 1.5,
                        posZ: 1.5,
                        cameraType: "minecraft:free",
                        easing: 0,
                        transitionType: "Linear",
                    },
                    {
                        times: 7,
                        timeStamp: "default",
                        posX: -2.0,
                        posY: 1.5,
                        posZ: 1.5,
                        cameraType: "minecraft:free",
                        easing: 0,
                        transitionType: "Linear",
                    },
                    {
                        times: 10,
                        timeStamp: "default",
                        posX: -2.0,
                        posY: 1.5,
                        posZ: 1.5,
                        cameraType: "minecraft:free",
                        easing: 0,
                        transitionType: "Linear",
                    },
                    {
                        times: 15,
                        timeStamp: "default",
                        posX: -2.0,
                        posY: 1.5,
                        posZ: 1.5,
                        cameraType: "minecraft:free",
                        easing: 0,
                        transitionType: "Linear",
                    },
                    {
                        times: 20,
                        timeStamp: "default",
                        posX: -2.0,
                        posY: 1.5,
                        posZ: 1.5,
                        cameraType: "minecraft:free",
                        easing: 0,
                        transitionType: "Linear",
                    },
                    {
                        times: 12,
                        timeStamp: "add_status",
                        changes: (Math.max((0.25 * (player.getComponent("minecraft:health").defaultValue - player.getComponent("minecraft:health").currentValue)),4)),
                        boost: "slashBoost",
                    },
                    {
                        times: 23,
                        timeStamp: "fade",
                        posX: 2.0,
                        posY: 1.0,
                        posZ: -3.5,
                        cameraType: "minecraft:free",
                        easing: 0.1,
                        transitionType: "Linear",
                        facing: ""
                    },
                    {
                        times: 30,
                        timeStamp: "default",
                        posX: 2.0,
                        posY: 2.0,
                        posZ: 1.5,
                        cameraType: "minecraft:free",
                        easing: 0,
                        transitionType: "Linear",
                    },
                    {
                        times: 59,
                        timeStamp: "shake",
                        intensity: 1.0,
                        time: 1.0,
                        shakeType: "rotational"
                    },
                    {
                        times: 50,
                        timeStamp: "restore_movement",
                        posX: 1.0,
                        posY: 1.5,
                        posZ: 1,
                        cameraType: "minecraft:free",
                        easing: 0.1,
                        transitionType: "outBounce",
                    }
                ]
                ultimatum(player, "D1", weapon, 10, cameras, 5, (10 * 1.5), 20, 10, 50, 1, 5, "line_target", "", [0,0], "long", "", "slash", "", 20, 10, true, "normal","", 1, true)
                player.runCommandAsync("tag @s remove attack")
                player.runCommandAsync("inputpermission set @s movement enabled")
                cooldowns(player,this.coodname,cooldown,15)
                //player.playAnimation("animation.minced.abilities.despair_particles")
            } break;
            default:{
                player.runCommand("scoreboard players remove @s exhaust 40")
                player.playAnimation(`animation.minced.greatsword.strenght_style.ultimate_despair`, {
                    stopExpression: "q.all_animations_finished"
                })
                let statuser = JSON.parse(player.getDynamicProperty("resetingStatus"))
                statuser["slashBoost"] = statuser.slashBoost + (Math.max((0.25 * (player.getComponent("minecraft:health").defaultValue - player.getComponent("minecraft:health").currentValue)),1.5))
                player.setDynamicProperty("resetingStatus", JSON.stringify(statuser))
                player.runCommandAsync("tag @s remove attack")
                player.runCommandAsync("inputpermission set @s movement enabled")
                cooldowns(player,this.name,cooldown,15)
            } break;
        }
       
    },
    resetStats(player) {
        let statuser = JSON.parse(player.getDynamicProperty("resetingStatus"))
        statuser["slashBoost"] = 0
        player.setDynamicProperty("resetingStatus", JSON.stringify(statuser))
        player.setProperty("aura:color", 0)
    }
}

export default ability