Skip to content
Closed
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
83 changes: 65 additions & 18 deletions src/Classes/TradeQuery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,22 @@ You can click this button to enter your POESESSID.
- You can only generate weighted searches for public leagues. (Generated searches can be modified
on trade site to work on other leagues and realms)]]

-- Fetches Box
-- Buyout selection
self.tradeTypes = {
"Instant buyout",
"Instant buyout and in person",
"In person (online in league)",
"In person (online)",
}

self.controls.tradeTypeSelection = new("DropDownControl", { "TOPLEFT", self.controls.poesessidButton, "BOTTOMLEFT" },
{ 0, row_vertical_padding, 188, row_height }, self.tradeTypes, function(index, value)
self.tradeTypeIndex = index
end)
-- remember previous choice
self.controls.tradeTypeSelection:SetSel(self.tradeTypeIndex or 1)

-- Fetches Box
self.maxFetchPerSearchDefault = 2
self.controls.fetchCountEdit = new("EditControl", {"TOPRIGHT", nil, "TOPRIGHT"}, {-12, 19, 154, row_height}, "", "Fetch Pages", "%D", 3, function(buf)
self.maxFetchPages = m_min(m_max(tonumber(buf) or self.maxFetchPerSearchDefault, 1), 10)
Expand Down Expand Up @@ -449,7 +464,7 @@ Highest Weight - Displays the order retrieved from trade]]
t_insert(slotTables, { slotName = self.itemsTab.sockets[nodeId].label, nodeId = nodeId })
end

self.controls.sectionAnchor = new("LabelControl", {"LEFT", self.controls.poesessidButton, "LEFT"}, {0, 0, 0, 0}, "")
self.controls.sectionAnchor = new("LabelControl", {"LEFT", self.controls.poesessidButton, "LEFT"}, {0, row_vertical_padding + row_height, 0, 0}, "")
top_pane_alignment_ref = {"TOPLEFT", self.controls.sectionAnchor, "TOPLEFT"}
local scrollBarShown = #slotTables > 21 -- clipping starts beyond this
-- dynamically hide rows that are above or below the scrollBar
Expand Down Expand Up @@ -926,6 +941,7 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
return
end
context.controls["priceButton"..context.row_idx].label = "Searching..."
self.lastQuery = query
self.tradeQueryRequests:SearchWithQueryWeightAdjusted(self.pbRealm, self.pbLeague, query,
function(items, errMsg)
if errMsg then
Expand Down Expand Up @@ -1089,8 +1105,6 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
local firstValidSlot = self:findValidSlotForWatchersEye()
local currentItem = firstValidSlot.selItemId ~= 0 and self.itemsTab.items[firstValidSlot.selItemId]
local eyeEquipped = currentItem and currentItem.name:find("Watcher's Eye")
-- for watcher's eye we can compare to an already existing one, or
-- default to comparing with all active sockets
self.itemsTab:AddItemTooltip(tooltip, item, eyeEquipped and firstValidSlot or nil, true)
else
self.itemsTab:AddItemTooltip(tooltip, item, slotTbl, true)
Expand All @@ -1102,23 +1116,56 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
return self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]].item_string ~= nil
end
-- Whisper so we can copy to clipboard
controls["whisperButton"..row_idx] = new("ButtonControl", { "TOPLEFT", controls["importButton"..row_idx], "TOPRIGHT"}, {8, 0, 185, row_height}, function()
return self.totalPrice[row_idx] and "Whisper for " .. self.totalPrice[row_idx].amount .. " " .. self.totalPrice[row_idx].currency or "Whisper"
end, function()
Copy(self.resultTbl[row_idx][self.itemIndexTbl[row_idx]].whisper)
end)
controls["whisperButton"..row_idx].enabled = function()
return self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]].whisper ~= nil
end
controls["whisperButton"..row_idx].tooltipFunc = function(tooltip)
controls["whisperButton" .. row_idx] = new("ButtonControl",
{ "TOPLEFT", controls["importButton" .. row_idx], "TOPRIGHT" }, { 8, 0, 170, row_height }, function()
local itemResult = self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]]

if not itemResult then return "" end

local price = self.totalPrice[row_idx] and
self.totalPrice[row_idx].amount .. " " .. self.totalPrice[row_idx].currency

if itemResult.whisper then
return price and "Whisper for " .. price or "Whisper"
else
return price and "Search for " .. price or "Search"
end

