import { world, Player } from "@minecraft/server";

world.afterEvents.entityHurt.subscribe(({ damageSource, hurtEntity, damage }) => {
  if (damage <= 0) return;

  const attacker = damageSource.damagingEntity;
  if (!(attacker instanceof Player)) return;

  if (attacker.hasTag("buff2")) {
    let multiplier = 2;

    try {
      const familyComp = hurtEntity.getComponent("minecraft:type_family");
      if (familyComp?.hasTypeFamily("monster")) {
        if (attacker.hasTag("difficulty_phase1")) {
          multiplier = 2.5;
        } else if (attacker.hasTag("difficulty_phase2")) {
          multiplier = 2.5;
        } else if (attacker.hasTag("difficulty_phase3")) {
          multiplier = 3.5;
        }
        else if (attacker.hasTag("difficulty_phase4")) {
          multiplier = 3.5;
        }
      }
    } catch (e) {
      // Error al acceder al componente, continuar con el multiplicador base
    }
try {
    hurtEntity.applyDamage(damage * multiplier);
    } catch (e) {
    }
  }
});
