class PlayerCombatStateTimePrereqState extends PrereqState
{
	var m_owner : weak< GameObject >;
	var m_listener : CallbackHandle;

	protected event OnStateUpdate( value : Float )
	{
		var checkPassed : Bool;
		const var prereq : PlayerCombatStateTimePrereq;
		prereq = ( ( PlayerCombatStateTimePrereq )( GetPrereq() ) );
		checkPassed = prereq.Evaluate( m_owner, value );
		OnChanged( checkPassed );
	}

}

class PlayerCombatStateTimePrereq extends IScriptablePrereq
{
	private var m_minTime : Float;
	default m_minTime = -1.f;
	private var m_maxTime : Float;
	default m_maxTime = -1.f;

	public const function Evaluate( owner : GameObject, value : Float ) : Bool
	{
		var minCheck : Bool;
		var maxCheck : Bool;
		minCheck = false;
		maxCheck = false;
		minCheck = ( m_minTime < 0.0 ) || ( value >= m_minTime );
		maxCheck = ( m_maxTime < 0.0 ) || ( value < m_maxTime );
		return minCheck && maxCheck;
	}

	protected override function Initialize( recordID : TweakDBID )
	{
		m_minTime = TweakDBInterface.GetFloat( recordID + T".minTime", -1.0 );
		m_maxTime = TweakDBInterface.GetFloat( recordID + T".maxTime", -1.0 );
	}

	protected const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var bb : IBlackboard;
		var castedState : PlayerCombatStateTimePrereqState;
		var player : weak< PlayerPuppet >;
		castedState = ( ( PlayerCombatStateTimePrereqState )( state ) );
		castedState.m_owner = ( ( GameObject )( context ) );
		player = ( ( PlayerPuppet )( context ) );
		if( player )
		{
			bb = GameInstance.GetBlackboardSystem( player.GetGame() ).Get( GetAllBlackboardDefs().PlayerPerkData );
			castedState.m_listener = bb.RegisterListenerFloat( GetAllBlackboardDefs().PlayerPerkData.CombatStateTime, castedState, 'OnStateUpdate' );
		}
		return false;
	}

	protected const override function OnUnregister( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var bb : IBlackboard;
		var castedState : PlayerCombatStateTimePrereqState;
		var player : weak< PlayerPuppet >;
		player = ( ( PlayerPuppet )( context ) );
		if( player )
		{
			bb = GameInstance.GetBlackboardSystem( player.GetGame() ).Get( GetAllBlackboardDefs().PlayerPerkData );
			castedState = ( ( PlayerCombatStateTimePrereqState )( state ) );
			bb.UnregisterListenerFloat( GetAllBlackboardDefs().PlayerPerkData.CombatStateTime, castedState.m_listener );
		}
	}

	protected const override function OnApplied( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var player : weak< PlayerPuppet >;
		var castedState : PlayerCombatStateTimePrereqState;
		player = ( ( PlayerPuppet )( context ) );
		if( player )
		{
			castedState = ( ( PlayerCombatStateTimePrereqState )( state ) );
			castedState.OnChanged( IsFulfilled( player.GetGame(), context ) );
		}
	}

	protected const override function IsFulfilled( game : GameInstance, context : IScriptable ) : Bool
	{
		var bb : IBlackboard;
		var player : weak< PlayerPuppet >;
		var checkPassed : Bool;
		player = ( ( PlayerPuppet )( context ) );
		bb = GameInstance.GetBlackboardSystem( player.GetGame() ).Get( GetAllBlackboardDefs().PlayerPerkData );
		checkPassed = Evaluate( player, bb.GetFloat( GetAllBlackboardDefs().PlayerPerkData.CombatStateTime ) );
		return checkPassed;
	}

}

