vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- |
2 | -- Simple Feign Health - by Brodrick ( aka Kirov ) |
||
3 | -- Version 2.0 |
||
4 | -- |
||
5 | -- Continues to show the player's health and mana values after they've feigned death. |
||
6 | -- Also attempts to show party / raid hunters' health and mana after they FD using |
||
7 | -- last known valid numbers. |
||
8 | -- |
||
9 | -- Attempts to keep track of a player's mana regen, as well as mana gains or drains. |
||
10 | -- Show accurate health for all FDed hunters in the player's group. |
||
11 | -- |
||
12 | |||
13 | |||
14 | SimpleFeignHealth_Saved = {}; |
||
15 | |||
16 | -- local vars |
||
17 | local ValidUnits = {}; |
||
18 | --SFH_ValidUnits = ValidUnits; -- for debugging |
||
19 | local manaRegen, |
||
20 | manaRegenLast, |
||
21 | manaRegenStart, |
||
22 | |||
23 | player, |
||
24 | playerUnit, |
||
25 | |||
26 | cacheUnit, |
||
27 | cacheMana, |
||
28 | cacheHealth, |
||
29 | |||
30 | frame, |
||
31 | tooltip, |
||
32 | statusbar; |
||
33 | |||
34 | -- hooked functions |
||
35 | local oldUnitHealth = UnitHealth; |
||
36 | local oldUnitMana = UnitMana; |
||
37 | local oldUnitIsDead = UnitIsDead; |
||
38 | |||
39 | -- local references for often used globals |
||
40 | local unitManaMax = UnitManaMax; |
||
41 | local unitStat = UnitStat; |
||
42 | local unitName = UnitName; |
||
43 | local getTime = GetTime; |
||
44 | |||
45 | local function print( msg ) |
||
46 | DEFAULT_CHAT_FRAME:AddMessage( msg ); |
||
47 | end |
||
48 | |||
49 | -- hack to prevent needless recalculation of the player's mana regen |
||
50 | -- which gets around the OnEvent order problem causing mis-matched results. |
||
51 | local function clearCache() |
||
52 | cacheHealth = nil; |
||
53 | cacheMana = nil; |
||
54 | this:GetScript("OnUpdate", nil); |
||
55 | end |
||
56 | |||
57 | -- all grouped units' health -- |
||
58 | ------------------------------- |
||
59 | local function getHealth(unit) |
||
60 | if ( tooltip ) then |
||
61 | if ( not cacheUnit or cacheUnit ~= unit ) then |
||
62 | if ( not cacheUnit ) then |
||
63 | frame:SetScript("OnUpdate", clearCache); |
||
64 | end |
||
65 | tooltip:SetUnit(unit); |
||
66 | cacheUnit = unit; |
||
67 | cacheHealth = nil; |
||
68 | end |
||
69 | if ( not cacheHealth ) then |
||
70 | cacheHealth = statusbar:GetValue(); |
||
71 | end |
||
72 | return cacheHealth; |
||
73 | end |
||
74 | return 0; |
||
75 | end |
||
76 | |||
77 | -- player's mana regen -- |
||
78 | ------------------------- |
||
79 | local function getManaRegen() |
||
80 | if ( not cacheMana ) then |
||
81 | cacheMana = playerUnit[2]; |
||
82 | if ( manaRegenTime ) then |
||
83 | if ( manaRegenLast ) then |
||
84 | manaRegenTime = manaRegenTime + getTime() - manaRegenLast; |
||
85 | manaRegenLast = getTime(); |
||
86 | end |
||
87 | local base, spirit = unitStat("player", 5); |
||
88 | local time = (manaRegenTime - mod(manaRegenTime, 2)); |
||
89 | manaRegenTime = manaRegenTime - time; |
||
90 | local regen = max(floor((spirit * time / 2 * 0.2) + ( time / 2 * 15 )),0); |
||
91 | cacheMana = min( cacheMana + regen, unitManaMax("player") ); |
||
92 | playerUnit[2] = cacheMana; |
||
93 | manaRegen = manaRegen + regen; |
||
94 | end |
||
95 | frame:SetScript("OnUpdate",clearCache); |
||
96 | end |
||
97 | return cacheMana; |
||
98 | end |
||
99 | |||
100 | -- add hunters to valid list -- |
||
101 | ------------------------------- |
||
102 | local function checkForHunters() |
||
103 | if ( SimpleFeignHealth_Saved["noparty"] ) then return; end |
||
104 | local raidNum = GetNumRaidMembers(); |
||
105 | local partyNum = GetNumPartyMembers(); |
||
106 | if ( raidNum > 0 ) then |
||
107 | for i=1, raidNum do |
||
108 | local unit = "raid"..i; |
||
109 | local _,class = UnitClass(unit); |
||
110 | if ( class == "HUNTER" ) then |
||
111 | local name = unitName( unit ); |
||
112 | if ( not ValidUnits[name] ) then |
||
113 | ValidUnits[name] = {unit,oldUnitMana(unit)}; |
||
114 | elseif ( name ~= player ) then |
||
115 | ValidUnits[name][1] = unit; |
||
116 | end |
||
117 | end |
||
118 | end |
||
119 | elseif ( partyNum > 0 ) then |
||
120 | for i=1, partyNum do |
||
121 | local unit = "party"..i; |
||
122 | local _,class = UnitClass(unit); |
||
123 | if ( class == "HUNTER" ) then |
||
124 | local name = unitName(unit); |
||
125 | if ( not ValidUnits[name] ) then |
||
126 | ValidUnits[name] = {unit,oldUnitMana(unit)}; |
||
127 | elseif ( name ~= player ) then |
||
128 | ValidUnits[name][1] = unit; |
||
129 | end |
||
130 | end |
||
131 | end |
||
132 | else -- cull all but player from list |
||
133 | for k, v in pairs(ValidUnits) do |
||
134 | if ( k ~= player ) then |
||
135 | v = nil; |
||
136 | end |
||
137 | end |
||
138 | end |
||
139 | end |
||
140 | |||
141 | |||
142 | -- check for fd -- |
||
143 | ------------------ |
||
144 | local function checkFeign( unit ) |
||
145 | local i, name, texture = 1, unitName(unit); |
||
146 | repeat |
||
147 | texture = UnitBuff( unit, i ); |
||
148 | if ( texture == "Interface\\Icons\\Ability_Rogue_FeignDeath" ) then |
||
149 | ValidUnits[name][3] = 1; |
||
150 | return 1; |
||
151 | end |
||
152 | i = i + 1; |
||
153 | until not texture; |
||
154 | ValidUnits[name][3] = nil; |
||
155 | end |
||
156 | |||
157 | |||
158 | -- initialization -- |
||
159 | -------------------- |
||
160 | frame = CreateFrame("frame","SFH_Frame"); |
||
161 | frame:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
162 | |||
163 | local function enable() |
||
164 | local _,class = UnitClass("player"); |
||
165 | if ( class == "HUNTER" ) then |
||
166 | frame:RegisterEvent("MIRROR_TIMER_START"); |
||
167 | frame:RegisterEvent("MIRROR_TIMER_STOP"); |
||
168 | player = unitName("player"); |
||
169 | ValidUnits[player] = {"player", oldUnitMana("player")}; |
||
170 | playerUnit = ValidUnits[player]; |
||
171 | --SFH_PlayerUnit = ValidUnits[player]; -- for debugging |
||
172 | end |
||
173 | checkForHunters(); |
||
174 | frame:RegisterEvent("UNIT_MANA"); |
||
175 | frame:RegisterEvent("UNIT_AURA"); |
||
176 | frame:RegisterEvent("PARTY_MEMBERS_CHANGED"); |
||
177 | if ( not tooltip ) then |
||
178 | tooltip = CreateFrame("GameTooltip","SFH_Tooltip",UIParent,"GameTooltipTemplate"); |
||
179 | tooltip:SetOwner(tooltip,"ANCHOR_NONE"); |
||
180 | statusbar = tooltip:GetChildren(); |
||
181 | end |
||
182 | end |
||
183 | |||
184 | local function disable() |
||
185 | ValidUnits = {}; |
||
186 | frame:UnregisterEvent("MIRROR_TIMER_START"); |
||
187 | frame:UnregisterEvent("MIRROR_TIMER_STOP"); |
||
188 | frame:UnregisterEvent("UNIT_MANA"); |
||
189 | frame:UnregisterEvent("UNIT_AURA"); |
||
190 | frame:UnregisterEvent("PARTY_MEMBERS_CHANGED"); |
||
191 | end |
||
192 | |||
193 | local function init() |
||
194 | print( "SimpleFeignHealh : loaded - /sfh" ); |
||
195 | |||
196 | SLASH_SFEIGNHEALTH1 = "/sfh"; |
||
197 | SLASH_SFEIGNHEALTH2 = "/simplefeignhealth"; |
||
198 | SLASH_SFEIGNHEALTH3 = "/feignhealth"; |
||
199 | SlashCmdList["SFEIGNHEALTH"] = SimpleFeignHealth_Console; |
||
200 | |||
201 | if ( not SimpleFeignHealth_Saved["disable"] ) then |
||
202 | enable(); |
||
203 | end |
||
204 | end |
||
205 | |||
206 | |||
207 | -- event catching -- |
||
208 | -------------------- |
||
209 | frame:SetScript("OnEvent", function() |
||
210 | if ( event == "PLAYER_ENTERING_WORLD" ) then |
||
211 | this:UnregisterEvent("PLAYER_ENTERING_WORLD"); |
||
212 | init(); |
||
213 | elseif ( event == "MIRROR_TIMER_START" ) then |
||
214 | if ( arg1 == "FEIGNDEATH" ) then |
||
215 | this:RegisterEvent("COMBAT_TEXT_UPDATE"); |
||
216 | manaRegenLast = getTime(); |
||
217 | manaRegenTime = -4; |
||
218 | manaRegen = 0; |
||
219 | end |
||
220 | elseif ( event == "MIRROR_TIMER_STOP" ) then |
||
221 | if ( arg1 == "FEIGNDEATH" ) then |
||
222 | this:UnregisterEvent("COMBAT_TEXT_UPDATE"); |
||
223 | end |
||
224 | elseif ( event == "PARTY_MEMBERS_CHANGED" ) then |
||
225 | -- Find hunters in party / raid |
||
226 | checkForHunters(); |
||
227 | elseif ( event == "COMBAT_TEXT_UPDATE" ) then |
||
228 | if ( not playerUnit[3] ) then return; end |
||
229 | if ( arg1 == "MANA" ) then |
||
230 | playerUnit[2] = max(min(playerUnit[2] + arg2,unitManaMax("player")),0); |
||
231 | end |
||
232 | else |
||
233 | local name = unitName(arg1); |
||
234 | if ( event == "UNIT_MANA" ) then |
||
235 | if ( ValidUnits[name] ) then |
||
236 | local mana = oldUnitMana( arg1 ); |
||
237 | if ( mana > 0 ) then |
||
238 | -- Keep track of all valid units' mana before FD |
||
239 | ValidUnits[name][2] = mana; |
||
240 | end |
||
241 | end |
||
242 | elseif ( event == "UNIT_AURA" ) then |
||
243 | if ( ValidUnits[name] ) then |
||
244 | checkFeign(arg1); |
||
245 | end |
||
246 | end |
||
247 | end |
||
248 | end |
||
249 | ); |
||
250 | |||
251 | |||
252 | -- console commands -- |
||
253 | ---------------------- |
||
254 | function SimpleFeignHealth_Console( msg ) |
||
255 | if ( string.sub( strlower( msg ), 1, 5 ) == "party" ) then |
||
256 | if ( SimpleFeignHealth_Saved["noparty"] ) then |
||
257 | SimpleFeignHealth_Saved["noparty"] = nil; |
||
258 | checkForHunters(); |
||
259 | print( "SimpleFeignHealh : enabled for party hunters" ); |
||
260 | else |
||
261 | SimpleFeignHealth_Saved["noparty"] = 1; |
||
262 | for k, v in ValidUnits do |
||
263 | if ( k ~= player ) then |
||
264 | ValidUnits[k] = nil; |
||
265 | end |
||
266 | end |
||
267 | print( "SimpleFeignHealh : disabled for party hunters" ); |
||
268 | end |
||
269 | elseif ( string.sub( strlower( msg ), 1, 2 ) == "on" ) then |
||
270 | enable(); |
||
271 | SimpleFeignHealth_Saved["disable"] = nil; |
||
272 | print( "SimpleFeignHealh : enabled" ); |
||
273 | elseif ( string.sub( strlower( msg ), 1, 3 ) == "off" ) then |
||
274 | disable(); |
||
275 | SimpleFeignHealth_Saved["disable"] = 1; |
||
276 | print( "SimpleFeignHealh : disabled" ); |
||
277 | elseif ( string.sub( strlower( msg ), 1, 6 ) == "toggle" ) then |
||
278 | if ( SimpleFeignHealth_Saved["disable"] ) then |
||
279 | SimpleFeignHealth_Saved["disable"] = nil; |
||
280 | enable(); |
||
281 | print( "SimpleFeignHealh : enabled" ); |
||
282 | else |
||
283 | SimpleFeignHealth_Saved["disable"] = 1; |
||
284 | disable(); |
||
285 | print( "SimpleFeignHealh : disabled" ); |
||
286 | end |
||
287 | else |
||
288 | if ( SimpleFeignHealth_Saved["disable"] ) then |
||
289 | print( "SimpleFeignHealh : /sfh : currently disabled" ); |
||
290 | else |
||
291 | print( "SimpleFeignHealh : /sfh : currently enabled" ); |
||
292 | end |
||
293 | print( "on / off / toggle - enable and disable this mod" ); |
||
294 | if ( SimpleFeignHealth_Saved["noparty"] ) then |
||
295 | print( "party hunters disabled" ); |
||
296 | else |
||
297 | print( "party hunters enabled" ); |
||
298 | end |
||
299 | print( "party - toggle showing heath / mana values for partied hunters" ); |
||
300 | end |
||
301 | end |
||
302 | |||
303 | |||
304 | -- hook functions -- |
||
305 | -------------------- |
||
306 | function UnitHealth( unit ) |
||
307 | local health = oldUnitHealth( unit ); |
||
308 | local name = unitName(unit); |
||
309 | if ( health == 0 and ValidUnits[name] and (ValidUnits[name][3] or checkFeign(unit)) ) then |
||
310 | return getHealth(unit); |
||
311 | end |
||
312 | return health; |
||
313 | end |
||
314 | |||
315 | function UnitMana( unit ) |
||
316 | local mana = oldUnitMana( unit ); |
||
317 | local name = unitName(unit); |
||
318 | if ( mana == 0 and ValidUnits[name] and (ValidUnits[name][3] or checkFeign(unit)) ) then |
||
319 | if ( player and name == player ) then |
||
320 | return getManaRegen(); |
||
321 | elseif ( ValidUnits[name][3] ) then |
||
322 | return ValidUnits[name][2]; |
||
323 | end |
||
324 | end |
||
325 | return mana; |
||
326 | end |
||
327 | |||
328 | function UnitIsDead( unit ) |
||
329 | local dead = oldUnitIsDead( unit ); |
||
330 | local name = unitName(unit); |
||
331 | if ( dead and ValidUnits[name] and (ValidUnits[name][3] or checkFeign(unit)) ) then |
||
332 | return; |
||
333 | end |
||
334 | return dead; |
||
335 | end |