big refactoring
This commit is contained in:
+13
-13
@@ -1,10 +1,10 @@
|
||||
aux.module 'cache'
|
||||
|
||||
private.MIN_ITEM_ID = 1
|
||||
private.MAX_ITEM_ID = 30000
|
||||
MIN_ITEM_ID = 1
|
||||
MAX_ITEM_ID = 30000
|
||||
|
||||
private.items_schema = {'record', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}}
|
||||
private.merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'} }
|
||||
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'} }
|
||||
|
||||
_G.aux_items = {}
|
||||
_G.aux_item_ids = {}
|
||||
@@ -35,29 +35,29 @@ end
|
||||
do
|
||||
local sell_scan_countdown, incomplete_buy_data
|
||||
|
||||
function private.on_merchant_show()
|
||||
function on_merchant_show()
|
||||
m.merchant_sell_scan()
|
||||
incomplete_buy_data = not m.merchant_buy_scan()
|
||||
end
|
||||
|
||||
function private.on_merchant_closed()
|
||||
function on_merchant_closed()
|
||||
sell_scan_countdown = nil
|
||||
incomplete_buy_data = false
|
||||
end
|
||||
|
||||
function private.on_merchant_update()
|
||||
function on_merchant_update()
|
||||
if incomplete_buy_data then
|
||||
incomplete_buy_data = not m.merchant_buy_scan()
|
||||
end
|
||||
end
|
||||
|
||||
function private.on_bag_update()
|
||||
function on_bag_update()
|
||||
if MerchantFrame:IsVisible() then
|
||||
sell_scan_countdown = 10
|
||||
end
|
||||
end
|
||||
|
||||
function private.merchant_on_update()
|
||||
function merchant_on_update()
|
||||
if sell_scan_countdown == 0 then
|
||||
sell_scan_countdown = nil
|
||||
m.merchant_sell_scan()
|
||||
@@ -67,7 +67,7 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function private.merchant_loaded()
|
||||
function merchant_loaded()
|
||||
for i=1,GetMerchantNumItems() do
|
||||
if not GetMerchantItemLink(i) then
|
||||
return false
|
||||
@@ -107,7 +107,7 @@ function public.item_id(item_name)
|
||||
return _G.aux_item_ids[strlower(item_name)]
|
||||
end
|
||||
|
||||
function private.merchant_buy_scan()
|
||||
function merchant_buy_scan()
|
||||
|
||||
local incomplete_data
|
||||
for i=1,GetMerchantNumItems() do
|
||||
@@ -146,7 +146,7 @@ function private.merchant_buy_scan()
|
||||
return not incomplete_data
|
||||
end
|
||||
|
||||
function private.merchant_sell_scan()
|
||||
function merchant_sell_scan()
|
||||
for slot in aux.util.inventory() do
|
||||
local item_info = aux.info.container_item(unpack(slot))
|
||||
if item_info then
|
||||
@@ -155,7 +155,7 @@ function private.merchant_sell_scan()
|
||||
end
|
||||
end
|
||||
|
||||
function private.scan_wdb(item_id)
|
||||
function scan_wdb(item_id)
|
||||
item_id = item_id or m.MIN_ITEM_ID
|
||||
|
||||
local processed = 0
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
aux.module 'disenchant'
|
||||
|
||||
private.UNCOMMON = 2
|
||||
private.RARE = 3
|
||||
private.EPIC = 4
|
||||
UNCOMMON = 2
|
||||
RARE = 3
|
||||
EPIC = 4
|
||||
|
||||
do
|
||||
local data = {
|
||||
@@ -41,7 +41,7 @@ do
|
||||
end
|
||||
|
||||
function m.LOAD()
|
||||
private.armor = aux.util.set(
|
||||
armor = aux.util.set(
|
||||
'INVTYPE_HEAD',
|
||||
'INVTYPE_NECK',
|
||||
'INVTYPE_SHOULDER',
|
||||
@@ -59,7 +59,7 @@ function m.LOAD()
|
||||
'INVTYPE_HOLDABLE'
|
||||
)
|
||||
|
||||
private.weapon = aux.util.set(
|
||||
weapon = aux.util.set(
|
||||
'INVTYPE_2HWEAPON' ,
|
||||
'INVTYPE_WEAPONMAINHAND',
|
||||
'INVTYPE_WEAPON',
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
aux.module 'history'
|
||||
|
||||
local history_schema = {'record', '#', {next_push='number'}, {daily_min_buyout='number'}, {daily_max_price='number'}, {data_points={'list', ';', {'record', '@', {market_value='number'}, {time='number'}}}}}
|
||||
private.value_cache = {}
|
||||
value_cache = {}
|
||||
|
||||
function private.next_push()
|
||||
function next_push()
|
||||
local date = date('*t')
|
||||
date.hour, date.min, date.sec = 24, 0, 0
|
||||
return time(date)
|
||||
end
|
||||
|
||||
function private.new_record()
|
||||
function new_record()
|
||||
return { next_push = m.next_push(), data_points = {} }
|
||||
end
|
||||
|
||||
function private.load_data()
|
||||
function load_data()
|
||||
local dataset = aux.persistence.load_dataset()
|
||||
dataset.history = dataset.history or {}
|
||||
return dataset.history
|
||||
end
|
||||
|
||||
function private.read_record(item_key)
|
||||
function read_record(item_key)
|
||||
local data = m.load_data()
|
||||
|
||||
local record
|
||||
@@ -37,7 +37,7 @@ function private.read_record(item_key)
|
||||
return record
|
||||
end
|
||||
|
||||
function private.write_record(item_key, record)
|
||||
function write_record(item_key, record)
|
||||
m.value_cache[item_key] = nil
|
||||
local data = m.load_data()
|
||||
data[item_key] = aux.persistence.write(history_schema, record)
|
||||
@@ -96,11 +96,11 @@ function public.market_value(item_key)
|
||||
return m.calculate_market_value(item_record)
|
||||
end
|
||||
|
||||
function private.calculate_market_value(item_record)
|
||||
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 private.weighted_median(list)
|
||||
function weighted_median(list)
|
||||
local sorted_list = {}
|
||||
for _, e in list do
|
||||
tinsert(sorted_list, e)
|
||||
@@ -116,7 +116,7 @@ function private.weighted_median(list)
|
||||
end
|
||||
end
|
||||
|
||||
function private.push_record(item_record)
|
||||
function push_record(item_record)
|
||||
|
||||
local market_value = m.calculate_market_value(item_record)
|
||||
if market_value then
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
aux.module 'post'
|
||||
|
||||
private.state = nil
|
||||
state = nil
|
||||
|
||||
function private.process()
|
||||
function process()
|
||||
if m.state.posted < m.state.count then
|
||||
|
||||
local stacking_complete
|
||||
@@ -23,7 +23,7 @@ function private.process()
|
||||
return m.stop()
|
||||
end
|
||||
|
||||
function private.post_auction(slot, k)
|
||||
function post_auction(slot, k)
|
||||
local item_info = aux.info.container_item(unpack(slot))
|
||||
if item_info.item_key == m.state.item_key and aux.info.auctionable(item_info.tooltip) and item_info.aux_quantity == m.state.stack_size then
|
||||
|
||||
|
||||
+15
-15
@@ -1,6 +1,6 @@
|
||||
aux.module 'scan'
|
||||
|
||||
private.PAGE_SIZE = 50
|
||||
PAGE_SIZE = 50
|
||||
|
||||
do
|
||||
local scan_states = {}
|
||||
@@ -31,23 +31,23 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function private.complete()
|
||||
function complete()
|
||||
local on_complete = m.state.params.on_complete
|
||||
scan_states[m.state.params.type] = nil
|
||||
aux.call(on_complete)
|
||||
end
|
||||
|
||||
private.state = aux.dynamic_table(scan_states, function(self)
|
||||
state = aux.dynamic_table(scan_states, function(self)
|
||||
local _, state = next(aux.util.filter(self.private, function(state) return state.id == aux.control.thread_id end))
|
||||
return state
|
||||
end)
|
||||
end
|
||||
|
||||
private.query = aux.dynamic_table(nil, function()
|
||||
query = aux.dynamic_table(nil, function()
|
||||
return m.state.params.queries[m.state.query_index]
|
||||
end)
|
||||
|
||||
function private.wait_for_callback(...)
|
||||
function wait_for_callback(...)
|
||||
local send_signal, signal_received = aux.util.signal()
|
||||
local suspended
|
||||
local ret
|
||||
@@ -69,17 +69,17 @@ function private.wait_for_callback(...)
|
||||
return aux.control.when(signal_received, function() return k(unpack(signal_received())) end)
|
||||
end
|
||||
|
||||
function private.total_pages(total_auctions)
|
||||
function total_pages(total_auctions)
|
||||
return ceil(total_auctions / m.PAGE_SIZE)
|
||||
end
|
||||
|
||||
function private.last_page(total_auctions)
|
||||
function last_page(total_auctions)
|
||||
local last_page = max(m.total_pages(total_auctions) - 1, 0)
|
||||
local last_page_limit = m.query.blizzard_query and m.query.blizzard_query.last_page or last_page
|
||||
return min(last_page_limit, last_page)
|
||||
end
|
||||
|
||||
function private.scan()
|
||||
function scan()
|
||||
m.state.query_index = m.state.query_index and m.state.query_index + 1 or 1
|
||||
if m.query() and (aux.index(m.query.blizzard_query, 'first_page') or 0) <= (aux.index(m.query.blizzard_query, 'last_page') or aux.huge) then
|
||||
if m.query.blizzard_query then
|
||||
@@ -93,7 +93,7 @@ function private.scan()
|
||||
end
|
||||
end
|
||||
|
||||
function private.process_query()
|
||||
function process_query()
|
||||
if m.query.blizzard_query then
|
||||
return m.submit_query()
|
||||
else
|
||||
@@ -101,7 +101,7 @@ function private.process_query()
|
||||
end
|
||||
end
|
||||
|
||||
function private.submit_query()
|
||||
function submit_query()
|
||||
aux.control.when(function() return m.state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||
aux.call(m.state.params.on_submit_query)
|
||||
m.state.last_query_time = GetTime()
|
||||
@@ -127,7 +127,7 @@ function private.submit_query()
|
||||
end)
|
||||
end
|
||||
|
||||
function private.scan_page(i)
|
||||
function scan_page(i)
|
||||
i = i or 1
|
||||
local recurse = function(retry)
|
||||
if i >= m.PAGE_SIZE then
|
||||
@@ -172,7 +172,7 @@ function private.scan_page(i)
|
||||
return recurse()
|
||||
end
|
||||
|
||||
function private.wait_for_results()
|
||||
function wait_for_results()
|
||||
local timeout = aux.util.later(m.state.last_query_time, 10)
|
||||
local send_signal, signal_received = aux.util.signal()
|
||||
aux.control.when(signal_received, function()
|
||||
@@ -201,7 +201,7 @@ function private.wait_for_results()
|
||||
end
|
||||
end
|
||||
|
||||
function private.wait_for_owner_results(send_signal)
|
||||
function wait_for_owner_results(send_signal)
|
||||
if m.state.page == aux.current_owner_page then
|
||||
return send_signal()
|
||||
else
|
||||
@@ -209,7 +209,7 @@ function private.wait_for_owner_results(send_signal)
|
||||
end
|
||||
end
|
||||
|
||||
function private.wait_for_list_results(send_signal, signal_received)
|
||||
function wait_for_list_results(send_signal, signal_received)
|
||||
local updated, last_update
|
||||
aux.control.event_listener('AUCTION_ITEM_LIST_UPDATE', function(kill)
|
||||
kill(signal_received())
|
||||
@@ -225,7 +225,7 @@ function private.wait_for_list_results(send_signal, signal_received)
|
||||
end, send_signal)
|
||||
end
|
||||
|
||||
function private.owner_data_complete(type)
|
||||
function owner_data_complete(type)
|
||||
for i=1,m.PAGE_SIZE do
|
||||
local auction_info = aux.info.auction(i, type)
|
||||
if auction_info and not auction_info.owner then
|
||||
|
||||
+11
-11
@@ -1,28 +1,28 @@
|
||||
aux.module 'stack'
|
||||
|
||||
private.state = nil
|
||||
state = nil
|
||||
|
||||
function private.stack_size(slot)
|
||||
function stack_size(slot)
|
||||
local container_item_info = aux.info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.count or 0
|
||||
end
|
||||
|
||||
function private.charges(slot)
|
||||
function charges(slot)
|
||||
local container_item_info = aux.info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.charges
|
||||
end
|
||||
|
||||
function private.max_stack(slot)
|
||||
function max_stack(slot)
|
||||
local container_item_info = aux.info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.max_stack
|
||||
end
|
||||
|
||||
function private.locked(slot)
|
||||
function locked(slot)
|
||||
local container_item_info = aux.info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.locked
|
||||
end
|
||||
|
||||
function private.find_item_slot(partial)
|
||||
function find_item_slot(partial)
|
||||
for slot in aux.util.inventory() do
|
||||
if m.matching_item(slot, partial) and not aux.util.eq(slot, m.state.target_slot) then
|
||||
return slot
|
||||
@@ -30,12 +30,12 @@ function private.find_item_slot(partial)
|
||||
end
|
||||
end
|
||||
|
||||
function private.matching_item(slot, partial)
|
||||
function matching_item(slot, partial)
|
||||
local item_info = aux.info.container_item(unpack(slot))
|
||||
return item_info and item_info.item_key == m.state.item_key and aux.info.auctionable(item_info.tooltip) and (not partial or item_info.count < item_info.max_stack)
|
||||
end
|
||||
|
||||
function private.find_empty_slot()
|
||||
function find_empty_slot()
|
||||
for slot, type in aux.util.inventory() do
|
||||
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
|
||||
return slot
|
||||
@@ -43,7 +43,7 @@ function private.find_empty_slot()
|
||||
end
|
||||
end
|
||||
|
||||
function private.find_charge_item_slot()
|
||||
function find_charge_item_slot()
|
||||
for slot in aux.util.inventory() do
|
||||
if m.matching_item(slot) and m.charges(slot) == m.state.target_size then
|
||||
return slot
|
||||
@@ -51,7 +51,7 @@ function private.find_charge_item_slot()
|
||||
end
|
||||
end
|
||||
|
||||
function private.move_item(from_slot, to_slot, amount, k)
|
||||
function move_item(from_slot, to_slot, amount, k)
|
||||
if m.locked(from_slot) or m.locked(to_slot) then
|
||||
return aux.control.wait(k)
|
||||
end
|
||||
@@ -66,7 +66,7 @@ function private.move_item(from_slot, to_slot, amount, k)
|
||||
return aux.control.when(function() return m.stack_size(to_slot) == expected_size end, k)
|
||||
end
|
||||
|
||||
function private.process()
|
||||
function process()
|
||||
|
||||
if not m.state.target_slot or not m.matching_item(m.state.target_slot) then
|
||||
m.state.target_slot = m.find_item_slot()
|
||||
|
||||
@@ -2,9 +2,9 @@ aux.module 'tooltip'
|
||||
|
||||
_G.aux_tooltip_value = true
|
||||
|
||||
private.game_tooltip_hooks = {}
|
||||
private.hooked_setter = nil
|
||||
private.game_tooltip_money = nil
|
||||
game_tooltip_hooks = {}
|
||||
hooked_setter = nil
|
||||
game_tooltip_money = nil
|
||||
|
||||
function m.LOAD()
|
||||
for func, hook in m.game_tooltip_hooks do
|
||||
@@ -43,7 +43,7 @@ function m.LOAD()
|
||||
end)
|
||||
end
|
||||
|
||||
function private.extend_tooltip(tooltip, link, quantity)
|
||||
function extend_tooltip(tooltip, link, quantity)
|
||||
local item_id, suffix_id = aux.info.parse_link(link)
|
||||
quantity = IsShiftKeyDown() and quantity or 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user