import { system, TicksPerSecond, world } from "@minecraft/server";

const CHECK_INTERVAL = 0.125 * TicksPerSecond;

const armorPieces = {
    Head: "cyd_dino:dark_scale_helmet",
    Chest: "cyd_dino:dark_scale_chestplate",
    Legs: "cyd_dino:dark_scale_leggings",
    Feet: "cyd_dino:dark_scale_boots"
};

const FULL_SET_EFFECTS = [
    { effect: 'fire_resistance', duration: CHECK_INTERVAL + 5 * TicksPerSecond, amplifier: 0 }
];

function checkDarkScaleArmor() {
    const players = world.getPlayers();

    players.forEach((player) => {
        const armorComponent = player.getComponent("minecraft:equippable");
        if (!armorComponent) return;

        let hasFullSet = true;
        for (const [slot, armorId] of Object.entries(armorPieces)) {
            const item = armorComponent.getEquipment(slot);
            if (!item || item.typeId !== armorId) {
                hasFullSet = false;
                break;
            }
        }

        if (hasFullSet) {
            FULL_SET_EFFECTS.forEach(({ effect, duration, amplifier }) => {
                player.addEffect(effect, duration, { 
                    amplifier: amplifier, 
                    showParticles: false 
                });
            });
            if (player.getEffect("poison")) {
                player.removeEffect("poison");
            }
        }
    });

    system.runTimeout(checkDarkScaleArmor, CHECK_INTERVAL);
}

system.runTimeout(checkDarkScaleArmor, CHECK_INTERVAL);