forked from jp-ganis/JPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jpevents.lua
executable file
·647 lines (584 loc) · 20.2 KB
/
jpevents.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
--[[[
@module Events
@description
JPS Event Handling. If you need to react to specific events or want to execute a function this module might help you.
Instead of creating your own frame and event-handler you can just hook into the JPS main frame and register functions
here.[br]
[br]
This module also contains profiling support for the events. If enabled you will get the memory consumption from all events summarized
- [i]Attention:[/i] This has a serious impact on FPS!
]]--
-- Logger
local LOG=jps.Logger(jps.LogLevel.ERROR)
-- JPS Frame
local jpsFrame = CreateFrame("Frame", "JPSFrame")
-- Update Table
local updateTable = {}
-- Event Table for all events
local eventTable = {}
-- Event Table for COMBAT_LOG_EVENT_UNFILTERED Sub-Types
local combatLogEventTable = {}
-- Localization
local L = MyLocalizationTable
--------------------------
-- (UN)REGISTER FUNCTIONS
--------------------------
--[[[
@function jps.registerOnUpdate
@description
Register OnUpdate Function[br]
Adds the given function to the update table if it wasn't already registered.[br]
[br][i]Usage:[/i][br]
[code]
jps.registerOnUpdate(function()[br]
print("Update")[br]
end)[br]
[/code]
@param fn function to be executed on update
]]--
function jps.registerOnUpdate(fn)
if not updateTable[fn] then
updateTable[fn] = fn
return true
end
end
--[[[
@function jps.unregisterOnUpdate
@description
Unregister OnUpdate Function[br]
Removes the given event function from the update table if it was registered earlier. Has no effect if the function wasn't registered.[br]
[br][i]Usage:[/i][br]
[code]
function myOnUpdate() ... end[br]
...[br]
jps.registerOnUpdate(myOnUpdate)[br]
...[br]
jps.unregisterOnUpdate(myOnUpdate)[br]
[/code]
@param fn function to unregister
]]--
function jps.unregisterOnUpdate(fn)
if updateTable[fn] then
updateTable[fn] = nil
return true
end
end
--[[[
@function jps.registerEvent
@description
Adds the given event function to the event table if it wasn't already registered.[br]
[br][i]Usage:[/i][br]
[code]
jps.registerEvent("LOOT_OPENED", function()[br]
print("You opened Loot!")[br]
end)[br]
[/code]
@param event event name
@param fn function to be executed on update
]]--
function jps.registerEvent(event, fn)
if not eventTable[event] then
eventTable[event] = {}
jpsFrame:RegisterEvent(event)
end
if not eventTable[event][fn] then
eventTable[event][fn] = fn
return true
end
end
--[[[
@function jps.unregisterEvent
@description
Removes the given event function from the event table if it was registered earlier. Has no effect if the function wasn't registered.[br]
[br][i]Usage:[/i][br]
[code]
function myLootOpened() ... end[br]
...[br]
jps.registerEvent("LOOT_OPENED", myLootOpened)[br]
...[br]
jps.unregisterEvent("LOOT_OPENED", myLootOpened)[br]
[/code]
@param event event name
@param fn function to unregister
]]--
function jps.unregisterEvent(event, fn)
if eventTable[event] and eventTable[event][fn] then
eventTable[event][fn] = nil
local count = 0
for k in pairs(eventTable[event]) do count = count + 1 end
if count == 0 then
jpsFrame:UnregisterEvent(event)
end
return true
end
end
--[[[
@function jps.registerCombatLogEventUnfiltered
@description
Register event subtype for COMBAT_LOG_EVENT_UNFILTERED - Adds the given event function to the COMBAT_LOG_EVENT_UNFILTERED table if it wasn't already registered.[br]
[br][i]Usage:[/i][br]
[code]
jps.registerCombatLogEventUnfiltered("SWING_DAMAGE", function()[br]
print("Swing Damage - yay!")[br]
end)[br]
[/code]
@param event name of the combat sub-event
@param fn function which should be executed on event
]]--
function jps.registerCombatLogEventUnfiltered(event, fn)
if not combatLogEventTable[event] then
combatLogEventTable[event] = {}
jpsFrame:RegisterEvent(event)
end
if not combatLogEventTable[event][fn] then
combatLogEventTable[event][fn] = fn
return true
end
end
--[[[
@function jps.unregisterCombatLogEventUnfiltered
@description
Removes the given event function from the COMBAT_LOG_EVENT_UNFILTERED table if it was registered earlier. Has no effect if the function wasn't registered.[br]
[br][i]Usage:[/i][br]
[code]
function mySwingDamage() ... end[br]
...[br]
jps.registerCombatLogEventUnfiltered("SWING_DAMAGE", mySwingDamage)[br]
...[br]
jps.unregisterCombatLogEventUnfiltered("SWING_DAMAGE", mySwingDamage)[br]
[/code]
@param event event name
@param fn function to unregister
]]--
function jps.unregisterCombatLogEventUnfiltered(event, fn)
if combatLogEventTable[event] and combatLogEventTable[event][fn] then
combatLogEventTable[event][fn] = nil
local count = 0
for k in pairs(combatLogEventTable[event]) do count = count + 1 end
if count == 0 then
jpsFrame:UnregisterEvent(event)
end
return true
end
end
--------------------------
-- PROFILING FUNCTIONS
--------------------------
local enableProfiling = false
local enableUnfilteredProfiling = false
local memoryUsageTable = {}
local memoryStartTable = {}
local memoryUsageInterval = 0
local function startProfileMemory(key)
if not memoryStartTable[key] then UpdateAddOnMemoryUsage(); memoryStartTable[key] = GetAddOnMemoryUsage("JPS") end
end
local function endProfileMemory(key)
if not memoryStartTable[key] then return end
if not memoryUsageTable[key] then memoryUsageTable[key] = 0 end
UpdateAddOnMemoryUsage()
memoryUsageTable[key] = GetAddOnMemoryUsage("JPS") - memoryStartTable[key]
end
local reportInterval = 15
local maxProfileDuration = 60
local lastReportUpdate = 0
local totalProfileDuration = 0
--[[[ Internal - Memory Usage Report ]]--
function jps.reportMemoryUsage(elapsed)
lastReportUpdate = lastReportUpdate + elapsed
totalProfileDuration = totalProfileDuration + elapsed
if lastReportUpdate > reportInterval then
lastReportUpdate = 0
print("Memory Usage Report:")
for key,usage in pairs(memoryUsageTable) do
print(" * " .. key .. ": " .. usage .. " KB in " .. reportInterval .. " seconds" )
end
UpdateAddOnMemoryUsage()
print(" *** TOTAL: " .. (GetAddOnMemoryUsage("JPS")-memoryUsageInterval) .. " KB in " .. reportInterval .. " seconds" )
memoryUsageInterval = GetAddOnMemoryUsage("JPS")
memoryStartTable = {}
memoryUsageTable = {}
end
if totalProfileDuration >= maxProfileDuration then
enableProfiling = false
enableUnfilteredProfiling = false
end
end
--[[[
@function jps.enableProfiling
@description
Enables profiling for one minute. Every 15 seconds you will get the memory consumption from all events summarized
- [i]Attention:[/i] This has a serious impact on FPS!
@param unfiltered [code]True[/code] if COMBAT_LOG_UNFILTERED events should be split up ([i]BIG PERFORMANCE DECREASE[/i]) - defaults to [code]False[/code]
]]--
function jps.enableProfiling(unfiltered)
totalProfileDuration = 0
lastReportUpdate = 0
enableProfiling = true
enableUnfilteredProfiling = unfiltered
UpdateAddOnMemoryUsage()
memoryUsageInterval = GetAddOnMemoryUsage("JPS")
end
--------------------------
-- EVENT LOOP FUNCTIONS
--------------------------
-- Update Handler
jpsFrame:SetScript("OnUpdate", function(self, elapsed)
if self.TimeSinceLastUpdate == nil then self.TimeSinceLastUpdate = 0 end
self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed
if (self.TimeSinceLastUpdate > jps.UpdateInterval) then
for _,fn in pairs(updateTable) do
local status, error = pcall(fn)
if not status then
LOG.error("Error %s on OnUpdate function %s", error, fn)
end
end
self.TimeSinceLastUpdate = 0
end
if enableProfiling then jps.reportMemoryUsage(elapsed) end
end)
--- Event Handler
jpsFrame:SetScript("OnEvent", function(self, event, ...)
if eventTable[event] then
if enableProfiling then startProfileMemory(event) end
for _,fn in pairs(eventTable[event]) do
local status, error = pcall(fn, ...)
if not status then
LOG.error("Error on event %s, function %s", error, fn)
end
end
if enableProfiling then endProfileMemory(event) end
end
-- Execute this code everytime
if jps.checkTimer("FacingBug") > 0 and jps.checkTimer("Facing") == 0 then
TurnLeftStop()
TurnRightStop()
CameraOrSelectOrMoveStop()
end
end)
--- COMBAT_LOG_EVENT_UNFILTERED Handler
jps.registerEvent("COMBAT_LOG_EVENT_UNFILTERED", function(timeStamp, event, ...)
if jps.Enabled and UnitAffectingCombat("player") == 1 and combatLogEventTable[event] then
LOG.debug("CombatLogEventUntfiltered: %s", event)
if enableUnfilteredProfiling and enableProfiling then startProfileMemory("COMBAT_LOG_EVENT_UNFILTERED::"..event) end
for _,fn in pairs(combatLogEventTable[event]) do
local status, error = pcall(fn, timeStamp, event, ...)
if not status then
LOG.error("Error on COMBAT_LOG_EVENT_UNFILTERED sub-event %s, function %s", error, fn)
end
end
if enableUnfilteredProfiling and enableProfiling then endProfileMemory("COMBAT_LOG_EVENT_UNFILTERED::"..event) end
end
end)
--------------------------
-- UPDATE FUNCTIONS
--------------------------
-- Garbage Collection
local function collectGarbage()
if jps.getConfigVal("collect garbage ingame(possible fps drop)") == 1 then
if GetAddOnMemoryUsage("JPS") > 5000 then collectgarbage("collect") end
end
end
jps.registerOnUpdate(collectGarbage)
-- TimeToDie Update
jps.registerOnUpdate(updateTimeToDie)
-- Combat
jps.registerOnUpdate(function()
if jps.Enabled and (jps.hasOOCRotation() > 0 or jps.Combat) then
jps_Combat()
end
end)
--------------------------
-- EVENT FUNCTIONS
--------------------------
-- PLAYER_LOGIN
jps.registerEvent("PLAYER_LOGIN", function()
NotifyInspect("player")
end)
-- PLAYER_ENTERING_WORLD
jps.registerEvent("PLAYER_ENTERING_WORLD", function()
jps.detectSpec()
reset_healtable()
jps.SortRaidStatus()
end)
-- INSPECT_READY
jps.registerEvent("INSPECT_READY", function()
if not jps.Spec then jps.detectSpec() end
if jps_variablesLoaded and not jps.Configged then
jps_createConfigFrame()
jps.runFunctionQueue("gui_loaded")
end
end)
-- VARIABLES_LOADED
jps.registerEvent("VARIABLES_LOADED", jps_VARIABLES_LOADED)
-- Enter Combat
jps.registerEvent("PLAYER_REGEN_DISABLED", function()
jps.Combat = true
jps.gui_toggleCombat(true)
jps.SortRaidStatus()
if jps.getConfigVal("timetodie frame visible") == 1 then
JPSEXTInfoFrame:Show()
end
jps.combatStart = GetTime()
end)
-- Leave Combat
local function leaveCombat()
if jps.checkTimer("FacingBug") > 0 then
TurnLeftStop()
TurnRightStop()
CameraOrSelectOrMoveStop()
end
jps.Opening = true
jps.Combat = false
jps.gui_toggleCombat(false)
jps.RaidTarget = {}
jps.EnemyTable = {}
jps.NextSpell = nil
jps.clearTimeToLive()
jps.SortRaidStatus() -- wipe jps.RaidTarget and jps.RaidStatus
if jps.getConfigVal("timetodie frame visible") == 1 then
JPSEXTInfoFrame:Hide()
end
jps.combatStart = 0
end
jps.registerEvent("PLAYER_REGEN_ENABLED", leaveCombat)
jps.registerEvent("PLAYER_REGEN_ENABLED", collectGarbage)
jps.registerEvent("PLAYER_UNGHOST", leaveCombat)
jps.registerEvent("PLAYER_UNGHOST", collectGarbage)
-- Group/Raid Update
jps.registerEvent("GROUP_ROSTER_UPDATE", jps.SortRaidStatus)
jps.registerEvent("RAID_ROSTER_UPDATE", jps.SortRaidStatus)
-- Dual Spec Respec -- only fire when spec change no other event before
jps.registerEvent("ACTIVE_TALENT_GROUP_CHANGED", jps.detectSpec)
jps.registerEvent("ACTIVE_TALENT_GROUP_CHANGED", jps.resetRotationTable)
jps.registerEvent("ACTIVE_TALENT_GROUP_CHANGED", function()
jps.detectSpecDisabled = false
end)
-- Save on Logout
jps.registerEvent("PLAYER_LEAVING_WORLD", jps_SAVE_PROFILE)
-- Hide Static Popup - thx here to Phelps & ProbablyEngine
local function hideStaticPopup(addon, eventBlocked)
jps.PLuaFlag = true
if string.upper(addon) == "JPS" then
StaticPopup1:Hide()
LOG.debug("Addon Action Blocked: %s", eventBlocked)
end
end
jps.registerEvent("ADDON_ACTION_FORBIDDEN", hideStaticPopup)
jps.registerEvent("ADDON_ACTION_BLOCKED", hideStaticPopup)
-- UI_ERROR_MESSAGE
jps.registerEvent("UI_ERROR_MESSAGE", function(event_error)
-- "UI_ERROR_MESSAGE" returns ONLY one arg1
-- http://www.wowwiki.com/WoW_Constants/Errors
-- http://www.wowwiki.com/WoW_Constants/Spells
if jps.Enabled then
if (event_error == SPELL_FAILED_NOT_BEHIND) then -- "You must be behind your target."
LOG.debug("SPELL_FAILED_NOT_BEHIND - %s", event_error)
jps.isNotBehind = true
jps.isBehind = false
elseif jps.FaceTarget and ((event_error == SPELL_FAILED_UNIT_NOT_INFRONT) or (event_error == ERR_BADATTACKFACING)) and not jps.moving then
LOG.debug("ERR_BADATTACKFACING - %s", event_error)
local TargetGuid = UnitGUID("target")
if FireHack and (TargetGuid ~= nil) then
--FH abpi changed
--local TargetObject = GetObjectFromGUID(TargetGuid)
--TargetObject:Face ()
else
jps.createTimer("Facing",0.6)
jps.createTimer("FacingBug",1.2)
TurnLeftStart()
CameraOrSelectOrMoveStart()
end
elseif (event_error == SPELL_FAILED_LINE_OF_SIGHT) or (event_error == SPELL_FAILED_VISION_OBSCURED) then
LOG.debug("SPELL_FAILED - %s", event_error)
jps.BlacklistPlayer(jps.LastTarget)
end
end
end)
-- "UNIT_SPELLCAST_SENT"
jps.registerEvent("UNIT_SPELLCAST_SENT", function(...)
local unitID = select(1,...)
local spellname = select(2,...)
jps.CastBar.latencySpell = spellname
if unitID == "player" and spellname then jps.CastBar.sentTime = GetTime() end
end)
descriptorTable = { L["Strikes"] , L["Roots"] , L["Transforms"] , L["Forces"] , L["Seduces"] }
-- "UNIT_SPELLCAST_START"
jps.registerEvent("UNIT_SPELLCAST_START", function(...)
local unitID = select(1,...)
local spellname = select(2,...)
if unitID == "player" and (spellname == jps.CastBar.latencySpell) then
jps.CastBar.startTime = GetTime()
else
jps.CastBar.startTime = nil
jps.CastBar.latency = 0
end
if jps.CastBar.startTime then
jps.CastBar.latency = jps.CastBar.startTime - jps.CastBar.sentTime
jps.CastBar.latencySpell = nil
else
jps.CastBar.latency = 0
end
if jps.checkTimer("CC") == 0 then
jps.CrowdControl = false
jps.CrowdControlTarget = nil
end
local spellID = select(5,...)
local castingTime = select(4, GetSpellInfo(spellID)) / 1000 -- castTime - Number - The cast time, in milliseconds
local descriptor = GetSpellDescription(spellID)
for _,desc in ipairs(descriptorTable) do
if jps.canDPS(unitID) and string.find(descriptor,desc) then
jps.createTimer("CC",castingTime)
jps.CrowdControl = true
jps.CrowdControlTarget = unitID
break end
end
end)
-- "UNIT_SPELLCAST_INTERRUPTED" -- "UNIT_SPELLCAST_STOP"
local function latencySpell ()
jps.CastBar.startTime = nil
jps.CastBar.latency = 0
end
jps.registerEvent("UNIT_SPELLCAST_INTERRUPTED", latencySpell)
jps.registerEvent("UNIT_SPELLCAST_STOP", latencySpell)
-- UNIT_SPELLCAST_SUCCEEDED
jps.registerEvent("UNIT_SPELLCAST_SUCCEEDED", function(...)
local unitID = select(1,...)
local spellname = select(2,...)
local spellID = select(5,...)
if jps.FaceTarget then
if (unitID == "player") and spellID then
jps.CurrentCast = tostring(select(1,GetSpellInfo(spellID)))
if jps.checkTimer("FacingBug") > 0 then
TurnLeftStop()
TurnRightStop()
CameraOrSelectOrMoveStop()
end
end
end
if (jps.Class == "Druid" and jps.Spec == "Feral") or jps.Class == "Rogue" then
-- "Druid" -- 5221 -- "Shred" -- "Ambush" 8676
if (unitID == "player") and spellname == tostring(select(1,GetSpellInfo(5221))) then
jps.isNotBehind = false
jps.isBehind = true
elseif (unitID == "player") and spellname == tostring(select(1,GetSpellInfo(8676))) then
jps.isNotBehind = false
jps.isBehind = true
end
end
end)
-- RAIDSTATUS UPDATE
-- UNIT_HEALTH events are sent for raid and party members regardless of their distance from the character of the host.
-- This makes UNIT_HEALTH extremely valuable to monitor PARTY AND RAID MEMBERS.
-- arg1 the UnitID of the unit whose health is affected player, pet, target, mouseover, party1..4, partypet1..4, raid1..40
-- "UNIT_HEALTH_FREQUENT" Same event as UNIT_HEALTH, but not throttled as aggressively by the client
-- "UNIT_HEALTH_PREDICTION" arg1 unitId receiving the incoming heal
jps.registerEvent("UNIT_HEALTH_FREQUENT", function(unit)
if jps.Enabled then
local unittarget = unit.."target"
if jps.isHealer then jps.UpdateRaidStatus(unit) end
if jps.canDPS(unittarget) then -- Working only with raidindex.."target" and not with unitname.."target"
local unittarget_hpct = jps.hp(unittarget)
local unittarget_guid = UnitGUID(unittarget)
local countTargets = 0
if jps.RaidTarget[unittarget_guid] ~= nil then
countTargets = jps.RaidTarget[unittarget_guid]["count"]
end
if jps.RaidTarget[unittarget_guid] == nil then
jps.RaidTarget[unittarget_guid] = {}
end
jps.RaidTarget[unittarget_guid]["unit"] = unittarget
jps.RaidTarget[unittarget_guid]["hpct"] = unittarget_hpct
jps.RaidTarget[unittarget_guid]["count"] = countTargets + 1
else
jps.removeTableKey(jps.RaidTarget,unittarget_guid)
jps.removeTableKey(jps.EnemyTable,unittarget_guid)
end
end
end)
-- PLAYER_LEVEL_UP - if jps was disabled because of toon level < 10
jps.registerEvent("PLAYER_LEVEL_UP", function(level)
jps.Level = level
if level == "10" then
jps.detectSpec()
jps.Enabled = true
jps.detectSpecDisabled = false
end
end)
jps.registerEvent("CHAT_MSG_ADDON",function(prefix,message,channel,sender)
if prefix == "D4" and (channel == "PARTY" or channel == "RAID" or channel == "INSTANCE_CHAT" or channel == "WHISPER" or channel == "GUILD") then --DBM Pull
local _,pt = (message or ""):match("^(PT).(%d+)")
if pt then
jps.startPulltimer(tonumber(pt))
end
end
end)
--------------------------
-- COMBAT_LOG_EVENT_UNFILTERED FUNCTIONS
--------------------------
-- eventtable[4] == sourceGUID
-- eventtable[5] == sourceName
-- eventtable[6] == sourceFlags
-- eventtable[8] == destGUID
-- eventtable[9] == destName
-- eventtable[10] == destFlags
-- eventtable[15] == amount if suffix is _DAMAGE or _HEAL
-- TABLE ENEMIES IN COMBAT
jps.registerEvent("COMBAT_LOG_EVENT_UNFILTERED", function(...)
local event = select(2,...)
local sourceGUID = select(4,...)
local sourceName = select(5,...)
local sourceFlags = select(6,...)
local destGUID = select(8,...)
local destName = select(9,...)
local destFlags = select(10,...)
local spellID = select(12,...)
if sourceName == GetUnitName("player") and event == "SPELL_HEAL" then
update_healtable(...)
end
if destName == GetUnitName("player") and (event == "SPELL_DAMAGE" or event == "SWING_DAMAGE") then
jps.createTimer("Player_Aggro", 4 )
end
if sourceName == GetUnitName("player") and spellID == 17 then
jps.createTimer("Shield", 12 )
end
if destGUID ~= nil and event == "UNIT_DIED" then
jps.removeTableKey(jps.RaidTimeToDie,destGUID)
jps.removeTableKey(jps.RaidTarget,destGUID)
jps.removeTableKey(jps.EnemyTable,destGUID)
end
if sourceFlags and (bit.band(sourceFlags,COMBATLOG_OBJECT_REACTION_HOSTILE) > 0)
and (bit.band(sourceFlags,COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) > 0)
and destFlags and (bit.band(destFlags,COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == 0)
and jps.canHeal(destName) and (sourceGUID ~= nil) then
local enemyFriend = jps.stringSplit(destName,"-") -- eventtable[9] == destName -- "Bob" or "Bob-Garona" to "Bob"
if jps.EnemyTable[sourceGUID] == nil then jps.EnemyTable[sourceGUID] = {} end
jps.EnemyTable[sourceGUID]["friend"] = enemyFriend -- TABLE OF ENEMY GUID TARGETING FRIEND NAME
end
-- TABLE DAMAGE
-- eventtable[15] -- amount if suffix is SPELL_DAMAGE or SPELL_HEAL
-- eventtable[12] -- amount if suffix is SWING_DAMAGE
local action = select(2, ...)
local periodic = select(15, ...)
local swing = select(12, ...)
local destGUID = select(8, ...)
local dmgTTD = 0
if destGUID ~= nil and (action == "SPELL_DAMAGE" or action == "SPELL_PERIODIC_DAMAGE") and periodic ~= nil then
if periodic > 0 then
dmgTTD = periodic
end
elseif destGUID ~= nil and (action == "SWING_DAMAGE") and swing ~= nil then
if swing > 0 then
dmgTTD = swing
end
end
if InCombatLockdown()==1 then -- InCombatLockdown() returns 1 if in combat or nil otherwise
jps.Combat = true
jps.gui_toggleCombat(true)
if jps.RaidTimeToDie[destGUID] == nil then jps.RaidTimeToDie[destGUID] = {} end
local dataset = jps.RaidTimeToDie[destGUID]
local data = table.getn(dataset)
if data >= jps.maxTDDLifetime then table.remove(dataset, jps.maxTDDLifetime) end
table.insert(dataset, 1, {GetTime(), dmgTTD})
jps.RaidTimeToDie[destGUID] = dataset --jps.RaidTimeToDie[unitGuid] = { [1] = {GetTime(), thisEvent[15] },[2] = {GetTime(), thisEvent[15] },[3] = {GetTime(), thisEvent[15] } }
end
end)