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 Jan 5, 2025
1 parent 3ce4635 commit 33255ed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4101,6 +4101,10 @@ 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 #1352 - New variables for combat sim stacking behavior
local int idxStatBoost;
local bool hasIdenticalStatBoosts;
// End Issue #1352

if(bLoot)
{
Expand Down Expand Up @@ -4137,6 +4141,7 @@ function bool HasUnModifiedItem(XComGameState AddToGameState, X2ItemTemplate Ite
for(idx = 0; idx < Inventory.Length; idx++)
{
ItemState = XComGameState_Item(`XCOMHISTORY.GetGameStateForObjectID(Inventory[idx].ObjectID));
hasIdenticalStatBoosts = false;

if(ItemState == none)
{
Expand All @@ -4149,10 +4154,27 @@ function bool HasUnModifiedItem(XComGameState AddToGameState, X2ItemTemplate Ite
{
if(ItemState.GetMyTemplate().ItemCat == 'combatsim')
{
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)
/// 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 compared
// 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,14 @@ simulated function bool HasBeenModified()
return true;
//end issue #104

WeaponTemplate = X2WeaponTemplate( m_ItemTemplate );

// Single line for Issues #93 and #306
if ((WeaponTemplate != none) && (GetNumUpgradeSlots() > 0) && (GetMyWeaponUpgradeCount() > 0))
WeaponTemplate = X2WeaponTemplate( m_ItemTemplate );
/// HL-Docs: ref:Bugfixes; issue:1429
/// When checking weapons for HasBeenModified, checking that the number of upgrade slots > 0 gives an incorrect response
/// for weapons which have attachments added by OnAcquired and therefore no slots on the weapon template (e.g. TLE / chosen
/// weapons). Mods which add additional copies of these weapons then cause the items to stack, which interferes with downstream
/// logic in GetItemFromInventory and PutItemInInventory, causing attachments to be stripped when the stacked item is equipped.
// Single line for Issues #93, #306 and #1429
if ((WeaponTemplate != none) /* && (GetNumUpgradeSlots() > 0)*/ && (GetMyWeaponUpgradeCount() > 0))
return true;

return false;
Expand Down

0 comments on commit 33255ed

Please sign in to comment.