class IsPlayerControlsDevicePrereqState extends PrereqState
{
	var m_listenerInfo : CallbackHandle;

	protected event OnStateUpdate( value : EntityID )
	{
		OnChanged( EntityID.IsDefined( value ) );
	}

}

class IsPlayerControlsDevicePrereq extends IScriptablePrereq
{

	protected const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var bb : IBlackboard;
		var castedState : IsPlayerControlsDevicePrereqState;
		var player : weak< PlayerPuppet >;
		castedState = ( ( IsPlayerControlsDevicePrereqState )( state ) );
		player = ( ( PlayerPuppet )( context ) );
		if( player )
		{
			bb = GameInstance.GetBlackboardSystem( player.GetGame() ).Get( GetAllBlackboardDefs().DeviceTakeControl );
			castedState.m_listenerInfo = bb.RegisterListenerEntityID( GetAllBlackboardDefs().DeviceTakeControl.ActiveDevice, castedState, 'OnStateUpdate' );
		}
		return false;
	}

	protected const override function OnUnregister( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var bb : IBlackboard;
		var castedState : IsPlayerControlsDevicePrereqState;
		var player : weak< PlayerPuppet >;
		player = ( ( PlayerPuppet )( context ) );
		if( player )
		{
			bb = GameInstance.GetBlackboardSystem( player.GetGame() ).Get( GetAllBlackboardDefs().DeviceTakeControl );
			castedState = ( ( IsPlayerControlsDevicePrereqState )( state ) );
			bb.UnregisterListenerEntityID( GetAllBlackboardDefs().DeviceTakeControl.ActiveDevice, castedState.m_listenerInfo );
		}
	}

}

