import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { HeartAbilityManager } from "../systems/index";
export async function dispenserAbility(player) {
    utils.mclog(`dispenser`);
    const direction = player.getViewDirection();
    const rotation = player.getRotation();
    HeartAbilityManager.addInvulnerability(player, "noFallDamage");
    const dispenser = utils.spawnEntitySafe(player.dimension, "ldz:dispenser_ability", player.location, { rotation });
    const alpha = utils.normalize(0, 90, Math.max(0, -rotation.x));
    dispenser.playSoundAt("dig.stone");
    await utils.waitForEvent(10, () => {
        player.playSoundAt("ability.dispensor.launch");
        player.applyKnockback(direction.x, direction.z, utils.lerp(60, 0, alpha), utils.lerp(0, 5, alpha));
    });
    utils.waitForEvent(20, () => {
        dispenser.remove();
    });
    const minTime = mc.system.currentTick + 20;
    await utils.waitForLoopEvent(5, () => mc.system.currentTick > minTime && player.isOnGround);
    HeartAbilityManager.removeInvulnerability(player, "noFallDamage");
}
