include "TriggerLibs/NativeLib"

include "TriggerLibs/HeroesLib"

include "TriggerLibs/GameLib"



include "LibHKEL_h"



//--------------------------------------------------------------------------------------------------

// Library: Kel'Thuzad

//--------------------------------------------------------------------------------------------------

// External Library Initialization

void libHKEL_InitLibraries () {

    libNtve_InitVariables();

    libCore_InitVariables();

    libGame_InitVariables();

}



// Variable Initialization

bool libHKEL_InitVariables_completed = false;



void libHKEL_InitVariables () {

    if (libHKEL_InitVariables_completed) {

        return;

    }



    libHKEL_InitVariables_completed = true;



    libHKEL_gv_heroKelThuzadMasteroftheColdDarkMaxTokenName = "";

}



// Functions

void libHKEL_gf_HeroKelThuzadIncrementHeroCountFunction () {

    // Automatic Variable Declarations

    // Implementation

    libHKEL_gv_heroKelThuzadTriggerRegistrationVariable += 1;

    if ((libHKEL_gv_heroKelThuzadTriggerRegistrationVariable == 1)) {

        TriggerEnable(libHKEL_gt_HeroKelThuzadChainsOfIceApplied, true);

        TriggerEnable(libHKEL_gt_HeroKelThuzadChainsPull, true);

        TriggerEnable(libHKEL_gt_HeroKelThuzadKelThuzadsPhylacteryAbilityCast, true);

        TriggerEnable(libHKEL_gt_HeroKelThuzadShiftingMaliceTakedownReduction, true);

        TriggerEnable(libHKEL_gt_HeroKelThuzadRegisterShade, true);

        TriggerEnable(libHKEL_gt_HeroKelThuzadShadeCastDeathandDecay, true);

        TriggerEnable(libHKEL_gt_HeroKelThuzadDeathchillExplosion, true);

        TriggerEnable(libHKEL_gt_KelThuzadRespec, true);

        TriggerEnable(libHKEL_gt_KelThuzadPicksLevel1TalentAfterMaxBlight, true);

        libHKEL_gv_heroKelThuzadMasteroftheColdDarkMaxTokenCount = CatalogReferenceGetAsFixed("Behavior,KelThuzadMasterOfTheColdDarkToken,Max", 0);

        libHKEL_gv_heroKelThuzadMasteroftheColdDarkMaxTokenName = CatalogFieldValueGet(c_gameCatalogBehavior, "KelThuzadMasterOfTheColdDarkToken", "TokenId", c_playerAny);

    }



}



void libHKEL_gf_HeroKelThuzadDecrementHeroCountFunction () {

    // Automatic Variable Declarations

    // Implementation

    libHKEL_gv_heroKelThuzadTriggerRegistrationVariable -= 1;

    if ((libHKEL_gv_heroKelThuzadTriggerRegistrationVariable < 0)) {

        libHKEL_gv_heroKelThuzadTriggerRegistrationVariable = 0;

    }



    if ((libHKEL_gv_heroKelThuzadTriggerRegistrationVariable == 0)) {

        TriggerEnable(libHKEL_gt_HeroKelThuzadChainsOfIceApplied, false);

        TriggerEnable(libHKEL_gt_HeroKelThuzadChainsPull, false);

        TriggerEnable(libHKEL_gt_HeroKelThuzadKelThuzadsPhylacteryAbilityCast, false);

        TriggerEnable(libHKEL_gt_HeroKelThuzadShiftingMaliceTakedownReduction, false);

        TriggerEnable(libHKEL_gt_HeroKelThuzadRegisterShade, false);

        TriggerEnable(libHKEL_gt_HeroKelThuzadShadeCastDeathandDecay, false);

        TriggerEnable(libHKEL_gt_HeroKelThuzadDeathchillExplosion, false);

        TriggerEnable(libHKEL_gt_KelThuzadRespec, false);

        TriggerEnable(libHKEL_gt_KelThuzadPicksLevel1TalentAfterMaxBlight, false);

        libHKEL_gv_heroKelThuzadMasteroftheColdDarkMaxTokenCount = 0.0;

        libHKEL_gv_heroKelThuzadMasteroftheColdDarkMaxTokenName = "";

    }



}



