-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
1917 lines (1751 loc) · 61.1 KB
/
Copy pathCore.lua
File metadata and controls
1917 lines (1751 loc) · 61.1 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
-- Originally created by Aeldra (EU-Proudmoore)
-- Classic & Retail versions by Codermik, additional coding by MrWizard & Speedwaystar
--
-- Join Discord: https://discord.gg/R6EkZ94TKK
-- Cast the most important buffs on you, tanks or party/raid members/pets.
--
-- SmartBuff Core
--
-------------------------------------------------------------------------------
local SG = SMARTBUFF_GLOBALS;
SMARTBUFF_DATE = "120626";
SMARTBUFF_VERSION = "r69."..SMARTBUFF_DATE;
SMARTBUFF_VERSIONNR = SMARTBUFF_CLIENTHIGH;
SMARTBUFF_TITLE = "SmartBuff";
SMARTBUFF_SUBTITLE = "Supports you in casting buffs";
SMARTBUFF_DESC = "Cast the most important buffs on you, your tanks, party/raid members/pets";
SMARTBUFF_VERS_TITLE = SMARTBUFF_TITLE .. " " .. SMARTBUFF_VERSION;
SMARTBUFF_OPTIONS_TITLE = SMARTBUFF_VERS_TITLE.." Classic ";
-- SG.RebuildTemplateList
-- Assembles SMARTBUFF_TEMPLATES from generics + instances + custom (localization sets the three parts).
-- Order matters: generics first, then instances, then custom. Matches Enum.SmartBuffGroup.
-- Returns: nothing
function SG.RebuildTemplateList()
SMARTBUFF_TEMPLATES = {};
for _, src in ipairs({SMARTBUFF_TEMPLATES_GENERICS, SMARTBUFF_TEMPLATES_INSTANCES, SMARTBUFF_TEMPLATES_CUSTOM}) do
if (src) then
for _, v in ipairs(src) do table.insert(SMARTBUFF_TEMPLATES, v); end
end
end
end
SG.RebuildTemplateList();
-- addon name
SG.addonName = SG.addonName or ...
-- Shared addon state (Check/Cast/Options modules use SMARTBUFF_GLOBALS)
if (not SG._coreReady) then
SG._coreReady = true;
SG.SmartbuffPrefix = SG.SmartbuffPrefix or "SBC1.0";
SG.SmartbuffHeader = SG.SmartbuffHeader or "Smartbuff";
SG.SmartbuffSession = SG.SmartbuffSession or true;
SG.SmartbuffVerCheck = SG.SmartbuffVerCheck or false;
SG.SmartbuffRevision = SG.SmartbuffRevision or 68;
SG.SmartbuffVerNotifyList = SG.SmartbuffVerNotifyList or {};
SG.GlobalCd = SG.GlobalCd or 1.5;
SG.maxSkipCoolDown = SG.maxSkipCoolDown or 3;
SG.maxRaid = SG.maxRaid or 40;
SG.maxBuffs = SG.maxBuffs or 40;
SG.maxScrollButtons = SG.maxScrollButtons or 30;
SG.numBuffs = SG.numBuffs or 0;
SG.tStartZone = SG.tStartZone or 0;
SG.tTicker = SG.tTicker or 0;
SG.tSync = SG.tSync or 0;
SG.tLastCheck = SG.tLastCheck or 0;
SG.iLastBuffSetup = SG.iLastBuffSetup or -1;
SG.iLastGroupSetup = SG.iLastGroupSetup or -99;
SG.tAutoBuff = SG.tAutoBuff or 0;
SG.tDebuff = SG.tDebuff or 0;
SG.iCurrentFont = SG.iCurrentFont or 6;
SG.iCurrentList = SG.iCurrentList or -1;
SG.iLastPlayer = SG.iLastPlayer or -1;
SG.cGroups = SG.cGroups or {};
SG.cClassGroups = SG.cClassGroups or {};
SG.cBuffs = SG.cBuffs or {};
SG.cBuffIndex = SG.cBuffIndex or {};
SG.cBuffTimer = SG.cBuffTimer or {};
SG.cBlacklist = SG.cBlacklist or {};
SG.cUnits = SG.cUnits or {};
SG.cBuffsCombat = SG.cBuffsCombat or {};
SG.cSpellRankInfo = SG.cSpellRankInfo or {};
SG.cAddUnitList = SG.cAddUnitList or {};
SG.cIgnoreUnitList = SG.cIgnoreUnitList or {};
SG.cPlayerTrackers = SG.cPlayerTrackers or {};
SG.cAuraCache = SG.cAuraCache or {};
SG.cBagIndexByID = SG.cBagIndexByID or {};
SG.cBagIndexByName = SG.cBagIndexByName or {};
SG.cBagIndexDirty = true;
SG.cIgnoreClasses = SG.cIgnoreClasses or {};
SG.imgSB = SG.imgSB or "Interface\\Icons\\inv_gizmo_goblinboombox_01";
SG.imgIconOn = SG.imgIconOn or "Interface\\AddOns\\SmartBuff\\Icons\\MiniMapButtonEnabled";
SG.imgIconOff = SG.imgIconOff or "Interface\\AddOns\\SmartBuff\\Icons\\MiniMapButtonDisabled";
SG.tracker = SG.tracker or "";
SG.soundPath = SG.soundPath or "Interface\\AddOns\\SmartBuff\\Sounds\\";
SG.DebugChatFrame = SG.DebugChatFrame or DEFAULT_CHAT_FRAME;
SG.SmartbuffCommands = SG.SmartbuffCommands or { "SBCVER", "SBCCMD", "SBCSYC" };
SG.cOrderGrp = SG.cOrderGrp or {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
SG.cFonts = SG.cFonts or {"NumberFontNormal", "NumberFontNormalLarge", "NumberFontNormalHuge", "GameFontNormal", "GameFontNormalLarge", "GameFontNormalHuge", "ChatFontNormal", "QuestFont", "MailTextFontNormal", "QuestTitleFont"};
SG.buildInfo = SG.buildInfo or select(4, GetBuildInfo());
SG.cClasses = SG.cClasses or {"DRUID", "HUNTER", "MAGE", "PALADIN", "PRIEST", "ROGUE", "SHAMAN", "WARLOCK", "WARRIOR", "HPET", "WPET", "TANK", "HEALER", "DAMAGER"};
end
BINDING_HEADER_SMARTBUFF = "SmartBuff";
-- Prevent the header from showing as a bindable "HEADER_SMARTBUFF" under Other (leave unbound)
BINDING_NAME_HEADER_SMARTBUFF = "";
SMARTBUFF_BOOK_TYPE_SPELL = "spell";
local BOOKTYPE_SPELL = SMARTBUFF_BOOK_TYPE_SPELL;
SG.isPrompting = false
SG.IconPaths = {
["Pet"] = "Interface\\Icons\\spell_nature_spiritwolf",
["Roles"] = "Interface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES",
["Classes"] = "Interface\\WorldStateFrame\\Icons-Classes",
};
SG.Icons = {
["WARRIOR"] = { SG.IconPaths.Classes, 0.00, 0.25, 0.00, 0.25 },
["MAGE"] = { SG.IconPaths.Classes, 0.25, 0.50, 0.00, 0.25 },
["ROGUE"] = { SG.IconPaths.Classes, 0.50, 0.75, 0.00, 0.25 },
["DRUID"] = { SG.IconPaths.Classes, 0.75, 1.00, 0.00, 0.25 },
["HUNTER"] = { SG.IconPaths.Classes, 0.00, 0.25, 0.25, 0.50 },
["SHAMAN"] = { SG.IconPaths.Classes, 0.25, 0.50, 0.25, 0.50 },
["PRIEST"] = { SG.IconPaths.Classes, 0.50, 0.75, 0.25, 0.50 },
["WARLOCK"] = { SG.IconPaths.Classes, 0.75, 1.00, 0.25, 0.50 },
["PALADIN"] = { SG.IconPaths.Classes, 0.00, 0.25, 0.50, 0.75 },
["PET"] = { SG.IconPaths.Pet, 0.08, 0.92, 0.08, 0.92},
["HPET"] = { SG.IconPaths.Pet, 0.08, 0.92, 0.08, 0.92},
["WPET"] = { SG.IconPaths.Pet, 0.08, 0.92, 0.08, 0.92},
["TANK"] = { SG.IconPaths.Roles, 0.0, 19/64, 22/64, 41/64 },
["HEALER"] = { SG.IconPaths.Roles, 20/64, 39/64, 1/64, 20/64 },
["DAMAGER"] = { SG.IconPaths.Roles, 20/64, 39/64, 22/64, 41/64 },
["NONE"] = { SG.IconPaths.Roles, 20/64, 39/64, 22/64, 41/64 },
};
SG.tracker = ""
-- available sounds (39)
SG.Sounds = {
"igPlayerBind.ogg",
"Aggro_Enter_Warning_State.ogg",
"Aggro_Pulled_Aggro.ogg",
"LFG_DungeonReady.ogg",
"LFG_Rewards.ogg",
"FX_SONIC_SPHEREPULSE_01.ogg",
"EyeOfKilroggDeath.ogg",
"GM_ChatWarning.ogg",
"Bloodlust_player_cast_head.ogg",
"collectfruit.ogg",
"collectgold.ogg",
"collectspud.ogg",
"collectwings.ogg",
"EnlargeCast.ogg",
"exitlevelunlocked.ogg",
"GO_7LF_Lightforged_Barrier_Death.ogg",
"RTC_80_ARD_Anvil_Strike.ogg",
"RTC_80_KAG_TransitionFX_In.ogg",
"SPELL_MK_BREW_DRINK01.ogg",
"SPELL_ShadowStrike_Cast.ogg",
"witchflyaway.ogg",
"gruntling_horn_bb.ogg",
"WispPissed3.ogg",
"FluteRun.ogg",
"GnomeFemaleMainJump.ogg",
"ShaysBell.ogg",
"UR_Kologarn_Slay02.ogg",
"UI_PetBattle_Victory02.ogg",
"PVPWarning.ogg",
"PVPFlagTakenHordeMono.ogg",
"YouAreWeak.ogg",
"PeasantPissed5.ogg",
"HumanFemaleSigh01.ogg",
"HumanMaleSigh01.ogg",
"GnomeMaleLaugh01.ogg",
"Emote_Whistle_01.ogg",
"VO_701_IMage_OF_Millhouse_Manastorm_05.ogg",
"VO_703_Millhouse_Manastorm_29_M.ogg",
"VO_901_Millificent_Manastorm_193617.ogg",
};
SG.LSM = LibStub:GetLibrary("LibSharedMedia-3.0", true);
SG.SoundList = SG.SoundList or {};
-- Sound list helpers (LibSharedMedia + bundled ogg files)
-- SG_SoundKeyFromFile (local)
-- Builds a LibSharedMedia sound key from a bundled filename.
-- Parameters:
-- file (string) Sound filename (e.g. "LFG_DungeonReady.ogg")
-- Returns:
-- (string) LSM key prefixed with "SmartBuff: "
local function SG_SoundKeyFromFile(file)
return "SmartBuff: " .. (file:gsub("%.ogg$", ""):gsub("%.mp3$", ""));
end
-- SG.RebuildSoundList
-- Refreshes SG.SoundList from LSM or falls back to bundled sound keys.
-- Parameters: none
-- Returns: nothing
function SG.RebuildSoundList()
if (SG.LSM) then
SG.SoundList = SG.LSM:List("sound") or {};
local filtered = {};
for _, key in ipairs(SG.SoundList) do
if (key ~= "None") then
filtered[#filtered + 1] = key;
end
end
SG.SoundList = filtered;
else
SG.SoundList = {};
for i, file in ipairs(SG.Sounds) do
SG.SoundList[i] = SG_SoundKeyFromFile(file);
end
end
end
-- SG.InitSharedMediaSounds
-- Registers bundled sounds with LibSharedMedia and hooks list refresh callbacks.
-- Parameters: none
-- Returns: nothing
function SG.InitSharedMediaSounds()
if (SG._lsmSoundsReady) then
SG.RebuildSoundList();
return;
end
SG._lsmSoundsReady = true;
if (SG.LSM) then
for _, file in ipairs(SG.Sounds) do
local key = SG_SoundKeyFromFile(file);
if (not SG.LSM:IsValid("sound", key)) then
SG.LSM:Register(SG.LSM.MediaType.SOUND, key, SG.soundPath .. file);
end
end
SG.LSM.RegisterCallback(SG, "LibSharedMedia_Registered", function(_, mediatype)
if (mediatype == "sound") then
SG.RebuildSoundList();
if (SmartBuffOptionsFrame_ddSounds and SmartBuffOptionsFrame and SmartBuffOptionsFrame:IsVisible()) then
SMARTBUFF_UpdateSoundDropdown();
end
end
end);
end
SG.RebuildSoundList();
end
-- SG.GetSoundDisplayName
-- Returns the display label for a sound list index.
-- Parameters:
-- index (number) Index into SG.SoundList
-- Returns:
-- (string) Sound key or fallback string
function SG.GetSoundDisplayName(index)
if (SG.SoundList and SG.SoundList[index]) then
return SG.SoundList[index];
end
return tostring(index or "?");
end
-- SG.ResolveSoundIndex
-- Resolves the active splash sound index from saved key, legacy index, or default.
-- Parameters: none
-- Returns:
-- (number) Index into SG.SoundList
function SG.ResolveSoundIndex()
SG.RebuildSoundList();
local list = SG.SoundList;
local count = list and #list or 0;
if (count == 0) then
return (SG.O and SG.O.AutoSoundSelection) or 1;
end
if (SG.O and SG.O.AutoSoundKey) then
for i, key in ipairs(list) do
if (key == SG.O.AutoSoundKey) then
return i;
end
end
end
local legacyIdx = SG.O and SG.O.AutoSoundSelection;
if (type(legacyIdx) == "number" and SG.Sounds[legacyIdx]) then
local legacyFile = SG.Sounds[legacyIdx]:lower();
if (SG.LSM) then
for i, key in ipairs(list) do
local path = SG.LSM:Fetch("sound", key);
if (type(path) == "string" and path:lower():find(legacyFile, 1, true)) then
return i;
end
end
end
if (legacyIdx >= 1 and legacyIdx <= count) then
return legacyIdx;
end
end
for i, key in ipairs(list) do
if (key:find("LFG_DungeonReady", 1, true)) then
return i;
end
end
return 1;
end
-- SG.SetSoundSelection
-- Saves splash sound choice by list index and LSM key.
-- Parameters:
-- index (number) Sound list index (clamped to valid range)
-- Returns: nothing
function SG.SetSoundSelection(index)
if (not SG.O) then return; end
SG.RebuildSoundList();
local count = SG.SoundList and #SG.SoundList or 0;
if (count < 1) then return; end
if (index < 1) then index = 1; end
if (index > count) then index = count; end
SG.O.AutoSoundSelection = index;
SG.O.AutoSoundKey = SG.SoundList[index];
end
-- SG.PlaySplashSoundMedia
-- Plays a sound by file path or numeric sound kit ID.
-- Parameters:
-- media (string|number) File path or PlaySound kit ID
-- Returns: nothing
function SG.PlaySplashSoundMedia(media)
if (not media) then return; end
if (type(media) == "number") then
PlaySound(media);
else
PlaySoundFile(media);
end
end
-- SG.PlaySplashSound
-- Plays the configured splash reminder sound.
-- Parameters: none
-- Returns: nothing
function SG.PlaySplashSound()
if (not SG.O) then return; end
local idx = SG.ResolveSoundIndex();
local key = SG.SoundList and SG.SoundList[idx];
if (key and SG.LSM) then
SG.PlaySplashSoundMedia(SG.LSM:Fetch("sound", key));
return;
end
if (SG.Sounds and SG.O.AutoSoundSelection and SG.Sounds[SG.O.AutoSoundSelection]) then
PlaySoundFile(SG.soundPath .. SG.Sounds[SG.O.AutoSoundSelection]);
end
end
-- Skip-over-buffing splash helpers
-- SG.GetSkipSplashDelay
-- Returns splash duration used between skip-over-buff transitions.
-- Parameters: none
-- Returns:
-- (number) Seconds (SplashDuration option, default 2)
function SG.GetSkipSplashDelay()
local d = SG.O and SG.O.SplashDuration;
if (not d or d <= 0) then return 2; end
return d;
end
-- SG.ShouldSkipBuff
-- Returns true when a buff has reached its skip-over reminder limit.
-- Parameters:
-- buffnS (string) Buff short name
-- Returns:
-- (boolean)
function SG.ShouldSkipBuff(buffnS)
if (not SG.O or not SG.O.SkipOverBuffing or not buffnS) then return false; end
local limit = SG.O.SkipSplashLimit;
if (not limit or limit <= 0) then return false; end
if (not SG.O.SkipSplashCounts) then return false; end
return (SG.O.SkipSplashCounts[buffnS] or 0) >= limit;
end
-- SG.RequestSkipSplashRecheck
-- Schedules the next auto check after splash duration (skip transition).
-- Parameters: none
-- Returns: nothing
function SG.RequestSkipSplashRecheck()
SG.tSkipSplashRecheck = GetTime() + SG.GetSkipSplashDelay();
end
-- SG.ResetSkipSplashCycle
-- Clears all per-buff skip-over splash counters.
-- Parameters: none
-- Returns: nothing
function SG.ResetSkipSplashCycle()
if (SG.O and SG.O.SkipSplashCounts) then
wipe(SG.O.SkipSplashCounts);
end
end
-- SG.IncrementSkipSplashCount
-- Increments splash reminder count for a buff; schedules transition at limit.
-- Parameters:
-- buffnS (string) Buff short name
-- Returns: nothing
function SG.IncrementSkipSplashCount(buffnS)
if (not SG.O or not buffnS) then return; end
if (not SG.O.SkipSplashCounts) then SG.O.SkipSplashCounts = { }; end
SG.O.SkipSplashCounts[buffnS] = (SG.O.SkipSplashCounts[buffnS] or 0) + 1;
SG.NoteSkipSplashAction();
local limit = SG.O.SkipSplashLimit or 3;
if (SG.O.SkipOverBuffing and SG.O.SkipSplashCounts[buffnS] >= limit) then
SG.RequestSkipSplashRecheck();
end
end
-- SG.ClearSkipSplashCount
-- Clears skip-over counter when a buff is applied or no longer missing.
-- Parameters:
-- buffnS (string) Buff short name
-- Returns: nothing
function SG.ClearSkipSplashCount(buffnS)
if (not SG.O or not SG.O.SkipSplashCounts or not buffnS) then return; end
SG.O.SkipSplashCounts[buffnS] = nil;
end
-- SG.BeginSkipSplashPass
-- Starts tracking a skip-over pass for player unit checks.
-- Parameters:
-- unit (string) Unit token being checked
-- Returns: nothing
function SG.BeginSkipSplashPass(unit)
if (unit == "player" and SG.O and SG.O.SkipOverBuffing) then
SG.skipSplashPass = { hadSkippedMissing = false, hadAction = false };
else
SG.skipSplashPass = nil;
end
end
-- SG.NoteSkipSplashSkipped
-- Marks that a buff was skipped during the current skip-over pass.
-- Parameters: none
-- Returns: nothing
function SG.NoteSkipSplashSkipped()
if (SG.skipSplashPass) then
SG.skipSplashPass.hadSkippedMissing = true;
end
end
-- SG.NoteSkipSplashAction
-- Marks that a splash or cast action occurred during the skip-over pass.
-- Parameters: none
-- Returns: nothing
function SG.NoteSkipSplashAction()
if (SG.skipSplashPass) then
SG.skipSplashPass.hadAction = true;
end
end
-- SG.CancelSkipSplashPass
-- Cancels skip-over pass tracking (e.g. after showing a splash).
-- Parameters: none
-- Returns: nothing
function SG.CancelSkipSplashPass()
SG.skipSplashPass = nil;
end
-- SG.FinishSkipSplashPass
-- Ends a skip-over pass; resets cycle when only skips occurred with no action.
-- Parameters: none
-- Returns: nothing
function SG.FinishSkipSplashPass()
local pass = SG.skipSplashPass;
SG.skipSplashPass = nil;
if (not pass or not SG.O or not SG.O.SkipOverBuffing) then return; end
if (pass.hadAction) then return; end
if (not pass.hadSkippedMissing) then return; end
SG.ResetSkipSplashCycle();
SG.RequestSkipSplashRecheck();
end
-- upvalues
local UnitCastingInfo = _G.UnitCastingInfo or _G.CastingInfo
local UnitChannelInfo = _G.UnitChannelInfo or _G.ChannelInfo
local GetNumSpecGroups = _G.GetNumTalentGroups or function(...) return 1 end
local GetActiveTalentGroup = _G.GetActiveTalentGroup or function() return 1 end
local IsActiveBattlefieldArena = _G.IsActiveBattlefieldArena or function(...) return false end
local HasLFGRestrictions = _G.HasLFGRestrictions or function() return false end
local LE_PARTY_CATEGORY_INSTANCE = _G.LE_PARTY_CATEGORY_INSTANCE
local CancelUnitBuff = _G.CancelUnitBuff
-- CancelPlayerBuffByName (local)
-- Cancels a helpful buff on the player by matching localized name (hunter anti-daze).
-- Parameters:
-- buffName (string) Localized buff name from GetSpellInfo
-- Returns:
-- (boolean) True when a matching buff was cancelled
local function CancelPlayerBuffByName(buffName)
if (not buffName or not CancelUnitBuff) then
return false;
end
for i = 1, 40 do
local name = UnitBuff("player", i);
if (not name) then
break;
end
if (name == buffName) then
CancelUnitBuff("player", i);
return true;
end
end
return false;
end
-- Popup to reset everything
StaticPopupDialogs["SMARTBUFF_DATA_PURGE"] = {
text = SMARTBUFF_OFT_PURGE_DATA,
button1 = SMARTBUFF_OFT_YES,
button2 = SMARTBUFF_OFT_NO,
OnAccept = function() SMARTBUFF_ResetAll() end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1
}
-- Popup to reloadui
StaticPopupDialogs["SMARTBUFF_GUI_RELOAD"] = {
text = SMARTBUFF_OFT_REQ_RELOAD,
button1 = SMARTBUFF_OFT_OKAY,
OnAccept = function() ReloadUI() end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1
}
-- Utility helpers
-- SG.Round
-- Rounds a number to the given decimal places.
-- Parameters:
-- num (number) Value to round
-- idp (number) Decimal places (default 0)
-- Returns:
-- (number) Rounded value
function SG.Round(num, idp)
SG.r_mult = 10^(idp or 0);
return math.floor(num * SG.r_mult + 0.5) / SG.r_mult;
end
-- SG.BCC
-- Builds a WoW chat color code from normalized RGB values.
-- Parameters:
-- r, g, b (number) Color components 0–1
-- Returns:
-- (string) "|cffRRGGBB" color prefix
function SG.BCC(r, g, b)
return string.format("|cff%02x%02x%02x", (r*255), (g*255), (b*255));
end
SG.BL = SG.BCC(0, 0, 1);
SG.BLD = SG.BCC(0, 0, 0.7);
SG.BLL = SG.BCC(0.5, 0.8, 1);
SG.GR = SG.BCC(0, 1, 0);
SG.GRD = SG.BCC(0, 0.7, 0);
SG.GRL = SG.BCC(0.6, 1, 0.6);
SG.RD = SG.BCC(1, 0, 0);
SG.RDD = SG.BCC(0.7, 0, 0);
SG.RDL = SG.BCC(1, 0.3, 0.3);
SG.YL = SG.BCC(1, 1, 0);
SG.YLD = SG.BCC(0.7, 0.7, 0);
SG.YLL = SG.BCC(1, 1, 0.5);
SG.OR = SG.BCC(1, 0.7, 0);
SG.ORD = SG.BCC(0.7, 0.5, 0);
SG.ORL = SG.BCC(1, 0.6, 0.3);
SG.WH = SG.BCC(1, 1, 1);
SG.CY = SG.BCC(0.5, 1, 1);
-- SG.treorder
-- Moves an element within an array table by offset n positions.
-- Parameters:
-- t (table) Array table
-- i (number) Source index
-- n (number) Offset (+/- positions)
-- Returns: nothing
function SG.treorder(t, i, n)
if (t and type(t) == "table" and t[i]) then
local s = t[i];
tremove(t, i);
if (i + n < 1) then
tinsert(t, 1, s);
elseif (i + n > #t) then
tinsert(t, s);
else
tinsert(t, i + n, s);
end
end
end
-- SG.tfind
-- Finds a value in a table and returns its key/index.
-- Parameters:
-- t (table) Table to search
-- s (any) Value to find
-- Returns:
-- (any|false) Key/index when found, else false
function SG.tfind(t, s)
if (t and type(t) == "table" and s) then
for k, v in pairs(t) do
if (v and v == s) then
return k;
end
end
end
return false;
end
-- SG.tcontains
-- Returns true if array table t contains value s.
-- Parameters:
-- t (table) Array table
-- s (any) Value to find
-- Returns:
-- (boolean)
function SG.tcontains(t, s)
if (t and type(t) == "table" and s) then
for _, v in ipairs(t) do
if (v == s) then
return true;
end
end
end
return false;
end
-- SG.ChkS
-- Returns text or empty string when nil (safe string for debug output).
-- Parameters:
-- text (string|nil)
-- Returns:
-- (string)
function SG.ChkS(text)
if (text == nil) then
text = "";
end
return text;
end
-- SG.IsVisibleToPlayer
-- Returns true when a frame is fully visible on screen.
-- Parameters:
-- self (Frame) Frame to test
-- Returns:
-- (boolean)
function SG.IsVisibleToPlayer(self)
if (not self) then return false; end
local w, h = UIParent:GetWidth(), UIParent:GetHeight();
local x, y = self:GetLeft(), UIParent:GetHeight() - self:GetTop();
if (x >= 0 and x < (w - self:GetWidth()) and y >= 0 and y < (h - self:GetHeight())) then
return true;
end
return false;
end
-- SG.CS
-- Returns current talent spec/group index (cached in SG.currentSpec).
-- Parameters: none
-- Returns:
-- (number) Spec index (default 1)
function SG.CS()
if (SG.currentSpec == nil) then
SG.currentSpec = GetActiveTalentGroup()
end
if (SG.currentSpec == nil) then
SG.currentSpec = 1;
end
return SG.currentSpec;
end
-- SG.CT
-- Returns current buff template name (cached in SG.currentTemplate).
-- Parameters: none
-- Returns:
-- (string) Template name from SMARTBUFF_TEMPLATES
function SG.CT()
if (SG.currentTemplate ~= nil) then
return SG.currentTemplate;
end
if (SG.O and SG.O.LastTemplate and SMARTBUFF_TEMPLATES) then
for _, tname in ipairs(SMARTBUFF_TEMPLATES) do
if (tname == SG.O.LastTemplate) then
SG.currentTemplate = SG.O.LastTemplate;
return SG.currentTemplate;
end
end
end
if (SMARTBUFF_TEMPLATES and SMARTBUFF_TEMPLATES[1]) then
SG.currentTemplate = SMARTBUFF_TEMPLATES[1];
return SG.currentTemplate;
end
SG.currentTemplate = SG.smartBuffTemplateForGroupKey("Solo");
return SG.currentTemplate;
end
-- SG.smartBuffTemplateForGroupKey
-- Maps Enum.SmartBuffGroup key to template name.
-- Parameters:
-- key (string) e.g. "Solo", "Party", "Raid"
-- Returns:
-- (string|nil) Template name
function SG.smartBuffTemplateForGroupKey(key)
if (not SMARTBUFF_TEMPLATES or not Enum or not Enum.SmartBuffGroup or not key) then
return nil;
end
local idx = Enum.SmartBuffGroup[key];
if (not idx) then
return nil;
end
return SMARTBUFF_TEMPLATES[idx];
end
-- SG.IsLFGGroup
-- True when the player is in a dungeon-finder (LFG) party.
-- Returns:
-- (boolean)
function SG.IsLFGGroup()
if (HasLFGRestrictions()) then
return true;
end
if (LE_PARTY_CATEGORY_INSTANCE and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) then
return true;
end
return false;
end
-- SG.buffsTemplateTable
-- Returns saved buff settings table for a template on current spec.
-- Parameters:
-- templateName (string|nil) Template name; defaults to SG.CT()
-- Returns:
-- (table|nil) Per-buff settings for the template
function SG.buffsTemplateTable(templateName)
if (not SG.B) then return nil; end
local spec = SG.B[SG.CS()];
if (not spec) then return nil; end
templateName = templateName or SG.CT();
if (not templateName) then return nil; end
return spec[templateName];
end
-- templateHasEnabledBuffs (local)
-- Returns true if any buff in the template has EnableS or EnableG set.
-- Parameters:
-- templateName (string) Template name
-- Returns:
-- (boolean)
local function templateHasEnabledBuffs(templateName)
local t = SG.buffsTemplateTable(templateName);
if (not t or type(t) ~= "table") then return false; end
for k, v in pairs(t) do
if (type(v) == "table" and (v.EnableS or v.EnableG)) then return true; end
end
return false;
end
-- SG.maybeCopyTemplateOnFirstSwitch
-- Copies buff settings from one template to another on first auto-switch (RetainTemplate).
-- Parameters:
-- fromT (string) Source template name
-- toT (string) Destination template name
-- Returns: nothing
function SG.maybeCopyTemplateOnFirstSwitch(fromT, toT)
if (not SG.buffsTemplateTable(fromT)) then return; end
if (not SG.O or not SG.O.RetainTemplate) then return; end
if (not templateHasEnabledBuffs(fromT)) then return; end
if (SG.buffsTemplateTable(toT) and templateHasEnabledBuffs(toT)) then return; end
local src = SG.buffsTemplateTable(fromT);
local spec = SG.B[SG.CS()];
if (not spec) then return; end
spec[toT] = spec[toT] or {};
local dst = spec[toT];
for k, v in pairs(src) do
if (type(v) == "table") then
dst[k] = {};
for k2, v2 in pairs(v) do
if (type(v2) == "table") then
local copy = {};
for a, b in pairs(v2) do copy[a] = b; end
dst[k][k2] = copy;
else
dst[k][k2] = v2;
end
end
else
dst[k] = v;
end
end
end
-- SG.GetBuffSettings
-- Returns per-buff settings for current spec and template.
-- Parameters:
-- buff (string) Buff short name
-- Returns:
-- (table|nil) Buff settings table
function SG.GetBuffSettings(buff)
if (SG.B and buff) then
return SG.B[SG.CS()][SG.CT()][buff];
end
return nil;
end
-- SG.InitBuffSettings
-- Creates or upgrades per-buff settings defaults for the current template.
-- Parameters:
-- cBI (table) Buff definition entry from SG.cBuffs
-- reset (boolean) When true, wipes and reinitializes settings
-- Returns: nothing
function SG.InitBuffSettings(cBI, reset)
local buff = cBI.BuffS;
local cBuff = SG.GetBuffSettings(buff);
if (cBuff == nil) then
SG.B[SG.CS()][SG.CT()][buff] = { };
cBuff = SG.B[SG.CS()][SG.CT()][buff];
reset = true;
end
if (reset) then
wipe(cBuff);
cBuff.EnableS = false;
cBuff.EnableG = false;
cBuff.SelfOnly = false;
cBuff.SelfNot = false;
cBuff.CIn = false;
cBuff.COut = true;
cBuff.MH = true; -- default to checked
cBuff.OH = false;
cBuff.RH = false;
cBuff.Reminder = true;
cBuff.RBTime = 0;
cBuff.ManaLimit = 0;
if (cBI.Type == SMARTBUFF_CONST_GROUP or cBI.Type == SMARTBUFF_CONST_ITEMGROUP) then
for n in pairs(SG.cClasses) do
if (cBI.Type == SMARTBUFF_CONST_GROUP and not SG.tcontains(SG.cIgnoreClasses, n) and not string.find(cBI.Params, SG.cClasses[n])) then
cBuff[SG.cClasses[n]] = true;
else
cBuff[SG.cClasses[n]] = false;
end
end
end
end
-- Upgrades
if (cBuff.RBTime == nil) then cBuff.Reminder = true; cBuff.RBTime = 0; end -- to 1.10g
if (cBuff.ManaLimit == nil) then cBuff.ManaLimit = 0; end -- to 1.12b
if (cBuff.SelfNot == nil) then cBuff.SelfNot = false; end -- to 2.0i
if (cBuff.AddList == nil) then cBuff.AddList = { }; end -- to 2.1a
if (cBuff.IgnoreList == nil) then cBuff.IgnoreList = { }; end -- to 2.1a
if (cBuff.RH == nil) then cBuff.RH = false; end -- to 4.0b
end
-- SG.InitBuffOrder
-- Syncs SG.B[spec].Order with available class buffs (add/remove entries).
-- Parameters:
-- reset (boolean) When true, clears order before rebuild
-- Returns: nothing
function SG.InitBuffOrder(reset)
if not SG.B then SG.B = {} end
if not SG.B[SG.CS()] then SG.B[SG.CS()] = {} end
if not SG.B[SG.CS()].Order then SG.B[SG.CS()].Order = {} end
local b;
local i;
local ord = SG.B[SG.CS()].Order;
if (reset) then
wipe(ord);
end
-- Remove no longer existing buffs in the order list
for k, v in pairs(ord) do
if (v and SG.cBuffIndex[v] == nil) then
SMARTBUFF_AddMsgD("Remove from buff order: "..v);
tremove(ord, k);
end
end
i = 1;
while (SG.cBuffs[i] and SG.cBuffs[i].BuffS) do
b = false;
for _, v in pairs(ord) do
if (v and v == SG.cBuffs[i].BuffS) then
b = true;
break;
end
end
-- buff not found add it to order list
if (not b) then
tinsert(ord, SG.cBuffs[i].BuffS);
SMARTBUFF_AddMsgD("Add to buff order: "..SG.cBuffs[i].BuffS);
end
i = i + 1;
end
end
-- SG.IsMinLevel
-- Returns true when player level meets minimum requirement.
-- Parameters:
-- minLevel (number|nil) Required level; nil always passes
-- Returns:
-- (boolean)
function SG.IsMinLevel(minLevel)
if (not minLevel) then
return true;
end
if (minLevel > UnitLevel("player")) then
return false;
end
return true;
end
-- SG.IsPlayerInGuild
-- Returns whether the player is in a guild.
-- Parameters: none
-- Returns:
-- (boolean)
function SG.IsPlayerInGuild()
return IsInGuild() -- and GetGuildInfo("player")
end
-- SG.IsTalentSkilled
-- Checks whether a talent tab entry matches name and has points spent.
-- Parameters:
-- t (number) Talent tab index
-- i (number) Talent index within tab
-- name (string) Expected talent name
-- Returns:
-- (boolean) True if matching talent has points
-- (number) Points spent in that talent
function SG.IsTalentSkilled(t, i, name)
local _, tName, _, _, tAvailable = GetTalentInfo(t, i);
if (tName) then
SG.isTTreeLoaded = true;
SMARTBUFF_AddMsgD("Talent: "..tName..", Points = "..tAvailable);
if (name and name == tName and tAvailable > 0) then
SMARTBUFF_AddMsgD("Debuff talent found: "..name..", Points = "..tAvailable);
return true, tAvailable;
end
else
SMARTBUFF_AddMsgD("Talent tree not available!");
SG.isTTreeLoaded = false;
end
return false, 0;
end
-- SMARTBUFF_OnLoad
-- Registers events, slash commands, and initializes spell IDs and sounds.
-- Parameters:
-- self (Frame) SmartBuff main event frame
-- Returns: nothing
function SMARTBUFF_OnLoad(self)
self:RegisterEvent("ADDON_LOADED");
self:RegisterEvent("PLAYER_LOGIN");
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("UNIT_NAME_UPDATE");
self:RegisterEvent("PLAYER_REGEN_ENABLED");
self:RegisterEvent("PLAYER_REGEN_DISABLED");
self:RegisterEvent("PLAYER_STARTED_MOVING");
self:RegisterEvent("PLAYER_STOPPED_MOVING");
self:RegisterEvent("PLAYER_TALENT_UPDATE");
self:RegisterEvent("SPELLS_CHANGED");
self:RegisterEvent("ACTIONBAR_HIDEGRID");
self:RegisterEvent("UNIT_AURA");
self:RegisterEvent("CHAT_MSG_ADDON");
self:RegisterEvent("CHAT_MSG_CHANNEL");
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT");
self:RegisterEvent("UNIT_SPELLCAST_FAILED");
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
self:RegisterEvent("MINIMAP_UPDATE_TRACKING")
self:RegisterEvent("BAG_UPDATE");
--auto template events
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
self:RegisterEvent("GROUP_ROSTER_UPDATE")
self:RegisterEvent("UPDATE_BINDINGS"); -- keybindings saved; re-apply SmartBuff Action override so key works without /reload
--One of them allows SmartBuff to be closed with the Escape key
tinsert(UISpecialFrames, "SmartBuffOptionsFrame");
UIPanelWindows["SmartBuffOptionsFrame"] = nil;
SlashCmdList["SMARTBUFF"] = SMARTBUFF_command;
SLASH_SMARTBUFF1 = "/sbo";
SLASH_SMARTBUFF2 = "/sbuff";
SLASH_SMARTBUFF3 = "/smartbuff";
SLASH_SMARTBUFF4 = "/sb";
SlashCmdList["SMARTBUFFMENU"] = SMARTBUFF_OptionsFrame_Toggle;
SLASH_SMARTBUFFMENU1 = "/sbm";
SlashCmdList["SmartReloadUI"] = function(msg) ReloadUI(); end;
SLASH_SmartReloadUI1 = "/rui";
SMARTBUFF_InitSpellIDs();
SG.InitSharedMediaSounds();