vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --Hemco's Pet Info Titan UI plugin.
2 --Version 1.4 beta 07-Aug-05
3 --Thanks to Scarabeus for the German localization.
4 --1.4 - Added support for warlocks.
5 --1.3 - Added attributes display.
6 -- Added XP info to the XP bar.
7 --1.2 - Added DPS stats.
8 -- Fixed name/level display settings bug.
9 -- Upated German localization -- Thanks again Scarabeus.
10 --1.1 - German localization -- Thanks Scarabeus
11 -- Added options to show name, level, or both.
12 -- 1600 update.
13 --1.0 - Initial release.
14  
15  
16  
17 TITAN_PETINFO_ID = "PetInfo";
18 TITAN_PETINFO_FREQ = 1;
19 TITAN_PETTINFO_PERCENT_FORMAT = "%d (%.1f%%)";
20 TITAN_PETTINFO_AS_FORMAT = "%.2f";
21 TITAN_PETTINFO_DPS_FORMAT = "%.1f";
22 avgSpan = 30;
23 uiLoaded = true;
24 xpHistory = {};
25 dpsHistory = {};
26 petAttribs = {};
27 battleDamage = 0;
28 battleStartTime = 0;
29 petLevel = "";
30 petName = "";
31 petNameChk = "";
32 petSex = "";
33 petHappiness = 0;
34 happinessStart = 0;
35 happiness = 0;
36 playerClass = "";
37 englishClass = "";
38 isHunter = false;
39  
40 --Slash commands
41  
42 function TitanPanelPetInfoButton_SlashCmd(command)
43 local cmd;
44 cmd = string.lower(command);
45 if cmd == "start" then
46 happiness = 0;
47 happinessStart = GetTime();
48 end
49 end
50  
51 --Button creation functions
52  
53 function TitanPanelPetInfoButton_OnLoad()
54  
55 this.registry = {
56 id = TITAN_PETINFO_ID,
57 menuText = TITAN_PETINFO_MENU_TEXT,
58 buttonTextFunction = "TitanPanelPetInfoButton_GetButtonText",
59 tooltipTitle = TITAN_PETINFO_TOOLTIP,
60 tooltipTextFunction = "TitanPanelPetInfoButton_GetTooltipText",
61 frequency = TITAN_PETINFO_FREQ,
62 iconWidth = 16,
63 savedVariables = {
64 ShowPetName = 1,
65 ShowPetLevel = 1,
66 ShowLabelText = 1,
67 ShowColoredText = 1,
68 ShowBarText = 1,
69 ShowPetAttrb = 1,
70 }
71 };
72  
73 this:RegisterEvent("PLAYER_XP_UPDATE");
74 this:RegisterEvent("PET_ATTACK_START");
75 this:RegisterEvent("PET_ATTACK_STOP");
76 --this:RegisterEvent("PET_UI_UPDATE");
77 this:RegisterEvent("CHAT_MSG_COMBAT_PET_HITS");
78 this:RegisterEvent("CHAT_MSG_SPELL_PET_DAMAGE");
79 this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS");
80  
81 SlashCmdList["TITAN_PET_INFO"] = TitanPanelPetInfoButton_SlashCmd;
82 SLASH_TITAN_PET_INFO1 = "/tpi";
83  
84 playerClass, englishClass = UnitClass("player");
85 if englishClass == "HUNTER" then
86 isHunter = true;
87 end
88  
89 end
90  
91 function TitanPanelPetInfoButton_OnEvent()
92 if (event == "PET_ATTACK_START") then
93 battleDamage = 0;
94 battleStartTime = GetTime();
95 happiness = 0;
96 happinessStart = GetTime();
97 elseif (event == "PET_ATTACK_STOP") then
98 length = GetTime() - battleStartTime;
99 TitanPanelPetInfoButton_AddDPSEntry(length, battleDamage);
100 elseif (event == "PET_UI_UPDATE") then
101 --TitanPanelPetInfoButton_OnXPUpdate();
102 elseif (event == "CHAT_MSG_COMBAT_PET_HITS" or event == "CHAT_MSG_SPELL_PET_DAMAGE") then
103 TitanPanelPetInfoButton_AddDamageEntry(arg1);
104 elseif (event == "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS") then
105 --TitanPanelPetInfoButton_GetHappyGain(arg1);
106 end
107 end
108  
109 function TitanPanelPetInfoButton_GetButtonText(id)
110 local button, id = TitanUtils_GetButton(id, true);
111  
112 if HasPetUI() then
113 petName = UnitName("pet");
114 petLevel = UnitLevel("pet");
115 if UnitSex("pet") == 2 then
116 petSex = TITAN_PETINFO_MENU_FEMALE;
117 else
118 petSex = TITAN_PETINFO_MENU_MALE;
119 end
120  
121 local currentXP, totalXP, toLevelXP = TitanPanelPetInfoButton_GetPetExperience();
122 local timeLeft, XPPerMin = TitanPanelPetInfoButton_XPTimeLeft();
123 local barText = TitanPanelPetInfoButton_BarText(toLevelXP, timeLeft);
124 --TitanPanelPetInfoButton_HappinessCheck();
125 TitanPetInfoText:SetText(barText)
126  
127 if TitanGetVar(TITAN_PETINFO_ID, "ShowPetLevel") and TitanGetVar(TITAN_PETINFO_ID, "ShowPetName") then
128 return TITAN_PETINFO_BUTTON_LABEL_PETINFO, TitanUtils_GetHighlightText(petName),
129 TITAN_PETINFO_BUTTON_LABEL_PETLEVEL, TitanUtils_GetHighlightText(petLevel);
130 elseif TitanGetVar(TITAN_PETINFO_ID, "ShowPetName") then
131 return TITAN_PETINFO_BUTTON_LABEL_PETINFO, TitanUtils_GetHighlightText(petName);
132 else
133 return TITAN_PETINFO_BUTTON_LABEL_PETLEVEL, TitanUtils_GetHighlightText(petLevel);
134 end
135  
136 else
137 TitanPetInfoText:SetText("");
138 return TITAN_PETINFO_BUTTON_LABEL_NOPET;
139 end
140  
141 end
142  
143 function TitanPanelPetInfoButton_GetTooltipText()
144 local currentXP, totalXP, toLevelXP = TitanPanelPetInfoButton_GetPetExperience();
145 local petType = UnitCreatureFamily("pet");
146 local currentXPPercent = currentXP / totalXP * 100;
147 local toLevelXPPercent = toLevelXP / totalXP * 100;
148 local totalTP, usedTP = GetPetTrainingPoints();
149 local freeTP = totalTP - usedTP;
150 local atkSpeed = UnitAttackSpeed("pet");
151 local atkRate = UnitAttackBothHands("pet");
152 local lowDmg, hiDmg, offlowDmg, offhiDmg, posBuff, negBuff, percentMod = UnitDamage("pet");
153 local listedDPS = (((lowDmg + hiDmg) * .5 + posBuff + negBuff) * percentMod) / atkSpeed;
154 local actualDPS = TitanPanelPetInfoButton_GetActualDPS();
155 TitanPanelPetInfoButton_OnXPUpdate();
156 if HasPetUI() then
157 if isHunter then
158 return ""..
159 TITAN_PETINFO_BUTTON_LABEL_TYPE.."\t"..TitanUtils_GetHighlightText(petType).."\n"..
160 TITAN_PETINFO_BUTTON_LABEL_FOOD.."\t"..TitanUtils_GetHighlightText(BuildListString(GetPetFoodTypes())).."\n"..
161 TITAN_PETINFO_BUTTON_LABEL_LOYALTY.."\t"..TitanUtils_GetHighlightText(GetPetLoyalty()).."\n"..
162 TITAN_PETINFO_MENU_GENDER.."\t"..TitanUtils_GetHighlightText(petSex).."\n"..
163 "\n"..
164 TITAN_PETINFO_BUTTON_LABEL_TRAINING_POINTS.."\t"..TitanUtils_GetHighlightText(freeTP).."\n"..
165 TITAN_PETINFO_BUTTON_LABEL_ARMOR_CLASS.."\t"..TitanUtils_GetHighlightText(UnitArmor("pet")).."\n"..
166 TITAN_PETINFO_BUTTON_LABEL_ATTACK_RATE.."\t"..TitanUtils_GetHighlightText(atkRate).."\n"..
167 TITAN_PETINFO_BUTTON_LABEL_ATTACK_SPEED.."\t"..TitanUtils_GetHighlightText(format(TITAN_PETTINFO_AS_FORMAT, atkSpeed)).."\n"..
168 TITAN_PETINFO_BUTTON_LABEL_DPS_LISTED.."\t"..TitanUtils_GetHighlightText(format(TITAN_PETTINFO_DPS_FORMAT, listedDPS)).."\n"..
169 TITAN_PETINFO_BUTTON_LABEL_DPS_ACTUAL.."\t"..TitanUtils_GetHighlightText(actualDPS).."\n"..
170 "\n"..
171 TitanPanelPetInfoButton_SetStats().."\n"..
172 TitanPanelPetInfoButton_ShowXPInfo(currentXP,currentXPPercent,toLevelXP,toLevelXPPercent,totalXP,timeLeft);
173 else
174 return ""..
175 TITAN_PETINFO_BUTTON_LABEL_TYPE.."\t"..TitanUtils_GetHighlightText(petType).."\n"..
176 TITAN_PETINFO_MENU_GENDER.."\t"..TitanUtils_GetHighlightText(petSex).."\n"..
177 "\n"..
178 TITAN_PETINFO_BUTTON_LABEL_ARMOR_CLASS.."\t"..TitanUtils_GetHighlightText(UnitArmor("pet")).."\n"..
179 TITAN_PETINFO_BUTTON_LABEL_ATTACK_RATE.."\t"..TitanUtils_GetHighlightText(atkRate).."\n"..
180 TITAN_PETINFO_BUTTON_LABEL_ATTACK_SPEED.."\t"..TitanUtils_GetHighlightText(format(TITAN_PETTINFO_AS_FORMAT, atkSpeed)).."\n"..
181 TITAN_PETINFO_BUTTON_LABEL_DPS_LISTED.."\t"..TitanUtils_GetHighlightText(format(TITAN_PETTINFO_DPS_FORMAT, listedDPS)).."\n"..
182 TITAN_PETINFO_BUTTON_LABEL_DPS_ACTUAL.."\t"..TitanUtils_GetHighlightText(actualDPS).."\n"..
183 "\n"..
184 TitanPanelPetInfoButton_SetStats();
185 end
186 else
187 return
188 end
189  
190 end
191  
192 function TitanPanelRightClickMenu_PreparePetInfoMenu()
193 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_PETINFO_ID].menuText);
194  
195 TitanPanelRightClickMenu_AddSpacer();
196 TitanPanelRightClickMenu_AddCommand(TITAN_PETINFO_MENU_RESET_SESSION, TITAN_PETINFO_ID, "TitanPanelPetInfoButton_ResetSession");
197  
198 TitanPanelRightClickMenu_AddSpacer();
199 local info = {};
200 info.text = TITAN_PETINFO_MENU_SHOW_PET_LEVEL;
201 info.func = TitanPanelPetInfoButton_ShowPetLevel
202 info.checked = TitanGetVar(TITAN_PETINFO_ID, "ShowPetLevel");
203 UIDropDownMenu_AddButton(info);
204  
205 info = {};
206 info.text = TITAN_PETINFO_MENU_SHOW_PET_NAME;
207 info.func = TitanPanelPetInfoButton_ShowPetName
208 info.checked = TitanGetVar(TITAN_PETINFO_ID, "ShowPetName");
209 UIDropDownMenu_AddButton(info);
210  
211 TitanPanelRightClickMenu_AddSpacer();
212 info = {};
213 info.text = TITAN_PETINFO_MENU_SHOW_BAR_TEXT;
214 info.func = TitanPanelPetInfoButton_ShowBarText
215 info.checked = TitanGetVar(TITAN_PETINFO_ID, "ShowBarText");
216 UIDropDownMenu_AddButton(info);
217 info = {};
218 info.text = TITAN_PETINFO_MENU_SHOW_PET_ATTRIB;
219 info.func = TitanPanelPetInfoButton_ShowPetAttrb
220 info.checked = TitanGetVar(TITAN_PETINFO_ID, "ShowPetAttrb");
221 UIDropDownMenu_AddButton(info);
222  
223 TitanPanelRightClickMenu_AddSpacer();
224 TitanPanelRightClickMenu_AddToggleLabelText(TITAN_PETINFO_ID);
225  
226 TitanPanelRightClickMenu_AddSpacer();
227 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_PETINFO_ID, TITAN_PANEL_MENU_FUNC_HIDE);
228 end
229  
230 function TitanPanelPetInfoButton_ResetSession()
231 xpHistory = {};
232 dpsHistory = {};
233 end
234  
235 function TitanPanelPetInfoButton_ShowPetName()
236 if TitanGetVar(TITAN_PETINFO_ID, "ShowPetLevel") and TitanGetVar(TITAN_PETINFO_ID, "ShowPetName") then
237 TitanSetVar(TITAN_PETINFO_ID, "ShowPetName", nil);
238 else
239 TitanSetVar(TITAN_PETINFO_ID, "ShowPetName", 1);
240 end
241  
242 TitanPanelButton_UpdateButton(TITAN_PETINFO_ID);
243 end
244  
245 function TitanPanelPetInfoButton_ShowPetLevel()
246 if TitanGetVar(TITAN_PETINFO_ID, "ShowPetLevel") and TitanGetVar(TITAN_PETINFO_ID, "ShowPetName") then
247 TitanSetVar(TITAN_PETINFO_ID, "ShowPetLevel", nil);
248 else
249 TitanSetVar(TITAN_PETINFO_ID, "ShowPetLevel", 1);
250 end
251  
252 TitanPanelButton_UpdateButton(TITAN_PETINFO_ID);
253 end
254  
255 function TitanPanelPetInfoButton_ShowBarText()
256 TitanSetVar(TITAN_PETINFO_ID, "ShowBarText", TitanUtils_Toggle(TitanGetVar(TITAN_PETINFO_ID, "ShowBarText")))
257 end
258  
259 function TitanPanelPetInfoButton_ShowPetAttrb()
260 TitanSetVar(TITAN_PETINFO_ID, "ShowPetAttrb", TitanUtils_Toggle(TitanGetVar(TITAN_PETINFO_ID, "ShowPetAttrb")))
261 end
262  
263 function TitanPanelPetInfoButton_SetStats()
264 local attrbStr = "";
265 for i=1, NUM_PET_STATS, 1 do
266 local label = getglobal("PetStatFrame"..i.."Label");
267 local text = getglobal("PetStatFrame"..i.."StatText");
268 local frame = getglobal("PetStatFrame"..i);
269 local stat;
270 local effectiveStat;
271 local posBuff;
272 local negBuff;
273 attrbStr = attrbStr..TEXT(getglobal("SPELL_STAT"..(i-1).."_NAME")).."\t";
274 stat, effectiveStat, posBuff, negBuff = UnitStat("pet", i);
275  
276 if ( ( posBuff == 0 ) and ( negBuff == 0 ) ) then
277 attrbStr = attrbStr..TitanUtils_GetHighlightText(effectiveStat);
278 else
279  
280 -- If there are any negative buffs then show the main number in red even if there are
281 -- positive buffs. Otherwise show in green.
282 if ( negBuff < 0 ) then
283 attrbStr = attrbStr..RED_FONT_COLOR_CODE..effectiveStat..FONT_COLOR_CODE_CLOSE;
284 else
285 attrbStr = attrbStr..GREEN_FONT_COLOR_CODE..effectiveStat..FONT_COLOR_CODE_CLOSE;
286 end
287 end
288 attrbStr = attrbStr.."\n"
289 end
290 if TitanGetVar(TITAN_PETINFO_ID, "ShowPetAttrb") then
291 return attrbStr;
292 else
293 return "";
294 end
295 end
296  
297  
298 function TitanPanelPetInfoButton_ShowXPInfo(currentXP,currentXPPercent,toLevelXP,toLevelXPPercent,totalXP,timeLeft)
299 local timeLeft, XPPerMin = TitanPanelPetInfoButton_XPTimeLeft();
300 return ""..
301 "\n"..
302 TITAN_PETINFO_BUTTON_LABEL_CURRENT_XP.."\t"..TitanUtils_GetHighlightText(format(TITAN_PETTINFO_PERCENT_FORMAT, currentXP, currentXPPercent)).."\n"..
303 TITAN_PETINFO_BUTTON_LABEL_NEEDED_XP.."\t"..TitanUtils_GetHighlightText(format(TITAN_PETTINFO_PERCENT_FORMAT, toLevelXP, toLevelXPPercent)).."\n"..
304 TITAN_PETINFO_BUTTON_LABEL_TOTAL_XP.."\t"..TitanUtils_GetHighlightText(totalXP).."\n"..
305 TITAN_PETINFO_BUTTON_LABEL_LEVEL_TIME_LEFT.."\t"..TitanUtils_GetHighlightText(timeLeft).."\n"..
306 TITAN_PETINFO_BUTTON_LABEL_XP_PER_MIN.."\t"..TitanUtils_GetHighlightText(XPPerMin);
307 end
308  
309 --Pet time-to-level funtions
310  
311 function TitanPanelPetInfoButton_SecondsToTime(seconds)
312  
313 if not seconds or seconds < 0 then
314 return '-:--:--';
315 end
316  
317 local s = math.mod(seconds, 60);
318 local m = math.floor(math.mod(seconds, 3600) / 60);
319 local h = math.floor(seconds / 3600);
320  
321 return string.format('%d:%02d:%02d', h, m, s);
322  
323 end
324  
325 function TitanPanelPetInfoButton_GetPetExperience()
326  
327 local currentXP, totalXP = GetPetExperience();
328 local toLevelXP = totalXP - currentXP;
329  
330 return currentXP, totalXP, toLevelXP;
331  
332 end
333  
334 function TitanPanelPetInfoButton_XPTimeLeft()
335  
336 local xpRate = TitanPanelPetInfoButton_GetXPRate()
337 if (UnitLevel("pet") == UnitLevel("player")) then
338 return TITAN_PETINFO_NOLEVEL1, TITAN_PETINFO_NOLEVEL2;
339 else
340 if xpRate then
341 local timeString = TitanPanelPetInfoButton_GetTimeToLevel(xpRate);
342 local xpPerMin = string.format('%.1f', xpRate * 60);
343 return timeString, xpPerMin;
344 else
345 return "-:--:--", "0.0";
346 end
347 end
348  
349 end
350  
351 function TitanPanelPetInfoButton_OnXPUpdate()
352  
353 local xp = GetPetExperience();
354  
355 if uiLoaded then
356 runningXP = xp;
357 uiLoaded = false;
358 else
359 local xpChange = xp - runningXP;
360 runningXP = xp;
361 if xpChange > 0 then
362 TitanPanelPetInfoButton_AddXPEntry(xpChange);
363 TitanPanelPetInfoButton_RemoveOldXP();
364 end
365 end
366  
367 end
368  
369 function TitanPanelPetInfoButton_RemoveOldXP()
370 local earliest = GetTime() - avgSpan * 60;
371 while xpHistory[1] and xpHistory[1].time < earliest do
372 table.remove(xpHistory, 1);
373 end
374 if xpHistory[1] then
375 xpHistory[1].xpChange = 0;
376 end
377 end
378  
379 function TitanPanelPetInfoButton_AddXPEntry(xpChange)
380 table.insert(xpHistory, {time = GetTime(), xpChange = xpChange});
381 end
382  
383 function TitanPanelPetInfoButton_GetXPRate()
384  
385 if table.getn(xpHistory) <= 1 then
386 return
387 end
388  
389 local start = xpHistory[1].time;
390 local elapsed = GetTime() - start;
391  
392 if elapsed < 1 then
393 return
394 end
395  
396 local xpEarned = 0;
397  
398 for i,j in pairs(xpHistory) do
399 xpEarned = xpEarned + j.xpChange;
400 end
401  
402 return xpEarned / elapsed;
403  
404 end
405  
406 function TitanPanelPetInfoButton_GetTimeToLevel(xpRate)
407 local currentXP, totalXP, toLevelXP = TitanPanelPetInfoButton_GetPetExperience();
408 return TitanPanelPetInfoButton_SecondsToTime(tonumber(math.floor(toLevelXP / xpRate)));
409 end
410  
411 function TitanPanelPetInfoButton_BarText(toLevelXP, timeLeft)
412 local barText;
413 if TitanGetVar(TITAN_PETINFO_ID, "ShowBarText") and isHunter then
414 local ttl = timeLeft;
415 if timeLeft == TITAN_PETINFO_NOLEVEL1 then
416 ttl = "-:--:--"
417 end
418 barText = petName.."'s needed XP:"..toLevelXP.." TTL:"..ttl;
419 return barText;
420 else
421 return
422 end
423 end
424  
425 --Actual pet DPS functions
426  
427 function TitanPanelPetInfoButton_AddDPSEntry(length, damage)
428 table.insert(dpsHistory, {time = GetTime(), length = length, damage = damage});
429 end
430  
431 function TitanPanelPetInfoButton_AddDamageEntry(str)
432 local dam = TitanPanelPetInfoButton_GetPetDamage(str);
433 battleDamage = battleDamage + dam;
434 end
435  
436 function TitanPanelPetInfoButton_GetPetDamage(str)
437 local damage = 0;
438 local sStart,sEnd = string.find(str, '%d+') ;
439  
440 if (sStart ~= nil) then
441 damage = tonumber(string.sub(str,sStart,sEnd));
442 end
443 return damage;
444 end
445  
446 function TitanPanelPetInfoButton_GetActualDPS()
447  
448 if table.getn(dpsHistory) < 1 then
449 return "--";
450 end
451  
452 local totalDam = 0;
453 local elapsed = 0;
454  
455 for i,j in pairs(dpsHistory) do
456 totalDam = totalDam + j.damage;
457 elapsed = elapsed + j.length;
458 end
459 return format(TITAN_PETTINFO_DPS_FORMAT, totalDam / elapsed);
460  
461 end
462  
463 function TitanPanelPetInfoButton_RemoveOldDPS()
464 local earliest = GetTime() - avgSpan * 60;
465 while dpsHistory[1] and dpsHistory[1].time < earliest do
466 table.remove(dpsHistory, 1);
467 end
468 end
469  
470 --Happiness functions
471  
472 function TitanPanelPetInfoButton_GetHappyGain(arg1)
473 local effect = 0;
474 if string.find(arg1, '^'..petName..' .* Happiness') then
475 effect = tonumber(string.find(arg1, '%d+'));
476 happiness = happiness + effect;
477 if effect < 35 then
478 TitanPanelPetInfoButton_HappinessCalc();
479 end
480 end
481 end
482  
483 function TitanPanelPetInfoButton_HappinessCalc()
484 local loss = 0;
485  
486 loss = happiness / (GetTime() - happinessStart);
487 --TPPIB_Debug(loss);
488 happinessStart = 0
489 end
490  
491 function TitanPanelPetInfoButton_HappinessCheck()
492 if happinessStart > 0 then
493 if (GetTime() - happinessStart > 60) and (GetTime() - happinessStart < 61) then
494 PetFeeder_Feed();
495 end
496 end
497 end
498  
499 --Debug function
500  
501 function TPPIB_Debug(msg)
502 DEFAULT_CHAT_FRAME:AddMessage(msg);
503 end