From 1fc5c5fbd5f00b46ecb15ce253591d7e34913211 Mon Sep 17 00:00:00 2001 From: "lijiuyang.5137" Date: Tue, 10 Nov 2026 22:02:42 +0800 Subject: [PATCH] Fix damage conversion result depending on table iteration order The second conversion step applied all conversions in one pairs() loop over tempConversions, where an entry for a converted type sets that type's share and every entry adds its conversions to other types. When a skill's own conversion and a global conversion both target the same type, the addition to that type is lost if the type's own share is set after it. pairs() order over string keys varies between LuaJIT processes, so the same build could give two results (e.g. 20% skill Physical-to-Fire plus 75% global to Fire: Fire 0.2 or 0.8). Set all shares first, then add all conversions, both in dmgTypeList order. Co-Authored-By: Claude Opus 5.5 --- spec/System/TestOffence_spec.lua | 16 ++++++++++++++++ src/Modules/CalcOffence.lua | 31 ++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 9 deletions(-) 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