LVBM.AddOns.Heigan = {
	["Name"] = LVBM_HTU_NAME,
	["Abbreviation1"] = "Heigan",
	["Abbreviation2"] = "htu",
	["Version"] = "1.0",
	["Author"] = "La Vendetta|Tandanu",
	["Description"] = LVBM_HTU_DESCRIPTION,
	["Instance"] = LVBM_NAXX,
	["GUITab"] = LVBMGUI_TAB_NAXX,
	["Sort"] = 32,
	["Options"] = {
		["Enabled"] = true,
		["Announce"] = false,
	},
	["Teleported"] = false,
	["InCombat"] = false,
	["Events"] = {
		["CHAT_MSG_MONSTER_YELL"] = true,
	},
	["OnEvent"] = function(event, arg1)
		if event == "CHAT_MSG_MONSTER_YELL" then
			if arg1 == LVBM_HTU_YELL_START1 or arg1 == LVBM_HTU_YELL_START2 or arg1 == LVBM_HTU_YELL_START3 then
				LVBM.AddOns.Heigan.OnEvent("TeleportBackWarning", 0);
			end
		elseif event == "TeleportWarning" then
			LVBM.AddOns.Heigan.InCombat = true;
			if arg1 and arg1 > 0 then
				LVBM.Announce(string.format(LVBM_HTU_TELEPORT_WARNING, arg1));
			elseif arg1 == 0 then
				LVBM.Announce(string.format(LVBM_HTU_TELEPORT_BACK_WARNING, 45));
				LVBM.Schedule(20, "LVBM.AddOns.Heigan.OnEvent", "TeleportBackWarning", 25);
				LVBM.Schedule(35, "LVBM.AddOns.Heigan.OnEvent", "TeleportBackWarning", 10);
				LVBM.Schedule(45, "LVBM.AddOns.Heigan.OnEvent", "TeleportBackWarning", 0);
				LVBM.EndStatusBarTimer("Teleport Back");
				LVBM.StartStatusBarTimer(45, "Teleport Back");	
			end
		elseif event == "TeleportBackWarning" then
			LVBM.AddOns.Heigan.InCombat = true;
			if arg1 and arg1 > 0 then
				LVBM.Announce(string.format(LVBM_HTU_TELEPORT_BACK_WARNING, arg1));
			elseif arg1 == 0 then
				LVBM.Announce(string.format(LVBM_HTU_TELEPORT_WARNING, 90));
				LVBM.Schedule(30, "LVBM.AddOns.Heigan.OnEvent", "TeleportWarning", 60);
				LVBM.Schedule(60, "LVBM.AddOns.Heigan.OnEvent", "TeleportWarning", 30);
				LVBM.Schedule(80, "LVBM.AddOns.Heigan.OnEvent", "TeleportWarning", 10);
				LVBM.Schedule(90, "LVBM.AddOns.Heigan.OnEvent", "TeleportWarning", 0);
				LVBM.EndStatusBarTimer("Teleport");
				LVBM.StartStatusBarTimer(90, "Teleport");
			end
		elseif event == "ConfirmCombatEnd" then
			if (not UnitAffectingCombat("player")) and (not UnitIsDeadOrGhost("player")) then
				LVBM.AddOns.Heigan.InCombat = false;
				LVBM.AddOns.Heigan.Teleported = false;
				LVBM.UnSchedule("LVBM.AddOns.Heigan.OnEvent");
				LVBM.EndStatusBarTimer("Teleport");
				LVBM.EndStatusBarTimer("Teleport Back");
			end
		end
	end,
	
	["OnUpdate"] = function(elapsed) 
		if (LVBM.AddOns.Heigan.InCombat) and (not UnitAffectingCombat("player")) and (not UnitIsDeadOrGhost("player")) and (not LVBM.GetScheduleTimeLeft("LVBM.AddOns.Heigan.OnEvent", "ConfirmCombatEnd")) then
			LVBM.Schedule(10, "LVBM.AddOns.Heigan.OnEvent", "ConfirmCombatEnd");
		end
	end,
	["UpdateInterval"] = 3,
};
