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@0
|
22
|
jcallahan@0
|
23 -----------------------------------------------------------------------
|
jcallahan@0
|
24 -- Local constants.
|
jcallahan@0
|
25 -----------------------------------------------------------------------
|
jcallahan@0
|
26 local DATABASE_DEFAULTS = {
|
jcallahan@0
|
27 global = {
|
jcallahan@0
|
28 items = {},
|
jcallahan@0
|
29 npcs = {},
|
jcallahan@0
|
30 objects = {},
|
jcallahan@0
|
31 quests = {},
|
jcallahan@0
|
32 }
|
jcallahan@0
|
33 }
|
jcallahan@0
|
34
|
jcallahan@0
|
35
|
jcallahan@1
|
36 local EVENT_MAPPING = {
|
jcallahan@1
|
37 -- ARTIFACT_COMPLETE = true,
|
jcallahan@0
|
38 -- ARTIFACT_HISTORY_READY = true,
|
jcallahan@0
|
39 -- AUCTION_HOUSE_SHOW = true,
|
jcallahan@0
|
40 -- BANKFRAME_OPENED = true,
|
jcallahan@0
|
41 -- BATTLEFIELDS_SHOW = true,
|
jcallahan@0
|
42 -- CHAT_MSG_ADDON = true,
|
jcallahan@0
|
43 -- CHAT_MSG_MONSTER_EMOTE = true,
|
jcallahan@0
|
44 -- CHAT_MSG_MONSTER_SAY = true,
|
jcallahan@0
|
45 -- CHAT_MSG_MONSTER_WHISPER = true,
|
jcallahan@0
|
46 -- CHAT_MSG_MONSTER_YELL = true,
|
jcallahan@0
|
47 -- CHAT_MSG_SYSTEM = true,
|
jcallahan@0
|
48 -- COMBAT_LOG_EVENT_UNFILTERED = true,
|
jcallahan@0
|
49 -- COMBAT_TEXT_UPDATE = true,
|
jcallahan@0
|
50 -- CONFIRM_BINDER = true,
|
jcallahan@0
|
51 -- CONFIRM_PET_UNLEARN = true,
|
jcallahan@0
|
52 -- CONFIRM_TALENT_WIPE = true,
|
jcallahan@0
|
53 -- CURRENCY_DISPLAY_UPDATE = true,
|
jcallahan@0
|
54 -- GOSSIP_ENTER_CODE = true,
|
jcallahan@0
|
55 -- GOSSIP_SHOW = true,
|
jcallahan@0
|
56 -- ITEM_TEXT_BEGIN = true,
|
jcallahan@0
|
57 -- LOCALPLAYER_PET_RENAMED = true,
|
jcallahan@0
|
58 -- LOOT_CLOSED = true,
|
jcallahan@1
|
59 LOOT_OPENED = true,
|
jcallahan@0
|
60 -- MAIL_SHOW = true,
|
jcallahan@0
|
61 -- MERCHANT_SHOW = true,
|
jcallahan@0
|
62 -- MERCHANT_UPDATE = true,
|
jcallahan@0
|
63 -- OPEN_TABARD_FRAME = true,
|
jcallahan@0
|
64 -- PET_BAR_UPDATE = true,
|
jcallahan@0
|
65 -- PET_STABLE_SHOW = true,
|
jcallahan@0
|
66 -- PLAYER_ALIVE = true,
|
jcallahan@0
|
67 -- PLAYER_ENTERING_WORLD = HandleZoneChange,
|
jcallahan@0
|
68 -- PLAYER_LOGIN = true,
|
jcallahan@0
|
69 -- PLAYER_LOGOUT = true,
|
jcallahan@2
|
70 PLAYER_TARGET_CHANGED = true,
|
jcallahan@0
|
71 -- QUEST_COMPLETE = true,
|
jcallahan@0
|
72 -- QUEST_DETAIL = true,
|
jcallahan@0
|
73 -- QUEST_LOG_UPDATE = true,
|
jcallahan@0
|
74 -- QUEST_PROGRESS = true,
|
jcallahan@0
|
75 -- TAXIMAP_OPENED = true,
|
jcallahan@0
|
76 -- TRADE_SKILL_SHOW = true,
|
jcallahan@0
|
77 -- TRADE_SKILL_UPDATE = true,
|
jcallahan@0
|
78 -- TRAINER_SHOW = true,
|
jcallahan@0
|
79 -- UNIT_QUEST_LOG_CHANGED = true,
|
jcallahan@1
|
80 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
|
jcallahan@1
|
81 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
|
jcallahan@1
|
82 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
|
jcallahan@1
|
83 UNIT_SPELLCAST_SENT = true,
|
jcallahan@1
|
84 UNIT_SPELLCAST_SUCCEEDED = true,
|
jcallahan@0
|
85 -- ZONE_CHANGED = HandleZoneChange,
|
jcallahan@0
|
86 -- ZONE_CHANGED_NEW_AREA = HandleZoneChange,
|
jcallahan@0
|
87 }
|
jcallahan@0
|
88
|
jcallahan@1
|
89 local AF = private.ACTION_TYPE_FLAGS
|
jcallahan@0
|
90
|
jcallahan@0
|
91 -----------------------------------------------------------------------
|
jcallahan@0
|
92 -- Local variables.
|
jcallahan@0
|
93 -----------------------------------------------------------------------
|
jcallahan@0
|
94 local db
|
jcallahan@0
|
95 local durability_timer_handle
|
jcallahan@2
|
96 local target_location_timer_handle
|
jcallahan@1
|
97 local action_data = {}
|
jcallahan@0
|
98
|
jcallahan@1
|
99 do
|
jcallahan@1
|
100 local UNIT_TYPE_BITMASK = 0x007
|
jcallahan@1
|
101
|
jcallahan@1
|
102 function WDP:ParseGUID(guid)
|
jcallahan@1
|
103 local types = private.UNIT_TYPES
|
jcallahan@1
|
104 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
|
jcallahan@1
|
105
|
jcallahan@1
|
106 if unit_type ~= types.PLAYER or unit_type ~= types.OBJECT or unit_type ~= types.PET then
|
jcallahan@1
|
107 return unit_type, tonumber(guid:sub(-12, -9), 16)
|
jcallahan@1
|
108 end
|
jcallahan@1
|
109
|
jcallahan@1
|
110 return unit_type
|
jcallahan@1
|
111 end
|
jcallahan@1
|
112 end -- do-block
|
jcallahan@1
|
113
|
jcallahan@1
|
114
|
jcallahan@1
|
115 -----------------------------------------------------------------------
|
jcallahan@1
|
116 -- Helper Functions.
|
jcallahan@1
|
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@2
|
141 return _G.GetRealZoneText(), ("%.2f"):format(x * 100), ("%.2f"):format(y * 100), map_level or 0
|
jcallahan@1
|
142 end
|
jcallahan@1
|
143
|
jcallahan@1
|
144
|
jcallahan@1
|
145 local function ItemLinkToID(item_link)
|
jcallahan@1
|
146 if not item_link then
|
jcallahan@1
|
147 return
|
jcallahan@1
|
148 end
|
jcallahan@1
|
149 local id = item_link:match("item:(%d+)")
|
jcallahan@1
|
150 return id and tonumber(id) or nil
|
jcallahan@1
|
151 end
|
jcallahan@0
|
152
|
jcallahan@0
|
153 -----------------------------------------------------------------------
|
jcallahan@0
|
154 -- Methods.
|
jcallahan@0
|
155 -----------------------------------------------------------------------
|
jcallahan@0
|
156 function WDP:OnInitialize()
|
jcallahan@0
|
157 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
|
jcallahan@0
|
158 end
|
jcallahan@0
|
159
|
jcallahan@0
|
160
|
jcallahan@0
|
161 function WDP:OnEnable()
|
jcallahan@0
|
162 for event_name, mapping in pairs(EVENT_MAPPING) do
|
jcallahan@1
|
163 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
|
jcallahan@0
|
164 end
|
jcallahan@0
|
165 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
|
jcallahan@2
|
166 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.2)
|
jcallahan@0
|
167 end
|
jcallahan@0
|
168
|
jcallahan@0
|
169
|
jcallahan@0
|
170 local function RecordDurability(item_id, durability)
|
jcallahan@0
|
171 if not durability or durability <= 0 then
|
jcallahan@0
|
172 return
|
jcallahan@0
|
173 end
|
jcallahan@0
|
174
|
jcallahan@0
|
175 if not db.items[item_id] then
|
jcallahan@0
|
176 db.items[item_id] = {}
|
jcallahan@0
|
177 end
|
jcallahan@0
|
178 db.items[item_id].durability = durability
|
jcallahan@0
|
179 end
|
jcallahan@0
|
180
|
jcallahan@0
|
181
|
jcallahan@0
|
182 function WDP:ProcessDurability()
|
jcallahan@0
|
183 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
|
jcallahan@1
|
184 local item_id = _G.GetInventoryItemID("player", slot_index)
|
jcallahan@0
|
185
|
jcallahan@0
|
186 if item_id and item_id > 0 then
|
jcallahan@1
|
187 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
|
jcallahan@0
|
188 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
189 end
|
jcallahan@0
|
190 end
|
jcallahan@0
|
191
|
jcallahan@0
|
192 for bag_index = 0, _G.NUM_BAG_SLOTS do
|
jcallahan@0
|
193 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@1
|
194 local item_id = _G.GetContainerItemID(bag_index, slot_index)
|
jcallahan@0
|
195
|
jcallahan@0
|
196 if item_id and item_id > 0 then
|
jcallahan@1
|
197 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
|
jcallahan@0
|
198 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
199 end
|
jcallahan@0
|
200 end
|
jcallahan@0
|
201 end
|
jcallahan@0
|
202 end
|
jcallahan@0
|
203
|
jcallahan@0
|
204
|
jcallahan@2
|
205 function WDP:UpdateTargetLocation()
|
jcallahan@2
|
206 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or _G.UnitIsTapped("target") then
|
jcallahan@2
|
207 return
|
jcallahan@2
|
208 end
|
jcallahan@2
|
209
|
jcallahan@2
|
210 for index = 1, 4 do
|
jcallahan@2
|
211 if not _G.CheckInteractDistance("target", index) then
|
jcallahan@2
|
212 return
|
jcallahan@2
|
213 end
|
jcallahan@2
|
214 end
|
jcallahan@2
|
215
|
jcallahan@2
|
216 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
217
|
jcallahan@2
|
218 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@2
|
219 return
|
jcallahan@2
|
220 end
|
jcallahan@2
|
221 local zone_name, x, y, map_level = CurrentLocationData()
|
jcallahan@2
|
222 local npc_data = db.npcs[unit_idnum].stats[("level_%d"):format(_G.UnitLevel("target"))]
|
jcallahan@2
|
223
|
jcallahan@2
|
224 if not npc_data.locations then
|
jcallahan@2
|
225 npc_data.locations = {}
|
jcallahan@2
|
226 end
|
jcallahan@2
|
227
|
jcallahan@2
|
228 if not npc_data.locations[zone_name] then
|
jcallahan@2
|
229 npc_data.locations[zone_name] = {}
|
jcallahan@2
|
230 end
|
jcallahan@2
|
231 npc_data.locations[zone_name][("%s:%s:%s"):format(map_level, x, y)] = true
|
jcallahan@2
|
232 end
|
jcallahan@2
|
233
|
jcallahan@2
|
234
|
jcallahan@0
|
235 -----------------------------------------------------------------------
|
jcallahan@0
|
236 -- Event handlers.
|
jcallahan@0
|
237 -----------------------------------------------------------------------
|
jcallahan@1
|
238 function WDP:CHAT_MSG_SYSTEM(event_name, message, sender_name, language)
|
jcallahan@0
|
239 end
|
jcallahan@0
|
240
|
jcallahan@0
|
241
|
jcallahan@1
|
242 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@1
|
243 local re_silver = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@1
|
244 local re_copper = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@1
|
245
|
jcallahan@1
|
246
|
jcallahan@1
|
247 local function _moneyMatch(money, re)
|
jcallahan@1
|
248 return money:match(re) or 0
|
jcallahan@0
|
249 end
|
jcallahan@0
|
250
|
jcallahan@0
|
251
|
jcallahan@1
|
252 local function _toCopper(money)
|
jcallahan@1
|
253 if not money then
|
jcallahan@1
|
254 return 0
|
jcallahan@1
|
255 end
|
jcallahan@1
|
256
|
jcallahan@1
|
257 return _moneyMatch(money, re_gold) * 10000 + _moneyMatch(money, re_silver) * 100 + _moneyMatch(money, re_copper)
|
jcallahan@0
|
258 end
|
jcallahan@0
|
259
|
jcallahan@0
|
260
|
jcallahan@1
|
261 local LOOT_VERIFY_FUNCS = {
|
jcallahan@1
|
262 [AF.NPC] = function()
|
jcallahan@1
|
263 local fishing_loot = _G.IsFishingLoot()
|
jcallahan@1
|
264
|
jcallahan@1
|
265 if not fishing_loot and _G.UnitExists("target") and not _G.UnitIsFriend("player", "target") and _G.UnitIsDead("target") then
|
jcallahan@1
|
266 if _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@1
|
267 return false
|
jcallahan@1
|
268 end
|
jcallahan@1
|
269 local unit_type, id_num = WDP:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@1
|
270 action_data.id_num = id_num
|
jcallahan@1
|
271 end
|
jcallahan@1
|
272 return true
|
jcallahan@1
|
273 end,
|
jcallahan@1
|
274 }
|
jcallahan@1
|
275
|
jcallahan@1
|
276 local LOOT_UPDATE_FUNCS = {
|
jcallahan@1
|
277 [AF.NPC] = function()
|
jcallahan@1
|
278 local npc = db.npcs[action_data.id_num]
|
jcallahan@1
|
279
|
jcallahan@1
|
280 if not npc then
|
jcallahan@1
|
281 db.npcs[action_data.id_num] = {}
|
jcallahan@1
|
282 npc = db.npcs[action_data.id_num]
|
jcallahan@1
|
283 end
|
jcallahan@1
|
284 npc.drops = npc.drops or {}
|
jcallahan@1
|
285
|
jcallahan@1
|
286 for index = 1, #action_data.drops do
|
jcallahan@1
|
287 table.insert(npc.drops, action_data.drops[index])
|
jcallahan@1
|
288 end
|
jcallahan@1
|
289 end,
|
jcallahan@1
|
290 }
|
jcallahan@1
|
291
|
jcallahan@1
|
292
|
jcallahan@1
|
293 function WDP:LOOT_OPENED()
|
jcallahan@1
|
294 if not action_data.type then
|
jcallahan@1
|
295 action_data.type = AF.NPC
|
jcallahan@1
|
296 end
|
jcallahan@1
|
297 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
|
jcallahan@2
|
298 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
|
jcallahan@1
|
299
|
jcallahan@1
|
300 if not verify_func or not update_func or not verify_func() then
|
jcallahan@1
|
301 return
|
jcallahan@1
|
302 end
|
jcallahan@1
|
303
|
jcallahan@1
|
304 local loot_registry = {}
|
jcallahan@1
|
305 action_data.drops = {}
|
jcallahan@1
|
306
|
jcallahan@1
|
307 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@1
|
308 local texture, item, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@1
|
309
|
jcallahan@1
|
310 if _G.LootSlotIsItem(loot_slot) then
|
jcallahan@1
|
311 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@1
|
312 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@1
|
313 elseif _G.LootSlotIsCoin(loot_slot) then
|
jcallahan@1
|
314 table.insert(action_data.drops, ("money:%d"):format(_toCopper(item)))
|
jcallahan@1
|
315 elseif _G.LootSlotIsCurrency(loot_slot) then
|
jcallahan@1
|
316 end
|
jcallahan@1
|
317 end
|
jcallahan@1
|
318
|
jcallahan@1
|
319 for item_id, quantity in pairs(loot_registry) do
|
jcallahan@1
|
320 table.insert(action_data.drops, ("%d:%d"):format(item_id, quantity))
|
jcallahan@1
|
321 end
|
jcallahan@1
|
322 update_func()
|
jcallahan@0
|
323 end
|
jcallahan@0
|
324
|
jcallahan@0
|
325
|
jcallahan@2
|
326 local GENDER_NAMES = {
|
jcallahan@2
|
327 "UNKNOWN",
|
jcallahan@2
|
328 "MALE",
|
jcallahan@2
|
329 "FEMALE",
|
jcallahan@2
|
330 }
|
jcallahan@2
|
331
|
jcallahan@2
|
332
|
jcallahan@2
|
333 local REACTION_NAMES = {
|
jcallahan@2
|
334 "HATED",
|
jcallahan@2
|
335 "HOSTILE",
|
jcallahan@2
|
336 "UNFRIENDLY",
|
jcallahan@2
|
337 "NEUTRAL",
|
jcallahan@2
|
338 "FRIENDLY",
|
jcallahan@2
|
339 "HONORED",
|
jcallahan@2
|
340 "REVERED",
|
jcallahan@2
|
341 "EXALTED",
|
jcallahan@2
|
342 }
|
jcallahan@2
|
343
|
jcallahan@2
|
344
|
jcallahan@2
|
345 local POWER_TYPE_NAMES = {
|
jcallahan@2
|
346 ["0"] = "MANA",
|
jcallahan@2
|
347 ["1"] = "RAGE",
|
jcallahan@2
|
348 ["2"] = "FOCUS",
|
jcallahan@2
|
349 ["3"] = "ENERGY",
|
jcallahan@2
|
350 ["6"] = "RUNIC_POWER",
|
jcallahan@2
|
351 }
|
jcallahan@2
|
352
|
jcallahan@2
|
353
|
jcallahan@2
|
354 function WDP:PLAYER_TARGET_CHANGED()
|
jcallahan@2
|
355 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@2
|
356 return
|
jcallahan@2
|
357 end
|
jcallahan@2
|
358 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
359
|
jcallahan@2
|
360 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@2
|
361 return
|
jcallahan@2
|
362 end
|
jcallahan@2
|
363
|
jcallahan@2
|
364 local npc = db.npcs[unit_idnum]
|
jcallahan@2
|
365
|
jcallahan@2
|
366 if not npc then
|
jcallahan@2
|
367 db.npcs[unit_idnum] = {}
|
jcallahan@2
|
368 npc = db.npcs[unit_idnum]
|
jcallahan@2
|
369 end
|
jcallahan@2
|
370 local _, class_token = _G.UnitClass("target")
|
jcallahan@2
|
371 npc.class = class_token
|
jcallahan@2
|
372 -- TODO: Add faction here
|
jcallahan@2
|
373 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"
|
jcallahan@3
|
374 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
|
jcallahan@2
|
375 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
|
jcallahan@2
|
376 npc.stats = npc.stats or {}
|
jcallahan@2
|
377
|
jcallahan@2
|
378 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
|
jcallahan@2
|
379
|
jcallahan@2
|
380 if not npc.stats[npc_level] then
|
jcallahan@2
|
381 npc.stats[npc_level] = {
|
jcallahan@2
|
382 max_health = _G.UnitHealthMax("target"),
|
jcallahan@2
|
383 }
|
jcallahan@3
|
384
|
jcallahan@3
|
385 local max_power = _G.UnitManaMax("target")
|
jcallahan@3
|
386
|
jcallahan@3
|
387 if max_power > 0 then
|
jcallahan@3
|
388 local power_type = _G.UnitPowerType("target")
|
jcallahan@3
|
389 npc.stats[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
|
jcallahan@3
|
390 end
|
jcallahan@2
|
391 end
|
jcallahan@2
|
392 end
|
jcallahan@2
|
393
|
jcallahan@2
|
394
|
jcallahan@1
|
395 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
|
jcallahan@1
|
396 if private.tracked_line or unit_id ~= "player" then
|
jcallahan@1
|
397 return
|
jcallahan@1
|
398 end
|
jcallahan@1
|
399 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
|
jcallahan@1
|
400
|
jcallahan@1
|
401 if not spell_label then
|
jcallahan@1
|
402 return
|
jcallahan@1
|
403 end
|
jcallahan@1
|
404 action_data.type = nil -- This will be set as appropriate below
|
jcallahan@1
|
405
|
jcallahan@1
|
406 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
|
jcallahan@1
|
407 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
|
jcallahan@1
|
408
|
jcallahan@1
|
409 if not tt_unit_name and _G.UnitName("target") == target_name then
|
jcallahan@1
|
410 tt_unit_name = target_name
|
jcallahan@1
|
411 tt_unit_id = "target"
|
jcallahan@1
|
412 end
|
jcallahan@1
|
413 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
|
jcallahan@1
|
414
|
jcallahan@1
|
415 if not tt_item_name and not tt_unit_name then
|
jcallahan@1
|
416 if target_name == "" then
|
jcallahan@1
|
417 return
|
jcallahan@1
|
418 end
|
jcallahan@1
|
419
|
jcallahan@1
|
420 local zone_name, x, y, map_level = CurrentLocationData()
|
jcallahan@1
|
421
|
jcallahan@1
|
422 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
|
jcallahan@1
|
423 action_data.map_level = map_level
|
jcallahan@1
|
424 action_data.name = target_name
|
jcallahan@1
|
425 action_data.type = AF.OBJECT
|
jcallahan@1
|
426 action_data.x = x
|
jcallahan@1
|
427 action_data.y = y
|
jcallahan@1
|
428 action_data.zone = zone_name
|
jcallahan@2
|
429 print(("Found spell flagged for OBJECT: %s (%s, %s)"):format(zone_name, x, y))
|
jcallahan@1
|
430 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
|
jcallahan@1
|
431 print("Found spell flagged for ZONE")
|
jcallahan@1
|
432 end
|
jcallahan@1
|
433 elseif tt_unit_name and not tt_item_name then
|
jcallahan@1
|
434 if bit.band(spell_flags, AF.NPC) == AF.NPC then
|
jcallahan@1
|
435 print("Found spell flagged for NPC")
|
jcallahan@1
|
436 end
|
jcallahan@1
|
437 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
|
jcallahan@1
|
438 print("Found spell flagged for ITEM")
|
jcallahan@1
|
439 else
|
jcallahan@1
|
440 print(("%s: We have an issue with types and flags."), event_name)
|
jcallahan@1
|
441 end
|
jcallahan@1
|
442
|
jcallahan@1
|
443 print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line))
|
jcallahan@1
|
444 private.tracked_line = spell_line
|
jcallahan@0
|
445 end
|
jcallahan@0
|
446
|
jcallahan@0
|
447
|
jcallahan@1
|
448 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
449 if unit_id ~= "player" then
|
jcallahan@1
|
450 return
|
jcallahan@1
|
451 end
|
jcallahan@1
|
452
|
jcallahan@1
|
453 if action_data.type == AF.OBJECT then
|
jcallahan@1
|
454 end
|
jcallahan@1
|
455
|
jcallahan@1
|
456 if private.SPELL_LABELS_BY_NAME[spell_name] then
|
jcallahan@1
|
457 print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id))
|
jcallahan@1
|
458 end
|
jcallahan@1
|
459 private.tracked_line = nil
|
jcallahan@0
|
460 end
|
jcallahan@0
|
461
|
jcallahan@1
|
462 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
463 if unit_id ~= "player" then
|
jcallahan@1
|
464 return
|
jcallahan@1
|
465 end
|
jcallahan@0
|
466
|
jcallahan@1
|
467 if private.tracked_line == spell_line then
|
jcallahan@1
|
468 private.tracked_line = nil
|
jcallahan@1
|
469 end
|
jcallahan@0
|
470 end
|