module refactoring
This commit is contained in:
+35
-35
@@ -1,19 +1,19 @@
|
||||
aux 'cache' local info, persistence = aux.info, aux.persistence
|
||||
|
||||
MIN_ITEM_ID = 1
|
||||
MAX_ITEM_ID = 30000
|
||||
local MIN_ITEM_ID = 1
|
||||
local MAX_ITEM_ID = 30000
|
||||
|
||||
--items_schema = record '#' {name='string'} {quality='number'} {level='number'} {class='string'} {subclass='string'} {slot='string'} {max_stack='number'} {texture='string'} -- TODO
|
||||
|
||||
items_schema = {'record', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}}
|
||||
merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'}}
|
||||
local items_schema = {'record', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}}
|
||||
local merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'}}
|
||||
|
||||
_G.aux_items = t
|
||||
_G.aux_item_ids = t
|
||||
_G.aux_auctionable_items = t
|
||||
_G.aux_merchant_buy = t
|
||||
_G.aux_merchant_sell = t
|
||||
_G.aux_characters = t
|
||||
aux_items = t
|
||||
aux_item_ids = t
|
||||
aux_auctionable_items = t
|
||||
aux_merchant_buy = t
|
||||
aux_merchant_sell = t
|
||||
aux_characters = t
|
||||
|
||||
function LOAD()
|
||||
scan_wdb()
|
||||
@@ -28,7 +28,7 @@ function LOAD()
|
||||
event_listener('NEW_AUCTION_UPDATE', function()
|
||||
for info in present(info.auction_sell_item()) do
|
||||
for item_id in present(item_id(info.name)) do
|
||||
_G.aux_merchant_sell[_E.item_id(info.name)] = info.vendor_price / (aux.info.max_item_charges(item_id) or info.count)
|
||||
aux_merchant_sell[_E.item_id(info.name)] = info.vendor_price / (aux.info.max_item_charges(item_id) or info.count)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -36,25 +36,25 @@ end
|
||||
|
||||
do
|
||||
local sell_scan_countdown, incomplete_buy_data
|
||||
function on_merchant_show()
|
||||
function private.on_merchant_show()
|
||||
merchant_sell_scan()
|
||||
incomplete_buy_data = not merchant_buy_scan()
|
||||
end
|
||||
function on_merchant_closed()
|
||||
function private.on_merchant_closed()
|
||||
sell_scan_countdown = nil
|
||||
incomplete_buy_data = false
|
||||
end
|
||||
function on_merchant_update()
|
||||
function private.on_merchant_update()
|
||||
if incomplete_buy_data then
|
||||
incomplete_buy_data = not merchant_buy_scan()
|
||||
end
|
||||
end
|
||||
function on_bag_update()
|
||||
function private.on_bag_update()
|
||||
if MerchantFrame:IsVisible() then
|
||||
sell_scan_countdown = 10
|
||||
end
|
||||
end
|
||||
function merchant_on_update()
|
||||
function private.merchant_on_update()
|
||||
if sell_scan_countdown == 0 then
|
||||
sell_scan_countdown = nil
|
||||
merchant_sell_scan()
|
||||
@@ -64,7 +64,7 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function merchant_loaded()
|
||||
function private.merchant_loaded()
|
||||
for i = 1, GetMerchantNumItems() do
|
||||
if not GetMerchantItemLink(i) then
|
||||
return false
|
||||
@@ -75,15 +75,15 @@ end
|
||||
|
||||
function public.merchant_info(item_id)
|
||||
local buy_info
|
||||
if _G.aux_merchant_buy[item_id] then
|
||||
buy_info = persistence.read(merchant_buy_schema, _G.aux_merchant_buy[item_id])
|
||||
if aux_merchant_buy[item_id] then
|
||||
buy_info = persistence.read(merchant_buy_schema, aux_merchant_buy[item_id])
|
||||
end
|
||||
|
||||
return _G.aux_merchant_sell[item_id], buy_info and buy_info.unit_price, buy_info and buy_info.limited
|
||||
return aux_merchant_sell[item_id], buy_info and buy_info.unit_price, buy_info and buy_info.limited
|
||||
end
|
||||
|
||||
function public.item_info(item_id)
|
||||
local data_string = _G.aux_items[item_id]
|
||||
local data_string = aux_items[item_id]
|
||||
if data_string then
|
||||
local cached_data = persistence.read(items_schema, data_string)
|
||||
return T(
|
||||
@@ -101,10 +101,10 @@ function public.item_info(item_id)
|
||||
end
|
||||
|
||||
function public.item_id(item_name)
|
||||
return _G.aux_item_ids[strlower(item_name)]
|
||||
return aux_item_ids[strlower(item_name)]
|
||||
end
|
||||
|
||||
function merchant_buy_scan()
|
||||
function private.merchant_buy_scan()
|
||||
|
||||
local incomplete_data
|
||||
for i = 1, GetMerchantNumItems() do
|
||||
@@ -113,8 +113,8 @@ function merchant_buy_scan()
|
||||
if link then
|
||||
local item_id = info.parse_link(link)
|
||||
local new_unit_price, new_limited = price / count, stock >= 0
|
||||
if _G.aux_merchant_buy[item_id] then
|
||||
local buy_info = persistence.read(merchant_buy_schema, _G.aux_merchant_buy[item_id])
|
||||
if aux_merchant_buy[item_id] then
|
||||
local buy_info = persistence.read(merchant_buy_schema, aux_merchant_buy[item_id])
|
||||
|
||||
local unit_price
|
||||
if buy_info.limited and not new_limited then
|
||||
@@ -125,12 +125,12 @@ function merchant_buy_scan()
|
||||
unit_price = min(buy_info.unit_price, new_unit_price)
|
||||
end
|
||||
|
||||
_G.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T(
|
||||
aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T(
|
||||
'unit_price', unit_price,
|
||||
'limited', buy_info.limited and new_limited
|
||||
))
|
||||
else
|
||||
_G.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T(
|
||||
aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T(
|
||||
'unit_price', new_unit_price,
|
||||
'limited', new_limited
|
||||
))
|
||||
@@ -143,25 +143,25 @@ function merchant_buy_scan()
|
||||
return not incomplete_data
|
||||
end
|
||||
|
||||
function merchant_sell_scan()
|
||||
function private.merchant_sell_scan()
|
||||
for slot in info.inventory do auto[slot] = true
|
||||
local item_info = temp-info.container_item(unpack(slot))
|
||||
if item_info then
|
||||
_G.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 scan_wdb(item_id)
|
||||
function private.scan_wdb(item_id)
|
||||
item_id = item_id or MIN_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 _G.aux_item_ids[strlower(name)] then
|
||||
_G.aux_item_ids[strlower(name)] = item_id
|
||||
_G.aux_items[item_id] = persistence.write(items_schema, T(
|
||||
if name and not aux_item_ids[strlower(name)] then
|
||||
aux_item_ids[strlower(name)] = item_id
|
||||
aux_items[item_id] = persistence.write(items_schema, T(
|
||||
'name', name,
|
||||
'quality', quality,
|
||||
'level', level,
|
||||
@@ -173,7 +173,7 @@ function scan_wdb(item_id)
|
||||
))
|
||||
local tooltip = info.tooltip(function(tooltip) tooltip:SetHyperlink(itemstring) end)
|
||||
if info.auctionable(tooltip, quality) then
|
||||
tinsert(_G.aux_auctionable_items, strlower(name))
|
||||
tinsert(aux_auctionable_items, strlower(name))
|
||||
end
|
||||
processed = processed + 1
|
||||
end
|
||||
@@ -183,7 +183,7 @@ function scan_wdb(item_id)
|
||||
if item_id <= MAX_ITEM_ID then
|
||||
thread(wait, 10, scan_wdb, item_id)
|
||||
else
|
||||
sort(_G.aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
|
||||
sort(aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+56
-57
@@ -1,71 +1,70 @@
|
||||
aux 'disenchant'
|
||||
|
||||
UNCOMMON, RARE, EPIC = 2, 3, 4
|
||||
local UNCOMMON, RARE, EPIC = 2, 3, 4
|
||||
|
||||
do
|
||||
local data = {
|
||||
[10940] = A('DUST', '1-20'),
|
||||
[11083] = A('DUST', '21-30'),
|
||||
[11137] = A('DUST', '31-40'),
|
||||
[11176] = A('DUST', '41-50'),
|
||||
[16204] = A('DUST', '51-60'),
|
||||
local data = T(
|
||||
10940, A('DUST', '1-20'),
|
||||
11083, A('DUST', '21-30'),
|
||||
11137, A('DUST', '31-40'),
|
||||
11176, A('DUST', '41-50'),
|
||||
16204, A('DUST', '51-60'),
|
||||
|
||||
[10938] = A('ESSENCE', '1-10'),
|
||||
[10939] = A('ESSENCE', '11-15'),
|
||||
[10998] = A('ESSENCE', '16-20'),
|
||||
[11082] = A('ESSENCE', '21-25'),
|
||||
[11134] = A('ESSENCE', '26-30'),
|
||||
[11135] = A('ESSENCE', '31-35'),
|
||||
[11174] = A('ESSENCE', '36-40'),
|
||||
[11175] = A('ESSENCE', '41-45'),
|
||||
[16202] = A('ESSENCE', '46-50'),
|
||||
[16203] = A('ESSENCE', '51-60'),
|
||||
10938, A('ESSENCE', '1-10'),
|
||||
10939, A('ESSENCE', '11-15'),
|
||||
10998, A('ESSENCE', '16-20'),
|
||||
11082, A('ESSENCE', '21-25'),
|
||||
11134, A('ESSENCE', '26-30'),
|
||||
11135, A('ESSENCE', '31-35'),
|
||||
11174, A('ESSENCE', '36-40'),
|
||||
11175, A('ESSENCE', '41-45'),
|
||||
16202, A('ESSENCE', '46-50'),
|
||||
16203, A('ESSENCE', '51-60'),
|
||||
|
||||
[10978] = A('SHARD', '1-20'),
|
||||
[11084] = A('SHARD', '21-25'),
|
||||
[11138] = A('SHARD', '26-30'),
|
||||
[11139] = A('SHARD', '31-35'),
|
||||
[11177] = A('SHARD', '36-40'),
|
||||
[11178] = A('SHARD', '41-45'),
|
||||
[14343] = A('SHARD', '46-50'),
|
||||
[14344] = A('SHARD', '51-60'),
|
||||
10978, A('SHARD', '1-20'),
|
||||
11084, A('SHARD', '21-25'),
|
||||
11138, A('SHARD', '26-30'),
|
||||
11139, A('SHARD', '31-35'),
|
||||
11177, A('SHARD', '36-40'),
|
||||
11178, A('SHARD', '41-45'),
|
||||
14343, A('SHARD', '46-50'),
|
||||
14344, A('SHARD', '51-60'),
|
||||
|
||||
[20725] = A('CRYSTAL', '51+'),
|
||||
}
|
||||
20725, A('CRYSTAL', '51+')
|
||||
)
|
||||
|
||||
function public.source(item_id)
|
||||
return unpack(data[item_id] or tt)
|
||||
return unpack(data[item_id] or empty)
|
||||
end
|
||||
end
|
||||
|
||||
function LOAD()
|
||||
ARMOR = S(
|
||||
'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'
|
||||
)
|
||||
WEAPON = S(
|
||||
'INVTYPE_2HWEAPON',
|
||||
'INVTYPE_WEAPONMAINHAND',
|
||||
'INVTYPE_WEAPON',
|
||||
'INVTYPE_WEAPONOFFHAND',
|
||||
'INVTYPE_SHIELD',
|
||||
'INVTYPE_RANGED',
|
||||
'INVTYPE_RANGEDRIGHT'
|
||||
)
|
||||
end
|
||||
local ARMOR = S(
|
||||
'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 = S(
|
||||
'INVTYPE_2HWEAPON',
|
||||
'INVTYPE_WEAPONMAINHAND',
|
||||
'INVTYPE_WEAPON',
|
||||
'INVTYPE_WEAPONOFFHAND',
|
||||
'INVTYPE_SHIELD',
|
||||
'INVTYPE_RANGED',
|
||||
'INVTYPE_RANGEDRIGHT'
|
||||
)
|
||||
|
||||
function public.value(slot, quality, level)
|
||||
local expectation
|
||||
@@ -81,7 +80,7 @@ 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 ARMOR[slot] and not WEAPON[slot] or level == 0 then
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
+5
-5
@@ -2,7 +2,7 @@ aux 'history' local persistence = aux.persistence
|
||||
|
||||
local history_schema = {'record', '#', {next_push='number'}, {daily_min_buyout='number'}, {daily_max_price='number'}, {data_points={'list', ';', {'record', '@', {market_value='number'}, {time='number'}}}} }
|
||||
|
||||
value_cache = t
|
||||
local value_cache = t
|
||||
|
||||
do
|
||||
local cache
|
||||
@@ -32,7 +32,7 @@ function private.new_record.get()
|
||||
return T('next_push', next_push, 'data_points', t)
|
||||
end
|
||||
|
||||
function read_record(item_key)
|
||||
function private.read_record(item_key)
|
||||
local record = data[item_key] and persistence.read(history_schema, data[item_key]) or new_record
|
||||
if record.next_push <= time() then
|
||||
push_record(record)
|
||||
@@ -41,7 +41,7 @@ function read_record(item_key)
|
||||
return record
|
||||
end
|
||||
|
||||
function write_record(item_key, record)
|
||||
function private.write_record(item_key, record)
|
||||
value_cache[item_key] = nil
|
||||
data[item_key] = persistence.write(history_schema, record)
|
||||
end
|
||||
@@ -100,7 +100,7 @@ function calculate_market_value(item_record)
|
||||
return item_record.daily_min_buyout and min(ceil(item_record.daily_min_buyout * 1.15), item_record.daily_max_price)
|
||||
end
|
||||
|
||||
function weighted_median(list)
|
||||
function private.weighted_median(list)
|
||||
sort(list, function(a,b) return a.value < b.value end)
|
||||
local weight = 0
|
||||
for _, element in list do
|
||||
@@ -111,7 +111,7 @@ function weighted_median(list)
|
||||
end
|
||||
end
|
||||
|
||||
function push_record(item_record)
|
||||
function private.push_record(item_record)
|
||||
for market_value in present(calculate_market_value(item_record)) do
|
||||
tinsert(item_record.data_points, 1, T('market_value', market_value, 'time', item_record.next_push))
|
||||
while getn(item_record.data_points) > 11 do
|
||||
|
||||
+4
-7
@@ -1,8 +1,8 @@
|
||||
aux 'post'
|
||||
|
||||
local state = nil
|
||||
local state
|
||||
|
||||
function process()
|
||||
function private.process()
|
||||
if state.posted < state.count then
|
||||
|
||||
local stacking_complete
|
||||
@@ -23,7 +23,7 @@ function process()
|
||||
return stop()
|
||||
end
|
||||
|
||||
function post_auction(slot, k)
|
||||
function private.post_auction(slot, k)
|
||||
local item_info = aux.info.container_item(unpack(slot))
|
||||
if item_info.item_key == state.item_key and aux.info.auctionable(item_info.tooltip) and item_info.aux_quantity == state.stack_size then
|
||||
|
||||
@@ -71,11 +71,8 @@ end
|
||||
|
||||
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, callback)
|
||||
stop()
|
||||
|
||||
local thread_id = thread(process)
|
||||
|
||||
state = {
|
||||
thread_id = thread_id,
|
||||
thread_id = thread(process),
|
||||
item_key = item_key,
|
||||
stack_size = stack_size,
|
||||
duration = duration,
|
||||
|
||||
+37
-24
@@ -27,22 +27,29 @@ do
|
||||
end
|
||||
end
|
||||
for _, state in aborted do
|
||||
(state.params.on_abort or nop)()
|
||||
do (state.params.on_abort or nop)() end
|
||||
end
|
||||
end
|
||||
|
||||
function complete()
|
||||
function private.complete()
|
||||
local on_complete = state.params.on_complete
|
||||
scan_states[state.params.type] = nil
|
||||
(on_complete or nop)()
|
||||
-- for _ in on_complete or nop do end TODO test performance
|
||||
do (on_complete or nop)() end
|
||||
end
|
||||
|
||||
function private.state.get()
|
||||
for _, state in scan_states do if state.id == thread_id then return state end end
|
||||
for _, state in scan_states do
|
||||
if state.id == thread_id then
|
||||
return state
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function private.query.get() return state.params.queries[state.query_index] end
|
||||
function private.query.get()
|
||||
return state.params.queries[state.query_index]
|
||||
end
|
||||
|
||||
function private.vararg.wait_for_callback(arg)
|
||||
local send_signal, signal_received = signal()
|
||||
@@ -52,10 +59,14 @@ function private.vararg.wait_for_callback(arg)
|
||||
local k = tremove(arg)
|
||||
|
||||
if f then
|
||||
tinsert(arg, {
|
||||
suspend = function() suspended = true end,
|
||||
resume = send_signal,
|
||||
})
|
||||
tinsert(arg, T(
|
||||
'suspend', function() suspended = true end,
|
||||
'resume', send_signal
|
||||
))
|
||||
-- tinsert(arg, -pairs TODO
|
||||
-- :suspend (function() suspended = true end)
|
||||
-- :resume (send_signal)
|
||||
-- )
|
||||
f(unpack(arg))
|
||||
end
|
||||
if not suspended then send_signal() end
|
||||
@@ -63,17 +74,17 @@ function private.vararg.wait_for_callback(arg)
|
||||
return when(signal_received, function() return k(unpack(signal_received())) end)
|
||||
end
|
||||
|
||||
function total_pages(total_auctions)
|
||||
function private.total_pages(total_auctions)
|
||||
return ceil(total_auctions / PAGE_SIZE)
|
||||
end
|
||||
|
||||
function last_page(total_auctions)
|
||||
function private.last_page(total_auctions)
|
||||
local last_page = max(total_pages(total_auctions) - 1, 0)
|
||||
local last_page_limit = query.blizzard_query and query.blizzard_query.last_page or last_page
|
||||
return min(last_page_limit, last_page)
|
||||
end
|
||||
|
||||
function scan()
|
||||
function private.scan()
|
||||
state.query_index = state.query_index and state.query_index + 1 or 1
|
||||
if query and (index(query.blizzard_query, 'first_page') or 0) <= (index(query.blizzard_query, 'last_page') or huge) then
|
||||
if query.blizzard_query then
|
||||
@@ -87,13 +98,13 @@ function scan()
|
||||
end
|
||||
end
|
||||
|
||||
function process_query()
|
||||
function private.process_query()
|
||||
return (query.blizzard_query and submit_query or scan_page)()
|
||||
end
|
||||
|
||||
function submit_query()
|
||||
function private.submit_query()
|
||||
when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||
(state.params.on_submit_query or nop)()
|
||||
do (state.params.on_submit_query or nop)() end
|
||||
state.last_query_time = GetTime()
|
||||
if state.params.type == 'bidder' then
|
||||
GetBidderAuctionItems(state.page)
|
||||
@@ -117,7 +128,7 @@ function submit_query()
|
||||
end)
|
||||
end
|
||||
|
||||
function scan_page(i)
|
||||
function private.scan_page(i)
|
||||
i = i or 1
|
||||
local recurse = function(retry)
|
||||
if i >= PAGE_SIZE then
|
||||
@@ -135,7 +146,7 @@ function scan_page(i)
|
||||
end
|
||||
|
||||
local auction_info = info.auction(i, state.params.type)
|
||||
if auction_info and (auction_info.owner or state.params.ignore_owner or _G.aux_ignore_owner) then
|
||||
if auction_info and (auction_info.owner or state.params.ignore_owner or aux_ignore_owner) then
|
||||
auction_info.index = i
|
||||
auction_info.page = state.page
|
||||
auction_info.blizzard_query = query.blizzard_query
|
||||
@@ -146,7 +157,7 @@ function scan_page(i)
|
||||
if (state.params.auto_buy_validator or nop)(auction_info) then
|
||||
local send_signal, signal_received = signal()
|
||||
when(signal_received, recurse)
|
||||
place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, partial(send_signal, true))
|
||||
place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, papply(send_signal, true))
|
||||
return thread(when, later(GetTime(), 10), send_signal, false)
|
||||
elseif not query.validator or query.validator(auction_info) then
|
||||
return wait_for_callback(state.params.on_auction, auction_info, function(removed)
|
||||
@@ -162,7 +173,7 @@ function scan_page(i)
|
||||
return recurse()
|
||||
end
|
||||
|
||||
function wait_for_results()
|
||||
function private.wait_for_results()
|
||||
local timeout = later(state.last_query_time, 10)
|
||||
local send_signal, signal_received = signal()
|
||||
when(signal_received, function()
|
||||
@@ -191,7 +202,7 @@ function wait_for_results()
|
||||
end
|
||||
end
|
||||
|
||||
function wait_for_owner_results(send_signal)
|
||||
function private.wait_for_owner_results(send_signal)
|
||||
if state.page == current_owner_page then
|
||||
return send_signal()
|
||||
else
|
||||
@@ -199,14 +210,14 @@ function wait_for_owner_results(send_signal)
|
||||
end
|
||||
end
|
||||
|
||||
function wait_for_list_results(send_signal, signal_received)
|
||||
function private.wait_for_list_results(send_signal, signal_received)
|
||||
local updated, last_update
|
||||
event_listener('AUCTION_ITEM_LIST_UPDATE', function(kill)
|
||||
kill(signal_received())
|
||||
last_update = GetTime()
|
||||
updated = true
|
||||
end)
|
||||
local ignore_owner = state.params.ignore_owner or _G.aux_ignore_owner
|
||||
local ignore_owner = state.params.ignore_owner or aux_ignore_owner
|
||||
return thread(when, function()
|
||||
-- short circuiting order important, owner_data_complete must be called iif an update has happened.
|
||||
local ok = updated and (ignore_owner or owner_data_complete('list')) or last_update and GetTime() - last_update > 5
|
||||
@@ -215,10 +226,12 @@ function wait_for_list_results(send_signal, signal_received)
|
||||
end, send_signal)
|
||||
end
|
||||
|
||||
function owner_data_complete(type)
|
||||
function private.owner_data_complete(type)
|
||||
for i = 1, PAGE_SIZE do
|
||||
local auction_info = info.auction(i, type)
|
||||
if auction_info and not auction_info.owner then return false end
|
||||
if auction_info and not auction_info.owner then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
+33
-33
@@ -1,9 +1,9 @@
|
||||
aux 'slash' local persistence = aux.persistence
|
||||
|
||||
_G.aux_ignore_owner = true
|
||||
aux_ignore_owner = true
|
||||
|
||||
_G.SLASH_AUX1 = '/aux'
|
||||
function _G.SlashCmdList.AUX(command)
|
||||
SLASH_AUX1 = '/aux'
|
||||
function SlashCmdList.AUX(command)
|
||||
if not command then return end
|
||||
local arguments = tokenize(command)
|
||||
if arguments[1] == 'clear' and arguments[2] == 'history' then
|
||||
@@ -13,77 +13,77 @@ function _G.SlashCmdList.AUX(command)
|
||||
persistence.dataset.post = nil
|
||||
print 'Post settings cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'datasets' then
|
||||
_G.aux_datasets = t
|
||||
aux_datasets = t
|
||||
print 'Datasets cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'buy' then
|
||||
_G.aux_merchant_buy = t
|
||||
aux_merchant_buy = t
|
||||
print 'Merchant buy prices cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'sell' then
|
||||
_G.aux_merchant_sell = t
|
||||
aux_merchant_sell = t
|
||||
print 'Merchant sell prices cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'item' and arguments[3] == 'cache' then
|
||||
_G.aux_items = t
|
||||
_G.aux_item_ids = t
|
||||
_G.aux_auctionable_items = t
|
||||
aux_items = t
|
||||
aux_item_ids = t
|
||||
aux_auctionable_items = t
|
||||
print 'Item cache cleared.'
|
||||
elseif arguments[1] == 'populate' and arguments[2] == 'wdb' then
|
||||
aux.cache.populate_wdb()
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'value' then
|
||||
_G.aux_tooltip_value = not _G.aux_tooltip_value
|
||||
print('Historical value in tooltip ' .. (_G.aux_tooltip_value and 'enabled' or 'disabled') .. '.')
|
||||
aux_tooltip_value = not aux_tooltip_value
|
||||
print('Historical value in tooltip ' .. (aux_tooltip_value and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'daily' then
|
||||
_G.aux_tooltip_daily = not _G.aux_tooltip_daily
|
||||
print('Market value in tooltip ' .. (_G.aux_tooltip_daily and 'enabled' or 'disabled') .. '.')
|
||||
aux_tooltip_daily = not aux_tooltip_daily
|
||||
print('Market value in tooltip ' .. (aux_tooltip_daily and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'vendor' and arguments[3] == 'buy' then
|
||||
_G.aux_tooltip_vendor_buy = not _G.aux_tooltip_vendor_buy
|
||||
print('Vendor buy price in tooltip ' .. (_G.aux_tooltip_vendor_buy and 'enabled' or 'disabled') .. '.')
|
||||
aux_tooltip_vendor_buy = not aux_tooltip_vendor_buy
|
||||
print('Vendor buy price in tooltip ' .. (aux_tooltip_vendor_buy and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'vendor' and arguments[3] == 'sell' then
|
||||
_G.aux_tooltip_vendor_sell = not _G.aux_tooltip_vendor_sell
|
||||
print('Vendor sell price in tooltip ' .. (_G.aux_tooltip_vendor_sell and 'enabled' or 'disabled') .. '.')
|
||||
aux_tooltip_vendor_sell = not aux_tooltip_vendor_sell
|
||||
print('Vendor sell price in tooltip ' .. (aux_tooltip_vendor_sell and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'value' then
|
||||
_G.aux_tooltip_disenchant_value = not _G.aux_tooltip_disenchant_value
|
||||
print('Disenchant value in tooltip ' .. (_G.aux_tooltip_disenchant_value and 'enabled' or 'disabled') .. '.')
|
||||
aux_tooltip_disenchant_value = not aux_tooltip_disenchant_value
|
||||
print('Disenchant value in tooltip ' .. (aux_tooltip_disenchant_value and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'distribution' then
|
||||
_G.aux_tooltip_disenchant_distribution = not _G.aux_tooltip_disenchant_distribution
|
||||
print('Disenchant distribution in tooltip ' .. (_G.aux_tooltip_disenchant_distribution and 'enabled' or 'disabled') .. '.')
|
||||
aux_tooltip_disenchant_distribution = not aux_tooltip_disenchant_distribution
|
||||
print('Disenchant distribution in tooltip ' .. (aux_tooltip_disenchant_distribution and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'source' then
|
||||
_G.aux_tooltip_disenchant_source = not _G.aux_tooltip_disenchant_source
|
||||
print('Disenchant source in tooltip ' .. (_G.aux_tooltip_disenchant_source and 'enabled' or 'disabled') .. '.')
|
||||
aux_tooltip_disenchant_source = not aux_tooltip_disenchant_source
|
||||
print('Disenchant source in tooltip ' .. (aux_tooltip_disenchant_source and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'ignore' and arguments[2] == 'owner' then
|
||||
_G.aux_ignore_owner = not _G.aux_ignore_owner
|
||||
print('Ignoring of owner ' .. (_G.aux_ignore_owner and 'enabled' or 'disabled') .. '.')
|
||||
aux_ignore_owner = not aux_ignore_owner
|
||||
print('Ignoring of owner ' .. (aux_ignore_owner and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'chars' and arguments[2] == 'add' then
|
||||
local realm = GetCVar('realmName')
|
||||
_G.aux_characters[realm] = _G.aux_characters[realm] or t
|
||||
aux_characters[realm] = aux_characters[realm] or t
|
||||
for i = 3, getn(arguments) do
|
||||
local name = gsub(strlower(arguments[i]), '^%l', strupper)
|
||||
if not _G.aux_characters[realm][name] then
|
||||
_G.aux_characters[realm][name] = true
|
||||
if not aux_characters[realm][name] then
|
||||
aux_characters[realm][name] = true
|
||||
print('Character "' .. name .. '" added.')
|
||||
end
|
||||
end
|
||||
elseif arguments[1] == 'chars' and arguments[2] == 'remove' then
|
||||
local realm = GetCVar('realmName')
|
||||
if not _G.aux_characters[realm] then
|
||||
if not aux_characters[realm] then
|
||||
return
|
||||
end
|
||||
for i = 3, getn(arguments) do
|
||||
local name = gsub(strlower(arguments[i]), '^%l', strupper)
|
||||
if _G.aux_characters[realm][name] then
|
||||
_G.aux_characters[realm][name] = nil
|
||||
if aux_characters[realm][name] then
|
||||
aux_characters[realm][name] = nil
|
||||
print('Character "' .. name .. '" removed.')
|
||||
end
|
||||
end
|
||||
elseif arguments[1] == 'chars' then
|
||||
local realm = GetCVar('realmName')
|
||||
local chars = t
|
||||
for name in _G.aux_characters[realm] or t do
|
||||
for name in aux_characters[realm] or t do
|
||||
tinsert(chars, name)
|
||||
end
|
||||
if getn(chars) > 0 then
|
||||
print('Your characters: "' .. join(chars, ', ') .. '".')
|
||||
else
|
||||
print 'You don\'t have any additional characters. To add your characters type "/aux chars add NAME1 NAME2 NAME3...".'
|
||||
print('You don\'t have any additional characters. To add your characters type "/aux chars add NAME1 NAME2 NAME3...".')
|
||||
end
|
||||
else
|
||||
print('Unknown command: "' .. command .. '"')
|
||||
|
||||
+14
-18
@@ -2,40 +2,40 @@ aux 'stack' local info = aux.info
|
||||
|
||||
local state
|
||||
|
||||
function stack_size(slot)
|
||||
function private.stack_size(slot)
|
||||
local container_item_info = info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.count or 0
|
||||
end
|
||||
|
||||
function charges(slot)
|
||||
function private.charges(slot)
|
||||
local container_item_info = info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.charges
|
||||
end
|
||||
|
||||
function max_stack(slot)
|
||||
function private.max_stack(slot)
|
||||
local container_item_info = info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.max_stack
|
||||
end
|
||||
|
||||
function locked(slot)
|
||||
function private.locked(slot)
|
||||
local container_item_info = info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.locked
|
||||
end
|
||||
|
||||
function find_item_slot(partial)
|
||||
function private.find_item_slot(papply)
|
||||
for slot in info.inventory do
|
||||
if matching_item(slot, partial) and not eq(slot, state.target_slot) then
|
||||
if matching_item(slot, papply) and not eq(slot, state.target_slot) then
|
||||
return slot
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function matching_item(slot, partial)
|
||||
function private.matching_item(slot, papply)
|
||||
local item_info = info.container_item(unpack(slot))
|
||||
return item_info and item_info.item_key == state.item_key and info.auctionable(item_info.tooltip) and (not partial or item_info.count < item_info.max_stack)
|
||||
return item_info and item_info.item_key == state.item_key and info.auctionable(item_info.tooltip) and (not papply or item_info.count < item_info.max_stack)
|
||||
end
|
||||
|
||||
function find_empty_slot()
|
||||
function private.find_empty_slot()
|
||||
for slot, type in info.inventory do
|
||||
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
|
||||
return slot
|
||||
@@ -43,7 +43,7 @@ function find_empty_slot()
|
||||
end
|
||||
end
|
||||
|
||||
function find_charge_item_slot()
|
||||
function private.find_charge_item_slot()
|
||||
for slot in info.inventory do
|
||||
if matching_item(slot) and charges(slot) == state.target_size then
|
||||
return slot
|
||||
@@ -51,7 +51,7 @@ function find_charge_item_slot()
|
||||
end
|
||||
end
|
||||
|
||||
function move_item(from_slot, to_slot, amount, k)
|
||||
function private.move_item(from_slot, to_slot, amount, k)
|
||||
if locked(from_slot) or locked(to_slot) then
|
||||
return wait(k)
|
||||
end
|
||||
@@ -66,15 +66,13 @@ function move_item(from_slot, to_slot, amount, k)
|
||||
return when(function() return stack_size(to_slot) == expected_size end, k)
|
||||
end
|
||||
|
||||
function process()
|
||||
|
||||
function private.process()
|
||||
if not state.target_slot or not matching_item(state.target_slot) then
|
||||
state.target_slot = find_item_slot()
|
||||
if not state.target_slot then
|
||||
return stop()
|
||||
end
|
||||
end
|
||||
|
||||
if charges(state.target_slot) then
|
||||
state.target_slot = find_charge_item_slot()
|
||||
return stop()
|
||||
@@ -109,16 +107,14 @@ function public.stop()
|
||||
local callback, slot = state.callback, state.target_slot
|
||||
slot = slot and matching_item(slot) and slot or nil
|
||||
state = nil
|
||||
(callback or nop)(slot)
|
||||
do (callback or nop)(slot) end
|
||||
end
|
||||
end
|
||||
|
||||
function public.start(item_key, size, callback)
|
||||
stop()
|
||||
|
||||
local thread_id = thread(process)
|
||||
state = {
|
||||
thread_id = thread_id,
|
||||
thread_id = thread(process),
|
||||
item_key = item_key,
|
||||
target_size = size,
|
||||
callback = callback,
|
||||
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
aux 'tooltip' local info, disenchant, cache, money, history = aux.info, aux.disenchant, aux.cache, aux.money, aux.history
|
||||
|
||||
_G.aux_tooltip_value = true
|
||||
aux_tooltip_value = true
|
||||
|
||||
local game_tooltip_hooks, game_tooltip_money = t, 0
|
||||
|
||||
@@ -43,8 +43,8 @@ end
|
||||
function extend_tooltip(tooltip, link, quantity)
|
||||
local item_id, suffix_id = info.parse_link(link)
|
||||
quantity = IsShiftKeyDown() and quantity or 1
|
||||
if _G.aux_tooltip_disenchant_source then
|
||||
local color = {r=.7, g=.7, b=.7}
|
||||
if aux_tooltip_disenchant_source then
|
||||
local color = { r=.7, g=.7, b=.7 }
|
||||
local type, range = disenchant.source(item_id)
|
||||
if type == 'CRYSTAL' then
|
||||
tooltip:AddLine(format('Can disenchant from level %s |cffa335eeEpic|r and |cff0070ddRare|r items.', range), color.r, color.g, color.b, true)
|
||||
@@ -60,8 +60,8 @@ function extend_tooltip(tooltip, link, quantity)
|
||||
if item_info then
|
||||
local distribution = disenchant.distribution(item_info.slot, item_info.quality, item_info.level)
|
||||
if getn(distribution) > 0 then
|
||||
if _G.aux_tooltip_disenchant_distribution then
|
||||
local color = {r=.8, g=.8, b=.2}
|
||||
if aux_tooltip_disenchant_distribution then
|
||||
local color = { r=.8, g=.8, b=.2 }
|
||||
|
||||
tooltip:AddLine('Disenchants into:', color.r, color.g, color.b)
|
||||
sort(distribution, function(a,b) return a.probability > b.probability end)
|
||||
@@ -69,37 +69,37 @@ function extend_tooltip(tooltip, link, quantity)
|
||||
tooltip:AddLine(format(' %s%% %s (%s-%s)', event.probability * 100, info.display_name(event.item_id, true) or 'item:' .. event.item_id, event.min_quantity, event.max_quantity), color.r, color.g, color.b)
|
||||
end
|
||||
end
|
||||
if _G.aux_tooltip_disenchant_value then
|
||||
local color = {r=.1, g=.6, b=.6}
|
||||
if aux_tooltip_disenchant_value then
|
||||
local color = { r=.1, g=.6, b=.6 }
|
||||
|
||||
local disenchant_value = disenchant.value(item_info.slot, item_info.quality, item_info.level)
|
||||
tooltip:AddLine('Disenchant Value: ' .. (disenchant_value and money.to_string2(disenchant_value) or GRAY_FONT_COLOR_CODE .. '---' .. FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||
end
|
||||
end
|
||||
end
|
||||
if _G.aux_tooltip_vendor_buy then
|
||||
local color = {r=.8, g=.5, b=.1}
|
||||
if aux_tooltip_vendor_buy then
|
||||
local color = { r=.8, g=.5, b=.1 }
|
||||
local _, price, limited = cache.merchant_info(item_id)
|
||||
if price then
|
||||
tooltip:AddLine('Vendor Buy ' .. (limited and '(limited): ' or ': ') .. money.to_string2(price * quantity), color.r, color.g, color.b)
|
||||
end
|
||||
end
|
||||
if _G.aux_tooltip_vendor_sell then
|
||||
local color = {r=.8, g=.5, b=.1}
|
||||
if aux_tooltip_vendor_sell then
|
||||
local color = { r=.8, g=.5, b=.1 }
|
||||
local price = cache.merchant_info(item_id)
|
||||
if price ~= 0 then
|
||||
tooltip:AddLine('Vendor Sell: ' .. (price and money.to_string2(price * quantity) or GRAY_FONT_COLOR_CODE .. '---' .. FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||
end
|
||||
end
|
||||
local color = {r=1, g=1, b=.6}
|
||||
local color = { r=1, g=1, b=.6 }
|
||||
local auctionable = not item_info or info.auctionable(info.tooltip(function(tooltip) tooltip:SetHyperlink(item_info.itemstring) end), item_info.quality)
|
||||
local item_key = (item_id or 0) .. ':' .. (suffix_id or 0)
|
||||
local value = history.value(item_key)
|
||||
if auctionable then
|
||||
if _G.aux_tooltip_value then
|
||||
if aux_tooltip_value then
|
||||
tooltip:AddLine('Value: ' .. (value and money.to_string2(value * quantity) or GRAY_FONT_COLOR_CODE .. '---' .. FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||
end
|
||||
if _G.aux_tooltip_daily then
|
||||
if aux_tooltip_daily then
|
||||
local market_value = history.market_value(item_key)
|
||||
tooltip:AddLine('Today: ' .. (market_value and money.to_string2(market_value * quantity) .. ' (' .. aux.auction_listing.percentage_historical(round(market_value / value * 100)) .. ')' or GRAY_FONT_COLOR_CODE .. '---' .. FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user