function createQuestCollectHeroes()
	TributeJingleAction = function()
		XGUIEng.ShowWidget("TradeWindow",0)
		return false
	end
	Logic.AddQuest(1, 3, MAINQUEST_OPEN, "Versammeln", "Versammelt eure Helden im Vorhof", 1)
	StartSimpleJob("heroescollector")
end

function heroescollector()
	if IsNear("dario","HeroCollectingPoint",500) then
		if IsNear("ari","HeroCollectingPoint",500) then
			if IsNear("salim","HeroCollectingPoint",500) then
				if IsNear("pilgrim","HeroCollectingPoint",500) then
					if IsNear("erec","HeroCollectingPoint",500) then
						if IsNear("helias","HeroCollectingPoint",500) then
							ReplaceEntity("InnerGate2", Entities.XD_DarkWallStraightGate_Closed)
							CreateTributDecision()
							return true
						end
					end
				end
			end
		end
	end
	return false
end

function CreateTributDecision()
	Message("Schaut in euer Tribut-Menü.")
	local job1 = {}
	
	job1.Tribute = 005
	Logic.AddTribute(	GetHumanPlayer(),
						job1.Tribute,
						0,
						0,
						"Ich will die Karte @color:255,0,0 normal @color:255,255,255 zu Ende spielen.",
						ResourceType.Gold,
						0)
	job1.Callback = ErsteEntscheidung
	SetupTributePaid(job1)
	local job2 = {}
	job2.Tribute = 006
	Logic.AddTribute(	GetHumanPlayer(),
						job2.Tribute,
						0,
						0,
						"Ich will die Karte @color:255,0,0 erweitert @color:255,255,255 zu Ende spielen. @cr Es könnte potentiell zu Lags/niedrigen FPS kommen.",
						ResourceType.Gold,
						0)
	job2.Callback = zweiteEntscheidung
	SetupTributePaid(job2)
end

function ErsteEntscheidung()
	SetMapMode = 0
	Logic.RemoveTribute(GetHumanPlayer(), 005)
	Logic.RemoveTribute(GetHumanPlayer(), 006)
	StartSimpleJob("StartAttackTimerFunc")
	createQuestDestroyLionsDen()
end

function zweiteEntscheidung()
	SetMapMode = 1
	Logic.RemoveTribute(GetHumanPlayer(), 006)
	Logic.RemoveTribute(GetHumanPlayer(), 005)
	StartSimpleJob("StartAttackTimerFunc")
	createQuestDestroyLionsDenAdvanced()
end

