class EffectPreAction_PreAttack extends EffectPreAction_Scripted
{
	protected editable var m_withFriendlyFire : Bool;
	default m_withFriendlyFire = false;
	protected editable var m_withSelfDamage : Bool;
	default m_withSelfDamage = false;

	public export const function Process( ctx : EffectScriptContext )
	{
		var i : Int32;
		var data : AttackData;
		var tempVariant : Variant;
		var newFlags : array< SHitFlag >;
		var effects : array< SHitStatusEffect >;
		var attackSource : IAttack;
		var TEMP_recordFlags : array< String >;
		var tempFlag : hitFlag;
		var attackPosition : Vector4;
		var weaponObject : WeaponObject;
		var weaponCharge : Float;
		var randRoll : Float;
		data = new AttackData;
		data.SetInstigator( ( ( GameObject )( EffectScriptContext.GetInstigator( ctx ) ) ) );
		data.SetSource( ( ( GameObject )( EffectScriptContext.GetSource( ctx ) ) ) );
		if( EffectData.GetFloat( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.randRoll, randRoll ) )
		{
			data.SetRandRoll( randRoll );
		}
		if( EffectData.GetVector( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.position, attackPosition ) )
		{
			data.SetAttackPosition( attackPosition );
		}
		if( EffectData.GetVariant( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.attack, tempVariant ) )
		{
			attackSource = ( ( IAttack )tempVariant );
			if( !( attackSource ) )
			{
				attackSource = ( ( Attack_GameEffect )tempVariant );
			}
			if( !( attackSource ) )
			{
				attackSource = ( ( Attack_Projectile )tempVariant );
			}
			if( !( attackSource ) )
			{
				attackSource = ( ( Attack_Continuous )tempVariant );
			}
		}
		if( EffectData.GetFloat( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.charge, weaponCharge ) )
		{
			data.SetWeaponCharge( weaponCharge );
		}
		weaponObject = ( ( WeaponObject )( EffectScriptContext.GetWeapon( ctx ) ) );
		if( weaponObject )
		{
			data.SetWeapon( weaponObject );
			data.SetTriggerMode( weaponObject.GetCurrentTriggerMode().Type() );
		}
		if( attackSource )
		{
			data.SetAttackDefinition( attackSource );
		}
		else if( weaponObject )
		{
			data.SetAttackDefinition( weaponObject.GetCurrentAttack() );
		}
		TEMP_recordFlags = data.GetAttackDefinition().GetRecord().HitFlags();
		for( i = 0; i < TEMP_recordFlags.Size(); i += 1 )
		{
			tempFlag = ( ( hitFlag )( ( ( Int32 )( EnumValueFromString( "hitFlag", TEMP_recordFlags[ i ] ) ) ) ) );
			if( ( ( Int32 )( tempFlag ) ) > -1 )
			{
				data.AddFlag( tempFlag, 'PreAttack' );
			}
		}
		EffectData.GetVariant( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.flags, tempVariant );
		if( tempVariant.IsValid() )
		{
			newFlags = ( ( array< SHitFlag > )tempVariant );
		}
		for( i = 0; i < newFlags.Size(); i += 1 )
		{
			data.AddFlag( newFlags[ i ].flag, 'PreAttack' );
		}
		if( m_withFriendlyFire )
		{
			data.AddFlag( hitFlag.FriendlyFire, 'PreAttack' );
		}
		if( m_withSelfDamage )
		{
			data.AddFlag( hitFlag.CanDamageSelf, 'PreAttack' );
		}
		if( EffectData.GetVariant( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.statusEffect, tempVariant ) )
		{
			effects = ( ( array< SHitStatusEffect > )tempVariant );
		}
		for( i = 0; i < effects.Size(); i += 1 )
		{
			data.AddStatusEffect( effects[ i ].id, effects[ i ].stacks );
		}
		data.SetAttackTime( EngineTime.ToFloat( GameInstance.GetTimeSystem( EffectScriptContext.GetGameInstance( ctx ) ).GetSimTime() ) );
		data.PreAttack();
		EffectData.SetVariant( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.attackData, data );
	}

}

class EffectPreAction_PreAttack_WithFriendlyFire extends EffectPreAction_PreAttack
{
	default m_withFriendlyFire = true;
	default m_withSelfDamage = true;
}

