X2 Mod

 avatar
unknown
csharp
10 months ago
3.6 kB
26
Indexable
/*
   This OPTC is to let "CarryUnit" ability in base game emit an event named "OnCarryUnitActivated"
   to be hooked by our listener later (in "AddCarryUnitDebuffTrigger")

 */
static event OnPostTemplatesCreated()
{
	local X2AbilityTemplateManager AbilityTemplateManager;
	local X2AbilityTemplate AbilityTemplate;

	local array<Name> TemplateNames;
	local Name TemplateName; 

	AbilityTemplateManager	= class'X2AbilityTemplateManager'.static.GetAbilityTemplateManager();
	AbilityTemplateManager.GetTemplateNames(TemplateNames);

    foreach TemplateNames(TemplateName)
    {
        AbilityTemplate = AbilityTemplateManager.FindAbilityTemplate(TemplateName);
        switch (TemplateName)
        {
            case 'CarryUnit':

                AbilityTemplate.PostActivationEvents.Add("OnCarryUnitActivated");   
                break; // found what we want

            default :
                continue; // not yet
        }
    }
}




static function array<X2DataTemplate> CreateTemplates()
{
	local array<X2DataTemplate> Templates;

    Templates.AddItem(AddCarryUnitDebuff());
    Templates.AddItem(AddCarryUnitDebuffTrigger());

    return Templates;
}



/*
    Since the debuff is a passive "ability", I copied & modified the "Lingering Shadow"
    code from LWOTC; i dont know yet why it has to be split into 2 abilities, but ill stick to that pattern

    both the ability "itself", and then the trigger
 */
static function X2AbilityTemplate AddCarryUnitDebuff()
{
	local X2AbilityTemplate Template;

	Template = PurePassive('CarryUnitDebuff', "img:///UILibrary_LWOTC.PerkIcons.UIPerk_LingeringShadow", false);
	Template.AdditionalAbilities.AddItem('CarryUnitDebuffTrigger');

	return Template;
}

/*
    the trigger
    
    this has the listener for the event we added above
 */
static function X2AbilityTemplate AddCarryUnitDebuffTrigger()
{
	local X2AbilityTemplate					Template;
	local X2AbilityTrigger_EventListener	EventListener;
	local X2Effect_PersistentStatChange		DebuffEffect;

	`CREATE_X2ABILITY_TEMPLATE(Template, 'CarryUnitDebuffTrigger');


    //// Just the normal stuff
    Template.IconImage = "img:///UILibrary_LWOTC.PerkIcons.UIPerk_LingeringShadow";
    Template.AbilitySourceName = 'eAbilitySource_Perk';
	Template.eAbilityIconBehaviorHUD = eAbilityIconBehavior_NeverShow;
	Template.Hostility = eHostility_Neutral;
	Template.bDisplayInUITacticalText = false;

	Template.AbilityToHitCalc = default.DeadEye;
	Template.AbilityTargetStyle = default.SelfTarget;
	Template.AbilityShooterConditions.AddItem(default.LivingShooterProperty);


    //// Trigger on CarryUnit ability being activated
	EventListener = new class'X2AbilityTrigger_EventListener';
	EventListener.ListenerData.EventID = 'OnCarryUnitActivated';            /// <-------------------- This is the event the listener is for
	EventListener.ListenerData.EventFn = class'XComGameState_Ability'.static.AbilityTriggerEventListener_Self;
	EventListener.ListenerData.Deferral = ELD_OnStateSubmitted;
	EventListener.ListenerData.Filter = eFilter_Unit;

    Template.AbilityTriggers.AddItem(EventListener);


    /*
        OMITTED:
        
        here goes the code to actually define the debuff effect
     */


	Template.BuildNewGameStateFn = TypicalAbility_BuildGameState;
	Template.BuildVisualizationFn = TypicalAbility_BuildVisualization;
	Template.BuildInterruptGameStateFn = TypicalAbility_BuildInterruptGameState;    


	return Template;
}
Editor is loading...