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


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

const ability = {
    name: 'S5',
    display_name: "Strong Punch",
    button_icon: "textures/items/diamond",
    registry_name: "strong_punch",
    description: 'Strong punches your opponent and deals heavy damage with stagger',
    indexNum: 17,
    level: "basic",
    cooldown: 50,
    damages: 15,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    anim_prefix: "strong_punch",
    filters: ["gauntlet", "katar"],
    slots: ["ability","charge","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: 40,
                        timeStamp: "add_impact_frame",
                        posX: -0.05,
                        posY: 1.0,
                        posZ: -0.61,
                        spawn: "pixel:aura"
                    },
                    {
                        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_strong_punch`)
                //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", "", [8,0], "long", "", "blunt", "", 20, 10, true, "normal",mainhand, 1)
              cooldowns(player,this.name,cooldown,5)
            } break;
            case ("charge"): {
                launchPlayer(player, launch_power, upwards)
                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, (5 * 1.5), 30, 10, 9, 1, 1, "line_target", "", [3,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, (5 * 1.5), 30, 10, 9, 1, 1, "line_target", "", [5,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, (5 * 1.5), 30, 10, 9, 1, 1, "line_target", "", [8,0.25], "long", "", "blunt", "", 20, 10, true, "no cooldown",mainhand,1, true)
                    } break;
                }
              cooldowns(player,this.name,cooldown,5)
            } break;
            default: {
              if(checker){
                  launchPlayer(player, launch_power, upwards)
                  player.playAnimation(`animation.minced.${weaponType}.ability_strong_punch`)
                  player.runCommand(`camerashake add @s 0.25 1 positional`)
                  attackPlayerMeikyu(player, 5, (10 * 1.5), 20, 10, 20, 1, 5, "line_target", "", [0,0], "long", "", "slash", "", 20, 10, true, "no cooldown",mainhand,1, true)
              } else{
                  player.playAnimation(`animation.minced.${weaponType}.ability_strong_punch`)
              }
              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