void libHKEL_gf_HeroKelThuzadPullVictims (unit lp_kelThuzad, int lp_kelThuzadPlayer) {

    // Variable Declarations

    point lv_chainHostPosition;

    point lv_chainTargetPosition;

    fixed lv_pullX;

    fixed lv_pullY;

    point lv_finalPullPoint;

    fixed lv_buildingRadius;

    int lv_itVictim;

    unit lv_itValidPullVictimUnit;

    unitgroup lv_validPullUnitGroup;

    unitgroup lv_notValidPullUnitGroup;

    unit lv_singleNotValidPullUnit;



    // Automatic Variable Declarations

    const int auto67F19502_ae = libHKEL_gv_heroKelThuzadChainVictimMaxCount;

    const int auto67F19502_ai = 1;

    unitgroup auto18C80D3F_g;

    int auto18C80D3F_u;

    const int auto15EB0731_ae = libHKEL_gv_heroKelThuzadChainVictimMaxCount;

    const int auto15EB0731_ai = 1;



    // Variable Initialization

    lv_chainHostPosition = UnitGetPosition(libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][libHKEL_gv_heroKelThuzadChainVictimHostIndex]);

    lv_chainTargetPosition = UnitGetPosition(libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][libHKEL_gv_heroKelThuzadChainVictimTargetIndex]);

    lv_pullX = ((PointGetX(lv_chainHostPosition) + PointGetX(lv_chainTargetPosition)) / 2.0);

    lv_pullY = ((PointGetY(lv_chainHostPosition) + PointGetY(lv_chainTargetPosition)) / 2.0);

    lv_finalPullPoint = Point(lv_pullX, lv_pullY);

    lv_validPullUnitGroup = UnitGroupEmpty();

    lv_notValidPullUnitGroup = UnitGroupEmpty();



    // Implementation

    if ((UnitIsAlive(libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][libHKEL_gv_heroKelThuzadChainVictimHostIndex]) == true) && (UnitIsAlive(libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][libHKEL_gv_heroKelThuzadChainVictimTargetIndex]) == true) && (UnitHasBehaviorWithCategoryFlag(libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][libHKEL_gv_heroKelThuzadChainVictimHostIndex], c_behaviorCategorySpecialDeathState) == false) && (UnitHasBehaviorWithCategoryFlag(libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][libHKEL_gv_heroKelThuzadChainVictimTargetIndex], c_behaviorCategorySpecialDeathState) == false) && (DistanceBetweenPoints(lv_chainHostPosition, lv_chainTargetPosition) <= libHKEL_gv_heroKelThuzadChainMaxPullDistance)) {

        lv_itVictim = 1;

        for ( ; ( (auto67F19502_ai >= 0 && lv_itVictim <= auto67F19502_ae) || (auto67F19502_ai < 0 && lv_itVictim >= auto67F19502_ae) ) ; lv_itVictim += auto67F19502_ai ) {

            if ((UnitFilterMatch(libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][lv_itVictim], lp_kelThuzadPlayer, UnitFilter((1 << c_targetFilterHeroic), 0, (1 << c_targetFilterPlayer) | (1 << c_targetFilterAlly) | (1 << c_targetFilterStructure) | (1 << c_targetFilterMissile), (1 << (c_targetFilterStasis - 32)) | (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32)) | (1 << (c_targetFilterUnstoppable - 32)))) == true)) {

                UnitGroupAdd(lv_validPullUnitGroup, libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][lv_itVictim]);

                if ((UnitGetTokenCount(libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit, libHKEL_gv_heroKelThuzadMasteroftheColdDarkMaxTokenName) >= libHKEL_gv_heroKelThuzadMasteroftheColdDarkMaxTokenCount)) {

                    UnitBehaviorAdd(libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][lv_itVictim], "KelThuzadBarbedChainsArmorDecrease", libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit, (PlayerHasTalent(lp_kelThuzadPlayer, "KelThuzadBarbedChains")));

                }



                UnitBehaviorAdd(libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit, "KelThuzadStripShieldsShield", libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit, (PlayerHasTalent(lp_kelThuzadPlayer, "KelThuzadStripShields")));

                UnitBehaviorAdd(libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit, "KelThuzadPowerOfIcecrown", libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit, (PlayerHasTalent(lp_kelThuzadPlayer, "KelThuzadPowerOfIcecrown")));

            }

            else {

                UnitGroupAdd(lv_notValidPullUnitGroup, libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][lv_itVictim]);

            }

        }

        if ((UnitGroupCount(lv_validPullUnitGroup, c_unitCountAlive) == libHKEL_gv_heroKelThuzadChainVictimMaxCount)) {

            UnitCreateEffectPoint(lp_kelThuzad, "KelThuzadChainsRetargetHeroPullImpactDummy", lv_chainTargetPosition);

        }

        else {

            UnitCreateEffectPoint(lp_kelThuzad, "KelThuzadChainsRetargetBuildingPullImpactDummy", lv_chainTargetPosition);

            if ((UnitGroupCount(lv_notValidPullUnitGroup, c_unitCountAlive) == 1)) {

                lv_singleNotValidPullUnit = UnitGroupUnit(lv_notValidPullUnitGroup, 1);

                if (((UnitHasBehavior2(lv_singleNotValidPullUnit, "TownGateBehavior") == true) || (UnitHasBehavior2(lv_singleNotValidPullUnit, "TownWallBehavior") == true))) {

                    lv_finalPullPoint = UnitGetPosition(lv_singleNotValidPullUnit);

                }

                else {

                    lv_buildingRadius = CatalogFieldValueGetAsFixed(c_gameCatalogUnit, UnitGetType(lv_singleNotValidPullUnit), "Radius", lp_kelThuzadPlayer);

                    lv_finalPullPoint = libNtve_gf_PointOffsetTowardsPoint(UnitGetPosition(lv_singleNotValidPullUnit), lv_buildingRadius, UnitGetPosition(UnitGroupUnit(lv_validPullUnitGroup, 1)));

                }

            }



        }

        if ((UnitGroupCount(lv_validPullUnitGroup, c_unitCountAlive) >= 1)) {

            if ((PlayerHasTalent(lp_kelThuzadPlayer, "KelThuzadChainLink") == true)) {

                UnitCreateEffectUnit(libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit, "KelThuzadChainLinkCooldownReduction", libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit);

                UnitCreateEffectUnit(libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit, "KelThuzadChainsOfKelThuzadChainLinkCreateManaHealer", libGame_gv_players[lp_kelThuzadPlayer].lv_heroUnit);

            }



            libNtve_gf_CreateUnitsWithDefaultFacing(1, "KelThuzadChainsPullUnit", c_unitCreateIgnorePlacement, lp_kelThuzadPlayer, lv_finalPullPoint, lp_kelThuzad);

            auto18C80D3F_g = lv_validPullUnitGroup;

            auto18C80D3F_u = UnitGroupCount(auto18C80D3F_g, c_unitCountAll);

            for (;; auto18C80D3F_u -= 1) {

                lv_itValidPullVictimUnit = UnitGroupUnitFromEnd(auto18C80D3F_g, auto18C80D3F_u);

                if (lv_itValidPullVictimUnit == null) { break; }

                UnitBehaviorAdd(lv_itValidPullVictimUnit, "KelThuzadChainsNoPull", lp_kelThuzad, 1);

                UnitIssueOrder(UnitLastCreated(), OrderTargetingUnit(AbilityCommand("KelThuzadChainsPull", 0), lv_itValidPullVictimUnit), c_orderQueueReplace);

            }

        }



    }



    lv_itVictim = 1;

    for ( ; ( (auto15EB0731_ai >= 0 && lv_itVictim <= auto15EB0731_ae) || (auto15EB0731_ai < 0 && lv_itVictim >= auto15EB0731_ae) ) ; lv_itVictim += auto15EB0731_ai ) {

        libHKEL_gv_heroKelThuzadChainsVictims[lp_kelThuzadPlayer][lv_itVictim] = null;

    }

}



