vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- CountDoom |
2 | -- Author: Scrum |
||
3 | -- based on work by Justin Milligan |
||
4 | |||
5 | |||
6 | -- USEFUL STUFF |
||
7 | -- isDemon = UnitCreatureType("target") == "Demon" |
||
8 | -- isElemental = UnitCreatureType("target") == "Elemental" |
||
9 | -- local targetName = UnitName("target"); |
||
10 | -- TargetByName( targetName ) |
||
11 | |||
12 | |||
13 | CD_DefaultConfig = {}; |
||
14 | -- 0.3 config items |
||
15 | CD_DefaultConfig.isLocked = true; |
||
16 | CD_DefaultConfig.announceSpells = "never"; |
||
17 | CD_DefaultConfig.playSounds = true; |
||
18 | CD_DefaultConfig.flashSpells = true; |
||
19 | CD_DefaultConfig.enable = true; |
||
20 | CD_DefaultConfig.layout = "vertical"; |
||
21 | CD_DefaultConfig.scale = "small"; |
||
22 | CD_DefaultConfig.hseconds = false; |
||
23 | CD_DefaultConfig.postExpireDelay = 0; |
||
24 | CD_DefaultConfig.outofcombatDelay = 0; |
||
25 | CD_DefaultConfig.announceChannel = nil; |
||
26 | |||
27 | CountDoom = {}; |
||
28 | CountDoom.debugVerbose = false; |
||
29 | CountDoom.debugEvents = false; |
||
30 | CountDoom.initialized = false; |
||
31 | CountDoom.playerName = nil; |
||
32 | CountDoom.realmName = nil; |
||
33 | CountDoom.activeSpell = nil; |
||
34 | CountDoom.soundPath = "Interface\\AddOns\\CountDoom\\"; |
||
35 | CountDoom.targetID = 0; |
||
36 | CountDoom.targetName = nil; |
||
37 | CountDoom.activeSpell = nil; |
||
38 | CountDoom.totalTime = 0; |
||
39 | CountDoom.activeSpellWaitingForTarget = nil; |
||
40 | CountDoom.petTargetName = nil; |
||
41 | CountDoom.petTargeLevel = 0; |
||
42 | CountDoom.petActiveSpell = nil; |
||
43 | CountDoom.lastSpellID = -1; |
||
44 | CountDoom.spellRank = nil; |
||
45 | CountDoom.timeRemoveAllTimers = nil; |
||
46 | CountDoom.event = {}; |
||
47 | CountDoom.event.castSpellName = nil; |
||
48 | CountDoom.event.castMode = nil; |
||
49 | CountDoom.event.castTarget = nil; |
||
50 | CountDoom.event.removedSpellName = nil; |
||
51 | CountDoom.event.removedLastReason = nil; |
||
52 | CountDoom.event.removedTarget = nil; |
||
53 | |||
54 | |||
55 | CountDoom.prt = function( msg, r, g, b ) |
||
56 | local msgOutput = DEFAULT_CHAT_FRAME; |
||
57 | if( msgOutput ) then |
||
58 | msgOutput:AddMessage( msg, r, g, b ); |
||
59 | end |
||
60 | end; |
||
61 | |||
62 | |||
63 | CountDoom.CombatPrint = function( msg, r, g, b ) |
||
64 | local msgOutput = ChatFrame2; |
||
65 | if( msgOutput ) then |
||
66 | msgOutput:AddMessage( msg, r, g, b ); |
||
67 | end |
||
68 | end; |
||
69 | |||
70 | |||
71 | CountDoom.dpf = function(arg1) |
||
72 | if (CountDoom.debugVerbose) then |
||
73 | CountDoom.prt("CountDoom<DEBUG>: " .. arg1); |
||
74 | debuginfo( arg1 ); |
||
75 | end |
||
76 | end; |
||
77 | |||
78 | |||
79 | CountDoom.ToStr = function(arg1) |
||
80 | local argType = type( arg1 ); |
||
81 | |||
82 | if argType == "nil" then |
||
83 | return "nil"; |
||
84 | elseif argType == "boolean" then |
||
85 | if arg1 then |
||
86 | return COUNTDOOM_TRUE; |
||
87 | else |
||
88 | return COUNTDOOM_FALSE; |
||
89 | end |
||
90 | else |
||
91 | return "" .. arg1; |
||
92 | end |
||
93 | end; |
||
94 | |||
95 | |||
96 | CountDoom.DisplaySettings = function() |
||
97 | CountDoom.prt( "Locked: " .. CountDoom.ToStr( CountDoom.config.isLocked ) ); |
||
98 | CountDoom.prt( "Announce Spells: " .. CountDoom.ToStr( CountDoom.config.announceSpells ) ); |
||
99 | CountDoom.prt( "Announce channel: " .. CountDoom.ToStr( CountDoom.config.announceChannel ) ); |
||
100 | CountDoom.prt( "Flash Spells: " .. CountDoom.ToStr( CountDoom.config.flashSpells ) ); |
||
101 | CountDoom.prt( "Play sounds: " .. CountDoom.ToStr( CountDoom.config.playSounds ) ); |
||
102 | CountDoom.prt( "Layout: " .. CountDoom.ToStr( CountDoom.config.layout ) ); |
||
103 | CountDoom.prt( "Scale: " .. CountDoom.ToStr( CountDoom.config.scale ) ); |
||
104 | CountDoom.prt( "Out of combat delay: " .. CountDoom.ToStr( CountDoom.config.outofcombatDelay ) ); |
||
105 | CountDoom.prt( "Delay after expiration: " .. CountDoom.ToStr( CountDoom.config.postExpireDelay ) ); |
||
106 | CountDoom.prt( "Display Hundredths: " .. CountDoom.ToStr( CountDoom.config.hseconds ) ); |
||
107 | end; |
||
108 | |||
109 | |||
110 | CountDoom.DisplayCommands = function() |
||
111 | CountDoom.prt("CountDoom Usage:"); |
||
112 | CountDoom.prt("/cd <enable|disable> -- enable/disable CountDoom" ); |
||
113 | CountDoom.prt("/cd <lock|unlock> -- lock/unlock timers" ); |
||
114 | CountDoom.prt("/cd announce -- toggle per spell announce" ); |
||
115 | CountDoom.prt("/cd play -- toggle per spell sounds" ); |
||
116 | CountDoom.prt("/cd flash -- toggle warning flashes" ); |
||
117 | CountDoom.prt("/cd layout -- cycle layout styles horiz/vert/text" ); |
||
118 | CountDoom.prt("/cd scale -- cycle icon scale" ); |
||
119 | CountDoom.prt("/cd <spell> -- dump spell information" ); |
||
120 | CountDoom.prt("/cd <spell> start -- debug: start a spell" ); |
||
121 | CountDoom.prt("/cd <spell> end -- debug: end a spell" ); |
||
122 | CountDoom.prt("/cd <spell> toggle -- enable disable tracking a spell" ); |
||
123 | CountDoom.prt("/cd ooc <seconds> -- delay before removing all timers" ); |
||
124 | CountDoom.prt("/cd expire <seconds> -- delay before removing expired timers" ); |
||
125 | CountDoom.prt("/cd hseconds -- display Hundredths of a second" ); |
||
126 | CountDoom.prt("/cd debug verbose -- verbose debug msgs" ); |
||
127 | end; |
||
128 | |||
129 | |||
130 | CountDoom.RegisterWorldEvents = function() |
||
131 | |||
132 | -- Need to detect changes to enslaved demon state |
||
133 | this:RegisterEvent("LOCALPLAYER_PET_CHANGED"); |
||
134 | this:RegisterEvent("UNIT_PET"); |
||
135 | |||
136 | this:RegisterEvent("SPELLCAST_STOP"); |
||
137 | this:RegisterEvent("SPELLCAST_FAILED"); |
||
138 | this:RegisterEvent("SPELLCAST_INTERRUPTED"); |
||
139 | |||
140 | -- Used for clearing timers after combat |
||
141 | this:RegisterEvent("PLAYER_REGEN_ENABLED"); |
||
142 | this:RegisterEvent("PLAYER_REGEN_DISABLED"); |
||
143 | |||
144 | -- Used to determine the target ID of a timer. It counts how many times |
||
145 | -- a player changes target (including back and forth) |
||
146 | this:RegisterEvent("PLAYER_TARGET_CHANGED"); |
||
147 | |||
148 | -- Used to detect when a spell was resisted or immune |
||
149 | this:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE"); |
||
150 | |||
151 | -- Used to detect when Succubus casts Seduction |
||
152 | this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE"); |
||
153 | this:RegisterEvent("CHAT_MSG_SPELL_PET_DAMAGE"); |
||
154 | |||
155 | -- Used to detect when the succubus Seduction fades |
||
156 | this:RegisterEvent("CHAT_MSG_SPELL_AURA_GONE_OTHER"); |
||
157 | |||
158 | -- Used to detect when someone dies. |
||
159 | this:RegisterEvent("CHAT_MSG_COMBAT_HOSTILE_DEATH"); |
||
160 | end; |
||
161 | |||
162 | |||
163 | CountDoom.RegisterEvents = function() |
||
164 | -- Used to know when a player zones in. |
||
165 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
166 | this:RegisterEvent("PLAYER_LEAVING_WORLD"); |
||
167 | |||
168 | CountDoom.RegisterWorldEvents(); |
||
169 | end; |
||
170 | |||
171 | |||
172 | CountDoom.UnregisterWorldEvents = function() |
||
173 | -- Need to detect changes to enslaved demon state |
||
174 | this:UnregisterEvent("LOCALPLAYER_PET_CHANGED"); |
||
175 | this:UnregisterEvent("UNIT_PET"); |
||
176 | |||
177 | this:UnregisterEvent("SPELLCAST_STOP"); |
||
178 | this:UnregisterEvent("SPELLCAST_FAILED"); |
||
179 | this:UnregisterEvent("SPELLCAST_INTERRUPTED"); |
||
180 | |||
181 | -- Used for clearing timers after combat |
||
182 | this:UnregisterEvent("PLAYER_REGEN_ENABLED"); |
||
183 | this:UnregisterEvent("PLAYER_REGEN_DISABLED"); |
||
184 | |||
185 | -- Used to determine the target ID of a timer. It counts how many times |
||
186 | -- a player changes target (including back and forth) |
||
187 | this:UnregisterEvent("PLAYER_TARGET_CHANGED"); |
||
188 | |||
189 | -- Used to detect when a spell was resisted or immune |
||
190 | this:UnregisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE"); |
||
191 | |||
192 | -- Used to detect when Succubus casts Seduction |
||
193 | this:UnregisterEvent("CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE"); |
||
194 | this:UnregisterEvent("CHAT_MSG_SPELL_PET_DAMAGE"); |
||
195 | |||
196 | -- Used to detect when the succubus Seduction fades |
||
197 | this:UnregisterEvent("CHAT_MSG_SPELL_AURA_GONE_OTHER"); |
||
198 | |||
199 | -- Used to detect when someone dies. |
||
200 | this:UnregisterEvent("CHAT_MSG_COMBAT_HOSTILE_DEATH"); |
||
201 | end; |
||
202 | |||
203 | |||
204 | CountDoom.UnregisterEvents = function() |
||
205 | -- Used to know when a player zones in. |
||
206 | this:UnregisterEvent("PLAYER_ENTERING_WORLD"); |
||
207 | this:UnregisterEvent("PLAYER_LEAVING_WORLD"); |
||
208 | |||
209 | CountDoom.UnregisterWorldEvents(); |
||
210 | end; |
||
211 | |||
212 | |||
213 | CountDoom.RegisterCommands = function() |
||
214 | SLASH_COUNTDOOM1 = "/countdoom"; |
||
215 | SLASH_COUNTDOOM2 = "/cd"; |
||
216 | SlashCmdList["COUNTDOOM"] = function(msg) |
||
217 | CountDoomSlash(msg); |
||
218 | end |
||
219 | end; |
||
220 | |||
221 | |||
222 | -- Credit to Morbain for the logic |
||
223 | CountDoom.UpdateDurations = function() |
||
224 | local tab, talent; |
||
225 | local numTalentTabs = GetNumTalentTabs(); |
||
226 | CountDoom.dpf( "Talent Tabs: " .. CountDoom.ToStr( numTalentTabs ) ); |
||
227 | |||
228 | for tab = 1, numTalentTabs do |
||
229 | local numTalents = GetNumTalents(tab); |
||
230 | CountDoom.dpf( "Talents: " .. CountDoom.ToStr( numTalents ) ); |
||
231 | for talent=1, numTalents do |
||
232 | local name, iconTexture, tier, column, rank, maxRank, isExceptional, meetsPrereq = |
||
233 | GetTalentInfo(tab, talent); |
||
234 | if name then |
||
235 | CountDoom.dpf( "("..tab..","..talent .. "): " .. name .. "= " .. rank .. "(" .. maxRank .. |
||
236 | ")" ); |
||
237 | end |
||
238 | end |
||
239 | end |
||
240 | |||
241 | local duration = CountDoomSpell[ "seduce" ].rankDuration[1]; |
||
242 | |||
243 | -- Determine if the player has improved succubus which increases timer duration. |
||
244 | local _, texture, _, _, rank, _, _, _ = GetTalentInfo(2, 7); |
||
245 | if (texture) then |
||
246 | duration = duration + (duration * 0.1 * rank) |
||
247 | end |
||
248 | |||
249 | CountDoomSpell[ "seduce" ].rankDuration[1] = duration; |
||
250 | end; |
||
251 | |||
252 | |||
253 | CountDoom.UpdateLayout = function() |
||
254 | if CountDoom.config.layout == "horizontal" then |
||
255 | CDTimers_LayoutHorizontal(); |
||
256 | elseif CountDoom.config.layout == "textonly" then |
||
257 | CDTimers_LayoutTextOnly(); |
||
258 | else |
||
259 | CDTimers_LayoutVertical(); |
||
260 | end |
||
261 | CDTimerSpell_UpdateSpellPrefixes(); |
||
262 | end; |
||
263 | |||
264 | |||
265 | CountDoom.CycleScale = function() |
||
266 | if CountDoom.config.scale == "small" then |
||
267 | CountDoom.config.scale = "medium"; |
||
268 | elseif CountDoom.config.scale == "medium" then |
||
269 | CountDoom.config.scale = "large"; |
||
270 | else |
||
271 | CountDoom.config.scale = "small"; |
||
272 | end |
||
273 | CountDoom.UpdateLayout(); |
||
274 | CountDoom.prt( "Scale set to: " .. CountDoom.config.scale ); |
||
275 | end; |
||
276 | |||
277 | |||
278 | |||
279 | CountDoom.UpdateDragButtons = function() |
||
280 | if CountDoom.config.isLocked ~= true then |
||
281 | CountDoomFrame:SetBackdropColor( 1.0, 1.0, 1.0, 1.0 ); |
||
282 | CountDoomFrame:SetBackdropBorderColor( 1.0, 1.0, 1.0, 1.0 ); |
||
283 | CountDoomFrameBackground:SetAlpha(1.0); |
||
284 | CountDoomFrame:Show(); |
||
285 | getglobal("CountDoomFrameDragButton"):Show(); |
||
286 | CountDoom.dpf("Showing drag buttons."); |
||
287 | else |
||
288 | CountDoomFrame:SetBackdropColor( 1.0, 1.0, 1.0, 0.0 ); |
||
289 | CountDoomFrame:SetBackdropBorderColor( 1.0, 1.0, 1.0, 0.0 ); |
||
290 | CountDoomFrameBackground:SetAlpha(0.0); |
||
291 | getglobal("CountDoomFrameDragButton"):Hide(); |
||
292 | CountDoom.dpf("Hiding drag buttons."); |
||
293 | |||
294 | if CDTimer_numTimers == 0 then |
||
295 | CountDoomFrame:Hide(); |
||
296 | end |
||
297 | end |
||
298 | end; |
||
299 | |||
300 | |||
301 | CountDoom.RotateLayout = function( frameName ) |
||
302 | if frameName == "CountDoomFrame" then |
||
303 | if CountDoom.config.layout == "vertical" then |
||
304 | CountDoom.config.layout = "horizontal"; |
||
305 | elseif CountDoom.config.layout == "horizontal" then |
||
306 | CountDoom.config.layout = "textonly"; |
||
307 | else |
||
308 | CountDoom.config.layout = "vertical"; |
||
309 | end |
||
310 | CountDoom.UpdateLayout(); |
||
311 | end |
||
312 | |||
313 | CountDoom.prt( "Layout set to: " .. CountDoom.config.layout ); |
||
314 | end; |
||
315 | |||
316 | |||
317 | CountDoom.CreateConfig = function( playerName, realmName ) |
||
318 | CountDoom.dpf("Initializing CountDoom.config"); |
||
319 | if not CountDoomConfig then |
||
320 | CountDoom.dpf("Allocating CountDoomConfig"); |
||
321 | CountDoomConfig = {}; |
||
322 | end |
||
323 | |||
324 | if not CountDoomConfig[realmName] then |
||
325 | CountDoomConfig[realmName] = {}; |
||
326 | end |
||
327 | |||
328 | if not CountDoomConfig[realmName][playerName] then |
||
329 | CountDoomConfig[realmName][playerName] = {}; |
||
330 | end |
||
331 | |||
332 | if (not CountDoomConfig[realmName][playerName].enableSpell) then |
||
333 | CountDoomConfig[realmName][playerName].enableSpell = {}; |
||
334 | end |
||
335 | |||
336 | -- set the defaults if the values weren't loaded by the SavedVariables.lua |
||
337 | if( CountDoomConfig[realmName][playerName].isLocked == nil ) then |
||
338 | CountDoomConfig[realmName][playerName].isLocked = CD_DefaultConfig.isLocked; |
||
339 | end |
||
340 | if( CountDoomConfig[realmName][playerName].warningSound == nil ) then |
||
341 | CountDoomConfig[realmName][playerName].warningSound = {}; |
||
342 | CountDoomConfig[realmName][playerName].warningSound[ "enslave" ] = "enslavewarning"; |
||
343 | end |
||
344 | if( CountDoomConfig[realmName][playerName].endSound == nil ) then |
||
345 | CountDoomConfig[realmName][playerName].endSound = {}; |
||
346 | CountDoomConfig[realmName][playerName].endSound[ "enslave" ] = "enslaveend"; |
||
347 | end |
||
348 | if( CountDoomConfig[realmName][playerName].announceSpells == nil ) then |
||
349 | CountDoomConfig[realmName][playerName].announceSpells = CD_DefaultConfig.announceSpells; |
||
350 | end |
||
351 | if( CountDoomConfig[realmName][playerName].playSounds == nil ) then |
||
352 | CountDoomConfig[realmName][playerName].playSounds = CD_DefaultConfig.playSounds; |
||
353 | end |
||
354 | if( CountDoomConfig[realmName][playerName].flashSpells == nil ) then |
||
355 | CountDoomConfig[realmName][playerName].flashSpells = CD_DefaultConfig.flashSpells; |
||
356 | end |
||
357 | if( CountDoomConfig[realmName][playerName].enable == nil ) then |
||
358 | CountDoomConfig[realmName][playerName].enable = CD_DefaultConfig.enable; |
||
359 | end |
||
360 | if( CountDoomConfig[realmName][playerName].layout == nil ) then |
||
361 | CountDoomConfig[realmName][playerName].layout = CD_DefaultConfig.layout; |
||
362 | end |
||
363 | if( CountDoomConfig[realmName][playerName].scale == nil ) then |
||
364 | CountDoomConfig[realmName][playerName].scale = CD_DefaultConfig.scale; |
||
365 | end |
||
366 | if( CountDoomConfig[realmName][playerName].hseconds == nil ) then |
||
367 | CountDoomConfig[realmName][playerName].hseconds = CD_DefaultConfig.hseconds; |
||
368 | end |
||
369 | if( CountDoomConfig[realmName][playerName].outofcombatDelay == nil ) then |
||
370 | CountDoomConfig[realmName][playerName].outofcombatDelay = CD_DefaultConfig.outofcombatDelay; |
||
371 | end |
||
372 | if( CountDoomConfig[realmName][playerName].postExpireDelay == nil ) then |
||
373 | CountDoomConfig[realmName][playerName].postExpireDelay = CD_DefaultConfig.postExpireDelay; |
||
374 | end |
||
375 | if( CountDoomConfig[realmName][playerName].announceChannel == nil ) then |
||
376 | CountDoomConfig[realmName][playerName].announceChannel = CD_DefaultConfig.announceChannel; |
||
377 | end |
||
378 | end; |
||
379 | |||
380 | |||
381 | CountDoom.Initialize = function () |
||
382 | |||
383 | if (CountDoom.initialized == true) then |
||
384 | CountDoom.dpf("Initialize: already loaded. returning."); |
||
385 | return |
||
386 | end |
||
387 | |||
388 | local playerName = UnitName("player"); |
||
389 | local realmName = GetRealmName(); |
||
390 | |||
391 | -- if CountDoom.playerName is "Unknown Entity" get out, need a real name |
||
392 | if (playerName == nil or playerName == UNKNOWNOBJECT) then |
||
393 | CountDoom.dpf("Initialize: invalid name. returning"); |
||
394 | return |
||
395 | end |
||
396 | |||
397 | CountDoom.playerName = playerName; |
||
398 | CountDoom.realmName = realmName; |
||
399 | |||
400 | -- Initialize our configuration |
||
401 | CountDoom.CreateConfig(playerName, realmName); |
||
402 | |||
403 | -- Alias the config to shorten the name. Hopefully, this save settings otherwise we're toast. |
||
404 | CountDoom.config = CountDoomConfig[realmName][playerName]; |
||
405 | |||
406 | CountDoom.RegisterEvents(); |
||
407 | CountDoom.RegisterCommands(); |
||
408 | CountDoom.UpdateDurations(); |
||
409 | CountDoom.UpdateLayout(); |
||
410 | CountDoom.UpdateDragButtons(); |
||
411 | CountDoom.GetSpellBookInfo(); |
||
412 | |||
413 | -- print out a nice message letting the user know the addon loaded |
||
414 | CountDoom.prt( COUNTDOOM_LOADED ); |
||
415 | |||
416 | -- All variables are loaded now |
||
417 | CountDoom.initialized = true; |
||
418 | end; |
||
419 | |||
420 | |||
421 | -- Sets the warning sound. (FUTURE USE) |
||
422 | CountDoom.SetWarningSound = function(spellAbbreviation, msg) |
||
423 | CountDoom.config.warningSound[ spellAbbreviation ] = msg; |
||
424 | CountDoom.prt( string.format( COUNTDOOM_SETWARNINGSOUNDMSG, warningSound[ spellAbbreviation ] ) ); |
||
425 | end; |
||
426 | |||
427 | |||
428 | -- Sets the end sound. (FUTURE USE) |
||
429 | CountDoom.SetEndSound = function(spellAbbreviation, msg) |
||
430 | CountDoom.config.endSound[ spellAbbreviation ] = msg; |
||
431 | CountDoom.prt( string.format( COUNTDOOM_SETENDSOUNDMSG, CountDoom.config.endSound[ spellAbbreviation ] ) ); |
||
432 | end; |
||
433 | |||
434 | |||
435 | CountDoom.ToggleAnnouncingSpells = function() |
||
436 | if CountDoom.config.announceSpells == nil or CountDoom.config.announceSpells == "never" then |
||
437 | CountDoom.config.announceSpells = "local"; |
||
438 | elseif CountDoom.config.announceSpells == "local" then |
||
439 | CountDoom.config.announceSpells = "party"; |
||
440 | elseif CountDoom.config.announceSpells == "party" then |
||
441 | CountDoom.config.announceSpells = "raid"; |
||
442 | elseif CountDoom.config.announceSpells == "raid" then |
||
443 | CountDoom.config.announceSpells = "channel"; |
||
444 | elseif CountDoom.config.announceSpells == "channel" then |
||
445 | CountDoom.config.announceSpells = "all"; |
||
446 | else |
||
447 | CountDoom.config.announceSpells = "never"; |
||
448 | end |
||
449 | |||
450 | CountDoom.prt( "Spells will be announced: " .. CountDoom.config.announceSpells ); |
||
451 | end; |
||
452 | |||
453 | |||
454 | CountDoom.SetEnable = function( enable ) |
||
455 | CountDoom.config.enable = enable; |
||
456 | if( CountDoom.config.enable == true ) then |
||
457 | CountDoom.prt( COUNTDOOM_ENABLEDMSG ); |
||
458 | else |
||
459 | CountDoom.prt( COUNTDOOM_DISABLEDMSG ); |
||
460 | end |
||
461 | end; |
||
462 | |||
463 | |||
464 | CountDoom.SetLocked = function( locked ) |
||
465 | CountDoom.config.isLocked = locked; |
||
466 | if( CountDoom.config.isLocked == true ) then |
||
467 | CountDoom.prt( COUNTDOOM_LOCKED ); |
||
468 | else |
||
469 | CountDoom.prt( COUNTDOOM_UNLOCKED ); |
||
470 | end |
||
471 | |||
472 | CountDoom.UpdateDragButtons(); |
||
473 | end; |
||
474 | |||
475 | |||
476 | CountDoom.ToggleFlashingSpells = function () |
||
477 | if( CountDoom.config.flashSpells == true ) then |
||
478 | CountDoom.config.flashSpells = false; |
||
479 | CountDoom.prt( COUNTDOOM_NOFLASHMSG ); |
||
480 | else |
||
481 | CountDoom.config.flashSpells = true; |
||
482 | CountDoom.prt( COUNTDOOM_YESFLASHMSG ); |
||
483 | end |
||
484 | end; |
||
485 | |||
486 | |||
487 | CountDoom.TogglePlayingSounds = function () |
||
488 | if( CountDoom.config.playSounds == true ) then |
||
489 | CountDoom.config.playSounds = false; |
||
490 | CountDoom.prt( COUNTDOOM_NOSOUNDSMSG ); |
||
491 | else |
||
492 | CountDoom.config.playSounds = true; |
||
493 | CountDoom.prt( COUNTDOOM_YESSOUNDSMSG ); |
||
494 | end |
||
495 | end; |
||
496 | |||
497 | |||
498 | CountDoom.ToggleHseconds = function () |
||
499 | if( CountDoom.config.hseconds == true ) then |
||
500 | CountDoom.config.hseconds = false; |
||
501 | CountDoom.prt( COUNTDOOM_HSECONDS_OFF ); |
||
502 | else |
||
503 | CountDoom.config.hseconds = true; |
||
504 | CountDoom.prt( COUNTDOOM_HSECONDS_ON ); |
||
505 | end |
||
506 | end; |
||
507 | |||
508 | |||
509 | CountDoom.SetOOCTime = function ( delayString ) |
||
510 | if delayString ~= nil then |
||
511 | local oocTime = tonumber( delayString ); |
||
512 | if oocTime ~= nil then |
||
513 | CountDoom.config.outofcombatDelay = oocTime; |
||
514 | end |
||
515 | end |
||
516 | |||
517 | CountDoom.prt( "Out of combat delay is: " .. CountDoom.ToStr( CountDoom.config.outofcombatDelay ) ); |
||
518 | end; |
||
519 | |||
520 | |||
521 | CountDoom.SetPostExpireDelay = function ( delayString ) |
||
522 | if delayString ~= nil then |
||
523 | local expireDelayTime = tonumber( delayString ); |
||
524 | if expireDelayTime ~= nil then |
||
525 | CountDoom.config.postExpireDelay = expireDelayTime; |
||
526 | end |
||
527 | end |
||
528 | |||
529 | CountDoom.prt( "Delay before removing expired timers: " .. CountDoom.ToStr( CountDoom.config.postExpireDelay ) ); |
||
530 | end; |
||
531 | |||
532 | |||
533 | CountDoom.SetAnnounceChannel = function( channelName ) |
||
534 | if channelName ~= nil then |
||
535 | CountDoom.config.announceChannel = channelName; |
||
536 | end |
||
537 | CountDoom.prt( "Announce channel: " .. CountDoom.ToStr( CountDoom.config.announceChannel ) ); |
||
538 | end; |
||
539 | |||
540 | |||
541 | CountDoom.DumpEvents = function () |
||
542 | CountDoom.prt( "Last spell cast: " .. CountDoom.ToStr( CountDoom.event.castSpellName ) ); |
||
543 | CountDoom.prt( "Mode: " .. CountDoom.ToStr( CountDoom.event.castMode ) ); |
||
544 | CountDoom.prt( "Target: " .. CountDoom.ToStr( CountDoom.event.castTarget ) ); |
||
545 | CountDoom.prt( "Last spell removed: " .. CountDoom.ToStr( CountDoom.event.removedSpellName ) ); |
||
546 | CountDoom.prt( "Removal reason: " .. CountDoom.ToStr( CountDoom.event.removedLastReason ) ); |
||
547 | CountDoom.prt( "Target: " .. CountDoom.ToStr( CountDoom.event.removedTarget ) ); |
||
548 | end; |
||
549 | |||
550 | |||
551 | CountDoom.FilterTimer = function( spellName ) |
||
552 | CountDoom.dpf( "CD: CountDoom.FilterTimer " .. CountDoom.ToStr( spellName ) ); |
||
553 | |||
554 | -- Destroy the last active spell |
||
555 | CountDoom.activeSpell = nil; |
||
556 | |||
557 | if (CountDoom.lastSpellID == nil or CountDoom.lastSpellID == -1 or |
||
558 | CountDoom.replacedASpell) then |
||
559 | return; |
||
560 | end |
||
561 | |||
562 | local spellIndex = CDTimerSpell_GetSpellIndex( CountDoom.lastSpellID ); |
||
563 | local spellNameLast = nil; |
||
564 | |||
565 | if spellIndex ~= -1 then |
||
566 | spellNameLast = CDTimerSpell_GetSpellName( spellIndex ); |
||
567 | end |
||
568 | |||
569 | if spellNameLast == spellName then |
||
570 | CDTimerSpell_DeleteIndex( spellIndex ); |
||
571 | end |
||
572 | |||
573 | CountDoom.lastSpellID = -1; |
||
574 | end; |
||
575 | |||
576 | |||
577 | function CountDoomSlash(msg) |
||
578 | |||
579 | msg = string.lower(msg); |
||
580 | local a, b, c, n = string.find (msg, "(%w+) ([_%w]+)"); |
||
581 | |||
582 | if( c == nil and n == nil ) then |
||
583 | a, b, c = string.find (msg, "(%w+)"); |
||
584 | end |
||
585 | |||
586 | if (c ~= nil) then |
||
587 | CountDoom.dpf("c:"..c); |
||
588 | else |
||
589 | CountDoom.dpf("c: nil"); |
||
590 | end |
||
591 | |||
592 | if (n ~= nil) then |
||
593 | CountDoom.dpf("n:"..n); |
||
594 | else |
||
595 | CountDoom.dpf("n: nil"); |
||
596 | end |
||
597 | |||
598 | if (c == nil) then |
||
599 | CountDoom.DisplayCommands(); |
||
600 | CountDoom.DisplaySettings(); |
||
601 | return; |
||
602 | end |
||
603 | |||
604 | if( CountDoomSpell[ c ] ~= nil ) then |
||
605 | if( n == "start" ) then |
||
606 | |||
607 | local targetInfo = {}; |
||
608 | targetInfo.targetName = UnitName( "target" ); |
||
609 | targetInfo.targetLevel = UnitLevel( "target" ); |
||
610 | targetInfo.id = CountDoom.targetID; |
||
611 | |||
612 | CountDoom.lastSpellID, CountDoom.replacedASpell = CDTimerSpell_CreateBySpellAbbreviation( c, targetInfo, nil ); |
||
613 | |||
614 | elseif( n == "end" ) then |
||
615 | CDTimerSpell_DestroyBySpellAbbreviation( c ); |
||
616 | |||
617 | CountDoom.event.removedSpellName = c; |
||
618 | CountDoom.event.removedLastReason = "/cd " .. c .. " end"; |
||
619 | CountDoom.event.removedTarget = nil; |
||
620 | elseif( n == "toggle" ) then |
||
621 | CountDoomSpell.ToggleEnabled( c ); |
||
622 | elseif( n == "play" ) then |
||
623 | CountDoomSpell.ToggleSound( c ); |
||
624 | elseif( n == "announce" ) then |
||
625 | CountDoomSpell.ToggleAnnounce( c ); |
||
626 | elseif( n == nil ) then |
||
627 | CountDoomSpell.Dump( c ); |
||
628 | end |
||
629 | elseif( c == "announce" ) then |
||
630 | CountDoom.ToggleAnnouncingSpells(); |
||
631 | elseif( c == "play" ) then |
||
632 | CountDoom.TogglePlayingSounds(); |
||
633 | elseif( c == "flash" ) then |
||
634 | CountDoom.ToggleFlashingSpells(); |
||
635 | elseif( c == "debug" ) then |
||
636 | if( n == "verbose" ) then |
||
637 | if( CountDoom.debugVerbose == true ) then |
||
638 | CountDoom.debugVerbose = false; |
||
639 | CountDoom.dpf( "debugVerbose is off" ); |
||
640 | else |
||
641 | CountDoom.debugVerbose = true; |
||
642 | CountDoom.dpf( "debugVerbose is on" ); |
||
643 | end |
||
644 | elseif( n == "events" ) then |
||
645 | if( CountDoom.debugEvents == true ) then |
||
646 | CountDoom.debugEvents = false; |
||
647 | CountDoom.prt( "debugEvents is off" ); |
||
648 | else |
||
649 | CountDoom.debugEvents = true; |
||
650 | CountDoom.prt( "debugEvents is on" ); |
||
651 | end |
||
652 | elseif( n == "dump" ) then |
||
653 | CountDoom.DumpEvents(); |
||
654 | end |
||
655 | elseif( c == "enable" ) then |
||
656 | CountDoom.SetEnable( true ); |
||
657 | elseif( c == "disable" ) then |
||
658 | CountDoom.SetEnable( false ); |
||
659 | elseif( c == "layout" ) then |
||
660 | CountDoom.RotateLayout( "CountDoomFrame" ); |
||
661 | elseif( c == "unlock" ) then |
||
662 | CountDoom.SetLocked( false ); |
||
663 | elseif( c == "lock" ) then |
||
664 | CountDoom.SetLocked( true ); |
||
665 | elseif( c == "scale" ) then |
||
666 | CountDoom.CycleScale(); |
||
667 | elseif( c == "hseconds" ) then |
||
668 | CountDoom.ToggleHseconds(); |
||
669 | elseif( c == "ooc" and n ~= nil ) then |
||
670 | CountDoom.SetOOCTime( n ); |
||
671 | elseif( c == "expire" and n ~= nil ) then |
||
672 | CountDoom.SetPostExpireDelay( n ); |
||
673 | elseif( c == "channel" ) then |
||
674 | CountDoom.SetAnnounceChannel( n ); |
||
675 | end |
||
676 | end |
||
677 | |||
678 | |||
679 | function CDFrame_OnUpdate(elapsed) |
||
680 | CountDoom.totalTime = CountDoom.totalTime + elapsed; |
||
681 | |||
682 | if CountDoom.timeRemoveAllTimers ~= nil then |
||
683 | |||
684 | -- Dont' remove timers if we have a pending spell to cast |
||
685 | if CountDoom.activeSpell ~= nil then |
||
686 | CountDoom.timeRemoveAllTimers = nil; |
||
687 | return; |
||
688 | end |
||
689 | |||
690 | if GetTime() >= CountDoom.timeRemoveAllTimers then |
||
691 | CountDoom.event.removedSpellName = "All timers"; |
||
692 | CountDoom.event.removedLastReason = event; |
||
693 | CountDoom.event.removedTarget = nil; |
||
694 | |||
695 | CDTimerSpell_RemoveCombatSpellTimers(); |
||
696 | CountDoom.timeRemoveAllTimers = nil; |
||
697 | end |
||
698 | end |
||
699 | end |
||
700 | |||
701 | |||
702 | function CDFrame_OnLoad() |
||
703 | -- Used for initialization of the mod |
||
704 | this:RegisterEvent("VARIABLES_LOADED"); |
||
705 | end |
||
706 | |||
707 | |||
708 | function CDFrame_OnEvent(event) |
||
709 | |||
710 | -- Keep track of the events |
||
711 | if CountDoom.debugVerbose or CountDoom.debugEvents then |
||
712 | local msg = "Event: " .. event .. ": " .. CountDoom.ToStr( arg1 ) .. " " .. CountDoom.ToStr( arg2 ); |
||
713 | |||
714 | if CountDoom.debugEvents then |
||
715 | CountDoom.CombatPrint(msg); |
||
716 | end |
||
717 | |||
718 | CountDoom.dpf(msg); |
||
719 | end |
||
720 | |||
721 | -- Initialize as soon as the player logs in |
||
722 | if (event == "VARIABLES_LOADED") then |
||
723 | CountDoom.Initialize(); |
||
724 | return; |
||
725 | end |
||
726 | |||
727 | if CountDoom.initialized ~= true then |
||
728 | return; |
||
729 | end |
||
730 | |||
731 | if CountDoom.config.enable ~= true then |
||
732 | return; |
||
733 | end |
||
734 | |||
735 | if UnitClass("player") ~= COUNTDOOM_WARLOCK then |
||
736 | return; |
||
737 | end |
||
738 | |||
739 | -- Pet status changed |
||
740 | if (event == "UNIT_PET" and arg1 == "player") or |
||
741 | (event == "LOCALPLAYER_PET_CHANGED") then |
||
742 | |||
743 | if (UnitIsFriend("player", "pet")) then |
||
744 | local iIterator = 1 |
||
745 | while (UnitDebuff("pet", iIterator)) do |
||
746 | local debuffString = UnitDebuff("pet", iIterator); |
||
747 | CountDoom.dpf( "Debuff[" .. iIterator .. "] " .. debuffString); |
||
748 | if (string.find(debuffString, COUNTDOOMDEBUFF_ENSLAVEDEMON)) then |
||
749 | |||
750 | local targetInfo = {}; |
||
751 | targetInfo.targetName = UnitName( "target" ); |
||
752 | targetInfo.targetLevel = UnitLevel( "target" ); |
||
753 | targetInfo.id = CountDoom.targetID; |
||
754 | |||
755 | CountDoom.lastSpellID, CountDoom.replacedASpell = CDTimerSpell_CreateBySpellAbbreviation( "enslave", targetInfo, nil ); |
||
756 | end |
||
757 | iIterator = iIterator + 1 |
||
758 | end |
||
759 | else |
||
760 | CDTimerSpell_DestroyBySpellAbbreviation( "enslave" ); |
||
761 | |||
762 | CountDoom.event.removedSpellName = "enslave"; |
||
763 | CountDoom.event.removedLastReason = event; |
||
764 | CountDoom.event.removedTarget = nil; |
||
765 | end |
||
766 | |||
767 | -- Started casting a spell (DEBUG) |
||
768 | elseif event == "SPELLCAST_START" then |
||
769 | |||
770 | --We used to track the activeSpell name by monitoring this event but |
||
771 | --unfortunately it doesn't track insta-cast spells |
||
772 | |||
773 | -- Spell casting was interrupted |
||
774 | elseif event == "SPELLCAST_INTERRUPTED" or event == "SPELLCAST_FAILED" then |
||
775 | |||
776 | CountDoom.activeSpell = nil; |
||
777 | CountDoom.targetName = nil; |
||
778 | CountDoom.targetLevel = 0; |
||
779 | CountDoom.activeSpellWaitingForTarget = nil; |
||
780 | |||
781 | if CountDoom.lastSpellID ~= -1 and CountDoom.replacedASpell == false then |
||
782 | CDTimerSpell_DeleteID( CountDoom.lastSpellID ); |
||
783 | |||
784 | CountDoom.event.removedSpellName = "spellID: " .. CountDoom.lastSpellID; |
||
785 | CountDoom.event.removedLastReason = event; |
||
786 | if CDTimerSpells[ CountDoom.lastSpellID ] ~= nil then |
||
787 | CountDoom.event.removedTarget = CDTimerSpells[ CountDoom.lastSpellID ].targetName; |
||
788 | else |
||
789 | CountDoom.event.removedTarget = nil; |
||
790 | end |
||
791 | end |
||
792 | |||
793 | CountDoom.lastSpellID = -1; |
||
794 | CountDoom.replacedASpell = false; |
||
795 | |||
796 | -- User stopped casting a spell |
||
797 | elseif event == "SPELLCAST_STOP" then |
||
798 | |||
799 | if CountDoom.activeSpell ~= nil then |
||
800 | local targetInfo = {}; |
||
801 | targetInfo.targetName = CountDoom.targetName; |
||
802 | targetInfo.targetLevel = CountDoom.targetLevel; |
||
803 | targetInfo.id = CountDoom.targetID; |
||
804 | |||
805 | -- We are likely to enter combat. Don't delete timers immediately. |
||
806 | CountDoom.timeRemoveAllTimers = nil; |
||
807 | |||
808 | CountDoom.lastSpellID, CountDoom.replacedASpell = CDTimerSpell_CreateBySpellName( |
||
809 | CountDoom.activeSpell, targetInfo, CountDoom.spellRank ); |
||
810 | CountDoom.activeSpell = nil; |
||
811 | end |
||
812 | |||
813 | -- Player has left combat |
||
814 | elseif event == "PLAYER_REGEN_ENABLED" then |
||
815 | |||
816 | CountDoom.timeRemoveAllTimers = GetTime() + CountDoom.config.outofcombatDelay; |
||
817 | |||
818 | -- Player has entered combat |
||
819 | elseif event == "PLAYER_REGEN_DISABLED" then |
||
820 | |||
821 | CountDoom.timeRemoveAllTimers = nil; |
||
822 | |||
823 | -- Pet has cast a spell (DEBUG) |
||
824 | elseif(event == "CHAT_MSG_SPELL_PET_DAMAGE") then |
||
825 | arg1 = string.gsub(arg1," %(.+%)","") -- strip trailing ()'s we don't use |
||
826 | arg1 = string.gsub(arg1,"%.$","") -- strip trailing .'s |
||
827 | |||
828 | local found,_,casterName,spellName,index3,index4,index5 = string.find(arg1, CD_SPELLCASTOTHERSTART); |
||
829 | if found then |
||
830 | CountDoom.dpf( "CD: " .. CountDoom.ToStr( casterName ) .. " begins to cast " .. CountDoom.ToStr( spellName ) ); |
||
831 | |||
832 | CountDoom.petTargetName = UnitName( "pettarget" ); |
||
833 | CountDoom.petTargeLevel = UnitLevel( "pettarget" ); |
||
834 | CountDoom.petActiveSpell = spellName; |
||
835 | end |
||
836 | |||
837 | elseif(event == "CHAT_MSG_SPELL_SELF_DAMAGE") then |
||
838 | arg1 = string.gsub(arg1," %(.+%)","") -- strip trailing ()'s we don't use |
||
839 | arg1 = string.gsub(arg1,"%.$","") -- strip trailing .'s |
||
840 | |||
841 | -- Determine if the target resisted |
||
842 | local found,_,spellName,mobName,index3,index4,index5 = string.find(arg1, CD_SPELLRESISTSELFOTHER); |
||
843 | if found then |
||
844 | CountDoom.dpf( "CD: " .. CountDoom.ToStr( spellName ) .. " was resisted by " .. CountDoom.ToStr( mobName ) ); |
||
845 | |||
846 | CountDoom.FilterTimer( spellName ); |
||
847 | return; |
||
848 | end |
||
849 | |||
850 | -- Determine if the target was immune |
||
851 | local found,_,spellName,mobName,index3,index4,index5 = string.find(arg1, CD_SPELLIMMUNESELFOTHER); |
||
852 | if found then |
||
853 | CountDoom.dpf( "CD: " .. CountDoom.ToStr( mobName ) .. " was immune to " .. CountDoom.ToStr( spellName ) ); |
||
854 | |||
855 | CountDoom.FilterTimer( spellName ); |
||
856 | return; |
||
857 | end |
||
858 | |||
859 | -- Determine if the target was evaded |
||
860 | local found,_,spellName,mobName,index3,index4,index5 = string.find(arg1, CD_SPELLEVADEDSELFOTHER); |
||
861 | if found then |
||
862 | CountDoom.dpf( "CD: " .. CountDoom.ToStr( mobName ) .. " evaded your " .. CountDoom.ToStr( spellName ) ); |
||
863 | |||
864 | CountDoom.FilterTimer( spellName ); |
||
865 | return; |
||
866 | end |
||
867 | |||
868 | -- Creature received damage. See if Succubus seduced a mob. |
||
869 | elseif(event == "CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE") then |
||
870 | arg1 = string.gsub(arg1," %(.+%)","") -- strip trailing ()'s we don't use |
||
871 | arg1 = string.gsub(arg1,"%.$","") -- strip trailing .'s |
||
872 | |||
873 | local found,_,mobName,spellName,index3,index4,index5 = string.find(arg1, CD_AURAADDEDOTHERHARMFUL); |
||
874 | if found and spellName ~= nil then |
||
875 | CountDoom.dpf( "CD: " .. CountDoom.ToStr( mobName ) .. " is afflicted by " .. CountDoom.ToStr( spellName ) ); |
||
876 | |||
877 | if (spellName == COUNTDOOMSPELL_SEDUCE and CountDoom.petActiveSpell == COUNTDOOMSPELL_SEDUCE) or |
||
878 | (spellName == COUNTDOOMSPELL_SPELL_LOCK) then |
||
879 | local targetInfo = {}; |
||
880 | targetInfo.targetName = CountDoom.petTargetName; |
||
881 | targetInfo.targetLevel = CountDoom.petTargeLevel; |
||
882 | targetInfo.id = -1; |
||
883 | |||
884 | -- Currently we assume pet casts max rank spell. |
||
885 | local petRank = nil; |
||
886 | |||
887 | CountDoom.lastSpellID, CountDoom.replacedASpell = CDTimerSpell_CreateBySpellName( spellName, targetInfo, petRank ); |
||
888 | |||
889 | CountDoom.petTargetName = nil; |
||
890 | CountDoom.petTargeLevel = 0; |
||
891 | CountDoom.petActiveSpell = nil; |
||
892 | end |
||
893 | |||
894 | return; |
||
895 | end |
||
896 | |||
897 | -- Created lost a debuff. See if Succubus' seduction had faded. |
||
898 | elseif(event == "CHAT_MSG_SPELL_AURA_GONE_OTHER") then |
||
899 | |||
900 | arg1 = string.gsub(arg1," %(.+%)","") -- strip trailing ()'s we don't use |
||
901 | arg1 = string.gsub(arg1,"%.$","") -- strip trailing .'s |
||
902 | |||
903 | local found,_,spellName,mobName,index3,index4,index5 = string.find(arg1, CD_AURAREMOVEDOTHER); |
||
904 | if found then |
||
905 | CountDoom.dpf( "CD: " .. CountDoom.ToStr( spellName ) .. " fades from " .. CountDoom.ToStr( mobName ) ); |
||
906 | |||
907 | if spellName == COUNTDOOMSPELL_SEDUCE or spellName == COUNTDOOMSPELL_SPELL_LOCK then |
||
908 | CDTimerSpell_DestroyBySpellName( spellName ); |
||
909 | |||
910 | CountDoom.event.removedSpellName = spellName; |
||
911 | CountDoom.event.removedLastReason = CHAT_MSG_SPELL_AURA_GONE_OTHER; |
||
912 | CountDoom.event.removedTarget = mobName; |
||
913 | end |
||
914 | |||
915 | return; |
||
916 | end |
||
917 | |||
918 | elseif event == "CHAT_MSG_COMBAT_HOSTILE_DEATH" then |
||
919 | |||
920 | arg1 = string.gsub(arg1," %(.+%)","") -- strip trailing ()'s we don't use |
||
921 | arg1 = string.gsub(arg1,"%.$","") -- strip trailing .'s |
||
922 | |||
923 | local found,_,mobName,index3,index4,index5 = string.find(arg1, CD_UNITDIESOTHER); |
||
924 | if found then |
||
925 | CountDoom.dpf( "CD: " .. CountDoom.ToStr( mobName ) .. " dies." ); |
||
926 | |||
927 | if UnitIsDead( "target" ) then |
||
928 | local deletedOne; |
||
929 | |||
930 | repeat |
||
931 | deletedOne = CDTimerSpell_DeleteTarget( CountDoom.targetID ); |
||
932 | until deletedOne == false; |
||
933 | end; |
||
934 | |||
935 | return; |
||
936 | end |
||
937 | |||
938 | -- Determine if the player has changed targets (FUTURE USE) |
||
939 | elseif event == "PLAYER_TARGET_CHANGED" then |
||
940 | |||
941 | -- Keep track of the current targetID |
||
942 | CountDoom.targetID = CountDoom.targetID + 1; |
||
943 | if CountDoom.targetID > 10000 then |
||
944 | CountDoom.targetID = 0; |
||
945 | end |
||
946 | |||
947 | -- Player has changed zones |
||
948 | elseif event == "PLAYER_ENTERING_WORLD" then |
||
949 | |||
950 | CountDoom.timeRemoveAllTimers = GetTime() + CountDoom.config.outofcombatDelay; |
||
951 | |||
952 | CountDoom.RegisterWorldEvents(); |
||
953 | |||
954 | -- Player has changed zones |
||
955 | elseif event == "PLAYER_LEAVING_WORLD" then |
||
956 | |||
957 | CountDoom.UnregisterWorldEvents(); |
||
958 | |||
959 | end |
||
960 | end |
||
961 | |||
962 | CountDoom.GetSpellBookInfo = function() |
||
963 | CountDoom.dpf( "CountDoom.GetSpellBookInfo" ); |
||
964 | |||
965 | local i; |
||
966 | for i = 1, GetNumSpellTabs(), 1 do |
||
967 | local name, texture, offset, numSpells = GetSpellTabInfo(i); |
||
968 | local y; |
||
969 | for y = 1, numSpells, 1 do |
||
970 | local spellName, rankName = GetSpellName(offset+y, BOOKTYPE_SPELL); |
||
971 | local _, _, rankStr = string.find(rankName, "(%d+)"); |
||
972 | |||
973 | local rank = tonumber(rankStr); |
||
974 | if rank then |
||
975 | if not CountDoom.spellTable then |
||
976 | CountDoom.spellTable = {}; |
||
977 | end; |
||
978 | |||
979 | if not CountDoom.spellTable[spellName] then |
||
980 | CountDoom.spellTable[spellName] = {}; |
||
981 | end |
||
982 | |||
983 | if not CountDoom.spellTable[spellName].maxRank or |
||
984 | rank > CountDoom.spellTable[spellName].maxRank then |
||
985 | CountDoom.spellTable[spellName].maxRank = rank; |
||
986 | end |
||
987 | |||
988 | CountDoom.dpf( "Adding spell (" .. y+offset .. ") " .. spellName .. " rank " .. rank .. " to spellTable" ); |
||
989 | |||
990 | CountDoom.spellTable[spellName][rank] = { ["tab"] = i, ["spell"] = y+offset }; |
||
991 | end |
||
992 | end |
||
993 | end |
||
994 | end; |
||
995 | |||
996 | |||
997 | -- SPELLCAST_START event only sets the spell name for spells that are |
||
998 | -- not insta-cast. To detect insta-cast spells, we need to hook into |
||
999 | -- the CastSpell function. Once hooked, each spell is placed into a hidden |
||
1000 | -- tooltip and the name is extracted. Courtesy of CT_RaidAssist. |
||
1001 | |||
1002 | CountDoom.oldCastSpell = CastSpell; |
||
1003 | CountDoom.OnCastSpell = function (spellId,spellbookTabNum) |
||
1004 | local spellName, spellRank = GetSpellName(spellId, spellbookTabNum); |
||
1005 | |||
1006 | CountDoom.dpf( CountDoom.ToStr( spellName ) .. " " .. CountDoom.ToStr( spellRank ) ); |
||
1007 | |||
1008 | if spellRank ~= nil then |
||
1009 | local _, _, spellRankString = string.find(spellRank, "(%d+)"); |
||
1010 | --local _, _, spellRankString = string.find( spellRank, "[^%d]*(%d+)"); |
||
1011 | rank = tonumber(spellRankString); |
||
1012 | |||
1013 | CountDoom.dpf( "Rank: " .. CountDoom.ToStr( rank ) ); |
||
1014 | end; |
||
1015 | |||
1016 | CountDoom.spellRank = rank; |
||
1017 | if SpellIsTargeting() then |
||
1018 | CountDoom.activeSpellWaitingForTarget = spellName; |
||
1019 | else |
||
1020 | CountDoom.activeSpell = spellName; |
||
1021 | CountDoom.targetName = UnitName( "target" ); |
||
1022 | CountDoom.targetLevel = UnitLevel( "target" ); |
||
1023 | CountDoom.lastSpellID = -1; |
||
1024 | CountDoom.replacedASpell = false; |
||
1025 | |||
1026 | CountDoom.event.castSpellName = spellName; |
||
1027 | CountDoom.event.castMode = "CastSpell"; |
||
1028 | CountDoom.event.castTarget = CountDoom.targetName; |
||
1029 | end |
||
1030 | |||
1031 | CountDoom.dpf( "Starting cast of: " .. CountDoom.ToStr( spellName ) .. " " .. spellId .. " " .. spellbookTabNum ); |
||
1032 | |||
1033 | CountDoom.oldCastSpell( spellId, spellbookTabNum ); |
||
1034 | end; |
||
1035 | CastSpell = CountDoom.OnCastSpell; |
||
1036 | |||
1037 | |||
1038 | CountDoom.oldSpellTargetUnit = SpellTargetUnit; |
||
1039 | CountDoom.OnSpellTargetUnit = function (unit) |
||
1040 | if CountDoom.activeSpellWaitingForTarget then |
||
1041 | CountDoom.activeSpell = CountDoom.activeSpellWaitingForTarget; |
||
1042 | CountDoom.targetName = UnitName( unit ); |
||
1043 | CountDoom.targetLevel = UnitLevel( unit ); |
||
1044 | CountDoom.activeSpellWaitingForTarget = nil; |
||
1045 | CountDoom.lastSpellID = -1; |
||
1046 | end |
||
1047 | |||
1048 | CountDoom.oldSpellTargetUnit(unit); |
||
1049 | end; |
||
1050 | SpellTargetUnit = CountDoom.OnSpellTargetUnit; |
||
1051 | |||
1052 | |||
1053 | CountDoom.oldTargetUnit = TargetUnit; |
||
1054 | CountDoom.OnTargetUnit = function (unit) |
||
1055 | if CountDoom.activeSpellWaitingForTarget then |
||
1056 | CountDoom.activeSpell = CountDoom.activeSpellWaitingForTarget; |
||
1057 | CountDoom.targetName = UnitName( unit ); |
||
1058 | CountDoom.targetLevel = UnitLevel( unit ); |
||
1059 | CountDoom.activeSpellWaitingForTarget = nil; |
||
1060 | CountDoom.lastSpellID = -1; |
||
1061 | end |
||
1062 | CountDoom.oldTargetUnit(unit); |
||
1063 | end; |
||
1064 | TargetUnit = CountDoom.OnTargetUnit; |
||
1065 | |||
1066 | |||
1067 | CountDoom.oldSpellStopTargetting = SpellStopTargetting; |
||
1068 | CountDoom.OnSpellStopTargetting = function() |
||
1069 | if CountDoom.activeSpellWaitingForTarget then |
||
1070 | CountDoom.activeSpell = nil; |
||
1071 | CountDoom.targetName = nil; |
||
1072 | CountDoom.targetLevel = 0; |
||
1073 | CountDoom.activeSpellWaitingForTarget = nil; |
||
1074 | end |
||
1075 | |||
1076 | CountDoom.oldSpellStopTargetting(); |
||
1077 | end; |
||
1078 | SpellStopTargetting = CountDoom.OnSpellStopTargetting; |
||
1079 | |||
1080 | |||
1081 | CountDoom.oldUseAction = UseAction; |
||
1082 | CountDoom.OnUseAction = function (a1, a2, a3) |
||
1083 | |||
1084 | -- Only process if it isn't a macro |
||
1085 | if GetActionText(a1) == nil then |
||
1086 | |||
1087 | CD_SpellDetector:Hide(); |
||
1088 | CD_SpellDetector:SetOwner(CountDoomFrame,"ANCHOR_NONE"); |
||
1089 | CD_SpellDetector:SetAction(a1); |
||
1090 | |||
1091 | local spellName = nil; |
||
1092 | |||
1093 | if CD_SpellDetectorTextLeft1 ~= nil then |
||
1094 | spellName = CD_SpellDetectorTextLeft1:GetText(); |
||
1095 | end; |
||
1096 | |||
1097 | local spellRank = nil; |
||
1098 | if CD_SpellDetectorTextRight1 ~= nil then |
||
1099 | spellRank = CD_SpellDetectorTextRight1:GetText(); |
||
1100 | end; |
||
1101 | local rank = nil; |
||
1102 | |||
1103 | if spellRank ~= nil then |
||
1104 | local _, _, spellRankString = string.find( spellRank, "[^%d]*(%d+)"); |
||
1105 | rank = tonumber(spellRankString); |
||
1106 | end; |
||
1107 | |||
1108 | CountDoom.spellRank = rank; |
||
1109 | if SpellIsTargeting() then |
||
1110 | CountDoom.activeSpellWaitingForTarget = spellName; |
||
1111 | else |
||
1112 | CountDoom.activeSpell = spellName; |
||
1113 | CountDoom.targetName = UnitName( "target" ); |
||
1114 | CountDoom.targetLevel = UnitLevel( "target" ); |
||
1115 | CountDoom.lastSpellID = -1; |
||
1116 | |||
1117 | CountDoom.event.castSpellName = spellName; |
||
1118 | CountDoom.event.castMode = "UseAction"; |
||
1119 | CountDoom.event.castTarget = CountDoom.targetName; |
||
1120 | end |
||
1121 | |||
1122 | if ( a3 and a3 == 1 ) then |
||
1123 | CountDoom.activeSpell = nil; |
||
1124 | end |
||
1125 | |||
1126 | if CountDoom.debugEvents then |
||
1127 | local msg = "UseAction: " .. CountDoom.ToStr( a1 ) .. " " .. CountDoom.ToStr( a2 ) .. " " .. CountDoom.ToStr( a3 ); |
||
1128 | msg = msg .. " " .. CountDoom.ToStr( spellName ); |
||
1129 | CountDoom.CombatPrint(msg); |
||
1130 | end |
||
1131 | |||
1132 | CountDoom.dpf( "UseAction cast of: " .. CountDoom.ToStr( spellName ) .. " Rank: " .. CountDoom.ToStr( rank ) ); |
||
1133 | end |
||
1134 | |||
1135 | CountDoom.oldUseAction(a1, a2, a3); |
||
1136 | end; |
||
1137 | UseAction = CountDoom.OnUseAction; |
||
1138 | |||
1139 | |||
1140 | CountDoom.oldCastSpellByName = CastSpellByName; |
||
1141 | CountDoom.OnCastSpellByName = function(spellString) |
||
1142 | |||
1143 | local startIndex, endIndex, spellName = string.find( spellString, "(.+)%(" ); |
||
1144 | local _, _, spellRankStr = string.find( spellString, "([%d]+)"); |
||
1145 | local rank = nil; |
||
1146 | |||
1147 | CountDoom.dpf( spellString ); |
||
1148 | |||
1149 | if spellName == nil then |
||
1150 | startIndex, endIndex, spellName = string.find( spellString, "(.+)" ); |
||
1151 | end |
||
1152 | |||
1153 | if spellName == nil then |
||
1154 | CountDoom.prt( "CountDoom: Error: Unable to determine spell information from: '" .. spellString .. "'"); |
||
1155 | CountDoom.prt( "CountDoom: contact mod owner with string for help." ); |
||
1156 | end |
||
1157 | |||
1158 | if spellRankStr ~= nil then |
||
1159 | CountDoom.dpf( spellRankStr ); |
||
1160 | rank = tonumber( spellRankStr ); |
||
1161 | end; |
||
1162 | |||
1163 | CountDoom.spellRank = rank; |
||
1164 | if SpellIsTargeting() then |
||
1165 | CountDoom.activeSpellWaitingForTarget = spellName; |
||
1166 | else |
||
1167 | CountDoom.activeSpell = spellName; |
||
1168 | CountDoom.targetName = UnitName( "target" ); |
||
1169 | CountDoom.targetLevel = UnitLevel( "target" ); |
||
1170 | CountDoom.lastSpellID = -1; |
||
1171 | CountDoom.replacedASpell = false; |
||
1172 | |||
1173 | CountDoom.event.castSpellName = spellName; |
||
1174 | CountDoom.event.castMode = "CastSpellByName"; |
||
1175 | CountDoom.event.castTarget = CountDoom.targetName; |
||
1176 | end |
||
1177 | |||
1178 | CountDoom.dpf( "CastSpellByName cast of: " .. CountDoom.ToStr( spellName ) .. " Rank: " .. CountDoom.ToStr( rank ) ); |
||
1179 | |||
1180 | return CountDoom.oldCastSpellByName(spellString); |
||
1181 | end; |
||
1182 | CastSpellByName = CountDoom.OnCastSpellByName; |
||
1183 | |||
1184 | --[[ Can't hook this in 1.10 |
||
1185 | |||
1186 | CountDoom.oldCameraOrSelectOrMoveStart = CameraOrSelectOrMoveStart; |
||
1187 | function CountDoom.OnCameraOrSelectOrMoveStart() |
||
1188 | -- If we're waiting to target |
||
1189 | local targetName = nil; |
||
1190 | local targetLevel = 0; |
||
1191 | |||
1192 | if CountDoom.activeSpellWaitingForTarget and UnitName("mouseover") then |
||
1193 | targetName = UnitName("mouseover"); |
||
1194 | targetLevel = UnitLevel("mouseover"); |
||
1195 | end |
||
1196 | |||
1197 | CountDoom.oldCameraOrSelectOrMoveStart(); |
||
1198 | |||
1199 | if CountDoom.activeSpellWaitingForTarget then |
||
1200 | CountDoom.activeSpell = CountDoom.activeSpellWaitingForTarget; |
||
1201 | CountDoom.targetName = targetName; |
||
1202 | CountDoom.targetLevel = targetLevel; |
||
1203 | CountDoom.activeSpellWaitingForTarget = nil; |
||
1204 | CountDoom.lastSpellID = -1; |
||
1205 | CountDoom.replacedASpell = false; |
||
1206 | end |
||
1207 | |||
1208 | end; |
||
1209 | CameraOrSelectOrMoveStart = CountDoom.OnCameraOrSelectOrMoveStart; |
||
1210 | --]] |
||
1211 | |||
1212 |