import { world, system } from "@minecraft/server";
import { babyMountToParticleMap, eggToBabyMapping, spectralRarityMapping } from "../DATA/Config";
export function spawnBabyMountFromEggWithDelay(entity) {
    const eggType = entity.typeId;
    const baseBabyId = eggToBabyMapping[eggType] || "kicu_mmad:plains_dragon_baby";
    if (!baseBabyId)
        return;
    const spectralChance = spectralRarityMapping[baseBabyId] || 10;
    const isSpectral = Math.random() * 100 < spectralChance;
    const babyEntityId = isSpectral ? `kicu_mmad:spectral_${baseBabyId.split(":")[1]}` : baseBabyId;
    const delay = Math.floor(Math.random() * 2) + 1 * 20;
    system.runTimeout(() => {
        const babyEntity = entity.dimension.spawnEntity(babyEntityId, entity.location);
        if (babyEntity) {
            babyEntity.triggerEvent("kicu_mmad:baby_spawned");
        }
        entity.dimension.spawnParticle(babyMountToParticleMap[babyEntityId] ?? "kicu_mmad:griffin_egg_break", entity.location);
    }, delay);
}
export function eggTimer(log) {
    let dimensions = [];
    world.getAllPlayers().forEach((player) => {
        const dimension = player.dimension;
        if (!dimensions.includes(dimension)) {
            dimensions.push(dimension);
        }
    });
    const objective = world.scoreboard.getObjective("kicu_mmad_EggTimer");
    dimensions.forEach((dimension) => {
        const eggs = dimension.getEntities({ families: ["kicu_mmad_mount_egg"] });
        eggs.forEach((egg) => {
            const eggIdentity = egg.scoreboardIdentity;
            if (!eggIdentity || !objective.getParticipants().includes(eggIdentity)) {
                objective.setScore(egg, 120);
            }
            else {
                const eggTimer = objective.getScore(eggIdentity);
                if (eggTimer && eggTimer <= 4) {
                    egg.runCommandAsync("event entity @s kicu_mmad:set_hatching_true");
                }
            }
        });
    });
    objective.getParticipants().forEach((participant) => {
        objective.addScore(participant, -1);
    });
}
export function eggClick(log, entity) {
    const objective = world.scoreboard.getObjective("kicu_mmad_EggTimer");
    const eggIdentity = entity.scoreboardIdentity;
    const player = entity.dimension.getPlayers({ location: entity.location, closest: 1 })[0];
    if (eggIdentity && objective.getParticipants().includes(eggIdentity)) {
        const eggTimerMinutes = objective.getScore(eggIdentity) ?? 120;
        if (eggTimerMinutes > 6) {
            const timerMinutes = Math.floor((eggTimerMinutes + 2) / 4);
            player.onScreenDisplay.setActionBar({
                rawtext: [
                    { text: timerMinutes.toLocaleString() },
                    { translate: "dialog.kicu_mmad.timer.remaining", with: ["\n"] },
                ],
            });
        }
        else {
            player.onScreenDisplay.setActionBar({
                rawtext: [{ translate: "dialog.kicu_mmad.timer.remaining1", with: ["\n"] }],
            });
        }
    }
}

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