// Triggers

//--------------------------------------------------------------------------------------------------

// Trigger: Hero - Kel'Thuzad - Chains Pull

//--------------------------------------------------------------------------------------------------

bool libHKEL_gt_HeroKelThuzadChainsPull_Func (bool testConds, bool runActions) {

    // Variable Declarations

    string lv_chainBehavior;

    unit lv_casterUnit;

    int lv_casterPlayer;

    unit lv_targetUnit;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_chainBehavior = EventUnitBehavior();

    lv_casterUnit = EventUnitBehaviorCasterUnit();

    lv_targetUnit = EventUnit();



    // Conditions

    if (testConds) {

        if (!((UnitHasBehavior2(lv_targetUnit, "KelThuzadChainsNoPull") == false))) {

            return false;

        }



        if (!((UnitIsAlive(lv_targetUnit) == true))) {

            return false;

        }

    }



    // Actions

    if (!runActions) {

        return true;

    }



    lv_casterUnit = UnitBehaviorEffectUnit(lv_targetUnit, "KelThuzadChainsHost", c_effectUnitCaster, 0);

    lv_casterPlayer = UnitGetOwner(UnitBehaviorEffectUnit(lv_targetUnit, lv_chainBehavior, c_effectUnitCaster, 0));

    if ((lv_chainBehavior == "KelThuzadChainsHost")) {

        libHKEL_gv_heroKelThuzadChainsVictims[lv_casterPlayer][libHKEL_gv_heroKelThuzadChainVictimHostIndex] = lv_targetUnit;

    }

    else {

        libHKEL_gv_heroKelThuzadChainsVictims[lv_casterPlayer][libHKEL_gv_heroKelThuzadChainVictimTargetIndex] = lv_targetUnit;

    }

    if ((libHKEL_gv_heroKelThuzadChainsVictims[lv_casterPlayer][libHKEL_gv_heroKelThuzadChainVictimHostIndex] != null) && (libHKEL_gv_heroKelThuzadChainsVictims[lv_casterPlayer][libHKEL_gv_heroKelThuzadChainVictimTargetIndex] != null) && (UnitHasBehavior2(libHKEL_gv_heroKelThuzadChainsVictims[lv_casterPlayer][libHKEL_gv_heroKelThuzadChainVictimHostIndex], "KelThuzadChainsHost") == true) && (UnitHasBehavior2(libHKEL_gv_heroKelThuzadChainsVictims[lv_casterPlayer][libHKEL_gv_heroKelThuzadChainVictimTargetIndex], "KelThuzadChainsTarget") == true) && (UnitIsAlive(libHKEL_gv_heroKelThuzadChainsVictims[lv_casterPlayer][libHKEL_gv_heroKelThuzadChainVictimHostIndex]) == true) && (UnitIsAlive(libHKEL_gv_heroKelThuzadChainsVictims[lv_casterPlayer][libHKEL_gv_heroKelThuzadChainVictimTargetIndex]) == true)) {

        libHKEL_gf_HeroKelThuzadPullVictims(lv_casterUnit, lv_casterPlayer);

    }



    return true;

}



