import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { ignoreEntities } from "../shared/constants";
const potionCount = 15;
class EffectData {
    constructor() {
        this.name = '';
        this.duration = 500;
        this.amplifier = 0;
    }
}
const effectPool = [
    { name: 'speed', duration: 500, amplifier: 1 },
    { name: 'haste', duration: 500, amplifier: 0 },
    { name: 'strength', duration: 500, amplifier: 0 },
    { name: 'jump_boost', duration: 500, amplifier: 0 },
    { name: 'fire_resistance', duration: 500, amplifier: 0 },
    { name: 'water_breathing', duration: 500, amplifier: 0 },
    { name: 'invisibility', duration: 500, amplifier: 0 },
    { name: 'night_vision', duration: 500, amplifier: 0 },
];
export async function swamp_hutAbility(player) {
    utils.mclog(`swamp_hut`);
    mc.world.playSound('mob.witch.celebrate', player.location);
    let potionRemaining = potionCount;
    utils.waitForLoopEvent(1, () => {
        player.dimension.spawnEntity('minecraft:splash_potion', { x: player.location.x + utils.getRandomInteger(-5, 5), y: player.location.y + 5, z: player.location.z + utils.getRandomInteger(-5, 5) });
        potionRemaining--;
        return potionRemaining < 0;
    });
    effectPool.sort(() => Math.random() - 0.5).slice(0, 3).forEach(effect => {
        player.addEffect(effect.name, effect.duration, { amplifier: effect.amplifier, showParticles: false });
    });
    player.dimension.getEntities({ location: player.location, maxDistance: 5, type: 'minecraft:frog' }).forEach(victim => {
        utils.runCommand(`summon tadpole ~ ~ ~ ~ ~`, victim);
        utils.runCommand(`particle ldz:swamp_hut_ability_transform ~ ~ ~`, victim);
        mc.world.playSound('random.fizz', victim.location);
        utils.waitForEvent(1, () => {
            if (victim.isValid()) {
                victim.teleport({ x: victim.location.x, y: -100, z: victim.location.z });
            }
        });
    });
    player.dimension.getEntities({ location: player.location, maxDistance: 5, excludeTypes: [...ignoreEntities, 'minecraft:frog', 'minecraft:tadpole'], excludeNames: [player.nameTag], excludeTags: ['friendlyFireOff'] }).forEach(victim => {
        utils.runCommand(`summon frog ~ ~ ~ ~ ~ spawn_cold`, victim);
        utils.runCommand(`particle ldz:swamp_hut_ability_transform ~ ~ ~`, victim);
        mc.world.playSound('random.fizz', victim.location);
        utils.waitForEvent(1, () => {
            if (victim.isValid()) {
                victim.teleport({ x: victim.location.x, y: -100, z: victim.location.z });
            }
        });
    });
}
