|
79 | 79 |
|
80 | 80 | local _optionTradeStatMap |
81 | 81 |
|
| 82 | +-- These option stats are still needed for legacy items, but are no longer |
| 83 | +-- included in the trade API's 3.29 stats response. |
| 84 | +local legacyOptionTradeStats = { |
| 85 | + { |
| 86 | + type = "explicit", |
| 87 | + id = "explicit.stat_2878779644", |
| 88 | + text = "Grants Level 20 Summon Bestial # Skill", |
| 89 | + options = { |
| 90 | + { id = 1, text = "rhoa" }, |
| 91 | + { id = 2, text = "ursa" }, |
| 92 | + { id = 3, text = "snake" }, |
| 93 | + }, |
| 94 | + }, |
| 95 | + { |
| 96 | + type = "explicit", |
| 97 | + id = "explicit.stat_3642528642", |
| 98 | + text = "Only affects Passives in # Ring", |
| 99 | + options = { |
| 100 | + { id = 1, text = "small" }, |
| 101 | + { id = 2, text = "medium" }, |
| 102 | + { id = 3, text = "large" }, |
| 103 | + { id = 4, text = "very large" }, |
| 104 | + { id = 5, text = "massive" }, |
| 105 | + }, |
| 106 | + }, |
| 107 | +} |
| 108 | + |
82 | 109 | ---@param tradeStats table table of data from https://www.pathofexile.com/api/trade2/data/stats |
83 | 110 | ---@return table optionTradeStatMap table containing helper data for matching trade option filters |
84 | 111 | local function getOptionTradeStatMap(tradeStats) |
85 | 112 | if _optionTradeStatMap then return _optionTradeStatMap end |
86 | | - local optionTradeStatMap = {} |
| 113 | + local optionTradeStatMap = { |
| 114 | + exact = {}, |
| 115 | + patterns = {}, |
| 116 | + } |
87 | 117 | for _, cat in ipairs(tradeStats) do |
88 | 118 | if cat.id == "enchant" or cat.id == "explicit" or cat.id == "implicit" then |
89 | 119 | for _, entry in ipairs(cat.entries) do |
90 | | - if entry.option and entry.text:match("#") then |
| 120 | + local tradeId, optionId = entry.id:match("^(.-)|(.+)$") |
| 121 | + if tradeId and optionId then |
| 122 | + -- The 3.29 trade API expands option stats into one entry per option, |
| 123 | + -- with the option value appended to the stat ID. |
| 124 | + local matchKey = entry.text:gsub(" Passage", ""):lower() |
| 125 | + optionTradeStatMap.exact[cat.id .. "\0" .. matchKey] = { |
| 126 | + tradeId = tradeId, |
| 127 | + value = tonumber(optionId) or optionId, |
| 128 | + } |
| 129 | + elseif entry.option and entry.text:match("#") then |
91 | 130 | -- pob parses the passage part as a separate mod line, which |
92 | 131 | -- causes trouble |
93 | 132 | local matchKey = entry.text:gsub("#", "(.*)"):gsub(" Passage", ""):lower() |
94 | 133 | -- make options lowercase |
95 | 134 | for _, option in ipairs(entry.option.options) do |
96 | 135 | option.text = option.text and option.text:lower() |
97 | 136 | end |
98 | | - optionTradeStatMap[matchKey] = { type = cat.id, options = entry.option.options, tradeId = entry.id } |
| 137 | + optionTradeStatMap.patterns[matchKey] = { type = cat.id, options = entry.option.options, tradeId = entry.id } |
99 | 138 | end |
100 | 139 | end |
101 | 140 | end |
102 | 141 | end |
| 142 | + for _, entry in ipairs(legacyOptionTradeStats) do |
| 143 | + local matchKey = entry.text:gsub("#", "(.*)"):lower() |
| 144 | + optionTradeStatMap.patterns[matchKey] = optionTradeStatMap.patterns[matchKey] or { |
| 145 | + type = entry.type, |
| 146 | + options = entry.options, |
| 147 | + tradeId = entry.id, |
| 148 | + } |
| 149 | + end |
103 | 150 |
|
104 | 151 | _optionTradeStatMap = optionTradeStatMap |
105 | 152 | return _optionTradeStatMap |
@@ -165,7 +212,11 @@ function M.findTradeIdOption(modLine, modType) |
165 | 212 |
|
166 | 213 | -- reformat double-line cluster enchants |
167 | 214 | modLine = modLine:gsub(".added small passive skills grant: ", " ") |
168 | | - for pat, entry in pairs(optionTradeStatMap) do |
| 215 | + local exactEntry = optionTradeStatMap.exact[modType .. "\0" .. modLine] |
| 216 | + if exactEntry then |
| 217 | + return exactEntry.tradeId, exactEntry.value |
| 218 | + end |
| 219 | + for pat, entry in pairs(optionTradeStatMap.patterns) do |
169 | 220 | local match = modLine:match(pat) |
170 | 221 | if entry.type == modType and match then |
171 | 222 | for _, option in ipairs(entry.options) do |
|
0 commit comments