mods/heromods/amazon.stormmod/base.stormdata/libhama.galaxy

libhama.galaxy
include "TriggerLibs/NativeLib"
include "TriggerLibs/HeroesLib"
include "TriggerLibs/GameLib"

include "LibHAMA_h"

//--------------------------------------------------------------------------------------------------
// Library: Amazon
//--------------------------------------------------------------------------------------------------
// External Library Initialization
void libHAMA_InitLibraries () {
    libNtve_InitVariables();
    libCore_InitVariables();
    libGame_InitVariables();
}

// Variable Initialization
bool libHAMA_InitVariables_completed = false;

void libHAMA_InitVariables () {
    if (libHAMA_InitVariables_completed) {
        return;
    }

    libHAMA_InitVariables_completed = true;

}

// Functions
void libHAMA_gf_HeroAmazonIncrementHeroCountFunction () {
    // Automatic Variable Declarations
    // Implementation
    libHAMA_gv_heroAmazonTriggerRegistrationVariable += 1;
    if ((libHAMA_gv_heroAmazonTriggerRegistrationVariable == 1)) {
        TriggerEnable(libHAMA_gt_HeroAmazonSurgeofLightDamageTaken, true);
        TriggerEnable(libHAMA_gt_HeroAmazonSurgeofLightResetCharge, true);
        TriggerEnable(libHAMA_gt_HeroAmazonTalentResetClearSurgeofLight, true);
        TriggerEnable(libHAMA_gt_HeroAmazonWarMatronFloatingText, true);
    }

}

void libHAMA_gf_HeroAmazonDecrementHeroCountFunction () {
    // Automatic Variable Declarations
    // Implementation
    libHAMA_gv_heroAmazonTriggerRegistrationVariable -= 1;
    if ((libHAMA_gv_heroAmazonTriggerRegistrationVariable < 0)) {
        libHAMA_gv_heroAmazonTriggerRegistrationVariable = 0;
    }

    if ((libHAMA_gv_heroAmazonTriggerRegistrationVariable == 0)) {
        TriggerEnable(libHAMA_gt_HeroAmazonSurgeofLightDamageTaken, false);
        TriggerEnable(libHAMA_gt_HeroAmazonSurgeofLightResetCharge, false);
        TriggerEnable(libHAMA_gt_HeroAmazonTalentResetClearSurgeofLight, false);
        TriggerEnable(libHAMA_gt_HeroAmazonWarMatronFloatingText, false);
    }

}

// Triggers
//--------------------------------------------------------------------------------------------------
// Trigger: Hero - Amazon - Surge of Light - Damage Taken
//--------------------------------------------------------------------------------------------------
bool libHAMA_gt_HeroAmazonSurgeofLightDamageTaken_Func (bool testConds, bool runActions) {
    // Variable Declarations
    unit lv_amazonUnit;
    int lv_amazonPlayer;
    string lv_maximumChargeReference;
    fixed lv_maximumCharge;
    fixed lv_damageTaken;
    fixed lv_damageThreshold;

    // Automatic Variable Declarations
    // Variable Initialization
    lv_amazonUnit = EventUnit();
    lv_amazonPlayer = EventPlayer();
    lv_maximumChargeReference = "AmazonAvoidanceSurgeOfLightDummyMaximumCharge";
    lv_maximumCharge = CatalogFieldValueGetAsFixed(c_gameCatalogEffect, lv_maximumChargeReference, "Amount", lv_amazonPlayer);
    lv_damageTaken = (EventUnitDamageAmount() + EventUnitDamageBehaviorShield());
    lv_damageThreshold = (lv_maximumCharge / CatalogFieldValueGetAsFixed(c_gameCatalogAbil, "AmazonSurgeOfLight", "Cost.Charge.CountMax", lv_amazonPlayer));

    // Conditions
    if (testConds) {
        if (!((UnitHasBehavior2(lv_amazonUnit, "AmazonAvoidanceDamageReduction") == true))) {
            return false;
        }

        if (!((PlayerHasTalent(lv_amazonPlayer, "AmazonSurgeOfLight") == true))) {
            return false;
        }

        if (!((PlayerGetChargeUsed(lv_amazonPlayer, "Abil/AmazonSurgeOfLight") > 0.0))) {
            return false;
        }
    }

    // Actions
    if (!runActions) {
        return true;
    }

    lv_damageTaken = (lv_damageTaken + libHAMA_gv_amazonSurgeOfLightChargeProgress[lv_amazonPlayer]);
    while ((lv_damageTaken > lv_damageThreshold) && (PlayerGetChargeUsed(lv_amazonPlayer, "Abil/AmazonSurgeOfLight") > 0.0)) {
        PlayerAddChargeUsed(lv_amazonPlayer, "Abil/AmazonSurgeOfLight", -1.0);
        lv_damageTaken = (lv_damageTaken - lv_damageThreshold);
    }
    libHAMA_gv_amazonSurgeOfLightChargeProgress[lv_amazonPlayer] = lv_damageTaken;
    if ((PlayerGetChargeUsed(lv_amazonPlayer, "Abil/AmazonSurgeOfLight") == 0.0)) {
        UnitBehaviorAdd(lv_amazonUnit, "AmazonAvoidanceSurgeOfLightAbilityReady", lv_amazonUnit, 1);
        libHAMA_gv_amazonSurgeOfLightChargeProgress[lv_amazonPlayer] = 0.0;
    }

    return true;
}

