Skip to content

Commit

Permalink
Fix issues with stacking behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDog86 committed Dec 27, 2024
1 parent 3ce4635 commit bdbf2e4
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 10 deletions.
21 changes: 21 additions & 0 deletions X2WOTCCommunityHighlander/Config/XComGame.ini
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,24 @@ iMixedCharacterPoolChance = 50

;;; Issue #1398 - Change to adjust the delay of the 'Squad member dead' voiceline after a unit is killed
fSquadMemberDeadVoicelineDelay = 3.0f

; Issue #1429 - Add items to this array to run the item's onAcquired function each time they are equipped
; (this prevents a bug where stackable items with fixed attachments would strip the attachments when equipped)
+TLEWeaponEquipFix=TLE_AssaultRifle_CV
+TLEWeaponEquipFix=TLE_SniperRifle_CV
+TLEWeaponEquipFix=TLE_Shotgun_CV
+TLEWeaponEquipFix=TLE_Cannon_CV
+TLEWeaponEquipFix=TLE_Pistol_CV
+TLEWeaponEquipFix=TLE_Sword_CV
+TLEWeaponEquipFix=TLE_AssaultRifle_MG
+TLEWeaponEquipFix=TLE_SniperRifle_MG
+TLEWeaponEquipFix=TLE_Shotgun_MG
+TLEWeaponEquipFix=TLE_Cannon_MG
+TLEWeaponEquipFix=TLE_Pistol_MG
+TLEWeaponEquipFix=TLE_Sword_MG
+TLEWeaponEquipFix=TLE_AssaultRifle_BM
+TLEWeaponEquipFix=TLE_SniperRifle_BM
+TLEWeaponEquipFix=TLE_Shotgun_BM
+TLEWeaponEquipFix=TLE_Cannon_BM
+TLEWeaponEquipFix=TLE_Pistol_BM
+TLEWeaponEquipFix=TLE_Sword_BM
6 changes: 6 additions & 0 deletions X2WOTCCommunityHighlander/Src/XComGame/Classes/CHHelpers.uc
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ var config bool bForce24hclockLeadingZero;
// Variable for Issue #1398 - Number of seconds to wait after a unit is killed before playing the 'OnSquadMemberDead' voiceline
var config float fSquadMemberDeadVoicelineDelay;

/// HL-Docs: ref:Bugfixes; issue:1429
// When certain items with fixed attachments (e.g. TLE Weapons) are stacked in the inventory by mods, equipping such items
// on a soldier will strip the attachments. Adding items to the configurable array below will ensure the item's onAcquired
// function will be called when equipping the item on the soldier, ensuring the attachments are re-added.
var config array<name> TLEWeaponEquipFix;

