include "TriggerLibs/NativeLib"

include "TriggerLibs/HeroesLib"

include "TriggerLibs/GameLib"



include "LibHGAR_h"



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

// Library: Garrosh

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

// External Library Initialization

void libHGAR_InitLibraries () {

    libNtve_InitVariables();

    libCore_InitVariables();

    libGame_InitVariables();

}



// Variable Initialization

bool libHGAR_InitVariables_completed = false;



void libHGAR_InitVariables () {

    if (libHGAR_InitVariables_completed) {

        return;

    }



    libHGAR_InitVariables_completed = true;



}



// Functions

void libHGAR_gf_HeroGarroshIncrementHeroCountFunction () {

    // Automatic Variable Declarations

    // Implementation

    libHGAR_gv_heroGarroshTriggerRegistrationVariable += 1;

    if ((libHGAR_gv_heroGarroshTriggerRegistrationVariable == 1)) {

        TriggerEnable(libHGAR_gt_HeroGarroshWreckingBallCameraLock, true);

        TriggerEnable(libHGAR_gt_HeroGarroshMortalComboProcCleanup, true);

    }



}



void libHGAR_gf_HeroGarroshDecrementHeroCountFunction () {

    // Automatic Variable Declarations

    // Implementation

    libHGAR_gv_heroGarroshTriggerRegistrationVariable -= 1;

    if ((libHGAR_gv_heroGarroshTriggerRegistrationVariable < 0)) {

        libHGAR_gv_heroGarroshTriggerRegistrationVariable = 0;

    }



    if ((libHGAR_gv_heroGarroshTriggerRegistrationVariable == 0)) {

        TriggerEnable(libHGAR_gt_HeroGarroshWreckingBallCameraLock, false);

        TriggerEnable(libHGAR_gt_HeroGarroshMortalComboProcCleanup, false);

    }



}



// Triggers

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

// Trigger: Hero - Garrosh - Mortal Combo Proc Cleanup

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

bool libHGAR_gt_HeroGarroshMortalComboProcCleanup_Func (bool testConds, bool runActions) {

    // Variable Declarations

    unit lv_garrosh;

    int lv_garroshPlayer;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_garrosh = EventPlayerEffectUsedUnit(c_effectUnitCaster);

    lv_garroshPlayer = UnitGetOwner(lv_garrosh);



    // Conditions

    if (testConds) {

        if (!((lv_garroshPlayer >= 1))) {

            return false;

        }



        if (!((lv_garroshPlayer <= libCore_gv_bALMaxPlayers))) {

            return false;

        }



        if (!((PlayerHasTalent(lv_garroshPlayer, "GarroshGroundbreakerMortalCombo") == true))) {

            return false;

        }

    }



    // Actions

    if (!runActions) {

        return true;

    }



    UnitCreateEffectUnit(lv_garrosh, "GarroshGroundbreakerMortalComboTalentCleanupSet", lv_garrosh);

    return true;

}



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

void libHGAR_gt_HeroGarroshMortalComboProcCleanup_Init () {

    libHGAR_gt_HeroGarroshMortalComboProcCleanup = TriggerCreate("libHGAR_gt_HeroGarroshMortalComboProcCleanup_Func");

    TriggerEnable(libHGAR_gt_HeroGarroshMortalComboProcCleanup, false);

    TriggerAddEventPlayerEffectUsed(libHGAR_gt_HeroGarroshMortalComboProcCleanup, c_playerAny, "GarroshGroundbreakerMortalComboCooldown");

    TriggerAddEventPlayerEffectUsed(libHGAR_gt_HeroGarroshMortalComboProcCleanup, c_playerAny, "GarroshGroundbreakerMortalComboWreckingBallCooldown");

}



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

// Trigger: Hero - Garrosh - Wrecking Ball - Camera Lock

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

bool libHGAR_gt_HeroGarroshWreckingBallCameraLock_Func (bool testConds, bool runActions) {

    // Variable Declarations

    unit lv_targetUnit;

    int lv_targetPlayer;

    int lv_itPlayer;

    fixed lv_vertOffset;

    fixed lv_horizOffset;



    // Automatic Variable Declarations

    // Variable Initialization

    lv_targetUnit = EventUnit();

    lv_targetPlayer = UnitGetOwner(EventUnit());



    // Conditions

    if (testConds) {

        if (!(((lv_targetPlayer >= 1) && (lv_targetPlayer <= 10) && (lv_targetUnit == libGame_gv_players[lv_targetPlayer].lv_heroUnit) && (UnitIsAlive(lv_targetUnit) == true)))) {

            return false;

        }

    }



    // Actions

    if (!runActions) {

        return true;

    }



    libGame_gf_PlayerHeroDisplacementCameraLock(lv_targetUnit, EventUnitBehavior());

    return true;

}



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

void libHGAR_gt_HeroGarroshWreckingBallCameraLock_Init () {

    libHGAR_gt_HeroGarroshWreckingBallCameraLock = TriggerCreate("libHGAR_gt_HeroGarroshWreckingBallCameraLock_Func");

    TriggerEnable(libHGAR_gt_HeroGarroshWreckingBallCameraLock, false);

    TriggerAddEventUnitBehaviorChange(libHGAR_gt_HeroGarroshWreckingBallCameraLock, null, "GarroshWreckingBallUnstoppable", c_unitBehaviorChangeActivate);

    TriggerAddEventUnitBehaviorChange(libHGAR_gt_HeroGarroshWreckingBallCameraLock, null, "GarroshWreckingBallEnemyDisplacement", c_unitBehaviorChangeActivate);

}



void libHGAR_InitTriggers () {

    libHGAR_gt_HeroGarroshMortalComboProcCleanup_Init();

    libHGAR_gt_HeroGarroshWreckingBallCameraLock_Init();

}



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

// Library Initialization

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

bool libHGAR_InitLib_completed = false;



void libHGAR_InitLib () {

    if (libHGAR_InitLib_completed) {

        return;

    }



    libHGAR_InitLib_completed = true;



    libHGAR_InitLibraries();

    libHGAR_InitVariables();

    libHGAR_InitTriggers();

}