WOTCStrategyOverhaul / CovertInfiltration

A mod that overhauls the Covert Actions system to bring back the Infiltration mechanic from Long War 2
MIT License
21 stars 8 forks source link

Infiltration modifiers config array cannot be reliably edited by other mods #673

Closed cannonfodder1 closed 3 years ago

cannonfodder1 commented 3 years ago

As a solution, shiremct has suggested making a new, empty infil modifiers array that runs in OPTC, after the usual array has created the templates.

shiremct commented 3 years ago

Took a crack at the function setup in X2Helper_Infiltration_TemplateMod.uc. Could be called right before PatchItemStats in OPTC:

...
var config(Infiltration) array<InfiltrationModifier> OPTC_InfilModifiers;
...

static function PatchInfiltrationTemplates()
{
    local X2InfiltrationModTemplateManager InfilTemplateManager;
    local X2InfiltrationModTemplate        InfilTemplate;
    local X2ItemTemplateManager            ItemTemplateManager;
    local X2ItemTemplate                   ItemTemplate;
    local X2CharacterTemplateManager       CharacterTemplateManager;
    local X2CharacterTemplate              CharacterTemplate;
    local X2AbilityTemplateManager         AbilityTemplateManager;
    local X2AbilityTemplate                AbilityTemplate;
    local InfiltrationModifier             OPTCInfilModifier;

    if (default.OPTC_InfilModifiers.Length < 1)
    {
        // No OPTC Modifiers to process, return
        return;
    }

    InfilTemplateManager = class'X2InfiltrationModTemplateManager'.static.GetInfilTemplateManager();
    ItemTemplateManager = class'X2ItemTemplateManager'.static.GetItemTemplateManager();
    AbilityTemplateManager = class'X2AbilityTemplateManager'.static.GetAbilityTemplateManager();
    CharacterTemplateManager = class'X2CharacterTemplateManager'.static.GetCharacterTemplateManager();

    foreach default.OPTC_InfilModifiers (OPTCInfilModifier)
    {
        // Add DLC check here once it has been updated? //
        // ******************************************** //

        switch (OPTCInfilModifier.ModifyType)
        {
            case eIMT_Ability:
                AbilityTemplate = AbilityTemplateManager.FindAbilityTemplate(OPTCInfilModifier.DataName);
                if (AbilityTemplate != none)
                {
                    InfilTemplate = InfilTemplateManager.GetInfilTemplateFromAbility(AbilityTemplate)
                    if (InfilTemplate != none)
                    {
                        InfilTemplate.HoursAdded = OPTCInfilModifier.InfilHoursAdded;
                        InfilTemplate.Deterrence = OPTCInfilModifier.RiskReductionPercent;
                    }
                }
                break;
            case eIMT_Character:
                CharacterTemplate = CharacterTemplateManager.FindCharacterTemplate(OPTCInfilModifier.DataName);
                if (CharacterTemplate != none)
                (
                    InfilTemplate = InfilTemplateManager.GetInfilTemplateFromCharacter(CharacterTemplate)
                    if (InfilTemplate != none)
                    {
                        InfilTemplate.HoursAdded = OPTCInfilModifier.InfilHoursAdded;
                        InfilTemplate.Deterrence = OPTCInfilModifier.RiskReductionPercent;
                    }
                }
                break;
            case eIMT_Item:
                ItemTemplate = ItemTemplateManager.FindItemTemplate(OPTCInfilModifier.DataName);
                if (ItemTemplate != none)
                    (
                    InfilTemplate = InfilTemplateManager.GetInfilTemplateFromItem(ItemTemplate)
                    if (InfilTemplate != none)
                    {
                        InfilTemplate.HoursAdded = OPTCInfilModifier.InfilHoursAdded;
                        InfilTemplate.Deterrence = OPTCInfilModifier.RiskReductionPercent;
                    }
                }
                break;              
            case eIMT_Category:
                ItemTemplate = ItemTemplateManager.FindItemTemplate(OPTCInfilModifier.DataName);
                if (ItemTemplate != none)
                    (
                    InfilTemplate = InfilTemplateManager.GetInfilTemplateFromCategory(ItemTemplate)
                    if (InfilTemplate != none)
                    {
                        InfilTemplate.HoursAdded = OPTCInfilModifier.InfilHoursAdded;
                        InfilTemplate.Deterrence = OPTCInfilModifier.RiskReductionPercent;
                    }
                }
                break;          
            default:
                break;
        }
    }
}

May not be perfect (not easy for me to test), but wanted to try providing a starting point.