forked from kc8pnd/MobInfo2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadMe_MobInfo_API.txt
321 lines (305 loc) · 13.1 KB
/
ReadMe_MobInfo_API.txt
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
--
-- This file explains in great detail all information and functions of
-- the MobInfo2 external API and the built-in MobHealth external API.
-- (API = Application Programmers Interface)
--
-- It tells you how to best check for the presence of the AddOn(s) and
-- provides functions for easy access to the MobInfo database and the
-- MobHealth database.
--
-- There are 3 sections:
--
-- Section 1 : How to best check if (any) MobHealth AddOn is available ?
-- Section 2 : Functions for accessing ALL MobHealth data
-- Section 3 : Functions for accessing ALL MobInfo data
-- Section 4 : Free Source Code for Accessing MobHealth in a Compatible Way
-- ==========================================================================
-- Section 1 : How to best check if (any) MobHealth AddOn is available ?
-- ==========================================================================
--
-- Info: there are at present three known AddOns that provide MobHealth
-- functionality and MobHealth data : "MobHealth by Telo", "MobHealth2
-- by Wyv" and MobInfo2. All three AddOns provide their service in
-- extremely similar, almost identical fashion.
--
-- The best way to check whether any one MobHealth service is available
-- is to add this simple "if" to your "VARIABLES_LOADED" event handler:
--
-- if MobHealthFrame then
-- ......
-- end
--
-- Its all that is required. If the condition is true you can rest
-- assured that one of the MobHealth AddOns is present. Please do NOT
-- place the check into the "OnLoad" event handler. That is potentially
-- unsave and error prone. "OnLoad" is called at a time where NOT all
-- AddOns have been loaded. On the other hand "VARIABLES_LOADED" is
-- invoked at a time when you can be sure that ALL AddOns have been
-- loaded and can thus be checked for and accessed.
-- ==========================================================================
-- ==========================================================================
-- Section 2 : Functions for accessing ALL MobHealth data
-- ==========================================================================
--
-- Note that Telos MobHealth (sadly!) does not offer such interface
-- functions. They got invented by MobHealth2. They get officially supported
-- by MobInfo. I will suggest to Telo to add them to his MobHealth
-- AddOn as well for the sake of compatibility.
--
-- This is the RECOMMENDED way to access the MobHealth data. Using the
-- functions make you independant of how the data is stored internally
-- within the AddOns database. Please do NOT access the AddOns database
-- variable directly. Instead ALWAYS use one of the three functions
-- listed below.
--
-- In the future I plan to make considerable changes to the way that
-- MobHealth stores its data. This will have great advantages for the
-- AddOn, but will result in problems for AddOns that access the database
-- variable directly. The source code for these functions is in
-- "MI2_Health.lua".
--
-- Additional compatibility note:
-- ------------------------------
-- In order to retain compatibility to Telos MobHealth you will have to
-- support both : a) the direct access to "MobHealthDB" and b) the
-- indirect access using the functions below. Here is an example of
-- how to do that (works for all 3 functions):
--
-- if MobHealth_PPP then
-- ... code that uses "MobHealth_PPP()"
-- else
-- ... your old code that uses "MobHealthDB"
-- end
--
-- To make it easier for you I have decided to simply supply you with the
-- entire necessary source code right here, for free. Go to section 4 and
-- simply copy the source code of the 3 local functions you find there
-- into your own AddOn. They are 100% compatible with the interface of
-- the 3 functions that I offer right here in section 2.
--
-----------------------------------------------------------------------------
-- function MobHealth_GetTargetCurHP()
--
-- Return current health points value for the current target as an integer
-- value. Return nil if there is no current target.
--
-- Example:
-- local targetCurrentHealth = MobHealth_GetTargetCurHP();
-- if targetCurrentHealth then
-- .......
-- end
-----------------------------------------------------------------------------
-
-----------------------------------------------------------------------------
-- function MobHealth_GetTargetMaxHP()
--
-- Return maximum health points value for the current target as an integer
-- value. Return nil if there is no current target.
--
-- Example:
-- local targetMaxHealth = MobHealth_GetTargetMaxHP();
-- if targetMaxHealth then
-- .......
-- end
-----------------------------------------------------------------------------
--
-----------------------------------------------------------------------------
-- function MobHealth_PPP( index )
--
-- Return the Points-Per-Percent (PPP) value for a Mob identified by its index.
-- The index is the concatination of the Mob name and the Mob level (see
-- example below). 0 is returned if the PPP value is not available for
-- the given index. The example also shows how to calculate the actual
-- health points from the health percentage and the PPP value
--
-- Example:
-- local name = UnitName("target");
-- local level = UnitLevel("target");
-- local index = name..":"..level;
-- local ppp = MobHealth_PPP( index );
-- local healthPercent = UnitHealth("target");
-- local curHealth = math.floor( healthPercent * ppp + 0.5);
-- local maxHealth = math.floor( 100 * ppp + 0.5);
-----------------------------------------------------------------------------
--
-- ==========================================================================
-- ==========================================================================
-- Section 3 : Functions for accessing ALL MobInfo data
-- ==========================================================================
--
-- Please ALWAYS use these functions for accessing the data in the MobInfo
-- database. This is the only safe and reliable way to access the MobInfo
-- data. For reasons of optimisation or extension the database variable(s)
-- might change spontaneously in layout and/or name. Using the interface
-- functions gives you the guarantee that you always get returned the
-- correct data.
--
-----------------------------------------------------------------------------
-- MI2_GetMobData( mobName, mobLevel [, unitId] )
--
-- Get and return all the data that MobInfo knows about a given mob.
-- This is an externally available interface function that can be
-- called by other AddOns to access MobInfo data. It should be fast,
-- efficient, and easy to use
--
-- The data describing a Mob is returned in table form as described below.
--
-- To identify the mob you must supply its name and level. You can
-- optionally supply a "unitId" to get additional info:
-- mobName : name of mob, eg. "Forest Lurker"
-- mobLevel : mob level as integer number
-- unitId : optional WoW unit identification, should be either
-- "target" or "mouseover"
--
-- Examples:
-- A. mobData = MI2_GetMobData( "Forest Lurker", 10 )
-- B. mobData = MI2_GetMobData( "Forest Lurker", 10, "target" )
--
-- Return Value:
-- The return value is a LUA table with one table entry for each value that
-- MobInfo can know about a Mob. Note that table entries exist ONLY if the
-- corresponding value has actually been collected for the given Mob.
-- Unrecorded values do NOT exist in the table and thus evaluate to a NIL
-- expression.
--
-- Values you can get without "unitId" (as per Example A above):
-- mobData.healthMax : health maximum
-- mobData.xp : experience value
-- mobData.kills : number of times current player has killed this mob
-- mobData.minDamage : minimum damage done by mob
-- mobData.maxDamage : maximum damage done by mob
-- mobData.dps : dps of Mon against current player
-- mobData.loots : number of times this mob has been looted
-- mobData.emptyLoots : number of times this mob gave empty loot
-- mobData.clothCount : number of times this mob gave cloth loot
-- mobData.copper : total money loot of this mob as copper amount
-- mobData.itemValue : total item value loot of this mob as copper amount
-- mobData.mobType : mob type for special mobs: 1=normal, 2=rare/elite, 3=boss
-- mobData.r1 : number of rarity 1 loot items (grey)
-- mobData.r2 : number of rarity 2 loot items (white)
-- mobData.r3 : number of rarity 3 loot items (green)
-- mobData.r4 : number of rarity 4 loot items (blue)
-- mobData.r5 : number of rarity 5 loot items (purple)
-- mobData.itemList : table that lists all recorded items looted from this mob
-- table entry index gives WoW item ID,
-- table entry value gives item amount
--
-- Additional values you will get with "unitId" (as per Example B above):
-- mobData.class : class of mob as localized text
-- mobData.healthCur : current health of given unit
-- mobData.manaCur : current mana of given unit
-- mobData.manaMax : maximum mana for given unit
--
-- Code Example:
--
-- local mobData = MI2_GetMobData( "Forest Lurker", 10 )
--
-- if mobData.xp then
-- DEFAULT_CHAT_FRAME:AddMessage( "XP = "..mobData.xp )
-- end
--
-- if mobData.copper and mobData.loots then
-- local avgLoot = mobData.copper / mobData.loots
-- DEFAULT_CHAT_FRAME:AddMessage( "average loot = "..avgLoot )
-- end
-----------------------------------------------------------------------------
--
-- ==========================================================================
-- ==========================================================================
-- Section 4 : Free Source Code for Accessing MobHealth in a Compatible Way
-- ==========================================================================
--
-- Simply copy the entire 3 function source code given below into your own
-- AddOn and then call the 3 functions whenever you have to access MobHealth
-- data.
--
-----------------------------------------------------------------------------
-- My_MobHealth_PPP( index )
--
-- Return the Points-Per-Percent (PPP) value for a Mob identified by its index.
-- The index is the concatination of the Mob name and the Mob level (see
-- example below). 0 is returned if the PPP value is not available for
-- the given index. The example also shows how to calculate the actual
-- health points from the health percentage and the PPP value
--
-- Example:
-- local name = UnitName("target");
-- local level = UnitLevel("target");
-- local index = name..":"..level;
-- local ppp = MobHealth_PPP( index );
-- local healthPercent = UnitHealth("target");
-- local curHealth = math.floor( healthPercent * ppp + 0.5);
-- local maxHealth = math.floor( 100 * ppp + 0.5);
-----------------------------------------------------------------------------
local function My_MobHealth_PPP( index )
if MobHealth_PPP then
return MobHealth_PPP( index );
else
if( index and MobHealthDB[index] ) then
local s, e, pts, pct = string.find(MobHealthDB[index], "^(%d+)/(%d+)$");
if( pts and pct ) then
pts = pts + 0;
pct = pct + 0;
if( pct ~= 0 ) then
return pts / pct;
end
end
end
return 0;
end
end -- of My_MobHealth_PPP
-----------------------------------------------------------------------------
-- My_MobHealth_GetTargetCurHP()
--
-- Return current health points value for the current target as an integer
-- value. Return nil if there is no current target.
--
-- Example:
-- local targetCurrentHealth = MobHealth_GetTargetCurHP();
-- if targetCurrentHealth then
-- .......
-- end
-----------------------------------------------------------------------------
local function My_MobHealth_GetTargetCurHP()
if MobHealth_GetTargetCurHP then
return MobHealth_GetTargetCurHP();
else
local name = UnitName("target");
local level = UnitLevel("target");
local healthPercent = UnitHealth("target");
if name and level and healthPercent then
local index = name..":"..level;
local ppp = MobHealth_PPP( index );
return math.floor( healthPercent * ppp + 0.5);
end
end
return 0;
end -- of My_MobHealth_GetTargetCurHP()
-----------------------------------------------------------------------------
-- My_MobHealth_GetTargetMaxHP()
--
-- Return maximum health points value for the current target as an integer
-- value. Return nil if there is no current target.
--
-- Example:
-- local targetMaxHealth = MobHealth_GetTargetMaxHP();
-- if targetMaxHealth then
-- .......
-- end
-----------------------------------------------------------------------------
local function My_MobHealth_GetTargetMaxHP()
if MobHealth_GetTargetMaxHP then
return MobHealth_GetTargetMaxHP();
else
local name = UnitName("target");
local level = UnitLevel("target");
if name and level then
local index = name..":"..level;
local ppp = MobHealth_PPP( index );
return math.floor( 100 * ppp + 0.5);
end
end
return 0;
end -- of My_MobHealth_GetTargetMaxHP()
--
-- ==========================================================================