local celeste = require("#Celeste")
local theo = getEntity("DialogNPC", "Celeste.Mod.DoonvHelper.Entities.")
function onBegin()
	if getFlag("CC_Found12KeysBox") then
		say("CC_EVIDENCE02_CELESTRIS_DIALOGUE_BOX03")
		return
	end
	
	
	-- OnlyOnce param in a trigger said a big "fuck you" to my cutscene, so I made a new file
	disableRetry()
	disableMovement()

	walkTo(theo.Position.X - 6 - 24)
	-- to rotate player to the right
	walk(6)

	
	if getFlag("CC_Celestris_TheoQuizRepeat") then
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO_START_REPEAT")
	else
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO_START")
	end
	
	
	local correct = 0
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO01")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO01_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO01_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO01_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO01_Q04")
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO01_A0" .. answer)
	if answer == 3 then correct = correct + 1 end 
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO02")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO02_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO02_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO02_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO02_Q04")
	if answer == 3 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO02_A0" .. answer)
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO03")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO03_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO03_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO03_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO03_Q04")
	if answer == 1 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO03_A0" .. answer)
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO04")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO04_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO04_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO04_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO04_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO04_Q05")
	if answer == 1 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO04_A0" .. answer)
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO05")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO05_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO05_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO05_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO05_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO05_Q05")
	if answer == 4 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO05_A0" .. answer)
	
	
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO06")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO06_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO06_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO06_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO06_Q04")
	if answer == 2 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO06_A0" .. answer)
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO07")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO07_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO07_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO07_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO07_Q04")
	if answer ~= 3 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO07_A0" .. answer)
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO08")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO08_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO08_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO08_Q03")
	if answer == 3 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO08_A0" .. answer)
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO09")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO09_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO09_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO09_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO09_Q04")
	local bobbin = answer == 2
	if answer == 2 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO09_A0" .. answer)
	
	
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10")
	local answer = (bobbin) 
		and choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q05", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q06")
		or  choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_Q05")
	if answer ~= 5 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO10_A0" .. answer)
	
	----------------------------------------------------------
	-- additional Balatro question
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_Q04")
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_A0" .. answer)
	if answer == 3 then 
		correct = correct + 1 
		local asklore = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_LORE_YES", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_LORE_NO")
		if asklore == 1 then say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_LORE") else say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_LORE_REFUSE") end
	elseif answer == 4 then
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO16_LORE")
	end 
	----------------------------------------------------------
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO11")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO11_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO11_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO11_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO11_Q04")
	if answer == 4 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO11_A0" .. answer)
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO12")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO12_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO12_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO12_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO12_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO12_Q05")
	if answer == 2 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO12_A0" .. answer)
	
	-- TADC question
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q05", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q06", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q07", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q08", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q09", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q10", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q11", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q12", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q13", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q14", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q15")
	if answer == 2 then
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_A02")
		answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q05", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q06", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q07", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q08", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q09", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q10", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q11", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q12", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q13", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q14", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_Q15")
		if answer > 1 then answer = answer + 1 end
	end
	
	if answer ~= 1 and answer ~= 10 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO13_A" .. (
		answer ==  1 and '01' or 
		answer ==  2 and '02' or 
		answer ==  9 and '09' or 
		answer == 10 and '10' or 
		answer == 14 and '14' or 
		answer == 15 and '15' or 
		answer == 16 and '16' or '03_13'))
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO14")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO14_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO14_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO14_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO14_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO14_Q05")
	if answer == 1 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO14_A0" .. answer)
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO15")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO15_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_THEO15_Q02")
	if answer == 1 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO15_A0" .. answer)
	
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO_END")
	
	
	if correct >= 12 then 
		setFlag("CC_Celestris_TheoQuizKey", true)
	end
	
	if correct == 0 then 
		setFlag("CC_Celestris_TheoQuizWin2", true)
		wait(1.2)
	elseif correct == 16 then
		setFlag("CC_Celestris_TheoQuizWin2", true)
		wait(1.2)
	elseif correct >= 12 then
		setFlag("CC_Celestris_TheoQuizWin1", true)
		wait(0.4)
	end
	

	say("CC_EVIDENCE02_CELESTRIS_QUIZ_THEO_ANSWER" .. correct)
end

function onEnd(room, wasSkipped)
	enableMovement()
	enableRetry()
	setFlag("CC_Celestris_TheoQuizWin1", false)
	setFlag("CC_Celestris_TheoQuizWin2", false)
	setFlag("CC_Celestris_TheoQuizRepeat", true)
end