import*as mc from"@minecraft/server";import*as vector from"../utils/vector";import*as selectors from"../utils/selectors";import{GeomancyWhitelist}from"../items/earthrendGauntlet";import{EXCLUDED_ENTITIES}from"../playerAbilities";import{spawnXp}from"../entities";export const ATTACK_RANGE=12;const ATTACK_KF=[20,35],ATTACK_CD=70,ATTACK_HIT_DIST=3,ATTACK_KB=1.5;export const ATTACK_DAMAGE=5;export function eventBehavior(t){const o=t.entity;if("register"===t.eventId)return o.setDynamicProperty("hf_mzs:attack_cooldown",70),void o.setProperty("hf_mzs:attacking",!1);if("drop"===t.eventId&&mc.world.gameRules.doMobLoot)spawnXp(o.location,4,o.dimension);else{if("attempt_attack"===t.eventId){if(o.getDynamicProperty("hf_mzs:attack_cooldown")>0)return;if(o.getDynamicProperty("hf_mzs:frozen"))return;const t=getTarget(o);if(void 0===t||!t.isValid())return;if(Math.abs(t.location.y-o.location.y)>2)return;return o.setProperty("hf_mzs:attacking",!0),o.addEffect("slowness",ATTACK_KF[1],{amplifier:100,showParticles:!1}),rotateToTarget(o,t),void mc.system.runTimeout((()=>{if(!t.isValid())return;rotateToTarget(o,t),selectors.union({location:o.location,maxDistance:3,excludeFamilies:["inanimate","hf_mzs_bluff"],excludeTypes:EXCLUDED_ENTITIES},[],o.dimension,o.id).forEach((t=>{if(t.isValid()){const e=vector.subtract(t.location,o.location);t.applyKnockback(e.x,e.z,1.5,.5),t.applyDamage(5,{cause:"entityAttack",damagingEntity:o})}}));const e=o.dimension.spawnEntity("hf_mzs:bluff_projectile",o.location),i=vector.flatten(o.getViewDirection(),"y");e.setDynamicProperty("hf_mzs:x_dir",i.x),e.setDynamicProperty("hf_mzs:z_dir",i.z),e.setDynamicProperty("hf_mzs:shooter",o.id),o.runCommand("/particle hf_mzs:bluff_crash2 ~~~"),o.runCommand("/particle hf_mzs:bluff_crash3 ~~~"),o.runCommand("/camerashake add @a[r=16] 0.25 0.25 positional"),mc.system.runTimeout((()=>{o.setDynamicProperty("hf_mzs:attack_cooldown",70),o.setProperty("hf_mzs:attacking",!1)}),ATTACK_KF[1]-ATTACK_KF[0])}),ATTACK_KF[0])}"death"!==t.eventId||mc.system.runTimeout((()=>{t.entity.isValid()&&t.entity.triggerEvent("drop")}),50)}}export function tick5(t){t.getDynamicProperty("hf_mzs:attack_cooldown")>0&&t.setDynamicProperty("hf_mzs:attack_cooldown",t.getDynamicProperty("hf_mzs:attack_cooldown")-5);const o=selectors.union({location:t.location,maxDistance:1,excludeFamilies:["inanimate"],excludeTypes:EXCLUDED_ENTITIES},[],t.dimension,t.id);for(let e=0;e<o.length;e++){if(void 0===o[e]||!o[e].isValid())continue;t.setDynamicProperty("hf_mzs:attack_cooldown",0);const i=vector.subtract(o[e].location,t.location);o[e].applyKnockback(i.x,i.y,1.5,0)}const e=t.dimension.getBlockFromRay(vector.add(t.location,vector.up),vector.down,{maxDistance:2,includePassableBlocks:!1,includeLiquidBlocks:!1});(void 0===e||e.block.isValid())&&(void 0!==e&&GeomancyWhitelist.includes(e.block.typeId)?t.setProperty("hf_mzs:on_rock",!0):t.setProperty("hf_mzs:on_rock",!1))}export function tick1(t){}function getTarget(t){const o=selectors.union({maxDistance:64,location:t.location},["player","hf_mzs_sculptor"],t.dimension,t.id,!1);for(const t of o)if(t.isValid()&&("minecraft:player"!==t.typeId||"creative"!==t.getGameMode()))return t}function rotateToTarget(t,o){const e=vector.subtract(o.location,t.location),i=Math.acos(e.y/vector.magnitude(e))/Math.PI*180-90,a=-Math.atan2(e.x,e.z)/Math.PI*180;t.setRotation({x:i,y:a})}