Advertisement
Guest User

Untitled

a guest
Jul 25th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static function bool CanAddItemToInventory_CH_Improved(
  2.     out int bCanAddItem,                   // out value for XComGameState_Unit
  3.     const EInventorySlot Slot,             // Inventory Slot you're trying to equip the Item into
  4.     const X2ItemTemplate ItemTemplate,     // Item Template of the Item you're trying to equip
  5.     int Quantity,
  6.     XComGameState_Unit UnitState,          // Unit State of the Unit you're trying to equip the Item on
  7.     optional XComGameState CheckGameState,
  8.     optional out string DisabledReason,    // out value for the UIArmory_Loadout
  9.     optional XComGameState_Item ItemState) // Item State of the Item we're trying to equip
  10. {
  11.     local X2ArmorTemplate               ArmorTemplate;
  12.     local XGParamTag                    LocTag;
  13.     local name                          ClassName;
  14.     local X2SoldierClassTemplateManager          Manager;
  15.  
  16.     local bool OverrideNormalBehavior;
  17.     local bool DoNotOverrideNormalBehavior;
  18.  
  19.     // Prepare return values to make it easier for us to read the code.
  20.     OverrideNormalBehavior = CheckGameState != none;
  21.     DoNotOverrideNormalBehavior = CheckGameState == none;
  22.  
  23.     // If there already is a Disabled Reason, it means another mod has already disallowed equipping this item.
  24.     // In this case, we do not interfere with that mod's functions for better compatibility.
  25.     if(DisabledReason != "")
  26.         return DoNotOverrideNormalBehavior;
  27.  
  28.     // Try to cast the Item Template to Armor Template. This will let us check whether the player is trying to equip armor or something else.
  29.     ArmorTemplate = X2ArmorTemplate(ItemTemplate);
  30.  
  31.     //  The function will proceed past this point only if the player is trying to equip armor.
  32.     if(ArmorTemplate != none)
  33.     {
  34.         //  Grab the soldier class template manager. We will use it later.
  35.         Manager = class'X2SoldierClassTemplateManager'.static.GetSoldierClassTemplateManager();
  36.  
  37.         //  Check if this soldier's class is allowed to equip this armor.
  38.         //  If this soldier class cannot equip this armor anyway (like Spark Armor), then we do not interfere with the game.
  39.         if (!Manager.FindSoldierClassTemplate(UnitState.GetSoldierClassTemplateName()).IsArmorAllowedByClass(ArmorTemplate))
  40.             return DoNotOverrideNormalBehavior;    
  41.  
  42.         //  If we got this far, it means the player is trying to equip armor on a soldier, and that soldier's class is normally allowed to equip it.
  43.         //  Let's take a look at the armor's category.
  44.         switch (ArmorTemplate.ArmorCat)
  45.         {
  46.             //  If this is Spartan Mjolnir armor
  47.             case 'MJOLNIR':
  48.                 //  And the soldier has the required perk to unlock this armor (Spartan Training Program), then we simply don't interfere with the game.
  49.                 //  remember, this armor is already allowed for this soldier class, so we don't need to do anything else.
  50.                 if (UnitState.HasSoldierAbility('SpartanIIProgram')) return DoNotOverrideNormalBehavior;
  51.                 else ClassName = 'SPARTAN-II_SS'; // if the soldier is normally allowed to use this armor, but doesn't have the necessary perk
  52.                 //  then we write down the name of the Super Soldier class that SHOULD be able to equip this armor
  53.                 //  this is basically the best way we can communicate to the player that their soldier is missing the required abiltiy - Spartan Training.
  54.                 break;
  55.             case 'NANOSUIT':    //  go through the same logic for other Super Soldier armor classes.
  56.                 if (UnitState.HasSoldierAbility('NanosuitRaptorTraining')) return DoNotOverrideNormalBehavior;
  57.                 else ClassName = 'Nanosuit_SS';
  58.                 break;
  59.             case 'GHOSTSUIT':
  60.                 if (UnitState.HasSoldierAbility('GhostProgram')) return DoNotOverrideNormalBehavior;
  61.                 else ClassName = 'Ghost_SS';
  62.                 break;
  63.             case 'NINJASUIT':
  64.                 if (UnitState.HasSoldierAbility('NinjaTheWayOfTheNinja')) return DoNotOverrideNormalBehavior;
  65.                 else ClassName = 'Ninja_SS';
  66.                 break;
  67.             case 'CYBORG':
  68.                 if (UnitState.HasSoldierAbility('CyborgCyberneticConversion')) return DoNotOverrideNormalBehavior;
  69.                 else ClassName = 'Cyborg_SS';
  70.                 break;
  71.             default:
  72.                 // if we got this far, it means the soldier is trying to equip an armor that doesn't belong to one of the Super Soldier classes,
  73.                 // so we don't need to do anything.
  74.                 return DoNotOverrideNormalBehavior;
  75.                 break;
  76.         }
  77.  
  78.         //  if we got this far, it means the soldier is trying to equip one of the Super Soldier armors,
  79.         //  but the soldier doesn't have the required ability.
  80.         //  so we build a message that will be shown in the Armory UI. This message will be displayed in big red letters,
  81.         //  letting the player know that this armor is available
  82.         //  only to a particular super soldier class.
  83.  
  84.         LocTag = XGParamTag(`XEXPANDCONTEXT.FindTag("XGParam"));
  85.  
  86.         //  use the Soldier Class Template Manager to find the Template for this soldier's class, and get its localized name (e.g. "Ninja")
  87.         LocTag.StrValue0 = Manager.FindSoldierClassTemplate(ClassName).DisplayName;
  88.  
  89.         //  build the message letting the player know only that Super Soldier class is able to equip this armor (e.g. "NINJA ONLY")
  90.         //  set that message to the out value for UI Armory
  91.         DisabledReason = class'UIUtilities_Text'.static.CapsCheckForGermanScharfesS(`XEXPAND.ExpandString(class'UIArmory_Loadout'.default.m_strNeedsSoldierClass));
  92.  
  93.         //  set the out value for XComGameState_Unit, letting the game know that this armor CANNOT be equipped on this soldier
  94.         bCanAddItem = 0;
  95.  
  96.         //  return the override value. This will force the game to actually use our out values we have just set.
  97.         return OverrideNormalBehavior;
  98.  
  99.     }
  100.  
  101.     return DoNotOverrideNormalBehavior; //the item is not Armor, so we don't interfere with the game.
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement