forked from AznamirWoW/PallyPower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPallyPower.lua
4374 lines (4130 loc) · 140 KB
/
PallyPower.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
PallyPower = LibStub("AceAddon-3.0"):NewAddon("PallyPower", "AceConsole-3.0", "AceEvent-3.0", "AceBucket-3.0", "AceTimer-3.0")
PallyPower.isVanilla = (_G.WOW_PROJECT_ID == _G.WOW_PROJECT_CLASSIC)
PallyPower.isBCC = (_G.WOW_PROJECT_ID == _G.WOW_PROJECT_BURNING_CRUSADE_CLASSIC)
PallyPower.isWrath = (_G.WOW_PROJECT_ID == _G.WOW_PROJECT_WRATH_CLASSIC)
local L = LibStub("AceLocale-3.0"):GetLocale("PallyPower")
local LSM3 = LibStub("LibSharedMedia-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local LUIDDM = LibStub("LibUIDropDownMenu-4.0")
local LCD = (PallyPower.isVanilla) and LibStub("LibClassicDurations", true)
local UnitAura = LCD and LCD.UnitAuraWrapper or UnitAura
local tinsert = table.insert
local tremove = table.remove
local twipe = table.wipe
local tsort = table.sort
local strfind = string.find
local strsub = string.sub
local format = string.format
local WisdomPallys, MightPallys, KingsPallys, SalvPallys, LightPallys, SancPallys = {}, {}, {}, {}, {}, {}
local classlist, classes = {}, {}
PallyPower.player = UnitName("player")
PallyPower_Talents = {}
PallyPower_Assignments = {}
PallyPower_NormalAssignments = {}
PallyPower_AuraAssignments = {}
AllPallys = {}
SyncList = {}
PP_DebugEnabled = false
local initialized = false
local isPally = false
PP_Symbols = 0
PP_Leader = false
PP_LeaderSalv = false
-- unit tables
local party_units = {}
local raid_units = {}
local leaders = {}
local roster = {}
local raidmaintanks = {}
local classmaintanks = {}
local raidmainassists = {}
local lastMsg = ""
local prevBuffDuration
do
table.insert(party_units, "player")
table.insert(party_units, "pet")
for i = 1, MAX_PARTY_MEMBERS do
table.insert(party_units, ("party%d"):format(i))
end
for i = 1, MAX_PARTY_MEMBERS do
table.insert(party_units, ("partypet%d"):format(i))
end
for i = 1, MAX_RAID_MEMBERS do
table.insert(raid_units, ("raid%d"):format(i))
end
for i = 1, MAX_RAID_MEMBERS do
table.insert(raid_units, ("raidpet%d"):format(i))
end
end
PallyPower.Credits1 = "PallyPower - by Aznamir (Lightbringer US)"
PallyPower.Credits2 = "Updated for Classic by Dyaxler, Es, gallantron, and Zid"
function PallyPower:Debug(s)
if (PP_DebugEnabled) then
DEFAULT_CHAT_FRAME:AddMessage("[PP] " .. tostring(s), 1, 0, 0)
end
end
-------------------------------------------------------------------
-- Ace Framework Events
-------------------------------------------------------------------
function PallyPower:OnInitialize()
if select(2, UnitClass("player")) == "PALADIN" then
self.db = LibStub("AceDB-3.0"):New("PallyPowerDB", PALLYPOWER_DEFAULT_VALUES, "Default")
else
self.db = LibStub("AceDB-3.0"):New("PallyPowerDB", PALLYPOWER_OTHER_VALUES, "Other")
self.db:SetProfile("Other")
end
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
self.opt = self.db.profile
self.options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
LibStub("AceConfig-3.0"):RegisterOptionsTable("PallyPower", self.options, {"pp", "pallypower"})
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("PallyPower", "PallyPower")
LSM3:Register("background", "None", "Interface\\Tooltips\\UI-Tooltip-Background")
LSM3:Register("background", "Banto", "Interface\\AddOns\\PallyPower\\Skins\\Banto")
LSM3:Register("background", "BantoBarReverse", "Interface\\AddOns\\PallyPower\\Skins\\BantoBarReverse")
LSM3:Register("background", "Glaze", "Interface\\AddOns\\PallyPower\\Skins\\Glaze")
LSM3:Register("background", "Gloss", "Interface\\AddOns\\PallyPower\\Skins\\Gloss")
LSM3:Register("background", "Healbot", "Interface\\AddOns\\PallyPower\\Skins\\Healbot")
LSM3:Register("background", "oCB", "Interface\\AddOns\\PallyPower\\Skins\\oCB")
LSM3:Register("background", "Smooth", "Interface\\AddOns\\PallyPower\\Skins\\Smooth")
self.zone = GetRealZoneText()
self:ScanInventory()
self:CreateLayout()
if self.opt.skin then
self:ApplySkin(self.opt.skin)
end
self.AutoBuffedList = {}
self.PreviousAutoBuffedUnit = nil
self.menuFrame = LUIDDM:Create_UIDropDownMenu("PallyPowerMenuFrame", UIParent)
if not PallyPowerConfigFrame then
local ConfigFrame = AceGUI:Create("Frame")
ConfigFrame:EnableResize(false)
LibStub("AceConfigDialog-3.0"):SetDefaultSize("PallyPower", 625, 580)
LibStub("AceConfigDialog-3.0"):Open("PallyPower", ConfigFrame)
ConfigFrame:Hide()
_G["PallyPowerConfigFrame"] = ConfigFrame.frame
table.insert(UISpecialFrames, "PallyPowerConfigFrame")
end
self.MinimapIcon = LibStub("LibDBIcon-1.0")
self.LDB =
LibStub("LibDataBroker-1.1"):NewDataObject(
"PallyPower",
{
["type"] = "data source",
["text"] = "PallyPower",
["icon"] = "Interface\\AddOns\\PallyPower\\Icons\\SummonChampion",
["OnTooltipShow"] = function(tooltip)
if self.opt.ShowTooltips then
tooltip:SetText(PALLYPOWER_NAME)
tooltip:AddLine(L["MINIMAP_ICON_TOOLTIP"])
tooltip:Show()
end
end,
["OnClick"] = function(_, button)
if (button == "LeftButton") then
PallyPowerBlessings_Toggle()
else
self:OpenConfigWindow()
end
end
}
)
self.MinimapIcon:Register("PallyPower", self.LDB, self.opt.minimap)
C_Timer.After(
2.0,
function()
PallyPowerMinimapIcon_Toggle()
end
)
if self.isVanilla then
LCD:Register("PallyPower")
end
-- the transition from TBC Classic to Wrath Classic has caused some errors for players with SavedVariables values intended for the 2.5.4 clients and earlier
if self.isWrath and not self.opt.WrathTransition then
PallyPower:Purge()
self.opt.WrathTransition = true
end
if not PallyPower_SavedPresets then
PallyPower_SavedPresets = {}
PallyPower_SavedPresets["PallyPower_Assignments"] = {[0] = {}}
PallyPower_SavedPresets["PallyPower_NormalAssignments"] = {[0] = {}}
PallyPower_SavedPresets["PallyPower_AuraAssignments"] = {[0] = {}}
end
local h = _G["PallyPowerFrame"]
h:ClearAllPoints()
h:SetPoint("CENTER", "UIParent", "CENTER", self.opt.display.offsetX, self.opt.display.offsetY)
end
function PallyPower:OnEnable()
isPally = select(2, UnitClass("player")) == "PALADIN"
self.opt.enable = true
self:ScanTalents()
self:ScanSpells()
self:ScanCooldowns()
self:RegisterEvent("CHAT_MSG_ADDON")
self:RegisterEvent("ZONE_CHANGED")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:RegisterEvent("GROUP_JOINED")
self:RegisterEvent("GROUP_LEFT")
self:RegisterEvent("PLAYER_ROLES_ASSIGNED")
self:RegisterEvent("UPDATE_BINDINGS", "BindKeys")
self:RegisterEvent("CHANNEL_UI_UPDATE", "ReportChannels")
self:RegisterBucketEvent("SPELLS_CHANGED", 1, "SPELLS_CHANGED")
self:RegisterBucketEvent("PLAYER_ENTERING_WORLD", 2, "PLAYER_ENTERING_WORLD")
self:RegisterBucketEvent({"GROUP_ROSTER_UPDATE", "PLAYER_REGEN_ENABLED", "UNIT_PET", "UNIT_AURA"}, 1, "UpdateRoster")
self:RegisterBucketEvent({"GROUP_ROSTER_UPDATE"}, 1, "UpdateAllPallys")
if isPally then
self:ScheduleRepeatingTimer(self.ScanInventory, 60, self)
self.ButtonsUpdate(self)
end
self:BindKeys()
self:UpdateRoster()
end
function PallyPower:OnDisable()
self.opt.enable = false
for i = 1, PALLYPOWER_MAXCLASSES do
classlist[i] = 0
classes[i] = {}
end
self:UpdateRoster()
self.auraButton:Hide()
self.rfButton:Hide()
self.autoButton:Hide()
PallyPowerAnchor:Hide()
self:UnbindKeys()
self:UnregisterAllEvents()
self:UnregisterAllBuckets()
end
function PallyPower:OnProfileChanged()
self.opt = self.db.profile
self:UpdateLayout()
end
function PallyPower:BindKeys()
local key1 = GetBindingKey("AUTOKEY1")
local key2 = GetBindingKey("AUTOKEY2")
if key1 then
SetOverrideBindingClick(self.autoButton, false, key1, "PallyPowerAuto", "Hotkey1")
end
if key2 then
SetOverrideBindingClick(self.autoButton, false, key2, "PallyPowerAuto", "Hotkey2")
end
end
function PallyPower:UnbindKeys()
ClearOverrideBindings(self.autoButton)
end
-------------------------------------------------------------------
-- Config Window Functionality
-------------------------------------------------------------------
function PallyPower:Purge()
PallyPower_Assignments = nil
PallyPower_NormalAssignments = nil
PallyPower_AuraAssignments = nil
PallyPower_Assignments = {}
PallyPower_NormalAssignments = {}
PallyPower_AuraAssignments = {}
PallyPower_SavedPresets = nil
end
function PallyPower:Reset()
if InCombatLockdown() then return end
local h = _G["PallyPowerFrame"]
h:ClearAllPoints()
h:SetPoint("CENTER", "UIParent", "CENTER", self.opt.display.offsetX, self.opt.display.offsetY)
self.opt.buffscale = 0.9
self.opt.border = "Blizzard Tooltip"
self.opt.layout = "Layout 2"
self.opt.skin = "Smooth"
local c = _G["PallyPowerBlessingsFrame"]
c:ClearAllPoints()
c:SetPoint("CENTER", "UIParent", "CENTER", 0, 0)
self.opt.configscale = 0.9
self:ApplySkin()
self:UpdateLayout()
end
function PallyPower:OpenConfigWindow()
if PallyPowerBlessingsFrame:IsVisible() then
PallyPowerBlessingsFrame:Hide()
LUIDDM:CloseDropDownMenus()
end
if not PallyPowerConfigFrame:IsShown() then
PallyPowerConfigFrame:Show()
PlaySound(SOUNDKIT.IG_SPELLBOOK_OPEN)
else
PallyPowerConfigFrame:Hide()
PlaySound(SOUNDKIT.IG_SPELLBOOK_CLOSE)
end
end
local function tablecopy(tbl)
if type(tbl) ~= "table" then return tbl end
local t = {}
for i,v in pairs(tbl) do
t[i] = tablecopy(v)
end
return t
end
local function safeget(t,k) -- always return nil or t[k] if at least t is a table / Treeston
return t and t[k]
end
function PallyPowerBlessings_Clear()
if InCombatLockdown() then return end
if GetNumGroupMembers() > 0 and PallyPower:CheckLeader(PallyPower.player) then
PallyPower:ClearAssignments(PallyPower.player)
PallyPower:SendMessage("CLEAR")
elseif GetNumGroupMembers() > 0 and not PallyPower:CheckLeader(PallyPower.player) then
for leadername in pairs(leaders) do
if not IsGuildMember(leadername) or PP_Leader == false then
PallyPower:ClearAssignments(PallyPower.player)
PallyPower:SendSelf()
end
end
else
PallyPower:ClearAssignments(PallyPower.player)
end
PallyPower:UpdateLayout()
PallyPower:UpdateRoster()
end
function PallyPowerBlessings_Refresh()
PallyPower:Debug("PallyPowerBlessings_Refresh")
PallyPower:ScanSpells()
PallyPower:ScanCooldowns()
PallyPower:ScanInventory()
if GetNumGroupMembers() > 0 then
PallyPower:SendSelf()
PallyPower:SendMessage("REQ")
end
PallyPower:UpdateLayout()
PallyPower:UpdateRoster()
end
function PallyPowerBlessings_Toggle()
if PallyPower.configFrame and PallyPower.configFrame:IsShown() then
PallyPower.configFrame:Hide()
end
if PallyPowerBlessingsFrame:IsVisible() then
PallyPowerBlessingsFrame:Hide()
LUIDDM:CloseDropDownMenus()
PlaySound(SOUNDKIT.IG_SPELLBOOK_CLOSE)
else
local c = _G["PallyPowerBlessingsFrame"]
c:ClearAllPoints()
c:SetPoint("CENTER", "UIParent", "CENTER", 0, 0)
PallyPower:ScanSpells()
PallyPower:ScanCooldowns()
PallyPower:ScanInventory()
if GetNumGroupMembers() > 0 then
PallyPower:SendSelf()
PallyPower:SendMessage("REQ")
end
PallyPowerBlessingsFrame:Show()
PlaySound(SOUNDKIT.IG_SPELLBOOK_OPEN)
table.insert(UISpecialFrames, "PallyPowerBlessingsFrame")
end
end
function PallyPowerMinimapIcon_Toggle()
if (PallyPower.opt.minimap.show == false) then
PallyPower.MinimapIcon:Hide("PallyPower")
else
PallyPower.MinimapIcon:Show("PallyPower")
end
end
function PallyPowerBlessings_ShowCredits(self)
if PallyPower.opt.ShowTooltips then
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:SetText(PallyPower.Credits1, 1, 1, 1)
GameTooltip:AddLine(PallyPower.Credits2, 1, 1, 1)
GameTooltip:Show()
end
end
function GetNormalBlessings(pname, class, tname)
if PallyPower_NormalAssignments[pname] and PallyPower_NormalAssignments[pname][class] then
local blessing = PallyPower_NormalAssignments[pname][class][tname]
if blessing then
return tostring(blessing)
else
return "0"
end
end
end
function SetNormalBlessings(pname, class, tname, value)
if not PallyPower_NormalAssignments[pname] then
PallyPower_NormalAssignments[pname] = {}
end
if not PallyPower_NormalAssignments[pname][class] then
PallyPower_NormalAssignments[pname][class] = {}
end
if value == 0 then
value = nil
end
PallyPower_NormalAssignments[pname][class][tname] = value
local msgQueue
msgQueue =
C_Timer.NewTimer(
2.0,
function()
if PallyPower_NormalAssignments and PallyPower_NormalAssignments[pname] and PallyPower_NormalAssignments[pname][class] and PallyPower_NormalAssignments[pname][class][tname] then
PallyPower:SendNormalBlessings(pname, class, tname)
PallyPower:UpdateLayout()
msgQueue:Cancel()
end
end
)
end
-- sends blessing to tname as previously set in PallyPower_NormalAssignments[pname]...
function PallyPower:SendNormalBlessings(pname, class, tname)
local value = safeget(safeget(safeget(PallyPower_NormalAssignments, pname), class), tname)
if value == nil then value = 0 end
self:SendMessage("NASSIGN " .. pname .. " " .. class .. " " .. tname .. " " .. value)
end
function PallyPowerGrid_NormalBlessingMenu(btn, mouseBtn, pname, class)
if InCombatLockdown() then return end
if (mouseBtn == "LeftButton") then
local menu = {}
local shortname = strsplit("%-", pname)
tinsert(menu, {text = "|cffffffff" .. shortname .. "|r " .. L["can be assigned"], isTitle = true, isNotRadio = true, notCheckable = 1})
tinsert(menu, {text = L["a Normal Blessing from:"], isTitle = true, isNotRadio = true, notCheckable = 1})
local pre, suf
for pally in pairs(AllPallys) do
local pallyMenu = {}
local control = PallyPower:CanControl(pally)
if not control then
pre = "|cff999999"
suf = "|r"
else
pre = ""
suf = ""
end
tinsert(pallyMenu, {
text = format("%s%s%s", pre, "(none)", suf),
checked = function() if GetNormalBlessings(pally, class, pname) == "0" then return true end end,
func = function() LUIDDM:CloseDropDownMenus(); SetNormalBlessings(pally, class, pname, 0) end
})
for index, blessing in ipairs(PallyPower.Spells) do
if PallyPower:CanBuff(pally, index) then
local unitID = PallyPower:GetUnitIdByName(pname)
if PallyPower:CanBuffBlessing(index, 0, unitID, true) then
tinsert(pallyMenu, {
text = format("%s%s%s", pre, blessing, suf),
checked = function() if GetNormalBlessings(pally, class, pname) == tostring(index) then return true end end,
func = function() LUIDDM:CloseDropDownMenus(); if control then SetNormalBlessings(pally, class, pname, index + 0) end end
})
end
end
end
local shortname = strsplit("%-", pally)
tinsert(menu, {
text = format("%s%s%s", pre, shortname, suf),
hasArrow = true,
menuList = pallyMenu,
checked = function()
if PallyPower_NormalAssignments[pally] and PallyPower_NormalAssignments[pally][class] and PallyPower_NormalAssignments[pally][class][pname] then
return true
else
SetNormalBlessings(pally, class, pname, 0)
end
end
})
end
tinsert(menu, {text = _G.CANCEL, func = function() end, isNotRadio = true, notCheckable = 1})
LUIDDM:EasyMenu(menu, PallyPower.menuFrame, "cursor", 0 , 0, "MENU")
elseif (mouseBtn == "RightButton") then
for pally in pairs(AllPallys) do
if PallyPower_NormalAssignments[pally] and PallyPower_NormalAssignments[pally][class] and PallyPower_NormalAssignments[pally][class][pname] then
PallyPower_NormalAssignments[pally][class][pname] = nil
end
PallyPower:SendNormalBlessings(pally, class, pname)
PallyPower:UpdateLayout()
end
end
end
function PallyPowerPlayerButton_OnClick(btn, mouseBtn)
if InCombatLockdown() then return end
local _, _, class, pnum = strfind(btn:GetName(), "PallyPowerBlessingsFrameClassGroup(.+)PlayerButton(.+)")
class = tonumber(class)
pnum = tonumber(pnum)
local pname = classes[class][pnum].name
PallyPowerGrid_NormalBlessingMenu(btn, mouseBtn, pname, class)
end
function PallyPowerPlayerButton_OnMouseWheel(btn, arg1)
if InCombatLockdown() then return end
local _, _, class, pnum = strfind(btn:GetName(), "PallyPowerBlessingsFrameClassGroup(.+)PlayerButton(.+)")
class = tonumber(class)
pnum = tonumber(pnum)
local pname = classes[class][pnum].name
PallyPower:PerformPlayerCycle(arg1, pname, class)
end
function PallyPowerGridButton_OnClick(btn, mouseBtn)
if InCombatLockdown() then return end
local _, _, pnum, class = strfind(btn:GetName(), "PallyPowerBlessingsFramePlayer(.+)Class(.+)")
class = tonumber(class)
pnum = tonumber(pnum)
local pname = _G["PallyPowerBlessingsFramePlayer" .. pnum .. "Name"]:GetText()
if not PallyPower:CanControl(pname) then
return false
end
if (mouseBtn == "RightButton") then
if PallyPower_Assignments and PallyPower_Assignments[pname] and PallyPower_Assignments[pname][class] then
PallyPower_Assignments[pname][class] = 0
end
PallyPower:SendMessage("ASSIGN " .. pname .. " " .. class .. " 0")
PallyPower:UpdateLayout()
else
PallyPower:PerformCycle(pname, class)
end
end
function PallyPowerGridButton_OnMouseWheel(btn, arg1)
if InCombatLockdown() then return end
local _, _, pnum, class = strfind(btn:GetName(), "PallyPowerBlessingsFramePlayer(.+)Class(.+)")
class = tonumber(class)
pnum = tonumber(pnum)
local pname = _G["PallyPowerBlessingsFramePlayer" .. pnum .. "Name"]:GetText()
if not PallyPower:CanControl(pname) then
return false
end
if (arg1 == -1) then --mouse wheel down
PallyPower:PerformCycle(pname, class)
else
PallyPower:PerformCycleBackwards(pname, class)
end
end
function PallyPowerBlessingsFrame_MouseUp()
if (PallyPowerBlessingsFrame.isMoving) then
PallyPowerBlessingsFrame:StopMovingOrSizing()
PallyPowerBlessingsFrame.isMoving = false
end
end
function PallyPowerBlessingsFrame_MouseDown(self, button)
if (((not PallyPowerBlessingsFrame.isLocked) or (PallyPowerBlessingsFrame.isLocked == 0)) and (button == "LeftButton")) then
PallyPowerBlessingsFrame:StartMoving()
PallyPowerBlessingsFrame:SetClampedToScreen(true)
PallyPowerBlessingsFrame.isMoving = true
end
end
function PallyPowerBlessingsGrid_Update(self, elapsed)
if not initialized then
return
end
if PallyPowerBlessingsFrame:IsVisible() then
local numPallys = 0
local numMaxClass = 0
for i = 1, PALLYPOWER_MAXCLASSES do
local fname = "PallyPowerBlessingsFrameClassGroup" .. i
_G[fname .. "ClassButtonIcon"]:SetTexture(PallyPower.ClassIcons[i])
for j = 1, PALLYPOWER_MAXPERCLASS do
local pbnt = fname .. "PlayerButton" .. j
if classes[i] and classes[i][j] then
local unit = classes[i][j]
if unit.name then
local shortname = Ambiguate(unit.name, "short")
if unit.unitid:find("pet") then
_G[pbnt .. "Text"]:SetText("|T132242:0|t "..shortname)
else
_G[pbnt .. "Text"]:SetText(shortname)
end
end
local normal, greater = PallyPower:GetSpellID(i, unit.name)
if normal ~= greater then
_G[pbnt .. "Icon"]:SetTexture(PallyPower.NormalBlessingIcons[normal])
else
_G[pbnt .. "Icon"]:SetTexture("")
end
_G[pbnt]:Show()
else
_G[pbnt]:Hide()
end
end
if classlist[i] then
numMaxClass = math.max(numMaxClass, classlist[i])
end
end
PallyPowerBlessingsFrame:SetScale(PallyPower.opt.configscale)
for i, name in pairs(SyncList) do
local fname = "PallyPowerBlessingsFramePlayer" .. i
local SkillInfo = AllPallys[name]
local BuffInfo = PallyPower_Assignments[name]
local NormalBuffInfo = PallyPower_NormalAssignments[name]
_G[fname .. "Name"]:SetText(name)
if PallyPower:CanControl(name) then
_G[fname .. "Name"]:SetTextColor(1, 1, 1)
else
if PallyPower:CheckLeader(name) then
_G[fname .. "Name"]:SetTextColor(0, 1, 0)
else
_G[fname .. "Name"]:SetTextColor(1, 0, 0)
end
end
_G[fname .. "Symbols"]:SetText(SkillInfo.symbols)
_G[fname .. "Symbols"]:SetTextColor(1, 1, 0.5)
for id = 1, PallyPower.isWrath and 4 or 6 do
if SkillInfo[id] then
_G[fname .. "Icon" .. id]:Show()
_G[fname .. "Skill" .. id]:Show()
local txt = SkillInfo[id].rank
if SkillInfo[id].talent and (SkillInfo[id].talent + 0 > 0) then
if PallyPower.isWrath and id > 2 then
txt = SkillInfo[id].talent
else
txt = txt .. "+" .. SkillInfo[id].talent
end
end
_G[fname .. "Skill" .. id]:SetText(txt)
else
_G[fname .. "Icon" .. id]:Hide()
_G[fname .. "Skill" .. id]:Hide()
end
end
if not AllPallys[name].AuraInfo then
AllPallys[name].AuraInfo = {}
end
local AuraInfo = AllPallys[name].AuraInfo
for id = 1, 3 do
if AuraInfo[id] then
_G[fname .. "AIcon" .. id]:Show()
_G[fname .. "ASkill" .. id]:Show()
local txt = AuraInfo[id].rank
if AuraInfo[id].talent and (AuraInfo[id].talent + 0 > 0) then
txt = txt .. "+" .. AuraInfo[id].talent
end
_G[fname .. "ASkill" .. id]:SetText(txt)
else
_G[fname .. "AIcon" .. id]:Hide()
_G[fname .. "ASkill" .. id]:Hide()
end
end
local aura = PallyPower_AuraAssignments[name]
if (aura and aura > 0) then
_G[fname .. "Aura1Icon"]:SetTexture(PallyPower.AuraIcons[aura])
else
_G[fname .. "Aura1Icon"]:SetTexture(nil)
end
if not AllPallys[name].CooldownInfo then
AllPallys[name].CooldownInfo = {}
end
local CooldownInfo = AllPallys[name].CooldownInfo
for id = 1, 2 do
if CooldownInfo[id] then
_G[fname .. "CIcon" .. id]:Show()
_G[fname .. "CSkill" .. id]:Show()
local txt
if CooldownInfo[id].start ~= 0 and CooldownInfo[id].duration ~= 0 then
CooldownInfo[id].text = PallyPower:FormatTime(CooldownInfo[id].start + CooldownInfo[id].duration - GetTime())
if CooldownInfo[id].start + CooldownInfo[id].duration - GetTime() < 1 then
CooldownInfo[id].text = "|cff00ff00Ready|r"
end
else
CooldownInfo[id].text = "|cff00ff00Ready|r"
end
if CooldownInfo[id].text then
txt = CooldownInfo[id].text
end
_G[fname .. "CSkill" .. id]:SetText(txt)
else
_G[fname .. "CIcon" .. id]:Hide()
_G[fname .. "CSkill" .. id]:Hide()
end
end
for id = 1, PALLYPOWER_MAXCLASSES do
if BuffInfo and BuffInfo[id] then
_G[fname .. "Class" .. id .. "Icon"]:SetTexture(PallyPower.BlessingIcons[BuffInfo[id]])
else
_G[fname .. "Class" .. id .. "Icon"]:SetTexture(nil)
end
local found
end
i = i + 1
numPallys = numPallys + 1
end
PallyPowerBlessingsFrame:SetHeight(14 + 24 + 56 + (numPallys * 100) + 22 + 13 * numMaxClass)
_G["PallyPowerBlessingsFramePlayer1"]:SetPoint("TOPLEFT", 8, -80 - 13 * numMaxClass)
for i = 1, PALLYPOWER_MAXCLASSES do
_G["PallyPowerBlessingsFrameClassGroup" .. i .. "Line"]:SetHeight(56 + 13 * numMaxClass)
end
_G["PallyPowerBlessingsFrameAuraGroup1Line"]:SetHeight(56 + 13 * numMaxClass)
for i = 1, PALLYPOWER_MAXPERCLASS do
local fname = "PallyPowerBlessingsFramePlayer" .. i
if i <= numPallys then
_G[fname]:Show()
else
_G[fname]:Hide()
end
end
PallyPowerBlessingsFrameFreeAssign:SetChecked(PallyPower.opt.freeassign)
end
end
function PallyPower_StartScaling(self, button)
if button == "RightButton" then
PallyPower.opt.configscale = 0.9
local c = _G["PallyPowerBlessingsFrame"]
c:ClearAllPoints()
c:SetPoint("CENTER", "UIParent", "CENTER", 0, 0)
PallyPowerBlessingsFrame:Show()
end
if button == "LeftButton" then
self:LockHighlight()
PallyPower.FrameToScale = self:GetParent()
PallyPower.ScalingWidth = self:GetParent():GetWidth() * PallyPower.FrameToScale:GetParent():GetEffectiveScale()
PallyPower.ScalingHeight = self:GetParent():GetHeight() * PallyPower.FrameToScale:GetParent():GetEffectiveScale()
PallyPowerScalingFrame:Show()
end
end
function PallyPower_StopScaling(self, button)
if button == "LeftButton" then
PallyPowerScalingFrame:Hide()
PallyPower.FrameToScale = nil
self:UnlockHighlight()
end
end
function PallyPower_ScaleFrame(scale)
local frame = PallyPower.FrameToScale
local oldscale = frame:GetScale() or 1
local framex = (frame:GetLeft() or PallyPowerPerOptions.XPos) * oldscale
local framey = (frame:GetTop() or PallyPowerPerOptions.YPos) * oldscale
frame:SetScale(scale)
if frame:GetName() == "PallyPowerBlessingsFrame" then
frame:SetClampedToScreen(true)
frame:SetPoint("TOPLEFT", "UIParent", "BOTTOMLEFT", framex / scale, framey / scale)
PallyPower.opt.configscale = scale
end
end
function PallyPower_ScalingFrame_Update(self, elapsed)
if not PallyPower.ScalingTime then
PallyPower.ScalingTime = 0
end
PallyPower.ScalingTime = PallyPower.ScalingTime + elapsed
if PallyPower.ScalingTime > 0.25 then
PallyPower.ScalingTime = 0
local frame = PallyPower.FrameToScale
local oldscale = frame:GetEffectiveScale()
local framex, framey, cursorx, cursory = frame:GetLeft() * oldscale, frame:GetTop() * oldscale, GetCursorPosition()
if PallyPower.ScalingWidth > PallyPower.ScalingHeight then
if (cursorx - framex) > 32 then
local newscale = (cursorx - framex) / PallyPower.ScalingWidth
if newscale < 0.5 then
PallyPower_ScaleFrame(0.5)
else
PallyPower_ScaleFrame(newscale)
end
end
else
if (framey - cursory) > 32 then
local newscale = (framey - cursory) / PallyPower.ScalingHeight
if newscale < 0.5 then
PallyPower_ScaleFrame(0.5)
else
PallyPower_ScaleFrame(newscale)
end
end
end
end
end
-------------------------------------------------------------------
-- Main Functionality
-------------------------------------------------------------------
function PallyPower:ReportChannels()
local channels = {GetChannelList()}
PallyPower_ChanNames = {}
PallyPower_ChanNames[0] = "None"
for i = 1, #channels / 3 do
local chanName = channels[i * 3 - 1]
if chanName ~= "LookingForGroup" and chanName ~= "General" and chanName ~= "Trade" and chanName ~= "LocalDefense" and chanName ~= "WorldDefense" and chanName ~= "GuildRecruitment" then
PallyPower_ChanNames[i] = chanName
end
end
return PallyPower_ChanNames
end
function PallyPower:Report(type, chanNum)
if not type then
if GetNumGroupMembers() > 0 then
if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) and IsInInstance() then
type = "INSTANCE_CHAT"
else
if IsInRaid() then
type = "RAID"
elseif IsInGroup(LE_PARTY_CATEGORY_HOME) then
type = "PARTY"
end
end
if self:CheckLeader(self.player) and type ~= "INSTANCE_CHAT" then
if #SyncList > 0 then
SendChatMessage(L["--- Paladin assignments ---"], type)
local list = {}
for name in pairs(AllPallys) do
local blessings
for i = 1, self.isWrath and 4 or 6 do
list[i] = 0
end
for id = 1, PALLYPOWER_MAXCLASSES do
local bid = PallyPower_Assignments[name][id]
if bid and bid > 0 then
list[bid] = list[bid] + 1
end
end
for id = 1, self.isWrath and 4 or 6 do
if (list[id] > 0) then
if (blessings) then
blessings = blessings .. ", "
else
blessings = ""
end
local spell = self.Spells[id]
blessings = blessings .. spell
end
end
if not (blessings) then
blessings = "Nothing"
end
SendChatMessage(name .. ": " .. blessings, type)
end
SendChatMessage(L["--- End of assignments ---"], type)
end
else
if type == "INSTANCE_CHAT" then
self:Print("Blessings Report is disabled in Battlegrounds.")
elseif type == "RAID" then
self:Print("You are not the raid leader or do not have raid assist.")
else
self:Print(ERR_NOT_LEADER)
end
end
else
if type == "RAID" then
self:Print(ERR_NOT_IN_RAID)
else
self:Print(ERR_NOT_IN_GROUP)
end
end
else
if ((type and (type ~= "INSTANCE_CHAT" or type ~= "RAID" or type ~= "PARTY")) and chanNum and (IsInRaid() or IsInGroup())) then
SendChatMessage(L["--- Paladin assignments ---"], type, nil, chanNum)
local list = {}
for name in pairs(AllPallys) do
local blessings
for i = 1, self.isWrath and 4 or 6 do
list[i] = 0
end
for id = 1, PALLYPOWER_MAXCLASSES do
local bid = PallyPower_Assignments[name][id]
if bid and bid > 0 then
list[bid] = list[bid] + 1
end
end
for id = 1, self.isWrath and 4 or 6 do
if (list[id] > 0) then
if (blessings) then
blessings = blessings .. ", "
else
blessings = ""
end
local spell = self.Spells[id]
blessings = blessings .. spell
end
end
if not (blessings) then
blessings = "Nothing"
end
SendChatMessage(name .. ": " .. blessings, type, nil, chanNum)
end
SendChatMessage(L["--- End of assignments ---"], type, nil, chanNum)
elseif not IsInGroup() then
self:Print(ERR_NOT_IN_GROUP)
elseif not IsInRaid() then
self:Print(ERR_NOT_IN_RAID)
end
end
end
function PallyPower:PerformCycle(name, class, skipzero)
local shift = (IsShiftKeyDown() and PallyPowerBlessingsFrame:IsMouseOver())
local control = (IsControlKeyDown() and PallyPowerBlessingsFrame:IsMouseOver())
local cur
if shift then
class = 5
end
if not PallyPower_Assignments[name] then
PallyPower_Assignments[name] = {}
end
if not PallyPower_Assignments[name][class] then
cur = 0
else
cur = PallyPower_Assignments[name][class]
end
PallyPower_Assignments[name][class] = 0
for testB = cur + 1, self.isWrath and 5 or 7 do
cur = testB
if self:CanBuff(name, testB) and (self:NeedsBuff(class, testB) or shift or control) then
do
break
end
end
end
if (self.isWrath and cur == 5) or (not self.isWrath and cur == 7) then
if skipzero then
if self:CanBuff(name, 1) then
if self.opt.SmartBuffs and (class == 1 or class == 2 or (self.isWrath and class == 10)) then
cur = 2
else
cur = 1
end
elseif self:CanBuff(name, 2) then
if self.opt.SmartBuffs and (class == 3 or (self.isVanilla and class == 6) or class == 7 or class == 8) then
cur = 1
else
cur = 2
end
end
else
cur = 0
end
end
if shift then
for testC = 1, PALLYPOWER_MAXCLASSES do
PallyPower_Assignments[name][testC] = cur
end
local msgQueue
msgQueue =
C_Timer.NewTimer(
2.0,
function()
self:SendMessage("MASSIGN " .. name .. " " .. PallyPower_Assignments[name][class])
self:UpdateLayout()
msgQueue:Cancel()
end
)
else
PallyPower_Assignments[name][class] = cur
local msgQueue
msgQueue =
C_Timer.NewTimer(
2.0,
function()
self:SendMessage("ASSIGN " .. name .. " " .. class .. " " .. PallyPower_Assignments[name][class])
self:UpdateLayout()
msgQueue:Cancel()
end
)
end
end
function PallyPower:PerformCycleBackwards(name, class, skipzero)
local shift = (IsShiftKeyDown() and PallyPowerBlessingsFrame:IsMouseOver())
local control = (IsControlKeyDown() and PallyPowerBlessingsFrame:IsMouseOver())
local cur
if shift then
class = 5
end
if name and not PallyPower_Assignments[name] then
PallyPower_Assignments[name] = {}
end