import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { HeartAbilityManager } from "../systems/index";
const fireballCount = 5;
export async function nether_fortressAbility(player) {
    utils.mclog(`nether_fortress`);
    HeartAbilityManager.addInvulnerability(player, 'noExplosionDamage');
    HeartAbilityManager.addInvulnerabilityToFriends('noExplosionDamage');
    player.addEffect('fire_resistance', 80, { showParticles: false });
    player.runCommand(`effect @a[tag=friendlyFireOff,r=20] fire_resistance 80 0 true`);
    mc.world.playSound('mob.ghast.scream', player.location);
    let fireballRemaining = fireballCount;
    await utils.waitForLoopEvent(5, () => {
        const location = { x: player.location.x + utils.getRandomInteger(-5, 5), y: player.location.y + 10, z: player.location.z + utils.getRandomInteger(-5, 5) };
        const fireball = player.dimension.spawnEntity('ldz:fortress_ability_projectile', location);
        if (player.hasTag('InSpawnHouse')) {
            fireball.triggerEvent('InSpawnHouse');
        }
        mc.world.playSound('mob.blaze.shoot', location);
        fireball.applyImpulse({ x: 0, y: -0.5, z: 0 });
        fireballRemaining--;
        return fireballRemaining < 0;
    });
    utils.waitForEvent(80, () => {
        utils.mclog('Finished');
        HeartAbilityManager.removeInvulnerability(player, 'noExplosionDamage');
        HeartAbilityManager.removeInvulnerabilityFromFriends('noExplosionDamage');
        player.removeEffect('fire_resistance');
        player.runCommand(`effect @a[tag=friendlyFireOff,r=20] fire_resistance 0 0 true`);
    });
}
