import { getRandomArrayEntry, getRandomInteger, mclog, waitForTicks } from "../../utils/index";
import { Task } from "./task";
import { EmoteTask } from "./emote";
export class IdleTask extends Task {
    async performTask() {
        await this.emoteTimer();
        return { outcome: "succeeded" };
    }
    async cleanupTask() {
        if (this.npc.Entity.isValid()) {
            this.npc.Entity.removeEffect("slowness");
        }
    }
    async emoteTimer() {
        this.shouldAbort();
        while (this.npc.Entity.isValid()) {
            this.shouldAbort();
            const emote = getRandomArrayEntry(this.options.emoteList);
            const emoteTime = getRandomInteger(this.options.emoteTime.min, this.options.emoteTime.max) * 20;
            mclog(`${this.id} Scheduled Emote (${emote.emoteAnimation}) ${emoteTime / 20} Seconds From Now`, "npc");
            await waitForTicks(emoteTime, this.id);
            this.shouldAbort();
            this.npc.broadcastEvent("emote");
            await new EmoteTask(this.npc, emote, this).start();
        }
    }
}
