class SlidingLadder extends BaseAnimatedDevice
{
	default m_controllerTypeName = 'SlidingLadderController';
	protected var m_offMeshConnectionDown : OffMeshConnectionComponent;
	protected var m_offMeshConnectionUp : OffMeshConnectionComponent;
	protected var m_ladderInteraction : InteractionComponent;
	private var m_wasShot : Bool;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		super.OnRequestComponents( ri );
		EntityRequestComponentsInterface.RequestComponent( ri, 'offMeshConnection_up', 'OffMeshConnectionComponent', true );
		EntityRequestComponentsInterface.RequestComponent( ri, 'offMeshConnection_down', 'OffMeshConnectionComponent', false );
		EntityRequestComponentsInterface.RequestComponent( ri, 'entrances', 'gameinteractionsComponent', false );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		super.OnTakeControl( ri );
		m_offMeshConnectionUp = ( ( OffMeshConnectionComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'offMeshConnection_up' ) ) );
		m_offMeshConnectionDown = ( ( OffMeshConnectionComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'offMeshConnection_down' ) ) );
		m_ladderInteraction = ( ( InteractionComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'entrances' ) ) );
		m_controller = ( ( SlidingLadderController )( EntityResolveComponentsInterface.GetComponent( ri, 'controller' ) ) );
	}

	protected override function ResolveGameplayState()
	{
		super.ResolveGameplayState();
		ToggleLadder();
	}

	protected event OnHitEvent( hit : gameHitEvent )
	{
		if( GetDevicePS().IsShootable() && GetDevicePS().IsNotActive() )
		{
			super.OnHitEvent( hit );
			m_wasShot = true;
			GetDevicePS().SetActive();
			ActivateAnimation();
		}
	}

	protected event OnDelayEvent( evt : DelayEvent )
	{
		ToggleLadder();
		RefreshInteraction( gamedeviceRequestType.Direct, GetPlayer( GetGame() ) );
		if( m_wasShot )
		{
			m_wasShot = false;
			GetDevicePS().GetDeviceOperationsContainer().Execute( 'DealDamage', this );
		}
	}

	protected override function OnPlayAnimation()
	{
		var delayEvent : DelayEvent;
		var timeScale : Float;
		var delayTime : Float;
		delayEvent = new DelayEvent;
		timeScale = GetTimeScale();
		delayTime = ( ( SlidingLadderControllerPS )( GetDevicePS() ) ).GetAnimTime();
		if( timeScale > 0.0 )
		{
			delayTime /= timeScale;
		}
		GameInstance.GetDelaySystem( GetGame() ).DelayEvent( this, delayEvent, delayTime );
	}

	protected override function GetTimeScale() : Float
	{
		return ( ( m_wasShot ) ? ( 3.0 ) : ( 1.0 ) );
	}

	protected override function Animate()
	{
		var delayEvent : DelayEvent;
		if( GetDevicePS().IsActive() )
		{
			AnimationControllerComponent.SetInputBool( this, 'expand', true );
			delayEvent = new DelayEvent;
			GameInstance.GetDelaySystem( GetGame() ).DelayEvent( this, delayEvent, ( ( SlidingLadderControllerPS )( GetDevicePS() ) ).GetAnimTime() );
		}
		else
		{
			AnimationControllerComponent.SetInputBool( this, 'expand', false );
		}
	}

	protected function ToggleLadder()
	{
		if( m_offMeshConnectionUp && m_ladderInteraction )
		{
			if( GetDevicePS().IsActive() )
			{
				m_offMeshConnectionUp.EnableOffMeshConnection();
				m_offMeshConnectionUp.EnableForPlayer();
				m_offMeshConnectionDown.EnableOffMeshConnection();
				m_offMeshConnectionDown.EnableForPlayer();
				m_ladderInteraction.Toggle( true );
			}
			else
			{
				m_offMeshConnectionUp.DisableOffMeshConnection();
				m_offMeshConnectionUp.DisableForPlayer();
				m_offMeshConnectionDown.DisableOffMeshConnection();
				m_offMeshConnectionDown.DisableForPlayer();
				m_ladderInteraction.Toggle( false );
			}
		}
	}

	private const override function GetController() : SlidingLadderController
	{
		return ( ( SlidingLadderController )( m_controller ) );
	}

	public const override function GetDevicePS() : SlidingLadderControllerPS
	{
		return GetController().GetPS();
	}

	public const override function DeterminGameplayRole() : EGameplayRole
	{
		return EGameplayRole.ClearPath;
	}

}

