class piercingGrenade extends BaseProjectile
{
	private editable var m_piercingEffect : EffectRef;
	private editable var m_pierceTime : Float;
	private editable var m_energyLossFactor : Float;
	private editable var m_startVelocity : Float;
	private editable var m_grenadeLifetime : Float;
	private editable var m_gravitySimulation : Float;
	private var m_trailEffectName : CName;
	default m_trailEffectName = 'trail';
	private var m_alive : Bool;
	default m_alive = true;

	protected event OnProjectileInitialize( eventData : gameprojectileSetUpEvent )
	{
		StartTrailEffect();
		m_projectileComponent.SetEnergyLossFactor( m_energyLossFactor, 0.05 );
	}

	private function StartTrailEffect()
	{
		var spawnEffectEvent : entSpawnEffectEvent;
		spawnEffectEvent = new entSpawnEffectEvent;
		spawnEffectEvent.effectName = m_trailEffectName;
		QueueEvent( ( ( Event )( spawnEffectEvent ) ) );
	}

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

	protected event OnShootTarget( eventData : gameprojectileShootTargetEvent )
	{
		if( m_alive )
		{
			Explode( eventData.startPoint );
			Release();
			m_alive = false;
		}
	}

	protected event OnTick( eventData : gameprojectileTickEvent ) {}

	protected event OnCollision( eventData : gameprojectileHitEvent )
	{
		var target : GameObject;
		var evt : gameprojectileShootTargetEvent;
		var hitInstance : gameprojectileHitInstance;
		hitInstance = eventData.hitInstances[ 0 ];
		target = ( ( GameObject )( hitInstance.hitObject ) );
		if( ( ( gamePuppet )( target ) ) )
		{
			Pierce( hitInstance.position );
		}
		else
		{
			evt = new gameprojectileShootTargetEvent;
			evt.startPoint = hitInstance.position;
			GameInstance.GetDelaySystem( GetGame() ).DelayEvent( this, evt, m_pierceTime );
			StopMovement();
		}
	}

	private function Explode( position : Vector4 )
	{
		var explosionEffect : EffectInstance;
		explosionEffect = m_projectileComponent.GetGameEffectInstance();
		EffectData.SetVector( explosionEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.position, position );
		explosionEffect.Run();
	}

	private function Pierce( position : Vector4 )
	{
		var piercingEffect : EffectInstance;
		piercingEffect = GameInstance.GetGameEffectSystem( GetGame() ).CreateEffect( m_piercingEffect, GameInstance.GetPlayerSystem( GetGame() ).GetLocalPlayerMainGameObject(), this );
		EffectData.SetVector( piercingEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.position, position );
		piercingEffect.Run();
	}

	private function StopMovement()
	{
		m_projectileComponent.ClearTrajectories();
	}

}

