class BaseAnimatedDeviceController extends ScriptableDeviceComponent
{

	public const override function GetPS() : BaseAnimatedDeviceControllerPS
	{
		return ( ( BaseAnimatedDeviceControllerPS )( GetBasePS() ) );
	}

}

class BaseAnimatedDeviceControllerPS extends ScriptableDeviceComponentPS
{
	default m_deviceName = "Gameplay-Devices-DisplayNames-RoadBlock";
	private instanceeditable persistent var m_isActive : Bool;
	protected instanceeditable var m_hasInteraction : Bool;
	protected instanceeditable var m_randomizeAnimationTime : Bool;
	[ customEditor = "TweakDBGroupInheritance;Interactions.InteractionChoice;Interactions.MountChoice" ]
	protected instanceeditable var m_nameForActivation : TweakDBID;
	[ customEditor = "TweakDBGroupInheritance;Interactions.InteractionChoice;Interactions.MountChoice" ]
	protected instanceeditable var m_nameForDeactivation : TweakDBID;

	public quest const function IsActive() : Bool
	{
		return m_isActive;
	}

	public quest const function IsNotActive() : Bool
	{
		return !( m_isActive );
	}

	public const function Randomize() : Bool
	{
		return m_randomizeAnimationTime;
	}

	protected override function GameAttached()
	{
		if( m_isActive )
		{
			m_activationState = EActivationState.ACTIVATED;
		}
		else
		{
			m_activationState = EActivationState.DEACTIVATED;
		}
	}

	public override function GetActions( out actions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		super.GetActions( actions, context );
		if( m_hasInteraction || context.requestType == gamedeviceRequestType.External )
		{
			actions.PushBack( ActionToggleActivate() );
		}
		SetActionIllegality( actions, m_illegalActions.regularActions );
		return true;
	}

	protected const override function CanCreateAnyQuickHackActions() : Bool
	{
		return true;
	}

	protected override function GetQuickHackActions( out actions : array< DeviceAction >, const context : ref< GetActionsContext > )
	{
		var currentAction : ScriptableDeviceAction;
		currentAction = ActionQuickHackToggleActivate();
		currentAction.SetObjectActionID( T"DeviceAction.ToggleStateClassHack" );
		actions.PushBack( currentAction );
		FinalizeGetQuickHackActions( actions, context );
	}

	public override function GetQuestActionByName( actionName : CName ) : DeviceAction
	{
		var action : DeviceAction;
		action = super.GetQuestActionByName( actionName );
		if( action == NULL )
		{
			switch( actionName )
			{
				case 'ForceActivate':
					action = ActionQuestForceActivate();
				break;
				case 'ForceDeactivate':
					action = ActionQuestForceDeactivate();
				break;
			}
		}
		return action;
	}

	public override function GetQuestActions( out actions : array< DeviceAction >, const context : ref< GetActionsContext > )
	{
		super.GetQuestActions( actions, context );
		actions.PushBack( ActionQuestForceActivate() );
		actions.PushBack( ActionQuestForceDeactivate() );
	}

	protected override function ActionToggleActivate() : ToggleActivate
	{
		var action : ToggleActivate;
		action = new ToggleActivate;
		action.clearanceLevel = DefaultActionsParametersHolder.GetToggleOpenClearance();
		action.SetUp( this );
		action.SetProperties( IsActive(), m_nameForActivation, m_nameForDeactivation );
		action.AddDeviceName( GetDeviceName() );
		action.CreateInteraction();
		action.CreateActionWidgetPackage();
		return action;
	}

	protected virtual function ActionQuickHackToggleActivate() : QuickHackToggleActivate
	{
		var action : QuickHackToggleActivate;
		action = new QuickHackToggleActivate;
		action.clearanceLevel = DefaultActionsParametersHolder.GetToggleOpenClearance();
		action.SetUp( this );
		action.SetProperties( IsActive(), m_nameForActivation, m_nameForDeactivation );
		action.AddDeviceName( GetDeviceName() );
		if( IsActive() )
		{
			action.CreateInteraction( , , m_nameForActivation );
		}
		else
		{
			action.CreateInteraction( , , m_nameForDeactivation );
		}
		action.CreateActionWidgetPackage();
		return action;
	}

	public override function OnToggleActivate( evt : ToggleActivate ) : EntityNotificationType
	{
		super.OnToggleActivate( evt );
		SetActiveState( !( IsActive() ) );
		NotifyParents();
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	protected function SetActiveState( isActive : Bool )
	{
		m_isActive = isActive;
	}

	public function OnQuickHackToggleActivate( evt : QuickHackToggleActivate ) : EntityNotificationType
	{
		SetActiveState( !( IsActive() ) );
		m_activationState = ( ( IsActive() ) ? ( EActivationState.ACTIVATED ) : ( EActivationState.DEACTIVATED ) );
		NotifyParents();
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	protected override function OnActivateDevice( evt : ActivateDevice ) : EntityNotificationType
	{
		if( m_activationState != EActivationState.ACTIVATED && IsON() )
		{
			super.OnActivateDevice( evt );
			SetActiveState( true );
			NotifyParents();
			return EntityNotificationType.SendThisEventToEntity;
		}
		return EntityNotificationType.DoNotNotifyEntity;
	}

	protected override function OnDeactivateDevice( evt : DeactivateDevice ) : EntityNotificationType
	{
		if( m_activationState != EActivationState.DEACTIVATED && IsON() )
		{
			super.OnDeactivateDevice( evt );
			SetActiveState( false );
			NotifyParents();
			return EntityNotificationType.SendThisEventToEntity;
		}
		return EntityNotificationType.DoNotNotifyEntity;
	}

}

