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([
        ["hand_cannon", 3.5],
        ["pistol", 5.5],
        ["grand_cross", 2.5],
    ])

const ability = {
    name: 'R1',
    display_name: "Rapid Fire",
    button_icon: "textures/items/diamond",
    registry_name: "rapid_fire",
    description: 'Shoots Multiple Projectiles',
    indexNum: 26,
    level: "advanced",
    cooldown: 100,
    damages: 15,
    charge_type: "continuous_with_delay",
    delay: 3,
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    filters: ["hand_cannon", "pistol", "grand_cross"],
    slots: ["charge"],
    coodname: "ctcd",
    horizontal: -0.0125,
    vertical: 0,
    execute(player, weaponType, mode, weapon) {
        const launch_power = this.horizontal
        const upwards = this.vertical
        let amm = JSON.parse(weapon.getDynamicProperty("ammo"))
        let bullet
        weaponType == "pistol" ? bullet = "minced:bullet" : weaponType == "hand_cannon" ? bullet = "pixel:hand_cannon_bullet" : bullet = "pixel:hand_cannon_bullet" 
        if(amm.length > 0) {
            spawnProjectile(player, `${bullet}`, 1, 1, 10, "normal", "", 3, 1, 30, 1, 1, 1, "line_target", [], [1, 2], "short", "", "blunt", 10, "normal", 1)
            player.playAnimation(`animation.minced.${weaponType}.trigger_rapid_fire`)
            launchPlayer(player, launch_power, upwards)
            
        } else {
            player.onScreenDisplay.setActionBar(`You Need More Bullets!!`)
        }
    }, 
    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