-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatchDebuffs.lua
More file actions
533 lines (522 loc) · 18.2 KB
/
watchDebuffs.lua
File metadata and controls
533 lines (522 loc) · 18.2 KB
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
Debuffs = {
locEffectTypeMap = {
CONFUSE = 'incap',
STUN_MECHANIC = 'stun',
STUN = 'stun',
SILENCE = 'silence',
PACIFYSILENCE = 'silence',
PACIFY = 'silence',
FEAR_MECHANIC = 'fear',
FEAR = 'fear',
CHARM = 'charm',
POSSESS = 'charm',
DISARM = 'disarm',
ROOT = 'root',
SCHOOL_INTERRUPT = 'interrupt'
},
getByLocAPI = function(who)
local who = who or "player";
local debuffs = {};
local locEvents = 0;
if (who == 'player') then
locEvents = C_LossOfControl.GetActiveLossOfControlDataCount();
else
locEvents = C_LossOfControl.GetActiveLossOfControlDataCountByUnit(who) or 0;
end
for i=1, locEvents, 1
do
local ev = nil;
if (who == 'player') then
ev = C_LossOfControl.GetActiveLossOfControlData(i);
else
ev = C_LossOfControl.GetActiveLossOfControlDataByUnit(who, i);
end
-- SILENCE, SCHOOL_INTERRUPT
-- FEAR_MECHANIC, FEAR, STUN_MECHANIC, STUN, PACIFYSILENCE, PACIFY, CHARM, DISARM, ROOT, CONFUSE, POSSESS
-- missing = slow, incapacitated, sleep
-- confuse = polymorph (incap?)
local dbType = Debuffs.locEffectTypeMap[ev.locType];
if (dbType ~= nil) then
local debuff = {
name = ev.displayText,
icon = nil,
["type"] = dbType,
length = ev.duration,
remaining = LCU.round(ev.timeRemaining),
desc = desc,
id = ev.spellID,
source = 'api',
extraInfo = ''
};
local desc = GetSpellDescription(ev.spellID);
if (dbType == 'interrupt') then
if (ev.lockoutSchool == 0) then
debuff.type = nil;
else
local schoolName = GetSchoolString(ev.lockoutSchool);
if (schoolName == 'Unknown') then
debuff.type = nil;
else
debuff.type = 'spellLock';
debuff.extraInfo = schoolName;
end
end
end
if (debuff.remaining == nil) then
debuff.remaining = 999;
end
if (debuff.type ~= nil and debuff.remaining > 0) then
local currDb = Debuffs.types[debuff.type].debuff;
if (currDb == false) then
debuffs[debuff.type] = debuff;
elseif (debuff.remaining > currDb.remaining or currDb.id == debuff.id) then
debuffs[debuff.type] = debuff;
end
end
-- else
-- LCMessage('unknown effect ' .. i .. ' - ' .. ev.locType .. ev.displayText .. LCU.str(ev.timeRemaining) .. GetSpellLink(ev.spellID), 'PRINT', LCU.round(ev.timeRemaining/2))
end
end
return debuffs;
end
,getByDebuffs = function(who)
who = who or 'player';
local debuffs = {};
local scanAuras = true;
local auraI = 1;
while(scanAuras==true) do
local n,icon,_,dbType,duration,expires,_,_,_,id = Debuffs.getAura(who,auraI,'HARMFUL');
if(n ~= nil and expires ~= nil) then
local desc = GetSpellDescription(id) or '';
local debuff = {
name = n,
icon = icon,
["type"] = (dbType or ''),
length = duration,
remaining = LCU.round(expires-GetTime()),
desc = desc,
id = id,
extraInfo = '',
source = 'debuff'
};
local dbType = Debuffs.getType(debuff);
if(dbType==false and LCU.debugMode) then LCU.sendMsg('Couldnt find type for "'..debuff.name..'" = "'..debuff.desc..'"') end
if(dbType~=false) then
debuffs[dbType] = debuff;
end
end
if(n == nil or auraI >= 40) then scanAuras = false; end
auraI = auraI+1;
end
return debuffs;
end
,types = {
fear = {
debuff = false
,enabled = true
,names = {'Fear','Feared','Scare','Scared','Psychic Scream'}
,descTerms = {' [fF]ear','^Fear','[sS]cared','flee in terror'}
,message = LCLang.dynaGet('%REF is feared for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer feared')
}
,charm = {
debuff = false
,enabled = true
,names = {'Charm','Charmed','Mind Control'}
,descTerms = {'[cC]harmed'}
,message = LCLang.dynaGet('%REF has been charmed for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer charmed')
}
,disarm = {
debuff = false
,enabled = true
,names = {'Disarm','Disarmed'}
,descTerms = {'[dD]isarm'}
,message = LCLang.dynaGet('%REF has been disarmed for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer disarmed')
}
,incap = {
debuff = false
,enabled = true
,names = {'Polymorph','Freeze','Hex','Hibernate','Choking','Choking Vines'}
,ignoreNames = {'Unbreakable Will'}
,descTerms = {' [iI]ncapacitat','^Incapacitated','[dD]isorient','[sS]apped','unable to act','[cC]hoke','[cC]hoking'}
,message = LCLang.dynaGet('%REF is incapacitated for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer incapacitated')
}
,sleep = {
debuff = false
,enabled = true
,names = {'Sleep'}
,descTerms = {'[dD]eep slumber','[sS]lumber','[aA]sleep','[sS]leeping'}
,message = LCLang.dynaGet('%REF is asleep for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer asleep')
}
,oom = {
debuff = false
,enabled = true
,names = {}
,descTerms = {}
,message = LCLang.dynaGet('%REF is out of mana!')
,recoverMessage = LCLang.dynaGet('%REF has mana again')
}
,root = {
debuff = false
,enabled = true
,names = {'Freeze','Root','Entangling Roots','Frozen'}
,descTerms = {' [rR]oot','^Rooted','[fF]rozen','[iI]mmobiliz'}
,message = LCLang.dynaGet('%REF has been rooted for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer rooted')
}
,silence = {
debuff = false
,enabled = true
,names = {'Silence','Solar Beam','Strangulate','Arcane Torrent','Silencing Shot'}
,ignoreNames = {'Unstable Afflication'}
,descTerms = {'Silenced',' ?[sS]ilence[ds]?','[cC]annot cast spells','[pP]acified'}
,message = LCLang.dynaGet('%REF has been silenced for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer silenced')
}
,slow = {
debuff = false
,enabled = true
,names = {'Dazed','Daze','Slow','Slowed','Hamstring','Ice Trap'}
,descTerms = {' [sS]low','^Slow',' [dD]azed?','^Dazed?','movement speed reduced'}
,message = LCLang.dynaGet('%REF has been slowed for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer slowed')
}
,stun = {
debuff = false
,enabled = true
,names = {'Stun','Stunned','Stomp'}
,ignoreNames = {'Rake'}
,descTerms = {' [sS]tun','^Stun'}
,message = LCLang.dynaGet('%REF has been stunned for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer stunned')
}
,spellLock = { --UNIT_SPELLCAST_INTERRUPTED , UNIT_SPELLCAST_STOP , UNIT_SPELLCAST_FAILED , UNIT_SPELLCAST_FAILED_QUIET
debuff = false
,enabled = true
,names = {}
,descTerms = {'preventing any spell in that school','preventing any spell from that school'}
,message = LCLang.dynaGet('%REF has been %sch locked for [remaining] seconds - {SPELL_LINK}')
,recoverMessage = LCLang.dynaGet('%REF is no longer %sch locked')
--[[
School can be checked with:
List of one spell for each spell school per class & spec
Check last interrupted spellID with IsUsableSpell (returns: usable, nomana)
Check last interrupted spellID isn't on cooldown with GetSpellCooldown (returns: start, duration, enabled)
(maybe check GetSpellDescription ?)
--]]
}
}
,addName = function(dbType,name)
if(Debuffs.types[dbType]==nil) then return false; end
local found = false;
for k,v in pairs(Debuffs.types[dbType].names) do
if(v == name) then found = true; end
end
if(found == false) then table.insert(Debuffs.types[dbType].names,name); end
end
,addNames = function(dbType,names)
for k,name in pairs(names) do
Debuffs.addName(dbType,name);
end
end
,addDesc = function(dbType,desc)
if(Debuffs.types[dbType]==nil or type(desc)~='string') then return false; end
local found = false;
for k,v in pairs(Debuffs.types[dbType].descTerms) do
if(v == desc) then found = true; end
end
if(found == false) then
table.insert(Debuffs.types[dbType].descTerms,desc);
end
end
,addDescs = function(dbType,descs)
for k,desc in pairs(descs) do
Debuffs.addDesc(dbType,desc);
end
end
,getDebuffMessage = function(dbType)
if(Debuffs.types[dbType]==nil) then return ''; end
return LCcfg.get('db_message_'..dbType,Debuffs.types[dbType].message);
end
,getDebuffRecoverMessage = function(dbType)
if(Debuffs.types[dbType]==nil) then return ''; end
return LCcfg.get('db_recovermessage_'..dbType,Debuffs.types[dbType].recoverMessage);
end
,isType = function(debuff,dbType)
if(Debuffs.types[dbType]==nil or not LCcfg.watching(dbType)) then return false; end
local ret = false;
for k,v in pairs(Debuffs.types[dbType].names) do
if(debuff.name == v) then ret = true; end
end
-- These are basic protection against unwanted matches where effects say "At 5 stacks they are stunned"/"if dispelled"
local excludeTerms = {'[dD]ispel','stack','application','%d yards','nearby enem'};
for k,v in pairs(Debuffs.types[dbType].descTerms) do
if(string.match(debuff.desc,v)~=nil and string.match(debuff.desc,'stack')==nil) then
ret = true;
for i,term in pairs(excludeTerms) do
if(ret == true and string.match(debuff.desc,term)~=nil) then
ret = false;
end
end
end
end
if(ret == true) then
for k,v in pairs(Debuffs.types[dbType].ignoreNames or {}) do
if(debuff.name == v) then ret = false; end
end
end
return ret;
end
,getType = function(debuff)
for dbType in pairs(Debuffs.types) do
if(Debuffs.isType(debuff,dbType)) then return dbType; end
end
return false;
end
,fillMsg = function(msg,debuff)
local role = LCcfg.getPlayerSpecRole();
if(role=='dps') then role = 'DPS';
else role = LCU.upperFirst(role); end
local ref = role=='DPS' and LCLang.get('A DPS') or LCLang.get('The '..role);
ref = ref..' ('..LCU.player.name..')';
local newMsg = msg;
if(debuff.remaining == nil or debuff.remaining > 100) then
newMsg = newMsg:gsub(' for %[remaining%] seconds', '');
end
newMsg = newMsg:gsub('%[remaining%]',tostring(LCU.round(debuff.remaining)));
newMsg = newMsg:gsub('%%TR',tostring(LCU.round(debuff.remaining)));
newMsg = newMsg:gsub('%{SPELL_LINK%}',(GetSpellLink(debuff.id) or ''));
newMsg = newMsg:gsub('%%SL',(GetSpellLink(debuff.id) or ''));
newMsg = newMsg:gsub('%%NM',LCU.player.name);
newMsg = newMsg:gsub('%%RL',role);
newMsg = newMsg:gsub('%%rl',string.lower(role));
newMsg = newMsg:gsub('%%REF',ref);
newMsg = newMsg:gsub('%%SCH',debuff.extraInfo);
newMsg = newMsg:gsub('%%sch',string.lower(debuff.extraInfo));
return newMsg;
end
,checkDebuffs = function(debuffs, who)
who = who or 'player';
if (type(LCU.debuffs[who]) ~= 'table') then
LCU.debuffs[who] = {};
end
local announcedDebuff = false;
for dbType,info in pairs(Debuffs.types) do
if(LCcfg.watching(dbType) and (LCU.debuffs[who][dbType] ~= nil or debuffs[dbType] ~= nil)) then
local currDebuff = LCU.debuffs[who][dbType];
local debuff = debuffs[dbType];
local hasGone = false;
if(debuff == nil) then
debuff = currDebuff;
hasGone = true;
end
local lastAnnounce = info.lastAnnounce or 0;
local theTime = GetTime();
local timeDiff = theTime - lastAnnounce;
local repeatLimit = nil;
if(info.repeatLimit) then
repeatLimit = info.repeatLimit;
elseif(hasGone == false) then
repeatLimit = 6;
if(debuff.remaining >= 20) then repeatLimit = 12; end
if(debuff.remaining >= 30) then repeatLimit = 18; end
if(debuff.remaining >= 50) then repeatLimit = 18; end
if(debuff.remaining >= 75) then repeatLimit = 20; end
else
repeatLimit = 9;
end
local minDebuffTime = LCcfg.getMinDebuffTime(dbType);
local safeToAnnounce = (timeDiff >= repeatLimit or lastAnnounce==0) and debuff.remaining >= minDebuffTime;
if(LCU.debugMode and debuff.remaining > 0 and debuff.remaining < minDebuffTime) then print(dbType .. ' warning stopped due to min debuff time config: ' .. debuff.remaining .. ' < ' .. minDebuffTime); end
if(type(info.extraInfo)=="function") then debuff.extraInfo = info.extraInfo(debuff); end
local message = Debuffs.getDebuffMessage(dbType);
if(type(message)=="function") then message = message(debuff); end
local recoverMessage = Debuffs.getDebuffRecoverMessage(dbType);
if(type(recoverMessage)=="function") then recoverMessage = recoverMessage(debuff); end
message = Debuffs.fillMsg(message,debuff);
recoverMessage = Debuffs.fillMsg(recoverMessage,debuff);
if(safeToAnnounce and debuff.remaining > 0 and hasGone == false) then
if info.announcedDebuff == false or debuff.remaining > 0.75 then
LCU.sendMsg(message);
end
info.announcedRecovery = false;
info.announcedDebuff = true;
announcedDebuff = true;
info.lastAnnounce = theTime;
elseif(info.announcedDebuff == true and (debuff.remaining<=0.2 or hasGone==true) and info.announcedRecovery~=true) then
debuffs[dbType] = nil;
info.announcedRecovery = true;
info.announcedDebuff = false;
if(recoverMessage ~= '-') then
LCU.sendMsg(recoverMessage);
end
info.lastAnnounce = GetTime()-(repeatLimit-2);
end
end
end
local hadControl = LCU.player.hasControl;
LCU.player.hasControl = HasFullControl();
if(LCU.debugMode) then
if(announcedDebuff == false and (hadControl and not LCU.player.hasControl)) then
LCU.announcePlayer('has lost control of their character.');
--[[
TEMPORARY
--]]
if(not LCcfg.get('missingDebuffs')) then LCcfg.set('missingDebuffs',{}); end
for dbType,info in pairs(Debuffs.types) do
if(info.debuff ~= false) then
local debuff = info.debuff;
local missing = LCcfg.get('missingDebuffs');
if(LCU.debugMode) then print('Missed: '..debuff.name..' __ '..(debuff.description or '(no description)')); end
missing[debuff.name] = debuff.description;
end
end
--[[
TEMPORARY
--]]
elseif(LCU.player.hasControl and not hadControl) then
LCU.announcePlayer('has regained control of their character.');
end
end
end
,getLink = function(debuff)
if(type(debuff)=="number") then
local name = GetSpellInfo(debuff);
debuff = {id=debuff,name=name};
end
return GetSpellLink(debuff.id);
end
,_fakeAura = false
,addFakeAura = function(type,auraData)
Debuffs._fakeAura = auraData;
end
,getAura = function(who,i,auraType)
local a = UnitAura(who,i,auraType);
if(a==nil and Debuffs._fakeAura) then
local n,icon,_,dbType,duration,expires,_,_,_,id;
local fakeA = Debuffs._fakeAura;
n = fakeA.name;
icon = fakeA.icon;
dbType = fakeA.type;
duration = fakeA.length;
expires = GetTime()+fakeA.remaining;
id = fakeA.id;
if (fakeA.remaining <= 0.1) then
Debuffs._fakeAura = false;
end
return n,icon,_,dbType,duration,expires,_,_,_,id;
else
local n,icon,_,dbType,duration,expires,_,_,_,id = UnitAura(who,i,auraType);
return n,icon,_,dbType,duration,expires,_,_,_,id;
end
end
,test = function(dbType)
local tests = {
slow = 31589 --Slow
,fear = 5782 --Fear
--,charm = 3384 --Mass Charm
--,incap = 115078 --Paralysis
--,incap = 115877 --Fully Petrified
,disarm = 236077
,incap = 182234 --Unbreakable will
,stun = 853 --Hammer of Justice
,sleep = 31298 --Sleep
,root = 339 --Entangling Roots
,silence = 15487 --Silence
,spellLock = 53550 --Mind Freeze
}
if(tests[dbType] and Debuffs.types[dbType].debuff==false) then
local dbid = tests[dbType];
local desc = GetSpellDescription(dbid);
local spName = GetSpellInfo(dbid);
local debuff = {name=spName,["type"]='test',length=9,remaining=3,desc=desc,id=dbid,extraInfo=''};
if(dbType=='spellLock') then
debuff.extraInfo = 'Nature';
Debuffs.addFakeAura('HARMFUL',debuff);
else
Debuffs.addFakeAura('HARMFUL',debuff);
end
end
end
}
local lastDebuffMessage = 0
function checkDebuffs()
local who = 'player';
local apiDbs = Debuffs.getByLocAPI(who);
local dbDbs = Debuffs.getByDebuffs(who);
local debuffs = {};
if (type(LCU.debuffs[who]) ~= 'table') then
LCU.debuffs[who] = {};
end
for dbType,_ in pairs(Debuffs.types) do
debuffs[dbType] = nil;
local dbVal = dbDbs[dbType];
local apiVal = apiDbs[dbType];
if (dbVal ~= nil or apiVal ~= nil) then
if (type(dbVal)=='table') then
debuffs[dbType] = dbVal;
end
if (type(apiVal)=='table' and (debuffs[dbType] == nil or debuffs[dbType].remaining < apiVal.remaining + 0.1)) then
debuffs[dbType] = apiVal;
end
end
end
-- check for debuff found debuff, matching a spell on a different type by the api
-- debuff description matching probs more accurate, so drop api version of same spell id
for dbType,db in pairs(debuffs) do
if (db ~= nil) then
for dbType2,db2 in pairs(debuffs) do
if (db2 ~= nil and dbType2 ~= dbType and db2.id == db.id) then
if (db.source == 'api' and db2.source == 'debuff') then
debuffs[dbType] = nil;
elseif (db.source == 'debuff' and db2.source == 'api') then
debuffs[dbType2] = nil;
end
end
end
end
end
local maxMana = UnitPowerMax(who, Enum.PowerType.Mana) or 0;
if (maxMana > 0) then
local mana = UnitPower(who, Enum.PowerType.Mana);
local perc = (mana / maxMana) * 100;
local brkPnt = tonumber(LCcfg.get('oomBreakpoint', 15, false));
local underBreakpoint = perc < brkPnt;
local almostRecovered = (LCU.debuffs[who].oom ~= nil and perc < brkPnt * 1.5 and perc < 95);
if (underBreakpoint or almostRecovered) then
debuffs.oom = {
name = 'Out of mana',
icon = nil,
["type"] = 'oom',
length = 20,
remaining = LCU.tern(almostRecovered, 0.5, 20),
desc = 'Out of mana',
id = 0,
extraInfo = '',
source = 'oom'
};
end
end
Debuffs.checkDebuffs(debuffs, who);
for dbType,_ in pairs(Debuffs.types) do
LCU.debuffs[who][dbType] = debuffs[dbType];
end
if(Debuffs._fakeAura ~= false) then
Debuffs._fakeAura.remaining = Debuffs._fakeAura.remaining-0.25;
end
if(#LCU.debuffs[who] > 0 and GetTime()-lastDebuffMessage >= 8 and LCU.debugMode==true) then
for k,debuff in pairs(LCU.debuffs[who]) do
local debuffMsg = 'Debuff #'..tostring(k)..':'
debuffMsg = debuffMsg .. GetSpellLink(debuff.id)
debuffMsg = debuffMsg..' ['..debuff.id..'] '
debuffMsg = debuffMsg..' ('..debuff.type..') '
debuffMsg = debuffMsg..' '..tostring(debuff.remaining)..' secs remaining.'
LCMessage(debuffMsg,'PRINT',LCU.round(debuff.remaining/2));
end
lastDebuffMessage = GetTime()
end
end