import { system } from "@minecraft/server";
const normalHeal = 2;
const sleepHeal = 4;
const lowHealthParticleValue = 0.5;
const healInterval = 30;
function handleDeath(sourceEntity, entityCurHealth) {
    if (entityCurHealth <= 3) {
        const statName = sourceEntity.typeId.replace("kicu_mmad:", "kicu_mmad_") + "_died_stat";
        sourceEntity.runCommand(`execute as @s[type=${sourceEntity.typeId}] at @p run scoreboard players add "${statName}" "kicu_mmad:jig_computer.addon_stats" 1`);
        system.run(() => {
            sourceEntity.triggerEvent("kicu_mmad:set_death");
        });
    }
}
function getHealFactor(entity) {
    return entity.getProperty("kicu_mmad:sleep") ? sleepHeal : normalHeal;
}
export function healMount(sourceEntity) {
    try {
        if (!sourceEntity) {
            return;
        }
        const healthComponent = sourceEntity.getComponent("health");
        if (!healthComponent) {
            return;
        }
        let entityCurHealth = healthComponent.currentValue;
        handleDeath(sourceEntity, entityCurHealth);
        let healCounter = sourceEntity.getDynamicProperty("kicu_mmad:heal_counter") || 0;
        healCounter++;
        if (healCounter >= healInterval) {
            sourceEntity.setDynamicProperty("kicu_mmad:heal_counter", 0);
            let entityNewHealth = healthComponent.currentValue + getHealFactor(sourceEntity);
            const entityMaxHealth = healthComponent.effectiveMax;
            entityNewHealth = Math.min(entityNewHealth, entityMaxHealth);
            const isHealthLow = entityNewHealth <= entityMaxHealth * lowHealthParticleValue;
            if (isHealthLow || sourceEntity.getProperty("kicu_mmad:sleep")) {
                sourceEntity.dimension.spawnParticle("kicu_mmad:healing_particle", sourceEntity.location);
            }
            system.run(() => {
                healthComponent.setCurrentValue(entityNewHealth);
            });
        }
        else {
            sourceEntity.setDynamicProperty("kicu_mmad:heal_counter", healCounter);
        }
    }
    catch {
        return;
    }
}

//# sourceMappingURL=../../../../../_KiCuMountsBPDebug/kicu/mmad/C/Healing.js.map
