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

function onTalk()
	makeUnskippable()
    disableRetry()
    disableMovement()
    player.ForceCameraUpdate = true
	engine.Scene:add(coroutineEntity)
	coroutineEntity:add(monocle.Coroutine(getLevel():ZoomTo(vector2(225, 90), 1.75, 1.25)))
    walkTo(-450, false, 1.0, false)
    local luanet = _G.luanet    
    player.Facing = luanet.enum(luanet.import_type("Celeste.Facings"), "Right")
	celeste.Audio.SetMusicParam("dialog", 1.0)
	
repeat
	if not getFlag("solex_conductorA") then
		result = choice("SJ2021_SOLOIINI_CONDUCTOR_CONV01_ASK", "SJ2021_SOLOIINI_CONDUCTOR_CONV02_ASK", "SJ2021_SOLOIINI_CONDUCTOR_CONV00_ASK")
		if result == 1 then
			say("SJ2021_SOLOIINI_CONDUCTOR_CONV01_SAY")
			setFlag("solex_conductorA")
		elseif result == 2 then
			say("SJ2021_SOLOIINI_CONDUCTOR_CONV02_SAY")
			setFlag("solex_conductorB")
		else
			result = 9
		end

	else
		if not getFlag("solex_conductorB") then
		result = choice("SJ2021_SOLOIINI_CONDUCTOR_CONV01_ASK", "SJ2021_SOLOIINI_CONDUCTOR_CONV02_ASK", "SJ2021_SOLOIINI_CONDUCTOR_CONV00_ASK")
		if result == 1 then
			say("SJ2021_SOLOIINI_CONDUCTOR_CONV01_SAY")
		elseif result == 2 then
			say("SJ2021_SOLOIINI_CONDUCTOR_CONV02_SAY")
			setFlag("solex_conductorB")
		else
			result = 9
		end
		
		else
		result = choice("SJ2021_SOLOIINI_CONDUCTOR_CONV01_ASK", "SJ2021_SOLOIINI_CONDUCTOR_CONV02_ASK", "SJ2021_SOLOIINI_CONDUCTOR_CONV03_ASK", "SJ2021_SOLOIINI_CONDUCTOR_CONV00_ASK")
		if result == 1 then
			say("SJ2021_SOLOIINI_CONDUCTOR_CONV01_SAY")
		elseif result == 2 then
			say("SJ2021_SOLOIINI_CONDUCTOR_CONV02_SAY")
		elseif result == 3 then
			say("SJ2021_SOLOIINI_CONDUCTOR_CONV03_SAY")
		else
			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