-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartBuff.lua
5169 lines (4493 loc) · 171 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
-- Created by Aeldra (EU-Proudmoore)
--
-- Cast the most important buffs on you or party/raid members/pets.
-------------------------------------------------------------------------------
--[[
FrameXML database
http://wowcompares.com/
Significant Changes
* The blizzard UI is being converted to use 'self' and the other local arguments in favor of 'this' and argN.
The old style arguments are going to be obsoleted, so AddOn code needs to be updated too.
This may mean there are changes in the signatures of Blizzard UI functions - update code that hooks or replaces the blizzard UI where necessary as well. !!!
* UPDATED: In the current beta build slash command handlers have a new 'self' parameter before the message that is the edit box the command ran from.
As this is a cause of major backward incompatibility the change is going to be reversed and the editBox will come AFTER the message -- ETA unknown !!!
* The SecureStateHeader has been replaced by a new secure template which allows for a more natural specification of rules in lua rather than via complex state tables.
More details will be forthcoming. !!!
Buff Information
* The various GetPlayerBuff functions have been removed and integrated into the appropriate unit functions, adding a new UnitAura function and updating the others:
name, rank, texture, count, debuffType, duration, timeLeft, untilCanceled = UnitAura("unit", [index] or ["name", "rank"][, "filter"]);
name, rank, texture, count, debuffType, duration, timeLeft, untilCanceled = UnitBuff("unit", [index] or ["name", "rank"][, "filter"]);
name, rank, texture, count, debuffType, duration, timeLeft, untilCanceled = UnitDebuff("unit", [index] or ["name", "rank"][, "filter"]);
CancelPlayerBuff([index] or ["name", "rank"][, "filter"]);
GameTooltip:SetUnitAura("unit", [index] or ["name", "rank"][, "filter"]);
GameTooltip:SetUnitBuff("unit", [index] or ["name", "rank"][, "filter"]);
GameTooltip:SetUnitDebuff("unit", [index] or ["name", "rank"][, "filter"]);
* The "filter" parameter can be any of "HELPFUL", "HARMFUL", "RAID", "CANCELABLE", "NOT_CANCELABLE". You can also specify several filters separated by a | character to chain multiple filters together (e.g. "HELPFUL|RAID" == helpful buffs that you can cast on your raid). By default UnitAura has "HELPFUL" as an implicit filter - you cannot get back BOTH helpful and harmful at the same time. Neither "HELPFUL" or "HARMFUL" have meaning for UnitBuff/UnitDebuff, and will be ignored.
* AddOns displaying remaining time should cache the time left and decrement their own counter, do not re-query the information every OnUpdate.
* The untilCanceled return value is true if the buff doesn't have its own duration (e.g. stealth)
]]--
SMARTBUFF_VERSION = "v1.13.2d";
SMARTBUFF_VERSIONNR = 11302;
SMARTBUFF_TITLE = "SmartBuff";
SMARTBUFF_SUBTITLE = "Supports you in cast buffs";
SMARTBUFF_DESC = "Cast the most important buffs on you or party/raid members/pets";
SMARTBUFF_VERS_TITLE = SMARTBUFF_TITLE .. " " .. SMARTBUFF_VERSION;
SMARTBUFF_OPTIONS_TITLE = SMARTBUFF_VERS_TITLE .. " Options";
local LCD = LibStub and LibStub("LibClassicDurations")
if LCD then LCD:Register(SMARTBUFF_TITLE) end
local UnitAuraFull = UnitAura
if LCD and LCD.UnitAura then UnitAuraFull = function(a, b, c) return LCD:UnitAura(a, b, c) end end
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 = 50;
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 isSetUnits = false;
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 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 iLastSubgroup = 0;
local tLastCheck = 0;
local iGroupSetup = -1;
local iLastBuffSetup = -1;
local sLastTexture = "";
local iLastGroupSetup = -99;
local sLastZone = "";
local tAutoBuff = 0;
local tDebuff = 0;
local sMsgWarning = "";
local iCurrentFont = 1;
local iCurrentList = -1;
local iLastPlayer = -1;
local cGroups = { };
local cClassGroups = { };
local cBuffs = { };
local cBuffIndex = { };
local cBuffTimer = { };
local cBlacklist = { };
local cUnits = { };
local cBuffsCombat = { };
local cScrBtnBO = nil;
local cAddUnitList = { };
local cIgnoreUnitList = { };
local cClasses = {"DRUID", "HUNTER", "MAGE", "PALADIN", "PRIEST", "ROGUE", "SHAMAN", "WARLOCK", "WARRIOR", "DEATHKNIGHT", "MONK", "DEMONHUNTER", "HPET", "WPET", "DKPET", "TANK", "HEALER", "DAMAGER"};
local cIgnoreClasses = { 10, 11, 12, 15, 16, 17, 18 };
local cOrderGrp = {0, 1, 2, 3, 4, 5, 6, 7, 8};
--local cOrderClass = {0, "WARRIOR", "PRIEST", "DRUID", "PALADIN", "SHAMAN", "MAGE", "WARLOCK", "HUNTER", "ROGUE", "DEATHKNIGHT", "MONK", "DEMONHUNTER", "HPET", "WPET", "DKPET"};
local cOrderClass = {0, "WARRIOR", "PRIEST", "DRUID", "PALADIN", "SHAMAN", "MAGE", "WARLOCK", "HUNTER", "ROGUE", "HPET", "WPET", "DKPET"};
local cFonts = {"NumberFontNormal", "NumberFontNormalLarge", "NumberFontNormalHuge", "GameFontNormal", "GameFontNormalLarge", "GameFontNormalHuge", "ChatFontNormal", "QuestFont", "MailTextFontNormal", "QuestTitleFont"};
local currentUnit = nil;
local currentSpell = nil;
local currentRank = nil;
local currentTemplate = nil;
local currentSpec = nil;
local imgSB = "Interface\\Icons\\Spell_Nature_Purge";
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 },
["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 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
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
}
-- 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);
-- 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
function strim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
local function ChkS(text)
if (text == nil) then
text = "";
end
return text;
end
local function IsFlying()
return false
end
local function UnitInVehicle(unit)
return false
end
local function UnitHasVehicleUI(unit)
return false
end
local function UnitGroupRolesAssigned(unit)
return "NONE"
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();
--print(format("w = %.0f, h = %.0f, x = %.0f, y = %.0f", w, h, x, y));
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 = GetSpecialization();
end
if (currentSpec == nil) then
currentSpec = 1;
SMARTBUFF_AddMsgErr("Could not detect active talent group, set to default = 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 = false;
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
--for n in pairs(cClasses) do
-- if (cBuff[cClasses[n]] == nil) then
-- cBuff[cClasses[n]] = false;
-- end
--end
end
local function InitBuffOrder(reset)
if (B[CS()].Order == nil) then
B[CS()].Order = { };
end
local b;
local i;
local ord = B[CS()].Order;
if (reset) then
wipe(ord);
SMARTBUFF_AddMsgD("Reset buff order");
end
-- Remove not 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
-- TODO: Redesign if reactivated!
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
local function IsPowerLimitOk(bs)
-- Check for power threshold
if (bs.ManaLimit and bs.ManaLimit > 0) then
local powerType, powerToken = UnitPowerType("player");
--print(tostring(powerType)..", "..powerToken);
-- if bs.ManaLimit <= 100 and powertype is mana then the ManaLimit is %
if (bs.ManaLimit <= 100 and powerType == 0) then
if (((UnitPower("player", powerType) / UnitPowerMax("player", powerType))) * 100 < bs.ManaLimit) then
--print(powerToken.." is below % threshold!");
return false;
end
elseif (UnitPower("player", powerType) < bs.ManaLimit) then
--print(powerToken.." is below threshold!");
return false;
end
end
return true;
end
-- SMARTBUFF_OnLoad
function SMARTBUFF_OnLoad(self)
self:RegisterEvent("ADDON_LOADED");
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("UNIT_NAME_UPDATE");
self:RegisterEvent("GROUP_ROSTER_UPDATE");
self:RegisterEvent("PLAYER_REGEN_ENABLED");
self:RegisterEvent("PLAYER_REGEN_DISABLED");
--self:RegisterEvent("PLAYER_TARGET_CHANGED");
--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("PLAYER_AURAS_CHANGED");
--self:RegisterEvent("ACTIONBAR_UPDATE_STATE");
-- self:RegisterEvent("CHAT_MSG_SPELL_FAILED_LOCALPLAYER");
-- self:RegisterEvent("UI_ERROR_MESSAGE");
self:RegisterEvent("UNIT_SPELLCAST_FAILED");
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
--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";
SlashCmdList["SMARTBUFFMENU"] = SMARTBUFF_OptionsFrame_Toggle;
SLASH_SMARTBUFFMENU1 = "/sbm";
SlashCmdList["SmartReloadUI"] = function(msg) ReloadUI(); end;
SLASH_SmartReloadUI1 = "/rui";
SMARTBUFF_InitSpellIDs();
--DEFAULT_CHAT_FRAME:AddMessage("SB OnLoad");
end
-- END SMARTBUFF_OnLoad
-- SMARTBUFF_OnEvent
function SMARTBUFF_OnEvent(self, event, ...)
local arg1, arg2, arg3, arg4 = ...;
if ((event == "UNIT_NAME_UPDATE" and arg1 == "player") or event == "PLAYER_ENTERING_WORLD") then
isPlayer = true;
if (event == "PLAYER_ENTERING_WORLD" and isInit and O.Toggle) then
isSetZone = true;
tStartZone = GetTime();
end
elseif(event == "ADDON_LOADED" and arg1 == SMARTBUFF_TITLE) then
isLoaded = true;
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 == "GROUP_ROSTER_UPDATE") then
isSetUnits = true;
elseif (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);
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);
--SMARTBUFF_SetButtonTexture(SmartBuff_KeyButton, imgSB);
--SMARTBUFF_AddMsgD("Leave combat, reset button");
end
SMARTBUFF_SyncBuffTimers();
SMARTBUFF_Check(1, true);
end
elseif (event == "PLAYER_TALENT_UPDATE") then
if(SmartBuffOptionsFrame:IsVisible()) then
SmartBuffOptionsFrame:Hide();
end
if (currentSpec ~= GetSpecialization()) then
currentSpec = GetSpecialization();
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;
--isAuraChanged = true;
--SMARTBUFF_AddMsgD("Aura changed: " .. arg1);
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
--SMARTBUFF_AddMsgD("Checking: " .. arg1);
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
--SMARTBUFF_AddMsgD(arg1 .. " is dazed, cancel " .. buff);
-- Deactivated for Cataclysm
--CancelUnitBuff("player", buff);
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 == "CHAT_MSG_SPELL_FAILED_LOCALPLAYER") then
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
SMARTBUFF_AddMsgWarn(UnitName(currentUnit).." ("..currentUnit..") blacklisted ("..O.BlacklistTimer.."sec)");
end
end
end
currentUnit = nil;
elseif (event == "UNIT_SPELLCAST_SUCCEEDED") then
--Fired when the client receives a message from SendAddonMessage
--arg1 "player"
--arg2 spell
--arg3 rank
--arg4 target
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: " .. arg1 .. ", " .. arg2 .. ", " .. arg3 .. ", " .. arg4)
if (string.find(arg1, "party") or string.find(arg1, "raid")) then
spell = arg2;
end
--SMARTBUFF_SetButtonTexture(SmartBuff_KeyButton, imgSB);
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
--if (not SMARTBUFF_IsPlayer(unit)) then
cBuffTimer[unit][spell] = GetTime();
--end
if (name ~= nil) then
SMARTBUFF_AddMsg(name .. ": " .. spell .. " " .. SMARTBUFF_MSG_BUFFED);
currentUnit = nil;
currentSpell = nil;
currentRank = nil;
end
end
if (isClearSplash) then
isClearSplash = false;
SMARTBUFF_Splash_Clear();
end
end
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();
_, tName = GetTalentInfo(1, 1, 1);
if (tName) then
SMARTBUFF_OnEvent(self, "SMARTBUFF_UPDATE");
end
end
else
if (isSetZone and GetTime() > (tStartZone + 4)) then
SMARTBUFF_CheckLocation();
end
SMARTBUFF_Ticker();
SMARTBUFF_Check(1);
end
end
function SMARTBUFF_Ticker(force)
if (force or GetTime() > tTicker + 1) then
tTicker = GetTime();
if (isSetUnits) then
isSetUnits = false;
SMARTBUFF_SetUnits();
isSyncReq = true;
end
if (isSyncReq or tTicker > tSync + 10) then
SMARTBUFF_SyncBuffTimers();
end
if (isAuraChanged) then
isAuraChanged = false;
--SMARTBUFF_AddMsgD("Force check");
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
-- Creates an array of units
function SMARTBUFF_SetUnits()
--if (not isInit or not O.Toggle) then return; end
if (InCombatLockdown()) then
isSetUnits = true;
return;
end
if (SmartBuffOptionsFrame:IsVisible()) then return; end
local i = 0;
local n = 0;
local j = 0;
local s = nil;
local psg = 0;
local b = false;
local iBFA = SMARTBUFF_IsActiveBattlefield();
if (iBFA > 0) then
SMARTBUFF_CheckLocation();
end
-- player
-- pet
-- party1-4
-- partypet1-4
-- raid1-40
-- raidpet1-40
iGroupSetup = -1;
if (IsInRaid()) then
iGroupSetup = 3;
elseif (GetNumSubgroupMembers() ~= 0) then
iGroupSetup = 2;
else
iGroupSetup = 1;
end
if (iGroupSetup ~= iLastGroupSetup) then
iLastGroupSetup = iGroupSetup;
wipe(cBlacklist);
wipe(cBuffTimer);
if (SMARTBUFF_TEMPLATES[iGroupSetup] == nil) then
SMARTBUFF_SetBuffs();
end
local tmp = SMARTBUFF_TEMPLATES[iGroupSetup];
if (O.AutoSwitchTemplate and currentTemplate ~= tmp and iBFA == 0) then
SMARTBUFF_AddMsg(SMARTBUFF_OFT_AUTOSWITCHTMP .. ": " .. currentTemplate .. " -> " .. tmp);
currentTemplate = tmp;
SMARTBUFF_SetBuffs();
end
SMARTBUFF_MiniGroup_Show();
--SMARTBUFF_AddMsgD("Group type changed");
end
wipe(cUnits);
wipe(cGroups);
cClassGroups = nil;
wipe(cAddUnitList);
wipe(cIgnoreUnitList);
-- Raid Setup
if (iGroupSetup == 3) then
cClassGroups = { };
local name, server, rank, subgroup, level, class, classeng, zone, online, isDead;
local sRUnit = nil;
j = 1;
for n = 1, maxRaid, 1 do
name, rank, subgroup, level, class, classeng, zone, online, isDead = GetRaidRosterInfo(n);
if (name) then
server = nil;
i = string.find(name, "-", 1, true);
if (i and i > 0) then
server = string.sub(name, i + 1);
name = string.sub(name, 1, i - 1);
SMARTBUFF_AddMsgD(name .. ", " .. server);
end
sRUnit = "raid"..n;
--SMARTBUFF_AddMsgD(name .. ", " .. sRUnit .. ", " .. UnitName(sRUnit));
SMARTBUFF_AddUnitToClass("raid", n);
SmartBuff_AddToUnitList(1, sRUnit, subgroup);
SmartBuff_AddToUnitList(2, sRUnit, subgroup);
if (name == sPlayerName and not server) then
psg = subgroup;
end
if (O.ToggleGrp[subgroup]) then
s = "";
if (name == UnitName(sRUnit)) then
if (cGroups[subgroup] == nil) then
cGroups[subgroup] = { };
end
if (name == sPlayerName and not server) then b = true; end
cGroups[subgroup][j] = sRUnit;
j = j + 1;
end
end
end
end --end for
if (not b or B[CS()][currentTemplate].SelfFirst) then
SMARTBUFF_AddSoloSetup();
iLastSubgroup = psg;
--SMARTBUFF_AddMsgD("Player not in selected groups or buff self first");
end
if (iLastSubgroup ~= psg) then
SMARTBUFF_AddMsgWarn(SMARTBUFF_TITLE .. ": " .. SMARTBUFF_MSG_SUBGROUP);
if (O.ToggleSubGrpChanged) then
O.ToggleGrp[psg] = true;
if (SmartBuffOptionsFrame:IsVisible()) then
SMARTBUFF_ShowSubGroupsOptions();
else
SMARTBUFF_OptionsFrame_Open();
end
end
iLastSubgroup = psg;
end
SMARTBUFF_AddMsgD("Raid Unit-Setup finished");
-- Party Setup
elseif (iGroupSetup == 2) then
cClassGroups = { };
if (B[CS()][currentTemplate].SelfFirst) then
SMARTBUFF_AddSoloSetup();
--SMARTBUFF_AddMsgD("Buff self first");
end
cGroups[1] = { };
cGroups[1][0] = "player";
SMARTBUFF_AddUnitToClass("player", 0);
for j = 1, 4, 1 do
cGroups[1][j] = "party"..j;
SMARTBUFF_AddUnitToClass("party", j);
SmartBuff_AddToUnitList(1, "party"..j, 1);
SmartBuff_AddToUnitList(2, "party"..j, 1);
--SMARTBUFF_AddMsgD("Add party"..j, 0, 1, 0.5);
end
SMARTBUFF_AddMsgD("Party Unit-Setup finished");
-- Solo Setup
else
SMARTBUFF_AddSoloSetup();
SMARTBUFF_AddMsgD("Solo Unit-Setup finished");
end
--collectgarbage();
end
function SMARTBUFF_AddUnitToClass(unit, i)
local u = unit;
local up = "pet";
if (unit ~= "player") then
u = unit..i;
up = unit.."pet"..i;
end
if (UnitExists(u)) then
if (not cUnits[1]) then
cUnits[1] = { };
end
cUnits[1][i] = u;
SMARTBUFF_AddMsgD("Unit added: " .. UnitName(u) .. ", " .. u);
local _, uc = UnitClass(u);
if (uc and not cClassGroups[uc]) then
cClassGroups[uc] = { };
end
if (uc) then
cClassGroups[uc][i] = u;
end
--SMARTBUFF_AddMsgD("Unit added: " .. UnitName(u) .. ", " .. u);
if (uc and uc == "HUNTER") then
if (not cClassGroups["HPET"]) then
cClassGroups["HPET"] = { };
end
cClassGroups["HPET"][i] = up;
--if (UnitExists(up)) then
--SMARTBUFF_AddMsgD("HPet added: " .. UnitName(up) .. ", " .. up);
--end
elseif (uc and uc == "DEATHKNIGHT") then
if (not cClassGroups["DKPET"]) then
cClassGroups["DKPET"] = { };
end
cClassGroups["DKPET"][i] = up;
--if (UnitExists(up)) then
--SMARTBUFF_AddMsgD("DKPet added: " .. UnitName(up) .. ", " .. up);
--end
elseif (uc and (uc == "WARLOCK" or uc == "MAGE")) then
if (not cClassGroups["WPET"]) then
cClassGroups["WPET"] = { };
end
cClassGroups["WPET"][i] = up;
--if (UnitExists(up)) then
--SMARTBUFF_AddMsgD("WPet added: " .. UnitName(up) .. ", " .. up);
--end
end
end
end
function SMARTBUFF_AddSoloSetup()
cGroups[0] = { };
cGroups[0][0] = "player";
cUnits[0] = { };