import { world } from "@minecraft/server";
import ScriptingModule from "../modules/scriptingModule";
import { WorldEvent } from "../modules/worldEventsModule";
export default class WorldEventModule extends ScriptingModule {
    constructor() {
        super("WorldEventModule");
        this.onInitialize = () => {
            this.registerWorldEvents();
        };
    }
    registerWorldEvents() {
        WorldEvent.register(new WorldEvent({
            id: "cc_re:sand_storm",
            dynamicProperty: "cc_re:allow_event_sand_storm",
            chance: 0.01,
            duration: 50,
            cooldown: 100,
            radius: 100,
            conditions: (player, tags) => tags.includes("cc_re:desert") &&
                player.location.y >=
                    (player.dimension.getTopmostBlock({ x: player.location.x, z: player.location.z })
                        ?.location.y || 60 - 10),
            effectOptions: {
                effects: [
                    {
                        effectType: "slowness",
                        properties: { amplifier: 1, showParticles: false },
                    },
                ],
                borderParticles: [
                    {
                        identifier: "cc_re:sand_storm_fog",
                        amount: 100,
                        interval: 1, // 1 second
                    },
                    {
                        identifier: "cc_re:sand_storm",
                        amount: 100,
                        interval: 1, // 1 second
                    },
                ],
            },
        }));
        WorldEvent.register(new WorldEvent({
            id: "cc_re:snow_storm",
            dynamicProperty: "cc_re:allow_event_snow_storm",
            chance: 0.01,
            duration: 50,
            cooldown: 100,
            radius: 100,
            conditions: (player, tags) => (tags.includes("cc_re:ice") || tags.includes("cc_re:cold")) &&
                player.location.y >=
                    (player.dimension.getTopmostBlock({ x: player.location.x, z: player.location.z })
                        ?.location.y || 60 - 10),
            effectOptions: {
                effects: [
                    {
                        effectType: "slowness",
                        properties: { amplifier: 1, showParticles: false },
                    },
                ],
                borderParticles: [
                    {
                        identifier: "cc_re:snow_storm_fog",
                        amount: 100,
                        interval: 1, // 1 second
                    },
                    {
                        identifier: "cc_re:snow_storm",
                        amount: 100,
                        interval: 1, // 1 second
                    },
                ],
            },
        }));
        WorldEvent.register(new WorldEvent({
            id: "cc_re:rain_storm",
            dynamicProperty: "cc_re:allow_event_rain_storm",
            chance: 0.01,
            duration: 50,
            cooldown: 100,
            radius: 100,
            conditions: (player, tags) => tags.includes("cc_re:overworld") &&
                !tags.includes("cc_re:desert") &&
                !tags.includes("cc_re:ice") &&
                !tags.includes("cc_re:cold") &&
                player.location.y >=
                    (player.dimension.getTopmostBlock({ x: player.location.x, z: player.location.z })
                        ?.location.y || 60 - 10),
            customOnStart: () => {
                world.getDimension("overworld").runCommandAsync("weather thunder");
            },
            customOnEnd: () => {
                world.getDimension("overworld").runCommandAsync("weather clear");
            },
            effectOptions: {
                borderParticles: [
                    {
                        identifier: "cc_re:rain_fog",
                        amount: 100,
                        interval: 1, // 1 second
                    },
                ],
            },
        }));
        WorldEvent.register(new WorldEvent({
            id: "cc_re:mist",
            dynamicProperty: "cc_re:allow_event_mist",
            chance: 0.01,
            duration: 50,
            cooldown: 100,
            radius: 100,
            conditions: (player, tags) => tags.includes("cc_re:overworld") &&
                player.location.y >=
                    (player.dimension.getTopmostBlock({ x: player.location.x, z: player.location.z })
                        ?.location.y || 60 - 10),
            effectOptions: {},
        }));
        // Schedule emission for each particle
        WorldEvent.initialize();
    }
}
