This repository was archived by the owner on Mar 1, 2026. It is now read-only.
forked from RubyGB/PallyPower
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPallyPower.lua
More file actions
1294 lines (1164 loc) · 46.7 KB
/
Copy pathPallyPower.lua
File metadata and controls
1294 lines (1164 loc) · 46.7 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
-- PallyPower (Vanilla 1.12) — Event-driven scanning version
-- Notes:
-- * Replaces periodic full raid scans with UNIT_AURA-driven incremental updates
-- * Rebuilds roster on roster/pet changes
-- * Uses BAG_UPDATE to refresh symbol count
-- * Debounces UI updates to avoid thrashing
local initalized = false
local clearTime = 0
local lastReqSent = 0
FiveMinuteBlessingOn = false
ppRefreshAfterClear = false
local TURTLE_REALMS = { Nordanaar=true, ["Tel'Abim"]=true, Ambershire=true }
local IS_TURTLE = TURTLE_REALMS[GetRealmName()] or false
local REGULAR_BLESSING_DURATION = IS_TURTLE and (10 * 60) or (5 * 60)
local GREATER_BLESSING_DURATION = IS_TURTLE and (30 * 60) or (15 * 60)
BINDING_HEADER_PALLYPOWER_HEADER = "Pally Power"
BINDING_NAME_TOGGLE = "Toggle Buff Bar"
BINDING_NAME_REPORT = "Report Assignments"
AllPallys = {}
PallyPower_Assignments = {}
PallyPower = {}
-- Global snapshot of buffs per class -> unit
CurrentBuffs = CurrentBuffs or {}
BlessingIcon = {}
BuffIcon = {}
PP_PerUser = {
scalemain = 1,
scalebar = 1,
scanfreq = 1, -- UI refresh interval in seconds
smartbuffs = 1,
chatfeedback = 1,
opacity = 0.5, -- frame backdrop alpha (0.0–1.0)
locked = false, -- lock frame positions (/pp lock)
}
-- === Event-driven state ===
local RosterUnits = {} -- array of unit ids (player, partyN, raidN, *petN)
local UnitClassID = {} -- map unit -> classID (0..9); pets use 9
local RosterSet = {} -- NEW: unit -> true for all valid units
local UnitAlias = {} -- maps "player" -> "raidN" (etc.) when in raid
local uiDirty = false -- mark UI needs refresh
local uiDebounce = 0 -- countdown timer for debounced refresh
-- Old fields kept for compatibility with existing code
LastCast = {}
LastCastOn = {}
PP_Symbols = 0
IsPally = 0
PP_PREFIX = "PLPWR"
local RestorSelfAutoCastTimeOut = 1
local RestorSelfAutoCast = false
-- Vanilla-safe helpers
local function table_wipe(t)
for k in pairs(t) do t[k] = nil end
end
local function PP_Debug(str)
if not str then str = "(nil)" end
if PP_DebugEnabled then
DEFAULT_CHAT_FRAME:AddMessage("[PP] " .. str, 1, 0, 0)
end
end
-- === Performance: cached state ===
-- Cached player name (set on first event, avoids repeated UnitName API calls)
local playerName
-- Reusable array for ScanOneUnit buff detection (avoids per-call allocation)
local scanHave = {false, false, false, false, false, false}
-- Cached UI frame references (populated lazily to avoid getglobal string lookups)
local BuffBarCache = {} -- [1..10] = { btn, classIcon, buffIcon, text, time, need, have, range, dead }
local PlayerFrameCache = {} -- [1..12] = { frame, name, symbols, icons[0..5], skills[0..5], classes[0..9] }
local function GetBuffBarEntry(n)
if not BuffBarCache[n] then
local prefix = "PallyPowerBuffBarBuff" .. n
BuffBarCache[n] = {
btn = getglobal(prefix),
classIcon = getglobal(prefix .. "ClassIcon"),
buffIcon = getglobal(prefix .. "BuffIcon"),
text = getglobal(prefix .. "Text"),
time = getglobal(prefix .. "Time"),
need = {},
have = {},
range = {},
dead = {},
}
end
return BuffBarCache[n]
end
local function GetPlayerFrameEntry(n)
if not PlayerFrameCache[n] then
local prefix = "PallyPowerFramePlayer" .. n
local entry = {
frame = getglobal(prefix),
name = getglobal(prefix .. "Name"),
symbols = getglobal(prefix .. "Symbols"),
icons = {},
skills = {},
classes = {},
}
for id = 0, 5 do
entry.icons[id] = getglobal(prefix .. "Icon" .. id)
entry.skills[id] = getglobal(prefix .. "Skill" .. id)
end
for id = 0, 9 do
entry.classes[id] = getglobal(prefix .. "Class" .. id .. "Icon")
end
PlayerFrameCache[n] = entry
end
return PlayerFrameCache[n]
end
-- Pre-allocated parts table for PallyPower_SendSelf string building
local sendSelfParts = {}
-- Track active LastCast entries to skip iteration when nothing is ticking
local LastCastCount = 0
-- Deferred roster rebuild to catch pets that load after PARTY_MEMBERS_CHANGED
local pendingRosterRebuild = 0
-- =========================
-- UI/Icon presets (unchanged)
-- =========================
function PallyPower_SwapIconsForFiveMin()
BlessingIcon[0] = "Interface\\Icons\\Spell_Holy_SealOfWisdom"
BlessingIcon[1] = "Interface\\Icons\\Spell_Holy_FistOfJustice"
BlessingIcon[2] = "Interface\\Icons\\Spell_Holy_SealOfSalvation"
BlessingIcon[3] = "Interface\\Icons\\Spell_Holy_PrayerOfHealing02"
BlessingIcon[4] = "Interface\\Icons\\Spell_Magic_MageArmor"
BlessingIcon[5] = "Interface\\Icons\\Spell_Nature_LightningShield"
BuffIcon[0] = "Interface\\Icons\\Spell_Holy_SealOfWisdom"
BuffIcon[1] = "Interface\\Icons\\Spell_Holy_FistOfJustice"
BuffIcon[2] = "Interface\\Icons\\Spell_Holy_SealOfSalvation"
BuffIcon[3] = "Interface\\Icons\\Spell_Holy_PrayerOfHealing02"
BuffIcon[4] = "Interface\\Icons\\Spell_Magic_MageArmor"
BuffIcon[5] = "Interface\\Icons\\Spell_Nature_LightningShield"
end
function PallyPower_SwapIconsForFifteenMin()
BlessingIcon[0] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofWisdom"
BlessingIcon[1] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofKings"
BlessingIcon[2] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofSalvation"
BlessingIcon[3] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofLight"
BlessingIcon[4] = "Interface\\Icons\\Spell_Magic_GreaterBlessingofKings"
BlessingIcon[5] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofSanctuary"
BuffIcon[0] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofWisdom"
BuffIcon[1] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofKings"
BuffIcon[2] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofSalvation"
BuffIcon[3] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofLight"
BuffIcon[4] = "Interface\\Icons\\Spell_Magic_GreaterBlessingofKings"
BuffIcon[5] = "Interface\\Icons\\Spell_Holy_GreaterBlessingofSanctuary"
end
-- =========================
-- Load / Events / Update
-- =========================
function PallyPower_OnLoad()
this:RegisterEvent("SPELLS_CHANGED")
this:RegisterEvent("PLAYER_ENTERING_WORLD")
this:RegisterEvent("PLAYER_LOGIN")
this:RegisterEvent("CHAT_MSG_ADDON")
this:RegisterEvent("CHAT_MSG_COMBAT_FRIENDLY_DEATH")
-- Roster + aura + pet + bags (event-driven scanning)
this:RegisterEvent("RAID_ROSTER_UPDATE")
this:RegisterEvent("PARTY_MEMBERS_CHANGED")
this:RegisterEvent("UNIT_AURA")
this:RegisterEvent("UNIT_PET")
this:RegisterEvent("BAG_UPDATE")
this:SetBackdropColor(0,0,0,PP_PerUser.opacity)
this:SetScale(1)
SlashCmdList["PALLYPOWER"] = function(msg) PallyPower_SlashCommandHandler(msg) end
if not PP_PerUser.quietmode then
DEFAULT_CHAT_FRAME:AddMessage("PallyPower for TurtleWoW version "..(PallyPower_Version or "?").." |cff00FF00loaded successfully!|r")
end
end
local function PruneCurrentBuffs()
-- Drop units no longer in roster set
for classId, bucket in pairs(CurrentBuffs) do
for unit in pairs(bucket) do
if unit ~= "_mask" and not RosterSet[unit] then
bucket[unit] = nil
end
end
-- if a class bucket becomes empty, remove it
local hasAny = false
for _ in pairs(bucket) do hasAny = true; break end
if not hasAny then CurrentBuffs[classId] = nil end
end
end
local function RebuildRoster()
-- reset
for k in pairs(RosterUnits) do RosterUnits[k] = nil end
for k in pairs(UnitClassID) do UnitClassID[k] = nil end
for k in pairs(RosterSet) do RosterSet[k] = nil end
for k in pairs(UnitAlias) do UnitAlias[k] = nil end
local function addUnit(u, classId)
if UnitExists(u) then
table.insert(RosterUnits, u)
UnitClassID[u] = classId
RosterSet[u] = true
end
end
if GetNumRaidMembers() > 0 then
-- raid: raidN already includes the player, so no separate "player" entry
for i=1, GetNumRaidMembers() do
local u = "raid"..i
local up = "raidpet"..i
addUnit(u, PallyPower_GetClassID(UnitClass(u)))
addUnit(up, 9)
-- Map "player"/"pet" aliases so UNIT_AURA for "player" resolves correctly
if UnitIsUnit(u, "player") then
UnitAlias["player"] = u
UnitAlias["pet"] = up
end
end
elseif GetNumPartyMembers() > 0 then
-- party: partyN does NOT include the player, so add them separately
addUnit("player", PallyPower_GetClassID(UnitClass("player")))
addUnit("pet", 9)
for i=1, GetNumPartyMembers() do
local u = "party"..i
local up = "partypet"..i
addUnit(u, PallyPower_GetClassID(UnitClass(u)))
addUnit(up, 9)
end
else
-- solo
addUnit("player", PallyPower_GetClassID(UnitClass("player")))
addUnit("pet", 9)
end
end
local function IsRosterUnit(unit)
return UnitClassID[unit] ~= nil
end
-- Compact paladin-relevant buff snapshot for one unit
local function ScanOneUnit(unit)
local classID = UnitClassID and UnitClassID[unit]
if not classID or classID < 0 then return end
if not UnitExists(unit) then return end
local name = UnitName(unit)
if not name or name == "" then return end
-- Reuse module-level scanHave array (no allocation)
scanHave[1] = false; scanHave[2] = false; scanHave[3] = false
scanHave[4] = false; scanHave[5] = false; scanHave[6] = false
local j = 1
while true do
local icon = UnitBuff(unit, j, true)
if not icon then break end
local id = PallyPower_GetBuffTextureID(icon)
if id >= 0 and id <= 5 then scanHave[id + 1] = true end
j = j + 1
end
-- Numeric mask (bit flags) — cheaper comparison than string
local mask = 0
if scanHave[1] then mask = mask + 1 end
if scanHave[2] then mask = mask + 2 end
if scanHave[3] then mask = mask + 4 end
if scanHave[4] then mask = mask + 8 end
if scanHave[5] then mask = mask + 16 end
if scanHave[6] then mask = mask + 32 end
CurrentBuffs[classID] = CurrentBuffs[classID] or {}
local entry = CurrentBuffs[classID][unit]
local vis = UnitIsVisible(unit) and true or false
if not entry then
-- First time seeing this unit: allocate entry
CurrentBuffs[classID][unit] = {
name = name, visible = vis,
[0] = scanHave[1], [1] = scanHave[2], [2] = scanHave[3],
[3] = scanHave[4], [4] = scanHave[5], [5] = scanHave[6],
_mask = mask
}
uiDirty = true
elseif entry._mask ~= mask or entry.visible ~= vis or entry.name ~= name then
-- Update in-place (no allocation)
entry.name = name
entry.visible = vis
entry[0] = scanHave[1]; entry[1] = scanHave[2]; entry[2] = scanHave[3]
entry[3] = scanHave[4]; entry[4] = scanHave[5]; entry[5] = scanHave[6]
entry._mask = mask
uiDirty = true
end
end
-- Backward-compatible function name (used elsewhere in the addon)
function PallyPower_ScanRaid()
if not PP_IsPally then return end
RebuildRoster()
for i = 1, table.getn(RosterUnits) do
ScanOneUnit(RosterUnits[i])
end
end
function PallyPower_OnUpdate(tdiff)
-- restore auto self-cast toggled for cast macro
if RestorSelfAutoCast then
RestorSelfAutoCastTimeOut = RestorSelfAutoCastTimeOut - tdiff
if RestorSelfAutoCastTimeOut < 0 then
RestorSelfAutoCast = false
SetCVar("autoSelfCast", "1")
end
end
-- countdowns for LastCast (skip iteration when nothing is ticking)
if LastCastCount > 0 then
local expiredKey = nil -- reuse single local for sequential removal
for i, k in LastCast do
k = k - tdiff
if k < 0 then
if expiredKey then
LastCast[expiredKey] = nil
LastCastCount = LastCastCount - 1
end
expiredKey = i
else
LastCast[i] = k
end
end
if expiredKey then
LastCast[expiredKey] = nil
LastCastCount = LastCastCount - 1
end
uiDirty = true -- ensure timer display refreshes at the scanfreq rate
end
-- Deferred roster rebuild (catches pets that load after party join)
if pendingRosterRebuild > 0 then
pendingRosterRebuild = pendingRosterRebuild - tdiff
if pendingRosterRebuild <= 0 then
pendingRosterRebuild = 0
RebuildRoster()
PruneCurrentBuffs()
for _, u in ipairs(RosterUnits) do ScanOneUnit(u) end
uiDirty = true
end
end
-- Debounced UI refresh
uiDebounce = uiDebounce - tdiff
if uiDirty and uiDebounce <= 0 then
uiDirty = false
uiDebounce = PP_PerUser.scanfreq
PallyPower_UpdateUI()
end
end
function PallyPower_OnEvent(event)
-- Cache player name on first event (avoids repeated API calls)
if not playerName then playerName = UnitName("player") end
if event == "SPELLS_CHANGED" or event == "PLAYER_ENTERING_WORLD" then
if UnitLevel("player") < 52 or FiveMinuteBlessingOn == true then
FiveMinBlessing = true
PallyPower_SwapIconsForFiveMin()
else
FiveMinBlessing = false
PallyPower_SwapIconsForFifteenMin()
end
PallyPower_UpdateUI()
PallyPower_ScanSpells()
-- initial roster+scan on world entry
if event == "PLAYER_ENTERING_WORLD" then
playerName = UnitName("player") -- refresh on world entry
if not PallyPower_Assignments[playerName] then
PallyPower_Assignments[playerName] = {}
if playerName == "Aznamir" then PP_DebugEnabled = true end
end
RebuildRoster()
PruneCurrentBuffs()
for i = 1, table.getn(RosterUnits) do ScanOneUnit(RosterUnits[i]) end
uiDirty = true
if IsPally == 1 and (GetNumRaidMembers() > 0 or GetNumPartyMembers() > 0) then
PallyPower_SendSelf()
PallyPower_RequestSend()
end
end
elseif event == "PLAYER_LOGIN" then
-- Merge defaults for keys added in newer versions (saved vars are now loaded)
local defaults = { opacity = 0.5, locked = false }
for k, v in pairs(defaults) do
if PP_PerUser[k] == nil then
PP_PerUser[k] = v
end
end
local lockVal = PP_PerUser.locked and 1 or 0
PallyPowerFrame.isLocked = lockVal
PallyPowerBuffBar.isLocked = lockVal
if PP_PerUser.locked then
PallyPowerFrameResizeButton:Hide()
PallyPowerBuffBarResizeButton:Hide()
end
PallyPower_ApplyOpacity()
PallyPower_UpdateUI()
elseif event == "CHAT_MSG_ADDON" and arg1 == PP_PREFIX and (arg3 == "PARTY" or arg3 == "RAID") then
PallyPower_ParseMessage(arg4, arg2)
elseif event == "CHAT_MSG_COMBAT_FRIENDLY_DEATH" then
-- no forced scan; UI will update on UNIT_AURA of the revived unit
elseif event == "RAID_ROSTER_UPDATE" or event == "PARTY_MEMBERS_CHANGED" then
RebuildRoster()
PruneCurrentBuffs()
for _, u in ipairs(RosterUnits) do ScanOneUnit(u) end
uiDirty = true
pendingRosterRebuild = 2 -- deferred rebuild to catch late-loading pets
if IsPally == 1 and (GetNumRaidMembers() > 0 or GetNumPartyMembers() > 0) then
PallyPower_SendSelf()
PallyPower_RequestSend()
end
elseif event == "UNIT_PET" then
RebuildRoster()
PruneCurrentBuffs() -- NEW
-- rescan owner + pet if present (resolve "player" -> "raidN" alias)
local owner = UnitAlias[arg1] or arg1
if owner then
local pet = (string.sub(owner,1,5)=="party") and ("partypet"..string.sub(owner,6))
or (string.sub(owner,1,4)=="raid" and ("raidpet"..string.sub(owner,5))
or "pet")
if UnitExists(owner) then ScanOneUnit(owner) end
if UnitExists(pet) then ScanOneUnit(pet) end
end
uiDirty = true
elseif event == "UNIT_AURA" then
local unit = UnitAlias[arg1] or arg1
if unit and IsRosterUnit(unit) then
ScanOneUnit(unit)
end
elseif event == "BAG_UPDATE" then
PallyPower_ScanInventory()
end
end
-- =========================
-- Commands / Report (unchanged)
-- =========================
function PallyPower_FiveMinuteBlessings()
local isChecked = FiveMinBlessingChk:GetChecked()
PP_Symbols = 0
FiveMinuteBlessingOn = (isChecked == 1)
ReloadUI()
end
function PallyPower_SlashCommandHandler(msg)
if msg == "debug" then
PP_DebugEnabled = not PP_DebugEnabled and true or nil
end
if msg == "report" then
PallyPower_Report()
return true
end
if msg == "lock" then
PP_PerUser.locked = not PP_PerUser.locked
local v = PP_PerUser.locked and 1 or 0
PallyPowerFrame.isLocked = v
PallyPowerBuffBar.isLocked = v
if PP_PerUser.locked then
PallyPowerFrameResizeButton:Hide()
PallyPowerBuffBarResizeButton:Hide()
else
PallyPowerFrameResizeButton:Show()
PallyPowerBuffBarResizeButton:Show()
end
DEFAULT_CHAT_FRAME:AddMessage("PallyPower: frames " .. (PP_PerUser.locked and "locked" or "unlocked"))
return
end
if PallyPowerFrame:IsVisible() then PallyPowerFrame:Hide() else PallyPowerFrame:Show() end
PallyPower_UpdateUI()
end
function PallyPower_Report()
if PallyPower_CanControl(playerName) then
local channel = (GetNumRaidMembers() > 0) and "RAID" or "PARTY"
PP_Debug(channel)
SendChatMessage(PallyPower_Assignments1, channel)
for name in AllPallys do
local blessings
local list = { [0]=0,[1]=0,[2]=0,[3]=0,[4]=0,[5]=0 }
for id = 0, 9 do
local bid = PallyPower_Assignments[name][id]
if bid >= 0 then list[bid] = list[bid] + 1 end
end
for id = 0, 5 do
if list[id] > 0 then
blessings = blessings and (blessings .. ", ") or ""
blessings = blessings .. PallyPower_BlessingID[id]
end
end
if not blessings then blessings = "Nothing" end
SendChatMessage(name .. ": " .. blessings, channel)
PP_Debug(name .. ": " .. blessings)
end
SendChatMessage(PallyPower_Assignments2, channel)
end
end
-- =========================
-- UI helpers (mostly unchanged)
-- =========================
function PallyPower_FormatTime(time)
if not time or time < 0 then return "" end
local mins = floor(time / 60)
local secs = time - (mins * 60)
return string.format("%d:%02d", mins, secs)
end
function PallyPowerGrid_Update()
if not initalized then
if not PP_PerUser.quietmode then
DEFAULT_CHAT_FRAME:AddMessage("[PallyPower] rerunning scan")
end
PallyPower_ScanSpells()
end
local i = 1
local numPallys = 0
if PallyPowerFrame:IsVisible() then
PallyPowerFrame:SetScale(PP_PerUser.scalemain)
for name, skills in AllPallys do
local pf = GetPlayerFrameEntry(i)
pf.name:SetText(name)
pf.symbols:SetText(skills["symbols"])
pf.symbols:SetTextColor(1, 1, 0.5)
if (PallyPower_CanControl(name)) then
pf.name:SetTextColor(1, 1, 1)
else
if (PallyPower_CheckRaidLeader(name)) then
pf.name:SetTextColor(0, 1, 0)
else
pf.name:SetTextColor(1, 0, 0)
end
end
for id = 0, 5 do
if (skills[id]) then
pf.icons[id]:Show()
pf.skills[id]:Show()
local txt = skills[id]["rank"]
if (skills[id]["talent"] + 0 > 0) then
txt = txt .. "+" .. skills[id]["talent"]
end
pf.skills[id]:SetText(txt)
else
pf.icons[id]:Hide()
pf.skills[id]:Hide()
end
end
for id = 0, 9 do
if (PallyPower_Assignments[name]) then
pf.classes[id]:SetTexture(BlessingIcon[PallyPower_Assignments[name][id]])
else
pf.classes[id]:SetTexture(nil)
end
end
i = i + 1
numPallys = numPallys + 1
end
PallyPowerFrame:SetHeight(14 + 24 + 56 + (numPallys * 56) + 22)
for j = 1, 12 do
local pf = GetPlayerFrameEntry(j)
if j <= numPallys then pf.frame:Show() else pf.frame:Hide() end
end
end
end
function PallyPower_UpdateUI()
if not initalized then PallyPower_ScanSpells() end
PallyPowerBuffBar:SetScale(PP_PerUser.scalebar)
local _, eclass = UnitClass("player")
if eclass == "PALADIN" then IsPally = 1 else PallyPowerBuffBar:Hide() end
if (IsPally == 1) or (GetNumRaidMembers() > 0 and GetNumPartyMembers() > 0) then
PallyPowerBuffBar:Show()
PallyPowerBuffBarTitleText:SetText(format(PallyPower_BuffBarTitle, PP_Symbols))
local BuffNum = 1
if PallyPower_Assignments[playerName] then
local assign = PallyPower_Assignments[playerName]
for class = 0, 9 do
if (assign[class] and assign[class] ~= -1 and CurrentBuffs[class]) then
local bc = GetBuffBarEntry(BuffNum)
bc.classIcon:SetTexture(PallyPower_ClassTexture[class])
bc.buffIcon:SetTexture(BlessingIcon[assign[class]])
local btn = bc.btn
btn.classID = class
btn.buffID = assign[class]
btn.need = {}; btn.have = {}; btn.range = {}; btn.dead = {}
local nneed, nhave, ndead = 0, 0, 0
if CurrentBuffs[class] then
for unit, stats in CurrentBuffs[class] do
if stats["visible"] then
if not stats[assign[class]] then
if UnitIsDeadOrGhost(unit) then
ndead = ndead + 1; tinsert(btn.dead, stats["name"])
else
nneed = nneed + 1; tinsert(btn.need, stats["name"])
end
else
tinsert(btn.have, stats["name"]); nhave = nhave + 1
end
else
tinsert(btn.range, stats["name"]); nhave = nhave + 1
end
end
end
if ndead > 0 then
bc.text:SetText(nneed .. " (" .. ndead .. ")")
else
bc.text:SetText(nneed)
end
if (nhave > 0) then
bc.time:SetText(PallyPower_FormatTime(LastCast[assign[class] .. class]))
btn.showTimer = true
else
bc.time:SetText("")
btn.showTimer = false
end
if (nhave == 0) then
btn:SetBackdropColor(1.0, 0.0, 0.0, PP_PerUser.opacity)
elseif (nneed > 0) then
btn:SetBackdropColor(1.0, 1.0, 0.5, PP_PerUser.opacity)
else
btn:SetBackdropColor(0.0, 0.0, 0.0, PP_PerUser.opacity)
end
btn:Show()
BuffNum = BuffNum + 1
end
end
end
for rest = BuffNum, 10 do
local bc = GetBuffBarEntry(rest)
bc.btn:Hide()
end
PallyPowerBuffBar:SetHeight(30 + (34 * (BuffNum - 1)))
end
end
-- =========================
-- Spell/Inventory scanning (minor edits)
-- =========================
function PallyPower_ScanSpells()
local RankInfo = {}
local i = 1
while true do
local spellName, spellRank = GetSpellName(i, BOOKTYPE_SPELL)
local spellTexture = GetSpellTexture(i, BOOKTYPE_SPELL)
if not spellName then break end
if not spellRank or spellRank == "" then spellRank = PallyPower_Rank1 end
local _, _, bless = string.find(spellName, PallyPower_BlessingSpellSearch)
if bless then
local tmp_str = string.find(spellName, "Greater")
local wantGreater = (FiveMinBlessing ~= true)
if (wantGreater and tmp_str == 1) or ((not wantGreater) and (tmp_str ~= 1)) then
for id, name in PallyPower_BlessingID do
if name == bless then
local _, _, rank = string.find(spellRank, PallyPower_RankSearch)
if not (RankInfo[id] and spellRank < RankInfo[id]["rank"]) then
RankInfo[id] = { rank = rank, id = i, name = name, talent = 0 }
end
end
end
end
end
i = i + 1
end
local numTabs = GetNumTalentTabs()
for t = 1, numTabs do
local numTalents = GetNumTalents(t)
for ti = 1, numTalents do
local nameTalent, _, _, _, currRank = GetTalentInfo(t, ti)
if string.find(nameTalent, PallyPower_BlessingTalentSearch) then
for id = 0, 1 do -- wis, might
if RankInfo[id] then RankInfo[id]["talent"] = currRank end
end
end
end
end
local _, class = UnitClass("player")
if class == "PALADIN" then
AllPallys[playerName] = RankInfo
if initalized then PallyPower_SendSelf() end
PP_IsPally = true
else
PP_Debug("I'm not a paladin?? " .. class)
PP_IsPally = nil
end
initalized = true
PallyPower_ScanInventory()
end
function PallyPower_ScanInventory()
if not PP_IsPally then return end
PP_Debug("Scanning for symbols")
local oldcount = PP_Symbols
PP_Symbols = 0
for bag = 0, 4 do
local slots = GetContainerNumSlots(bag)
if slots then
for slot = 1, slots do
local link = GetContainerItemLink(bag, slot)
if link and string.find(link, PallyPower_Symbol) then
local _, count = GetContainerItemInfo(bag, slot)
PP_Symbols = PP_Symbols + (count or 0)
end
end
end
end
if PP_Symbols ~= oldcount then
PallyPower_SendMessage("SYMCOUNT " .. PP_Symbols)
end
AllPallys[playerName] = AllPallys[playerName] or {}
AllPallys[playerName]["symbols"] = PP_Symbols
end
-- =========================
-- Messaging / Assignments (unchanged)
-- =========================
function PallyPower_RequestSend()
if GetTime() - lastReqSent < 5 then return end
lastReqSent = GetTime()
PallyPower_SendMessage("REQ")
end
function PallyPower_SendSelf()
if not initalized then PallyPower_ScanSpells() end
if not AllPallys[playerName] then return end
-- Build message with reusable parts table (avoids 21+ string concatenations)
table_wipe(sendSelfParts)
local n = 0
n = n + 1; sendSelfParts[n] = "SELF "
local RankInfo = AllPallys[playerName]
for id = 0, 5 do
if not RankInfo[id] then
n = n + 1; sendSelfParts[n] = "nn"
else
n = n + 1; sendSelfParts[n] = RankInfo[id]["rank"]
n = n + 1; sendSelfParts[n] = RankInfo[id]["talent"]
end
end
n = n + 1; sendSelfParts[n] = "@"
local assign = PallyPower_Assignments[playerName]
for id = 0, 9 do
if not assign or not assign[id] or assign[id] == -1 then
n = n + 1; sendSelfParts[n] = "n"
else
n = n + 1; sendSelfParts[n] = assign[id]
end
end
PallyPower_SendMessage(table.concat(sendSelfParts))
PallyPower_SendMessage("SYMCOUNT " .. PP_Symbols)
end
function PallyPower_SendMessage(msg)
if GetNumRaidMembers() == 0 then
SendAddonMessage(PP_PREFIX, msg, "PARTY", playerName)
else
SendAddonMessage(PP_PREFIX, msg, "RAID", playerName)
end
end
-- Restores clearing of all assignments for self or by leader
function PallyPower_Clear(fromupdate, who)
-- who = the player requesting the clear (defaults to you)
if not who then
who = playerName
end
for name, skills in PallyPower_Assignments do
if (PallyPower_CheckRaidLeader(who) or name == who) then
if not PP_PerUser.quietmode then
if name == who then
DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8080 PallyPower|r -- |cffFFFF00Clearing...|r")
else
-- rate-limit the "leader cleared" message
if (clearTime + 5) < GetTime() then
clearTime = GetTime()
DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8080 PallyPower|r -- |cffFFFF00Clearing as requested by leader: |r"..who)
end
end
end
-- set all classes to -1 (unassigned)
if PallyPower_Assignments[name] then
for class in PallyPower_Assignments[name] do
PallyPower_Assignments[name][class] = -1
end
end
ppRefreshAfterClear = true
end
end
-- Do a clean refresh (event-driven: rebuild roster snapshot, UI, symbols, and re-sync)
PallyPower_Refresh()
-- If this wasn’t triggered by a network message, broadcast CLEAR
if not fromupdate then
PallyPower_SendMessage("CLEAR")
end
end
function PallyPower_ParseMessage(sender, msg)
if sender == playerName then return end
if msg == "REQ" then
PallyPower_SendSelf()
end
if string.find(msg, "^SELF") then
AllPallys[sender] = {}
local _, _, numbers, assign = string.find(msg, "SELF ([0-9n]*)@?([0-9n]*)")
for id = 0, 5 do
local rank = string.sub(numbers, id * 2 + 1, id * 2 + 1)
local talent = string.sub(numbers, id * 2 + 2, id * 2 + 2)
if rank ~= "n" then
AllPallys[sender][id] = { rank = rank, talent = talent }
end
end
-- Only adopt remote assignments on first contact (no local data yet)
if not PallyPower_Assignments[sender] or not next(PallyPower_Assignments[sender]) then
PallyPower_Assignments[sender] = PallyPower_Assignments[sender] or {}
if assign and assign ~= "" then
for id = 0, 9 do
local tmp = string.sub(assign, id + 1, id + 1)
if tmp == "n" or tmp == "" then tmp = -1 end
PallyPower_Assignments[sender][id] = (tmp + 0)
end
end
end
uiDirty = true
end
if string.find(msg, "^ASSIGN") then
local _, _, name, class, skill = string.find(msg, "^ASSIGN (.*) (.*) (.*)")
if (name ~= sender) and (not PallyPower_CheckRaidLeader(sender)) then return end
PallyPower_Assignments[name] = PallyPower_Assignments[name] or {}
class = class + 0; skill = skill + 0
PallyPower_Assignments[name][class] = skill
uiDirty = true
end
if string.find(msg, "^MASSIGN") then
local _, _, name, skill = string.find(msg, "^MASSIGN (.*) (.*)")
if (name ~= sender) and (not PallyPower_CheckRaidLeader(sender)) then return end
PallyPower_Assignments[name] = PallyPower_Assignments[name] or {}
skill = skill + 0
for class = 0, 9 do PallyPower_Assignments[name][class] = skill end
uiDirty = true
end
if string.find(msg, "^SYMCOUNT ([0-9]*)") then
local _, _, count = string.find(msg, "^SYMCOUNT ([0-9]*)")
if AllPallys[sender] then
AllPallys[sender]["symbols"] = count
else
PallyPower_RequestSend()
end
end
if string.find(msg, "^CLEAR") then
PallyPower_Clear(true, sender)
end
end
-- =========================
-- Misc/UI wiring (unchanged)
-- =========================
function PallyPower_ShowCredits()
GameTooltip:SetOwner(this, "ANCHOR_TOPLEFT")
GameTooltip:SetText(PallyPower_Credits1, 1, 1, 1)
GameTooltip:AddLine(PallyPower_Credits2)
GameTooltip:AddLine(PallyPower_Credits3)
GameTooltip:AddLine(PallyPower_Credits4)
GameTooltip:AddLine(PallyPower_Credits5)
GameTooltip:AddLine(PallyPower_Credits6, 0, 1, 0)
GameTooltip:Show()
end
function PallyPowerFrame_MouseDown(arg1)
if (((not PallyPowerFrame.isLocked) or (PallyPowerFrame.isLocked == 0)) and (arg1 == "LeftButton")) then
PallyPowerFrame:StartMoving(); PallyPowerFrame.isMoving = true
end
end
function PallyPowerFrame_MouseUp()
if (PallyPowerFrame.isMoving) then
PallyPowerFrame:StopMovingOrSizing(); PallyPowerFrame.isMoving = false
end
end
function PallyPowerBuffBar_MouseDown(arg1)
if (((not PallyPowerBuffBar.isLocked) or (PallyPowerBuffBar.isLocked == 0)) and (arg1 == "LeftButton")) then
PallyPowerBuffBar:StartMoving(); PallyPowerBuffBar.isMoving = true
PallyPowerBuffBar.startPosX = PallyPowerBuffBar:GetLeft()
PallyPowerBuffBar.startPosY = PallyPowerBuffBar:GetTop()
end
end
function PallyPowerBuffBar_MouseUp()
if (PallyPowerBuffBar.isMoving) then
PallyPowerBuffBar:StopMovingOrSizing(); PallyPowerBuffBar.isMoving = false
end
if abs(PallyPowerBuffBar.startPosX - PallyPowerBuffBar:GetLeft()) < 2 and abs(PallyPowerBuffBar.startPosY - PallyPowerBuffBar:GetTop()) < 2 then
PallyPowerFrame:Show(); uiDirty = true
end
end
function PallyPowerGridButton_OnLoad(btn) end
function PallyPowerGridButton_OnLeave(btn) end
function PallyPowerGridButton_OnEnter(btn) end
function PallyPowerGridButton_OnClick(btn, mouseBtn)
local _, _, pnum, class = string.find(btn:GetName(), "PallyPowerFramePlayer(.+)Class(.+)")
pnum = pnum + 0; class = class + 0
local pname = GetPlayerFrameEntry(pnum).name:GetText()
if not PallyPower_CanControl(pname) then return end
if mouseBtn == "RightButton" then
PallyPower_Assignments[pname][class] = -1
uiDirty = true
PallyPower_SendMessage("ASSIGN " .. pname .. " " .. class .. " -1")
else
PallyPower_PerformCycle(pname, class)
end
end
function PallyPower_PerformCycleBackwards(name, class)
local shift = IsShiftKeyDown()
if shift then class = 4 end
local cur = (PallyPower_Assignments[name][class] or 6)
if cur == -1 then cur = 6 end
PallyPower_Assignments[name][class] = -1
for test = cur - 1, -1, -1 do
cur = test
if PallyPower_CanBuff(name, test) and (PallyPower_NeedsBuff(class, test) or shift) then break end
end
if shift then
for test = 0, 9 do PallyPower_Assignments[name][test] = cur end
PallyPower_SendMessage("MASSIGN " .. name .. " " .. cur)
else
PallyPower_Assignments[name][class] = cur
PallyPower_SendMessage("ASSIGN " .. name .. " " .. class .. " " .. cur)
end
uiDirty = true
end
function PallyPower_PerformCycle(name, class)
local shift = IsShiftKeyDown()
if shift then class = 4 end
local cur = PallyPower_Assignments[name][class] or -1
PallyPower_Assignments[name][class] = -1
for test = cur + 1, 6 do
if PallyPower_CanBuff(name, test) and (PallyPower_NeedsBuff(class, test) or shift) then
cur = test; break
end
end
if cur == 6 then cur = -1 end
if shift then
for test = 0, 9 do PallyPower_Assignments[name][test] = cur end
PallyPower_SendMessage("MASSIGN " .. name .. " " .. cur)
else
PallyPower_Assignments[name][class] = cur
PallyPower_SendMessage("ASSIGN " .. name .. " " .. class .. " " .. cur)