import { world, system } from "@minecraft/server";
import { getWardLocations } from "./Warding";
import { eggScoreDict, wildDragonDict } from "../DATA/Config";
const nestSpawnRate = 2;
const nestSpawnRarity = 9;
export function instantNestDespawn(entity, location, typeId, isFromItem, log) {
    if (!isFromItem &&
        (entity.dimension.getEntities({ location: location, maxDistance: 100, families: ["kicu_mmad_nest"] }).length > 1 ||
            entity.dimension.getEntities({ location: location, maxDistance: 45, type: "player" }).length > 1 ||
            Math.floor(Math.random() * nestSpawnRarity) !== 1)) {
        entity.triggerEvent("kicu_mmad:remove");
    }
    else {
        let isRemoved = false;
        if (!isFromItem) {
            getWardLocations().forEach((wardLocation) => {
                const distanceX = location.x - wardLocation.x;
                const distanceY = location.y - wardLocation.y;
                const distanceZ = location.z - wardLocation.z;
                if (Math.sqrt(distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ) < 400) {
                    entity.triggerEvent("kicu_mmad:remove");
                    isRemoved = true;
                }
            });
        }
        if (!isRemoved) {
            const objective = world.scoreboard.getObjective("kicu_mmad_NestHasEgg");
            if (Math.floor(Math.random() * nestSpawnRate) === 0 || isFromItem) {
                entity.dimension.spawnEntity(wildDragonDict[typeId], location);
                entity.triggerEvent("kicu_mmad:set_egg_true");
                objective.setScore(entity, eggScoreDict[typeId]);
                if (Math.floor(Math.random() * 5) === 0) {
                    entity.dimension.spawnEntity(wildDragonDict[typeId], location);
                }
            }
            else {
                objective.setScore(entity, 0);
            }
            entity.setProperty("kicu_mmad:render", true);
            system.runTimeout(() => {
                const randomNumber = Math.floor(Math.random() * 4) + 1;
                entity.playAnimation(`animation.kicu_mmad_nest.place${randomNumber}`);
            }, 1);
        }
    }
}

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