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

const ANKY_HORIZONTAL = 1.6;
const ANKY_VERTICAL = 0.5;

const PRENO_HORIZONTAL = 1;
const PRENO_VERTICAL = 0.3;

const TRIKE_HORIZONTAL = 2.2;
const TRIKE_VERTICAL = 0.7;

world.afterEvents.entityHurt.subscribe((data) => {
    const { damageSource, hurtEntity: victim } = data;
    const attacker = damageSource.damagingEntity;

    if (!attacker) return;
    if (attacker.typeId == "pb_dino:pulmonoscorpius") {
      const diff = attacker?.getProperty("pb_dino:diff_setting");
      if (diff == "easy") {
        victim.addEffect("fatal_poison", 40, {
          amplifier: 0,
          showParticles: true,
        });
      }
      if (diff == "normal") {
        victim.addEffect("fatal_poison", 100, {
          amplifier: 0,
          showParticles: true,
        });
      }
      if (diff == "hard") {
        victim.addEffect("fatal_poison", 200, {
          amplifier: 0,
          showParticles: true,
        });
      }
    }
    if (attacker.typeId == "pb_dino:ankylosaurus") {
      victim.applyKnockback(
        victim.location.x - attacker.location.x,
        victim.location.z - attacker.location.z,
        ANKY_HORIZONTAL,
        ANKY_VERTICAL
      );
    }
    if (attacker.typeId == "pb_dino:prenocephale") {
      victim.applyKnockback(
        victim.location.x - attacker.location.x,
        victim.location.z - attacker.location.z,
        PRENO_HORIZONTAL,
        PRENO_VERTICAL
      );
    }
    if (attacker.typeId == "pb_dino:triceratops") {
      victim.applyKnockback(
        victim.location.x - attacker.location.x,
        victim.location.z - attacker.location.z,
        TRIKE_HORIZONTAL,
        TRIKE_VERTICAL
      );
    }
});
