-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManaWarning.lua
910 lines (766 loc) · 28.4 KB
/
ManaWarning.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
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
-- Author : Kwast
-- Create Date : 1/11/2008 3:46:08 PM
-- savedvariable
ManaWarning_Settings = {};
-- defaults
bManaWarningActive = true;
sManaWarningMsg = "Need Mana";
iManaWarningTmr = 20;
iManaTreshhold = 50.0;
bManaDoPotsCheck = true;
bManaDoCombatCheck = true;
bManaOomStatusAnnounce = true;
iOomPercentageTreshhold = 5.0;
iOomWarningTmr = 60;
bHealthWarningActive = true;
sHealthWarningMsg = "Need Healing";
iHealthWarningTmr = 20;
iHealthTreshhold = 50.0;
bHealthDoPotsCheck = true;
bHealthDoCombatCheck = true;
bDisableInPvp = true;
sOomMsg = "OOM!";
sPotionHint = "";
iManaFloodProtection = 99;
iCurrentManaFloodCount = 0;
bOnlyCheckPotionsInRaid = false;
bAnnounceOomToParty = false;
bAnnounceOomToInstance = false;
bAnnounceOomToRaid = true;
sCurrentSpecName = "";
--
-- IconHelpers
icons1 = {
star = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_1:0|t",
circle = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_2:0|t",
diamond = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_3:0|t",
triangle = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_4:0|t",
moon = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_5:0|t",
square = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_6:0|t",
cross = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_7:0|t",
skull = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_8:0|t",
}
icons2 = {
rt1 = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_1:0|t",
rt2 = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_2:0|t",
rt3 = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_3:0|t",
rt4 = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_4:0|t",
rt5 = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_5:0|t",
rt6 = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_6:0|t",
rt7 = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_7:0|t",
rt8 = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_8:0|t",
}
function ManaWarning_ResolveIcons( s1 )
local s2 = s1;
for sIconName,sImageLink in pairs(icons1) do
s2 = string.gsub( s2, "{"..sIconName.."}", sImageLink );
end
for sIconName,sImageLink in pairs(icons2) do
s2 = string.gsub( s2, "{"..sIconName.."}", sImageLink );
end
return s2;
end
-- timer stuff
ManaWarning_Timers = {};
function ManaWarning_Schedule( t, f )
local now = GetTime();
local task = { now + t, f };
tinsert( ManaWarning_Timers, task );
end
function ManaWarning_CheckTasks()
local c = #(ManaWarning_Timers);
local i = 1;
while i <= c do
local task = ManaWarning_Timers[i];
if GetTime() > task[1] then
tremove( ManaWarning_Timers, i );
c = c - 1;
i = i - 1;
local f = task[2];
f();
end
i = i + 1;
end
end
--
function chkWarningMana_OnClick()
if ( chkWarningMana:GetChecked() ) then
edManaThresh:Show();
lblManaThresh:Show();
lblMana:Show();
lblManaText:Show();
edManaText:Show();
lblManaInt:Show();
edManaInt:Show();
lblManaIntSeconds:Show();
edManaFloodProtection:Show();
else
edManaThresh:Hide();
lblManaThresh:Hide();
lblMana:Hide();
lblManaText:Hide();
edManaText:Hide();
lblManaInt:Hide();
edManaInt:Hide();
lblManaIntSeconds:Hide();
edManaFloodProtection:Hide();
end
end
function chkWarningHealth_OnClick()
if ( chkWarningHealth:GetChecked() ) then
edHealthThresh:Show();
lblHealthThresh:Show();
lblHealth:Show();
chkWarningHealthCombat:Show();
chkWarningHealthChecks:Show();
lblHealthText:Show();
edHealthText:Show();
lblHealthInt:Show();
edHealthInt:Show();
lblHealthIntSeconds:Show();
else
edHealthThresh:Hide();
lblHealthThresh:Hide();
lblHealth:Hide();
chkWarningHealthCombat:Hide();
chkWarningHealthChecks:Hide();
lblHealthText:Hide();
edHealthText:Hide();
lblHealthInt:Hide();
edHealthInt:Hide();
lblHealthIntSeconds:Hide();
end
end
function chkWarningOom_OnClick()
if ( chkWarningOom:GetChecked() ) then
lblOomThresh:Show();
edOomThresh:Show();
lblOomThreshPerc:Show();
lblOomInt:Show();
edOomInt:Show();
lblOomIntSeconds:Show();
edOomText:Show();
chkAnnounceOomToParty:Show();
chkAnnounceOomToInstance:Show();
chkAnnounceOomToRaid:Show();
else
lblOomThresh:Hide();
edOomThresh:Hide();
lblOomThreshPerc:Hide();
lblOomInt:Hide();
edOomInt:Hide();
lblOomIntSeconds:Hide();
edOomText:Hide();
chkAnnounceOomToParty:Hide();
chkAnnounceOomToInstance:Hide();
chkAnnounceOomToRaid:Hide();
end
end
function btnSave_OnClick()
ManaWarningSettings_SaveSettingsIntoVars();
ManaWarningSettings_SaveToSavedVariables();
end
function btnCancel_OnClick()
ManaWarningSettings_LoadFromSavedVariables();
end
function ManaWarningSettings_InitDefaults()
bManaWarningActive = true;
sManaWarningMsg = "Need Mana";
iManaWarningTmr = 20;
iManaTreshhold = 50.0;
bManaDoPotsCheck = true;
bManaDoCombatCheck = true;
bManaOomStatusAnnounce = true;
iOomPercentageTreshhold = 10.0;
iOomWarningTmr = 60;
bHealthWarningActive = true;
sHealthWarningMsg = "Need Healing";
iHealthWarningTmr = 20;
iHealthTreshhold = 50.0;
bHealthDoPotsCheck = true;
bHealthDoCombatCheck = true;
iManaFloodProtection = 99;
iCurrentManaFloodCount = 0;
bOnlyCheckPotionsInRaid = false;
bAnnounceOomToParty = false;
bAnnounceOomToInstance = false;
sOomMsg = "OOM!";
bAnnounceOomToRaid = true;
end
function ManaWarningSettings_LoadFromVars()
chkWarningMana:SetChecked( bManaWarningActive );
edManaThresh:SetNumber( iManaTreshhold );
edManaText:SetText( sManaWarningMsg );
edManaInt:SetNumber( iManaWarningTmr );
chkWarningManaCombat:SetChecked( bManaDoCombatCheck );
chkWarningManaChecks:SetChecked( bManaDoPotsCheck );
chkWarningHealth:SetChecked( bHealthWarningActive );
edHealthThresh:SetNumber( iHealthTreshhold );
edHealthText:SetText( sHealthWarningMsg );
edHealthInt:SetNumber( iHealthWarningTmr );
chkWarningHealthCombat:SetChecked( bHealthDoCombatCheck );
chkWarningHealthChecks:SetChecked( bHealthDoPotsCheck );
chkWarningOom:SetChecked( bManaOomStatusAnnounce );
edOomThresh:SetNumber( iOomPercentageTreshhold );
edOomInt:SetNumber( iOomWarningTmr );
edOomText:SetText( sOomMsg );
edManaFloodProtection:SetNumber( iManaFloodProtection );
chkOnlyCheckPotionsInRaid:SetChecked( bOnlyCheckPotionsInRaid );
chkAnnounceOomToParty:SetChecked( bAnnounceOomToParty );
chkAnnounceOomToInstance:SetChecked( bAnnounceOomToInstance );
chkAnnounceOomToRaid:SetChecked( bAnnounceOomToRaid );
end
function ManaWarningSettings_SaveSettingsIntoVars()
bManaWarningActive = chkWarningMana:GetChecked();
iManaTreshhold = edManaThresh:GetNumber();
sManaWarningMsg = edManaText:GetText();
iManaWarningTmr = edManaInt:GetNumber();
bManaDoCombatCheck = chkWarningManaCombat:GetChecked();
bManaDoPotsCheck = chkWarningManaChecks:GetChecked();
bHealthWarningActive = chkWarningHealth:GetChecked();
iHealthTreshhold = edHealthThresh:GetNumber();
sHealthWarningMsg = edHealthText:GetText();
iHealthWarningTmr = edHealthInt:GetNumber();
bHealthDoCombatCheck = chkWarningHealthCombat:GetChecked();
bHealthDoPotsCheck = chkWarningHealthChecks:GetChecked();
bManaOomStatusAnnounce = chkWarningOom:GetChecked();
iOomPercentageTreshhold = edOomThresh:GetNumber();
iOomWarningTmr = edOomInt:GetNumber();
sOomMsg = edOomText:GetText();
iManaFloodProtection = edManaFloodProtection:GetNumber();
bOnlyCheckPotionsInRaid = chkOnlyCheckPotionsInRaid:GetChecked();
bAnnounceOomToParty = chkAnnounceOomToParty:GetChecked();
bAnnounceOomToInstance = chkAnnounceOomToInstance:GetChecked();
bAnnounceOomToRaid = chkAnnounceOomToRaid:GetChecked();
end
function ManaWarningSettings_Refresh()
chkWarningManaText:SetText( "Mana warning" );
chkWarningHealthText:SetText( "Health warning" );
chkWarningOomText:SetText( "OOM warning" );
chkWarningManaCombatText:SetText( "Only when in combat" );
chkWarningManaChecksText:SetText( "Check cooldowns" );
chkWarningHealthCombatText:SetText( "Only when in combat" );
chkWarningHealthChecksText:SetText( "Check cooldowns" );
chkOnlyCheckPotionsInRaidText:SetText( "Only check potions in raid" );
chkAnnounceOomToPartyText:SetText( "Announce OOM to party" );
chkAnnounceOomToInstanceText:SetText( "Announce OOM to instance" );
chkAnnounceOomToRaidText:SetText( "Announce OOM to raid" );
ManaWarningSettings_LoadFromVars();
chkWarningMana_OnClick();
chkWarningHealth_OnClick();
chkWarningOom_OnClick();
end
function ManaWarningSettings_LoadFromSavedVariables()
if ( #(ManaWarning_Settings) >= 15 ) then
bManaWarningActive = ManaWarning_Settings[1];
iManaTreshhold = ManaWarning_Settings[2];
sManaWarningMsg = ManaWarning_Settings[3];
iManaWarningTmr = ManaWarning_Settings[4];
bManaDoCombatCheck = ManaWarning_Settings[5];
bManaDoPotsCheck = ManaWarning_Settings[6];
bHealthWarningActive = ManaWarning_Settings[7];
iHealthTreshhold = ManaWarning_Settings[8];
sHealthWarningMsg = ManaWarning_Settings[9];
iHealthWarningTmr = ManaWarning_Settings[10];
bHealthDoCombatCheck = ManaWarning_Settings[11];
bHealthDoPotsCheck = ManaWarning_Settings[12];
bManaOomStatusAnnounce = ManaWarning_Settings[13];
iOomPercentageTreshhold = ManaWarning_Settings[14];
iOomWarningTmr = ManaWarning_Settings[15];
-- dirty hack for old situation with mp instead of percentages
if iManaTreshhold > 100.0 then
iManaTreshhold = 50.0;
end
if iHealthTreshhold > 100.0 then
iHealthTreshhold = 50.0;
end
if #(ManaWarning_Settings) >= 16 then
sOomMsg = ManaWarning_Settings[16];
end;
bDisableInPvp = ManaWarning_Settings[17];
if #(ManaWarning_Settings) >= 18 then
iManaFloodProtection = ManaWarning_Settings[18];
end
bOnlyCheckPotionsInRaid = ManaWarning_Settings[19];
bAnnounceOomToParty = ManaWarning_Settings[20];
bAnnounceOomToRaid = ManaWarning_Settings[21];
if ManaWarning_Settings[22] == -1 then
-- old, default to false
else
bAnnounceOomToInstance = ManaWarning_Settings[22];
end
else
ManaWarningSettings_InitDefaults();
ManaWarningSettings_SaveToSavedVariables();
end
end
function ManaWarningSettings_SaveToSavedVariables()
ManaWarning_Settings = {};
ManaWarning_Settings[1] = bManaWarningActive;
ManaWarning_Settings[2] = iManaTreshhold;
ManaWarning_Settings[3] = sManaWarningMsg;
ManaWarning_Settings[4] = iManaWarningTmr;
ManaWarning_Settings[5] = bManaDoCombatCheck;
ManaWarning_Settings[6] = bManaDoPotsCheck;
ManaWarning_Settings[7] = bHealthWarningActive;
ManaWarning_Settings[8] = iHealthTreshhold;
ManaWarning_Settings[9] = sHealthWarningMsg;
ManaWarning_Settings[10] = iHealthWarningTmr;
ManaWarning_Settings[11] = bHealthDoCombatCheck;
ManaWarning_Settings[12] = bHealthDoPotsCheck;
ManaWarning_Settings[13] = bManaOomStatusAnnounce;
ManaWarning_Settings[14] = iOomPercentageTreshhold;
ManaWarning_Settings[15] = iOomWarningTmr;
ManaWarning_Settings[16] = sOomMsg;
ManaWarning_Settings[17] = bDisableInPvp;
ManaWarning_Settings[18] = iManaFloodProtection;
ManaWarning_Settings[19] = bOnlyCheckPotionsInRaid;
ManaWarning_Settings[20] = bAnnounceOomToParty;
ManaWarning_Settings[21] = bAnnounceOomToRaid;
ManaWarning_Settings[22] = bAnnounceOomToInstance;
end
function btnRestoreDefaults_OnClick()
ManaWarningSettings_InitDefaults();
ManaWarningSettings_LoadFromVars();
chkWarningMana_OnClick();
chkWarningHealth_OnClick();
chkWarningOom_OnClick();
end
-------------------------------------------------
-- consts
CONST_VARSLOADED = "VARIABLES_LOADED";
CONST_POWERUPDATE = "UNIT_POWER_UPDATE";
CONST_HEALTHUPDATE = "UNIT_HEALTH";
CONST_PLAYER = "player";
CONST_SPEC_CHANGE = "ACTIVE_TALENT_GROUP_CHANGED";
-- vars
bReady = false;
bManaWarningGiven = false;
bHealthWarningGiven = false;
bManaOOMWarningGiven = false;
bDebug = false;
-- Mage shared cooldown gems
MANA_RESTORING_STUFF_A = {
--[36799] = "Mana Gem",
--[33312] = "Mana Sapphire",
--[22044] = "Mana Emerald",
--[8008] = "Mana Sapphire",
--[8007] = "Mana Citrine",
--[5513] = "Mana Jade",
--[5514] = "Mana Agate",
};
-- Shared cooldown mana pots
MANA_RESTORING_STUFF_B = {
[127835] = "Ancient Mana Potion",
[109222] = "Draenic Mana Potion",
[109221] = "Draenic Channeled Mana Potion",
[76098] = "Master Mana Potion",
[57192] = "Mythical Mana Potion",
[57193] = "Mighty Rejuvenation Potion",
[57194] = "Potion of Concentration",
[40077] = "Crazy Alchemist's Potion",
[42545] = "Runic Mana Injector",
[33448] = "Runic Mana Potion",
[43570] = "Endless Mana Potion",
[22832] = "Super Mana Potion",
[33093] = "Mana Potion Injector",
[40067] = "Icy Mana Potion",
[43530] = "Argent Mana Potion",
[34440] = "Mad Alchemist's Potion",
[22850] = "Super Rejuvenation Potion",
[31677] = "Fel Mana Potion",
[28101] = "Unstable Mana Potion",
[13444] = "Major Mana Potion",
[33935] = "Crystal Mana Potion",
[32948] = "Auchenai Mana Potion",
};
-- health stuff; no cooldown, just disapears when used
HEALTH_RESTORING_STUFF_A = {
[129196] = "Legion Healthstone",
[22105] = "Master Healthstone",
[22104] = "Master Healthstone",
[22103] = "Master Healthstone",
[32578] = "Charged Crystal Focus",
};
-- Shared cooldown mana pots
HEALTH_RESTORING_STUFF_B = {
[127834] = "Ancient Healing Potion",
[127836] = "Ancient Rejuvenation Potion",
[136569] = "Aged Health Potion",
[109226] = "Draenic Rejuvenation Potion",
[109223] = "Healing Tonic",
[117415] = "Smuggled Tonic",
[80040] = "Endless Master Healing Potion",
[76097] = "Master Healing Potion",
[57191] = "Mythical Healing Potion",
[57193] = "Mighty Rejuvenation Potion",
[40077] = "Crazy Alchemist's Potion",
[41166] = "Runic Healing Injector",
[33447] = "Runic Healing Potion",
[43569] = "Endless Healing Potion",
[22829] = "Super Healing Potion",
[33092] = "Healing Potion Injector",
[43531] = "Argent Healing Potion",
[34440] = "Mad Alchemist's Potion",
[22850] = "Super Rejuvenation Potion",
[31676] = "Fel Regeneration Potion",
[13446] = "Major Healing Potion",
[33934] = "Crystal Healing Potion",
[32947] = "Auchenai Healing Potion",
};
-- OnLoad function
function ManaWarning_OnLoad(obj)
ManaWarningSettings:Hide();
obj:RegisterEvent( CONST_VARSLOADED );
obj:RegisterEvent( CONST_POWERUPDATE );
obj:RegisterEvent( CONST_HEALTHUPDATE );
obj:RegisterEvent( CONST_SPEC_CHANGE );
obj.name = "ManaWarning";
obj.okay = function (obj) btnSave_OnClick(); end;
obj.cancel = function (obj) btnCancel_OnClick(); end;
obj.default = function (obj) btnRestoreDefaults_OnClick(); end;
obj.refresh = function (obj) ManaWarningSettings_Refresh(); end;
InterfaceOptions_AddCategory(obj);
sCurrentSpecName = GetCurrentTalentSpec();
end
function ManaWarning_PlayerIsInPvp()
if UnitIsPVP(CONST_PLAYER) then
return true;
end
return false;
end
-- OnEvent
function ManaWarning_OnEvent( obj, event, ... )
ManaWarning_CheckTasks();
if ( event == CONST_VARSLOADED ) then
ManaWarningSettings_LoadFromSavedVariables();
bReady = true;
elseif ( event == CONST_POWERUPDATE ) then
bDoCheck = true;
if bDisableInPvp then
bDoCheck = not ManaWarning_PlayerIsInPvp();
end
if bDoCheck then
local unitId, resource = ...;
if ( bManaWarningActive or bManaOomStatusAnnounce ) then
if (resource == "MANA") then
-- or (resource == "FOCUS") ??
-- apparently you get updates for everyone in your party/raid, so check if we get a "player" update
if ( unitId == CONST_PLAYER ) then
ManaWarning_PlayerManaUpdate();
end
end
end
end
elseif ( event == CONST_HEALTHUPDATE ) then
bDoCheck = true;
if bDisableInPvp then
bDoCheck = not ManaWarning_PlayerIsInPvp();
end
if bDoCheck then
local unitId = ...;
if ( bHealthWarningActive ) then
if ( unitId == CONST_PLAYER ) then
ManaWarning_PlayerHealthUpdate();
end
end
end
elseif ( event == CONST_SPEC_CHANGE ) then
ManaWarning_PlayerSpecChange();
end
end
function getLowestCDInArrayOfItems( iHighestCD, array )
iLowestRemainingTime = iHighestCD;
for itemId,sName in pairs(array) do
ic = GetItemCount( itemId );
if ( ic > 0 ) then
pot_start, pot_dur, pot_en = GetItemCooldown( itemId );
remaining_time = 0;
if ( pot_start > 0 ) then
current_time = GetTime();
remaining_time = floor( pot_dur - (current_time - pot_start) );
end
if ( remaining_time < iLowestRemainingTime ) then
iLowestRemainingTime = remaining_time;
end
end
if ( iLowestRemainingTime == 0 ) then
sPotionHint = sName;
break;
end
end
return iLowestRemainingTime;
end
function getSpellCD( sName )
current_time = GetTime();
usable, nomana = IsUsableSpell( sName );
if ( usable ) then
spell_start, spell_dur, spell_en = GetSpellCooldown( sName );
if ( spell_start ) then
if spell_dur < 1.5 then -- ignore gcd
return 0;
else
if ( spell_start > 0 ) then
remaining_time = floor( spell_dur - (current_time - spell_start) );
return remaining_time;
end
end
end
return 0;
end
return 600;
end
--function HasManaTideTotemOut()
-- for i = 1, 40 do
-- local buff = UnitBuff(CONST_PLAYER, i);
-- if buff then
-- if (buff == "Mana Tide Totem") then
-- return true;
-- end
-- end
-- end
--
-- return false;
--end
-- Are all Mana restoring items on cooldown?
function ManaWarning_TimeManaOnCooldown()
iLowestRemainingTime = 600; -- 10 minutes
iLowestRemainingTime = getLowestCDInArrayOfItems( iLowestRemainingTime, MANA_RESTORING_STUFF_A );
if ( iLowestRemainingTime == 0 ) then
return 0;
end
-- special spells
locClass, enClass = UnitClass( CONST_PLAYER );
if ( enClass == "DRUID" ) then
iSpCd = getSpellCD( "Innervate" );
if ( iSpCd < iLowestRemainingTime ) then
iLowestRemainingTime = iSpCd;
end
if ( iSpCd == 0 ) then
sPotionHint = "Innervate";
return 0;
end
elseif ( enClass == "MAGE" ) then
iSpCd = getSpellCD( "Evocation" );
if ( iSpCd < iLowestRemainingTime ) then
iLowestRemainingTime = iSpCd;
end
if ( iSpCd == 0 ) then
sPotionHint = "Evocation";
return 0;
end
elseif ( enClass == "PRIEST" ) then
iSpCd = getSpellCD( "Mindbender" );
if ( iSpCd < iLowestRemainingTime ) then
iLowestRemainingTime = iSpCd;
end
if ( iSpCd == 0 ) then
sPotionHint = "Mindbender";
return 0;
end
iSpCd = getSpellCD( "Shadowfiend" );
if ( iSpCd < iLowestRemainingTime ) then
iLowestRemainingTime = iSpCd;
end
if ( iSpCd == 0 ) then
sPotionHint = "Shadowfiend";
return 0;
end
-- iSpCd = getSpellCD( "Hymn of Hope" );
-- if ( iSpCd < iLowestRemainingTime ) then
-- iLowestRemainingTime = iSpCd;
-- end
-- if ( iSpCd == 0 ) then
-- sPotionHint = "Hymn of Hope";
-- return 0;
-- end
elseif ( enClass == "SHAMAN" ) then
-- iSpCd = getSpellCD("Mana Tide Totem")
-- if ( iSpCd == 0 ) and not HasManaTideTotemOut() then
-- sPotionHint = "Mana Tide Totem";
-- return 0;
-- end
end
bCheckPots = false;
if bOnlyCheckPotionsInRaid then
bCheckPots = UnitInRaid(CONST_PLAYER);
else
bCheckPots = true;
end
if bCheckPots then
iLowestRemainingTime = getLowestCDInArrayOfItems( iLowestRemainingTime, MANA_RESTORING_STUFF_B );
if ( iLowestRemainingTime == 0 ) then
return 0;
end
end
return iLowestRemainingTime;
end
-- Are all Health restoring items on cooldown?
function ManaWarning_TimeHealthOnCooldown()
iLowestRemainingTime = 600; -- 10 minutes
iLowestRemainingTime = getLowestCDInArrayOfItems( iLowestRemainingTime, HEALTH_RESTORING_STUFF_A );
if ( iLowestRemainingTime == 0 ) then
return 0;
end
bCheckPots = false;
if bOnlyCheckPotionsInRaid then
bCheckPots = UnitInRaid(CONST_PLAYER);
else
bCheckPots = true;
end
if bCheckPots then
iLowestRemainingTime = getLowestCDInArrayOfItems( iLowestRemainingTime, HEALTH_RESTORING_STUFF_B );
if ( iLowestRemainingTime == 0 ) then
return 0;
end
end
return iLowestRemainingTime;
end
function ManaWarning_MessagePartyRaid( sMsg )
local sMsg2 = ManaWarning_ResolveIcons( sMsg );
RaidNotice_AddMessage(RaidBossEmoteFrame, sMsg2, ChatTypeInfo["RAID_WARNING"]);
local done = false;
if ( UnitInRaid( CONST_PLAYER ) ) then
if (bAnnounceOomToRaid) and not ManaWarning_PlayerIsInPvp() then
SendChatMessage( sMsg, "RAID", nil, "" );
done = true;
else
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage( sMsg2, 1.0, 0.0, 0.0);
done = true;
end
end
elseif (bAnnounceOomToInstance) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
SendChatMessage( sMsg, "INSTANCE_CHAT", nil, "" );
done = true;
end;
if not done and bAnnounceOomToParty and IsInGroup() then
SendChatMessage( sMsg, "PARTY", nil, "" );
done = true;
end;
if not done then
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage( sMsg2, 1.0, 0.0, 0.0);
end
end
end
function ManaWarning_MessageSelf( sMsg )
local sMsg2 = ManaWarning_ResolveIcons( sMsg );
RaidNotice_AddMessage(RaidBossEmoteFrame, sMsg2, ChatTypeInfo["RAID_WARNING"]);
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage( sMsg2, 1.0, 0.0, 0.0);
end
end
-- PlayerManaUpdate
function ManaWarning_PlayerManaUpdate()
-- if mana user atm
if ( UnitPowerType( CONST_PLAYER ) == 0 ) then
maxmana = UnitPowerMax( CONST_PLAYER );
currentmana = UnitPower( CONST_PLAYER );
bMayGiveWarning = true;
if ( bManaDoCombatCheck ) then
-- don't warn if we're not in combat
if ( UnitAffectingCombat( CONST_PLAYER ) == nil ) then
bMayGiveWarning = false;
end
end
iLowestRemainingTime = 0;
if ( bManaDoPotsCheck ) then
sPotionHint = "";
iLowestRemainingTime = ManaWarning_TimeManaOnCooldown();
end
if ( bMayGiveWarning and bManaOomStatusAnnounce and not bManaOOMWarningGiven ) then
oom_tresh = maxmana / 100.0 * iOomPercentageTreshhold;
if ( currentmana < oom_tresh ) then
bManaOOMWarningGiven = true;
if ( bManaDoPotsCheck ) then
ManaWarning_MessagePartyRaid( sOomMsg.." (CD's "..iLowestRemainingTime.."s)" );
else
ManaWarning_MessagePartyRaid( sOomMsg );
end
ManaWarning_Schedule( iOomWarningTmr, ManaWarning_ResetManaOOMWarningGiven );
end
end
if ( bManaWarningActive and bMayGiveWarning and not bManaWarningGiven ) then
mana_tresh = maxmana / 100.0 * iManaTreshhold;
if ( currentmana < mana_tresh ) then
bManaWarningGiven = true;
if ( iLowestRemainingTime == 0 ) then
iLowestRemainingTime = iManaWarningTmr;
end
ManaWarning_Schedule( iLowestRemainingTime, ManaWarning_ResetManaWarningGiven );
if iCurrentManaFloodCount < iManaFloodProtection then
iCurrentManaFloodCount = iCurrentManaFloodCount + 1;
if ( bManaDoPotsCheck ) then
if not ( sPotionHint == "" ) then
ManaWarning_MessageSelf( sManaWarningMsg .. " (Try using " .. sPotionHint .. ")");
end
else
ManaWarning_MessageSelf( sManaWarningMsg );
end
end
else
-- reset flood protection once you're above the treshhold
iCurrentManaFloodCount = 0;
-- class specific stuff once no more below treshhold
--locClass, enClass = UnitClass( CONST_PLAYER );
--if ( enClass == "HUNTER" ) then
--end
end
end
end
end
-- PlayerHealthUpdate
function ManaWarning_PlayerHealthUpdate()
currenthp = UnitHealth( CONST_PLAYER );
maxhp = UnitHealthMax( CONST_PLAYER );
bMayGiveWarning = true;
if ( bHealthDoCombatCheck ) then
-- don't warn if we're not in combat
if ( UnitAffectingCombat( CONST_PLAYER ) == nil ) then
bMayGiveWarning = false;
end
end
if ( bMayGiveWarning and not bHealthWarningGiven ) then
health_tresh = maxhp / 100.0 * iHealthTreshhold;
if ( currenthp < health_tresh ) then
bHealthWarningGiven = true;
iLowestRemainingTime = 0;
if ( bHealthDoPotsCheck ) then
sPotionHint = "";
iLowestRemainingTime = ManaWarning_TimeHealthOnCooldown();
end
if ( iLowestRemainingTime == 0 ) then
iLowestRemainingTime = iHealthWarningTmr;
end
ManaWarning_Schedule( iLowestRemainingTime, ManaWarning_ResetHealthWarningGiven );
if ( bHealthDoPotsCheck ) then
if not ( sPotionHint == "" ) then
ManaWarning_MessageSelf( sHealthWarningMsg .. " (Try using " .. sPotionHint .. ")");
end
else
ManaWarning_MessageSelf( sHealthWarningMsg );
end
end
end
end
-- PlayerSpecChange
function ManaWarning_PlayerSpecChange()
sCurrentSpecName = GetCurrentTalentSpec();
end
-- Resets a boolean, so the ManaWarning will again show on the screen if we're still without mana
function ManaWarning_ResetManaWarningGiven()
bManaWarningGiven = false;
end
function ManaWarning_ResetHealthWarningGiven()
bHealthWarningGiven = false;
end
-- Resets a boolean, so the OOM-message will again show
function ManaWarning_ResetManaOOMWarningGiven()
bManaOOMWarningGiven = false;
end
-- Returns current Talent specialization
function GetCurrentTalentSpec()
local currentSpec = GetSpecialization()
return currentSpec and select(2, GetSpecializationInfo(currentSpec)) or "None"
end