Skip to content

Commit 5b3454a

Browse files
committed
FIX(mods): globalLimit style mods did not work sometimes
When a mod gots pice wise parsed the tags can be added to the mod table in unpredictable order. The inital implementation was simply checking the first tag which caused the global limit functionality to not work sometimes. This commit moves the logic into EvalMod.
1 parent d2090d7 commit 5b3454a

3 files changed

Lines changed: 49 additions & 210 deletions

File tree

src/Classes/ModDB.lua

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,7 @@ function ModDBClass:SumInternal(context, modType, cfg, flags, keywordFlags, sour
9898
local mod = modList[i]
9999
if mod.type == modType and band(flags, mod.flags) == mod.flags and MatchKeywordFlags(keywordFlags, mod.keywordFlags) and (not source or ( mod.source and mod.source:match("[^:]+") == source )) then
100100
if mod[1] then
101-
local value = context:EvalMod(mod, cfg) or 0
102-
if mod[1].globalLimit and mod[1].globalLimitKey then
103-
globalLimits[mod[1].globalLimitKey] = globalLimits[mod[1].globalLimitKey] or 0
104-
if globalLimits[mod[1].globalLimitKey] + value > mod[1].globalLimit then
105-
value = mod[1].globalLimit - globalLimits[mod[1].globalLimitKey]
106-
end
107-
globalLimits[mod[1].globalLimitKey] = globalLimits[mod[1].globalLimitKey] + value
108-
end
101+
local value = context:EvalMod(mod, cfg, globalLimits) or 0
109102
result = result + value
110103
else
111104
result = result + mod.value
@@ -133,14 +126,7 @@ function ModDBClass:MoreInternal(context, cfg, flags, keywordFlags, source, ...)
133126
if mod.type == "MORE" and band(flags, mod.flags) == mod.flags and MatchKeywordFlags(keywordFlags, mod.keywordFlags) and (not source or mod.source:match("[^:]+") == source) then
134127
local value
135128
if mod[1] then
136-
value = context:EvalMod(mod, cfg) or 0
137-
if mod[1].globalLimit and mod[1].globalLimitKey then
138-
globalLimits[mod[1].globalLimitKey] = globalLimits[mod[1].globalLimitKey] or 0
139-
if globalLimits[mod[1].globalLimitKey] + value > mod[1].globalLimit then
140-
value = mod[1].globalLimit - globalLimits[mod[1].globalLimitKey]
141-
end
142-
globalLimits[mod[1].globalLimitKey] = globalLimits[mod[1].globalLimitKey] + value
143-
end
129+
value = context:EvalMod(mod, cfg, globalLimits) or 0
144130
else
145131
value = mod.value or 0
146132
end
@@ -249,15 +235,7 @@ function ModDBClass:TabulateInternal(context, result, modType, cfg, flags, keywo
249235
if (mod.type == modType or not modType) and band(flags, mod.flags) == mod.flags and MatchKeywordFlags(keywordFlags, mod.keywordFlags) and (not source or mod.source:match("[^:]+") == source) then
250236
local value
251237
if mod[1] then
252-
value = context:EvalMod(mod, cfg)
253-
if mod[1].globalLimit and mod[1].globalLimitKey then
254-
value = value or 0
255-
globalLimits[mod[1].globalLimitKey] = globalLimits[mod[1].globalLimitKey] or 0
256-
if globalLimits[mod[1].globalLimitKey] + value > mod[1].globalLimit then
257-
value = mod[1].globalLimit - globalLimits[mod[1].globalLimitKey]
258-
end
259-
globalLimits[mod[1].globalLimitKey] = globalLimits[mod[1].globalLimitKey] + value
260-
end
238+
value = context:EvalMod(mod, cfg, globalLimits)
261239
else
262240
value = mod.value
263241
end

src/Classes/ModStore.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,22 @@ function ModStoreClass:GetStat(stat, cfg)
260260
end
261261
end
262262

263-
function ModStoreClass:EvalMod(mod, cfg)
263+
function ModStoreClass:EvalMod(mod, cfg, globalLimits)
264264
local value = mod.value
265265
for _, tag in ipairs(mod) do
266266
if tag.type == "Multiplier" then
267267
local target = self
268268
local limitTarget = self
269+
270+
if globalLimits and tag.globalLimit and tag.globalLimitKey then
271+
value = value or 0
272+
globalLimits[tag.globalLimitKey] = globalLimits[tag.globalLimitKey] or 0
273+
if globalLimits[tag.globalLimitKey] + value > tag.globalLimit then
274+
value = tag.globalLimit - globalLimits[tag.globalLimitKey]
275+
end
276+
globalLimits[tag.globalLimitKey] = globalLimits[tag.globalLimitKey] + value
277+
end
278+
269279
-- Allow limiting a self multiplier on a parent multiplier (eg. Agony Crawler on player virulence)
270280
-- This explicit target is necessary because even though the GetMultiplier method does call self.parent.GetMultiplier, it does so with noMod = true,
271281
-- disabling the summation (3rd part): (not noMod and self:Sum("BASE", cfg, multiplierName[var]) or 0)

0 commit comments

Comments
 (0)