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