
.namespace s17_c01

function OnEnable()
	Closeup.OnEnable("MiniGame")
	Reset()
	gamestart=false
	if DebugOptions.DebugMode == true then
		InventoryManager.AddInInventory("InventoryFil")
		InventoryManager.AddInInventory("InventoryReservoir")
		InventoryManager.AddInInventory("InventoryBouchons")
		InventoryManager.AddInInventory("InventoryTube")
	end
	
	-- valve1_4.Layer = LayerForeground
	-- valve2_2.Layer = LayerForeground
	-- valve3_5.Layer = LayerForeground
	-- valve4_2.Layer = LayerForeground
	-- valve5_3.Layer = LayerForeground
	-- valve6_5.Layer = LayerForeground
	-- valve7_3.Layer = LayerForeground
	-- valve8_2.Layer = LayerForeground
	-- fils.Layer = LayerForeground
	-- liquide1.Layer = LayerMiddleground01
	-- liquide2.Layer = LayerMiddleground01
	-- liquide3.Layer = LayerMiddleground01
	-- liquide4.Layer = LayerMiddleground01
	-- liquide5.Layer = LayerMiddleground01
	-- eprouvettes.Layer = LayerForeground

end

function Reset()
	tabeprouv={4,4,4,4,4}
	win=false
	liquide1.Position_Y=500
	liquide2.Position_Y=500
	liquide3.Position_Y=500
	liquide4.Position_Y=500
	liquide5.Position_Y=500
	transla=0
	transl1 = 0 -- negatif ou positif selon si le liquide quitte ou arrive
	transl2 = 0
	transl3 = 0
	transl4 = 0
	transl5 = 0
	cond1 = 0 -- permet de mettre en place la mise au niveau du début
end

function OnUpdate()
	
	--OPLog.Log("tabeprouv"..tabeprouv[1])
	-- OPLog.Log("transla "..transla)
	-- OPLog.Log("pos1 "..tabeprouv[1])
	-- OPLog.Log("pos2 "..tabeprouv[2])
	-- OPLog.Log("pos3 "..tabeprouv[3])
	-- OPLog.Log("pos4 "..tabeprouv[4])
	-- OPLog.Log("pos5 "..tabeprouv[5])
	-- liquide1.Position_Y=720-65*tabeprouv[1]
	-- OPLog.Log("transl1 "..transl1)
	-- OPLog.Log("transl2 "..transl2)
	-- OPLog.Log("transl3 "..transl3)
	-- OPLog.Log("transl4 "..transl4)
	-- OPLog.Log("transl5 "..transl5)
	
	--mettre les niveaux à 4 au début du mini jeu
	if valve1_4.Enabled and valve2_2.Enabled and valve3_5.Enabled and valve4_2.Enabled and
	   valve5_3.Enabled and valve6_5.Enabled and valve7_3.Enabled and valve8_2.Enabled and
	   eprouvettes.Enabled and reservoir1.Enabled and reservoir2.Enabled and fils.Enabled and cond1==0 then
		
		kitbegin_hotspot.Enabled=false
		gamestart=true
		liquide1.Enabled=true
		liquide2.Enabled=true
		liquide3.Enabled=true
		liquide4.Enabled=true
		liquide5.Enabled=true
		cond1 = 1
	end
	
	if cond1==1 then
		if tabeprouv[1] > 4 then
			transl1=1
		else
			transl1=-1
		end
		if tabeprouv[2] > 4 then
			transl2=1
		else
			transl2=-1
		end
		if tabeprouv[3] > 4 then
			transl3=1
		else
			transl3=-1
		end
		if tabeprouv[4] > 4 then
			transl4=1
		else
			transl4=-1
		end
		if tabeprouv[5] > 4 then
			transl5=1
		else
			transl5=-1
		end
		tabeprouv[1]=4
		tabeprouv[2]=4
		tabeprouv[3]=4
		tabeprouv[4]=4
		tabeprouv[5]=4
		transla=1
		cond1=2
	end
	
	if transla==1 then
		
		if transl1 ~= 0 and liquide1.Position_Y ~= 500-45*tabeprouv[1] then
			liquide1.Position_Y=liquide1.Position_Y + transl1
		else
			transl1 = 0
			valve1_4.Rotation = 0
		end
		
		if transl2 ~= 0 and liquide2.Position_Y ~= 500-45*tabeprouv[2] then
			liquide2.Position_Y=liquide2.Position_Y + transl2
		else
			transl2 = 0
			valve2_2.Rotation = 0
			valve3_5.Rotation = 0
		end
		
		if transl3 ~= 0 and liquide3.Position_Y ~= 500-45*tabeprouv[3] then
			liquide3.Position_Y=liquide3.Position_Y + transl3
		else
			transl3 = 0
			valve4_2.Rotation = 0
			valve5_3.Rotation = 0
		end
		
		if transl4 ~= 0 and liquide4.Position_Y ~= 500-45*tabeprouv[4] then
			liquide4.Position_Y=liquide4.Position_Y + transl4
		else
			transl4 = 0
			valve6_5.Rotation = 0
			valve7_3.Rotation = 0
		end
		
		if transl5 ~= 0 and liquide5.Position_Y ~= 500-45*tabeprouv[5] then
			liquide5.Position_Y=liquide5.Position_Y + transl5
		else
			transl5 = 0
			valve8_2.Rotation = 0
		end
		
		if transl1 == 0 and  transl2 == 0 and  transl3 == 0 and  transl4 == 0 and  transl5 == 0 then
			transla=0
		end
	end
	
	if tabeprouv[1]==2 and tabeprouv[2]==3 and tabeprouv[3]==6 and tabeprouv[4]==6 and tabeprouv[5]==3 and 
		transl1 == 0 and transl2 == 0 and transl3 == 0 and transl4 == 0 and transl5 == 0 then
		Itsawin()
		transl1 = 1
	end
	
