a lot of refactoring, performance issue fixed
This commit is contained in:
+41
-47
@@ -150,65 +150,59 @@ function private.merchant_sell_scan()
|
||||
for slot in Aux.util.inventory() do
|
||||
local item_info = Aux.info.container_item(unpack(slot))
|
||||
if item_info then
|
||||
aux_merchant_sell[item_info.item_id] = item_info.tooltip.money / item_info.aux_quantity
|
||||
aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function private.scan_wdb()
|
||||
function private.scan_wdb(item_id)
|
||||
item_id = item_id or MIN_ITEM_ID
|
||||
|
||||
local function helper(item_id)
|
||||
local processed = 0
|
||||
while processed <= 100 and item_id <= MAX_ITEM_ID do
|
||||
local itemstring = 'item:'..item_id
|
||||
local name, _, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring)
|
||||
if name and not aux_item_ids[strlower(name)] then
|
||||
aux_item_ids[strlower(name)] = item_id
|
||||
aux_items[item_id] = Aux.persistence.write(items_schema, {
|
||||
name = name,
|
||||
quality = quality,
|
||||
level = level,
|
||||
class = class,
|
||||
subclass = subclass,
|
||||
slot = slot,
|
||||
max_stack = max_stack,
|
||||
texture = texture,
|
||||
})
|
||||
local tooltip = Aux.info.tooltip(function(tt) tt:SetHyperlink(itemstring) end)
|
||||
if Aux.info.auctionable(tooltip, quality) then
|
||||
tinsert(aux_auctionable_items, strlower(name))
|
||||
end
|
||||
processed = processed + 1
|
||||
local processed = 0
|
||||
while processed <= 100 and item_id <= MAX_ITEM_ID do
|
||||
local itemstring = 'item:'..item_id
|
||||
local name, _, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring)
|
||||
if name and not aux_item_ids[strlower(name)] then
|
||||
aux_item_ids[strlower(name)] = item_id
|
||||
aux_items[item_id] = Aux.persistence.write(items_schema, {
|
||||
name = name,
|
||||
quality = quality,
|
||||
level = level,
|
||||
class = class,
|
||||
subclass = subclass,
|
||||
slot = slot,
|
||||
max_stack = max_stack,
|
||||
texture = texture,
|
||||
})
|
||||
local tooltip = Aux.info.tooltip(function(tt) tt:SetHyperlink(itemstring) end)
|
||||
if Aux.info.auctionable(tooltip, quality) then
|
||||
tinsert(aux_auctionable_items, strlower(name))
|
||||
end
|
||||
item_id = item_id + 1
|
||||
end
|
||||
|
||||
if item_id <= MAX_ITEM_ID then
|
||||
local t0 = GetTime()
|
||||
Aux.control.as_soon_as(function() return GetTime() - t0 > 0.1 end, Aux.f(helper, item_id))
|
||||
else
|
||||
sort(aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
|
||||
processed = processed + 1
|
||||
end
|
||||
item_id = item_id + 1
|
||||
end
|
||||
|
||||
helper(MIN_ITEM_ID)
|
||||
if item_id <= MAX_ITEM_ID then
|
||||
local t0 = GetTime()
|
||||
Aux.control.as_soon_as(function() return GetTime() - t0 > 0.1 end, m.scan_wdb, item_id)
|
||||
else
|
||||
sort(aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
|
||||
end
|
||||
end
|
||||
|
||||
function public.populate_wdb()
|
||||
function public.populate_wdb(item_id)
|
||||
item_id = item_id or MIN_ITEM_ID
|
||||
|
||||
local function helper(item_id)
|
||||
if item_id > MAX_ITEM_ID then
|
||||
Aux.log('Cache populated.')
|
||||
return
|
||||
end
|
||||
|
||||
if not GetItemInfo('item:'..item_id) then
|
||||
Aux.log('Fetching item '..item_id..'.')
|
||||
AuxTooltip:SetHyperlink('item:'..item_id)
|
||||
end
|
||||
|
||||
Aux.control.on_next_update(Aux.f(helper, item_id + 1))
|
||||
if item_id > MAX_ITEM_ID then
|
||||
Aux.log('Cache populated.')
|
||||
return
|
||||
end
|
||||
|
||||
helper(MIN_ITEM_ID)
|
||||
if not GetItemInfo('item:'..item_id) then
|
||||
Aux.log('Fetching item '..item_id..'.')
|
||||
AuxTooltip:SetHyperlink('item:'..item_id)
|
||||
end
|
||||
|
||||
Aux.control.thread(m.populate_wdb, item_id + 1)
|
||||
end
|
||||
+67
-62
@@ -1,69 +1,74 @@
|
||||
local m, public, private = Aux.module'disenchant'
|
||||
|
||||
function public.source(item_id)
|
||||
private.UNCOMMON = 2
|
||||
private.RARE = 3
|
||||
private.EPIC = 4
|
||||
|
||||
local info = {
|
||||
[10940] = {'DUST', '1-20'},
|
||||
[11083] = {'DUST', '21-30'},
|
||||
[11137] = {'DUST', '31-40'},
|
||||
[11176] = {'DUST', '41-50'},
|
||||
[16204] = {'DUST', '51-60'},
|
||||
do
|
||||
local data = {
|
||||
[10940] = {'DUST', '1-20'},
|
||||
[11083] = {'DUST', '21-30'},
|
||||
[11137] = {'DUST', '31-40'},
|
||||
[11176] = {'DUST', '41-50'},
|
||||
[16204] = {'DUST', '51-60'},
|
||||
|
||||
[10938] = {'ESSENCE', '1-10'},
|
||||
[10939] = {'ESSENCE', '11-15'},
|
||||
[10998] = {'ESSENCE', '16-20'},
|
||||
[11082] = {'ESSENCE', '21-25'},
|
||||
[11134] = {'ESSENCE', '26-30'},
|
||||
[11135] = {'ESSENCE', '31-35'},
|
||||
[11174] = {'ESSENCE', '36-40'},
|
||||
[11175] = {'ESSENCE', '41-45'},
|
||||
[16202] = {'ESSENCE', '46-50'},
|
||||
[16203] = {'ESSENCE', '51-60'},
|
||||
[10938] = {'ESSENCE', '1-10'},
|
||||
[10939] = {'ESSENCE', '11-15'},
|
||||
[10998] = {'ESSENCE', '16-20'},
|
||||
[11082] = {'ESSENCE', '21-25'},
|
||||
[11134] = {'ESSENCE', '26-30'},
|
||||
[11135] = {'ESSENCE', '31-35'},
|
||||
[11174] = {'ESSENCE', '36-40'},
|
||||
[11175] = {'ESSENCE', '41-45'},
|
||||
[16202] = {'ESSENCE', '46-50'},
|
||||
[16203] = {'ESSENCE', '51-60'},
|
||||
|
||||
[10978] = {'SHARD', '1-20'},
|
||||
[11084] = {'SHARD', '21-25'},
|
||||
[11138] = {'SHARD', '26-30'},
|
||||
[11139] = {'SHARD', '31-35'},
|
||||
[11177] = {'SHARD', '36-40'},
|
||||
[11178] = {'SHARD', '41-45'},
|
||||
[14343] = {'SHARD', '46-50'},
|
||||
[14344] = {'SHARD', '51-60'},
|
||||
[10978] = {'SHARD', '1-20'},
|
||||
[11084] = {'SHARD', '21-25'},
|
||||
[11138] = {'SHARD', '26-30'},
|
||||
[11139] = {'SHARD', '31-35'},
|
||||
[11177] = {'SHARD', '36-40'},
|
||||
[11178] = {'SHARD', '41-45'},
|
||||
[14343] = {'SHARD', '46-50'},
|
||||
[14344] = {'SHARD', '51-60'},
|
||||
|
||||
[20725] = {'CRYSTAL', '51+'},
|
||||
}
|
||||
[20725] = {'CRYSTAL', '51+'},
|
||||
}
|
||||
|
||||
return unpack(info[item_id] or {})
|
||||
function public.source(item_id)
|
||||
return data[item_id] and unpack(data[item_id])
|
||||
end
|
||||
end
|
||||
|
||||
local armor = {
|
||||
INVTYPE_HEAD = true,
|
||||
INVTYPE_NECK = true,
|
||||
INVTYPE_SHOULDER = true,
|
||||
INVTYPE_BODY = true,
|
||||
INVTYPE_CHEST = true,
|
||||
INVTYPE_ROBE = true,
|
||||
INVTYPE_WAIST = true,
|
||||
INVTYPE_LEGS = true,
|
||||
INVTYPE_FEET = true,
|
||||
INVTYPE_WRIST = true,
|
||||
INVTYPE_HAND = true,
|
||||
INVTYPE_FINGER = true,
|
||||
INVTYPE_TRINKET = true,
|
||||
INVTYPE_CLOAK = true,
|
||||
INVTYPE_HOLDABLE = true,
|
||||
}
|
||||
function public.LOAD()
|
||||
private.armor = Aux.util.set(
|
||||
'INVTYPE_HEAD',
|
||||
'INVTYPE_NECK',
|
||||
'INVTYPE_SHOULDER',
|
||||
'INVTYPE_BODY',
|
||||
'INVTYPE_CHEST',
|
||||
'INVTYPE_ROBE',
|
||||
'INVTYPE_WAIST',
|
||||
'INVTYPE_LEGS',
|
||||
'INVTYPE_FEET',
|
||||
'INVTYPE_WRIST',
|
||||
'INVTYPE_HAND',
|
||||
'INVTYPE_FINGER',
|
||||
'INVTYPE_TRINKET',
|
||||
'INVTYPE_CLOAK',
|
||||
'INVTYPE_HOLDABLE'
|
||||
)
|
||||
|
||||
local weapon = {
|
||||
INVTYPE_2HWEAPON = true,
|
||||
INVTYPE_WEAPONMAINHAND = true,
|
||||
INVTYPE_WEAPON = true,
|
||||
INVTYPE_WEAPONOFFHAND = true,
|
||||
INVTYPE_SHIELD = true,
|
||||
INVTYPE_RANGED = true,
|
||||
INVTYPE_RANGEDRIGHT = true,
|
||||
}
|
||||
|
||||
local UNCOMMON, RARE, EPIC = 2, 3, 4
|
||||
private.weapon = Aux.util.set(
|
||||
'INVTYPE_2HWEAPON' ,
|
||||
'INVTYPE_WEAPONMAINHAND',
|
||||
'INVTYPE_WEAPON',
|
||||
'INVTYPE_WEAPONOFFHAND',
|
||||
'INVTYPE_SHIELD',
|
||||
'INVTYPE_RANGED',
|
||||
'INVTYPE_RANGEDRIGHT'
|
||||
)
|
||||
end
|
||||
|
||||
function public.value(slot, quality, level)
|
||||
local expectation
|
||||
@@ -79,19 +84,19 @@ function public.value(slot, quality, level)
|
||||
end
|
||||
|
||||
function public.distribution(slot, quality, level)
|
||||
if not (armor[slot] or weapon[slot]) or level == 0 then
|
||||
if not (m.armor[slot] or m.weapon[slot]) or level == 0 then
|
||||
return {}
|
||||
end
|
||||
|
||||
local function p(probability_armor, probability_weapon)
|
||||
if armor[slot] then
|
||||
if m.armor[slot] then
|
||||
return probability_armor
|
||||
elseif weapon[slot] then
|
||||
elseif m.weapon[slot] then
|
||||
return probability_weapon
|
||||
end
|
||||
end
|
||||
|
||||
if quality == UNCOMMON then
|
||||
if quality == m.UNCOMMON then
|
||||
if level <= 10 then
|
||||
return {
|
||||
{item_id=10940, min_quantity=1, max_quantity=2, probability=p(0.8, 0.2)},
|
||||
@@ -158,7 +163,7 @@ function public.distribution(slot, quality, level)
|
||||
{item_id=14344, min_quantity=1, max_quantity=1, probability=p(0.05, 0.03)},
|
||||
}
|
||||
end
|
||||
elseif quality == RARE then
|
||||
elseif quality == m.RARE then
|
||||
if level <= 20 then
|
||||
return {{item_id=10978, min_quantity=1, max_quantity=1, probability=1}}
|
||||
elseif level <= 25 then
|
||||
@@ -178,7 +183,7 @@ function public.distribution(slot, quality, level)
|
||||
elseif level <= 60 then
|
||||
return {{item_id=14344, min_quantity=1, max_quantity=1, probability=0.995}, {item_id=20725, min_quantity=1, max_quantity=1, probability=0.005}}
|
||||
end
|
||||
elseif quality == EPIC then
|
||||
elseif quality == m.EPIC then
|
||||
if level <= 40 then
|
||||
return {{item_id=11177, min_quantity=2, max_quantity=4, probability=1}}
|
||||
elseif level <= 45 then
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@ function private.post_auction(slot, k)
|
||||
Aux.control.event_listener('CHAT_MSG_SYSTEM', function()
|
||||
if arg1 == ERR_AUCTION_STARTED then
|
||||
c()
|
||||
return Aux.control.kill
|
||||
Aux.control.kill()
|
||||
end
|
||||
end)
|
||||
else
|
||||
@@ -69,7 +69,7 @@ end
|
||||
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, callback)
|
||||
m.stop()
|
||||
|
||||
local thread_id = Aux.control.new_thread(m.process)
|
||||
local thread_id = Aux.control.thread(m.process)
|
||||
|
||||
m.state = {
|
||||
thread_id = thread_id,
|
||||
|
||||
+149
-145
@@ -5,28 +5,52 @@ local PAGE_SIZE = 50
|
||||
private.threads = {}
|
||||
private.last_query_time = {}
|
||||
|
||||
private.th = Aux.dynamic_table(function()
|
||||
private.state = Aux.dynamic_table(function()
|
||||
return Aux.util.filter(m.threads, function(thread) return thread.id == Aux.control.thread_id end)[1]
|
||||
end)
|
||||
|
||||
private.q = Aux.dynamic_table(function()
|
||||
return m.th.params.queries[m.th.query_index]
|
||||
return m.state.params.queries[m.state.query_index]
|
||||
end)
|
||||
|
||||
function private.wait_for_callback(...)
|
||||
local ok = true
|
||||
local ret
|
||||
|
||||
local f = tremove(arg, 1)
|
||||
local k = tremove(arg)
|
||||
|
||||
if f then
|
||||
tinsert(arg, {
|
||||
suspend = function() ok = false end,
|
||||
resume = function(...) ok = true ret = arg end,
|
||||
})
|
||||
f(unpack(arg))
|
||||
end
|
||||
|
||||
if ok then
|
||||
return k()
|
||||
else
|
||||
return Aux.control.when(function() return ok end, function() return k(unpack(ret)) end)
|
||||
end
|
||||
end
|
||||
|
||||
function private.total_pages(total_auctions)
|
||||
return math.ceil(total_auctions / PAGE_SIZE)
|
||||
end
|
||||
|
||||
function private.last_page(total_auctions)
|
||||
local last_page = max(m.total_pages(total_auctions) - 1, 0)
|
||||
local last_page_limit = Aux.index(m.q.blizzard_query).last_page/last_page
|
||||
local last_page_limit = m.q.blizzard_query and m.q.blizzard_query.last_page or last_page
|
||||
return min(last_page_limit, last_page)
|
||||
end
|
||||
|
||||
function public.start(params)
|
||||
m.abort(Aux.index(m.threads[params.type]).id/0)
|
||||
if m.threads[params.type] then
|
||||
m.abort(m.threads[params.type].id)
|
||||
end
|
||||
|
||||
local thread_id = Aux.control.new_thread(Aux.f(m.wait_for_callback, params.on_scan_start, m.scan))
|
||||
local thread_id = Aux.control.thread(Aux.f(m.wait_for_callback, params.on_scan_start, m.scan))
|
||||
|
||||
m.threads[params.type] = {
|
||||
id = thread_id,
|
||||
@@ -45,42 +69,146 @@ function public.abort(scan_id)
|
||||
end
|
||||
end
|
||||
|
||||
for _, thread in ipairs(aborted_threads) do
|
||||
Aux.call(thread.params.on_abort)
|
||||
for _, thread in aborted_threads do
|
||||
Aux.safe_call(thread.params.on_abort)
|
||||
end
|
||||
end
|
||||
|
||||
function private.complete()
|
||||
local on_complete = m.state.params.on_complete
|
||||
m.threads[m.state.params.type] = nil
|
||||
if on_complete then
|
||||
return on_complete()
|
||||
end
|
||||
end
|
||||
|
||||
function private.scan()
|
||||
Aux.log(Aux.control.thread_id)
|
||||
m.state.query_index = m.state.query_index and m.state.query_index + 1 or 1
|
||||
if m.q() then
|
||||
if m.q.blizzard_query then
|
||||
m.state.page = m.q.blizzard_query.first_page or 0
|
||||
else
|
||||
m.state.page = nil
|
||||
end
|
||||
return m.wait_for_callback(m.state.params.on_start_query, m.state.query_index, m.process_query)
|
||||
else
|
||||
m.complete()
|
||||
end
|
||||
end
|
||||
|
||||
function private.process_query()
|
||||
if m.q.blizzard_query then
|
||||
return m.submit_query()
|
||||
else
|
||||
return m.scan_page()
|
||||
end
|
||||
end
|
||||
|
||||
function private.submit_query()
|
||||
Aux.control.when(function() return m.state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||
Aux.safe_call(m.state.params.on_submit_query)
|
||||
m.last_query_time[m.state.params.type] = GetTime()
|
||||
if m.state.params.type == 'bidder' then
|
||||
GetBidderAuctionItems(m.state.page)
|
||||
elseif m.state.params.type == 'owner' then
|
||||
GetOwnerAuctionItems(m.state.page)
|
||||
else
|
||||
local blizzard_query = m.q.blizzard_query or {}
|
||||
QueryAuctionItems(
|
||||
blizzard_query.name,
|
||||
blizzard_query.min_level,
|
||||
blizzard_query.max_level,
|
||||
blizzard_query.slot,
|
||||
blizzard_query.class,
|
||||
blizzard_query.subclass,
|
||||
m.state.page,
|
||||
blizzard_query.usable,
|
||||
blizzard_query.quality
|
||||
)
|
||||
end
|
||||
return m.wait_for_results()
|
||||
end)
|
||||
end
|
||||
|
||||
function private.scan_page(i)
|
||||
i = i or 1
|
||||
local recurse = function(retry)
|
||||
if i >= PAGE_SIZE then
|
||||
m.wait_for_callback(m.state.params.on_page_scanned, function()
|
||||
if m.q.blizzard_query and m.state.page < m.last_page(m.state.total_auctions) then
|
||||
m.state.page = m.state.page + 1
|
||||
return m.process_query()
|
||||
else
|
||||
return m.scan()
|
||||
end
|
||||
end)
|
||||
else
|
||||
return m.scan_page(retry and i or i + 1)
|
||||
end
|
||||
end
|
||||
|
||||
local auction_info = Aux.info.auction(i, m.state.params.type)
|
||||
if auction_info and (auction_info.owner or m.state.params.ignore_owner or aux_ignore_owner) then
|
||||
auction_info.index = i
|
||||
auction_info.page = m.state.page
|
||||
auction_info.blizzard_query = m.q.blizzard_query
|
||||
auction_info.query_type = m.state.params.type
|
||||
|
||||
Aux.history.process_auction(auction_info)
|
||||
|
||||
if Aux.safe_call(m.state.params.auto_buy_validator, auction_info) then
|
||||
local c = Aux.control.await(recurse)
|
||||
Aux.place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, Aux.f(c, true))
|
||||
return Aux.control.thread(Aux.control.sleep, 10, Aux.f(c, false))
|
||||
elseif not m.q.validator or m.q.validator(auction_info) then
|
||||
return m.wait_for_callback(m.state.params.on_auction, auction_info, function(removed)
|
||||
if removed then
|
||||
return recurse(true)
|
||||
else
|
||||
return recurse()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
return recurse()
|
||||
end
|
||||
|
||||
function private.timeout(type)
|
||||
return GetTime() - m.last_query_time[type] > 11
|
||||
end
|
||||
|
||||
function private.wait_for_results()
|
||||
local c = Aux.control.await(function()
|
||||
if m.timeout(m.th.params.type) then
|
||||
if m.timeout(m.state.params.type) then
|
||||
return m.submit_query()
|
||||
else
|
||||
_, m.th.total_auctions = GetNumAuctionItems(m.th.params.type)
|
||||
_, m.state.total_auctions = GetNumAuctionItems(m.state.params.type)
|
||||
return m.wait_for_callback(
|
||||
m.th.params.on_page_loaded,
|
||||
m.th.page - (m.q.blizzard_query.first_page or 0) + 1,
|
||||
m.last_page(m.th.total_auctions) - (m.q.blizzard_query.first_page or 0) + 1,
|
||||
m.total_pages(m.th.total_auctions) - 1,
|
||||
m.state.params.on_page_loaded,
|
||||
m.state.page - (m.q.blizzard_query.first_page or 0) + 1,
|
||||
m.last_page(m.state.total_auctions) - (m.q.blizzard_query.first_page or 0) + 1,
|
||||
m.total_pages(m.state.total_auctions) - 1,
|
||||
m.scan_page
|
||||
)
|
||||
end
|
||||
end)
|
||||
Aux.control.as_soon_as(Aux.f(m.timeout, m.th.params.type), c)
|
||||
if m.th.params.type == 'bidder' then
|
||||
|
||||
local type = m.state.params.type
|
||||
Aux.control.as_soon_as(function() return -c or m.timeout(type) end, c)
|
||||
|
||||
if m.state.params.type == 'bidder' then
|
||||
return Aux.control.as_soon_as(function() return Aux.bids_loaded end, c)
|
||||
elseif m.th.params.type == 'owner' then
|
||||
elseif m.state.params.type == 'owner' then
|
||||
return m.wait_for_owner_results(c)
|
||||
elseif m.th.params.type == 'list' then
|
||||
elseif m.state.params.type == 'list' then
|
||||
return m.wait_for_list_results(c)
|
||||
end
|
||||
end
|
||||
|
||||
function private.wait_for_owner_results(c)
|
||||
if m.th.page == Aux.current_owner_page then
|
||||
if m.state.page == Aux.current_owner_page then
|
||||
return c()
|
||||
else
|
||||
return Aux.control.on_next_event('AUCTION_OWNED_LIST_UPDATE', c)
|
||||
@@ -90,17 +218,14 @@ end
|
||||
function private.wait_for_list_results(c)
|
||||
local updated, last_update
|
||||
Aux.control.event_listener('AUCTION_ITEM_LIST_UPDATE', function()
|
||||
if -c then
|
||||
return Aux.control.kill
|
||||
end
|
||||
Aux.control.kill(-c)
|
||||
last_update = GetTime()
|
||||
updated = true
|
||||
end)
|
||||
local type = m.th.params.type
|
||||
local ignore_owner = m.th.params.ignore_owner or aux_ignore_owner
|
||||
local ignore_owner = m.state.params.ignore_owner or aux_ignore_owner
|
||||
return Aux.control.as_soon_as(function()
|
||||
-- short circuiting order important, owner_data_complete must be called iif an update has happened.
|
||||
local ok = updated and (ignore_owner or m.owner_data_complete(type)) or last_update and GetTime() - last_update > 5
|
||||
local ok = updated and (ignore_owner or m.owner_data_complete('list')) or last_update and GetTime() - last_update > 5
|
||||
updated = false
|
||||
return ok
|
||||
end, c)
|
||||
@@ -115,124 +240,3 @@ function private.owner_data_complete(type)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function private.wait_for_callback(...)
|
||||
local ok = true
|
||||
local ret
|
||||
|
||||
local f = tremove(arg, 1)
|
||||
local k = tremove(arg)
|
||||
|
||||
if f then
|
||||
tinsert(arg, {
|
||||
suspend = function() ok = false end,
|
||||
resume = function(...) ok = true ret = arg end,
|
||||
})
|
||||
f(unpack(arg))
|
||||
end
|
||||
|
||||
if ok then
|
||||
return k()
|
||||
else
|
||||
return Aux.control.when(function() return ok end, function() return k(unpack(ret)) end)
|
||||
end
|
||||
end
|
||||
|
||||
function private.scan()
|
||||
m.th.query_index = m.th.query_index and m.th.query_index + 1 or 1
|
||||
if m.q() then
|
||||
if m.q.blizzard_query then
|
||||
m.th.page = m.q.blizzard_query.first_page or 0
|
||||
else
|
||||
m.th.page = nil
|
||||
end
|
||||
return m.wait_for_callback(m.th.params.on_start_query, m.th.query_index, m.process_query)
|
||||
else
|
||||
local on_complete = m.th.params.on_complete
|
||||
m.threads[m.th.params.type] = nil
|
||||
if on_complete then
|
||||
return on_complete()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function private.process_query()
|
||||
if m.q.blizzard_query then
|
||||
return m.submit_query()
|
||||
else
|
||||
return m.scan_page()
|
||||
end
|
||||
end
|
||||
|
||||
function private.scan_page()
|
||||
return m.scan_page_helper(1)
|
||||
end
|
||||
|
||||
function private.scan_page_helper(i)
|
||||
local recurse = function(retry)
|
||||
if i >= PAGE_SIZE then
|
||||
m.wait_for_callback(m.th.params.on_page_scanned, function()
|
||||
if m.q.blizzard_query and m.th.page < m.last_page(m.th.total_auctions) then
|
||||
m.th.page = m.th.page + 1
|
||||
return m.process_query()
|
||||
else
|
||||
return m.scan()
|
||||
end
|
||||
end)
|
||||
else
|
||||
return m.scan_page_helper(retry and i or i + 1)
|
||||
end
|
||||
end
|
||||
|
||||
local auction_info = Aux.info.auction(i, m.th.params.type)
|
||||
if auction_info and (auction_info.owner or m.th.params.ignore_owner or aux_ignore_owner) then
|
||||
auction_info.index = i
|
||||
auction_info.page = m.th.page
|
||||
auction_info.blizzard_query = m.q.blizzard_query
|
||||
auction_info.query_type = m.th.params.type
|
||||
|
||||
Aux.history.process_auction(auction_info)
|
||||
|
||||
if Aux.call(m.th.params.auto_buy_validator, auction_info)/false then
|
||||
local c = Aux.control.await(recurse)
|
||||
Aux.place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, Aux.f(c, true))
|
||||
return Aux.control.new_thread(Aux.control.sleep, 10, Aux.f(c, false))
|
||||
elseif Aux.call(m.q.validator, auction_info)/true then
|
||||
return m.wait_for_callback(m.th.params.on_auction, auction_info, function(removed)
|
||||
if removed then
|
||||
return recurse(true)
|
||||
else
|
||||
return recurse()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
return recurse()
|
||||
end
|
||||
|
||||
function private.submit_query()
|
||||
Aux.control.when(function() return m.th.params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||
Aux.call(m.th.params.on_submit_query)
|
||||
m.last_query_time[m.th.params.type] = GetTime()
|
||||
if m.th.params.type == 'bidder' then
|
||||
GetBidderAuctionItems(m.th.page)
|
||||
elseif m.th.params.type == 'owner' then
|
||||
GetOwnerAuctionItems(m.th.page)
|
||||
else
|
||||
local blizzard_query = Aux.option(m.q.blizzard_query)/{}
|
||||
QueryAuctionItems(
|
||||
blizzard_query.name,
|
||||
blizzard_query.min_level,
|
||||
blizzard_query.max_level,
|
||||
blizzard_query.slot,
|
||||
blizzard_query.class,
|
||||
blizzard_query.subclass,
|
||||
m.th.page,
|
||||
blizzard_query.usable,
|
||||
blizzard_query.quality
|
||||
)
|
||||
end
|
||||
return m.wait_for_results()
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -73,13 +73,13 @@ function SlashCmdList.AUX(command)
|
||||
elseif arguments[1] == 'chars' then
|
||||
local realm = GetCVar('realmName')
|
||||
local chars = {}
|
||||
for name, _ in pairs(aux_characters[realm] or {}) do
|
||||
for name, _ in aux_characters[realm] or {} do
|
||||
tinsert(chars, name)
|
||||
end
|
||||
if getn(chars) > 0 then
|
||||
Aux.log('Your characters: "'..Aux.util.join(chars, ', ')..'".')
|
||||
else
|
||||
Aux.log('You don\'t have any additional characters. Type "/aux addchar NAME" to add one.')
|
||||
Aux.log('You don\'t have any additional characters. To add your characters type "/aux chars add NAME1 NAME2 NAME3...".')
|
||||
end
|
||||
else
|
||||
Aux.log('Unknown command: "'..command..'"')
|
||||
|
||||
@@ -126,7 +126,7 @@ end
|
||||
function public.start(item_key, size, callback)
|
||||
m.stop()
|
||||
|
||||
local thread_id = Aux.control.new_thread(m.process)
|
||||
local thread_id = Aux.control.thread(m.process)
|
||||
|
||||
m.state = {
|
||||
thread_id = thread_id,
|
||||
|
||||
@@ -48,7 +48,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
|
||||
quantity = IsShiftKeyDown() and quantity or 1
|
||||
|
||||
if aux_tooltip_disenchant_source then
|
||||
local color = {r=0.7, g=0.7, b=0.7 }
|
||||
local color = {r=0.7, g=0.7, b=0.7}
|
||||
|
||||
local type, range = Aux.disenchant.source(item_id)
|
||||
|
||||
@@ -105,7 +105,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
|
||||
end
|
||||
end
|
||||
|
||||
local color = {r=1, g=1, b=0.6 }
|
||||
local color = {r=1, g=1, b=0.6}
|
||||
|
||||
local auctionable = not item_info or Aux.info.auctionable(Aux.info.tooltip(function(tt) tt:SetHyperlink(item_info.itemstring) end), item_info.quality)
|
||||
local item_key = (item_id or 0)..':'..(suffix_id or 0)
|
||||
|
||||
Reference in New Issue
Block a user