import { system } from "@minecraft/server";
import { coordExtractor } from "./../../util/utils.js";


const ability = {
    name: 'searing',
    display_name: "Searing",
    effect_icon: "textures/items/diamond",
    description: 'Reduce Enemy max health for a short period while also burning them',
    indexNum: 2,
    execute(player, target, mode, dmg) {
        if(target.typeId == "minecraft:player") {
            target.camera.fade({
                fadeColor: {
                    red: 0.5411764706,
                    blue: 0.07450980392,
                    green: 0.2705882353,
                } ,
                fadeTime: {
                    fadeInTime: 0,
                    fadeOutTime: 0.2,
                    holdTime: 0.5
                }
            })
        } 
        target.setOnFire(20,true)
        system.runTimeout(()=>{
            let oldRedux = JSON.parse(target.getDynamicProperty("resetingStatus"))
            if(oldRedux.effects.HR == undefined) {
                oldRedux.effects["HR"] = {
                    dur: 30,
                    redux: (dmg * 0.15)
                }
                let Loa = coordExtractor(target,1)
                target.dimension.spawnParticle(`combat:bleed_activate`,Loa);
            } else {
                oldRedux.effects["HR"] = {
                    dur: 30,
                    redux: oldRedux.effects.HR.redux + (dmg * 0.15)
                }
            }
            let newRedux = oldRedux
            target.setDynamicProperty("resetingStatus",JSON.stringify(newRedux))
        },3) 
    },
    resetStats(player) {
        let statuser = JSON.parse(player.getDynamicProperty("resetingStatus"))
        statuser["Boost"] = statuser.Boost - 0.5
        player.setDynamicProperty("resetingStatus", JSON.stringify(statuser))
        player.setProperty("aura:color", 0)
    }
}

export default ability