//--------------------------------------------------------------------------------------------------

void libHKEL_gt_HeroKelThuzadChainsPull_Init () {

    libHKEL_gt_HeroKelThuzadChainsPull = TriggerCreate("libHKEL_gt_HeroKelThuzadChainsPull_Func");

    TriggerEnable(libHKEL_gt_HeroKelThuzadChainsPull, false);

    TriggerAddEventUnitBehaviorChange(libHKEL_gt_HeroKelThuzadChainsPull, null, "KelThuzadChainsHost", c_unitBehaviorChangeCreate);

    TriggerAddEventUnitBehaviorChange(libHKEL_gt_HeroKelThuzadChainsPull, null, "KelThuzadChainsTarget", c_unitBehaviorChangeCreate);

}



//--------------------------------------------------------------------------------------------------

// Trigger: Kel'Thuzad Respec

//--------------------------------------------------------------------------------------------------

bool libHKEL_gt_KelThuzadRespec_Func (bool testConds, bool runActions) {

    // Variable Declarations

    int lv_player;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_player = libGame_gf_HeroRespecsTalentsPlayer();



    // Actions

    if (!runActions) {

        return true;

    }



    UnitSetTokenCount(libGame_gv_players[lv_player].lv_heroUnit, "KelThuzadMasterOfTheColdDarkToken", 0.0, libGame_gv_players[lv_player].lv_heroUnit);

    CatalogFieldValueModifyFixed(c_gameCatalogEffect, "KelThuzadDeathAndDecayRotSearch", "AreaArray[" + IntToString(0) + "].Radius", lv_player, CatalogFieldValueGetAsFixed(c_gameCatalogEffect, "KelThuzadDeathAndDecayRotSearch", "AreaArray[" + IntToString(0) + "].Radius", 0), c_upgradeOperationSet);

    CatalogFieldValueModifyFixed(c_gameCatalogEffect, "KelThuzadDeathAndDecayShadeRotSearch", "AreaArray[" + IntToString(0) + "].Radius", lv_player, CatalogFieldValueGetAsFixed(c_gameCatalogEffect, "KelThuzadDeathAndDecayShadeRotSearch", "AreaArray[" + IntToString(0) + "].Radius", 0), c_upgradeOperationSet);

    CatalogFieldValueModifyFixed(c_gameCatalogActor, "KelThuzadDeathAndDecayRotVisual", "Scale", lv_player, CatalogFieldValueGetAsFixed(c_gameCatalogActor, "KelThuzadDeathAndDecayRotVisual", "Scale", 0), c_upgradeOperationSet);

    CatalogFieldValueModifyFixed(c_gameCatalogBehavior, "KelThuzadFrostNovaRoot", "Duration", lv_player, CatalogFieldValueGetAsFixed(c_gameCatalogBehavior, "KelThuzadFrostNovaRoot", "Duration", 0), c_upgradeOperationSet);

    UnitBehaviorRemove(libGame_gv_players[lv_player].lv_heroUnit, "KelThuzadChillingTouchController", 1);

    UnitBehaviorRemove(libGame_gv_players[lv_player].lv_heroUnit, "KelThuzadChillingTouchActive", 1);

    UnitBehaviorRemove(libGame_gv_players[lv_player].lv_heroUnit, "KelThuzadChillingTouchCooldown", 1);

    return true;

}