// Start Issue #885
enum EHLDelegateReturn
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4101,6 +4101,12 @@ function bool HasItemInInventoryOrLoadout(X2ItemTemplate ItemTemplate, optional
function bool HasUnModifiedItem(XComGameState AddToGameState, X2ItemTemplate ItemTemplate, out XComGameState_Item ItemState, optional bool bLoot = false, optional XComGameState_Item CombatSimTest)
{
local int idx;
// Start Issue #1429 - New variables to improve stacking behaviour
local int idxAttach, idxStatBoost;
local bool hasIdenticalAttachments, hasIdenticalStatBoosts;
local array<name> inventoryWeaponUpgrades;
local array<name> selectedWeaponUpgrades;
// End Issue #1429

if(bLoot)
{
Expand Down Expand Up @@ -4134,25 +4140,74 @@ function bool HasUnModifiedItem(XComGameState AddToGameState, X2ItemTemplate Ite
}
else
{
// Start Issue #1429 - Get the list of weapon upgrades from the itemsstate which is passed in
if(CombatSimTest != none)
{
selectedWeaponUpgrades = CombatSimTest.GetMyWeaponUpgradeTemplateNames();
}
for(idx = 0; idx < Inventory.Length; idx++)
{
ItemState = XComGameState_Item(`XCOMHISTORY.GetGameStateForObjectID(Inventory[idx].ObjectID));

inventoryWeaponUpgrades = ItemState.GetMyWeaponUpgradeTemplateNames();
hasIdenticalAttachments = false;
hasIdenticalStatBoosts = false;
if(ItemState == none)
{
ItemState = XComGameState_Item(AddToGameState.GetGameStateForObjectID(Inventory[idx].ObjectID));
}

// Issue #1429 - If the item we're putting back into the inventory matches something which is already there
// And it also has the same array of attachments, we can allow the items to stack
if(ItemState != none)
{
if (ItemState.GetMyTemplateName() == ItemTemplate.DataName && (ItemState.Quantity > 0 || ItemState.GetMyTemplate().ItemCat == 'resource') && !ItemState.HasBeenModified())
if (ItemState.GetMyTemplateName() == ItemTemplate.DataName)
{
if(ItemState.GetMyTemplate().ItemCat == 'combatsim')
If (selectedWeaponUpgrades.Length == 0)
{
if(ItemState.StatBoosts.Length > 0 && CombatSimTest.StatBoosts.Length > 0 && ItemState.StatBoosts[0].Boost == CombatSimTest.StatBoosts[0].Boost && ItemState.StatBoosts[0].StatType == CombatSimTest.StatBoosts[0].StatType)
hasIdenticalAttachments = true;
}
else if(inventoryWeaponUpgrades.Length != 0)
{
hasIdenticalAttachments = true;
for(idxAttach = 0; idxAttach < inventoryWeaponUpgrades.Length; idxAttach++)
{
If(inventoryWeaponUpgrades[idxAttach] != selectedWeaponUpgrades[idxAttach])
{
hasIdenticalAttachments = false;
break;
}
}
}
}
// Issue #1429 - Removed check for !HasBeenModified as it's now handled by hasIdenticalAttachments
if (hasIdenticalAttachments && (ItemState.Quantity > 0 || ItemState.GetMyTemplate().ItemCat == 'resource'))
// End Issue #1429
{
if(ItemState.GetMyTemplate().ItemCat == 'combatsim')
{
/// HL-Docs: ref:Bugfixes; issue:1352
// Mod-added PCS items which did not provide exactly 1 stat boost were not being properly checked by HasUnModifiedItem
// New checks added here mean that PCS items with no stat boosts, or more than one stat boost, are properly checked
// for stacking behaviour
// Begin Issue #1352
hasIdenticalStatBoosts = true;
if(CombatSimTest.StatBoosts.Length != 0)
{
for(idxStatBoost = 0; idxStatBoost < ItemState.StatBoosts.Length; idxStatBoost++)
{
If(ItemState.StatBoosts[idxStatBoost].Boost != CombatSimTest.StatBoosts[idxStatBoost].Boost || ItemState.StatBoosts[idxStatBoost].StatType != CombatSimTest.StatBoosts[idxStatBoost].StatType)
{
hasIdenticalStatBoosts = false;
break;
}
}
}
if(hasIdenticalStatBoosts)
{
return true;
}
// End Issue #1352
}
else
{
Expand All @@ -4162,7 +4217,7 @@ function bool HasUnModifiedItem(XComGameState AddToGameState, X2ItemTemplate Ite
}
}
}

return false;
}

Expand All @@ -4176,7 +4231,9 @@ function bool PutItemInInventory(XComGameState AddToGameState, XComGameState_Ite

ItemTemplate = ItemState.GetMyTemplate();

if( ItemState.HasBeenModified() || ItemTemplate.bAlwaysUnique )
// Issue #1429 - HasBeenModifiedCheck moved later in the function to prevent short-circuiting new stacking logic
// for modified items which have the same attachments (this is handled by HasUnModifiedItem)
if( ItemTemplate.bAlwaysUnique )
{
HQModified = true;

Expand All @@ -4191,12 +4248,12 @@ function bool PutItemInInventory(XComGameState AddToGameState, XComGameState_Ite
}
else
{
if(!ItemState.GetMyTemplate().bInfiniteItem)
if(!ItemState.GetMyTemplate().bInfiniteItem || ItemState.HasBeenModified())
{
if( HasUnModifiedItem(AddToGameState, ItemTemplate, InventoryItemState, bLoot, ItemState) )
{
HQModified = false;

if(InventoryItemState.ObjectID != ItemState.ObjectID)
{
NewInventoryItemState = XComGameState_Item(AddToGameState.ModifyStateObject(class'XComGameState_Item', InventoryItemState.ObjectID));
Expand Down Expand Up @@ -4363,9 +4420,18 @@ function bool GetItemFromInventory(XComGameState AddToGameState, StateObjectRefe
if(InventoryItemState.Quantity > 1)
{
HQModified = false;
InventoryItemState = XComGameState_Item(AddToGameState.ModifyStateObject(class'XComGameState_Item', InventoryItemState.ObjectID));
InventoryItemState.Quantity--;
ItemState = XComGameState_Item(AddToGameState.CreateNewStateObject(class'XComGameState_Item', InventoryItemState.GetMyTemplate()));
// Begin Issue #1429 - If the item being fetched from inventory is one with attachments added via onAcquiredFn
// Use CreateInstanceFromTemplate instead of CreateNewStateObject
If(class'CHHelpers'.default.TLEWeaponEquipFix.Find(ItemState.GetMyTemplateName()) != INDEX_NONE)
{
ItemState = InventoryItemState.GetMyTemplate().CreateInstanceFromTemplate(AddToGameState);
}
Else
{
ItemState = XComGameState_Item(AddToGameState.CreateNewStateObject(class'XComGameState_Item', InventoryItemState.GetMyTemplate()));
}
// End Issue #1429
ItemState.StatBoosts = InventoryItemState.StatBoosts; // Make sure the stat boosts are the same. Used for PCS.
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,9 @@ simulated function bool HasBeenModified()
WeaponTemplate = X2WeaponTemplate( m_ItemTemplate );

// Single line for Issues #93 and #306
if ((WeaponTemplate != none) && (GetNumUpgradeSlots() > 0) && (GetMyWeaponUpgradeCount() > 0))
// Issue #1429 - Remove the check for GetNumUpgradeSlots - this causes an incorrect response for weapons with
// fixed attachments and no slots on the template (e.g. if the attachments are added by an onAcquired function)
if ((WeaponTemplate != none) /* && (GetNumUpgradeSlots() > 0)*/ && (GetMyWeaponUpgradeCount() > 0))
return true;

return false;
Expand Down

0 comments on commit bdbf2e4

Please sign in to comment.