PrioritizeRightClickMelee

Tracking Issue: #1138

This feature allows mods to override the logic for selecting the ability that should be used when the player triggers a right-click melee action on a target.

How to use

Implement the following code in your mod's class that extends X2DownloadableContentInfo:

static event OnPostTemplatesCreated()
{
    local CHHelpers CHHelpersObj;

    CHHelpersObj = class'CHHelpers'.static.GetCDO();
    if (CHHelpersObj != none)
    {
        CHHelpersObj.AddPrioritizeRightClickMeleeCallback(PrioritizeRightClickMelee);
    }
}

// To avoid crashes associated with garbage collection failure when transitioning between Tactical and Strategy,
// this function must be bound to the ClassDefaultObject of your class. Having this function in a class that
// `extends X2DownloadableContentInfo` is the easiest way to ensure that.
static private function EHLDelegateReturn PrioritizeRightClickMelee(XComGameState_Unit UnitState, out XComGameState_Ability PrioritizedMeleeAbility, optional XComGameState_BaseObject TargetObject)
{
# Delegate Priority
You can optionally specify callback Priority. The default Priority is 50.
```unrealscript
CHHelpersObj.AddPrioritizeRightClickMeleeCallback(PrioritizeRightClickMelee, 45);

Delegates with higher Priority value are executed first. Delegates with the same Priority are executed in the order they were added to CHHelpers, which would normally be the same as DLCRunOrder. This function will return true if the delegate was successfully registered.

Removing Delegates

If necessary, use this function to remove a delegate.

CHHelpersObj.RemovePrioritizeRightClickMeleeCallback(PrioritizeRightClickMelee);

The function will return true if the Callback was successfully deleted, return false otherwise.

Source code references