class InteractiveAd extends InteractiveDevice
{
	default m_controllerTypeName = 'InteractiveAdController';
	protected var m_triggerComponent : TriggerComponent;
	protected var m_triggerExitComponent : TriggerComponent;
	protected var m_aduiComponent : worlduiWidgetComponent;
	protected var m_showAd : Bool;
	protected var m_showVendor : Bool;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		super.OnRequestComponents( ri );
		EntityRequestComponentsInterface.RequestComponent( ri, 'trigger', 'gameStaticTriggerAreaComponent', false );
		EntityRequestComponentsInterface.RequestComponent( ri, 'triggerExit', 'gameStaticTriggerAreaComponent', false );
		EntityRequestComponentsInterface.RequestComponent( ri, 'ui', 'worlduiWidgetComponent', false );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		super.OnTakeControl( ri );
		m_triggerComponent = ( ( TriggerComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'trigger' ) ) );
		m_triggerExitComponent = ( ( TriggerComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'triggerExit' ) ) );
		m_uiComponent = ( ( worlduiWidgetComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'ui' ) ) );
		m_controller = ( ( InteractiveAdController )( EntityResolveComponentsInterface.GetComponent( ri, 'controller' ) ) );
	}

	public const override function GetBlackboardDef() : InteractiveDeviceBlackboardDef
	{
		return GetDevicePS().GetBlackboardDef();
	}

	protected override function CreateBlackboard()
	{
		m_blackboard = IBlackboard.Create( GetAllBlackboardDefs().InteractiveDeviceBlackboard );
	}

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

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

	protected override function ResolveGameplayState()
	{
		super.ResolveGameplayState();
		if( IsUIdirty() && m_isInsideLogicArea )
		{
			RefreshUI();
		}
	}

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

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

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

	protected function DelayInteractiveAdEvent()
	{
		var evt : InteractiveAdFinishedEvent;
		evt = new InteractiveAdFinishedEvent;
		GameInstance.GetDelaySystem( GetGame() ).DelayEvent( this, evt, 1.0 );
	}

	protected event OnInteractiveAdFinishedEvent( evt : InteractiveAdFinishedEvent )
	{
		GetDevicePS().SetIsReady( m_showAd );
		GetBlackboard().SetBool( GetBlackboardDef().showVendor, false );
		GetBlackboard().FireCallbacks();
		RefreshUI();
	}

	protected event OnCloseAd( evt : CloseAd )
	{
		m_showAd = false;
		GetBlackboard().SetBool( GetBlackboardDef().showAd, false );
		GetBlackboard().FireCallbacks();
		RefreshUI();
	}

	protected event OnShowVendor( evt : ShowVendor )
	{
		m_showAd = false;
		GetBlackboard().SetBool( GetBlackboardDef().showVendor, true );
		GetBlackboard().FireCallbacks();
		GetDevicePS().AddLocation( true );
		SetFactValue( GetGame(), 'q001_show_vendingmachine_mappin', 1 );
		PlaySoundEvent( this, 'amb_int_custom_megabuilding_01_adverts_interactive_nicola_01_select' );
		DelayInteractiveAdEvent();
		DetermineInteractionStateByTask( GetDevicePS().GenerateContext( gamedeviceRequestType.Direct, GetInteractionClearance(), GameInstance.GetPlayerSystem( GetGame() ).GetLocalPlayerMainGameObject(), GetEntityID() ) );
		RefreshUI();
	}

	protected event OnAreaEnter( evt : AreaEnteredEvent )
	{
		if( evt.componentName == 'trigger' && ( ( PlayerPuppet )( EntityGameInterface.GetEntity( evt.activator ) ) ) )
		{
			PlaySoundEvent( this, 'amb_int_custom_megabuilding_01_adverts_interactive_nicola_01_approach' );
			m_showAd = true;
			GetBlackboard().SetBool( GetBlackboardDef().showAd, true );
			GetBlackboard().FireCallbacks();
			GetDevicePS().SetIsReady( m_showAd );
			RefreshUI();
		}
	}

	protected event OnAreaExit( evt : AreaExitedEvent )
	{
		if( evt.componentName == 'trigger' && ( ( PlayerPuppet )( EntityGameInterface.GetEntity( evt.activator ) ) ) )
		{
			PlaySoundEvent( this, 'amb_int_custom_megabuilding_01_adverts_interactive_nicola_01_stop' );
			m_showAd = false;
			GetBlackboard().SetBool( GetBlackboardDef().showAd, false );
			GetBlackboard().FireCallbacks();
			GetDevicePS().SetIsReady( m_showAd );
			RefreshUI();
		}
	}

}

class InteractiveAdFinishedEvent extends Event
{
}

