local celeste = require("#Celeste")
function onBegin()
	if getFlag("CC_Found12KeysBox") then
		say("CC_EVIDENCE02_CELESTRIS_DIALOGUE_BOX04")
		return
	end
	
	disableRetry()
	playMusic('event:/fusion/dodonpachi05', nil)
	
	
	-- move to the button
	walkTo(8250)
	walk(6)
	disableMovement()
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_START")
	
	-- appear fly dummy, disappear doonv npc
	setFlag('badelineQuizDummyAppear', true)
	setFlag('badelineQuizNPCAppear', false)
	
	-- move to the dummy
	enableMovement()
	walkTo(8200)
	walk(6)
	disableMovement()

	
	local correct = 0
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY01")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY01_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY01_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY01_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY01_Q04")
	if answer == 4 then correct = correct + 1 end
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY01_A0" .. answer)
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_Q04")
	if answer == 2 then correct = correct + 1 end
	if answer == 4 then
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_A04")
		wait(0.3)
		setFlag('badelineQuizDummyCoffeeAppear', true)
		wait(0.2)
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_A04A")
		setFlag('badelineQuizDummyCoffeeAppear', false)
		wait(0.6)
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_A04B")
	else
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_A0" .. answer)
	end
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03_Q04")
	if answer == 2 then 
		correct = correct + 1
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03_RIGHT")
	else
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03_WRONG")
		choice("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03B_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03B_Q02")
		say('CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03B_WRONG')
		answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03C_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03C_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03C_Q03")
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY03C_WRONG0" .. answer)
	end
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY04")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY04_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY04_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY04_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY04_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY04_Q05")
	if answer == 1 then 
		correct = correct + 1 
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY04_A01")
	elseif answer == 5 then
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY04_A05")
	else
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY04_A02")
	end
	
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY05")
	local answer = choice("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY05_Q01", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY05_Q02", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY05_Q03", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY05_Q04", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY05_Q05", "CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY05_Q06")
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY05_A0" .. answer)
	if answer == 4 then 
		correct = correct - 10 
	end
	
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_END")
	
	
	if correct < 0 then
		corrent = -correct
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_ANSWER_N" .. correct)
	else
		say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_ANSWER" .. correct)
	end
	
	if correct >= 4 then
		setFlag("badelineQuizCubeGenerate", true)
		wait(1.2)
	end
end

function onEnd(room, wasSkipped)
	playMusic('music_farewell_granny', nil)
	setFlag('CC_Celestris_BaddyQuizRepeat', true)
	setFlag('badelineQuizDummyAppear', false)
	setFlag('badelineQuizDummyCoffeeAppear', false)
	setFlag('badelineQuizNPCAppear', true)
	setCameraOffset(0, -1.2)
	
	enableMovement()
	enableRetry()
end