end	

function Itsawin()
	if tabeprouv[1]==2 and tabeprouv[2]==3 and tabeprouv[3]==6 and tabeprouv[4]==6 and tabeprouv[5]==3 then
		OPLog.Log("Animation du coffre s17_c01")
		Animcoffre.Play(self)
		tabeprouv[1]=4
	else
		if tabeprouv[1] > 2 then
			transl1=1
		else
			transl1=-1
		end
		if tabeprouv[2] > 3 then
			transl2=1
		else
			transl2=-1
		end
		if tabeprouv[3] > 6 then
			transl3=1
		else
			transl3=-1
		end
		if tabeprouv[4] > 6 then
			transl4=1
		else
			transl4=-1
		end
		if tabeprouv[5] > 3 then
			transl5=1
		else
			transl5=-1
		end
		tabeprouv[1]=2
		tabeprouv[2]=3
		tabeprouv[3]=6
		tabeprouv[4]=6
		tabeprouv[5]=3
		transla=1
	end
end

function OnEnter()
	SequencePlayer.Enabled = true
	if InventoryKit.Equipped == false and SampleLevel.IsEqual("s17_c01_kit",false) then		
		SequencePlayer.PlaySequence("GP_1710",self,nil)
		gamestart=false
		return true
	elseif InventoryKit.Equipped == false and SampleLevel.IsEqual("s17_c01_kit",true) then
		gamestart=true
		kitbegin_hotspot.Enabled=false
		fils.Enabled=true
		reservoir1.Enabled=true
		reservoir2.Enabled=true
		valve1_4.Enabled=true
		valve2_2.Enabled=true
		valve3_5.Enabled=true
		valve4_2.Enabled=true
		valve5_3.Enabled=true
		valve6_5.Enabled=true
		valve7_3.Enabled=true
		valve8_2.Enabled=true
		eprouvettes.Enabled=true
		liquide1.Enabled=true
		liquide2.Enabled=true
		liquide3.Enabled=true
		liquide4.Enabled=true
		liquide5.Enabled=true
		SequencePlayer.PlaySequence("AI_"..GetCurrentManager().Name,s17_c01,nil,"help")
	end
end

function OnAnimationEnd ()
	PlaySoundEffect("int_closeupwin")
	NavigationManager.SwitchTo(nil,"s17_SearchSite")
	SampleLevel.Set("s17_c01_win",true)
	PlaySoundEffect("gmp_safeexplosion")
end

function OnPickObject(objname)

end

function OnSearchEnd(typesearch)

end

function CondSpecificToFinish() 

end