Skip to content
Draft
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
43 changes: 43 additions & 0 deletions spec/System/TestTradeQueryRequests_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,49 @@ Strict-Transport-Security: max-age=63115200; includeSubDomains; preload]]
end)

describe("FetchResultBlock", function()
it("preserves item influences in reconstructed item strings", function()
local response = dkjson.encode({
result = {
{
id = "influenced",
listing = {
price = { amount = 1, currency = "chaos", type = "~price" },
whisper = "hi",
account = { name = "seller" },
},
item = {
rarity = "Rare",
name = "Test Subject",
typeLine = "Astral Plate",
influences = {
shaper = true,
elder = true,
warlord = true,
hunter = true,
crusader = true,
redeemer = true,
},
searing = true,
tangled = true,
},
},
},
})
local fetchedItems
requests.requestQueue.fetch = { }
requests:FetchResultBlock("test", function(items)
fetchedItems = items
end)

local request = table.remove(requests.requestQueue.fetch, 1)
request.callback(response)

local item = new("Item", fetchedItems[1].item_string)
for _, influenceInfo in ipairs(itemLib.influenceInfo.all) do
assert.is_true(item[influenceInfo.key], influenceInfo.display)
end
end)

it("reads weighted sums from current and legacy pseudo mods", function()
local function makeTradeEntry(id, pseudoMods)
return {
Expand Down
17 changes: 17 additions & 0 deletions src/Classes/TradeQueryRequests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
local dkjson = require "dkjson"
local utils = LoadModule("Modules/Utils")

local tradeInfluenceApiKeys = {
shaper = "shaper",
elder = "elder",
adjudicator = "warlord",
basilisk = "hunter",
crusader = "crusader",
eyrie = "redeemer",
cleansing = "searing",
tangle = "tangled",
}

---@class TradeQueryRequests
local TradeQueryRequestsClass = newClass("TradeQueryRequests", function(self, rateLimiter)
self.maxFetchPerSearch = 10
Expand Down Expand Up @@ -357,6 +368,12 @@ function TradeQueryRequestsClass:FetchResultBlock(url, callback)
for _, modLine in ipairs(item.explicitMods) do
t_insert(rawLines, processLine(modLine))
end
for _, influenceInfo in ipairs(itemLib.influenceInfo.all) do
local apiKey = tradeInfluenceApiKeys[influenceInfo.key]
if apiKey and ((item.influences and item.influences[apiKey]) or item[apiKey]) then
t_insert(rawLines, influenceInfo.display .. " Item")
end
end
if item.duplicated then
t_insert(rawLines, "Mirrored")
end
Expand Down
Loading