import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { HeartAbilityManager } from "../systems/index";
const skullCount = 10;
export async function witherAbility(player) {
    utils.mclog(`wither`);
    HeartAbilityManager.addInvulnerability(player, 'noDamage');
    HeartAbilityManager.addInvulnerabilityToFriends('noDamage');
    mc.world.playSound('mob.wither.shoot', player.location);
    for (let index = 0; index < skullCount; index++) {
        const origin = new utils.Vector3(player.getHeadLocation()).add(new utils.Vector3(player.getViewDirection()).multiply(1.5));
        const skull = player.dimension.spawnEntity('minecraft:wither_skull', origin);
        if (player.hasTag('InSpawnHouse')) {
            skull.triggerEvent('InSpawnHouse');
        }
        const direction = new utils.Vector3(player.getViewDirection()).rotateByAngle(utils.getRandomInteger(-15, 15)).normalize().multiply(2);
        skull.applyImpulse(direction);
        player.removeEffect('wither');
        await utils.waitForEvent(2, () => { });
    }
    utils.waitForEvent(10, () => {
        player.removeEffect('wither');
        utils.runCommand(`effect @a[tag=friendlyFireOff] wither 0 0`);
        HeartAbilityManager.removeInvulnerability(player, 'noDamage');
        HeartAbilityManager.removeInvulnerabilityFromFriends('noDamage');
    });
}
