class ActionForceResetDevice extends ActionBool
{
	default actionName = 'ActionForceResetDevice';
	var m_restartDuration : Int32;
	default m_restartDuration = 30;
}

class ActionOverride extends ActionBool
{
	default actionName = 'ActionOverride';

	public function SetProperties() {}

	public override function GetTweakDBChoiceRecord() : String
	{
		if( TDBID.IsValid( m_objectActionID ) )
		{
			return super.GetTweakDBChoiceRecord();
		}
		else
		{
			return "Override";
		}
	}

}

class ElectricBoxController extends MasterController
{

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

}

class ElectricBoxControllerPS extends MasterControllerPS
{
	private instanceeditable inlined var m_techieSkillChecks : EngineeringContainer;
	private instanceeditable var m_questFactSetup : ComputerQuickHackData;
	private persistent var m_isOverriden : Bool;

	protected override function GameAttached() {}

	protected override function GetSkillCheckContainerForSetup() : BaseSkillCheckContainer
	{
		return m_techieSkillChecks;
	}

	public quest const function IsOverriden() : Bool
	{
		return m_isOverriden;
	}

	public override function GetActions( out actions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		if( !( super.GetActions( actions, context ) ) )
		{
			return false;
		}
		if( !( IsON() ) )
		{
			return false;
		}
		if( !( m_isOverriden ) )
		{
			actions.PushBack( ActionOverride() );
		}
		SetActionIllegality( actions, m_illegalActions.regularActions );
		return true;
	}

	private function ActionOverride() : ActionOverride
	{
		var action : ActionOverride;
		action = new ActionOverride;
		action.SetUp( this );
		action.AddDeviceName( m_deviceName );
		if( TDBID.IsValid( m_questFactSetup.alternativeName ) )
		{
			action.CreateInteraction( , , m_questFactSetup.alternativeName );
		}
		else
		{
			action.CreateInteraction();
		}
		action.SetIllegal( m_illegalActions.skillChecks || m_illegalActions.regularActions );
		return action;
	}

	protected override function OnActionEngineering( evt : ActionEngineering ) : EntityNotificationType
	{
		super.OnActionEngineering( evt );
		m_isOverriden = true;
		ExecutePSAction( ActionOverride(), 'direct' );
		return EntityNotificationType.DoNotNotifyEntity;
	}

	protected override function OnActionOverride( evt : ActionOverride ) : EntityNotificationType
	{
		m_isOverriden = true;
		if( IsConnectedToSecuritySystem() )
		{
			TriggerSecuritySystemNotification( evt.GetExecutor(), GetOwnerEntityWeak().GetWorldPosition(), ESecurityNotificationType.ILLEGAL_ACTION );
		}
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	public function GetQuestSetup() : ComputerQuickHackData
	{
		return m_questFactSetup;
	}

	public function WorkspotFinished()
	{
		m_isOverriden = true;
		RefreshSlaves();
	}

	private const function RefreshSlaves()
	{
		SendActionToAllSlaves( new ActionOverride );
	}

	protected override function GetDeviceIconTweakDBID() : TweakDBID
	{
		return T"DeviceIcons.GeneratorDeviceIcon";
	}

	protected override function GetBackgroundTextureTweakDBID() : TweakDBID
	{
		return T"DeviceIcons.GeneratorDeviceBackground";
	}

	public const override function GetBlackboardDef() : DeviceBaseBlackboardDef
	{
		return GetAllBlackboardDefs().ElectricBoxBlackBoard;
	}

}