//--------------------------------------------------------------------------------------------------

void libHKEL_gt_KelThuzadRespec_Init () {

    libHKEL_gt_KelThuzadRespec = TriggerCreate("libHKEL_gt_KelThuzadRespec_Func");

    TriggerEnable(libHKEL_gt_KelThuzadRespec, false);

    libGame_gf_HeroRespecsTalents(libHKEL_gt_KelThuzadRespec);

}



//--------------------------------------------------------------------------------------------------

// Trigger: Kel'Thuzad Picks Level 1 Talent After Max Blight

//--------------------------------------------------------------------------------------------------

bool libHKEL_gt_KelThuzadPicksLevel1TalentAfterMaxBlight_Func (bool testConds, bool runActions) {

    // Variable Declarations

    unit lv_heroUnit;



    // Automatic Variable Declarations

    string autoA4CEE6E7_val;



    // Variable Initialization

    lv_heroUnit = libGame_gv_players[libGame_gf_HeroGainTalentPlayer()].lv_heroUnit;



    // Conditions

    if (testConds) {

        if (!((UnitGetType(lv_heroUnit) == "HeroKelThuzad"))) {

            return false;

        }



        if (!((UnitGetTokenCount(lv_heroUnit, "KelThuzadMasterOfTheColdDarkToken") == 30.0))) {

            return false;

        }

    }



    // Actions

    if (!runActions) {

        return true;

    }



    autoA4CEE6E7_val = libGame_gf_HeroGainTalentGainedTalent();

    if (autoA4CEE6E7_val == "KelThuzadThePlaguelands") {

        UnitCreateEffectUnit(lv_heroUnit, "KelThuzadThePlaguelandsCompleteModifyPlayer", lv_heroUnit);

    }

    else if (autoA4CEE6E7_val == "KelThuzadBlightedFrost") {

        UnitCreateEffectUnit(lv_heroUnit, "KelThuzadBlightedFrostCompleteModifyPlayer", lv_heroUnit);

    }

    else {

    }

    return true;

}



//--------------------------------------------------------------------------------------------------

void libHKEL_gt_KelThuzadPicksLevel1TalentAfterMaxBlight_Init () {

    libHKEL_gt_KelThuzadPicksLevel1TalentAfterMaxBlight = TriggerCreate("libHKEL_gt_KelThuzadPicksLevel1TalentAfterMaxBlight_Func");

    TriggerEnable(libHKEL_gt_KelThuzadPicksLevel1TalentAfterMaxBlight, false);

    libGame_gf_HeroGainTalent(libHKEL_gt_KelThuzadPicksLevel1TalentAfterMaxBlight);

}



