diff 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
line wrap: on
line diff
--- a/ICU.lua	Tue Feb 15 01:23:33 2011 +0100
+++ b/ICU.lua	Fri Feb 18 23:58:20 2011 +0100
@@ -38,6 +38,7 @@
 
 local minFlaskDuration = 10;
 local noFlask, noFood, hasLowDuration = {},{},{};
+local notReady, notReadyAFK, responders = {}, {}, {};
 
 local defaults = {
 	profile = {
@@ -55,6 +56,7 @@
 		lowFlaskDurationMessage = L["Your Flask runs out in less than 10 minutes!"],
 		disabledZones = {},
 		enableAllZones = true,
+		announceReadyCheck = true,
 	}
 }
 
@@ -76,6 +78,16 @@
 	AceConfigDialog:AddToBlizOptions("ICU", "Whispers","ICU","messages")
 	AceConfigDialog:AddToBlizOptions("ICU", "Disabled Zones","ICU","zones")
 	AceConfigDialog:AddToBlizOptions("ICU", "Profiles","ICU","profile")
+	
+	-- Ready check confirm event registration
+	if self.db.profile.announceReadyCheck then
+		self:RegisterEvent("READY_CHECK_CONFIRM");
+	end
+	
+	-- Ready check event registration
+	if not self.db.profile.manualCheckOnly then
+		icu:RegisterEvent("READY_CHECK");
+	end
 end
 
 function icu:refreshConfig()
@@ -87,6 +99,12 @@
 		icu:RegisterEvent("READY_CHECK");
 	end
 	
+	if not self.db.profile.announceReadyCheck then
+		icu:UnregisterEvent("READY_CHECK_CONFIRM");
+	else
+		icu:RegisterEvent("READY_CHECK_CONFIRM");
+	end
+	
 	--print("ICU: Config refreshed!");
 end
 
