Advertisement
DeleteMetaInf

X2DownloadableContentInfo_TacticalReloadNew2.uc

Apr 15th, 2023
1,780
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //---------------------------------------------------------------------------------------
  2. //  FILE:   XComDownloadableContentInfo_TacticalReloadNew2.uc                                    
  3. //          
  4. //  Use the X2DownloadableContentInfo class to specify unique mod behavior when the
  5. //  player creates a new campaign or loads a saved game.
  6. //  
  7. //---------------------------------------------------------------------------------------
  8. //  Copyright (c) 2016 Firaxis Games, Inc. All rights reserved.
  9. //---------------------------------------------------------------------------------------
  10.  
  11. class X2DownloadableContentInfo_TacticalReloadNew2 extends X2DownloadableContentInfo config(TacticalReloadNew2);
  12.  
  13. // Config variables
  14. var config bool SWAP_DEMOLITION;
  15. var config bool CROSS_${1}< ${3} >
  16.  
  17. /// This method is run if the player loads a saved game inside the stragy layer
  18. static event OnLoadedSavedGameToStrategy()
  19. {
  20.     `LOG("OnLoadedSavedGame is activated", true, 'TacticalReloadNew2');
  21.     if(default.SWAP_DEMOLITION == true)
  22.     {
  23.         `LOG("SWAP_DEMOLITION is being called in OnLoadedSavedGame", true, 'TacticalReloadNew2');
  24.         SwapDemolition();
  25.     }
  26. }
  27.  
  28. /// Called when the player starts a new campaign while this mod is installed
  29. static event InstallNewCampaign(XComGameState StartState)
  30. {
  31.     if(default.SWAP_DEMOLITION == true)
  32.     {
  33.         PatchSoldierClassTemplates();
  34.         `LOG("PatchSoldierCclassTemplates has been run!", true, 'TacticalReloadNew2');
  35.     }
  36. }
  37.  
  38. /// Run after all the templates have been created
  39. static event OnPostTemplatesCreated()
  40. {
  41.     `LOG("All templates have been created.", true, 'TacticalReloadNew2');
  42.     if(default.SWAP_DEMOLITION == true)
  43.     {
  44.         PatchSoldierClassTemplates();
  45.         `LOG("PatchSoldierCclassTemplates has been run!", true, 'TacticalReloadNew2');
  46.     }
  47. }
  48.  
  49. /// Function to patch the SoldierClassTemplates (from the base game's X2SoldierClassTemplateManager(.uc) class) and replace Demolition with TacticalReload
  50. static function PatchSoldierClassTemplates()
  51. {      
  52.     local X2SoldierClassTemplateManager Manager;
  53.     local X2SoldierClassTemplate        SoldierClassTemplate;
  54.     local int i;
  55.  
  56.     Manager = class'X2SoldierClassTemplateManager'.static.GetSoldierClassTemplateManager();
  57.  
  58.     SoldierClassTemplate = Manager.FindSoldierClassTemplate('Grenadier');
  59.     //  Requires unprotecting X2SoldierClassTemplate -> SoldierRanks class
  60.     // Loop through the AbilitySlots of the Sergeant rank in reverse order
  61.     if (SoldierClassTemplate != none && SoldierClassTemplate.SoldierRanks.Length > 0)
  62.     {
  63.         // Check if the current AbilitySlot has the Demolition ability
  64.         for (i = SoldierClassTemplate.SoldierRanks[2].AbilitySlots.Length - 1; i >= 0; i--)
  65.         {
  66.             // Replace the Demolition ability with TacticalReload and end the loop
  67.             if (SoldierClassTemplate.SoldierRanks[2].AbilitySlots[i].AbilityType.AbilityName == 'Demolition')
  68.             {
  69.                 SoldierClassTemplate.SoldierRanks[2].AbilitySlots[i].AbilityType.AbilityName = 'TacticalReload';
  70.                 break;
  71.             }
  72.         }
  73.     }      
  74. }    
  75.  
  76. // Set values to ones defined in the config (config values are defined in X2Effect_TacticalReloadDamage.uc)
  77. /*
  78. static function bool AbilityTagExpandHandler(string InString, out string OutString)
  79. {
  80.     local name TagText;
  81.    
  82.     TagText = name(InString);
  83.     switch (TagText)
  84.     {
  85.     // Bonus damage
  86.     case 'BONUSDMGCV':
  87.         OutString = string(class'X2Effect_TacticalReloadNew2'.default.TR_BONUS_DAMAGE_CV);
  88.         return true;
  89.     case 'BONUSDMGMG':
  90.         OutString = string(class'X2Effect_TacticalReloadNew2'.default.TR_BONUS_DAMAGE_MG);
  91.         return true;
  92.     case 'BONUSDMGBM':
  93.         OutString = string(class'X2Effect_TacticalReloadNew2'.default.TR_BONUS_DAMAGE_BM);
  94.         return true;
  95.     // Bonus aim
  96.     case 'BONUSAIMCV':
  97.         OutString = string(class'X2Effect_TacticalReloadNew2'.default.TR_BONUS_AIM_CV);
  98.         return true;
  99.     case 'BONUSAIMMG':
  100.         OutString = string(class'X2Effect_TacticalReloadNew2'.default.TR_BONUS_AIM_MG);
  101.         return true;
  102.     case 'BONUSAIMBM':
  103.         OutString = string(class'X2Effect_TacticalReloadNew2'.default.TR_BONUS_AIM_BM);
  104.         return true;
  105.     // Bonus crit chance
  106.     case 'BONUSCRITCV':
  107.         OutString = string(class'X2Effect_TacticalReloadNew2'.default.TR_BONUS_CRIT_CV);
  108.         return true;
  109.     case 'BONUSCRITMG':
  110.         OutString = string(class'X2Effect_TacticalReloadNew2'.default.TR_BONUS_CRIT_MG);
  111.         return true;
  112.     case 'BONUSCRITBM':
  113.         OutString = string(class'X2Effect_TacticalReloadNew2'.default.TR_BONUS_CRIT_BM);
  114.         return true;
  115. //End  
  116.     default:
  117.         return false;
  118.     }
  119. }*/
  120.  
  121. // Function to swap Demolition with TacticalReload
  122. static function SwapDemolition()
  123. {    
  124.     local XComGameStateHistory                History;
  125.     local XComGameState_Unit                  UnitState;
  126.     local XComGameState_HeadquartersXCom      XComHQ;
  127.     local StateObjectReference                UnitRef;
  128.     local XComGameState                       NewGameState;
  129.  
  130.     History = `XCOMHISTORY;
  131.     XComHQ = `XCOMHQ;
  132.  
  133.     `LOG("SwapDemolition() function is called", true, 'TacticalReloadNew2');
  134.  
  135.     NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Adding UnitState");
  136.  
  137.     foreach XComHQ.Crew(UnitRef)
  138.     {
  139.         UnitState = XComGameState_Unit(History.GetGameStateForObjectID(UnitRef.ObjectID));
  140.         if (UnitState != none && UnitState.GetSoldierClassTemplateName() == 'Grenadier')
  141.         {
  142.            if (UnitState.AbilityTree[2].Abilities[0].AbilityName == 'Demolition')
  143.            {
  144.                 `LOG("Demolition found", true, 'TacticalReloadNew2');
  145.                 UnitState = XComGameState_Unit(NewGameState.ModifyStateObject(class'XComGameState_Unit', UnitState.ObjectID));
  146.                 UnitState.AbilityTree[2].Abilities[0].AbilityName = 'TacticalReload';
  147.            }
  148.         }
  149.     }    
  150.  
  151.     foreach XComHQ.DeadCrew(UnitRef)
  152.     {
  153.         UnitState = XComGameState_Unit(History.GetGameStateForObjectID(UnitRef.ObjectID));
  154.         if (UnitState != none && UnitState.GetSoldierClassTemplateName() == 'Grenadier')
  155.         {
  156.            if (UnitState.AbilityTree[2].Abilities[0].AbilityName == 'TacticalReload')
  157.            {
  158.                 `LOG("Demolition found", true, 'TacticalReloadNew2');
  159.                 UnitState = XComGameState_Unit(NewGameState.ModifyStateObject(class'XComGameState_Unit', UnitState.ObjectID));
  160.                 UnitState.AbilityTree[2].Abilities[0].AbilityName = 'TacticalReloadr';
  161.            }
  162.         }
  163.     }
  164.  
  165.     if(NewGameState != none)
  166.     {
  167.         `LOG("NewGameState is being submitted", true, 'TacticalReloadNew2');
  168.         History.AddGameStateToHistory(NewGameState);
  169.     }
  170. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement