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