class SampleBumpEvent extends Event
{
	var m_amount : Int32;
	default m_amount = 1;
}

class SampleEntityWithCounterPS extends GameObjectPS
{
	protected persistent var m_counter : Int32;

	public const function ReadTheCounter() : Int32
	{
		return m_counter;
	}

	public function OnBumpTheCounter( evt : SampleBumpEvent ) : EntityNotificationType
	{
		m_counter += evt.m_amount;
		return EntityNotificationType.SendThisEventToEntity;
	}

}

class SampleEntityWithCounter extends GameObject
{

	protected const override function GetPS() : SampleEntityWithCounterPS
	{
		return ( ( SampleEntityWithCounterPS )( GetBasePS() ) );
	}

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		EntityRequestComponentsInterface.RequestComponent( ri, 'SampleCounterDisplayComponent', 'SampleCounterDisplayComponent', true );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		var component : SampleCounterDisplayComponent;
		component = ( ( SampleCounterDisplayComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'SampleCounterDisplayComponent' ) ) );
		component.m_targetPersistentID = GetPersistentID();
	}

	public function OnBumpTheCounter( evt : SampleBumpEvent )
	{
	}

}

class SampleInteractiveEntityThatBumpsTheCounter extends GameObject
{
	instanceeditable var m_targetEntityWithCounter : NodeRef;
	var m_targetPersistentID : PersistentID;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		EntityRequestComponentsInterface.RequestComponent( ri, 'SampleCounterDisplayComponent', 'SampleCounterDisplayComponent', true );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		var component : SampleCounterDisplayComponent;
		component = ( ( SampleCounterDisplayComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'SampleCounterDisplayComponent' ) ) );
		m_targetPersistentID = ResolveNodeRefWithEntityID( m_targetEntityWithCounter, GetEntityID() );
		component.m_targetPersistentID = m_targetPersistentID;
	}

	protected event OnInteractionChoice( choice : InteractionChoiceEvent )
	{
		var evt : SampleBumpEvent;
		evt = new SampleBumpEvent;
		GameInstance.GetPersistencySystem( GetGame() ).QueuePSEvent( m_targetPersistentID, 'SampleEntityWithCounterPS', evt );
	}

}

class SampleCounterDisplayComponent extends ScriptableComponent
{
	var m_targetPersistentID : PersistentID;

	public function OnUpdate( deltaTime : Float )
	{
		if( PersistentID.IsDefined( m_targetPersistentID ) )
		{
			DisplayCounter();
		}
	}

	public function DisplayCounter()
	{
		var counterValue : Int32;
		const var psObject : SampleEntityWithCounterPS;
		psObject = ( ( SampleEntityWithCounterPS )( GetPersistencySystem().GetConstAccessToPSObject( m_targetPersistentID, 'SampleEntityWithCounterPS' ) ) );
		counterValue = psObject.ReadTheCounter();
		GetDebugVisualizerSystem().DrawText3D( GetOwner().GetWorldPosition(), "Counter: " + IntToString( counterValue ), Color( 0, 255, 0, 255 ), 0.001 );
	}

}

class SampleComponentWithCounterPS extends GameComponentPS
{
	protected persistent var m_counter : Int32;
	default m_counter = 1000;

	public const function ReadTheCounter() : Int32
	{
		return m_counter;
	}

	public function BumpTheCounter() : Int32
	{
		m_counter = m_counter + 1;
		return m_counter;
	}

}

class SampleComponentWithCounter extends ScriptableComponent
{

	protected const override function GetPS() : SampleComponentWithCounterPS
	{
		return ( ( SampleComponentWithCounterPS )( GetBasePS() ) );
	}

	public function OnUpdate( deltaTime : Float )
	{
		var counterValue : Int32;
		counterValue = GetPS().BumpTheCounter();
		GetDebugVisualizerSystem().DrawText3D( GetOwner().GetWorldPosition(), "Counter: " + IntToString( counterValue ), Color( 0, 255, 0, 255 ), 0.001 );
	}

}

