import { getRandomArrayEntry, waitForEvent, waitForTicks } from "../../utils/index";
import { Task } from "../../npc/tasks/task";
import { EmoteTask } from "../../npc/index";
export class CostumeChangeTask extends Task {
    constructor() {
        super(...arguments);
        this.emotes = [
            { emoteAnimation: 'costume_change.0', emoteSeconds: 3.5, emoteEvent: 'equip_costume' },
            { emoteAnimation: 'costume_change.1', emoteSeconds: 2.5, emoteEvent: 'equip_costume' },
            { emoteAnimation: 'costume_change.2', emoteSeconds: 2, emoteEvent: 'equip_costume' },
            { emoteAnimation: 'costume_change.3', emoteSeconds: 4.5, emoteEvent: 'equip_costume' },
            { emoteAnimation: 'costume_change.4', emoteSeconds: 3, emoteEvent: 'equip_costume' },
        ];
    }
    async performTask() {
        if (this.npc.Entity.getProperty("costume") === this.options.costumeId) {
            return { outcome: "failed" };
        }
        this.npc.Entity.triggerEvent("start_goal_idle");
        const emote = getRandomArrayEntry(this.emotes);
        await waitForTicks(2);
        waitForEvent((emote.emoteSeconds / 2) * 20, () => {
            this.npc.Entity.setProperty("costume", this.options.costumeId);
            this.npc.Entity.dimension.playSound("ldz_crcomp:craftee.costume_swoosh", this.npc.Entity.location);
        });
        await new EmoteTask(this.npc, emote, this).start();
        await waitForTicks(2);
        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");
        }
    }
}
