import { world } from "@minecraft/server";
import { boss, removerPrefixo } from "./communs";

world.afterEvents.entityHitEntity.subscribe((event) => {
    const { damagingEntity, hitEntity } = event;
    if (boss[removerPrefixo(damagingEntity.typeId)]) {
        const {damage_melee,damage_range,spawnAnimation,tagAttack} = boss[removerPrefixo(damagingEntity.typeId)]
        try {
            hitEntity.addTag(`${tagAttack}`)
        } 
        catch {
            return
        }
        if (damagingEntity.typeId == "ns_ab:raijin") {
            if (damagingEntity.getProperty(`ns_ab:raijin_armor`)) {
                hitEntity.addEffect('fire_resistance',40);
                hitEntity.dimension.spawnEntity('minecraft:lightning_bolt',hitEntity.location)
            }
        }
    }
})