class ElectricBox extends InteractiveMasterDevice
{
	default m_controllerTypeName = 'ElectricBoxController';

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		super.OnRequestComponents( ri );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		super.OnTakeControl( ri );
		m_controller = ( ( ElectricBoxController )( EntityResolveComponentsInterface.GetComponent( ri, 'controller' ) ) );
	}

	protected event OnGameAttached()
	{
		super.OnGameAttached();
		UpdateAnimState();
	}

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

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

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

	protected event OnActionOverride( evt : ActionOverride )
	{
		var delay : DelayEvent;
		var playerPuppet : PlayerPuppet;
		playerPuppet = ( ( PlayerPuppet )( GameInstance.GetPlayerSystem( GetGame() ).GetLocalPlayerControlledGameObject() ) );
		EnterWorkspot( playerPuppet, false, 'disassembleWorkspot' );
		SetGameplayRoleToNone();
		SetQuestFact();
		m_interaction.Toggle( false );
		SendDataToUIBlackboard( playerPuppet );
		UpdateDeviceState();
		delay = new DelayEvent;
		GameInstance.GetDelaySystem( GetGame() ).DelayEvent( this, delay, 3.4000001 );
	}

	protected function SendDataToUIBlackboard( player : PlayerPuppet )
	{
		GetPSMBlackboard( player ).SetBool( GetAllBlackboardDefs().PlayerStateMachine.IsInteractingWithDevice, true );
		GetBlackboard().SetBool( GetAllBlackboardDefs().ElectricBoxBlackBoard.isOverriden, true );
		GetBlackboard().FireCallbacks();
	}

	private function GetPSMBlackboard( player : PlayerPuppet ) : IBlackboard
	{
		return GameInstance.GetBlackboardSystem( GetGame() ).GetLocalInstanced( player.GetEntityID(), GetAllBlackboardDefs().PlayerStateMachine );
	}

	protected event OnDelayEvent( evt : DelayEvent )
	{
		GetDevicePS().WorkspotFinished();
	}

	protected function SetQuestFact()
	{
		var properties : ComputerQuickHackData;
		properties = GetDevicePS().GetQuestSetup();
		if( IsNameValid( properties.factName ) )
		{
			if( properties.operationType == EMathOperationType.Set )
			{
				SetFactValue( GetGame(), properties.factName, properties.factValue );
			}
			else
			{
				AddFact( GetGame(), properties.factName, properties.factValue );
			}
		}
	}

	protected override function EnterWorkspot( activator : GameObject, optional freeCamera : Bool, optional componentName : CName, optional deviceData : CName )
	{
		var workspotSystem : WorkspotGameSystem;
		workspotSystem = GameInstance.GetWorkspotSystem( activator.GetGame() );
		workspotSystem.PlayInDeviceSimple( this, activator, freeCamera, componentName, 'deviceWorkspot', '', 0.5, WorkspotSlidingBehaviour.PlayAtResourcePosition );
	}

	private function UpdateAnimState()
	{
		var animFeature : AnimFeature_SimpleDevice;
		animFeature = new AnimFeature_SimpleDevice;
		animFeature.isOpen = GetDevicePS().IsOverriden();
		AnimationControllerComponent.ApplyFeature( this, 'DeviceMaintenancePanel', animFeature );
	}

}

