-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTimers.lua
More file actions
2419 lines (2177 loc) · 65.2 KB
/
Timers.lua
File metadata and controls
2419 lines (2177 loc) · 65.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
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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local GetItemInfo = C_Item.GetItemInfo or GetItemInfo;
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 GetSpellCooldown = GetSpellCooldown or function(spellID)
if not spellID then
return nil;
end
local spellCooldownInfo = C_Spell.GetSpellCooldown(spellID);
if spellCooldownInfo then
return spellCooldownInfo.startTime, spellCooldownInfo.duration, spellCooldownInfo.isEnabled, spellCooldownInfo.modRate;
end
end
local GetSpellCharges = GetSpellCharges or function(spellID)
if not spellID then
return nil;
end
local chargeInfo = C_Spell.GetSpellCharges(spellID);
if chargeInfo then
return chargeInfo.currentCharges, chargeInfo.maxCharges, chargeInfo.cooldownStartTime, chargeInfo.cooldownDuration, chargeInfo.chargeModRate;
end
end
local GetTime = GetTime;
local GetItemCooldown = C_Item.GetItemCooldown or GetItemCooldown;
local GetRuneCooldown = GetRuneCooldown;
local GetRuneType = GetRuneType;
local GetTotemInfo = GetTotemInfo;
local GetWeaponEnchantInfo = GetWeaponEnchantInfo;
local GetInventoryItemTexture = GetInventoryItemTexture;
local GetGlyphSocketInfo = GetGlyphSocketInfo;
local GetSpecialization = C_SpecializationInfo.GetSpecialization or (C_SpecializationInfo and C_SpecializationInfo.GetActiveSpecGroup) and C_SpecializationInfo.GetActiveSpecGroup or GetSpecialization;
local GetSpecializationInfo = GetSpecializationInfo;
local GetTalentInfo = GetTalentInfo;
local UnitExists = UnitExists;
local UnitPower = UnitPower;
local UnitPowerMax = UnitPowerMax;
local UnitHealth = UnitHealth;
local UnitHealthMax = UnitHealthMax;
local UnitAlternatePowerInfo = UnitAlternatePowerInfo;
local UnitAlternatePowerTextureInfo = UnitAlternatePowerTextureInfo;
local UnitGetIncomingHeals = UnitGetIncomingHeals;
local select = select;
local pairs = pairs;
local ipairs = ipairs;
local wipe = wipe;
local tonumber = tonumber;
local string_find = string.find;
local string_match = string.match;
local string_gmatch = string.gmatch;
local string_trim = strtrim;
local string_gsub = string.gsub;
local string_len = strlenutf8;
local string_lower = string.lower;
local string_split = strsplit;
local strconcat = strconcat;
local table_insert = table.insert;
-- boolean operators for timer entries
local BOOLOP_NONE, BOOLOP_AND, BOOLOP_OR, BOOLOP_RELAXEDAND = 0, 1, 2, 3;
-- local variables
local _;
-- 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);
-- WOW classic support
local AuraUtil_FindAuraByName = AuraUtil.FindAuraByName;
local UnitAura = UnitAura;
local UnitCastingInfo = UnitCastingInfo;
local UnitChannelInfo = UnitChannelInfo;
if (wowclassic and Gnosis.libcldur) then
UnitAura = function(...)
return Gnosis.libcldur:UnitAura(...);
end
AuraUtil_FindAuraByName = function(spellname, unit, filter)
local i = 1;
repeat
local name, ic, sta, _, d, s, _, _, _, id, _, _, _, _, _, eff1, eff2, eff3 =
UnitAura(unit, i, filter);
if (spellname == name) then
return name, ic, sta, _, d, s, _, _, _, id, _, _, _, _, _, eff1, eff2, eff3;
end
i = i + 1;
until id == nil or i > 40;
return nil;
end
end
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
if (wowbcc) then
UnitCastingInfo = function(unit)
local name, text, texture, startTimeMS, endTimeMS, isTradeSkill, castID, spellId = UnitCastingInfo(unit)
return name, text, texture, startTimeMS, endTimeMS, isTradeSkill, castID, nil, spellId
end
end
if (wowclassic) or (wowbcc) then
GetSpecializationInfo = function()
return nil, "";
end
GetTalentInfo = function()
return 1, "";
end
end
-- string helper functions
function Gnosis:ParseTimer_TrimCmd(line)
return string_gsub(line, "^[%s%.,]*(.-)%s*$", "%1");
end
local function ParseTimer_IsComment(line)
local comment = string_find(line, "^[%s%.,]*(%-%-)");
if (comment) then
return true;
else
return false;
end
end
function Gnosis:ParseTimer_GetCommand(bnwlist, linetostart)
local curcmd, boolop;
-- is valid table?
if (type(bnwlist) ~= "table") then
return;
end
-- remove comments
while (#bnwlist >= linetostart and ParseTimer_IsComment(bnwlist[linetostart])) do
linetostart = linetostart + 1;
end
if (linetostart > #bnwlist) then
return;
end
-- grab first non comment (and remove tokens)
-- remove tokens '\\'. '&', '+'. '*'
-- '\\': append line; '&': previous and current line have to be valid, same as 'and'
-- '?': either previous or current line has to be valid (or both)
-- '*': simply compute line, same as 'or', belongs to previous '&' or '+'
curcmd = string_match(bnwlist[linetostart], "^[%s%.,\\&%?%*]*(.*)")
linetostart = linetostart + 1;
if (not curcmd) then
return;
end
-- append lines beginning with '\\'
while (linetostart <= #bnwlist) do
if (ParseTimer_IsComment(bnwlist[linetostart])) then
-- comment, next line
linetostart = linetostart + 1;
else
local token, append = string_match(bnwlist[linetostart], "^[%s%.,]*([\\&%?%*])[%s%.,\\&%?%*]*(.*)");
if (token) then
if (token == "\\") then
-- append line
curcmd = curcmd .. " " .. append;
linetostart = linetostart + 1;
elseif (token == "&") then
boolop = BOOLOP_AND;
break;
elseif (token == "?") then
boolop = BOOLOP_RELAXEDAND;
break;
elseif (token == "*") then
boolop = BOOLOP_OR;
break;
else
break;
end
else
break;
end
end
end
return curcmd, linetostart, boolop;
end
local function in_value_range(cur_val, cur_val_perc, range_tab)
--[[ range_tab structure
[1] == value lower bound (>=)
[2] == value upper bound (<=)
[3] == stacks lower bound (>=)
[4] == stacks upper bound (<=)
[5] == value lower bound is in percent (true, nil)
[6] == value upper bound is in percent (true, nil) ]]
if(range_tab[1]) then
if(range_tab[5]) then
if(cur_val_perc < range_tab[1]) then
return false;
end
elseif(cur_val < range_tab[1]) then
return false;
end
end
if(range_tab[2]) then
if(range_tab[6]) then
if(cur_val_perc > range_tab[2]) then
return false;
end
elseif(cur_val > range_tab[2]) then
return false;
end
end
return true;
end
local function in_stacks_range(stacks, range_tab)
if(range_tab[3]) then
if(not stacks or stacks < range_tab[3]) then
return false;
end
end
if(range_tab[4]) then
if(not stacks or stacks > range_tab[4]) then
return false;
end
end
return true;
end
local function set_not(ti)
ti.bChannel = true;
ti.dur = 1;
ti.fin = 1;
ti.bSpecial = true;
ti.valIsStatic = true;
ti.ok = true;
end
local function set_times(timer, ti, dur, fin, ischannel)
if (ti.ok) then
if (timer.bNot) then
ti.ok = nil;
else
if (ti.valIsStatic or timer.bExists) then
set_not(ti);
else
ti.bChannel = ischannel;
ti.dur = dur;
ti.fin = fin;
end
end
elseif (timer.bNot) then
set_not(ti);
end
end
function Gnosis:Timers_Spell(bar, timer, ti)
-- cast
local spell, _, icon, s, d, _, _, notInterruptible = UnitCastingInfo(timer.unit);
if(d and d > 0) then
if(timer.spell == "all" or timer.spell == "any" or timer.spell == spell) then
ti.cname = spell;
ti.icon = icon;
ti.unit = timer.unit;
ti.notInterruptible = notInterruptible or nil;
local dur, fin = d-s, d;
if(timer.brange) then
local rem = fin/1000-GetTime();
ti.ok = in_value_range(rem, rem*100000/dur, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, dur, fin, false);
end
else
spell, _, icon, s, d, _, _, notInterruptible = UnitChannelInfo(timer.unit);
if(d and d > 0) then
if(timer.spell == "all" or timer.spell == "any" or timer.spell == spell) then
ti.cname = spell;
ti.icon = icon;
ti.unit = timer.unit;
ti.notInterruptible = notInterruptible or nil;
local dur, fin = d-s, d;
if(timer.brange) then
local rem = fin/1000-GetTime();
ti.ok = in_value_range(rem, rem*100000/dur, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, dur, fin, true);
end
end
end
end
function Gnosis:Timers_SpellCD(bar, timer, ti)
-- cooldown, player only
ti.unit = "player";
local s, d = GetSpellCooldown(timer.spell);
local dur, fin;
local cd_info = Gnosis.timer_cds[timer.spell];
local curtime = GetTime();
if (d and d <= 1.5 and cd_info and curtime < cd_info.fin and (s+d) >= cd_info.fin) then
-- duration of the global cooldown
dur, fin = cd_info.dur, cd_info.fin;
elseif (d and d > 1.5) then
-- duration greater than global cd
dur, fin = d, s + d;
if (cd_info) then
cd_info.dur = dur;
cd_info.fin = fin;
else
Gnosis.timer_cds[timer.spell] = { dur = dur, fin = fin };
end
end
if (dur) then
ti.cname = timer.spell;
ti.icon = timer.icon or select(3, GetSpellInfo(timer.spell));
if(timer.brange) then
local rem = fin - curtime;
ti.ok = in_value_range(rem, rem*100/dur, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, dur*1000, fin*1000, true);
elseif (timer.bNot) then
ti.cname = timer.spell;
ti.icon = timer.icon or select(3, GetSpellInfo(timer.spell));
set_not(ti);
end
end
function Gnosis:Timers_Counter(bar, timer, ti)
ti.unit = "player";
local cnter = Gnosis.counters[timer.spell];
if (cnter and cnter.endtime < GetTime()) then
cnter = nil;
end
if (cnter) then
ti.cname = timer.spell;
if (timer.brange) then
local curcnt = GetTime() - cnter.starttime;
local totcnt = cnter.endtime - cnter.starttime;
ti.ok = in_value_range(curcnt, curcnt*100/totcnt, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti,
(cnter.endtime-cnter.starttime)*1000,
cnter.endtime*1000,
true
);
elseif (timer.bNot) then
ti.cname = timer.spell;
set_not(ti);
end
end
local function GetAura(timer, unit)
if (timer.spellid) then
-- aura id
local _, name, ic, sta, d, s, eff1, eff2, eff3, id;
local i = 1;
repeat
name, ic, sta, _, d, s, _, _, _, id, _, _, _, _, _, eff1, eff2, eff3 =
UnitAura(unit, i, timer.filter);
if (id and id == timer.spellid) then
timer.spell = name;
if (timer.auraeffect3) then
if (eff3 and eff3 > 0) then
return ic, sta, timer.auraeffect3, eff3, eff3, true;
end
elseif (timer.auraeffect2) then
if (eff2 and eff2 > 0) then
return ic, sta, timer.auraeffect2, eff2, eff2, true;
end
elseif (timer.auraeffect1) then
if (eff1 and eff1 > 0) then
return ic, sta, timer.auraeffect1, eff1, eff1, true;
end
elseif (timer.aurastacks) then
if (sta and sta > 0) then
return ic, sta, timer.aurastacks, sta, eff1, true;
end
else
-- timer bar
return ic, sta, d, s, eff, false;
end
-- nothing to return
return ic;
end
i = i + 1;
until id == nil or i > 40;
return;
else
-- aura name
local _, ic, sta, _, d, s, _, _, _, _, _, _, _, _, _, eff1, eff2, eff3 =
AuraUtil_FindAuraByName(timer.spell, unit, timer.filter);
if (timer.auraeffect3) then
if (eff3 and eff3 > 0) then
return ic, sta, timer.auraeffect3, eff3, eff3, true;
end
elseif (timer.auraeffect2) then
if (eff2 and eff2 > 0) then
return ic, sta, timer.auraeffect2, eff2, eff2, true;
end
elseif (timer.auraeffect1) then
if (eff1 and eff1 > 0) then
return ic, sta, timer.auraeffect1, eff1, eff1, true;
end
elseif (timer.aurastacks) then
if (sta and sta > 0) then
return ic, sta, timer.aurastacks, sta, eff1, true;
end
else
-- timer bar
return ic, sta, d, s, eff, false;
end
-- nothing to return
return ic;
end
end
function Gnosis:Timers_Aura(bar, timer, ti)
-- aura == buff or debuff (== hot or dot)
ti.unit = timer.unit;
local ic, sta, d, s, effect, isspecial = GetAura(timer, timer.unit);
if (s) then
ti.cname = timer.spell;
ti.stacks = (sta and sta > 0) and sta or nil;
ti.icon = ic;
if (isspecial) then
ti.unit = timer.unit;
ti.bSpecial = true;
if (timer.brange) then
ti.ok = in_value_range(s, s*100/d, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, d, s, true);
else
local rem = 0;
if (s > 0) then
rem = s - GetTime();
end
if (rem > 0) then
-- dynamic aura
if (timer.brange) then
if (in_value_range(rem, rem*100/d, timer.range_tab) and
in_stacks_range(sta, timer.range_tab)) then
ti.ok = true;
end
else
ti.ok = true;
end
set_times(timer, ti, d * 1000, s * 1000, true);
elseif (s == 0 and d == 0 and not timer.bNot) then
-- static aura
if (timer.brange) then
if (in_stacks_range(sta, timer.range_tab)) then
ti.ok = true;
end
else
ti.ok = true;
end
ti.valIsStatic = true;
set_times(timer, ti);
end
end
elseif (timer.bNot) then
ti.cname = timer.spell;
ti.icon = timer.icon or select(3, GetSpellInfo(timer.spell));
set_not(ti);
end
end
function Gnosis:Timers_GroupAura(bar, timer, ti)
ti.unit = nil;
-- scan current group for aura, also scan existing pets
local _, ic, sta, d, s, effect, isspecial;
local n = GetNumGroupMembers();
if (IsInRaid() and n >= 2) then
-- scan raid
for i = 1, n do
local curunit = "raid" .. i;
ic, sta, d, s, effect, isspecial = GetAura(timer, curunit);
if (s) then
ti.unit = curunit;
break;
end
curunit = "raidpet" .. i;
if (UnitExists(curunit)) then
ic, sta, d, s, effect, isspecial = GetAura(timer, curunit);
if (s) then
ti.unit = curunit;
break;
end
end
end
elseif (n >= 2) then
-- scan player and group members
ic, sta, d, s, effect, isspecial = GetAura(timer, "player");
if (s) then
ti.unit = "player";
else
if (UnitExists("playerpet")) then
ic, sta, d, s, effect, isspecial = GetAura(timer, "playerpet");
end
if (s) then
ti.unit = "playerpet";
else
for i = 1, (n - 1) do
local curunit = "party" .. i;
ic, sta, d, s, effect, isspecial = GetAura(timer, curunit);
if (s) then
ti.unit = curunit;
break;
end
curunit = "partypet" .. i;
if (UnitExists(curunit)) then
ic, sta, d, s, effect, isspecial = GetAura(timer, curunit);
if (s) then
ti.unit = curunit;
break;
end
end
end
end
end
else
-- scan player (player not in group)
ic, sta, d, s, effect, isspecial = GetAura(timer, "player");
if (s) then
ti.unit = "player";
else
if (UnitExists("playerpet")) then
ic, sta, d, s, effect, isspecial = GetAura(timer, "playerpet");
if (s) then
ti.unit = "playerpet";
end
end
end
end
if (ti.unit) then
ti.cname = timer.spell;
ti.stacks = (sta and sta > 0) and sta or nil;
ti.effect = effect;
ti.icon = ic;
if (isspecial) then
ti.unit = timer.unit;
ti.bSpecial = true;
if (timer.brange) then
ti.ok = in_value_range(s, s*100/d, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, d, s, true);
else
local rem = 0;
if (s > 0) then
rem = s - GetTime();
end
if (rem > 0) then
-- dynamic aura
if (timer.brange) then
if (in_value_range(rem, rem*100/d, timer.range_tab) and
in_stacks_range(sta, timer.range_tab)) then
ti.ok = true;
end
else
ti.ok = true;
end
set_times(timer, ti, d * 1000, s * 1000, true);
elseif (s == 0 and d == 0 and not timer.bNot) then
-- static aura
if (timer.brange) then
if (in_stacks_range(sta, timer.range_tab)) then
ti.ok = true;
end
else
ti.ok = true;
end
ti.valIsStatic = true;
set_times(timer, ti);
end
end
elseif (timer.bNot) then
ti.unit = timer.unit;
ti.cname = timer.spell;
ti.icon = timer.icon or select(3, GetSpellInfo(timer.spell));
set_not(ti);
end
end
function Gnosis:Timers_SpellRecharge(bar, timer, ti)
-- spell charges, player only
ti.unit = "player";
local curcharges, maxcharges, cdstart, cddur = GetSpellCharges(timer.spell);
if (curcharges == nil) then
return;
end
if (timer.chargecnt) then
-- display amount of charges
ti.cname = timer.spell;
ti.icon = timer.icon;
ti.bSpecial = true;
if (timer.brange) then
ti.ok = in_value_range(curcharges, curcharges*100/maxcharges, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, maxcharges, curcharges);
else
-- recharge cooldown
if (curcharges ~= maxcharges) then
if (timer.brange) then
local rem = cddur-(GetTime()-cdstart);
ti.ok = in_value_range(rem, rem*100/cddur, timer.range_tab) and
in_stacks_range(curcharges, timer.range_tab);
else
ti.ok = true;
end
ti.cname = timer.spell;
ti.stacks = curcharges;
ti.icon = timer.icon;
set_times(timer, ti, cddur*1000, (cdstart+cddur)*1000, true);
elseif (timer.bNot) then
ti.cname = timer.spell;
ti.stacks = curcharges;
ti.icon = timer.icon;
set_not(ti);
end
end
end
function Gnosis:Timers_ItemCD(bar, timer, ti)
-- itemcd, player only
if (not timer.iid) then
local itemname, link, _, _, _, _, _, _, _, itex = GetItemInfo(timer.spell);
if (link) then
timer.iid = string_match(link, "|Hitem:(%d+):");
timer.itex = itex;
timer.iname = itemname;
end
end
if (timer.iid) then
ti.unit = "player";
local s, d = GetItemCooldown(timer.iid);
if (d and d > 1.5) then -- duration greater than global cd
ti.cname = timer.iname;
ti.icon = timer.itex;
local dur, fin = d, s+d;
if (timer.brange) then
local rem = fin - GetTime();
ti.ok = in_value_range(rem, rem*100/dur, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, dur*1000, fin*1000, true);
elseif (timer.bNot) then
ti.cname = timer.iname;
ti.icon = timer.itex;
set_not(ti);
end
end
end
function Gnosis:Timers_ItemEquipped(bar, timer, ti)
-- item equipped? player only
if (not timer.iid) then
local itemname, link, _, _, _, _, _, _, _, itex = GetItemInfo(timer.spell);
if (link) then
timer.iid = string_match(link, "|Hitem:(%d+):");
timer.itex = itex;
timer.iname = itemname;
end
end
if (timer.iname) then
ti.unit = "player";
if (IsEquippedItem(timer.iname)) then
ti.cname = timer.iname;
ti.icon = timer.itex;
ti.ok = true;
ti.valIsStatic = true;
set_times(timer, ti);
elseif (timer.bNot) then
ti.cname = timer.iname;
ti.icon = timer.itex;
set_not(ti);
end
end
end
function Gnosis:Timers_RuneCD(bar, timer, ti)
-- rune cooldown, player only
ti.unit = "player";
-- check for runetype
local rune = GetRuneType(timer.spell);
if (rune and timer.runetype and timer.runetype ~= rune) then
return;
end
-- check cooldown
local s, d, rdy = GetRuneCooldown(timer.spell);
if (s and (not rdy) and (s+d) >= GetTime()) then
if (rune) then
ti.cname = Gnosis.tRuneName[rune];
ti.icon = Gnosis.tRuneTexture[rune];
else
ti.cname = "";
ti.icon = nil;
end
local dur, fin = d, s+d;
if (timer.brange) then
local rem = fin - GetTime();
ti.ok = in_value_range(rem, rem*100/dur, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, dur*1000, fin*1000, true);
elseif (timer.bNot) then
if (rune) then
ti.cname = Gnosis.tRuneName[rune];
ti.icon = Gnosis.tRuneTexture[rune];
else
ti.cname = "";
ti.icon = nil;
end
set_not(ti);
end
end
function Gnosis:Timers_TotemDuration(bar, timer, ti)
-- totem duration
ti.unit = "player";
local bExist, name, s, d, icon = GetTotemInfo(timer.spell);
if(bExist and name and s and s > 0) then
ti.cname = name;
ti.icon = icon;
local dur, fin = d, s+d;
if(timer.brange) then
local rem = fin - GetTime();
ti.ok = in_value_range(rem, rem*100/dur, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, dur*1000, fin*1000, true);
elseif(timer.bNot) then
ti.cname = "";
ti.icon = nil;
set_not(ti);
end
end
function Gnosis:Timers_InnerCD(bar, timer, ti)
ti.unit = "player";
local bExist = false;
if (Gnosis.ti_icd_active[timer.spell]) then
if (GetTime() * 1000 >= Gnosis.ti_icd_active[timer.spell]) then
-- inner cd expired
Gnosis.ti_icd_active[timer.spell] = nil;
else
bExist = true;
end
end
if (bExist) then
ti.cname = timer.spell;
ti.icon = timer.icon;
local dur, fin = Gnosis.ti_icd[timer.spell].duration, Gnosis.ti_icd_active[timer.spell];
if(timer.brange) then
local rem = fin / 1000 - GetTime();
ti.ok = in_value_range(rem, rem*100000/dur, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, dur, fin, true);
elseif (timer.bNot) then
ti.cname = timer.spell;
ti.icon = timer.icon;
set_not(ti);
end
end
function Gnosis:Timers_WeaponEnchant(bar, timer, ti, exists, expires, charges)
-- weapon enchant (player only)
if(exists) then
ti.cname = timer.spell;
local dur = expires;
local fin = expires + GetTime()*1000;
local bardur = (bar.dur or bar.duration);
if(timer.spell == bar.castname and bardur and bardur > dur) then
dur = bardur;
end
if(timer.brange) then
local rem = expires;
ti.ok = in_value_range(rem/1000, rem*100/dur, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, dur, fin, true);
end
end
function Gnosis:Timers_WeaponEnchantMain(bar, timer, ti)
ti.unit = "player";
local exists, expires, charges = select(1, GetWeaponEnchantInfo());
if(exists) then
local tt = Gnosis.tooltip;
tt:ClearLines();
tt:SetInventoryItem("player", 16);
local num = tt:NumLines();
for i = 1, num do
if(string_find(_G["GnosisGameTooltipTextLeft"..i]:GetText(), timer.spell)) then
ti.icon = GetInventoryItemTexture("player", 16);
Gnosis:Timers_WeaponEnchant(bar, timer, ti, exists, expires, charges);
end
end
elseif(timer.bNot) then
ti.cname = timer.spell;
ti.icon = GetInventoryItemTexture("player", 16);
set_not(ti);
end
end
function Gnosis:Timers_WeaponEnchantOff(bar, timer, ti)
ti.unit = "player";
local exists, expires, charges = select(4, GetWeaponEnchantInfo());
if(exists) then
local tt = Gnosis.tooltip;
tt:ClearLines();
tt:SetInventoryItem("player", 17);
local num = tt:NumLines();
for i = 1, num do
if(string_find(_G["GnosisGameTooltipTextLeft"..i]:GetText(), timer.spell)) then
ti.icon = GetInventoryItemTexture("player", 17);
Gnosis:Timers_WeaponEnchant(bar, timer, ti, exists, expires, charges);
end
end
elseif(timer.bNot) then
ti.cname = timer.spell;
ti.icon = GetInventoryItemTexture("player", 17);
set_not(ti);
end
end
function Gnosis:Timers_Range(bar, timer, ti)
-- range between player and selected unit
local minRange, maxRange;
if (UnitExists(timer.unit)) then
minRange, maxRange = Gnosis.range:GetRange(timer.unit);
end
if (minRange and maxRange) then
ti.unit = timer.unit;
ti.bSpecial = true;
if (timer.brange) then
--[[ range_tab structure
[1] == value lower bound (>=)
[2] == value upper bound (<=)
[3] == stacks lower bound (>=)
[4] == stacks upper bound (<=)
[5] == value lower bound is in percent (true, nil)
[6] == value upper bound is in percent (true, nil) ]]
if (timer.range_tab[5] or timer.range_tab[6]) then
-- percentages of what??? (not allowed)
ti.ok = false;
else
if (minRange <= (timer.range_tab[2] or 10000) and
maxRange >= (timer.range_tab[1] or 0)) then
ti.ok = true;
end
end
else
ti.ok = true;
end
set_times(timer, ti, maxRange, minRange, true);
elseif (timer.bNot) then
ti.cname = "";
ti.icon = nil;
ti.unit = timer.unit;
set_not(ti);
end
end
function Gnosis:Timers_Power(bar, timer, ti)
-- mana, rage, focus, energy
local s, d = UnitPower(timer.unit), UnitPowerMax(timer.unit);
if(d and d > 0) then
local pts = select(2, UnitPowerType(timer.unit));
ti.cname = pts and _G[pts] or "";
ti.unit = timer.unit;
ti.bSpecial = true;
if(timer.brange) then
ti.ok = in_value_range(s, s*100/d, timer.range_tab);
else
ti.ok = true;
end
set_times(timer, ti, d, s, true);
elseif(timer.bNot) then
ti.cname = "";
ti.icon = nil;
ti.unit = timer.unit;
set_not(ti);
end
end
function Gnosis:Timers_PowerGeneric(bar, timer, ti)
-- soul shards, eclipse, holy power, dark force, light force (chi)
-- shadow orbs, burning embers and demonic fury
-- combo points (6.0)
local idx = timer.type - 2000;
local s, d = UnitPower(timer.unit, idx, timer.resource_decimals), UnitPowerMax(timer.unit, idx, timer.resource_decimals);
if (d and d > 0) then
-- values including decimals?
if (timer.resource_decimals) then
s = s / 10;
d = d / 10;
end
-- get name and icon of the effect
if (not ti.cname or ti.cname == "") then
ti.cname =