end, function()
local itemResult = self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]]
if itemResult.whisper then
Copy(itemResult.whisper)
else
local exactQuery = dkjson.decode(self.lastQuery)
-- use trade sum to get the specific item. both min and max
-- weight fields seem to be inconsistent. making the minimum
-- e.g. exactly 172.3 as on the result item does not always work
exactQuery.query.stats[1].value = { min = floor(itemResult.weight, 1) - 0.1, max = round(itemResult.weight, 1) + 0.1 }
-- also apply trader name. this should make false positives
-- extremely unlikely. this doesn't seem to take up a filter
-- slot
exactQuery.query.filters.trade_filters = { filters = { account = itemResult.trader } }

local exactQueryStr = dkjson.encode(exactQuery)

self.tradeQueryRequests:SearchWithQuery(self.pbRealm, self.pbLeague, exactQueryStr, function(_, _)
end, {callbackQueryId = function(queryId)
local url = self.hostName.."trade/search/"..self.pbLeague.."/"..queryId
Copy(url)
OpenURL(url)
end})
end
end)

controls["whisperButton" .. row_idx].tooltipFunc = function(tooltip)
tooltip:Clear()
if self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]].item_string then
tooltip.center = true
tooltip:AddLine(16, "Copies the item purchase whisper to the clipboard")
end
tooltip.center = true
local itemResult = self.itemIndexTbl[row_idx] and self.resultTbl[row_idx][self.itemIndexTbl[row_idx]]
local text = itemResult.whisper and "Copies the item purchase whisper to the clipboard" or
"Opens the search page to show the item"
tooltip:AddLine(16, text)
end
end

-- Method to update the Total Price string sum of all items
function TradeQueryClass:GetTotalPriceString()
local text = ""
Expand Down
18 changes: 16 additions & 2 deletions src/Classes/TradeQueryGenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,15 @@
-- This Stat diff value will generally be higher than the weighted sum of the same item, because the stats are all applied at once and can thus multiply off each other.
-- So apply a modifier to get a reasonable min and hopefully approximate that the query will start out with small upgrades.
local minWeight = megalomaniacSpecialMinWeight or currentStatDiff * 0.5


-- what the trade site API uses for the above
self.tradeTypes = {
"securable",
"available",
"onlineleague",

Check warning on line 1011 in src/Classes/TradeQueryGenerator.lua

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (onlineleague)
"online",
}
local selectedTradeType = self.tradeTypes[self.tradeTypeIndex]
-- Generate trade query str and open in browser
local filters = 0
local queryTable = {
Expand All @@ -1016,7 +1024,7 @@
}
}
},
status = { option = "available" },
status = { option = selectedTradeType },
stats = {
{
type = "weight",
Expand Down Expand Up @@ -1104,6 +1112,10 @@
}
end

if options.account then
queryTable.query.filters.trade_filters.filters.account = {input = options.account}
end

if options.maxLevel and options.maxLevel > 0 then
queryTable.query.filters.req_filters = {
disabled = false,
Expand Down Expand Up @@ -1302,6 +1314,8 @@
controls.generateQuery = new("ButtonControl", { "BOTTOM", nil, "BOTTOM" }, {-45, -10, 80, 20}, "Execute", function()
main:ClosePopup()

self.tradeTypeIndex = context.controls.tradeTypeSelection.selIndex

if controls.includeMirrored then
self.lastIncludeMirrored, options.includeMirrored = controls.includeMirrored.state, controls.includeMirrored.state
end
Expand Down
6 changes: 6 additions & 0 deletions src/Classes/TradeQueryRequests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,14 @@ function TradeQueryRequestsClass:FetchResultBlock(url, callback)
table.insert(items, {
amount = trade_entry.listing.price.amount,
currency = trade_entry.listing.price.currency,
-- note: using these to travel to the hideout or for a
-- direct whisper is not allowed, even if they are provided
-- right here
-- hideout_token = trade_entry.listing.hideout_token,
-- whisper_token = trade_entry.listing.whisper_token,
item_string = common.base64.decode(trade_entry.item.extended.text),
whisper = trade_entry.listing.whisper,
trader = trade_entry.listing.account.name,
weight = trade_entry.item.pseudoMods and trade_entry.item.pseudoMods[1]:match("Sum: (.+)") or "0",
id = trade_entry.id
})
Expand Down
Loading