vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 Name: MobHealth2
4 Author: Wyv & Skeeve
5 Description: Displays health value for mobs.
6 Original version by Telo.
7 ]]
8  
9  
10 -- remember previous font type and font size
11 local lOldFontId = 0
12 local lOldFontSize = 0
13  
14  
15 --------------------------------------------------------------------------------------------------
16 -- external functions for macros / scripts
17 --------------------------------------------------------------------------------------------------
18  
19 -----------------------------------------------------------------------------
20 -- MobHealth_GetTargetCurHP()
21 --
22 -- Return current health points value for the current target as an integer
23 -- value. Return nil if there is no current target.
24 --
25 -- Example:
26 -- local targetCurrentHealth = MobHealth_GetTargetCurHP()
27 -- if targetCurrentHealth then
28 -- .......
29 -- end
30 -----------------------------------------------------------------------------
31 function MobHealth_GetTargetCurHP()
32 if MI2_Target.curHealth then
33 return MI2_Target.curHealth
34 else
35 return nil
36 end
37 end -- of MobHealth_GetTargetCurHP()
38  
39  
40 -----------------------------------------------------------------------------
41 -- MobHealth_GetTargetMaxHP()
42 --
43 -- Return maximum health points value for the current target as an integer
44 -- value. Return nil if there is no current target.
45 --
46 -- Example:
47 -- local targetMaxHealth = MobHealth_GetTargetMaxHP()
48 -- if targetMaxHealth then
49 -- .......
50 -- end
51 -----------------------------------------------------------------------------
52 function MobHealth_GetTargetMaxHP()
53 -- for compatibility to MobHealth-2: only return maxHP if there is a curHP
54 if MI2_Target.curHealth then
55 return MI2_Target.maxHealth
56 else
57 return nil
58 end
59 end -- of MobHealth_GetTargetMaxHP()
60  
61  
62 -----------------------------------------------------------------------------
63 -- MobHealth_PPP( index )
64 --
65 -- Return the Points-Per-Percent (PPP) value for a Mob identified by its index.
66 -- The index is the concatination of the Mob name and the Mob level (see
67 -- example below). 0 is returned if the PPP value is not available for
68 -- the given index. The example also shows how to calculate the actual
69 -- health points from the health percentage and the PPP value
70 --
71 -- Example:
72 -- local name = UnitName("target")
73 -- local level = UnitLevel("target")
74 -- local index = name..":"..level
75 -- local ppp = MobHealth_PPP( index )
76 -- local healthPercent = UnitHealth("target")
77 -- local curHealth = math.floor( healthPercent * ppp + 0.5)
78 -- local maxHealth = math.floor( 100 * ppp + 0.5)
79 -----------------------------------------------------------------------------
80 function MobHealth_PPP( index )
81 if index and MobHealthDB[index] then
82 local s, e, pts, pct = string.find(MobHealthDB[index], "^(%d+)/(%d+)$")
83 if ( pts and pct ) then
84 pts = pts + 0
85 pct = pct + 0
86 if ( pct ~= 0 ) then
87 return pts / pct
88 end
89 end
90 end
91 return 0
92 end
93  
94  
95 -----------------------------------------------------------------------------
96 -- MI2_GetHealthData()
97 --
98 -- get health data for a given mob from the given health database
99 -- (ie. either mob health database or player health database)
100 -----------------------------------------------------------------------------
101 function MI2_GetHealthData( database, index )
102 local s, e, pts, pct
103 if database[index] then
104 s, e, pts, pct = string.find(database[index], "^(%d+)/(%d+)$")
105 end
106 return ((pts or 0) + 0), ((pct or 0) + 0)
107 end -- MI2_GetHealthData()
108  
109  
110 -----------------------------------------------------------------------------
111 -- MobHealth_Set()
112 --
113 -- store pct and pts values for a given mob index in the given database
114 -----------------------------------------------------------------------------
115 function MobHealth_Set( database, index, pts, pct)
116 if pts or pct then
117 database[index] = (pts or 0).."/"..(pct or 0)
118 else
119 database[index] = nil
120 end
121 end -- MobHealth_Set()
122  
123  
124 -----------------------------------------------------------------------------
125 -- MI2_CalculateHealth()
126 --
127 -- (re)calculate current health and maximum for current target
128 -----------------------------------------------------------------------------
129 function MI2_CalculateHealth( updateMaxHealth )
130 if MI2_Target.unitHealth > 0 then
131 local curHealthMax = UnitHealthMax("target") -- have to check because BeastLore changes maxhealth from percent to value
132 if curHealthMax ~= 100 then
133 if MI2_Target.healthDB then
134 MobHealth_Set( MI2_Target.healthDB, MI2_Target.index, curHealthMax * 25, 2500 )
135 MI2_Target = { totalPercent = 0, maxHealth=curHealthMax }
136 MI2_Target.unitHealth = UnitHealth("target")
137 end
138 MI2_Target.curHealth = MI2_Target.unitHealth
139 MI2_Target.maxHealth = curHealthMax
140 MI2_Target.unitHealth = math.floor(100.0 * MI2_Target.unitHealth / MI2_Target.maxHealth + 0.5)
141 MI2_Target.showHealth = 1
142 elseif MI2_Target.totalPercent > 0 then
143 local ppp = MI2_Target.totalDamage / MI2_Target.totalPercent
144 MI2_Target.curHealth = math.floor(MI2_Target.unitHealth * ppp + 0.5)
145 if updateMaxHealth then
146 MI2_Target.maxHealth = math.floor( (100 * ppp) + 0.5 )
147 end
148 MI2_Target.showHealth = 1
149 end
150 end
151 end -- MI2_CalculateHealth()
152  
153  
154 -----------------------------------------------------------------------------
155 -- MobHealth_Display()
156 --
157 -- display the values and percentage for health / mana in target frame
158 -----------------------------------------------------------------------------
159 function MobHealth_Display( )
160 local healthText, manaText
161  
162 -- create health and percent text if showing is enabled
163 if MI2_Target.showHealth then
164 if MobInfoConfig.TargetHealth == 1 then
165 healthText = string.format("%d/%d", MI2_Target.curHealth, MI2_Target.maxHealth )
166 end
167 if MobInfoConfig.HealthPercent == 1 then
168 if healthText then
169 healthText = healthText..string.format(" (%d%%)", MI2_Target.unitHealth )
170 else
171 healthText = string.format("%d%%", MI2_Target.unitHealth )
172 end
173 end
174 end
175  
176 -- create mana text based on mana show flags
177 local maxmana = UnitManaMax("target")
178 if maxmana > 0 then
179 local mana = UnitMana("target")
180 if MobInfoConfig.TargetMana == 1 then
181 manaText = string.format("%d/%d", mana, maxmana )
182 end
183 if MobInfoConfig.ManaPercent == 1 then
184 if manaText then
185 manaText = manaText..string.format(" (%d%%)", math.floor(100.0 * mana / maxmana))
186 else
187 manaText = string.format("%d%%", math.floor(100.0 * mana / maxmana))
188 end
189 end
190 end
191  
192 MI2_MobHealthText:SetText( healthText or "" )
193 MI2_MobManaText:SetText( manaText or "" )
194 end -- MobHealth_Display()
195  
196  
197 -----------------------------------------------------------------------------
198 -- MI2_MobHealth_SetFont()
199 --
200 -- set new font for display of health / mana in target frame
201 -----------------------------------------------------------------------------
202 local function MI2_MobHealth_SetFont( fontId, fontSize )
203 local fontName
204  
205 if fontId ~= lOldFontId or fontSize ~= lOldFontSize then
206 lOldFontId = fontId
207 lOldFontSize = fontSize
208  
209 -- select font name to use
210 if fontId == 1 then
211 fontName = "Fonts\\ARIALN.TTF" -- NumberFontNormal
212 elseif fontId == 2 then
213 fontName = "Fonts\\FRIZQT__.TTF" -- GameFontNormal
214 else
215 fontName = "Fonts\\MORPHEUS.TTF" -- ItemTextFontNormal
216 end
217  
218 -- set font for health and mana text
219 MI2_MobHealthText:SetFont( fontName, fontSize )
220 MI2_MobManaText:SetFont( fontName, fontSize )
221 end
222  
223 end -- of MI2_MobHealth_SetFont()
224  
225  
226 -----------------------------------------------------------------------------
227 -- MI2_MobHealth_SetPos()
228 --
229 -- set position and font for mob health/mana texts
230 -----------------------------------------------------------------------------
231 function MI2_MobHealth_SetPos( )
232 local font
233  
234 -- set poition for health and mana text
235 MI2_MobHealthText:SetPoint( "TOP", "TargetFrameHealthBar", "BOTTOM", MobInfoConfig.HealthPosX, MobInfoConfig.HealthPosY )
236 MI2_MobManaText:SetPoint( "TOP", "TargetFrameManaBar", "BOTTOM", MobInfoConfig.ManaPosX, MobInfoConfig.ManaPosY )
237  
238 -- update font ID and font size
239 MI2_MobHealth_SetFont( MobInfoConfig.TargetFont, MobInfoConfig.TargetFontSize )
240  
241 -- redisplay health / mana values
242 MobHealth_Display()
243 end -- of MI2_MobHealth_SetPos()
244  
245  
246 -----------------------------------------------------------------------------
247 -- MI2_MobHealth_Reset()
248 -----------------------------------------------------------------------------
249 function MI2_MobHealth_Reset()
250 MI2_MobHealth_ClearTargetData()
251 MobHealthDB = {}
252 MobHealthPlayerDB = {}
253 end
254  
255  
256 -----------------------------------------------------------------------------
257 -- MI2_SaveTargetHealthData()
258 --
259 -- Save health data for current target in health database
260 -----------------------------------------------------------------------------
261 function MI2_SaveTargetHealthData()
262 if MI2_Target.index and MI2_Target.totalPercent > 0 and MI2_Target.totalPercent < 10000 then
263 MobHealth_Set( MI2_Target.healthDB, MI2_Target.index, MI2_Target.totalDamage, MI2_Target.totalPercent )
264 end
265 end -- MI2_SaveTargetHealthData()
266  
267  
268 -----------------------------------------------------------------------------
269 -- MI2_MobHealth_ClearTargetData()
270 --
271 -- Clear mob health data for current target
272 -----------------------------------------------------------------------------
273 function MI2_MobHealth_ClearTargetData()
274 if MI2_Target.index then
275 MI2_Target.healthDB[MI2_Target.index] = nil
276 MI2_Target = {}
277 MobHealth_Display()
278 end
279 end -- MI2_MobHealth_ClearTargetData()
280