abstract class TweakAIActionConditionAbstract extends AIbehaviorconditionScript
{
	private var m_actionRecord : weak< AIAction_Record >;
	private var m_actionDebugName : String;

	private final function Initialize( context : ScriptExecutionContext ) : Bool
	{
		var actionRecord : weak< AIAction_Record >;
		if( !( GetActionRecord( context, m_actionDebugName, actionRecord ) ) )
		{
			return false;
		}
		if( actionRecord != m_actionRecord )
		{
			m_actionRecord = actionRecord;
			if( StartInitCooldowns( context ) )
			{
				return false;
			}
		}
		return true;
	}

	private override final function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		var blackBoard : IBlackboard;
		if( !( Initialize( context ) ) )
		{
			return false;
		}
		if( ( ( AISubActionRandomize_Record )( m_actionRecord.AnimData().AnimVariationSubAction() ) ) )
		{
			blackBoard = ( ( ScriptedPuppet )( ScriptExecutionContext.GetOwner( context ) ) ).GetAIControllerComponent().GetActionBlackboard();
			if( ( ( TweakDBID )( blackBoard.GetVariant( GetAllBlackboardDefs().AIAction.ownerLastAnimVariationAction ) ) ) != m_actionRecord.GetID() )
			{
				blackBoard.SetVariant( GetAllBlackboardDefs().AIAction.ownerLastAnimVariationAction, TDBID.None() );
				blackBoard.SetBool( GetAllBlackboardDefs().AIAction.ownerCurrentAnimVariationSet, false );
			}
			if( AICondition.ActivationCheck( context, m_actionRecord ) )
			{
				blackBoard.SetVariant( GetAllBlackboardDefs().AIAction.ownerLastAnimVariationAction, m_actionRecord.GetID() );
				return true;
			}
		}
		else if( AICondition.ActivationCheck( context, m_actionRecord ) )
		{
			return true;
		}
		return false;
	}

	private override final function Activate( context : ScriptExecutionContext ) {}

	private override final function Deactivate( context : ScriptExecutionContext ) {}

	private final function StartInitCooldowns( const context : ScriptExecutionContext ) : Bool
	{
		var i : Int32;
		var count : Int32;
		var record : AIActionCooldown_Record;
		count = m_actionRecord.GetInitCooldownsCount();
		for( i = 0; i < count; i += 1 )
		{
			record = m_actionRecord.GetInitCooldownsItem( i );
			AIActionHelper.StartCooldown( ScriptExecutionContext.GetOwner( context ), record );
		}
		return count > 0;
	}

	public override function GetDescription( context : ScriptExecutionContext ) : String
	{
		return m_actionDebugName;
	}

	private virtual function GetActionRecord( const context : ScriptExecutionContext, actionDebugName : ref< String >, out actionRecord : weak< AIAction_Record > ) : Bool
	{
		return false;
	}

}

