Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions spec/System/TestTradeQueryGenerator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@ describe("TradeQueryGenerator", function()
-- Simplified assertion; in full impl, check modData
assert.is_true(true)
end)

it("prefers the trade stat exported by the mod over a sibling that differs only by sign", function()
local queryGen = new("TradeQueryGenerator"):TradeQueryGenerator({ itemsTab = {} })
queryGen.modData = { Implicit = { } }
local mod = copyTable(data.itemMods.ItemExclusive.StaffSpellBlockPercent3)
mod.type = "Implicit"

queryGen:ProcessMod("", mod, nil, nil, { Staff = true })

assert.are.equals("implicit.stat_19803471", queryGen.modData.Implicit["2138_AdditionalSpellBlock"].tradeMod.id)
end)

it("keeps label order when the exported trade stat has an identical label", function()
local queryGen = new("TradeQueryGenerator"):TradeQueryGenerator({ itemsTab = {} })
queryGen.modData = { Explicit = { } }
local mod = copyTable(data.itemMods.Item.ChanceToDodge1)

queryGen:ProcessMod("", mod, nil, nil, { Boots = true })

assert.are.equals("explicit.stat_3680664274", queryGen.modData.Explicit["814_ChanceToSuppressSpellsOld"].tradeMod.id)
end)

it("skips a trade stat whose fixed number differs from the mod line, even when a roll range contains it", function()
local queryGen = new("TradeQueryGenerator"):TradeQueryGenerator({ itemsTab = {} })
queryGen.modData = { Explicit = { } }
-- "(8-10)% chance to gain Onslaught for 4 seconds on Kill": the label "for 10 seconds" sorts first.
-- Two trade stats share the "4 seconds" label, so the label is asserted rather than one of their ids.
local mod = copyTable(data.itemMods.Item.OnslaughtOnKillInfluenceMaven)

queryGen:ProcessMod("", mod, nil, nil, { Boots = true })

assert.are.equals("#% chance to gain Onslaught for 4 seconds on Kill", queryGen.modData.Explicit["2687_ChanceToGainOnslaughtOnKillMaven"].tradeMod.text)
end)
end)

