vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Alkitron Honor Tab
3 Replaces the standard Honor tab with an enhanced version.
4  
5 by morganti@laughing skull, http://ui.worldofwar.net/users.php?name=morg
6 ]]
7  
8  
9 HF_INFO = {};
10 hfsaved = {};
11 honor_last = 0;
12 --don't change these values
13 last_update = time();
14 scoreboardscan_interval = 1;
15  
16 function HonorFrame_OnLoad()
17 this:RegisterEvent("VARIABLES_LOADED");
18 this:RegisterEvent("PLAYER_PVP_KILLS_CHANGED");
19 this:RegisterEvent("PLAYER_ENTERING_WORLD");
20 this:RegisterEvent("PLAYER_PVP_RANK_CHANGED");
21 this:RegisterEvent("CHAT_MSG_COMBAT_HONOR_GAIN");
22 this:RegisterEvent("CHAT_MSG_SPELL_CREATURE_VS_CREATURE_BUFF");
23 this:RegisterEvent("UPDATE_BATTLEFIELD_STATUS");
24 this:RegisterEvent("UPDATE_BATTLEFIELD_SCORE");
25 this:RegisterEvent("UPDATE_WORLD_STATES");
26 end
27  
28 function resethonor()
29 local hky, dky, contributiony = GetPVPYesterdayStats();
30 local hkt, dkt = GetPVPSessionStats();
31 local hkw, contributionw = GetPVPThisWeekStats();
32  
33 player = UnitName("player").." - "..GetRealmName();
34  
35 HF_INFO[player] = {
36 ["honor_yesterday"] = contributiony;
37 ["honor"] = 0;
38 ["honor_bonus"] = 0;
39 ["kills_today"] = hkt;
40 ["kills_yesterday"] = hky;
41 ["honor_week"] = contributionw;
42 ["faction"] = checkfaction();
43 ["verbose"] = 1;
44 }
45 HF_INFO[player]['hk_list'] = {};
46  
47 hfsaved = HF_INFO[player];
48 HonorFrame_Update();
49  
50 DEFAULT_CHAT_FRAME:AddMessage("[Alkitron Honor Tab] RESET: UnitFactionGroup returned " .. hfsaved.faction);
51 end
52  
53 function checkfaction()
54 local factiongroup = UnitFactionGroup("player");
55  
56 if (factiongroup == "Alliance") then
57 factiongroup = 1;
58 elseif (factiongroup == "Horde") then
59 factiongroup = 0;
60 elseif (factiongroup == nil) then
61 factiongroup = 2;
62 DEFAULT_CHAT_FRAME:AddMessage("[Alkitron Honor Tab] ERROR: UnitFactionGroup() returned nil");
63 end
64  
65 return factiongroup;
66 end
67  
68 function HonorFrame_OnEvent(event)
69 if (event == "VARIABLES_LOADED") then
70  
71 local hky, dky, contributiony = GetPVPYesterdayStats();
72 local hkt, dkt = GetPVPSessionStats();
73 local hkw, contributionw = GetPVPThisWeekStats();
74  
75 player = UnitName("player").." - "..GetRealmName();
76  
77 if (not HF_INFO[player]) then
78 HF_INFO[player] = {
79 ["honor_yesterday"] = contributiony;
80 ["honor"] = 0;
81 ["honor_bonus"] = 0;
82 ["kills_today"] = hkt;
83 ["kills_yesterday"] = hky;
84 ["honor_week"] = contributionw;
85 ["faction"] = checkfaction();
86 ["verbose"] = 1;
87 }
88 end
89  
90 hfsaved = HF_INFO[player];
91  
92 if (hfsaved.kills_today == nil) then hfsaved.kills_today = hkt; end
93 if (hfsaved.kills_yesterday == nil) then hfsaved.kills_yesterday = hky; end
94 if (HF_INFO[player]['hk_list'] == nil) then HF_INFO[player]['hk_list'] = {}; end
95 if (hfsaved.honor_week == nil) then hfsaved.honor_week = contributionw; end
96 if (hfsaved.faction == nil) then hfsaved.faction = checkfaction(); end
97 if (hfsaved.verbose == nil) then hfsaved.verbose = 1; end
98  
99 HonorFrame_Update();
100 DEFAULT_CHAT_FRAME:AddMessage("[Alkitron Honor Tab] Loaded for " .. player);
101  
102 elseif ( event == "PLAYER_PVP_KILLS_CHANGED" or event == "PLAYER_PVP_RANK_CHANGED") then
103  
104 HonorFrame_Update();
105  
106 elseif ( event == "PLAYER_ENTERING_WORLD" ) then
107  
108 HonorFrame_Update();
109  
110 elseif ( event == "CHAT_MSG_COMBAT_HONOR_GAIN") then
111  
112 local Pattern = string.gsub(string.gsub(COMBATLOG_HONORGAIN, "([()])", "%%%1"), "%%[ds]", "([%%w ]+)");
113 local s,e,hk_thisplayer,honor_thisplayer,honor_diminished,diminishing_return,ename,erank,ehonor;
114  
115 s, e, ename, erank, ehonor = string.find(arg1, Pattern);
116  
117 if (ename) and (erank) and (ehonor) then
118  
119 if (not HF_INFO[player]['hk_list'][ename]) then
120 HF_INFO[player]['hk_list'][ename] = { ['killed'] = 1; ['honor_total'] = 0; };
121 else
122 HF_INFO[player]['hk_list'][ename]['killed'] = HF_INFO[player]['hk_list'][ename]['killed'] + 1;
123 --HF_INFO[player]['hk_list'][ename]['honor_total'] = HF_INFO[player]['hk_list'][ename]['honor_total'] + ehonor;
124 end
125  
126 hk_thisplayer = HF_INFO[player]['hk_list'][ename]['killed'];
127 honor_thisplayer = HF_INFO[player]['hk_list'][ename]['honor_total'];
128  
129 if (hk_thisplayer == 1) then
130 diminishing_return = 1;
131 elseif (hk_thisplayer == 2) then
132 diminishing_return = .75;
133 elseif (hk_thisplayer == 3) then
134 diminishing_return = .50;
135 elseif (hk_thisplayer == 4) then
136 diminishing_return = .25;
137 else
138 diminishing_return = 0;
139 end
140  
141 honor_diminished = ehonor * diminishing_return;
142  
143 if (honor_diminished - floor(honor_diminished) > .5) then
144 honor_diminished = ceil(honor_diminished);
145 else
146 honor_diminished = floor(honor_diminished);
147 end
148  
149 HF_INFO[player]['hk_list'][ename]['honor_total'] = HF_INFO[player]['hk_list'][ename]['honor_total'] + honor_diminished;
150  
151 if (hfsaved.verbose == 1 and diminishing_return == 0) then
152 DEFAULT_CHAT_FRAME:AddMessage(ename .. " is no longer worth any honor (" .. hk_thisplayer .. " kills / " .. honor_thisplayer .. " honor)");
153 end
154  
155 HonorFrame_Update(honor_diminished,1);
156  
157 end
158  
159 elseif ( event == "CHAT_MSG_SPELL_CREATURE_VS_CREATURE_BUFF") then
160  
161 local bonushonortext = "begins to cast Honor Points %+(%d+)";
162 local bonushonor = 0;
163  
164 for bonushonor in string.gfind(arg1, bonushonortext) do
165 hfsaved.honor_bonus = hfsaved.honor_bonus + tonumber(bonushonor);
166 DEFAULT_CHAT_FRAME:AddMessage("Bonus Honor gained: " .. bonushonor .. ".", 1, 1, 0);
167 HonorFrame_Update();
168 end
169  
170 elseif (event == "UPDATE_BATTLEFIELD_STATUS") then
171  
172 RequestBattlefieldScoreData();
173  
174 elseif (event == "UPDATE_BATTLEFIELD_SCORE") then
175  
176 checkscoreboard();
177  
178 elseif (event == "UPDATE_WORLD_STATES") then
179  
180 local temptime = time() - last_update;
181  
182 if (temptime >= scoreboardscan_interval) then
183 checkscoreboard();
184 end
185  
186 end
187 end
188  
189 function checkscoreboard()
190 local name, kills, killingBlows, deaths, honorGained, faction, rank, race, class, tempbonus, i, e;
191  
192 RequestBattlefieldScoreData();
193 e = GetNumBattlefieldScores();
194 last_update = time();
195  
196 for i=1, e do
197 name, killingBlows, honorableKills, deaths, honorGained,
198 faction, rank, race, class = GetBattlefieldScore(i);
199 if (faction == hfsaved.faction) then
200 if (name == UnitName("player")) then
201 if (honorGained == 0) then
202 honor_last = 0;
203 end
204 if (honorGained > honor_last) then
205 tempbonus = (honorGained - honor_last);
206 honor_last = honorGained;
207 hfsaved.honor_bonus = hfsaved.honor_bonus + tempbonus;
208 HonorFrame_Update();
209  
210 if (hfsaved.verbose == 1) then
211 DEFAULT_CHAT_FRAME:AddMessage("Adding " .. tempbonus .. " bonus honor.", 1, 1, 0);
212 end
213 end
214 i = e;
215 end
216 else
217 if (hfsaved.faction == 2) then
218 DEFAULT_CHAT_FRAME:AddMessage("[Alkitron Honor Tab] Improper faction variable detected, attempting to fix...");
219 hfsaved.faction = checkfaction();
220 DEFAULT_CHAT_FRAME:AddMessage("[Alkitron Honor Tab] Faction set to: " .. hfsaved.faction .. " (1=Alliance,0=Horde,2=nil)");
221 end
222 end
223 end
224 end
225  
226 function checkrollover()
227 local hkw, contributionw = GetPVPThisWeekStats();
228 local hky, dky, contributiony = GetPVPYesterdayStats();
229 local hks, dks = GetPVPSessionStats();
230  
231 if (hfsaved.honor_week < contributionw) then
232  
233 hfsaved.kills_yesterday = hfsaved.kills_today;
234 hfsaved.honor_yesterday = hfsaved.honor + hfsaved.honor_bonus;
235 hfsaved.honor_bonus = 0;
236 hfsaved.honor = 0;
237 hfsaved.kills_today = 0;
238 hfsaved.honor_week = contributionw;
239 HF_INFO[player]['hk_list'] = {};
240  
241 DEFAULT_CHAT_FRAME:AddMessage("[Alkitron Honor Tab] Just reset stats for the day. (1)");
242  
243 elseif (hfsaved.honor_week > contributionw and contributionw == 0) then
244  
245 local hklw, dklw, contributionlw, ranklw = GetPVPLastWeekStats();
246  
247 if (hfsaved.honor_week < contributionlw) then
248  
249 hfsaved.kills_yesterday = hfsaved.kills_today;
250 hfsaved.honor_yesterday = hfsaved.honor + hfsaved.honor_bonus;
251 hfsaved.honor_bonus = 0;
252 hfsaved.honor = 0;
253 hfsaved.kills_today = 0;
254 hfsaved.honor_week = contributionw;
255 HF_INFO[player]['hk_list'] = {};
256  
257 DEFAULT_CHAT_FRAME:AddMessage("[Alkitron Honor Tab] Just reset stats for the week.");
258  
259 end
260  
261 elseif (hfsaved.honor_week == contributionw) then
262  
263 if (hky == 0 and contributiony == 0) then
264 if(hks == 0) then
265 hfsaved.kills_yesterday = hfsaved.kills_today;
266 hfsaved.honor_yesterday = hfsaved.honor + hfsaved.honor_bonus;
267 hfsaved.honor_bonus = 0;
268 hfsaved.honor = 0;
269 hfsaved.kills_today = 0;
270 hfsaved.honor_week = contributionw;
271 HF_INFO[player]['hk_list'] = {};
272 DEFAULT_CHAT_FRAME:AddMessage("[Alkitron Honor Tab] Just reset stats for the day. (2)");
273 end
274 end
275  
276 end
277 end
278  
279 function HonorFrame_Update(honor,kill)
280 local hk, hky, dk, contribution, rank, highestRank, rankName, rankNumber, temptotal;
281  
282 checkrollover();
283  
284 if (honor) then
285 hfsaved.honor = honor + hfsaved.honor;
286 end
287  
288 if (kill) then
289 hfsaved.kills_today = hfsaved.kills_today + 1;
290 end
291  
292 hk = hfsaved.kills_today;
293 temptotal = hfsaved.honor + hfsaved.honor_bonus;
294  
295 -- This session's values
296 HonorFrameCurrentHKText:SetText("Kills");
297 --HonorFrameCurrentSessionTitle:SetText("Today's Honor");
298 HonorFrameCurrentHKValue:SetTextColor(1,1,1);
299 HonorFrameCurrentHKValue:SetText("Estimated / Bonus / Total Honor");
300 HonorFrameCurrentDKText:SetTextColor(0,1,0);
301 HonorFrameCurrentDKText:SetText(hk);
302 HonorFrameCurrentDKValue:SetTextColor(0,1,0);
303 if (hfsaved.honor == 0 and hfsaved.honor_bonus == 0) then
304 HonorFrameCurrentDKValue:SetText("none");
305 else
306 HonorFrameCurrentDKValue:SetText(hfsaved.honor .. " + " .. hfsaved.honor_bonus .. " = " .. temptotal);
307 end
308  
309  
310 -- Yesterday's values
311 hk, dk, contribution = GetPVPYesterdayStats();
312 hky = hfsaved.kills_yesterday;
313  
314 --HonorFrameYesterdayTitle:SetText("Yesterday's Honor");
315 HonorFrameYesterdayHKText:SetText("Kills");
316 HonorFrameYesterdayHKValue:SetTextColor(1,1,1);
317 HonorFrameYesterdayHKValue:SetText("Estimated / Actual Honor");
318 HonorFrameYesterdayContributionText:SetTextColor(0,1,0);
319 HonorFrameYesterdayContributionText:SetText(hk);
320 HonorFrameYesterdayContributionValue:SetTextColor(0,1,0);
321 if (contribution == 0) then
322 HonorFrameYesterdayContributionValue:SetText("none");
323 else
324 HonorFrameYesterdayContributionValue:SetText(hfsaved.honor_yesterday .. " / " .. contribution);
325 end
326  
327  
328 -- This Week's values
329 hk, contribution = GetPVPThisWeekStats();
330 local temptotal2 = contribution + temptotal;
331 local temptotal3 = hk + hfsaved.kills_today;
332  
333 --HonorFrameThisWeekTitle:SetText("This Week's Honor");
334 HonorFrameThisWeekHKText:SetTextColor(1,1,1);
335 HonorFrameThisWeekHKText:SetText("Kills");
336 HonorFrameThisWeekContributionText:SetTextColor(0,1,0);
337 HonorFrameThisWeekContributionText:SetText(temptotal3);
338 HonorFrameThisWeekHKValue:SetTextColor(1,1,1);
339 HonorFrameThisWeekHKValue:SetText("Today / This Week / Total Honor");
340 HonorFrameThisWeekContributionValue:SetTextColor(0,1,0);
341 if (contribution == 0) then
342 HonorFrameThisWeekContributionValue:SetText("none");
343 else
344 HonorFrameThisWeekContributionValue:SetText(temptotal .. " + " .. contribution .. " = " .. temptotal2);
345 end
346  
347 -- Last Week's values
348 hk, dk, contribution, rank = GetPVPLastWeekStats();
349 HonorFrameLastWeekHKValue:SetText(hk);
350 HonorFrameLastWeekContributionValue:SetTextColor(1,.5,0);
351 HonorFrameLastWeekContributionValue:SetText(contribution);
352 HonorFrameLastWeekStandingValue:SetText(rank);
353  
354  
355 -- Lifetime stats
356 hk, dk, highestRank = GetPVPLifetimeStats();
357 HonorFrameLifeTimeHKValue:SetText(hk);
358 HonorFrameLifeTimeDKValue:SetText(dk);
359 rankName, rankNumber = GetPVPRankInfo(highestRank);
360 if ( not rankName ) then
361 rankName = NONE;
362 end
363 HonorFrameLifeTimeRankValue:SetText(rankName);
364  
365 -- Set rank name and number
366 rankName, rankNumber = GetPVPRankInfo(UnitPVPRank("player"));
367 if ( not rankName ) then
368 rankName = NONE;
369 end
370  
371 -- Calculate How far we are into current rank
372 rankPercent = tostring(GetPVPRankProgress() * 100);
373 rankPercent = string.sub(rankPercent, 1, 5);
374  
375 HonorFrameCurrentPVPTitle:SetText(rankName);
376 HonorFrameCurrentPVPRank:SetText("("..RANK.." "..rankNumber..") " .. rankPercent .. "%");
377  
378 -- Set icon
379 if ( rankNumber > 0 ) then
380 HonorFramePvPIcon:SetTexture(format("%s%02d","Interface\\PvPRankBadges\\PvPRank",rankNumber));
381 HonorFramePvPIcon:Show();
382 else
383 HonorFramePvPIcon:Hide();
384 end
385  
386 -- Set rank progress and bar color
387 local factionGroup, factionName = UnitFactionGroup("player");
388 if ( factionGroup == "Alliance" ) then
389 HonorFrameProgressBar:SetStatusBarColor(0.05, 0.15, 0.36);
390 else
391 HonorFrameProgressBar:SetStatusBarColor(0.63, 0.09, 0.09);
392 end
393 HonorFrameProgressBar:SetValue(GetPVPRankProgress());
394  
395 -- Recenter rank text
396 HonorFrameCurrentPVPTitle:SetPoint("TOP", "HonorFrame", "TOP", - HonorFrameCurrentPVPRank:GetWidth()/2, -83);
397 end
398  
399 function showkills()
400 local ename,kills,htotal;
401 local i = 0;
402 for ename in HF_INFO[player]['hk_list'] do
403 i = i+ 1;
404 kills = HF_INFO[player]['hk_list'][ename]['killed'];
405 htotal = HF_INFO[player]['hk_list'][ename]['honor_total'];
406 DEFAULT_CHAT_FRAME:AddMessage(ename .. " " .. kills .. " " .. htotal);
407 end
408 DEFAULT_CHAT_FRAME:AddMessage(i .. " entries found");
409 end