<?xml version="1.0" ?>

<Scene name="HallFusebox" type="XMLMinigame" hide_ui="$rotary_01_state != 0 and $rotary_02_state != 0 and $rotary_03_state != 0 and $rotary_04_state != 0">

	<Audio source="mildred_music"/>

	<Action condition="$animate_rotary != 0" type="LockScene"/>

	<!-- Scene layers -->
	<if t="$fuse_01_placed"> <Object type="ImageBox" image="scene_fuse_01" x="199" y="290" click_through="1"/> </if>
    <if t="$fuse_02_placed"> <Object type="ImageBox" image="scene_fuse_02" x="354" y="290" click_through="1"/> </if>
    <if t="$fuse_03_placed"> <Object type="ImageBox" image="scene_fuse_03" x="508" y="290" click_through="1"/> </if>
    <if t="$fuse_04_placed"> <Object type="ImageBox" image="scene_fuse_04" x="663" y="290" click_through="1"/> </if>

	<!-- 1 -->
    <if t="$rotary_01_state == 1">
		<if t="$animate_rotary == 1">
			<Object type="ImageBox" image="scene_rotary_01" x="200" y="289" click_through="1" angle="-270">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_01" x="200" y="289" click_through="1" angle="0"/>
		</else>
		</if>
	</if>
    <if t="$rotary_01_state == 2">
		<if t="$animate_rotary == 1">
			<Object type="ImageBox" image="scene_rotary_01" x="200" y="289" click_through="1" angle="0">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_01" x="200" y="289" click_through="1" angle="-90"/>
		</else>
		</if>
	</if>
    <if t="$rotary_01_state == 3">
		<if t="$animate_rotary == 1">
			<Object type="ImageBox" image="scene_rotary_01" x="200" y="289" click_through="1" angle="-90">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_01" x="200" y="289" click_through="1" angle="-180"/>
		</else>
		</if>
	</if>
    <if t="$rotary_01_state == 4">
		<if t="$animate_rotary == 1">
			<Object type="ImageBox" image="scene_rotary_01" x="200" y="289" click_through="1" angle="-180">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_01" x="200" y="289" click_through="1" angle="-270"/>
		</else>
		</if>
	</if>

	<!-- 2 -->
    <if t="$rotary_02_state == 1">
		<if t="$animate_rotary == 2">
			<Object type="ImageBox" image="scene_rotary_02" x="355" y="289" click_through="1" angle="-270">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_02" x="355" y="289" click_through="1" angle="0"/>
		</else>
		</if>
	</if>

    <if t="$rotary_02_state == 2">
		<if t="$animate_rotary == 2">
			<Object type="ImageBox" image="scene_rotary_02" x="355" y="289" click_through="1" angle="0">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_02" x="355" y="289" click_through="1" angle="-90"/>
		</else>
		</if>
	</if>

    <if t="$rotary_02_state == 3">
		<if t="$animate_rotary == 2">
			<Object type="ImageBox" image="scene_rotary_02" x="355" y="289" click_through="1" angle="-90">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_02" x="355" y="289" click_through="1" angle="-180"/>
		</else>
		</if>
	</if>

    <if t="$rotary_02_state == 4">
		<if t="$animate_rotary == 2">
			<Object type="ImageBox" image="scene_rotary_02" x="355" y="289" click_through="1" angle="-180">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_02" x="355" y="289" click_through="1" angle="-270"/>
		</else>
		</if>
	</if>

	<!-- 3 -->
    <if t="$rotary_03_state == 1">
		<if t="$animate_rotary == 3">
			<Object type="ImageBox" image="scene_rotary_03" x="508" y="289" click_through="1" angle="-270">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_03" x="508" y="289" click_through="1" angle="0"/>
		</else>
		</if>
	</if>

    <if t="$rotary_03_state == 2">
		<if t="$animate_rotary == 3">
			<Object type="ImageBox" image="scene_rotary_03" x="508" y="289" click_through="1" angle="0">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_03" x="508" y="289" click_through="1" angle="-90"/>
		</else>
		</if>
	</if>

    <if t="$rotary_03_state == 3">
		<if t="$animate_rotary == 3">
			<Object type="ImageBox" image="scene_rotary_03" x="508" y="289" click_through="1" angle="-90">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_03" x="508" y="289" click_through="1" angle="-180"/>
		</else>
		</if>
	</if>

    <if t="$rotary_03_state == 4">
		<if t="$animate_rotary == 3">
			<Object type="ImageBox" image="scene_rotary_03" x="508" y="289" click_through="1" angle="-180">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_03" x="508" y="289" click_through="1" angle="-270"/>
		</else>
		</if>
	</if>

	<!-- 4 -->
    <if t="$rotary_04_state == 1">
		<if t="$animate_rotary == 4">
			<Object type="ImageBox" image="scene_rotary_04" x="664" y="289" click_through="1" angle="-270">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_04" x="664" y="289" click_through="1" angle="0"/>
		</else>
		</if>
	</if>

    <if t="$rotary_04_state == 2">
		<if t="$animate_rotary == 4">
			<Object type="ImageBox" image="scene_rotary_04" x="664" y="289" click_through="1" angle="0">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_04" x="664" y="289" click_through="1" angle="-90"/>
		</else>
		</if>
	</if>

    <if t="$rotary_04_state == 3">
		<if t="$animate_rotary == 4">
			<Object type="ImageBox" image="scene_rotary_04" x="664" y="289" click_through="1" angle="-90">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_04" x="664" y="289" click_through="1" angle="-180"/>
		</else>
		</if>
	</if>

    <if t="$rotary_04_state == 4">
		<if t="$animate_rotary == 4">
			<Object type="ImageBox" image="scene_rotary_04" x="664" y="289" click_through="1" angle="-180">
				<Animator type="Rotator" amplitude="-90" speed="5"/>
			</Object>
		<else>
			<Object type="ImageBox" image="scene_rotary_04" x="664" y="289" click_through="1" angle="-270"/>
		</else>
		</if>
	</if>


	<if t="$rotary_01_state == 2"> <Object type="ImageBox" image="add_fuse_light_01" alpha="255" click_through="1" x="212" y="383" /> </if>
    <if t="$rotary_02_state == 4"> <Object type="ImageBox" image="add_fuse_light_02" alpha="255" click_through="1" x="367" y="383" /> </if>
    <if t="$rotary_03_state == 2"> <Object type="ImageBox" image="add_fuse_light_03" alpha="255" click_through="1" x="520" y="383" /> </if>
    <if t="$rotary_04_state == 3"> <Object type="ImageBox" image="add_fuse_light_04" alpha="255" click_through="1" x="675" y="383" /> </if>

	<Action condition="not $animate_rotary == skip" type="SetVar" var="animate_rotary" value="0" reset="0"/>
	<Animator type="DelayedAction" time="0.25"> <Action type="UnlockScene"/> </Animator>

	<!-- Actions -->
	<if t="$rotary_01_state != 0 and $rotary_02_state != 0 and $rotary_03_state != 0 and $rotary_04_state != 0">
		<Action name="HallFusebox_OnBack" type="SwitchScene" scene="mildred.HallSmallFlashlight"/>
	<else>
		<Action color="FFFF00" type="SwitchScene" scene="mildred.HallSmallFlashlight" cursor="walk"/>
	</else>
	</if>

	<Action name="HallFusebox_OnSuccess" type="Composite">
		<Action type="SetVar" var="fusebox_solved" value="1" reset="0"/>
		<Action condition="$lr_lamp_fixed" type="RemoveItem" item="flashlight" reset="0"/>
		<Action type="Say" key="FUSEBOX_SOLVED"/>
		<Action type="SetVar" var="task16_electricity" value="2" reset="0"/>
		<Action type="SetVar" var="task17_explore_mildred" value="1" reset="0"/>
		<Action type="UnlockScene"/>
		<Action type="SwitchScene" scene="HallSmall" fade_time="1"/>
	</Action>

	<!-- 1 -->
	<if t="$fuse_01_placed == 0">
		<Action color="FF0000" type="ItemAction" cursor="look">
			<Action itemaction="noitem" type="Say" key="NO_FUSE"/>
			<Action itemaction="fuse" type="Composite">
				<Action type="RemoveItem" item="fuse" reset="0"/>
				<Action type="PlaySound" sound="item_scene_generic"/>
				<Action type="SetVar" var="fuse_01_placed" value="1"/>
			</Action>
		</Action>
	<else>
		<if t="$rotary_01_state == 0">
			<Action color="FF0000" type="ItemAction" cursor="look">
				<Action itemaction="noitem" type="Say" key="NO_ROTATOR"/>
				<Action itemaction="rotator" type="Composite">
					<Action type="RemoveItem" item="rotator" reset="0"/>
					<Action type="PlaySound" sound="item_inplace_heavy"/>
					<Action type="SetVar" var="rotary_01_state" value="1"/>
				</Action>
			</Action>
		<else> <!-- rotatable -->
			<Action condition="$rotary_01_state != 0 and $rotary_02_state != 0 and $rotary_03_state != 0 and $rotary_04_state != 0" color="FF0000" type="Composite" cursor="use">
				<Action type="SetVar" var="animate_rotary" value="1" reset="0"/>
				<Action type="IncVar" var="rotary_01_state" value="1" reset="0"/>
				<Action condition="$rotary_01_state } 4" type="SetVar" var="rotary_01_state" value="1" reset="0"/>
				<Action type="SetVar" var="rotary_02_state" value="1" reset="0"/>
				<Action condition="not $rotary_01_state == 2" type="PlaySound" sound="ui.minigame_generic"/>
				<Action condition="$rotary_01_state == 2" type="PlaySound" sound="ui.minigame_generic_2"/>
				<Action type="ResetScene"/>
			</Action>
		</else>
		</if>
	</else>
	</if>

	<!-- 2 -->
	<if t="$fuse_02_placed == 0">
		<Action color="00FF00" type="ItemAction" cursor="look">
			<Action itemaction="noitem" type="Say" key="NO_FUSE"/>
			<Action itemaction="fuse" type="Composite">
				<Action type="RemoveItem" item="fuse" reset="0"/>
				<Action type="PlaySound" sound="item_scene_generic"/>
				<Action type="SetVar" var="fuse_02_placed" value="1"/>
			</Action>
		</Action>
	<else>
		<if t="$rotary_02_state == 0">
			<Action color="00FF00" type="ItemAction" cursor="look">
				<Action itemaction="noitem" type="Say" key="NO_ROTATOR"/>
				<Action itemaction="rotator" type="Composite">
					<Action type="RemoveItem" item="rotator" reset="0"/>
					<Action type="PlaySound" sound="item_inplace_heavy"/>
					<Action type="SetVar" var="rotary_02_state" value="1"/>
				</Action>
			</Action>
		<else> <!-- rotatable -->
			<Action condition="$rotary_01_state != 0 and $rotary_02_state != 0 and $rotary_03_state != 0 and $rotary_04_state != 0" color="00FF00" type="Composite" cursor="use">
				<Action type="IncVar" var="rotary_02_state" value="1" reset="0"/>
				<Action type="SetVar" var="animate_rotary" value="2" reset="0"/>
				<Action condition="$rotary_02_state } 4" type="SetVar" var="rotary_02_state" value="1" reset="0"/>
				<Action type="SetVar" var="rotary_04_state" value="1" reset="0"/>
				<Action condition="not $rotary_02_state == 4" type="PlaySound" sound="ui.minigame_generic"/>
				<Action condition="$rotary_02_state == 4" type="PlaySound" sound="ui.minigame_generic_2"/>
				<Action type="ResetScene"/>
			</Action>
		</else>
		</if>
	</else>
	</if>

	<!-- 3 -->
	<if t="$fuse_03_placed == 0">
		<Action color="0000FF" type="ItemAction" cursor="look">
			<Action itemaction="noitem" type="Say" key="NO_FUSE"/>
			<Action itemaction="fuse" type="Composite">
				<Action type="RemoveItem" item="fuse" reset="0"/>
				<Action type="PlaySound" sound="item_scene_generic"/>
				<Action type="SetVar" var="fuse_03_placed" value="1"/>
			</Action>
		</Action>
	<else>
		<if t="$rotary_03_state == 0">
			<Action color="0000FF" type="ItemAction" cursor="look">
				<Action itemaction="noitem" type="Say" key="NO_ROTATOR"/>
				<Action itemaction="rotator" type="Composite">
					<Action type="RemoveItem" item="rotator" reset="0"/>
					<Action type="PlaySound" sound="item_inplace_heavy"/>
					<Action type="SetVar" var="rotary_03_state" value="1"/>
				</Action>
			</Action>
		<else> <!-- rotatable -->
			<Action condition="$rotary_01_state != 0 and $rotary_02_state != 0 and $rotary_03_state != 0 and $rotary_04_state != 0" color="0000FF" type="Composite" cursor="use">
				<Action type="SetVar" var="animate_rotary" value="3" reset="0"/>
				<Action type="IncVar" var="rotary_03_state" value="1" reset="0"/>
				<Action condition="$rotary_03_state } 4" type="SetVar" var="rotary_03_state" value="1" reset="0"/>
				<Action type="SetVar" var="rotary_01_state" value="1" reset="0"/>
				<Action condition="not $rotary_03_state == 2" type="PlaySound" sound="ui.minigame_generic"/>
				<Action condition="$rotary_03_state == 2" type="PlaySound" sound="ui.minigame_generic_2"/>
				<Action type="ResetScene"/>
			</Action>
		</else>
		</if>
	</else>
	</if>

	<!-- 4 -->
	<if t="$fuse_04_placed == 0">
		<Action color="00FFFF" type="ItemAction" cursor="look">
			<Action itemaction="noitem" type="Say" key="NO_FUSE"/>
			<Action itemaction="fuse" type="Composite">
				<Action type="RemoveItem" item="fuse" reset="0"/>
				<Action type="PlaySound" sound="item_scene_generic"/>
				<Action type="SetVar" var="fuse_04_placed" value="1"/>
			</Action>
		</Action>
	<else>
		<if t="$rotary_04_state == 0">
			<Action color="00FFFF" type="ItemAction" cursor="look">
				<Action itemaction="noitem" type="Say" key="NO_ROTATOR"/>
				<Action itemaction="rotator" type="Composite">
					<Action type="RemoveItem" item="rotator" reset="0"/>
					<Action type="PlaySound" sound="item_inplace_heavy"/>
					<Action type="SetVar" var="rotary_04_state" value="1"/>
				</Action>
			</Action>
		<else> <!-- rotatable -->
			<Action condition="$rotary_01_state != 0 and $rotary_02_state != 0 and $rotary_03_state != 0 and $rotary_04_state != 0" color="00FFFF" type="Composite" cursor="use">
				<Action type="SetVar" var="animate_rotary" value="4" reset="0"/>
				<Action type="IncVar" var="rotary_04_state" value="1" reset="0"/>
				<Action condition="$rotary_04_state } 4" type="SetVar" var="rotary_04_state" value="1" reset="0"/>
				<Action condition="not $rotary_04_state == 3" type="PlaySound" sound="ui.minigame_generic"/>
				<Action condition="$rotary_04_state == 3" type="PlaySound" sound="ui.minigame_generic_2"/>
				<Action type="ResetScene"/>
			</Action>
		</else>
		</if>
	</else>
	</if>

	<Action condition="$animate_rotary != skip and $rotary_01_state == 2 and $rotary_02_state == 4 and $rotary_03_state == 2 and $rotary_04_state == 3" type="SetVar" var="minigame_solved" value="1" reset="0"/>

	<Action name="HallFusebox_OnSkip" type="Composite">
		<Action type="LockScene"/>
		<Action type="SetVar" var="animate_rotary" value="skip" reset="0"/>
		<Action type="SetVar" var="rotary_01_state" value="2" reset="0"/>
		<Action type="SetVar" var="rotary_02_state" value="4" reset="0"/>
		<Action type="SetVar" var="rotary_03_state" value="2" reset="0"/>
		<Action type="SetVar" var="rotary_04_state" value="3" reset="0"/>
		<Action type="ResetScene"/>
	</Action>


</Scene>