var _a;
import { EntityDamageCause } from '@minecraft/server';
import WitherbossAttack from './witherbossAttack';
import { createLocationShockWave } from './shockWave';
import WBVector3 from '../../util/wbVector3';
import { IMMUNE_ATTACK_ENTITIES, SHORT_RANGE_SQ } from '../witherbossSettings';
export default class CoreBlastAttack extends WitherbossAttack {
    constructor() {
        super(...arguments);
        this.tickCount = 0;
    }
    onStart() {
        const entity = this.wither.getEntity();
        if (!entity) {
            return;
        }
        // Start the animation on the wither core body
        // this.wither.setAnimationState('attack_core_blast');
        this.coreBlastEntity = entity.dimension.spawnEntity('twb_wisu:core_blast', this.getEffectLocation());
    }
    getEffectLocation() {
        const entity = this.wither.getEntity();
        return new WBVector3(0, 4.5, 1)
            .rotateY(this.savedYRotation ?? entity.getRotation().y)
            .add(entity.location);
    }
    tickAttack() {
        // If the wither is dead, end the attack
        const entity = this.wither.getEntity();
        if (!entity) {
            this.coreBlastEntity?.remove();
            return;
        }
        if (this.coreBlastEntity && this.coreBlastEntity.isValid()) {
            this.coreBlastEntity.teleport(this.getEffectLocation());
        }
        if (this.tickCount === 55) {
            this.savedYRotation = this.wither.getEntity()?.getRotation().y;
            entity.triggerEvent('twb_wisu:make_stationary_no_rotation');
            this.wither.setAnimationState('attack_core_blast');
            entity.dimension.playSound('twb_wisu:witherboss.attack.core_blast.windup', entity.location, { volume: 16 });
        }
        else if (this.tickCount === 56) {
            // Let AC automatically return to 'idle' once the animation is finished
            this.wither.setIdleAnimationState();
        }
        if (this.tickCount === CoreBlastAttack.SUMMONING_CIRCLE_DURATION) {
            // Play sound
            entity.dimension.playSound('twb_wisu:witherboss.attack.core_blast.cast', entity.location, { volume: 16 });
            // Spawn knockback wave
            createLocationShockWave(entity.dimension, entity.location, {
                entity: this.wither.getEntity(),
                size: CoreBlastAttack.CORE_BLAST_RANGE,
                startRange: 0.5,
                speed: 1.5,
                knockback: 5,
                damage: 20,
                damageOptions: {
                    cause: EntityDamageCause.entityAttack,
                    damagingEntity: entity
                },
                entityHitFunction: (e) => !IMMUNE_ATTACK_ENTITIES.includes(e.typeId),
                knockbackRangeFunction: (kb, _) => [kb, kb / 6],
                // edgeParticles: ['twb_wisu:cloud_soul'],
                // edgeParticlesHeight: 2
            });
        }
        this.tickCount++;
    }
    endAttack() {
        if (this.tickCount >= CoreBlastAttack.CORE_BLAST_DURATION) {
            this.wither.getEntity()?.triggerEvent('twb_wisu:make_moving');
            return true;
        }
        return false;
    }
    static getAttackRegistry() {
        return {
            canStartAttack(wither) {
                const entity = wither.getEntity();
                if (!entity)
                    return false;
                return wither.getTargetController()
                    .getTargets()
                    .find((target) => WBVector3.distanceSquared(target.location, entity.location)
                    <= SHORT_RANGE_SQ) !== undefined;
            },
            attackChance: 0.0025,
            createNewAttack(wither) {
                return new CoreBlastAttack(wither);
            }
        };
    }
}
_a = CoreBlastAttack;
CoreBlastAttack.CORE_BLAST_RANGE = 22;
CoreBlastAttack.CORE_BLAST_DURATION = 180;
// eslint-disable-next-line max-len
CoreBlastAttack.SUMMONING_CIRCLE_PARTICLE_COUNT = Math.floor(Math.PI * 2 * _a.CORE_BLAST_RANGE);
CoreBlastAttack.SUMMONING_CIRCLE_DURATION = 120;
