Skip to content

Commit ce01a7b

Browse files
Support trade inversed mods and improve flask mod's behaviour in trader (#6118)
* Try to invert mods if they don't parse normally this lets more be parsed. * Fix jewel block * cleanup * Fix faster/slower
1 parent c664910 commit ce01a7b

File tree

2 files changed

+1230
-11
lines changed

2 files changed

+1230
-11
lines changed

src/Classes/TradeQueryGenerator.lua

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ local itemCategoryTags = {
3737
["AbyssJewel"] = { ["default"] = true, ["abyss_jewel"] = true, ["abyss_jewel_melee"] = true, ["abyss_jewel_ranged"] = true, ["abyss_jewel_summoner"] = true, ["abyss_jewel_caster"] = true },
3838
["BaseJewel"] = { ["default"] = true, ["jewel"] = true, ["not_int"] = true, ["not_str"] = true, ["not_dex"] = true },
3939
["AnyJewel"] = { ["default"] = true, ["jewel"] = true, ["not_int"] = true, ["not_str"] = true, ["not_dex"] = true, ["abyss_jewel"] = true, ["abyss_jewel_melee"] = true, ["abyss_jewel_ranged"] = true, ["abyss_jewel_summoner"] = true, ["abyss_jewel_caster"] = true },
40-
["Flask"] = { ["flask"] = true, ["hybrid_flask"] = true, ["utility_flask"] = true, ["mana_flask"] = true, ["life_flask"] = true, ["expedition_flask"] = true, ["critical_utility_flask"] = true }
40+
["Flask"] = { ["default"] = true, ["flask"] = true, ["hybrid_flask"] = true, ["utility_flask"] = true, ["mana_flask"] = true, ["life_flask"] = true, ["expedition_flask"] = true, ["critical_utility_flask"] = true }
4141
}
4242

