|
|
|
|
@ -3,6 +3,19 @@ local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_Shopping") -- loa
|
|
|
|
|
|
|
|
|
|
local private = {itemOperations={}} |
|
|
|
|
|
|
|
|
|
local function GetActiveOperations(itemString, operations) |
|
|
|
|
if not operations or #operations == 0 then return end |
|
|
|
|
local active = {} |
|
|
|
|
for _, opName in ipairs(operations) do |
|
|
|
|
TSMAPI:UpdateOperation("Shopping", opName) |
|
|
|
|
local opSettings = TSM.operations[opName] |
|
|
|
|
if opSettings then |
|
|
|
|
tinsert(active, opSettings) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
return active |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
function private.Create(parent) |
|
|
|
|
local frame = CreateFrame("Frame", nil, parent) |
|
|
|
|
frame:SetAllPoints() |
|
|
|
|
@ -39,33 +52,57 @@ function private.ScanCallback(event, ...)
|
|
|
|
|
local filter = ... |
|
|
|
|
local maxPrice |
|
|
|
|
for _, itemString in ipairs(filter.items) do |
|
|
|
|
local operation = private.itemOperations[itemString] |
|
|
|
|
local operationPrice = TSM:GetMaxPrice(operation.maxPrice, itemString) |
|
|
|
|
if not operationPrice then return end |
|
|
|
|
if operation.showAboveMaxPrice then |
|
|
|
|
local operations = GetActiveOperations(itemString, private.itemOperations[itemString]) |
|
|
|
|
if not operations or #operations == 0 then return end |
|
|
|
|
local itemMaxPrice |
|
|
|
|
for _, operation in ipairs(operations) do |
|
|
|
|
if operation.showAboveMaxPrice then |
|
|
|
|
itemMaxPrice = nil |
|
|
|
|
break |
|
|
|
|
end |
|
|
|
|
local operationPrice = TSM:GetMaxPrice(operation.maxPrice, itemString) |
|
|
|
|
if operationPrice then |
|
|
|
|
itemMaxPrice = itemMaxPrice and max(itemMaxPrice, operationPrice) or operationPrice |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
if itemMaxPrice == nil then |
|
|
|
|
maxPrice = nil |
|
|
|
|
break |
|
|
|
|
end |
|
|
|
|
maxPrice = maxPrice and max(maxPrice, operationPrice) or operationPrice |
|
|
|
|
if not itemMaxPrice then return end |
|
|
|
|
maxPrice = maxPrice and max(maxPrice, itemMaxPrice) or itemMaxPrice |
|
|
|
|
end |
|
|
|
|
return maxPrice |
|
|
|
|
elseif event == "process" then |
|
|
|
|
local itemString, auctionItem = ... |
|
|
|
|
-- filter out auctions according to operation settings |
|
|
|
|
itemString = TSMAPI:GetBaseItemString(itemString, true) |
|
|
|
|
local operation = private.itemOperations[itemString] |
|
|
|
|
if not operation then return end |
|
|
|
|
local operationPrice = TSM:GetMaxPrice(operation.maxPrice, itemString) |
|
|
|
|
if not operationPrice then return end |
|
|
|
|
local operations = GetActiveOperations(itemString, private.itemOperations[itemString]) |
|
|
|
|
if not operations or #operations == 0 then return end |
|
|
|
|
auctionItem:FilterRecords(function(record) |
|
|
|
|
local buyout = record:GetItemBuyout() or 0 |
|
|
|
|
for _, operation in ipairs(operations) do |
|
|
|
|
if operation.evenStacks and record.count % 5 ~= 0 then |
|
|
|
|
return true |
|
|
|
|
end |
|
|
|
|
if not operation.showAboveMaxPrice then |
|
|
|
|
return (record:GetItemBuyout() or 0) > operationPrice |
|
|
|
|
-- not an even stack for this operation |
|
|
|
|
elseif operation.showAboveMaxPrice then |
|
|
|
|
return false |
|
|
|
|
else |
|
|
|
|
local operationPrice = TSM:GetMaxPrice(operation.maxPrice, itemString) |
|
|
|
|
if operationPrice and buyout <= operationPrice then |
|
|
|
|
return false |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
return true |
|
|
|
|
end) |
|
|
|
|
auctionItem:SetMarketValue(operationPrice) |
|
|
|
|
local marketValue |
|
|
|
|
for _, operation in ipairs(operations) do |
|
|
|
|
local operationPrice = TSM:GetMaxPrice(operation.maxPrice, itemString) |
|
|
|
|
if operationPrice then |
|
|
|
|
marketValue = marketValue and max(marketValue, operationPrice) or operationPrice |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
auctionItem:SetMarketValue(marketValue) |
|
|
|
|
return auctionItem |
|
|
|
|
elseif event == "done" then |
|
|
|
|
TSM.Search:SetSearchBarDisabled(false) |
|
|
|
|
@ -87,11 +124,13 @@ function private.StartScan()
|
|
|
|
|
else |
|
|
|
|
-- it's a valid operation |
|
|
|
|
for itemString in pairs(data.items) do |
|
|
|
|
local baseItemString = TSMAPI:GetBaseItemString(itemString, true) or itemString |
|
|
|
|
local _, err = TSM:GetMaxPrice(opSettings.maxPrice, itemString) |
|
|
|
|
if err then |
|
|
|
|
TSM:Printf(L["Invalid custom price source for %s. %s"], TSMAPI:GetSafeItemInfo(itemString) or itemString, err) |
|
|
|
|
else |
|
|
|
|
private.itemOperations[itemString] = opSettings |
|
|
|
|
private.itemOperations[baseItemString] = private.itemOperations[baseItemString] or {} |
|
|
|
|
tinsert(private.itemOperations[baseItemString], opName) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|