scanner refactoring and some bugfixes
This commit is contained in:
@@ -32,10 +32,14 @@ function AuxBuySearchButton_OnClick()
|
|||||||
Aux.scan.start{
|
Aux.scan.start{
|
||||||
query = search_query,
|
query = search_query,
|
||||||
on_start_page = function(i)
|
on_start_page = function(i)
|
||||||
set_message('Scanning auctions: page ' .. i .. ' ...')
|
set_message('Scanning auctions: page ' .. i + 1 .. ' ...')
|
||||||
end,
|
end,
|
||||||
on_read_auction = function(i)
|
on_read_auction = function(i)
|
||||||
local auction_item = Aux.info.auction_item(i)
|
local auction_item = Aux.info.auction_item(i)
|
||||||
|
if not auction_item then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local stack_size = auction_item.charges or auction_item.count
|
local stack_size = auction_item.charges or auction_item.count
|
||||||
if auction_item.name == search_query.name then
|
if auction_item.name == search_query.name then
|
||||||
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.quality, auction_item.owner, auction_item.itemlink)
|
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.quality, auction_item.owner, auction_item.itemlink)
|
||||||
@@ -98,32 +102,39 @@ function AuxBuyBuySelectedButton_OnClick()
|
|||||||
Aux.scan.start{
|
Aux.scan.start{
|
||||||
query = search_query,
|
query = search_query,
|
||||||
on_start_page = function(i)
|
on_start_page = function(i)
|
||||||
set_message('Scanning auctions: page ' .. i .. ' ...')
|
set_message('Scanning auctions: page ' .. i + 1 .. ' ...')
|
||||||
end,
|
end,
|
||||||
on_read_auction = function(i)
|
on_read_auction = function(i)
|
||||||
local auction_item = Aux.info.auction_item(i)
|
local auction_item = Aux.info.auction_item(i)
|
||||||
|
|
||||||
|
if not auction_item then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local stack_size = auction_item.charges or auction_item.count
|
||||||
|
|
||||||
|
if not auction_item.name or not stack_size or not auction_item.buyout_price then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if auction_item.name and auction_item.count and auction_item.buyout_price then
|
local key = auction_item.name.."_"..stack_size.."_"..auction_item.buyout_price
|
||||||
local key = auction_item.name.."_"..auction_item.count.."_"..auction_item.buyout_price
|
if order[key] then
|
||||||
if order[key] then
|
|
||||||
|
if GetMoney() >= auction_item.buyout_price then
|
||||||
|
PlaceAuctionBid("list", i, auction_item.buyout_price)
|
||||||
|
progress.auctions = progress.auctions + 1
|
||||||
|
progress.units = progress.units + stack_size
|
||||||
|
progress.expense = progress.expense + auction_item.buyout_price
|
||||||
|
end
|
||||||
|
|
||||||
if GetMoney() >= auction_item.buyout_price then
|
if order[key] > 1 then
|
||||||
PlaceAuctionBid("list", i, auction_item.buyout_price)
|
order[key] = order[key] - 1
|
||||||
progress.auctions = progress.auctions + 1
|
|
||||||
progress.units = progress.units + auction_item.count
|
|
||||||
progress.expense = progress.expense + auction_item.buyout_price
|
|
||||||
end
|
|
||||||
|
|
||||||
if order[key] > 1 then
|
|
||||||
order[key] = order[key] - 1
|
|
||||||
else
|
|
||||||
order[key] = nil
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
local stack_size = auction_item.charges or auction_item.count
|
order[key] = nil
|
||||||
if auction_item.name == search_query.name then
|
end
|
||||||
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.quality, auction_item.owner, auction_item.itemlink)
|
else
|
||||||
end
|
if auction_item.name == search_query.name then
|
||||||
|
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.quality, auction_item.owner, auction_item.itemlink)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -47,6 +47,11 @@ end
|
|||||||
|
|
||||||
function Aux.info.auction_item(index)
|
function Aux.info.auction_item(index)
|
||||||
local itemlink = GetAuctionItemLink("list", index)
|
local itemlink = GetAuctionItemLink("list", index)
|
||||||
|
|
||||||
|
if not itemlink then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local auction_item = itemlink_item(itemlink)
|
local auction_item = itemlink_item(itemlink)
|
||||||
|
|
||||||
local name, texture, count, quality, usable, level, min_bid, min_increment, buyout_price, bid_amount, high_bidder, owner, sale_status, id, has_all_info = GetAuctionItemInfo("list", index)
|
local name, texture, count, quality, usable, level, min_bid, min_increment, buyout_price, bid_amount, high_bidder, owner, sale_status, id, has_all_info = GetAuctionItemInfo("list", index)
|
||||||
|
|||||||
@@ -1,41 +1,58 @@
|
|||||||
Aux.scan = {}
|
Aux.scan = {}
|
||||||
|
|
||||||
local STATE_IDLE = 0
|
|
||||||
local STATE_PREQUERY = 1
|
|
||||||
local STATE_POSTQUERY = 2
|
|
||||||
local STATE_PROCESSING = 3 -- doesn't avoid race conditions completely!
|
|
||||||
|
|
||||||
local NUM_AUCTION_ITEMS_PER_PAGE = 50
|
local NUM_AUCTION_ITEMS_PER_PAGE = 50
|
||||||
|
|
||||||
local currentJob
|
local current_job
|
||||||
local currentPage
|
local current_page
|
||||||
local state = STATE_IDLE
|
local page_state
|
||||||
|
|
||||||
local timeOfLastUpdate = GetTime()
|
local last_query_request = GetTime()
|
||||||
|
|
||||||
-- forward declaration of local functions
|
-- forward declaration of local functions
|
||||||
local submitQuery, processQueryResults
|
local submit_query, process_query_results
|
||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
function Aux.scan.on_event()
|
function Aux.scan.on_event()
|
||||||
if event == "AUCTION_ITEM_LIST_UPDATE" then
|
if event == "AUCTION_ITEM_LIST_UPDATE" and current_job and not page_state then
|
||||||
if state == STATE_POSTQUERY then
|
local count, total_count = GetNumAuctionItems("list")
|
||||||
state = STATE_PROCESSING
|
if current_job.on_start_page then
|
||||||
processQueryResults()
|
current_job.on_start_page(current_page)
|
||||||
end
|
end
|
||||||
|
page_state = {
|
||||||
|
index = 1,
|
||||||
|
count = count,
|
||||||
|
total_count = total_count,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
function Aux.scan.on_update()
|
function Aux.scan.on_update()
|
||||||
if state == STATE_PREQUERY and GetTime() - timeOfLastUpdate > 0.5 then
|
if page_state then
|
||||||
|
if page_state.index <= page_state.count and current_job.on_read_auction then
|
||||||
timeOfLastUpdate = GetTime()
|
current_job.on_read_auction(page_state.index)
|
||||||
|
end
|
||||||
|
|
||||||
|
if page_state.index == page_state.count then
|
||||||
|
if page_state.index == NUM_AUCTION_ITEMS_PER_PAGE then
|
||||||
|
page_state = nil
|
||||||
|
current_page = current_page + 1
|
||||||
|
else
|
||||||
|
Aux.scan.complete()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if page_state then
|
||||||
|
page_state.index = page_state.index + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif current_job and GetTime() - last_query_request > 0.5 then
|
||||||
|
last_query_request = GetTime()
|
||||||
|
|
||||||
if CanSendAuctionQuery() then
|
if CanSendAuctionQuery() then
|
||||||
submitQuery()
|
submit_query()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -43,47 +60,40 @@ end
|
|||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
function Aux.scan.idle()
|
function Aux.scan.idle()
|
||||||
return state == STATE_IDLE
|
return not current_job
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
function Aux.scan.complete()
|
function Aux.scan.complete()
|
||||||
if state ~= STATE_IDLE then
|
if current_job and current_job.on_complete then
|
||||||
if currentJob.on_complete then
|
current_job.on_complete()
|
||||||
currentJob.on_complete()
|
|
||||||
end
|
|
||||||
|
|
||||||
currentJob = nil
|
|
||||||
currentPage = nil
|
|
||||||
state = STATE_IDLE
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
current_job = nil
|
||||||
|
current_page = nil
|
||||||
|
page_state = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
function Aux.scan.abort()
|
function Aux.scan.abort()
|
||||||
if state ~= STATE_IDLE then
|
if current_job and current_job.on_abort then
|
||||||
if currentJob and currentJob.on_abort then
|
current_job.on_abort()
|
||||||
currentJob.on_abort()
|
|
||||||
end
|
|
||||||
|
|
||||||
currentJob = nil
|
|
||||||
currentPage = nil
|
|
||||||
state = STATE_IDLE
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
current_job = nil
|
||||||
|
current_page = nil
|
||||||
|
page_state = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
function Aux.scan.start(job)
|
function Aux.scan.start(job)
|
||||||
|
Aux.scan.abort()
|
||||||
if state ~= STATE_IDLE then
|
|
||||||
Aux.scan.abort()
|
|
||||||
end
|
|
||||||
|
|
||||||
currentJob = job
|
current_job = job
|
||||||
state = STATE_PREQUERY
|
current_page = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
@@ -109,41 +119,16 @@ end
|
|||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
function submitQuery()
|
function submit_query()
|
||||||
QueryAuctionItems(
|
QueryAuctionItems(
|
||||||
currentJob.query.name,
|
current_job.query.name,
|
||||||
currentJob.query.minLevel,
|
current_job.query.minLevel,
|
||||||
currentJob.query.maxLevel,
|
current_job.query.maxLevel,
|
||||||
currentJob.query.invTypeIndex,
|
current_job.query.invTypeIndex,
|
||||||
currentJob.query.classIndex,
|
current_job.query.classIndex,
|
||||||
currentJob.query.subclassIndex,
|
current_job.query.subclassIndex,
|
||||||
currentPage,
|
current_page,
|
||||||
currentJob.query.isUsable,
|
current_job.query.isUsable,
|
||||||
currentJob.query.qualityIndex
|
current_job.query.qualityIndex
|
||||||
)
|
)
|
||||||
state = STATE_POSTQUERY
|
|
||||||
currentPage = currentPage and currentPage + 1 or 1
|
|
||||||
end
|
|
||||||
|
|
||||||
-----------------------------------------
|
|
||||||
|
|
||||||
function processQueryResults()
|
|
||||||
|
|
||||||
local numBatchAuctions, totalAuctions = GetNumAuctionItems("list")
|
|
||||||
|
|
||||||
if currentJob.on_start_page then
|
|
||||||
currentJob.on_start_page(currentPage)
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, numBatchAuctions do
|
|
||||||
if currentJob.on_read_auction then
|
|
||||||
currentJob.on_read_auction(i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if numBatchAuctions == NUM_AUCTION_ITEMS_PER_PAGE then
|
|
||||||
state = STATE_PREQUERY
|
|
||||||
else
|
|
||||||
Aux.scan.complete()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@@ -306,11 +306,11 @@ function Aux_RefreshEntries()
|
|||||||
subclassIndex = subclass_index,
|
subclassIndex = subclass_index,
|
||||||
},
|
},
|
||||||
on_start_page = function(i)
|
on_start_page = function(i)
|
||||||
set_message('Scanning auctions: page ' .. i .. ' ...')
|
set_message('Scanning auctions: page ' .. i + 1 .. ' ...')
|
||||||
end,
|
end,
|
||||||
on_read_auction = function(i)
|
on_read_auction = function(i)
|
||||||
local auction_item = Aux.info.auction_item(i)
|
local auction_item = Aux.info.auction_item(i)
|
||||||
if auction_item.name == name then
|
if auction_item and auction_item.name == name then
|
||||||
local stack_size = auction_item.charges or auction_item.count
|
local stack_size = auction_item.charges or auction_item.count
|
||||||
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.duration, auction_item.owner)
|
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.duration, auction_item.owner)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user