RustyDios

CHL_itemrestriction

Jul 26th, 2023
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //---------------------------------------------------------------------------------------
  3. //  Adds item inventory checks for Proxian Whistle Cannon
  4. //  Code adapted from everywhere, because I fucking HATE this function
  5. //---------------------------------------------------------------------------------------
  6.  
  7. static function bool CanAddItemToInventory_CH_Improved(out int bCanAddItem, const EInventorySlot Slot, const X2ItemTemplate ItemTemplate, int Quantity, XComGameState_Unit UnitState, optional XComGameState CheckGameState, optional out string DisabledReason, optional XComGameState_Item ItemState)
  8. {
  9.     local XGParamTag        LocTag;
  10.     local X2WeaponTemplate  WeaponTemplate;
  11.     local name WeaponTemplateName, UnitClassName;
  12.  
  13.     local bool OverrideNormalBehavior, DoNotOverrideNormalBehavior;
  14.  
  15.     // Prepare return values to make it easier for us to read the code. Thanks Iridar!
  16.     OverrideNormalBehavior = CheckGameState != none;
  17.     DoNotOverrideNormalBehavior = CheckGameState == none;
  18.  
  19.     //Get the weapon under investigation
  20.     WeaponTemplate = X2WeaponTemplate(ItemState.GetMyTemplate());
  21.     WeaponTemplateName = WeaponTemplate.DataName;
  22.  
  23.     //Get the class under investigation
  24.     UnitClassName = UnitState.GetSoldierClassTemplateName();
  25.  
  26.     //if DisabledReason is not blank, then it has already been filled in by another mod, no need for us to restrict it too.
  27.     if(DisabledReason != "")
  28.     {
  29.         `LOG("Disabled Reason already exists for [" @WeaponTemplateName @"]: " $ DisabledReason, default.bEnableLogging,'Proxian_HeavyWeaponTraits');
  30.         return DoNotOverrideNormalBehavior;
  31.     }
  32.    
  33.     //class can use this weapon natively, no need for us to enable it
  34.     //if(UnitState.GetSoldierClassTemplate().IsWeaponAllowedByClass(WeaponTemplate))
  35.     //{
  36.     //  `LOG("Unit can already use weapon", default.bEnableLogging,'Proxian_HeavyWeaponTraits');
  37.     //  return DoNotOverrideNormalBehavior;
  38.     //}
  39.  
  40.     DisabledReason = "";
  41.  
  42.     LocTag = XGParamTag(`XEXPANDCONTEXT.FindTag("XGParam"));
  43.     LocTag.StrValue0 = UnitState.GetSoldierClassTemplate().DisplayName;
  44.  
  45.     //stop any class BUT Proxians from using the whistle Cannon
  46.     if (WeaponTemplate != none && WeaponTemplateName == 'Prox_WristRocket_Storm')
  47.     {
  48.         if (UnitClassName != 'Proxian')
  49.         {
  50.             DisabledReason = class'UIUtilities_Text'.static.CapsCheckForGermanScharfesS(`XEXPAND.ExpandString(class'UIArmory_Loadout'.default.m_strUnavailableToClass));
  51.         }
  52.     }
  53.  
  54.     //it is a valid weapon for the heavy slot
  55.     if(WeaponTemplate != none && Slot == eInvSlot_HeavyWeapon )
  56.     {
  57.         //stop Proxians from equiping any other heavy weapons
  58.         if(UnitClassName == 'Proxian')
  59.         {
  60.             if (WeaponTemplateName != 'Prox_WristRocket_Storm')
  61.             {
  62.                 DisabledReason = class'UIUtilities_Text'.static.CapsCheckForGermanScharfesS(`XEXPAND.ExpandString(class'UIArmory_Loadout'.default.m_strUnavailableToClass));
  63.             }
  64.         }
  65.     }
  66.  
  67.     //it is a valid weapon for the utility slot
  68.     if(WeaponTemplate != none && Slot == eInvSlot_Utility )
  69.     {
  70.         //stop Proxians from equiping these problematic items
  71.         if(UnitClassName == 'Proxian')
  72.         {
  73.             if (    WeaponTemplateName == 'SustainingSphere'
  74.                 ||  WeaponTemplateName == 'Skulljack'
  75.                 ||  WeaponTemplateName == 'UtilityItem_AshBlackIceSkulljack'
  76.                 )
  77.             {
  78.                 DisabledReason = class'UIUtilities_Text'.static.CapsCheckForGermanScharfesS(`XEXPAND.ExpandString(class'UIArmory_Loadout'.default.m_strUnavailableToClass));
  79.             }
  80.         }
  81.     }
  82.  
  83.     //now after checking all requirements
  84.     if (DisabledReason != "")
  85.     {
  86.         `LOG("Unit does not have correct class for" @WeaponTemplate.GetItemFriendlyNameNoStats(), default.bEnableLogging,'Proxian_HeavyWeaponTraits');
  87.         bCanAddItem = 0;
  88.         return OverrideNormalBehavior; //return as we have found this weapon has a class requirement that we have not met
  89.     }
  90.  
  91.     return DoNotOverrideNormalBehavior; //return to avoid overwriting disabled reasons if there's nothing we are doing
  92. }
  93.  
Tags: CHL
Add Comment
Please, Sign In to add comment