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