Skip to content

Commit 47eeb7a

Browse files
authored
fix time-lost jewel mods being added when they shouldn't (#55)
1 parent 4c80961 commit 47eeb7a

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/Modules/CalcSetup.lua

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,42 @@ local function setRadiusJewelStats(radiusJewel, radiusJewelStats)
9999
local function setStats(jewel, radiusJewelStats, index, alternate)
100100
local variant = (alternate and jewel.variantAlt or jewel.variant) or index
101101
local range = jewel.explicitModLines[variant].range
102+
local line = jewel.explicitModLines[variant].line
102103
local value = 0
103-
jewel.explicitModLines[variant].line:gsub("%((%d+)%-(%d+)%)",
104+
105+
line:gsub("%((%d+)%-(%d+)%)",
104106
function(num1, num2)
105107
value = round(num1 + (num2-num1) * range)
106108
end
107109
)
108110
radiusJewelStats[index] = {
109-
isNotable = (jewel.explicitModLines[variant].line:match("^(%S+)") == "Notable"),
110-
sd = jewel.explicitModLines[variant].line:gsub(".*grant ", ""):gsub("%(.-%)", value)
111+
isNotable = (line:match("^(%S+)") == "Notable"),
112+
toAdd = (line:find("also% grant")~= nil), -- only add mods with the "also grant" text to radiusNodes
113+
sd = line:gsub(".*grant ", ""):gsub("%(.-%)", value)
111114
}
112115
end
113116

114117
local jewel = radiusJewel.item
115-
if jewel.baseName:find("Time%-Lost") == 1 then
118+
if jewel.baseName:find("Time%-Lost") ~= nil then
116119
radiusJewelStats.source = radiusJewel.data.modSource
117120
if jewel.title == "Against the Darkness" then
118121
setStats(jewel, radiusJewelStats, 1, false)
119122
setStats(jewel, radiusJewelStats, 2, true)
120123
else
121-
for modIndex, _ in ipairs(jewel.explicitModLines) do
124+
local jewelModLines = copyTable(jewel.explicitModLines, true)
125+
-- sanitize mods in case of line breaks
126+
for id, mod in ipairs(jewelModLines) do
127+
local line1, line2 = mod.line:match("^(.-)\n(.*)$")
128+
-- if a line break is found, copy the modLineTable, modify the original with the first string
129+
-- and add the table with second string to the end
130+
if line1 and line2 then
131+
jewel.explicitModLines[id].line = line1
132+
local linebreakMod = copyTable(jewel.explicitModLines[id])
133+
linebreakMod.line = line2
134+
t_insert(jewel.explicitModLines, linebreakMod)
135+
end
136+
end
137+
for modIndex, _ in ipairs(jewelModLines) do
122138
setStats(jewel, radiusJewelStats, modIndex, false)
123139
end
124140
end
@@ -136,8 +152,9 @@ local function addStats(jewel, node, spec)
136152
local radiusJewelStats = { }
137153
setRadiusJewelStats(jewel, radiusJewelStats)
138154
for _, stat in ipairs(radiusJewelStats) do
139-
-- the node and jewelStat types match, add sd to node if it's not already there
140-
if not isValueInTable(node.sd, stat.sd) and ((node.type == "Notable" and stat.isNotable) or (node.type ~= "Notable" and not stat.isNotable)) then
155+
-- the node and stat types match, add sd to node if it's not already there and it's an 'also grant' mod
156+
if not isValueInTable(node.sd, stat.sd) and ((node.type == "Notable" and stat.isNotable) or (node.type == "Normal" and not stat.isNotable))
157+
and stat.toAdd then
141158
t_insert(node.sd, stat.sd)
142159
end
143160
end
@@ -149,7 +166,7 @@ local function addStatsFromJewelToNode(jewel, node, spec)
149166
-- attribute nodes do not count as Small Passives
150167
if not node.isAttribute then
151168
local itemsTab = spec.build.itemsTab
152-
-- if Against the Darkness is socketed, add the stat
169+
-- if the Time-Lost jewel is socketed, add the stat
153170
if itemsTab.activeSocketList then
154171
for _, nodeId in pairs(itemsTab.activeSocketList) do
155172
local _, socketedJewel = itemsTab:GetSocketAndJewelForNodeID(nodeId)
@@ -174,7 +191,7 @@ function calcs.buildModListForNode(env, node, incSmallPassiveSkill)
174191
-- Run first pass radius jewels
175192
for _, rad in pairs(env.radiusJewelList) do
176193
if rad.type == "Other" and rad.nodes[node.id] and rad.nodes[node.id].type ~= "Mastery" then
177-
if rad.item.baseName:find("Time%-Lost") ~= 1 then
194+
if rad.item.baseName:find("Time%-Lost") == nil then
178195
rad.func(node, modList, rad.data)
179196
else
180197
local nodeList = addStatsFromJewelToNode(rad, node, env.build.spec)
@@ -198,7 +215,7 @@ function calcs.buildModListForNode(env, node, incSmallPassiveSkill)
198215
-- Run second pass radius jewels
199216
for _, rad in pairs(env.radiusJewelList) do
200217
if rad.nodes[node.id] and rad.nodes[node.id].type ~= "Mastery" and (rad.type == "Threshold" or (rad.type == "Self" and env.allocNodes[node.id]) or (rad.type == "SelfUnalloc" and not env.allocNodes[node.id])) then
201-
if rad.item.baseName:find("Time%-Lost") ~= 1 then
218+
if rad.item.baseName:find("Time%-Lost") == nil then
202219
rad.func(node, modList, rad.data)
203220
else
204221
local nodeList = addStatsFromJewelToNode(rad, node, env.build.spec)

0 commit comments

Comments
 (0)