vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[ RestedBonus: Displays rested bonus information.
2 Written by Vincent of Blackhand, (copyright 2005 by D.A.Down)
3  
4 Version history:
5 1.0 - WoW 1.10 update.
6 0.9 - WoW 1.9 update.
7 0.8.1 - Added ignore and percent options.
8 0.8 - WoW 1.8 update, added delete command.
9 0.7.5 - WoW 1.7 update, replaced game time with system time.
10 0.7.4 - added level up flag, grey on low rest, key bindings.
11 0.7.3 - added player level, /rbs shortcut.
12 0.7.2 - WoW 1.6 update, uses current chat window.
13 0.7.1 - Color coded the display.
14 0.7 - Initial public release.
15 ]]
16  
17 local Server,Player,Del;
18 local FCg = "|cffbbbbbb";
19 local FCw = "|cffffffff";
20 local FCy = "|cffffff10";
21 local FCo = "|cffff9050";
22 local FCr = "|cffff4040";
23 local LGreen = {r=0.5; g=1.0; b=0.0};
24 local function rgb(c) return c.r, c.g, c.b; end
25 local function print(msg) SELECTED_CHAT_FRAME:AddMessage("RB: "..msg, rgb(LGreen)); end
26  
27 RestedBonus_Data = {}
28 RestedBonus_Percent = 100
29  
30 function RestedBonus_Init()
31 -- add our chat commands
32 SlashCmdList["RESTEDBONUS"] = RestedBonus_Cmd;
33 SLASH_RESTEDBONUS1 = "/restedbonus";
34 SLASH_RESTEDBONUS2 = "/rb";
35 SlashCmdList["RESTEDBONUSS"] = function() RestedBonus_Cmd('server'); end;
36 SLASH_RESTEDBONUSS1 = "/rbs";
37 SlashCmdList["RESTEDBONUSD"] = RestedBonus_Delete;
38 SLASH_RESTEDBONUSD1 = "/rbd";
39 Player = UnitName("player");
40 Server = GetCVar("realmName");
41 if(not RestedBonus_Data[Server]) then RestedBonus_Data[Server]={}; end
42 -- Hook player logout
43 RestedBonus_Logout_Save = Logout;
44 Logout = function() RestedBonus_Logout(); RestedBonus_Logout_Save(); end
45 -- Hook player quit
46 RestedBonus_Quit_Save = Quit;
47 Quit = function() RestedBonus_Logout(); RestedBonus_Quit_Save(); end;
48 end
49  
50 function RestedBonus_Logout()
51 if(RestedBonus_Save(true)) then print("Rested data saved."); end
52 end
53  
54 function RestedBonus_Save(logout)
55 if(Del and logout) then return; end
56 if(RestedBonus_Data[Server][Player] and RestedBonus_Data[Server][Player].lvl==0) then return; end
57 local bonus = GetXPExhaustion();
58 local curXP = UnitXP("player");
59 local maxXP = UnitXPMax("player");
60 local level = UnitLevel("player");
61 if(not bonus) then bonus = 0; end
62 local data = {bonus=bonus;maxXP=maxXP;time=time(),rest=IsResting(),lvl=level};
63 data.lvlXP = maxXP-curXP;
64 RestedBonus_Data[Server][Player] = data;
65 return data;
66 end
67  
68 local function find_name(data,str)
69 local name = strlower(str);
70 local match = function(k,v) return name==strlower(k) and {k,v} or nil; end
71 local svr = foreach(data,match);
72 if(svr) then return svr[1],svr[2]; end
73 end
74  
75 local function RB_Delete(player,server)
76 if(not RestedBonus_Data[server]) then
77 local name = find_name(RestedBonus_Data,server);
78 if(name) then server = name;
79 else print(FCr.."Unknown server, '"..server.."'"); return; end
80 end
81 if(not RestedBonus_Data[server][player]) then
82 local name = find_name(RestedBonus_Data[server],player);
83 if(name) then player = name;
84 else print(FCr.."Unknown player, '"..player.."'"); return; end
85 end
86 RestedBonus_Data[server][player] = nil;
87 if(not next(RestedBonus_Data[server])) then
88 RestedBonus_Data[server] = nil;
89 end
90 print("Deleted "..player.." on "..server);
91 end
92  
93 function RestedBonus_Delete(msg)
94 if(msg=='') then RB_Delete(Player,Server); Del=1; return; end
95 local s,e,player,server = strfind(msg,'^(%S+)%s+(%S+)$');
96 if(s) then RB_Delete(player,server);
97 else RB_Delete(msg,Server); end
98 end
99  
100 -- handle our chat command
101 function RestedBonus_Cmd(msg)
102 local data = RestedBonus_Save();
103 if(msg=='') then
104 RestedBonus_Display(Player,data);
105 elseif(msg=='server') then
106 RestedBonus_Server(Server,RestedBonus_Data[Server]);
107 elseif(msg=='all') then
108 foreach(RestedBonus_Data,RestedBonus_Server);
109 elseif(msg=='ignore') then
110 if(RestedBonus_Data[Server][Player].lvl>0) then
111 RestedBonus_Data[Server][Player].lvl = 0
112 print(Player.." will be ignored in reports.")
113 return
114 end
115 RestedBonus_Data[Server][Player].lvl = UnitLevel("player")
116 print(Player.." will be included in reports.");
117 elseif(msg=='percent') then
118 RestedBonus_Percent = 250 - RestedBonus_Percent;
119 print("Full bonus percent is now "..RestedBonus_Percent);
120 else
121 local svr,list = find_name(RestedBonus_Data,msg);
122 if(svr) then RestedBonus_Server(svr,list);
123 else print(FCr.."Unknown server, '"..msg.."'"); end
124 end
125 end
126  
127 function RestedBonus_Server(svr,list)
128 print(FCw..svr.." characters:");
129 foreach(list,RestedBonus_Display);
130 end
131  
132 function RestedBonus_Display(name,data)
133 if(not data) then return; end
134 local bonus,maxBonus,fc,lvl,flag = data.bonus, data.maxXP*1.5, '', '', '';
135 if(data.time<1e9) then
136 print(name..FCr.." has old time data; log to update.");
137 return;
138 end
139 if(not bonus) then bonus = 0; end
140 local speed = data.rest and 1 or 4;
141 if(data.time<time()) then
142 bonus = bonus+floor((time()-data.time)*maxBonus/864000/speed/2)*2;
143 if(bonus>maxBonus) then bonus = maxBonus; end
144 end
145 local pct = floor(bonus/maxBonus*RestedBonus_Percent);
146 if(data.lvlXP and bonus>=data.lvlXP) then flag = '+'; end
147 if(data.lvl) then
148 if(data.lvl==0) then return; end
149 if(data.lvlXP) then
150 lvl = data.lvl+floor(10-10*data.lvlXP/data.maxXP)/10;
151 lvl = format(" (%1.1f%s)",lvl,flag);
152 else lvl = format(" (%d%s)",data.lvl,flag); end
153 end
154 msg = format("%s%s is %d%% rested (RB=%d)",name,lvl,pct,bonus);
155 if(bonus<maxBonus) then
156 secs = floor((1-bonus/maxBonus)*864000*speed);
157 if(secs<86400) then fc = FCy;
158 elseif(bonus/maxBonus<0.16 and flag=='') then fc = FCg; end
159 local duration = SecondsToTime(secs);
160 if(data.rest or name~=Player) then
161 msg = msg..", fully rested in "..duration;
162 else msg = msg..", can camp for "..duration; end
163 else fc = FCo; end
164 if(data.time>time()) then fc = FCr; end
165 print(fc..msg..'.');
166 end