import { waitForLoopEvent } from "../../utils/index";
import { Task } from "../../npc/tasks/task";
import { IdleTask } from "../../npc/tasks/idle";
export class DefaultTask extends Task {
    constructor() {
        super(...arguments);
        this.idleOptions = {
            emoteTime: { min: 60, max: 90 },
            emoteList: [
                { emoteAnimation: 'hit_the_whoa', emoteSeconds: 4, emoteEvent: 'hit_the_whoa' },
                { emoteAnimation: 'napoleon_dynamite', emoteSeconds: 9, emoteEvent: 'napoleon_dynamite' },
                { emoteAnimation: 'rasputin', emoteSeconds: 7, emoteEvent: 'rasputin' },
                { emoteAnimation: 'shuffle_dance', emoteSeconds: 8, emoteEvent: 'shuffle_dance' },
                { emoteAnimation: 'spongebob', emoteSeconds: 6, emoteEvent: 'spongebob' },
            ]
        };
    }
    async performTask() {
        while (this.npc.Entity.isValid()) {
            this.npc.Entity.triggerEvent("start_goal_idle");
            const idleTask = new IdleTask(this.npc, this.idleOptions, this);
            waitForLoopEvent(5, () => {
                if (this.npc.Entity.getProperty("has_target")) {
                    this.shouldAbort();
                    idleTask.abort();
                    this.npc.Entity.triggerEvent("start_guard_owner");
                    return true;
                }
                return false;
            }, this.id);
            await idleTask.start();
            this.shouldAbort();
            if (this.npc.Entity.getProperty("has_target")) {
                await waitForLoopEvent(10, () => !this.npc.Entity.getProperty("has_target"));
                this.shouldAbort();
            }
            this.npc.Entity.triggerEvent("end_guard_owner");
            this.npc.Entity.triggerEvent("start_goal_idle");
        }
        this.npc.Entity.triggerEvent("end_goal_idle");
        return { outcome: "succeeded" };
    }
    async cleanupTask() {
        if (this.npc.Entity.isValid()) {
            this.npc.Entity.triggerEvent("end_goal_idle");
            this.npc.Entity.triggerEvent("end_guard_owner");
        }
    }
}
