-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartBuff.lua
More file actions
4537 lines (3950 loc) · 152 KB
/
SmartBuff.lua
File metadata and controls
4537 lines (3950 loc) · 152 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
-- 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 = "v3.3e";
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";
BINDING_HEADER_SMARTBUFF = "SmartBuff";
SMARTBUFF_BOOK_TYPE_SPELL = "spell";
local O = nil; -- Options local
local B = nil; -- Buff settings local
local GlobalCd = 1.6;
local maxSkipCoolDown = 3;
local maxRaid = 40;
local maxBuffs = 36;
local maxCheckButtons = 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 isBuff_KirusSoV = false;
local isShapeshifted = false;
local sShapename = "";
local tStart = 0;
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 cAddUnitList = { };
local cIgnoreUnitList = { };
local cClasses = {"DRUID", "HUNTER", "MAGE", "PALADIN", "PRIEST", "ROGUE", "SHAMAN", "WARLOCK", "WARRIOR", "DEATHKNIGHT","HPET", "WPET", "DKPET"};
local cOrderClass = {0, "WARRIOR", "PRIEST", "DRUID", "PALADIN", "SHAMAN", "MAGE", "WARLOCK", "HUNTER", "ROGUE", "DEATHKNIGHT", "HPET", "WPET", "DKPET"};
local cOrderGrp = {0, 1, 2 , 3, 4 , 5 , 6, 7, 8, 9};
local cFonts = {"NumberFontNormal", "NumberFontNormalLarge", "NumberFontNormalHuge", "GameFontNormal", "GameFontNormalLarge", "GameFontNormalHuge", "ChatFontNormal", "SystemFont", "MailTextFontNormal", "QuestTitleFont"};
local currentUnit = nil;
local currentSpell = 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 DebugChatFrame = DEFAULT_CHAT_FRAME;
-- 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);
local function ChkS(text)
if (text == nil) then
text = "";
end
return text;
end
--[[
local CastHook = function (spellname, unit)
--local msg = "";
--table.foreach({...}, function(k,v) msg = msg .. k .. "=[" .. tostring(v) .."] "; end);
--DEFAULT_CHAT_FRAME:AddMessage("[Echo] " .. msg);
if (spellname and unit) then
DEFAULT_CHAT_FRAME:AddMessage("Spell hook: " .. spellname .. ", " .. unit);
end;
end;
local CastSpellHook = function (...)
local msg = "";
table.foreach({...}, function(k,v) msg = msg .. k .. "=[" .. tostring(v) .."] "; end);
DEFAULT_CHAT_FRAME:AddMessage("[Echo] " .. msg);
end;
]]--
local function CS()
if (currentSpec == nil) then
currentSpec = GetActiveTalentGroup();
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
-- for watching
SMARTBUFF_CGroups = cGroups
SMARTBUFF_cBuffs = cBuffs
-- SMARTBUFF_OnLoad
function SMARTBUFF_OnLoad(self)
self:RegisterEvent("ADDON_LOADED");
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("UNIT_NAME_UPDATE");
self:RegisterEvent("PARTY_MEMBERS_CHANGED");
self:RegisterEvent("RAID_ROSTER_UPDATE");
self:RegisterEvent("PLAYER_REGEN_ENABLED");
self:RegisterEvent("PLAYER_REGEN_DISABLED");
--self:RegisterEvent("PLAYER_TARGET_CHANGED");
self:RegisterEvent("PLAYER_TALENT_UPDATE");
self:RegisterEvent("LEARNED_SPELL_IN_TAB");
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_SENT");
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["SMARTBUFFRELOAD"] = function(msg) ReloadUI(); end;
SLASH_SMARTBUFFRELOAD1 = "/rui";
SMARTBUFF_InitSpellIDs();
--DEFAULT_CHAT_FRAME:AddMessage("SB OnLoad");
end
-- END SMARTBUFF_OnLoad
-- SMARTBUFF_OnEvent
function SMARTBUFF_OnEvent(self, event, arg1, arg2, arg3, arg4, arg5)
--DebugChatFrame:AddMessage(event);
if ((event == "UNIT_NAME_UPDATE" and arg1 == "player") or event == "PLAYER_ENTERING_WORLD") then
isPlayer = true;
if(tStart == 0) then
tStart = GetTime();
--DebugChatFrame:AddMessage("SB set start timer: " .. tStart);
--DebugChatFrame:AddMessage("SB channel name: " .. GetChannelName(1));
end
if (event == "PLAYER_ENTERING_WORLD" and isInit and O.Toggle) then
--SMARTBUFF_AddMsgD("Set zone");
isSetZone = true;
tStartZone = GetTime();
end
elseif(event == "ADDON_LOADED" and arg1 == SMARTBUFF_TITLE) then
--DebugChatFrame:AddMessage("SB loaded");
isLoaded = true;
end
if (isLoaded and isPlayer and not isInit and not InCombatLockdown()) then
if (event == "UPDATE_MOUSEOVER_UNIT" or event == "CHAT_MSG_CHANNEL" or (GetChannelName(1) > 0 and GetTime() > (tStart + 2)) or GetTime() > (tStart + 8)) then
--DebugChatFrame:AddMessage("SB timer: " .. GetTime());
--DebugChatFrame:AddMessage("SB channel name: " .. GetChannelName(1));
SMARTBUFF_Options_Init(self);
end
end
if (not isInit or SMARTBUFF_Options == nil) then
return;
end;
if (event == "PARTY_MEMBERS_CHANGED" or event == "RAID_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) 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("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 ~= 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 == "LEARNED_SPELL_IN_TAB" 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" or sPlayerClass == "HERO") 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);
if (SMARTBUFF_IsDebuffTexture(arg1, "Spell_Frost_Stun")) then
local _, _, buff = SMARTBUFF_CheckUnitBuffs("player", SMARTBUFF_AOTC, SMARTBUFF_AOTP, true);
if (buff) then
if (arg1 == "player" or (buff == SMARTBUFF_AOTP and SMARTBUFF_CheckUnitBuffs(arg1, SMARTBUFF_AOTP, nil, true) == nil)) then
--SMARTBUFF_AddMsgD(arg1 .. " is dazed, cancel " .. buff);
CancelUnitBuff("player", buff);
end
end
end
end
end
--[[
elseif (event == "CHAT_MSG_ADDON" and O.CTRASync) then
--Fired when the client receives a message from SendAddonMessage
--arg1 prefix
--arg2 message
--arg3 distribution type ("PARTY","RAID","GUILD" or "BATTLEGROUND")
--arg4 sender
if (not isCombat and arg1 == "CTRA" and arg3 == "RAID") then
local msg = arg2;
local dtype = arg3;
local sender = arg4;
if (string.find(msg, "^RN ")) then
--SMARTBUFF_AddMsgD(sender .. ": " .. msg);
local bdata = false;
local unit = nil;
local subgroup = nil;
local classeng = nil;
local uname = nil;
for sg = 1, 8, 1 do
if (cGroups[sg] ~= nil) then
for _, un in pairs(cGroups[sg]) do
if (un and UnitIsPlayer(un) and UnitName(un) == sender) then
_, classeng = UnitClass(un);
subgroup = sg;
unit = un;
bdata = true;
SMARTBUFF_AddMsgD(sender .. "(Grp " .. subgroup .. ", " .. unit .. ") data retrived");
break;
end
end
end
end
if (bdata) then
if (string.find(msg, "#")) then
local k = 0;
local v = nil;
local arr = SMARTBUFF_Split(msg, "#");
for _, v in pairs(arr) do
k = k + 1;
SMARTBUFF_AddMsgD(k .. ". " .. v);
SMARTBUFF_CTRASync(unit, subgroup, classeng, v);
end
else
SMARTBUFF_AddMsgD("1. " .. msg);
SMARTBUFF_CTRASync(unit, subgroup, classeng, msg);
end
end
end
end
end
]]--
--if (event == "PLAYER_TARGET_CHANGED") then
--[[
if (O.TargetSwitch) then
if (GetTime() > tAutoBuff + GlobalCd) then
tAutoBuff = GetTime();
--SMARTBUFF_Check(5);
end
end
]]--
if (event == "CHAT_MSG_SPELL_FAILED_LOCALPLAYER") then
SMARTBUFF_AddMsgD("Spell failed: " .. 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 == "UI_ERROR_MESSAGE") then
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;
end
end
if (isClearSplash) then
isClearSplash = false;
SMARTBUFF_Splash_Clear();
end
end
end
end
-- END SMARTBUFF_OnEvent
function SMARTBUFF_OnUpdate(self, elapsed)
if (not isInit) then
if (isLoaded and GetTime() > tAutoBuff + 0.5) then
tAutoBuff = GetTime();
SMARTBUFF_OnEvent(self, "SMARTBUFF_UPDATE");
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();
--SMARTBUFF_SyncBuffTimers();
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 SMARTBUFF_Options and O.Debug) then
DebugChatFrame:AddMessage(msg, r, g, b);
end
DebugMessage(msg);
end
function DebugMessage(msg, ...)
if (SMARTBUFF_Options and O.Debug) then
if ViragDevTool_AddData then
ViragDevTool_AddData({...}, "SmartBuff: "..msg);
end
end
end
function DebugMessageBreak()
if (SMARTBUFF_Options and O.Debug) then
if ViragDevTool_AddData then
ViragDevTool_AddData("");
end
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 (GetNumRaidMembers() ~= 0) then
iGroupSetup = 3;
elseif (GetNumPartyMembers() ~= 0) then
iGroupSetup = 2;
else
iGroupSetup = 1;
end
if (iGroupSetup ~= iLastGroupSetup) then
iLastGroupSetup = iGroupSetup;
cBlacklist = { };
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
cUnits = { };
cGroups = { };
cClassGroups = nil;
cAddUnitList = { };
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, GetNumRaidMembers(), 1 do
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;
--if (O.Debug) then s = "Add raid"..n .. ": " .. name .. "(" .. subgroup .. "/" .. class .. "/" .. classeng .. ")"; end
j = j + 1;
if (classeng == "HUNTER" or classeng == "WARLOCK" or classeng == "DEATHKNIGHT" or classeng == "MAGE") then
cGroups[subgroup][j] = "raidpet"..n;
--if (O.Debug) then s = s .. ", add raidpet"..n; end
j = j + 1;
end
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
--table.sort(cGroups);
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);
if (sPlayerClass == "HUNTER" or sPlayerClass == "WARLOCK" or sPlayerClass == "DEATHKNIGHT" or sPlayerClass == "MAGE" or sPlayerClass == "HERO") then
cGroups[1][9] = "pet";
end
for j = 1, 4, 1 do
cGroups[1][j] = "party"..j;
cGroups[1][j + 4] = "partypet"..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");
--table.sort(cGroups);
-- Solo Setup
else
SMARTBUFF_AddSoloSetup();
SMARTBUFF_AddMsgD("Solo Unit-Setup finished");
DebugMessage("Solo Unit-Setup finished", cGroups)
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] = { };
cUnits[0][0] = "player";
DebugMessage("SMARTBUFF_AddSoloSetup -> sPlayerClass", sPlayerClass)
DebugMessage("SMARTBUFF_AddSoloSetup -> test", sPlayerClass == "HUNTER" or sPlayerClass == "WARLOCK" or sPlayerClass == "DEATHKNIGHT" or sPlayerClass == "MAGE" or sPlayerClass == "HERO")
if (sPlayerClass == "HUNTER" or sPlayerClass == "WARLOCK" or sPlayerClass == "DEATHKNIGHT" or sPlayerClass == "MAGE" or sPlayerClass == "HERO") then
cGroups[0][1] = "pet";
DebugMessage("Adding a pet to the buff list", cGroups)
end
if (B[CS()][currentTemplate] and B[CS()][currentTemplate].SelfFirst) then
if (not cClassGroups) then
cClassGroups = { };
end
cClassGroups[0] = { };
cClassGroups[0][0] = "player";
end
end
-- END SMARTBUFF_SetUnits
-- Get Spell ID from spellbook
function SMARTBUFF_GetSpellID(spellname)
if (spellname) then
spellname = string.lower(spellname);
else
return nil;
end
local i = 0;
local id = nil;
local spellN;
while true do
i = i + 1;
spellN = GetSpellName(i, SMARTBUFF_BOOK_TYPE_SPELL);
--if (spellN) then SMARTBUFF_AddMsgD(spellN .. " found"); end
if (not spellN or string.lower(spellN) == spellname) then
break;
end
end
while (spellN ~= nil) do
id = i;
i = i + 1;
spellN = GetSpellName(i, SMARTBUFF_BOOK_TYPE_SPELL);
--if (spellN) then SMARTBUFF_AddMsgD(spellname .. " ID = " .. id); end
if (not spellN or string.lower(spellN) ~= spellname) then
break;
end
end
return id;
end
-- END SMARTBUFF_GetSpellID
-- Set the buff array
function SMARTBUFF_SetBuffs()
--if (not O.Toggle) then return; end
local n = 1;
local buff = nil;
local ct = currentTemplate;
if (B[CS()] == nil) then
B[CS()] = { };
end
SMARTBUFF_InitItemList();
SMARTBUFF_InitSpellList();
if (B[CS()][ct] == nil) then
B[CS()][ct] = { };
B[CS()][ct].SelfFirst = false;
end
-- update to 1.12c
if (B[CS()][ct].GrpBuffSize == nil) then
B[CS()][ct].GrpBuffSize = 4;
end
cBuffs = nil;
cBuffs = { };
cBuffIndex = { };
numBuffs = 0;
for _, buff in ipairs(SMARTBUFF_BUFFLIST) do
n = SMARTBUFF_SetBuff(buff, n);
end
for _, buff in ipairs(SMARTBUFF_WEAPON) do
n = SMARTBUFF_SetBuff(buff, n);
end
for _, buff in ipairs(SMARTBUFF_RACIAL) do
n = SMARTBUFF_SetBuff(buff, n);
end
for _, buff in ipairs(SMARTBUFF_TRACKING) do
n = SMARTBUFF_SetBuff(buff, n);
end
for _, buff in ipairs(SMARTBUFF_SCROLL) do
n = SMARTBUFF_SetBuff(buff, n);
end
for _, buff in ipairs(SMARTBUFF_FOOD) do
n = SMARTBUFF_SetBuff(buff, n);
end
for _, buff in ipairs(SMARTBUFF_POTION) do
n = SMARTBUFF_SetBuff(buff, n);
end
cBuffsCombat = { };
SMARTBUFF_SetInCombatBuffs();
numBuffs = n - 1;
isSetBuffs = false;
end
function SMARTBUFF_SetBuff(buff, i)
if (buff == nil or buff[1] == nil or i > maxCheckButtons) then return i; end
cBuffs[i] = nil;
cBuffs[i] = { };
cBuffs[i].BuffS = buff[1];
cBuffs[i].DurationS = ceil(buff[2] * 60);
cBuffs[i].Type = buff[3];
cBuffs[i].CanCharge = false;
cBuffs[i].IDS = SMARTBUFF_GetSpellID(cBuffs[i].BuffS);
if (cBuffs[i].IDS == nil and not (SMARTBUFF_IsItem(cBuffs[i].Type))) then
cBuffs[i] = nil;
return i;
end
if (cBuffs[i].IDS) then
cBuffs[i].IconS = GetSpellTexture(cBuffs[i].IDS, SMARTBUFF_BOOK_TYPE_SPELL);
else
local bag, slot, count, texture = SMARTBUFF_FindReagent(cBuffs[i].BuffS);
if (count == 0) then
cBuffs[i] = nil;
return i;
end
cBuffs[i].IconS = texture;
end
SMARTBUFF_AddMsgD("Add "..buff[1]);
if (buff[4] ~= nil) then cBuffs[i].LevelsS = buff[4]; else cBuffs[i].LevelsS = nil; end
if (buff[5] ~= nil) then cBuffs[i].Exclude = buff[5]; else cBuffs[i].Exclude = "x"; end
local ct = currentTemplate;
local name = cBuffs[i].BuffS;
if (B[CS()][ct][name] == nil) then
B[CS()][ct][name] = { };
B[CS()][ct][name].EnableS = false;
B[CS()][ct][name].EnableG = false;
B[CS()][ct][name].SelfOnly = false;
B[CS()][ct][name].SelfNot = false;
B[CS()][ct][name].CIn = false;
B[CS()][ct][name].COut = true;
B[CS()][ct][name].MH = false;
B[CS()][ct][name].OH = false;
B[CS()][ct][name].Reminder = true;
B[CS()][ct][name].RBTime = 0;