vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 --Kills To Level : Titan Enabled
3 --Craig Willis
4 --17/05/05
5  
6 local TITAN_KTL_ID = "KTL";
7  
8 KTL_Version="0.53";
9 usingT = 0; --for Titan check
10 usingF = 0; --for Fubar check
11 KTL_XP = 0;
12 KTL_MAXXP = 0; --Needed to remove calc error when leveling
13 KTL_LITTLE_R = 0; --Needed to remove calc error when low rested.
14 KTL_COMBAT = 0;
15 KTL_SMALL = 0;
16  
17 --Loading Functs
18 function TitanPanelKTLButton_OnLoad()
19 this.registry = {
20 id = TITAN_KTL_ID,
21 menuText = TITAN_KTL_MENU_TEXT,
22 buttonTextFunction = "TitanPanelKTLButton_GetButtonText",
23 tooltipTitle = TITAN_KTL_TOOLTIP,
24 savedVariables = {
25 ShowLabelText = 1,
26 }
27 };
28 usingT=1; --Set to 1 when titan is available, 0 when no titan
29 end
30  
31 function TitanPanelKTLButton_OnEvent()
32 TitanPanelButton_UpdateButton(TITAN_KTL_ID);
33 end
34  
35 function Fubar_OnLoad()
36  
37 KillsToLevelFu = FuBarPlugin:new {
38 name = "FuBar - KillsToLevelFu",
39 desc = "Simple calculation mod that used the xp gained, to calculate kills to level",
40 version = KTL_VERSION,
41 aceCompatible = 103,
42 fuCompatible = 102,
43 author = "Willister",
44 email = "willister@hotmail.com",
45 website = "http://ui.worldofwar.net/ui.php?id=746",
46 category = "others",
47 db= AceDatabase:new("KillsToLevelFu"),
48 hasIcon = false,
49 textFrame = "",
50 }
51  
52 function KillsToLevelFu:UpdateText(string)
53 if (string~=null) then
54 self:SetText(string)
55 else
56 local label, text = KTL_TextUpdate();
57 self:SetText(label..text)
58 end
59 end
60  
61 function KillsToLevelFu:OnClick()
62 KTL_LabelChange();
63 local label, text = KTL_TextUpdate();
64 KillsToLevelFu:UpdateText(label..text);
65 end
66  
67 KillsToLevelFu:RegisterForLoad()
68 usingF = 1;
69 end
70  
71 function KillMod_OnLoad()
72 KTLOnLoad();
73 end
74  
75 function KillMod_OnEvent()
76 KTLOnEvent();
77 end
78  
79 --Titan Functs
80 function TitanPanelKTLButton_GetButtonText(id)
81 local labelText, valueText = KTL_TextUpdate();
82 return labelText, TitanUtils_GetHighlightText(valueText);
83 end
84  
85  
86 function TitanPanelRightClickMenu_PrepareKTLMenu()
87 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_KTL_ID].menuText);
88 TitanPanelRightClickMenu_AddToggleLabelText(TITAN_KTL_ID);
89 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_KTL_ID, TITAN_PANEL_MENU_FUNC_HIDE);
90 end
91  
92 function TitanPanelKTLButton_OnClick()
93 KTL_LabelChange();
94 TitanPanelButton_UpdateButton(TITAN_KTL_ID);
95 end
96  
97  
98 --KTL functions
99 function KTLOnLoad()
100 SlashCmdList["KILLCOMMAND"] = KillMod_SlashHandler;
101 SLASH_KILLCOMMAND1 = "/Kill";
102 SLASH_KILLCOMMAND1 = "/ktl";
103  
104  
105 this:RegisterEvent("VARIABLES_LOADED"); --Set hook if needed and check chat frame
106 this:RegisterEvent("PLAYER_XP_UPDATE");
107 this:RegisterEvent("QUEST_FINISHED");
108 this:RegisterEvent("PLAYER_LEAVE_COMBAT");
109 this:RegisterEvent("PLAYER_LOGIN");
110  
111 if( DEFAULT_CHAT_FRAME ) then
112 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_LOADED,KTL_Version));
113 end
114 if FuBar then --Checks on Load for FuBar
115 Fubar_OnLoad();
116 end
117  
118 if (not KTL_ARRAY) then KTL_ARRAY = {}; end --If the array doesnt exist, make it
119  
120 end
121  
122 function KTLOnEvent()
123 if(event == "VARIABLES_LOADED") then
124 KTL_LoadConfig();
125 StatusShow();
126 elseif(event == "PLAYER_XP_UPDATE") then
127 KillMod_XPChange();
128 elseif(event == "QUEST_FINISHED") then
129 if(KTL_ARRAY["KTL_QUEST_STATE"]==0) then --If we are checking for quests, then do the QTL maths
130 KillMod_QuestDone();
131 else
132 end
133 elseif(event == "PLAYER_LEAVE_COMBAT") then
134 if(KTL_ARRAY["KTL_QUEST_STATE"]==0) then
135 KillMod_CombatDone(); --Idea behind this is that after a quest finished event
136 else --Stay in quest mode, until the next time combnat is finished
137 end
138 elseif(event == "PLAYER_LOGIN") then
139 KTL_XP = UnitXP("player");
140 if (KTL_ARRAY["KTL_STATE"] == 6) then
141 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "old xp", KTL_XP));
142 end
143 else
144 DEFAULT_CHAT_FRAME:AddMessage("Unregistered event: "..event);
145 end
146 end
147  
148 function KTL_LoadConfig()
149 if (not KTL_ARRAY["INITIALIZED"]) then --if init isnt true, there is a problem with the array, clear and reset it
150 KTL_ARRAY = {};
151 KTL_ARRAY["INITIALIZED"] = true;
152 KTL_ARRAY["KTL_FRAME"] = 2;
153 KTL_ARRAY["KTL_STATE"] = 1;
154 KTL_ARRAY["KTL_LABEL"] = TITAN_KTL_BUTTON_LABEL;
155 KTL_ARRAY["KTL_QUEST_STATE"] = 1;
156 KTL_ARRAY["KTL_RK"] = 0; --KTL storage
157 KTL_ARRAY["KTL_NK"] = 0;
158 KTL_ARRAY["KTL_Q"] = 0;
159 end
160  
161 KTL_CHAT_FRAME = getglobal("ChatFrame"..KTL_ARRAY["KTL_FRAME"]); --Once saved variables loaded, then hook to the correct chat frame
162 KTL_XP = UnitXP("player"); --Load these when all variables are loaded
163 KTL_MAXXP = UnitXPMax("player");
164 if (KTL_ARRAY["KTL_STATE"] == 6) then
165 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "old xp", KTL_XP));
166 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "old ktl",KTL_ARRAY["KTL_NK"]));
167 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "old Rktl",KTL_ARRAY["KTL_RK"]));
168 end
169 if (usingT==1) then TitanPanelButton_UpdateButton(TITAN_KTL_ID); end
170 if (usingF==1) then
171 local label, text = KTL_TextUpdate();
172 KillsToLevelFu:UpdateText(label..text);
173 end
174 end
175  
176 function KTL_TextUpdate()
177 local count, labelText, valueText;
178 labelText = KTL_ARRAY["KTL_LABEL"];
179 if (KTL_COMBAT == 0) then
180 if (KTL_ARRAY["KTL_RK"] == 0) then
181 --No rested kills
182 if (KTL_ARRAY["KTL_NK"] == 0) then
183 --No Normal Kills, No Rested, Blank Info
184 valueText = "Blank";
185 else
186 --Normal Only
187 valueText = format(TITAN_KTL_BUTTON_TEXT_N,KTL_ARRAY["KTL_NK"]);
188 end
189 else
190 --Rested Kills
191 if (KTL_ARRAY["KTL_NK"] == 0) then
192 --No Normal Kills, Rested Only
193 valueText = format(TITAN_KTL_BUTTON_TEXT_R,KTL_ARRAY["KTL_RK"]);
194 else
195 --Normal and Rested Kills
196 valueText = format(TITAN_KTL_BUTTON_TEXT_R_N,KTL_ARRAY["KTL_RK"],KTL_ARRAY["KTL_NK"]);
197 end
198 end;
199 elseif (KTL_COMBAT == 1) then
200 valueText = format(TITAN_KTL_BUTTON_TEXT_Q, KTL_ARRAY["KTL_Q"]);
201 end
202 if (KTL_ARRAY["KTL_STATE"] == 6) then
203 DEFAULT_CHAT_FRAME:AddMessage("Done a Button Text Update");
204 end
205 return labelText, valueText;
206 end
207  
208 function KTL_LabelChange()
209 if(KTL_SMALL == 0) then
210 --Large Lables
211 KTL_SMALL = 1;
212 if(KTL_COMBAT == 0) then
213 --Combat labels
214 KTL_ARRAY["KTL_LABEL"] = TITAN_KTL_BUTTON_LABEL;
215 elseif(KTL_COMBAT == 1) then
216 --Quest Labels
217 KTL_ARRAY["KTL_LABEL"] = TITAN_KTL_BUTTON_QUEST_LABEL;
218 end
219 elseif(KTL_SMALL == 1) then
220 --Small Lables
221 KTL_SMALL = 2;
222 if(KTL_COMBAT == 0) then
223 --Combat labels
224 KTL_ARRAY["KTL_LABEL"] = TITAN_KTL_BUTTON_SMALL_LABEL;
225 elseif(KTL_COMBAT == 1) then
226 --Quest Labels
227 KTL_ARRAY["KTL_LABEL"] = TITAN_KTL_BUTTON_SMALL_QUEST_LABEL;
228 end
229  
230 elseif(KTL_SMALL == 2) then
231 --No Lables
232 KTL_SMALL = 0;
233 KTL_ARRAY["KTL_LABEL"] = "";
234  
235 end
236 if (usingT==1) then TitanPanelButton_UpdateButton(TITAN_KTL_ID); end
237 if (usingF==1) then
238 local label, text = KTL_TextUpdate();
239 KillsToLevelFu:UpdateText(label..text);
240 end
241 end
242  
243  
244 function KillMod_QuestDone()
245 KTL_COMBAT=1;
246 end
247  
248 function KillMod_CombatDone()
249 KTL_COMBAT=0;
250 end
251  
252 function KillMod_XPChange()
253  
254 local cXp;
255 cXp = UnitXP("player"); --cXp Current xp
256 if (KTL_ARRAY["KTL_STATE"] == 6) then
257 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "old xp", KTL_XP));
258 end
259 if (KTL_ARRAY["KTL_STATE"] == 6) then
260 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "current xp", cXp));
261 end
262 if (KTL_ARRAY["KTL_STATE"] > 0) then --State 0 == off
263 local xpDif;
264 local xp2level;
265 local restedKill;
266 local ktl;
267 local rested;
268 local typestring;
269  
270 if (KTL_ARRAY["KTL_STATE"] == 2) then
271 typestring = KTL_AVG;
272 elseif (KTL_ARRAY["KTL_STATE"] == 6) then
273 typestring = KTL_DEB;
274 else
275 typestring = KTL_EXACT;
276 end; --That just told the mod which text to display, depending on the mode your in
277  
278 xpDif = cXp - KTL_XP; --Easy to understand, new xp minus old xp.
279 if (KTL_ARRAY["KTL_STATE"] == 6) then
280 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "xp diff", xpDif));
281 end
282 if (xpDif == 0) then
283 --Something has called me, and there has been no xp change, dont do anything
284 --xpDif = (KTL_MAXXP - KTL_XP) + cXp; --Should be correct xp change now.
285 else
286 if (xpDif < 0) then
287 xpDif = (KTL_MAXXP - KTL_XP) + cXp; --Should be correct xp change now.
288 if (KTL_ARRAY["KTL_STATE"] == 6) then
289 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "new xp difference", xpDif));
290 end
291 end
292 if (KTL_LITTLE_R > 0) then
293 if (KTL_COMBAT == 0) then
294 xpDif = xpDif - KTL_LITTLE_R;
295 KTL_LITTLE_R = 0;
296 end
297 end
298  
299 xp2level = UnitXPMax("player") - cXp; --Easy again.
300 if (KTL_ARRAY["KTL_STATE"] == 6) then
301 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "xp to level", xp2level));
302 end
303 restedKill = xpDif/2; --Half the change is always rested, even in a group. Only case where it isn't, is when
304 if (KTL_ARRAY["KTL_STATE"] == 6) then
305 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "rested xp from this kill", restedKill));
306 end
307 ktl = xp2level/xpDif; --Simple again
308 if (KTL_ARRAY["KTL_STATE"] == 6) then
309 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "kills to level", ktl));
310 end
311 if(KTL_COMBAT == 1) then
312 KTL_ARRAY["KTL_Q"] = ktl;
313 --Quests To Level Update
314 if (KTL_ARRAY["KTL_STATE"] == 3) then
315 --Titan Bar only, dont update to channel
316 else
317 KTL_CHAT_FRAME:AddMessage(format(KTL_QUEST, ktl), 1.0, 1.0, 0.0);
318 end;
319 else
320  
321 rested = GetXPExhaustion();
322  
323 if (rested == nil) then rested = 0;
324 end
325 if (KTL_ARRAY["KTL_STATE"] == 6) then
326 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "rested xp", rested));
327 end
328 if (rested > 0) then
329 if (restedKill*ktl > rested) then --if the rested amount from this kill, times the number of kills to level is greater than the current
330 --rested amount, there will be normal kills and rested to level
331 if (rested < xpDif) then
332 KTL_LITTLE_R = rested; --If you have less rested than half the xp, then the game added a different amount of rested- little_r
333 if (KTL_ARRAY["KTL_STATE"] == 6) then
334 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "little r", KTL_LITTLE_R));
335 end
336 end
337 local normxp = UnitXPMax("player") - (cXp+rested); --How much normal xp you need to level
338 if (KTL_ARRAY["KTL_STATE"] == 6) then
339 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "normal xp to level", normxp));
340 end
341 local numrkills = rested/xpDif;
342  
343 KTL_ARRAY["KTL_RK"] = ceil(numrkills);
344 KTL_ARRAY["KTL_NK"] = normxp/restedKill;
345 KTL_ARRAY["KTL_NK"] = ceil(KTL_ARRAY["KTL_NK"]);
346 if (KTL_ARRAY["KTL_STATE"] == 6) then
347 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "number of rested kills",KTL_ARRAY["KTL_RK"]));
348 end
349 if (KTL_ARRAY["KTL_STATE"] == 6) then
350 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "number of normal kills",KTL_ARRAY["KTL_NK"]));
351 end
352 --Normal and Rested Kills Update
353 if (KTL_ARRAY["KTL_STATE"] == 3) then
354 --Titan Bar only, dont update to channel
355 else
356 KTL_CHAT_FRAME:AddMessage(format(KTL_REST_NORM, KTL_ARRAY["KTL_RK"], KTL_ARRAY["KTL_NK"], typestring), 1.0, 1.0, 0.0);
357 end;
358 --remainingxp divided by half of the xp you recieved gives you the normal kills
359 else
360 KTL_ARRAY["KTL_RK"]=ceil(ktl);
361 KTL_ARRAY["KTL_NK"]=0;
362 if (KTL_ARRAY["KTL_STATE"] == 6) then
363 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "number of rested kills",KTL_ARRAY["KTL_RK"]));
364 end
365 --Rested Kills Only Update
366 if (KTL_ARRAY["KTL_STATE"] == 3) then
367 --Titan Bar only, dont update to channel
368 else
369 KTL_CHAT_FRAME:AddMessage(format(KTL_REST, KTL_ARRAY["KTL_RK"], typestring), 1.0, 1.0, 0.0);
370 end
371 end
372  
373 else
374 KTL_ARRAY["KTL_RK"]=0;
375 KTL_ARRAY["KTL_NK"]=ceil(ktl);
376 if (KTL_ARRAY["KTL_STATE"] == 6) then
377 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "number of normal kills",KTL_ARRAY["KTL_NK"]));
378 end
379 --Normal Kills Only Update
380 if (KTL_ARRAY["KTL_STATE"] == 3) then
381 --Titan Bar only, dont update to channel
382 else
383 KTL_CHAT_FRAME:AddMessage(format(KTL_NORM,KTL_ARRAY["KTL_NK"], typestring), 1.0, 1.0, 0.0);
384 end
385 end
386 end
387 end
388 end
389 if (usingT==1) then TitanPanelButton_UpdateButton(TITAN_KTL_ID); end
390 if (usingF==1) then
391 local label, text = KTL_TextUpdate();
392 KillsToLevelFu:UpdateText(label..text);
393 end
394 KTL_XP = cXp;
395 if (KTL_ARRAY["KTL_STATE"] == 6) then
396 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "current xp", KTL_XP));
397 end
398 KTL_MAXXP = UnitXPMax("player");
399 if (KTL_ARRAY["KTL_STATE"] == 6) then
400 KTL_CHAT_FRAME:AddMessage(format(KTL_DEBUG_STRING, "max xp", KTL_MAXXP));
401 end
402  
403 end
404  
405 function StatusShow()
406 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_VERSION..".",KTL_Version));
407 local frametype;
408 if (KTL_ARRAY["KTL_FRAME"] == 2) then
409 frametype = KTL_COMBAT_FRAME;
410 elseif (KTL_ARRAY["KTL_FRAME"] == 1) then
411 frametype = KTL_GENERAL_FRAME;
412 end
413 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_FRAME,frametype));
414 if (KTL_ARRAY["KTL_STATE"] == 0) then
415 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_OFF));
416 elseif (KTL_ARRAY["KTL_STATE"] == 1) then
417 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
418 elseif (KTL_ARRAY["KTL_STATE"] == 2) then
419 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_AVERAGE));
420 elseif (KTL_ARRAY["KTL_STATE"] == 3) then
421 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_TITAN));
422 elseif (KTL_ARRAY["KTL_STATE"] == 6) then
423 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_DEBUG));
424 end
425 if (KTL_ARRAY["KTL_QUEST_STATE"] == 0) then
426 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_QUEST_ON));
427 else
428 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_QUEST_OFF));
429 end
430  
431 end
432  
433 function KillMod_SlashHandler(msg)
434 local index, value;
435 if (not msg or msg == "") then --Show Help
436 for index, value in KTL_HELP_TEXT do
437 DEFAULT_CHAT_FRAME:AddMessage(value);
438 end
439 else
440 local command=strlower(msg);
441 if (command == KTL_STATUS) then
442 StatusShow();
443 elseif (command == KTL_ON) then
444 KTL_ARRAY["KTL_STATE"] = 1;
445 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
446 elseif (command == KTL_OFF) then
447 KTL_ARRAY["KTL_STATE"] = 0;
448 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_OFF));
449 elseif (command == KTL_HELP) then --Show Help, again
450 for index, value in KTL_HELP_TEXT do
451 DEFAULT_CHAT_FRAME:AddMessage(value);
452 end
453 elseif (command == KTL_SLASH_FRAME) then --Change KTl Frame
454 --Dunno how to yet, so just toggling
455 if (KTL_ARRAY["KTL_FRAME"] == 2) then
456 KTL_ARRAY["KTL_FRAME"] = 1;
457 KTL_CHAT_FRAME = getglobal("ChatFrame"..KTL_ARRAY["KTL_FRAME"]);
458 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_FRAME,KTL_GENERAL_FRAME));
459 else
460 KTL_CHAT_FRAME = getglobal("ChatFrame"..KTL_ARRAY["KTL_FRAME"]);
461 KTL_ARRAY["KTL_FRAME"] = 2;
462 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_FRAME,KTL_COMBATL_FRAME));
463 end
464 elseif (command == KTL_DEBUG) then --toggle debug
465 if (KTL_ARRAY["KTL_STATE"] == 6) then
466 KTL_ARRAY["KTL_STATE"] = 1;
467 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
468 else
469 KTL_ARRAY["KTL_STATE"] = 6;
470 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_DEBUG));
471 end
472 elseif (command == KTL_AVERAGE) then --toggle average
473 if (KTL_ARRAY["KTL_STATE"] == 2) then
474 KTL_ARRAY["KTL_STATE"] = 1;
475 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
476 else
477 KTL_ARRAY["KTL_STATE"] = 2;
478 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_AVERAGE));
479 end
480 elseif (command == KTL_TITAN) then --toggle Titan only mode
481 if (KTL_ARRAY["KTL_STATE"] == 3) then
482 KTL_ARRAY["KTL_STATE"] = 1;
483 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
484 else
485 KTL_ARRAY["KTL_STATE"] = 3;
486 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_TITAN));
487 end
488 elseif (command == KTL_QUEST_O) then --toggle Titan Quest mode
489 if (KTL_ARRAY["KTL_QUEST_STATE"] == 1) then
490 KTL_ARRAY["KTL_QUEST_STATE"] = 0;
491 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_QUEST_ON));
492 else
493 KTL_ARRAY["KTL_QUEST_STATE"] = 1;
494 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_QUEST_OFF));
495 end
496 end
497 end
498 end
499