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

/*let effects = new JsonDatabase("effectives")


export function getEffects(player){
    return effects.get(player.name)
}*/


const potionTypes = new Map([
        ["poison", "P1"],
        ["slowness", "P2"],
        ["wither", "P3"],
        ["weakness", "P4"],
        ["night_vision", "P5"],
    ])

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

const ability = {
    name: 'T3',
    display_name: "Tip",
    button_icon: "textures/items/diamond",
    registry_name: "tip",
    description: 'Tips your weapon with a potion',
    indexNum: 21,
    level: "advanced",
    cooldown: 100,
    damages: 15,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    coodname: "thrwcd",
    filters: ["spear", "dagger"],
    slots: ["ability"],
    horizontal: 0.25,
    vertical: 0,
    execute(player, weaponType, mode, weapon) {
        const cooldown = this.cooldown
        const damage = this.damages
        const range = this.ranges
        const dist = this.distance
        const cdname = this.coodname
        const launch_power = this.horizontal
        const upwards = this.vertical
        const targetNum = 1
        const multiplier = weaponBoost.get(weaponType)
        const atkspd = 1
        player.runCommand("scoreboard players remove @s exhaust 5")
        launchPlayer(player, launch_power, upwards)
        let potions = getPotionItem(player)
        let checker = item.getLore()
        let typing = checker[0].split("|")
        checker[0] = `${potionTypes.get(potion)}|${typing[1]}|$)${typing[2]}`
        player.playAnimation(`animation.minced.${weaponType}.ability_tip`)
        item.setLore(checker)
        player.getComponent('equippable')?.setEquipment(EquipmentSlot.Mainhand, item)
        let remover = system.runInterval(()=>{
            let checks = item.getLore()
            let typings = checker[0].split("|")
            checks[0] = `00|${typings[1]}|$)${typings[2]}`
            item.setLore(checks)
            player.getComponent('equippable')?.setEquipment(EquipmentSlot.Mainhand, item)
            system.clearRun(remover)
        },600)
        //effects.set(player.name,potions)
        cooldowns(player,this.name,cooldown,30)
    }, 
    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