Skip to content

Commit ff488f7

Browse files
author
LocalIdentity
committed
Dedupe CalcsTab
1 parent 4a28a50 commit ff488f7

1 file changed

Lines changed: 69 additions & 76 deletions

File tree

src/Classes/CalcsTab.lua

Lines changed: 69 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ function CalcsTabClass:PowerBuilder()
479479
local cache = { }
480480
local distanceMap = { }
481481
local distanceList = { }
482+
local masteryNodeList = { }
482483
local newPowerMax = {
483484
singleStat = 0,
484485
offence = 0,
@@ -506,6 +507,28 @@ function CalcsTabClass:PowerBuilder()
506507
self.build.spec.tree:ProcessStats(effectNode)
507508
return effectNode
508509
end
510+
511+
local function calculateAddNodePower(power, node, output, buildPathNodes)
512+
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
513+
power.singleStat = self:CalculatePowerStat(self.powerStat, output, calcBase)
514+
if node.path and not node.ascendancyName then
515+
newPowerMax.singleStat = m_max(newPowerMax.singleStat, power.singleStat)
516+
power.pathPower = power.singleStat
517+
if node.pathDist > 1 then
518+
power.pathPower = self:CalculatePowerStat(self.powerStat, calcFunc({ addNodes = buildPathNodes() }, useFullDPS), calcBase)
519+
end
520+
end
521+
elseif not self.powerStat or not self.powerStat.ignoreForNodes then
522+
power.offence, power.defence = self:CalculateCombinedOffDefStat(output, calcBase)
523+
power.singleStat = power.offence
524+
if node.path and not node.ascendancyName then
525+
newPowerMax.offence = m_max(newPowerMax.offence, power.offence)
526+
newPowerMax.defence = m_max(newPowerMax.defence, power.defence)
527+
newPowerMax.offencePerPoint = m_max(newPowerMax.offencePerPoint, power.offence / node.pathDist)
528+
newPowerMax.defencePerPoint = m_max(newPowerMax.defencePerPoint, power.defence / node.pathDist)
529+
end
530+
end
531+
end
509532

510533
local start = GetTime()
511534
local nodeIndex = 0
@@ -519,6 +542,7 @@ function CalcsTabClass:PowerBuilder()
519542
if node.modKey ~= "" and not self.mainEnv.grantedPassives[nodeId] then
520543
if node.type == "Mastery" and node.allMasteryOptions then
521544
if not (self.nodePowerMaxDepth and self.nodePowerMaxDepth < node.pathDist) then
545+
t_insert(masteryNodeList, node)
522546
for _, masteryEffect in ipairs(node.masteryEffects or { }) do
523547
local assignedNodeId = isValueInTable(self.build.spec.masterySelections, masteryEffect.effect)
524548
if not assignedNodeId or assignedNodeId == node.id then
@@ -558,29 +582,13 @@ function CalcsTabClass:PowerBuilder()
558582
cache[node.modKey] = calcFunc({ addNodes = { [node] = true } }, useFullDPS)
559583
end
560584
local output = cache[node.modKey]
561-
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
562-
node.power.singleStat = self:CalculatePowerStat(self.powerStat, output, calcBase)
563-
if node.path and not node.ascendancyName then
564-
newPowerMax.singleStat = m_max(newPowerMax.singleStat, node.power.singleStat)
565-
node.power.pathPower = node.power.singleStat
566-
local pathNodes = { }
567-
for _, node in pairs(node.path) do
568-
pathNodes[node] = true
569-
end
570-
if node.pathDist > 1 then
571-
node.power.pathPower = self:CalculatePowerStat(self.powerStat, calcFunc({ addNodes = pathNodes }, useFullDPS), calcBase)
572-
end
573-
end
574-
elseif not self.powerStat or not self.powerStat.ignoreForNodes then
575-
node.power.offence, node.power.defence = self:CalculateCombinedOffDefStat(output, calcBase)
576-
node.power.singleStat = node.power.offence
577-
if node.path and not node.ascendancyName then
578-
newPowerMax.offence = m_max(newPowerMax.offence, node.power.offence)
579-
newPowerMax.defence = m_max(newPowerMax.defence, node.power.defence)
580-
newPowerMax.offencePerPoint = m_max(newPowerMax.offencePerPoint, node.power.offence / node.pathDist)
581-
newPowerMax.defencePerPoint = m_max(newPowerMax.defencePerPoint, node.power.defence / node.pathDist)
585+
calculateAddNodePower(node.power, node, output, function()
586+
local pathNodes = { }
587+
for _, pathNode in pairs(node.path) do
588+
pathNodes[pathNode] = true
582589
end
583-
end
590+
return pathNodes
591+
end)
584592
elseif node.alloc and node.modKey ~= "" and not self.mainEnv.grantedPassives[nodeId] then
585593
if not cache[node.modKey.."_remove"] then
586594
cache[node.modKey.."_remove"] = calcFunc({ removeNodes = { [node] = true } }, useFullDPS)
@@ -622,63 +630,48 @@ function CalcsTabClass:PowerBuilder()
622630
end
623631
end
624632

625-
for nodeId, node in pairs(self.build.spec.nodes) do
626-
if node.type == "Mastery" and node.allMasteryOptions and node.modKey ~= "" and not self.mainEnv.grantedPassives[nodeId] then
627-
if not (self.nodePowerMaxDepth and self.nodePowerMaxDepth < node.pathDist) then
628-
for _, masteryEffect in ipairs(node.masteryEffects or { }) do
629-
local assignedNodeId = isValueInTable(self.build.spec.masterySelections, masteryEffect.effect)
630-
if not assignedNodeId or assignedNodeId == node.id then
631-
local effect = self.build.spec.tree.masteryEffects[masteryEffect.effect]
632-
if effect then
633-
local effectNode = buildMasteryEffectNode(node, effect)
634-
if effectNode.modKey ~= "" then
635-
if not cache[effectNode.modKey] then
636-
cache[effectNode.modKey] = calcFunc({ addNodes = { [effectNode] = true } }, useFullDPS)
637-
end
638-
local output = cache[effectNode.modKey]
639-
node.power.masteryEffects[effect.id] = { }
640-
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
641-
node.power.masteryEffects[effect.id].singleStat = self:CalculatePowerStat(self.powerStat, output, calcBase)
642-
node.power.masteryEffects[effect.id].pathPower = node.power.masteryEffects[effect.id].singleStat
643-
if node.path and not node.ascendancyName then
644-
newPowerMax.singleStat = m_max(newPowerMax.singleStat, node.power.masteryEffects[effect.id].singleStat)
645-
local pathNodes = {
646-
[effectNode] = true
647-
}
648-
for _, pathNode in pairs(node.path) do
649-
if pathNode ~= node then
650-
pathNodes[pathNode] = true
651-
end
652-
end
653-
if node.pathDist > 1 then
654-
node.power.masteryEffects[effect.id].pathPower = self:CalculatePowerStat(self.powerStat, calcFunc({ addNodes = pathNodes }, useFullDPS), calcBase)
655-
end
656-
end
657-
node.power.singleStat = m_max(node.power.singleStat or 0, node.power.masteryEffects[effect.id].singleStat)
658-
node.power.pathPower = m_max(node.power.pathPower or 0, node.power.masteryEffects[effect.id].pathPower)
659-
elseif not self.powerStat or not self.powerStat.ignoreForNodes then
660-
node.power.masteryEffects[effect.id].offence, node.power.masteryEffects[effect.id].defence = self:CalculateCombinedOffDefStat(output, calcBase)
661-
node.power.masteryEffects[effect.id].singleStat = node.power.masteryEffects[effect.id].offence
662-
if node.path and not node.ascendancyName then
663-
newPowerMax.offence = m_max(newPowerMax.offence, node.power.masteryEffects[effect.id].offence)
664-
newPowerMax.defence = m_max(newPowerMax.defence, node.power.masteryEffects[effect.id].defence)
665-
newPowerMax.offencePerPoint = m_max(newPowerMax.offencePerPoint, node.power.masteryEffects[effect.id].offence / node.pathDist)
666-
newPowerMax.defencePerPoint = m_max(newPowerMax.defencePerPoint, node.power.masteryEffects[effect.id].defence / node.pathDist)
667-
end
668-
node.power.offence = m_max(node.power.offence or 0, node.power.masteryEffects[effect.id].offence)
669-
node.power.defence = m_max(node.power.defence or 0, node.power.masteryEffects[effect.id].defence)
670-
node.power.singleStat = m_max(node.power.singleStat or 0, node.power.masteryEffects[effect.id].singleStat)
671-
end
672-
end
673-
nodeIndex = nodeIndex + 1
674-
if coroutine.running() and GetTime() - start > 100 then
675-
if self.build.powerBuilderProgressCallback then
676-
self.build.powerBuilderProgressCallback(m_floor(nodeIndex/total*100))
633+
for _, node in ipairs(masteryNodeList) do
634+
for _, masteryEffect in ipairs(node.masteryEffects or { }) do
635+
local assignedNodeId = isValueInTable(self.build.spec.masterySelections, masteryEffect.effect)
636+
if not assignedNodeId or assignedNodeId == node.id then
637+
local effect = self.build.spec.tree.masteryEffects[masteryEffect.effect]
638+
if effect then
639+
local effectNode = buildMasteryEffectNode(node, effect)
640+
if effectNode.modKey ~= "" then
641+
if not cache[effectNode.modKey] then
642+
cache[effectNode.modKey] = calcFunc({ addNodes = { [effectNode] = true } }, useFullDPS)
643+
end
644+
local output = cache[effectNode.modKey]
645+
node.power.masteryEffects[effect.id] = { }
646+
local effectPower = node.power.masteryEffects[effect.id]
647+
calculateAddNodePower(effectPower, node, output, function()
648+
local pathNodes = {
649+
[effectNode] = true
650+
}
651+
for _, pathNode in pairs(node.path) do
652+
if pathNode ~= node then
653+
pathNodes[pathNode] = true
677654
end
678-
coroutine.yield()
679-
start = GetTime()
680655
end
656+
return pathNodes
657+
end)
658+
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
659+
effectPower.pathPower = effectPower.pathPower or effectPower.singleStat
660+
node.power.singleStat = m_max(node.power.singleStat or 0, effectPower.singleStat)
661+
node.power.pathPower = m_max(node.power.pathPower or 0, effectPower.pathPower)
662+
elseif not self.powerStat or not self.powerStat.ignoreForNodes then
663+
node.power.offence = m_max(node.power.offence or 0, effectPower.offence)
664+
node.power.defence = m_max(node.power.defence or 0, effectPower.defence)
665+
node.power.singleStat = m_max(node.power.singleStat or 0, effectPower.singleStat)
666+
end
667+
end
668+
nodeIndex = nodeIndex + 1
669+
if coroutine.running() and GetTime() - start > 100 then
670+
if self.build.powerBuilderProgressCallback then
671+
self.build.powerBuilderProgressCallback(m_floor(nodeIndex/total*100))
681672
end
673+
coroutine.yield()
674+
start = GetTime()
682675
end
683676
end
684677
end

0 commit comments

Comments
 (0)