import*as mc from"@minecraft/server";import*as effects from"../effects";import*as vector from"../utils/vector";import*as selectors from"../utils/selectors";import{spawnXp}from"../entities";const masks=["hf_mzs:mask_bliss","hf_mzs:mask_faith","hf_mzs:mask_fear","hf_mzs:mask_fury","hf_mzs:mask_misery","hf_mzs:mask_rage"],maskEffects={0:"jump_boost",1:"health_boost",2:"speed",3:"strength",4:"resistance",5:"haste"},allEnchantments=["aqua_affinity","blast_protection","curse_of_binding","curse_of_vanishing","fire_protection","mending","projectile_protection","protection","respiration","thorns","unbreaking"];export function eventBehavior(t){if("register"!==t.eventId)if("to_attack"!==t.eventId){if("drop"===t.eventId&&mc.world.gameRules.doMobLoot)return spawnXp(t.entity.location,5,t.entity.dimension),void dropMask(t);if("is_attacking"!==t.eventId)return"alert"===t.eventId?(t.entity.runCommand("/tp @s ~~~ facing @p[r=12]"),void t.entity.addEffect("slowness",14,{amplifier:100,showParticles:!1})):"roar"===t.eventId?(t.entity.runCommand("/tp @s ~~~ facing @p[r=12]"),void t.entity.addEffect("slowness",20,{amplifier:100,showParticles:!1})):void("turned_into_mask"!==t.eventId?"death"!==t.eventId||mc.system.runTimeout((()=>{t.entity.isValid()&&t.entity.triggerEvent("drop")}),60):dropMaskTamed(t.entity));if(selectors.union({location:t.entity.location,maxDistance:16,excludeFamilies:["hf_mzs_umvuthana_crane","hf_mzs_umvuthi"]},["hf_mzs_umvuthana"],t.entity.dimension,t.entity.id).forEach((t=>{!t.isValid()||t.getProperty("hf_mzs:tamed")||t.getProperty("hf_mzs:death")||t.getProperty("hf_mzs:spawn")||t.getProperty("hf_mzs:counter")||t.getProperty("hf_mzs:turning_into_mask")||t.getProperty("hf_mzs:roaring")||t.triggerEvent("cooldown")})),t.entity.getComponent("minecraft:health").currentValue>4)return;t.entity.addEffect("speed",40,{amplifier:1,showParticles:!1})}else t.entity.addEffect("speed",20,{amplifier:1,showParticles:!1});else t.entity.addEffect(maskEffects[t.entity.getProperty("hf_mzs:mask")],9999,{amplifier:0,showParticles:!1})}function dropMask(t){if(!0===t.entity.getProperty("hf_mzs:tamed")||Math.random()<.7)return;const e=new mc.ItemStack(masks[t.entity.getProperty("hf_mzs:mask")]);e.setDynamicProperty("hf_mzs:entity",t.entity.typeId),t.entity.dimension.spawnItem(e,t.entity.location)}function dropMaskTamed(t){const e=new mc.ItemStack(masks[t.getProperty("hf_mzs:mask")]);e.setDynamicProperty("hf_mzs:entity",t.typeId),void 0!==t.nameTag&&(e.nameTag=t.nameTag);for(const n of allEnchantments)void 0!==t.getDynamicProperty("hf_mzs:"+n)&&e.getComponent("enchantable").addEnchantment({type:new mc.EnchantmentType(n),level:t.getDynamicProperty("hf_mzs:"+n)});const n=55-t.getComponent("minecraft:health").currentValue/20*54;e.getComponent("minecraft:durability").damage=Math.min(n+5,54),t.dimension.spawnItem(e,vector.add(t.location,{x:0,y:1.5,z:0})),t.remove()}