class ModifyCritWithDistance extends ModifyAttackEffector
{
	var m_critChanceBonus : Float;
	var m_minDistance : Float;
	var m_maxDistance : Float;
	var m_improveWithDistance : Bool;

	protected override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		m_critChanceBonus = TweakDBInterface.GetFloat( record + T".critChanceBonus", 0.0 );
		m_minDistance = TweakDBInterface.GetFloat( record + T".minDistance", 0.0 );
		m_maxDistance = TweakDBInterface.GetFloat( record + T".maxDistance", 0.0 );
		m_improveWithDistance = TweakDBInterface.GetBool( record + T".improveWithDistance", false );
	}

	protected override function Uninitialize( game : GameInstance ) {}

	protected override function RepeatedAction( owner : GameObject )
	{
		var hitEvent : gameHitEvent;
		var coveredDistance, adjustedDistance, distanceDelta, critChanceValue : Float;
		distanceDelta = m_maxDistance - m_minDistance;
		if( distanceDelta < 0.0 )
		{
			return;
		}
		hitEvent = GetHitEvent();
		if( !( hitEvent ) )
		{
			return;
		}
		coveredDistance = MinF( Vector4.Distance( hitEvent.attackData.GetAttackPosition(), hitEvent.target.GetWorldPosition() ), m_maxDistance );
		adjustedDistance = MaxF( coveredDistance - m_minDistance, 0.0 );
		if( m_improveWithDistance )
		{
			if( coveredDistance < m_minDistance )
			{
				return;
			}
			critChanceValue = ( ( distanceDelta > 0.0 ) ? ( ( adjustedDistance / distanceDelta ) * m_critChanceBonus ) : ( m_critChanceBonus ) );
		}
		else
		{
			if( coveredDistance >= m_maxDistance )
			{
				return;
			}
			critChanceValue = ( ( distanceDelta > 0.0 ) ? ( m_critChanceBonus * ( 1.0 - ( adjustedDistance / distanceDelta ) ) ) : ( m_critChanceBonus ) );
		}
		hitEvent.attackData.SetAdditionalCritChance( critChanceValue );
	}

}

