From 5acdc1327fb6c9a568eb791c602bbc5c22ac44bc Mon Sep 17 00:00:00 2001 From: vaisest <4550061+vaisest@users.noreply.github.com> Date: Sat, 1 Aug 2026 12:05:26 +0300 Subject: [PATCH] Add support for selected pseudo stats in trader weights --- src/Classes/TradeQueryGenerator.lua | 67 +++++++++++++++++++++++++---- src/Modules/Common.lua | 2 +- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/Classes/TradeQueryGenerator.lua b/src/Classes/TradeQueryGenerator.lua index 7564354cb4a..b1300eb1fbb 100644 --- a/src/Classes/TradeQueryGenerator.lua +++ b/src/Classes/TradeQueryGenerator.lua @@ -145,7 +145,7 @@ local eldritchModSlots = { ["Boots"] = true } -local MAX_FILTERS = 35 +local MAX_FILTERS = 36 local function logToFile(...) ConPrintf(...) @@ -934,16 +934,65 @@ function TradeQueryGeneratorClass:FinishQuery() local effective_max = MAX_FILTERS - num_extra - local prioritizedMods = {} + local pseudoMap = { + ["3372524247"] = "pseudo.pseudo_total_fire_resistance", + ["4220027924"] = "pseudo.pseudo_total_cold_resistance", + ["1671376347"] = "pseudo.pseudo_total_lightning_resistance", + ["2923486259"] = "pseudo.pseudo_total_chaos_resistance", + ["4080418644"] = "pseudo.pseudo_total_strength", + ["3261801346"] = "pseudo.pseudo_total_dexterity", + ["328541901"] = "pseudo.pseudo_total_intelligence", + } + local ignoredStats = { + -- % all resistances + ["2901986750"] = true, + -- all attributes + ["1379411836"] = true, + ["2897413282"] = true, + } + -- block all hybrid resistance stats + local resElements = { "fire", "cold", "lightning", "chaos" } + for _, elem1 in ipairs(resElements) do + for _, elem2 in ipairs(resElements) do + local stats = { string.format("%s_and_%s_damage_resistance_%%", elem1, elem2) } + ignoredStats[tostring(HashStats(stats))] = true + end + end + -- block all hybrid attribute stats + local attributeElements = { "dexterity", "strength", "intelligence" } + for _, elem1 in ipairs(attributeElements) do + for _, elem2 in ipairs(attributeElements) do + local stats = { string.format("base_%s_and_%s", elem1, elem2) } + ignoredStats[tostring(HashStats(stats))] = true + stats = { string.format("additional_%s_and_%s", elem1, elem2) } + ignoredStats[tostring(HashStats(stats))] = true + end + end + local statFilters = {} + local pseudoMods = {} for _, entry in ipairs(self.modWeights) do - if #prioritizedMods < effective_max then - table.insert(prioritizedMods, entry) + local hash = entry.tradeModId:match("stat_(%d+)") + local filterEntry = { id = entry.tradeModId, value = { weight = (entry.invert == true and entry.weight * -1 or entry.weight) } } + -- avoid adding hybrid stats since we get the weight for them from + -- individual stats + if ignoredStats[hash] then + goto weightContinue + elseif pseudoMap[hash] then + local tradeId = pseudoMap[hash] + filterEntry.id = tradeId + -- avoid adding duplicate pseudo filters: update existing + if pseudoMods[tradeId] then + pseudoMods[tradeId].value.weight = math.max(filterEntry.value.weight, pseudoMods[tradeId].value.weight) + else + pseudoMods[tradeId] = filterEntry + table.insert(statFilters, filterEntry) + end else - break + table.insert(statFilters, filterEntry) end - end - self.modWeights = prioritizedMods + ::weightContinue:: + end for k, v in pairs(self.calcContext.special.queryExtra or {}) do queryTable.query[k] = v @@ -964,8 +1013,8 @@ function TradeQueryGeneratorClass:FinishQuery() t_insert(queryTable.query.stats, andFilters) end - for _, entry in ipairs(self.modWeights) do - t_insert(queryTable.query.stats[1].filters, { id = entry.tradeModId, value = { weight = (entry.invert == true and entry.weight * -1 or entry.weight) } }) + for _, entry in ipairs(statFilters) do + t_insert(queryTable.query.stats[1].filters, entry) filters = filters + 1 if filters == effective_max then break diff --git a/src/Modules/Common.lua b/src/Modules/Common.lua index 752456d0d41..c7dc008210e 100644 --- a/src/Modules/Common.lua +++ b/src/Modules/Common.lua @@ -1068,7 +1068,7 @@ local GGG_STAT_HASH32_SEED = 0xC58F1A7B -- used for calculating the trade hash from stat hash fields local GGG_TRADE_SEED = 0x02312233 ---@param stats string[] ----@param extraStat string extra stat for time-lost jewels +---@param extraStat string? extra stat for time-lost jewels ---@return integer function HashStats(stats, extraStat) if extraStat then