vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --Kills To Level : Titan Enabled
2 --Craig Willis
3 --17/05/05
4  
5 local TITAN_KTL_ID = "KTL";
6  
7 KTL_Version="0.40";
8 KTL_Frame = 2;
9 KTL_State = 1;
10 KTL_AvgCalc = 0;
11 KTL_AvgKills = 0;
12 KTL_RK = 0;
13 KTL_NK = 0;
14 KTL_LABEL = TITAN_KTL_BUTTON_LABEL;
15 KTL_STRING = "";
16  
17 local usingT = 0;
18 local KTL_XP;
19 local KTL_MAXXP; --Needed to remove calc error when leveling
20  
21 KTL_CHAT_FRAME = getglobal("ChatFrame"..KTL_Frame);
22  
23 function TitanPanelKTLButton_OnLoad()
24 this.registry = {
25 id = TITAN_KTL_ID,
26 menuText = TITAN_KTL_MENU_TEXT,
27 buttonTextFunction = "TitanPanelKTLButton_GetButtonText",
28 tooltipTitle = TITAN_KTL_TOOLTIP,
29 savedVariables = {
30 ShowLabelText = 1,
31 }
32 };
33 usingT=1;
34  
35 SlashCmdList["KILLCOMMAND"] = KillMod_SlashHandler;
36 SLASH_KILLCOMMAND1 = "/Kill";
37 SLASH_KILLCOMMAND1 = "/ktl";
38  
39 KTL_XP = UnitXP("Player");
40 KTL_MAXXP = UnitXPMax("player");
41 this:RegisterEvent("VARIABLES_LOADED"); --Set hook if needed and check chat frame
42 this:RegisterEvent("PLAYER_XP_UPDATE");
43  
44 if( DEFAULT_CHAT_FRAME ) then
45 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_LOADED,KTL_Version));
46 end
47 end
48  
49 function TitanPanelKTLButton_OnEvent()
50 if(event == "VARIABLES_LOADED") then
51 StatusShow();
52 elseif(event == "PLAYER_XP_UPDATE") then
53 KillMod_XPChange();
54 else
55 DEFAULT_CHAT_FRAME:AddMessage("Unregistered event: "..event);
56 end
57 TitanPanelButton_UpdateButton(TITAN_KTL_ID);
58 end
59  
60 function TitanPanelKTLButton_GetButtonText(id)
61 local count, labelText, valueText;
62 labelText = KTL_LABEL;
63 if (KTL_RK == 0) then
64 --No rested kills
65 if (KTL_NK == 0) then
66 --No Normal Kills, No Rested, Blank Info
67 valueText = "Blank";
68 else
69 --Normal Only
70 valueText = format(TITAN_KTL_BUTTON_TEXT_N, KTL_NK);
71 end
72 else
73 --Rested Kills
74 if (KTL_NK == 0) then
75 --No Normal Kills, Rested Only
76 valueText = format(TITAN_KTL_BUTTON_TEXT_R, KTL_RK);
77 else
78 --Normal and Rested Kills
79 valueText = format(TITAN_KTL_BUTTON_TEXT_R_N, KTL_RK, KTL_NK);
80 end
81 end;
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 if(KTL_LABEL == TITAN_KTL_BUTTON_LABEL) then
94 KTL_LABEL = TITAN_KTL_BUTTON_SMALL_LABEL;
95 TitanPanelButton_UpdateButton(TITAN_KTL_ID);
96 elseif(KTL_LABEL == TITAN_KTL_BUTTON_SMALL_LABEL) then
97 KTL_LABEL = TITAN_KTL_BUTTON_LABEL;
98 TitanPanelButton_UpdateButton(TITAN_KTL_ID);
99 end
100 end
101  
102 --KTL functions
103  
104 function KillMod_OnLoad()
105 if (usingT==0) then
106  
107 SlashCmdList["KILLCOMMAND"] = KillMod_SlashHandler;
108 SLASH_KILLCOMMAND1 = "/Kill";
109 SLASH_KILLCOMMAND1 = "/ktl";
110  
111 KTL_XP = UnitXP("Player");
112  
113 this:RegisterEvent("VARIABLES_LOADED"); --Set hook if needed and check chat frame
114 this:RegisterEvent("PLAYER_XP_UPDATE");
115  
116 if( DEFAULT_CHAT_FRAME ) then
117 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_LOADED,KTL_Version));
118 end
119 end
120 end
121  
122 function KillMod_OnEvent()
123 if (usingT==0) then
124 if(event == "VARIABLES_LOADED") then
125 StatusShow();
126 elseif(event == "PLAYER_XP_UPDATE") then
127 KillMod_XPChange();
128 else
129 DEFAULT_CHAT_FRAME:AddMessage("Unregistered event: "..event);
130 end
131 end
132 end
133  
134 function KillMod_XPChange()
135  
136 local cXp;
137 cXp = UnitXP("Player");
138  
139 if (KTL_State > 0) then
140 local xpDif;
141 local xp2level;
142 local restedKill;
143 local ktl;
144 local rested;
145 local typestring;
146  
147 if (KTL_State == 2) then
148 typestring = KTL_AVG;
149 elseif (KTL_State == 6) then
150 typestring = KTL_DEB;
151 else
152 typestring = KTL_EXACT;
153 end; --That just told the mod which text to display, depending on the mod your in
154  
155 xpDif = cXp - KTL_XP; --Easy to understand, new xp minus old xp.
156 if (xpDif < 0) then
157 xpDif = (KTL_MAXXP - KTL_XP) + cXp; --Should be correct xp change now.
158 end
159  
160 xp2level = UnitXPMax("player") - cXp; --Easy again.
161 restedKill = xpDif/2; --I'm assuming that half of the xp change is due to rested, not always the case, but I dont know how to check yet.
162 ktl = xp2level/xpDif; --Simple again
163 rested = GetXPExhaustion();
164  
165 if (rested == nil) then rested = 0;
166 end
167  
168 if (rested > 0) then
169  
170 if (restedKill*ktl > rested) then
171 local numrkills = rested/restedKill --How many of the kills will be rested, done by dividing the amount of rested this kill by the total amount of rested
172 local totalxpr = xpDif*numrkills --This says how much xp you will get using up all your rested
173 local remainingxp = xp2level-totalxpr --The remaining xp, after rested xp is used
174 KTL_RK = ceil(numrkills);
175 KTL_NK = remainingxp/restedKill;
176 KTL_NK = ceil(KTL_NK);
177 if (KTL_State == 3) then
178 --Titan Bar only, dont update to channel
179 else
180 KTL_CHAT_FRAME:AddMessage(format(KTL_REST_NORM, KTL_RK, KTL_NK, typestring), 1.0, 1.0, 0.0);
181 end;
182 --remainingxp divided by half of the xp you recieved gives you the normal kills
183 else
184 KTL_RK=ceil(ktl);
185 KTL_NK=0;
186 if (KTL_State == 3) then
187 --Titan Bar only, dont update to channel
188 else
189 KTL_CHAT_FRAME:AddMessage(format(KTL_REST, KTL_RK, typestring), 1.0, 1.0, 0.0);
190 end
191 end
192  
193 else
194 KTL_RK=0;
195 KTL_NK=ceil(ktl);
196 if (KTL_State == 3) then
197 --Titan Bar only, dont update to channel
198 else
199 KTL_CHAT_FRAME:AddMessage(format(KTL_NORM, KTL_NK, typestring), 1.0, 1.0, 0.0);
200 end
201 end
202  
203 end
204  
205 KTL_XP = cXp;
206 KTL_MAXXP = UnitXPMax("player");
207  
208 end
209  
210 function StatusShow()
211 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_VERSION..".",KTL_Version));
212 if (KTL_State == 0) then
213 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_OFF));
214 elseif (KTL_State == 1) then
215 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
216 elseif (KTL_State == 2) then
217 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_AVERAGE));
218 elseif (KTL_State == 3) then
219 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_TITAN));
220 elseif (KTL_State == 6) then
221 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_DEBUG));
222 end
223 end
224  
225 function KillMod_SlashHandler(msg)
226 local index, value;
227 if (not msg or msg == "") then --Show Help
228 for index, value in KTL_HELP_TEXT do
229 DEFAULT_CHAT_FRAME:AddMessage(value);
230 end
231 else
232 local command=strlower(msg);
233 if (command == KTL_STATUS) then
234 StatusShow();
235 elseif (command == KTL_ON) then
236 KTL_State = 1;
237 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
238 elseif (command == KTL_OFF) then
239 KTL_State = 0;
240 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_OFF));
241 elseif (command == KTL_HELP) then --Show Help, again
242 for index, value in KTL_HELP_TEXT do
243 DEFAULT_CHAT_FRAME:AddMessage(value);
244 end
245 elseif (command == KTL_DEBUG) then --toggle debug
246 if (KTL_State == 6) then
247 KTL_State = 1;
248 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
249 else
250 KTL_State = 6;
251 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_DEBUG));
252 end
253 elseif (command == KTL_AVERAGE) then --toggle average
254 if (KTL_State == 2) then
255 KTL_State = 1;
256 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
257 else
258 KTL_State = 2;
259 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_AVERAGE));
260 end
261 elseif (command == KTL_TITAN) then --toggle Titan only mode
262 if (KTL_State == 3) then
263 KTL_State = 1;
264 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_ON));
265 else
266 KTL_State = 3;
267 DEFAULT_CHAT_FRAME:AddMessage(format(KTL_HELP_TITAN));
268 end
269 end
270 end
271 end
272