vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | -- |
||
3 | -- This file explains in great detail all information and functions required for |
||
4 | -- external access from other AddOns to MobInfo2 and the built-in MobHealth. |
||
5 | -- It tells you how to best check for the presence of the AddOn(s) and |
||
6 | -- provides functions for easy access to the MobInfo database and the |
||
7 | -- MobHealth database. |
||
8 | -- |
||
9 | -- There are 3 sections: |
||
10 | -- |
||
11 | -- Section 1 : How to best check if (any) MobHealth AddOn is available ? |
||
12 | -- Section 2 : Functions for accessing ALL MobHealth data |
||
13 | -- Section 3 : Functions for accessing ALL MobInfo data |
||
14 | -- Section 4 : Free Source Code for Accessing MobHealth in a Compatible Way |
||
15 | |||
16 | |||
17 | -- ========================================================================== |
||
18 | -- Section 1 : How to best check if (any) MobHealth AddOn is available ? |
||
19 | -- ========================================================================== |
||
20 | -- |
||
21 | -- Info: there are at present three known AddOns that provide MobHealth |
||
22 | -- functionality and MobHealth data : "MobHealth by Telo", "MobHealth2 |
||
23 | -- by Wyv" and MobInfo2. All three AddOns provide their service in |
||
24 | -- extremely similar, almost identical fashion. |
||
25 | -- |
||
26 | -- The best way to check whether any one MobHealth service is available |
||
27 | -- is to add this simple "if" to your "VARIABLES_LOADED" event handler: |
||
28 | -- |
||
29 | -- if MobHealthFrame then |
||
30 | -- ...... |
||
31 | -- end |
||
32 | -- |
||
33 | -- Its all that is required. If the condition is true you can rest |
||
34 | -- assured that one of the MobHealth AddOns is present. Please do NOT |
||
35 | -- place the check into the "OnLoad" event handler. That is potentially |
||
36 | -- unsave and error prone. "OnLoad" is called at a time where NOT all |
||
37 | -- AddOns have been loaded. On the other hand "VARIABLES_LOADED" is |
||
38 | -- invoked at a time when you can be sure that ALL AddOns have been |
||
39 | -- loaded and can thus be checked for and accessed. |
||
40 | -- ========================================================================== |
||
41 | |||
42 | |||
43 | -- ========================================================================== |
||
44 | -- Section 2 : Functions for accessing ALL MobHealth data |
||
45 | -- ========================================================================== |
||
46 | -- |
||
47 | -- Note that Telos MobHealth (sadly!) does not offer such interface |
||
48 | -- functions. They got invented by MobHealth2. They get officially supported |
||
49 | -- by MobInfo. I will suggest to Telo to add them to his MobHealth |
||
50 | -- AddOn as well for the sake of compatibility. |
||
51 | -- |
||
52 | -- This is the RECOMMENDED way to access the MobHealth data. Using the |
||
53 | -- functions make you independant of how the data is stored internally |
||
54 | -- within the AddOns database. Please do NOT access the AddOns database |
||
55 | -- variable directly. Instead ALWAYS use one of the three functions |
||
56 | -- listed below. |
||
57 | -- |
||
58 | -- In the future I plan to make considerable changes to the way that |
||
59 | -- MobHealth stores its data. This will have great advantages for the |
||
60 | -- AddOn, but will result in problems for AddOns that access the database |
||
61 | -- variable directly. The source code for these functions is in |
||
62 | -- "MI2_Health.lua". |
||
63 | -- |
||
64 | -- Additional compatibility note: |
||
65 | -- ------------------------------ |
||
66 | -- In order to retain compatibility to Telos MobHealth you will have to |
||
67 | -- support both : a) the direct access to "MobHealthDB" and b) the |
||
68 | -- indirect access using the functions below. Here is an example of |
||
69 | -- how to do that (works for all 3 functions): |
||
70 | -- |
||
71 | -- if MobHealth_PPP then |
||
72 | -- ... code that uses "MobHealth_PPP()" |
||
73 | -- else |
||
74 | -- ... your old code that uses "MobHealthDB" |
||
75 | -- end |
||
76 | -- |
||
77 | -- To make it easier for you I have decided to simply supply you with the |
||
78 | -- entire necessary source code right here, for free. Go to section 4 and |
||
79 | -- simply copy the source code of the 3 local functions you find there |
||
80 | -- into your own AddOn. They are 100% compatible with the interface of |
||
81 | -- the 3 functions that I offer right here in section 2. |
||
82 | -- |
||
83 | ----------------------------------------------------------------------------- |
||
84 | -- function MobHealth_GetTargetCurHP() |
||
85 | -- |
||
86 | -- Return current health points value for the current target as an integer |
||
87 | -- value. Return nil if there is no current target. |
||
88 | -- |
||
89 | -- Example: |
||
90 | -- local targetCurrentHealth = MobHealth_GetTargetCurHP(); |
||
91 | -- if targetCurrentHealth then |
||
92 | -- ....... |
||
93 | -- end |
||
94 | ----------------------------------------------------------------------------- |
||
95 | - |
||
96 | ----------------------------------------------------------------------------- |
||
97 | -- function MobHealth_GetTargetMaxHP() |
||
98 | -- |
||
99 | -- Return maximum health points value for the current target as an integer |
||
100 | -- value. Return nil if there is no current target. |
||
101 | -- |
||
102 | -- Example: |
||
103 | -- local targetMaxHealth = MobHealth_GetTargetMaxHP(); |
||
104 | -- if targetMaxHealth then |
||
105 | -- ....... |
||
106 | -- end |
||
107 | ----------------------------------------------------------------------------- |
||
108 | -- |
||
109 | ----------------------------------------------------------------------------- |
||
110 | -- function MobHealth_PPP( index ) |
||
111 | -- |
||
112 | -- Return the Points-Per-Percent (PPP) value for a Mob identified by its index. |
||
113 | -- The index is the concatination of the Mob name and the Mob level (see |
||
114 | -- example below). 0 is returned if the PPP value is not available for |
||
115 | -- the given index. The example also shows how to calculate the actual |
||
116 | -- health points from the health percentage and the PPP value |
||
117 | -- |
||
118 | -- Example: |
||
119 | -- local name = UnitName("target"); |
||
120 | -- local level = UnitLevel("target"); |
||
121 | -- local index = name..":"..level; |
||
122 | -- local ppp = MobHealth_PPP( index ); |
||
123 | -- local healthPercent = UnitHealth("target"); |
||
124 | -- local curHealth = math.floor( healthPercent * ppp + 0.5); |
||
125 | -- local maxHealth = math.floor( 100 * ppp + 0.5); |
||
126 | ----------------------------------------------------------------------------- |
||
127 | -- |
||
128 | -- ========================================================================== |
||
129 | |||
130 | |||
131 | -- ========================================================================== |
||
132 | -- Section 3 : Functions for accessing ALL MobInfo data |
||
133 | -- ========================================================================== |
||
134 | -- |
||
135 | -- Please ALWAYS use these functions for accessing the data in the MobInfo |
||
136 | -- database. This is the only safe and reliable way to access the MobInfo |
||
137 | -- data. For reasons of optimisation or extension the database variable(s) |
||
138 | -- might change spontaneously in layout and/or name. Using the interface |
||
139 | -- functions gives you the guarantee that you always get returned the |
||
140 | -- correct data. |
||
141 | -- |
||
142 | ----------------------------------------------------------------------------- |
||
143 | -- MobInfo_GetData( index ) |
||
144 | -- |
||
145 | -- !!! TO BE DONE !!! |
||
146 | -- |
||
147 | -- Sorry, but I have not yet found the time to finish this function. It |
||
148 | -- will become available with version 2.2 of the MobInfo AddOn. |
||
149 | ----------------------------------------------------------------------------- |
||
150 | -- |
||
151 | -- ========================================================================== |
||
152 | |||
153 | |||
154 | -- ========================================================================== |
||
155 | -- Section 4 : Free Source Code for Accessing MobHealth in a Compatible Way |
||
156 | -- ========================================================================== |
||
157 | -- |
||
158 | -- Simply copy the entire 3 function source code given below into your own |
||
159 | -- AddOn and then call the 3 functions whenever you have to access MobHealth |
||
160 | -- data. |
||
161 | -- |
||
162 | |||
163 | |||
164 | ----------------------------------------------------------------------------- |
||
165 | -- My_MobHealth_PPP( index ) |
||
166 | -- |
||
167 | -- Return the Points-Per-Percent (PPP) value for a Mob identified by its index. |
||
168 | -- The index is the concatination of the Mob name and the Mob level (see |
||
169 | -- example below). 0 is returned if the PPP value is not available for |
||
170 | -- the given index. The example also shows how to calculate the actual |
||
171 | -- health points from the health percentage and the PPP value |
||
172 | -- |
||
173 | -- Example: |
||
174 | -- local name = UnitName("target"); |
||
175 | -- local level = UnitLevel("target"); |
||
176 | -- local index = name..":"..level; |
||
177 | -- local ppp = MobHealth_PPP( index ); |
||
178 | -- local healthPercent = UnitHealth("target"); |
||
179 | -- local curHealth = math.floor( healthPercent * ppp + 0.5); |
||
180 | -- local maxHealth = math.floor( 100 * ppp + 0.5); |
||
181 | ----------------------------------------------------------------------------- |
||
182 | local function My_MobHealth_PPP( index ) |
||
183 | if MobHealth_PPP then |
||
184 | return MobHealth_PPP( index ); |
||
185 | else |
||
186 | if( index and MobHealthDB[index] ) then |
||
187 | local s, e, pts, pct = string.find(MobHealthDB[index], "^(%d+)/(%d+)$"); |
||
188 | if( pts and pct ) then |
||
189 | pts = pts + 0; |
||
190 | pct = pct + 0; |
||
191 | if( pct ~= 0 ) then |
||
192 | return pts / pct; |
||
193 | end |
||
194 | end |
||
195 | end |
||
196 | return 0; |
||
197 | end |
||
198 | end -- of My_MobHealth_PPP |
||
199 | |||
200 | |||
201 | ----------------------------------------------------------------------------- |
||
202 | -- My_MobHealth_GetTargetCurHP() |
||
203 | -- |
||
204 | -- Return current health points value for the current target as an integer |
||
205 | -- value. Return nil if there is no current target. |
||
206 | -- |
||
207 | -- Example: |
||
208 | -- local targetCurrentHealth = MobHealth_GetTargetCurHP(); |
||
209 | -- if targetCurrentHealth then |
||
210 | -- ....... |
||
211 | -- end |
||
212 | ----------------------------------------------------------------------------- |
||
213 | local function My_MobHealth_GetTargetCurHP() |
||
214 | if MobHealth_GetTargetCurHP then |
||
215 | return MobHealth_GetTargetCurHP(); |
||
216 | else |
||
217 | local name = UnitName("target"); |
||
218 | local level = UnitLevel("target"); |
||
219 | local healthPercent = UnitHealth("target"); |
||
220 | if name and level and healthPercent then |
||
221 | local index = name..":"..level; |
||
222 | local ppp = MobHealth_PPP( index ); |
||
223 | return math.floor( healthPercent * ppp + 0.5); |
||
224 | end |
||
225 | end |
||
226 | return 0; |
||
227 | end -- of My_MobHealth_GetTargetCurHP() |
||
228 | |||
229 | |||
230 | ----------------------------------------------------------------------------- |
||
231 | -- My_MobHealth_GetTargetMaxHP() |
||
232 | -- |
||
233 | -- Return maximum health points value for the current target as an integer |
||
234 | -- value. Return nil if there is no current target. |
||
235 | -- |
||
236 | -- Example: |
||
237 | -- local targetMaxHealth = MobHealth_GetTargetMaxHP(); |
||
238 | -- if targetMaxHealth then |
||
239 | -- ....... |
||
240 | -- end |
||
241 | ----------------------------------------------------------------------------- |
||
242 | local function My_MobHealth_GetTargetMaxHP() |
||
243 | if MobHealth_GetTargetMaxHP then |
||
244 | return MobHealth_GetTargetMaxHP(); |
||
245 | else |
||
246 | local name = UnitName("target"); |
||
247 | local level = UnitLevel("target"); |
||
248 | if name and level then |
||
249 | local index = name..":"..level; |
||
250 | local ppp = MobHealth_PPP( index ); |
||
251 | return math.floor( 100 * ppp + 0.5); |
||
252 | end |
||
253 | end |
||
254 | return 0; |
||
255 | end -- of My_MobHealth_GetTargetMaxHP() |
||
256 | |||
257 | -- |
||
258 | -- ========================================================================== |