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

const weaponBoost = new Map([
        ["gauntlet", 5.5],
        ["katar", 3.25],
    ])

const ability = {
    name: 'U1',
    display_name: "Uppercut",
    button_icon: "textures/items/diamond",
    registry_name: "uppercut",
    description: 'Upper Cuts your opponent and deals heavy damage with stagger',
    indexNum: 17,
    level: "basic",
    cooldown: 100,
    damages: 15,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    filters: ["gauntlet", "katar"],
    slots: ["ability","ultimate"],
    horizontal: 0.25,
    vertical: 0,
    execute(player, weaponType, mode, weapon) {
        const cooldown = this.cooldown
        const launch_power = this.horizontal
        const upwards = this.vertical
        let equipment = player.getComponent("minecraft:equippable");
        let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
        switch(mode) {
            case ("ultimate"): {
                let cameras = [
                    {
                        times: 2,
                        timeStamp: "default",
                        posX: 5.0,
                        posY: 2.0,
                        posZ: 0.0,
                        cameraType: "minecraft:free",
                        easing: 0.1,
                        transitionType: "Linear",
                        facing: player.location
                    },
                    {
                        times: 4,
                        timeStamp: "attack_start",
                        posX: 2.0,
                        posY: 1.8,
                        posZ: 0.0,
                        cameraType: "minecraft:free",
                        easing: 1,
                        transitionType: "Linear",
                        facing: ""
                    },
                    {
                        times: 30,
                        timeStamp: "fade",
                        posX: 2.0,
                        posY: 1.0,
                        posZ: -3.5,
                        cameraType: "minecraft:free",
                        easing: 0.1,
                        transitionType: "Linear",
                        facing: ""
                    },
                    {
                        times: 35,
                        timeStamp: "default",
                        posX: 2.0,
                        posY: 1.0,
                        posZ: -3.5,
                        cameraType: "minecraft:free",
                        easing: 0.1,
                        transitionType: "Linear",
                        facing: player.location
                    },
                    {
                        times: 1.0,
                        timeStamp: "restore_movement",
                        posX: 0.0,
                        posY: 1.0,
                        posZ: 0.0,
                        cameraType: "minecraft:free",
                        easing: 0.1,
                        transitionType: "Linear",
                        facing: ""
                    }
                ]
                launchPlayer(player, launch_power, upwards)
                player.playAnimation(`animation.minced.gauntlet.ultimate_uppercut`)
                //player.runCommand(`camerashake add @s 0.25 1 positional`)
                ultimatum(player, "S5", weaponType, 67, cameras, 5, (10 * 1.5), 20, 10, 34, 1, 5, "line_target", "", [10,3], "long", "", "blunt", "", 20, 10, true, "normal",mainhand, 1)
              cooldowns(player,this.name,cooldown,cooldown)
            } break;
            case ("charge"): {
              launchPlayer(player, launch_power, upwards)
              player.playAnimation(`animation.minced.${weaponType}.trigger_uppercut`)
              player.runCommand(`camerashake add @s 0.25 1 positional`)
              attackPlayerMeikyu(player, 5, (10 * 1.5), 20, 10, 20, 1, 5, "line_target", "", [0.5,0.75], "long", "", "slash", "", 20, 10, true, "normal",mainhand, 1, true)
              cooldowns(player,this.name,cooldown,cooldown)
            } break;
            default: {
              launchPlayer(player, launch_power, upwards)
              player.playAnimation(`animation.minced.${weaponType}.ability_uppercut`)
              player.runCommand(`camerashake add @s 0.25 1 positional`)
              attackPlayerMeikyu(player, 5, (10 * 1.5), 20, 10, 20, 1, 5, "line_target", "", [0.5,0.75], "long", "", "slash", "", 20, 10, true, "no cooldown",mainhand,1, true)
              cooldowns(player,this.name,cooldown,cooldown)
            } break;
          }
    }, 
    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