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