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


const weaponBoost = new Map([
        ["spear", 3.5],
        ["glaive", 4.5],
    ])

const ability = {
    name: 'Y1',
    display_name: "Dragon Awakening",
    button_icon: "textures/items/diamond",
    registry_name: "ya_zi",
    description: 'Swings in front of.you to damage enemies',
    indexNum: 25,
    level: "saint",
    cooldown: 100,
    damages: 15,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : true,
    filters: ["glaive"],
    slots: ["ultimate", "charge","ability"],
    anim_prefix: "ya_zi",
    coodname: "yzcd",
    horizontal: 3.5,
    vertical: 0.9,
    execute(player, weaponType, mode, weapon) {
        const cooldown = this.cooldown
        const damage = this.damages
        const launch_power = this.horizontal
        const upwards = this.vertical
        player.runCommand("scoreboard players remove @s exhaust 40")
        let equipment = player.getComponent("minecraft:equippable");
        let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
        switch(mode) {
            case ("ultimate"): {
                let cameras = [
                    {
                        times: 2,
                        timeStamp: "default",
                        posX: 0.0,
                        posY: 1.5,
                        posZ: 5.0,
                        cameraType: "minecraft:free",
                        easing: 0.1,
                        transitionType: "Linear",
                        facing: player.getHeadLocation()
                    },
                    {
                        times: 4,
                        timeStamp: "default",
                        posX: 0.0,
                        posY: 1.5,
                        posZ: 1.0,
                        cameraType: "minecraft:free",
                        easing: 2,
                        transitionType: "Linear",
                        facing: player.getHeadLocation()
                    },
                    {
                        times: 44,
                        timeStamp: "default",
                        posX: 0.0,
                        posY: 1.6,
                        posZ: 0.9,
                        cameraType: "minecraft:free",
                        easing: 0.3,
                        transitionType: "Linear",
                        facing: player.getHeadLocation()
                    },
                    {
                        times: 1.0,
                        timeStamp: "restore_movement",
                        posX: 0.0,
                        posY: 1.6,
                        posZ: 0.9,
                        cameraType: "minecraft:free",
                        easing: 0.1,
                        transitionType: "Linear",
                        facing: player.getHeadLocation()
                    }
                ]
                player.playAnimation(`animation.minced.${weaponType}.ultimate_ya_zi`)
                player.playAnimation(`animation.minced.${weaponType}.yazi_particles`)
                //player.runCommand(`camerashake add @s 0.25 1 positional`)
                player.setProperty("part:special_model", 1)
                ultimatum(player, "Y1", weaponType, 55, cameras, 5, (10 * 1.5), 20, 10, 34, 1, 5, "line_target", "", [10,3], "long", "", "slash", "", 20, 10, true, "normal",mainhand, 1)
                cooldowns(player,this.name,cooldown,90)
            } break;
            case ("charge"): {
                launchPlayer(player, 3, 0.25)
                let charger = world.scoreboard.getObjective("chargecount").getScore(player)
                let chargeTest = Math.floor(charger / 10)
                player.playAnimation(`animation.minced.${weaponType}.trigger_${this.anim_prefix}`)
                switch(chargeTest) {
                    case 1: {
                        player.runCommand(`camerashake add @s 0.25 1 rotational`)
                        attackPlayerMeikyu(player, 5, damage, 30, 10, 11, 2, 10, "line_target", "", [2,0.25], "long", "", "blunt", "", 20, 10, true, "no cooldown",mainhand,1, true)    
                    } break;
                    case 2: {
                        player.runCommand(`camerashake add @s 0.5 1 positional`)
                        attackPlayerMeikyu(player, 5, (damage * 1.25), 30, 10, 11, 2, 10, "line_target", "", [3,0.25], "long", "", "blunt", "", 20, 10, true, "no cooldown",mainhand,1, true)
                    } break;
                    case 3: {
                        player.runCommand(`camerashake add @s 0.75 1 positional`)
                        attackPlayerMeikyu(player, 5, (damage * 1.75), 30, 10, 11, 2, 10, "line_target", "", [5,0.25], "long", "", "blunt", "", 20, 10, true, "no cooldown",mainhand,1, true)
                    } break;
                }
                cooldowns(player,this.name,15,15)
            } break;
            default: {
                launchPlayer(player, 5, 0.13)
                player.playAnimation(`animation.minced.${weaponType}.ability_ya_zi`)
                player.runCommand(`camerashake add @s 0.25 1 positional`)
                attackPlayerMeikyu(player, 5, damage, 20, 10, 20, 1, 5, "line_target", "", [0,0], "long", "", "slash", "", 20, 10, true, "no cooldown",mainhand,1)
                cooldowns(player,this.name,10,10)
            } break;
          }
    }, 
    resetStats(player) {
        player.setProperty("part:special_model", 0)
    }
}

export default ability