module refactoring

This commit is contained in:
Simon Hirsig
2017-11-01 15:01:41 +01:00
parent 9989ceb42f
commit 8823b34904
36 changed files with 669 additions and 646 deletions
+18 -18
View File
@@ -1,9 +1,9 @@
module 'aux.core.cache'
module 'aux.util.info'
include 'T'
include 'aux'
local info = require 'aux.util.info'
local T = require 'T'
local persistence = require 'aux.util.persistence'
local MIN_ITEM_ID = 1
@@ -18,7 +18,7 @@ _G.aux_auctionable_items = {}
_G.aux_merchant_buy = {}
_G.aux_merchant_sell = {}
function LOAD()
function handle.LOAD()
scan_wdb()
event_listener('MERCHANT_SHOW', on_merchant_show)
@@ -29,22 +29,22 @@ function LOAD()
CreateFrame('Frame', nil, MerchantFrame):SetScript('OnUpdate', merchant_on_update)
event_listener('NEW_AUCTION_UPDATE', function()
local data = info.auction_sell_item()
local data = auction_sell_item()
if data then
local item_id = item_id(data.name)
if item_id then
aux_merchant_sell[item_id] = data.vendor_price / (info.max_item_charges(item_id) or data.count)
aux_merchant_sell[item_id] = data.vendor_price / (max_item_charges(item_id) or data.count)
end
end
end)
end
do
local characters = empty
local characters = T.empty
function M.is_player(name)
return characters[name] and true or false
end
function LOAD2()
function handle.LOAD2()
characters = realm_data'characters'
for k, v in pairs(characters) do
if GetTime() > v + 60 * 60 * 24 * 30 then
@@ -104,7 +104,7 @@ function M.item_info(item_id)
local data_string = aux_items[item_id]
if data_string then
local cached_data = persistence.read(items_schema, data_string)
return O(
return T.map(
'name', cached_data.name,
'itemstring', 'item:' .. item_id .. ':0:0:0',
'quality', cached_data.quality,
@@ -128,7 +128,7 @@ function merchant_buy_scan()
local _, _, price, count, stock = GetMerchantItemInfo(i)
local link = GetMerchantItemLink(i)
if link then
local item_id = info.parse_link(link)
local item_id = parse_link(link)
local new_unit_price, new_limited = price / count, stock >= 0
if aux_merchant_buy[item_id] then
local buy_info = persistence.read(merchant_buy_schema, aux_merchant_buy[item_id])
@@ -142,12 +142,12 @@ function merchant_buy_scan()
unit_price = min(buy_info.unit_price, new_unit_price)
end
aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, temp-O(
aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T.temp-T.map(
'unit_price', unit_price,
'limited', buy_info.limited and new_limited
))
else
aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, temp-O(
aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T.temp-T.map(
'unit_price', new_unit_price,
'limited', new_limited
))
@@ -161,9 +161,9 @@ function merchant_buy_scan()
end
function merchant_sell_scan()
for slot in info.inventory do
temp(slot)
local item_info = temp-info.container_item(unpack(slot))
for slot in inventory() do
T.temp(slot)
local item_info = T.temp-container_item(unpack(slot))
if item_info then
aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity
end
@@ -179,7 +179,7 @@ function scan_wdb(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] = persistence.write(items_schema, temp-O(
aux_items[item_id] = persistence.write(items_schema, T.temp-T.map(
'name', name,
'quality', quality,
'level', level,
@@ -189,8 +189,8 @@ function scan_wdb(item_id)
'max_stack', max_stack,
'texture', texture
))
local tooltip = info.tooltip('link', itemstring)
if info.auctionable(tooltip, quality) then
local tooltip = tooltip('link', itemstring)
if auctionable(tooltip, quality) then
tinsert(aux_auctionable_items, strlower(name))
end
processed = processed + 1
+63 -62
View File
@@ -1,13 +1,14 @@
module 'aux.core.disenchant'
include 'T'
include 'aux'
local T = require 'T'
local history = require 'aux.core.history'
local UNCOMMON, RARE, EPIC = 2, 3, 4
local ARMOR = S(
local ARMOR = T.set(
'INVTYPE_HEAD',
'INVTYPE_NECK',
'INVTYPE_SHOULDER',
@@ -25,7 +26,7 @@ local ARMOR = S(
'INVTYPE_HOLDABLE'
)
local WEAPON = S(
local WEAPON = T.set(
'INVTYPE_2HWEAPON',
'INVTYPE_WEAPONMAINHAND',
'INVTYPE_WEAPON',
@@ -50,7 +51,7 @@ end
function M.distribution(slot, quality, level)
if not ARMOR[slot] and not WEAPON[slot] or level == 0 then
return T
return T.acquire()
end
local function p(probability_armor, probability_weapon)
@@ -63,103 +64,103 @@ function M.distribution(slot, quality, level)
if quality == UNCOMMON then
if level <= 10 then
return temp-A(
temp-O('item_id', 10940, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.8, .2)),
temp-O('item_id', 10938, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .8))
return T.temp-T.list(
T.temp-T.map('item_id', 10940, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.8, .2)),
T.temp-T.map('item_id', 10938, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .8))
)
elseif level <= 15 then
return temp-A(
temp-O('item_id', 10940, 'min_quantity', 2, 'max_quantity', 3, 'probability', p(.75, .2)),
temp-O('item_id', 10939, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
temp-O('item_id', 10978, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
return T.temp-T.list(
T.temp-T.map('item_id', 10940, 'min_quantity', 2, 'max_quantity', 3, 'probability', p(.75, .2)),
T.temp-T.map('item_id', 10939, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T.temp-T.map('item_id', 10978, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 20 then
return temp-A(
temp-O('item_id', 10940, 'min_quantity', 4, 'max_quantity', 6, 'probability', p(.75, .15)),
temp-O('item_id', 10998, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.15, .75)),
temp-O('item_id', 10978, 'min_quantity', 1, 'max_quantity', 1, 'probability', .10)
return T.temp-T.list(
T.temp-T.map('item_id', 10940, 'min_quantity', 4, 'max_quantity', 6, 'probability', p(.75, .15)),
T.temp-T.map('item_id', 10998, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.15, .75)),
T.temp-T.map('item_id', 10978, 'min_quantity', 1, 'max_quantity', 1, 'probability', .10)
)
elseif level <= 25 then
return temp-A(
temp-O('item_id', 11083, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .2)),
temp-O('item_id', 11082, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
temp-O('item_id', 11084, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
return T.temp-T.list(
T.temp-T.map('item_id', 11083, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .2)),
T.temp-T.map('item_id', 11082, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T.temp-T.map('item_id', 11084, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 30 then
return temp-A(
temp-O('item_id', 11083, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .2)),
temp-O('item_id', 11134, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
temp-O('item_id', 11138, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
return T.temp-T.list(
T.temp-T.map('item_id', 11083, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .2)),
T.temp-T.map('item_id', 11134, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T.temp-T.map('item_id', 11138, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 35 then
return temp-A(
temp-O('item_id', 11137, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .2)),
temp-O('item_id', 11135, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
temp-O('item_id', 11139, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
return T.temp-T.list(
T.temp-T.map('item_id', 11137, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .2)),
T.temp-T.map('item_id', 11135, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T.temp-T.map('item_id', 11139, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 40 then
return temp-A(
temp-O('item_id', 11137, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .2)),
temp-O('item_id', 11174, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
temp-O('item_id', 11177, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
return T.temp-T.list(
T.temp-T.map('item_id', 11137, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .2)),
T.temp-T.map('item_id', 11174, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T.temp-T.map('item_id', 11177, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 45 then
return temp-A(
temp-O('item_id', 11176, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .2)),
temp-O('item_id', 11175, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
temp-O('item_id', 11178, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
return T.temp-T.list(
T.temp-T.map('item_id', 11176, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .2)),
T.temp-T.map('item_id', 11175, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T.temp-T.map('item_id', 11178, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 50 then
return temp-A(
temp-O('item_id', 11176, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .22)),
temp-O('item_id', 16202, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
temp-O('item_id', 14343, 'min_quantity', 1, 'max_quantity', 1, 'probability', p(.05, .03))
return T.temp-T.list(
T.temp-T.map('item_id', 11176, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .22)),
T.temp-T.map('item_id', 16202, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T.temp-T.map('item_id', 14343, 'min_quantity', 1, 'max_quantity', 1, 'probability', p(.05, .03))
)
elseif level <= 55 then
return temp-A(
temp-O('item_id', 16204, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .22)),
temp-O('item_id', 16203, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
temp-O('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', p(.05, .03))
return T.temp-T.list(
T.temp-T.map('item_id', 16204, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .22)),
T.temp-T.map('item_id', 16203, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T.temp-T.map('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', p(.05, .03))
)
elseif level <= 60 then
return temp-A(
temp-O('item_id', 16204, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .22)),
temp-O('item_id', 16203, 'min_quantity', 2, 'max_quantity', 3, 'probability', p(.2, .75)),
temp-O('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', p(.05, .03))
return T.temp-T.list(
T.temp-T.map('item_id', 16204, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .22)),
T.temp-T.map('item_id', 16203, 'min_quantity', 2, 'max_quantity', 3, 'probability', p(.2, .75)),
T.temp-T.map('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', p(.05, .03))
)
end
elseif quality == RARE then
if level <= 20 then
return temp-A(temp-O('item_id', 10978, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 10978, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
elseif level <= 25 then
return temp-A(temp-O('item_id', 11084, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 11084, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
elseif level <= 30 then
return temp-A(temp-O('item_id', 11138, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 11138, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
elseif level <= 35 then
return temp-A(temp-O('item_id', 11139, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 11139, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
elseif level <= 40 then
return temp-A(temp-O('item_id', 11177, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 11177, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
elseif level <= 45 then
return temp-A(temp-O('item_id', 11178, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 11178, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
elseif level <= 50 then
return temp-A(temp-O('item_id', 14343, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 14343, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
elseif level <= 55 then
return temp-A(temp-O('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', .995), temp-O('item_id', 20725, 'min_quantity', 1, 'max_quantity', 1, 'probability', .005))
return T.temp-T.list(T.temp-T.map('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', .995), T.temp-T.map('item_id', 20725, 'min_quantity', 1, 'max_quantity', 1, 'probability', .005))
elseif level <= 60 then
return temp-A(temp-O('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', .995), temp-O('item_id', 20725, 'min_quantity', 1, 'max_quantity', 1, 'probability', .005))
return T.temp-T.list(T.temp-T.map('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', .995), T.temp-T.map('item_id', 20725, 'min_quantity', 1, 'max_quantity', 1, 'probability', .005))
end
elseif quality == EPIC then
if level <= 40 then
return temp-A(temp-O('item_id', 11177, 'min_quantity', 2, 'max_quantity', 4, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 11177, 'min_quantity', 2, 'max_quantity', 4, 'probability', 1))
elseif level <= 45 then
return temp-A(temp-O('item_id', 11178, 'min_quantity', 2, 'max_quantity', 4, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 11178, 'min_quantity', 2, 'max_quantity', 4, 'probability', 1))
elseif level <= 50 then
return temp-A(temp-O('item_id', 14343, 'min_quantity', 2, 'max_quantity', 4, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 14343, 'min_quantity', 2, 'max_quantity', 4, 'probability', 1))
elseif level <= 55 then
return temp-A(temp-O('item_id', 20725, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 20725, 'min_quantity', 1, 'max_quantity', 1, 'probability', 1))
elseif level <= 60 then
return temp-A(temp-O('item_id', 20725, 'min_quantity', 1, 'max_quantity', 2, 'probability', 1))
return T.temp-T.list(T.temp-T.map('item_id', 20725, 'min_quantity', 1, 'max_quantity', 2, 'probability', 1))
end
end
return T
return T.acquire()
end
+14 -13
View File
@@ -1,21 +1,22 @@
module 'aux.core.history'
include 'T'
include 'aux'
local T = require 'T'
local persistence = require 'aux.util.persistence'
local history_schema = {'tuple', '#', {next_push='number'}, {daily_min_buyout='number'}, {data_points={'list', ';', {'tuple', '@', {value='number'}, {time='number'}}}}}
local value_cache = {}
function LOAD2()
function handle.LOAD2()
data = faction_data'history'
end
do
local next_push = 0
function get.next_push()
function get_next_push()
if time() > next_push then
local date = date('*t')
date.hour, date.min, date.sec = 24, 0, 0
@@ -25,12 +26,12 @@ do
end
end
function get.new_record()
return temp-O('next_push', next_push, 'data_points', T)
function new_record()
return T.temp-T.map('next_push', get_next_push(), 'data_points', T.acquire())
end
function read_record(item_key)
local record = data[item_key] and persistence.read(history_schema, data[item_key]) or new_record
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)
write_record(item_key, record)
@@ -41,7 +42,7 @@ end
function write_record(item_key, record)
data[item_key] = persistence.write(history_schema, record)
if value_cache[item_key] then
release(value_cache[item_key])
T.release(value_cache[item_key])
value_cache[item_key] = nil
end
end
@@ -64,11 +65,11 @@ function M.value(item_key)
local item_record, value
item_record = read_record(item_key)
if getn(item_record.data_points) > 0 then
local total_weight, weighted_values = 0, temp-T
local total_weight, weighted_values = 0, T.temp-T.acquire()
for _, data_point in pairs(item_record.data_points) do
local weight = .99 ^ round((item_record.data_points[1].time - data_point.time) / (60 * 60 * 24))
total_weight = total_weight + weight
tinsert(weighted_values, O('value', data_point.value, 'weight', weight))
tinsert(weighted_values, T.map('value', data_point.value, 'weight', weight))
end
for _, weighted_value in pairs(weighted_values) do
weighted_value.weight = weighted_value.weight / total_weight
@@ -77,7 +78,7 @@ function M.value(item_key)
else
value = item_record.daily_min_buyout
end
value_cache[item_key] = O('value', value, 'next_push', item_record.next_push)
value_cache[item_key] = T.map('value', value, 'next_push', item_record.next_push)
end
return value_cache[item_key].value
end
@@ -99,11 +100,11 @@ end
function push_record(item_record)
if item_record.daily_min_buyout then
tinsert(item_record.data_points, 1, O('value', item_record.daily_min_buyout, 'time', item_record.next_push))
tinsert(item_record.data_points, 1, T.map('value', item_record.daily_min_buyout, 'time', item_record.next_push))
while getn(item_record.data_points) > 11 do
release(item_record.data_points[getn(item_record.data_points)])
T.release(item_record.data_points[getn(item_record.data_points)])
tremove(item_record.data_points)
end
end
item_record.next_push, item_record.daily_min_buyout = next_push, nil
item_record.next_push, item_record.daily_min_buyout = get_next_push(), nil
end
-1
View File
@@ -1,6 +1,5 @@
module 'aux.core.post'
include 'T'
include 'aux'
local info = require 'aux.util.info'
+50 -49
View File
@@ -1,8 +1,9 @@
module 'aux.core.scan'
include 'T'
include 'aux'
local T = require 'T'
local info = require 'aux.util.info'
local history = require 'aux.core.history'
@@ -26,7 +27,7 @@ do
end
function M.abort(scan_id)
local aborted = T
local aborted = T.acquire()
for type, state in pairs(scan_states) do
if not scan_id or state.id == scan_id then
kill_thread(state.id)
@@ -40,26 +41,26 @@ do
end
function M.stop()
state.stopped = true
get_state().stopped = true
end
function complete()
local on_complete = state.params.on_complete
scan_states[state.params.type] = nil
local on_complete = get_state().params.on_complete
scan_states[get_state().params.type] = nil
do (on_complete or nop)() end
end
function get.state()
function get_state()
for _, state in pairs(scan_states) do
if state.id == thread_id then
if state.id == thread_id() then
return state
end
end
end
end
function get.query()
return state.params.queries[state.query_index]
function get_query()
return get_state().params.queries[get_state().query_index]
end
function total_pages(total_auctions)
@@ -68,21 +69,21 @@ end
function last_page(total_auctions)
local last_page = max(total_pages(total_auctions) - 1, 0)
local last_page_limit = query.blizzard_query.last_page or last_page
local last_page_limit = get_query().blizzard_query.last_page or last_page
return min(last_page_limit, last_page)
end
function scan()
state.query_index = state.query_index and state.query_index + 1 or 1
if query and not state.stopped then
do (state.params.on_start_query or nop)(state.query_index) end
if query.blizzard_query then
if (query.blizzard_query.first_page or 0) <= (query.blizzard_query.last_page or huge) then
state.page = query.blizzard_query.first_page or 0
get_state().query_index = get_state().query_index and get_state().query_index + 1 or 1
if get_query() and not get_state().stopped then
do (get_state().params.on_start_query or nop)(get_state().query_index) end
if get_query().blizzard_query then
if (get_query().blizzard_query.first_page or 0) <= (get_query().blizzard_query.last_page or huge) then
get_state().page = get_query().blizzard_query.first_page or 0
return submit_query()
end
else
state.page = nil
get_state().page = nil
return scan_page()
end
end
@@ -91,13 +92,13 @@ end
do
local function submit()
if state.params.type == 'bidder' then
GetBidderAuctionItems(state.page)
elseif state.params.type == 'owner' then
GetOwnerAuctionItems(state.page)
if get_state().params.type == 'bidder' then
GetBidderAuctionItems(get_state().page)
elseif get_state().params.type == 'owner' then
GetOwnerAuctionItems(get_state().page)
else
state.last_list_query = GetTime()
local blizzard_query = query.blizzard_query or T
get_state().last_list_query = GetTime()
local blizzard_query = get_query().blizzard_query or T.acquire()
QueryAuctionItems(
blizzard_query.name,
blizzard_query.min_level,
@@ -105,7 +106,7 @@ do
blizzard_query.slot,
blizzard_query.class,
blizzard_query.subclass,
state.page,
get_state().page,
blizzard_query.usable,
blizzard_query.quality
)
@@ -113,8 +114,8 @@ do
return wait_for_results()
end
function submit_query()
if state.stopped then return end
if state.params.type ~= 'list' then
if get_state().stopped then return end
if get_state().params.type ~= 'list' then
return submit()
else
return when(CanSendAuctionQuery, submit)
@@ -126,30 +127,30 @@ function scan_page(i)
i = i or 1
if i > PAGE_SIZE then
do (state.params.on_page_scanned or nop)() end
if query.blizzard_query and state.page < last_page(state.total_auctions) then
state.page = state.page + 1
do (get_state().params.on_page_scanned or nop)() end
if get_query().blizzard_query and get_state().page < last_page(get_state().total_auctions) then
get_state().page = get_state().page + 1
return submit_query()
else
return scan()
end
end
local auction_info = info.auction(i, state.params.type)
if auction_info and (auction_info.owner or state.params.ignore_owner or aux_ignore_owner) then
local auction_info = info.auction(i, get_state().params.type)
if auction_info and (auction_info.owner or get_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
auction_info.query_type = state.params.type
auction_info.page = get_state().page
auction_info.blizzard_query = get_query().blizzard_query
auction_info.query_type = get_state().params.type
history.process_auction(auction_info)
if (state.params.auto_buy_validator or nop)(auction_info) then
if (get_state().params.auto_buy_validator or nop)(auction_info) then
local send_signal, signal_received = signal()
when(signal_received, scan_page, i)
return place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, send_signal)
elseif not query.validator or query.validator(auction_info) then
do (state.params.on_auction or nop)(auction_info) end
elseif not get_query().validator or get_query().validator(auction_info) then
do (get_state().params.on_auction or nop)(auction_info) end
end
end
@@ -157,29 +158,29 @@ function scan_page(i)
end
function wait_for_results()
if state.params.type == 'bidder' then
return when(function() return bids_loaded end, accept_results)
elseif state.params.type == 'owner' then
if get_state().params.type == 'bidder' then
return when(function() return bids_loaded() end, accept_results)
elseif get_state().params.type == 'owner' then
return wait_for_owner_results()
elseif state.params.type == 'list' then
elseif get_state().params.type == 'list' then
return wait_for_list_results()
end
end
function accept_results()
_, state.total_auctions = GetNumAuctionItems(state.params.type)
_, get_state().total_auctions = GetNumAuctionItems(get_state().params.type)
do
(state.params.on_page_loaded or nop)(
state.page - (query.blizzard_query.first_page or 0) + 1,
last_page(state.total_auctions) - (query.blizzard_query.first_page or 0) + 1,
total_pages(state.total_auctions) - 1
(get_state().params.on_page_loaded or nop)(
get_state().page - (get_query().blizzard_query.first_page or 0) + 1,
last_page(get_state().total_auctions) - (get_query().blizzard_query.first_page or 0) + 1,
total_pages(get_state().total_auctions) - 1
)
end
return scan_page()
end
function wait_for_owner_results()
if state.page == current_owner_page then
if get_state().page == current_owner_page() then
return accept_results()
else
local updated
@@ -194,8 +195,8 @@ function wait_for_list_results()
last_update = GetTime()
updated = true
end)
local timeout = later(5, state.last_list_query)
local ignore_owner = state.params.ignore_owner or aux_ignore_owner
local timeout = later(5, get_state().last_list_query)
local ignore_owner = get_state().params.ignore_owner or aux_ignore_owner
return when(function()
if not last_update and timeout() then
return true
+3 -3
View File
@@ -2,9 +2,9 @@ module 'aux.core.slash'
include 'aux'
local cache = require 'aux.core.cache'
local info = require 'aux.util.info'
function LOAD2()
function handle.LOAD2()
tooltip_settings = character_data'tooltip'
end
@@ -53,7 +53,7 @@ function SlashCmdList.AUX(command)
_G.aux_auctionable_items = {}
print('Item cache cleared.')
elseif arguments[1] == 'populate' and arguments[2] == 'wdb' then
cache.populate_wdb()
info.populate_wdb()
else
print('Usage:')
print('- scale [' .. color.blue(aux_scale) .. ']')
+10 -9
View File
@@ -1,34 +1,35 @@
module 'aux.core.stack'
include 'T'
include 'aux'
local T = require 'T'
local info = require 'aux.util.info'
local state
function stack_size(slot)
local container_item_info = temp-info.container_item(unpack(slot))
local container_item_info = T.temp-info.container_item(unpack(slot))
return container_item_info and container_item_info.count or 0
end
function charges(slot)
local container_item_info = temp-info.container_item(unpack(slot))
local container_item_info = T.temp-info.container_item(unpack(slot))
return container_item_info and container_item_info.charges
end
function max_stack(slot)
local container_item_info = temp-info.container_item(unpack(slot))
local container_item_info = T.temp-info.container_item(unpack(slot))
return container_item_info and container_item_info.max_stack
end
function locked(slot)
local container_item_info = temp-info.container_item(unpack(slot))
local container_item_info = T.temp-info.container_item(unpack(slot))
return container_item_info and container_item_info.locked
end
function find_item_slot(partial)
for slot in info.inventory do
for slot in info.inventory() do
if matching_item(slot, partial) and not eq(slot, state.target_slot) then
return slot
end
@@ -36,12 +37,12 @@ function find_item_slot(partial)
end
function matching_item(slot, partial)
local item_info = temp-info.container_item(unpack(slot))
local item_info = T.temp-info.container_item(unpack(slot))
return item_info and item_info.item_key == state.item_key and info.auctionable(item_info.tooltip, nil, true) and (not partial or item_info.count < item_info.max_stack)
end
function find_empty_slot()
for slot, type in info.inventory do
for slot, type in info.inventory() do
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
return slot
end
@@ -49,7 +50,7 @@ function find_empty_slot()
end
function find_charge_item_slot()
for slot in info.inventory do
for slot in info.inventory() do
if matching_item(slot) and charges(slot) == state.target_size then
return slot
end
+17 -17
View File
@@ -1,11 +1,11 @@
module 'aux.core.tooltip'
include 'T'
include 'aux'
local T = require 'T'
local info = require 'aux.util.info'
local money = require 'aux.util.money'
local cache = require 'aux.core.cache'
local disenchant = require 'aux.core.disenchant'
local history = require 'aux.core.history'
local auction_listing = require 'aux.gui.auction_listing'
@@ -14,23 +14,23 @@ local UNKNOWN = GRAY_FONT_COLOR_CODE .. '?' .. FONT_COLOR_CODE_CLOSE
local game_tooltip_hooks, game_tooltip_money = {}, 0
function LOAD()
function handle.LOAD()
settings = character_data('tooltip', {value=true})
do
local inside_hook = false
for name, f in pairs(game_tooltip_hooks) do
local name, f = name, f
hook(name, GameTooltip, vararg-function(arg)
hook(name, GameTooltip, T.vararg-function(arg)
inside_hook = true
game_tooltip_money = 0
local tmp = A(orig[GameTooltip][name](unpack(arg)))
local tmp = T.list(orig[GameTooltip][name](unpack(arg)))
inside_hook = false
f(unpack(arg))
return ret(tmp)
return T.unpack(tmp)
end)
end
local orig = GameTooltip:GetScript'OnTooltipAddMoney'
GameTooltip:SetScript('OnTooltipAddMoney', vararg-function(arg)
GameTooltip:SetScript('OnTooltipAddMoney', T.vararg-function(arg)
if inside_hook then
game_tooltip_money = arg1
else
@@ -39,22 +39,22 @@ function LOAD()
end)
end
local orig = SetItemRef
setglobal('SetItemRef', vararg-function(arg)
setglobal('SetItemRef', T.vararg-function(arg)
local name, _, quality = GetItemInfo(arg[1])
local tmp = A(orig(unpack(arg)))
local tmp = T.list(orig(unpack(arg)))
if not IsShiftKeyDown() and not IsControlKeyDown() and name then
local color_code = select(4, GetItemQualityColor(quality))
local link = color_code .. '|H' .. arg[1] .. '|h[' .. name .. ']|h' .. FONT_COLOR_CODE_CLOSE
extend_tooltip(ItemRefTooltip, link, 1)
end
return ret(tmp)
return T.unpack(tmp)
end)
end
function M.extend_tooltip(tooltip, link, quantity)
local item_id, suffix_id = info.parse_link(link)
quantity = IsShiftKeyDown() and quantity or 1
local item_info = temp-info.item(item_id)
local item_info = T.temp-info.item(item_id)
if item_info then
local distribution = disenchant.distribution(item_info.slot, item_info.quality, item_info.level)
if getn(distribution) > 0 then
@@ -72,18 +72,18 @@ function M.extend_tooltip(tooltip, link, quantity)
end
end
if settings.merchant_buy then
local _, price, limited = cache.merchant_info(item_id)
local _, price, limited = info.merchant_info(item_id)
if price then
tooltip:AddLine('Vendor Buy ' .. (limited and '(limited): ' or ': ') .. money.to_string2(price * quantity), color.tooltip.merchant())
end
end
if settings.merchant_sell then
local price = cache.merchant_info(item_id)
local price = info.merchant_info(item_id)
if price ~= 0 then
tooltip:AddLine('Vendor: ' .. (price and money.to_string2(price * quantity) or UNKNOWN), color.tooltip.merchant())
end
end
local auctionable = not item_info or info.auctionable(temp-info.tooltip('link', item_info.itemstring), item_info.quality)
local auctionable = not item_info or info.auctionable(T.temp-info.tooltip('link', item_info.itemstring), item_info.quality)
local item_key = (item_id or 0) .. ':' .. (suffix_id or 0)
local value = history.value(item_key)
if auctionable then
@@ -148,7 +148,7 @@ end
function game_tooltip_hooks:SetInboxItem(index)
local name, _, quantity = GetInboxItem(index)
local id = name and cache.item_id(name)
local id = name and info.item_id(name)
if id then
local _, itemstring, quality = GetItemInfo(id)
local hex = select(4, GetItemQualityColor(tonumber(quality)))
@@ -206,8 +206,8 @@ end
function game_tooltip_hooks:SetAuctionSellItem()
local name, _, quantity = GetAuctionSellItemInfo()
if name then
for slot in info.inventory do
temp(slot)
for slot in info.inventory() do
T.temp(slot)
local link = GetContainerItemLink(unpack(slot))
if link and select(5, info.parse_link(link)) == name then
extend_tooltip(GameTooltip, link, quantity)