LVBM.AddOns.Thaddius = {
	["Name"] = LVBM_THADDIUS_NAME,
	["Abbreviation1"] = "thad",
	["Abbreviation2"] = "thadd",
	["Version"] = "1.0",
	["Author"] = "La Vendetta|Tandanu",
	["Description"] = LVBM_THADDIUS_DESCRIPTION,
	["Instance"] = LVBM_NAXX,
	["GUITab"] = LVBMGUI_TAB_NAXX,
	["Sort"] = 44,
	["Options"] = {
		["Enabled"] = true,
		["Announce"] = false,
		["WarnWhenNotChanged"] = false,
		["AltStrat"] = false,
	},
	["oldCharge"] = "",
	["InCombat"] = false,
	["LastPol"] = 0,
	["TeslaCoil"] = false,
	["DropdownMenu"] = {
		[1] = {
			["variable"] = "LVBM.AddOns.Thaddius.Options.WarnWhenNotChanged",
			["text"] = LVBM_THADDIUS_WARN_NOT_CHANGED,
			["func"] = function() LVBM.AddOns.Thaddius.Options.WarnWhenNotChanged = not LVBM.AddOns.Thaddius.Options.WarnWhenNotChanged; end,
		},
		[2] = {
			["variable"] = "LVBM.AddOns.Thaddius.Options.AltStrat",
			["text"] = LVBM_THADDIUS_ALT_STRATEGY,
			["func"] = function() LVBM.AddOns.Thaddius.Options.AltStrat = not LVBM.AddOns.Thaddius.Options.AltStrat; end,
		},
	},
	["Events"] = {
		["CHAT_MSG_MONSTER_YELL"] = true,
		["CHAT_MSG_MONSTER_EMOTE"] = true,
		["CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE"] = true,
		["PLAYER_AURAS_CHANGED"] = true,
	},
	["OnEvent"] = function(event, arg1)
		if (event == "CHAT_MSG_MONSTER_YELL") then
			if (arg1 == LVBM_THADDIUS_YELL_START1) or (arg1 == LVBM_THADDIUS_YELL_START2) or (arg1 == LVBM_THADDIUS_YELL_START3) then
				LVBM.AddOns.Thaddius.TeslaCoil = false;
				LVBM.Announce(string.format(LVBM_THADDIUS_ENRAGE_WARNING, 5, LVBM_MINUTES));
				LVBM.Schedule(120, "LVBM.AddOns.Thaddius.OnEvent", "EnrageWarning", 180);
				LVBM.Schedule(180, "LVBM.AddOns.Thaddius.OnEvent", "EnrageWarning", 120);
				LVBM.Schedule(240, "LVBM.AddOns.Thaddius.OnEvent", "EnrageWarning", 60);
				LVBM.Schedule(270, "LVBM.AddOns.Thaddius.OnEvent", "EnrageWarning", 30);
				LVBM.Schedule(290, "LVBM.AddOns.Thaddius.OnEvent", "EnrageWarning", 10);
				LVBM.StartStatusBarTimer(300, "Enrage");
				LVBM.AddOns.Thaddius.InCombat = true;
			elseif (arg1 == LVBM_THADDIUS_YELL_POL) then
				LVBM.Announce(LVBM_THADDIUS_POL_SHIFT);
				LVBM.EndStatusBarTimer("Polarity Shift");
				LVBM.StartStatusBarTimer(30, "Polarity Shift");
			end
		elseif (event == "CHAT_MSG_MONSTER_EMOTE") then
			if arg1 == LVBM_THADDIUS_TESLA_EMOTE and not LVBM.AddOns.Thaddius.TeslaCoil then --and arg2 == LVBM_THADDIUS_TESLA_COIL then
				 LVBM.AddOns.Thaddius.TeslaCoil = true;
				LVBM.Announce(LVBM_THADDIUS_PHASE_2_SOON);
				LVBM.StartStatusBarTimer(5, "Phase 2");
			end
		elseif (event == "CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE") then
			if arg1 == LVBM_THADDIUS_CAST_POL then
				LVBM.Announce(string.format(LVBM_THADDIUS_POL_WARNING, 3));
				LVBM.EndStatusBarTimer("Polarity Shift");
				LVBM.StartStatusBarTimer(3, "Polarity Shift cast");
			end
		elseif (event == "PLAYER_AURAS_CHANGED") and GetTime() > (LVBM.AddOns.Thaddius.LastPol + 26) then
			local charge, i;
			charge = "";
			i = 1;
			while UnitDebuff("player", i) do
				local texture, stacks;
				texture, stacks = UnitDebuff("player", i)
				if texture == "Interface\\Icons\\Spell_ChargeNegative" then
					if stacks > 1 then
						return; 
					end					
					charge = LVBM_THADDIUS_NEGATIVE;
				elseif texture == "Interface\\Icons\\Spell_ChargePositive" then
					if stacks > 1 then
						return; 
					end					
					charge = LVBM_THADDIUS_POSITIVE;
				end
				i = i + 1;
			end
			if charge == "" then
				return;
			end
			LVBM.AddOns.Thaddius.LastPol = GetTime();
			if LVBM.AddOns.Thaddius.Options.AltStrat then
				if charge ~= LVBM.AddOns.Thaddius.oldCharge then
					LVBM.AddSpecialWarning(LVBM_THADDIUS_RIGHT, true, true);
				else
					LVBM.AddSpecialWarning(LVBM_THADDIUS_LEFT, true, true);
				end
				LVBM.AddOns.Thaddius.oldCharge = charge;
			else
				if charge ~= LVBM.AddOns.Thaddius.oldCharge then
					LVBM.AddSpecialWarning(string.format(LVBM_THADDIUS_CHARGE_CHANGED, charge), true, true);
				elseif LVBM.AddOns.Thaddius.Options.WarnWhenNotChanged then
					LVBM.AddSpecialWarning(LVBM_THADDIUS_CHARGE_NOT_CHANGED, true, true);
				end
				LVBM.AddOns.Thaddius.oldCharge = charge;				
			end
		elseif (event == "EnrageWarning") then
			if arg1 == 180 then
				LVBM.Announce(string.format(LVBM_THADDIUS_ENRAGE_WARNING, 3, LVBM_MINUTES));
			elseif arg1 == 120 then
				LVBM.Announce(string.format(LVBM_THADDIUS_ENRAGE_WARNING, 2, LVBM_MINUTES));
			elseif arg1 == 60 then
				LVBM.Announce(string.format(LVBM_THADDIUS_ENRAGE_WARNING, 1, LVBM_MINUTE));
			elseif arg1 == 30 then
				LVBM.Announce(string.format(LVBM_THADDIUS_ENRAGE_WARNING, 30, LVBM_SECONDS));
			elseif arg1 == 10 then
				LVBM.Announce(string.format(LVBM_THADDIUS_ENRAGE_WARNING, 10, LVBM_SECONDS));
			end
		elseif event == "ConfirmCombatEnd" then
			if not UnitAffectingCombat("player") and not UnitIsDeadOrGhost("player") then			
				LVBM.UnSchedule("LVBM.AddOns.Thaddius.OnEvent");
				LVBM.EndStatusBarTimer("Enrage");
				LVBM.EndStatusBarTimer("Polarity Shift");
				LVBM.AddOns.Thaddius.InCombat = false;				
				LVBM.AddOns.Thaddius.oldCharge = "";
			end
		end
	end,
	["OnUpdate"] = function(elapsed) 
		if (LVBM.AddOns.Thaddius.InCombat) and (not UnitAffectingCombat("player")) and (not UnitIsDeadOrGhost("player")) and (not LVBM.GetScheduleTimeLeft("LVBM.AddOns.Thaddius.OnEvent", "ConfirmCombatEnd")) then
			LVBM.Schedule(7, "LVBM.AddOns.Thaddius.OnEvent", "ConfirmCombatEnd");
		end
	end,
	["UpdateInterval"] = 3,
};
