-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpellNotifications.lua
More file actions
167 lines (148 loc) · 6.26 KB
/
SpellNotifications.lua
File metadata and controls
167 lines (148 loc) · 6.26 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
--[[
Version 2.0 maintained by LucyON & Oscarwizyo
]]
local _, addon = ...
SpellNotifications = addon
local reflected = {}
local ME, FRIENDLY, PET
-- Helper function to check if a GUID matches any of our tracked targets
local function isTrackedTarget(guid)
local targetGuids = addon.TargetGuids()
for _, target in ipairs(targetGuids) do
if guid == UnitGUID(target) then
return true
end
end
return false
end
-- Helper function to get spell school name
local function getSpellSchoolName(extraSchool)
local spellSchool = addon.SpellSchools()[extraSchool]
return spellSchool or "unknown spell school"
end
-- Handle interrupt events
local function handleInterrupt(sourceFlags)
if bit.band(sourceFlags, ME) > 0 then
local extraSchool = select(17, CombatLogGetCurrentEventInfo())
local spellSchool = getSpellSchoolName(extraSchool)
addon.print("Interrupted " .. string.lower(spellSchool) .. ".", addon.Colors().GREEN, addon.Sizes().SMALL)
end
end
-- Handle dispel events
local function handleDispel(sourceFlags, destFlags)
if bit.band(sourceFlags, ME) > 0 then
local spellName = select(16, CombatLogGetCurrentEventInfo())
local color = bit.band(destFlags, FRIENDLY) > 0 and addon.Colors().WHITE or addon.Colors().YELLOW
addon.print("Dispelled " .. spellName .. ".", color, addon.Sizes().SMALL)
end
end
-- Handle spell steal events
local function handleSpellSteal(sourceFlags)
if bit.band(sourceFlags, ME) > 0 then
local spellName = select(16, CombatLogGetCurrentEventInfo())
addon.print("Stole " .. spellName .. ".", addon.Colors().YELLOW, addon.Sizes().SMALL)
end
end
-- Handle pet death events
local function handlePetDeath(event, destFlags)
local isDeathEvent = event == "UNIT_DIED" or event == "UNIT_DESTROYED" or event == "UNIT_DISSIPATES"
if isDeathEvent and bit.band(destFlags, ME) > 0 and bit.band(destFlags, PET) > 0 then
addon.print("Pet dead.", addon.Colors().RED, addon.Sizes().LARGE)
addon.playSound("buzz")
end
end
-- Handle spell reflection tracking
local function handleSpellReflection(event, sourceFlags, destGUID)
if (event == "SPELL_AURA_APPLIED" or event == "SPELL_AURA_REMOVED") and bit.band(sourceFlags, ME) > 0 then
local spellName = select(13, CombatLogGetCurrentEventInfo())
if spellName == "Mass Spell Reflection" then
reflected[destGUID] = (event == "SPELL_AURA_APPLIED")
end
end
end
-- Handle reflected spell misses
local function handleReflectedMiss(destFlags, destGUID)
if bit.band(destFlags, ME) <= 0 then
local spellName, _, missType = select(13, CombatLogGetCurrentEventInfo())
if missType == "REFLECT" and reflected[destGUID] then
addon.print("Reflected " .. spellName .. ".", addon.Colors().BLUE, addon.Sizes().SMALL)
end
end
end
-- Handle spell misses on player
local function handlePlayerSpellMissOnPlayer(destFlags, destName)
if bit.band(destFlags, ME) > 0 then
local spellName, _, missType = select(13, CombatLogGetCurrentEventInfo())
if missType == "REFLECT" then
addon.print("Reflected " .. spellName .. ".", addon.Colors().WHITE, addon.Sizes().SMALL)
elseif destName == "Grounding Totem" then
addon.print("Grounded " .. spellName .. ".", addon.Colors().WHITE, addon.Sizes().SMALL)
end
end
end
-- Handle grounding totem damage
local function handleGroundingDamage(destFlags, destName)
if bit.band(destFlags, ME) > 0 then
local spellName = select(13, CombatLogGetCurrentEventInfo())
if destName == "Grounding Totem" then
addon.print("Grounded " .. spellName .. ".", addon.Colors().WHITE, addon.Sizes().SMALL)
end
end
end
-- Handle spell misses by player
local function handlePlayerSpellMiss(destGUID, destName)
if isTrackedTarget(destGUID) then
local spellName, _, missType = select(13, CombatLogGetCurrentEventInfo())
local resistMethod = addon.MissTypes()[missType]
if missType == "ABSORB" then
return
elseif destName == "Grounding Totem" then
resistMethod = "grounded"
elseif missType == "REFLECT" then
resistMethod = "reflected"
elseif resistMethod == nil then
resistMethod = "missed"
end
local color = (resistMethod == "immune" or resistMethod == "evaded") and addon.Colors().RED or addon.Colors().WHITE
addon.print(spellName .. " " .. resistMethod .. ".", color, addon.Sizes().LARGE)
end
end
function SpellNotifications.OnLoad(self)
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("UNIT_HEALTH")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:RegisterEvent("PLAYER_REGEN_DISABLED") -- enter combat
self:RegisterEvent("PLAYER_REGEN_ENABLED") -- leave combat
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("ACTIONBAR_UPDATE_STATE")
end
function SpellNotifications.OnEvent(event)
local timeStamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags,
destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()
local size = addon.Sizes()
local color = addon.Colors()
local affiliation = addon.Affiliations()
ME, FRIENDLY, PET = affiliation.MINE, affiliation.FRIENDLY, affiliation.PET
-- Handle different event types
if event == "SPELL_INTERRUPT" then
handleInterrupt(sourceFlags)
elseif event == "SPELL_DISPEL" then
handleDispel(sourceFlags, destFlags)
elseif event == "SPELL_STOLEN" then
handleSpellSteal(sourceFlags)
elseif event == "UNIT_DIED" or event == "UNIT_DESTROYED" or event == "UNIT_DISSIPATES" then
handlePetDeath(event, destFlags)
elseif event == "SPELL_AURA_APPLIED" or event == "SPELL_AURA_REMOVED" then
handleSpellReflection(event, sourceFlags, destGUID)
elseif event == "SPELL_MISSED" then
if bit.band(sourceFlags, ME) > 0 then
handlePlayerSpellMiss(destGUID, destName)
elseif bit.band(destFlags, ME) > 0 then
handlePlayerSpellMissOnPlayer(destFlags, destName)
elseif bit.band(destFlags, ME) <= 0 then
handleReflectedMiss(destFlags, destGUID)
end
elseif event == "SPELL_DAMAGE" then
handleGroundingDamage(destFlags, destName)
end
end