--
-- La Vendetta Instructor Razuvious Raid Warning AddOn
-- (c) by Nitram from La Vendetta on DE-Azshara
--
-- DE-INFO:
-- Damit dieses Addon Funktioniert muss beim Pull ein PET oder 
-- ein Spieler in Sichtlinie zu dem Razuvious sein und den
-- Disrupting Shout abbekommen. (einmalig)
-- Dieses Addon gibt den Manaklassen die Möglichkeit ähnlich wie
-- bei Chromagus aus Sicht zu laufen und damit zu überleben.
--
-- EN-INFO:
-- To get this Addon working, a Pet or Player needs to be in 
-- Line of Sight to Razuvious and afflicted by his spell
-- Disrupting Shout.
-- This Addon allows the Mana Classes to be in LOS to 
-- Razuvious and running out at the right Time like Chromagus.

LVBM.AddOns.Razuvious = {
	["Name"] = LVBM_IR_NAME,
	["Abbreviation1"] = "Razu",
	["Abbreviation2"] = "Razuvious",
	["Abbreviation3"] = "ir",
	["Version"] = "1.6",
	["Author"] = "Nitram",
	["Description"] = LVBM_IR_DESCRIPTION,
	["Instance"] = LVBM_NAXX,
	["GUITab"] = LVBMGUI_TAB_NAXX,
	["Sort"] = 21,
	["Options"] = {
		["Enabled"] = true,
		["Announce"] = false,
		["10SecWarning"] = true,
	},
	["Lastshout"] = 0,
	["OnLoop"] = false,
	["InCombat"] = false,
	["DropdownMenu"] = {
		[1] = {
			["variable"] = "LVBM.AddOns.Razuvious.Options['10SecWarning']",
			["text"] = LVBM_IR_SHOW_10SEC_WARNING,
			["func"] = function() LVBM.AddOns.Razuvious.Options["10SecWarning"] = not LVBM.AddOns.Razuvious.Options["10SecWarning"]; end,
		},
	},
	["Events"] = {
		["CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE"] = true,		-- Disrupting Shout on YOU
		["CHAT_MSG_SPELL_CREATURE_VS_PARTY_DAMAGE"] = true,		-- on Party
		["CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE"] = true,		-- on Raid / Pet
		["CHAT_MSG_MONSTER_YELL"] = true,
	},
	
	["OnEvent"] = function(event, arg1)			
		if ( event == "CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE" or 				
			 event == "CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE" or
			 event == "CHAT_MSG_SPELL_CREATURE_VS_PARTY_DAMAGE" ) then
			
			if( string.find(arg1, LVBM_IR_SPELL_1) )then
				if( LVBM.AddOns.Razuvious.Lastshout > 0 and math.floor(GetTime() - LVBM.AddOns.Razuvious.Lastshout) > 0 ) then
					LVBM.AddOns.Razuvious.InCombat = true;
					LVBM.AddMsg(LVBM_IR_TIMER_UPDATED);		-- To see that the Loop is Sync'd to the Shout
					
--					LVBM.AddMsg("Time since last D-Shout : ".. (time() - LVBM.AddOns.Razuvious.Lastshout) );
					LVBM.AddOns.Razuvious.OnEvent("StartNewDShoutTimer");
					LVBM.AddOns.Razuvious.Lastshout = GetTime();
				else
					LVBM.AddOns.Razuvious.OnEvent("StartNewDShoutTimer");
					LVBM.AddOns.Razuvious.Lastshout = GetTime();
				end
			end
		end
			
		if (event == "StartNewDShoutTimer") then
			if (GetTime() - LVBM.AddOns.Razuvious.Lastshout) < 2  then return true; end	-- Don't need Spam
				
			LVBM.UnSchedule("LVBM.AddOns.Razuvious.OnEvent");			-- Don't need the Loop & Warnings
			
			LVBM.Announce(string.format(LVBM_IR_SHOUT_WARNING, 25));		-- Callout Warning
			LVBM.StartStatusBarTimer(25, "Disrupting Shout");
			LVBM.Schedule(15, "LVBM.AddOns.Razuvious.OnEvent", "DShout10SecWarning");			-- Schedule Warnings
			LVBM.Schedule(20, "LVBM.AddOns.Razuvious.OnEvent", "DShout5SecWarning");
			LVBM.Schedule(22, "LVBM.AddOns.Razuvious.OnEvent", "DShout3SecWarning");
				
			LVBM.AddOns.Razuvious.OnLoop = true;
			LVBM.AddOns.Razuvious.InCombat = true;
		elseif (event == "CHAT_MSG_MONSTER_YELL") then
			if (arg1 == LVBM_IR_YELL_1) or (arg1 == LVBM_IR_YELL_2) or (arg1 == LVBM_IR_YELL_3) or (arg1 == LVBM_IR_YELL_4) then
				LVBM.AddOns.Razuvious.OnEvent("StartNewDShoutTimer");
				LVBM.AddOns.Razuvious.Lastshout = GetTime();
			end
		elseif (event == "DShout10SecWarning") and LVBM.AddOns.Razuvious.Options["10SecWarning"] then
			LVBM.Announce(string.format(LVBM_IR_SHOUT_WARNING, 10));
			
		elseif (event == "DShout5SecWarning") then
			LVBM.Announce(string.format(LVBM_IR_SHOUT_WARNING, 5));
			
		elseif (event == "DShout3SecWarning") then
--			LVBM.Announce("*** Disrupting Shout in 3 Sec ***", "RAID_WARNING");
			
			LVBM.Schedule(4, "LVBM.AddOns.Razuvious.OnEvent", "StartNewDShoutTimer");			-- Schedule Loop
		elseif (event == "ConfirmCombatEnd") then
			if (not UnitAffectingCombat("player")) and (not UnitIsDeadOrGhost("player")) then			
				LVBM.UnSchedule("LVBM.AddOns.Razuvious.OnEvent");
				LVBM.EndStatusBarTimer("Disrupting Shout");
				LVBM.AddOns.Razuvious.InCombat = false;
			end
		end
	end,
	
	["OnUpdate"] = function(elapsed) 
		if (LVBM.AddOns.Razuvious.InCombat) and (not UnitAffectingCombat("player")) and (not UnitIsDeadOrGhost("player")) and (not LVBM.GetScheduleTimeLeft("LVBM.AddOns.Razuvious.OnEvent", "ConfirmCombatEnd")) then
			LVBM.Schedule(10, "LVBM.AddOns.Razuvious.OnEvent", "ConfirmCombatEnd");
		end
	end,
	["UpdateInterval"] = 3,	
}
