-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealerWatch.lua
265 lines (210 loc) · 7.42 KB
/
healerWatch.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
-------------------------------------------------------------------------------
-- init
C_ChatInfo.RegisterAddonMessagePrefix("HealerWatch_WA")
aura_env.nameToUnitMap = {}
aura_env.realmNameSuffix = GetRealmName():gsub(" ", "")
aura_env.playerNameWithRealm = (GetUnitName("player")
.. '-' .. aura_env.realmNameSuffix)
function aura_env.canAccessUnitMana(unit)
-- Return 'true' if we can query for 'unit's mana. Otherwise, return
-- 'false'.
return Enum.PowerType.Mana == UnitPowerType(unit) or unit == "player"
end
function aura_env.getManaPercentValue(unit)
-- Return the percentage mana that the specified 'unit' has, out of 100.
-- If 'unit's mana cannot be retrieved, return 0 instead.
local maxMana = UnitPowerMax(unit, Enum.PowerType.Mana)
if maxMana == 0 then
return 0
end
return (UnitPower(unit, Enum.PowerType.Mana) * 100 / maxMana)
end
local drinkingBuffNames = {
["Food & Drink"] = true,
["Drink"] = true,
["Refreshment"] = true,
["Quiet Contemplation"] = true,
}
function aura_env.isDrinking(unit)
-- Return 'true' if the specified 'unit' is drinking. Otherwise, return
-- 'false'.
for i = 1, 40 do
local buffData = C_UnitAuras.GetBuffDataByIndex(unit, i)
if buffData == nil then
return false
end
if drinkingBuffNames[buffData["name"]] ~= nil then
return true
end
end
return false
end
function aura_env.raid20Members(skipRaid1)
-- Return a closure that iterates from 'raid1' through 'raid20'. If
-- 'skipRaid1' is 'true', then return a closure that iterates instead from
-- 'raid2' through 'raid21'.
local i
local last
if skipRaid1 then
i = 2
last = 21
else
i = 1
last = 20
end
return function()
if i <= last then
local raidIndex = i
i = i + 1
return "raid" .. raidIndex
else
return nil
end
end
end
-------------------------------------------------------------------------------
-- TSU: PLAYER_ROLES_ASSIGNED, UPDATE_INSTANCE_INFO, UNIT_POWER_UPDATE, UNIT_DISPLAYPOWER, UNIT_HEALTH, CHAT_MSG_ADDON, UNIT_AURA
function(allstates, event, ...)
if event == "PLAYER_ROLES_ASSIGNED" or event == "UPDATE_INSTANCE_INFO" then
-- Clear and repopulate 'allstates' and 'aura_env.nameToUnitMap' with
-- the healers in the group.
for k, _ in pairs(allstates) do
allstates[k] = nil
end
local nameToUnitMap = {}
-- Limit the raid group iteration to the first 20 members if the player
-- is in a mythic raid instance.
--
-- 'raid1' is always the raid leader, regardless of group, whereas the
-- remaining 'raidN' members are ordered by group. If 'raid1' is in a
-- group whose number is greater than that of 'raid21', then assume
-- that 'raid1' is acting as the "21st raider" and iterate from 'raid2'
-- through 'raid21'. Otherwise, iterate from 'raid1' through 'raid20'.
local groupIterator = WA_IterateGroupMembers()
if select(3, GetInstanceInfo()) == 16 and UnitExists("raid21") then
local raid1Subgroup = select(3, GetRaidRosterInfo(1))
local raid21Subgroup = select(3, GetRaidRosterInfo(21))
local skipRaid1 = (raid1Subgroup > raid21Subgroup)
groupIterator = aura_env.raid20Members(skipRaid1)
end
for unit in groupIterator do
if UnitGroupRolesAssigned(unit) == "HEALER" then
local unitName, unitRealm = UnitName(unit)
if unitRealm == nil then
unitRealm = aura_env.realmNameSuffix
end
unitName = unitName .. "-" .. unitRealm
nameToUnitMap[unitName] = unit
allstates[unit] = {
["show"] = true,
["unit"] = unit,
["progressType"] = "static",
["autoHide"] = false,
["total"] = 100,
["changed"] = true,
["value"] = aura_env.getManaPercentValue(unit),
["dead"] = UnitIsDeadOrGhost(unit),
["drinking"] = aura_env.isDrinking(unit),
}
end
end
aura_env.nameToUnitMap = nameToUnitMap
return true
elseif event == "UNIT_POWER_UPDATE" or event == "UNIT_DISPLAYPOWER" then
local unit, _ = ...
local state = allstates[unit]
if state == nil then
return false
end
if aura_env.canAccessUnitMana(unit) then
state["changed"] = true
state["value"] = aura_env.getManaPercentValue(unit)
return true
end
return false
elseif event == "UNIT_HEALTH" then
local unit, _ = ...
local state = allstates[unit]
if state == nil then
return false
end
local wasDead = state["dead"]
local isDead = UnitIsDeadOrGhost(unit)
if wasDead ~= isDead then
state["changed"] = true
state["dead"] = isDead
return true
end
return false
elseif event == "CHAT_MSG_ADDON" then
local prefix, message, channel, sender = ...
if prefix ~= "HealerWatch_WA"
or sender == aura_env.playerNameWithRealm then
return false
end
if channel ~= "PARTY"
and channel ~= "RAID"
and channel ~= "INSTANCE_CHAT" then
return false
end
local unit = aura_env.nameToUnitMap[sender]
if unit == nil then
return false
end
if not aura_env.canAccessUnitMana(unit) then
local state = allstates[unit]
state["changed"] = true
state["value"] = tonumber(message)
return true
end
return false
elseif event == "UNIT_AURA" then
local unit, _ = ...
local state = allstates[unit]
if state == nil then
return false
end
local wasDrinking = state["drinking"]
local isDrinking = aura_env.isDrinking(unit)
if wasDrinking ~= isDrinking then
state["changed"] = true
state["drinking"] = isDrinking
return true
end
return false
end
end
-------------------------------------------------------------------------------
-- Custom Variables
{
-- Standard conditions:
["value"] = true,
["total"] = true,
-- Custom conditions:
["unit"] = "string",
["dead"] = "bool",
["drinking"] = "bool"
}
-------------------------------------------------------------------------------
-- mana publisher custom text function
function()
local now = GetTime()
if aura_env.lastTime ~= nil and aura_env.lastTime + 2 > now then
return ""
end
aura_env.lastTime = now
local targetChannel
if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
targetChannel = "INSTANCE_CHAT"
elseif UnitInRaid("player") then
targetChannel = "RAID"
elseif UnitInParty("player") then
targetChannel = "PARTY"
else
return ""
end
local mana = (UnitPower("player", Enum.PowerType.Mana) * 100
/ UnitPowerMax("player", Enum.PowerType.Mana))
C_ChatInfo.SendAddonMessage("HealerWatch_WA", mana, targetChannel)
return ""
end