@@ -82,6 +82,11 @@ local tradeStatCategoryIndices = {
8282 [" PassiveNode" ] = 2 ,
8383}
8484
85+ -- Strips numeric tokens and punctuation for text-based mod matching.
86+ local function normalizeModText (text )
87+ return text :gsub (" [#()0-9%-%+%.]" ," " ):gsub (" %s+" , " " )
88+ end
89+
8590local influenceSuffixes = { " _shaper" , " _elder" , " _adjudicator" , " _basilisk" , " _crusader" , " _eyrie" }
8691local influenceDropdownNames = { " None" }
8792local hasInfluenceModIds = { }
@@ -125,21 +130,21 @@ local function normTradeText(text)
125130 return (text :match (" ^%s*(.-)%s*$" ))
126131end
127132
128- -- Forward declaration — defined below, after the class method definitions.
133+ -- Forward declaration - defined below, after the class method definitions.
129134local buildAndCachePseudoMapping
130135
131136-- Hard-coded fallbacks for pseudo texts that don't normalize to the same form as any explicit/implicit text.
132137-- Key = normalized pseudo text; value = list of explicit/implicit tradeModIds to map to that pseudo.
133138local pseudoNormFallbacks = {
134- -- Pseudo "+#% total Attack Speed" → "attack speed"; explicit "#% increased Attack Speed" → "increased attack speed"
139+ -- Pseudo "+#% total Attack Speed" -> "attack speed"; explicit "#% increased Attack Speed" -> "increased attack speed"
135140 [" attack speed" ] = { " explicit.stat_681332047" , " implicit.stat_681332047" },
136- -- Pseudo "+#% total Cast Speed" → "cast speed"; explicit "#% increased Cast Speed" → "increased cast speed"
141+ -- Pseudo "+#% total Cast Speed" -> "cast speed"; explicit "#% increased Cast Speed" -> "increased cast speed"
137142 [" cast speed" ] = { " explicit.stat_2891184298" , " implicit.stat_2891184298" },
138- -- Pseudo "+#% Global Critical Strike Chance" → "global critical strike chance";
139- -- explicit "#% increased Global Critical Strike Chance" → "increased global critical strike chance"
143+ -- Pseudo "+#% Global Critical Strike Chance" -> "global critical strike chance";
144+ -- explicit "#% increased Global Critical Strike Chance" -> "increased global critical strike chance"
140145 [" global critical strike chance" ] = { " explicit.stat_587431675" , " implicit.stat_587431675" },
141- -- Pseudo "+#% total Critical Strike Chance for Spells" → "critical strike chance for spells";
142- -- explicit "#% increased Critical Strike Chance for Spells" → "increased critical strike chance for spells"
146+ -- Pseudo "+#% total Critical Strike Chance for Spells" -> "critical strike chance for spells";
147+ -- explicit "#% increased Critical Strike Chance for Spells" -> "increased critical strike chance for spells"
143148 [" critical strike chance for spells" ] = { " explicit.stat_737908626" , " implicit.stat_737908626" },
144149}
145150
@@ -456,6 +461,9 @@ function TradeQueryGeneratorClass:InitMods()
456461 end
457462 else
458463 local tradeStats = fetchStats ()
464+ if not tradeStats then
465+ return
466+ end
459467 tradeStats :gsub (" \n " , " " )
460468 local tradeQueryStatsParsed = dkjson .decode (tradeStats )
461469 buildAndCachePseudoMapping (tradeQueryStatsParsed )
@@ -476,6 +484,9 @@ function TradeQueryGeneratorClass:InitMods()
476484
477485 -- originates from: https://www.pathofexile.com/api/trade/data/stats
478486 local tradeStats = fetchStats ()
487+ if not tradeStats then
488+ return
489+ end
479490 tradeStats :gsub (" \n " , " " )
480491 local tradeQueryStatsParsed = dkjson .decode (tradeStats )
481492
@@ -1122,7 +1133,7 @@ function TradeQueryGeneratorClass:CountCraftedAffixesFromModLines(modLines, item
11221133 for modId , mod in pairs (pool ) do
11231134 if mod .types then -- only crafted mods use types instead of weightKey/weightVal
11241135 for _ , line in ipairs (mod ) do
1125- local key = line : gsub ( " [#()0-9%-%+%.] " , " " ): gsub ( " %s+ " , " " ):match (" ^%s*(.-)%s*$" )
1136+ local key = normalizeModText ( line ):match (" ^%s*(.-)%s*$" )
11261137 if key ~= " " and not lineToAffix [key ] then
11271138 lineToAffix [key ] = { affixType = mod .type , modId = modId }
11281139 end
@@ -1137,7 +1148,7 @@ function TradeQueryGeneratorClass:CountCraftedAffixesFromModLines(modLines, item
11371148 local prefixCount , suffixCount = 0 , 0
11381149 for _ , modLine in ipairs (modLines ) do
11391150 if modLine .crafted then
1140- local key = modLine .line : gsub ( " [#()0-9%-%+%.] " , " " ): gsub ( " %s+ " , " " ):match (" ^%s*(.-)%s*$" )
1151+ local key = normalizeModText ( modLine .line ):match (" ^%s*(.-)%s*$" )
11411152 local match = lineToAffix [key ]
11421153 if match and not seenModIds [match .modId ] then
11431154 seenModIds [match .modId ] = true
@@ -1311,32 +1322,35 @@ function TradeQueryGeneratorClass:FinishQuery()
13111322 -- maps to the (Local) trade stat rather than the global ring/jewel version.
13121323 local function buildTextLookup (modTypeData , preferLocal )
13131324 local lookup = {}
1314- local localOverrides = {}
1325+ -- Only allocate the local-override table when the caller needs it.
1326+ local localOverrides = preferLocal and {} or nil
13151327 for _ , entry in pairs (modTypeData ) do
1316- local key = entry .tradeMod .text : gsub ( " [#()0-9%-%+%.] " , " " ): gsub ( " %s+ " , " " )
1328+ local key = normalizeModText ( entry .tradeMod .text )
13171329 if key ~= " " and not lookup [key ] then
13181330 lookup [key ] = entry .tradeMod .id
13191331 end
13201332 -- overrideModLine is set for "(Local)" trade stats; its value is the item
13211333 -- display text without " (Local)", which is what modLine.line will contain.
1322- local overrideLine = entry .specialCaseData and entry .specialCaseData .overrideModLine
1323- if overrideLine then
1324- local overrideKey = overrideLine :gsub (" [#()0-9%-%+%.]" ," " ):gsub (" %s+" , " " )
1325- if overrideKey ~= " " then
1326- localOverrides [overrideKey ] = entry .tradeMod .id
1334+ if localOverrides then
1335+ local overrideLine = entry .specialCaseData and entry .specialCaseData .overrideModLine
1336+ if overrideLine then
1337+ local overrideKey = normalizeModText (overrideLine )
1338+ if overrideKey ~= " " then
1339+ localOverrides [overrideKey ] = entry .tradeMod .id
1340+ end
13271341 end
13281342 end
13291343 local singular = entry .specialCaseData and entry .specialCaseData .overrideModLineSingular
13301344 if singular then
1331- local singKey = singular : gsub ( " [#()0-9%-%+%.] " , " " ): gsub ( " %s+ " , " " )
1345+ local singKey = normalizeModText ( singular )
13321346 if singKey ~= " " and not lookup [singKey ] then
13331347 lookup [singKey ] = entry .tradeMod .id
13341348 end
13351349 end
13361350 end
13371351 -- Merge local overrides last so they win over any global entry with the same text.
1338- -- Only do this for item types that actually carry local mods (weapons and armour).
1339- if preferLocal then
1352+ -- Only done for item types that actually carry local mods (weapons and armour).
1353+ if localOverrides then
13401354 for k , v in pairs (localOverrides ) do
13411355 lookup [k ] = v
13421356 end
@@ -1347,11 +1361,10 @@ function TradeQueryGeneratorClass:FinishQuery()
13471361 local explicitTextToId = buildTextLookup (self .modData .Explicit , preferLocal )
13481362 local implicitTextToId = buildTextLookup (self .modData .Implicit )
13491363 if options .includeEldritch then
1350- for k , v in pairs (buildTextLookup (self .modData .Eater )) do
1351- explicitTextToId [k ] = explicitTextToId [k ] or v
1352- end
1353- for k , v in pairs (buildTextLookup (self .modData .Exarch )) do
1354- explicitTextToId [k ] = explicitTextToId [k ] or v
1364+ for _ , eldritchModType in ipairs ({ " Eater" , " Exarch" }) do
1365+ for k , v in pairs (buildTextLookup (self .modData [eldritchModType ])) do
1366+ explicitTextToId [k ] = explicitTextToId [k ] or v
1367+ end
13551368 end
13561369 end
13571370
@@ -1387,7 +1400,7 @@ function TradeQueryGeneratorClass:FinishQuery()
13871400 local function addModLines (modLines , primaryLookup , fallbackLookup )
13881401 for _ , modLine in ipairs (modLines ) do
13891402 if not modLine .crafted then
1390- local matchStr = modLine .line : gsub ( " [#()0-9%-%+%.] " , " " ): gsub ( " %s+ " , " " )
1403+ local matchStr = normalizeModText ( modLine .line )
13911404 local tradeModId = primaryLookup [matchStr ]
13921405 local usedFallback = false
13931406 if not tradeModId and fallbackLookup then
0 commit comments