comparison ICU.lua @ 7:f020d96ccfc8

Added options to announce ready checks to selected report destination. Cleaned up options further.
author Xiiph
date Fri, 18 Feb 2011 23:58:20 +0100
parents 60ac81ad00a2
children 0ed4c1a0412e
comparison
equal deleted inserted replaced
6:60ac81ad00a2 7:f020d96ccfc8
36 }; 36 };
37 37
38 38
39 local minFlaskDuration = 10; 39 local minFlaskDuration = 10;
40 local noFlask, noFood, hasLowDuration = {},{},{}; 40 local noFlask, noFood, hasLowDuration = {},{},{};
41 local notReady, notReadyAFK, responders = {}, {}, {};
41 42
42 local defaults = { 43 local defaults = {
43 profile = { 44 profile = {
44 checkFlask = true, 45 checkFlask = true,
45 checkFood = true, 46 checkFood = true,
53 noFoodMessage = L["Well Fed reminder!"], 54 noFoodMessage = L["Well Fed reminder!"],
54 noFlaskMessage = L["Flask reminder!"], 55 noFlaskMessage = L["Flask reminder!"],
55 lowFlaskDurationMessage = L["Your Flask runs out in less than 10 minutes!"], 56 lowFlaskDurationMessage = L["Your Flask runs out in less than 10 minutes!"],
56 disabledZones = {}, 57 disabledZones = {},
57 enableAllZones = true, 58 enableAllZones = true,
59 announceReadyCheck = true,
58 } 60 }
59 } 61 }
60 62
61 function icu:OnInitialize() 63 function icu:OnInitialize()
62 self.db = LibStub("AceDB-3.0"):New("icuDB", defaults, true) 64 self.db = LibStub("AceDB-3.0"):New("icuDB", defaults, true)
74 76
75 AceConfigDialog:AddToBlizOptions("ICU", nil, nil, "general") 77 AceConfigDialog:AddToBlizOptions("ICU", nil, nil, "general")
76 AceConfigDialog:AddToBlizOptions("ICU", "Whispers","ICU","messages") 78 AceConfigDialog:AddToBlizOptions("ICU", "Whispers","ICU","messages")
77 AceConfigDialog:AddToBlizOptions("ICU", "Disabled Zones","ICU","zones") 79 AceConfigDialog:AddToBlizOptions("ICU", "Disabled Zones","ICU","zones")
78 AceConfigDialog:AddToBlizOptions("ICU", "Profiles","ICU","profile") 80 AceConfigDialog:AddToBlizOptions("ICU", "Profiles","ICU","profile")
81
82 -- Ready check confirm event registration
83 if self.db.profile.announceReadyCheck then
84 self:RegisterEvent("READY_CHECK_CONFIRM");
85 end
86
87 -- Ready check event registration
88 if not self.db.profile.manualCheckOnly then
89 icu:RegisterEvent("READY_CHECK");
90 end
79 end 91 end
80 92
81 function icu:refreshConfig() 93 function icu:refreshConfig()
82 --print("ICU: Config refreshing ..."); 94 --print("ICU: Config refreshing ...");
83 95
84 if self.db.profile.manualCheckOnly then 96 if self.db.profile.manualCheckOnly then
85 icu:UnregisterEvent("READY_CHECK"); 97 icu:UnregisterEvent("READY_CHECK");
86 else 98 else
87 icu:RegisterEvent("READY_CHECK"); 99 icu:RegisterEvent("READY_CHECK");
100 end
101
102 if not self.db.profile.announceReadyCheck then
103 icu:UnregisterEvent("READY_CHECK_CONFIRM");
104 else
105 icu:RegisterEvent("READY_CHECK_CONFIRM");
88 end 106 end
89 107
90 --print("ICU: Config refreshed!"); 108 --print("ICU: Config refreshed!");
91 end 109 end
92 110
125 }, 143 },
126 general = { 144 general = {
127 name = L["General Settings"], 145 name = L["General Settings"],
128 type = 'group', 146 type = 'group',
129 args = { 147 args = {
148 advertiseICU = {
149 type = 'toggle',
150 order = 1,
151 width = 'full',
152 name = L["Advertise ICU"],
153 desc = L["Let everyone know you are using ICU! Prefixes whispers and reports"],
154 set = function(o,v,...) self.db.profile.advertiseICU = v end,
155 get = function() return self.db.profile.advertiseICU end,
156 },
130 checkFlask = { 157 checkFlask = {
131 type = 'toggle', 158 type = 'toggle',
159 order = 2,
132 name = L["Check for Flask"], 160 name = L["Check for Flask"],
133 desc = L["Checks the raid for valid flasks and reports results"], 161 desc = L["Checks the raid for valid flasks and reports results"],
134 set = function(o,v,...) self.db.profile.checkFlask = v end, 162 set = function(o,v,...) self.db.profile.checkFlask = v end,
135 get = function() return self.db.profile.checkFlask end, 163 get = function() return self.db.profile.checkFlask end,
136 }, 164 },
137 checkLowFlaskDuration = { 165 checkLowFlaskDuration = {
138 type = 'toggle', 166 type = 'toggle',
167 order = 3,
139 name = L["Flask expiration"], 168 name = L["Flask expiration"],
140 desc = L["Check for soon to expire flask buffs"], 169 desc = L["Check for soon to expire flask buffs"],
141 set = function(o,v,...) self.db.profile.checkLowFlaskDuration = v end, 170 set = function(o,v,...) self.db.profile.checkLowFlaskDuration = v end,
142 get = function() return self.db.profile.checkLowFlaskDuration end, 171 get = function() return self.db.profile.checkLowFlaskDuration end,
143 }, 172 },
144 checkFood = { 173 checkFood = {
145 type = 'toggle', 174 type = 'toggle',
175 order = 4,
146 name = L["Check for Food"], 176 name = L["Check for Food"],
147 desc = L["Checks the raid for valid food buffs and reports results"], 177 desc = L["Checks the raid for valid food buffs and reports results"],
148 set = function(o,v,...) self.db.profile.checkFood = v end, 178 set = function(o,v,...) self.db.profile.checkFood = v end,
149 get = function() return self.db.profile.checkFood end, 179 get = function() return self.db.profile.checkFood end,
150 }, 180 },
151 advertiseICU = {
152 type = 'toggle',
153 name = L["Advertise ICU"],
154 desc = L["Let everyone know you are using ICU! Prefixes whispers and reports"],
155 set = function(o,v,...) self.db.profile.advertiseICU = v end,
156 get = function() return self.db.profile.advertiseICU end,
157 },
158 remindRaider = { 181 remindRaider = {
159 type = 'toggle', 182 type = 'toggle',
183 order = 5,
184 width = 'full',
160 name = L["Raid reminder"], 185 name = L["Raid reminder"],
161 desc = L["Whisper the raider lacking (or soon to expire, if enabled) food/flask buff a reminder"], 186 desc = L["Whisper the raider lacking (or soon to expire, if enabled) food/flask buff a reminder"],
162 set = function(o,v,...) self.db.profile.remindRaider = v end, 187 set = function(o,v,...) self.db.profile.remindRaider = v end,
163 get = function() return self.db.profile.remindRaider end, 188 get = function() return self.db.profile.remindRaider end,
164 }, 189 },
190 breakOne = {
191 type = 'description',
192 fontSize = 'large',
193 name = ' ',
194 order = 7,
195 width = 'full',
196 },
197 manualCheckOnly = {
198 type = 'toggle',
199 order = 8,
200 name = L["Manual checks only"],
201 desc = L["Only perform buff checks if initiated manually (via /icu check)"],
202 set = function(o,v,...) self.db.profile.manualCheckOnly = v; self:refreshConfig() end,
203 get = function() return self.db.profile.manualCheckOnly end,
204 },
205 checkAfterFinish = {
206 type = 'toggle',
207 order = 9,
208 width = 'full',
209 name = L["Inspect AFTER ready check finishes"],
210 desc = L["Don't check buffs until the ready check has finished (or timed out)"],
211 set = function(o,v,...) self.db.profile.checkAfterFinish = v end,
212 get = function() return self.db.profile.checkAfterFinish end,
213 },
214 breakTwo = {
215 type = 'description',
216 fontSize = 'large',
217 name = ' ',
218 order = 10,
219 width = 'full',
220 },
221 announceReadyCheck = {
222 type = 'toggle',
223 order = 11,
224 name = L["Report ready checks"],
225 desc = L["Report the results of ready checks"],
226 width = 'double',
227 set = function(o,v,...) self.db.profile.announceReadyCheck = v; self:refreshConfig() end,
228 get = function() return self.db.profile.announceReadyCheck end,
229 },
165 reportResults = { 230 reportResults = {
166 type = 'toggle', 231 type = 'toggle',
167 name = L["Report results"], 232 order = 12,
168 desc = L["Report the results after finishing"], 233 width = 'full',
234 name = L["Report buff checks"],
235 desc = L["Report flask/food check results"],
169 set = function(o,v,...) self.db.profile.reportResults = v end, 236 set = function(o,v,...) self.db.profile.reportResults = v end,
170 get = function() return self.db.profile.reportResults end, 237 get = function() return self.db.profile.reportResults end,
171 }, 238 },
172 reportDestination = { 239 reportDestination = {
173 type = 'select', 240 type = 'select',
241 order = 13,
174 style = "dropdown", 242 style = "dropdown",
175 name = L["Report Destination"], 243 name = L["Report Destination"],
176 desc = L["Report the results to the following channel"], 244 desc = L["Report the results to the following channel"],
177 values = { 245 values = {
178 ["OFFICER"] = L["Officer"], 246 ["OFFICER"] = L["Officer"],
181 ["GUILD"] = L["Guild"], 249 ["GUILD"] = L["Guild"],
182 ["SELF"] = L["Self"], 250 ["SELF"] = L["Self"],
183 }, 251 },
184 set = function(o,v,...) self.db.profile.reportDestination = v end, 252 set = function(o,v,...) self.db.profile.reportDestination = v end,
185 get = function() return self.db.profile.reportDestination end, 253 get = function() return self.db.profile.reportDestination end,
186 },
187 manualCheckOnly = {
188 type = 'toggle',
189 name = L["Manual checks only"],
190 desc = L["Only perform buff checks if initiated manually (via /icu check)"],
191 set = function(o,v,...) self.db.profile.manualCheckOnly = v; self:refreshConfig() end,
192 get = function() return self.db.profile.manualCheckOnly end,
193 },
194 checkAfterFinish = {
195 type = 'toggle',
196 name = L["Check after readycheck"],
197 desc = L["Don't check buffs until ready check has finished (or timed out)"],
198 set = function(o,v,...) self.db.profile.checkAfterFinish = v end,
199 get = function() return self.db.profile.checkAfterFinish end,
200 }, 254 },
201 }, 255 },
202 }, 256 },
203 messages = { 257 messages = {
204 name = L["Messages"], 258 name = L["Messages"],
233 zones = { 287 zones = {
234 name = L["Disabled Zones"], 288 name = L["Disabled Zones"],
235 type = 'group', 289 type = 'group',
236 set = function(i,v) 290 set = function(i,v)
237 self.db.profile.disabledZones[i[#i]] = v; 291 self.db.profile.disabledZones[i[#i]] = v;
238 --@debug@
239 print("Enabling/Disabling Zone",i[#i],v,#self.db.profile.disabledZones);
240 --@end-debug@
241 end, 292 end,
242 get = function(i) 293 get = function(i)
243 return self.db.profile.disabledZones[i[#i]]; 294 return self.db.profile.disabledZones[i[#i]];
244 end, 295 end,
245 args = { 296 args = {
249 width = 'full', 300 width = 'full',
250 order = 0, 301 order = 0,
251 }, 302 },
252 breakOne = { 303 breakOne = {
253 type = 'description', 304 type = 'description',
254 name = '', 305 fontSize = 'large',
306 name = ' ',
255 order = 1, 307 order = 1,
256 width = 'full', 308 width = 'full',
257 }, 309 },
258 enableAllZones = { 310 enableAllZones = {
259 type = 'toggle', 311 type = 'toggle',
269 end, 321 end,
270 get = function (i) return self.db.profile.enableAllZones end, 322 get = function (i) return self.db.profile.enableAllZones end,
271 }, 323 },
272 breakTwo = { 324 breakTwo = {
273 type = 'description', 325 type = 'description',
274 name = '', 326 fontSize = 'large',
327 name = ' ',
275 order = 3, 328 order = 3,
276 width = 'full', 329 width = 'full',
277 }, 330 },
278 bwd = { 331 bwd = {
279 type = 'toggle', 332 type = 'toggle',
360 end 413 end
361 end 414 end
362 415
363 end 416 end
364 417
365 if self.db.profile.reportResults and self.db.profile.reportDestination ~= "SELF" then 418 -- Announce the report if inspectRaid was by a slash command instead of ready check event
366 SendChatMessage("---- "..L["ICU"].." "..L["Report"].." ----",self.db.profile.reportDestination,nil,nil); 419 if not automatic then
367 end 420 self:announceReport(false);
368 421 end
369 if self.db.profile.reportResults then 422 end
370 if #noFlask > 0 and self.db.profile.checkFlask then 423
371 local reportFlaskMessage = L["Missing Flask"]..": " .. table.concat(noFlask, ", "); 424 function icu:announceReport(automatic)
425 SendChatMessage("---- "..L["ICU"].." "..L["Report"].." ----",self.db.profile.reportDestination,nil,nil);
426
427 -- Check flask
428 if #noFlask > 0 and self.db.profile.checkFlask then
429 local reportFlaskMessage = L["Missing Flask"]..": " .. table.concat(noFlask, ", ");
430
431 if self.db.profile.reportDestination == "SELF" then
432 DEFAULT_CHAT_FRAME:AddMessage(reportFlaskMessage);
433 else
434 SendChatMessage(reportFlaskMessage,self.db.profile.reportDestination,nil,nil);
435 end
436 elseif self.db.profile.checkFlask then -- Nobody is missing a flask
437 if self.db.profile.reportDestination == "SELF" then
438 DEFAULT_CHAT_FRAME:AddMessage(L["Nobody is missing a proper flask."]);
439 else
440 SendChatMessage(L["Nobody is missing a proper flask."],self.db.profile.reportDestination,nil,nil);
441 end
442 end
443
444 -- Check food
445 if #noFood > 0 and self.db.profile.checkFood then
446 local reportFoodMessage = L["Missing Food"]..": " .. table.concat(noFood, ", ");
447
448 if self.db.profile.reportDestination == "SELF" then
449 DEFAULT_CHAT_FRAME:AddMessage(reportFoodMessage);
450 else
451 SendChatMessage(reportFoodMessage,self.db.profile.reportDestination,nil,nil);
452 end
453 elseif self.db.profile.checkFood then -- Nobody is missing a food buff
454 if self.db.profile.reportDestination == "SELF" then
455 DEFAULT_CHAT_FRAME:AddMessage(L["Nobody is missing a proper food buff."]);
456 else
457 SendChatMessage(L["Nobody is missing a proper food buff."],self.db.profile.reportDestination,nil,nil);
458 end
459 end
460
461 -- Check ready
462 if automatic and self.db.profile.announceReadyCheck then -- Check was initialized by ready check event
463 if (#notReady > 0) or (#notReadyAFK > 0) then
464 local reportNotReady = L["Not Ready"]..": " .. table.concat(notReady, ", ") .. (#notReadyAFK > 0 and #notReady > 0 and ", " or "") .. table.concat(notReadyAFK, ", ");
372 465
373 if self.db.profile.reportDestination == "SELF" then 466 if self.db.profile.reportDestination == "SELF" then
374 DEFAULT_CHAT_FRAME:AddMessage(reportFlaskMessage); 467 DEFAULT_CHAT_FRAME:AddMessage(reportNotReady);
375 else 468 else
376 SendChatMessage(reportFlaskMessage,self.db.profile.reportDestination,nil,nil); 469 SendChatMessage(reportNotReady,self.db.profile.reportDestination,nil,nil);
377 end 470 end
378 elseif self.db.profile.checkFlask then -- Nobody is missing a flask 471 else -- Everyone is ready
379 if self.db.profile.reportDestination == "SELF" then 472 if self.db.profile.reportDestination == "SELF" then
380 DEFAULT_CHAT_FRAME:AddMessage(L["Nobody is missing a proper flask."]); 473 DEFAULT_CHAT_FRAME:AddMessage(L["Everyone is ready."]);
381 else 474 else
382 SendChatMessage(L["Nobody is missing a proper flask."],self.db.profile.reportDestination,nil,nil); 475 SendChatMessage(L["Everyone is ready."],self.db.profile.reportDestination,nil,nil);
383 end 476 end
384 end 477 end
385 478 end
386 if #noFood > 0 and self.db.profile.checkFood then 479
387 local reportFoodMessage = L["Missing Food"]..": " .. table.concat(noFood, ", "); 480 self:wipeTables();
388
389 if self.db.profile.reportDestination == "SELF" then
390 DEFAULT_CHAT_FRAME:AddMessage(reportFoodMessage);
391 else
392 SendChatMessage(reportFoodMessage,self.db.profile.reportDestination,nil,nil);
393 end
394 elseif self.db.profile.checkFood then -- Nobody is missing a food buff
395 if self.db.profile.reportDestination == "SELF" then
396 DEFAULT_CHAT_FRAME:AddMessage(L["Nobody is missing a proper food buff."]);
397 else
398 SendChatMessage(L["Nobody is missing a proper food buff."],self.db.profile.reportDestination,nil,nil);
399 end
400 end
401
402 end
403
404 noFlask, noFood, hasLowDuration = {},{},{};
405 end 481 end
406 482
407 function icu:validateBuffs(playerIndex) 483 function icu:validateBuffs(playerIndex)
408 local i = 1; 484 local i = 1;
409 local hasFood, hasFlask, hasLowDuration = false, false, false; 485 local hasFood, hasFlask, hasLowDuration = false, false, false;
435 end 511 end
436 512
437 return hasFood, hasFlask, hasLowDuration; 513 return hasFood, hasFlask, hasLowDuration;
438 end 514 end
439 515
440 function icu:READY_CHECK() 516 function icu:READY_CHECK(event,requester)
441 --print("Ready check init!"); 517 --print("Ready check init!");
442 if self.db.profile.manualCheckOnly then 518 if self.db.profile.manualCheckOnly then
443 icu:UnregisterEvent("READY_CHECK"); 519 icu:UnregisterEvent("READY_CHECK");
444 return true; 520 return true;
445 end 521 end
446 522
447 if not self.db.profile.checkAfterFinish then 523 responders[#responders+1] = requester;
524
525 if not self.db.profile.checkAfterFinish and GetNumRaidMembers() then
448 self:inspectRaid(nil,true); 526 self:inspectRaid(nil,true);
449 else 527 else
450 self:ScheduleTimer("READY_CHECK_FINISHED", 30); 528 self:ScheduleTimer("READY_CHECK_FINISHED", 30);
451 self:RegisterEvent("READY_CHECK_FINISHED"); 529 self:RegisterEvent("READY_CHECK_FINISHED");
452 end 530 end
453 end 531 end
454 532
533 function icu:wipeTables()
534 -- Wipe tables
535 wipe(noFlask);
536 wipe(noFood);
537 wipe(hasLowDuration);
538 wipe(notReady);
539 wipe(notReadyAFK);
540 wipe(responders);
541 end
542
455 function icu:READY_CHECK_FINISHED() 543 function icu:READY_CHECK_FINISHED()
456 --print("Ready check finish!"); 544 --print("Ready check finish!");
457 self:UnregisterEvent("READY_CHECK_FINISHED"); 545 self:UnregisterEvent("READY_CHECK_FINISHED");
458 self:CancelAllTimers(); 546 self:CancelAllTimers();
459 self:inspectRaid(nil,true); 547
548 -- Not in a raid group
549 if GetNumRaidMembers() then
550 self:inspectRaid(nil,true);
551
552 if self.db.profile.announceReadyCheck then
553 self:confirmReady();
554 end
555
556 self:announceReport(true);
557 end
558 end
559
560 function icu:READY_CHECK_CONFIRM(event,unit,status)
561 local raider = UnitName(unit);
562 -- Seeing we only check in raids, and this event fires twice for unites in your subgroup
563 -- Such as Raid1, and Party1 == Same unit
564 -- Dont parse the party event
565 if string.match(unit,"party") then
566 return true;
567 end
568
569 -- Raider is NOT afk, but might not be ready
570 responders[#responders+1] = raider;
571
572 -- 1 ready, 0 not ready
573 if not status then
574 notReady[#notReady+1] = raider;
575 end
576 end
577
578 function icu:confirmReady()
579 local numRaiders, matchFound = GetNumRaidMembers(), false;
580
581 --@debug@
582 print(#responders);
583 --@end-debug@
584
585 if #responders < numRaiders then
586 for i = 1, numRaiders do
587 matchFound = false;
588
589 -- Get raider name
590 local raider = GetRaidRosterInfo(i);
591
592 --@debug@
593 print(raider);
594 --@end-debug@
595
596 for i = 1, #responders do
597 print("Iterating through responders ...");
598 print(responders[i],raider);
599 if responders[i] == raider then
600 --@debug@
601 print(responders[i],raider);
602 --@end-debug@
603 matchFound = true;
604 break;
605 end
606 end
607
608 if not matchFound and raider then
609 --@debug@
610 print("Tag following raider as AFK: ",raider,matchFound);
611 --@end-debug@
612 notReadyAFK[#notReadyAFK+1] = raider .. " (AFK)";
613 elseif not raider then -- GetRaidRosterInfo did not return a proper name, out of bounds??
614 print("Something is wrong ...");
615 else
616 --@debug@
617 print(i,raider);
618 --@end-debug@
619 end
620 end
621 end
460 end 622 end
461 623
462 function icu:getDB() 624 function icu:getDB()
463 return self.db; 625 return self.db;
464 end 626 end
466 local function filterChat(self, event, msg) 628 local function filterChat(self, event, msg)
467 local db = icu:getDB(); 629 local db = icu:getDB();
468 if msg == db.profile.noFoodMessage or msg == db.profile.noFlaskMessage or msg == db.profile.lowFlaskDurationMessage or msg == (L["ICU"]..": "..db.profile.noFoodMessage) or msg == (L["ICU"]..": "..db.profile.noFlaskMessage) or msg == (L["ICU"]..": "..db.profile.lowFlaskDurationMessage) then return true end 630 if msg == db.profile.noFoodMessage or msg == db.profile.noFlaskMessage or msg == db.profile.lowFlaskDurationMessage or msg == (L["ICU"]..": "..db.profile.noFoodMessage) or msg == (L["ICU"]..": "..db.profile.noFlaskMessage) or msg == (L["ICU"]..": "..db.profile.lowFlaskDurationMessage) then return true end
469 end 631 end
470 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_ICU_INFORM", filterChat) 632 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_ICU_INFORM", filterChat)
471
472 icu:RegisterEvent("READY_CHECK");
473 633
474 --@do-not-package@ 634 --@do-not-package@
475 function icu:test(cond) 635 function icu:test(cond)
476 if true and not cond then 636 if true and not cond then
477 print("First.") 637 print("First.")