local result
local vector2 = require("#microsoft.xna.framework.vector2")
local coroutineEntity = monocle.Entity()

function onTalk()
    disableRetry()
    disableMovement()
    local luanet = _G.luanet    
    player.Facing = luanet.enum(luanet.import_type("Celeste.Facings"), "Left")
	if not getFlag("galeIntro") then
		wait(.3)
		say("ssc2024_xolimono_galeintro")
		wait(.5)
		say("ssc2024_xolimono_galeintro2")
		setFlag("galeIntro")
	end

	
repeat
	if not getFlag("galeA") then
		result = choice("ssc2024_xolimono_galeask1", "ssc2024_xolimono_galeask2", "ssc2024_xolimono_galeask3", "ssc2024_xolimono_gale_end")
		if result == 1 then
			say("ssc2024_xolimono_galeconvo1")
			setFlag("galeA")
		elseif result == 2 then
			say("ssc2024_xolimono_galeconvo2")
			setFlag("galeB")
		elseif result == 3 then
			say("ssc2024_xolimono_galeconvo3")
			setFlag("galeC")
		else
			say("ssc2024_xolimono_gale_end")
			result = 9
		end

	else
		if not getFlag("galeB") then
		result = choice("ssc2024_xolimono_galeask1", "ssc2024_xolimono_galeask2", "ssc2024_xolimono_galeask3", "ssc2024_xolimono_gale_end")
		if result == 1 then
			say("ssc2024_xolimono_galeconvo1")
			setFlag("galeA")
		elseif result == 2 then
			say("ssc2024_xolimono_galeconvo2")
			setFlag("galeB")
		elseif result == 3 then
			say("ssc2024_xolimono_galeconvo3")
			setFlag("galeC")
		else
			say("ssc2024_xolimono_gale_end")
			result = 9
		end
		
		else
		result = choice("ssc2024_xolimono_galeask1", "ssc2024_xolimono_galeask2", "ssc2024_xolimono_galeask3", "ssc2024_xolimono_gale_end")
		if result == 1 then
			say("ssc2024_xolimono_galeconvo1")
			setFlag("galeA")
		elseif result == 2 then
			say("ssc2024_xolimono_galeconvo2")
			setFlag("galeB")
		elseif result == 3 then
			say("ssc2024_xolimono_galeconvo3")
			setFlag("galeC")
		else
			say("ssc2024_xolimono_gale_end")
			result = 9
		end
	end
end
until result == 9
	coroutine.yield(getLevel():ZoomBack(0.5))
end

function onEnd()
	getLevel():remove(coroutineEntity)
    player.ForceCameraUpdate = false
	celeste.Audio.SetMusicParam("dialog", 0.0)
    enableRetry()
    enableMovement()
end