class ThrowableWeaponObject extends WeaponObject
{
	protected var m_projectileComponent : ProjectileComponent;
	protected var m_weaponOwner : weak< GameObject >;

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

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		m_projectileComponent = ( ( ProjectileComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'projectileComponent' ) ) );
		if( m_projectileComponent )
		{
			m_projectileComponent.SetEnergyLossFactor( 0.0, 0.0 );
			m_projectileComponent.SetCollisionEvaluator( new WeaponCollisionEvaluator );
		}
	}

	protected event OnProjectileInitialize( eventData : gameprojectileSetUpEvent )
	{
		m_weaponOwner = eventData.owner;
		AnimationControllerComponent.PushEventToReplicate( this, 'Throw' );
	}

	protected event OnShoot( eventData : gameprojectileShootEvent )
	{
		OnThrow( eventData );
	}

	protected event OnShootTarget( eventData : gameprojectileShootTargetEvent )
	{
		OnThrow( eventData );
	}

	private function OnThrow( eventData : gameprojectileShootEvent )
	{
		var fxResource : FxResource;
		var worldTransform : WorldTransform;
		var throwDirectionOnGround : Vector4;
		fxResource = GetFxPackage().GetVfxGroundThrow();
		if( FxResource.IsValid( fxResource ) )
		{
			WorldTransform.SetPosition( worldTransform, eventData.startPoint );
			throwDirectionOnGround = eventData.startVelocity;
			throwDirectionOnGround = Matrix.GetDirectionVector( eventData.localToWorld );
			throwDirectionOnGround.Z = 0.0;
			WorldTransform.SetOrientationFromDir( worldTransform, throwDirectionOnGround );
			GameInstance.GetFxSystem( GetGame() ).SpawnEffectOnGround( fxResource, worldTransform, 10.0 );
		}
	}

	protected event OnCollision( eventData : gameprojectileHitEvent )
	{
		var attackRecord : Attack_Record;
		AnimationControllerComponent.PushEventToReplicate( this, 'Reset' );
		if( !( m_weaponOwner ) )
		{
			return false;
		}
		if( eventData.hitInstances[ 0 ].hitObject )
		{
			attackRecord = TweakDBInterface.GetAttackRecord( T"NPCAttacks.StrongThrowImpact" );
			ProjectileGameEffectHelper.RunEffectFromAttack( m_weaponOwner, m_weaponOwner, this, attackRecord, eventData );
		}
		else
		{
			GameObjectEffectHelper.StartEffectEvent( this, 'imp_concrete' );
		}
	}

	protected event OnTick( eventData : gameprojectileTickEvent ) {}
}

class WeaponCollisionEvaluator extends gameprojectileScriptCollisionEvaluator
{

	protected override function EvaluateCollision( defaultOnCollisionAction : gameprojectileOnCollisionAction, params : CollisionEvaluatorParams ) : gameprojectileOnCollisionAction
	{
		if( !( params.target ) )
		{
			return gameprojectileOnCollisionAction.Stop;
		}
		return gameprojectileOnCollisionAction.None;
	}

}