describe("Talisman mods", function()
Expand Down
73 changes: 61 additions & 12 deletions src/Classes/TradeQueryGenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,63 @@ local function getStatEntries(modType)
end
end

-- Number tokens of a trade label or mod line, in order: "#" for a value position, the number otherwise.
-- A range such as "(10-15)" is a value position too, so a rolled value never stands in for a fixed number.
local function getNumberTokens(text)
local tokens = { }
for token in text:gsub("%(%-?[%d%.]+%-%-?[%d%.]+%)", "#"):gmatch("[#%d][%d%.]*") do
tokens[#tokens + 1] = token
end
return tokens
end

-- True when every fixed number of the trade label equals the mod line's number at the same position.
local function fixedNumbersMatch(tradeText, modLine)
local tradeTokens, modTokens = getNumberTokens(tradeText), getNumberTokens(modLine)
if #tradeTokens ~= #modTokens then
return false
end
for index, token in ipairs(tradeTokens) do
if token ~= "#" and tonumber(token) ~= tonumber(modTokens[index]) then
return false
end
end
return true
end

-- Find the trade stat whose label, without signs and numbers, equals strippedText.
-- "#% increased Spell Damage per 10 Intelligence" and "... per 16 Intelligence" are distinct trade stats with the
-- same stripped label, so labels whose fixed numbers disagree with modLine are skipped unless none agree.
-- "#% Chance to Block Attack Damage" and "+#% Chance to Block Attack Damage" are distinct trade stats, and the
-- first one in label order is not the one items carry, so when labels differ only by sign, prefer the stat the
-- mod exports in tradeHashes. Identical labels keep label order: legacy mods export hashes Trade no longer lists.
local function findTradeStatByStrippedText(entries, strippedText, tradeHashes, modLine)
local matches, numberMatches = { }, { }
for _, entry in ipairs(entries or { }) do
if entry.text:gsub("[#()0-9%-%+%.]","") == strippedText then
matches[#matches + 1] = entry
if fixedNumbersMatch(entry.text, modLine) then
numberMatches[#numberMatches + 1] = entry
end
end
end
if #numberMatches > 0 then
matches = numberMatches
end
local firstMatch, exportedMatch = matches[1], nil
for _, entry in ipairs(matches) do
local tradeHash = tonumber(entry.id:match("%.stat_(%d+)$"))
if tradeHash and tradeHashes and tradeHashes[tradeHash] then
exportedMatch = entry
break
end
end
if exportedMatch and exportedMatch.text ~= firstMatch.text and exportedMatch.text:gsub("[%+%-]","") == firstMatch.text:gsub("[%+%-]","") then
return exportedMatch
end
return firstMatch
end

-- slots that allow eldritch mods (non-unique only)
local eldritchModSlots = {
["Body Armour"] = true,
Expand Down Expand Up @@ -252,22 +309,14 @@ function TradeQueryGeneratorClass:ProcessMod(modId, mod, tradeQueryStatsParsed,
-- Try to match to a local mod fallback to global if no match
if mod.group:match("Local") then
local matchLocalStr = (modLine .. " (Local)"):gsub("[#()0-9%-%+%.]","")
for _, entry in pairs(getStatEntries(modType) or {}) do
if entry.text:gsub("[#()0-9%-%+%.]","") == matchLocalStr then
tradeMod = entry
specialCaseData.overrideModLine = entry.text:sub(1,-9)
break
end
tradeMod = findTradeStatByStrippedText(getStatEntries(modType), matchLocalStr, mod.tradeHashes, modLine)
if tradeMod then
specialCaseData.overrideModLine = tradeMod.text:sub(1,-9)
end
end
if tradeMod == nil then
local matchStr = modLine:gsub("[#()0-9%-%+%.]","")
for _, entry in ipairs(getStatEntries(modType) or {}) do
if entry.text:gsub("[#()0-9%-%+%.]","") == matchStr then
tradeMod = entry
break
end
end
tradeMod = findTradeStatByStrippedText(getStatEntries(modType), matchStr, mod.tradeHashes, modLine)
end
if tradeMod == nil then
if inverse then
Expand Down
92 changes: 46 additions & 46 deletions src/Data/QueryMods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14789,8 +14789,8 @@ return {
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2818518881",
["text"] = "#% increased Spell Damage per 10 Intelligence",
["id"] = "explicit.stat_3961014595",
["text"] = "#% increased Spell Damage per 16 Intelligence",
["type"] = "explicit",
},
},
Expand All @@ -14807,8 +14807,8 @@ return {
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_1073314277",
["text"] = "#% increased Spell Damage per 10 Strength",
["id"] = "explicit.stat_4249521944",
["text"] = "#% increased Spell Damage per 16 Strength",
["type"] = "explicit",
},
},
Expand Down Expand Up @@ -37233,22 +37233,22 @@ return {
["max"] = 20,
["min"] = 8,
},
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2530372417",
["text"] = "#% Chance to Block Attack Damage",
["id"] = "explicit.stat_1702195217",
["text"] = "+#% Chance to Block Attack Damage",
["type"] = "explicit",
},
},
["2137_BlockingBlocksSpellsUber"] = {
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2530372417",
["text"] = "#% Chance to Block Attack Damage",
["id"] = "explicit.stat_1702195217",
["text"] = "+#% Chance to Block Attack Damage",
["type"] = "explicit",
},
},
Expand All @@ -37261,12 +37261,12 @@ return {
["max"] = 5,
["min"] = 5,
},
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2530372417",
["text"] = "#% Chance to Block Attack Damage",
["id"] = "explicit.stat_1702195217",
["text"] = "+#% Chance to Block Attack Damage",
["type"] = "explicit",
},
},
Expand All @@ -37279,22 +37279,22 @@ return {
["max"] = 5,
["min"] = 5,
},
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2530372417",
["text"] = "#% Chance to Block Attack Damage",
["id"] = "explicit.stat_1702195217",
["text"] = "+#% Chance to Block Attack Damage",
["type"] = "explicit",
},
},
["2137_SpellBlockAndBlockUber"] = {
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2530372417",
["text"] = "#% Chance to Block Attack Damage",
["id"] = "explicit.stat_1702195217",
["text"] = "+#% Chance to Block Attack Damage",
["type"] = "explicit",
},
},
Expand All @@ -37319,12 +37319,12 @@ return {
["max"] = 20,
["min"] = 8,
},
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_561307714",
["text"] = "#% Chance to Block Spell Damage",
["id"] = "explicit.stat_19803471",
["text"] = "+#% Chance to Block Spell Damage",
["type"] = "explicit",
},
},
Expand Down Expand Up @@ -40203,8 +40203,8 @@ return {
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2453026567",
["text"] = "#% chance to gain Onslaught for 10 seconds on Kill",
["id"] = "explicit.stat_3023957681",
["text"] = "#% chance to gain Onslaught for 4 seconds on Kill",
["type"] = "explicit",
},
},
Expand All @@ -40221,8 +40221,8 @@ return {
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2453026567",
["text"] = "#% chance to gain Onslaught for 10 seconds on Kill",
["id"] = "explicit.stat_3023957681",
["text"] = "#% chance to gain Onslaught for 4 seconds on Kill",
["type"] = "explicit",
},
},
Expand All @@ -40235,8 +40235,8 @@ return {
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2453026567",
["text"] = "#% chance to gain Onslaught for 10 seconds on Kill",
["id"] = "explicit.stat_3023957681",
["text"] = "#% chance to gain Onslaught for 4 seconds on Kill",
["type"] = "explicit",
},
},
Expand All @@ -40249,8 +40249,8 @@ return {
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2453026567",
["text"] = "#% chance to gain Onslaught for 10 seconds on Kill",
["id"] = "explicit.stat_3023957681",
["text"] = "#% chance to gain Onslaught for 4 seconds on Kill",
["type"] = "explicit",
},
},
Expand Down Expand Up @@ -42362,8 +42362,8 @@ return {
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_2453026567",
["text"] = "#% chance to gain Onslaught for 10 seconds on Kill",
["id"] = "explicit.stat_3023957681",
["text"] = "#% chance to gain Onslaught for 4 seconds on Kill",
["type"] = "explicit",
},
},
Expand Down Expand Up @@ -45372,8 +45372,8 @@ return {
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_889691035",
["text"] = "#% increased Attack Speed per 10 Dexterity",
["id"] = "explicit.stat_2241560081",
["text"] = "#% increased Attack Speed per 25 Dexterity",
["type"] = "explicit",
},
},
Expand Down Expand Up @@ -52440,12 +52440,12 @@ return {
["max"] = 15,
["min"] = 15,
},
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "explicit.stat_4070519133",
["text"] = "#% Chance to Block Spell Damage while on Low Life",
["id"] = "explicit.stat_2253286128",
["text"] = "+#% Chance to Block Spell Damage while on Low Life",
["type"] = "explicit",
},
},
Expand Down Expand Up @@ -60043,12 +60043,12 @@ return {
["max"] = 25,
["min"] = 20,
},
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "implicit.stat_2530372417",
["text"] = "#% Chance to Block Attack Damage",
["id"] = "implicit.stat_1702195217",
["text"] = "+#% Chance to Block Attack Damage",
["type"] = "implicit",
},
},
Expand All @@ -60057,12 +60057,12 @@ return {
["max"] = 6,
["min"] = 3,
},
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "implicit.stat_2530372417",
["text"] = "#% Chance to Block Attack Damage",
["id"] = "implicit.stat_1702195217",
["text"] = "+#% Chance to Block Attack Damage",
["type"] = "implicit",
},
},
Expand All @@ -60075,12 +60075,12 @@ return {
["max"] = 25,
["min"] = 20,
},
["sign"] = "+",
["sign"] = "",
["specialCaseData"] = {
},
["tradeMod"] = {
["id"] = "implicit.stat_561307714",
["text"] = "#% Chance to Block Spell Damage",
["id"] = "implicit.stat_19803471",
["text"] = "+#% Chance to Block Spell Damage",
["type"] = "implicit",
},
},
Expand Down
Loading