//--------------------------------------------------------------------------------------------------
void libHAMA_gt_HeroAmazonSurgeofLightDamageTaken_Init () {
    libHAMA_gt_HeroAmazonSurgeofLightDamageTaken = TriggerCreate("libHAMA_gt_HeroAmazonSurgeofLightDamageTaken_Func");
    TriggerEnable(libHAMA_gt_HeroAmazonSurgeofLightDamageTaken, false);
    TriggerAddEventUnitDamaged(libHAMA_gt_HeroAmazonSurgeofLightDamageTaken, null, c_unitDamageTypeAny, c_unitDamageEither, null);
}

//--------------------------------------------------------------------------------------------------
// Trigger: Hero - Amazon - Surge of Light - Reset Charge
//--------------------------------------------------------------------------------------------------
bool libHAMA_gt_HeroAmazonSurgeofLightResetCharge_Func (bool testConds, bool runActions) {
    // Variable Declarations
    string lv_currentChargeReference;

    // Automatic Variable Declarations
    // Variable Initialization
    lv_currentChargeReference = "AmazonAvoidanceSurgeOfLightDummyCurrentCharge";

    // Actions
    if (!runActions) {
        return true;
    }

    libHAMA_gv_amazonSurgeOfLightChargeProgress[UnitGetOwner(EventUnit())] = 0.0;
    return true;
}

//--------------------------------------------------------------------------------------------------
void libHAMA_gt_HeroAmazonSurgeofLightResetCharge_Init () {
    libHAMA_gt_HeroAmazonSurgeofLightResetCharge = TriggerCreate("libHAMA_gt_HeroAmazonSurgeofLightResetCharge_Func");
    TriggerEnable(libHAMA_gt_HeroAmazonSurgeofLightResetCharge, false);
    TriggerAddEventUnitBehaviorChange(libHAMA_gt_HeroAmazonSurgeofLightResetCharge, null, "AmazonAvoidanceSurgeOfLightAbilityReady", c_unitBehaviorChangeDestroy);
}

//--------------------------------------------------------------------------------------------------
// Trigger: Hero - Amazon - Surge of Light - Reset Clear
//--------------------------------------------------------------------------------------------------
bool libHAMA_gt_HeroAmazonTalentResetClearSurgeofLight_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;
    }

    libHAMA_gv_amazonSurgeOfLightChargeProgress[lv_player] = 0.0;
    PlayerAddChargeUsed(lv_player, "Abil/AmazonSurgeOfLight", (CatalogFieldValueGetAsFixed(c_gameCatalogAbil, "AmazonSurgeOfLight", "Cost.Charge.CountMax", lv_player) - PlayerGetChargeUsed(lv_player, "Abil/AmazonSurgeOfLight")));
    return true;
}

//--------------------------------------------------------------------------------------------------
void libHAMA_gt_HeroAmazonTalentResetClearSurgeofLight_Init () {
    libHAMA_gt_HeroAmazonTalentResetClearSurgeofLight = TriggerCreate("libHAMA_gt_HeroAmazonTalentResetClearSurgeofLight_Func");
    TriggerEnable(libHAMA_gt_HeroAmazonTalentResetClearSurgeofLight, false);
    libGame_gf_HeroRespecsTalents(libHAMA_gt_HeroAmazonTalentResetClearSurgeofLight);
}

