-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVendorPrice.lua
205 lines (189 loc) · 6.13 KB
/
VendorPrice.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
VendorPrice = {}
local VP = VendorPrice
VP.isVanilla = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
VP.isCata = WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC
if not VP.isVanilla and not VP.isCata then
return
end
local GetItemInfo = GetItemInfo or C_Item.GetItemInfo
local SELL_PRICE_TEXT = format("%s:", SELL_PRICE)
local overridePrice
local CharacterBags = {}
-- CONTAINER_BAG_OFFSET is 19 on classic and 30 on retail
-- but classic uses slot 31 to 34 for bags
for i = 31, 34 do
CharacterBags[i] = true
end
local firstBankBag = C_Container.ContainerIDToInventoryID(NUM_BAG_SLOTS + 1)
local lastBankBag = C_Container.ContainerIDToInventoryID(NUM_BAG_SLOTS + NUM_BANKBAGSLOTS)
for i = firstBankBag, lastBankBag do
CharacterBags[i] = true
end
local FIRST_KEYRING_INVSLOT = 107
local function IsMerchant(tt)
if MerchantFrame:IsShown() then
local name = tt:GetOwner():GetName()
if name then
return not (name:find("Character") or name:find("TradeSkill"))
end
end
end
-- source was only really used for auctionator
local function ShouldShowPrice(tt, source)
return not IsMerchant(tt)
end
-- OnTooltipSetItem fires twice for recipes
local function CheckRecipe(tt, classID, isOnTooltipSetItem)
if classID == Enum.ItemClass.Recipe and isOnTooltipSetItem then
tt.isFirstMoneyLine = not tt.isFirstMoneyLine
return tt.isFirstMoneyLine
end
end
-- modify the tooltip when pressing shift, has a small delay
local _SetTooltipMoney = SetTooltipMoney
function SetTooltipMoney(frame, money, ...)
if IsShiftKeyDown() and overridePrice then
_SetTooltipMoney(frame, overridePrice, ...)
else
_SetTooltipMoney(frame, money, ...)
overridePrice = nil
end
end
GameTooltip:HookScript("OnHide", function()
overridePrice = nil
end)
function VP:SetPrice(tt, hasCataTooltip, source, count, item, isOnTooltipSetItem)
if ShouldShowPrice(tt, source) then
count = count or 1
item = item or select(2, tt:GetItem())
if item then
local sellPrice, classID = select(11, GetItemInfo(item))
if sellPrice and sellPrice > 0 and not CheckRecipe(tt, classID, isOnTooltipSetItem) then
local isShift = IsShiftKeyDown() and count > 1
local displayPrice = isShift and sellPrice or sellPrice * count
if self.isVanilla then
SetTooltipMoney(tt, displayPrice, nil, SELL_PRICE_TEXT)
elseif self.isCata then
if hasCataTooltip then
if isShift then
overridePrice = displayPrice
end
else
SetTooltipMoney(tt, displayPrice, nil, SELL_PRICE_TEXT)
end
end
tt:Show()
end
end
end
end
local SetItem = {
SetAction = function(tt, slot)
if GetActionInfo(slot) == "item" then
VP:SetPrice(tt, true, "SetAction", GetActionCount(slot))
end
end,
SetAuctionItem = function(tt, auctionType, index)
local _, _, count = GetAuctionItemInfo(auctionType, index)
VP:SetPrice(tt, false, "SetAuctionItem", count)
end,
SetAuctionSellItem = function(tt)
local _, _, count = GetAuctionSellItemInfo()
VP:SetPrice(tt, true, "SetAuctionSellItem", count)
end,
SetBagItem = function(tt, bag, slot)
local info = C_Container.GetContainerItemInfo(bag, slot)
if info and info.stackCount then
VP:SetPrice(tt, true, "SetBagItem", info.stackCount)
end
end,
--SetBagItemChild
--SetBuybackItem -- already shown
--SetCompareItem
SetCraftItem = function(tt, index, reagent)
local _, _, count = GetCraftReagentInfo(index, reagent)
-- otherwise returns an empty link
local itemLink = GetCraftReagentItemLink(index, reagent)
VP:SetPrice(tt, true, "SetCraftItem", count, itemLink)
end,
SetCraftSpell = function(tt)
VP:SetPrice(tt, true, "SetCraftSpell")
end,
--SetHyperlink -- item information is not readily available
SetInboxItem = function(tt, messageIndex, attachIndex)
local count, itemID
if attachIndex then
count = select(4, GetInboxItem(messageIndex, attachIndex))
else
count, itemID = select(14, GetInboxHeaderInfo(messageIndex))
end
VP:SetPrice(tt, false, "SetInboxItem", count, itemID)
end,
SetInventoryItem = function(tt, unit, slot)
local count
if not CharacterBags[slot] then
count = GetInventoryItemCount(unit, slot)
end
if slot < FIRST_KEYRING_INVSLOT then
VP:SetPrice(tt, VP:IsShown(BankFrame), "SetInventoryItem", count)
end
end,
--SetInventoryItemByID
--SetItemByID
SetLootItem = function(tt, slot)
local _, _, count = GetLootSlotInfo(slot)
VP:SetPrice(tt, false, "SetLootItem", count)
end,
SetLootRollItem = function(tt, rollID)
local _, _, count = GetLootRollItemInfo(rollID)
VP:SetPrice(tt, false, "SetLootRollItem", count)
end,
--SetMerchantCostItem -- alternate currency
--SetMerchantItem -- already shown
SetQuestItem = function(tt, questType, index)
local _, _, count = GetQuestItemInfo(questType, index)
VP:SetPrice(tt, false, "SetQuestItem", count)
end,
SetQuestLogItem = function(tt, _, index)
local _, _, count = GetQuestLogRewardInfo(index)
VP:SetPrice(tt, false, "SetQuestLogItem", count)
end,
--SetRecipeReagentItem -- retail
--SetRecipeResultItem -- retail
SetSendMailItem = function(tt, index)
local count = select(4, GetSendMailItem(index))
VP:SetPrice(tt, true, "SetSendMailItem", count)
end,
SetTradePlayerItem = function(tt, index)
local _, _, count = GetTradePlayerItemInfo(index)
VP:SetPrice(tt, true, "SetTradePlayerItem", count)
end,
SetTradeSkillItem = function(tt, index, reagent)
local count
if reagent then
count = select(3, GetTradeSkillReagentInfo(index, reagent))
else -- show minimum instead of maximum count
count = GetTradeSkillNumMade(index)
end
VP:SetPrice(tt, false, "SetTradeSkillItem", count)
end,
SetTradeTargetItem = function(tt, index)
local _, _, count = GetTradeTargetItemInfo(index)
VP:SetPrice(tt, false, "SetTradeTargetItem", count)
end,
SetTrainerService = function(tt, index)
VP:SetPrice(tt, true, "SetTrainerService")
end,
}
for method, func in pairs(SetItem) do
hooksecurefunc(GameTooltip, method, func)
end
ItemRefTooltip:HookScript("OnTooltipSetItem", function(tt)
local item = select(2, tt:GetItem())
if item then
local sellPrice, classID = select(11, GetItemInfo(item))
if sellPrice and sellPrice > 0 and not CheckRecipe(tt, classID, true) then
SetTooltipMoney(tt, sellPrice, nil, SELL_PRICE_TEXT)
end
end
end)