4343
local craftedCategoryTags = {
@@ -203,7 +203,7 @@ function TradeQueryGeneratorClass:ProcessMod(modId, mod, tradeQueryStatsParsed,
203203

204204
-- Special cases
205205
local specialCaseData = { }
206-
if mod.group and mod.group:find("Shield") and modLine:find("Chance to Block") then
206+
if mod.group and (mod.group:find("Local") or mod.group:find("Shield")) and modLine:find("Chance to Block$") then
207207
specialCaseData.overrideModLine = "+#% Chance to Block"
208208
modLine = modLine .. " (Shields)"
209209
elseif modLine == "You can apply an additional Curse" then
@@ -214,7 +214,10 @@ function TradeQueryGeneratorClass:ProcessMod(modId, mod, tradeQueryStatsParsed,
214214
modLine = "Bow Attacks fire 1 additional Arrows"
215215
elseif modLine == "Projectiles Pierce an additional Target" then
216216
specialCaseData.overrideModLineSingular = "Projectiles Pierce an additional Target"
217-
modLine = "Projectiles Pierce 1 additional Target"
217+
modLine = "Projectiles Pierce 1 additional Targets"
218+
elseif modLine == "Has 1 Abyssal Socket" then
219+
specialCaseData.overrideModLineSingular = "Has 1 Abyssal Socket"
220+
modLine = "Has 1 Abyssal Sockets"
218221
end
219222

220223
-- If this is the first tier for this mod, find matching trade mod and init the entry
@@ -223,10 +226,37 @@ function TradeQueryGeneratorClass:ProcessMod(modId, mod, tradeQueryStatsParsed,
223226
goto continue
224227
end
225228

229+
local function swapInverse(modLine)
230+
local priorStr = modLine
231+
local inverseKey
232+
if modLine:match("increased") then
233+
modLine = modLine:gsub("([^ ]+) increased", "-%1 reduced")
234+
if modLine ~= priorStr then inverseKey = "increased" end
235+
elseif modLine:match("reduced") then
236+
modLine = modLine:gsub("([^ ]+) reduced", "-%1 increased")
237+
if modLine ~= priorStr then inverseKey = "reduced" end
238+
elseif modLine:match("more") then
239+
modLine = modLine:gsub("([^ ]+) more", "-%1 less")
240+
if modLine ~= priorStr then inverseKey = "more" end
241+
elseif modLine:match("less") then
242+
modLine = modLine:gsub("([^ ]+) less", "-%1 more")
243+
if modLine ~= priorStr then inverseKey = "less" end
244+
elseif modLine:match("expires ([^ ]+) slower") then
245+
modLine = modLine:gsub("([^ ]+) slower", "-%1 faster")
246+
if modLine ~= priorStr then inverseKey = "slower" end
247+
elseif modLine:match("expires ([^ ]+) faster") then
248+
modLine = modLine:gsub("([^ ]+) faster", "-%1 slower")
249+
if modLine ~= priorStr then inverseKey = "faster" end
250+
end
251+
return modLine, inverseKey
252+
end
253+
226254
local uniqueIndex = tostring(statOrder).."_"..mod.group
255+
local inverse = false
256+
local inverseKey
257+
::reparseMod::
227258
if self.modData[modType][uniqueIndex] == nil then
228259
local tradeMod = nil
229-
230260
-- Try to match to a local mod fallback to global if no match
231261
if mod.group:match("Local") then
232262
local matchLocalStr = (modLine .. " (Local)"):gsub("[#()0-9%-%+%.]","")
@@ -248,11 +278,25 @@ function TradeQueryGeneratorClass:ProcessMod(modId, mod, tradeQueryStatsParsed,
248278
end
249279
end
250280
if tradeMod == nil then
251-
logToFile("Unable to match %s mod: %s", modType, modLine)
252-
goto nextModLine
281+
if inverse then
282+
logToFile("Unable to match %s mod: %s", modType, modLine)
283+
goto nextModLine
284+
else -- try swapping increased / decreased and signed and other similar mods.
285+
modLine, inverseKey = swapInverse(modLine)
286+
inverse = true
287+
if inverseKey then
288+
goto reparseMod
289+
else
290+
logToFile("Unable to match %s mod: %s", modType, modLine)
291+
goto nextModLine
292+
end
293+
end
253294
end
254295

255-
self.modData[modType][uniqueIndex] = { tradeMod = tradeMod, specialCaseData = specialCaseData }
296+
self.modData[modType][uniqueIndex] = { tradeMod = tradeMod, specialCaseData = specialCaseData, inverseKey = inverseKey }
297+
elseif self.modData[modType][uniqueIndex].inverseKey and modLine:match(self.modData[modType][uniqueIndex].inverseKey) then
298+
inverse = true
299+
modLine = swapInverse(modLine)
256300
end
257301

258302
-- tokenize the numerical variables for this mod and store the sign if there is one
@@ -263,16 +307,31 @@ function TradeQueryGeneratorClass:ProcessMod(modId, mod, tradeQueryStatsParsed,
263307
if poundPos == nil then
264308
break
265309
end
266-
startPos, endPos, sign, min, max = modLine:find("([%+%-]?)%(?(%d+%.?%d*)%-?(%d*%.?%d*)%)?", poundPos + tokenizeOffset)
310+
311+
local startPos, endPos, sign, min, max = modLine:find("([%+%-]?)%(?(%d+%.?%d*)%-?(%d*%.?%d*)%)?", poundPos + tokenizeOffset)
267312

268313
if endPos == nil then
269314
logToFile("[GMD] Error extracting tokens from '%s' for tradeMod '%s'", modLine, self.modData[modType][uniqueIndex].tradeMod.text)
270315
goto nextModLine
271316
end
272317

318+
max = #max > 0 and tonumber(max) or tonumber(min)
319+
273320
tokenizeOffset = tokenizeOffset + (endPos - startPos)
321+
322+
if inverse then
323+
sign = nil
324+
min = -min
325+
max = -max
326+
if min > max then
327+
local temp = max
328+
max = min
329+
min = temp
330+
end
331+
end
332+
274333
table.insert(tokens, min)
275-
table.insert(tokens, #max > 0 and tonumber(max) or tonumber(min))
334+
table.insert(tokens, max)
276335
if sign ~= nil then
277336
self.modData[modType][uniqueIndex].sign = sign
278337
end
@@ -359,7 +418,6 @@ function TradeQueryGeneratorClass:InitMods()
359418
end
360419
end
361420
self:GenerateModData(data.itemMods.Item, tradeQueryStatsParsed, regularItemMask)
362-
self:GenerateModData(data.veiledMods, tradeQueryStatsParsed, regularItemMask)
363421
self:GenerateModData(data.itemMods.Jewel, tradeQueryStatsParsed, { ["BaseJewel"] = true, ["AnyJewel"] = true })
364422
self:GenerateModData(data.itemMods.JewelAbyss, tradeQueryStatsParsed, { ["AbyssJewel"] = true, ["AnyJewel"] = true })
365423
self:GenerateModData(data.itemMods.Flask, tradeQueryStatsParsed, { ["Flask"] = true })
@@ -381,6 +439,7 @@ function TradeQueryGeneratorClass:InitMods()
381439

382440
regularItemMask.Flask = true -- Update mask as flasks can have crafted mods.
383441
self:GenerateModData(data.masterMods, tradeQueryStatsParsed, regularItemMask)
442+
self:GenerateModData(data.veiledMods, tradeQueryStatsParsed, regularItemMask)
384443

385444
-- megalomaniac
386445
local clusterNotableMods = {}

0 commit comments

Comments
 (0)