//--------------------------------------------------------------------------------------------------
// Trigger: Hero - Amazon - War Matron Floating Text
//--------------------------------------------------------------------------------------------------
bool libHAMA_gt_HeroAmazonWarMatronFloatingText_Func (bool testConds, bool runActions) {
    // Variable Declarations
    int lv_triggeringUnitOwner;

    // Automatic Variable Declarations
    // Variable Initialization
    lv_triggeringUnitOwner = UnitGetOwner(EventUnit());

    // Conditions
    if (testConds) {
        if (!((lv_triggeringUnitOwner >= 1))) {
            return false;
        }

        if (!((lv_triggeringUnitOwner <= libCore_gv_bALMaxPlayers))) {
            return false;
        }

        if (!(((EventUnitBehaviorCumulativeDamageModification() > 0.0) || (libHAMA_gv_heroAmazonWarMatronDamagePrevented[lv_triggeringUnitOwner] > 0.0)))) {
            return false;
        }
    }

    // Actions
    if (!runActions) {
        return true;
    }

    libHAMA_gv_heroAmazonWarMatronDamagePrevented[lv_triggeringUnitOwner] = (libHAMA_gv_heroAmazonWarMatronDamagePrevented[lv_triggeringUnitOwner] + EventUnitBehaviorCumulativeDamageModification());
    if ((UnitHasBehavior2(EventUnit(), "AmazonFendWarMatronBonusProtectedBehavior") == false)) {
        FloatingCombatElementCreateNumberTextAtUnit(PlayerGroupSingle(lv_triggeringUnitOwner), "FloatingCombatElements/FloatingCombatAmountReadable", "", EventUnit(), FixedToInt(libHAMA_gv_heroAmazonWarMatronDamagePrevented[lv_triggeringUnitOwner]), StringExternal("Param/Value/lib_HVAR_D90A4267"), libNtve_gv_FloatingCombatTextAutoRandomSeed);
        libHAMA_gv_heroAmazonWarMatronDamagePrevented[lv_triggeringUnitOwner] = 0.0;
    }

    return true;
}

//--------------------------------------------------------------------------------------------------
void libHAMA_gt_HeroAmazonWarMatronFloatingText_Init () {
    libHAMA_gt_HeroAmazonWarMatronFloatingText = TriggerCreate("libHAMA_gt_HeroAmazonWarMatronFloatingText_Func");
    TriggerEnable(libHAMA_gt_HeroAmazonWarMatronFloatingText, false);
    TriggerAddEventUnitBehaviorChange(libHAMA_gt_HeroAmazonWarMatronFloatingText, null, "AmazonFendWarMatronChannelProtectedBehavior", c_unitBehaviorChangeRefresh);
    TriggerAddEventUnitBehaviorChange(libHAMA_gt_HeroAmazonWarMatronFloatingText, null, "AmazonFendWarMatronChannelProtectedBehavior", c_unitBehaviorChangeDecrease);
    TriggerAddEventUnitBehaviorChange(libHAMA_gt_HeroAmazonWarMatronFloatingText, null, "AmazonFendWarMatronBonusProtectedBehavior", c_unitBehaviorChangeRefresh);
    TriggerAddEventUnitBehaviorChange(libHAMA_gt_HeroAmazonWarMatronFloatingText, null, "AmazonFendWarMatronBonusProtectedBehavior", c_unitBehaviorChangeDecrease);
}

void libHAMA_InitTriggers () {
    libHAMA_gt_HeroAmazonSurgeofLightDamageTaken_Init();
    libHAMA_gt_HeroAmazonSurgeofLightResetCharge_Init();
    libHAMA_gt_HeroAmazonTalentResetClearSurgeofLight_Init();
    libHAMA_gt_HeroAmazonWarMatronFloatingText_Init();
}

//--------------------------------------------------------------------------------------------------
// Library Initialization
//--------------------------------------------------------------------------------------------------
bool libHAMA_InitLib_completed = false;

void libHAMA_InitLib () {
    if (libHAMA_InitLib_completed) {
        return;
    }

    libHAMA_InitLib_completed = true;

    libHAMA_InitLibraries();
    libHAMA_InitVariables();
    libHAMA_InitTriggers();
}