import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { HeartAbilityManager } from "../systems/index";
const lightningCount = 3;
export async function creeperAbility(player) {
    utils.mclog(`Creeper`);
    HeartAbilityManager.addInvulnerability(player, 'noDamage');
    let loopCount = lightningCount;
    await utils.waitForLoopEvent(10, () => {
        const spawnLocation = new utils.Vector3(player.location).add(new utils.Vector3({ x: utils.getRandomInteger(-10, 10), y: 0, z: utils.getRandomInteger(-10, 10) }));
        utils.waitForEvent(5, () => {
            const creeper = player.dimension.spawnEntity('ldz:creeper_ability_dummy', spawnLocation);
            if (player.hasTag('InSpawnHouse')) {
                creeper.triggerEvent('InSpawnHouse');
                mc.world.playSound('ambient.weather.thunder', spawnLocation);
                mc.world.playSound('ambient.weather.lightning.impact', spawnLocation);
            }
            else {
                player.dimension.spawnEntity('minecraft:lightning_bolt', spawnLocation);
            }
            mc.world.playSound('random.fuse', spawnLocation, { pitch: 0.5 });
        });
        loopCount--;
        return loopCount <= 0;
    });
    utils.waitForEvent(45, () => {
        HeartAbilityManager.removeInvulnerability(player, 'noDamage');
    });
}
