From d365e7f65d168f89bd56167a279a2aa084da6d4d Mon Sep 17 00:00:00 2001 From: Mickael Cagnion Date: Wed, 18 Nov 2026 17:09:15 +0100 Subject: [PATCH 1/2] Prefer the exported trade stat when labels differ only by sign ProcessMod matched trade stats by their label with signs and numbers stripped, so "#% Chance to Block Attack Damage" and its "+#%" sibling were the same key and the first one in label order won. Ten attack and spell block mods, seven explicit and three implicit, then queried the unsigned stat instead of the one they export. When the stat the mod exports in tradeHashes differs from the first match only by sign, use it. Identical labels keep label order, because legacy mods export hashes that Trade no longer lists. --- spec/System/TestTradeQueryGenerator_spec.lua | 21 +++++++ src/Classes/TradeQueryGenerator.lua | 37 ++++++++---- src/Data/QueryMods.lua | 60 ++++++++++---------- 3 files changed, 76 insertions(+), 42 deletions(-) diff --git a/spec/System/TestTradeQueryGenerator_spec.lua b/spec/System/TestTradeQueryGenerator_spec.lua index 4f3c035b5eb..c96d68e0f60 100644 --- a/spec/System/TestTradeQueryGenerator_spec.lua +++ b/spec/System/TestTradeQueryGenerator_spec.lua @@ -12,6 +12,27 @@ 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) end) describe("Talisman mods", function() diff --git a/src/Classes/TradeQueryGenerator.lua b/src/Classes/TradeQueryGenerator.lua index 097a2e7f948..f90e6a36355 100644 --- a/src/Classes/TradeQueryGenerator.lua +++ b/src/Classes/TradeQueryGenerator.lua @@ -132,6 +132,27 @@ local function getStatEntries(modType) end end +-- Find the trade stat whose label, without signs and numbers, equals strippedText. +-- "#% 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) + local firstMatch, exportedMatch + for _, entry in ipairs(entries or { }) do + if entry.text:gsub("[#()0-9%-%+%.]","") == strippedText then + firstMatch = firstMatch or entry + local tradeHash = tonumber(entry.id:match("%.stat_(%d+)$")) + if not exportedMatch and tradeHash and tradeHashes and tradeHashes[tradeHash] then + exportedMatch = entry + end + 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, @@ -252,22 +273,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) + 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) end if tradeMod == nil then if inverse then diff --git a/src/Data/QueryMods.lua b/src/Data/QueryMods.lua index 76bfc6942f2..a314eaa56d7 100644 --- a/src/Data/QueryMods.lua +++ b/src/Data/QueryMods.lua @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, From 1961f5d28de4f9f41367a7fe43fb7fbf083b06a7 Mon Sep 17 00:00:00 2001 From: Mickael Cagnion Date: Wed, 18 Nov 2026 17:09:15 +0100 Subject: [PATCH 2/2] Skip trade stats whose fixed numbers differ from the mod line Stripping numbers from labels also merged trade stats that differ only by a fixed number, such as "per 10 Intelligence" and "per 16 Intelligence", or Onslaught "for 4 seconds" and "for 10 seconds". The first label in order won, so those mods queried the wrong stat. Compare the label's fixed numbers with the mod line's numbers at the same positions, treating a roll range as a value position, and keep only the labels that agree. When none agree, every label stays a candidate as before. --- spec/System/TestTradeQueryGenerator_spec.lua | 12 +++++ src/Classes/TradeQueryGenerator.lua | 52 +++++++++++++++++--- src/Data/QueryMods.lua | 32 ++++++------ 3 files changed, 72 insertions(+), 24 deletions(-) diff --git a/spec/System/TestTradeQueryGenerator_spec.lua b/spec/System/TestTradeQueryGenerator_spec.lua index c96d68e0f60..4a8b3be5235 100644 --- a/spec/System/TestTradeQueryGenerator_spec.lua +++ b/spec/System/TestTradeQueryGenerator_spec.lua @@ -33,6 +33,18 @@ describe("TradeQueryGenerator", function() 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() diff --git a/src/Classes/TradeQueryGenerator.lua b/src/Classes/TradeQueryGenerator.lua index f90e6a36355..7d2e3025735 100644 --- a/src/Classes/TradeQueryGenerator.lua +++ b/src/Classes/TradeQueryGenerator.lua @@ -132,21 +132,57 @@ 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) - local firstMatch, exportedMatch +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 - firstMatch = firstMatch or entry - local tradeHash = tonumber(entry.id:match("%.stat_(%d+)$")) - if not exportedMatch and tradeHash and tradeHashes and tradeHashes[tradeHash] then - exportedMatch = entry + 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 @@ -273,14 +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%-%+%.]","") - tradeMod = findTradeStatByStrippedText(getStatEntries(modType), matchLocalStr, mod.tradeHashes) + 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%-%+%.]","") - tradeMod = findTradeStatByStrippedText(getStatEntries(modType), matchStr, mod.tradeHashes) + tradeMod = findTradeStatByStrippedText(getStatEntries(modType), matchStr, mod.tradeHashes, modLine) end if tradeMod == nil then if inverse then diff --git a/src/Data/QueryMods.lua b/src/Data/QueryMods.lua index a314eaa56d7..dd63c95a36d 100644 --- a/src/Data/QueryMods.lua +++ b/src/Data/QueryMods.lua @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, }, @@ -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", }, },