import { end, nether, waitForTicks } from "../../utils/index";
import { Task } from "../../npc/tasks/task";
import { FindLowLightTask } from "../../npc/tasks/findLowLight";
import { MoveToTargetTask } from "../../npc/tasks/moveToTarget";
import { PlaceBlockTask } from "../../npc/tasks/placeBlock";
const MOVE_TO_TARGET_DEFAULTS = { startNavEvent: "start_goal_nav_node", endNavEvent: "end_goal_nav_node", navTargetTypeId: "ldz_crcomp:nav_node", stopDistance: 2 };
const PLACE_TORCH_DEFAULTS = {
    block: {
        block: "minecraft:torch",
        properties: { torch_facing_direction: "top" },
    },
    emoteData: {
        emoteAnimation: "place_torch",
        emoteSeconds: 0.5,
        playSound: { sound: "dig.wood", volume: 2 },
    }
};
export class GoLightingTask extends Task {
    async performTask() {
        if (this.npc.Entity.getProperty("light_level") >= 15 || this.npc.Entity.dimension === nether || this.npc.Entity.dimension === end) {
            this.npc.broadcastEvent("no_light");
            return { outcome: "failed" };
        }
        this.npc.broadcastEvent("light");
        await waitForTicks(30, this.id);
        let successCount = 0;
        while (this.npc.Entity.getProperty("light_level") < 15) {
            this.shouldAbort();
            const result = await new FindLowLightTask(this.npc, { lightCheckEntity: "ldz_crcomp:block_check", debugParticles: this.npc.Owner.hasTag("dev") }, this).start();
            if (result.outcome === "succeeded") {
                if ((await new MoveToTargetTask(this.npc, Object.assign({ location: result.data.lowLightLocation }, MOVE_TO_TARGET_DEFAULTS)).start()).outcome === "succeeded") {
                    await new PlaceBlockTask(this.npc, Object.assign({ location: result.data.lowLightLocation }, PLACE_TORCH_DEFAULTS), this).start();
                    successCount++;
                    this.npc.broadcastEvent("torch");
                }
                this.npc.Entity.triggerEvent("start_goal_idle");
                await waitForTicks(100, this.id);
                this.npc.Entity.triggerEvent("end_goal_idle");
            }
            else {
                this.npc.Entity.triggerEvent("start_goal_idle");
                await waitForTicks(100, this.id);
                this.npc.Entity.triggerEvent("end_goal_idle");
            }
        }
        return successCount > 0 ? { outcome: "succeeded" } : { outcome: "failed" };
    }
    async cleanupTask() {
    }
}
