From 0a4b9c4eb6cf929325d68981c42c30f120aa456d Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sun, 20 Mar 2016 19:20:54 +0100 Subject: [PATCH] vendor filters --- Aux-AddOn.toc | 2 +- core.lua | 8 ++++---- merchant.lua | 20 ++++++++++---------- persistence.lua | 4 ++-- scan_util.lua | 30 ++++++++++++++++++++++++++++++ slash.lua | 6 ++++++ tooltip.lua | 18 +++++++++++++++++- 7 files changed, 70 insertions(+), 18 deletions(-) diff --git a/Aux-AddOn.toc b/Aux-AddOn.toc index 2d81644..4c2425d 100644 --- a/Aux-AddOn.toc +++ b/Aux-AddOn.toc @@ -1,6 +1,6 @@ ## Interface: 11200 ## Title: Aux -## 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 +## SavedVariablesPerCharacter: aux_recent_searches, aux_favorite_searches, aux_post_mode, aux_price_per_unit, aux_tooltip_daily, aux_tooltip_vendor_buy, aux_tooltip_vendor_sell, 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 diff --git a/core.lua b/core.lua index 108d986..065cc1e 100644 --- a/core.lua +++ b/core.lua @@ -99,8 +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 _, price, unlimited = Aux.merchant.info(item_id) - local value = price and unlimited and price or Aux.history.value(item_id..':'..suffix_id) + local _, price, limited = Aux.merchant.info(item_id) + local value = price and not limited and price or Aux.history.value(item_id..':'..suffix_id) if not value then total_cost = nil break @@ -126,8 +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 _, price, unlimited = Aux.merchant.info(item_id) - local value = price and unlimited and price or Aux.history.value(item_id..':'..suffix_id) + local _, price, limited = Aux.merchant.info(item_id) + local value = price and not limited and price or Aux.history.value(item_id..':'..suffix_id) if not value then total_cost = nil break diff --git a/merchant.lua b/merchant.lua index 1710b26..c674cb0 100644 --- a/merchant.lua +++ b/merchant.lua @@ -8,13 +8,13 @@ function public.on_load() end function public.info(item_id) - local unit_price, unlimited + local unit_price, limited 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]) + unit_price, limited = tonumber(buy_fields[1]), not not tonumber(buy_fields[2]) end - return aux_merchant_sell[item_id], unit_price, unlimited + return aux_merchant_sell[item_id], unit_price, limited end function private.scan_merchant() @@ -30,28 +30,28 @@ 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) - local new_unit_price, new_unlimited = price / count, Aux.persistence.blizzard_boolean(stock == -1) + local new_unit_price, new_limited = price / count, Aux.persistence.blizzard_boolean(stock >= 0) 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 old_unit_price, old_limited = 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 + if old_limited and not new_limited then unit_price = new_unit_price + elseif new_limited and not old_limited then + unit_price = old_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, + old_limited or new_limited, }, '#') else aux_merchant_buy[item_id] = Aux.util.join({ new_unit_price, - new_unlimited, + new_limited, }, '#') end end diff --git a/persistence.lua b/persistence.lua index aadfd2c..042ec0b 100644 --- a/persistence.lua +++ b/persistence.lua @@ -12,8 +12,8 @@ function private.get_dataset_key() return private.realm..'|'..private.faction end -function public.blizzard_boolean(bool) - return bool and 1 or nil +function public.blizzard_boolean(boolean) + return boolean and 1 or nil end function public.load_dataset() diff --git a/scan_util.lua b/scan_util.lua index af06b6c..3a5def1 100644 --- a/scan_util.lua +++ b/scan_util.lua @@ -271,6 +271,36 @@ m.filters = { end }, + ['bid-vendor-profit'] = { + arity = 1, + test = function(amount) + amount = Aux.money.from_string(amount or '') or 0 + if amount > 0 then + return function(auction_record) + local vendor_price = Aux.merchant.info(auction_record.item_id) + return vendor_price and vendor_price * auction_record.aux_quantity - auction_record.bid_price >= amount + end + else + return false, {}, 'Erroneous Bid Vendor Profit Modifier' + end + end + }, + + ['buyout-vendor-profit'] = { + arity = 1, + test = function(amount) + amount = Aux.money.from_string(amount or '') or 0 + if amount > 0 then + return function(auction_record) + local vendor_price = Aux.merchant.info(auction_record.item_id) + return vendor_price and vendor_price * auction_record.aux_quantity - auction_record.buyout_price >= amount + end + else + return false, {}, 'Erroneous Buyout Vendor Profit Modifier' + end + end + }, + ['discard'] = { arity = 0, test = function() diff --git a/slash.lua b/slash.lua index 266cd25..7657b95 100644 --- a/slash.lua +++ b/slash.lua @@ -24,6 +24,12 @@ function SlashCmdList.AUX(parameter) elseif parameter == 'tooltip daily' then aux_tooltip_daily = not aux_tooltip_daily Aux.log('Market value in tooltip '..(aux_tooltip_daily and 'enabled' or 'disabled')..'.') + elseif parameter == 'tooltip vendor 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 parameter == 'tooltip vendor 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 parameter == 'tooltip disenchant 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')..'.') diff --git a/tooltip.lua b/tooltip.lua index 91af836..b8e855b 100644 --- a/tooltip.lua +++ b/tooltip.lua @@ -62,7 +62,6 @@ function private.extend_tooltip(tooltip, hyperlink, quantity) 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) @@ -87,6 +86,23 @@ function private.extend_tooltip(tooltip, hyperlink, quantity) end end + if aux_tooltip_vendor_buy then + local color = {r=0.8, g=0.5, b=0.1} + + local _, price, limited = Aux.merchant.info(item_id) + if price then + tooltip:AddLine('Vendor Buy '..(limited and '(limited): ' or ': ')..Aux.util.format_money(price), 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.merchant.info(item_id) + if price then + tooltip:AddLine('Vendor Sell: '..Aux.util.format_money(price), color.r, color.g, color.b) + end + end + local item_key = (item_id or 0)..':'..(suffix_id or 0) local value = Aux.history.value(item_key)