import { system, TicksPerSecond } from "@minecraft/server";
import { shadowPhoenixArmorConfig } from "../DATA/ArmorConfig";
export function applyWitherEffectToProjectileOwner(attacker) {
    applyShadowEffect(attacker);
}
export function applyWitherEffectToAttacker(log, damagingEntity) {
    try {
        const damagingEntityId = damagingEntity.typeId;
        if (damagingEntityId.startsWith("kicu_mmad:") && damagingEntityId.endsWith("_wild")) {
            applyShadowEffect(damagingEntity);
        }
        else {
            const monsters = damagingEntity.dimension.getEntities({
                families: ["monster"],
                maxDistance: shadowPhoenixArmorConfig.effectRange,
                location: damagingEntity.location,
            });
            if (monsters.length > 0) {
                applyShadowEffect(damagingEntity);
            }
        }
    }
    catch { }
}
function getRandomMinMax(min, max) {
    return Math.random() * (max - min) + min;
}
function applyShadowEffect(hitEntity) {
    try {
        if (hitEntity) {
            hitEntity.addEffect("wither", shadowPhoenixArmorConfig.effectDuration * TicksPerSecond, {
                amplifier: shadowPhoenixArmorConfig.effectAmplifier,
            });
        }
        const { location: hitEntityLocation, dimension, isOnGround } = hitEntity;
        system.run(() => {
            const { x, y, z } = hitEntityLocation;
            if (isOnGround) {
                const shadowPhoenixGlyph = shadowPhoenixArmorConfig.particleEffects.shadowPhoenixGlyph;
                dimension.runCommand(`particle ${shadowPhoenixGlyph} ${x} ${y + 0.03} ${z}`);
                system.runTimeout(() => {
                    dimension.runCommand(`particle ${shadowPhoenixGlyph} ${x} ${y + 0.03} ${z}`);
                }, 3);
                dimension.runCommand(`particle ${shadowPhoenixArmorConfig.particleEffects.shadowPhoenixGlyph2} ${x} ${y + 0.01} ${z}`);
            }
            dimension.runCommand(`particle ${shadowPhoenixArmorConfig.particleEffects.shadowPhoenixParticles} ${x} ${y + 0.02} ${z}`);
            const players = dimension.getPlayers({ maxDistance: 16 });
            if (players.length > 0) {
                players.forEach((player) => {
                    player.playSound(shadowPhoenixArmorConfig.soundEffect.sound, {
                        volume: shadowPhoenixArmorConfig.soundEffect.volume,
                        pitch: getRandomMinMax(shadowPhoenixArmorConfig.soundEffect.pitchRange.min, shadowPhoenixArmorConfig.soundEffect.pitchRange.max),
                    });
                });
            }
        });
        const intervalId = system.runInterval(() => {
            hitEntity.dimension.spawnParticle("kicu_mmad:shadow_phoenix_effect_new", hitEntity.location);
        }, 10);
        system.runTimeout(() => {
            system.clearRun(intervalId);
        }, shadowPhoenixArmorConfig.effectDuration);
    }
    catch {
        return;
    }
}

//# sourceMappingURL=../../../../../_KiCuMountsBPDebug/kicu/mmad/A/ShadowPhoenixArmor.js.map
