class TankTurretComponent extends ScriptableComponent
{
	[ customEditor = "TweakDBGroupInheritance;Attack_GameEffect" ]
	editable var m_attackRecord : TweakDBID;
	editable var m_slotComponentName1 : CName;
	editable var m_slotName1 : CName;
	editable var m_slotComponentName2 : CName;
	editable var m_slotName2 : CName;
	private var m_slotComponent1 : SlotComponent;
	private var m_slotComponent2 : SlotComponent;

	public function OnGameAttach()
	{
		var owner : GameObject;
		var player : GameObject;
		owner = GetOwner();
		player = GameInstance.GetPlayerSystem( owner.GetGame() ).GetLocalPlayerMainGameObject();
		player.RegisterInputListener( this, 'ShootTertiary' );
		m_slotComponent1 = ( ( SlotComponent )( FindComponentByName( m_slotComponentName1 ) ) );
		m_slotComponent2 = ( ( SlotComponent )( FindComponentByName( m_slotComponentName2 ) ) );
	}

	protected event OnAction( action : ListenerAction, consumer : ListenerActionConsumer )
	{
		if( m_slotComponent1 )
		{
			Shoot( m_slotComponent1, m_slotName1 );
		}
		if( m_slotComponent2 )
		{
			Shoot( m_slotComponent2, m_slotName2 );
		}
	}

	private function Shoot( slotComponent : SlotComponent, slotName : CName )
	{
		var attack : Attack_GameEffect;
		var attackContext : AttackInitContext;
		var statMods : array< gameStatModifierData >;
		var position : Vector4;
		var forward : Vector4;
		var slotTransform : WorldTransform;
		var effect : EffectInstance;
		var validSlotPosition : Bool;
		validSlotPosition = slotComponent.GetSlotTransform( slotName, slotTransform );
		GameInstance.GetTargetingSystem( GetOwner().GetGame() ).GetDefaultCrosshairData( GameInstance.GetPlayerSystem( GetOwner().GetGame() ).GetLocalPlayerMainGameObject(), position, forward );
		if( validSlotPosition )
		{
			position = WorldPosition.ToVector4( WorldTransform.GetWorldPosition( slotTransform ) );
		}
		else
		{
			position = WorldPosition.ToVector4( WorldTransform.GetWorldPosition( GetEntity().GetWorldTransform() ) );
		}
		attackContext.source = GetOwner();
		attackContext.record = TweakDBInterface.GetAttackRecord( m_attackRecord );
		attackContext.instigator = attackContext.source;
		attack = ( ( Attack_GameEffect )( IAttack.Create( attackContext ) ) );
		attack.GetStatModList( statMods );
		effect = attack.PrepareAttack( GetOwner() );
		EffectData.SetVector( effect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.position, position );
		EffectData.SetVector( effect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.muzzlePosition, position );
		EffectData.SetVector( effect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.forward, forward );
		EffectData.SetVariant( effect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.attack, ( ( IAttack )( attack ) ) );
		EffectData.SetVariant( effect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.attackStatModList, statMods );
		attack.StartAttack();
	}

}

class TankTurret extends WeakspotObject
{

	protected event OnWeakspotInitialized() {}
}

