-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaladinBuffer.lua
More file actions
545 lines (463 loc) · 16.4 KB
/
PaladinBuffer.lua
File metadata and controls
545 lines (463 loc) · 16.4 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
--[[
Paladin Buffer, Mayen/Selari (Horde) from Illidan (US) PvP
]]
PaladinBuffer = LibStub("AceAddon-3.0"):NewAddon("PaladinBuffer", "AceEvent-3.0")
local L = PaladinBufferLocals
local playerName = UnitName("player")
local playerGUID
local raidUnits, petUnits, partyUnits, groupRoster, hasGroupRank, classList, talentData, freeAssign, guidMap = {}, {}, {}, {}, {}, {}, {}, {}, {}
local improved = {[GetSpellInfo(20244)] = {"wisdom", "gwisdom"}, [GetSpellInfo(20042)] = {"might", "gmight"}}
local blessingTypes = {["gmight"] = "greater", ["gwisdom"] = "greater", ["gkings"] = "greater", ["gsanct"] = "greater", ["might"] = "single", ["wisdom"] = "single", ["kings"] = "single", ["sanct"] = "single"}
local blessings = {["might"] = GetSpellInfo(56520), ["gmight"] = GetSpellInfo(48934), ["wisdom"] = GetSpellInfo(56521), ["gwisdom"] = GetSpellInfo(48938), ["sanct"] = GetSpellInfo(20911), ["gsanct"] = GetSpellInfo(25899), ["kings"] = GetSpellInfo(20217), ["gkings"] = GetSpellInfo(25898)}
local blacklist = {["WARRIOR"] = "gwisdom", ["ROGUE"] = "gwisdom", ["PRIEST"] = "gmight", ["MAGE"] = "gmight", ["DEATHKNIGHT"] = "gwisdom"}
local instanceType
function PaladinBuffer:OnInitialize()
self.defaults = {
profile = {
ppSupport = true,
requireLeader = false,
mergePets = false,
offline = false,
greaterbinding = "CTRL-1",
singleBinding = "CTRL-2",
scale = 1.0,
rangeThreshold = 1.0,
singleThreshold = 5,
greaterThreshold = 15,
blessings = {[playerName] = {}},
assignments = {[playerName] = {}},
inside = {["raid"] = true, ["party"] = true, ["none"] = true},
frame = {
enabled = true,
classes = true,
hideInCombat = true,
outOfGroup = false,
locked = false,
popout = true,
growUp = false,
scale = 1.0,
columns = 1,
popDirection = "LEFT",
border = {r = 0.75, g = 0.75, b = 0.75},
background = {r = 0, g = 0, b = 0},
needRebuff = {r = 0.70, g = 0.10, b = 0.10},
cantRebuff = {r = 0.80, g = 0.80, b = 0.10},
},
},
}
-- Initialize the DB
self.db = LibStub:GetLibrary("AceDB-3.0"):New("PaladinBufferDB", self.defaults)
self.db.RegisterCallback(self, "OnProfileChanged", "Reload")
self.db.RegisterCallback(self, "OnProfileCopied", "Reload")
self.db.RegisterCallback(self, "OnProfileReset", "Reload")
self.revision = tonumber(string.match("$Revision$", "(%d+)") or 1)
-- If they aren't a Paladin disable this mod
if( select(2, UnitClass("player")) ~= "PALADIN" ) then
PaladinBuffer.disabled = true
end
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("SPELLS_CHANGED", "ScanSpells")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
-- Load class list
for classToken in pairs(RAID_CLASS_COLORS) do
classList[classToken] = true
end
-- Save a list of unitids
for i=1, MAX_RAID_MEMBERS do
raidUnits[i] = "raid" .. i
petUnits[raidUnits[i]] = raidUnits[i] .. "pet"
end
for i=1, MAX_PARTY_MEMBERS do
partyUnits[i] = "party" .. i
petUnits[partyUnits[i]] = partyUnits[i] .. "pet"
end
-- So modules can access this data
self.classList = classList
self.blessings = blessings
self.blessingTypes = blessingTypes
self.improved = improved
self.talentData = talentData
self.raidUnits = raidUnits
self.partyUnits = partyUnits
self.groupRoster = groupRoster
self.freeAssign = freeAssign
self.blacklist = blacklist
self.petUnits = petUnits
self.guidMap = guidMap
end
-- Only call events if the mod is enabled
function PaladinBuffer:Enable()
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("RAID_ROSTER_UPDATE", "ScanGroup")
self:RegisterEvent("PARTY_MEMBERS_CHANGED", "ScanGroup")
self:RegisterEvent("UNIT_PET")
self:ScanGroup()
self:UpdateKeyBindings()
end
function PaladinBuffer:Disable()
self:UnregisterEvent("RAID_ROSTER_UPDATE")
self:UnregisterEvent("PARTY_MEMBERS_CHANGED")
self:UnregisterEvent("UNIT_PET")
self:UnregisterEvent("PLAYER_REGEN_DISABLED")
end
-- Do they have permission to assign us something?
function PaladinBuffer:HasPermission(name)
if( not PaladinBuffer.db.profile.requireLeader ) then
return true
end
return name and hasGroupRank[name] or false
end
-- Reset the players blessing assignments
function PaladinBuffer:ClearAssignments(caster)
if( self.db.profile.assignments[caster] ) then
for assignment in pairs(self.db.profile.assignments[caster]) do
self.db.profile.assignments[caster][assignment] = nil
end
self:SendMessage("PB_ASSIGNMENTS_UPDATED", caster)
end
end
-- Initialize the basic player data we need for them
local function setupPlayerData(caster)
local self = PaladinBuffer
local fire
if( not self.db.profile.assignments[caster] ) then
self.db.profile.assignments[caster] = {}
fire = true
end
if( not self.db.profile.blessings[caster] ) then
self.db.profile.blessings[caster] = {}
fire = true
end
end
-- Assign a Paladin to a specific assignment
function PaladinBuffer:AssignBlessing(caster, spellToken, assignment, skip)
setupPlayerData(caster)
-- Check if the blessing was already assigned, if so cancel it for the other person
if( spellToken and not classList[assignment] ) then
for name, assignments in pairs(PaladinBuffer.db.profile.assignments) do
if( name ~= caster and assignments[assignment] == spellToken ) then
assignments[assignment] = nil
end
end
end
self.db.profile.assignments[caster][assignment] = spellToken
if( not skip ) then
self:SendMessage("PB_ASSIGNMENTS_UPDATED", caster)
end
end
-- Mass assign everyone to this
function PaladinBuffer:MassAssignBlessing(caster, spellToken, skip)
setupPlayerData(caster)
-- Assign the player to doing the blessing on everyone in this class as long as it's not blacklisted
for classToken in pairs(classList) do
if( not blacklist[classToken] or blacklist[classToken] ~= spellToken ) then
self.db.profile.assignments[caster][classToken] = spellToken
end
end
-- Now check if someone else is already doing one of these blessings, if so unassign them
if( spellToken ) then
for name, assignments in pairs(PaladinBuffer.db.profile.assignments) do
if( name ~= caster ) then
for classToken, token in pairs(assignments) do
if( token == spellToken ) then
assignments[classToken] = nil
end
end
end
end
end
if( not skip ) then
self:SendMessage("PB_ASSIGNMENTS_UPDATED", caster)
end
end
-- Update assignment permissions
function PaladinBuffer:UpdatePermissions(caster, free)
freeAssign[caster] = free
end
-- Reset the talent data we have for them
function PaladinBuffer:ResetBlessingData(caster)
if( self.db.profile.blessings[caster] ) then
for k in pairs(self.db.profile.blessings[caster]) do
self.db.profile.blessings[caster][k] = nil
end
self:SendMessage("PB_SPELL_DATA", caster)
end
end
-- Set someone as having an improved blessing
function PaladinBuffer:SetBlessingData(caster, spellToken, rank, skip)
setupPlayerData(caster)
self.db.profile.blessings[caster][spellToken] = rank
if( not skip ) then
self:SendMessage("PB_SPELL_DATA", caster, spellToken, rank)
end
end
-- Clear assignments to people having none
function PaladinBuffer:ClearAllAssignments()
for name, data in pairs(self.db.profile.assignments) do
for target, val in pairs(data) do
data[target] = nil
end
self:SendMessage("PB_ASSIGNMENTS_UPDATED")
end
end
-- Remove a single persons assignment
function PaladinBuffer:RemovePlayerData(caster)
self.db.profile.assignments[caster] = nil
self.db.profile.blessings[caster] = nil
self:SendMessage("PB_ASSIGNMENTS_UPDATED", caster)
end
-- Remove the table completely, remove all assignments
function PaladinBuffer:ResetAllAssignments()
for name, assignments in pairs(self.db.profile.assignments) do
if( name ~= playerName ) then
self.db.profile.assignments[name] = nil
self.db.profile.blessings[name] = nil
end
end
self:SendMessage("PB_ASSIGNMENTS_UPDATED")
end
-- Scan what spells the player has
function PaladinBuffer:ScanSpells()
if( PaladinBuffer.disabled ) then
return
end
-- Reset what we have
for token in pairs(self.db.profile.blessings[playerName]) do
self.db.profile.blessings[playerName][token] = nil
end
-- Figure out what we know
for spellToken, spellName in pairs(blessings) do
local rank = select(2, GetSpellInfo(spellName))
if( rank ) then
rank = rank == "" and 1 or tonumber(string.match(rank, "(%d+)"))
self.db.profile.blessings[playerName][spellToken] = rank
self.foundSpells = true
else
self.db.profile.blessings[playerName][spellToken] = nil
end
end
-- Check and make sure the player can still cast a buff on there assignment
local fullUpdate
for assignedTo, token in pairs(self.db.profile.assignments[playerName]) do
if( not self.db.profile.blessings[playerName][token] ) then
self.db.profile.assignments[playerName][assignedTo] = nil
sendUpdate = true
end
end
-- Now scan talents for improvements
for tree=1, MAX_TALENT_TABS do
for talent=1, GetNumTalents(tree) do
local name, _, _, _, points, maxPoints = GetTalentInfo(tree, talent)
if( improved[name] ) then
for _, spellToken in pairs(improved[name]) do
talentData[spellToken] = maxPoints
-- This means, Rank 5 Greater Blessing of Wisdom with 2/2 Improved Blessing of Wisdom is 5.2
-- meaning we can do a direct compare out of this table to find who has the highest rank + improvements
-- AND if we have to we can string split by the decimal and get the rank/improved! win/win
if( type(self.db.profile.blessings[playerName][spellToken]) == "number" ) then
self.db.profile.blessings[playerName][spellToken] = self.db.profile.blessings[playerName][spellToken] + (points / 10)
end
end
end
end
end
-- Send updated blessing update
if( not self.isLoggingIn and ( GetNumRaidMembers() > 0 or GetNumPartyMembers() > 0 ) ) then
if( fullUpdate ) then
self.modules.Sync:SendAssignments()
self:SendMessage("PB_ASSIGNMENTS_UPDATED")
else
self.modules.Sync:SendBlessingData()
end
end
self:SendMessage("PB_SPELL_DATA")
end
-- Update the rosters pet info
function PaladinBuffer:UNIT_PET(event, unit)
if( UnitExists(petUnits[unit]) ) then
groupRoster[unit] = petUnits[unit]
guidMap[UnitGUID(unit)] = unit
else
groupRoster[unit] = nil
end
end
local function loadUnit(unit)
local name = UnitName(unit)
groupRoster[name] = unit
local pet = petUnits[unit]
if( UnitExists(pet) ) then
groupRoster[unit] = pet
guidMap[UnitGUID(pet)] = pet
end
end
-- Raid roster was updated, reload it
function PaladinBuffer:ScanGroup()
-- Reset data from previous scan
for k in pairs(groupRoster) do groupRoster[k] = nil end
for k in pairs(hasGroupRank) do hasGroupRank[k] = nil end
for k in pairs(guidMap) do guidMap[k] = nil end
-- Player always has rank
groupRoster[playerName] = "player"
hasGroupRank[playerName] = true
guidMap[playerGUID] = "player"
-- Left raid :(
if( GetNumRaidMembers() == 0 and GetNumPartyMembers() == 0 ) then
self:ResetAllAssignments()
self:SendMessage("PB_ROSTER_UPDATED")
return
end
-- Scan raid
for i=1, GetNumRaidMembers() do
local name = UnitName(raidUnits[i])
if( select(2, GetRaidRosterInfo(i)) > 0 ) then
hasGroupRank[name] = true
end
if( name ~= playerName ) then
loadUnit(raidUnits[i])
end
end
-- Not in a raid, so scan party
if( GetNumRaidMembers() == 0 ) then
for i=1, GetNumPartyMembers() do
loadUnit(partyUnits[i])
hasGroupRank[UnitName(partyUnits[i])] = true
end
end
-- Remove data if the person left the raid
for name in pairs(PaladinBuffer.db.profile.blessings) do
if( not groupRoster[name] and name ~= playerName ) then
PaladinBuffer.db.profile.blessings[name] = nil
PaladinBuffer.db.profile.assignments[name] = nil
self:SendMessage("PB_RESET_ASSIGNMENTS", name)
end
end
-- Trigger that the roster list was updated
self:SendMessage("PB_ROSTER_UPDATED")
end
-- Entering the world for the first time, might need to do some setup
function PaladinBuffer:PLAYER_ENTERING_WORLD()
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
playerGUID = UnitGUID("player")
if( GetNumRaidMembers() > 0 or GetNumPartyMembers() > 0 ) then
self:ScanGroup()
else
groupRoster[playerName] = "player"
guidMap[playerGUID] = "player"
hasGroupRank[playerName] = true
end
self.isLoggingIn = true
self:ZONE_CHANGED_NEW_AREA()
self:ScanSpells()
self:UpdateKeyBindings()
self.isLoggingIn = false
end
function PaladinBuffer:ZONE_CHANGED_NEW_AREA()
local type = select(2, IsInInstance())
if( type ~= instanceType ) then
if( self.db.profile.inside[type] ) then
-- Enable main
self:Enable()
-- Enable modules
self.isEnabled = true
for _, module in pairs(self.modules) do
if( module.Enable ) then
module:Enable()
end
end
else
-- Disable main
self:Disable()
-- Disable modules
self.isEnabled = nil
for _, module in pairs(self.modules) do
if( module.Disable ) then
module:Disable()
end
end
end
end
instanceType = type
end
-- We had a key binding update queued
function PaladinBuffer:PLAYER_REGEN_ENABLED()
self:UpdateKeyBindings()
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
end
-- Reset any set attributes on the smart functions
function PaladinBuffer:PLAYER_REGEN_DISABLED()
if( self.smartGreaterButton ) then
self.smartGreaterButton:SetAttribute("type", nil)
self.smartGreaterButton:SetAttribute("unit", nil)
self.smartGreaterButton:SetAttribute("spell", nil)
end
if( self.smartSingleButton ) then
self.smartSingleButton:SetAttribute("type", nil)
self.smartSingleButton:SetAttribute("unit", nil)
self.smartSingleButton:SetAttribute("spell", nil)
end
end
-- Update key bindings for the auto buffing
function PaladinBuffer:UpdateKeyBindings()
if( InCombatLockdown() ) then
self:RegisterEvent("PLAYER_REGEN_ENABLED")
return
end
-- Greater smart buffing
if( not self.smartGreaterButton ) then
self.smartGreaterButton = CreateFrame("Button", "PBSmartGreaterButton", nil, "SecureActionButtonTemplate")
self.smartGreaterButton:SetScript("PreClick", function(self)
if( not InCombatLockdown() and PaladinBuffer.isEnabled ) then
local type, unit, spell = PaladinBuffer.modules.BuffGUI:AutoBuffLowestGreater("ALL")
self:SetAttribute("type", type)
self:SetAttribute("unit", unit)
self:SetAttribute("spell", spell)
end
end)
end
if( self.db.profile.greaterBinding and self.db.profile.greaterBinding ~= "" ) then
SetOverrideBindingClick(self.smartGreaterButton, false, self.db.profile.greaterBinding, self.smartGreaterButton:GetName())
else
ClearOverrideBindings(self.smartGreaterButton)
end
-- Single smart buffing
if( not self.smartSingleButton ) then
self.smartSingleButton = CreateFrame("Button", "PBSmartSingleButton", nil, "SecureActionButtonTemplate")
self.smartSingleButton:SetScript("PreClick", function(self)
if( not InCombatLockdown() and PaladinBuffer.isEnabled ) then
local type, unit, spell = PaladinBuffer.modules.BuffGUI:AutoBuffLowestSingle("ALL")
self:SetAttribute("type", type)
self:SetAttribute("unit", unit)
self:SetAttribute("spell", spell)
end
end)
end
if( self.db.profile.singleBinding and self.db.profile.singleBinding ~= "" ) then
SetOverrideBindingClick(self.smartSingleButton, false, self.db.profile.singleBinding, self.smartSingleButton:GetName())
else
ClearOverrideBindings(self.smartSingleButton)
end
end
-- Random misc
function PaladinBuffer:Print(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cff33ff99Paladin Buffer|r: " .. msg)
end
function PaladinBuffer:Echo(msg)
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
local sentRequirements
function PaladinBuffer:Reload()
instanceType = nil
self:ZONE_CHANGED_NEW_AREA()
self:UpdateKeyBindings()
-- No sense in sending our leadership requirements if they didn't change
if( sentRequirements ~= PaladinBuffer.db.profile.requireLeader ) then
self.modules.Sync:SendLeaderRequirements()
sentRequires = PaladinBuffer.db.profile.requireLeader
end
-- Reload modules if needed
for _, module in pairs(self.modules) do
if( module.Reload ) then
module:Reload()
end
end
end