import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { ignoreEntities } from "../shared/constants";
const effectDuration = 5 * 20;
export function glowstoneAbility(player) {
    utils.mclog(`glowstone`);
    player.runCommand('playanimation @s animation.generic.light_up');
    player.dimension.getPlayers({ location: player.location, maxDistance: 10 }).forEach(player => {
        player.onScreenDisplay.setActionBar('ignore,whiteout');
        player.playSound('ability.glowstone.flashbang');
    });
    const lightLocation = new utils.Vector3(player.getHeadLocation());
    player.runCommand(`fill ${lightLocation} ${lightLocation} minecraft:light_block_15 replace minecraft:air`);
    utils.waitForEvent(10, () => {
        player.runCommand(`fill ${lightLocation} ${lightLocation} minecraft:air replace minecraft:light_block_15`);
    });
    player.dimension.getEntities({ location: player.location, maxDistance: 10, excludeTypes: ignoreEntities, excludeNames: [player.nameTag], excludeTags: ['friendlyFireOff'] }).forEach(victim => {
        const endTime = mc.system.currentTick + effectDuration;
        const particleLocation = new utils.Vector3(victim.getHeadLocation());
        utils.runCommand(`particle ldz:ability_glowstone ${particleLocation}`);
        utils.waitForLoopEvent(0, () => {
            try {
                victim.clearVelocity();
                victim.addEffect('slowness', 5, { amplifier: 10, showParticles: false });
                victim.addEffect('blindness', 5, { amplifier: 10, showParticles: false });
            }
            catch (error) { }
            return mc.system.currentTick > endTime;
        });
    });
}
