-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartBuff.lua
4782 lines (4274 loc) · 156 KB
/
SmartBuff.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
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 & Speedwaystar
-- Retail version fixes / improvements by Codermik & Speedwaystar
-- Discord: https://discord.gg/R6EkZ94TKK
-- Cast the most important buffs on you, tanks or party/raid members/pets.
-------------------------------------------------------------------------------
SMARTBUFF_DATE = "171023";
SMARTBUFF_VERSION = "r57."..SMARTBUFF_DATE;
SMARTBUFF_VERSIONNR = 30403;
SMARTBUFF_VERWOTLK = false;
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 ";
-- addon name
local addonName = ...
local SmartbuffPrefix = "SBC1.0";
local SmartbuffHeader = "Smartbuff";
local SmartbuffCommands = { "SBCVER", "SBCCMD", "SBCSYC" }
local SmartbuffSession = true;
local SmartbuffVerCheck = false; -- for my use when checking guild users/testers versions :)
local buildInfo = select(4, GetBuildInfo())
local SmartbuffRevision = 57;
local SmartbuffVerNotifyList = {}
-- Using LibRangeCheck-2.0 by Mitchnull
-- https://www.wowace.com/projects/librangecheck-2-0
local LRC = LibStub("LibRangeCheck-2.0")
local SG = SMARTBUFF_GLOBALS;
local OG = nil; -- Options global
local O = nil; -- Options local
local B = nil; -- Buff settings local
local _;
BINDING_HEADER_SMARTBUFF = "SmartBuff";
SMARTBUFF_BOOK_TYPE_SPELL = "spell";
local GlobalCd = 1.5;
local maxSkipCoolDown = 3;
local maxRaid = 40;
local maxBuffs = 40;
local maxScrollButtons = 30;
local numBuffs = 0;
local isLoaded = false;
local isPlayer = false;
local isInit = false;
local isCombat = false;
local isSetBuffs = false;
local isSetZone = false;
local isFirstError = false;
local isMounted = false;
local isCTRA = true;
local isKeyUpChanged = false;
local isKeyDownChanged = false;
local isAuraChanged = false;
local isClearSplash = false;
local isRebinding = false;
local isParrot = false;
local isSync = false;
local isSyncReq = false;
local isInitBtn = false;
local isPrompting = false
local isShapeshifted = false;
local sShapename = "";
local tStartZone = 0;
local tTicker = 0;
local tSync = 0;
local sRealmName = nil;
local sPlayerName = nil;
local sID = nil;
local sPlayerClass = nil;
local tLastCheck = 0;
local iLastBuffSetup = -1;
local sLastTexture = "";
local iLastGroupSetup = -99;
local sLastZone = "";
local tAutoBuff = 0;
local tDebuff = 0;
local sMsgWarning = "";
local iCurrentFont = 6;
local iCurrentList = -1;
local iLastPlayer = -1;
local isPlayerMoving = false;
local cGroups = { };
local cClassGroups = { };
local cBuffs = { };
local cBuffIndex = { };
local cBuffTimer = { };
local cBlacklist = { };
local cUnits = { };
local cBuffsCombat = { };
local cSpellRankInfo = { };
local cScrBtnBO = nil;
local cAddUnitList = { };
local cIgnoreUnitList = { };
local cPlayerTrackers = { };
local cDisableTrackSwitch = false;
local cLootOpenedDisable = false;
local cClasses;
local cIgnoreClasses;
-- client version check
if buildInfo < SMARTBUFF_VERSIONNR then
-- assume we are classic era/hardcore.
cClasses = {"DRUID", "HUNTER", "MAGE", "PALADIN", "PRIEST", "ROGUE", "SHAMAN", "WARLOCK", "WARRIOR", "DEATHKNIGHT", "MONK", "DEMONHUNTER", "EVOKER", "HPET", "WPET", "DKPET", "TANK", "HEALER", "DAMAGER"};
cIgnoreClasses = { 10, 11, 12, 13, 16, 19 };
SMARTBUFF_VERWOTLK = false
else
-- wrath of the lich king.
cClasses = {"DRUID", "HUNTER", "MAGE", "PALADIN", "PRIEST", "ROGUE", "SHAMAN", "WARLOCK", "WARRIOR", "DEATHKNIGHT", "MONK", "DEMONHUNTER", "EVOKER", "HPET", "WPET", "DKPET", "TANK", "HEALER", "DAMAGER"};
cIgnoreClasses = { 11, 12, 13, 19 };
SMARTBUFF_VERWOTLK = true
end
local cOrderGrp = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
local cFonts = {"NumberFontNormal", "NumberFontNormalLarge", "NumberFontNormalHuge", "GameFontNormal", "GameFontNormalLarge", "GameFontNormalHuge", "ChatFontNormal", "QuestFont", "MailTextFontNormal", "QuestTitleFont"};
local currentUnit = nil;
local currentSpell = nil;
local currentTemplate = nil;
local currentSpec = nil;
local imgSB = "Interface\\Icons\\inv_gizmo_goblinboombox_01";
local imgIconOn = "Interface\\AddOns\\SmartBuff\\Icons\\MiniMapButtonEnabled";
local imgIconOff = "Interface\\AddOns\\SmartBuff\\Icons\\MiniMapButtonDisabled";
local IconPaths = {
["Pet"] = "Interface\\Icons\\spell_nature_spiritwolf",
["Roles"] = "Interface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES",
["Classes"] = "Interface\\WorldStateFrame\\Icons-Classes",
};
local Icons = {
["WARRIOR"] = { IconPaths.Classes, 0.00, 0.25, 0.00, 0.25 },
["MAGE"] = { IconPaths.Classes, 0.25, 0.50, 0.00, 0.25 },
["ROGUE"] = { IconPaths.Classes, 0.50, 0.75, 0.00, 0.25 },
["DRUID"] = { IconPaths.Classes, 0.75, 1.00, 0.00, 0.25 },
["HUNTER"] = { IconPaths.Classes, 0.00, 0.25, 0.25, 0.50 },
["SHAMAN"] = { IconPaths.Classes, 0.25, 0.50, 0.25, 0.50 },
["PRIEST"] = { IconPaths.Classes, 0.50, 0.75, 0.25, 0.50 },
["WARLOCK"] = { IconPaths.Classes, 0.75, 1.00, 0.25, 0.50 },
["PALADIN"] = { IconPaths.Classes, 0.00, 0.25, 0.50, 0.75 },
["DEATHKNIGHT"] = { IconPaths.Classes, 0.25, 0.50, 0.50, 0.75 },
["MONK"] = { IconPaths.Classes, 0.50, 0.75, 0.50, 0.75 },
["DEMONHUNTER"] = { IconPaths.Classes, 0.75, 1.00, 0.50, 0.75 },
["EVOKER"] = { IconPaths.Classes, 0.75, 1.00, 0.50, 0.75 },
["PET"] = { IconPaths.Pet, 0.08, 0.92, 0.08, 0.92},
["TANK"] = { IconPaths.Roles, 0.0, 19/64, 22/64, 41/64 },
["HEALER"] = { IconPaths.Roles, 20/64, 39/64, 1/64, 20/64 },
["DAMAGER"] = { IconPaths.Roles, 20/64, 39/64, 22/64, 41/64 },
["NONE"] = { IconPaths.Roles, 20/64, 39/64, 22/64, 41/64 },
};
local tracker = ""
-- available sounds (39)
local soundPath = "Interface\\AddOns\\SmartBuff\\Sounds\\";
local 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", -- just for you Emmalee ;-)
"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",
};
local DebugChatFrame = DEFAULT_CHAT_FRAME;
-- upvalues
local UnitCastingInfo = _G.UnitCastingInfo or _G.CastingInfo
local UnitChannelInfo = _G.UnitChannelInfo or _G.ChannelInfo
local GetNumSpecGroups = _G.GetNumSpecGroups or function(...) return 1 end
local IsActiveBattlefieldArena = _G.IsActiveBattlefieldArena or function(...) 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
}
-- Rounds a number to the given number of decimal places.
local r_mult;
local function Round(num, idp)
r_mult = 10^(idp or 0);
return math.floor(num * r_mult + 0.5) / r_mult;
end
-- Returns a chat color code string
local function BCC(r, g, b)
return string.format("|cff%02x%02x%02x", (r*255), (g*255), (b*255));
end
local BL = BCC(0, 0, 1);
local BLD = BCC(0, 0, 0.7);
local BLL = BCC(0.5, 0.8, 1);
local GR = BCC(0, 1, 0);
local GRD = BCC(0, 0.7, 0);
local GRL = BCC(0.6, 1, 0.6);
local RD = BCC(1, 0, 0);
local RDD = BCC(0.7, 0, 0);
local RDL = BCC(1, 0.3, 0.3);
local YL = BCC(1, 1, 0);
local YLD = BCC(0.7, 0.7, 0);
local YLL = BCC(1, 1, 0.5);
local OR = BCC(1, 0.7, 0);
local ORD = BCC(0.7, 0.5, 0);
local ORL = BCC(1, 0.6, 0.3);
local WH = BCC(1, 1, 1);
local CY = BCC(0.5, 1, 1);
-- function to preview selected warning sound in options screen
function SMARTBUFF_PlaySpashSound()
PlaySoundFile(soundPath..Sounds[O.AutoSoundSelection]);
end
function SMARTBUFF_ChooseSplashSound()
local menu = {}
local i = 1
for sound, soundpath in pairs(sounds) do
menu[i] = { text = sound, notCheckable = true, func = function() PlaySound(soundpath) end }
i = i + 1
end
local dropDown = CreateFrame("Frame", "DropDownMenuFrame", UIParent, "UIDropDownMenuTemplate")
dropDown:SetPoint("CENTER", UIParent, "CENTER")
dropDown:SetScript("OnMouseUp", function (self, button, down)
print("mousedown")
end)
end
-- Reorders values in the table
local function 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
-- Finds a value in the table and returns the index
local function 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
local function 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
local function ChkS(text)
if (text == nil) then
text = "";
end
return text;
end
local function 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
local function CS()
if (currentSpec == nil) then
currentSpec = GetActiveTalentGroup()
end
if (currentSpec == nil) then
currentSpec = 1;
end
return currentSpec;
end
local function CT()
return currentTemplate;
end
local function GetBuffSettings(buff)
if (B and buff) then
return B[CS()][CT()][buff];
end
return nil;
end
local function InitBuffSettings(cBI, reset)
local buff = cBI.BuffS;
local cBuff = GetBuffSettings(buff);
if (cBuff == nil) then
B[CS()][CT()][buff] = { };
cBuff = B[CS()][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(cClasses) do
if (cBI.Type == SMARTBUFF_CONST_GROUP and not tcontains(cIgnoreClasses, n) and not string.find(cBI.Params, cClasses[n])) then
cBuff[cClasses[n]] = true;
else
cBuff[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
local function InitBuffOrder(reset)
if not B then B = {} end
if not B[CS()] then B[CS()] = {} end
if not B[CS()].Order then B[CS()].Order = {} end
local b;
local i;
local ord = B[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 cBuffIndex[v] == nil) then
SMARTBUFF_AddMsgD("Remove from buff order: "..v);
tremove(ord, k);
end
end
i = 1;
while (cBuffs[i] and cBuffs[i].BuffS) do
b = false;
for _, v in pairs(ord) do
if (v and v == cBuffs[i].BuffS) then
b = true;
break;
end
end
-- buff not found add it to order list
if (not b) then
tinsert(ord, cBuffs[i].BuffS);
SMARTBUFF_AddMsgD("Add to buff order: "..cBuffs[i].BuffS);
end
i = i + 1;
end
end
local function IsMinLevel(minLevel)
if (not minLevel) then
return true;
end
if (minLevel > UnitLevel("player")) then
return false;
end
return true;
end
local function IsPlayerInGuild()
return IsInGuild() -- and GetGuildInfo("player")
end
local function IsTalentSkilled(t, i, name)
local _, tName, _, _, tAvailable = GetTalentInfo(t, i);
if (tName) then
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!");
isTTreeLoaded = false;
end
return false, 0;
end
-- toggle the auto gathering switcher.
function ToggleAutoGatherer()
if (not isInit or not SMARTBUFF_VERWOTLK) then return end
O.TrackSwitchActive = not O.TrackSwitchActive;
if not SmartBuffOptionsFrame:IsShown() then -- quiet while in options
if O.TrackSwitchActive then
DEFAULT_CHAT_FRAME:AddMessage("|cff00e0ffSmartbuff Build "..SMARTBUFF_VERSION.." (Client: "..buildInfo..")|cffffffff "..SMARTBUFF_AUTOGATHERON)
else
DEFAULT_CHAT_FRAME:AddMessage("|cff00e0ffSmartbuff Build "..SMARTBUFF_VERSION.." (Client: "..buildInfo..")|cffffffff "..SMARTBUFF_AUTOGATHEROFF)
end
PlaySound(15263);
end
end
-- Read number of tracking abilities
function ScanPlayerTrackers()
if (not isInit or not SMARTBUFF_VERWOTLK) then return end
local count = C_Minimap.GetNumTrackingTypes();
local spellcount = 0;
cPlayerTrackers = { };
for i=1,count do
local name, texture, active, category = C_Minimap.GetTrackingInfo(i);
if category == "spell" then
-- only interested in minerals, herbs and fish here
if name == SMARTBUFF_OFT_MINERALS or name == SMARTBUFF_OFT_HERBS or name == SMARTBUFF_OFT_FINDFISH then
spellcount = spellcount + 1
tinsert(cPlayerTrackers, {i, name})
end
end
end
O.TrackMaxPosition = spellcount
end
-- toggle trackers
local lastFire = GetTime()
function ToggleGatheringTrackers()
if (not isInit or not SMARTBUFF_VERWOTLK) then return end
local tmptable
if O.TrackSwitchActive and not cDisableTrackSwitch and not cLootOpenedDisable then
local currentTime = GetTime()
if (currentTime - lastFire) >= O.TrackSwitchDelay and not InCombatLockdown() then
ScanPlayerTrackers()
currentTime = GetTime()
lastFire = currentTime
if not SmartBuffOptionsFrame:IsShown() then
tmptable = cPlayerTrackers[O.TrackPosition]
local tmptablesize = #cPlayerTrackers
if tmptablesize <= 1 then
-- turn the auto switch off, it will only benefit when more than one gathering tracking is available.
DEFAULT_CHAT_FRAME:AddMessage("|cff00e0ffSmartbuff Gathering Switcher : |cffffffff"..SMARTBUFF_TRACKINGDISABLE)
O.TrackSwitchActive = false
end
if tmptable then
if tmptable[2] == "Find Fish" and O.TrackSwitchFish then
C_Minimap.SetTracking(tmptable[1], true)
elseif tmptable[2] == "Find Fish" and not O.TrackSwitchFish then
O.TrackPosition = O.TrackPosition + 1
if O.TrackPosition > O.TrackMaxPosition then
O.TrackPosition = 1
end
tmptable = cPlayerTrackers[O.TrackPosition]
C_Minimap.SetTracking(tmptable[1], true)
elseif tmptable[2] ~= "Find Fish" then
C_Minimap.SetTracking(tmptable[1], true)
end
O.TrackPosition = O.TrackPosition + 1
if O.TrackPosition > O.TrackMaxPosition then
O.TrackPosition = 1
end
end
end
end
end
end
-- SMARTBUFF_OnLoad
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("LOOT_OPENED")
self:RegisterEvent("LOOT_CLOSED")
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")
--auto template events
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
self:RegisterEvent("GROUP_ROSTER_UPDATE")
--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();
end
-- END SMARTBUFF_OnLoad
-- SMARTBUFF_OnEvent
function SMARTBUFF_OnEvent(self, event, ...)
local arg1, arg2, arg3, arg4, arg5 = ...;
if ((event == "UNIT_NAME_UPDATE" and arg1 == "player") or event == "PLAYER_ENTERING_WORLD") then
if IsPlayerInGuild() and event == "PLAYER_ENTERING_WORLD" then
C_ChatInfo.SendAddonMessage(SmartbuffPrefix, SmartbuffHeader.."¦"..SmartbuffCommands[1].."¦"..SmartbuffRevision.."¦"..SMARTBUFF_VERSION, "GUILD")
end
isPlayer = true;
if (event == "PLAYER_ENTERING_WORLD" and isInit and O.Toggle) then
isSetZone = true;
tStartZone = GetTime();
end
elseif event == "MINIMAP_UPDATE_TRACKING" and not SMARTBUFF_VERWOTLK then
if not GetTrackingTexture() then
-- we dont have a tracker so force a reset.
tracker = "";
end
elseif(event == "ADDON_LOADED" and arg1 == SMARTBUFF_TITLE) then
isLoaded = true;
end
-- PLAYER_LOGIN
if event == "PLAYER_LOGIN" then
local prefixResult = C_ChatInfo.RegisterAddonMessagePrefix(SmartbuffPrefix)
end
-- these two stop the tracking switcher when a loot window is opened
-- otherwise if autoloot isnt on it can close the loot window when it
-- does a switch.. gotta love these things..
if event == "LOOT_OPENED" then
cLootOpenedDisable = true
SMARTBUFF_AddMsgD("Loot window opened");
end
if event == "LOOT_CLOSED" then
cLootOpenedDisable = false
SMARTBUFF_AddMsgD("Loot window closed");
end
-- CHAT_MSG_ADDON
if event == "CHAT_MSG_ADDON" then
local pktHeader, pktCmd, pktData1, pktData2
if arg1 == SmartbuffPrefix then
if arg2 then
pktHeader, pktCmd, pktData1, pktData2 = strsplit("¦", arg2, 4)
if pktHeader == SmartbuffHeader then
if pktCmd == SmartbuffCommands[1] then -- version packet
pktData1 = tonumber(pktData1)
if pktData1 > SmartbuffRevision and SmartbuffSession then
DEFAULT_CHAT_FRAME:AddMessage(SMARTBUFF_MSG_NEWVER1..SMARTBUFF_VERSION..SMARTBUFF_MSG_NEWVER2..pktData1..SMARTBUFF_MSG_NEWVER3)
SmartbuffSession = false
end
if SmartbuffVerCheck then
if arg5 and arg5 ~= UnitName("player") then
DEFAULT_CHAT_FRAME:AddMessage("|cff00e0ffSmartbuff Versions: |cffFFFF00"..arg5.."|cffffffff has "..pktData2.." installed.")
end
end
elseif pktCmd == SmartbuffCommands[2] then -- command packet (future feature)
elseif pktCmd == SmartbuffCommands[3] then -- sync packet (future feature)
else
SMARTBUFF_AddMsgD("Warning: Received an unknown command packet to the addon.");
end
else
SMARTBUFF_AddMsgD("Warning: Not a valid packet header sent to the addon.");
end
end
end
end
if (event == "SMARTBUFF_UPDATE" and isLoaded and isPlayer and not isInit and not InCombatLockdown()) then
SMARTBUFF_Options_Init(self);
end
if (not isInit or O == nil) then
return;
end;
if (event == "PLAYER_REGEN_DISABLED") then
SMARTBUFF_Ticker(true);
if (O.Toggle) then
if (O.InCombat) then
for spell, data in pairs(cBuffsCombat) do
if (data and data.Unit and data.ActionType) then
if (data.Type == SMARTBUFF_CONST_SELF or data.Type == SMARTBUFF_CONST_FORCESELF or data.Type == SMARTBUFF_CONST_STANCE or data.Type == SMARTBUFF_CONST_ITEM) then
SmartBuff_KeyButton:SetAttribute("unit", nil);
else
SmartBuff_KeyButton:SetAttribute("unit", data.Unit);
end
SmartBuff_KeyButton:SetAttribute("type", data.ActionType);
SmartBuff_KeyButton:SetAttribute("spell", spell);
SmartBuff_KeyButton:SetAttribute("item", nil);
SmartBuff_KeyButton:SetAttribute("target-slot", nil);
SmartBuff_KeyButton:SetAttribute("target-item", nil);
SmartBuff_KeyButton:SetAttribute("macrotext", nil);
SmartBuff_KeyButton:SetAttribute("action", nil);
SMARTBUFF_AddMsgD("Enter Combat, set button: " .. spell .. " on " .. data.Unit .. ", " .. data.ActionType);
break;
end
end
end
SMARTBUFF_SyncBuffTimers();
SMARTBUFF_Check(1, true);
if SMARTBUFF_IsFishingPoleEquiped() and O.WarnCombatFishingRod then -- i'll add an option to turn this off later
-- warn the player he/she is in combat with a fishing pole equipped.
DEFAULT_CHAT_FRAME:AddMessage("|cffff0000Smartbuff Warning: |cffff6060"..SMARTBUFF_OFT_FRODWARN)
PlaySound(12197);
end
end
elseif (event == "PLAYER_REGEN_ENABLED") then
SMARTBUFF_Ticker(true);
if (O.Toggle) then
if (O.InCombat) then
SmartBuff_KeyButton:SetAttribute("type", nil);
SmartBuff_KeyButton:SetAttribute("unit", nil);
SmartBuff_KeyButton:SetAttribute("spell", nil);
end
SMARTBUFF_SyncBuffTimers();
SMARTBUFF_Check(1, true);
end
elseif (event == "PLAYER_STARTED_MOVING") then
isPlayerMoving = true;
elseif (event == "PLAYER_STOPPED_MOVING") then
isPlayerMoving = false;
elseif (event == "PLAYER_TALENT_UPDATE") then
if(SmartBuffOptionsFrame:IsVisible()) then
SmartBuffOptionsFrame:Hide();
end
if (currentSpec ~= GetActiveTalentGroup()) then
currentSpec = GetActiveTalentGroup();
if (B[currentSpec] == nil) then
B[currentSpec] = { };
end
SMARTBUFF_AddMsg(format(SMARTBUFF_MSG_SPECCHANGED, tostring(currentSpec)), true);
isSetBuffs = true;
end
elseif (event == "SPELLS_CHANGED" or event == "ACTIONBAR_HIDEGRID") then
isSetBuffs = true;
end
if (not O.Toggle) then
return;
end;
if (event == "UNIT_AURA") then
if (UnitAffectingCombat("player") and (arg1 == "player" or string.find(arg1, "^party") or string.find(arg1, "^raid"))) then
isSyncReq = true;
end
-- checks if aspect of cheetah or pack is active and cancel it if someone gets dazed
if (sPlayerClass == "HUNTER" and O.AntiDaze and (arg1 == "player" or string.find(arg1, "^party") or string.find(arg1, "^raid") or string.find(arg1, "pet"))) then
local _, _, stuntex = GetSpellInfo(1604); --get Dazed icon
if (SMARTBUFF_IsDebuffTexture(arg1, stuntex)) then
buff = nil;
if (arg1 == "player" and SMARTBUFF_CheckBuff(arg1, SMARTBUFF_AOTC)) then
buff = SMARTBUFF_AOTC;
elseif (SMARTBUFF_CheckBuff(arg1, SMARTBUFF_AOTP, true)) then
buff = SMARTBUFF_AOTP;
end
if (buff) then
if (O.ToggleAutoSplash and not SmartBuffOptionsFrame:IsVisible()) then
SmartBuffSplashFrame:Clear();
SmartBuffSplashFrame:SetTimeVisible(1);
SmartBuffSplashFrame:AddMessage("!!! CANCEL "..buff.." !!!", O.ColSplashFont.r, O.ColSplashFont.g, O.ColSplashFont.b, 1.0);
end
if (O.ToggleAutoChat) then
SMARTBUFF_AddMsgWarn("!!! CANCEL "..buff.." !!!", true);
end
end
end
end
end
if (event == "UI_ERROR_MESSAGE") then
SMARTBUFF_AddMsgD(string.format("Error message: %s",arg1));
end
if (event == "UNIT_SPELLCAST_FAILED") then
currentUnit = arg1;
SMARTBUFF_AddMsgD(string.format("Spell failed: %s",arg1));
if (currentUnit and (string.find(currentUnit, "party") or string.find(currentUnit, "raid") or (currentUnit == "target" and O.Debug))) then
if (UnitName(currentUnit) ~= sPlayerName and O.BlacklistTimer > 0) then
cBlacklist[currentUnit] = GetTime();
if (currentUnit and UnitName(currentUnit)) then
end
end
end
currentUnit = nil;
elseif (event == "UNIT_SPELLCAST_SUCCEEDED") then
if (arg1 and arg1 == "player") then
local unit = nil;
local spell = nil;
local target = nil;
if (arg1 and arg2) then
if (not arg3) then arg3 = ""; end
if (not arg4) then arg4 = ""; end
SMARTBUFF_AddMsgD("Spellcast succeeded: target " .. arg1 .. ", spellID " .. arg3 .. " (" ..GetSpellInfo(arg3) .. "), " .. arg4)
if (string.find(arg1, "party") or string.find(arg1, "raid")) then
spell = arg2;
end
end
if (currentUnit and currentSpell and currentUnit ~= "target") then
unit = currentUnit;
spell = currentSpell;
end
if (unit) then
local name = UnitName(unit);
if (cBuffTimer[unit] == nil) then
cBuffTimer[unit] = { };
end
cBuffTimer[unit][spell] = GetTime();
if (name ~= nil) then
SMARTBUFF_AddMsg(name .. ": " .. spell .. " " .. SMARTBUFF_MSG_BUFFED);
currentUnit = nil;
currentSpell = nil;
end
end
if (isClearSplash) then
isClearSplash = false;
SMARTBUFF_Splash_Clear();
end
end
end
if event == "ZONE_CHANGED_NEW_AREA" or event == "GROUP_ROSTER_UPDATE" then
SMARTBUFF_SetTemplate()
end
end
-- END SMARTBUFF_OnEvent
function SMARTBUFF_OnUpdate(self, elapsed)
if not self.Elapsed then
self.Elapsed = 0.2
end
self.Elapsed = self.Elapsed - elapsed
if self.Elapsed > 0 then
return
end
self.Elapsed = 0.2
if (not isInit) then
if (isLoaded and GetTime() > tAutoBuff + 0.5) then
tAutoBuff = GetTime();
local specID = GetActiveTalentGroup()
if (specID) then
SMARTBUFF_OnEvent(self, "SMARTBUFF_UPDATE");
end
end
else
SMARTBUFF_Ticker();
SMARTBUFF_Check(1);
ToggleGatheringTrackers();
end
end
function SMARTBUFF_Ticker(force)
if (force or GetTime() > tTicker + 1) then
tTicker = GetTime();
if (isSyncReq or tTicker > tSync + 10) then
SMARTBUFF_SyncBuffTimers();
end
if (isAuraChanged) then
isAuraChanged = false;
SMARTBUFF_Check(1, true);
end
end
end
-- Will dump the value of msg to the default chat window
function SMARTBUFF_AddMsg(msg, force)
if (DEFAULT_CHAT_FRAME and (force or not O.ToggleMsgNormal)) then
DEFAULT_CHAT_FRAME:AddMessage(YLL .. msg .. "|r");
end
end
function SMARTBUFF_AddMsgErr(msg, force)
if (DEFAULT_CHAT_FRAME and (force or not O.ToggleMsgError)) then
DEFAULT_CHAT_FRAME:AddMessage(RDL .. SMARTBUFF_TITLE .. ": " .. msg .. "|r");
end
end
function SMARTBUFF_AddMsgWarn(msg, force)
if (DEFAULT_CHAT_FRAME and (force or not O.ToggleMsgWarning)) then
if (isParrot) then
Parrot:ShowMessage(CY .. msg .. "|r");
else
DEFAULT_CHAT_FRAME:AddMessage(CY .. msg .. "|r");
end
end
end
function SMARTBUFF_AddMsgD(msg, r, g, b)
if (r == nil) then r = 0.5; end
if (g == nil) then g = 0.8; end
if (b == nil) then b = 1; end
if (DebugChatFrame and O and O.Debug) then
DebugChatFrame:AddMessage(msg, r, g, b);
end
end
Enum.SmartBuffGroup = {
Solo = 1,
Party = 2,
Raid = 3,
Battleground = 4,
Arena = 5,
ICC = 6,
TOC = 7,
Ulduar = 7,
Ony = 8,
Naxx = 9,
Custom1 = 10,
Custom2 = 11,
Custom3 = 12,
Custom4 = 13,
Custom5 = 14
}
-- Set the current template and create an array of units
local GatherDisableAnnounce = true
function SMARTBUFF_SetTemplate()
if (InCombatLockdown()) then return end
if (SmartBuffOptionsFrame:IsVisible()) then return end
local newTemplate = currentTemplate
cDisableTrackSwitch = false; -- on unless otherwise changed
if O.AutoSwitchTemplate then
newTemplate = SMARTBUFF_TEMPLATES[Enum.SmartBuffGroup.Solo];
local name, instanceType, difficultyID, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceID, instanceGroupSize, LfgDungeonID = GetInstanceInfo()
if IsInRaid() then
newTemplate = SMARTBUFF_TEMPLATES[Enum.SmartBuffGroup.Raid];
elseif IsInGroup() then
newTemplate = SMARTBUFF_TEMPLATES[Enum.SmartBuffGroup.Party];
end
-- check instance type (allows solo raid clearing, etc)
if instanceType == "raid" then
newTemplate = SMARTBUFF_TEMPLATES[Enum.SmartBuffGroup.Raid];
elseif instanceType == "party" then
newTemplate = SMARTBUFF_TEMPLATES[Enum.SmartBuffGroup.Party];
end
end
-- if autoswitch on instance change is enabled, load new instance template if any
local isRaidInstanceTemplate = false
if O.AutoSwitchTemplateInst then
local zone = GetRealZoneText()
local instances = Enum.MakeEnumFromTable(SMARTBUFF_INSTANCES);
local i = instances[zone]
if i and SMARTBUFF_TEMPLATES[i + Enum.SmartBuffGroup.Arena] then
newTemplate = SMARTBUFF_TEMPLATES[i + Enum.SmartBuffGroup.Arena]
isRaidInstanceTemplate = true
end
end
if currentTemplate ~= newTemplate then
SMARTBUFF_AddMsgD("Current tmpl: " .. currentTemplate or "nil" .. " - new tmpl: " .. newTemplate or "nil");
SMARTBUFF_AddMsg(SMARTBUFF_TITLE.." :: "..SMARTBUFF_OFT_AUTOSWITCHTMP .. ": " .. currentTemplate .. " -> " .. newTemplate);
end
currentTemplate = newTemplate;
SMARTBUFF_SetBuffs();
wipe(cBlacklist);
wipe(cBuffTimer);
wipe(cUnits);
wipe(cGroups);
cClassGroups = nil;
wipe(cAddUnitList);
wipe(cIgnoreUnitList);
-- Raid Setup, including smart instance templates
if currentTemplate == (SMARTBUFF_TEMPLATES[Enum.SmartBuffGroup.Raid]) or isRaidInstanceTemplate then
cClassGroups = { };
local name, server, rank, subgroup, level, class, classeng, zone, online, isDead;
local sRUnit = nil;
-- do we want to disable the gathering switcher?
if O.TrackDisableGrp and O.TrackSwitchActive then
cDisableTrackSwitch = true;
if GatherDisableAnnounce then -- make sure we only announce the once for this session (unless a reloadui ofc)
SMARTBUFF_AddMsg("Raid -> Auto gathering tracker disabled while in a raid, switching to preset (if any).");
GatherDisableAnnounce = false
end
end
-- do we have a fishing rod equipped and entered a raid?
if SMARTBUFF_IsFishingPoleEquiped() and O.WarnGroupFishingRod then
-- warn the player he/she has a fishing pole equipped.
DEFAULT_CHAT_FRAME:AddMessage("|cffff0000Smartbuff Warning: |cffff6060"..SMARTBUFF_OFT_FRINSWARN)
PlaySound(12197);
end
j = 1;