-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshotRake.lua
232 lines (183 loc) · 7.4 KB
/
snapshotRake.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
-------------------------------------------------------------------------------
-- On Init
aura_env.stealthSpellIds = {
-- A look-up set of spell IDs that make the next Rake count as used from
-- stealth.
[391974] = true, -- Sudden Ambush
[5215] = true, -- Prowl
[58984] = true, -- Shadowmeld
}
-- A look-up set of aura instance IDs for stealth auras currently on the
-- player.
aura_env.activeStealths = {}
aura_env.isStealthed = function()
-- Return 'true' if any stealth spell IDs are on the player. Otherwise,
-- return 'false'.
for _, _ in pairs(aura_env.activeStealths) do
return true
end
return false
end
-------------------------------------------------------------------------------
-- TSU: UNIT_AURA:player, UNIT_AURA:nameplate, NAME_PLATE_UNIT_REMOVED, NAME_PLATE_UNIT_ADDED, PLAYER_TARGET_CHANGED
function(allstates, event, unit, updateInfo)
if event == 'UNIT_AURA' and unit == 'player' then
-- Check if Sudden Ambush, Prowl, or Shadowmeld is being added or
-- removed.
if updateInfo['addedAuras'] ~= nil then
for _, data in ipairs(updateInfo['addedAuras']) do
local spellId = data['spellId']
if aura_env.stealthSpellIds[spellId] ~= nil then
aura_env.activeStealths[data['auraInstanceID']] = true
end
end
end
if updateInfo['removedAuraInstanceIDs'] ~= nil then
for _, auraInstanceId in ipairs(
updateInfo['removedAuraInstanceIDs']) do
aura_env.activeStealths[auraInstanceId] = nil
end
end
return false
elseif event == 'STATUS' then
-- Fetch whether we're in stealth.
for spellId, _ in pairs(aura_env.stealthSpellIds) do
local data = C_UnitAuras.GetPlayerAuraBySpellID(spellId)
if data ~= nil then
aura_env.activeStealths[data['auraInstanceID']] = true
end
end
return false
elseif event == 'UNIT_AURA' then
-- Check if we already have a state for Rake on this unit.
local unitGuid = UnitGUID(unit)
local state = allstates[unitGuid]
if state == nil then
-- Check if the aura being added is Rake from the player. If it
-- is, then create a state for it. Include in the state whether
-- any of the stealthed states is not 'nil'.
if updateInfo['addedAuras'] == nil then
return false
end
for _, data in ipairs(updateInfo['addedAuras']) do
if (data['sourceUnit'] == 'player'
and data['spellId'] == 155722) then
allstates[unitGuid] = {
['show'] = true,
['changed'] = true,
['progressType'] = 'timed',
['autoHide'] = true,
['name'] = data['name'],
['icon'] = data['icon'],
['spellId'] = data['spellId'],
['unit'] = unit,
['expirationTime'] = data['expirationTime'],
['duration'] = data['duration'],
['auraInstanceId'] = data['auraInstanceID'],
['fromStealth'] = aura_env.isStealthed(),
['isTarget'] = UnitIsUnit(unit, 'target')
}
return true
end
end
else
-- Check if the Rake from the player is being updated.
if updateInfo['updatedAuraInstanceIDs'] == nil then
return false
end
for _, auraInstanceId in ipairs(
updateInfo['updatedAuraInstanceIDs']) do
if state['auraInstanceId'] == auraInstanceId then
local data = C_UnitAuras.GetAuraDataByAuraInstanceID(
unit,
auraInstanceId)
-- The expiration time sometimes gets micro-adjusted with
-- updates. Don't update the 'fromStealth' value for these
-- jitters.
local timeDifference = math.abs(state['expirationTime']
- data['expirationTime'])
if timeDifference >= 0.5 then
state['fromStealth'] = aura_env.isStealthed()
end
state['changed'] = true
state['unit'] = unit
state['expirationTime'] = data['expirationTime']
state['duration'] = data['duration']
return true
end
end
return false
end
elseif event == 'NAME_PLATE_UNIT_REMOVED' then
-- Check if this unit has a state. If it does, set its 'unit' value to
-- 'nil'.
local unitGuid = UnitGUID(unit)
local state = allstates[unitGuid]
if state == nil then
return false
end
state['changed'] = true
state['unit'] = nil
return true
elseif event == 'NAME_PLATE_UNIT_ADDED' then
-- Check if this unit has a state. If it does, set its 'unit' value to
-- this unit.
local unitGuid = UnitGUID(unit)
local state = allstates[unitGuid]
if state == nil then
return false
end
state['changed'] = true
state['unit'] = unit
return true
elseif event == "PLAYER_TARGET_CHANGED" then
-- If the previous target has a state, clear its 'isTarget' value.
local changed = false
if aura_env.targetGuid ~= nil then
local state = allstates[aura_env.targetGuid]
if state ~= nil then
state['changed'] = true
state['isTarget'] = false
changed = true
end
end
aura_env.targetGuid = UnitGUID("target")
if aura_env.targetGuid ~= nil then
local state = allstates[aura_env.targetGuid]
if state ~= nil then
state['changed'] = true
state['isTarget'] = true
changed = true
end
end
return changed
elseif event == 'OPTIONS' then
-- Create a dummy state to test out the display options.
local rakeSpellId = 155722
local spellInfo = C_Spell.GetSpellInfo(rakeSpellId)
allstates['dummy'] = {
['show'] = true,
['changed'] = true,
['progressType'] = 'timed',
['autoHide'] = true,
['name'] = spellInfo['name'],
['icon'] = spellInfo['iconID'],
['spellId'] = rakeSpellId,
['unit'] = 'nameplate1',
['expirationTime'] = GetTime() + 12,
['duration'] = 12,
['auraInstanceId'] = 0,
['fromStealth'] = true,
['isTarget'] = true
}
end
end
-------------------------------------------------------------------------------
-- Custom Variables
{
['expirationTime'] = true,
['duration'] = true,
['unit'] = 'string',
['fromStealth'] = 'bool',
['isTarget'] = 'bool',
}