import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { ignoreEntities } from "../shared/constants";
const duration = 3 * 20;
export async function strongholdAbility(player) {
    utils.mclog(`stronghold`);
    player.triggerEvent('add_stronghold_ability_eye_projectile');
    mc.world.playSound('mob.evocation_illager.cast_spell', player.location);
    utils.waitForEvent(2, () => {
        const endTime = mc.system.currentTick + duration;
        const eyes = player.dimension.getEntities({ type: 'ldz:stronghold_ability_eye_projectile', excludeTags: ['proccessing'] });
        eyes.forEach(eye => eye.addTag('proccessing'));
        utils.waitForLoopEvent(0, () => {
            eyes.forEach(eye => {
                if (eye.isValid()) {
                    eye.dimension.getEntities({ location: eye.location, maxDistance: 10, excludeTypes: ignoreEntities, excludeNames: [player.nameTag], excludeTags: ['friendlyFireOff'] }).forEach(victim => {
                        const origin = new utils.Vector3(victim.location);
                        const destination = new utils.Vector3(eye.location);
                        const direction = destination.subtract(origin).normalize();
                        victim.applyKnockback(direction.x, direction.z, 0.75, direction.y * 2);
                    });
                }
            });
            return mc.system.currentTick > endTime;
        });
    });
}
