big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-22 20:57:51 +02:00
parent 7d7d56277b
commit e024597cff
18 changed files with 216 additions and 4 deletions
+209
View File
@@ -0,0 +1,209 @@
module 'cache'
MIN_ITEM_ID = 1
MAX_ITEM_ID = 30000
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 = {}
_g.aux_auctionable_items = {}
_g.aux_merchant_buy = {}
_g.aux_merchant_sell = {}
_g.aux_characters = {}
function LOAD()
import 'persistence' 'info'
scan_wdb()
event_listener('MERCHANT_SHOW', on_merchant_show)
event_listener('MERCHANT_CLOSED', on_merchant_closed)
event_listener('MERCHANT_UPDATE', on_merchant_update)
event_listener('BAG_UPDATE', on_bag_update)
CreateFrame('Frame', nil, MerchantFrame):SetScript('OnUpdate', merchant_on_update)
event_listener('NEW_AUCTION_UPDATE', function()
for info in present(info.auction_sell_item()) do
for item_id in present(cache.item_id(info.name)) do
_g.aux_merchant_sell[cache.item_id(info.name)] = info.vendor_price / (info.max_item_charges(item_id) or info.count)
end
end
end)
end
do
local sell_scan_countdown, incomplete_buy_data
function on_merchant_show()
merchant_sell_scan()
incomplete_buy_data = not merchant_buy_scan()
end
function on_merchant_closed()
sell_scan_countdown = nil
incomplete_buy_data = false
end
function on_merchant_update()
if incomplete_buy_data then
incomplete_buy_data = not merchant_buy_scan()
end
end
function on_bag_update()
if MerchantFrame:IsVisible() then
sell_scan_countdown = 10
end
end
function merchant_on_update()
if sell_scan_countdown == 0 then
sell_scan_countdown = nil
merchant_sell_scan()
elseif sell_scan_countdown then
sell_scan_countdown = sell_scan_countdown - 1
end
end
end
function 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 _g.aux_merchant_buy[item_id] then
buy_info = persistence.read(merchant_buy_schema, _g.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
end
function public.item_info(item_id)
local data_string = _g.aux_items[item_id]
if data_string then
local cached_data = 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 _g.aux_item_ids[strlower(item_name)]
end
function 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 = 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])
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
_g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
unit_price = unit_price,
limited = buy_info.limited and new_limited,
})
else
_g.aux_merchant_buy[item_id] = 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 merchant_sell_scan()
for slot in inventory do
local item_info = 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
end
end
end
function 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, {
name = name,
quality = quality,
level = level,
class = class,
subclass = subclass,
slot = slot,
max_stack = max_stack,
texture = texture,
})
local tooltip = info.tooltip(function(tt) tt:SetHyperlink(itemstring) end)
if info.auctionable(tooltip, quality) then
tinsert(_g.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()
thread(when, function() return GetTime() - t0 > 0.1 end, 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)
end
end
function public.populate_wdb(item_id)
item_id = item_id or MIN_ITEM_ID
if item_id > MAX_ITEM_ID then
log('Cache populated.')
return
end
if not GetItemInfo('item:'..item_id) then
log('Fetching item '..item_id..'.')
AuxTooltip:SetHyperlink('item:'..item_id)
end
thread(populate_wdb, item_id + 1)
end
+197
View File
@@ -0,0 +1,197 @@
module 'disenchant'
UNCOMMON = 2
RARE = 3
EPIC = 4
do
local data = {
[10940] = {'DUST', '1-20'},
[11083] = {'DUST', '21-30'},
[11137] = {'DUST', '31-40'},
[11176] = {'DUST', '41-50'},
[16204] = {'DUST', '51-60'},
[10938] = {'ESSENCE', '1-10'},
[10939] = {'ESSENCE', '11-15'},
[10998] = {'ESSENCE', '16-20'},
[11082] = {'ESSENCE', '21-25'},
[11134] = {'ESSENCE', '26-30'},
[11135] = {'ESSENCE', '31-35'},
[11174] = {'ESSENCE', '36-40'},
[11175] = {'ESSENCE', '41-45'},
[16202] = {'ESSENCE', '46-50'},
[16203] = {'ESSENCE', '51-60'},
[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+'},
}
function public.source(item_id)
return unpack(data[item_id] or {})
end
end
function LOAD()
armor = set-from
'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 = set-from
'INVTYPE_2HWEAPON'
'INVTYPE_WEAPONMAINHAND'
'INVTYPE_WEAPON'
'INVTYPE_WEAPONOFFHAND'
'INVTYPE_SHIELD'
'INVTYPE_RANGED'
'INVTYPE_RANGEDRIGHT'
end
function public.value(slot, quality, level)
local expectation
for _, event in distribution(slot, quality, level) do
local value = 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
+132
View File
@@ -0,0 +1,132 @@
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'}}}}}
value_cache = {}
function next_push()
local date = date('*t')
date.hour, date.min, date.sec = 24, 0, 0
return time(date)
end
function new_record()
return { next_push = next_push(), data_points = {} }
end
function load_data()
local dataset = persistence.load_dataset()
dataset.history = dataset.history or {}
return dataset.history
end
function read_record(item_key)
local data = load_data()
local record
if data[item_key] then
record = persistence.read(history_schema, data[item_key])
else
record = new_record()
end
if record.next_push <= time() then
push_record(record)
write_record(item_key, record)
end
return record
end
function write_record(item_key, record)
value_cache[item_key] = nil
local data = load_data()
data[item_key] = persistence.write(history_schema, record)
end
function public.process_auction(auction_record)
local item_record = 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)
write_record(auction_record.item_key, item_record)
end
function public.price_data(item_key)
local item_record = 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 value_cache[item_key] or value_cache[item_key].next_push <= time() then
local item_record = 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^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 = weighted_median(weighted_values)
else
value = calculate_market_value(item_record)
end
value_cache[item_key] = {value=value, next_push=item_record.next_push}
end
return value_cache[item_key].value
end
function public.market_value(item_key)
local item_record = read_record(item_key)
return calculate_market_value(item_record)
end
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)
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 push_record(item_record)
local market_value = calculate_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 = next_push()
end
+88
View File
@@ -0,0 +1,88 @@
module 'post'
state = nil
function process()
if state.posted < state.count then
local stacking_complete
local send_signal, signal_received = signal()
when(signal_received, function()
local slot = signal_received()[1]
if slot then
return post_auction(slot, process)
else
return stop()
end
end)
return stack.start(state.item_key, state.stack_size, send_signal)
end
return stop()
end
function post_auction(slot, k)
local item_info = info.container_item(unpack(slot))
if item_info.item_key == state.item_key and 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, round(state.unit_start_price * item_info.aux_quantity)), round(state.unit_buyout_price * item_info.aux_quantity), state.duration)
local send_signal, signal_received = signal()
when(signal_received, function()
state.posted = state.posted + 1
return k()
end)
local posted
event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_STARTED then
send_signal()
kill()
end
end)
else
return stop()
end
end
function public.stop()
if state then
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)
stop()
local thread_id = thread(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
+234
View File
@@ -0,0 +1,234 @@
module 'scan'
PAGE_SIZE = 50
do
local scan_states = {}
function public.start(params)
for _, old_state in {scan_states[params.type]} do
abort(old_state.id)
end
local thread_id = thread(L(wait_for_callback, params.on_scan_start, scan))
scan_states[params.type] = {
id = thread_id,
params = params,
}
return thread_id
end
function public.abort(scan_id)
local aborted = {}
for type, state in scan_states do
if not scan_id or state.id == scan_id then
kill_thread(state.id)
scan_states[type] = nil
tinsert(aborted, state)
end
end
for _, state in aborted do
call(state.params.on_abort)
end
end
function complete()
local on_complete = state.params.on_complete
scan_states[state.params.type] = nil
call(on_complete)
end
function accessor.state()
local _, state = next(filter(scan_states, function(state) return state.id == thread_id end))
return state
end
end
function accessor.query() return state.params.queries[state.query_index] end
function wait_for_callback(...)
local send_signal, signal_received = signal()
local suspended
local ret
local f = tremove(arg, 1)
local k = tremove(arg)
if f then
tinsert(arg, {
suspend = function() suspended = true end,
resume = send_signal,
})
f(unpack(arg))
end
if not suspended then
send_signal()
end
return when(signal_received, function() return k(unpack(signal_received())) end)
end
function total_pages(total_auctions)
return ceil(total_auctions / PAGE_SIZE)
end
function 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()
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
state.page = query.blizzard_query.first_page or 0
else
state.page = nil
end
return wait_for_callback(state.params.on_start_query, state.query_index, process_query)
else
complete()
end
end
function process_query()
if query.blizzard_query then
return submit_query()
else
return scan_page()
end
end
function submit_query()
when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
call(state.params.on_submit_query)
state.last_query_time = GetTime()
if state.params.type == 'bidder' then
GetBidderAuctionItems(state.page)
elseif state.params.type == 'owner' then
GetOwnerAuctionItems(state.page)
else
local blizzard_query = query.blizzard_query or {}
QueryAuctionItems(
blizzard_query.name,
blizzard_query.min_level,
blizzard_query.max_level,
blizzard_query.slot,
blizzard_query.class,
blizzard_query.subclass,
state.page,
blizzard_query.usable,
blizzard_query.quality
)
end
return wait_for_results()
end)
end
function scan_page(i)
i = i or 1
local recurse = function(retry)
if i >= PAGE_SIZE then
wait_for_callback(state.params.on_page_scanned, function()
if query.blizzard_query and state.page < last_page(state.total_auctions) then
state.page = state.page + 1
return process_query()
else
return scan()
end
end)
else
return scan_page(retry and i or i + 1)
end
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
auction_info.index = i
auction_info.page = state.page
auction_info.blizzard_query = query.blizzard_query
auction_info.query_type = state.params.type
history.process_auction(auction_info)
if call(state.params.auto_buy_validator, 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, L(send_signal, true))
return thread(when, later(GetTime(), 10), L(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)
if removed then
return recurse(true)
else
return recurse()
end
end)
end
end
return recurse()
end
function wait_for_results()
local timeout = later(state.last_query_time, 10)
local send_signal, signal_received = signal()
when(signal_received, function()
if timeout() then
return submit_query()
else
_, state.total_auctions = GetNumAuctionItems(state.params.type)
return wait_for_callback(
state.params.on_page_loaded,
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,
scan_page
)
end
end)
thread(when, timeout, send_signal)
if state.params.type == 'bidder' then
return thread(when, function() return bids_loaded end, send_signal)
elseif state.params.type == 'owner' then
return wait_for_owner_results(send_signal)
elseif state.params.type == 'list' then
return wait_for_list_results(send_signal, signal_received)
end
end
function wait_for_owner_results(send_signal)
if state.page == current_owner_page then
return send_signal()
else
return on_next_event('AUCTION_OWNED_LIST_UPDATE', send_signal)
end
end
function 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
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
updated = false
return ok
end, send_signal)
end
function 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
end
return true
end
+87
View File
@@ -0,0 +1,87 @@
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
persistence.load_dataset().history = nil
log 'History cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'post' then
persistence.load_dataset().post = nil
log 'Post settings cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'datasets' then
_g.aux_datasets = {}
log 'Datasets cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'buy' then
_g.aux_merchant_buy = {}
log 'Merchant buy prices cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'sell' then
_g.aux_merchant_sell = {}
log 'Merchant sell prices cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'item' and arguments[3] == 'cache' then
_g.aux_items = {}
_g.aux_item_ids = {}
_g.aux_auctionable_items = {}
log 'Item cache cleared.'
elseif arguments[1] == 'populate' and arguments[2] == 'wdb' then
cache.populate_wdb()
elseif arguments[1] == 'tooltip' and arguments[2] == 'value' then
_g.aux_tooltip_value = not _g.aux_tooltip_value
log('Historical value in tooltip '..(_g.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
log('Market value in tooltip '..(_g.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
log('Vendor buy price in tooltip '..(_g.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
log('Vendor sell price in tooltip '..(_g.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
log('Disenchant value in tooltip '..(_g.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
log('Disenchant distribution in tooltip '..(_g.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
log('Disenchant source in tooltip '..(_g.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
log('Ignoring of owner '..(_g.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 {}
for i=3,getn(arguments) do
local name = string.gsub(strlower(arguments[i]), '^%l', strupper)
if not _g.aux_characters[realm][name] then
_g.aux_characters[realm][name] = true
log('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
return
end
for i=3,getn(arguments) do
local name = string.gsub(strlower(arguments[i]), '^%l', strupper)
if _g.aux_characters[realm][name] then
_g.aux_characters[realm][name] = nil
log('Character "'..name..'" removed.')
end
end
elseif arguments[1] == 'chars' then
local realm = GetCVar 'realmName'
local chars = {}
for name in _g.aux_characters[realm] or {} do
tinsert(chars, name)
end
if getn(chars) > 0 then
log('Your characters: "'..table.concat(chars, ', ')..'".')
else
log 'You don\'t have any additional characters. To add your characters type "/aux chars add NAME1 NAME2 NAME3...".'
end
else
log('Unknown command: "'..command..'"')
end
end
+128
View File
@@ -0,0 +1,128 @@
module 'stack'
state = nil
function 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)
local container_item_info = info.container_item(unpack(slot))
return container_item_info and container_item_info.charges
end
function 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)
local container_item_info = info.container_item(unpack(slot))
return container_item_info and container_item_info.locked
end
function find_item_slot(partial)
for slot in inventory do
if matching_item(slot, partial) and not eq(slot, state.target_slot) then
return slot
end
end
end
function matching_item(slot, partial)
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)
end
function find_empty_slot()
for slot, type in inventory do
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
return slot
end
end
end
function find_charge_item_slot()
for slot in inventory do
if matching_item(slot) and charges(slot) == state.target_size then
return slot
end
end
end
function move_item(from_slot, to_slot, amount, k)
if locked(from_slot) or locked(to_slot) then
return wait(k)
end
amount = min(max_stack(from_slot) - stack_size(to_slot), stack_size(from_slot), amount)
local expected_size = stack_size(to_slot) + amount
ClearCursor()
SplitContainerItem(from_slot[1], from_slot[2], amount)
PickupContainerItem(unpack(to_slot))
return when(function() return stack_size(to_slot) == expected_size end, k)
end
function 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()
end
if stack_size(state.target_slot) > state.target_size then
local slot = find_item_slot(true) or find_empty_slot()
if slot then
return move_item(
state.target_slot,
slot,
stack_size(state.target_slot) - state.target_size,
process
)
end
elseif stack_size(state.target_slot) < state.target_size then
local slot = find_item_slot()
if slot then
return move_item(
slot,
state.target_slot,
state.target_size - stack_size(state.target_slot),
process
)
end
end
return stop()
end
function public.stop()
if state then
kill_thread(state.thread_id)
local callback, slot = state.callback, state.target_slot
if slot and not matching_item(slot) then
slot = nil
end
state = nil
call(callback, slot)
end
end
function public.start(item_key, size, callback)
stop()
local thread_id = thread(process)
state = {
thread_id = thread_id,
item_key = item_key,
target_size = size,
callback = callback,
}
end
+248
View File
@@ -0,0 +1,248 @@
module 'tooltip'
--import 'gui' 'lol' 'kek'
_g.aux_tooltip_value = true
game_tooltip_hooks = {}
hooked_setter = nil
game_tooltip_money = nil
function LOAD()
for func, hook in game_tooltip_hooks do
local func, hook = func, hook
_m.hook(
func,
function(...)
hooked_setter = true
game_tooltip_money = 0
local results = {orig[GameTooltip][func](unpack(arg)) }
hooked_setter = false
hook(unpack(arg))
return unpack(results)
end,
GameTooltip
)
end
local orig = SetItemRef
setglobal('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'..FONT_COLOR_CODE_CLOSE
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 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=0.7, g=0.7, b=0.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)
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 = 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
if _g.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, 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=0.1, g=0.6, b=0.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=0.8, g=0.5, b=0.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=0.8, g=0.5, b=0.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=0.6}
local auctionable = not item_info or info.auctionable(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 = history.value(item_key)
if auctionable then
if _g.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
local market_value = history.market_value(item_key)
tooltip:AddLine('Today: '..(market_value and money.to_string2(market_value * quantity)..' ('..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
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'..FONT_COLOR_CODE_CLOSE
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)
extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetLootItem(slot)
local link = GetLootSlotLink(slot)
if link then
local _, _, quantity = GetLootSlotInfo(slot)
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)
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)
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)
extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetInboxItem(index)
local name, _, quantity = GetInboxItem(index)
local id = name and 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'..FONT_COLOR_CODE_CLOSE
extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetInventoryItem(unit, slot)
local link = GetInventoryItemLink(unit, slot)
if link then
extend_tooltip(GameTooltip, link, 1)
end
end
function game_tooltip_hooks:SetMerchantItem(slot)
local link = GetMerchantItemLink(slot)
if link then
local _, _, _, quantity = GetMerchantItemInfo(slot)
extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetCraftItem(skill, slot)
local link, quantity
if slot then
link, quantity = GetCraftReagentItemLink(skill, slot), select(3, GetCraftReagentInfo(skill, slot))
else
link, quantity = GetCraftItemLink(skill), 1
end
if link then
extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetCraftSpell(slot)
if x(GetCraftItemLink(slot)) then
extend_tooltip(GameTooltip, __, 1)
end
end
function game_tooltip_hooks:SetTradeSkillItem(skill, slot)
local link, quantity
if slot then
link, quantity = GetTradeSkillReagentItemLink(skill, slot), select(3, GetTradeSkillReagentInfo(skill, slot))
else
link, quantity = GetTradeSkillItemLink(skill), 1
end
if link then
extend_tooltip(GameTooltip, link, quantity)
end
end
function game_tooltip_hooks:SetAuctionSellItem()
local name, _, quantity = GetAuctionSellItemInfo()
if name then
for slot in inventory do
local link = GetContainerItemLink(unpack(slot))
if link and select(5, info.parse_link(link)) == name then
extend_tooltip(GameTooltip, link, quantity)
return
end
end
end
end