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@23
|
41 COMBAT_LOG_EVENT_UNFILTERED = true,
|
jcallahan@18
|
42 COMBAT_TEXT_UPDATE = true,
|
jcallahan@13
|
43 LOOT_CLOSED = true,
|
jcallahan@1
|
44 LOOT_OPENED = true,
|
jcallahan@7
|
45 MERCHANT_SHOW = "UpdateMerchantItems",
|
jcallahan@7
|
46 MERCHANT_UPDATE = "UpdateMerchantItems",
|
jcallahan@2
|
47 PLAYER_TARGET_CHANGED = true,
|
jcallahan@9
|
48 QUEST_COMPLETE = true,
|
jcallahan@9
|
49 QUEST_DETAIL = true,
|
jcallahan@9
|
50 QUEST_LOG_UPDATE = true,
|
jcallahan@4
|
51 UNIT_QUEST_LOG_CHANGED = true,
|
jcallahan@1
|
52 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
|
jcallahan@1
|
53 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
|
jcallahan@1
|
54 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
|
jcallahan@1
|
55 UNIT_SPELLCAST_SENT = true,
|
jcallahan@1
|
56 UNIT_SPELLCAST_SUCCEEDED = true,
|
jcallahan@0
|
57 }
|
jcallahan@0
|
58
|
jcallahan@4
|
59
|
jcallahan@1
|
60 local AF = private.ACTION_TYPE_FLAGS
|
jcallahan@0
|
61
|
jcallahan@4
|
62
|
jcallahan@0
|
63 -----------------------------------------------------------------------
|
jcallahan@0
|
64 -- Local variables.
|
jcallahan@0
|
65 -----------------------------------------------------------------------
|
jcallahan@0
|
66 local db
|
jcallahan@0
|
67 local durability_timer_handle
|
jcallahan@2
|
68 local target_location_timer_handle
|
jcallahan@1
|
69 local action_data = {}
|
jcallahan@20
|
70 local faction_names = {}
|
jcallahan@0
|
71
|
jcallahan@1
|
72
|
jcallahan@1
|
73 -----------------------------------------------------------------------
|
jcallahan@1
|
74 -- Helper Functions.
|
jcallahan@1
|
75 -----------------------------------------------------------------------
|
jcallahan@19
|
76 local function DBEntry(data_type, unit_id)
|
jcallahan@19
|
77 if not data_type or not unit_id then
|
jcallahan@6
|
78 return
|
jcallahan@6
|
79 end
|
jcallahan@19
|
80 local unit = db[data_type][unit_id]
|
jcallahan@6
|
81
|
jcallahan@10
|
82 if not unit then
|
jcallahan@19
|
83 db[data_type][unit_id] = {}
|
jcallahan@19
|
84 unit = db[data_type][unit_id]
|
jcallahan@6
|
85 end
|
jcallahan@10
|
86 return unit
|
jcallahan@6
|
87 end
|
jcallahan@6
|
88
|
jcallahan@6
|
89
|
jcallahan@22
|
90 local function InstanceDifficultyToken()
|
jcallahan@22
|
91 local _, instance_type, instance_difficulty, difficulty_name, _, _, is_dynamic = _G.GetInstanceInfo()
|
jcallahan@22
|
92 if difficulty_name == "" then
|
jcallahan@22
|
93 difficulty_name = "NONE"
|
jcallahan@22
|
94 end
|
jcallahan@22
|
95 return ("%s:%s:%s"):format(instance_type:upper(), difficulty_name:upper():gsub(" ", "_"), _G.tostring(is_dynamic))
|
jcallahan@22
|
96 end
|
jcallahan@22
|
97
|
jcallahan@22
|
98
|
jcallahan@1
|
99 local function CurrentLocationData()
|
jcallahan@1
|
100 local map_level = _G.GetCurrentMapDungeonLevel() or 0
|
jcallahan@1
|
101 local x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
102
|
jcallahan@1
|
103 x = x or 0
|
jcallahan@1
|
104 y = y or 0
|
jcallahan@1
|
105
|
jcallahan@1
|
106 if x == 0 and y == 0 then
|
jcallahan@1
|
107 for level_index = 1, _G.GetNumDungeonMapLevels() do
|
jcallahan@1
|
108 _G.SetDungeonMapLevel(level_index)
|
jcallahan@1
|
109 x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
110
|
jcallahan@1
|
111 if x and y and (x > 0 or y > 0) then
|
jcallahan@1
|
112 _G.SetDungeonMapLevel(map_level)
|
jcallahan@1
|
113 map_level = level_index
|
jcallahan@1
|
114 break
|
jcallahan@1
|
115 end
|
jcallahan@1
|
116 end
|
jcallahan@1
|
117 end
|
jcallahan@1
|
118
|
jcallahan@1
|
119 if _G.DungeonUsesTerrainMap() then
|
jcallahan@1
|
120 map_level = map_level - 1
|
jcallahan@1
|
121 end
|
jcallahan@22
|
122 return _G.GetRealZoneText(), ("%.2f"):format(x * 100), ("%.2f"):format(y * 100), map_level or 0, InstanceDifficultyToken()
|
jcallahan@1
|
123 end
|
jcallahan@1
|
124
|
jcallahan@1
|
125
|
jcallahan@1
|
126 local function ItemLinkToID(item_link)
|
jcallahan@1
|
127 if not item_link then
|
jcallahan@1
|
128 return
|
jcallahan@1
|
129 end
|
jcallahan@7
|
130 return tonumber(item_link:match("item:(%d+)"))
|
jcallahan@1
|
131 end
|
jcallahan@0
|
132
|
jcallahan@4
|
133
|
jcallahan@4
|
134 do
|
jcallahan@4
|
135 local UNIT_TYPE_BITMASK = 0x007
|
jcallahan@4
|
136
|
jcallahan@4
|
137 function WDP:ParseGUID(guid)
|
jcallahan@5
|
138 if not guid then
|
jcallahan@5
|
139 return
|
jcallahan@5
|
140 end
|
jcallahan@4
|
141 local types = private.UNIT_TYPES
|
jcallahan@4
|
142 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
|
jcallahan@4
|
143
|
jcallahan@10
|
144 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
|
jcallahan@4
|
145 return unit_type, tonumber(guid:sub(-12, -9), 16)
|
jcallahan@4
|
146 end
|
jcallahan@4
|
147
|
jcallahan@4
|
148 return unit_type
|
jcallahan@4
|
149 end
|
jcallahan@4
|
150 end -- do-block
|
jcallahan@4
|
151
|
jcallahan@4
|
152
|
jcallahan@10
|
153 local function UpdateObjectLocation(identifier)
|
jcallahan@10
|
154 if not identifier then
|
jcallahan@10
|
155 return
|
jcallahan@10
|
156 end
|
jcallahan@22
|
157 local zone_name, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@19
|
158 local object = DBEntry("objects", identifier)
|
jcallahan@11
|
159 object.locations = object.locations or {}
|
jcallahan@10
|
160
|
jcallahan@11
|
161 if not object.locations[zone_name] then
|
jcallahan@11
|
162 object.locations[zone_name] = {}
|
jcallahan@10
|
163 end
|
jcallahan@22
|
164 object.locations[zone_name][("%s:%s:%s:%s"):format(instance_token, map_level, x, y)] = true
|
jcallahan@10
|
165 end
|
jcallahan@10
|
166
|
jcallahan@10
|
167
|
jcallahan@19
|
168 local function HandleItemUse(item_link, bag_index, slot_index)
|
jcallahan@19
|
169 if not item_link then
|
jcallahan@19
|
170 return
|
jcallahan@19
|
171 end
|
jcallahan@19
|
172 local item_id = ItemLinkToID(item_link)
|
jcallahan@19
|
173
|
jcallahan@19
|
174 if not bag_index or not slot_index then
|
jcallahan@19
|
175 for new_bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@19
|
176 for new_slot_index = 1, _G.GetContainerNumSlots(new_bag_index) do
|
jcallahan@19
|
177 if item_id == ItemLinkToID(_G.GetContainerItemLink(new_bag_index, new_slot_index)) then
|
jcallahan@19
|
178 bag_index = new_bag_index
|
jcallahan@19
|
179 slot_index = new_slot_index
|
jcallahan@19
|
180 break
|
jcallahan@19
|
181 end
|
jcallahan@19
|
182 end
|
jcallahan@19
|
183 end
|
jcallahan@19
|
184 end
|
jcallahan@19
|
185
|
jcallahan@19
|
186 if not bag_index or not slot_index then
|
jcallahan@19
|
187 return
|
jcallahan@19
|
188 end
|
jcallahan@19
|
189 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@19
|
190
|
jcallahan@19
|
191 if not is_lootable then
|
jcallahan@19
|
192 return
|
jcallahan@19
|
193 end
|
jcallahan@19
|
194 DatamineTT:ClearLines()
|
jcallahan@19
|
195 DatamineTT:SetBagItem(bag_index, slot_index)
|
jcallahan@19
|
196
|
jcallahan@19
|
197 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@19
|
198 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@19
|
199
|
jcallahan@19
|
200 if not current_line then
|
jcallahan@19
|
201 break
|
jcallahan@19
|
202 end
|
jcallahan@19
|
203
|
jcallahan@19
|
204 if current_line:GetText() == _G.ITEM_OPENABLE then
|
jcallahan@19
|
205 table.wipe(action_data)
|
jcallahan@19
|
206 action_data.type = AF.ITEM
|
jcallahan@19
|
207 action_data.item_id = item_id
|
jcallahan@19
|
208 action_data.loot_type = "contains"
|
jcallahan@19
|
209 break
|
jcallahan@19
|
210 end
|
jcallahan@19
|
211 end
|
jcallahan@19
|
212 end
|
jcallahan@19
|
213
|
jcallahan@19
|
214
|
jcallahan@20
|
215 local function UpdateFactionNames()
|
jcallahan@20
|
216 for faction_index = 1, 1000 do
|
jcallahan@20
|
217 local faction_name, _, _, _, _, _, _, _, is_header = _G.GetFactionInfo(faction_index)
|
jcallahan@20
|
218
|
jcallahan@20
|
219 if faction_name and not is_header then
|
jcallahan@20
|
220 faction_names[faction_name] = true
|
jcallahan@20
|
221 elseif not faction_name then
|
jcallahan@20
|
222 break
|
jcallahan@20
|
223 end
|
jcallahan@20
|
224 end
|
jcallahan@20
|
225 end
|
jcallahan@20
|
226
|
jcallahan@20
|
227
|
jcallahan@0
|
228 -----------------------------------------------------------------------
|
jcallahan@0
|
229 -- Methods.
|
jcallahan@0
|
230 -----------------------------------------------------------------------
|
jcallahan@0
|
231 function WDP:OnInitialize()
|
jcallahan@0
|
232 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
|
jcallahan@14
|
233
|
jcallahan@14
|
234 local raw_db = _G["WoWDBProfilerData"]
|
jcallahan@14
|
235
|
jcallahan@18
|
236 local build_num = tonumber(private.build_num)
|
jcallahan@14
|
237
|
jcallahan@14
|
238 if raw_db.build_num and raw_db.build_num < build_num then
|
jcallahan@14
|
239 for entry in pairs(DATABASE_DEFAULTS.global) do
|
jcallahan@14
|
240 db[entry] = {}
|
jcallahan@14
|
241 end
|
jcallahan@14
|
242 raw_db.build_num = build_num
|
jcallahan@14
|
243 elseif not raw_db.build_num then
|
jcallahan@14
|
244 raw_db.build_num = build_num
|
jcallahan@14
|
245 end
|
jcallahan@0
|
246 end
|
jcallahan@0
|
247
|
jcallahan@0
|
248
|
jcallahan@0
|
249 function WDP:OnEnable()
|
jcallahan@0
|
250 for event_name, mapping in pairs(EVENT_MAPPING) do
|
jcallahan@1
|
251 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
|
jcallahan@0
|
252 end
|
jcallahan@0
|
253 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
|
jcallahan@2
|
254 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.2)
|
jcallahan@19
|
255
|
jcallahan@19
|
256 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit)
|
jcallahan@19
|
257 if target_unit then
|
jcallahan@19
|
258 return
|
jcallahan@19
|
259 end
|
jcallahan@19
|
260 HandleItemUse(_G.GetContainerItemLink(bag_index, slot_index), bag_index, slot_index)
|
jcallahan@19
|
261 end)
|
jcallahan@19
|
262
|
jcallahan@19
|
263 _G.hooksecurefunc("UseItemByName", function(identifier, target_unit)
|
jcallahan@19
|
264 if target_unit then
|
jcallahan@19
|
265 return
|
jcallahan@19
|
266 end
|
jcallahan@19
|
267 local _, item_link = _G.GetItemInfo(identifier)
|
jcallahan@19
|
268 HandleItemUse(item_link)
|
jcallahan@19
|
269 end)
|
jcallahan@0
|
270 end
|
jcallahan@0
|
271
|
jcallahan@0
|
272
|
jcallahan@0
|
273 local function RecordDurability(item_id, durability)
|
jcallahan@0
|
274 if not durability or durability <= 0 then
|
jcallahan@0
|
275 return
|
jcallahan@0
|
276 end
|
jcallahan@0
|
277
|
jcallahan@0
|
278 if not db.items[item_id] then
|
jcallahan@0
|
279 db.items[item_id] = {}
|
jcallahan@0
|
280 end
|
jcallahan@0
|
281 db.items[item_id].durability = durability
|
jcallahan@0
|
282 end
|
jcallahan@0
|
283
|
jcallahan@0
|
284
|
jcallahan@0
|
285 function WDP:ProcessDurability()
|
jcallahan@0
|
286 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
|
jcallahan@1
|
287 local item_id = _G.GetInventoryItemID("player", slot_index)
|
jcallahan@0
|
288
|
jcallahan@0
|
289 if item_id and item_id > 0 then
|
jcallahan@1
|
290 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
|
jcallahan@0
|
291 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
292 end
|
jcallahan@0
|
293 end
|
jcallahan@0
|
294
|
jcallahan@0
|
295 for bag_index = 0, _G.NUM_BAG_SLOTS do
|
jcallahan@0
|
296 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@1
|
297 local item_id = _G.GetContainerItemID(bag_index, slot_index)
|
jcallahan@0
|
298
|
jcallahan@0
|
299 if item_id and item_id > 0 then
|
jcallahan@1
|
300 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
|
jcallahan@0
|
301 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
302 end
|
jcallahan@0
|
303 end
|
jcallahan@0
|
304 end
|
jcallahan@0
|
305 end
|
jcallahan@0
|
306
|
jcallahan@0
|
307
|
jcallahan@2
|
308 function WDP:UpdateTargetLocation()
|
jcallahan@22
|
309 local is_dead = _G.UnitIsDead("target")
|
jcallahan@22
|
310
|
jcallahan@22
|
311 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not is_dead) then
|
jcallahan@2
|
312 return
|
jcallahan@2
|
313 end
|
jcallahan@2
|
314
|
jcallahan@2
|
315 for index = 1, 4 do
|
jcallahan@2
|
316 if not _G.CheckInteractDistance("target", index) then
|
jcallahan@2
|
317 return
|
jcallahan@2
|
318 end
|
jcallahan@2
|
319 end
|
jcallahan@22
|
320 local target_guid = _G.UnitGUID("target")
|
jcallahan@22
|
321 local unit_type, unit_idnum = self:ParseGUID(target_guid)
|
jcallahan@2
|
322
|
jcallahan@2
|
323 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@2
|
324 return
|
jcallahan@2
|
325 end
|
jcallahan@22
|
326 local zone_name, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@22
|
327 local npc_data = DBEntry("npcs", unit_idnum).encounter_data[("level_%d"):format(_G.UnitLevel("target"))]
|
jcallahan@6
|
328 npc_data.locations = npc_data.locations or {}
|
jcallahan@2
|
329
|
jcallahan@2
|
330 if not npc_data.locations[zone_name] then
|
jcallahan@2
|
331 npc_data.locations[zone_name] = {}
|
jcallahan@2
|
332 end
|
jcallahan@22
|
333
|
jcallahan@22
|
334 -- Only record corpse location if there is no entry for this GUID.
|
jcallahan@22
|
335 if is_dead and npc_data.locations[zone_name][target_guid] then
|
jcallahan@22
|
336 return
|
jcallahan@22
|
337 end
|
jcallahan@22
|
338 npc_data.locations[zone_name][target_guid] = ("%s:%s:%s:%s"):format(instance_token, map_level, x, y)
|
jcallahan@2
|
339 end
|
jcallahan@2
|
340
|
jcallahan@2
|
341
|
jcallahan@0
|
342 -----------------------------------------------------------------------
|
jcallahan@0
|
343 -- Event handlers.
|
jcallahan@0
|
344 -----------------------------------------------------------------------
|
jcallahan@23
|
345 do
|
jcallahan@23
|
346 local EXTRACT_GAS_SPELL_ID = 30427
|
jcallahan@23
|
347 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
348 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
349
|
jcallahan@23
|
350
|
jcallahan@23
|
351 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@23
|
352 if not spell_id then
|
jcallahan@23
|
353 return
|
jcallahan@23
|
354 end
|
jcallahan@23
|
355 local source_type, source_id = WDP:ParseGUID(source_guid)
|
jcallahan@23
|
356
|
jcallahan@23
|
357 if not source_id or source_type ~= private.UNIT_TYPES.NPC then
|
jcallahan@23
|
358 return
|
jcallahan@23
|
359 end
|
jcallahan@23
|
360
|
jcallahan@23
|
361 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then
|
jcallahan@23
|
362 local npc = DBEntry("npcs", source_id)
|
jcallahan@23
|
363 local instance_token = InstanceDifficultyToken()
|
jcallahan@23
|
364 npc.spells = npc.spells or {}
|
jcallahan@23
|
365 npc.spells[instance_token] = npc.spells[instance_token] or {}
|
jcallahan@23
|
366 npc.spells[instance_token][spell_id] = true
|
jcallahan@23
|
367 end
|
jcallahan@23
|
368 end
|
jcallahan@23
|
369
|
jcallahan@23
|
370
|
jcallahan@23
|
371 local COMBAT_LOG_FUNCS = {
|
jcallahan@23
|
372 SPELL_AURA_APPLIED = RecordNPCSpell,
|
jcallahan@23
|
373 SPELL_CAST_START = RecordNPCSpell,
|
jcallahan@23
|
374 SPELL_CAST_SUCCESS = RecordNPCSpell,
|
jcallahan@23
|
375 UNIT_DISSIPATES = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags)
|
jcallahan@23
|
376 -- TODO: Write this.
|
jcallahan@23
|
377 end,
|
jcallahan@23
|
378 }
|
jcallahan@23
|
379
|
jcallahan@23
|
380
|
jcallahan@23
|
381 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...)
|
jcallahan@23
|
382 local combat_log_func = COMBAT_LOG_FUNCS[sub_event]
|
jcallahan@23
|
383
|
jcallahan@23
|
384 if not combat_log_func then
|
jcallahan@23
|
385 return
|
jcallahan@23
|
386 end
|
jcallahan@23
|
387 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...)
|
jcallahan@23
|
388 end
|
jcallahan@23
|
389 end -- do-block
|
jcallahan@23
|
390
|
jcallahan@23
|
391
|
jcallahan@18
|
392 function WDP:COMBAT_TEXT_UPDATE(event, message_type, faction_name, amount)
|
jcallahan@21
|
393 local npc = DBEntry("npcs", action_data.id_num)
|
jcallahan@21
|
394
|
jcallahan@21
|
395 if not npc then
|
jcallahan@21
|
396 return
|
jcallahan@21
|
397 end
|
jcallahan@22
|
398 npc.encounter_data[action_data.npc_level].reputations = npc.encounter_data[action_data.npc_level].reputations or {}
|
jcallahan@22
|
399 npc.encounter_data[action_data.npc_level].reputations[faction_name] = amount
|
jcallahan@18
|
400 end
|
jcallahan@18
|
401
|
jcallahan@18
|
402
|
jcallahan@13
|
403 function WDP:LOOT_CLOSED()
|
jcallahan@18
|
404 -- table.wipe(action_data)
|
jcallahan@0
|
405 end
|
jcallahan@0
|
406
|
jcallahan@0
|
407
|
jcallahan@13
|
408 do
|
jcallahan@13
|
409 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
410 local re_silver = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
411 local re_copper = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
412
|
jcallahan@13
|
413
|
jcallahan@13
|
414 local function _moneyMatch(money, re)
|
jcallahan@13
|
415 return money:match(re) or 0
|
jcallahan@1
|
416 end
|
jcallahan@1
|
417
|
jcallahan@0
|
418
|
jcallahan@13
|
419 local function _toCopper(money)
|
jcallahan@13
|
420 if not money then
|
jcallahan@13
|
421 return 0
|
jcallahan@13
|
422 end
|
jcallahan@0
|
423
|
jcallahan@13
|
424 return _moneyMatch(money, re_gold) * 10000 + _moneyMatch(money, re_silver) * 100 + _moneyMatch(money, re_copper)
|
jcallahan@1
|
425 end
|
jcallahan@1
|
426
|
jcallahan@1
|
427
|
jcallahan@13
|
428 local LOOT_VERIFY_FUNCS = {
|
jcallahan@16
|
429 [AF.ITEM] = function()
|
jcallahan@16
|
430 local locked_item_id
|
jcallahan@16
|
431
|
jcallahan@16
|
432 for bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@16
|
433 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@16
|
434 local _, _, is_locked = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@16
|
435
|
jcallahan@16
|
436 if is_locked then
|
jcallahan@16
|
437 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index))
|
jcallahan@16
|
438 end
|
jcallahan@16
|
439 end
|
jcallahan@16
|
440 end
|
jcallahan@16
|
441
|
jcallahan@16
|
442 if not locked_item_id or (action_data.item_id and action_data.item_id ~= locked_item_id) then
|
jcallahan@16
|
443 return false
|
jcallahan@16
|
444 end
|
jcallahan@16
|
445 action_data.item_id = locked_item_id
|
jcallahan@16
|
446 return true
|
jcallahan@16
|
447 end,
|
jcallahan@13
|
448 [AF.NPC] = function()
|
jcallahan@17
|
449 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@15
|
450 return false
|
jcallahan@13
|
451 end
|
jcallahan@15
|
452 local unit_type, id_num = WDP:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@15
|
453 action_data.id_num = id_num
|
jcallahan@13
|
454 return true
|
jcallahan@13
|
455 end,
|
jcallahan@14
|
456 [AF.OBJECT] = true,
|
jcallahan@17
|
457 [AF.ZONE] = function()
|
jcallahan@17
|
458 return action_data.loot_type and _G.IsFishingLoot()
|
jcallahan@17
|
459 end,
|
jcallahan@13
|
460 }
|
jcallahan@13
|
461
|
jcallahan@13
|
462
|
jcallahan@22
|
463 local function GenericLootUpdate(data_type)
|
jcallahan@22
|
464 local entry = DBEntry(data_type, action_data.id_num)
|
jcallahan@22
|
465
|
jcallahan@22
|
466 if not entry then
|
jcallahan@22
|
467 return
|
jcallahan@22
|
468 end
|
jcallahan@22
|
469 local loot_type = action_data.loot_type or "drops"
|
jcallahan@22
|
470 entry[loot_type] = entry[loot_type] or {}
|
jcallahan@22
|
471
|
jcallahan@22
|
472 for index = 1, #action_data.loot_list do
|
jcallahan@22
|
473 table.insert(entry[loot_type], action_data.loot_list[index])
|
jcallahan@22
|
474 end
|
jcallahan@22
|
475 end
|
jcallahan@22
|
476
|
jcallahan@22
|
477
|
jcallahan@13
|
478 local LOOT_UPDATE_FUNCS = {
|
jcallahan@16
|
479 [AF.ITEM] = function()
|
jcallahan@19
|
480 local item = DBEntry("items", action_data.item_id)
|
jcallahan@19
|
481 local loot_type = action_data.loot_type or "drops"
|
jcallahan@16
|
482 item[loot_type] = item[loot_type] or {}
|
jcallahan@16
|
483
|
jcallahan@17
|
484 for index = 1, #action_data.loot_list do
|
jcallahan@17
|
485 table.insert(item[loot_type], action_data.loot_list[index])
|
jcallahan@16
|
486 end
|
jcallahan@16
|
487 end,
|
jcallahan@13
|
488 [AF.NPC] = function()
|
jcallahan@22
|
489 GenericLootUpdate("npcs")
|
jcallahan@13
|
490 end,
|
jcallahan@13
|
491 [AF.OBJECT] = function()
|
jcallahan@22
|
492 GenericLootUpdate("objects")
|
jcallahan@17
|
493 end,
|
jcallahan@17
|
494 [AF.ZONE] = function()
|
jcallahan@17
|
495 local loot_type = action_data.loot_type or "drops"
|
jcallahan@19
|
496 local zone = DBEntry("zones", action_data.zone)
|
jcallahan@17
|
497 zone[loot_type] = zone[loot_type] or {}
|
jcallahan@17
|
498
|
jcallahan@22
|
499 local location_data = ("%s:%s:%s:%s"):format(action_data.instance_token, action_data.map_level, action_data.x, action_data.y)
|
jcallahan@17
|
500 local loot_data = zone[loot_type][location_data]
|
jcallahan@17
|
501
|
jcallahan@17
|
502 if not loot_data then
|
jcallahan@17
|
503 zone[loot_type][location_data] = {}
|
jcallahan@17
|
504 loot_data = zone[loot_type][location_data]
|
jcallahan@17
|
505 end
|
jcallahan@17
|
506
|
jcallahan@17
|
507 for index = 1, #action_data.loot_list do
|
jcallahan@17
|
508 table.insert(loot_data, action_data.loot_list[index])
|
jcallahan@13
|
509 end
|
jcallahan@13
|
510 end,
|
jcallahan@13
|
511 }
|
jcallahan@13
|
512
|
jcallahan@13
|
513
|
jcallahan@13
|
514 function WDP:LOOT_OPENED()
|
jcallahan@18
|
515 if action_data.looting then
|
jcallahan@18
|
516 return
|
jcallahan@18
|
517 end
|
jcallahan@18
|
518
|
jcallahan@13
|
519 if not action_data.type then
|
jcallahan@13
|
520 action_data.type = AF.NPC
|
jcallahan@1
|
521 end
|
jcallahan@13
|
522 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
|
jcallahan@13
|
523 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
|
jcallahan@13
|
524
|
jcallahan@14
|
525 if not verify_func or not update_func then
|
jcallahan@13
|
526 return
|
jcallahan@13
|
527 end
|
jcallahan@13
|
528
|
jcallahan@14
|
529 if _G.type(verify_func) == "function" and not verify_func() then
|
jcallahan@14
|
530 return
|
jcallahan@14
|
531 end
|
jcallahan@18
|
532 -- TODO: Remove this check once the MoP client goes live
|
jcallahan@18
|
533 local wow_version = private.wow_version
|
jcallahan@13
|
534 local loot_registry = {}
|
jcallahan@17
|
535 action_data.loot_list = {}
|
jcallahan@18
|
536 action_data.looting = true
|
jcallahan@13
|
537
|
jcallahan@18
|
538 if wow_version == "5.0.1" then
|
jcallahan@18
|
539 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@18
|
540 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@13
|
541
|
jcallahan@18
|
542 local slot_type = _G.GetLootSlotType(loot_slot)
|
jcallahan@18
|
543
|
jcallahan@18
|
544 if slot_type == _G.LOOT_SLOT_ITEM then
|
jcallahan@18
|
545 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@18
|
546 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@18
|
547 elseif slot_type == _G.LOOT_SLOT_MONEY then
|
jcallahan@18
|
548 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@18
|
549 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
|
jcallahan@18
|
550 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@18
|
551 end
|
jcallahan@18
|
552 end
|
jcallahan@18
|
553 else
|
jcallahan@18
|
554 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@18
|
555 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@18
|
556 if _G.LootSlotIsItem(loot_slot) then
|
jcallahan@18
|
557 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@18
|
558 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@18
|
559 elseif _G.LootSlotIsCoin(loot_slot) then
|
jcallahan@18
|
560 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@18
|
561 elseif _G.LootSlotIsCurrency(loot_slot) then
|
jcallahan@18
|
562 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@18
|
563 end
|
jcallahan@13
|
564 end
|
jcallahan@13
|
565 end
|
jcallahan@13
|
566
|
jcallahan@13
|
567 for item_id, quantity in pairs(loot_registry) do
|
jcallahan@17
|
568 table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity))
|
jcallahan@13
|
569 end
|
jcallahan@13
|
570 update_func()
|
jcallahan@1
|
571 end
|
jcallahan@13
|
572 end -- do-block
|
jcallahan@0
|
573
|
jcallahan@0
|
574
|
jcallahan@5
|
575 local POINT_MATCH_PATTERNS = {
|
jcallahan@5
|
576 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@5
|
577 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@5
|
578 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@5
|
579 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@5
|
580 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@5
|
581 }
|
jcallahan@5
|
582
|
jcallahan@5
|
583
|
jcallahan@7
|
584 function WDP:UpdateMerchantItems()
|
jcallahan@4
|
585 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@4
|
586
|
jcallahan@4
|
587 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@4
|
588 return
|
jcallahan@4
|
589 end
|
jcallahan@19
|
590 local merchant = DBEntry("npcs", unit_idnum)
|
jcallahan@6
|
591 merchant.sells = merchant.sells or {}
|
jcallahan@5
|
592
|
jcallahan@5
|
593 for item_index = 1, _G.GetMerchantNumItems() do
|
jcallahan@5
|
594 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
|
jcallahan@5
|
595 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
|
jcallahan@5
|
596
|
jcallahan@5
|
597 if item_id and item_id > 0 then
|
jcallahan@5
|
598 local price_string = copper_price
|
jcallahan@5
|
599
|
jcallahan@5
|
600 if extended_cost then
|
jcallahan@5
|
601 local bg_points = 0
|
jcallahan@5
|
602 local personal_points = 0
|
jcallahan@5
|
603
|
jcallahan@5
|
604 DatamineTT:ClearLines()
|
jcallahan@5
|
605 DatamineTT:SetMerchantItem(item_index)
|
jcallahan@5
|
606
|
jcallahan@5
|
607 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@5
|
608 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@5
|
609
|
jcallahan@5
|
610 if not current_line then
|
jcallahan@5
|
611 break
|
jcallahan@5
|
612 end
|
jcallahan@5
|
613 local breakout
|
jcallahan@5
|
614
|
jcallahan@5
|
615 for match_index = 1, #POINT_MATCH_PATTERNS do
|
jcallahan@5
|
616 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
|
jcallahan@5
|
617 personal_points = personal_points + (match1 or 0)
|
jcallahan@5
|
618 bg_points = bg_points + (match2 or 0)
|
jcallahan@5
|
619
|
jcallahan@5
|
620 if match1 or match2 then
|
jcallahan@5
|
621 breakout = true
|
jcallahan@5
|
622 break
|
jcallahan@5
|
623 end
|
jcallahan@5
|
624 end
|
jcallahan@5
|
625
|
jcallahan@5
|
626 if breakout then
|
jcallahan@5
|
627 break
|
jcallahan@5
|
628 end
|
jcallahan@5
|
629 end
|
jcallahan@5
|
630 local currency_list = {}
|
jcallahan@5
|
631
|
jcallahan@5
|
632 price_string = ("%s:%s:%s"):format(price_string, bg_points, personal_points)
|
jcallahan@5
|
633
|
jcallahan@5
|
634 for cost_index = 1, _G.GetMerchantItemCostInfo(item_index) do
|
jcallahan@5
|
635 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index)
|
jcallahan@5
|
636 local currency_id = currency_link and ItemLinkToID(currency_link) or nil
|
jcallahan@5
|
637
|
jcallahan@5
|
638 if not currency_id or currency_id < 1 then
|
jcallahan@5
|
639 if not icon_texture then
|
jcallahan@5
|
640 return
|
jcallahan@5
|
641 end
|
jcallahan@5
|
642 currency_id = icon_texture:match("[^\\]+$"):lower()
|
jcallahan@5
|
643 end
|
jcallahan@5
|
644 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id)
|
jcallahan@5
|
645 end
|
jcallahan@5
|
646
|
jcallahan@5
|
647 for currency_index = 1, #currency_list do
|
jcallahan@5
|
648 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
|
jcallahan@5
|
649 end
|
jcallahan@5
|
650 end
|
jcallahan@6
|
651 merchant.sells[("%s:%s:[%s]"):format(item_id, stack_size, price_string)] = num_available
|
jcallahan@5
|
652 end
|
jcallahan@4
|
653 end
|
jcallahan@14
|
654
|
jcallahan@14
|
655 if _G.CanMerchantRepair() then
|
jcallahan@14
|
656 merchant.can_repair = true
|
jcallahan@14
|
657 end
|
jcallahan@4
|
658 end
|
jcallahan@4
|
659
|
jcallahan@4
|
660
|
jcallahan@18
|
661 do
|
jcallahan@18
|
662 local GENDER_NAMES = {
|
jcallahan@18
|
663 "UNKNOWN",
|
jcallahan@18
|
664 "MALE",
|
jcallahan@18
|
665 "FEMALE",
|
jcallahan@18
|
666 }
|
jcallahan@2
|
667
|
jcallahan@2
|
668
|
jcallahan@18
|
669 local REACTION_NAMES = {
|
jcallahan@18
|
670 "HATED",
|
jcallahan@18
|
671 "HOSTILE",
|
jcallahan@18
|
672 "UNFRIENDLY",
|
jcallahan@18
|
673 "NEUTRAL",
|
jcallahan@18
|
674 "FRIENDLY",
|
jcallahan@18
|
675 "HONORED",
|
jcallahan@18
|
676 "REVERED",
|
jcallahan@18
|
677 "EXALTED",
|
jcallahan@18
|
678 }
|
jcallahan@2
|
679
|
jcallahan@2
|
680
|
jcallahan@18
|
681 local POWER_TYPE_NAMES = {
|
jcallahan@18
|
682 ["0"] = "MANA",
|
jcallahan@18
|
683 ["1"] = "RAGE",
|
jcallahan@18
|
684 ["2"] = "FOCUS",
|
jcallahan@18
|
685 ["3"] = "ENERGY",
|
jcallahan@18
|
686 ["6"] = "RUNIC_POWER",
|
jcallahan@18
|
687 }
|
jcallahan@2
|
688
|
jcallahan@2
|
689
|
jcallahan@18
|
690 function WDP:PLAYER_TARGET_CHANGED()
|
jcallahan@18
|
691 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@18
|
692 return
|
jcallahan@18
|
693 end
|
jcallahan@18
|
694 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
695
|
jcallahan@18
|
696 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@18
|
697 return
|
jcallahan@18
|
698 end
|
jcallahan@19
|
699 local npc = DBEntry("npcs", unit_idnum)
|
jcallahan@18
|
700 local _, class_token = _G.UnitClass("target")
|
jcallahan@18
|
701 npc.class = class_token
|
jcallahan@20
|
702
|
jcallahan@20
|
703 UpdateFactionNames()
|
jcallahan@20
|
704 DatamineTT:ClearLines()
|
jcallahan@20
|
705 DatamineTT:SetUnit("target")
|
jcallahan@20
|
706
|
jcallahan@20
|
707 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@20
|
708 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@20
|
709
|
jcallahan@20
|
710 if not current_line then
|
jcallahan@20
|
711 break
|
jcallahan@20
|
712 end
|
jcallahan@20
|
713 local line_text = current_line:GetText()
|
jcallahan@20
|
714
|
jcallahan@20
|
715 if faction_names[line_text] then
|
jcallahan@20
|
716 npc.faction = line_text
|
jcallahan@20
|
717 break
|
jcallahan@20
|
718 end
|
jcallahan@20
|
719 end
|
jcallahan@18
|
720 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"
|
jcallahan@18
|
721 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
|
jcallahan@18
|
722 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
|
jcallahan@22
|
723 npc.encounter_data = npc.encounter_data or {}
|
jcallahan@2
|
724
|
jcallahan@18
|
725 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
|
jcallahan@3
|
726
|
jcallahan@22
|
727 if not npc.encounter_data[npc_level] then
|
jcallahan@22
|
728 npc.encounter_data[npc_level] = {
|
jcallahan@18
|
729 max_health = _G.UnitHealthMax("target"),
|
jcallahan@18
|
730 }
|
jcallahan@3
|
731
|
jcallahan@18
|
732 local max_power = _G.UnitManaMax("target")
|
jcallahan@18
|
733
|
jcallahan@18
|
734 if max_power > 0 then
|
jcallahan@18
|
735 local power_type = _G.UnitPowerType("target")
|
jcallahan@22
|
736 npc.encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
|
jcallahan@18
|
737 end
|
jcallahan@3
|
738 end
|
jcallahan@21
|
739 table.wipe(action_data)
|
jcallahan@21
|
740 action_data.type = AF.NPC
|
jcallahan@21
|
741 action_data.id_num = unit_idnum
|
jcallahan@21
|
742 action_data.npc_level = npc_level
|
jcallahan@2
|
743 end
|
jcallahan@18
|
744 end -- do-block
|
jcallahan@2
|
745
|
jcallahan@12
|
746 do
|
jcallahan@12
|
747 local function UpdateQuestJuncture(point)
|
jcallahan@12
|
748 local unit_name = _G.UnitName("questnpc")
|
jcallahan@9
|
749
|
jcallahan@12
|
750 if not unit_name then
|
jcallahan@12
|
751 return
|
jcallahan@12
|
752 end
|
jcallahan@12
|
753 local unit_type, unit_id = WDP:ParseGUID(_G.UnitGUID("questnpc"))
|
jcallahan@9
|
754
|
jcallahan@12
|
755 if unit_type == private.UNIT_TYPES.OBJECT then
|
jcallahan@12
|
756 UpdateObjectLocation(unit_id)
|
jcallahan@12
|
757 end
|
jcallahan@19
|
758 local quest = DBEntry("quests", _G.GetQuestID())
|
jcallahan@12
|
759 quest[point] = quest[point] or {}
|
jcallahan@12
|
760 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
|
jcallahan@12
|
761 end
|
jcallahan@10
|
762
|
jcallahan@12
|
763
|
jcallahan@12
|
764 function WDP:QUEST_COMPLETE()
|
jcallahan@12
|
765 UpdateQuestJuncture("end")
|
jcallahan@10
|
766 end
|
jcallahan@10
|
767
|
jcallahan@12
|
768
|
jcallahan@12
|
769 function WDP:QUEST_DETAIL()
|
jcallahan@12
|
770 UpdateQuestJuncture("begin")
|
jcallahan@10
|
771 end
|
jcallahan@12
|
772 end -- do-block
|
jcallahan@9
|
773
|
jcallahan@9
|
774
|
jcallahan@4
|
775 function WDP:QUEST_LOG_UPDATE()
|
jcallahan@4
|
776 self:UnregisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
777 end
|
jcallahan@4
|
778
|
jcallahan@4
|
779
|
jcallahan@4
|
780 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id)
|
jcallahan@4
|
781 if unit_id ~= "player" then
|
jcallahan@4
|
782 return
|
jcallahan@4
|
783 end
|
jcallahan@4
|
784 self:RegisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
785 end
|
jcallahan@4
|
786
|
jcallahan@4
|
787
|
jcallahan@1
|
788 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
|
jcallahan@1
|
789 if private.tracked_line or unit_id ~= "player" then
|
jcallahan@1
|
790 return
|
jcallahan@1
|
791 end
|
jcallahan@1
|
792 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
|
jcallahan@1
|
793
|
jcallahan@1
|
794 if not spell_label then
|
jcallahan@1
|
795 return
|
jcallahan@1
|
796 end
|
jcallahan@18
|
797 table.wipe(action_data)
|
jcallahan@1
|
798
|
jcallahan@1
|
799 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
|
jcallahan@1
|
800 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
|
jcallahan@1
|
801
|
jcallahan@1
|
802 if not tt_unit_name and _G.UnitName("target") == target_name then
|
jcallahan@1
|
803 tt_unit_name = target_name
|
jcallahan@1
|
804 tt_unit_id = "target"
|
jcallahan@1
|
805 end
|
jcallahan@1
|
806 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
|
jcallahan@1
|
807
|
jcallahan@16
|
808 if tt_unit_name and not tt_item_name then
|
jcallahan@16
|
809 if bit.band(spell_flags, AF.NPC) == AF.NPC then
|
jcallahan@16
|
810 if not tt_unit_id or tt_unit_name ~= target_name then
|
jcallahan@16
|
811 return
|
jcallahan@16
|
812 end
|
jcallahan@16
|
813 action_data.type = AF.NPC
|
jcallahan@16
|
814 action_data.loot_type = spell_label:lower()
|
jcallahan@16
|
815 end
|
jcallahan@16
|
816 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
|
jcallahan@16
|
817 action_data.type = AF.ITEM
|
jcallahan@16
|
818 action_data.loot_type = spell_label:lower()
|
jcallahan@16
|
819
|
jcallahan@16
|
820 if tt_item_name and tt_item_name == target_name then
|
jcallahan@16
|
821 action_data.item_id = ItemLinkToID(tt_item_link)
|
jcallahan@16
|
822 elseif target_name and target_name ~= "" then
|
jcallahan@16
|
823 local _, target_item_link = _G.GetItemInfo(target_name)
|
jcallahan@16
|
824 action_data.item_id = ItemLinkToID(target_item_link)
|
jcallahan@16
|
825 end
|
jcallahan@16
|
826 elseif not tt_item_name and not tt_unit_name then
|
jcallahan@22
|
827 local zone_name, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@1
|
828
|
jcallahan@22
|
829 action_data.instance_token = instance_token
|
jcallahan@17
|
830 action_data.map_level = map_level
|
jcallahan@17
|
831 action_data.name = target_name
|
jcallahan@17
|
832 action_data.x = x
|
jcallahan@17
|
833 action_data.y = y
|
jcallahan@17
|
834 action_data.zone = zone_name
|
jcallahan@17
|
835
|
jcallahan@1
|
836 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
|
jcallahan@17
|
837 if target_name == "" then
|
jcallahan@17
|
838 return
|
jcallahan@17
|
839 end
|
jcallahan@11
|
840 local identifier = ("%s:%s"):format(spell_label, target_name)
|
jcallahan@11
|
841 UpdateObjectLocation(identifier)
|
jcallahan@11
|
842
|
jcallahan@1
|
843 action_data.type = AF.OBJECT
|
jcallahan@11
|
844 action_data.identifier = identifier
|
jcallahan@1
|
845 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
|
jcallahan@17
|
846 action_data.type = AF.ZONE
|
jcallahan@17
|
847 action_data.loot_type = spell_label:lower()
|
jcallahan@1
|
848 end
|
jcallahan@1
|
849 end
|
jcallahan@1
|
850
|
jcallahan@18
|
851 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line))
|
jcallahan@1
|
852 private.tracked_line = spell_line
|
jcallahan@0
|
853 end
|
jcallahan@0
|
854
|
jcallahan@0
|
855
|
jcallahan@1
|
856 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
857 if unit_id ~= "player" then
|
jcallahan@1
|
858 return
|
jcallahan@1
|
859 end
|
jcallahan@1
|
860
|
jcallahan@18
|
861 -- if private.SPELL_LABELS_BY_NAME[spell_name] then
|
jcallahan@18
|
862 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id))
|
jcallahan@18
|
863 -- end
|
jcallahan@1
|
864 private.tracked_line = nil
|
jcallahan@0
|
865 end
|
jcallahan@0
|
866
|
jcallahan@1
|
867 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
868 if unit_id ~= "player" then
|
jcallahan@1
|
869 return
|
jcallahan@1
|
870 end
|
jcallahan@0
|
871
|
jcallahan@1
|
872 if private.tracked_line == spell_line then
|
jcallahan@1
|
873 private.tracked_line = nil
|
jcallahan@1
|
874 end
|
jcallahan@0
|
875 end
|