//--------------------------------------------------------------------------------------------------

// Trigger: Hero - Kel'Thuzad - Chains Of Ice Applied

//--------------------------------------------------------------------------------------------------

bool libHKEL_gt_HeroKelThuzadChainsOfIceApplied_Func (bool testConds, bool runActions) {

    // Variable Declarations

    int lv_owner;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_owner = UnitGetOwner(EventPlayerEffectUsedUnit(c_effectUnitCaster));



    // Actions

    if (!runActions) {

        return true;

    }



    if (((UnitGetType(libGame_gv_players[lv_owner].lv_heroUnit) == "HeroKelThuzad") && (PlayerHasTalent(lv_owner, "KelThuzadPowerOfIcecrown") == true))) {

        UnitBehaviorAdd(libGame_gv_players[lv_owner].lv_heroUnit, "KelThuzadPowerOfIcecrown", libGame_gv_players[lv_owner].lv_heroUnit, 1);

    }



    return true;

}



//--------------------------------------------------------------------------------------------------

void libHKEL_gt_HeroKelThuzadChainsOfIceApplied_Init () {

    libHKEL_gt_HeroKelThuzadChainsOfIceApplied = TriggerCreate("libHKEL_gt_HeroKelThuzadChainsOfIceApplied_Func");

    TriggerAddEventPlayerEffectUsed(libHKEL_gt_HeroKelThuzadChainsOfIceApplied, c_playerAny, "KelThuzadChainsOfIceApply");

}



//--------------------------------------------------------------------------------------------------

// Trigger: Hero - Kel'Thuzad -Deathchill Explosion

//--------------------------------------------------------------------------------------------------

bool libHKEL_gt_HeroKelThuzadDeathchillExplosion_Func (bool testConds, bool runActions) {

    // Variable Declarations

    int lv_player;

    unit lv_unit;

    unit lv_vehicle;

    point lv_deadUnitPosition;

    unit lv_unit2;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_player = libGame_gf_HeroParticipatedInTakedownKillingPlayer();

    lv_unit = libGame_gv_players[lv_player].lv_heroUnit;

    lv_vehicle = libGame_gv_players[lv_player].lv_activeVehicle;

    lv_unit2 = libGame_gf_HeroParticipatedInTakedownKilledHero();



    // Conditions

    if (testConds) {

        if (!((UnitIsAlive(lv_unit) == true))) {

            return false;

        }



        if (!((PlayerHasTalent(lv_player, "KelThuzadDeathchill") == true))) {

            return false;

        }



        if (!(((UnitGetType(lv_unit) == "HeroKelThuzad") || (UnitGetType(lv_vehicle) == "HeroKelThuzad")))) {

            return false;

        }



        if (!(((UnitHasBehavior2(lv_unit2, "KelThuzadFrozenTombDeathchill") == true)))) {

            return false;

        }

    }



    // Actions

    if (!runActions) {

        return true;

    }



    lv_deadUnitPosition = UnitGetPosition(libGame_gf_HeroParticipatedInTakedownKilledHero());

    UnitCreateEffectPointWithSource(lv_unit, "KelThuzadFrozenTombSearch", lv_deadUnitPosition, c_gameCatalogBehavior, "KelThuzadFrozenTombDeathchill");

    return true;

}



//--------------------------------------------------------------------------------------------------

void libHKEL_gt_HeroKelThuzadDeathchillExplosion_Init () {

    libHKEL_gt_HeroKelThuzadDeathchillExplosion = TriggerCreate("libHKEL_gt_HeroKelThuzadDeathchillExplosion_Func");

    TriggerEnable(libHKEL_gt_HeroKelThuzadDeathchillExplosion, false);

    libGame_gf_HeroParticipatedInTakedown(libHKEL_gt_HeroKelThuzadDeathchillExplosion);

}



//--------------------------------------------------------------------------------------------------

// Trigger: Hero - Kel'Thuzad - Shifting Malice Takedown Reduction

//--------------------------------------------------------------------------------------------------

