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

const weaponBoost = new Map([
        ["katar", 3],
        ["lance", 5],
    ])

const ability = {
    name: 'P1',
    display_name: "Pierce",
    button_icon: "textures/items/diamond",
    registry_name: "pierce",
    description: 'Swings in front of.you to damage enemies',
    indexNum: 10,
    level: "basic",
    cooldown: 100,
    damages: 15,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    filters: ["katar", "lance"],
    slots: ["ability"],
    coodname: "prccd",
    horizontal: 0.5,
    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"): {
              if(checker){
                  launchPlayer(player, launch_power, upwards)
                  player.playAnimation(`animation.minced.${weaponType}.ultimate_slash_air`)
                  //player.runCommand(`camerashake add @s 0.25 1 positional`)
                  let cameras = [
                      {
                          times: 0.1,
                          timeStamp: "default",
                          posX: 0.0,
                          posY: 1.0,
                          posZ: -0.25,
                          cameraType: "minecraft:free",
                          easing: 0.1,
                          transitionType: "out_bounce",
                      },
                      {
                          times: 0.3,
                          timeStamp: "attack_start",
                          posX: 0.0,
                          posY: 1.0,
                          posZ: -1.0,
                          cameraType: "minecraft:free",
                          easing: 0.1,
                          transitionType: "out_bounce",
                      },
                      {
                          times: 0.5,
                          timeStamp: "default",
                          posX: 0.0,
                          posY: 1.5,
                          posZ: -1.5,
                          cameraType: "minecraft:free",
                          easing: 0.1,
                          transitionType: "out_bounce",
                      },
                      {
                          times: 0.7,
                          timeStamp: "default",
                          posX: 0.0,
                          posY: 2.0,
                          posZ: -2.25,
                          cameraType: "minecraft:free",
                          easing: 0.1,
                          transitionType: "out_bounce",
                      },
                      {
                          times: 0.9,
                          timeStamp: "default",
                          posX: 0.0,
                          posY: 2.0,
                          posZ: -3.25,
                          cameraType: "minecraft:free",
                          easing: 0.1,
                          transitionType: "out_bounce",
                      },
                      {
                          times: 1.0,
                          timeStamp: "restore_movement",
                          posX: 0.0,
                          posY: 3.0,
                          posZ: -4.0,
                          cameraType: "minecraft:free",
                          easing: 0.1,
                          transitionType: "out_bounce",
                      }
                  ]
                  ultimatum(player, "S1", weaponType, 10, cameras, 5, (10 * 1.5), 20, 10, 20, 1, 5, "line_target", "", [0,0], "long", "", "slash", "", 20, 10, true, "normal",weapon, 1)
              } else{
                  player.playAnimation(`animation.minced.${weaponType}.ultimate_slash`)
              }
              cooldowns(player,this.name,cooldown,cooldown)
            } break;
            case ("charge"): {
              if(checker){
                  launchPlayer(player, launch_power, upwards)
                  player.playAnimation(`animation.minced.${weaponType}.ability_pierce`)
                  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, "normal",mainhand, 1, true)
              } else{
                  player.playAnimation(`animation.minced.${weaponType}.ability_slash`)
              }
              cooldowns(player,this.name,cooldown,cooldown)
            } break;
            default: {
              if(checker){
                  launchPlayer(player, launch_power, upwards)
                  player.playAnimation(`animation.minced.${weaponType}.ability_pierce`)
                  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_slash`)
              }
              cooldowns(player,this.name,cooldown,cooldown)
            } break;
          }

        cooldowns(player,this.name,cooldown,cooldown)
    }, 
    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