From ce4567d92880bf9066a8985c0dca7ac1f5c19a17 Mon Sep 17 00:00:00 2001 From: David Medgyesy Date: Thu, 26 Nov 2026 13:35:14 +0100 Subject: [PATCH 1/2] Reconcile granted skill groups for equipment previews Refs PathOfBuildingCommunity/PathOfBuilding#10427 Refs PathOfBuildingCommunity/PathOfBuilding#8093 --- spec/System/TestItemMods_spec.lua | 57 ++++++++++++++++++++++++++++++ src/Classes/SkillsTab.lua | 17 ++++++--- src/Modules/CalcSetup.lua | 58 ++++++++++++++++++++----------- src/Modules/Common.lua | 2 +- 4 files changed, 109 insertions(+), 25 deletions(-) diff --git a/spec/System/TestItemMods_spec.lua b/spec/System/TestItemMods_spec.lua index a2a3cf5d1c4..326e3e975d5 100644 --- a/spec/System/TestItemMods_spec.lua +++ b/spec/System/TestItemMods_spec.lua @@ -1503,6 +1503,63 @@ describe("TetsItemMods", function() build.itemsTab:AddDisplayItem() end + it("adds and removes item-granted Envy in item previews", function() + addItem("Rarity: NORMAL\nCutlass") + build.skillsTab:PasteSocketGroup("Ethereal Knives 20/0 1\n") + local group = build.skillsTab.socketGroupList[1] + group.includeInFullDPS = true + local candidate = new("Item"):Item("Rarity: UNIQUE\nUnited in Dream\nCutlass\nImplicits: 0\nGrants Level 25 Envy") + build.itemsTab:AddItem(candidate, true) + runCallback("OnFrame") + + local slot = build.itemsTab.slots["Weapon 1"] + local originalItemId = slot.selItemId + local calculate, original = build.calcsTab:GetMiscCalculator() + local adding = calculate({ repSlotName = "Weapon 1", repItem = candidate }) + assert.are.equal(originalItemId, slot.selItemId) + assert.are.same({ group }, build.skillsTab.socketGroupList) + + slot:SetSelItemId(candidate.id) + build.buildFlag = true + runCallback("OnFrame") + local equipped = build.calcsTab.mainOutput + assert.is_true(equipped.TotalDPS > original.TotalDPS) + assert.are.equal(equipped.TotalDPS, adding.TotalDPS) + assert.are.equal(equipped.FullDPS, adding.FullDPS) + + calculate = build.calcsTab:GetMiscCalculator() + local removing = calculate({ repSlotName = "Weapon 1", repItem = build.itemsTab.items[originalItemId] }) + assert.are.equal(original.TotalDPS, removing.TotalDPS) + assert.are.equal(original.FullDPS, removing.FullDPS) + assert.are.equal(candidate.id, slot.selItemId) + + local envy = assert(findActiveSkill("Envy")).socketGroup + envy.enabled = false + build.buildFlag = true + runCallback("OnFrame") + calculate = build.calcsTab:GetMiscCalculator() + local unchanged = calculate({ repSlotName = "Weapon 1", repItem = candidate }) + assert.are.equal(original.TotalDPS, unchanged.TotalDPS) + assert.is_false(envy.enabled) + end) + + it("leaves the triggered skill data unchanged when previewing an item", function() + build.skillsTab:PasteSocketGroup("Fireball 20/0 1\n") + runCallback("OnFrame") + local candidate = new("Item"):Item("Rarity: UNIQUE\nBubonic Trail\nMurder Boots\nImplicits: 0\nTriggers Level 20 Death Walk when Equipped") + local grant = candidate.grantedSkills[1] + assert.is_true(grant.triggered) + local level = data.skills[grant.skillId].levels[grant.level] + local cost = level.cost + + local calculate = build.calcsTab:GetMiscCalculator() + calculate({ repSlotName = "Boots", repItem = candidate }) + + assert.are.equal(cost, level.cost) + assert.are.equal(0, build.itemsTab.slots.Boots.selItemId) + assert.are.equal(1, #build.skillsTab.socketGroupList) + end) + -- Pearl of Tsoatha: despite the "Socketed in" wording these support skills granted -- by the item in that slot as well, which ExtraSupport normally excludes it("ExtraSupport marked appliesToGrantedSkills supports an item granted skill", function() diff --git a/src/Classes/SkillsTab.lua b/src/Classes/SkillsTab.lua index 04d383461cd..779dafbd723 100644 --- a/src/Classes/SkillsTab.lua +++ b/src/Classes/SkillsTab.lua @@ -1168,7 +1168,8 @@ end -- Processes the given socket group, filling in information that will be used for display or calculations ---@param socketGroup table -function SkillsTabClass:ProcessSocketGroup(socketGroup) +---@param isolated boolean? Copy shared skill data before overriding the cost. +function SkillsTabClass:ProcessSocketGroup(socketGroup, isolated) -- Loop through the skill gem list local data = self.build.data for _, gemInstance in ipairs(socketGroup.gemList) do @@ -1195,9 +1196,17 @@ function SkillsTabClass:ProcessSocketGroup(socketGroup) else gemInstance.grantedEffect = data.skills[gemInstance.skillId] end - if gemInstance.triggered then - if gemInstance.grantedEffect.levels[gemInstance.level] then - gemInstance.grantedEffect.levels[gemInstance.level].cost = {} + if gemInstance.triggered and gemInstance.grantedEffect then + local effect = gemInstance.grantedEffect + local level = gemInstance.level + if effect.levels[level] then + if isolated then + effect = copyTable(effect, true) + effect.levels = copyTable(effect.levels, true) + effect.levels[level] = copyTable(effect.levels[level], true) + gemInstance.grantedEffect = effect + end + effect.levels[level].cost = {} end end elseif gemInstance.nameSpec:match("%S") then diff --git a/src/Modules/CalcSetup.lua b/src/Modules/CalcSetup.lua index e6535b0538d..5f0540d9854 100644 --- a/src/Modules/CalcSetup.lua +++ b/src/Modules/CalcSetup.lua @@ -1506,7 +1506,23 @@ function calcs.initEnv(build, mode, override, specEnv) end if not accelerate.skills then - if env.mode == "MAIN" then + local isItemPreview = env.mode == "CALCULATOR" and override.repSlotName ~= nil + local socketGroupList = build.skillsTab.socketGroupList + if isItemPreview then + -- Reconcile grants for the candidate without changing the live groups or gems. + socketGroupList = { } + for index, liveGroup in ipairs(build.skillsTab.socketGroupList) do + local group = copyTable(liveGroup, true) + group.gemList = { } + for gemIndex, gem in ipairs(liveGroup.gemList) do + group.gemList[gemIndex] = copyTable(gem, true) + end + socketGroupList[index] = group + end + end + env.socketGroupList = socketGroupList + + if env.mode == "MAIN" or isItemPreview then local function getNormalizedSkillLevel(grantedSkill) -- Levels in socketGroup.gemList[1].level are normalized -- grantedSkill.level is not causing group match miss which causes all things that rely on group order to fail @@ -1523,7 +1539,7 @@ function calcs.initEnv(build, mode, override, specEnv) for _, grantedSkill in ipairs(env.grantedSkills) do -- Check if a matching group already exists local group - for index, socketGroup in pairs(build.skillsTab.socketGroupList) do + for _, socketGroup in ipairs(socketGroupList) do if socketGroup.source == grantedSkill.source and socketGroup.slot == grantedSkill.slotName then if socketGroup.gemList[1] and socketGroup.gemList[1].skillId == grantedSkill.skillId and (socketGroup.gemList[1].level == grantedSkill.level or socketGroup.gemList[1].level == getNormalizedSkillLevel(grantedSkill)) then group = socketGroup @@ -1535,7 +1551,7 @@ function calcs.initEnv(build, mode, override, specEnv) if not group then -- Create a new group for this skill group = { label = "", enabled = true, gemList = { }, source = grantedSkill.source, slot = grantedSkill.slotName } - t_insert(build.skillsTab.socketGroupList, group) + t_insert(socketGroupList, group) markList[group] = true end @@ -1558,13 +1574,13 @@ function calcs.initEnv(build, mode, override, specEnv) activeGemInstance.triggerChance = grantedSkill.triggerChance wipeTable(group.gemList) t_insert(group.gemList, activeGemInstance) - build.skillsTab:ProcessSocketGroup(group) + build.skillsTab:ProcessSocketGroup(group, isItemPreview) end if #env.explodeSources ~= 0 then -- Check if a matching group already exists local group - for _, socketGroup in pairs(build.skillsTab.socketGroupList) do + for _, socketGroup in ipairs(socketGroupList) do if socketGroup.source == "Explode" then group = socketGroup break @@ -1573,7 +1589,7 @@ function calcs.initEnv(build, mode, override, specEnv) if not group then -- Create a new group for this skill group = { label = "On Kill Monster Explosion", enabled = true, gemList = { }, source = "Explode", noSupports = true } - t_insert(build.skillsTab.socketGroupList, group) + t_insert(socketGroupList, group) end -- Update the group group.explodeSources = env.explodeSources @@ -1601,16 +1617,16 @@ function calcs.initEnv(build, mode, override, specEnv) t_insert(group.gemList, activeGemInstance) end markList[group] = true - build.skillsTab:ProcessSocketGroup(group) + build.skillsTab:ProcessSocketGroup(group, isItemPreview) end -- Remove any socket groups that no longer have a matching item local i = 1 - while build.skillsTab.socketGroupList[i] do - local socketGroup = build.skillsTab.socketGroupList[i] + while socketGroupList[i] do + local socketGroup = socketGroupList[i] if socketGroup.source and not markList[socketGroup] then - t_remove(build.skillsTab.socketGroupList, i) - if build.skillsTab.displayGroup == socketGroup then + t_remove(socketGroupList, i) + if not isItemPreview and build.skillsTab.displayGroup == socketGroup then build.skillsTab.displayGroup = nil end else @@ -1644,11 +1660,13 @@ function calcs.initEnv(build, mode, override, specEnv) -- Determine main skill group if env.mode == "CALCS" then - env.calcsInput.skill_number = m_min(m_max(#build.skillsTab.socketGroupList, 1), env.calcsInput.skill_number or 1) + env.calcsInput.skill_number = m_min(m_max(#socketGroupList, 1), env.calcsInput.skill_number or 1) env.mainSocketGroup = env.calcsInput.skill_number else - build.mainSocketGroup = m_min(m_max(#build.skillsTab.socketGroupList, 1), build.mainSocketGroup or 1) - env.mainSocketGroup = build.mainSocketGroup + env.mainSocketGroup = m_min(m_max(#socketGroupList, 1), build.mainSocketGroup or 1) + if not isItemPreview then + build.mainSocketGroup = env.mainSocketGroup + end end -- Process supports and put them into the correct buckets @@ -1663,7 +1681,7 @@ function calcs.initEnv(build, mode, override, specEnv) local processedSockets = {} local socketIndexByGem = {} local slotSocketedCounts = {} - for _, group in ipairs(build.skillsTab.socketGroupList) do + for _, group in ipairs(socketGroupList) do if group.slot then local socketOffset = slotSocketedCounts[group.slot] or 0 for gemIndex, gemInstance in ipairs(group.gemList) do @@ -1679,7 +1697,7 @@ function calcs.initEnv(build, mode, override, specEnv) ---@type table local fromItemReplacements = {} -- Process support gems adding them to applicable support lists - for index, group in ipairs(build.skillsTab.socketGroupList) do + for index, group in ipairs(socketGroupList) do local slot = group.slot and build.itemsTab.slots[group.slot] group.slotEnabled = not slot or not slot.weaponSet or slot.weaponSet == (build.itemsTab.activeItemSet.useSecondWeaponSet and 2 or 1) -- if group is main skill or group is enabled @@ -1822,7 +1840,7 @@ function calcs.initEnv(build, mode, override, specEnv) -- Process active skills adding the applicable supports local socketGroupSkillListList = { } - for index, group in ipairs(build.skillsTab.socketGroupList) do + for index, group in ipairs(socketGroupList) do if index == env.mainSocketGroup or (group.enabled and group.slotEnabled) then local isTreeSkill = not group.slot and group.source and group.source:lower():find("tree") local slotName = group.slot and group.slot:gsub(" Swap", "") or (isTreeSkill and "Passive Tree") or nil @@ -1887,7 +1905,7 @@ function calcs.initEnv(build, mode, override, specEnv) if group.source then if supportLists[slotName] then -- add socketed supports from other socketGroups - for _, otherSocketGroup in ipairs(build.skillsTab.socketGroupList) do + for _, otherSocketGroup in ipairs(socketGroupList) do if otherSocketGroup.slot and otherSocketGroup.slot == group.slot and not (otherSocketGroup.source and otherSocketGroup.source == group.source) then for _, gem in ipairs(otherSocketGroup.gemList) do if gem.gemData and gem.gemData.grantedEffect and gem.gemData.grantedEffect.support then @@ -1907,7 +1925,7 @@ function calcs.initEnv(build, mode, override, specEnv) for crossLinkedSupportSlot, crossLinkedSupportGroup in pairs(env.crossLinkedSupportGroups) do for _, crossLinkedSupportedSlot in ipairs(crossLinkedSupportGroup) do if crossLinkedSupportedSlot == slotName and supportLists[crossLinkedSupportSlot] then - for _, otherSocketGroup in ipairs(build.skillsTab.socketGroupList) do + for _, otherSocketGroup in ipairs(socketGroupList) do if otherSocketGroup.slot and otherSocketGroup.slot == crossLinkedSupportSlot then for _, gem in ipairs(otherSocketGroup.gemList) do if gem.gemData and gem.gemData.grantedEffect and gem.gemData.grantedEffect.support then @@ -1954,7 +1972,7 @@ function calcs.initEnv(build, mode, override, specEnv) end -- Process calculated active skill lists - for index, group in ipairs(build.skillsTab.socketGroupList) do + for index, group in ipairs(socketGroupList) do local isTreeSkill = not group.slot and group.source and group.source:lower():find("tree") local slotName = group.slot and group.slot:gsub(" Swap", "") or (isTreeSkill and "Passive Tree") or nil socketGroupSkillListList[slotName or "noSlot"] = socketGroupSkillListList[slotName or "noSlot"] or {} diff --git a/src/Modules/Common.lua b/src/Modules/Common.lua index e8c7dfd03fb..5086e38b8a2 100644 --- a/src/Modules/Common.lua +++ b/src/Modules/Common.lua @@ -911,7 +911,7 @@ function cacheSkillUUID(skill, env) end end - for i, group in ipairs(env.build.skillsTab.socketGroupList) do + for i, group in ipairs(env.socketGroupList or env.build.skillsTab.socketGroupList) do if skill.socketGroup == group then groupIdx = i break From 35259dae5d0af9d8896cd566272ef6d112d4c260 Mon Sep 17 00:00:00 2001 From: David Medgyesy Date: Fri, 27 Nov 2026 16:51:53 +0100 Subject: [PATCH 2/2] Keep the main skill selected when a granted group before it is removed Removing an item-granted skill group shifted the groups after it, so the main skill index pointed at the next skill. That happened when the item was really swapped, and with the preview change also in item comparisons. --- spec/System/TestItemMods_spec.lua | 29 +++++++++++++++++++++++++++++ src/Modules/CalcSetup.lua | 6 +++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/spec/System/TestItemMods_spec.lua b/spec/System/TestItemMods_spec.lua index 326e3e975d5..27a8970431b 100644 --- a/spec/System/TestItemMods_spec.lua +++ b/spec/System/TestItemMods_spec.lua @@ -1543,6 +1543,35 @@ describe("TetsItemMods", function() assert.is_false(envy.enabled) end) + it("keeps the main skill selected when a granted skill group before it is removed", function() + local envySword = new("Item"):Item("Rarity: UNIQUE\nUnited in Dream\nCutlass\nImplicits: 0\nGrants Level 25 Envy") + build.itemsTab:AddItem(envySword, true) + build.itemsTab.slots["Weapon 1"]:SetSelItemId(envySword.id) + build.buildFlag = true + runCallback("OnFrame") + build.skillsTab:PasteSocketGroup("Ethereal Knives 20/0 1\n") + build.skillsTab:PasteSocketGroup("Fireball 20/0 1\n") + runCallback("OnFrame") + -- Envy's group comes first, so removing it shifts the other groups down + assert.are.equal("Envy", build.skillsTab.socketGroupList[1].gemList[1].nameSpec) + build.mainSocketGroup = 2 + build.buildFlag = true + runCallback("OnFrame") + assert.are.equal("Ethereal Knives", build.calcsTab.mainEnv.player.mainSkill.activeEffect.grantedEffect.name) + + local plainSword = new("Item"):Item("Rarity: NORMAL\nCutlass") + local calculate = build.calcsTab:GetMiscCalculator() + local preview = calculate({ repSlotName = "Weapon 1", repItem = plainSword }) + assert.are.equal(2, build.mainSocketGroup) + + build.itemsTab:AddItem(plainSword, true) + build.itemsTab.slots["Weapon 1"]:SetSelItemId(plainSword.id) + build.buildFlag = true + runCallback("OnFrame") + assert.are.equal("Ethereal Knives", build.calcsTab.mainEnv.player.mainSkill.activeEffect.grantedEffect.name) + assert.are.equal(build.calcsTab.mainOutput.TotalDPS, preview.TotalDPS) + end) + it("leaves the triggered skill data unchanged when previewing an item", function() build.skillsTab:PasteSocketGroup("Fireball 20/0 1\n") runCallback("OnFrame") diff --git a/src/Modules/CalcSetup.lua b/src/Modules/CalcSetup.lua index 5f0540d9854..ca942d81e13 100644 --- a/src/Modules/CalcSetup.lua +++ b/src/Modules/CalcSetup.lua @@ -1521,6 +1521,7 @@ function calcs.initEnv(build, mode, override, specEnv) end end env.socketGroupList = socketGroupList + local mainSocketGroup = build.mainSocketGroup if env.mode == "MAIN" or isItemPreview then local function getNormalizedSkillLevel(grantedSkill) @@ -1621,6 +1622,8 @@ function calcs.initEnv(build, mode, override, specEnv) end -- Remove any socket groups that no longer have a matching item + -- Keep the selected main group selected when a group before it is removed + local mainGroup = socketGroupList[mainSocketGroup or 1] local i = 1 while socketGroupList[i] do local socketGroup = socketGroupList[i] @@ -1633,6 +1636,7 @@ function calcs.initEnv(build, mode, override, specEnv) i = i + 1 end end + mainSocketGroup = isValueInArray(socketGroupList, mainGroup) or mainSocketGroup end -- Get the weapon data tables for the equipped weapons @@ -1663,7 +1667,7 @@ function calcs.initEnv(build, mode, override, specEnv) env.calcsInput.skill_number = m_min(m_max(#socketGroupList, 1), env.calcsInput.skill_number or 1) env.mainSocketGroup = env.calcsInput.skill_number else - env.mainSocketGroup = m_min(m_max(#socketGroupList, 1), build.mainSocketGroup or 1) + env.mainSocketGroup = m_min(m_max(#socketGroupList, 1), mainSocketGroup or 1) if not isItemPreview then build.mainSocketGroup = env.mainSocketGroup end