// Priority: 800

/*
    Mob Stats Script
    Adjusts the attributes (Health, Damage, etc.) of specific mobs.
    Author: vyrriox
*/

EntityEvents.spawned((event) => {
    const { entity } = event;

    // Wither: 500 HP
    if (entity.type === "minecraft:wither") {
        entity.setAttributeBaseValue("generic.max_health", 500);
        entity.health = 500;
    }

    // Ender Dragon: 2000 HP
    if (entity.type === "minecraft:ender_dragon") {
        entity.setAttributeBaseValue("generic.max_health", 2000);
        entity.health = 2000;
    }

    // Warden: 1000 HP
    if (entity.type === "minecraft:warden") {
        entity.setAttributeBaseValue("generic.max_health", 1000);
        entity.health = 1000;
    }

    // Twilight Forest Bosses Boost (+50%)
    const tfBosses = [
        "twilightforest:naga",
        "twilightforest:lich",
        "twilightforest:minoshroom",
        "twilightforest:hydra",
        "twilightforest:knight_phantom",
        "twilightforest:ur_ghast",
        "twilightforest:alpha_yeti",
        "twilightforest:snow_queen"
    ];

    if (tfBosses.includes(entity.type)) {
        // Boost Factor: 1.5x (+50%)
        let multiplier = 2.0;

        // Health
        let baseHealth = entity.getAttributeBaseValue("generic.max_health");
        let newHealth = baseHealth * multiplier;
        entity.setAttributeBaseValue("generic.max_health", newHealth);
        entity.health = newHealth;

        // Armor
        let baseArmor = entity.getAttributeBaseValue("generic.armor");
        if (baseArmor > 0) { // Only boost if they have armor naturally
            entity.setAttributeBaseValue("generic.armor", baseArmor * multiplier);
        }

        // Attack Damage
        // Some bosses might use magic or ranged attacks not affected by generic.attack_damage,
        // but this covers melee interactions.
        let baseDamage = entity.getAttributeBaseValue("generic.attack_damage");
        if (baseDamage > 0) {
            entity.setAttributeBaseValue("generic.attack_damage", baseDamage * multiplier);
        }
    }

    // Final Boss Addon - Castle Keeper: x5 Boost (Mega Buff)
    if (entity.type === "twilight_forest_final_boss:castle_keeper") {
        let megaMultiplier = 10.0;

        // Health
        let kHealth = entity.getAttributeBaseValue("generic.max_health");
        entity.setAttributeBaseValue("generic.max_health", kHealth * megaMultiplier);
        entity.health = kHealth * megaMultiplier;

        // Armor
        let kArmor = entity.getAttributeBaseValue("generic.armor");
        if (kArmor > 0) entity.setAttributeBaseValue("generic.armor", kArmor * megaMultiplier);

        // Damage
        let kDamage = entity.getAttributeBaseValue("generic.attack_damage");
        if (kDamage > 0) entity.setAttributeBaseValue("generic.attack_damage", kDamage * megaMultiplier);
    }

    // Aether Bosses Boost (x3.0)
    const aetherBosses = [
        "aether:slider",
        "aether:valkyrie_queen",
        "aether:sun_spirit"
    ];

    if (aetherBosses.includes(entity.type)) {
        let aetherMultiplier = 3.0;

        // Health
        let aHealth = entity.getAttributeBaseValue("generic.max_health");
        entity.setAttributeBaseValue("generic.max_health", aHealth * aetherMultiplier);
        entity.health = aHealth * aetherMultiplier;

        // Armor
        let aArmor = entity.getAttributeBaseValue("generic.armor");
        if (aArmor > 0) entity.setAttributeBaseValue("generic.armor", aArmor * aetherMultiplier);

        // Damage
        let aDamage = entity.getAttributeBaseValue("generic.attack_damage");
        if (aDamage > 0) entity.setAttributeBaseValue("generic.attack_damage", aDamage * aetherMultiplier);
    }

    // Ars Nouveau Bosses Boost (x2.0)
    // Primary boss is Wilden Chimera
    const arsNouveauBosses = [
        "ars_nouveau:wilden_boss",
        "ars_nouveau:wilden_guardian",
        "ars_nouveau:wilden_stalker",
        "ars_nouveau:wilden_hunter"
    ];

    if (arsNouveauBosses.includes(entity.type)) {
        let arsMultiplier = 2.0;

        // Health
        let anHealth = entity.getAttributeBaseValue("generic.max_health");
        entity.setAttributeBaseValue("generic.max_health", anHealth * arsMultiplier);
        entity.health = anHealth * arsMultiplier;

        // Armor
        let anArmor = entity.getAttributeBaseValue("generic.armor");
        if (anArmor > 0) entity.setAttributeBaseValue("generic.armor", anArmor * arsMultiplier);

        // Damage
        let anDamage = entity.getAttributeBaseValue("generic.attack_damage");
        if (anDamage > 0) entity.setAttributeBaseValue("generic.attack_damage", anDamage * arsMultiplier);
    }

    // Deeper and Darker Bosses/Mini-Bosses Boost (x4.0)
    const ddBosses = [
        "deeperdarker:shriek_worm",
        "deeperdarker:stalker",
        "deeperdarker:sculk_snapper",
        "deeperdarker:shattered"
    ];

    if (ddBosses.includes(entity.type)) {
        let ddMultiplier = 4.0;

        // Health
        let ddHealth = entity.getAttributeBaseValue("generic.max_health");
        entity.setAttributeBaseValue("generic.max_health", ddHealth * ddMultiplier);
        entity.health = ddHealth * ddMultiplier;

        // Armor
        let ddArmor = entity.getAttributeBaseValue("generic.armor");
        if (ddArmor > 0) entity.setAttributeBaseValue("generic.armor", ddArmor * ddMultiplier);

        // Damage
        let ddDamage = entity.getAttributeBaseValue("generic.attack_damage");
        if (ddDamage > 0) entity.setAttributeBaseValue("generic.attack_damage", ddDamage * ddMultiplier);
    }

    // Iron's Spells 'n Spellbooks Bosses (x2.0)
    const issBosses = [
        "irons_spellbooks:dead_king",
        "irons_spellbooks:dead_king_corpse",
        "irons_spellbooks:archevoker",
        "irons_spellbooks:necromancer",
        "irons_spellbooks:priest", // Pyromancer/Cryomancer are often regular mobs, leaving them out unless requested
        "irons_spellbooks:citadel_keeper" // Checking if this exists or falls under keeper
    ];

    if (issBosses.includes(entity.type)) {
        let issMultiplier = 2.0;

        // Health
        let issHealth = entity.getAttributeBaseValue("generic.max_health");
        entity.setAttributeBaseValue("generic.max_health", issHealth * issMultiplier);
        entity.health = issHealth * issMultiplier;

        // Armor
        let issArmor = entity.getAttributeBaseValue("generic.armor");
        if (issArmor > 0) entity.setAttributeBaseValue("generic.armor", issArmor * issMultiplier);

        // Damage
        let issDamage = entity.getAttributeBaseValue("generic.attack_damage");
        if (issDamage > 0) entity.setAttributeBaseValue("generic.attack_damage", issDamage * issMultiplier);
    }

    // Mutant Monsters Bosses (x2.0)
    const mutantBosses = [
        "mutantmonsters:mutant_creeper",
        "mutantmonsters:mutant_zombie",
        "mutantmonsters:mutant_skeleton",
        "mutantmonsters:mutant_enderman",
        "mutantmonsters:mutant_snow_golem",
        "mutantmonsters:spider_pig"
    ];

    if (mutantBosses.includes(entity.type)) {
        let mmMultiplier = 2.0;

        // Health
        let mmHealth = entity.getAttributeBaseValue("generic.max_health");
        entity.setAttributeBaseValue("generic.max_health", mmHealth * mmMultiplier);
        entity.health = mmHealth * mmMultiplier;

        // Armor
        let mmArmor = entity.getAttributeBaseValue("generic.armor");
        if (mmArmor > 0) entity.setAttributeBaseValue("generic.armor", mmArmor * mmMultiplier);

        // Damage
        let mmDamage = entity.getAttributeBaseValue("generic.attack_damage");
        if (mmDamage > 0) entity.setAttributeBaseValue("generic.attack_damage", mmDamage * mmMultiplier);
    }

    // Mowzie's Mobs Bosses (x2.5)
    // Common IDs: ferrous_wroughtnaut, frostmaw, barako, naga
    const mowzieBosses = [
        "mowziesmobs:ferrous_wroughtnaut",
        "mowziesmobs:frostmaw",
        "mowziesmobs:naga",
        "mowziesmobs:umvuthi"
    ];

    if (mowzieBosses.includes(entity.type)) {
        let mowzieMultiplier = 2.5;

        // Health
        let mzHealth = entity.getAttributeBaseValue("generic.max_health");
        entity.setAttributeBaseValue("generic.max_health", mzHealth * mowzieMultiplier);
        entity.health = mzHealth * mowzieMultiplier;

        // Armor
        let mzArmor = entity.getAttributeBaseValue("generic.armor");
        if (mzArmor > 0) entity.setAttributeBaseValue("generic.armor", mzArmor * mowzieMultiplier);

        // Damage
        let mzDamage = entity.getAttributeBaseValue("generic.attack_damage");
        if (mzDamage > 0) entity.setAttributeBaseValue("generic.attack_damage", mzDamage * mowzieMultiplier);
    }

    // Knight Quest Bosses (x2.0)
    // Main Boss: Netherman (The One Who Fell)
    // Mini-bosses: Eld Knight, Ratman, etc.
    const knightQuestBosses = [
        "knightquest:netherman",
        "knightquest:eldknight",
        "knightquest:ratman",
        "knightquest:swampman"
    ];

    // Also checking for potential "human" friendly name matches if IDs are obscure, 
    // but KubeJS EntityType check is strict. We stick to likely IDs.

    if (knightQuestBosses.includes(entity.type)) {
        let kqMultiplier = 2.0;

        // Health
        let kqHealth = entity.getAttributeBaseValue("generic.max_health");
        entity.setAttributeBaseValue("generic.max_health", kqHealth * kqMultiplier);
        entity.health = kqHealth * kqMultiplier;

        // Armor
        let kqArmor = entity.getAttributeBaseValue("generic.armor");
        if (kqArmor > 0) entity.setAttributeBaseValue("generic.armor", kqArmor * kqMultiplier);

        // Damage
        let kqDamage = entity.getAttributeBaseValue("generic.attack_damage");
        if (kqDamage > 0) entity.setAttributeBaseValue("generic.attack_damage", kqDamage * kqMultiplier);
    }
});

console.info("[Arcadia V2] Mob Stats Loaded.");
