-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoulOfTheForest.elvuiBuffHighlighter.lua
391 lines (310 loc) · 13.2 KB
/
soulOfTheForest.elvuiBuffHighlighter.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
-------------------------------------------------------------------------------
--[[ TODO
- Support SOTF detection in Convoke?
]]
-------------------------------------------------------------------------------
--[[ Implementation Notes
There is no consistent order in which 'SPELL_CAST_SUCCESS',
'SPELL_AURA_APPLIED'/'SPELL_AURA_REFRESH', and 'SPELL_AURA_REMOVED' events are
fired. We therefore assume:
- If a 'SPELL_CAST_SUCCESS' of an empowerable HOT comes after a
'SPELL_AURA_APPLIED' of SOTF but before a 'SPELL_AURA_REMOVED' of SOTF, then
the spell cast is empowered by SOTF.
- If SOTF is 'SPELL_AURA_REMOVED' before a 'SPELL_CAST_SUCCESS' of an
empowerable HOT, but the 'SPELL_CAST_SUCCESS' of an empowerable HOT fires
later with the same 'timestamp', then that spell cast is empowered by SOTF.
- A 'SPELL_AURA_APPLIED'/'SPELL_AURA_REFRESH' of a spell is empowered only if
it has the same 'timestamp', 'spellId', and 'targetGuid' as an empowered
cast. If the empowered cast is Wild Growth, then the 'targetGuid' is
ignored.
A 'SPELL_CAST_SUCCESS' comes *after* its corresponding
'SPELL_AURA_APPLIED'/'SPELL_AURA_REFRESH' on the player, but *before* its
corresponding 'SPELL_AURA_APPLIED'/'SPELL_AURA_REFRESH' on other group members.
Therefore, when we observe a 'SPELL_CAST_SUCCESS' targeting the player, we also
rerun the 'SPELL_AURA_APPLIED'/'SPELL_AURA_REFRESH' logic.
We check 'SPELL_CAST_SUCCESS' at all to order amongst 'SPELL_CAST_SUCCESS'
events and determine which are empowered by SOTF. Two spells may be cast at
the same 'timestamp' due to spell queueing, but only the first of the
'SPELL_CAST_SUCCESS'es would be empowered by SOTF.
'SPELL_AURA_APPLIED'/'SPELL_AURA_REFRESH' cannot be relied upon for deducing
spell cast order.
]]
-------------------------------------------------------------------------------
-- init
aura_env.trackedSpellIds = {
[114108] = true, -- Soul of the Forest
[197721] = true, -- Flourish
[774] = true, -- Rejuvenation
[8936] = true, -- Regrowth
[48438] = true, -- Wild Growth
[155777] = true, -- Rejuvenation (Germination)
}
aura_env.sotfState = {
---------------
-- PRIVATE DATA
---------------
["__sotfApplied"] = false,
["__empoweredTimestamp"] = nil,
["__empoweredTarget"] = nil,
["__empoweredCastSpellId"] = nil,
------------------------
-- PRIVATE CLASS METHODS
------------------------
["__MakeStateKey"] = function(targetGuid, spellId)
return spellId .. targetGuid
end,
["__GetGroupUnitIdFromUnitGuid"] = function(unitGuid)
-- Return a unit ID for the unit with the specified 'unitGuid' if the
-- unit is in the current player's group. Otherwise, return 'nil'.
for unit in WA_IterateGroupMembers() do
if UnitGUID(unit) == unitGuid then
return unit
end
end
return nil
end,
--------------------
-- PRIVATE ACCESSORS
--------------------
["__IsEmpowered"] = function(self, timestamp, targetGuid, spellId)
-- Return 'true' if the specified 'spellId' on the specified
-- 'targetGuid' at the specified 'timestamp' is empowered. Otherwise,
-- return 'false'.
if spellId == 48438 then
-- This is an application of Wild Growth. Check its spell ID,
-- allow a time tolerance for the timestamp, and ignore the target.
return self.__empoweredCastSpellId == spellId
and self.__empoweredTimestamp <= timestamp
and self.__empoweredTimestamp + 0.2 > timestamp
elseif spellId == 155777 then
-- This is an application of Germination. The empowered cast spell
-- ID should be Rejuvenation.
return self.__empoweredTimestamp == timestamp
and self.__empoweredTarget == targetGuid
and self.__empoweredCastSpellId == 774
else
return self.__empoweredTimestamp == timestamp
and self.__empoweredTarget == targetGuid
and self.__empoweredCastSpellId == spellId
end
end,
---------------
-- MANIPULATORS
---------------
["ApplySotf"] = function(self)
-- Apply the SOTF buff.
self.__sotfApplied = true
end,
["RemoveSotf"] = function(self, timestamp)
-- Remove the SOTF buff at the specified 'timestamp'.
self.__sotfApplied = false
if self.__empoweredTimestamp ~= timestamp then
-- The SOTF buff is newly removed, but we don't know yet what spell
-- it empowers.
self.__empoweredTimestamp = timestamp
self.__empoweredTarget = nil
self.__empoweredCastSpellId = nil
end
end,
["RecordHealCast"] = function(self, timestamp, targetGuid, spellId)
-- Record the specified 'spellId' on the specified 'targetGuid' as the
-- last casted heal at the specified 'timestamp', and update the
-- empowered cast state data as appropriate.
if self.__sotfApplied
or (self.__empoweredTimestamp == timestamp and self.__empoweredCastSpellId == nil) then
-- The SOTF aura is applied, or it was removed at 'timestamp'
-- without first empowering a spell. This 'spellId' at 'timestamp'
-- consumes the SOTF empowerment.
self.__sotfApplied = false
self.__empoweredTimestamp = timestamp
self.__empoweredTarget = targetGuid
self.__empoweredCastSpellId = spellId
end
end,
["Flourish"] = function(self, allstates)
-- Refresh the duration and expiration time on all states in the
-- specified 'allstates'. Return 'true' if 'allstates' is updated.
-- Otherwise, return 'false'.
local changed = false
for _, state in pairs(allstates) do
if state.show == true then
local _, _, _, _, duration, expirationTime = WA_GetUnitBuff(state.unit, state.spellId, "PLAYER")
state.duration = duration
state.expirationTime = expirationTime
state.changed = true
changed = true
end
end
return changed
end,
["ApplyHeal"] = function(self, allstates, timestamp, targetGuid, spellId)
-- Apply or refresh a HOT effect with the specified 'spellId' to the
-- unit with the specified 'targetGuid' at the specified 'timestamp'.
-- Update the specified 'allstates' as appropriate. Return 'true' if
-- 'allstates' is updated. Otherwise, return 'false'.
local stateKey = self.__MakeStateKey(targetGuid, spellId)
local state = allstates[stateKey]
if self:__IsEmpowered(timestamp, targetGuid, spellId) then
-- Insert or update the state in 'allstates'.
if state == nil then
state = {}
allstates[stateKey] = state
end
local targetUnit = self.__GetGroupUnitIdFromUnitGuid(targetGuid)
state.changed = true
state.show = true
state.icon = select(3, GetSpellInfo(spellId))
state.spellId = spellId
state.unit = targetUnit
state.progressType = "timed"
state.autoHide = true
local _, _, _, _, duration, expirationTime = WA_GetUnitBuff(targetUnit, spellId, "PLAYER")
state.duration = duration
state.expirationTime = expirationTime
return true
else
-- Remove the state from 'allstates'.
if state == nil then
return false
end
state.changed = true
state.show = false
return true
end
end,
["RemoveHeal"] = function(self, allstates, targetGuid, spellId)
-- Remove a HOT effect with the specified 'spellId' from the unit with
-- the specified 'targetGuid'. Update the specified 'allstates' as
-- appropriate.
local stateKey = self.__MakeStateKey(targetGuid, spellId)
local state = allstates[stateKey]
if state == nil then
return false
end
state.changed = true
state.show = false
return true
end,
}
-------------------------------------------------------------------------------
-- TSU: CLEU:SPELL_AURA_APPLIED:SPELL_AURA_REFRESH:SPELL_AURA_REMOVED:SPELL_CAST_SUCCESS, WA_SOTF_DEFERRED_FLOURISH
function(allstates, event)
if event == "WA_SOTF_DEFERRED_FLOURISH" then
return aura_env.sotfState:Flourish(allstates)
end
local timestamp, subevent, _, sourceGuid, _, _, _, targetGuid, _, targetFlags, _, spellId = CombatLogGetCurrentEventInfo()
-- Ignore events not caused by the player.
if sourceGuid ~= UnitGUID("player") then
return false
end
-- Ignore untracked spell IDs.
if aura_env.trackedSpellIds[spellId] == nil then
return false
end
-- Ignore events not affecting the player or a group member, unless the
-- event is a 'SPELL_CAST_SUCCESS' of Wild Growth, which never specifies a
-- target.
if (subevent ~= "SPELL_CAST_SUCCESS" or spellId ~= 48438)
and (bit.band(targetFlags, COMBATLOG_OBJECT_TYPE_PLAYER) == 0
or bit.band(targetFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) ~= 0) then
return false
end
-- Update state.
local sotfState = aura_env.sotfState;
if aura_env.config.debug then
print(CombatLogGetCurrentEventInfo())
end
if subevent == "SPELL_CAST_SUCCESS" and spellId ~= 197721 then
sotfState:RecordHealCast(timestamp, targetGuid, spellId)
-- 'SPELL_CAST_SUCCESS' fires after its corresponding
-- 'SPELL_AURA_APPLIED'/'SPELL_AURA_REFRESH' on the player, so we need
-- to "backfill" on that 'SPELL_AURA_APPLIED'/'SPELL_AURA_REFRESH'
-- event.
if (targetGuid == sourceGuid or spellId == 48438)
and aura_env.lastPlayerAppliedHealTime == timestamp
and (aura_env.lastPlayerAppliedHeal == spellId
or (aura_env.lastPlayerAppliedHeal == 155777 and spellId == 774)) then
return sotfState:ApplyHeal(allstates,
timestamp,
sourceGuid,
aura_env.lastPlayerAppliedHeal)
end
elseif subevent == "SPELL_AURA_APPLIED"
or subevent == "SPELL_AURA_REFRESH" then
if spellId == 114108 then -- Soul of the Forest
sotfState:ApplySotf()
return false
elseif spellId == 197721 then -- Flourish
-- Delay the processing of this event, since the duration of the
-- buffs might not be updated immediately.
C_Timer.After(0.1, function() WeakAuras.ScanEvents("WA_SOTF_DEFERRED_FLOURISH") end)
return false
else
if targetGuid == sourceGuid then
aura_env.lastPlayerAppliedHealTime = timestamp
aura_env.lastPlayerAppliedHeal = spellId
end
return sotfState:ApplyHeal(allstates,
timestamp,
targetGuid,
spellId)
end
elseif subevent == "SPELL_AURA_REMOVED" then
if spellId == 114108 then -- Soul of the Forest
sotfState:RemoveSotf(timestamp)
return false
elseif spellId == 197721 then -- Flourish
return false
else
return sotfState:RemoveHeal(allstates, targetGuid, spellId)
end
end
end
-------------------------------------------------------------------------------
-- Animations -> Main -> Fade
function()
-- Get the ElvUI buff icon frame for this clone, whether it's tracked as a
-- "Buff" or as a "Buff Indicator". If it's tracked as both, prefer the
-- "Buff Indicator".
--
-- Here be dragons and use of undocumented (i.e., private) addon behavior.
local tracksState = function(frame)
-- Return 'true' if the specified ElvUI button 'frame' tracks
-- 'aura_env.state.spellId' from the player and is shown. Otherwise,
-- return 'false'.
return frame:IsShown()
and frame.spellID == aura_env.state.spellId
and frame.caster == "player"
end
local buffIconFrame = aura_env.region.relativeTo
if buffIconFrame ~= nil
and tracksState(buffIconFrame) then
return 0.5
end
local unitFrame = WeakAuras.GetUnitFrame(aura_env.state.unit)
if unitFrame == nil then
return 0
end
buffIconFrame = nil
for _,frame in ipairs(unitFrame.__owner.AuraWatch) do
if tracksState(frame) then
buffIconFrame = frame
break
end
end
if buffIconFrame == nil then
for _,frame in ipairs(unitFrame.__owner.Buffs) do
if tracksState(frame) then
buffIconFrame = frame
break
end
end
end
if buffIconFrame == nil then
return 0
end
aura_env.region:SetAnchor("CENTER", buffIconFrame, "CENTER")
aura_env.region:SetWidth(buffIconFrame:GetWidth())
aura_env.region:SetHeight(buffIconFrame:GetHeight())
return 0.5
end