vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- |
2 | -- MI2_Events.lua |
||
3 | -- |
||
4 | -- Handlers for all WoW events that MobInfo subscribes to. This includes |
||
5 | -- the main MobInfo OnEvent handler called "MI2_OnEvent()". Event handling |
||
6 | -- is based on a global table of event handlers called "MI2_EventHandlers[]". |
||
7 | -- For each event that MobInfo supports the corresponding handler function |
||
8 | -- is available in the table. |
||
9 | -- |
||
10 | -- (this is code restructering work in progress, it has not yet been completed ... ) |
||
11 | -- |
||
12 | |||
13 | |||
14 | -- global variable holding all current target data for entire MobInfo2 AddOn |
||
15 | MI2_Target = {} |
||
16 | MI2_LastTargetIdx = nil |
||
17 | MI2_CurContinent = 0 |
||
18 | MI2_CurZone = 0 |
||
19 | |||
20 | -- miscellaneous other event related global vairables |
||
21 | MI2_IsNonMobLoot = nil |
||
22 | |||
23 | -- local table holding all event handler functions |
||
24 | local MI2_EventHandlers = { } |
||
25 | local MI2_GT_OnShow_Orig |
||
26 | local MI2_Scan_SelfBuff |
||
27 | |||
28 | |||
29 | ----------------------------------------------------------------------------- |
||
30 | -- MI2_CheckForSeparateMobHealth() |
||
31 | -- |
||
32 | -- Detect the presence of separate MobHelath AddOns and disable the internal |
||
33 | -- MobHealth functionality if found |
||
34 | ----------------------------------------------------------------------------- |
||
35 | local function MI2_CheckForSeparateMobHealth() |
||
36 | if MobHealth_OnLoad then |
||
37 | if MobInfoConfig.DisableHealth ~= 2 then |
||
38 | MobInfoConfig.DisableHealth = 2 |
||
39 | UIErrorsFrame:AddMessage( MI_TXT_MH_DISABLED, 0.0, 1.0, 1.0, 1.0, 20 ) |
||
40 | end |
||
41 | MI2_MobHealthFrame:Hide() |
||
42 | else |
||
43 | if MobInfoConfig.DisableHealth ~= 0 then |
||
44 | MobInfoConfig.DisableHealth = 0 |
||
45 | end |
||
46 | end |
||
47 | end -- MI2_CheckForSeparateMobHealth |
||
48 | |||
49 | |||
50 | ----------------------------------------------------------------------------- |
||
51 | -- MI2_MobInfo_Initialize() |
||
52 | -- |
||
53 | -- main global initialization function, this is called as the handler |
||
54 | -- for the "VARIABLES_LOADED" event |
||
55 | ----------------------------------------------------------------------------- |
||
56 | local function MI2_MobInfo_Initialize() |
||
57 | |||
58 | -- initialize "MobInfoConfig" data structure (main MobInfo config options) |
||
59 | MI2_InitOptions() |
||
60 | |||
61 | -- register with all AddOn managers that MobInfo attempts to support |
||
62 | -- currently that is: myAddons, KHAOS (mainly for Cosmos), EARTH (originally for Cosmos) |
||
63 | MI2_RegisterWithAddonManagers() |
||
64 | |||
65 | -- check for presence of separate interferring MobHealth AddOn |
||
66 | -- initialize built-in MobHealth if not disabled |
||
67 | MI2_CheckForSeparateMobHealth() |
||
68 | if MobInfoConfig.DisableHealth < 2 then |
||
69 | MI2_MobHealth_SetPos() |
||
70 | end |
||
71 | |||
72 | -- ensure that MobHealthFrame get set correctly (if we have to set it for compatibility) |
||
73 | if MobHealthFrame == "MI2" then |
||
74 | MobHealthFrame = MI2_MobHealthFrame |
||
75 | end |
||
76 | |||
77 | -- setup a confirmation dialog for critical configuration options |
||
78 | StaticPopupDialogs["MOBINFO_CONFIRMATION"] = { |
||
79 | button1 = TEXT(OKAY), |
||
80 | button2 = TEXT(CANCEL), |
||
81 | showAlert = 1, |
||
82 | timeout = 0, |
||
83 | exclusive = 1, |
||
84 | whileDead = 1, |
||
85 | interruptCinematic = 1 |
||
86 | } |
||
87 | |||
88 | -- cleanup for all databases |
||
89 | MI2_CleanupDatabases() |
||
90 | |||
91 | -- obtain player name and realm name |
||
92 | local charName = GetCVar( "realmName" )..':'..UnitName("player") |
||
93 | if not MI2_CharTable[charName] then |
||
94 | MI2_CharTable.charCount = MI2_CharTable.charCount + 1 |
||
95 | MI2_CharTable[charName] = "c"..MI2_CharTable.charCount |
||
96 | end |
||
97 | MI2_PlayerName = MI2_CharTable[charName] |
||
98 | |||
99 | -- load the MobInfo item sell price table |
||
100 | MI2_BuildSellPriceTable() |
||
101 | -- setup event handling for the entire AddOn (MobInfo and MobHealth) |
||
102 | MI2_UpdateMobInfoState() |
||
103 | -- initialize slash commands processing |
||
104 | MI2_SlashInit() |
||
105 | -- build cross reference table for fast item tooltips |
||
106 | MI2_BuildXRefItemTable() |
||
107 | |||
108 | |||
109 | -- hook into OnShow for game tooltip |
||
110 | MI2_GT_OnShow_Orig = GameTooltip:GetScript("OnShow") |
||
111 | GameTooltip:SetScript( "OnShow", MI2_GameTooltip_OnShow ) |
||
112 | |||
113 | -- from this point onward process events |
||
114 | MI2_InitializeEventTable() |
||
115 | |||
116 | if not (myAddOnsFrame_Register or EarthFeature_AddButton or Khaos) then |
||
117 | chattext("MobInfo-2 v"..miVersionNo.." Loaded, "..mifontGreen.."enter /mi2 or /mobinfo2 for help") |
||
118 | end |
||
119 | end -- MI2_MobInfo_Initialize() |
||
120 | |||
121 | |||
122 | ----------------------------------------------------------------------------- |
||
123 | -- MI2_EventSelfBuff() |
||
124 | -- |
||
125 | -- event handler for the WoW "CHAT_MSG_SPELL_SELF_BUFF" event |
||
126 | -- This event is called for lots of miscellaneous reasons. The reason I |
||
127 | -- subscribe to it is to detect the opening of chest loot or collecting |
||
128 | -- loot (chests, barrels, mining, herbs) |
||
129 | ----------------------------------------------------------------------------- |
||
130 | local function MI2_EventSelfBuff() |
||
131 | if MI2_Debug > 0 then chattext("M2DBG: event="..event..", a1="..(arg1 or "<nil>")..", a2="..(arg2 or "<nil>") ) end |
||
132 | local s,e, lootAction, lootType = string.find( arg1, MI2_Scan_SelfBuff ) |
||
133 | |||
134 | -- set global flag that a non Mob loot window is being opened |
||
135 | if lootAction and lootType then |
||
136 | MI2_IsNonMobLoot = true |
||
137 | end |
||
138 | end -- MI2_EventSelfBuff() |
||
139 | |||
140 | |||
141 | ----------------------------------------------------------------------------- |
||
142 | -- MI2_EventUnitCombat() |
||
143 | -- |
||
144 | -- Event handler for the "UNIT_COMBAT" event. This handler will |
||
145 | -- accumulate all damage done to the current target, and will record all |
||
146 | -- damage done to the player by the current target. |
||
147 | ----------------------------------------------------------------------------- |
||
148 | local function MI2_EventUnitCombat() |
||
149 | if arg1 == "target" then |
||
150 | if MI2_Target.index then |
||
151 | if arg2 ~= "HEAL" and arg4 > 0 then |
||
152 | MI2_Target.tempDamage = MI2_Target.tempDamage + arg4 |
||
153 | end |
||
154 | end |
||
155 | elseif arg1 == "player" then |
||
156 | if arg3 ~= "CRITICAL" and MI2_Target.mobIndex then -- observed: MI2_Target can be NIL |
||
157 | MI2_RecordDamage( MI2_Target.mobIndex, tonumber(arg4) ) |
||
158 | end |
||
159 | end |
||
160 | end -- MI2_EventUnitCombat() |
||
161 | |||
162 | |||
163 | ----------------------------------------------------------------------------- |
||
164 | -- MI2_EventUnitHealth() |
||
165 | -- |
||
166 | -- Event handler for the "UNIT_HEALTH" event. This handler will |
||
167 | -- process health number that WoW gives us for the current target. Combining |
||
168 | -- the health value with the damage done to the current target and with the |
||
169 | -- current health percentage of the target allows us to calculate the PPP |
||
170 | -- value (Point Per Percent) for the current target. The PPP value can then |
||
171 | -- be used to calculate a health value from a given health percentage. |
||
172 | -- |
||
173 | -- new feature : overkill protection : skip damage values that are |
||
174 | -- higher then remaining health |
||
175 | -- |
||
176 | -- if health value has changed update game tooltip |
||
177 | ----------------------------------------------------------------------------- |
||
178 | local function MI2_EventUnitHealth() |
||
179 | local healthUpdated = false |
||
180 | |||
181 | if arg1 == "target" then |
||
182 | local health = UnitHealth("target") |
||
183 | MI2_Target.unitHealth = health |
||
184 | |||
185 | if health > 0 and MI2_Target.index then |
||
186 | -- calculate and sum up change in health percentage, skip negative changes (ie. target heals) |
||
187 | local change = MI2_Target.lastPercent - health |
||
188 | if change > 0 and MI2_Target.tempDamage > 0 then |
||
189 | MI2_Target.totalDamage = MI2_Target.totalDamage + MI2_Target.tempDamage |
||
190 | MI2_Target.totalPercent = MI2_Target.totalPercent + change |
||
191 | MI2_Target.lastPercent = health |
||
192 | MI2_Target.tempDamage = 0 |
||
193 | elseif change < 0 then |
||
194 | MI2_Target.lastPercent = health |
||
195 | MI2_Target.tempDamage = 0 |
||
196 | end |
||
197 | -- update DB immediately for new Mobs to support other AddOns |
||
198 | if MI2_Target.totalPercent < 90 then |
||
199 | MI2_SaveTargetHealthData() |
||
200 | end |
||
201 | healthUpdated = true |
||
202 | if MI2_Debug > 1 then chattext("M2DBG: UNIT_HEALTH: chng="..change..", h="..health..", HP="..MI2_Target.curHealth.."/"..MI2_Target.maxHealth..", totHP="..MI2_Target.totalDamage..", totP="..MI2_Target.totalPercent ) end |
||
203 | end |
||
204 | |||
205 | -- recalculate current health and update health display |
||
206 | MI2_CalculateHealth( MobInfoConfig.StableMax == 0 or MI2_Target.totalPercent < 90 ) |
||
207 | MobHealth_Display( ) |
||
208 | end |
||
209 | |||
210 | -- update health and mana shown in MobInfo tooltip |
||
211 | if GameTooltip:IsShown() then |
||
212 | MI2_UpdateTooltipHealthMana( MI2_Target.curHealth, MI2_Target.maxHealth ) |
||
213 | end |
||
214 | end -- MI2_EventUnitHealth() |
||
215 | |||
216 | |||
217 | ----------------------------------------------------------------------------- |
||
218 | -- MI2_EventUnitMana() |
||
219 | -- |
||
220 | -- Event handler for the "UNIT_MANA" event. |
||
221 | -- This handler will |
||
222 | ----------------------------------------------------------------------------- |
||
223 | local function MI2_EventUnitMana() |
||
224 | if arg1 == "target" then |
||
225 | -- recalculate current health and update health display |
||
226 | MI2_Target.unitHealth = UnitHealth("target") |
||
227 | MI2_CalculateHealth() |
||
228 | MobHealth_Display( ) |
||
229 | end |
||
230 | |||
231 | -- update health and mana shown in MobInfo tooltip |
||
232 | if GameTooltip:IsShown() then |
||
233 | MI2_UpdateTooltipHealthMana() |
||
234 | end |
||
235 | end -- MI2_EventUnitMana() |
||
236 | |||
237 | |||
238 | ----------------------------------------------------------------------------- |
||
239 | -- MI2_OnTargetChanged() |
||
240 | -- |
||
241 | -- Event handler for the "PLAYER_TARGET_CHANGED" event. This handler will |
||
242 | -- fill the global variable "MI2_Target" with all the data that MobInfo2 |
||
243 | -- needs to know about the current target. |
||
244 | ----------------------------------------------------------------------------- |
||
245 | local function MI2_OnTargetChanged() |
||
246 | local name = UnitName("target") |
||
247 | local level = UnitLevel("target") |
||
248 | local maxHealth = UnitHealthMax("target") |
||
249 | |||
250 | -- process table monitoring current targets |
||
251 | MI2_ProcessTargetTable() |
||
252 | MI2_IsNonMobLoot = false -- to reset non Mob loot detection |
||
253 | |||
254 | -- previous target post processing: update targets HP in database, |
||
255 | -- remember last targets mob index, update DPS if recorded |
||
256 | if MI2_Target.mobIndex then |
||
257 | MI2_SaveTargetHealthData() |
||
258 | MI2_LastTargetIdx = MI2_Target.mobIndex |
||
259 | if MI2_Target.FightStartTime then |
||
260 | MI2_RecordDps( MI2_Target.mobIndex, MI2_Target.FightEndTime - MI2_Target.FightStartTime, MI2_Target.FightDamage ) |
||
261 | end |
||
262 | end |
||
263 | |||
264 | if name and level and maxHealth == 100 |
||
265 | and (UnitCanAttack("player","target") or UnitIsPlayer("target")) then |
||
266 | MI2_Target = { name=name, level=level, tempDamage=0, maxHealth=100 } |
||
267 | MI2_Target.class = UnitClass("target") |
||
268 | MI2_Target.lastPercent = UnitHealth("target") |
||
269 | |||
270 | -- set index to either player or mob and store matching health database |
||
271 | if UnitIsPlayer("target") then |
||
272 | MI2_Target.index = name |
||
273 | MI2_Target.healthDB = MobHealthPlayerDB |
||
274 | else |
||
275 | MI2_Target.index = name..":"..level |
||
276 | MI2_Target.healthDB = MobHealthDB |
||
277 | MI2_Target.mobIndex = MI2_Target.index |
||
278 | MI2_NewMobTarget( MI2_Target.index ) |
||
279 | end |
||
280 | |||
281 | -- health calculation and health tracking initialisation |
||
282 | local pts, pct = MI2_GetHealthData( MI2_Target.healthDB, MI2_Target.index ) |
||
283 | MI2_Target.totalDamage = pts |
||
284 | MI2_Target.totalPercent = pct |
||
285 | else |
||
286 | MI2_Target = { totalPercent = 0, maxHealth=maxHealth } |
||
287 | end |
||
288 | |||
289 | -- update mob health display with health for new target |
||
290 | MI2_Target.unitHealth = UnitHealth("target") |
||
291 | MI2_CalculateHealth( true ) |
||
292 | MobHealth_Display() |
||
293 | |||
294 | -- update options dialog if shown |
||
295 | if frmMIConfig:IsVisible() then |
||
296 | MI2_DbOptionsFrameOnShow() |
||
297 | end |
||
298 | |||
299 | if MI2_Debug > 0 then if MI2_Target then chattext( "M2DBG: new target: idx=["..(MI2_Target.index or "nil").."], last=["..(MI2_LastTargetIdx or "nil").."]" ) |
||
300 | else chattext( "M2DBG: new target: idx=[nil], last=["..(MI2_LastTargetIdx or "nil").."]" ) end end |
||
301 | end -- MI2_OnTargetChanged() |
||
302 | |||
303 | |||
304 | ----------------------------------------------------------------------------- |
||
305 | -- MI2_EventZoneChanged() |
||
306 | -- |
||
307 | -- event handler for the WoW "CHAT_MSG_SPELL_SELF_BUFF" event |
||
308 | -- This event is called for lots of miscellaneous reasons. The reason I |
||
309 | -- subscribe to it is to detect the opening of chest loot or collecting |
||
310 | -- loot (chests, barrels, mining, herbs) |
||
311 | ----------------------------------------------------------------------------- |
||
312 | local function MI2_EventZoneChanged() |
||
313 | SetMapToCurrentZone(); |
||
314 | local continent = GetCurrentMapContinent() |
||
315 | if continent > 0 then |
||
316 | MI2_CurContinent = continent |
||
317 | end |
||
318 | local zone = GetCurrentMapZone() |
||
319 | if zone > 0 then |
||
320 | MI2_CurZone = zone |
||
321 | end |
||
322 | |||
323 | -- track globally unknown zones (ie. mainly instance names) |
||
324 | local zoneName = GetZoneText() |
||
325 | if zone == 0 and zoneName ~= "" then |
||
326 | if not MI2_ZoneTable[zoneName] then |
||
327 | MI2_ZoneTable.cnt = MI2_ZoneTable.cnt + 1 |
||
328 | MI2_ZoneTable[zoneName] = 100 + MI2_ZoneTable.cnt |
||
329 | end |
||
330 | MI2_CurZone = MI2_ZoneTable[zoneName] |
||
331 | MI2_Zones[MI2_CurContinent][MI2_CurZone] = zoneName |
||
332 | end |
||
333 | end -- MI2_EventZoneChanged() |
||
334 | |||
335 | |||
336 | ----------------------------------------------------------------------------- |
||
337 | -- MI2_Player_Login() |
||
338 | -- |
||
339 | -- register the GameTooltip:OnShow event at player login time. This ensures |
||
340 | -- that MobInfo is the (hopefully) last AddOn to hook into this event. |
||
341 | ----------------------------------------------------------------------------- |
||
342 | local function MI2_Player_Login() |
||
343 | -- MI2_GT_OnShow_Orig = GameTooltip:GetScript("OnShow") |
||
344 | -- GameTooltip:SetScript( "OnShow", MI2_GameTooltip_OnShow ) |
||
345 | |||
346 | -- create list of all zones for Mob location tracking |
||
347 | local continentNames = { GetMapContinents() } |
||
348 | local count = 0 |
||
349 | MI2_Zones = { [0] = { [0]="" } } |
||
350 | for idx,val in continentNames do |
||
351 | count = count + 1 |
||
352 | MI2_Zones[count] = { GetMapZones(count) } |
||
353 | end |
||
354 | |||
355 | -- add instance zones stored in MI2_ZoneTable to zone table |
||
356 | for idx,val in MI2_ZoneTable do |
||
357 | if idx ~= "cnt" then |
||
358 | MI2_Zones[0][val] = idx |
||
359 | MI2_Zones[1][val] = idx |
||
360 | MI2_Zones[2][val] = idx |
||
361 | end |
||
362 | end |
||
363 | |||
364 | MI2_EventZoneChanged() |
||
365 | |||
366 | -- import TipBuddy Mob location data into the MobInfo database |
||
367 | MI2_ImportLocationsFromMI2B() |
||
368 | end -- MI2_Player_Login() |
||
369 | |||
370 | |||
371 | ----------------------------------------------------------------------------- |
||
372 | -- MI2_GameTooltip_OnShow |
||
373 | -- |
||
374 | -- OnShow event handler for the GameTooltip frame |
||
375 | -- This handler will : |
||
376 | -- * call the original handler which it replaces |
||
377 | -- * if a valid Mob is hovered display the corresponding MobInfo data |
||
378 | -- * if a known item is hovered add the corresponding item data |
||
379 | ----------------------------------------------------------------------------- |
||
380 | function MI2_GameTooltip_OnShow( ) |
||
381 | MI2_HealthLine, MI2_ManaLine = nil, nil |
||
382 | |||
383 | -- check if mobinfo tooltip extensions are enabled and check for keypress mode |
||
384 | if MobInfoConfig.DisableMobInfo == 0 and (MobInfoConfig.KeypressMode == 0 |
||
385 | or MobInfoConfig.KeypressMode == 1 and IsAltKeyDown()) then |
||
386 | local firstline = getglobal("GameTooltipTextLeft1"); |
||
387 | |||
388 | if UnitCreatureType("mouseover") and UnitIsFriend("player","mouseover") == nil then |
||
389 | -- add mob data to mob tooltip (show abbreviated location) |
||
390 | MI2_BuildMobInfoTooltip( UnitName("mouseover"), UnitLevel("mouseover"), nil ) |
||
391 | GameTooltip:Show() |
||
392 | elseif firstline and MobInfoConfig.ItemTooltip == 1 and UnitClass("mouseover") == nil then |
||
393 | -- add item loot info to item tooltip |
||
394 | if MI2_BuildItemDataTooltip( firstline:GetText() ) then |
||
395 | GameTooltip:Show() |
||
396 | end |
||
397 | end |
||
398 | end |
||
399 | |||
400 | -- call original WoW event for GameTooltip:OnShow() |
||
401 | if MI2_GT_OnShow_Orig then |
||
402 | MI2_GT_OnShow_Orig(event) |
||
403 | end |
||
404 | end -- MI2_GameTooltip_OnShow() |
||
405 | |||
406 | |||
407 | ----------------------------------------------------------------------------- |
||
408 | -- MI2_InitializeEventTable() |
||
409 | -- |
||
410 | -- Initialize the event handler table according to the current MobInfo |
||
411 | -- config options settings. |
||
412 | ----------------------------------------------------------------------------- |
||
413 | function MI2_InitializeEventTable() |
||
414 | MI2_EventHandlers = {} |
||
415 | |||
416 | MI2_EventHandlers["VARIABLES_LOADED"] = MI2_MobInfo_Initialize |
||
417 | MI2_EventHandlers["PLAYER_LOGIN"] = MI2_Player_Login |
||
418 | MI2_EventHandlers["PLAYER_TARGET_CHANGED"] = MI2_OnTargetChanged |
||
419 | MI2_EventHandlers["CHAT_MSG_COMBAT_XP_GAIN"] = MI2x_EventCreatureDiesXP |
||
420 | MI2_EventHandlers["CHAT_MSG_COMBAT_HOSTILE_DEATH"] = MI2x_CreatureDiesHostile |
||
421 | MI2_EventHandlers["CHAT_MSG_SPELL_SELF_BUFF"] = MI2_EventSelfBuff -- for treasure/collect loot detection |
||
422 | MI2_EventHandlers["LOOT_OPENED"] = MI2_EventLootOpened |
||
423 | MI2_EventHandlers["LOOT_CLOSED"] = MI2_EventLootClosed |
||
424 | MI2_EventHandlers["LOOT_SLOT_CLEARED"] = MI2_EventLootSlotCleared |
||
425 | MI2_EventHandlers["UNIT_COMBAT"] = MI2_EventUnitCombat |
||
426 | MI2_EventHandlers["UNIT_HEALTH"] = MI2_EventUnitHealth |
||
427 | MI2_EventHandlers["UNIT_MANA"] = MI2_EventUnitMana |
||
428 | MI2_EventHandlers["ZONE_CHANGED_NEW_AREA"] = MI2_EventZoneChanged |
||
429 | MI2_EventHandlers["ZONE_CHANGED_INDOORS"] = MI2_EventZoneChanged |
||
430 | |||
431 | -- DPS events only needed when char data recording is enabled |
||
432 | if MobInfoConfig.SaveCharData == 1 then |
||
433 | MI2_EventHandlers["CHAT_MSG_COMBAT_SELF_HITS"] = MI2_EventSelfMelee |
||
434 | MI2_EventHandlers["CHAT_MSG_SPELL_SELF_DAMAGE"] = MI2_EventSelfSpell |
||
435 | MI2_EventHandlers["CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE"] = MI2_EventSpellPeriodic |
||
436 | MI2_EventHandlers["CHAT_MSG_COMBAT_PET_HITS"] = MI2_EventSelfPet |
||
437 | MI2_EventHandlers["CHAT_MSG_SPELL_PET_DAMAGE"] = MI2_EventSelfPet |
||
438 | end |
||
439 | |||
440 | -- register event handlers for tooltip (if active) |
||
441 | if MobInfoConfig.DisableMobInfo == 0 then |
||
442 | if MI2_Debug > 0 then chattext( "M2DBG: UpdateMobInfoState: MobInfo enabled" ) end |
||
443 | end |
||
444 | |||
445 | -- register event handlers for MobHealth (if active) |
||
446 | if MobInfoConfig.DisableHealth == 0 then |
||
447 | if MI2_Debug > 0 then chattext( "M2DBG: UpdateMobInfoState: MobHealth enabled" ) end |
||
448 | end |
||
449 | end -- MI2_InitializeEventTable() |
||
450 | |||
451 | |||
452 | ----------------------------------------------------------------------------- |
||
453 | -- MI2_OnEvent() |
||
454 | -- |
||
455 | -- MobInfo main event handler function, gets called for all registered events |
||
456 | -- uses table of event handlers which gets initialised in "OnLoad" |
||
457 | ----------------------------------------------------------------------------- |
||
458 | function MI2_OnEvent( event ) |
||
459 | if event then |
||
460 | -- debug output section for testing/debugging |
||
461 | if MI2_Debug > 2 then |
||
462 | chattext("M2DBG: event="..event..", a1="..(arg1 or "<nil>")..", a2="..(arg2 or "<nil>")..", a3="..(arg3 or "<nil>")..", a4="..(arg4 or "<nil>")) |
||
463 | end |
||
464 | |||
465 | -- call event handler function for event |
||
466 | if MI2_EventHandlers[event] then |
||
467 | MI2_EventHandlers[event]() |
||
468 | return 0 |
||
469 | else |
||
470 | if MI2_Debug > 0 then |
||
471 | chattext("M2DBG: unknown event="..event..", a1="..(arg1 or "<nil>")..", a2="..(arg2 or "<nil>")..", a3="..(arg3 or "<nil>")..", a4="..(arg4 or "<nil>")) |
||
472 | end |
||
473 | end |
||
474 | end |
||
475 | end -- MI2_OnEvent |
||
476 | |||
477 | |||
478 | ----------------------------------------------------------------------------- |
||
479 | -- MI2_OnLoad() |
||
480 | -- |
||
481 | -- register all events that we want to receive and process, build table |
||
482 | -- of event handler functions for easy processing of events in "OnEvent" |
||
483 | ----------------------------------------------------------------------------- |
||
484 | function MI2_OnLoad() |
||
485 | -- register all events that we want to catch and process |
||
486 | this:RegisterEvent("VARIABLES_LOADED") |
||
487 | this:RegisterEvent("PLAYER_LOGIN") |
||
488 | this:RegisterEvent("PLAYER_TARGET_CHANGED") |
||
489 | this:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN") |
||
490 | this:RegisterEvent("CHAT_MSG_COMBAT_HOSTILE_DEATH") |
||
491 | this:RegisterEvent("CHAT_MSG_COMBAT_SELF_HITS") |
||
492 | this:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE") |
||
493 | this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE") |
||
494 | this:RegisterEvent("CHAT_MSG_COMBAT_PET_HITS") |
||
495 | this:RegisterEvent("CHAT_MSG_SPELL_PET_DAMAGE") |
||
496 | this:RegisterEvent("CHAT_MSG_SPELL_SELF_BUFF") |
||
497 | this:RegisterEvent("UNIT_COMBAT") |
||
498 | this:RegisterEvent("UNIT_HEALTH") |
||
499 | this:RegisterEvent("UNIT_MANA") |
||
500 | this:RegisterEvent("LOOT_OPENED") |
||
501 | this:RegisterEvent("LOOT_CLOSED") |
||
502 | this:RegisterEvent("LOOT_SLOT_CLEARED") |
||
503 | this:RegisterEvent("ZONE_CHANGED_NEW_AREA") |
||
504 | this:RegisterEvent("ZONE_CHANGED_INDOORS") |
||
505 | |||
506 | -- only react to VARIABLES_LOADED until event has fired |
||
507 | MI2_EventHandlers = { VARIABLES_LOADED = MI2_MobInfo_Initialize } |
||
508 | |||
509 | -- prepare for importing external database data |
||
510 | MI2_PrepareForImport() |
||
511 | |||
512 | -- create chat event scan strings from global WoW constants |
||
513 | MI2_Scan_SelfBuff = string.gsub( SIMPLEPERFORMSELFOTHER, "(%%s)", "%(%.%+%)" ) |
||
514 | MI2_Scan_SelfBuff = string.gsub( MI2_Scan_SelfBuff, "(%%%d$s)", "%(%.%+%)") |
||
515 | |||
516 | -- set some stuff that is needed (only) for improved compatibility |
||
517 | -- to other AddOns wanting to use MobHealth info |
||
518 | if not MobHealth_OnEvent then |
||
519 | if MI2_Debug > 0 then chattext( "M2DBG: setting up compatibility variables" ) end |
||
520 | MobHealthFrame = "MI2" |
||
521 | MobHealth_OnEvent = MI2_OnEvent |
||
522 | end |
||
523 | |||
524 | if MI2_Debug > 0 then chattext( "M2DBG: MobInfo_OnLoad: all events registered" ) end |
||
525 | end -- MI2_OnLoad() |