import { world, EquipmentSlot } from '@minecraft/server';
import { print } from './print';
import { calculateKnockbackVector } from './armorHandler';
/**
 * Array of weapon names to compare with item IDs.
 * @type {string[]>}
 * @param ["minecraft:apple"]
 */
const weaponNames = new Array("fire_hydra_hammer", "water_hydra_hammer", "purpur_hydra_hammer", "skeletal_hydra_hammer", "warden_hydra_hammer", "mega_hydra_sword");
const fireWeapons = new Array("fire_hydra_hammer");
const iceWeapons = new Array();
const lightningWeapons = new Array("mega_hydra_sword");
const poisonWeapons = new Array("purpur_hydra_hammer");
const soulfireWeapons = new Array("warden_hydra_hammer");
const waterWeapons = new Array("water_hydra_hammer");
const windWeapons = new Array();
const skeletalWeapons = new Array("skeletal_hydra_hammer");
/**
 * Checks if the attacking entity of the entityHitEntity event is a player if yes applies the relevant weapon skill based on the equipped weapon
 * @param {Object} event - entityHitEntity event.
 */
export function weaponEntityHitEntityHandler(event) {
    var _a;
    const damagingEntity = event.damagingEntity;
    const hitEntity = event.hitEntity;
    if (!damagingEntity || !hitEntity || damagingEntity.typeId !== "minecraft:player")
        return;
    const equipment = (_a = damagingEntity.getComponent('equippable')) === null || _a === void 0 ? void 0 : _a.getEquipment(EquipmentSlot.Mainhand);
    if (!equipment || !equipment.typeId.toString().includes('ss_hyd'))
        return;
    const equipmentName = equipment.typeId.split(":")[1];
    if (!weaponNames.includes(equipmentName))
        return;
    if (fireWeapons.includes(equipmentName)) {
        world.playSound('ss_hyd.fire_hammer', hitEntity.location);
        hitEntity.setOnFire(5, true);
    }
    else if (iceWeapons.includes(equipmentName)) {
        hitEntity.addEffect("slowness", 100, { amplifier: 3, showParticles: true });
    }
    else if (lightningWeapons.includes(equipmentName)) {
        handleLightningSword(event);
    }
    else if (poisonWeapons.includes(equipmentName)) {
        world.playSound('ss_hyd.purpur_hammer', hitEntity.location);
        hitEntity.addEffect("fatal_poison", 100, { amplifier: 3, showParticles: true });
    }
    else if (soulfireWeapons.includes(equipmentName)) {
        world.playSound('ss_hyd.warden_hammer', hitEntity.location);
        hitEntity.addEffect("blindness", 40, { amplifier: 0, showParticles: true });
        damagingEntity.addEffect("regeneration", 40, { amplifier: 1, showParticles: true });
    }
    else if (waterWeapons.includes(equipmentName) || windWeapons.includes(equipmentName)) {
        world.playSound('ss_hyd.water_hammer', hitEntity.location);
        handleKnockbackSword(event);
    }
    else if (skeletalWeapons.includes(equipmentName)) {
        hitEntity.addEffect("wither", 100, { amplifier: 3, showParticles: true });
        world.playSound('ss_hyd.skeleton_hammer', hitEntity.location);
    }
}
/**
 * summons lightning_bolt entity on the attacked entity
 *
 * @param {Object} event - entityHitEntity event.
 */
function handleLightningSword(event) {
    const kbVector = calculateKnockbackVector(event.hitEntity.location, event.damagingEntity.location, 1);
    event.hitEntity.applyKnockback(kbVector.x, kbVector.z, 2, 0.3);
    if (event.damagingEntity.typeId == "minecraft:player") {
        event.damagingEntity.playSound("ss_hyd.mega_sword_attack");
    }
}
/**
 * applies knockback on the attacked entity
 *
 * @param {Object} event - entityHitEntity event.
 */
function handleKnockbackSword(event) {
    const kbVector = calculateKnockbackVector(event.hitEntity.location, event.damagingEntity.location, 1);
    event.hitEntity.applyKnockback(kbVector.x, kbVector.z, 2, 0.3);
}