bool libHKEL_gt_HeroKelThuzadShiftingMaliceTakedownReduction_Func (bool testConds, bool runActions) {

    // Variable Declarations

    int lv_player;

    unit lv_unit;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_player = libGame_gf_HeroParticipatedInTakedownKillingPlayer();

    lv_unit = libGame_gv_players[lv_player].lv_heroUnit;



    // Conditions

    if (testConds) {

        if (!((UnitGetType(lv_unit) == "HeroKelThuzad"))) {

            return false;

        }

    }



    // Actions

    if (!runActions) {

        return true;

    }



    UnitCreateEffectUnit(lv_unit, "KelThuzadShiftingMaliceCooldownRefund", lv_unit);

    return true;

}



//--------------------------------------------------------------------------------------------------

void libHKEL_gt_HeroKelThuzadShiftingMaliceTakedownReduction_Init () {

    libHKEL_gt_HeroKelThuzadShiftingMaliceTakedownReduction = TriggerCreate("libHKEL_gt_HeroKelThuzadShiftingMaliceTakedownReduction_Func");

    TriggerEnable(libHKEL_gt_HeroKelThuzadShiftingMaliceTakedownReduction, false);

    libGame_gf_HeroParticipatedInTakedown(libHKEL_gt_HeroKelThuzadShiftingMaliceTakedownReduction);

}



//--------------------------------------------------------------------------------------------------

// Trigger: Hero - Kel'Thuzad - Kel'Thuzad's Phylactery - Ability Cast

//--------------------------------------------------------------------------------------------------

bool libHKEL_gt_HeroKelThuzadKelThuzadsPhylacteryAbilityCast_Func (bool testConds, bool runActions) {

    // Variable Declarations

    unit lv_unit;

    int lv_player;

    int lv_alliedTeam;

    int lv_enemyTeam;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_unit = EventPlayerEffectUsedUnit(c_effectUnitCaster);

    lv_player = UnitGetOwner(lv_unit);

    lv_alliedTeam = libGame_gf_TeamNumberOfPlayer(lv_player);

    lv_enemyTeam = libGame_gf_EnemyTeam(lv_alliedTeam);



    // Conditions

    if (testConds) {

        if (!((UnitIsAlive(lv_unit) == false))) {

            return false;

        }

    }



    // Actions

    if (!runActions) {

        return true;

    }



    libGame_gv_players[lv_player].lv_suppressReviveVOSound = true;

    UnitSetTokenCount(lv_unit, "KelThuzadPhylacteryQuestToken", 0.0, lv_unit);

    libGame_gf_HeroDeathUpdateRespawnTimer(lv_player, 0.0);

    UIDisplayMessage(libGame_gf_PlayersOnTeamHeroes(lv_alliedTeam, false), c_messageAreaChat, StringExternal("Param/Value/lib_HKEL_24DED21B"));

    UIDisplayMessage(libGame_gf_PlayersOnTeamHeroes(lv_enemyTeam, false), c_messageAreaChat, StringExternal("Param/Value/lib_HKEL_FDF62E23"));

    libGame_gv_players[lv_player].lv_suppressReviveVOSound = false;

    return true;

}



//--------------------------------------------------------------------------------------------------

void libHKEL_gt_HeroKelThuzadKelThuzadsPhylacteryAbilityCast_Init () {

    libHKEL_gt_HeroKelThuzadKelThuzadsPhylacteryAbilityCast = TriggerCreate("libHKEL_gt_HeroKelThuzadKelThuzadsPhylacteryAbilityCast_Func");

    TriggerEnable(libHKEL_gt_HeroKelThuzadKelThuzadsPhylacteryAbilityCast, false);

    TriggerAddEventPlayerEffectUsed(libHKEL_gt_HeroKelThuzadKelThuzadsPhylacteryAbilityCast, c_playerAny, "KelThuzadPhylacteryDummy");

}



//--------------------------------------------------------------------------------------------------

// Trigger: Hero - Kel'Thuzad - Register Shade

//--------------------------------------------------------------------------------------------------

