import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { HeartAbilityManager } from "../systems/index";
const distance = 5;
export async function woodland_mansionAbility(player) {
    utils.mclog(`woodland_mansion`);
    mc.world.playSound('mob.evocation_illager.prepare_summon', player.location);
    await utils.waitForEvent(5, () => { });
    HeartAbilityManager.addInvulnerabilityToFriends('noDamage');
    launchFangs(new utils.Vector3({ x: 1, y: 0, z: 0 }), player);
    launchFangs(new utils.Vector3({ x: -1, y: 0, z: 0 }), player);
    launchFangs(new utils.Vector3({ x: 0, y: 0, z: 1 }), player);
    launchFangs(new utils.Vector3({ x: 0, y: 0, z: -1 }), player);
    launchFangs(new utils.Vector3({ x: -1, y: 0, z: -1 }), player);
    launchFangs(new utils.Vector3({ x: 1, y: 0, z: 1 }), player);
    launchFangs(new utils.Vector3({ x: 1, y: 0, z: -1 }), player);
    launchFangs(new utils.Vector3({ x: -1, y: 0, z: 1 }), player);
    await utils.waitForEvent(15, () => {
        HeartAbilityManager.removeInvulnerabilityFromFriends('noDamage');
    });
}
async function launchFangs(direction, player) {
    for (let index = 2; index <= distance; index++) {
        const origin = new utils.Vector3(player.location).add({ x: direction.x * index, y: 3, z: direction.z * index });
        const block = player.dimension.getBlockFromRay(origin, { x: 0, y: -1, z: 0 }, { includeLiquidBlocks: true, includePassableBlocks: false, maxDistance: 10 });
        let target = origin;
        if (block) {
            target = new utils.Vector3(block.block.location).add(new utils.Vector3(block.faceLocation));
        }
        else {
            target.y = player.location.y;
        }
        utils.runCommand(`summon evocation_fang ${target.toCommandString()}`, player);
        await utils.waitForEvent(2, () => { });
    }
}
