import { EquipmentSlot, world } from "@minecraft/server";
import { VENOMITE_ARMOR } from "./common/venomiteArmor";
import { GLACIAL_NECKLACE } from "./specific/glacialNecklace";
import { INFERNAL_NECKLACE } from "./specific/infernalNecklace";
import { EntityComponents } from "../entities/utils/entityComponents";
import { COBALTIUM_SWORD } from "./specific/cobaltiumSword";
import { VENOMITE_TOOLS } from "./common/venomiteTools";
import { DUSKITE_TOOLS } from "./common/duskiteTools";

world.afterEvents.entityHitEntity.subscribe(ev => {
    const {damagingEntity, hitEntity} = ev;

    const equippable = EntityComponents.getEquippable(damagingEntity);
    
    const mainhandItem = equippable?.getEquipment(EquipmentSlot.Mainhand)
    const chestplateItem = equippable?.getEquipment(EquipmentSlot.Chest)

    const mainhandItemId = mainhandItem?.typeId
    const chestplateItemId = chestplateItem?.typeId
    
    
    switch(mainhandItemId) {
        case "piki_beyondsurvival:corrupted_battleaxe": 
            hitEntity.addEffect("wither", 20 * 4, {amplifier: 0, showParticles: true})
            break;
        case "piki_beyondsurvival:frost_sword":
            hitEntity.addEffect("slowness", 20 * 8, {amplifier: 0, showParticles: true})
            hitEntity.addEffect("weakness", 20 * 4, {amplifier: 0, showParticles: true})
            break
        case "piki_beyondsurvival:pyro_sword":
            hitEntity.setOnFire(7, true);
            break;
    }

    switch(damagingEntity.typeId) {
        case "piki_beyondsurvival:infernoid":
            hitEntity.setOnFire(7, true);
            break;
    }

    if (VENOMITE_ARMOR.isArmorActive(equippable, true)) VENOMITE_ARMOR.applyPoisonAttack(hitEntity)
    if (GLACIAL_NECKLACE.isGlacialNecklace(chestplateItem)) GLACIAL_NECKLACE.applyAttackEffect(hitEntity)
    if (INFERNAL_NECKLACE.isInfernalNecklace(chestplateItem)) INFERNAL_NECKLACE.applyAttackEffect(hitEntity)
    if (COBALTIUM_SWORD.isCobaltiumSword(mainhandItemId)) COBALTIUM_SWORD.applyAttackEffect(damagingEntity, hitEntity)
    if (VENOMITE_TOOLS.isVenomiteTool(mainhandItemId)) VENOMITE_TOOLS.applyAttackEffect(hitEntity)
    if (DUSKITE_TOOLS.isDuskiteTool(mainhandItemId)) DUSKITE_TOOLS.applyAttackEffect(hitEntity)
})