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

const TAG_ARMOR_EFFECT = 'oct_plev_armor_effect_demon'

// Armor effect on demon armor
function main() {
	
	for (let player of world.getAllPlayers()) {
		const armorEquipped = player.getComponent(EntityEquippableComponent.componentId)

		const hasHelmet = armorEquipped.getEquipment(EquipmentSlot.Head)?.typeId == "oct_plev:demon_helmet";
		const hasChestplate = armorEquipped.getEquipment(EquipmentSlot.Chest)?.typeId == "oct_plev:demon_chestplate";
		const hasLeggings = armorEquipped.getEquipment(EquipmentSlot.Legs)?.typeId == "oct_plev:demon_leggings";
		const hasBoots = armorEquipped.getEquipment(EquipmentSlot.Feet)?.typeId == "oct_plev:demon_boots";

		// const hasFullArmor = hasHelmet && hasChestplate && hasLeggings && hasBoots
		// const hasAnyArmor = hasHelmet || hasChestplate || hasLeggings || hasBoots
		const hasThreeParts = ((hasHelmet && hasChestplate && hasLeggings) || (hasHelmet && hasChestplate && hasBoots) || (hasHelmet && hasLeggings && hasBoots) || (hasChestplate && hasLeggings && hasBoots))
		

		if(hasThreeParts && !player.hasTag(TAG_ARMOR_EFFECT)) {
			player.addTag(TAG_ARMOR_EFFECT);			
			player.runCommand("/effect @s fire_resistance 100000 0 true");
			player.runCommand("/effect @s speed 100000 1 true");
		}
		else if (!hasThreeParts && player.hasTag(TAG_ARMOR_EFFECT)) {
			player.removeTag(TAG_ARMOR_EFFECT);
			player.runCommand("/effect @s fire_resistance 0");
			player.runCommand("/effect @s speed 0");
		
		}
	}
}
system.runInterval(main, 5);