function StartAttackTimerFunc()
	if DoorTimer == nil then
		Logic.SetQuestType(1, 3, MAINQUEST_CLOSED, 1)
		DoorTimer = 6
		--Songlength woanders rein. hier wird direkt wintermusik getriggert
		function
		LocalMusic_UpdateMusic()
		end
		LocalMusic.SongLength = 0
		Stream.Start(Folders.Map.."attacksound.mp3",150)
		--[[ist das nötig?
		for _,buildingID in ipairs(InvisBuildingsPart1) do
			SetVisibility(Logic.GetEntityIDByName(buildingID),true)
			Logic.SetEntityInvulnerabilityFlag(buildingID, true)
		end
		]]
		function
		LocalMusic.CallbackSettlerKilled(_HurterPlayerID, _HurtPlayerID)
		end
		if XGUIEng.IsWidgetShown("GameClock") == 0 then
			XGUIEng.ShowWidget("GameClocK", 1)
		end
		StartSimpleHiResJob("BurningBuildingHandler")
		createSingleDoorsQuest()
	else
		DoorTimer = DoorTimer - 1
	end
	
	if DoorTimer == 0 then
		XGUIEng.SetTextColor(gvGUI_WidgetID.GameClock, 255, 255, 255)
		XGUIEng.SetWidgetPositionAndSize(gvGUI_WidgetID.GameClock, oldClockCoordinates[1], oldClockCoordinates[2], oldClockCoordinates[3], oldClockCoordinates[4])
		XGUIEng.SetMaterialColor(gvGUI_WidgetID.GameClock, 0, 36, 39, 36, 109)
		
		function
		GUIUpdate_Clock()
			local Seconds = Logic.GetTime()
			local TotalMinutes = math.floor( Seconds / 60 )
			local Hours = math.floor( TotalMinutes / 60 )
			local Minutes = math.mod( TotalMinutes, 60 )
			local TotalSeconds = math.mod( math.floor(Seconds), 60 )	
			local String = " "
			if Hours > 0 then		
				if Hours < 10 then
					String = String .. "0" .. Hours .. ":"
				else
					String = String .. Hours .. ":"
				end
			elseif Hours == 0 then
				String = String .. "00".. ":"
			end
			if Minutes == 0 then
				String = String .. "00" .. ":"
			else
				if Minutes <10 then
					String = String .. "0" .. Minutes .. ":"
				else
					String = String .. Minutes .. ":"
				end
			end
			if TotalSeconds < 10 then		
				String = String .. "0" .. TotalSeconds	
			else		
				String = String .. TotalSeconds	
			end
			XGUIEng.SetText(gvGUI_WidgetID.GameClock, String)	
		end
		
		function
		LocalMusic_UpdateMusic()
			if LocalMusic.BattlesOnTheMap == 0 then
				--Music is playing?
				if  LocalMusic.SongLength  > Logic.GetTime() then	 
					return
				end	
			end
			local SetToUse
			LocalMusic.BattlesOnTheMap = 1
			if LocalMusic.BattlesOnTheMap == 1 then
				SetToUse = LocalMusic.SetBattle
			end
			local SongAmount = table.getn(SetToUse)
			local Random = 1 + XGUIEng.GetRandom(SongAmount-1)
			local SongToPlay = Folders.Music .. SetToUse[Random][1]	
			Sound.StartMusic( SongToPlay, 130)
			LocalMusic.SongLength =  Logic.GetTime() + SetToUse[Random][2]
			LocalMusic.BattlesOnTheMap = 0
		end
		--Gebäude in Teil 1 noch sichtbar machen 
		startQuestDestroyLionsDen()
		ersteToreReplacen()
		--[[if SetMapMode == 1 then
			createQuestDestroyLionsDenAdvanced()
		else
			createQuestDestroyLionsDen()
		end]]

		return true
	end
	
	if DoorTimer == 6 then
		XGUIEng.SetTextColor(gvGUI_WidgetID.GameClock, 0, 128, 0)
	elseif DoorTimer == 5 then
		XGUIEng.SetTextColor(gvGUI_WidgetID.GameClock, 0, 128, 0)
	elseif DoorTimer == 4 then
		XGUIEng.SetTextColor(gvGUI_WidgetID.GameClock, 0, 255, 0)
	elseif DoorTimer == 3 then
		XGUIEng.SetTextColor(gvGUI_WidgetID.GameClock, 255, 255, 0)
	elseif DoorTimer == 2 then
		XGUIEng.SetTextColor(gvGUI_WidgetID.GameClock, 255, 128, 0)
	elseif DoorTimer == 1 then
		XGUIEng.SetTextColor(gvGUI_WidgetID.GameClock, 255, 0, 0)
	end
	if tempfunc == nil then
		tempfunc = GUIUpdate_Clock
		oldClockCoordinates = {	 470,
								 73,
								 84,
								 20
								}
		XGUIEng.SetMaterialColor(gvGUI_WidgetID.GameClock, 0, 0, 0, 0, 0)
		XGUIEng.SetWidgetPositionAndSize(gvGUI_WidgetID.GameClock, 470, 374, 84, 20)
		function GUIUpdate_Clock()
			XGUIEng.SetText(gvGUI_WidgetID.GameClock, "@center "..DoorTimer)
		end
	end
	return false
end

