95 lignes
2.6 KiB
Lua
95 lignes
2.6 KiB
Lua
|
|
local GetTime = QuestHelper_GetTime
|
|
|
|
QuestHelper_File["collect_merchant.lua"] = "4.0.1.$svnversion$"
|
|
QuestHelper_Loadtime["collect_merchant.lua"] = GetTime()
|
|
|
|
-- http://www.penny-arcade.com/comic/2005/01/05/
|
|
|
|
local debug_output = false
|
|
if QuestHelper_File["collect_merchant.lua"] == "Development Version" then debug_output = true end
|
|
|
|
local QHCM
|
|
|
|
local IsMonsterGUID
|
|
local GetMonsterType
|
|
local GetItemType
|
|
|
|
local function AddChatType(typ)
|
|
local target = UnitGUID("target")
|
|
if not target then return end
|
|
|
|
if not IsMonsterGUID(target) then return end
|
|
|
|
target = GetMonsterType(target)
|
|
|
|
local ret = {}
|
|
ret.base_info = string.format("%d\t%s", target, typ)
|
|
table.insert(QHCM, ret)
|
|
return ret
|
|
end
|
|
|
|
local function MerchantShow()
|
|
local ct = GetMerchantNumItems()
|
|
for i = 1, ct do if not GetMerchantItemLink(i) then return end end -- We want to make sure it's cached, otherwise we'll return wonky data. Technically this biases things away from "yes he's a shopkeeper", but honestly, it doesn't matter that much.
|
|
|
|
targ = AddChatType("shop")
|
|
if not targ then return end -- welllllp
|
|
|
|
local ct = GetMerchantNumItems()
|
|
--QuestHelper:TextOut(string.format("nitems %d", ct))
|
|
|
|
for i = 1, ct do
|
|
local itemid = GetMerchantItemLink(i)
|
|
QuestHelper: Assert(itemid)
|
|
itemid = GetItemType(itemid)
|
|
local _, _, price, quant, avail, _, ext_cost = GetMerchantItemInfo(i)
|
|
local shop_item = {}
|
|
shop_item.base_info = string.format("%d\t%d\t%d\t%d", itemid, quant, avail, price)
|
|
|
|
if ext_cost then
|
|
ext_costs = {}
|
|
for curr = 1, GetMerchantItemCostInfo(i) do
|
|
local tex, val, link, name = GetMerchantItemCostItem(i, curr)
|
|
local ext_cost_detail = {}
|
|
ext_cost_detail.base_info = string.format("%s\t%d", name, val)
|
|
ext_cost_detail.link = link
|
|
ext_cost_detail.texture = tex
|
|
table.insert(ext_costs, ext_cost_detail)
|
|
end
|
|
|
|
shop_item.ext_costs = ext_costs
|
|
end
|
|
|
|
--if debug_output then QuestHelper:TextOut(dstr) end
|
|
if not targ.shop then targ.shop = {} end
|
|
|
|
table.insert(targ.shop, shop_item)
|
|
end
|
|
end
|
|
|
|
local function GossipShow()
|
|
AddChatType("talk")
|
|
end
|
|
|
|
local function QuestGreeting()
|
|
AddChatType("quest")
|
|
end
|
|
|
|
|
|
function QH_Collect_Merchant_Init(QHCData, API)
|
|
if not QHCData.merchant then QHCData.merchant = {} end
|
|
QHCM = QHCData.merchant
|
|
|
|
QH_Event("MERCHANT_SHOW", MerchantShow)
|
|
QH_Event("GOSSIP_SHOW", GossipShow)
|
|
QH_Event("QUEST_GREETING", QuestGreeting)
|
|
|
|
IsMonsterGUID = API.Utility_IsMonsterGUID
|
|
GetMonsterType = API.Utility_GetMonsterType
|
|
GetItemType = API.Utility_GetItemType
|
|
QuestHelper: Assert(IsMonsterGUID)
|
|
QuestHelper: Assert(GetMonsterType)
|
|
QuestHelper: Assert(GetItemType)
|
|
end
|