import * as mc from "@minecraft/server";
import { MeleeAttack, mclog } from "../utils/index";
export function initWanderingTraderWeapon() {
    new MeleeAttack({
        attackID: "ldz:wandering_trader_weapon",
        damage: 3,
        range: 3,
        subscribeToScriptEvent: true,
        hitCallbacks: [
            (player, hitEntity) => {
                mclog(`${player.nameTag} used wandering_trader_weapon`);
                tazeEntity(hitEntity);
            }
        ],
    });
}
function tazeEntity(entity) {
    if (entity.matches({ type: "minecraft:player" })) {
        entity.runCommand("inputpermission set @s movement disabled");
    }
    const tazeDuration = Math.floor((2 + Math.random() * 3) * mc.TicksPerSecond);
    mclog(`Tazing ${entity.typeId} for ${tazeDuration} ticks`);
    const tazeTimeoutHandle = mc.system.runTimeout(endTaze, tazeDuration);
    const tazeLoopHandle = mc.system.runInterval(() => {
        if (!entity.isValid()) {
            endTaze();
            return;
        }
        entity.dimension.spawnParticle("ldz:shocked", entity.location);
        if (entity.matches({ type: "minecraft:player" })) {
            entity.runCommand("camerashake add @s 0.1 1");
        }
        else {
            entity.addEffect("slowness", 2, { showParticles: false, amplifier: 10 });
        }
    }, 2);
    function endTaze() {
        mc.system.clearRun(tazeTimeoutHandle);
        mc.system.clearRun(tazeLoopHandle);
        if (entity.isValid() && entity.matches({ type: "minecraft:player" })) {
            entity.runCommand("camerashake stop @s");
            entity.runCommand("inputpermission set @s movement enabled");
        }
    }
}
