Skip to content

Commit 0526f77

Browse files
committed
Fix ratio inaccuracy after reaching max values
The weights and actual attribute values of attributes that had already reached maximum values were still taken into account when calculating current and target ratios, leading to wrong effective weights. Now, if weights are `str: 10 / dex: 2 / int: 1` and strength reaches its limit, it will be treated as `str: 0 / dex: 2 / int: 1`
1 parent 0bd5b49 commit 0526f77

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/Classes/PassiveSpec.lua

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,23 +2205,38 @@ function PassiveSpecClass:GetAutoAttribute(cachedPlayerAttr, cachedPathAttrResul
22052205
end
22062206
end
22072207

2208-
playerAttr.sumTotal = m_max(1, playerAttr.dex.total + playerAttr.int.total + playerAttr.str.total ) -- use m_max to protect against division by 0 (e.g. in "Omniscience"-like scenarios)
2209-
playerAttr.dex.ratio = playerAttr.dex.total / playerAttr.sumTotal
2210-
playerAttr.int.ratio = playerAttr.int.total / playerAttr.sumTotal
2211-
playerAttr.str.ratio = playerAttr.str.total / playerAttr.sumTotal
2212-
2213-
local maxDiff = nil
2214-
local neededAttr = nil
2215-
22162208
-- Update weights based on attribute requirements if necessary
22172209
if autoAttributeConfig.useAttrReq then
22182210
self.autoAttributeConfig = self.build.treeTab:UpdateAutoAttributeConfig(autoAttributeConfig)
22192211
end
2212+
2213+
-- Mark attributes ineligble if the max value is set and already exceeded.
2214+
local effConfigWeightTotal = 0
2215+
for _, attr in ipairs(attributeList) do
2216+
if autoAttributeConfig[attr].max ~= nil and autoAttributeConfig[attr].useMaxVal and (playerAttr[attr].total >= autoAttributeConfig[attr].max) then
2217+
playerAttr[attr].eligible = false
2218+
playerAttr[attr].effTotal = 0
2219+
else
2220+
playerAttr[attr].eligible = true
2221+
playerAttr[attr].effTotal = playerAttr[attr].total
2222+
effConfigWeightTotal = effConfigWeightTotal + autoAttributeConfig[attr].weight
2223+
end
2224+
end
2225+
2226+
-- Calculating effective totals and ratios that exclude attributes that already exceed max
2227+
playerAttr.effSumTotal = m_max(1, playerAttr.dex.effTotal + playerAttr.int.effTotal + playerAttr.str.effTotal ) -- use m_max to protect against division by 0 (e.g. in "Omniscience"-like scenarios)
2228+
playerAttr.dex.effRatio = playerAttr.dex.effTotal / playerAttr.effSumTotal
2229+
playerAttr.int.effRatio = playerAttr.int.effTotal / playerAttr.effSumTotal
2230+
playerAttr.str.effRatio = playerAttr.str.effTotal / playerAttr.effSumTotal
2231+
2232+
local maxDiff = nil
2233+
local neededAttr = nil
22202234

2235+
-- Find attribute with greatest diff from effective target ratio
22212236
for _, attr in ipairs(attributeList) do
2222-
-- Check if the max value is set and if it's already been exceeded.
2223-
if autoAttributeConfig[attr].max == nil or (not autoAttributeConfig[attr].useMaxVal) or playerAttr[attr].total < autoAttributeConfig[attr].max then
2224-
local diff = autoAttributeConfig[attr].ratio - playerAttr[attr].ratio
2237+
if playerAttr[attr].eligible then
2238+
local effConfigRatio = autoAttributeConfig[attr].weight / m_max(effConfigWeightTotal, 1 )
2239+
local diff = effConfigRatio - playerAttr[attr].effRatio
22252240
if (maxDiff == nil) or (diff > maxDiff) then
22262241
maxDiff = diff
22272242
neededAttr = attr

0 commit comments

Comments
 (0)