class ShardCaseContainerPS extends gameLootContainerBasePS
{
	default m_markAsQuest = true;
}

class ShardCaseContainer extends ContainerObjectSingleItem
{
	var m_wasOpened : Bool;
	var m_shardMesh : MeshComponent;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		EntityRequestComponentsInterface.RequestComponent( ri, 'shard', 'MeshComponent', false );
		EntityRequestComponentsInterface.RequestComponent( ri, 'vision', 'gameVisionModeComponent', false );
		EntityRequestComponentsInterface.RequestComponent( ri, 'scanning', 'gameScanningComponent', false );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		m_shardMesh = ( ( MeshComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'shard' ) ) );
		m_visionComponent = ( ( VisionModeComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'vision' ) ) );
		m_scanningComponent = ( ( ScanningComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'scanning' ) ) );
	}

	protected event OnInteraction( choiceEvent : InteractionChoiceEvent )
	{
		var lootActionWrapper : LootChoiceActionWrapper;
		var evt : ShardCaseAnimationEnded;
		lootActionWrapper = LootChoiceActionWrapper.Unwrap( choiceEvent );
		if( LootChoiceActionWrapper.IsValid( lootActionWrapper ) )
		{
			if( !( m_wasOpened ) )
			{
				OpenContainerWithTransformAnimation();
				m_wasOpened = true;
			}
			if( lootActionWrapper.action != 'Take' )
			{
				evt = new ShardCaseAnimationEnded;
				evt.activator = choiceEvent.activator;
				evt.item = lootActionWrapper.itemId;
				if( lootActionWrapper.action == 'Read' )
				{
					evt.read = true;
				}
				GameInstance.GetDelaySystem( GetGame() ).DelayEvent( this, evt, 0.55000001 );
			}
		}
	}

	protected event OnShardCaseAnimationEnded( evt : ShardCaseAnimationEnded )
	{
		m_shardMesh.Toggle( false );
		if( evt.read )
		{
			ItemActionsHelper.ReadItem( evt.activator, evt.item );
		}
	}

	public const override function IsShardContainer() : Bool
	{
		return true;
	}

	public function IsShardRead() : Bool
	{
		return UIItemsHelper.IsShardRead( itemTDBID, GetGame() );
	}

}

class ShardCaseAnimationEnded extends Event
{
	var activator : weak< GameObject >;
	var item : ItemID;
	var read : Bool;
}

