class ItemLootedEvent extends Event
{
}

import class ItemObject extends TimeDilatable
{
	private var m_lootQuality : gamedataQuality;
	private var m_isIconic : Bool;
	private var m_isBroken : Bool;

	public import function GetItemID() : ItemID;
	public import const function GetItemData() : weak< gameItemData >;
	public import function QueueEventToChildItems( evt : Event );
	public import function GetAnimationParameters() : array< CName >;
	public import function IsClientSideOnlyGadget() : Bool;
	public import const function IsConnectedWithDrop() : Bool;
	public import const function GetConnectedItemDrop() : weak< gameItemDropObject >;
	public import const function IsVisualSpawnAttached() : Bool;

	protected virtual function EvaluateLootQualityByTask()
	{
		GameInstance.GetDelaySystem( GetGame() ).QueueTask( this, NULL, 'EvaluateLootQualityTask', gameScriptTaskExecutionStage.Any );
	}

	protected export function EvaluateLootQualityTask( data : ScriptTaskData )
	{
		EvaluateLootQuality();
	}

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

	protected event OnVisualSpawnAttached()
	{
		var workspotSystem : WorkspotGameSystem;
		var owner : GameObject;
		m_isIconic = RPGManager.IsItemIconic( GetItemData() );
		m_isIconic = RPGManager.IsItemBroken( GetItemData() );
		if( IsContainer() )
		{
			ToggleLootHighlight( IsQuest() );
			EvaluateLootQualityByTask();
		}
		if( GetItemData().HasTag( 'WorkspotSyncAnimated' ) )
		{
			owner = GetOwner();
			if( owner )
			{
				workspotSystem = GameInstance.GetWorkspotSystem( owner.GetGame() );
				if( workspotSystem )
				{
					workspotSystem.SynchronizeItemWithOwner( this, owner );
				}
			}
		}
	}

	protected event OnItemLooted( evt : ItemLootedEvent )
	{
		var evtToSend : UnregisterAllMappinsEvent;
		evtToSend = new UnregisterAllMappinsEvent;
		QueueEvent( evtToSend );
		if( IsQuest() )
		{
			ToggleLootHighlight( false );
		}
	}

	protected event OnEvaluateLootQuality( evt : gameEvaluateLootQualityEvent )
	{
		EvaluateLootQuality();
	}

	private function EvaluateLootQuality()
	{
		m_lootQuality = RPGManager.GetItemDataQuality( GetItemData() );
		m_isIconic = m_isIconic || RPGManager.IsItemIconic( GetItemData() );
		m_isBroken = m_isBroken || RPGManager.IsItemBroken( GetItemData() );
		ToggleLootHighlight( IsQuest() );
	}

	protected const function HasValidLootQuality() : Bool
	{
		return m_lootQuality != gamedataQuality.Invalid && m_lootQuality != gamedataQuality.Random;
	}

	public const override function IsContainer() : Bool
	{
		if( GetItemData().HasTag( 'NoLootMappin' ) )
		{
			return false;
		}
		else
		{
			return IsConnectedWithDrop();
		}
	}

	public const override function GetDefaultHighlight() : FocusForcedHighlightData
	{
		var highlight : FocusForcedHighlightData;
		var outline : EFocusOutlineType;
		if( !( IsConnectedWithDrop() ) )
		{
			return NULL;
		}
		if( m_scanningComponent.IsBraindanceBlocked() || m_scanningComponent.IsPhotoModeBlocked() )
		{
			return NULL;
		}
		outline = GetCurrentOutline();
		highlight = new FocusForcedHighlightData;
		highlight.sourceID = GetEntityID();
		highlight.sourceName = GetClassName();
		highlight.priority = EPriority.Low;
		highlight.outlineType = outline;
		if( outline == EFocusOutlineType.QUEST )
		{
			highlight.highlightType = EFocusForcedHighlightType.QUEST;
		}
		else if( outline == EFocusOutlineType.ITEM )
		{
			highlight.highlightType = EFocusForcedHighlightType.ITEM;
		}
		else
		{
			highlight = NULL;
		}
		return highlight;
	}

	public const override function GetCurrentOutline() : EFocusOutlineType
	{
		var outlineType : EFocusOutlineType;
		if( IsConnectedWithDrop() )
		{
			if( IsQuest() )
			{
				outlineType = EFocusOutlineType.QUEST;
			}
			else
			{
				outlineType = EFocusOutlineType.ITEM;
			}
		}
		else
		{
			outlineType = EFocusOutlineType.INVALID;
		}
		return outlineType;
	}

	protected const override function ShouldRegisterToHUD() : Bool
	{
		if( m_forceRegisterInHudManager )
		{
			return true;
		}
		return false;
	}

	public const override function IsQuest() : Bool
	{
		return super.IsQuest() || GetItemData().HasTag( 'Quest' );
	}

	public const override function DeterminGameplayRole() : EGameplayRole
	{
		if( IsContainer() )
		{
			return EGameplayRole.Loot;
		}
		else
		{
			return EGameplayRole.None;
		}
	}

	public const override function GetIsIconic() : Bool
	{
		return m_isIconic;
	}

	public const override function GetIsBroken() : Bool
	{
		return m_isBroken;
	}

	public const override function GetLootQuality() : gamedataQuality
	{
		return m_lootQuality;
	}

	private function ToggleLootHighlight( enable : Bool )
	{
		var effectInstance : EffectInstance;
		effectInstance = GameInstance.GetGameEffectSystem( GetGame() ).CreateEffectStatic( 'loot_highlight', 'item_highlight', this );
		EffectData.SetEntity( effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.entity, this );
		EffectData.SetBool( effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.renderMaterialOverride, false );
		EffectData.SetBool( effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.enable, enable );
		effectInstance.Run();
	}

}

