// CBTTaskWasInCriticalState
// copyrajt orajt - W. Żerek

class CBTTaskWasInCriticalState extends IBehTreeTask
{
	var timeDifference : float;
	var maxTimeDifference : float;
	var criticalState : ECriticalStateType;
	var timeOfLastCSDeactivation : float;

	private var storageHandler : CAIStorageHandler;
	protected var combatDataStorage : CBaseAICombatStorage;
	
	function IsAvailable() : bool
	{
		InitializeCombatDataStorage();
		timeOfLastCSDeactivation = combatDataStorage.GetTimeOfLastCSDeactivation( criticalState );
		
		if( timeOfLastCSDeactivation )
		{
			timeDifference = GetLocalTime() - timeOfLastCSDeactivation;
			
			if( timeDifference < maxTimeDifference )
			{
				return true;
			}
			
			return false;
		}
		else
		{
			return false;
		}
	}
	
	function InitializeCombatDataStorage()
	{
		if ( !combatDataStorage )
		{
			storageHandler = InitializeCombatStorage();
			combatDataStorage = (CBaseAICombatStorage)storageHandler.Get();
		}
	}
}

class CBTTaskWasInCriticalStateDef extends IBehTreeTaskDefinition
{
	default instanceClass = 'CBTTaskWasInCriticalState';

	editable var maxTimeDifference : float;
	editable var criticalState : ECriticalStateType;
	
	default maxTimeDifference = 5;
	default criticalState = ECST_BurnCritical;
}