diff --git a/spec/System/TestOffence_spec.lua b/spec/System/TestOffence_spec.lua index 2e8ca720f0..e9246d5f86 100644 --- a/spec/System/TestOffence_spec.lua +++ b/spec/System/TestOffence_spec.lua @@ -41,4 +41,20 @@ describe("TestOffence", function() assert.are.equals(2, build.calcsTab.mainOutput.PhysicalMinBase) assert.are.equals(0.5, build.calcsTab.mainOutput.ColdSummedMinBase) end) + + it("applies a global conversion on top of a skill conversion to the same type independently of table order", function() + build.skillsTab:PasteSocketGroup("Exsanguinate 20/0 1") + build.configTab.input.customMods = [[ + 20% of Exsanguinate and Reap Physical Damage Converted to Fire Damage + 75% of Damage Converted to Fire Damage + ]] + build.configTab:BuildModList() + runCallback("OnFrame") + + -- Skill conversion first: 20% of Physical to Fire; then 75% of the remaining 80% to Fire. + -- The Fire part stays Fire (75% of Fire to Fire is no conversion). + local conversion = build.calcsTab.mainEnv.player.mainSkill.conversionTable.Physical + assert.are.equals(0.8, conversion.Fire) + assert.is_true(math.abs(conversion.mult - 0.2) < 0.000001) + end) end) diff --git a/src/Modules/CalcOffence.lua b/src/Modules/CalcOffence.lua index 960a5e16d4..7b7ecbae3d 100644 --- a/src/Modules/CalcOffence.lua +++ b/src/Modules/CalcOffence.lua @@ -2485,16 +2485,29 @@ function calcs.offence(env, actor, activeSkill) end end - -- Apply all conversions simultaneously - for fromType, data in pairs(tempConversions) do - if fromType == damageType then - activeSkill.conversionTable[damageType].mult = data.mult - else - activeSkill.conversionTable[damageType][fromType] = data.base + -- Apply all conversions simultaneously: set every remaining share first, then add every conversion. + -- Doing both in one pass made the result depend on pairs() order: an addition to a type was lost + -- when that type's own share was set after it (e.g. a skill's own conversion to Fire plus a global + -- conversion to Fire). + for _, fromType in ipairs(dmgTypeList) do + local data = tempConversions[fromType] + if data then + if fromType == damageType then + activeSkill.conversionTable[damageType].mult = data.mult + else + activeSkill.conversionTable[damageType][fromType] = data.base + end end - for toType, amount in pairs(data.conv) do - activeSkill.conversionTable[damageType][toType] = - (activeSkill.conversionTable[damageType][toType] or 0) + amount + end + for _, fromType in ipairs(dmgTypeList) do + local data = tempConversions[fromType] + if data then + for _, toType in ipairs(dmgTypeList) do + if data.conv[toType] then + activeSkill.conversionTable[damageType][toType] = + (activeSkill.conversionTable[damageType][toType] or 0) + data.conv[toType] + end + end end end