jcallahan@0
|
1 -----------------------------------------------------------------------
|
jcallahan@0
|
2 -- Upvalued Lua API.
|
jcallahan@0
|
3 -----------------------------------------------------------------------
|
jcallahan@0
|
4 local _G = getfenv(0)
|
jcallahan@0
|
5
|
jcallahan@0
|
6 local pairs = _G.pairs
|
jcallahan@1
|
7 local tonumber = _G.tonumber
|
jcallahan@1
|
8
|
jcallahan@1
|
9 local bit = _G.bit
|
jcallahan@1
|
10 local math = _G.math
|
jcallahan@1
|
11 local table = _G.table
|
jcallahan@1
|
12
|
jcallahan@0
|
13
|
jcallahan@0
|
14 -----------------------------------------------------------------------
|
jcallahan@0
|
15 -- AddOn namespace.
|
jcallahan@0
|
16 -----------------------------------------------------------------------
|
jcallahan@0
|
17 local ADDON_NAME, private = ...
|
jcallahan@0
|
18
|
jcallahan@0
|
19 local LibStub = _G.LibStub
|
jcallahan@0
|
20 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceTimer-3.0")
|
jcallahan@0
|
21
|
jcallahan@4
|
22 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
|
jcallahan@5
|
23 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
|
jcallahan@5
|
24
|
jcallahan@0
|
25
|
jcallahan@0
|
26 -----------------------------------------------------------------------
|
jcallahan@0
|
27 -- Local constants.
|
jcallahan@0
|
28 -----------------------------------------------------------------------
|
jcallahan@0
|
29 local DATABASE_DEFAULTS = {
|
jcallahan@0
|
30 global = {
|
jcallahan@0
|
31 items = {},
|
jcallahan@0
|
32 npcs = {},
|
jcallahan@0
|
33 objects = {},
|
jcallahan@0
|
34 quests = {},
|
jcallahan@17
|
35 zones = {},
|
jcallahan@0
|
36 }
|
jcallahan@0
|
37 }
|
jcallahan@0
|
38
|
jcallahan@0
|
39
|
jcallahan@1
|
40 local EVENT_MAPPING = {
|
jcallahan@18
|
41 COMBAT_TEXT_UPDATE = true,
|
jcallahan@13
|
42 LOOT_CLOSED = true,
|
jcallahan@1
|
43 LOOT_OPENED = true,
|
jcallahan@7
|
44 MERCHANT_SHOW = "UpdateMerchantItems",
|
jcallahan@7
|
45 MERCHANT_UPDATE = "UpdateMerchantItems",
|
jcallahan@2
|
46 PLAYER_TARGET_CHANGED = true,
|
jcallahan@9
|
47 QUEST_COMPLETE = true,
|
jcallahan@9
|
48 QUEST_DETAIL = true,
|
jcallahan@9
|
49 QUEST_LOG_UPDATE = true,
|
jcallahan@4
|
50 UNIT_QUEST_LOG_CHANGED = true,
|
jcallahan@1
|
51 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
|
jcallahan@1
|
52 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
|
jcallahan@1
|
53 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
|
jcallahan@1
|
54 UNIT_SPELLCAST_SENT = true,
|
jcallahan@1
|
55 UNIT_SPELLCAST_SUCCEEDED = true,
|
jcallahan@0
|
56 }
|
jcallahan@0
|
57
|
jcallahan@4
|
58
|
jcallahan@1
|
59 local AF = private.ACTION_TYPE_FLAGS
|
jcallahan@0
|
60
|
jcallahan@4
|
61
|
jcallahan@0
|
62 -----------------------------------------------------------------------
|
jcallahan@0
|
63 -- Local variables.
|
jcallahan@0
|
64 -----------------------------------------------------------------------
|
jcallahan@0
|
65 local db
|
jcallahan@0
|
66 local durability_timer_handle
|
jcallahan@2
|
67 local target_location_timer_handle
|
jcallahan@1
|
68 local action_data = {}
|
jcallahan@0
|
69
|
jcallahan@1
|
70
|
jcallahan@1
|
71 -----------------------------------------------------------------------
|
jcallahan@1
|
72 -- Helper Functions.
|
jcallahan@1
|
73 -----------------------------------------------------------------------
|
jcallahan@10
|
74 local function UnitEntry(unit_type, unit_id)
|
jcallahan@10
|
75 if not unit_type or not unit_id then
|
jcallahan@6
|
76 return
|
jcallahan@6
|
77 end
|
jcallahan@10
|
78 local unit = db[unit_type][unit_id]
|
jcallahan@6
|
79
|
jcallahan@10
|
80 if not unit then
|
jcallahan@10
|
81 db[unit_type][unit_id] = {}
|
jcallahan@10
|
82 unit = db[unit_type][unit_id]
|
jcallahan@6
|
83 end
|
jcallahan@10
|
84 return unit
|
jcallahan@6
|
85 end
|
jcallahan@6
|
86
|
jcallahan@6
|
87
|
jcallahan@1
|
88 local function CurrentLocationData()
|
jcallahan@1
|
89 local map_level = _G.GetCurrentMapDungeonLevel() or 0
|
jcallahan@1
|
90 local x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
91
|
jcallahan@1
|
92 x = x or 0
|
jcallahan@1
|
93 y = y or 0
|
jcallahan@1
|
94
|
jcallahan@1
|
95 if x == 0 and y == 0 then
|
jcallahan@1
|
96 for level_index = 1, _G.GetNumDungeonMapLevels() do
|
jcallahan@1
|
97 _G.SetDungeonMapLevel(level_index)
|
jcallahan@1
|
98 x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
99
|
jcallahan@1
|
100 if x and y and (x > 0 or y > 0) then
|
jcallahan@1
|
101 _G.SetDungeonMapLevel(map_level)
|
jcallahan@1
|
102 map_level = level_index
|
jcallahan@1
|
103 break
|
jcallahan@1
|
104 end
|
jcallahan@1
|
105 end
|
jcallahan@1
|
106 end
|
jcallahan@1
|
107
|
jcallahan@1
|
108 if _G.DungeonUsesTerrainMap() then
|
jcallahan@1
|
109 map_level = map_level - 1
|
jcallahan@1
|
110 end
|
jcallahan@8
|
111 local _, instance_type = _G.IsInInstance()
|
jcallahan@8
|
112 return _G.GetRealZoneText(), ("%.2f"):format(x * 100), ("%.2f"):format(y * 100), map_level or 0, instance_type:upper()
|
jcallahan@1
|
113 end
|
jcallahan@1
|
114
|
jcallahan@1
|
115
|
jcallahan@1
|
116 local function ItemLinkToID(item_link)
|
jcallahan@1
|
117 if not item_link then
|
jcallahan@1
|
118 return
|
jcallahan@1
|
119 end
|
jcallahan@7
|
120 return tonumber(item_link:match("item:(%d+)"))
|
jcallahan@1
|
121 end
|
jcallahan@0
|
122
|
jcallahan@4
|
123
|
jcallahan@4
|
124 do
|
jcallahan@4
|
125 local UNIT_TYPE_BITMASK = 0x007
|
jcallahan@4
|
126
|
jcallahan@4
|
127 function WDP:ParseGUID(guid)
|
jcallahan@5
|
128 if not guid then
|
jcallahan@5
|
129 return
|
jcallahan@5
|
130 end
|
jcallahan@4
|
131 local types = private.UNIT_TYPES
|
jcallahan@4
|
132 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
|
jcallahan@4
|
133
|
jcallahan@10
|
134 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
|
jcallahan@4
|
135 return unit_type, tonumber(guid:sub(-12, -9), 16)
|
jcallahan@4
|
136 end
|
jcallahan@4
|
137
|
jcallahan@4
|
138 return unit_type
|
jcallahan@4
|
139 end
|
jcallahan@4
|
140 end -- do-block
|
jcallahan@4
|
141
|
jcallahan@4
|
142
|
jcallahan@10
|
143 local function UpdateObjectLocation(identifier)
|
jcallahan@10
|
144 if not identifier then
|
jcallahan@10
|
145 return
|
jcallahan@10
|
146 end
|
jcallahan@10
|
147 local zone_name, x, y, map_level, instance_type = CurrentLocationData()
|
jcallahan@10
|
148 local object = UnitEntry("objects", identifier)
|
jcallahan@11
|
149 object.locations = object.locations or {}
|
jcallahan@10
|
150
|
jcallahan@11
|
151 if not object.locations[zone_name] then
|
jcallahan@11
|
152 object.locations[zone_name] = {}
|
jcallahan@10
|
153 end
|
jcallahan@11
|
154 object.locations[zone_name][("%s:%s:%s:%s"):format(instance_type, map_level, x, y)] = true
|
jcallahan@10
|
155 end
|
jcallahan@10
|
156
|
jcallahan@10
|
157
|
jcallahan@0
|
158 -----------------------------------------------------------------------
|
jcallahan@0
|
159 -- Methods.
|
jcallahan@0
|
160 -----------------------------------------------------------------------
|
jcallahan@0
|
161 function WDP:OnInitialize()
|
jcallahan@0
|
162 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
|
jcallahan@14
|
163
|
jcallahan@14
|
164 local raw_db = _G["WoWDBProfilerData"]
|
jcallahan@14
|
165
|
jcallahan@18
|
166 local build_num = tonumber(private.build_num)
|
jcallahan@14
|
167
|
jcallahan@14
|
168 if raw_db.build_num and raw_db.build_num < build_num then
|
jcallahan@14
|
169 for entry in pairs(DATABASE_DEFAULTS.global) do
|
jcallahan@14
|
170 db[entry] = {}
|
jcallahan@14
|
171 end
|
jcallahan@14
|
172 raw_db.build_num = build_num
|
jcallahan@14
|
173 elseif not raw_db.build_num then
|
jcallahan@14
|
174 raw_db.build_num = build_num
|
jcallahan@14
|
175 end
|
jcallahan@0
|
176 end
|
jcallahan@0
|
177
|
jcallahan@0
|
178
|
jcallahan@0
|
179 function WDP:OnEnable()
|
jcallahan@0
|
180 for event_name, mapping in pairs(EVENT_MAPPING) do
|
jcallahan@1
|
181 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
|
jcallahan@0
|
182 end
|
jcallahan@0
|
183 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
|
jcallahan@2
|
184 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.2)
|
jcallahan@0
|
185 end
|
jcallahan@0
|
186
|
jcallahan@0
|
187
|
jcallahan@0
|
188 local function RecordDurability(item_id, durability)
|
jcallahan@0
|
189 if not durability or durability <= 0 then
|
jcallahan@0
|
190 return
|
jcallahan@0
|
191 end
|
jcallahan@0
|
192
|
jcallahan@0
|
193 if not db.items[item_id] then
|
jcallahan@0
|
194 db.items[item_id] = {}
|
jcallahan@0
|
195 end
|
jcallahan@0
|
196 db.items[item_id].durability = durability
|
jcallahan@0
|
197 end
|
jcallahan@0
|
198
|
jcallahan@0
|
199
|
jcallahan@0
|
200 function WDP:ProcessDurability()
|
jcallahan@0
|
201 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
|
jcallahan@1
|
202 local item_id = _G.GetInventoryItemID("player", slot_index)
|
jcallahan@0
|
203
|
jcallahan@0
|
204 if item_id and item_id > 0 then
|
jcallahan@1
|
205 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
|
jcallahan@0
|
206 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
207 end
|
jcallahan@0
|
208 end
|
jcallahan@0
|
209
|
jcallahan@0
|
210 for bag_index = 0, _G.NUM_BAG_SLOTS do
|
jcallahan@0
|
211 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@1
|
212 local item_id = _G.GetContainerItemID(bag_index, slot_index)
|
jcallahan@0
|
213
|
jcallahan@0
|
214 if item_id and item_id > 0 then
|
jcallahan@1
|
215 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
|
jcallahan@0
|
216 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
217 end
|
jcallahan@0
|
218 end
|
jcallahan@0
|
219 end
|
jcallahan@0
|
220 end
|
jcallahan@0
|
221
|
jcallahan@0
|
222
|
jcallahan@2
|
223 function WDP:UpdateTargetLocation()
|
jcallahan@2
|
224 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or _G.UnitIsTapped("target") then
|
jcallahan@2
|
225 return
|
jcallahan@2
|
226 end
|
jcallahan@2
|
227
|
jcallahan@2
|
228 for index = 1, 4 do
|
jcallahan@2
|
229 if not _G.CheckInteractDistance("target", index) then
|
jcallahan@2
|
230 return
|
jcallahan@2
|
231 end
|
jcallahan@2
|
232 end
|
jcallahan@2
|
233
|
jcallahan@2
|
234 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
235
|
jcallahan@2
|
236 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@2
|
237 return
|
jcallahan@2
|
238 end
|
jcallahan@8
|
239 local zone_name, x, y, map_level, instance_type = CurrentLocationData()
|
jcallahan@10
|
240 local npc_data = UnitEntry("npcs", unit_idnum).stats[("level_%d"):format(_G.UnitLevel("target"))]
|
jcallahan@6
|
241 npc_data.locations = npc_data.locations or {}
|
jcallahan@2
|
242
|
jcallahan@2
|
243 if not npc_data.locations[zone_name] then
|
jcallahan@2
|
244 npc_data.locations[zone_name] = {}
|
jcallahan@2
|
245 end
|
jcallahan@8
|
246 npc_data.locations[zone_name][("%s:%s:%s:%s"):format(instance_type, map_level, x, y)] = true
|
jcallahan@2
|
247 end
|
jcallahan@2
|
248
|
jcallahan@2
|
249
|
jcallahan@0
|
250 -----------------------------------------------------------------------
|
jcallahan@0
|
251 -- Event handlers.
|
jcallahan@0
|
252 -----------------------------------------------------------------------
|
jcallahan@18
|
253 function WDP:COMBAT_TEXT_UPDATE(event, message_type, faction_name, amount)
|
jcallahan@18
|
254 -- if message_type ~= "FACTION" or _G.UnitIsUnit("target", "questnpc") then
|
jcallahan@18
|
255 -- return
|
jcallahan@18
|
256 -- end
|
jcallahan@18
|
257 -- local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@18
|
258 -- local npc = UnitEntry("npcs", unit_idnum)
|
jcallahan@18
|
259 --
|
jcallahan@18
|
260 -- if not npc then
|
jcallahan@18
|
261 -- return
|
jcallahan@18
|
262 -- end
|
jcallahan@18
|
263 -- npc.reputations = npc.reputations or {}
|
jcallahan@18
|
264 -- npc.reputations[faction_name] = amount
|
jcallahan@18
|
265 --
|
jcallahan@18
|
266 -- print(("%s: %s, %s, %s"):format(event, message_type, faction_name, amount))
|
jcallahan@18
|
267 end
|
jcallahan@18
|
268
|
jcallahan@18
|
269
|
jcallahan@13
|
270 function WDP:LOOT_CLOSED()
|
jcallahan@18
|
271 -- table.wipe(action_data)
|
jcallahan@0
|
272 end
|
jcallahan@0
|
273
|
jcallahan@0
|
274
|
jcallahan@13
|
275 do
|
jcallahan@13
|
276 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
277 local re_silver = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
278 local re_copper = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
279
|
jcallahan@13
|
280
|
jcallahan@13
|
281 local function _moneyMatch(money, re)
|
jcallahan@13
|
282 return money:match(re) or 0
|
jcallahan@1
|
283 end
|
jcallahan@1
|
284
|
jcallahan@0
|
285
|
jcallahan@13
|
286 local function _toCopper(money)
|
jcallahan@13
|
287 if not money then
|
jcallahan@13
|
288 return 0
|
jcallahan@13
|
289 end
|
jcallahan@0
|
290
|
jcallahan@13
|
291 return _moneyMatch(money, re_gold) * 10000 + _moneyMatch(money, re_silver) * 100 + _moneyMatch(money, re_copper)
|
jcallahan@1
|
292 end
|
jcallahan@1
|
293
|
jcallahan@1
|
294
|
jcallahan@13
|
295 local LOOT_VERIFY_FUNCS = {
|
jcallahan@16
|
296 [AF.ITEM] = function()
|
jcallahan@16
|
297 local locked_item_id
|
jcallahan@16
|
298
|
jcallahan@16
|
299 for bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@16
|
300 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@16
|
301 local _, _, is_locked = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@16
|
302
|
jcallahan@16
|
303 if is_locked then
|
jcallahan@16
|
304 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index))
|
jcallahan@16
|
305 end
|
jcallahan@16
|
306 end
|
jcallahan@16
|
307 end
|
jcallahan@16
|
308
|
jcallahan@16
|
309 if not locked_item_id or (action_data.item_id and action_data.item_id ~= locked_item_id) then
|
jcallahan@16
|
310 return false
|
jcallahan@16
|
311 end
|
jcallahan@16
|
312 action_data.item_id = locked_item_id
|
jcallahan@16
|
313 return true
|
jcallahan@16
|
314 end,
|
jcallahan@13
|
315 [AF.NPC] = function()
|
jcallahan@17
|
316 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@15
|
317 return false
|
jcallahan@13
|
318 end
|
jcallahan@15
|
319 local unit_type, id_num = WDP:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@15
|
320 action_data.id_num = id_num
|
jcallahan@13
|
321 return true
|
jcallahan@13
|
322 end,
|
jcallahan@14
|
323 [AF.OBJECT] = true,
|
jcallahan@17
|
324 [AF.ZONE] = function()
|
jcallahan@17
|
325 return action_data.loot_type and _G.IsFishingLoot()
|
jcallahan@17
|
326 end,
|
jcallahan@13
|
327 }
|
jcallahan@13
|
328
|
jcallahan@13
|
329
|
jcallahan@13
|
330 local LOOT_UPDATE_FUNCS = {
|
jcallahan@16
|
331 [AF.ITEM] = function()
|
jcallahan@16
|
332 local item = UnitEntry("items", action_data.item_id)
|
jcallahan@17
|
333 local loot_type = action_data.loot_type
|
jcallahan@16
|
334 item[loot_type] = item[loot_type] or {}
|
jcallahan@16
|
335
|
jcallahan@17
|
336 for index = 1, #action_data.loot_list do
|
jcallahan@17
|
337 table.insert(item[loot_type], action_data.loot_list[index])
|
jcallahan@16
|
338 end
|
jcallahan@16
|
339 end,
|
jcallahan@13
|
340 [AF.NPC] = function()
|
jcallahan@13
|
341 local npc = UnitEntry("npcs", action_data.id_num)
|
jcallahan@15
|
342
|
jcallahan@15
|
343 if not npc then
|
jcallahan@15
|
344 return
|
jcallahan@15
|
345 end
|
jcallahan@13
|
346 local loot_type = action_data.loot_type or "drops"
|
jcallahan@13
|
347 npc[loot_type] = npc[loot_type] or {}
|
jcallahan@13
|
348
|
jcallahan@17
|
349 for index = 1, #action_data.loot_list do
|
jcallahan@17
|
350 table.insert(npc[loot_type], action_data.loot_list[index])
|
jcallahan@13
|
351 end
|
jcallahan@13
|
352 end,
|
jcallahan@13
|
353 [AF.OBJECT] = function()
|
jcallahan@13
|
354 local object = UnitEntry("objects", action_data.identifier)
|
jcallahan@13
|
355 object.drops = object.drops or {}
|
jcallahan@13
|
356
|
jcallahan@17
|
357 for index = 1, #action_data.loot_list do
|
jcallahan@17
|
358 table.insert(object.drops, action_data.loot_list[index])
|
jcallahan@17
|
359 end
|
jcallahan@17
|
360 end,
|
jcallahan@17
|
361 [AF.ZONE] = function()
|
jcallahan@17
|
362 local loot_type = action_data.loot_type or "drops"
|
jcallahan@17
|
363 local zone = UnitEntry("zones", action_data.zone)
|
jcallahan@17
|
364 zone[loot_type] = zone[loot_type] or {}
|
jcallahan@17
|
365
|
jcallahan@17
|
366 local location_data = ("%s:%s:%s:%s"):format(action_data.instance_type, action_data.map_level, action_data.x, action_data.y)
|
jcallahan@17
|
367 local loot_data = zone[loot_type][location_data]
|
jcallahan@17
|
368
|
jcallahan@17
|
369 if not loot_data then
|
jcallahan@17
|
370 zone[loot_type][location_data] = {}
|
jcallahan@17
|
371 loot_data = zone[loot_type][location_data]
|
jcallahan@17
|
372 end
|
jcallahan@17
|
373
|
jcallahan@17
|
374 for index = 1, #action_data.loot_list do
|
jcallahan@17
|
375 table.insert(loot_data, action_data.loot_list[index])
|
jcallahan@13
|
376 end
|
jcallahan@13
|
377 end,
|
jcallahan@13
|
378 }
|
jcallahan@13
|
379
|
jcallahan@13
|
380
|
jcallahan@13
|
381 function WDP:LOOT_OPENED()
|
jcallahan@18
|
382 if action_data.looting then
|
jcallahan@18
|
383 return
|
jcallahan@18
|
384 end
|
jcallahan@18
|
385
|
jcallahan@13
|
386 if not action_data.type then
|
jcallahan@13
|
387 action_data.type = AF.NPC
|
jcallahan@1
|
388 end
|
jcallahan@13
|
389 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
|
jcallahan@13
|
390 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
|
jcallahan@13
|
391
|
jcallahan@14
|
392 if not verify_func or not update_func then
|
jcallahan@13
|
393 return
|
jcallahan@13
|
394 end
|
jcallahan@13
|
395
|
jcallahan@14
|
396 if _G.type(verify_func) == "function" and not verify_func() then
|
jcallahan@14
|
397 return
|
jcallahan@14
|
398 end
|
jcallahan@18
|
399 -- TODO: Remove this check once the MoP client goes live
|
jcallahan@18
|
400 local wow_version = private.wow_version
|
jcallahan@13
|
401 local loot_registry = {}
|
jcallahan@17
|
402 action_data.loot_list = {}
|
jcallahan@18
|
403 action_data.looting = true
|
jcallahan@13
|
404
|
jcallahan@18
|
405 if wow_version == "5.0.1" then
|
jcallahan@18
|
406 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@18
|
407 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@13
|
408
|
jcallahan@18
|
409 local slot_type = _G.GetLootSlotType(loot_slot)
|
jcallahan@18
|
410
|
jcallahan@18
|
411 if slot_type == _G.LOOT_SLOT_ITEM then
|
jcallahan@18
|
412 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@18
|
413 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@18
|
414 elseif slot_type == _G.LOOT_SLOT_MONEY then
|
jcallahan@18
|
415 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@18
|
416 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
|
jcallahan@18
|
417 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@18
|
418 end
|
jcallahan@18
|
419 end
|
jcallahan@18
|
420 else
|
jcallahan@18
|
421 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@18
|
422 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@18
|
423 if _G.LootSlotIsItem(loot_slot) then
|
jcallahan@18
|
424 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@18
|
425 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@18
|
426 elseif _G.LootSlotIsCoin(loot_slot) then
|
jcallahan@18
|
427 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@18
|
428 elseif _G.LootSlotIsCurrency(loot_slot) then
|
jcallahan@18
|
429 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@18
|
430 end
|
jcallahan@13
|
431 end
|
jcallahan@13
|
432 end
|
jcallahan@13
|
433
|
jcallahan@13
|
434 for item_id, quantity in pairs(loot_registry) do
|
jcallahan@17
|
435 table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity))
|
jcallahan@13
|
436 end
|
jcallahan@13
|
437 update_func()
|
jcallahan@1
|
438 end
|
jcallahan@13
|
439 end -- do-block
|
jcallahan@0
|
440
|
jcallahan@0
|
441
|
jcallahan@5
|
442 local POINT_MATCH_PATTERNS = {
|
jcallahan@5
|
443 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@5
|
444 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@5
|
445 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@5
|
446 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@5
|
447 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@5
|
448 }
|
jcallahan@5
|
449
|
jcallahan@5
|
450
|
jcallahan@7
|
451 function WDP:UpdateMerchantItems()
|
jcallahan@4
|
452 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@4
|
453
|
jcallahan@4
|
454 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@4
|
455 return
|
jcallahan@4
|
456 end
|
jcallahan@10
|
457 local merchant = UnitEntry("npcs", unit_idnum)
|
jcallahan@6
|
458 merchant.sells = merchant.sells or {}
|
jcallahan@5
|
459
|
jcallahan@5
|
460 for item_index = 1, _G.GetMerchantNumItems() do
|
jcallahan@5
|
461 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
|
jcallahan@5
|
462 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
|
jcallahan@5
|
463
|
jcallahan@5
|
464 if item_id and item_id > 0 then
|
jcallahan@5
|
465 local price_string = copper_price
|
jcallahan@5
|
466
|
jcallahan@5
|
467 if extended_cost then
|
jcallahan@5
|
468 local bg_points = 0
|
jcallahan@5
|
469 local personal_points = 0
|
jcallahan@5
|
470
|
jcallahan@5
|
471 DatamineTT:ClearLines()
|
jcallahan@5
|
472 DatamineTT:SetMerchantItem(item_index)
|
jcallahan@5
|
473
|
jcallahan@5
|
474 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@5
|
475 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@5
|
476
|
jcallahan@5
|
477 if not current_line then
|
jcallahan@5
|
478 break
|
jcallahan@5
|
479 end
|
jcallahan@5
|
480 local breakout
|
jcallahan@5
|
481
|
jcallahan@5
|
482 for match_index = 1, #POINT_MATCH_PATTERNS do
|
jcallahan@5
|
483 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
|
jcallahan@5
|
484 personal_points = personal_points + (match1 or 0)
|
jcallahan@5
|
485 bg_points = bg_points + (match2 or 0)
|
jcallahan@5
|
486
|
jcallahan@5
|
487 if match1 or match2 then
|
jcallahan@5
|
488 breakout = true
|
jcallahan@5
|
489 break
|
jcallahan@5
|
490 end
|
jcallahan@5
|
491 end
|
jcallahan@5
|
492
|
jcallahan@5
|
493 if breakout then
|
jcallahan@5
|
494 break
|
jcallahan@5
|
495 end
|
jcallahan@5
|
496 end
|
jcallahan@5
|
497 local currency_list = {}
|
jcallahan@5
|
498
|
jcallahan@5
|
499 price_string = ("%s:%s:%s"):format(price_string, bg_points, personal_points)
|
jcallahan@5
|
500
|
jcallahan@5
|
501 for cost_index = 1, _G.GetMerchantItemCostInfo(item_index) do
|
jcallahan@5
|
502 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index)
|
jcallahan@5
|
503 local currency_id = currency_link and ItemLinkToID(currency_link) or nil
|
jcallahan@5
|
504
|
jcallahan@5
|
505 if not currency_id or currency_id < 1 then
|
jcallahan@5
|
506 if not icon_texture then
|
jcallahan@5
|
507 return
|
jcallahan@5
|
508 end
|
jcallahan@5
|
509 currency_id = icon_texture:match("[^\\]+$"):lower()
|
jcallahan@5
|
510 end
|
jcallahan@5
|
511 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id)
|
jcallahan@5
|
512 end
|
jcallahan@5
|
513
|
jcallahan@5
|
514 for currency_index = 1, #currency_list do
|
jcallahan@5
|
515 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
|
jcallahan@5
|
516 end
|
jcallahan@5
|
517 end
|
jcallahan@6
|
518 merchant.sells[("%s:%s:[%s]"):format(item_id, stack_size, price_string)] = num_available
|
jcallahan@5
|
519 end
|
jcallahan@4
|
520 end
|
jcallahan@14
|
521
|
jcallahan@14
|
522 if _G.CanMerchantRepair() then
|
jcallahan@14
|
523 merchant.can_repair = true
|
jcallahan@14
|
524 end
|
jcallahan@4
|
525 end
|
jcallahan@4
|
526
|
jcallahan@4
|
527
|
jcallahan@18
|
528 do
|
jcallahan@18
|
529 local GENDER_NAMES = {
|
jcallahan@18
|
530 "UNKNOWN",
|
jcallahan@18
|
531 "MALE",
|
jcallahan@18
|
532 "FEMALE",
|
jcallahan@18
|
533 }
|
jcallahan@2
|
534
|
jcallahan@2
|
535
|
jcallahan@18
|
536 local REACTION_NAMES = {
|
jcallahan@18
|
537 "HATED",
|
jcallahan@18
|
538 "HOSTILE",
|
jcallahan@18
|
539 "UNFRIENDLY",
|
jcallahan@18
|
540 "NEUTRAL",
|
jcallahan@18
|
541 "FRIENDLY",
|
jcallahan@18
|
542 "HONORED",
|
jcallahan@18
|
543 "REVERED",
|
jcallahan@18
|
544 "EXALTED",
|
jcallahan@18
|
545 }
|
jcallahan@2
|
546
|
jcallahan@2
|
547
|
jcallahan@18
|
548 local POWER_TYPE_NAMES = {
|
jcallahan@18
|
549 ["0"] = "MANA",
|
jcallahan@18
|
550 ["1"] = "RAGE",
|
jcallahan@18
|
551 ["2"] = "FOCUS",
|
jcallahan@18
|
552 ["3"] = "ENERGY",
|
jcallahan@18
|
553 ["6"] = "RUNIC_POWER",
|
jcallahan@18
|
554 }
|
jcallahan@2
|
555
|
jcallahan@2
|
556
|
jcallahan@18
|
557 function WDP:PLAYER_TARGET_CHANGED()
|
jcallahan@18
|
558 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@18
|
559 return
|
jcallahan@18
|
560 end
|
jcallahan@18
|
561 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
562
|
jcallahan@18
|
563 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@18
|
564 return
|
jcallahan@18
|
565 end
|
jcallahan@18
|
566 table.wipe(action_data)
|
jcallahan@2
|
567
|
jcallahan@18
|
568 local npc = UnitEntry("npcs", unit_idnum)
|
jcallahan@18
|
569 local _, class_token = _G.UnitClass("target")
|
jcallahan@18
|
570 npc.class = class_token
|
jcallahan@18
|
571 -- TODO: Add faction here
|
jcallahan@18
|
572 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"
|
jcallahan@18
|
573 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
|
jcallahan@18
|
574 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
|
jcallahan@18
|
575 npc.stats = npc.stats or {}
|
jcallahan@2
|
576
|
jcallahan@18
|
577 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
|
jcallahan@3
|
578
|
jcallahan@18
|
579 if not npc.stats[npc_level] then
|
jcallahan@18
|
580 npc.stats[npc_level] = {
|
jcallahan@18
|
581 max_health = _G.UnitHealthMax("target"),
|
jcallahan@18
|
582 }
|
jcallahan@3
|
583
|
jcallahan@18
|
584 local max_power = _G.UnitManaMax("target")
|
jcallahan@18
|
585
|
jcallahan@18
|
586 if max_power > 0 then
|
jcallahan@18
|
587 local power_type = _G.UnitPowerType("target")
|
jcallahan@18
|
588 npc.stats[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
|
jcallahan@18
|
589 end
|
jcallahan@3
|
590 end
|
jcallahan@2
|
591 end
|
jcallahan@18
|
592 end -- do-block
|
jcallahan@2
|
593
|
jcallahan@12
|
594 do
|
jcallahan@12
|
595 local function UpdateQuestJuncture(point)
|
jcallahan@12
|
596 local unit_name = _G.UnitName("questnpc")
|
jcallahan@9
|
597
|
jcallahan@12
|
598 if not unit_name then
|
jcallahan@12
|
599 return
|
jcallahan@12
|
600 end
|
jcallahan@12
|
601 local unit_type, unit_id = WDP:ParseGUID(_G.UnitGUID("questnpc"))
|
jcallahan@9
|
602
|
jcallahan@12
|
603 if unit_type == private.UNIT_TYPES.OBJECT then
|
jcallahan@12
|
604 UpdateObjectLocation(unit_id)
|
jcallahan@12
|
605 end
|
jcallahan@12
|
606 local quest = UnitEntry("quests", _G.GetQuestID())
|
jcallahan@12
|
607 quest[point] = quest[point] or {}
|
jcallahan@12
|
608 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
|
jcallahan@12
|
609 end
|
jcallahan@10
|
610
|
jcallahan@12
|
611
|
jcallahan@12
|
612 function WDP:QUEST_COMPLETE()
|
jcallahan@12
|
613 UpdateQuestJuncture("end")
|
jcallahan@10
|
614 end
|
jcallahan@10
|
615
|
jcallahan@12
|
616
|
jcallahan@12
|
617 function WDP:QUEST_DETAIL()
|
jcallahan@12
|
618 UpdateQuestJuncture("begin")
|
jcallahan@10
|
619 end
|
jcallahan@12
|
620 end -- do-block
|
jcallahan@9
|
621
|
jcallahan@9
|
622
|
jcallahan@4
|
623 function WDP:QUEST_LOG_UPDATE()
|
jcallahan@4
|
624 self:UnregisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
625 end
|
jcallahan@4
|
626
|
jcallahan@4
|
627
|
jcallahan@4
|
628 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id)
|
jcallahan@4
|
629 if unit_id ~= "player" then
|
jcallahan@4
|
630 return
|
jcallahan@4
|
631 end
|
jcallahan@4
|
632 self:RegisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
633 end
|
jcallahan@4
|
634
|
jcallahan@4
|
635
|
jcallahan@1
|
636 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
|
jcallahan@1
|
637 if private.tracked_line or unit_id ~= "player" then
|
jcallahan@1
|
638 return
|
jcallahan@1
|
639 end
|
jcallahan@1
|
640 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
|
jcallahan@1
|
641
|
jcallahan@1
|
642 if not spell_label then
|
jcallahan@1
|
643 return
|
jcallahan@1
|
644 end
|
jcallahan@18
|
645 table.wipe(action_data)
|
jcallahan@1
|
646
|
jcallahan@1
|
647 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
|
jcallahan@1
|
648 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
|
jcallahan@1
|
649
|
jcallahan@1
|
650 if not tt_unit_name and _G.UnitName("target") == target_name then
|
jcallahan@1
|
651 tt_unit_name = target_name
|
jcallahan@1
|
652 tt_unit_id = "target"
|
jcallahan@1
|
653 end
|
jcallahan@1
|
654 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
|
jcallahan@1
|
655
|
jcallahan@16
|
656 if tt_unit_name and not tt_item_name then
|
jcallahan@16
|
657 if bit.band(spell_flags, AF.NPC) == AF.NPC then
|
jcallahan@16
|
658 if not tt_unit_id or tt_unit_name ~= target_name then
|
jcallahan@16
|
659 return
|
jcallahan@16
|
660 end
|
jcallahan@16
|
661 action_data.type = AF.NPC
|
jcallahan@16
|
662 action_data.loot_type = spell_label:lower()
|
jcallahan@16
|
663 end
|
jcallahan@16
|
664 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
|
jcallahan@16
|
665 action_data.type = AF.ITEM
|
jcallahan@16
|
666 action_data.loot_type = spell_label:lower()
|
jcallahan@16
|
667
|
jcallahan@16
|
668 if tt_item_name and tt_item_name == target_name then
|
jcallahan@16
|
669 action_data.item_id = ItemLinkToID(tt_item_link)
|
jcallahan@16
|
670 elseif target_name and target_name ~= "" then
|
jcallahan@16
|
671 local _, target_item_link = _G.GetItemInfo(target_name)
|
jcallahan@16
|
672 action_data.item_id = ItemLinkToID(target_item_link)
|
jcallahan@16
|
673 end
|
jcallahan@16
|
674 elseif not tt_item_name and not tt_unit_name then
|
jcallahan@8
|
675 local zone_name, x, y, map_level, instance_type = CurrentLocationData()
|
jcallahan@1
|
676
|
jcallahan@17
|
677 action_data.instance_type = instance_type
|
jcallahan@17
|
678 action_data.map_level = map_level
|
jcallahan@17
|
679 action_data.name = target_name
|
jcallahan@17
|
680 action_data.x = x
|
jcallahan@17
|
681 action_data.y = y
|
jcallahan@17
|
682 action_data.zone = zone_name
|
jcallahan@17
|
683
|
jcallahan@1
|
684 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
|
jcallahan@17
|
685 if target_name == "" then
|
jcallahan@17
|
686 return
|
jcallahan@17
|
687 end
|
jcallahan@11
|
688 local identifier = ("%s:%s"):format(spell_label, target_name)
|
jcallahan@11
|
689 UpdateObjectLocation(identifier)
|
jcallahan@11
|
690
|
jcallahan@1
|
691 action_data.type = AF.OBJECT
|
jcallahan@11
|
692 action_data.identifier = identifier
|
jcallahan@1
|
693 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
|
jcallahan@17
|
694 action_data.type = AF.ZONE
|
jcallahan@17
|
695 action_data.loot_type = spell_label:lower()
|
jcallahan@1
|
696 end
|
jcallahan@1
|
697 end
|
jcallahan@1
|
698
|
jcallahan@18
|
699 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line))
|
jcallahan@1
|
700 private.tracked_line = spell_line
|
jcallahan@0
|
701 end
|
jcallahan@0
|
702
|
jcallahan@0
|
703
|
jcallahan@1
|
704 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
705 if unit_id ~= "player" then
|
jcallahan@1
|
706 return
|
jcallahan@1
|
707 end
|
jcallahan@1
|
708
|
jcallahan@18
|
709 -- if private.SPELL_LABELS_BY_NAME[spell_name] then
|
jcallahan@18
|
710 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id))
|
jcallahan@18
|
711 -- end
|
jcallahan@1
|
712 private.tracked_line = nil
|
jcallahan@0
|
713 end
|
jcallahan@0
|
714
|
jcallahan@1
|
715 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
716 if unit_id ~= "player" then
|
jcallahan@1
|
717 return
|
jcallahan@1
|
718 end
|
jcallahan@0
|
719
|
jcallahan@1
|
720 if private.tracked_line == spell_line then
|
jcallahan@1
|
721 private.tracked_line = nil
|
jcallahan@1
|
722 end
|
jcallahan@0
|
723 end
|