function ersteToreReplacen()
	for _,buildingID in ipairs(InvisBuildingsPart1) do
		invubuildingID1 = Logic.GetEntityIDByName(buildingID)
		SetVisibility(invubuildingID1,false)
		Logic.SetEntityInvulnerabilityFlag(invubuildingID1, 0)
	end
	--Gebäude in Teil 1 noch sichtbar machen.
	ReplaceEntity("InnerGate4", Entities.XD_DarkWallStraightGate)
	ReplaceEntity("InnerGate2", Entities.XD_DarkWallStraightGate)
	ReplaceEntity("InnerGate5", Entities.XD_DarkWallStraightGate)
	ReplaceEntity("InnerGate3", Entities.XD_DarkWallStraightGate)
end

function createSingleDoorsQuest()
	local Quest = {}
	Quest.Target = "innerFestungSpawnTurm1"
	Quest.Callback = tuere1
	SetupDestroy(Quest)
end

function tuere1()
	for _,buildingID in ipairs(InvisBuildingsPart2) do
		invubuildingID2 = Logic.GetEntityIDByName(buildingID)
		SetVisibility(invubuildingID2,false)
		Logic.SetEntityInvulnerabilityFlag(invubuildingID2, 0)
	end
	ReplaceEntity("checkpointtoor1", Entities.XD_DarkWallStraightGate)
	--Gebäude in Teil 2 noch sichtbar machen.
	local Quest = {}
	Quest.Target = "innerFestungSpawnTurm2"
	Quest.Callback = tuere2
	SetupDestroy(Quest)
end

function tuere2()
	for _,buildingID in ipairs(InvisBuildingsPart3) do
		invubuildingID3 = Logic.GetEntityIDByName(buildingID)
		SetVisibility(invubuildingID3,false)
		Logic.SetEntityInvulnerabilityFlag(invubuildingID3, 0)
	end
	ReplaceEntity("checkpointtoor2", Entities.XD_DarkWallStraightGate)
	ReplaceEntity("InnerGate8", Entities.XD_DarkWallStraightGate)
	ReplaceEntity("InnerGate7", Entities.XD_DarkWallStraightGate)
	--Gebäude in Teil 3 noch sichtbar machen.
	local Quest = {}
	Quest.Target = "innerFestungSpawnTurm3"
	Quest.Callback = tuere3
	SetupDestroy(Quest)
end

function tuere3()
	for _,buildingID in ipairs(InvisBuildingsPart4) do
		invubuildingID4 = Logic.GetEntityIDByName(buildingID)
		SetVisibility(invubuildingID4,false)
		Logic.SetEntityInvulnerabilityFlag(invubuildingID4, 0)
	end
	ReplaceEntity("InnerGate9", Entities.XD_DarkWallStraightGate)
	ReplaceEntity("checkpointtoor3", Entities.XD_DarkWallStraightGate)
	SpokenMessage(String.MainKey.."LionsGateOpen")
	--Gebäude in Teil 4 noch sichtbar machen.
	local Quest = {}
	Quest.Target = "innerFestungSpawnTurm4"
	Quest.Callback = tuere4
	SetupDestroy(Quest)
end

function tuere4()
	for _,buildingID in ipairs(InvisBuildingsPart5) do
		invubuildingID5 = Logic.GetEntityIDByName(buildingID)
		SetVisibility(invubuildingID5,false)
		Logic.SetEntityInvulnerabilityFlag(invubuildingID5, 0)
	end
	ReplaceEntity("checkpointtoor6", Entities.XD_DarkWallStraightGate)
	ReplaceEntity("checkpointtoor4", Entities.XD_DarkWallStraightGate)
	--Gebäude in Teil 5 noch sichtbar machen.
	local Quest = {}
	Quest.Target = "innerFestungSpawnTurm5"
	Quest.Callback = tuere5
	SetupDestroy(Quest)
end

function tuere5()
	for _,buildingID in ipairs(InvisBuildingsPart6) do
		invubuildingID6 = Logic.GetEntityIDByName(buildingID)
		SetVisibility(invubuildingID6,false)
		Logic.SetEntityInvulnerabilityFlag(invubuildingID6, 0)
	end
	ReplaceEntity("checkpointtoor7", Entities.XD_DarkWallStraightGate)
	ReplaceEntity("checkpointtoor5", Entities.XD_DarkWallStraightGate)
	--LionsDen und beide Türme sichtbar machen
end