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

const weaponBoost = new Map([
        ["spear", 3.5],
        ["scythe", 5.5],
        ["scissors", 2.5],
    ])

const ability = {
    name: 'C2',
    display_name: "Charged shot",
    button_icon: "textures/items/diamond",
    registry_name: "charge_shot",
    description: 'Charges a flare',
    indexNum: 28,
    level: "advanced",
    cooldown: 10,
    damages: 15,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    filters: ["hand_cannon"],
    slots: ["ability"],
    coodname: "ctcd",
    horizontal: 0.5,
    vertical: 0,
    execute(player, weaponType, mode, weapon) {
        const cooldown = this.cooldown
        const launch_power = this.horizontal
        const upwards = this.vertical
        const multiplier = weaponBoost.get(weaponType)
        spawnProjectile(player, `pixel:hand_cannon_bullet<minecraft:stone>`, 1, 0, 20, "normal", "",10, 1, 30, 1, 1, 1, "line_target", ["lashes"], [1, 2], "short", "", "blunt", 10, "normal", 1)
        player.playAnimation(`animation.minced.${weaponType}.ability_charge_shot`)
        player.runCommand("scoreboard players remove @s exhaust 30")
        let launcher = system.runInterval(() => {
            launchPlayer(player, launch_power, upwards)
            system.clearRun(launcher)
        },4)
        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