class ArcadeMachineController extends ScriptableDeviceComponent
{

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

}

class ArcadeMachineControllerPS extends ScriptableDeviceComponentPS
{
	default m_deviceName = "LocKey#1635";
	default m_tweakDBRecord = T"Devices.ArcadeMachine";
	default m_tweakDBDescriptionRecord = T"device_descriptions.ArcadeMachine";
	default m_hasAuthorizationModule = true;
	protected const instanceeditable var m_gameVideosPaths : array< ResRef >;
	var DEBUG_enableArcadeMinigames : Bool;
	default DEBUG_enableArcadeMinigames = true;
	private var m_minigame : ArcadeMinigame;
	default m_minigame = ArcadeMinigame.INVALID;
	private var m_combatStateListener : CallbackHandle;

	protected event OnInstantiated()
	{
		super.OnInstantiated();
		if( !( IsStringValid( m_deviceName ) ) )
		{
			m_deviceName = "LocKey#1635";
		}
	}

	protected function IsPlayable() : Bool
	{
		return IsON() && ( m_minigame == ArcadeMinigame.RoachRace || m_minigame == ArcadeMinigame.Shooter );
	}

	protected const override function ShouldExposePersonalLinkAction() : Bool
	{
		if( !( super.ShouldExposePersonalLinkAction() ) )
		{
			return false;
		}
		return !( IsPlayerInteractingWithDevice() );
	}

	protected const function IsPlayerInteractingWithDevice() : Bool
	{
		var playerStateMachineBlackboard : IBlackboard;
		playerStateMachineBlackboard = GameInstance.GetBlackboardSystem( GetGameInstance() ).GetLocalInstanced( GetPlayerEntityID(), GetAllBlackboardDefs().PlayerStateMachine );
		return playerStateMachineBlackboard.GetBool( GetAllBlackboardDefs().PlayerStateMachine.IsInteractingWithDevice );
	}

	public override function GetActions( out actions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		if( !( super.GetActions( actions, context ) ) )
		{
			return false;
		}
		if( ( ( ( !( DEBUG_enableArcadeMinigames ) || !( IsPlayable() ) ) || IsGlitching() ) || IsPlayerInteractingWithDevice() ) || ( ( PlayerPuppet )( GetPlayerMainObject() ) ).IsInCombat() )
		{
			return false;
		}
		actions.PushBack( ActionBeginArcadeMinigame( context.processInitiatorObject ) );
		SetActionIllegality( actions, m_illegalActions.regularActions );
		return true;
	}

	protected function ActionBeginArcadeMinigame( executor : GameObject ) : BeginArcadeMinigameUI
	{
		var action : BeginArcadeMinigameUI;
		action = new BeginArcadeMinigameUI;
		action.clearanceLevel = DefaultActionsParametersHolder.GetInteractiveClearance();
		action.SetUp( this );
		action.SetProperties();
		action.SetExecutor( executor );
		action.AddDeviceName( m_deviceName );
		action.CreateInteraction();
		return action;
	}

	protected function OnBeginArcadeMinigameUI( evt : BeginArcadeMinigameUI ) : EntityNotificationType
	{
		var menuEvent : inkMenuInstance_SpawnEvent;
		var userData : ArcadeMinigameUserData;
		if( evt.IsCompleted() )
		{
			UseNotifier( evt );
			if( ( ( PlayerPuppet )( GetPlayerMainObject() ) ).IsInCombat() )
			{
				return EntityNotificationType.SendThisEventToEntity;
			}
			userData = new ArcadeMinigameUserData;
			userData.m_minigame = m_minigame;
			menuEvent = new inkMenuInstance_SpawnEvent;
			menuEvent.Init( 'OnArcadeMinigameBegin', userData );
			GameInstance.GetUISystem( GetGameInstance() ).QueueEvent( menuEvent );
			return EntityNotificationType.DoNotNotifyEntity;
		}
		ExecutePSActionWithDelay( evt, this );
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

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

	protected override function GetQuickHackActions( out outActions : array< DeviceAction >, const context : ref< GetActionsContext > )
	{
		var currentAction : ScriptableDeviceAction;
		currentAction = ActionGlitchScreen( T"DeviceAction.GlitchScreenSuicide", T"QuickHack.SuicideHackBase" );
		currentAction.SetDurationValue( GetDistractionDuration( currentAction ) );
		outActions.PushBack( currentAction );
		currentAction = ActionGlitchScreen( T"DeviceAction.GlitchScreenBlind", T"QuickHack.BlindHack" );
		currentAction.SetDurationValue( GetDistractionDuration( currentAction ) );
		outActions.PushBack( currentAction );
		currentAction = ActionGlitchScreen( T"DeviceAction.GlitchScreenGrenade", T"QuickHack.GrenadeHackBase" );
		currentAction.SetDurationValue( GetDistractionDuration( currentAction ) );
		outActions.PushBack( currentAction );
		if( !( GlitchScreen.IsDefaultConditionMet( this, context ) ) )
		{
			SetActionsInactiveAll( outActions, "LocKey#7003" );
		}
		currentAction = ActionQuickHackDistraction();
		currentAction.SetObjectActionID( T"DeviceAction.MalfunctionClassHack" );
		currentAction.SetDurationValue( GetDistractionDuration( currentAction ) );
		currentAction.SetInactiveWithReason( QuickHackDistraction.IsDefaultConditionMet( this, context ), "LocKey#7003" );
		outActions.PushBack( currentAction );
		if( IsGlitching() || IsDistracting() )
		{
			SetActionsInactiveAll( outActions, "LocKey#7004" );
		}
		FinalizeGetQuickHackActions( outActions, context );
	}

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

	public const function GetGameVideoPath() : ResRef
	{
		var randValue : Int32;
		var path : ResRef;
		if( m_gameVideosPaths.Size() <= 0 )
		{
			return path;
		}
		else if( m_gameVideosPaths.Size() > 1 )
		{
			randValue = RandRange( 0, m_gameVideosPaths.Size() );
			path = m_gameVideosPaths[ randValue ];
		}
		else
		{
			path = m_gameVideosPaths[ 0 ];
		}
		return path;
	}

	public function SetArcadeMinigame( minigame : ArcadeMinigame )
	{
		m_minigame = minigame;
	}

	public const override function GetBlackboardDef() : ArcadeMachineBlackboardDef
	{
		return GetAllBlackboardDefs().ArcadeMachineBlackBoard;
	}

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

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

}

class BeginArcadeMinigameUI extends ActionBool
{
	default m_duration = 3.967;

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

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

}

