local celeste = require("#Celeste")

function onBegin()
	--say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_A01")
	--say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_A02")
	--say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_A03")
	--say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY02_A04")
	--say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_ANSWER0")
	--say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_ANSWER1")
	--say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_ANSWER2")
	--say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_ANSWER3")
	--say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_ANSWER4")
	
	if getFlag('CC_Celestris_BaddyQuizRepeat') then
		return
	end
	
	if getFlag("CC_Found12KeysBox") then
		say("CC_EVIDENCE02_CELESTRIS_DIALOGUE_BOX04")
		return
	end

	
	waitUntilOnGround()
	walk(1)		-- rotate player to the right
	disableMovement()
	disableRetry()
	
	
	
	
	wait(0.1)
	setFlag('badelineQuizDummyAppear', true)
	wait(0.3)

	playMusic('event:/fusion/dodonpachi05', nil)
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_START_TRIGGER00")
	
	-- camera to the room and go back
	player.ForceCameraUpdate = true
	setCameraOffset(4.2, -2.1)
	wait(1.3)
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_START_TRIGGER01")
	wait(0.3)
	setCameraOffset(0, -1.2)
	wait(1.2)
	player.ForceCameraUpdate = false
	
	say("CC_EVIDENCE02_CELESTRIS_QUIZ_BADDY_START_TRIGGER02")
	

	-- to rotate player to the right
	--wait(0.3)
	--local cubes = getEntity("CubeGenerator", "Celeste.Mod.EvaHelper.Portaline.")
	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