--
--	TwinEmps by Tandanu v1.0
--	modivied by Nitram to v1.1 with bug explode
--

LVBM.AddOns.TwinEmps = {
	["Name"] = LVBM_TWINEMPS_NAME,
	["Abbreviation1"] = "twins",
	["Abbreviation2"] = "twinemp",
	["Abbreviation3"] = "twin",
	["Version"] = "1.1",
	["Author"] = "La Vendetta|Tandanu",
	["Description"] = LVBM_TWINEMPS_DESCRIPTION,
	["Instance"] = LVBM_AQ40,
	["GUITab"] = LVBMGUI_TAB_AQ40,
	["Sort"] = 6,
	["Options"] = {
		["Enabled"] = true,
		["Announce"] = false,
	},
	["InCombat"] = false,
	["Events"] = {
		["CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE"] = true,
		["CHAT_MSG_SPELL_PERIODIC_CREATURE_BUFFS"] = true,
		["PLAYER_REGEN_DISABLED"] = true,
	},
	
	["OnEvent"] = function(event, arg1)	
		if event == "PLAYER_REGEN_DISABLED" and GetRealZoneText() == LVBM_AQ40 and not LVBM.AddOns.TwinEmps.InCombat then
			if LVBM.UnitExists(LVBM_TWINEMPS_VEKNILASH) then
				LVBM.Schedule(10, "LVBM.AddOns.TwinEmps.OnEvent", "ConfirmCombat");
			end
		elseif ( event == "CHAT_MSG_SPELL_PERIODIC_CREATURE_BUFFS" and string.find(arg1, LVBM_TWINEMPS_EXPLODE_EXPR) ) then
			LVBM.AddSpecialWarning(LVBM_TWINEMPS_EXPLODE_ANNOUNCE);

		elseif event == "ConfirmCombat" then		
			if LVBM.DetectCombat(LVBM_TWINEMPS_VEKNILASH) then
				LVBM.AddOns.TwinEmps.InCombat = true;
				LVBM.Schedule(290, "LVBM.AddOns.TwinEmps.OnEvent", "EnrageWarning", 10)
				LVBM.Schedule(590, "LVBM.AddOns.TwinEmps.OnEvent", "EnrageWarning", 5)
				LVBM.Schedule(830, "LVBM.AddOns.TwinEmps.OnEvent", "EnrageWarning", 1)
				LVBM.Schedule(860, "LVBM.AddOns.TwinEmps.OnEvent", "EnrageWarning", 0.5)
				LVBM.StartStatusBarTimer(890, "Enrage");
				
				LVBM.StartStatusBarTimer(20, "Teleport");
				LVBM.Schedule(10, "LVBM.AddOns.TwinEmps.OnEvent", "TeleportWarning", 10);
				LVBM.Schedule(15, "LVBM.AddOns.TwinEmps.OnEvent", "TeleportWarning", 5);
			end			
	
		elseif event == "CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE" then -- mob casts a spell
			if (arg1 == LVBM_TWINEMPS_CAST_SPELL_1) or (arg1 == LVBM_TWINEMPS_CAST_SPELL_2) then
				LVBM.Announce(LVBM_TWINEMPS_TELEPORT_ANNOUNCE);
				LVBM.EndStatusBarTimer("Teleport");
				LVBM.StartStatusBarTimer(30, "Teleport");
				LVBM.Schedule(20, "LVBM.AddOns.TwinEmps.OnEvent", "TeleportWarning", 10);
				LVBM.Schedule(25, "LVBM.AddOns.TwinEmps.OnEvent", "TeleportWarning", 5);
			end
		elseif event == "TeleportWarning" then
			if arg1 then
				LVBM.Announce(string.format(LVBM_TWINEMPS_TELEPORT_WARNING, arg1));
			end
		elseif event == "EnrageWarning" then
			if arg1 and arg1 >= 1 then
				LVBM.Announce(string.format(LVBM_TWINEMPS_ENRAGE_WARNING, arg1, LVBM_MIN));
			elseif arg1 == 0.5 then
				LVBM.Announce(string.format(LVBM_TWINEMPS_ENRAGE_WARNING, 30, LVBM_SEC));
			end
		elseif (event == "ConfirmCombatEnd") then
			if (not UnitAffectingCombat("player")) and (not UnitIsDeadOrGhost("player")) then
				LVBM.AddOns.TwinEmps.InCombat = false;
				LVBM.UnSchedule("LVBM.AddOns.TwinEmps.OnEvent");
				LVBM.EndStatusBarTimer("Enrage");
			end
		end
	end,
	["OnUpdate"] = function(elapsed)
		if (LVBM.AddOns.TwinEmps.InCombat) 
		and (not UnitAffectingCombat("player")) 
		and (not UnitIsDeadOrGhost("player")) 
		and (not LVBM.GetScheduleTimeLeft("LVBM.AddOns.TwinEmps.OnEvent", "ConfirmCombatEnd")) then

			LVBM.Schedule(10, "LVBM.AddOns.TwinEmps.OnEvent", "ConfirmCombatEnd");
		end
	end,
	["UpdateInterval"] = 3,
};