bool libHKEL_gt_HeroKelThuzadRegisterShade_Func (bool testConds, bool runActions) {

    // Variable Declarations

    int lv_kelThuzadPlayer;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_kelThuzadPlayer = UnitGetOwner(EventUnit());



    // Actions

    if (!runActions) {

        return true;

    }



    if ((libHKEL_gv_heroKelThuzadShades[lv_kelThuzadPlayer] != null)) {

        UnitCreateEffectUnit(libHKEL_gv_heroKelThuzadShades[lv_kelThuzadPlayer], "SuicideTimeout", libHKEL_gv_heroKelThuzadShades[lv_kelThuzadPlayer]);

    }



    libHKEL_gv_heroKelThuzadShades[lv_kelThuzadPlayer] = EventUnitCreatedUnit();

    return true;

}



//--------------------------------------------------------------------------------------------------

void libHKEL_gt_HeroKelThuzadRegisterShade_Init () {

    libHKEL_gt_HeroKelThuzadRegisterShade = TriggerCreate("libHKEL_gt_HeroKelThuzadRegisterShade_Func");

    TriggerEnable(libHKEL_gt_HeroKelThuzadRegisterShade, false);

    TriggerAddEventUnitCreated(libHKEL_gt_HeroKelThuzadRegisterShade, null, "KelThuzadSpawnShade", null);

}



//--------------------------------------------------------------------------------------------------

// Trigger: Hero - Kel'Thuzad - Shade Cast Death and Decay

//--------------------------------------------------------------------------------------------------

bool libHKEL_gt_HeroKelThuzadShadeCastDeathandDecay_Func (bool testConds, bool runActions) {

    // Variable Declarations

    int lv_casterPlayer;

    point lv_point;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_casterPlayer = UnitGetOwner(EventUnit());

    lv_point = EventUnitTargetPoint();



    // Conditions

    if (testConds) {

        if (!((UnitGetType(libGame_gv_players[lv_casterPlayer].lv_heroUnit) == "HeroKelThuzad"))) {

            return false;

        }



        if (!((libHKEL_gv_heroKelThuzadShades[lv_casterPlayer] != null))) {

            return false;

        }

    }



    // Actions

    if (!runActions) {

        return true;

    }



    UnitIssueOrder(libHKEL_gv_heroKelThuzadShades[lv_casterPlayer], OrderTargetingPoint(AbilityCommand("KelThuzadDeathAndDecayShade", 0), lv_point), c_orderQueueAddToFront);

    return true;

}



//--------------------------------------------------------------------------------------------------

void libHKEL_gt_HeroKelThuzadShadeCastDeathandDecay_Init () {

    libHKEL_gt_HeroKelThuzadShadeCastDeathandDecay = TriggerCreate("libHKEL_gt_HeroKelThuzadShadeCastDeathandDecay_Func");

    TriggerEnable(libHKEL_gt_HeroKelThuzadShadeCastDeathandDecay, false);

    TriggerAddEventUnitAbility(libHKEL_gt_HeroKelThuzadShadeCastDeathandDecay, null, AbilityCommand("KelThuzadDeathAndDecay", 0), c_abilEffectStageCast, false);

}



void libHKEL_InitTriggers () {

    libHKEL_gt_HeroKelThuzadChainsPull_Init();

    libHKEL_gt_KelThuzadRespec_Init();

    libHKEL_gt_KelThuzadPicksLevel1TalentAfterMaxBlight_Init();

    libHKEL_gt_HeroKelThuzadChainsOfIceApplied_Init();

    libHKEL_gt_HeroKelThuzadDeathchillExplosion_Init();

    libHKEL_gt_HeroKelThuzadShiftingMaliceTakedownReduction_Init();

    libHKEL_gt_HeroKelThuzadKelThuzadsPhylacteryAbilityCast_Init();

    libHKEL_gt_HeroKelThuzadRegisterShade_Init();

    libHKEL_gt_HeroKelThuzadShadeCastDeathandDecay_Init();

}



//--------------------------------------------------------------------------------------------------

// Library Initialization

//--------------------------------------------------------------------------------------------------

bool libHKEL_InitLib_completed = false;



void libHKEL_InitLib () {

    if (libHKEL_InitLib_completed) {

        return;

    }



    libHKEL_InitLib_completed = true;



    libHKEL_InitLibraries();

    libHKEL_InitVariables();

    libHKEL_InitTriggers();

}