-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck.lua
More file actions
2242 lines (2066 loc) · 81.9 KB
/
Copy pathCheck.lua
File metadata and controls
2242 lines (2066 loc) · 81.9 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
-------------------------------------------------------------------------------
-- SmartBuff Check
-------------------------------------------------------------------------------
local SG = SMARTBUFF_GLOBALS;
-- Aura cache (rebuilt per check pass; keyed by unit then buff name)
-- SG.SMARTBUFF_ClearAuraCache
-- Clears all cached unit buff auras.
-- Parameters: none
-- Returns: nothing
function SG.SMARTBUFF_ClearAuraCache()
wipe(SG.cAuraCache);
end
-- SG.SMARTBUFF_InvalidateAuraCache
-- Drops the aura cache entry for one unit.
-- Parameters:
-- unit (string) Unit token
-- Returns: nothing
function SG.SMARTBUFF_InvalidateAuraCache(unit)
if (unit) then SG.cAuraCache[unit] = nil; end
end
-- SG.SMARTBUFF_BuildAuraCache
-- Scans UnitBuff slots and builds a name-keyed cache for the unit.
-- Parameters:
-- unit (string) Unit token
-- Returns:
-- (table) Cache table { [buffName] = { name, icon, count, ... } }
function SG.SMARTBUFF_BuildAuraCache(unit)
local cache = { };
for i = 1, 40 do
local name, icon, count, debuffType, duration, expirationTime, caster = UnitBuff(unit, i);
if (not name) then break; end
cache[name] = { name, icon, count, debuffType, duration, expirationTime, caster };
end
SG.cAuraCache[unit] = cache;
return cache;
end
-- SG.SMARTBUFF_GetAuraCache
-- Returns the aura cache for a unit, building it if missing.
-- Parameters:
-- unit (string) Unit token
-- Returns:
-- (table) Aura cache for the unit
function SG.SMARTBUFF_GetAuraCache(unit)
local cache = SG.cAuraCache[unit];
if (not cache) then
cache = SG.SMARTBUFF_BuildAuraCache(unit);
end
return cache;
end
-- SMARTBUFF_RebuildBagIndex
-- Rebuilds bag item count indexes by item ID and item name.
-- Parameters: none
-- Returns: nothing
function SMARTBUFF_RebuildBagIndex()
wipe(SG.cBagIndexByID);
wipe(SG.cBagIndexByName);
for bag = 0, NUM_BAG_FRAMES do
for slot = 1, C_Container.GetContainerNumSlots(bag) do
local bagItemID = C_Container.GetContainerItemID(bag, slot);
if (bagItemID) then
local containerInfo = C_Container.GetContainerItemInfo(bag, slot);
local stackCount = containerInfo and containerInfo.stackCount or 1;
SG.cBagIndexByID[bagItemID] = (SG.cBagIndexByID[bagItemID] or 0) + stackCount;
local bagItemName = GetItemInfo(bagItemID);
if (bagItemName) then
SG.cBagIndexByName[bagItemName] = (SG.cBagIndexByName[bagItemName] or 0) + stackCount;
end
end
end
end
SG.cBagIndexDirty = false;
end
-- SG.SMARTBUFF_EnsureBagIndex
-- Rebuilds the bag index when marked dirty.
-- Parameters: none
-- Returns: nothing
function SG.SMARTBUFF_EnsureBagIndex()
if (SG.cBagIndexDirty) then SMARTBUFF_RebuildBagIndex(); end
end
-- SG.SMARTBUFF_HasBagItemID
-- Checks whether the player has at least one of the given item ID in bags.
-- Parameters:
-- itemID (number) Item ID to look up
-- Returns:
-- (boolean) True if count > 0
function SG.SMARTBUFF_HasBagItemID(itemID)
if (not itemID) then return false; end
SG.SMARTBUFF_EnsureBagIndex();
return (SG.cBagIndexByID[itemID] or 0) > 0;
end
-- SG.SMARTBUFF_HasConjuredItemList
-- Returns true if any item ID in the list is present in bags.
-- Parameters:
-- itemList (table) Array of item IDs
-- Returns:
-- (boolean)
function SG.SMARTBUFF_HasConjuredItemList(itemList)
if (not itemList) then return false; end
SG.SMARTBUFF_EnsureBagIndex();
for _, itemID in pairs(itemList) do
if (type(itemID) == "number" and (SG.cBagIndexByID[itemID] or 0) > 0) then
return true;
end
end
return false;
end
-- SG.SMARTBUFF_GetMageGemItemID
-- Maps a mage conjure-gem buff name to its created item ID.
-- Parameters:
-- buffnS (string) Buff short name
-- Returns:
-- (number|nil) Item ID, or nil if not a gem conjure buff
function SG.SMARTBUFF_GetMageGemItemID(buffnS)
if (not SG.cMageGemItemIDs) then
SG.cMageGemItemIDs = {
[SMARTBUFF_CREATEMGEM_AGATE] = 5514,
[SMARTBUFF_CREATEMGEM_CITRINE] = 8007,
[SMARTBUFF_CREATEMGEM_JADE] = 5513,
[SMARTBUFF_CREATEMGEM_RUBY] = 8008,
[SMARTBUFF_CREATEMGEM_EMERALD] = 22044,
};
end
return SG.cMageGemItemIDs[buffnS];
end
-- SG.SMARTBUFF_IsMageConjureBuff
-- Returns whether the buff is a mage food/water/gem conjure entry.
-- Parameters:
-- buffnS (string) Buff short name
-- Returns:
-- (boolean)
function SG.SMARTBUFF_IsMageConjureBuff(buffnS)
return buffnS == SMARTBUFF_CONJFOOD or buffnS == SMARTBUFF_CONJWATER
or buffnS == SMARTBUFF_CREATEMGEM_AGATE or buffnS == SMARTBUFF_CREATEMGEM_CITRINE
or buffnS == SMARTBUFF_CREATEMGEM_JADE or buffnS == SMARTBUFF_CREATEMGEM_RUBY
or buffnS == SMARTBUFF_CREATEMGEM_EMERALD;
end
-- SG.SMARTBUFF_IsWarlockConjureBuff
-- Returns whether the buff is a warlock soul/health/fire conjure entry.
-- Parameters:
-- buffnS (string) Buff short name
-- Returns:
-- (boolean)
function SG.SMARTBUFF_IsWarlockConjureBuff(buffnS)
return buffnS == SMARTBUFF_CREATEHS or buffnS == SMARTBUFF_CREATESOULS
or buffnS == SMARTBUFF_CREATESPELLS or buffnS == SMARTBUFF_CREATEFIRES;
end
-- SMARTBUFF_PreCheck
-- Gatekeeper before a buff check: options, timers, mount/combat state, UI setup.
-- Parameters:
-- mode (number) 0 = manual cast, 1 = auto splash, 5 = scroll wheel
-- force (boolean) Bypass auto-timer when true
-- Returns:
-- (boolean) True if checking may proceed
function SMARTBUFF_PreCheck(mode, force)
if (not SG.isInit) then return false end
if (not SG.isInitBtn) then
SMARTBUFF_InitActionButtonPos();
end
if (not SG.O.Toggle) then
if (mode == 0) then
SMARTBUFF_AddMsg(SMARTBUFF_MSG_DISABLED);
end
return false;
end
if (mode == 1 and not force) then
if (SG.tSkipSplashRecheck) then
if (GetTime() < SG.tSkipSplashRecheck) then
return false;
end
SG.tSkipSplashRecheck = nil;
elseif ((GetTime() - SG.tLastCheck) < SG.O.AutoTimer) then
return false;
end
end
SG.tLastCheck = GetTime();
-- If buffs can't casted, hide UI elements
if (UnitInVehicle("player") or UnitHasVehicleUI("player")) then
if (not InCombatLockdown() and SmartBuff_KeyButton:IsVisible()) then
SmartBuff_KeyButton:Hide();
end
return false;
else
SMARTBUFF_ShowSAButton();
end
-- if we have nothing to do and the option is set then just hide the action button.
if SG.O.HideSAButtonNoAction and not InCombatLockdown() then
SmartBuff_KeyButton:Hide()
end
if not SG.O.HideSAButtonNoAction and not SG.O.HideSAButton then
SMARTBUFF_SetButtonTexture(SmartBuff_KeyButton, SG.imgSB);
end
if (SmartBuffOptionsFrame:IsVisible()) then return false; end
-- check for mount-spells (Classic/TBC: Paladin only)
if (SG.sPlayerClass == "PALADIN" and (IsMounted() or IsFlying()) and not SMARTBUFF_CheckBuff("player", SMARTBUFF_CRUSADERAURA)) then
return true;
end
if ((mode == 1 and not SG.O.ToggleAuto) or IsMounted() and not SG.O.ToggleMountedPrompt or IsFlying() or LootFrame:IsVisible()
or UnitOnTaxi("player") or UnitIsDeadOrGhost("player") or UnitIsCorpse("player")
or (mode ~= 1 and (SMARTBUFF_IsPicnic("player") or SMARTBUFF_IsFishing("player")))
or (UnitInVehicle("player") or UnitHasVehicleUI("player"))
or (not SG.O.BuffInCities and IsResting() and not UnitIsPVP("player"))) then
if (UnitIsDeadOrGhost("player")) then
SMARTBUFF_CheckBuffTimers();
end
return false;
end
if (UnitAffectingCombat("player")) then
SG.isCombat = true;
else
SG.isCombat = false;
end
if (not SG.isCombat and SG.isSetBuffs) then
SMARTBUFF_SetBuffs();
SG.isSyncReq = true;
end
SG.sMsgWarning = "";
SG.isFirstError = true;
return true;
end
-- Buff timer functions
-- SMARTBUFF_CheckBuffTimers
-- Clears buff timers for dead units and resets group timers when units are cleared.
-- Parameters: none
-- Returns: nothing
function SMARTBUFF_CheckBuffTimers()
local n = 0;
local ct = SG.currentTemplate;
local cGrp = SG.cUnits;
for subgroup in pairs(cGrp) do
n = 0;
if (cGrp[subgroup] ~= nil) then
for _, unit in pairs(cGrp[subgroup]) do
if (unit) then
if (SMARTBUFF_CheckUnitBuffTimers(unit)) then
n = n + 1;
end
end
end
if (SG.cBuffTimer[subgroup]) then
SG.cBuffTimer[subgroup] = nil;
SMARTBUFF_AddMsgD("Group " .. subgroup .. ": group timer reseted");
end
end
end
end
-- SMARTBUFF_CheckUnitBuffTimers
-- Clears unit and class buff timers when the unit is dead (hunters: ignores feign death).
-- Parameters:
-- unit (string) Unit token
-- Returns:
-- (boolean|nil) True if timers were cleared
function SMARTBUFF_CheckUnitBuffTimers(unit)
if (UnitExists(unit) and UnitIsConnected(unit) and UnitIsFriend("player", unit) and UnitIsPlayer(unit) and UnitIsDeadOrGhost(unit)) then
local _, uc = UnitClass(unit);
local fd = nil;
if (uc == "HUNTER") then
fd = SMARTBUFF_IsFeignDeath(unit);
end
if (not fd) then
if (SG.cBuffTimer[unit]) then
SG.cBuffTimer[unit] = nil;
SMARTBUFF_AddMsgD(UnitName(unit) .. ": unit timer reseted");
end
if (SG.cBuffTimer[uc]) then
SG.cBuffTimer[uc] = nil;
SMARTBUFF_AddMsgD(uc .. ": class timer reseted");
end
return true;
end
end
end
-- SMARTBUFF_ResetBuffTimers
-- Forces internal buff timers to near-expiry for all enabled buffs, then runs an auto check.
-- Parameters: none
-- Returns: nothing
function SMARTBUFF_ResetBuffTimers()
if (not SG.isInit) then return; end
local ct = SG.currentTemplate;
local t = GetTime();
local rbTime = 0;
local i = 0;
local d = 0;
local tl = 0;
local buffS = nil;
local buff = nil;
local unit = nil;
local obj = nil;
local uc = nil;
local cGrp = SG.cGroups;
for subgroup in pairs(cGrp) do
n = 0;
if (cGrp[subgroup] ~= nil) then
for _, unit in pairs(cGrp[subgroup]) do
if (unit and UnitExists(unit) and UnitIsConnected(unit) and UnitIsFriend("player", unit) and UnitIsPlayer(unit) and not UnitIsDeadOrGhost(unit)) then
_, uc = UnitClass(unit);
i = 1;
while (SG.cBuffs[i] and SG.cBuffs[i].BuffS) do
d = -1;
buff = nil;
rbTime = 0;
buffS = SG.cBuffs[i].BuffS;
rbTime = SG.B[SG.CS()][ct][buffS].RBTime;
if (rbTime <= 0) then
rbTime = SG.O.RebuffTimer;
end
if (SG.cBuffs[i].BuffG and SG.B[SG.CS()][ct][buffS].EnableG and SG.cBuffs[i].IDG ~= nil and SG.cBuffs[i].DurationG > 0) then
d = SG.cBuffs[i].DurationG;
buff = SG.cBuffs[i].BuffG;
obj = subgroup;
end
if (d > 0 and buff) then
if (not SG.cBuffTimer[obj]) then
SG.cBuffTimer[obj] = { };
end
SG.cBuffTimer[obj][buff] = t - d + rbTime - 1;
end
buff = nil;
if (buffS and SG.B[SG.CS()][ct][buffS].EnableS and SG.cBuffs[i].IDS ~= nil and SG.cBuffs[i].DurationS > 0
and uc and SG.B[SG.CS()][ct][buffS][uc]) then
d = SG.cBuffs[i].DurationS;
buff = buffS;
obj = unit;
end
if (d > 0 and buff) then
if (not SG.cBuffTimer[obj]) then
SG.cBuffTimer[obj] = { };
end
SG.cBuffTimer[obj][buff] = t - d + rbTime - 1;
end
i = i + 1;
end
end
end
end
end
SMARTBUFF_Check(1, true);
end
-- SMARTBUFF_ShowBuffTimers
-- Prints remaining time on all tracked internal buff timers to chat.
-- Parameters: none
-- Returns: nothing
function SMARTBUFF_ShowBuffTimers()
if (not SG.isInit) then return; end
local ct = SG.currentTemplate;
local t = GetTime();
local rbTime = 0;
local i = 0;
local d = 0;
local tl = 0;
local buffS = nil;
for unit in pairs(SG.cBuffTimer) do
for buff in pairs(SG.cBuffTimer[unit]) do
if (unit and buff and SG.cBuffTimer[unit][buff]) then
d = -1;
buffS = nil;
if (SG.cBuffIndex[buff]) then
i = SG.cBuffIndex[buff];
if (SG.cBuffs[i].BuffS == buff and SG.cBuffs[i].DurationS > 0) then
d = SG.cBuffs[i].DurationS;
buffS = SG.cBuffs[i].BuffS;
elseif (SG.cBuffs[i].BuffG == buff and SG.cBuffs[i].DurationG > 0) then
d = SG.cBuffs[i].DurationG;
buffS = SG.cBuffs[i].BuffS;
end
i = i + 1;
end
if (buffS and SG.B[SG.CS()][ct][buffS] ~= nil) then
if (d > 0) then
rbTime = SG.B[SG.CS()][ct][buffS].RBTime;
if (rbTime <= 0) then
rbTime = SG.O.RebuffTimer;
end
tl = SG.cBuffTimer[unit][buff] + d - t;
if (tl >= 0) then
local s = "";
if (string.find(unit, "^party") or string.find(unit, "^raid") or string.find(unit, "^player") or string.find(unit, "^pet")) then
local un = UnitName(unit);
if (un) then
un = " (" .. un .. ")";
else
un = "";
end
s = "Unit " .. unit .. un;
elseif (string.find(unit, "^%d$")) then
s = "Grp " .. unit;
else
s = "Class " .. unit;
end
SMARTBUFF_AddMsg(string.format("%s: %s, time left: %.0f, rebuff time: %.0f", s, buff, tl, rbTime));
else
SG.cBuffTimer[unit][buff] = nil;
end
else
SG.cBuffTimer[unit][buff] = nil;
end
end
end
end
end
end
-- SMARTBUFF_SyncBuffTimers
-- Syncs internal buff timers with actual buff durations on all group units.
-- Parameters: none
-- Returns: nothing
function SMARTBUFF_SyncBuffTimers()
if (not SG.isInit or SG.isSync or SG.isSetBuffs or SMARTBUFF_IsTalentFrameVisible()) then return; end
SG.isSync = true;
SG.tSync = GetTime();
local ct = SG.currentTemplate;
local rbTime = 0;
local i = 0;
local buffS = nil;
local unit = nil;
local uc = nil;
local cGrp = SG.cGroups;
for subgroup in pairs(cGrp) do
n = 0;
if (cGrp[subgroup] ~= nil) then
for _, unit in pairs(cGrp[subgroup]) do
if (unit and UnitExists(unit) and UnitIsConnected(unit) and UnitIsFriend("player", unit) and UnitIsPlayer(unit) and not UnitIsDeadOrGhost(unit)) then
_, uc = UnitClass(unit);
i = 1;
while (SG.cBuffs[i] and SG.cBuffs[i].BuffS) do
rbTime = 0;
buffS = SG.cBuffs[i].BuffS;
rbTime = SG.B[SG.CS()][ct][buffS].RBTime;
if (rbTime <= 0) then
rbTime = SG.O.RebuffTimer;
end
if (buffS and SG.B[SG.CS()][ct][buffS].EnableS and SG.cBuffs[i].IDS ~= nil and SG.cBuffs[i].DurationS > 0) then
if (SG.cBuffs[i].Type ~= SMARTBUFF_CONST_SELF or (SG.cBuffs[i].Type == SMARTBUFF_CONST_SELF and SMARTBUFF_IsPlayer(unit))) then
SMARTBUFF_SyncBuffTimer(unit, unit, SG.cBuffs[i]);
end
end
i = i + 1;
end -- END while
end
end -- END for
end
end -- END for
SG.isSync = false;
SG.isSyncReq = false;
end
-- SMARTBUFF_SyncBuffTimer
-- Updates one buff timer entry from the unit's current aura time remaining.
-- Parameters:
-- unit (string) Unit token to read auras from
-- grp (string) Timer group key (unit, subgroup, or class)
-- cBuff (table) Buff definition from SG.cBuffs
-- Returns: nothing
function SMARTBUFF_SyncBuffTimer(unit, grp, cBuff)
if (not unit or not grp or not cBuff) then return end
local d = cBuff.DurationS;
local buff = cBuff.BuffS;
if (d and d > 0 and buff) then
local t = GetTime();
local ret, _, _, timeleft = SMARTBUFF_CheckUnitBuffs(unit, buff, cBuff.Type, cBuff.Links, cBuff.Chain);
if (ret == nil and timeleft ~= nil) then
if (not SG.cBuffTimer[grp]) then SG.cBuffTimer[grp] = { } end
st = SG.Round(t - d + timeleft, 2);
if (not SG.cBuffTimer[grp][buff] or (SG.cBuffTimer[grp][buff] and SG.cBuffTimer[grp][buff] ~= st)) then
SG.cBuffTimer[grp][buff] = st;
if (timeleft > 60) then
SMARTBUFF_AddMsgD("Buff timer sync: " .. grp .. ", " .. buff .. ", " .. string.format("%.1f", timeleft/60) .. "min");
else
SMARTBUFF_AddMsgD("Buff timer sync: " .. grp .. ", " .. buff .. ", " .. string.format("%.1f", timeleft) .. "sec");
end
end
end
end
end
-- SMARTBUFF_IsShapeshifted
-- Detects whether the player is in shaman ghost wolf or druid shapeshift form.
-- Parameters: none
-- Returns:
-- (boolean) True if shapeshifted
-- (string|nil) Form name when shapeshifted
function SMARTBUFF_IsShapeshifted()
if (SG.sPlayerClass == "SHAMAN") then
if (GetShapeshiftForm(true) > 0) then
return true, "Ghost Wolf";
end
elseif (SG.sPlayerClass == "DRUID") then
local i;
for i = 1, GetNumShapeshiftForms(), 1 do
local icon, active, castable, spellId = GetShapeshiftFormInfo(i);
local name = GetSpellInfo(spellId);
if (active and castable and name ~= SMARTBUFF_DRUID_TREANT) then
return true, name;
end
end
end
return false, nil;
end
-- SG.buildSpellRankInfo
-- Scans the spellbook and builds SG.cSpellRankInfo for all ranks of a spell.
-- Parameters:
-- spell (string) Base spell name
-- Returns: nothing (populates SG.cSpellRankInfo)
function SG.buildSpellRankInfo(spell)
local spellName, spellSubName, name, spellID;
local rank = 1;
SG.cSpellRankInfo = {}; -- always clear it
for i = 1, 300 do -- 300 is more than enough
spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL);
if spellName == spell then
name, _, _, _, _, _, spellID, _ = GetSpellInfo(spellName.."("..spellSubName..")");
tinsert(SG.cSpellRankInfo, {rank, spellName, spellSubName, spellName.."("..spellSubName..")", spellID});
rank = rank + 1;
end
end
end
-- SG.getSpellRankInfo
-- Looks up one rank entry from SG.cSpellRankInfo.
-- Parameters:
-- rank (number) Rank index (1-based)
-- Returns:
-- (number) Rank index
-- (string) Spell name
-- (string) Sub name (rank text)
-- (string) Full spell name with rank
-- (number) Spell ID
function SG.getSpellRankInfo(rank)
for rankcount, ranks in ipairs(SG.cSpellRankInfo) do
if ranks[1] == rank then
return ranks[1], ranks[2], ranks[3], ranks[4], ranks[5];
end
end
end
-- SMARTBUFF_CheckSpellLevel (local)
-- Picks the highest spell rank valid for the target unit level.
-- Parameters:
-- spell (string) Base spell name
-- unit (string) Target unit token
-- buffLevels (table) Minimum level per rank index
-- Returns:
-- (number|nil) Rank, spell name, sub name, full rank name, spell ID; nil if max level or no levels
local function SMARTBUFF_CheckSpellLevel(spell, unit, buffLevels)
if not buffLevels then return nil; end
local uLevel = nil;
local bSpellRank = 0;
local rank, spellName, spellSubName, spellNameRank, spellID;
uLevel = UnitLevel(unit);
if uLevel == 80 then return nil; end -- no reason to down-rank on a max level, just exit.
SG.buildSpellRankInfo(spell);
-- get rank (ipairs ensures correct order so we pick the highest valid rank)
for count, levelrange in ipairs(buffLevels) do
if uLevel >= levelrange then
bSpellRank = count;
end
end
rank, spellName, spellSubName, spellNameRank, spellID = SG.getSpellRankInfo(bSpellRank)
return rank, spellName, spellSubName, spellNameRank, spellID;
end
-- SMARTBUFF_Check
-- Main buff check: combat buffs, target, then party/raid units in order.
-- Parameters:
-- mode (number) 0 = manual, 1 = auto splash, 5 = scroll wheel
-- force (boolean) Force check past auto-timer
-- Returns:
-- (number) Result code from SMARTBUFF_BuffUnit (0/1/3) or nil
-- (string|nil) Action type (spell/item)
-- (string|nil) Spell or item name
-- (number|nil) Inventory slot
-- (string|nil) Unit token
-- (number|nil) Buff type constant
function SMARTBUFF_Check(mode, force)
if (SG.IsChecking or not SMARTBUFF_PreCheck(mode, force)) then return; end
SG.IsChecking = true;
SG.SMARTBUFF_ClearAuraCache();
SG.SMARTBUFF_EnsureBagIndex();
local ct = SG.currentTemplate;
local unit = nil;
local units = nil;
local unitsGrp = nil;
local unitB = nil;
local unitL = nil;
local unitU = nil;
local idL = nil;
local idU = nil;
local subgroup = 0;
local i;
local j;
local n;
local m;
local rc;
local rank;
local reagent;
local nGlobal = 0;
SMARTBUFF_checkBlacklist();
-- 1. check in combat buffs
if (InCombatLockdown()) then -- and SG.O.InCombat
for spell in pairs(SG.cBuffsCombat) do
if (spell) then
local ret, actionType, spellName, slot, unit, buffType = SMARTBUFF_BuffUnit("player", 0, mode, spell)
SMARTBUFF_AddMsgD("Check combat spell: " .. spell .. ", ret = " .. ret);
if (ret and ret == 0) then
SG.IsChecking = false;
return;
end
end
end
end
-- 2. buff target, if enabled
if ((mode == 0 or mode == 5) and SG.O.BuffTarget) then
local actionType, spellName, slot, buffType;
i, actionType, spellName, slot, _, buffType = SMARTBUFF_BuffUnit("target", 0, mode);
if (i <= 1) then
if (i == 0) then
--SG.tLastCheck = GetTime() - SG.O.AutoTimer + SG.GlobalCd;
end
SG.IsChecking = false;
return i, actionType, spellName, slot, "target", buffType;
end
end
-- 3. check groups
local cGrp = SG.cGroups;
local cOrd = SG.cOrderGrp;
SG.isMounted = IsMounted() or IsFlying();
for _, subgroup in pairs(cOrd) do
if (cGrp[subgroup] ~= nil or (type(subgroup) == "number" and subgroup == 1)) then
if (cGrp[subgroup] ~= nil) then
units = cGrp[subgroup];
else
units = nil;
end
if (SG.cUnits and type(subgroup) == "number" and subgroup == 1) then
unitsGrp = SG.cUnits[1];
else
unitsGrp = units;
end
-- check buffs
if (units) then
for _, unit in pairs(units) do
if (SG.isSetBuffs) then break; end
SMARTBUFF_AddMsgD("Checking single unit = "..unit);
local spellName, actionType, slot, buffType;
i, actionType, spellName, slot, _, buffType = SMARTBUFF_BuffUnit(unit, subgroup, mode);
if (i <= 1) then
if (i == 0 and mode ~= 1) then
--SG.tLastCheck = GetTime() - SG.O.AutoTimer + SG.GlobalCd;
if (actionType == SMARTBUFF_ACTION_ITEM) then
--SG.tLastCheck = SG.tLastCheck + 2;
end
end
SG.IsChecking = false;
return i, actionType, spellName, slot, unit, buffType;
end
end
end
end
end -- for groups
if (mode == 0) then
if (SG.sMsgWarning == "" or SG.sMsgWarning == " ") then
SMARTBUFF_AddMsg(SMARTBUFF_MSG_NOTHINGTODO);
else
SMARTBUFF_AddMsgWarn(SG.sMsgWarning);
SG.sMsgWarning = "";
end
end
SG.IsChecking = false;
end
-- SMARTBUFF_BuffUnit
-- Evaluates all enabled buffs in list order for one unit; casts or shows splash.
-- Parameters:
-- unit (string) Unit token
-- subgroup (number|string) Raid/party subgroup key for group timers
-- mode (number) 0 = cast, 1 = splash check, 5 = scroll wheel
-- spell (string|nil) Optional single-spell filter (combat buffs)
-- Returns:
-- (number) 0 = action/splash taken, 1 = cooldown, 3 = nothing to do
-- plus actionType, spellName, slot, unit, buffType when casting (mode 0/5)
function SMARTBUFF_BuffUnit(unit, subgroup, mode, spell)
local bs = nil;
local buff = nil;
local buffname = nil;
local buffnS = nil;
local uc = nil;
local ur = "NONE";
local un = nil;
local uct = nil;
local ucf = nil;
local r;
local i;
local bt = 0;
local cd = 0;
local cds = 0;
local charges = 0;
local handtype = "";
local bExpire = false;
local isPvP = false;
local bufftarget = nil;
local rbTime = 0;
local bUsable = false;
local time = GetTime();
local cBuff = nil;
local iId = nil;
local iSlot = -1;
local spellNameRank = nil
if (UnitIsPVP("player")) then isPvP = true end
SMARTBUFF_CheckUnitBuffTimers(unit);
SG.isPrompting = false;
if (UnitExists(unit) and UnitIsFriend("player", unit) and not UnitIsDeadOrGhost(unit) and not UnitIsCorpse(unit) and (UnitInRange(unit) or unit == "player" or (unit == "target" and (UnitIsPlayer("target") or UnitCreatureType("target")))))
and (UnitIsConnected(unit) or not UnitIsPlayer(unit)) and UnitIsVisible(unit) and not UnitOnTaxi(unit) and not SG.cBlacklist[unit] and ((not UnitIsPVP(unit) and (not isPvP or SG.O.BuffPvP)) or (UnitIsPVP(unit)
and (isPvP or SG.O.BuffPvP))) then
_, uc = UnitClass(unit);
un = UnitName(unit);
ur = UnitGroupRolesAssigned(unit);
uct = UnitCreatureType(unit);
ucf = UnitCreatureFamily(unit);
if (uct == nil) then uct = ""; end
if (ucf == nil) then ucf = ""; end
SG.isShapeshifted, SG.sShapename = SMARTBUFF_IsShapeshifted();
SG.BeginSkipSplashPass(unit);
for i, buffnS in ipairs(SG.B[SG.CS()].Order) do
if (SG.isSetBuffs or SmartBuffOptionsFrame:IsVisible()) then break; end
cBuff = SG.cBuffs[SG.cBuffIndex[buffnS]];
bs = SG.GetBuffSettings(buffnS);
bExpire = false;
handtype = "";
charges = -1;
bufftarget = nil;
bUsable = false;
iId = nil;
iSlot = -1;
if (cBuff and bs) then bUsable = bs.EnableS end
if (bUsable and spell and spell ~= buffnS) then
bUsable = false;
SMARTBUFF_AddMsgD("Exclusive check on " .. spell .. ", current spell = " .. buffnS);
end
if (bUsable and cBuff.Type == SMARTBUFF_CONST_SELF and not SMARTBUFF_IsPlayer(unit)) then bUsable = false end
local spellToCheck = buffnS;
if (bUsable and cBuff.LevelsS and unit) then
local _, _, _, spellNameRank = SMARTBUFF_CheckSpellLevel(buffnS, unit, cBuff.LevelsS);
if (spellNameRank) then spellToCheck = spellNameRank; end
end
if (bUsable and cBuff.Type ~= SMARTBUFF_CONST_TRACK and not SMARTBUFF_IsItem(cBuff.Type) and not IsUsableSpell(spellToCheck)) then bUsable = false end
if (bUsable and bs.SelfNot and SMARTBUFF_IsPlayer(unit)) then bUsable = false end
if (bUsable and cBuff.Params == SG.CheckFishingPole and SMARTBUFF_IsFishingPoleEquiped()) then bUsable = false end
-- Check for buffs which depends on a pet
if (bUsable and cBuff.Params == SG.CheckPet and UnitExists("pet")) then bUsable = false end
if (bUsable and cBuff.Params == SG.CheckPetNeeded and not UnitExists("pet")) then bUsable = false end
if SG.O.HideSAButtonNoAction and not SG.O.HideSAButton and not InCombatLockdown() then
SmartBuff_KeyButton:Show();
end
-- Check for mount auras (Classic/TBC: Paladin only)
if (bUsable and SG.sPlayerClass == "PALADIN") then
SG.isMounted = IsMounted() or IsFlying();
if ((buffnS ~= SMARTBUFF_CRUSADERAURA and SG.isMounted) or (buffnS == SMARTBUFF_CRUSADERAURA and not SG.isMounted)) then
bUsable = false;
end
end
-- check for mage conjured items (only for relevant conjure buffs)
if (bUsable and SG.sPlayerClass == "MAGE" and SG.SMARTBUFF_IsMageConjureBuff(buffnS)) then
local lookupData;
local gemItemID = SG.SMARTBUFF_GetMageGemItemID(buffnS);
if (buffnS == SMARTBUFF_CONJFOOD) then
lookupData = ConjuredMageFood;
elseif (buffnS == SMARTBUFF_CONJWATER) then
lookupData = ConjuredMageWater;
end
if (lookupData or gemItemID) then
if (SG.isPlayerMoving) then
bUsable = false;
elseif (lookupData and SG.SMARTBUFF_HasConjuredItemList(lookupData)) then
bUsable = false;
SG.ClearSkipSplashCount(buffnS);
elseif (gemItemID and SG.SMARTBUFF_HasBagItemID(gemItemID)) then
bUsable = false;
SG.ClearSkipSplashCount(buffnS);
end
end
end
-- check for warlock conjured items (only for relevant conjure buffs)
if (bUsable and SG.sPlayerClass == "WARLOCK" and SG.SMARTBUFF_IsWarlockConjureBuff(buffnS)) then
local lookupData;
if (not (SG.SMARTBUFF_HasBagItemID(6265) or SG.buildInfo >= SMARTBUFF_CLIENTHIGH)) then
SMARTBUFF_AddMsgD("Soul Shard is missing in bag, cannot continue.");
bUsable = false;
else
if (buffnS == SMARTBUFF_CREATEHS) then lookupData = ConjuredLockHealthStones
elseif (buffnS == SMARTBUFF_CREATESOULS) then lookupData = ConjuredLockSoulstones
elseif (buffnS == SMARTBUFF_CREATESPELLS) then lookupData = ConjuredLockSpellstones
elseif (buffnS == SMARTBUFF_CREATEFIRES) then lookupData = ConjuredLockFirestones end
if (lookupData) then
if (SG.isPlayerMoving) then
bUsable = false;
elseif (SG.SMARTBUFF_HasConjuredItemList(lookupData)) then
bUsable = false;
SG.ClearSkipSplashCount(buffnS);
end
end
if (bUsable and buffnS == SMARTBUFF_CREATEHS and UnitHealth("player") == UnitHealthMax("player")) then
bUsable = false;
end
end
end
-- extra testing for revive pet on hunters,
-- only allow if the pet is actually dead
if (bUsable and SG.sPlayerClass == "HUNTER") and buffnS == SMARTBUFF_REVIVEPET then
if not UnitIsDead("pet") then
SMARTBUFF_AddMsgD("Pet appears to be very much alive!");
bUsable = false;
else
SMARTBUFF_AddMsgD("Pet appears to be dead, revive available.");
end
end
if (bUsable and not (cBuff.Type == SMARTBUFF_CONST_TRACK or SMARTBUFF_IsItem(cBuff.Type))) then
-- check if you have enough mana/rage/energy to cast
local isUsable, notEnoughMana = IsUsableSpell(buffnS);
if (notEnoughMana) then
bUsable = false;
SMARTBUFF_AddMsgD("Buff " .. cBuff.BuffS .. ", not enough mana!");
elseif (mode ~= 1 and isUsable == nil and buffnS ~= SMARTBUFF_PWS) then
bUsable = false;
SMARTBUFF_AddMsgD("Buff " .. cBuff.BuffS .. " is not usable!");
end
end
if (bUsable and bs.EnableS and (cBuff.IDS ~= nil or SMARTBUFF_IsItem(cBuff.Type) or cBuff.Type == SMARTBUFF_CONST_TRACK)
and ((mode ~= 1 and ((SG.isCombat and bs.CIn) or (not SG.isCombat and bs.COut)))
or (mode == 1 and bs.Reminder and ((not SG.isCombat and bs.COut)
or (SG.isCombat and (bs.CIn or SG.O.ToggleAutoCombat)))))) then
-- do we want to have normal camera zoom when buffing?
if not SG.O.ScrollWheelZooming then SG.isPrompting = true; end
if (not bs.SelfOnly or (bs.SelfOnly and SMARTBUFF_IsPlayer(unit))) then
-- get current spell cooldown
cd = 0;
cds = 0;
if (cBuff.IDS) then
cds, cd = GetSpellCooldown(buffnS);
if cds then
cd = (cds + cd) - GetTime();
if (cd < 0) then
cd = 0;
end
SMARTBUFF_AddMsgD(buffnS.." cd = "..cd);
else
cd = 0;
end
end
-- check if spell has cooldown
if (cd <= 0 or (mode == 1 and cd <= 1.5)) then
if (cBuff.IDS and SG.sMsgWarning == SMARTBUFF_MSG_CD) then
SG.sMsgWarning = " ";
end
rbTime = bs.RBTime;
if (rbTime <= 0) then
rbTime = SG.O.RebuffTimer;
end
SMARTBUFF_AddMsgD(uc.." "..SG.CT());
if (not SMARTBUFF_IsInList(unit, un, bs.IgnoreList) and (((cBuff.Type == SMARTBUFF_CONST_GROUP or cBuff.Type == SMARTBUFF_CONST_ITEMGROUP)
and (bs[ur]
or (bs.SelfOnly and SMARTBUFF_IsPlayer(unit))
or (bs[uc] and (UnitIsPlayer(unit) or uct == SMARTBUFF_HUMANOID or (uc == "DRUID" and (uct == SMARTBUFF_BEAST or uct == SMARTBUFF_ELEMENTAL))))
or (bs["HPET"] and uct == SMARTBUFF_BEAST and uc ~= "DRUID")
or (bs["WPET"] and (uct == SMARTBUFF_DEMON or (uc ~= "DRUID" and uct == SMARTBUFF_ELEMENTAL)) and ucf ~= SMARTBUFF_DEMONTYPE)))
or (cBuff.Type ~= SMARTBUFF_CONST_GROUP and SMARTBUFF_IsPlayer(unit))
or SMARTBUFF_IsInList(unit, un, bs.AddList))) then
buff = nil;
-- Gathering ability ------------------------------------------------------------------------
if (cBuff.Type == SMARTBUFF_CONST_GATHERING) then
local b = false;
for key, spellId in ipairs(SBClassicGatherers) do
spellName = GetSpellInfo(spellId)
if spellName ~= nil and spellName ~= SG.tracker then
if IsPlayerSpell(spellId) and spellName == buffnS then
CastSpellByName(spellName)
SG.tracker = spellName
SMARTBUFF_AddMsgD(spellName.." applied.");
end
else
SG.isPrompting = false
end
end
-- Tracking ability ------------------------------------------------------------------------
elseif (cBuff.Type == SMARTBUFF_CONST_TRACK) then
local count = C_Minimap.GetNumTrackingTypes();
for n = 1, C_Minimap.GetNumTrackingTypes() do
local trackN, trackT, trackA, trackC = C_Minimap.GetTrackingInfo(n);
if (trackN ~= nil and not trackA) then
SMARTBUFF_AddMsgD(n..". "..trackN.." ("..trackC..")");
if (trackN == buffnS) then
if (SG.sPlayerClass == "DRUID" and buffnS == SMARTBUFF_DRUID_TRACK) then
if (SG.isShapeshifted and SG.sShapename == SMARTBUFF_DRUID_CAT) then
buff = buffnS;
C_Minimap.SetTracking(n, 1); -- bugfix: not referencing C_Minimap. 7/5/2023
end
else
buff = buffnS;
C_Minimap.SetTracking(n, 1);
end
if (buff ~= nil) then
SMARTBUFF_AddMsgD("Tracking enabled: "..buff);
buff = nil;
end
end
end
end
-- Food, Scroll, Potion or conjured items ------------------------------------------------------------------------
elseif (cBuff.Type == SMARTBUFF_CONST_FOOD or cBuff.Type == SMARTBUFF_CONST_SCROLL or cBuff.Type == SMARTBUFF_CONST_POTION or cBuff.Type == SMARTBUFF_CONST_ITEM or
cBuff.Type == SMARTBUFF_CONST_ITEMGROUP) then
if (cBuff.Type == SMARTBUFF_CONST_ITEM) then
bt = nil;
buff = nil;
if (cBuff.Params ~= SG.NIL) then
local cr = SMARTBUFF_CountReagent(cBuff.Params, cBuff.Chain);
SMARTBUFF_AddMsgD(cr.." "..cBuff.Params.." found");
if (cr == 0) then