Skip to content

Commit 191bd6f

Browse files
github-actions[bot]LocalIdentityLocalIdentity
authored
[pob2-port] Change loops to use iPairs if possible (PathOfBuildingCommunity#9045)
* Apply changes from PathOfBuildingCommunity/PathOfBuilding-PoE2#1494 * Fix merge issues * Use PoB 2 format for skill costs calcs --------- Co-authored-by: LocalIdentity <LocalIdentity@users.noreply.github.com> Co-authored-by: LocalIdentity <localidentity2@gmail.com>
1 parent 07335bc commit 191bd6f

3 files changed

Lines changed: 100 additions & 89 deletions

File tree

src/Classes/Item.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ function ItemClass:BuildModListForSlotNum(baseList, slotNum)
13741374
weaponData.rangeBonus = calcLocal(modList, "WeaponRange", "BASE", 0) + 10 * calcLocal(modList, "WeaponRangeMetre", "BASE", 0) + m_floor(self.quality / 10 * calcLocal(modList, "AlternateQualityLocalWeaponRangePer10Quality", "BASE", 0))
13751375
weaponData.range = self.base.weapon.Range + weaponData.rangeBonus
13761376
local LocalIncEle = calcLocal(modList, "LocalElementalDamage", "INC", 0)
1377-
for _, dmgType in pairs(dmgTypeList) do
1377+
for _, dmgType in ipairs(dmgTypeList) do
13781378
local min = (self.base.weapon[dmgType.."Min"] or 0) + calcLocal(modList, dmgType.."Min", "BASE", 0)
13791379
local max = (self.base.weapon[dmgType.."Max"] or 0) + calcLocal(modList, dmgType.."Max", "BASE", 0)
13801380
if dmgType == "Physical" then
@@ -1417,7 +1417,7 @@ function ItemClass:BuildModListForSlotNum(baseList, slotNum)
14171417
end
14181418
end
14191419
weaponData.TotalDPS = 0
1420-
for _, dmgType in pairs(dmgTypeList) do
1420+
for _, dmgType in ipairs(dmgTypeList) do
14211421
weaponData.TotalDPS = weaponData.TotalDPS + (weaponData[dmgType.."DPS"] or 0)
14221422
end
14231423
elseif self.base.armour then

src/Classes/ModStore.lua

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function ModStoreClass:ScaleAddMod(mod, scale, replace)
5858
local precision = ((data.highPrecisionMods[subMod.name] and data.highPrecisionMods[subMod.name][subMod.type])) or ((m_floor(subMod.value) ~= subMod.value) and data.defaultHighPrecision) or nil
5959
if precision then
6060
local power = 10 ^ precision
61-
subMod.value = math.floor(subMod.value * scale * power) / power
61+
subMod.value = m_floor(subMod.value * scale * power) / power
6262
else
6363
subMod.value = m_modf(round(subMod.value * scale, 2))
6464
end
@@ -265,6 +265,9 @@ end
265265

266266
function ModStoreClass:EvalMod(mod, cfg, globalLimits)
267267
local value = mod.value
268+
local GetStat = self.GetStat
269+
local GetMultiplier = self.GetMultiplier
270+
local GetCondition = self.GetCondition
268271
for _, tag in ipairs(mod) do
269272
if tag.type == "Multiplier" then
270273
local target = self
@@ -290,13 +293,13 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
290293
local base = 0
291294
if tag.varList then
292295
for _, var in pairs(tag.varList) do
293-
base = base + target:GetMultiplier(var, cfg)
296+
base = base + GetMultiplier(target, var, cfg)
294297
end
295298
else
296-
base = target:GetMultiplier(tag.var, cfg)
299+
base = GetMultiplier(target, tag.var, cfg)
297300
end
298301
if tag.divVar then
299-
tag.div = self:GetMultiplier(tag.divVar, cfg)
302+
tag.div = GetMultiplier(self, tag.divVar, cfg)
300303
end
301304
local mult = m_floor(base / (tag.div or 1) + 0.0001)
302305
if tag.noFloor then
@@ -305,7 +308,7 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
305308
local limitTotal
306309
local limitNegTotal
307310
if tag.limit or tag.limitVar or tag.limitStat then
308-
local limit = tag.limit or tag.limitVar and limitTarget:GetMultiplier(tag.limitVar, cfg) or tag.limitStat and limitTarget:GetStat(tag.limitStat, cfg)
311+
local limit = tag.limit or tag.limitVar and GetMultiplier(limitTarget, tag.limitVar, cfg) or tag.limitStat and GetStat(limitTarget, tag.limitStat, cfg)
309312
if tag.limitTotal then
310313
limitTotal = limit
311314
elseif tag.limitNegTotal then
@@ -347,6 +350,14 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
347350
end
348351
elseif tag.type == "MultiplierThreshold" then
349352
local target = self
353+
local thresholdTarget = self
354+
if tag.thresholdActor then
355+
if self.actor[tag.thresholdActor] then
356+
thresholdTarget = self.actor[tag.thresholdActor].modDB
357+
else
358+
return
359+
end
360+
end
350361
if tag.actor then
351362
if self.actor[tag.actor] then
352363
target = self.actor[tag.actor].modDB
@@ -357,13 +368,13 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
357368
local mult = 0
358369
if tag.varList then
359370
for _, var in pairs(tag.varList) do
360-
mult = mult + target:GetMultiplier(var, cfg)
371+
mult = mult + GetMultiplier(target, var, cfg)
361372
end
362373
else
363-
mult = target:GetMultiplier(tag.var, cfg)
374+
mult = GetMultiplier(target, tag.var, cfg)
364375
end
365-
local threshold = tag.threshold or target:GetMultiplier(tag.thresholdVar, cfg)
366-
if (tag.upper and mult > threshold) or (not tag.upper and mult < threshold) then
376+
local threshold = tag.threshold or GetMultiplier(thresholdTarget, tag.thresholdVar, cfg)
377+
if (tag.upper and mult > threshold) or (tag.equals and mult ~= threshold) or (not (tag.upper and tag.exact) and mult < threshold) then
367378
return
368379
end
369380
elseif tag.type == "PerStat" then
@@ -377,15 +388,18 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
377388
if tag.statList then
378389
base = 0
379390
for _, stat in ipairs(tag.statList) do
380-
base = base + target:GetStat(stat, cfg)
391+
base = base + GetStat(target, stat, cfg)
381392
end
382393
else
383-
base = target:GetStat(tag.stat, cfg)
394+
base = GetStat(target, tag.stat, cfg)
395+
end
396+
if tag.divVar then
397+
tag.div = GetMultiplier(self, tag.divVar, cfg)
384398
end
385399
local mult = m_floor(base / (tag.div or 1) + 0.0001)
386400
local limitTotal
387401
if tag.limit or tag.limitVar then
388-
local limit = tag.limit or self:GetMultiplier(tag.limitVar, cfg)
402+
local limit = tag.limit or GetMultiplier(self, tag.limitVar, cfg)
389403
if tag.limitTotal then
390404
limitTotal = limit
391405
else
@@ -422,19 +436,19 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
422436
if tag.statList then
423437
base = 0
424438
for _, stat in ipairs(tag.statList) do
425-
base = base + target:GetStat(stat, cfg)
439+
base = base + GetStat(target, stat, cfg)
426440
end
427441
else
428-
base = target:GetStat(tag.stat, cfg)
442+
base = GetStat(target, tag.stat, cfg)
429443
end
430-
local percent = tag.percent or self:GetMultiplier(tag.percentVar, cfg)
444+
local percent = tag.percent or GetMultiplier(self, tag.percentVar, cfg)
431445
local mult = base * (percent and percent / 100 or 1)
432446
if tag.floor then
433447
mult = m_floor(mult)
434448
end
435449
local limitTotal
436450
if tag.limit or tag.limitVar then
437-
local limit = tag.limit or self:GetMultiplier(tag.limitVar, cfg)
451+
local limit = tag.limit or GetMultiplier(self, tag.limitVar, cfg)
438452
if tag.limitTotal then
439453
limitTotal = limit
440454
else
@@ -465,14 +479,14 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
465479
if tag.statList then
466480
stat = 0
467481
for _, stat in ipairs(tag.statList) do
468-
stat = stat + self:GetStat(stat, cfg)
482+
stat = stat + GetStat(self, stat, cfg)
469483
end
470484
else
471-
stat = self:GetStat(tag.stat, cfg)
485+
stat = GetStat(self, tag.stat, cfg)
472486
end
473-
local threshold = tag.threshold or self:GetStat(tag.thresholdStat, cfg)
487+
local threshold = tag.threshold or GetStat(self, tag.thresholdStat, cfg)
474488
if tag.thresholdPercent or tag.thresholdPercentVar then
475-
local thresholdPercent = tag.thresholdPercent or self:GetMultiplier(tag.thresholdPercentVar, cfg)
489+
local thresholdPercent = tag.thresholdPercent or GetMultiplier(self, tag.thresholdPercentVar, cfg)
476490
threshold = threshold * (thresholdPercent and thresholdPercent / 100 or 1)
477491
end
478492
if (tag.upper and stat > threshold) or (not tag.upper and stat < threshold) then
@@ -524,18 +538,18 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
524538
if not allOneH["Added"..var] then
525539
return
526540
end
527-
elseif self:GetCondition(var, cfg) or (cfg and cfg.skillCond and cfg.skillCond[var]) then
541+
elseif GetCondition(self, var, cfg) or (cfg and cfg.skillCond and cfg.skillCond[var]) then
528542
match = true
529543
break
530544
end
531545
end
532546
else
533547
if tag.neg and allOneH and allOneH["Added"..tag.var] ~= nil then
534-
if not allOneH["Added"..var] then
548+
if not allOneH["Added"..tag.var] then
535549
return
536550
end
537551
else
538-
match = self:GetCondition(tag.var, cfg) or (cfg and cfg.skillCond and cfg.skillCond[tag.var])
552+
match = GetCondition(self, tag.var, cfg) or (cfg and cfg.skillCond and cfg.skillCond[tag.var])
539553
end
540554
end
541555
if tag.neg then
@@ -553,13 +567,13 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
553567
if target and (tag.var or tag.varList) then
554568
if tag.varList then
555569
for _, var in pairs(tag.varList) do
556-
if target:GetCondition(var, cfg) then
570+
if GetCondition(target, var, cfg) then
557571
match = true
558572
break
559573
end
560574
end
561575
else
562-
match = target:GetCondition(tag.var, cfg)
576+
match = GetCondition(target, tag.var, cfg)
563577
end
564578
elseif tag.actor and cfg and tag.actor == cfg.actor then
565579
match = true
@@ -805,8 +819,7 @@ function ModStoreClass:EvalMod(mod, cfg, globalLimits)
805819

806820
-- validate for actor and minionData
807821
for _, tagList in pairs(self.actor.minionData.monsterTags) do
808-
local matchName = tagList
809-
matchName = matchName:lower()
822+
local matchName = tagList:lower()
810823
if tag.monsterTagList then
811824
for _, name in pairs(tag.monsterTagList) do
812825
if name:lower() == matchName then

0 commit comments

Comments
 (0)