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

const weaponBoost = new Map([
        ["glaive", 1],
        ["rapier", 3],
    ])

const ability = {
    name: 'D2',
    display_name: "Deploy",
    button_icon: "textures/items/diamond",
    registry_name: "deploy",
    description: 'Deploy you grand cross',
    indexNum: 31,
    level: "intermediate",
    cooldown: 15,
    damages: 10,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    filters: ["grand_cross"],
    slots: ["ability"],
    horizontal: 0 ,
    vertical: 0,
    execute(player, weaponType, mode, weapon) {
        const cooldown = this.cooldown
        let equipment = player.getComponent("minecraft:equippable");
        let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
        let loc = player.location
        let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), 2));
        let nCorss = player.dimension.spawnEntity(`minced:iron_grand_cross_entity`, lof);
        let container = nCorss.getComponent('inventory').container
       
        try{
            let items = JSON.parse(mainhand.getDynamicProperty("storedItems"))
            for (let i = 0; i < items.length; i++) {
                container.addItem(items[i])
           }
        } catch(err){}
        
        system.runTimeout(()=>{
            equipment?.setEquipment('Mainhand', undefined)
        },5)
        
        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