restructuring

This commit is contained in:
Manuel Simon Hirsig
2016-07-12 09:01:34 +02:00
parent d56476ebe1
commit 62ef563afe
33 changed files with 38 additions and 32 deletions
+219
View File
@@ -0,0 +1,219 @@
local private, public = {}, {}
Aux.cache = public
local MIN_ITEM_ID, MAX_ITEM_ID = 1, 30000
aux_items = {}
aux_item_ids = {}
aux_auctionable_items = {}
aux_merchant_buy = {}
aux_merchant_sell = {}
aux_characters = {}
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'}}
function public.on_load()
private.scan_wdb()
Aux.control.event_listener('MERCHANT_SHOW', private.on_merchant_show):start()
Aux.control.event_listener('MERCHANT_CLOSED', private.on_merchant_closed):start()
Aux.control.event_listener('MERCHANT_UPDATE', private.on_merchant_update):start()
Aux.control.event_listener('BAG_UPDATE', private.on_bag_update):start()
CreateFrame('Frame', nil, MerchantFrame):SetScript('OnUpdate', private.merchant_on_update)
Aux.control.event_listener('NEW_AUCTION_UPDATE', function()
local info = Aux.info.auction_sell_item()
if info then
if Aux.cache.item_id(info.name) then
aux_merchant_sell[Aux.cache.item_id(info.name)] = info.vendor_price / info.aux_quantity
end
end
end):start()
end
do
local sell_scan_countdown, incomplete_buy_data
function private.on_merchant_show()
private.merchant_sell_scan()
incomplete_buy_data = not private.merchant_buy_scan()
end
function private.on_merchant_closed()
sell_scan_countdown = nil
incomplete_buy_data = false
end
function private.on_merchant_update()
if incomplete_buy_data then
incomplete_buy_data = not private.merchant_buy_scan()
end
end
function private.on_bag_update()
if MerchantFrame:IsVisible() then
sell_scan_countdown = 10
end
end
function private.merchant_on_update()
if sell_scan_countdown == 0 then
sell_scan_countdown = nil
private.merchant_sell_scan()
elseif sell_scan_countdown then
sell_scan_countdown = sell_scan_countdown - 1
end
end
end
function private.merchant_loaded()
for i=1,GetMerchantNumItems() do
if not GetMerchantItemLink(i) then
return false
end
end
return true
end
function public.merchant_info(item_id)
local buy_info
if aux_merchant_buy[item_id] then
buy_info = Aux.persistence.read(merchant_buy_schema, aux_merchant_buy[item_id])
end
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 = aux_items[item_id]
if data_string then
local cached_data = Aux.persistence.read(items_schema, data_string)
return {
name = cached_data.name,
itemstring = 'item:'..item_id..':0:0:0',
quality = cached_data.quality,
level = cached_data.level,
class = cached_data.class,
subclass = cached_data.subclass,
slot = cached_data.slot,
max_stack = cached_data.max_stack,
texture = cached_data.texture,
}
end
end
function public.item_id(item_name)
return aux_item_ids[strlower(item_name)]
end
function private.merchant_buy_scan()
local incomplete_data
for i=1,GetMerchantNumItems() do
local _, _, price, count, stock = GetMerchantItemInfo(i)
local link = GetMerchantItemLink(i)
if link then
local item_id = Aux.info.parse_hyperlink(link)
local new_unit_price, new_limited = price / count, stock >= 0
if aux_merchant_buy[item_id] then
local buy_info = Aux.persistence.read(merchant_buy_schema, aux_merchant_buy[item_id])
local unit_price
if buy_info.limited and not new_limited then
unit_price = new_unit_price
elseif new_limited and not buy_info.limited then
unit_price = buy_info.unit_price
else
unit_price = min(buy_info.unit_price, new_unit_price)
end
aux_merchant_buy[item_id] = Aux.persistence.write(merchant_buy_schema, {
unit_price = unit_price,
limited = buy_info.limited and new_limited,
})
else
aux_merchant_buy[item_id] = Aux.persistence.write(merchant_buy_schema, {
unit_price = new_unit_price,
limited = new_limited,
})
end
else
incomplete_data = true
end
end
return not incomplete_data
end
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
end
end
end
function private.scan_wdb()
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
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, function()
return helper(item_id)
end)
else
sort(aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
end
end
helper(MIN_ITEM_ID)
end
function public.populate_wdb()
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(function()
return helper(item_id + 1)
end)
end
helper(MIN_ITEM_ID)
end
+196
View File
@@ -0,0 +1,196 @@
local private, public = {}, {}
Aux.disenchant = public
function public.source(item_id)
local info = {
[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'},
[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+'},
}
return unpack(info[item_id] or {})
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,
}
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
function public.value(slot, quality, level)
local expectation
for _, event in public.distribution(slot, quality, level) do
local value = Aux.history.value(event.item_id..':'..0)
if not value then
return
else
expectation = (expectation or 0) + event.probability * (event.min_quantity + event.max_quantity) / 2 * value
end
end
return expectation
end
function public.distribution(slot, quality, level)
if not (armor[slot] or weapon[slot]) or level == 0 then
return {}
end
local function p(probability_armor, probability_weapon)
if armor[slot] then
return probability_armor
elseif weapon[slot] then
return probability_weapon
end
end
if quality == UNCOMMON then
if level <= 10 then
return {
{item_id=10940, min_quantity=1, max_quantity=2, probability=p(0.8, 0.2)},
{item_id=10938, min_quantity=1, max_quantity=2, probability=p(0.2, 0.8)},
}
elseif level <= 15 then
return {
{item_id=10940, min_quantity=2, max_quantity=3, probability=p(0.75, 0.2)},
{item_id=10939, min_quantity=1, max_quantity=2, probability=p(0.2, 0.75)},
{item_id=10978, min_quantity=1, max_quantity=1, probability=0.05},
}
elseif level <= 20 then
return {
{item_id=10940, min_quantity=4, max_quantity=6, probability=p(0.75, 0.15)},
{item_id=10998, min_quantity=1, max_quantity=2, probability=p(0.15, 0.75)},
{item_id=10978, min_quantity=1, max_quantity=1, probability=0.10},
}
elseif level <= 25 then
return {
{item_id=11083, min_quantity=1, max_quantity=2, probability=p(0.75, 0.2)},
{item_id=11082, min_quantity=1, max_quantity=2, probability=p(0.2, 0.75)},
{item_id=11084, min_quantity=1, max_quantity=1, probability=0.05},
}
elseif level <= 30 then
return {
{item_id=11083, min_quantity=2, max_quantity=5, probability=p(0.75, 0.2)},
{item_id=11134, min_quantity=1, max_quantity=2, probability=p(0.2, 0.75)},
{item_id=11138, min_quantity=1, max_quantity=1, probability=0.05},
}
elseif level <= 35 then
return {
{item_id=11137, min_quantity=1, max_quantity=2, probability=p(0.75, 0.2)},
{item_id=11135, min_quantity=1, max_quantity=2, probability=p(0.2, 0.75)},
{item_id=11139, min_quantity=1, max_quantity=1, probability=0.05},
}
elseif level <= 40 then
return {
{item_id=11137, min_quantity=2, max_quantity=5, probability=p(0.75, 0.2)},
{item_id=11174, min_quantity=1, max_quantity=2, probability=p(0.2, 0.75)},
{item_id=11177, min_quantity=1, max_quantity=1, probability=0.05},
}
elseif level <= 45 then
return {
{item_id=11176, min_quantity=1, max_quantity=2, probability=p(0.75, 0.2)},
{item_id=11175, min_quantity=1, max_quantity=2, probability=p(0.2, 0.75)},
{item_id=11178, min_quantity=1, max_quantity=1, probability=0.05},
}
elseif level <= 50 then
return {
{item_id=11176, min_quantity=2, max_quantity=5, probability=p(0.75, 0.22)},
{item_id=16202, min_quantity=1, max_quantity=2, probability=p(0.2, 0.75)},
{item_id=14343, min_quantity=1, max_quantity=1, probability=p(0.05, 0.03)},
}
elseif level <= 55 then
return {
{item_id=16204, min_quantity=1, max_quantity=2, probability=p(0.75, 0.22)},
{item_id=16203, min_quantity=1, max_quantity=2, probability=p(0.2, 0.75)},
{item_id=14344, min_quantity=1, max_quantity=1, probability=p(0.05, 0.03)},
}
elseif level <= 60 then
return {
{item_id=16204, min_quantity=2, max_quantity=5, probability=p(0.75, 0.22)},
{item_id=16203, min_quantity=2, max_quantity=3, probability=p(0.2, 0.75)},
{item_id=14344, min_quantity=1, max_quantity=1, probability=p(0.05, 0.03)},
}
end
elseif quality == RARE then
if level <= 20 then
return {{item_id=10978, min_quantity=1, max_quantity=1, probability=1}}
elseif level <= 25 then
return {{item_id=11084, min_quantity=1, max_quantity=1, probability=1}}
elseif level <= 30 then
return {{item_id=11138, min_quantity=1, max_quantity=1, probability=1}}
elseif level <= 35 then
return {{item_id=11139, min_quantity=1, max_quantity=1, probability=1}}
elseif level <= 40 then
return {{item_id=11177, min_quantity=1, max_quantity=1, probability=1}}
elseif level <= 45 then
return {{item_id=11178, min_quantity=1, max_quantity=1, probability=1}}
elseif level <= 50 then
return {{item_id=14343, min_quantity=1, max_quantity=1, probability=1}}
elseif level <= 55 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}}
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
if level <= 40 then
return {{item_id=11177, min_quantity=2, max_quantity=4, probability=1}}
elseif level <= 45 then
return {{item_id=11178, min_quantity=2, max_quantity=4, probability=1}}
elseif level <= 50 then
return {{item_id=14343, min_quantity=2, max_quantity=4, probability=1}}
elseif level <= 55 then
return {{item_id=20725, min_quantity=1, max_quantity=1, probability=1}}
elseif level <= 60 then
return {{item_id=20725, min_quantity=1, max_quantity=2, probability=1}}
end
end
return {}
end
+133
View File
@@ -0,0 +1,133 @@
local private, public = {}, {}
Aux.history = public
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 = {}
function private.next_push()
local date = date('*t')
date.hour, date.min, date.sec = 24, 0, 0
return time(date)
end
function private.new_record()
return { next_push = private.next_push(), data_points = {} }
end
function private.load_data()
local dataset = Aux.persistence.load_dataset()
dataset.history = dataset.history or {}
return dataset.history
end
function private.read_record(item_key)
local data = private.load_data()
local record
if data[item_key] then
record = Aux.persistence.read(history_schema, data[item_key])
else
record = private.new_record()
end
if record.next_push <= time() then
private.push_record(record)
private.write_record(item_key, record)
end
return record
end
function private.write_record(item_key, record)
private.value_cache[item_key] = nil
local data = private.load_data()
data[item_key] = Aux.persistence.write(history_schema, record)
end
function public.process_auction(auction_record)
local item_record = private.read_record(auction_record.item_key)
local unit_bid_price = ceil(auction_record.bid_price / auction_record.aux_quantity)
local unit_buyout_price = ceil(auction_record.buyout_price / auction_record.aux_quantity)
if auction_record.buyout_price > 0 then
item_record.daily_min_buyout = item_record.daily_min_buyout and min(item_record.daily_min_buyout, unit_buyout_price) or unit_buyout_price
end
item_record.daily_max_price = max(item_record.daily_max_price or 0, unit_buyout_price, unit_bid_price)
private.write_record(auction_record.item_key, item_record)
end
function public.price_data(item_key)
local item_record = private.read_record(item_key)
return item_record.daily_min_buyout, item_record.daily_max_price, item_record.data_points
end
function public.value(item_key)
if not private.value_cache[item_key] or private.value_cache[item_key].next_push <= time() then
local item_record = private.read_record(item_key)
local value
if getn(item_record.data_points) > 0 then
local weighted_values = {}
local total_weight = 0
for _, data_point in item_record.data_points do
local weight = 0.99^Aux.round((item_record.data_points[1].time - data_point.time) / (60*60*24))
total_weight = total_weight + weight
tinsert(weighted_values, {value = data_point.market_value, weight = weight})
end
for _, weighted_value in weighted_values do
weighted_value.weight = weighted_value.weight / total_weight
end
value = private.weighted_median(weighted_values)
else
value = private.market_value(item_record)
end
private.value_cache[item_key] = {value=value, next_push=item_record.next_push}
end
return private.value_cache[item_key].value
end
function public.market_value(item_key)
local item_record = private.read_record(item_key)
return private.market_value(item_record)
end
function private.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)
local sorted_list = {}
for _, e in list do
tinsert(sorted_list, e)
end
sort(sorted_list, function(a,b) return a.value < b.value end)
local weight = 0
for _, element in sorted_list do
weight = weight + element.weight
if weight >= 0.5 then
return element.value
end
end
end
function private.push_record(item_record)
local market_value = private.market_value(item_record)
if market_value then
tinsert(item_record.data_points, 1, { market_value = market_value, time = item_record.next_push })
while getn(item_record.data_points) > 11 do
tremove(item_record.data_points)
end
end
item_record.daily_min_buyout = nil
item_record.daily_max_price = nil
item_record.next_push = private.next_push()
end
+96
View File
@@ -0,0 +1,96 @@
local private, public = {}, {}
Aux.post = public
local state
function private.process()
if state.posted < state.count then
local stacking_complete, target_slot
Aux.stack.start(
state.item_key,
state.stack_size,
function(slot)
stacking_complete = true
target_slot = slot
end
)
return Aux.control.wait_until(function() return stacking_complete end, function()
if target_slot then
return private.post_auction(target_slot, private.process)
else
return public.stop()
end
end)
end
return public.stop()
end
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
ClearCursor()
ClickAuctionSellItemButton()
ClearCursor()
PickupContainerItem(unpack(slot))
ClickAuctionSellItemButton()
ClearCursor()
StartAuction(max(1, Aux.round(state.unit_start_price * item_info.aux_quantity)), Aux.round(state.unit_buyout_price * item_info.aux_quantity), state.duration)
local posted
local listener = Aux.control.event_listener('CHAT_MSG_SYSTEM')
listener:set_action(function()
if arg1 == ERR_AUCTION_STARTED then
posted = true
listener:stop()
end
end)
listener:start()
Aux.control.wait_until(function() return posted end, function()
state.posted = state.posted + 1
return k()
end)
else
return public.stop()
end
end
function public.stop()
if state then
Aux.control.kill_thread(state.thread_id)
local callback = state.callback
local posted = state.posted
state = nil
if callback then
callback(posted)
end
end
end
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, callback)
public.stop()
local thread_id = Aux.control.new_thread(private.process)
state = {
thread_id = thread_id,
item_key = item_key,
stack_size = stack_size,
duration = duration,
unit_start_price = unit_start_price,
unit_buyout_price = unit_buyout_price,
count = count,
posted = 0,
callback = callback,
}
end
+241
View File
@@ -0,0 +1,241 @@
local private , public = {}, {}
Aux.scan = public
local PAGE_SIZE = 50
local state
local threads = {}
function private.last_page(total_count)
local total_pages = math.ceil(total_count / PAGE_SIZE)
local last_page = max(total_pages - 1, 0)
local last_page_limit = Aux.util.safe_index(private.current_query().blizzard_query, 'last_page')
return last_page_limit and min(last_page_limit, last_page) or last_page
end
function private.current_query()
return private.current_thread().params.queries[private.current_thread().query_index]
end
function private.current_thread()
for _, thread in threads do
if thread.id == Aux.control.thread_id then
return thread
end
end
end
function public.start(params)
if threads[params.type] then
public.abort(threads[params.type].id)
end
local thread_id = Aux.control.new_thread(function()
return private.wait_for_callback(private.current_thread().params.on_scan_start, private.scan)
end)
threads[params.type] = {
id = thread_id,
params = params,
}
return thread_id
end
function public.abort(scan_id)
local aborted_threads = {}
for t, thread in pairs(threads) do
if not scan_id or thread.id == scan_id then
Aux.control.kill_thread(thread.id)
threads[t] = nil
tinsert(aborted_threads, thread)
end
end
for _, thread in ipairs(aborted_threads) do
if thread.params.on_abort then
thread.params.on_abort()
end
end
end
function private.wait_for_results(k)
if private.current_thread().params.type == 'bidder' then
return Aux.control.wait_until(function() return Aux.bids_loaded end, k)
elseif private.current_thread().params.type == 'owner' then
return private.wait_for_owner_results(k)
elseif private.current_thread().params.type == 'list' then
return private.wait_for_list_results(k)
end
end
function private.wait_for_owner_results(k)
local updated
if private.current_thread().page == Aux.current_owner_page then
updated = true
else
Aux.control.on_next_event('AUCTION_OWNED_LIST_UPDATE', function()
updated = true
end)
end
Aux.control.wait_until(function() return updated end, k)
end
function private.wait_for_list_results(k)
local updated, last_update
local listener = Aux.control.event_listener('AUCTION_ITEM_LIST_UPDATE', function()
last_update = GetTime()
updated = true
end)
listener:start()
Aux.control.wait_until(function()
-- order important, owner_data_complete must be called after an update to request missing data
local ok = updated and private.owner_data_complete() or last_update and GetTime() - last_update > 5
updated = false
return ok
end, function()
listener:stop()
return k()
end)
end
function private.owner_data_complete()
if private.current_thread().params.ignore_owner or aux_ignore_owner then
return true
end
local count = GetNumAuctionItems(private.current_thread().params.type)
for i=1,count do
local auction_info = Aux.info.auction(i, private.current_thread().params.type)
if auction_info and not auction_info.owner then
return false
end
end
return true
end
function private.wait_for_callback(...)
local ok = true
local f = tremove(arg, 1)
local k = tremove(arg)
if f then
tinsert(arg, {
suspend = function() ok = false end,
resume = function() ok = true end,
})
f(unpack(arg))
end
if ok then
return k()
else
return Aux.control.wait_until(function() return ok end, k)
end
end
function private.scan()
private.current_thread().query_index = private.current_thread().query_index and private.current_thread().query_index + 1 or 1
if private.current_query() then
if private.current_query().blizzard_query then
private.current_thread().page = private.current_query().blizzard_query.first_page or 0
else
private.current_thread().page = nil
end
private.wait_for_callback(private.current_thread().params.on_start_query, private.current_thread().query_index, private.process_query)
else
local on_complete = private.current_thread().params.on_complete
threads[private.current_thread().params.type] = nil
if on_complete then
return on_complete()
end
end
end
function private.process_query()
if private.current_query().blizzard_query then
return private.submit_query(private.scan_page)
else
return private.scan_page()
end
end
function private.scan_page()
private.scan_auctions(function()
private.wait_for_callback(private.current_thread().params.on_page_scanned, function()
if private.current_query().blizzard_query and private.current_thread().page < private.last_page(private.current_thread().total_auctions) then
private.current_thread().page = private.current_thread().page + 1
return private.process_query()
else
return private.scan()
end
end)
end)
end
function private.scan_auctions(k)
return private.scan_auctions_helper(1, k)
end
function private.scan_auctions_helper(i, k)
local recurse = function()
if i >= (private.current_thread().page_auctions or GetNumAuctionItems(private.current_thread().params.type)) then
return k()
else
return private.scan_auctions_helper(i + 1, k)
end
end
local auction_info = Aux.info.auction(i, private.current_thread().params.type)
if auction_info and (auction_info.owner or private.current_thread().params.ignore_owner or aux_ignore_owner) then
auction_info.index = i
auction_info.page = private.current_thread().page
auction_info.blizzard_query = private.current_query().blizzard_query
auction_info.query_type = private.current_thread().params.type
Aux.history.process_auction(auction_info)
if not private.current_query().validator or private.current_query().validator(auction_info) then
return private.wait_for_callback(private.current_thread().params.on_auction, auction_info, recurse)
end
end
return recurse()
end
function private.submit_query(k)
Aux.control.wait_until(function() return private.current_thread().params.type ~= 'list' or CanSendAuctionQuery() end, function()
if private.current_thread().params.on_submit_query then
private.current_thread().params.on_submit_query()
end
if private.current_thread().params.type == 'bidder' then
GetBidderAuctionItems(private.current_thread().page)
elseif private.current_thread().params.type == 'owner' then
GetOwnerAuctionItems(private.current_thread().page)
else
QueryAuctionItems(
Aux.util.safe_index(private.current_query().blizzard_query, 'name'),
Aux.util.safe_index(private.current_query().blizzard_query, 'min_level'),
Aux.util.safe_index(private.current_query().blizzard_query, 'max_level'),
Aux.util.safe_index(private.current_query().blizzard_query, 'slot'),
Aux.util.safe_index(private.current_query().blizzard_query, 'class'),
Aux.util.safe_index(private.current_query().blizzard_query, 'subclass'),
private.current_thread().page,
Aux.util.safe_index(private.current_query().blizzard_query, 'usable'),
Aux.util.safe_index(private.current_query().blizzard_query, 'quality')
)
end
private.wait_for_results(function()
private.current_thread().page_auctions, private.current_thread().total_auctions = GetNumAuctionItems(private.current_thread().params.type)
private.wait_for_callback(
private.current_thread().params.on_page_loaded,
private.current_thread().page - (private.current_query().blizzard_query.first_page or 0) + 1,
max(1, private.last_page(private.current_thread().total_auctions) - (private.current_query().blizzard_query.first_page or 0) + 1),
k
)
end)
end)
end
+87
View File
@@ -0,0 +1,87 @@
SLASH_AUX1 = '/aux'
function SlashCmdList.AUX(command)
if not command then return end
local arguments = Aux.util.tokenize(command)
if arguments[1] == 'clear' and arguments[2] == 'history' then
Aux.persistence.load_dataset().history = nil
Aux.log('History cleared.')
elseif arguments[1] == 'clear' and arguments[2] == 'post' then
Aux.persistence.load_dataset().post = nil
Aux.log('Post settings cleared.')
elseif arguments[1] == 'clear' and arguments[2] == 'datasets' then
aux_datasets = {}
Aux.log('Datasets cleared.')
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'buy' then
aux_merchant_buy = {}
Aux.log('Merchant buy prices cleared.')
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'sell' then
aux_merchant_sell = {}
Aux.log('Merchant sell prices cleared.')
elseif arguments[1] == 'clear' and arguments[2] == 'item' and arguments[3] == 'cache' then
aux_items = {}
aux_item_ids = {}
aux_auctionable_items = {}
Aux.log('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
aux_tooltip_value = not aux_tooltip_value
Aux.log('Historical value in tooltip '..(aux_tooltip_value and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'tooltip' and arguments[2] == 'daily' then
aux_tooltip_daily = not aux_tooltip_daily
Aux.log('Market value in tooltip '..(aux_tooltip_daily and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'tooltip' and arguments[2] == 'vendor' and arguments[3] == 'buy' then
aux_tooltip_vendor_buy = not aux_tooltip_vendor_buy
Aux.log('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
aux_tooltip_vendor_sell = not aux_tooltip_vendor_sell
Aux.log('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
aux_tooltip_disenchant_value = not aux_tooltip_disenchant_value
Aux.log('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
aux_tooltip_disenchant_distribution = not aux_tooltip_disenchant_distribution
Aux.log('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
aux_tooltip_disenchant_source = not aux_tooltip_disenchant_source
Aux.log('Disenchant source in tooltip '..(aux_tooltip_disenchant_source and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'ignore' and arguments[2] == 'owner' then
aux_ignore_owner = not aux_ignore_owner
Aux.log('Ignoring of owner '..(aux_ignore_owner and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'addchar' then
local realm = GetCVar('realmName')
aux_characters[realm] = aux_characters[realm] or {}
for i=2,getn(arguments) do
local name = string.gsub(strlower(arguments[i]), '^%l', strupper)
if not aux_characters[realm][name] then
aux_characters[realm][name] = true
Aux.log('Character "'..name..'" added.')
end
end
elseif arguments[1] == 'delchar' then
local realm = GetCVar('realmName')
if not aux_characters[realm] then
return
end
for i=2,getn(arguments) do
local name = string.gsub(strlower(arguments[i]), '^%l', strupper)
if aux_characters[realm][name] then
aux_characters[realm][name] = nil
Aux.log('Character "'..name..'" removed.')
end
end
elseif arguments[1] == 'chars' then
local realm = GetCVar('realmName')
local chars = {}
for name, _ in pairs(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.')
end
else
Aux.log('Unknown command: "'..command..'"')
end
end
+138
View File
@@ -0,0 +1,138 @@
local private, public = {}, {}
Aux.stack = public
local state
function private.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)
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)
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)
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)
for slot in Aux.util.inventory() do
if private.matching_item(slot, partial) and not Aux.util.table_eq(slot, state.target_slot) then
return slot
end
end
end
function private.matching_item(slot, partial)
local item_info = Aux.info.container_item(unpack(slot))
return item_info and item_info.item_key == 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()
for slot, type in Aux.util.inventory() do
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
return slot
end
end
end
function private.find_charge_item_slot()
for slot in Aux.util.inventory() do
if private.matching_item(slot) and private.charges(slot) == state.target_size then
return slot
end
end
end
function private.move_item(from_slot, to_slot, amount, k)
if private.locked(from_slot) or private.locked(to_slot) then
return Aux.control.wait(k)
end
amount = min(private.max_stack(from_slot) - private.stack_size(to_slot), private.stack_size(from_slot), amount)
local expected_size = private.stack_size(to_slot) + amount
ClearCursor()
SplitContainerItem(from_slot[1], from_slot[2], amount)
PickupContainerItem(unpack(to_slot))
return Aux.control.wait_until(function() return private.stack_size(to_slot) == expected_size end, k)
end
function private.process()
if not state.target_slot or not private.matching_item(state.target_slot) then
state.target_slot = private.find_item_slot()
if not state.target_slot then
return public.stop()
end
end
if private.charges(state.target_slot) then
state.target_slot = private.find_charge_item_slot()
return public.stop()
end
if private.stack_size(state.target_slot) > state.target_size then
local slot = private.find_item_slot(true) or private.find_empty_slot()
if slot then
return private.move_item(
state.target_slot,
slot,
private.stack_size(state.target_slot) - state.target_size,
private.process
)
end
elseif private.stack_size(state.target_slot) < state.target_size then
local slot = private.find_item_slot()
if slot then
return private.move_item(
slot,
state.target_slot,
state.target_size - private.stack_size(state.target_slot),
private.process
)
end
end
return public.stop()
end
function public.stop()
if state then
Aux.control.kill_thread(state.thread_id)
local callback, slot = state.callback, state.target_slot
if slot and not private.matching_item(slot) then
slot = nil
end
state = nil
if callback then
callback(slot)
end
end
end
function public.start(item_key, size, callback)
public.stop()
local thread_id = Aux.control.new_thread(private.process)
state = {
thread_id = thread_id,
item_key = item_key,
target_size = size,
callback = callback,
}
end
+253
View File
@@ -0,0 +1,253 @@
local private, public = {}, {}
Aux.tooltip = public
aux_tooltip_value = true
local game_tooltip_hooks = {}
local hooked_setter
local game_tooltip_money
function public.on_load()
for func, hook in game_tooltip_hooks do
local func, hook = func, hook
Aux.hook(
func,
function(...)
hooked_setter = true
game_tooltip_money = 0
local results = {Aux.orig[GameTooltip][func](unpack(arg)) }
hooked_setter = false
hook(unpack(arg))
return unpack(results)
end,
GameTooltip
)
end
local orig = SetItemRef
SetItemRef = function(...)
local result = orig(unpack(arg))
local name, _, quality = GetItemInfo(arg[1])
if not IsShiftKeyDown() and not IsControlKeyDown() and name then
local _, _, _, hex = GetItemQualityColor(quality)
local link = hex.. '|H'..arg[1]..'|h['..name..']|h|r'
private.extend_tooltip(ItemRefTooltip, link, 1)
end
return result
end
local orig = GameTooltip:GetScript('OnTooltipAddMoney')
GameTooltip:SetScript('OnTooltipAddMoney', function(...)
if hooked_setter then
game_tooltip_money = arg1
else
return orig(unpack(arg))
end
end)
end
function private.extend_tooltip(tooltip, hyperlink, quantity)
local item_id, suffix_id = Aux.info.parse_hyperlink(hyperlink)
quantity = IsShiftKeyDown() and quantity or 1
if aux_tooltip_disenchant_source then
local color = {r=0.7, g=0.7, b=0.7 }
local type, range = Aux.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)
elseif type == 'SHARD' then
tooltip:AddLine(format('Can disenchant from level %s |cff0070ddRare|r and |cff1eff00Uncommon|r items.', range), color.r, color.g, color.b, true)
elseif type == 'ESSENCE' then
tooltip:AddLine(format('Can disenchant from level %s |cff1eff00Uncommon|r items.', range), color.r, color.g, color.b, true)
elseif type == 'DUST' then
tooltip:AddLine(format('Can disenchant from level %s |cff1eff00Uncommon|r items.', range), color.r, color.g, color.b, true)
end
end
local item_info = Aux.info.item(item_id)
if item_info then
local distribution = Aux.disenchant.distribution(item_info.slot, item_info.quality, item_info.level)
if getn(distribution) > 0 then
if aux_tooltip_disenchant_distribution then
local color = {r=0.8, g=0.8, b=0.2}
tooltip:AddLine('Disenchants into:', color.r, color.g, color.b)
sort(distribution, function(a,b) return a.probability > b.probability end)
for _, event in distribution do
tooltip:AddLine(format(' %s%% %s (%s-%s)', event.probability * 100, Aux.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 aux_tooltip_disenchant_value then
local color = {r=0.1, g=0.6, b=0.6}
local disenchant_value = Aux.disenchant.value(item_info.slot, item_info.quality, item_info.level)
tooltip:AddLine('Disenchant Value: '..(disenchant_value and Aux.util.format_money(disenchant_value) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end
end
end
if aux_tooltip_vendor_buy then
local color = {r=0.8, g=0.5, b=0.1}
local _, price, limited = Aux.cache.merchant_info(item_id)
if price then
tooltip:AddLine('Vendor Buy '..(limited and '(limited): ' or ': ')..Aux.util.format_money(price * quantity), color.r, color.g, color.b)
end
end
if aux_tooltip_vendor_sell then
local color = {r=0.8, g=0.5, b=0.1}
local price = Aux.cache.merchant_info(item_id)
if price ~= 0 then
tooltip:AddLine('Vendor Sell: '..(price and Aux.util.format_money(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=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)
local value = Aux.history.value(item_key)
if auctionable then
if aux_tooltip_value then
tooltip:AddLine('Value: '..(value and Aux.util.format_money(value * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end
if aux_tooltip_daily then
local market_value = Aux.history.market_value(item_key)
tooltip:AddLine('Today: '..(market_value and Aux.util.format_money(market_value * quantity)..' ('..Aux.auction_listing.percentage_historical(Aux.round(market_value / value * 100))..')' or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end
end
if tooltip == GameTooltip and game_tooltip_money > 0 then
SetTooltipMoney(tooltip, game_tooltip_money)
end
tooltip:Show()
end
function game_tooltip_hooks:SetHyperlink(itemstring)
local name, _, quality = GetItemInfo(itemstring)
if name then
local _, _, _, hex = GetItemQualityColor(quality)
local link = hex.. '|H'..itemstring..'|h['..name..']|h|r'
private.extend_tooltip(GameTooltip, link, 1)
end
end
function game_tooltip_hooks:SetAuctionItem(type, index)
local link = GetAuctionItemLink(type, index)
if link then
local _, _, quantity = GetAuctionItemInfo(type, index)
private.extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetLootItem(slot)
local link = GetLootSlotLink(slot)
if link then
local _, _, quantity = GetLootSlotInfo(slot)
private.extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetQuestItem(qtype, slot)
local link = GetQuestItemLink(qtype, slot)
if link then
local _, _, quantity = GetQuestItemInfo(qtype, slot)
private.extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetQuestLogItem(qtype, slot)
local link = GetQuestLogItemLink(qtype, slot)
if link then
local _, _, quantity = GetQuestLogRewardInfo(slot)
private.extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetBagItem(bag, slot)
local link = GetContainerItemLink(bag, slot)
if link then
local _, quantity = GetContainerItemInfo(bag, slot)
private.extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetInboxItem(index)
local name, _, quantity = GetInboxItem(index)
local id = name and Aux.cache.item_id(name)
if id then
local _, itemstring, quality = GetItemInfo(id)
local _, _, _, hex = GetItemQualityColor(tonumber(quality))
local link = hex.. '|H'..itemstring..'|h['..name..']|h|r'
private.extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetInventoryItem(unit, slot)
local link = GetInventoryItemLink(unit, slot)
if link then
private.extend_tooltip(GameTooltip, link, 1)
end
end
function game_tooltip_hooks:SetMerchantItem(slot)
local link = GetMerchantItemLink(slot)
if link then
local _, _, _, quantity = GetMerchantItemInfo(slot)
private.extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetCraftItem(skill, slot)
local link, quantity
if slot then
link = GetCraftReagentItemLink(skill, slot)
quantity = ({GetCraftReagentInfo(skill, slot)})[3]
else
link = GetCraftItemLink(skill)
quantity = 1
end
if link then
private.extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetCraftSpell(slot)
local link = GetCraftItemLink(slot)
if link then
private.extend_tooltip(GameTooltip, link, 1)
end
end
function game_tooltip_hooks:SetTradeSkillItem(skill, slot)
local link, quantity
if slot then
link = GetTradeSkillReagentItemLink(skill, slot)
quantity = ({GetTradeSkillReagentInfo(skill, slot)})[3]
else
link = GetTradeSkillItemLink(skill)
quantity = 1
end
if link then
private.extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetAuctionSellItem()
local name, _, quantity, _, _, _ = GetAuctionSellItemInfo()
if name then
for slot in Aux.util.inventory() do
local link = GetContainerItemLink(unpack(slot))
if link and ({Aux.info.parse_hyperlink(link)})[5] == name then
private.extend_tooltip(GameTooltip, link, quantity)
return
end
end
end
end