importonly class gameCpoPickableItem extends GameObject
{
	protected import function EquipItem( puppet : GameObject );
	public import function GetItemIDToEquip() : ItemID;
}

class RespawnHealthConsumable extends Event
{
}

class HealthConsumable extends gameCpoPickableItem
{
	private var m_interactionComponent : InteractionComponent;
	private var m_meshComponent : MeshComponent;
	private instanceeditable var m_disappearAfterEquip : Bool;
	default m_disappearAfterEquip = true;
	private instanceeditable var m_respawnTime : Float;
	default m_respawnTime = -1.f;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		super.OnRequestComponents( ri );
		EntityRequestComponentsInterface.RequestComponent( ri, 'interactions', 'gameinteractionsComponent', true );
		EntityRequestComponentsInterface.RequestComponent( ri, 'mesh', 'entMeshComponent', true );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		super.OnTakeControl( ri );
		m_interactionComponent = ( ( InteractionComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'interactions' ) ) );
		m_meshComponent = ( ( MeshComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'mesh' ) ) );
	}

	protected event OnGameAttached()
	{
		var choice : InteractionChoice;
		super.OnGameAttached();
		choice.choiceMetaData.tweakDBName = "PickUp";
		m_interactionComponent.SetSingleChoice( choice );
	}

	protected event OnInteractionChoiceEvent( evt : InteractionChoiceEvent )
	{
		var muppetPtr : weak< Muppet >;
		if( evt.actionType == gameinputActionType.BUTTON_PRESSED )
		{
			muppetPtr = ( ( Muppet )( evt.activator ) );
			if( !( ( muppetPtr && ( muppetPtr.GetItemQuantity( GetItemIDToEquip() ) <= 0 ) ) ) && ( GameInstance.GetTransactionSystem( GetGame() ).GetItemQuantity( evt.activator, GetItemIDToEquip() ) >= 1 ) )
			{
				return false;
			}
			EquipItem( evt.activator );
			if( m_disappearAfterEquip )
			{
				m_interactionComponent.Toggle( false );
				m_meshComponent.Toggle( false );
				if( m_respawnTime > 0.0 )
				{
					GameInstance.GetDelaySystem( GetGame() ).DelayEvent( this, new RespawnHealthConsumable, m_respawnTime );
				}
			}
		}
	}

	protected event OnTurnOn( evt : RespawnHealthConsumable )
	{
		m_interactionComponent.Toggle( true );
		m_meshComponent.Toggle( true );
	}

}

