-
Notifications
You must be signed in to change notification settings - Fork 5
/
MerchantUtil.lua
62 lines (57 loc) · 2.3 KB
/
MerchantUtil.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---@class RemixGemHelperPrivate
local Private = select(2, ...)
local const = Private.constants
local addon = Private.Addon
local merchantUtil = {}
Private.MerchantUtil = merchantUtil
---@param lines table
---@return string
function merchantUtil:GetRestriction(lines)
for _, lineData in ipairs(lines) do
if const.MERCHANT_RESTRICTIONS[lineData.type] then
return const.MERCHANT_RESTRICTIONS[lineData.type]
end
end
return "NONE"
end
function merchantUtil:GetMerchantItems()
local items = {}
for itemIndex = 1, GetMerchantNumItems() do
local _, itemIcon, itemCopperCost = GetMerchantItemInfo(itemIndex)
local itemInfo = C_TooltipInfo.GetMerchantItem(itemIndex)
if itemInfo then
local restriction = self:GetRestriction(itemInfo.lines)
if not items[restriction] then items[restriction] = {} end
local itemCost = {}
if itemCopperCost > 0 then
tinsert(itemCost, {
type = "MONEY",
value = itemCopperCost,
})
if not items[restriction].cost then items[restriction].cost = {} end
if not items[restriction].cost["MONEY"] then items[restriction].cost["MONEY"] = 0 end
items[restriction].cost["MONEY"] = items[restriction].cost["MONEY"] + itemCopperCost
end
for costIndex = 1, GetMerchantItemCostInfo(itemIndex) do
local costIcon, costValue, costLink = GetMerchantItemCostItem(itemIndex, costIndex)
tinsert(itemCost, {
type = "CURRENCY",
icon = costIcon,
link = costLink,
value = costValue
})
if costIcon then
if not items[restriction].cost then items[restriction].cost = {} end
if not items[restriction].cost[costIcon] then items[restriction].cost[costIcon] = 0 end
items[restriction].cost[costIcon] = items[restriction].cost[costIcon] + costValue
end
end
tinsert(items[restriction], {
icon = itemIcon,
link = itemInfo.hyperlink,
costInfo = itemCost,
})
end
end
return items
end