vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 BINDING_HEADER_ZASHIR = "Zashir's Tome of Power";
2 BINDING_NAME_DEATHESTIMATOR = "Death Estimator";
3  
4 DeathEstimatorLastHealth = {};
5 DeathEstimatorLastHealthTable = {};
6 DeathEstimatorLastTime = {};
7 DeathEstimatorDisplayLastUpdated = {};
8 DeathEstimatorUnitTypeList = { "player", "pet", "target", "party1", "party2", "party3", "party4" };
9 DeathEstimatorDisplayResetDelay = 5;
10 DeathEstimatorIntervalsToAverage = 10;
11  
12 function DeathEstimator_OnLoad()
13 this:RegisterEvent("UNIT_HEALTH");
14 this:RegisterEvent("PLAYER_PET_CHANGED");
15 this:RegisterEvent("PLAYER_TARGET_CHANGED");
16 this:RegisterEvent("PARTY_MEMBERS_CHANGED");
17  
18 DeathEstimatorPlayerLabel:SetText("Player ETD:");
19 DeathEstimatorPlayerText:SetText("??:??:??");
20 DeathEstimatorPetLabel:SetText("Pet ETD:");
21 DeathEstimatorTargetLabel:SetText("Target ETD:");
22  
23 DeathEstimator_OnEvent("PLAYER_PET_CHANGED");
24 DeathEstimator_OnEvent("PLAYER_TARGET_CHANGED");
25 end
26  
27 function DeathEstimator_PartyOnLoad()
28 this:RegisterEvent("UNIT_HEALTH");
29 this:RegisterEvent("PARTY_MEMBERS_CHANGED");
30  
31 DeathEstimator_OnEvent("PARTY_MEMBERS_CHANGED");
32 end
33  
34 function DeathEstimator_OnEvent(event)
35 local DeathEstimatorPartyWindowHeight = 0;
36 local DeathEstimatorWindowHeight = 64;
37  
38 if ( event == "PLAYER_PET_CHANGED" ) then
39 if ( UnitExists("pet") ) then
40 DeathEstimatorLastHealth["pet"] = UnitHealth("pet");
41 DeathEstimatorPetButton:Show();
42 DeathEstimatorTargetButton:SetPoint("TOPLEFT", "DeathEstimatorFrame", "TOPLEFT", 2, -32);
43 else
44 DeathEstimatorLastHealth["pet"] = nil;
45 DeathEstimatorPetButton:Hide();
46 DeathEstimatorTargetButton:SetPoint("TOPLEFT", "DeathEstimatorFrame", "TOPLEFT", 2, -16);
47 end
48 DeathEstimatorLastHealthTable["pet"] = {};
49 DeathEstimatorPetText:SetText("??:??:??");
50 end
51  
52 if ( event == "PLAYER_TARGET_CHANGED" ) then
53 if ( UnitExists("target") ) then
54 DeathEstimatorLastHealth["target"] = UnitHealth("target");
55 DeathEstimatorTargetButton:Show();
56 else
57 DeathEstimatorLastHealth["target"] = nil;
58 DeathEstimatorTargetButton:Hide();
59 end
60 DeathEstimatorLastHealthTable["target"] = {};
61 DeathEstimatorTargetText:SetText("??:??:??");
62 end
63  
64 if ( (event == "PLAYER_TARGET_CHANGED") or (event == "PLAYER_PET_CHANGED") ) then
65 if ( not UnitExists("pet") ) then
66 DeathEstimatorWindowHeight = DeathEstimatorWindowHeight - 16;
67 end
68 if ( not UnitExists("target") ) then
69 DeathEstimatorWindowHeight = DeathEstimatorWindowHeight - 16;
70 end
71 if ( DeathEstimatorWindowHeight < 32 ) then
72 DeathEstimatorWindowHeight = 32;
73 end
74 DeathEstimatorFrame:SetHeight(DeathEstimatorWindowHeight);
75 end
76  
77 if ( event == "PARTY_MEMBERS_CHANGED" ) then
78 if ( UnitInParty("party1") ) then
79 DeathEstimatorPartyFrame:Show();
80 else
81 DeathEstimatorPartyFrame:Hide();
82 end
83  
84 if ( UnitExists("party1") ) then
85 DeathEstimatorParty1Label:SetText((UnitName("party1"))..":");
86 DeathEstimatorParty1Text:SetText("??:??:??");
87 DeathEstimatorParty1Button:Show();
88 DeathEstimatorLastHealthTable["party1"] = {};
89 else
90 DeathEstimatorParty1Button:Hide();
91 end
92 if ( UnitExists("party2") ) then
93 DeathEstimatorParty2Label:SetText((UnitName("party2"))..":");
94 DeathEstimatorParty2Text:SetText("??:??:??");
95 DeathEstimatorParty2Button:Show();
96 DeathEstimatorLastHealthTable["party2"] = {};
97 else
98 DeathEstimatorParty2Button:Hide();
99 end
100 if ( UnitExists("party3") ) then
101 DeathEstimatorParty3Label:SetText((UnitName("party3"))..":");
102 DeathEstimatorParty3Text:SetText("??:??:??");
103 DeathEstimatorParty3Button:Show();
104 DeathEstimatorLastHealthTable["party3"] = {};
105 else
106 DeathEstimatorParty3Button:Hide();
107 end
108 if ( UnitExists("party4") ) then
109 DeathEstimatorParty4Label:SetText((UnitName("party4"))..":");
110 DeathEstimatorParty4Text:SetText("??:??:??");
111 DeathEstimatorParty4Button:Show();
112 DeathEstimatorLastHealthTable["party4"] = {};
113 else
114 DeathEstimatorParty4Button:Hide();
115 end
116  
117 if ( DeathEstimatorPartyFrame:IsVisible() ) then
118 for i = 1, 4, 1 do
119 if ( UnitExists("party"..i) ) then
120 DeathEstimatorPartyWindowHeight = DeathEstimatorPartyWindowHeight + 24;
121 end
122 end
123 if ( DeathEstimatorPartyWindowHeight < 32 ) then
124 DeathEstimatorPartyWindowHeight = 32;
125 end
126 if ( DeathEstimatorPartyWindowHeight == 72 ) then
127 DeathEstimatorPartyWindowHeight = 64;
128 end
129 if ( DeathEstimatorPartyWindowHeight > 80 ) then
130 DeathEstimatorPartyWindowHeight = 80;
131 end
132 DeathEstimatorPartyFrame:SetHeight(DeathEstimatorPartyWindowHeight);
133 end
134 end
135 end
136  
137 function DeathEstimator_OnUpdate()
138 local i
139 local DeathEstimatorHealthLost = {};
140 local DeathEstimatorHealthLossAverage = 0;
141  
142 for index, DeathEstimatorUnitType in DeathEstimatorUnitTypeList do
143 if ( UnitExists(DeathEstimatorUnitType) ) then
144 if ( not DeathEstimatorLastTime[DeathEstimatorUnitType] ) then
145 DeathEstimatorLastTime[DeathEstimatorUnitType] = GetTime();
146 end
147  
148 if ( (GetTime() - DeathEstimatorLastTime[DeathEstimatorUnitType]) >= 1 ) then
149 DeathEstimatorLastTime[DeathEstimatorUnitType] = GetTime();
150  
151 if ( not DeathEstimatorLastHealth[DeathEstimatorUnitType] ) then
152 DeathEstimatorLastHealth[DeathEstimatorUnitType] = UnitHealth(DeathEstimatorUnitType);
153 end
154  
155 if ( not DeathEstimatorLastHealthTable[DeathEstimatorUnitType] ) then
156 DeathEstimatorLastHealthTable[DeathEstimatorUnitType] = {};
157 end
158  
159 if ( not (DeathEstimatorLastHealth[DeathEstimatorUnitType] == UnitHealth(DeathEstimatorUnitType)) ) then
160 DeathEstimatorHealthLost[DeathEstimatorUnitType] = DeathEstimatorLastHealth[DeathEstimatorUnitType] - UnitHealth(DeathEstimatorUnitType);
161 DeathEstimatorLastHealth[DeathEstimatorUnitType] = UnitHealth(DeathEstimatorUnitType);
162 table.insert(DeathEstimatorLastHealthTable[DeathEstimatorUnitType], DeathEstimatorHealthLost[DeathEstimatorUnitType]);
163 if ( table.getn(DeathEstimatorLastHealthTable[DeathEstimatorUnitType]) >= DeathEstimatorIntervalsToAverage ) then
164 for i = table.getn(DeathEstimatorLastHealthTable[DeathEstimatorUnitType]) - DeathEstimatorIntervalsToAverage + 1, table.getn(DeathEstimatorLastHealthTable[DeathEstimatorUnitType]), 1 do
165 DeathEstimatorHealthLossAverage = DeathEstimatorHealthLossAverage + DeathEstimatorLastHealthTable[DeathEstimatorUnitType][i];
166 end
167 DeathEstimatorHealthLossAverage = DeathEstimatorHealthLossAverage / DeathEstimatorIntervalsToAverage;
168 else
169 for i = 1, table.getn(DeathEstimatorLastHealthTable[DeathEstimatorUnitType]), 1 do
170 DeathEstimatorHealthLossAverage = DeathEstimatorHealthLossAverage + DeathEstimatorLastHealthTable[DeathEstimatorUnitType][i];
171 end
172 DeathEstimatorHealthLossAverage = DeathEstimatorHealthLossAverage / table.getn(DeathEstimatorLastHealthTable[DeathEstimatorUnitType]);
173 end
174 if ( DeathEstimatorHealthLossAverage > 0 ) then
175 DeathEstimator_DisplayETD(DeathEstimatorHealthLossAverage, UnitHealth(DeathEstimatorUnitType), DeathEstimatorUnitType);
176 else
177 DeathEstimatorLastHealthTable[DeathEstimatorUnitType] = {};
178 end
179 else
180 if ( UnitHealth(DeathEstimatorUnitType) == UnitHealthMax(DeathEstimatorUnitType) ) then
181 DeathEstimatorLastHealthTable[DeathEstimatorUnitType] = {};
182 else
183 table.insert(DeathEstimatorLastHealthTable[DeathEstimatorUnitType], 0);
184 end
185 end
186 end
187 end
188 end
189  
190 if ( DeathEstimatorDisplayLastUpdated["player"] and ((GetTime() - DeathEstimatorDisplayLastUpdated["player"]) >= DeathEstimatorDisplayResetDelay) ) then
191 DeathEstimatorPlayerText:SetText("??:??:??");
192 DeathEstimatorLastHealthTable["player"] = {};
193 end
194 if ( DeathEstimatorDisplayLastUpdated["pet"] and ((GetTime() - DeathEstimatorDisplayLastUpdated["pet"]) >= DeathEstimatorDisplayResetDelay) ) then
195 DeathEstimatorPetText:SetText("??:??:??");
196 DeathEstimatorLastHealthTable["pet"] = {};
197 end
198 if ( DeathEstimatorDisplayLastUpdated["target"] and ((GetTime() - DeathEstimatorDisplayLastUpdated["target"]) >= DeathEstimatorDisplayResetDelay) ) then
199 DeathEstimatorTargetText:SetText("??:??:??");
200 DeathEstimatorLastHealthTable["target"] = {};
201 end
202 if ( DeathEstimatorDisplayLastUpdated["party1"] and ((GetTime() - DeathEstimatorDisplayLastUpdated["party1"]) >= DeathEstimatorDisplayResetDelay) ) then
203 if ( UnitExists("party1") ) then
204 DeathEstimatorParty1Label:SetText((UnitName("party1"))..":");
205 DeathEstimatorParty1Text:SetText("??:??:??");
206 end
207 DeathEstimatorLastHealthTable["party1"] = {};
208 end
209 if ( DeathEstimatorDisplayLastUpdated["party2"] and ((GetTime() - DeathEstimatorDisplayLastUpdated["party2"]) >= DeathEstimatorDisplayResetDelay) ) then
210 if ( UnitExists("party2") ) then
211 DeathEstimatorParty2Label:SetText((UnitName("party2"))..":");
212 DeathEstimatorParty2Text:SetText("??:??:??");
213 end
214 DeathEstimatorLastHealthTable["party2"] = {};
215 end
216 if ( DeathEstimatorDisplayLastUpdated["party3"] and ((GetTime() - DeathEstimatorDisplayLastUpdated["party3"]) >= DeathEstimatorDisplayResetDelay) ) then
217 if ( UnitExists("party3") ) then
218 DeathEstimatorParty3Label:SetText((UnitName("party3"))..":");
219 DeathEstimatorParty3Text:SetText("??:??:??");
220 end
221 DeathEstimatorLastHealthTable["party3"] = {};
222 end
223 if ( DeathEstimatorDisplayLastUpdated["party4"] and ((GetTime() - DeathEstimatorDisplayLastUpdated["party4"]) >= DeathEstimatorDisplayResetDelay) ) then
224 if ( UnitExists("party4") ) then
225 DeathEstimatorParty4Label:SetText((UnitName("party4"))..":");
226 DeathEstimatorParty4Text:SetText("??:??:??");
227 end
228 DeathEstimatorLastHealthTable["party4"] = {};
229 end
230 end
231  
232 function DeathEstimator_DisplayETD(HealthLossAverage, TargetHealthLeft, TargetType)
233 local MinutesToLive = "00";
234 local HoursToLive = "00";
235 local SecondsToLive = ceil(TargetHealthLeft / HealthLossAverage);
236  
237 if ( SecondsToLive >= 3600 ) then
238 HoursToLive = floor(SecondsToLive / 3600);
239 SecondsToLive = SecondsToLive - (HoursToLive * 3600);
240 if ( HoursToLive < 10 ) then
241 HoursToLive = "0"..(HoursToLive);
242 end
243 end
244 if ( SecondsToLive >= 60 ) then
245 MinutesToLive = floor(SecondsToLive / 60);
246 SecondsToLive = SecondsToLive - (MinutesToLive * 60);
247 if ( MinutesToLive < 10 ) then
248 MinutesToLive = "0"..(MinutesToLive);
249 end
250 end
251 if ( SecondsToLive < 10 ) then
252 SecondsToLive = "0"..(SecondsToLive);
253 end
254  
255 if ( TargetType == "player" ) then
256 DeathEstimatorPlayerText:SetText((HoursToLive)..":"..(MinutesToLive)..":"..(SecondsToLive));
257 end
258 if ( TargetType == "pet") then
259 DeathEstimatorPetText:SetText((HoursToLive)..":"..(MinutesToLive)..":"..(SecondsToLive));
260 end
261 if ( TargetType == "target" ) then
262 DeathEstimatorTargetText:SetText((HoursToLive)..":"..(MinutesToLive)..":"..(SecondsToLive));
263 end
264  
265 if ( TargetType == "party1" ) then
266 DeathEstimatorParty1Text:SetText((HoursToLive)..":"..(MinutesToLive)..":"..(SecondsToLive));
267 end
268 if ( TargetType == "party2" ) then
269 DeathEstimatorParty2Text:SetText((HoursToLive)..":"..(MinutesToLive)..":"..(SecondsToLive));
270 end
271 if ( TargetType == "party3" ) then
272 DeathEstimatorParty3Text:SetText((HoursToLive)..":"..(MinutesToLive)..":"..(SecondsToLive));
273 end
274 if ( TargetType == "party4" ) then
275 DeathEstimatorParty4Text:SetText((HoursToLive)..":"..(MinutesToLive)..":"..(SecondsToLive));
276 end
277  
278 DeathEstimatorDisplayLastUpdated[TargetType] = GetTime();
279 end
280  
281 function ToggleDeathEstimator()
282 if ( DeathEstimatorFrame:IsVisible() ) then
283 DeathEstimatorFrame:Hide();
284 else
285 DeathEstimatorFrame:Show();
286 end
287 end