progress on vendor database

This commit is contained in:
Manuel Simon Hirsig
2016-03-20 18:40:18 +01:00
parent acc3da3f25
commit 83c9ba5bdb
5 changed files with 55 additions and 10 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
## Interface: 11200
## Title: Aux
## SavedVariablesPerCharacter: aux_recent_searches, aux_favorite_searches
## SavedVariables: aux_datasets, aux_items, aux_auctionable_items, aux_post_mode, aux_price_per_unit, aux_tooltip_daily, aux_tooltip_disenchant_value, aux_tooltip_disenchant_distribution, aux_tooltip_disenchant_source
## SavedVariablesPerCharacter: aux_recent_searches, aux_favorite_searches, aux_post_mode, aux_price_per_unit, aux_tooltip_daily, aux_tooltip_disenchant_value, aux_tooltip_disenchant_distribution, aux_tooltip_disenchant_source
## SavedVariables: aux_datasets, aux_items, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell
slash.lua
core.xml
+5 -2
View File
@@ -47,6 +47,7 @@ function Aux.on_load()
end)
end
Aux.merchant.on_load()
Aux.item_cache.on_load()
Aux.persistence.on_load()
Aux.tooltip.on_load()
@@ -98,7 +99,8 @@ function Aux.on_addon_loaded()
for i=1,reagent_count do
local item_id, suffix_id = Aux.info.parse_hyperlink(GetCraftReagentItemLink(id, i))
local count = ({GetCraftReagentInfo(id, i)})[3]
local value = Aux.history.value(item_id..':'..suffix_id)
local _, price, unlimited = Aux.merchant.info(item_id)
local value = price and unlimited and price or Aux.history.value(item_id..':'..suffix_id)
if not value then
total_cost = nil
break
@@ -124,7 +126,8 @@ function Aux.on_addon_loaded()
for i=1,reagent_count do
local item_id, suffix_id = Aux.info.parse_hyperlink(GetTradeSkillReagentItemLink(id, i))
local count = ({GetTradeSkillReagentInfo(id, i)})[3]
local value = Aux.history.value(item_id..':'..suffix_id)
local _, price, unlimited = Aux.merchant.info(item_id)
local value = price and unlimited and price or Aux.history.value(item_id..':'..suffix_id)
if not value then
total_cost = nil
break
+36 -4
View File
@@ -1,18 +1,27 @@
local private, public = {}, {}
Aux.merchant = public
local sell_data = {}
local buy_data = {}
aux_merchant_buy, aux_merchant_sell = {}, {}
function public.on_load()
Aux.control.event_listener('MERCHANT_SHOW', private.scan_merchant).start()
end
function public.info(item_id)
local unit_price, unlimited
if aux_merchant_buy[item_id] then
local buy_fields = Aux.util.split(aux_merchant_buy[item_id], '#')
unit_price, unlimited = tonumber(buy_fields[1]), not not tonumber(buy_fields[2])
end
return aux_merchant_sell[item_id], unit_price, unlimited
end
function private.scan_merchant()
Aux.util.loop_inventory(function(bag, slot)
local item_info = Aux.info.container_item(bag, slot)
if item_info then
sell_data[item_info.item_id] = item_info.tooltip.money / item_info.aux_quantity
aux_merchant_sell[item_info.item_id] = item_info.tooltip.money / item_info.aux_quantity
end
end)
@@ -21,6 +30,29 @@ function private.scan_merchant()
for i=1,merchant_item_count do
local item_id = Aux.info.parse_hyperlink(GetMerchantItemLink(i))
local _, _, price, count, stock = GetMerchantItemInfo(i)
buy_data[item_id] = Aux.util.join({price / count, stock}, '#')
local new_unit_price, new_unlimited = price / count, Aux.persistence.blizzard_boolean(stock == -1)
if aux_merchant_buy[item_id] then
local fields = Aux.util.split(aux_merchant_buy[item_id], '#')
local old_unit_price, old_unlimited = tonumber(fields[1]), tonumber(fields[2])
local unit_price
if old_unlimited and not new_unlimited then
unit_price = old_unit_price
elseif new_unlimited and not old_unlimited then
unit_price = new_unit_price
else
unit_price = min(old_unit_price, new_unit_price)
end
aux_merchant_buy[item_id] = Aux.util.join({
unit_price,
old_unlimited or new_unlimited,
}, '#')
else
aux_merchant_buy[item_id] = Aux.util.join({
new_unit_price,
new_unlimited,
}, '#')
end
end
end
+4
View File
@@ -12,6 +12,10 @@ function private.get_dataset_key()
return private.realm..'|'..private.faction
end
function public.blizzard_boolean(bool)
return bool and 1 or nil
end
function public.load_dataset()
local dataset_key = private.get_dataset_key()
aux_datasets[dataset_key] = aux_datasets[dataset_key] or {}
+8 -2
View File
@@ -6,9 +6,15 @@ function SlashCmdList.AUX(parameter)
elseif parameter == 'clear post' then
Aux.persistence.load_dataset().post = nil
Aux.log('Post settings cleared.')
elseif parameter == 'clear' then
elseif parameter == 'clear datasets' then
aux_datasets = {}
Aux.log('Database cleared.')
Aux.log('Datasets cleared.')
elseif parameter == 'clear merchant buy' then
aux_merchant_buy = {}
Aux.log('Merchant buy prices cleared.')
elseif parameter == 'clear merchant sell' then
aux_merchant_sell = {}
Aux.log('Merchant sell prices cleared.')
elseif parameter == 'clear item cache' then
aux_items = {}
aux_auctionable_items = {}