-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPurgeatory.lua
332 lines (294 loc) · 11.9 KB
/
Purgeatory.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
--[[
Purgeatory 3, Mayen of US-Mal'Ganis PvP
]]
Purgeatory = {}
local L = PurgeatoryLocals
local instanceType, arenaBracket
local summonedTotems = {}
local summonedObjects = {}
local old
function Purgeatory:OnInitialize()
self.defaults = {
profile = {
showIcon = true,
dispelSuccessMsg = "*spell",
dispelFailMsg = "FAILED *spell",
dispelColor = {r = 1, g = 1, b = 1},
dispelLocation = "rwframe",
interruptMsg = "*spell",
interruptColor = {r = 1, g = 1, b = 1},
interruptLocation = "rwframe",
reflectMsg = "Reflected *spell",
reflectColor = {r = 1, g = 1, b = 1},
reflectLocation = "rwframe",
groundingMsg = "Grounded *spell",
groundingColor = {r = 1, g = 1, b = 1},
groundingLocation = "rwframe",
zones = {
["none"] = {
enabled = true,
dispelOffensive = true,
dispelDefensive = true,
dispelFail = true,
interrupt = true,
reflect = true,
grounding = true,
},
["party"] = {
enabled = true,
dispelOffensive = true,
dispelDefensive = true,
dispelFail = true,
interrupt = true,
reflect = true,
grounding = true,
},
["raid"] = {
enabled = true,
dispelOffensive = true,
dispelDefensive = true,
dispelFail = true,
interrupt = true,
reflect = true,
grounding = true,
},
["arena"] = {
enabled = true,
dispelOffensive = true,
dispelDefensive = true,
dispelFail = true,
interrupt = true,
reflect = true,
grounding = true,
},
["pvp"] = {
enabled = true,
dispelOffensive = true,
dispelDefensive = true,
dispelFail = true,
interrupt = true,
reflect = true,
grounding = true,
},
["*"] = {
enabled = true,
dispelOffensive = true,
dispelDefensive = true,
dispelFail = true,
interrupt = true,
reflect = true,
grounding = true,
},
},
},
}
-- Initialize DB
self.db = LibStub:GetLibrary("AceDB-3.0"):New("PurgeatoryDB", self.defaults, true)
self.db.RegisterCallback(self, "OnProfileChanged", "Reload")
self.db.RegisterCallback(self, "OnProfileCopied", "Reload")
self.db.RegisterCallback(self, "OnProfileReset", "Reload")
end
local COMBATLOG_OBJECT_REACTION_HOSTILE = COMBATLOG_OBJECT_REACTION_HOSTILE
local COMBATLOG_OBJECT_AFFILIATION_MINE = COMBATLOG_OBJECT_AFFILIATION_MINE
function Purgeatory:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventType, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, ...)
local isHostile = bit.band(destFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE
--function Purgeatory:SendMessage(msg, spellID, spellName, usedSpellName, destName, dest, color)
if (eventType == "SPELL_CAST_START" and sourceName == UnitName("target")) then
local spellID, spellName, spellSchool = ...
if (spellName == "Penance") then
if (GetSpellCooldown("Kick") == 0) then
CastSpellByName("Kick");
end
end
elseif (eventType == "SPELL_CAST_SUCCESS" and destName == UnitName("player")) then
local spellID, spellName, spellSchool, extraSpellID, extraSpellName, extraSpellSchool = ...
if (spellName == "Blind" or spellName == "Psychic Horror" or spellName == "Hammer of Justice" or spellName == "Deep Freeze") then
if (GetSpellCooldown("Vanish") == 0) then
CastSpellByName("Vanish");
end
end
elseif (eventType == "SPELL_CAST_SUCCESS") then
local spellID, spellName, spellSchool, extraSpellID, extraSpellName, extraSpellSchool = ...
if (spellName == "Shadowfury" or spellName == "Hurlement de terreur") then
if (GetSpellCooldown("Vanish") == 0) then
CastSpellByName("Vanish");
elseif (GetSpellCooldown("Blind") == 0) then
CastSpellByName("Blind");
end
elseif (sourceName == UnitName("target") and (spellName == "PvP Trinket" or spellName == "Vanish" or spellName == "Every Man for Himself")) then
CastSpellByName("Blind");
end
end
-- We got interrupted, or we interrupted someone else
if( eventType == "SPELL_INTERRUPT" and self.db.profile.zones[instanceType].interrupt ) then
local spellID, spellName, spellSchool, extraSpellID, extraSpellName, extraSpellSchool = ...
if (bit.band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) > 0) then
self:SendMessage(self.db.profile.interruptMsg, extraSpellID, extraSpellName, spellName, destName, self.db.profile.interruptLocation, self.db.profile.interruptColor)
end
-- We tried to dispel a buff, and failed
elseif( eventType == "SPELL_DISPEL_FAILED" and self.db.profile.zones[instanceType].dispelFail and ( ( isHostile and self.db.profile.zones[instanceType].dispelOffensive ) or ( not isHostile and self.db.profile.zones[instanceType].dispelDefensive ) ) ) then
local spellID, spellName, spellSchool, extraSpellID, extraSpellName, extraSpellSchool, auraType = ...
if (bit.band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) > 0) then
self:SendMessage(self.db.profile.dispelFailMsg, extraSpellID, extraSpellName, spellName, destName, self.db.profile.dispelLocation, self.db.profile.dispelColor)
end
-- Managed to dispel or steal a buff
elseif( ( eventType == "SPELL_DISPEL" or eventType == "SPELL_STOLEN" ) and ( ( isHostile and self.db.profile.zones[instanceType].dispelOffensive ) or ( not isHostile and self.db.profile.zones[instanceType].dispelDefensive ) ) ) then
local spellID, spellName, spellSchool, extraSpellID, extraSpellName, extraSpellSchool, auraType = ...
if (bit.band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) > 0) then
self:SendMessage(self.db.profile.dispelSuccessMsg, extraSpellID, extraSpellName, spellName, destName, self.db.profile.dispelLocation, self.db.profile.dispelColor)
end
-- Managed to reflect a spell
elseif (eventType == "SPELL_MISSED") then
if (bit.band(destFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) > 0) then
local spellID, spellName, spellSchool, missType = ...
if (missType == "REFLECT" and self.db.profile.zones[instanceType].reflect) then
self:SendMessage(self.db.profile.reflectMsg, spellID, spellName, spellName, destName, self.db.profile.reflectLocation, self.db.profile.reflectColor)
elseif ((destName == "Totem de glèbe" or destName == "Grounding Totem") and (bit.band(destFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) > 0) and self.db.profile.zones[instanceType].grounding) then
self:SendMessage(self.db.profile.groundingMsg, spellID, spellName, spellName, destName, self.db.profile.groundingLocation, self.db.profile.groundingColor)
end
end
-- Managed to ground spell
elseif ((destName == "Totem de glèbe" or destName == "Grounding Totem") and self.db.profile.zones[instanceType].grounding) then
if (bit.band(destFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) > 0) then
local spellID, spellName = ...
if (eventType == "SPELL_CAST_SUCCESS") then
old = spellName
self:SendMessage(self.db.profile.groundingMsg, spellID, spellName, spellName, destName, self.db.profile.groundingLocation, self.db.profile.groundingColor)
elseif (eventType == "SPELL_DAMAGE") then
if (spellName ~= old) then
self:SendMessage(self.db.profile.groundingMsg, spellID, spellName, spellName, destName, self.db.profile.groundingLocation, self.db.profile.groundingColor)
end
end
end
end
end
-- Enabling Purgeatory based on zone type
function Purgeatory:PLAYER_ENTERING_WORLD()
self:ZONE_CHANGED_NEW_AREA()
end
function Purgeatory:ZONE_CHANGED_NEW_AREA()
local type = select(2, IsInInstance())
if( type ~= instanceType ) then
if( self.db.profile.zones[type].enabled ) then
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
else
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end
end
instanceType = type
end
function Purgeatory:Reload()
instanceType = nil
self:ZONE_CHANGED_NEW_AREA()
end
-- Strips server name
function Purgeatory:StripServer(text)
local name, server = string.match(text, "(.-)%-(.*)$")
if( not name and not server ) then
return text
end
return name
end
-- Wrap the message with an icon if needed
function Purgeatory:WrapIcon(msg, spellID)
if( not self.db.profile.showIcon or not spellID ) then
return msg
end
local icon = select(3, GetSpellInfo(spellID))
return icon and string.format("|T%s:0:0|t %s", icon, msg) or msg
end
local chatFrames = {}
local _G = getfenv(0)
function Purgeatory:SendMessage(msg, spellID, spellName, usedSpellName, destName, dest, color)
-- We're undergrouped, so redirect it to our fake alert frame
if( dest == "rw" and GetNumRaidMembers() == 0 and GetNumPartyMembers() == 0 ) then
dest = "rwframe"
-- We're grouped, in a raid and not leader or assist
elseif( dest == "rw" and not IsRaidLeader() and not IsRaidOfficer() and GetNumRaidMembers() > 0 ) then
dest = "party"
end
-- Do special things to the message
msg = string.gsub(msg, "*target", self:StripServer(destName or ""))
msg = string.gsub(msg, "*spell", spellName or "")
msg = string.gsub(msg, "*used", usedSpellName or "")
-- Strip out any () leftover from no name being given
msg = string.trim(string.gsub(msg, "%(%)", ""))
-- Chat frame
if( tonumber(dest) ) then
chatFrames[dest] = chatFrames[dest] or _G["ChatFrame" .. dest] or DEFAULT_CHAT_FRAME
chatFrames[dest]:AddMessage(string.format("|cff33ff99Purgeatory|r|cffffffff:|r %s", self:WrapIcon(msg, spellID)), color.r, color.g, color.b)
-- Announcement in /s
elseif( dest == "say" ) then
SendChatMessage(msg, "SAY")
-- Raid warning announcement to raid/party
elseif( dest == "rw" ) then
SendChatMessage(msg, "RAID_WARNING")
-- Party chat
elseif( dest == "party" ) then
SendChatMessage(msg, "PARTY")
-- Raid warning frame, will not send it out to the party
elseif( dest == "rwframe" ) then
if( not self.alertFrame ) then
self.alertFrame = CreateFrame("MessageFrame", nil, UIParent)
self.alertFrame:SetInsertMode("TOP")
self.alertFrame:SetFrameStrata("HIGH")
self.alertFrame:SetWidth(UIParent:GetWidth())
self.alertFrame:SetHeight(60)
self.alertFrame:SetFadeDuration(0.5)
self.alertFrame:SetTimeVisible(2)
self.alertFrame:SetFont((GameFontNormal:GetFont()), 20, "OUTLINE")
self.alertFrame:SetPoint("CENTER", 0, 130)
end
self.alertFrame:AddMessage(self:WrapIcon(msg, spellID), color.r, color.g, color.b)
-- Combat text
elseif( dest == "ct" ) then
msg = self:WrapIcon(msg)
-- SCT
if( IsAddOnLoaded("sct") ) then
SCT:DisplayText(msg, color, nil, "event", 1)
-- MSBT
elseif( IsAddOnLoaded("MikScrollingBattleText") ) then
MikSBT.DisplayMessage(msg, MikSBT.DISPLAYTYPE_NOTIFICATION, false, color.r * 255, color.g * 255, color.b * 255)
-- Blizzard Combat Text
elseif( IsAddOnLoaded("Blizzard_CombatText") ) then
-- Haven't cached the movement function yet
if( not COMBAT_TEXT_SCROLL_FUNCTION ) then
CombatText_UpdateDisplayedMessages()
end
CombatText_AddMessage(msg, COMBAT_TEXT_SCROLL_FUNCTION, color.r, color.g, color.b)
end
end
end
function Purgeatory:Print(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cff33ff99Purgeatory|r: " .. msg)
end
-- Event handler
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
frame:SetScript("OnEvent", function(self, event, ...)
if( event == "ADDON_LOADED" ) then
if( select(1, ...) == "Purgeatory" ) then
Purgeatory:OnInitialize()
Purgeatory:ZONE_CHANGED_NEW_AREA()
self:UnregisterEvent("ADDON_LOADED")
end
else
Purgeatory[event](Purgeatory, event, ...)
end
end)
function Purgeatory:RegisterEvent(event)
frame:RegisterEvent(event)
end
function Purgeatory:UnregisterEvent(event)
frame:UnregisterEvent(event)
end
--[[
PurgeatoryLocals = setmetatable(PurgeatoryLocals, {
__index = function(t, k)
rawset(t, k, k)
return k
end,
})
]]