local luaCutscenesUtils = require("#Celeste.Mod.MaxHelpingHand.Module.LuaCutscenesUtils")


function onTalk()
	if getFlag("dw_talked_otherself") and getFlag("dw_talked_whitespace") then
		disablePause()
		disableMovement()
		walkTo(-751)
		player.Facing = getEnum("Celeste.Facings", "Right")

		coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoralSacrifice"))
		coroutine.yield(luaCutscenesUtils.ChoiceWithDifferentFont("OMORI_GAME", "CBR_DeepWell_RoadEndchoice1", "CBR_DeepWell_RoadEndchoice2"))
		local coralbranchsacrifice = luaCutscenesUtils.GetChoice()

		if coralbranchsacrifice == 1 then
			disablePause()
			disableMovement()
			coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoralSacrificeAccept"))
			wait(0.5)
			player.ForceCameraUpdate = true
			wait(0.5)
			player.Depth = -50001
			setFlag("flagdecal_deeperwell")
			wait(3)
			setFlag("entrada_deeperwell")
		end

		if coralbranchsacrifice == 2 then
			enableMovement()
			enablePause()
		end

	else if getFlag("dw_talked_otherself") or getFlag("dw_talked_whitespace") then
		disableMovement()
		walkTo(-751)
		player.Facing = getEnum("Celeste.Facings", "Right")

		coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3more"))
		coroutine.yield(luaCutscenesUtils.ChoiceWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3choice1", "CBR_DeeperWell_BranchCoral3choice2"))
		local coralbranch = luaCutscenesUtils.GetChoice()

		if coralbranch == 1 then
			coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3otherselfconfirmation"))

			coroutine.yield(luaCutscenesUtils.ChoiceWithDifferentFont("OMORI_GAME", "CBR_DeepWell_RoadEndchoice1", "CBR_DeepWell_RoadEndchoice2"))
			local coralbranchotherself = luaCutscenesUtils.GetChoice()
			if coralbranchotherself == 1 then
				coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3otherself"))
				wait(0.5)
				coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3otherself2"))
				setFlag("dw_talked_otherself")
			else
				enableMovement()
				enablePause()
			end

		else if coralbranch == 2 then
			coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3whitespaceconfirmation"))

			coroutine.yield(luaCutscenesUtils.ChoiceWithDifferentFont("OMORI_GAME", "CBR_DeepWell_RoadEndchoice1", "CBR_DeepWell_RoadEndchoice2"))
			local coralbranchwhitespace = luaCutscenesUtils.GetChoice()
			if coralbranchwhitespace == 1 then
					coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3whitespace"))
					wait(0.5)
					coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3whitespace2"))
					setFlag("dw_talked_whitespace")
			else
					enableMovement()
					enablePause()
			end
		end
	end

	else
		disableMovement()
		walkTo(-751)
		player.Facing = getEnum("Celeste.Facings", "Right")

		coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral1"))
		wait(0.3)
		player.Facing = getEnum("Celeste.Facings", "Left")
		wait(0.1)
		coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral2"))
		player.Facing = getEnum("Celeste.Facings", "Right")
		wait(0.2)
		coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3"))
		coroutine.yield(luaCutscenesUtils.ChoiceWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3choice1", "CBR_DeeperWell_BranchCoral3choice2"))
		local coralbranch = luaCutscenesUtils.GetChoice()

		if coralbranch == 1 then
			coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3otherselfconfirmation"))

			coroutine.yield(luaCutscenesUtils.ChoiceWithDifferentFont("OMORI_GAME", "CBR_DeepWell_RoadEndchoice1", "CBR_DeepWell_RoadEndchoice2"))
			local coralbranchotherself = luaCutscenesUtils.GetChoice()
			if coralbranchotherself == 1 then
				coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3otherself"))
				wait(0.5)
				coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3otherself2"))
				setFlag("dw_talked_otherself")
			end

		else if coralbranch == 2 then
				coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3whitespaceconfirmation"))

				coroutine.yield(luaCutscenesUtils.ChoiceWithDifferentFont("OMORI_GAME", "CBR_DeepWell_RoadEndchoice1", "CBR_DeepWell_RoadEndchoice2"))
				local coralbranchwhitespace = luaCutscenesUtils.GetChoice()
					if coralbranchwhitespace == 1 then
						coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3whitespace"))
						wait(0.5)
						coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_BranchCoral3whitespace2"))
						setFlag("dw_talked_whitespace")
					end
				end
			end
		end
	end
end

function onEnd(room, wasSkipped)
	if wasSkipped then
		enableMovement()
		enablePause()
		setFlag("dw_talked_otherself")
		setFlag("dw_talked_whitespace")
	end
	enableMovement()
	enablePause()
end