class ConsecutiveHitsPrereqCondition extends BaseHitPrereqCondition
{
	private var m_timeOut : Float;
	private var m_consecutiveHitsRequired : Int32;
	private var m_uniqueTarget : Bool;
	private var m_consecutiveHits : Int32;
	default m_consecutiveHits = 0;
	private var m_lastTargetID : EntityID;
	private var m_lastHitTime : Float;
	default m_lastHitTime = -1.0f;

	public override function SetData( recordID : TweakDBID )
	{
		super.SetData( recordID );
		m_timeOut = TweakDBInterface.GetFloat( recordID + T".timeOut", 0.0 );
		m_consecutiveHitsRequired = TweakDBInterface.GetInt( recordID + T".consecutiveHitsRequired", 1 );
		m_uniqueTarget = TweakDBInterface.GetBool( recordID + T".uniqueTarget", false );
	}

	public override function Evaluate( hitEvent : gameHitEvent ) : Bool
	{
		var result : Bool;
		var targetID : EntityID;
		var attackTime : Float;
		result = false;
		targetID = hitEvent.target.GetEntityID();
		attackTime = hitEvent.attackData.GetAttackTime();
		if( m_lastHitTime == -1.0 )
		{
			m_lastHitTime = attackTime;
		}
		if( ( attackTime - m_lastHitTime ) > m_timeOut )
		{
			m_consecutiveHits = 0;
		}
		if( !( EntityID.IsDefined( m_lastTargetID ) ) )
		{
			m_lastTargetID = targetID;
		}
		if( m_uniqueTarget )
		{
			if( targetID == m_lastTargetID )
			{
				m_consecutiveHits += 1;
			}
			else
			{
				m_consecutiveHits = 1;
			}
		}
		else
		{
			m_consecutiveHits += 1;
		}
		m_lastTargetID = targetID;
		m_lastHitTime = attackTime;
		result = ( m_consecutiveHits % m_consecutiveHitsRequired ) == 0;
		return result != m_invert;
	}

	public override function OnMissTriggered( missEvent : gameMissEvent )
	{
		m_consecutiveHits = 0;
		m_lastHitTime = -1.0;
		m_lastTargetID = EMPTY_ENTITY_ID();
	}

}

