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

const weaponBoost = new Map([
        ["dagger", 1],
        ["spear", 2.65],
    ])

const ability = {
    name: 'A3',
    display_name: "Air Slash",
    button_icon: "textures/ui/abilities/slash",
    registry_name: "air_slash",
    description: 'Shoots out a shockwave in front of you to damage enemies',
    indexNum: 20,
    level: "advanced",
    cooldown: 10,
    damages: 15,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    ranges: 3,
    distance: 1,
    canSwitch : false,
    filters: ["greatsword", "dagger", "katana", "saber", "rapier"],
    slots: ["ability","charge"],
    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()
        let attackEffect = ["lashes"]
        switch(mode) {
            case ("charge"): {
                let charger = world.scoreboard.getObjective("chargecount").getScore(player)
                let chargeTest = Math.floor(charger / 10)
                console.warn(chargeTest)
                player.playAnimation(`animation.minced.${weaponType}.trigger_air_slash`)
                switch(chargeTest) {
                    case 1: {
                        player.runCommand(`camerashake add @s 0.25 1 positional`)
                        spawnProjectile(player, `minced:air_slash`, 0.75, 1, 1, "normal", "", 10, 1, 30, 1, 1, 1, "line_target", attackEffect, [1, 0], "short", "", "blunt", 10, "normal", 1)
                    } break;
                    case 2: {
                        player.runCommand(`camerashake add @s 0.5 1 positional`)
                        spawnProjectile(player, `minced:air_slash`, 0.75, 1, 2, "normal", "", 15, 1, 30, 1, 1, 1, "line_target", attackEffect, [2, 0], "short", "", "blunt", 10, "normal", 1)
                    } break;
                    case 3: {
                        player.runCommand(`camerashake add @s 0.75 1 positional`)
                        spawnProjectile(player, `minced:air_slash`, 0.75, 1, 3, "normal", "", 20, 1, 30, 1, 1, 1, "line_target", attackEffect, [3, 0], "short", "", "blunt", 10, "normal", 1)
                    } break;
                } 
              cooldowns(player,this.name,cooldown,cooldown)
            } break;
            default: {
               
                player.playAnimation(`animation.minced.${weaponType}.ability_air_slash`)
                system.runTimeout(()=>{
                    launchPlayer(player, launch_power, upwards)
                    spawnProjectile(player, `minced:air_slash`, 0.75, 1, 5, "normal", "", 10, 1, 30, 1, 1, 1, "line_target", attackEffect, [1, 0], "short", "", "blunt", 10, "normal", 1)
                    player.setProperty("aura:color", 0)
                },10)
                player.setProperty("aura:color", 8)
                system.runTimeout(()=>{
                             
                },40)
               
              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