-
Notifications
You must be signed in to change notification settings - Fork 6
/
TradeskillInfo.lua
311 lines (289 loc) · 10.6 KB
/
TradeskillInfo.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
local addonName,addonTable = ...
local DA = LibStub("AceAddon-3.0"):GetAddon("Skillet") -- for DebugAids.lua
--[[
Skillet: A tradeskill window replacement.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]--
-- This file contains code used to access recipe/tradeskill information
--[[
--
-- GetItemInfo(item)
-- item can be: itemID or "itemString" or "itemName" or "itemLink"
--
1. itemName
String - The localized name of the item.
2. itemLink
String - The localized item link of the item.
3. itemRarity
Number - The quality of the item. The value is 0 to 7, which represents Poor to Heirloom. This appears to include gains from upgrades/bonuses.
4. itemLevel
Number - The base item level of this item, not including item levels gained from upgrades. Use GetDetailedItemLevelInfo to get the actual current level of the item.
5. itemMinLevel
Number - The minimum level required to use the item, 0 meaning no level requirement.
6. itemType
String - The localized type of the item: Armor, Weapon, Quest, Key, etc.
7. itemSubType
String - The localized sub-type of the item: Enchanting, Cloth, Sword, etc. See itemType.
8. itemStackCount
Number - How many of the item per stack: 20 for Runecloth, 1 for weapon, 100 for Alterac Ram Hide, etc.
9. itemEquipLoc
String - The type of inventory equipment location in which the item may be equipped, or "" if it can't be equippable. The string returned is also the name of a global string variable e.g. if "INVTYPE_WEAPONMAINHAND" is returned, _G["INVTYPE_WEAPONMAINHAND"] will be the localized, displayable name of the location.
10. itemIcon
Number (fileID) - The icon texture for the item.
11. itemSellPrice
Number - The price, in copper, a vendor is willing to pay for this item, 0 for items that cannot be sold.
12. itemClassID
Number - This is the numerical value that determines the string to display for 'itemType'.
13. itemSubClassID
Number - This is the numerical value that determines the string to display for 'itemSubType'
14. bindType
Number - Item binding type: 0 - none; 1 - on pickup; 2 - on equip; 3 - on use; 4 - quest.
15. expacID
Number - ?
16. itemSetID
Number - ?
17. isCraftingReagent
Boolean - ?
]]--
--
-- If an item requires a specific level before it can be used, then
-- the level is returned, otherwise 0 is returned
--
function Skillet:GetLevelRequiredToUse(item)
if not item then return end
-- local level = select(5, GetItemInfo(item))
-- if not level then level = 0 end
-- return level
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount,
itemEquipLoc, itemIcon, itemSellPrice, itemClassID, itemSubClassID, bindType, expacID, itemSetID,
isCraftingReagent = GetItemInfo(item)
--
-- is the return value OK?
--
if not itemMinLevel then itemMinLevel = 0 end
return itemMinLevel
end
--
-- If an item has an item level, then it
-- is returned, otherwise 0 is returned
--
function Skillet:GetItemLevel(item)
if not item then return end
-- local level = select(4, GetItemInfo(item))
-- if not level then level = 0 end
-- return level
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount,
itemEquipLoc, itemIcon, itemSellPrice, itemClassID, itemSubClassID, bindType, expacID, itemSetID,
isCraftingReagent = GetItemInfo(item)
--
-- is the return value OK?
--
if not itemLevel then itemLevel = 0 end
if type(itemLevel) ~= "number" then
DA.DEBUG(0,"GetItemLevel("..tostring(item)..")= "..tostring(itemLevel))
itemLevel = 0
end
return itemLevel
end
function Skillet:GetItemIDFromLink(link) -- works with items or enchants
--DA.DEBUG(3,"GetItemIDFromLink("..tostring(DA.PLINK(link))..")")
if (link) then
local linktype, id = string.match(link, "|H([^:]+):(%d+)")
--DA.DEBUG(3,"linktype= "..tostring(linktype)..", id= "..tostring(id))
if id then
return tonumber(id), tostring(linktype)
end
end
end
--
-- Checks a link and returns the level of the that item's quality. If the link is
-- invalid, or not item quality could be found, nil is returned.
--
-- Handy info: _G["ITEM_QUALITY" .. level .. "_DESC"] returns "Epic", etc (localized)
--
-- @return
-- level: from 0 (Poor) to 6 (Artifact).
-- r, g, b: color code for the items color
-- hex: hexidecimal representation of the string, as well as "|c" in the beginning.
--
function Skillet:GetQualityFromLink(link)
if (not link) then return end
local color = link:match("(|c%x+)|Hitem:%p?%d+:%p?%d+:%p?%d+:%p?%d+:%p?%d+:%p?%d+:%p?%d+:%p?%d+|h%[.-%]|h|r")
if (color) then
for i = 0, 6 do
local r, g, b, hex = GetItemQualityColor(i)
if color == hex then
-- found it
return i, r, g, b, hex
end
end
end
--
-- no match
--
end
--
-- Returns the name of the current trade skill
--
function Skillet:GetTradeName(tradeID)
--DA.DEBUG(2,"GetTradeName("..tostring(tradeID)..")")
local tradeNameT,tradeNameS
tradeNameT = Skillet.tradeSkillNamesByID[tradeID]
tradeNameS = GetSpellInfo(tradeID)
--DA.DEBUG(2,"tradeNameT= "..tostring(tradeNameT)..", tradeNameS= "..tostring(tradeNameS))
if not tradeNameT then
return tradeNameS
end
return tradeNameT
end
--
-- Returns a link for the currently selected tradeskill item.
-- The input is an index into the currently selected tradeskill
-- or craft.
--
function Skillet:GetTradeSkillItemLink(index)
--DA.DEBUG(2,"GetTradeSkillItemLink("..tostring(index)..") currentTrade= "..tostring(self.currentTrade))
local recipe, recipeID = self:GetRecipeDataByTradeIndex(self.currentTrade, index)
local _, link
if recipe then
if self.isCraft then
link = GetCraftItemLink(index)
elseif self.currentTrade == 7411 and recipe.itemID == 0 then
if Skillet.db.profile.enchant_scrolls and recipe.scrollID then
_, link = GetItemInfo(recipe.scrollID)
else
link = GetTradeSkillRecipeLink(index)
end
else
_, link = GetItemInfo(recipe.itemID)
end
return link
end
return nil
end
function Skillet:GetNumTradeSkills(tradeOverride, playerOverride)
local tradeID = tradeOverride or self.currentTrade
local player = playerOverride or self.currentPlayer
local numSkills = #self.db.realm.skillDB[playerOverride][tradeID]
return numSkills
end
function Skillet:GetTradeSkillCooldown(skillIndex)
local skill = self.GetSkill(self.currentPlayer, self.currentTrade, skillIndex)
if skill then
local coolDown = skill.cooldown
local now = GetTime()
if coolDown then
return math.max(0,coolDown - now)
end
end
end
function Skillet:GetTradeSkillNumReagents(skillIndex)
local recipe = self:GetRecipeDataByTradeIndex(self.currentTrade, skillIndex)
if recipe then
return #recipe.reagentData
end
end
function Skillet:GetTradeSkillReagentInfo(skillIndex, reagentIndex)
local recipe = self:GetRecipeDataByTradeIndex(self.currentTrade, skillIndex)
if recipe then
local reagentID = recipe.reagentData[reagentIndex].id
local reagentName = GetItemInfo(reagentID)
local reagentTexture = GetItemIcon(reagentID)
local reagentCount = recipe.reagentData[reagentIndex].numNeeded
local playerReagentCount = self:GetInventory(reagentID)
return reagentName, reagentTexture, reagentCount, playerReagentCount
end
end
--
-- Returns a link for the reagent required to create the specified
-- item, the index'th reagent required for the item is returned
--
function Skillet:GetTradeSkillReagentItemLink(skillIndex, index)
--DA.DEBUG(2,"GetTradeSkillReagentItemLink("..tostring(skillIndex)..", "..tostring(index)..") currentTrade= "..tostring(self.currentTrade))
if skillIndex and index then
local recipe = self:GetRecipeDataByTradeIndex(self.currentTrade, skillIndex)
if recipe and recipe.reagentData[index] then
local _, link = GetItemInfo(recipe.reagentData[index].id)
return link
end
end
return nil
end
function Skillet:GetTradeSkillTools(skillIndex)
local skill = self:GetSkill(self.currentPlayer, self.currentTrade, skillIndex)
if skill then
local recipe = self:GetRecipe(skill.id)
local toolList = {}
for i=1,#recipe.tools do
toolList[i*2-1] = recipe.tools[i]
toolList[i*2 ] = skill.tools[i] or 1
end
return unpack(toolList)
end
end
function Skillet:ExpandTradeSkillSubClass(skillIndex)
end
--
-- Gets the trade skill line, and knows how to do the right
-- thing depending on whether or not this is a craft.
--
function Skillet:GetTradeSkillLine()
DA.DEBUG(0,"GetTradeSkillLine(), currentTrade= "..tostring(self.currentTrade))
if self.currentTrade then
local tradeName = GetSpellInfo(self.currentTrade)
local ranks = self:GetSkillRanks(self.currentPlayer, self.currentTrade)
local rank, maxRank
if ranks then
rank, maxRank = ranks.rank, ranks.maxRank
else
rank, maxRank = 0, 0
end
DA.DEBUG(0,"GetTradeSkillLine= "..tostring(tradeName)..", "..tostring(rank)..", "..tostring(maxRank))
return tradeName, rank, maxRank
else
return nil, nil, nil
end
end
--
-- Returns the number of trade or craft skills
--
function Skillet:GetNumTradeSkills()
return self:GetNumSkills(self.currentPlayer, self.currentTrade)
end
function Skillet:GetTradeSkillCooldown(index)
local skill = self:GetSkill(self.currentPlayer, self.currentTrade, index)
if skill and skill.cooldown then
local cooldown = skill.cooldown - GetTime()
if cooldown > 0 then
return cooldown
end
end
end
function Skillet:GetTradeSkillIcon(skillIndex)
local recipe = self:GetRecipeDataByTradeIndex(self.currentTrade, skillIndex)
local texture
if recipe then
if recipe.numMade > 0 then
texture = GetItemIcon(recipe.itemID) -- get the item texture
else
texture = "Interface\\Icons\\Spell_Holy_GreaterHeal" -- standard enchant icon
end
end
return texture or "Interface\\Icons\\INV_Misc_QuestionMark"
end
function Skillet:GetTradeSkillNumMade(skillIndex)
local recipe = self:GetRecipeDataByTradeIndex(self.currentTrade, skillIndex)
if recipe then
return recipe.numMade, recipe.numMade
end
return 1,1
end