-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCallback.lua
More file actions
840 lines (742 loc) · 23.4 KB
/
Callback.lua
File metadata and controls
840 lines (742 loc) · 23.4 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
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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
-- local functions
local GetTime = GetTime;
local UnitDamage = UnitDamage;
local UnitName = UnitName;
local UnitClass = UnitClass;
local UnitIsPlayer = UnitIsPlayer;
local pairs = pairs;
local ipairs = ipairs;
local unpack = unpack;
local min = min;
local abs = abs;
local GetSpellInfo = GetSpellInfo or function(spellID)
if not spellID then
return nil;
end
local spellInfo = C_Spell.GetSpellInfo(spellID);
if spellInfo then
return spellInfo.name, nil, spellInfo.iconID, spellInfo.castTime, spellInfo.minRange, spellInfo.maxRange, spellInfo.spellID, spellInfo.originalIconID;
end
end
-- local variables
local _;
local rangeCheckTarget, rangeCheckSpell;
-- mainline or classic
local wowmainline = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE);
local wowclassic = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC);
local wowbcc = (WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC);
local wowwc = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC);
local wowcc = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC);
local wowanyclassic = (wowclassic or wowbcc or wowwc or wowcc);
-- WOW classic support
local UnitCastingInfo = UnitCastingInfo;
local UnitChannelInfo = UnitChannelInfo;
local GetSpecialization = C_SpecializationInfo.GetSpecialization or (C_SpecializationInfo and C_SpecializationInfo.GetActiveSpecGroup) and C_SpecializationInfo.GetActiveSpecGroup or GetSpecialization;
if (wowclassic and Gnosis.libclcno) then
UnitCastingInfo = function(unit)
return Gnosis.libclcno:UnitCastingInfo(unit);
end
UnitChannelInfo = function(unit)
return Gnosis.libclcno:UnitChannelInfo(unit);
end
end
-- init OnUpdate handler, anchoring bars
function Gnosis:OnUpdate()
-- variables already initialized?
if (Gnosis.ver ~= nil) then
-- initial bar anchoring
Gnosis:AnchorAllBars();
Gnosis.OnUpdate = Gnosis.Update;
end
end
-- timer update
function Gnosis:StartTimerUpdate(fCurTime, bForce)
if((fCurTime - self.lastTimerScan) > self.s.iTimerScanEvery or bForce) then
self.lastTimerScan = fCurTime;
self.rangeCheck = true; --using the timer method for limiting the castbar rangecheck update rate
for key, value in ipairs(self.ti_fl) do
self:ScanTimerbar(value, fCurTime);
end
else
self.rangeCheck = false;
end
end
-- OnUpdate handler
function Gnosis:Update()
local fCurTime = GetTime() * 1000;
-- update bars
for key, value in pairs(self.activebars) do
local conf = value.conf;
local rem = value.endTime - fCurTime;
if (rem >= 0) then
if (conf.incombatsel == 1 or conf.incombatsel == self.curincombattype or conf.bUnlocked) then
local val = min(rem/value.duration, 1);
value.rtext:SetText(self:GenerateTime(value,
(value.endTime - fCurTime) / 1000,
(value.dur or value.duration) / 1000,
value.pushback and (value.pushback / 1000))
);
val = (value.channel and (not conf.bChanAsNorm)) and val or (1 - val);
value.bar:SetValue(val);
if (conf.orient == 2) then
if(conf.bInvDir) then
value.cbs:SetPoint("CENTER", value.bar, "TOP", 0, -val * value.barheight);
else
value.cbs:SetPoint("CENTER", value.bar, "BOTTOM", 0, val * value.barheight);
end
else
if (conf.bInvDir) then
value.cbs:SetPoint("CENTER", value.bar, "RIGHT", -val * value.barwidth, 0);
else
value.cbs:SetPoint("CENTER", value.bar, "LEFT", val * value.barwidth, 0);
end
end
if (value.reanchor) then
self:ReAnchorBar(value);
end
-- timer bars use different code to show/hide castbars
if (value.bBarHidden and not value.tiType) then
value.bBarHidden = nil;
value:Show();
end
elseif (not value.tiType) then
value:Hide();
value.bBarHidden = true;
end
--range check
if self.rangeCheck then
self:playerCastbarRangeCheck(value);
end
else
-- cleanup/fade out gcd castbars
if (conf.bUnlocked or conf.bShowWNC) then
self:CleanupCastbar(value);
else
self:PrepareCastbarForFadeout(value, fCurTime);
end
end
end
for key, value in pairs(self.fadeoutbars) do
local val = (value.endTime - fCurTime) / (value.duration);
if (val >= 0.0) then
value:SetAlpha(val * value.alpha);
else
value:Hide();
self:CleanupCastbar(value);
end
end
-- clip test
self:ClipTest(fCurTime);
-- scan units for whom no events will be generated by client
if (self.bScan) then
for key, value in pairs(self.scan) do
self:ScanUnit(key, value);
end
end
-- timers
self:StartTimerUpdate(fCurTime);
-- LibDialog-1.0 bandaid
if (Gnosis.bDelayedEsc) then
StaticPopup_EscapePressed();
Gnosis.bDelayedEsc = nil;
end
end
function Gnosis:playerCastbarRangeCheck(cb)
if cb.conf.bRangeCheck and cb.conf.unit == "player" and cb.conf.bartype == "cb" then
if IsSpellInRange(rangeCheckSpell, rangeCheckTarget) == 0 then
if not cb.outOfRangeColorApplied then
cb.bar:SetStatusBarColor(unpack(cb.conf.colOutOfRange));
cb.outOfRangeColorApplied = true;
end
else
if cb.outOfRangeColorApplied then
self:activeBarColors(cb);
cb.outOfRangeColorApplied = false;
end
end
end
end
-- events
function Gnosis:UNIT_SPELLCAST_SUCCEEDED(event, unit, _, spellid)
if (unit == "player") then
local spell = GetSpellInfo(spellid);
local fCurTime = GetTime() * 1000.0;
self:FindGCDBars(spell, fCurTime, spellid);
-- update timer bars now (to make gcd bars appear instantly)
self:StartTimerUpdate(fCurTime, true);
if (self.iSwing == 2) then
self.strAutoShot, _, self.iconAutoShot = GetSpellInfo(75);
self.strShootWand, _, self.iconShootWand = GetSpellInfo(5019);
if (spell == self.strAutoShot) then
self:FindSwingTimers("sr", spell, self.iconAutoShot, fCurTime, false);
self:FindSwingTimers("smr", spell, self.iconAutoShot, fCurTime, false);
elseif (spell == self.strShootWand) then
self:FindSwingTimers("sr", spell, self.iconShootWand, fCurTime, false);
self:FindSwingTimers("smr", spell, self.iconShootWand, fCurTime, false);
end
end
end
end
function Gnosis:UNIT_SPELLCAST_START(event, unit, _, spellid)
local cb = self:FindCB(unit);
if (cb) then
local fCurTime = GetTime() * 1000.0;
repeat
self:SetupCastbar(cb, false, fCurTime);
cb = self:FindCBNext(unit);
until cb == nil;
end
if (unit == "player") then
local spell = GetSpellInfo(spellid);
local fCurTime = GetTime() * 1000.0;
--set up variables for the range check
rangeCheckSpell = spell;
self:FindGCDBars(spell, fCurTime, spellid);
if (self.iLastTradeSkillCnt) then
self.iLastTradeSkillCnt = self.iLastTradeSkillCnt - 1;
self.bNewTradeSkill = nil;
end
end
end
function Gnosis:UNIT_SPELLCAST_CHANNEL_START(event, unit, _, spellid)
local cb = self:FindCB(unit);
if (cb) then
local fCurTime = GetTime() * 1000.0;
repeat
self:SetupCastbar(cb, true, fCurTime);
cb = self:FindCBNext(unit);
until cb == nil;
end
-- clip test
if (unit == "player") then
--set up variables for the range check
rangeCheckSpell = GetSpellInfo(spellid);
-- generate new clip test data
self:SetupChannelData();
end
end
function Gnosis:UNIT_SPELLCAST_EMPOWER_START(event, unit, _, spellid)
local cb = self:FindCB(unit);
if (cb) then
local fCurTime = GetTime() * 1000.0;
repeat
self:SetupCastbar(cb, true, fCurTime);
cb = self:FindCBNext(unit);
until cb == nil;
end
-- clip test
if (unit == "player") then
-- generate new clip test data
self:SetupChannelData();
end
end
function Gnosis:UNIT_SPELLCAST_STOP(event, unit, _, spellid)
local cb = self:FindCB(unit);
if (cb) then
local fCurTime = GetTime() * 1000.0;
repeat
if (cb.bActive) then
local conf = cb.conf;
if ((conf.bUnlocked or conf.bShowWNC) and not (cb.bIsTrade and cb.tscnt > 1)) then
self:CleanupCastbar(cb);
elseif (not (cb.bIsTrade and cb.tscnt > 1)) then
self:PrepareCastbarForFadeout(cb, fCurTime);
if (conf.bColSuc) then
cb.cbs:Hide();
cb.bar:SetStatusBarColor(unpack(conf.colSuccess));
cb.bar:SetValue(1.0);
end
end
end
cb = self:FindCBNext(unit);
until cb == nil;
end
end
function Gnosis:UNIT_SPELLCAST_CHANNEL_STOP(event, unit, _, spellid)
local cb = self:FindCB(unit);
if (cb) then
local fCurTime = GetTime() * 1000.0;
repeat
if (cb.bActive) then
local conf = cb.conf;
if (conf.bUnlocked or conf.bShowWNC) then
self:CleanupCastbar(cb);
else
self:PrepareCastbarForFadeout(cb, fCurTime);
end
end
cb = self:FindCBNext(unit);
until cb == nil;
end
-- clip test
if (unit == "player") then
-- request unintentional clipping test
self:RequestClipTest();
end
end
function Gnosis:UNIT_SPELLCAST_EMPOWER_STOP(event, unit, _, spellid)
local cb = self:FindCB(unit);
if (cb) then
local fCurTime = GetTime() * 1000.0;
repeat
if (cb.bActive) then
local conf = cb.conf;
if (conf.bUnlocked or conf.bShowWNC) then
self:CleanupCastbar(cb);
else
self:PrepareCastbarForFadeout(cb, fCurTime);
end
end
cb = self:FindCBNext(unit);
until cb == nil;
end
-- clip test
if (unit == "player") then
-- request unintentional clipping test
self:RequestClipTest();
end
end
function Gnosis:UNIT_SPELLCAST_CHANNEL_UPDATE(event, unit)
local cb = self:FindCB(unit);
if (cb) then
repeat
if (cb.bActive) then
local spell, _, _, startTime, endTime = UnitChannelInfo(unit);
if (spell) then
self:UpdateCastbar(cb, startTime, endTime, spell);
end
end
cb = self:FindCBNext(unit);
until cb == nil;
end
-- clip test
if (unit == "player") then
-- update clipping test
self:UpdateClipTest();
end
end
function Gnosis:UNIT_SPELLCAST_EMPOWER_UPDATE(event, unit)
local cb = self:FindCB(unit);
if (cb) then
repeat
if (cb.bActive) then
local spell, _, _, startTime, endTime = UnitChannelInfo(unit);
if (spell) then
self:UpdateCastbar(cb, startTime, endTime, spell);
end
end
cb = self:FindCBNext(unit);
until cb == nil;
end
-- clip test
if (unit == "player") then
-- update clipping test
self:UpdateClipTest();
end
end
function Gnosis:UNIT_SPELLCAST_DELAYED(event, unit)
local cb = self:FindCB(unit);
if (cb) then
repeat
if (cb.bActive) then
local spell, _, _, startTime, endTime = UnitCastingInfo(unit);
if (spell) then
self:UpdateCastbar(cb, startTime, endTime, spell);
end
end
cb = self:FindCBNext(unit);
until cb == nil;
end
end
function Gnosis:UNIT_SPELLCAST_INTERRUPTIBLE(event, unit)
local cb = self:FindCB(unit);
if (cb) then
repeat
if (cb.bActive) then
cb.bar:SetStatusBarColor(unpack(cb.conf.colBar));
self:SetBorderColor(cb, cb.conf.colBorder, cb.conf.colBarBg);
cb.sicon:Hide();
end
cb = self:FindCBNext(unit);
until cb == nil;
end
end
function Gnosis:UNIT_SPELLCAST_NOT_INTERRUPTIBLE(event, unit)
local cb = self:FindCB(unit);
if (cb) then
repeat
if (cb.bActive) then
cb.bar:SetStatusBarColor(unpack(cb.conf.colBarNI));
self:SetBorderColor(cb, cb.conf.colBorderNI, cb.conf.colBarBg);
if (cb.conf.bShowShield) then
cb.sicon:Show();
else
cb.sicon:Hide();
end
end
cb = self:FindCBNext(unit);
until cb == nil;
end
end
function Gnosis:UNIT_SPELLCAST_INTERRUPTED(event, unit, lineid, spellid)
local spell = GetSpellInfo(spellid)
local cb = self:FindCB(unit);
if (cb) then
local fCurTime = GetTime() * 1000.0;
repeat
-- cb.castname == spell : bandaid for classes that can cast spells while running
-- the wow api sends interrupt events for previously casted spells...
if (cb.bActive and cb.castname == spell) then
local conf = cb.conf;
cb.bar:SetValue(cb.channel and 0 or 1.0);
if (cb.channel) then
cb.bar:SetStatusBarColor(unpack(conf.colInterrupted));
end
if (cb.bIsTrade) then
-- tradeskill interrupted
cb.bIsTrade = nil;
end
if (conf.bUnlocked or conf.bShowWNC) then
self:CleanupCastbar(cb);
else
self:PrepareCastbarForFadeout(cb, fCurTime);
cb.cbs:Hide();
if (not cb.channel) then
cb.bar:SetStatusBarColor(unpack(conf.colInterrupted));
end
cb.bar:SetValue(cb.channel and 0 or 1.0);
end
end
cb = self:FindCBNext(unit);
until cb == nil;
end
end
function Gnosis:UNIT_SPELLCAST_FAILED(event, unit, lineid, spellid)
local spell = GetSpellInfo(spellid)
local cb = self:FindCB(unit);
if (cb) then
local fCurTime = GetTime() * 1000.0;
repeat
if (cb.bActive) then
local conf = cb.conf;
if (cb.id and cb.id == lineid) then
cb.bar:SetValue(cb.channel and 0 or 1.0);
if (cb.channel) then
cb.bar:SetStatusBarColor(unpack(conf.colFailed));
end
if (conf.bUnlocked or conf.bShowWNC) then
self:CleanupCastbar(cb);
else
self:PrepareCastbarForFadeout(cb, fCurTime);
cb.cbs:Hide();
if (not cb.channel) then
cb.bar:SetStatusBarColor(unpack(conf.colFailed));
end
cb.bar:SetValue(cb.channel and 0 or 1.0);
end
end
end
cb = self:FindCBNext(unit);
until cb == nil;
end
end
Gnosis.UNIT_SPELLCAST_FAILED_QUIET = Gnosis.UNIT_SPELLCAST_FAILED;
function Gnosis:PLAYER_REGEN_DISABLED()
self.curincombattype = 2; -- in combat "flag"
end
function Gnosis:PLAYER_REGEN_ENABLED()
self.curincombattype = 3; -- out of combat "flag"
end
function Gnosis:COMBAT_LOG_EVENT_UNFILTERED()
-- not certain about the values/order returned by CombatLogGetCurrentEventInfo()
-- seems ok from initial (very short) testing
local ts, event, _, sguid, _, _, _, dguid, dname, _, _,
sid, spellname, _, dmg, oh, absorbed, bcritheal,
bmultiheal, _, bcrit, _, _, _, bmulti = CombatLogGetCurrentEventInfo();
if (sguid == self.guid) then -- player
local fCurTime = GetTime() * 1000;
local heal_done = (event == "SPELL_HEAL" or event == "SPELL_PERIODIC_HEAL");
local dmg_done = (event == "SPELL_DAMAGE" or event == "SPELL_PERIODIC_DAMAGE");
local dmg_missed = (event == "SPELL_MISSED" or event == "SPELL_PERIODIC_MISSED");
if (dmg_done or heal_done or dmg_missed) then
-- ticks from channeled spell?
local cc, nc = self.curchannel, self.nextchannel;
local selcc = (cc and cc.spell == spellname) and cc or ((nc and nc.spell == spellname) and nc or nil);
local selccnext = (cc and cc.spell == spellname) and false or ((nc and nc.spell == spellname) and true or false);
if (selcc) then
-- tick
local dmgdone = (dmg_done or heal_done) and dmg or 0;
selcc.type = heal_done;
selcc.dmg = selcc.dmg + dmgdone;
selcc.eh = selcc.eh + (heal_done and (dmg - oh) or 0);
selcc.oh = selcc.oh + (heal_done and oh or 0);
local isNormalTick = true;
if ((heal_done and bmultiheal) or ((not heal_done) and (bmulti or event == "SPELL_DAMAGE"))) then
-- multistrike
selcc.mastery = selcc.mastery + 1;
isNormalTick = false;
if(selcc.bticksound) then
self:PlaySounds();
end
else
-- non multistrike tick
selcc.ticks = selcc.ticks + 1;
if(selcc.bticksound) then
self:PlaySounds();
end
end
selcc.lastticktime = fCurTime;
selcc.hits = (bcrit or (event == "SPELL_MISSED" or event == "SPELL_PERIODIC_MISSED")) and selcc.hits or (selcc.hits + 1);
selcc.crits = (bcrit and (event == "SPELL_DAMAGE" or event == "SPELL_PERIODIC_DAMAGE")) and (selcc.crits + 1) or selcc.crits;
selcc.crits = (bcritheal and event == "SPELL_HEAL") and (selcc.crits + 1) or selcc.crits;
-- cliptest enable and non aoe spell?
if (isNormalTick and selcc.bcliptest and not selcc.baeo) then
if ((not selccnext and (cc and nc)) or selcc.ticks >= selcc.maxticks) then
-- max ticks or last tick for current channel
-- check channeled spell out at once
selcc.freqtest = fCurTime + 250;
selcc.fforcedtest = fCurTime + 250;
end
end
end
elseif (self.bSwingBar and self.iSwing == 1) then
if (event == "SPELL_EXTRA_ATTACKS") then
self.iExtraSwings = dmg; -- amount of extra swings, cannot use arg12 with cataclysm
self.bNextSwingNotExtra = true;
elseif (event == "SWING_DAMAGE" or event == "SWING_MISSED") then
if (self.iExtraSwings > 0 and not self.bNextSwingNotExtra) then
self.iExtraSwings = self.iExtraSwings - 1;
else
self.bNextSwingNotExtra = false;
self.strAutoAttack, _, self.iconAutoAttack = GetSpellInfo(6603);
self:FindSwingTimers("sm", self.strAutoAttack, self.iconAutoAttack, fCurTime, true);
self:FindSwingTimers("smr", self.strAutoAttack, self.iconAutoAttack, fCurTime, true);
end
end
end
if (self.ti_icd[spellname] and event ~= "SPELL_CAST_FAILED") then
--print("player", spellname, self.ti_icd[spellname].duration, event);
if (self.ti_icd_active[spellname] == nil or not self.ti_icd[spellname].norefresh) then
self.ti_icd_active[spellname] = fCurTime + self.ti_icd[spellname].duration;
end
end
elseif (dguid == self.guid) then -- player is target
if (event == "SWING_MISSED" and sid == "PARRY") then
local fCurTime = GetTime() * 1000;
-- parry haste
Gnosis:FindSwingTimersParry("sm", fCurTime);
Gnosis:FindSwingTimersParry("smr", fCurTime);
end
if (self.ti_icd[spellname] and event ~= "SPELL_CAST_FAILED") then
--print("is target", spellname, self.ti_icd[spellname].duration, event);
if (self.ti_icd_active[spellname] == nil or not self.ti_icd[spellname].norefresh) then
self.ti_icd_active[spellname] = GetTime() * 1000 + self.ti_icd[spellname].duration;
end
end
end
end
function Gnosis:UNIT_SPELLCAST_SENT(event, unit, target)
if (wowmainline) then
if (issecretvalue(unit) or issecretvalue(target)) then
return
end
end
-- latency estimation
self.strLastTarget = (target and target ~= "") and target or nil;
self.lag = select(4, GetNetStats());
if (unit == "player") then
--set up variables for the range check
if target then
local success, result = pcall(function()
if target == UnitName("player") then
rangeCheckTarget = "player"
elseif target == UnitName("target") then
rangeCheckTarget = "target"
elseif target == UnitName("focus") then
rangeCheckTarget = "focus"
elseif target == UnitName("mouseover") then
rangeCheckTarget = "mouseover"
else
rangeCheckTarget = nil
end
end)
if not success then
rangeCheckTarget = nil
end
else
rangeCheckTarget = nil
end
end
-- grab unit class of target if possible
if (self.strLastTarget) then
local _, class = UnitClass(target);
local guid = nil;
if (class) then
self.strLastTargetClass = class;
else
-- try to get class from target and mouseover
local unit_ = (not issecretvalue(UnitName("target")) and UnitName("target") == target) and "target" or
((not issecretvalue(UnitName("mouseover")) and UnitName("mouseover") == target) and "mouseover" or nil);
if (unit_ and UnitIsPlayer(unit_)) then
_, self.strLastTargetClass = UnitClass(unit_);
else
self.strLastTargetClass = nil;
end
end
else
self.strLastTargetClass = nil;
end
end
function Gnosis:MIRROR_TIMER_START(event, timer, curval, maxval, scale, paused, label)
local cb = self:FindCB("mirror");
if (cb) then
local fCurTime = GetTime() * 1000;
repeat
self:SetupMirrorbar(cb, label, scale < 0 and true or false, curval / (abs(scale)) , maxval / (abs(scale)), fCurTime, timer);
cb = self:FindCBNext("mirror");
until cb == nil;
end
end
function Gnosis:MIRROR_TIMER_STOP(event, timer)
local cb = self:FindCB("mirror");
local numMirrorTimerTypes = MIRRORTIMER_NUMTIMERS or 3;
if (cb) then
local fCurTime = GetTime() * 1000;
repeat
local bDoCleanup = true;
local conf = cb.conf;
if (cb.castname == timer) then
for i = 1, numMirrorTimerTypes do
local timer, init, maxval, scale, paused, label = GetMirrorTimerInfo(i);
if (timer and timer ~= cb.castname and init ~= 0 and maxval ~= 0) then
local curval = GetMirrorTimerProgress(timer);
if (self:SetupMirrorbar(cb, label, scale < 0 and true or false, curval / (abs(scale)) , maxval / (abs(scale)), fCurTime, timer)) then
bDoCleanup = false;
break;
end
end
end
if (bDoCleanup and cb.bActive) then
if (conf.bUnlocked or conf.bShowWNC) then
self:CleanupCastbar(cb);
else
self:PrepareCastbarForFadeout(cb, fCurTime);
end
end
end
cb = self:FindCBNext("mirror");
until cb == nil;
end
end
function Gnosis:PLAYER_UNGHOST()
self:MIRROR_TIMER_STOP();
end
function Gnosis:PLAYER_ALIVE()
self:MIRROR_TIMER_STOP();
end
function Gnosis:PLAYER_ENTERING_WORLD()
-- create spellcasting events for focus/target when entering world
if (UnitCastingInfo("focus")) then
Gnosis:UNIT_SPELLCAST_START("UNIT_SPELLCAST_START", "focus");
elseif (UnitChannelInfo("focus")) then
Gnosis:UNIT_SPELLCAST_CHANNEL_START("UNIT_SPELLCAST_CHANNEL_START", "focus");
else
Gnosis:UNIT_SPELLCAST_CHANNEL_STOP("UNIT_SPELLCAST_CHANNEL_STOP", "focus");
end
if (UnitCastingInfo("target")) then
Gnosis:UNIT_SPELLCAST_START("UNIT_SPELLCAST_START", "target");
elseif (UnitChannelInfo("target")) then
Gnosis:UNIT_SPELLCAST_CHANNEL_START("UNIT_SPELLCAST_CHANNEL_START", "target");
else
Gnosis:UNIT_SPELLCAST_CHANNEL_STOP("UNIT_SPELLCAST_CHANNEL_STOP", "target");
end
end
function Gnosis:PLAYER_FOCUS_CHANGED()
-- create spellcasting events for focus unit when changing focus target
if (UnitCastingInfo("focus")) then
Gnosis:UNIT_SPELLCAST_START("UNIT_SPELLCAST_START", "focus");
elseif (UnitChannelInfo("focus")) then
Gnosis:UNIT_SPELLCAST_CHANNEL_START("UNIT_SPELLCAST_CHANNEL_START", "focus");
else
Gnosis:UNIT_SPELLCAST_CHANNEL_STOP("UNIT_SPELLCAST_CHANNEL_STOP", "focus");
end
end
function Gnosis:PLAYER_TARGET_CHANGED()
-- create spellcasting events for target unit when changing target
if (UnitCastingInfo("target")) then
Gnosis:UNIT_SPELLCAST_START("UNIT_SPELLCAST_START", "target");
elseif (UnitChannelInfo("target")) then
Gnosis:UNIT_SPELLCAST_CHANNEL_START("UNIT_SPELLCAST_CHANNEL_START", "target");
else
Gnosis:UNIT_SPELLCAST_CHANNEL_STOP("UNIT_SPELLCAST_CHANNEL_STOP", "target");
end
end
-- swing timer events
function Gnosis:PLAYER_ENTER_COMBAT(event)
local _, _, offlowDmg, offhiDmg = UnitDamage("player");
-- dual wielding? if yes don't show timer
if (offlowDmg and not self.bIsDruid and abs(offhiDmg-offlowDmg) > 0.1) then
self.bSwingBar = false;
return;
else
self.iSwing = 1;
end
for key, value in pairs(self.castbars) do
local conf = Gnosis.s.cbconf[key];
if (conf.bEn and (conf.unit == "sm" or conf.unit == "smr")) then
self.bSwingBar = true;
self.iExtraSwings = 0;
self.bNextSwingNotExtra = false;
return;
end
end
end
function Gnosis:PLAYER_LEAVE_COMBAT(event)
if (self.iSwing == 1) then
self.iSwing = 0;
self.bSwingBar = false;
end
end
function Gnosis:START_AUTOREPEAT_SPELL(event)
self.iSwing = 2;
for key, value in pairs(self.castbars) do
local conf = Gnosis.s.cbconf[key];
if (conf.bEn and (conf.unit == "sr" or conf.unit == "smr")) then
self.bSwingBar = true;
return;
end
end
end
function Gnosis:STOP_AUTOREPEAT_SPELL(event)
if (self.iSwing == 2) then
self.iSwing = 0;
self.bSwingBar = false;
end
end
function Gnosis:DISPLAY_SIZE_CHANGED()
end
function Gnosis:PLAYER_TALENT_UPDATE()
self.iCurSpec = self:SafeGetSpecialization();
for key, value in pairs(self.castbars) do
local conf = Gnosis.s.cbconf[key];
if (conf.bEn) then
self:SetBarParams(value.name)
end
end
self:CreateCBTables();
end
function Gnosis:SafeGetSpecialization()
-- always return 1 for classic
if (wowanyclassic) then
return 1;
end
-- get current specialization
local currentspec = GetSpecialization();
-- set to 1 in case GetSpecialization() returns nil or 5
-- GetSpecialization() returns 5 for newly created players since 9.0.1
if (not currentspec or currentspec > 4) then
return 1;
else
return currentspec;
end
end