class DisassemblableComponent extends ScriptableComponent
{
	private var disassembled : Bool;
	default disassembled = false;
	private var disassembleTargetRequesters : array< weak< GameObject > >;

	protected export function OnGameAttach() {}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface ) {}

	protected export function OnGameDetach() {}

	protected function OnUpdate( deltaTime : Float ) {}

	public const function ObtainParts()
	{
		var player : PlayerPuppet;
		var trans : TransactionSystem;
		player = ( ( PlayerPuppet )( GetPlayerSystem().GetLocalPlayerMainGameObject() ) );
		RPGManager.GiveScavengeReward( player.GetGame(), T"RPGActionRewards.ExtractParts", GetOwner().GetEntityID() );
		trans = GetTransactionSystem();
		GameInstance.GetActivityLogSystem( player.GetGame() ).AddLog( ( "Device disassembled. You now have " + ( ( String )( trans.GetItemQuantity( player, ItemID.CreateQuery( T"Items.parts" ) ) ) ) ) + " parts." );
	}

	protected event OnTargetRequested( evt : DisassembleTargetRequest )
	{
		var scavengeTargetEvent : ScavengeTargetConfirmEvent;
		if( !( disassembled ) )
		{
			scavengeTargetEvent = new ScavengeTargetConfirmEvent;
			scavengeTargetEvent.target = GetOwner();
			evt.requester.QueueEvent( scavengeTargetEvent );
			if( !( disassembleTargetRequesters.Contains( evt.requester ) ) )
			{
				disassembleTargetRequesters.PushBack( evt.requester );
			}
		}
	}

	protected event OnDisassembled( evt : DisassembleEvent )
	{
		var i : Int32;
		var targetScavengedEvent : TargetScavengedEvent;
		if( !( disassembled ) )
		{
			ObtainParts();
			disassembled = true;
			for( i = disassembleTargetRequesters.Size() - 1; i >= 0; i -= 1 )
			{
				targetScavengedEvent = new TargetScavengedEvent;
				targetScavengedEvent.target = GetOwner();
				disassembleTargetRequesters[ i ].QueueEvent( targetScavengedEvent );
				disassembleTargetRequesters.Erase( i );
			}
		}
	}

}

class DisassembleTargetRequest extends Event
{
	var requester : weak< GameObject >;
}

class DisassembleEvent extends Event
{
}

