class BasicDistractionDeviceController extends ScriptableDeviceComponent
{

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

}

class BasicDistractionDeviceControllerPS extends ScriptableDeviceComponentPS
{
	default m_deviceName = "LocKey#42164";
	default m_tweakDBRecord = T"Devices.BaseDistractor";
	default m_tweakDBDescriptionRecord = T"device_descriptions.BaseDistractor";
	[ category = "Distraction properties" ]
	protected editable var m_distractorType : EPlaystyleType;
	default m_distractorType = EPlaystyleType.NETRUNNER;
	protected instanceeditable inlined var m_basicDistractionDeviceSkillChecks : EngDemoContainer;
	[ category = "Distraction properties" ]
	protected const editable var m_effectOnStartNames : array< CName >;
	[ category = "Distraction properties" ]
	protected editable var m_animationType : EAnimationType;
	default m_animationType = EAnimationType.TRANSFORM;
	[ category = "Tech design" ]
	protected editable var m_forceAnimationSystem : Bool;
	[ category = "Distraction properties" ][ tooltip = "Leave empty if you want to keep the default one" ][ customEditor = "TweakDBGroupInheritance;ObjectAction" ]
	instanceeditable var m_overrideDistractionActionId : TweakDBID;

	protected event OnInstantiated()
	{
		super.OnInstantiated();
	}

	protected override function Initialize()
	{
		super.Initialize();
	}

	protected override function GameAttached() {}

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

	public const function GetAnimationType() : EAnimationType
	{
		return m_animationType;
	}

	public const function GetForceAnimationSystem() : Bool
	{
		return m_forceAnimationSystem;
	}

	public const function GetEffectOnStartNames() : array< CName >
	{
		return m_effectOnStartNames;
	}

	protected override function ActionQuickHackDistraction() : QuickHackDistraction
	{
		var action : QuickHackDistraction;
		action = new QuickHackDistraction;
		action.SetUp( this );
		action.SetProperties();
		if( TDBID.IsValid( m_overrideDistractionActionId ) )
		{
			action.SetObjectActionID( m_overrideDistractionActionId );
		}
		else
		{
			action.SetObjectActionID( T"DeviceAction.MalfunctionClassHack" );
		}
		action.AddDeviceName( m_deviceName );
		action.SetExecutor( GetPlayer( GetGameInstance() ) );
		action.SetDurationValue( action.GetModifiedDurationTime( GetDistractionDuration( action ) ) );
		action.CreateInteraction();
		return action;
	}

	protected function ActionSpiderbotDistractDevice() : SpiderbotDistractDevice
	{
		var action : SpiderbotDistractDevice;
		action = new SpiderbotDistractDevice;
		action.clearanceLevel = DefaultActionsParametersHolder.GetSpiderbotClearance();
		action.SetUp( this );
		action.SetProperties();
		action.AddDeviceName( m_deviceName );
		action.CreateInteraction();
		return action;
	}

	protected function ActionSpiderbotDistractDevicePerformed() : SpiderbotDistractDevicePerformed
	{
		var action : SpiderbotDistractDevicePerformed;
		action = new SpiderbotDistractDevicePerformed;
		action.clearanceLevel = DefaultActionsParametersHolder.GetSpiderbotClearance();
		action.SetUp( this );
		action.SetProperties();
		action.AddDeviceName( m_deviceName );
		return action;
	}

	protected override function CanCreateAnySpiderbotActions() : Bool
	{
		if( m_distractorType == EPlaystyleType.TECHIE )
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	protected override function GetSpiderbotActions( actions : ref< array< DeviceAction > >, const context : ref< GetActionsContext > )
	{
		if( m_distractorType == EPlaystyleType.NETRUNNER )
		{
			return;
		}
		if( !( IsDistracting() ) )
		{
			actions.PushBack( ActionSpiderbotDistractDevice() );
		}
	}

	protected const override function CanCreateAnyQuickHackActions() : Bool
	{
		return m_distractorType == EPlaystyleType.NETRUNNER;
	}

	protected override function GetQuickHackActions( out actions : array< DeviceAction >, const context : ref< GetActionsContext > )
	{
		var currentAction : ScriptableDeviceAction;
		super.GetQuickHackActions( actions, context );
		if( m_distractorType == EPlaystyleType.TECHIE || m_distractorType == EPlaystyleType.NONE )
		{
			return;
		}
		currentAction = ActionQuickHackDistraction();
		currentAction.SetInactiveWithReason( !( IsDistracting() ), "LocKey#7004" );
		actions.PushBack( currentAction );
		FinalizeGetQuickHackActions( actions, context );
	}

	public function OnSpiderbotDistractExplosiveDevice( evt : SpiderbotDistractDevice ) : EntityNotificationType
	{
		var action : ScriptableDeviceAction;
		m_distractExecuted = true;
		action = ActionSpiderbotDistractDevicePerformed();
		action.SetDurationValue( GetDistractionDuration( action ) );
		SendSpiderbotToPerformAction( action, evt.GetExecutor() );
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	public function OnSpiderbotDistractExplosiveDevicePerformed( evt : SpiderbotDistractDevicePerformed ) : EntityNotificationType
	{
		if( evt.IsStarted() )
		{
			m_distractExecuted = true;
			evt.SetCanTriggerStim( true );
			ExecutePSActionWithDelay( evt, this, evt.GetDurationValue() );
		}
		else
		{
			m_distractExecuted = false;
			evt.SetCanTriggerStim( false );
		}
		UseNotifier( evt );
		if( !( IsFinal() ) )
		{
		}
		return EntityNotificationType.SendThisEventToEntity;
	}

}

enum EPlaystyleType
{
	NONE = -1,
	TECHIE = 0,
	NETRUNNER = 1,
	TECHIE_AND_NETRUNNER = 2,
}

class SpiderbotDistractDevice extends ActionBool
{

	public function SetProperties()
	{
		actionName = 'SpiderbotDistractDevice';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( actionName, true, 'LocKey#596', 'LocKey#596' );
	}

	public override function GetTweakDBChoiceRecord() : String
	{
		return "SpiderbotDistraction";
	}

	public constexpr static function IsAvailable( device : ScriptableDeviceComponentPS ) : Bool
	{
		return true;
	}

	public static function IsClearanceValid( clearance : Clearance ) : Bool
	{
		if( Clearance.IsInRange( clearance, DefaultActionsParametersHolder.GetInteractiveClearance() ) )
		{
			return true;
		}
		return false;
	}

	public static function IsContextValid( const context : ref< GetActionsContext > ) : Bool
	{
		if( context.requestType == gamedeviceRequestType.Remote )
		{
			return true;
		}
		return false;
	}

}

class SpiderbotDistractDevicePerformed extends ActionBool
{

	public function SetProperties()
	{
		actionName = 'SpiderbotDistractDevicePerformed';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( actionName, true, 'SpiderbotDistractDevicePerformed', 'SpiderbotDistractDevicePerformed' );
	}

	public constexpr static function IsAvailable( device : ScriptableDeviceComponentPS ) : Bool
	{
		return true;
	}

	public constexpr static function IsClearanceValid( clearance : Clearance ) : Bool
	{
		return true;
	}

	public constexpr static function IsContextValid( const context : ref< GetActionsContext > ) : Bool
	{
		return true;
	}

}

