Mercurial > wow > icu
comparison ICU.lua @ 0:98c6f55e6619
First commit
author | Xiiph |
---|---|
date | Sat, 05 Feb 2011 16:45:02 +0100 |
parents | |
children | 6af2d0a0c537 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:98c6f55e6619 |
---|---|
1 local L = LibStub("AceLocale-3.0"):GetLocale("ICU") | |
2 if not L then return end | |
3 | |
4 local icu = LibStub("AceAddon-3.0"):NewAddon("ICU", "AceEvent-3.0", "AceTimer-3.0"); | |
5 | |
6 -- Accepted flasks | |
7 local flaskID = { | |
8 79469, -- Flask of Steelskin | |
9 79470, -- Flask of the Draconic Mind | |
10 79471, -- Flask of the Winds | |
11 79472, -- Flask of Titanic Strength | |
12 94160, -- Flask of Flowing Water | |
13 }; | |
14 | |
15 -- Accepted well-fed buffs | |
16 local foodID = { | |
17 87545, -- 90 Strength | |
18 87546, -- 90 Agility | |
19 87547, -- 90 Intellect | |
20 87548, -- 90 Spirit | |
21 87549, -- 90 Mastery | |
22 87550, -- 90 Hit | |
23 87551, -- 90 Crit | |
24 87552, -- 90 Haste | |
25 }; | |
26 | |
27 | |
28 local minFlaskDuration = 10; | |
29 local noFlask, noFood, hasLowDuration = {},{},{}; | |
30 | |
31 local defaults = { | |
32 profile = { | |
33 checkFlask = true, | |
34 checkFood = true, | |
35 checkLowFlaskDuration = true, | |
36 remindRaider = true, | |
37 reportResults = true, | |
38 reportDestination = "OFFICER", | |
39 manualCheckOnly = false, | |
40 checkAfterFinish = true, | |
41 advertiseICU = true, | |
42 noFoodMessage = L["Well Fed reminder!"], | |
43 noFlaskMessage = L["Flask reminder!"], | |
44 lowFlaskDurationMessage = L["Your Flask runs out in less than 10 minutes!"], | |
45 } | |
46 } | |
47 | |
48 function icu:OnInitialize() | |
49 self.db = LibStub("AceDB-3.0"):New("icuDB", defaults, true) | |
50 | |
51 self.db.RegisterCallback(self, "OnProfileChanged", "refreshConfig") | |
52 self.db.RegisterCallback(self, "OnProfileCopied", "refreshConfig") | |
53 self.db.RegisterCallback(self, "OnProfileReset", "refreshConfig") | |
54 | |
55 self.options = self:getOptions() | |
56 | |
57 local AceConfig = LibStub("AceConfig-3.0") | |
58 local AceConfigDialog = LibStub("AceConfigDialog-3.0") | |
59 | |
60 AceConfig:RegisterOptionsTable("ICU", self.options, {"icu"}) | |
61 | |
62 AceConfigDialog:AddToBlizOptions("ICU", nil, nil, "general") | |
63 AceConfigDialog:AddToBlizOptions("ICU", "Profiles","ICU","profile") | |
64 end | |
65 | |
66 function icu:refreshConfig() | |
67 --print("ICU: Config refreshing ..."); | |
68 | |
69 if self.db.profile.manualCheckOnly then | |
70 icu:UnregisterEvent("READY_CHECK"); | |
71 else | |
72 icu:RegisterEvent("READY_CHECK"); | |
73 end | |
74 | |
75 --print("ICU: Config refreshed!"); | |
76 end | |
77 | |
78 function icu:config() | |
79 InterfaceOptionsFrame_OpenToCategory("ICU") | |
80 end | |
81 | |
82 function icu:getOptions() | |
83 local options = { | |
84 handler = icu, | |
85 type = 'group', | |
86 args = { | |
87 config = { | |
88 name = L["Options"], | |
89 desc = L["Shows the blizzard addon configuration window"], | |
90 type = 'execute', | |
91 func = "config", | |
92 hidden = true, | |
93 cmdHidden = false, | |
94 }, | |
95 check = { | |
96 name = L["Raid Check"], | |
97 desc = L["Checks the raid for flask/food buffs"], | |
98 type = 'execute', | |
99 func = function() self:inspectRaid(false) end, | |
100 hidden = true, | |
101 cmdHidden = false, | |
102 }, | |
103 quiet = { | |
104 name = L["Raid Check (Silent)"], | |
105 desc = L["Checks the raid for flask/food buffs, but does not remind raiders, regardless of other settings."], | |
106 type = 'execute', | |
107 func = function() self:inspectRaid(true) end, | |
108 hidden = true, | |
109 cmdHidden = false, | |
110 }, | |
111 general = { | |
112 name = L["General Settings"], | |
113 type = 'group', | |
114 args = { | |
115 checkFlask = { | |
116 type = 'toggle', | |
117 name = L["Check for Flask"], | |
118 desc = L["Checks the raid for valid flasks and reports results"], | |
119 set = function(o,v,...) self.db.profile.checkFlask = v end, | |
120 get = function() return self.db.profile.checkFlask end, | |
121 }, | |
122 checkLowFlaskDuration = { | |
123 type = 'toggle', | |
124 name = L["Flask expiration"], | |
125 desc = L["Check for soon to expire flask buffs"], | |
126 set = function(o,v,...) self.db.profile.checkLowFlaskDuration = v end, | |
127 get = function() return self.db.profile.checkLowFlaskDuration end, | |
128 }, | |
129 checkFood = { | |
130 type = 'toggle', | |
131 name = L["Check for Food"], | |
132 desc = L["Checks the raid for valid food buffs and reports results"], | |
133 set = function(o,v,...) self.db.profile.checkFood = v end, | |
134 get = function() return self.db.profile.checkFood end, | |
135 }, | |
136 advertiseICU = { | |
137 type = 'toggle', | |
138 name = L["Advertise ICU"], | |
139 desc = L["Let everyone know you are using ICU! Prefixes whispers and reports"], | |
140 set = function(o,v,...) self.db.profile.advertiseICU = v end, | |
141 get = function() return self.db.profile.advertiseICU end, | |
142 }, | |
143 remindRaider = { | |
144 type = 'toggle', | |
145 name = L["Raid reminder"], | |
146 desc = L["Whisper the raider lacking (or soon to expire, if enabled) food/flask buff a reminder"], | |
147 set = function(o,v,...) self.db.profile.remindRaider = v end, | |
148 get = function() return self.db.profile.remindRaider end, | |
149 }, | |
150 reportResults = { | |
151 type = 'toggle', | |
152 name = L["Report results"], | |
153 desc = L["Report the results after finishing"], | |
154 set = function(o,v,...) self.db.profile.reportResults = v end, | |
155 get = function() return self.db.profile.reportResults end, | |
156 }, | |
157 reportDestination = { | |
158 type = 'select', | |
159 style = "dropdown", | |
160 name = L["Report Destination"], | |
161 desc = L["Report the results to the following channel"], | |
162 values = { | |
163 ["OFFICER"] = L["Officer"], | |
164 ["SAY"] = L["Say"], | |
165 ["RAID"] = L["Raid"], | |
166 ["GUILD"] = L["Guild"], | |
167 ["SELF"] = L["Self"], | |
168 }, | |
169 set = function(o,v,...) self.db.profile.reportDestination = v end, | |
170 get = function() return self.db.profile.reportDestination end, | |
171 }, | |
172 manualCheckOnly = { | |
173 type = 'toggle', | |
174 name = L["Manual checks only"], | |
175 desc = L["Only perform buff checks if initiated manually (via /icu check)"], | |
176 set = function(o,v,...) self.db.profile.manualCheckOnly = v; self:refreshConfig() end, | |
177 get = function() return self.db.profile.manualCheckOnly end, | |
178 }, | |
179 checkAfterFinish = { | |
180 type = 'toggle', | |
181 name = L["Check after readycheck"], | |
182 desc = L["Don't check buffs until ready check has finished (or timed out)"], | |
183 set = function(o,v,...) self.db.profile.checkAfterFinish = v end, | |
184 get = function() return self.db.profile.checkAfterFinish end, | |
185 }, | |
186 noFlaskMessage = { | |
187 type = 'input', | |
188 name = L["Flask reminder"], | |
189 desc = L["Message whispered to raiders missing a cataclysm flask"], | |
190 set = function(o,v,...) self.db.profile.noFlaskMessage = v end, | |
191 get = function() return self.db.profile.noFlaskMessage end, | |
192 }, | |
193 lowFlaskDurationMessage = { | |
194 type = 'input', | |
195 name = L["Flask expiration"], | |
196 desc = L["Message whispered to raiders with less than 10 minutes left on their flask"], | |
197 set = function(o,v,...) self.db.profile.lowFlaskDurationMessage = v end, | |
198 get = function() return self.db.profile.lowFlaskDurationMessage end, | |
199 }, | |
200 noFoodMessage = { | |
201 type = 'input', | |
202 name = L["Food reminder"], | |
203 desc = L["Message whispered to raiders missing the well-fed buff"], | |
204 set = function(o,v,...) self.db.profile.noFoodMessage = v end, | |
205 get = function() return self.db.profile.noFoodMessage end, | |
206 }, | |
207 | |
208 } | |
209 }, | |
210 profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db), | |
211 }, | |
212 } | |
213 return options | |
214 end | |
215 | |
216 function icu:inspectRaid(silent) | |
217 -- Not in a raid group | |
218 local icuAd = ""; | |
219 | |
220 if GetNumRaidMembers() == 0 then | |
221 return true | |
222 end | |
223 | |
224 if self.db.profile.advertiseICU then | |
225 icuAd = L["ICU"] .. ": "; | |
226 else | |
227 icuAd = ""; | |
228 end | |
229 | |
230 for i = 1, GetNumRaidMembers() do | |
231 local raider = GetRaidRosterInfo(i); | |
232 if raider then | |
233 | |
234 local hasFood, hasFlask, hasLowDuration = icu:validateBuffs(i); | |
235 | |
236 if not hasFood and self.db.profile.checkFood then | |
237 noFood[#noFood+1] = raider; | |
238 -- Tell player | |
239 if self.db.profile.remindRaider and not silent then | |
240 SendChatMessage(icuAd .. self.db.profile.noFoodMessage,"WHISPER",nil,raider); | |
241 end | |
242 end | |
243 | |
244 if not hasFlask and self.db.profile.checkFlask then | |
245 noFlask[#noFlask+1] = raider; | |
246 -- Tell player | |
247 if self.db.profile.remindRaider and not silent then | |
248 SendChatMessage(icuAd .. self.db.profile.noFlaskMessage,"WHISPER",nil,raider); | |
249 end | |
250 elseif hasLowDuration and not silent then | |
251 if self.db.profile.remindRaider and self.db.profile.checkLowFlaskDuration then | |
252 SendChatMessage(icuAd .. self.db.profile.lowFlaskDurationMessage,"WHISPER",nil,raider); | |
253 end | |
254 end | |
255 end | |
256 | |
257 end | |
258 | |
259 if self.db.profile.reportResults and (#noFlask > 0 or #noFood > 0) and self.db.profile.advertiseICU and self.db.profile.reportDestination ~= "SELF" then | |
260 SendChatMessage("---- "..L["ICU"].." "..L["Report"].." ----",self.db.profile.reportDestination,nil,nil); | |
261 end | |
262 | |
263 if self.db.profile.reportResults then | |
264 if #noFlask > 0 and self.db.profile.checkFlask then | |
265 local reportFlaskMessage = L["Missing Flask"]..": " .. table.concat(noFlask, ", "); | |
266 | |
267 if self.db.profile.reportDestination == "SELF" then | |
268 DEFAULT_CHAT_FRAME:AddMessage(reportFlaskMessage); | |
269 else | |
270 SendChatMessage(reportFlaskMessage,self.db.profile.reportDestination,nil,nil); | |
271 end | |
272 end | |
273 | |
274 if #noFood > 0 and self.db.profile.checkFood then | |
275 local reportFoodMessage = L["Missing Food"]..": " .. table.concat(noFood, ", "); | |
276 | |
277 if self.db.profile.reportDestination == "SELF" then | |
278 DEFAULT_CHAT_FRAME:AddMessage(reportFoodMessage); | |
279 else | |
280 SendChatMessage(reportFoodMessage,self.db.profile.reportDestination,nil,nil); | |
281 end | |
282 end | |
283 end | |
284 | |
285 noFlask, noFood, hasLowDuration = {},{},{}; | |
286 end | |
287 | |
288 function icu:validateBuffs(playerIndex) | |
289 local i = 1; | |
290 local hasFood, hasFlask, hasLowDuration = false, false, false; | |
291 local name, _, _, _, _, _, expirationTime, _, _, _, spellId = UnitBuff("raid"..playerIndex,i); | |
292 | |
293 while name do | |
294 -- Check for food | |
295 if not hasFood then | |
296 for k,v in ipairs(foodID) do | |
297 if v == spellId then | |
298 hasFood = true; | |
299 end | |
300 end | |
301 end | |
302 -- Check for flask | |
303 if not hasFlask then | |
304 for k,v in ipairs(flaskID) do | |
305 if v == spellId then | |
306 hasFlask = true; | |
307 -- Check if low duration | |
308 if expirationTime and ((expirationTime-GetTime())/60) <= minFlaskDuration then | |
309 hasLowDuration = true; | |
310 end | |
311 end | |
312 end | |
313 end | |
314 i = i + 1; | |
315 name, _, _, _, _, _, expirationTime, _, _, _, spellId = UnitBuff("raid"..playerIndex,i); | |
316 end | |
317 | |
318 return hasFood, hasFlask, hasLowDuration; | |
319 end | |
320 | |
321 function icu:READY_CHECK() | |
322 --print("Ready check init!"); | |
323 if self.db.profile.manualCheckOnly then | |
324 icu:UnregisterEvent("READY_CHECK"); | |
325 return true; | |
326 end | |
327 | |
328 if not self.db.profile.checkAfterFinish then | |
329 self:inspectRaid(); | |
330 else | |
331 self:ScheduleTimer("READY_CHECK_FINISHED", 30); | |
332 self:RegisterEvent("READY_CHECK_FINISHED"); | |
333 end | |
334 end | |
335 | |
336 function icu:READY_CHECK_FINISHED() | |
337 --print("Ready check finish!"); | |
338 self:UnregisterEvent("READY_CHECK_FINISHED"); | |
339 self:CancelAllTimers(); | |
340 self:inspectRaid(); | |
341 end | |
342 | |
343 function icu:filterChat(self, event, msg) | |
344 if msg == self.db.profile.noFoodMessage or msg == self.db.profile.noFlaskMessage or msg == self.db.profile.lowFlaskDurationMessage or msg == L["ICU"]..": "..self.db.profile.noFoodMessage or msg == L["ICU"]..": "..self.db.profile.noFlaskMessage or msg == L["ICU"]..": "..self.db.profile.lowFlaskDurationMessage then return true end | |
345 end | |
346 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_ICU_INFORM", icu:filterChat) | |
347 | |
348 icu:RegisterEvent("READY_CHECK"); | |
349 | |
350 --@do-not-package@ | |
351 function icu:test(cond) | |
352 if true and not cond then | |
353 print("First.") | |
354 else | |
355 print("Second.") | |
356 end | |
357 end | |
358 | |
359 function icu:grabVar(var) | |
360 print(self.db.profile[var]) | |
361 end | |
362 | |
363 _G.icu = icu; | |
364 --@end-do-not-package@ |