import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
const monsterCount = 5;
const down = { x: 0, y: -1, z: 0 };
const aboveBlock = { x: 0, y: 0.6, z: 0 };
export async function dungeonAbility(player) {
    utils.mclog(`dungeon`);
    let monsterRemaining = monsterCount;
    await utils.waitForLoopEvent(5, () => {
        const origin = new utils.Vector3({ x: player.location.x + utils.getRandomInteger(-5, 5), y: player.location.y + 5, z: player.location.z + utils.getRandomInteger(-5, 5) });
        const block = player.dimension.getBlockFromRay(origin, down, { includeLiquidBlocks: false, includePassableBlocks: false, maxDistance: 10 });
        let target = origin;
        if (block) {
            target = new utils.Vector3(block.block.location).add(new utils.Vector3(block.faceLocation).add(new utils.Vector3(aboveBlock)));
        }
        utils.runCommand(`event entity @s add_dungeon_ability_spawner`, player);
        utils.waitForEvent(5, () => {
            mc.world.playSound('random.fizz', target);
            utils.runCommand(`tp @e[family=dungeon_ability_spawner,c=1,tag=!dontTP] ${target.toCommandString()}`);
            utils.runCommand(`particle ldz:mob_block_spawn_emitter ${target.toCommandString()}`);
            utils.runCommand(`tag @e[family=dungeon_ability_spawner] add dontTP`, player);
        });
        monsterRemaining--;
        return monsterRemaining <= 0;
    });
}
