Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------------------
- // Adds item inventory checks for Proxian Whistle Cannon
- // Code adapted from everywhere, because I fucking HATE this function
- //---------------------------------------------------------------------------------------
- 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)
- {
- local XGParamTag LocTag;
- local X2WeaponTemplate WeaponTemplate;
- local name WeaponTemplateName, UnitClassName;
- local bool OverrideNormalBehavior, DoNotOverrideNormalBehavior;
- // Prepare return values to make it easier for us to read the code. Thanks Iridar!
- OverrideNormalBehavior = CheckGameState != none;
- DoNotOverrideNormalBehavior = CheckGameState == none;
- //Get the weapon under investigation
- WeaponTemplate = X2WeaponTemplate(ItemState.GetMyTemplate());
- WeaponTemplateName = WeaponTemplate.DataName;
- //Get the class under investigation
- UnitClassName = UnitState.GetSoldierClassTemplateName();
- //if DisabledReason is not blank, then it has already been filled in by another mod, no need for us to restrict it too.
- if(DisabledReason != "")
- {
- `LOG("Disabled Reason already exists for [" @WeaponTemplateName @"]: " $ DisabledReason, default.bEnableLogging,'Proxian_HeavyWeaponTraits');
- return DoNotOverrideNormalBehavior;
- }
- //class can use this weapon natively, no need for us to enable it
- //if(UnitState.GetSoldierClassTemplate().IsWeaponAllowedByClass(WeaponTemplate))
- //{
- // `LOG("Unit can already use weapon", default.bEnableLogging,'Proxian_HeavyWeaponTraits');
- // return DoNotOverrideNormalBehavior;
- //}
- DisabledReason = "";
- LocTag = XGParamTag(`XEXPANDCONTEXT.FindTag("XGParam"));
- LocTag.StrValue0 = UnitState.GetSoldierClassTemplate().DisplayName;
- //stop any class BUT Proxians from using the whistle Cannon
- if (WeaponTemplate != none && WeaponTemplateName == 'Prox_WristRocket_Storm')
- {
- if (UnitClassName != 'Proxian')
- {
- DisabledReason = class'UIUtilities_Text'.static.CapsCheckForGermanScharfesS(`XEXPAND.ExpandString(class'UIArmory_Loadout'.default.m_strUnavailableToClass));
- }
- }
- //it is a valid weapon for the heavy slot
- if(WeaponTemplate != none && Slot == eInvSlot_HeavyWeapon )
- {
- //stop Proxians from equiping any other heavy weapons
- if(UnitClassName == 'Proxian')
- {
- if (WeaponTemplateName != 'Prox_WristRocket_Storm')
- {
- DisabledReason = class'UIUtilities_Text'.static.CapsCheckForGermanScharfesS(`XEXPAND.ExpandString(class'UIArmory_Loadout'.default.m_strUnavailableToClass));
- }
- }
- }
- //it is a valid weapon for the utility slot
- if(WeaponTemplate != none && Slot == eInvSlot_Utility )
- {
- //stop Proxians from equiping these problematic items
- if(UnitClassName == 'Proxian')
- {
- if ( WeaponTemplateName == 'SustainingSphere'
- || WeaponTemplateName == 'Skulljack'
- || WeaponTemplateName == 'UtilityItem_AshBlackIceSkulljack'
- )
- {
- DisabledReason = class'UIUtilities_Text'.static.CapsCheckForGermanScharfesS(`XEXPAND.ExpandString(class'UIArmory_Loadout'.default.m_strUnavailableToClass));
- }
- }
- }
- //now after checking all requirements
- if (DisabledReason != "")
- {
- `LOG("Unit does not have correct class for" @WeaponTemplate.GetItemFriendlyNameNoStats(), default.bEnableLogging,'Proxian_HeavyWeaponTraits');
- bCanAddItem = 0;
- return OverrideNormalBehavior; //return as we have found this weapon has a class requirement that we have not met
- }
- return DoNotOverrideNormalBehavior; //return to avoid overwriting disabled reasons if there's nothing we are doing
- }
Add Comment
Please, Sign In to add comment