@@ -127,8 +145,18 @@
 				name = L["General Settings"],
 				type = 'group',
 				args = {
+					advertiseICU = {
+						type = 'toggle',
+						order = 1,
+						width = 'full',
+						name = L["Advertise ICU"],
+						desc = L["Let everyone know you are using ICU! Prefixes whispers and reports"],
+						set = function(o,v,...) self.db.profile.advertiseICU = v end,
+						get = function() return self.db.profile.advertiseICU end,
+					},
 					checkFlask = {
 						type = 'toggle',
+						order = 2,
 						name = L["Check for Flask"],
 						desc = L["Checks the raid for valid flasks and reports results"],
 						set = function(o,v,...) self.db.profile.checkFlask = v end,
@@ -136,6 +164,7 @@
 					},
 					checkLowFlaskDuration = {
 						type = 'toggle',
+						order = 3,
 						name = L["Flask expiration"],
 						desc = L["Check for soon to expire flask buffs"],
 						set = function(o,v,...) self.db.profile.checkLowFlaskDuration = v end,
@@ -143,34 +172,73 @@
 					},
 					checkFood = {
 						type = 'toggle',
+						order = 4,
 						name = L["Check for Food"],
 						desc = L["Checks the raid for valid food buffs and reports results"],
 						set = function(o,v,...) self.db.profile.checkFood = v end,
 						get = function() return self.db.profile.checkFood end,
 					},
-					advertiseICU = {
-						type = 'toggle',
-						name = L["Advertise ICU"],
-						desc = L["Let everyone know you are using ICU! Prefixes whispers and reports"],
-						set = function(o,v,...) self.db.profile.advertiseICU = v end,
-						get = function() return self.db.profile.advertiseICU end,
-					},
 					remindRaider = {
 						type = 'toggle',
+						order = 5,
+						width = 'full',
 						name = L["Raid reminder"],
 						desc = L["Whisper the raider lacking (or soon to expire, if enabled) food/flask buff a reminder"],
 						set = function(o,v,...) self.db.profile.remindRaider = v end,
 						get = function() return self.db.profile.remindRaider end,
 					},
+					breakOne = {
+						type = 'description',
+						fontSize = 'large',
+						name = ' ',
+						order = 7,
+						width = 'full',
+					},
+					manualCheckOnly = {
+						type = 'toggle',
+						order = 8,
+						name = L["Manual checks only"],
+						desc = L["Only perform buff checks if initiated manually (via /icu check)"],
+						set = function(o,v,...) self.db.profile.manualCheckOnly = v; self:refreshConfig() end,
+						get = function() return self.db.profile.manualCheckOnly end,
+					},
+					checkAfterFinish = {
+						type = 'toggle',
+						order = 9,
+						width = 'full',
+						name = L["Inspect AFTER ready check finishes"],
+						desc = L["Don't check buffs until the ready check has finished (or timed out)"],
+						set = function(o,v,...) self.db.profile.checkAfterFinish = v end,
+						get = function() return self.db.profile.checkAfterFinish end,
+					},
+					breakTwo = {
+						type = 'description',
+						fontSize = 'large',
+						name = ' ',
+						order = 10,
+						width = 'full',
+					},
+					announceReadyCheck = {
+						type = 'toggle',
+						order = 11,
+						name = L["Report ready checks"],
+						desc = L["Report the results of ready checks"],
+						width = 'double',
+						set = function(o,v,...) self.db.profile.announceReadyCheck = v; self:refreshConfig() end,
+						get = function() return self.db.profile.announceReadyCheck end,
+					},
 					reportResults = {
 						type = 'toggle',
-						name = L["Report results"],
-						desc = L["Report the results after finishing"],
+						order = 12,
+						width = 'full',
+						name = L["Report buff checks"],
+						desc = L["Report flask/food check results"],
 						set = function(o,v,...) self.db.profile.reportResults = v end,
 						get = function() return self.db.profile.reportResults end,
 					},
 					reportDestination = {
 						type = 'select',
+						order = 13,
 						style = "dropdown",
 						name = L["Report Destination"],
 						desc = L["Report the results to the following channel"],
@@ -184,20 +252,6 @@
 						set = function(o,v,...) self.db.profile.reportDestination = v end,
 						get = function() return self.db.profile.reportDestination end,
 					},
-					manualCheckOnly = {
-						type = 'toggle',
-						name = L["Manual checks only"],
-						desc = L["Only perform buff checks if initiated manually (via /icu check)"],
-						set = function(o,v,...) self.db.profile.manualCheckOnly = v; self:refreshConfig() end,
-						get = function() return self.db.profile.manualCheckOnly end,
-					},
-					checkAfterFinish = {
-						type = 'toggle',
-						name = L["Check after readycheck"],
-						desc = L["Don't check buffs until ready check has finished (or timed out)"],
-						set = function(o,v,...) self.db.profile.checkAfterFinish = v end,
-						get = function() return self.db.profile.checkAfterFinish end,
-					},
 				},
 			},
 			messages = {
@@ -235,9 +289,6 @@
 				type = 'group',
 				set = 	function(i,v)
 							self.db.profile.disabledZones[i[#i]] = v;
-							--@debug@
-							print("Enabling/Disabling Zone",i[#i],v,#self.db.profile.disabledZones);
-							--@end-debug@
 						end,
 				get = 	function(i)
 							return self.db.profile.disabledZones[i[#i]];
@@ -251,7 +302,8 @@
 					},
 					breakOne = {
 						type = 'description',
-						name = '',
+						fontSize = 'large',
+						name = ' ',
 						order = 1,
 						width = 'full',
 					},
@@ -271,7 +323,8 @@
 					},
 					breakTwo = {
 						type = 'description',
-						name = '',
+						fontSize = 'large',
+						name = ' ',
 						order = 3,
 						width = 'full',
 					},
@@ -362,46 +415,69 @@
 		
 	end
 	
-	if self.db.profile.reportResults and self.db.profile.reportDestination ~= "SELF" then
-		SendChatMessage("---- "..L["ICU"].." "..L["Report"].." ----",self.db.profile.reportDestination,nil,nil);
+	-- Announce the report if inspectRaid was by a slash command instead of ready check event
+	if not automatic then
+		self:announceReport(false);
+	end
+end
+
+function icu:announceReport(automatic)
+	SendChatMessage("---- "..L["ICU"].." "..L["Report"].." ----",self.db.profile.reportDestination,nil,nil);
+	
+	-- Check flask
+	if #noFlask > 0 and self.db.profile.checkFlask then
+		local reportFlaskMessage = L["Missing Flask"]..": " .. table.concat(noFlask, ", ");
+		
+		if self.db.profile.reportDestination == "SELF" then
+			DEFAULT_CHAT_FRAME:AddMessage(reportFlaskMessage);
+		else
+			SendChatMessage(reportFlaskMessage,self.db.profile.reportDestination,nil,nil);
+		end
+	elseif self.db.profile.checkFlask then	-- Nobody is missing a flask
+		if self.db.profile.reportDestination == "SELF" then
+			DEFAULT_CHAT_FRAME:AddMessage(L["Nobody is missing a proper flask."]);
+		else
+			SendChatMessage(L["Nobody is missing a proper flask."],self.db.profile.reportDestination,nil,nil);
+		end
 	end
 	
-	if self.db.profile.reportResults then
-		if #noFlask > 0 and self.db.profile.checkFlask then
-			local reportFlaskMessage = L["Missing Flask"]..": " .. table.concat(noFlask, ", ");
+	-- Check food
+	if #noFood > 0 and self.db.profile.checkFood then
+		local reportFoodMessage = L["Missing Food"]..": " .. table.concat(noFood, ", ");
+		
+		if self.db.profile.reportDestination == "SELF" then
+			DEFAULT_CHAT_FRAME:AddMessage(reportFoodMessage);
+		else
+			SendChatMessage(reportFoodMessage,self.db.profile.reportDestination,nil,nil);
+		end
+	elseif self.db.profile.checkFood then	-- Nobody is missing a food buff
+		if self.db.profile.reportDestination == "SELF" then
+			DEFAULT_CHAT_FRAME:AddMessage(L["Nobody is missing a proper food buff."]);
+		else
+			SendChatMessage(L["Nobody is missing a proper food buff."],self.db.profile.reportDestination,nil,nil);
+		end
+	end
+	
+	-- Check ready
+	if automatic and self.db.profile.announceReadyCheck then -- Check was initialized by ready check event
+		if (#notReady > 0) or (#notReadyAFK > 0) then
+			local reportNotReady = L["Not Ready"]..": " .. table.concat(notReady, ", ") .. (#notReadyAFK > 0 and #notReady > 0 and ", " or "") .. table.concat(notReadyAFK, ", ");
 			
 			if self.db.profile.reportDestination == "SELF" then
-				DEFAULT_CHAT_FRAME:AddMessage(reportFlaskMessage);
+				DEFAULT_CHAT_FRAME:AddMessage(reportNotReady);
 			else
-				SendChatMessage(reportFlaskMessage,self.db.profile.reportDestination,nil,nil);
+				SendChatMessage(reportNotReady,self.db.profile.reportDestination,nil,nil);
 			end
-		elseif self.db.profile.checkFlask then	-- Nobody is missing a flask
+		else	-- Everyone is ready
 			if self.db.profile.reportDestination == "SELF" then
-				DEFAULT_CHAT_FRAME:AddMessage(L["Nobody is missing a proper flask."]);
+				DEFAULT_CHAT_FRAME:AddMessage(L["Everyone is ready."]);
 			else
-				SendChatMessage(L["Nobody is missing a proper flask."],self.db.profile.reportDestination,nil,nil);
+				SendChatMessage(L["Everyone is ready."],self.db.profile.reportDestination,nil,nil);
 			end
 		end
-		
-		if #noFood > 0 and self.db.profile.checkFood then
-			local reportFoodMessage = L["Missing Food"]..": " .. table.concat(noFood, ", ");
-			
-			if self.db.profile.reportDestination == "SELF" then
-				DEFAULT_CHAT_FRAME:AddMessage(reportFoodMessage);
-			else
-				SendChatMessage(reportFoodMessage,self.db.profile.reportDestination,nil,nil);
-			end
-		elseif self.db.profile.checkFood then	-- Nobody is missing a food buff
-			if self.db.profile.reportDestination == "SELF" then
-				DEFAULT_CHAT_FRAME:AddMessage(L["Nobody is missing a proper food buff."]);
-			else
-				SendChatMessage(L["Nobody is missing a proper food buff."],self.db.profile.reportDestination,nil,nil);
-			end
-		end
-		
 	end
 	
-	noFlask, noFood, hasLowDuration = {},{},{};
+	self:wipeTables();
 end
 
 function icu:validateBuffs(playerIndex)
@@ -437,14 +513,16 @@
 	return hasFood, hasFlask, hasLowDuration;
 end
 
-function icu:READY_CHECK()
+function icu:READY_CHECK(event,requester)
 	--print("Ready check init!");
 	if self.db.profile.manualCheckOnly then
 		icu:UnregisterEvent("READY_CHECK");
 		return true;
 	end
 	
-	if not self.db.profile.checkAfterFinish then
+	responders[#responders+1] = requester;
+	
+	if not self.db.profile.checkAfterFinish and GetNumRaidMembers() then
 		self:inspectRaid(nil,true);
 	else
 		self:ScheduleTimer("READY_CHECK_FINISHED", 30);
@@ -452,11 +530,95 @@
 	end
 end
 
+function icu:wipeTables()
+	-- Wipe tables
+	wipe(noFlask);
+	wipe(noFood);
+	wipe(hasLowDuration);
+	wipe(notReady);
+	wipe(notReadyAFK);
+	wipe(responders);
+end
+
 function icu:READY_CHECK_FINISHED()
 	--print("Ready check finish!");
 	self:UnregisterEvent("READY_CHECK_FINISHED");
 	self:CancelAllTimers();
-	self:inspectRaid(nil,true);
+	
+	-- Not in a raid group
+	if GetNumRaidMembers() then
+		self:inspectRaid(nil,true);
+		
+		if self.db.profile.announceReadyCheck then
+			self:confirmReady();
+		end
+		
+		self:announceReport(true);
+	end
+end
+
+function icu:READY_CHECK_CONFIRM(event,unit,status)
+	local raider = UnitName(unit);
+	-- Seeing we only check in raids, and this event fires twice for unites in your subgroup
+	-- Such as Raid1, and Party1 == Same unit
+	-- Dont parse the party event
+	if string.match(unit,"party") then
+		return true;
+	end
+	
+	-- Raider is NOT afk, but might not be ready
+	responders[#responders+1] = raider;
+	
+	-- 1 ready, 0 not ready
+	if not status then
+		notReady[#notReady+1] = raider;
+	end
+end
+
+function icu:confirmReady()
+	local numRaiders, matchFound = GetNumRaidMembers(), false;
+	
+	--@debug@
+	print(#responders);
+	--@end-debug@
+	
+	if #responders < numRaiders then
+		for i = 1, numRaiders do
+			matchFound = false;
+		
+			-- Get raider name
+			local raider = GetRaidRosterInfo(i);
+			
+			--@debug@
+			print(raider);
+			--@end-debug@
+					
+			for i = 1, #responders do
+				print("Iterating through responders ...");
+				print(responders[i],raider);
+				if responders[i] == raider then
+					--@debug@
+					print(responders[i],raider);
+					--@end-debug@
+					matchFound = true;
+					break;
+				end
+			end
+			
+			if not matchFound and raider then
+				--@debug@
+				print("Tag following raider as AFK: ",raider,matchFound);
+				--@end-debug@
+				notReadyAFK[#notReadyAFK+1] = raider .. " (AFK)";
+			elseif not raider then -- GetRaidRosterInfo did not return a proper name, out of bounds??
+				print("Something is wrong ...");
+			else
+				--@debug@
+				print(i,raider);
+				--@end-debug@
+			end
+		end
+	end
 end
 
 function icu:getDB()
@@ -469,8 +631,6 @@
 end
 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_ICU_INFORM", filterChat)
 
-icu:RegisterEvent("READY_CHECK");
-
 --@do-not-package@
 function icu:test(cond)
 	if true and not cond then