adam@17
|
1 local _, AskMrRobot = ...
|
adam@17
|
2 local L = AskMrRobot.L;
|
adam@17
|
3
|
adam@17
|
4 -- item link format: |cffa335ee|Hitem:itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:upgradeId:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2...|h[item name]|h|r
|
adam@17
|
5
|
adam@17
|
6 -- get an object with all of the parts fo the item link format that we care about
|
adam@17
|
7 function AskMrRobot.parseItemLink(itemLink)
|
adam@17
|
8 if not itemLink then return nil end
|
adam@17
|
9
|
adam@17
|
10 local str = string.match(itemLink, "|Hitem:([\-%d:]+)|")
|
adam@17
|
11 if not str then return nil end
|
adam@17
|
12
|
adam@17
|
13 local parts = { strsplit(":", str) }
|
adam@17
|
14
|
adam@17
|
15 local item = {}
|
adam@17
|
16 item.id = tonumber(parts[1])
|
adam@17
|
17 item.enchantId = tonumber(parts[2])
|
adam@17
|
18 item.gemIds = { tonumber(parts[3]), tonumber(parts[4]), tonumber(parts[5]), tonumber(parts[6]) }
|
adam@17
|
19 item.suffixId = math.abs(tonumber(parts[7])) -- convert suffix to positive number, that's what we use in our code
|
adam@17
|
20 --item.uniqueId = tonumber(parts[8])
|
adam@17
|
21 --item.level = tonumber(parts[9])
|
adam@17
|
22 item.upgradeId = tonumber(parts[10])
|
adam@17
|
23 --item.difficultyId = tonumber(parts[11])
|
adam@17
|
24
|
adam@17
|
25 local numBonuses = tonumber(parts[12])
|
adam@28
|
26 if numBonuses and numBonuses > 0 then
|
adam@17
|
27 item.bonusIds = {}
|
adam@17
|
28 for i = 13, 12 + numBonuses do
|
adam@17
|
29 table.insert(item.bonusIds, tonumber(parts[i]))
|
adam@17
|
30 end
|
yellowfive@39
|
31 table.sort(item.bonusIds)
|
adam@17
|
32 end
|
adam@17
|
33
|
adam@17
|
34 return item
|
adam@17
|
35 end
|
adam@17
|
36
|
yellowfive@31
|
37 -- item link format: |cffa335ee|Hitem:itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:upgradeId:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2...|h[item name]|h|r
|
yellowfive@31
|
38
|
yellowfive@31
|
39 function AskMrRobot.createItemLink(itemObj)
|
yellowfive@31
|
40
|
yellowfive@31
|
41 if itemObj == nil or itemObj.id == nil or itemObj.id == 0 then return nil end
|
yellowfive@31
|
42
|
yellowfive@31
|
43 local parts = {}
|
yellowfive@31
|
44 table.insert(parts, "item")
|
yellowfive@31
|
45 table.insert(parts, itemObj.id)
|
yellowfive@31
|
46 table.insert(parts, itemObj.enchantId)
|
yellowfive@31
|
47 table.insert(parts, itemObj.gemIds[1])
|
yellowfive@31
|
48 table.insert(parts, itemObj.gemIds[2])
|
yellowfive@31
|
49 table.insert(parts, itemObj.gemIds[3])
|
yellowfive@31
|
50 table.insert(parts, itemObj.gemIds[4])
|
yellowfive@33
|
51
|
yellowfive@33
|
52 if itemObj.suffixId == 0 then
|
yellowfive@33
|
53 table.insert(parts, 0)
|
yellowfive@33
|
54 else
|
yellowfive@33
|
55 table.insert(parts, -math.abs(itemObj.suffixId))
|
yellowfive@33
|
56 end
|
yellowfive@33
|
57
|
yellowfive@31
|
58 table.insert(parts, 0)
|
yellowfive@31
|
59 table.insert(parts, UnitLevel("player"))
|
yellowfive@31
|
60 table.insert(parts, itemObj.upgradeId)
|
yellowfive@31
|
61 table.insert(parts, 0)
|
yellowfive@31
|
62
|
yellowfive@31
|
63 if itemObj.bonusIds then
|
yellowfive@31
|
64 table.insert(parts, #itemObj.bonusIds)
|
yellowfive@31
|
65 for i,v in ipairs(itemObj.bonusIds) do
|
yellowfive@31
|
66 table.insert(parts, v)
|
yellowfive@31
|
67 end
|
yellowfive@31
|
68 end
|
yellowfive@31
|
69
|
yellowfive@31
|
70 return table.concat(parts, ":")
|
yellowfive@31
|
71 end
|
yellowfive@31
|
72
|
yellowfive@31
|
73 function AskMrRobot.createGemLink(gemId)
|
yellowfive@31
|
74
|
yellowfive@31
|
75 end
|
yellowfive@31
|
76
|
adam@17
|
77 -- convenience to get just the item id (or 0 if not a valid link) from an item link
|
adam@17
|
78 function AskMrRobot.getItemIdFromLink(itemLink)
|
adam@17
|
79 if not itemLink then return 0 end
|
adam@17
|
80 local parts = { strsplit(":", itemLink) }
|
adam@17
|
81 local id = tonumber(parts[2])
|
adam@17
|
82 return (id and id ~= 0 and id or 0)
|
adam@17
|
83 end
|
adam@17
|
84
|
adam@17
|
85 function AskMrRobot.getItemUniqueId(item, noUpgrade)
|
adam@17
|
86 if item == nil then return "" end
|
adam@17
|
87 local ret = item.id .. ""
|
adam@17
|
88 if item.bonusIds then
|
adam@17
|
89 for i = 1, #item.bonusIds do
|
adam@17
|
90 ret = ret .. "b" .. item.bonusIds[i]
|
adam@17
|
91 end
|
adam@17
|
92 end
|
adam@17
|
93 if item.suffixId ~= 0 then
|
adam@17
|
94 ret = ret .. "s" .. item.suffixId
|
adam@17
|
95 end
|
adam@17
|
96 if not noUpgrade and item.upgradeId ~= 0 then
|
adam@17
|
97 ret = ret .. "u" .. item.upgradeId
|
adam@17
|
98 end
|
adam@17
|
99 return ret
|
adam@17
|
100 end
|
adam@17
|
101
|
adam@17
|
102 AskMrRobot.instanceIds = {
|
adam@17
|
103 HeartOfFear = 1009,
|
adam@17
|
104 MogushanVaults = 1008,
|
adam@17
|
105 SiegeOfOrgrimmar = 1136,
|
adam@17
|
106 TerraceOfEndlessSpring = 996,
|
adam@17
|
107 ThroneOfThunder = 1098
|
adam@17
|
108 }
|
adam@17
|
109
|
adam@17
|
110 -- instances that we currently support logging for
|
adam@17
|
111 AskMrRobot.supportedInstanceIds = {
|
adam@17
|
112 [1136] = true
|
adam@17
|
113 }
|
adam@17
|
114
|
adam@17
|
115 -- returns true if currently in a supported instance
|
adam@17
|
116 function AskMrRobot.IsSupportedInstance()
|
adam@17
|
117
|
adam@17
|
118 local zone, _, difficultyIndex, _, _, _, _, instanceMapID = GetInstanceInfo()
|
adam@17
|
119 if AskMrRobot.supportedInstanceIds[tonumber(instanceMapID)] then
|
adam@17
|
120 return true
|
adam@17
|
121 else
|
adam@17
|
122 return false
|
adam@17
|
123 end
|
adam@17
|
124 end
|
adam@17
|
125
|
adam@17
|
126 AskMrRobot.classIds = {
|
adam@17
|
127 ["NONE"] = 0,
|
adam@17
|
128 ["DEATHKNIGHT"] = 1,
|
adam@17
|
129 ["DRUID"] = 2,
|
adam@17
|
130 ["HUNTER"] = 3,
|
adam@17
|
131 ["MAGE"] = 4,
|
adam@17
|
132 ["MONK"] = 5,
|
adam@17
|
133 ["PALADIN"] = 6,
|
adam@17
|
134 ["PRIEST"] = 7,
|
adam@17
|
135 ["ROGUE"] = 8,
|
adam@17
|
136 ["SHAMAN"] = 9,
|
adam@17
|
137 ["WARLOCK"] = 10,
|
adam@17
|
138 ["WARRIOR"] = 11,
|
adam@17
|
139 }
|
adam@17
|
140
|
adam@17
|
141 AskMrRobot.professionIds = {
|
adam@17
|
142 ["None"] = 0,
|
adam@17
|
143 ["Mining"] = 1,
|
adam@17
|
144 ["Skinning"] = 2,
|
adam@17
|
145 ["Herbalism"] = 3,
|
adam@17
|
146 ["Enchanting"] = 4,
|
adam@17
|
147 ["Jewelcrafting"] = 5,
|
adam@17
|
148 ["Engineering"] = 6,
|
adam@17
|
149 ["Blacksmithing"] = 7,
|
adam@17
|
150 ["Leatherworking"] = 8,
|
adam@17
|
151 ["Inscription"] = 9,
|
adam@17
|
152 ["Tailoring"] = 10,
|
adam@17
|
153 ["Alchemy"] = 11,
|
adam@17
|
154 ["Fishing"] = 12,
|
adam@17
|
155 ["Cooking"] = 13,
|
adam@17
|
156 ["First Aid"] = 14,
|
adam@17
|
157 ["Archaeology"] = 15
|
adam@17
|
158 }
|
adam@17
|
159
|
adam@17
|
160 AskMrRobot.raceIds = {
|
adam@17
|
161 ["None"] = 0,
|
adam@17
|
162 ["BloodElf"] = 1,
|
adam@17
|
163 ["Draenei"] = 2,
|
adam@17
|
164 ["Dwarf"] = 3,
|
adam@17
|
165 ["Gnome"] = 4,
|
adam@17
|
166 ["Human"] = 5,
|
adam@17
|
167 ["NightElf"] = 6,
|
adam@17
|
168 ["Orc"] = 7,
|
adam@17
|
169 ["Tauren"] = 8,
|
adam@17
|
170 ["Troll"] = 9,
|
adam@17
|
171 ["Scourge"] = 10,
|
adam@17
|
172 ["Undead"] = 10,
|
adam@17
|
173 ["Goblin"] = 11,
|
adam@17
|
174 ["Worgen"] = 12,
|
adam@17
|
175 ["Pandaren"] = 13
|
adam@17
|
176 }
|
adam@17
|
177
|
adam@17
|
178 AskMrRobot.factionIds = {
|
adam@17
|
179 ["None"] = 0,
|
adam@17
|
180 ["Alliance"] = 1,
|
adam@17
|
181 ["Horde"] = 2
|
adam@17
|
182 }
|
adam@17
|
183
|
adam@17
|
184 AskMrRobot.specIds = {
|
adam@17
|
185 [250] = 1, -- DeathKnightBlood
|
adam@17
|
186 [251] = 2, -- DeathKnightFrost
|
adam@17
|
187 [252] = 3, -- DeathKnightUnholy
|
adam@17
|
188 [102] = 4, -- DruidBalance
|
adam@17
|
189 [103] = 5, -- DruidFeral
|
adam@17
|
190 [104] = 6, -- DruidGuardian
|
adam@17
|
191 [105] = 7, -- DruidRestoration
|
adam@17
|
192 [253] = 8, -- HunterBeastMastery
|
adam@17
|
193 [254] = 9, -- HunterMarksmanship
|
adam@17
|
194 [255] = 10, -- HunterSurvival
|
adam@17
|
195 [62] = 11, -- MageArcane
|
adam@17
|
196 [63] = 12, -- MageFire
|
adam@17
|
197 [64] = 13, -- MageFrost
|
adam@17
|
198 [268] = 14, -- MonkBrewmaster
|
yellowfive@23
|
199 [270] = 15, -- MonkMistweaver
|
yellowfive@23
|
200 [269] = 16, -- MonkWindwalker
|
adam@17
|
201 [65] = 17, -- PaladinHoly
|
adam@17
|
202 [66] = 18, -- PaladinProtection
|
adam@17
|
203 [70] = 19, -- PaladinRetribution
|
adam@17
|
204 [256] = 20, -- PriestDiscipline
|
adam@17
|
205 [257] = 21, -- PriestHoly
|
adam@17
|
206 [258] = 22, -- PriestShadow
|
adam@17
|
207 [259] = 23, -- RogueAssassination
|
adam@17
|
208 [260] = 24, -- RogueCombat
|
adam@17
|
209 [261] = 25, -- RogueSubtlety
|
adam@17
|
210 [262] = 26, -- ShamanElemental
|
adam@17
|
211 [263] = 27, -- ShamanEnhancement
|
adam@17
|
212 [264] = 28, -- ShamanRestoration
|
adam@17
|
213 [265] = 29, -- WarlockAffliction
|
adam@17
|
214 [266] = 30, -- WarlockDemonology
|
adam@17
|
215 [267] = 31, -- WarlockDestruction
|
adam@17
|
216 [71] = 32, -- WarriorArms
|
adam@17
|
217 [72] = 33, -- WarriorFury
|
adam@17
|
218 [73] = 34 -- WarriorProtection
|
adam@17
|
219 }
|
adam@17
|
220
|
adam@17
|
221 -- reverse map of our spec ID to the game's spec ID
|
adam@17
|
222 AskMrRobot.gameSpecIds = {}
|
adam@17
|
223 for k,v in pairs(AskMrRobot.specIds) do
|
adam@17
|
224 AskMrRobot.gameSpecIds[v] = k
|
adam@17
|
225 end
|
adam@17
|
226
|
adam@17
|
227 -- lookup from our socket color ID to string
|
adam@17
|
228 AskMrRobot.socketColorIds = {
|
adam@17
|
229 [0] = "Prismatic",
|
adam@17
|
230 [1] = "Red",
|
adam@17
|
231 [2] = "Yellow",
|
adam@17
|
232 [3] = "Blue",
|
adam@17
|
233 [4] = "Meta",
|
adam@17
|
234 [5] = "Cogwheel",
|
adam@17
|
235 [6] = "ShaTouched"
|
adam@17
|
236 }
|
adam@17
|
237
|
adam@17
|
238 -- map of game slot names to slot IDs (same both in our code and in-game)
|
adam@17
|
239 AskMrRobot.slotNameToId = {
|
adam@17
|
240 ["HeadSlot"] = 1,
|
adam@17
|
241 ["NeckSlot"] = 2,
|
adam@17
|
242 ["ShoulderSlot"] = 3,
|
adam@17
|
243 ["ChestSlot"] = 5,
|
adam@17
|
244 ["WaistSlot"] = 6,
|
adam@17
|
245 ["LegsSlot"] = 7,
|
adam@17
|
246 ["FeetSlot"] = 8,
|
adam@17
|
247 ["WristSlot"] = 9,
|
adam@17
|
248 ["HandsSlot"] = 10,
|
adam@17
|
249 ["Finger0Slot"] = 11,
|
adam@17
|
250 ["Finger1Slot"] = 12,
|
adam@17
|
251 ["Trinket0Slot"] = 13,
|
adam@17
|
252 ["Trinket1Slot"] = 14,
|
adam@17
|
253 ["BackSlot"] = 15,
|
adam@17
|
254 ["MainHandSlot"] = 16,
|
adam@17
|
255 ["SecondaryHandSlot"] = 17
|
adam@17
|
256 }
|
adam@17
|
257
|
adam@17
|
258 -- map of slot ID to display text
|
adam@17
|
259 AskMrRobot.slotDisplayText = {
|
adam@17
|
260 [1] = _G["HEADSLOT"],
|
adam@17
|
261 [2] = _G["NECKSLOT"],
|
adam@17
|
262 [3] = _G["SHOULDERSLOT"],
|
adam@17
|
263 [5] = _G["CHESTSLOT"],
|
adam@17
|
264 [6] = _G["WAISTSLOT"],
|
adam@17
|
265 [7] = _G["LEGSSLOT"],
|
adam@17
|
266 [8] = _G["FEETSLOT"],
|
yellowfive@31
|
267 [9] = _G["WRISTSLOT"],
|
adam@17
|
268 [10] = _G["HANDSSLOT"],
|
yellowfive@31
|
269 [11] = _G["FINGER0SLOT"] .. " 1",
|
yellowfive@31
|
270 [12] = _G["FINGER1SLOT"] .. " 2",
|
yellowfive@31
|
271 [13] = _G["TRINKET0SLOT"] .. " 1",
|
yellowfive@31
|
272 [14] = _G["TRINKET1SLOT"] .. " 2",
|
adam@17
|
273 [15] = _G["BACKSLOT"],
|
adam@17
|
274 [16] = _G["MAINHANDSLOT"],
|
adam@17
|
275 [17] = _G["SECONDARYHANDSLOT"]
|
adam@17
|
276 }
|
adam@17
|
277
|
adam@17
|
278 -- all slot IDs that we care about, ordered in our standard display order
|
adam@17
|
279 AskMrRobot.slotIds = { 16, 17, 1, 2, 3, 15, 5, 9, 10, 6, 7, 8, 11, 12, 13, 14 }
|
adam@17
|
280
|
adam@17
|
281 -- cache slot orders to make slot sorting easier
|
adam@17
|
282 local _slotIdToOrder = {}
|
adam@17
|
283 for i = 1, #AskMrRobot.slotIds do
|
adam@17
|
284 _slotIdToOrder[AskMrRobot.slotIds[i]] = i
|
adam@17
|
285 end
|
adam@17
|
286
|
adam@17
|
287 -- given a table where the keys are slot IDs, sort in the standard slot order
|
adam@17
|
288 function AskMrRobot.sortSlots(t)
|
adam@17
|
289 return AskMrRobot.spairs(t, function(x, a, b)
|
adam@17
|
290 if a == nil and b == nil then return 0 end
|
adam@17
|
291 return _slotIdToOrder[a] < _slotIdToOrder[b]
|
adam@17
|
292 end)
|
adam@17
|
293 end
|