Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/System/TestOffence_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
31 changes: 22 additions & 9 deletions src/Modules/CalcOffence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading