class sampleBulletGeneric extends BaseProjectile
{
	private var m_meshComponent : IComponent;
	private var m_damage : EffectInstance;
	private var m_countTime : Float;
	private editable var m_startVelocity : Float;
	private editable var m_lifetime : Float;
	private var m_alive : Bool;
	default m_alive = true;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		super.OnRequestComponents( ri );
		EntityRequestComponentsInterface.RequestComponent( ri, 'MeshComponent', 'IComponent', true );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		super.OnTakeControl( ri );
		m_meshComponent = EntityResolveComponentsInterface.GetComponent( ri, 'MeshComponent' );
	}

	private function Reset()
	{
		m_countTime = 0.0;
		m_alive = true;
		m_meshComponent.Toggle( true );
	}

	protected event OnProjectileInitialize( eventData : gameprojectileSetUpEvent )
	{
		var linearParams : LinearTrajectoryParams;
		linearParams = new LinearTrajectoryParams;
		super.OnProjectileInitialize( eventData );
		linearParams.startVel = m_startVelocity;
		m_projectileComponent.AddLinear( linearParams );
	}

	private function StartTrailEffect()
	{
		m_projectileComponent.SpawnTrailVFX();
		GameObject.PlaySoundEvent( this, 'Time_Dilation_Bullet_Trails_bullets_normal' );
	}

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

	protected event OnShootTarget( eventData : gameprojectileShootTargetEvent )
	{
		Reset();
		StartTrailEffect();
	}

	protected event OnTick( eventData : gameprojectileTickEvent )
	{
		m_countTime += eventData.deltaTime;
		if( ( m_countTime > m_lifetime ) || !( m_alive ) )
		{
			Release();
		}
	}

	protected event OnCollision( projectileHitEvent : gameprojectileHitEvent )
	{
		var object : GameObject;
		var explosionAttack : Attack_GameEffect;
		var explosionEffect : EffectInstance;
		var attackContext : AttackInitContext;
		var statMods : array< gameStatModifierData >;
		var damageHitEvent : gameprojectileHitEvent;
		var hitInstance : gameprojectileHitInstance;
		var i : Int32;
		damageHitEvent = new gameprojectileHitEvent;
		if( m_alive )
		{
			attackContext.source = this;
			attackContext.record = TweakDBInterface.GetAttackRecord( T"Attacks.REMOVE_BulletWithDamage" );
			attackContext.instigator = m_user;
			explosionAttack = ( ( Attack_GameEffect )( IAttack.Create( attackContext ) ) );
			explosionEffect = explosionAttack.PrepareAttack( m_user );
			explosionAttack.GetStatModList( statMods );
			EffectData.SetVariant( explosionEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.attack, ( ( IAttack )( explosionAttack ) ) );
			EffectData.SetVariant( explosionEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.attackStatModList, statMods );
		}
		for( i = 0; i < projectileHitEvent.hitInstances.Size(); i += 1 )
		{
			hitInstance = projectileHitEvent.hitInstances[ i ];
			object = ( ( GameObject )( hitInstance.hitObject ) );
			if( m_alive )
			{
				damageHitEvent.hitInstances.PushBack( hitInstance );
				if( !( object.HasTag( 'bullet_no_destroy' ) ) )
				{
					m_countTime = 0.0;
					m_alive = false;
					m_meshComponent.Toggle( false );
					m_projectileComponent.ClearTrajectories();
					break;
				}
			}
		}
		if( damageHitEvent.hitInstances.Size() > 0 )
		{
			EffectData.SetVariant( explosionEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.projectileHitEvent, damageHitEvent );
			explosionAttack.StartAttack();
		}
	}

}

