Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 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)
  2. {
  3.     local X2WeaponTemplate                      WeaponTemplate;
  4.     local ABILITY_WEAPON_UNLOCK                 AbilityUnlock;
  5.  
  6.     `log("(CH_Improved) ABILITY_WEAPON_UNLOCKS.Length =" @ default.ABILITY_WEAPON_UNLOCKS.Length);
  7.     WeaponTemplate = X2WeaponTemplate(ItemState.GetMyTemplate());
  8.     if(CheckGameState == none)
  9.     {
  10.         // If DisabledReason is not blank, then this template has already been disabled by another mod, ignore.
  11.         if (DisabledReason != "")
  12.             return true;
  13.  
  14.         // If the template is normally allowed for this class, ignore
  15.         if (UnitState.GetSoldierClassTemplate().IsWeaponAllowedByClass(WeaponTemplate))
  16.             return true;
  17.  
  18.         foreach default.ABILITY_WEAPON_UNLOCKS(AbilityUnlock)
  19.         {
  20.             if (UnitState.HasSoldierAbility(AbilityUnlock.ABILITY_NAME))
  21.             {
  22.                 if (WeaponTemplate.WeaponCat == AbilityUnlock.WEAPON_CATEGORY)
  23.                 {
  24.                     // Unit has an ability enabling this weapon template, allow
  25.                     DisabledReason = "";
  26.                     return false;
  27.         }   }   }
  28.         return true;
  29.     }
  30.     return CanAddItemToInventory(bCanAddItem, Slot, ItemTemplate, Quantity, UnitState, CheckGameState);
  31. }
  32.  
  33. static private function bool CanAddItemToInventory(out int bCanAddItem, const EInventorySlot Slot, const X2ItemTemplate ItemTemplate, int Quantity, XComGameState_Unit UnitState, XComGameState CheckGameState)
  34. {
  35.     local X2WeaponTemplate                      WeaponTemplate;
  36.     local ABILITY_WEAPON_UNLOCK                 AbilityUnlock;
  37.  
  38.     `log("ABILITY_WEAPON_UNLOCKS.Length =" @ default.ABILITY_WEAPON_UNLOCKS.Length);
  39.     bCanAddItem = 0;
  40.     WeaponTemplate = X2WeaponTemplate(ItemTemplate);
  41.    
  42.     // If the template is normally allowed for this class, ignore
  43.     if (UnitState.GetSoldierClassTemplate().IsWeaponAllowedByClass(WeaponTemplate))
  44.         return false;
  45.  
  46.     foreach default.ABILITY_WEAPON_UNLOCKS(AbilityUnlock)
  47.     {
  48.         if (UnitState.HasSoldierAbility(AbilityUnlock.ABILITY_NAME))
  49.         {
  50.             if (WeaponTemplate.WeaponCat == AbilityUnlock.WEAPON_CATEGORY)
  51.             {
  52.                 // Unit has an ability enabling this weapon template, allow
  53.                 bCanAddItem = 1;
  54.                 break;
  55.     }   }   }
  56.     return bCanAddItem > 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement