class ConstantStatPoolPrereqListener extends BaseStatPoolPrereqListener
{
	protected var m_state : weak< ConstantStatPoolPrereqState >;

	protected event OnStatPoolValueReached( oldValue : Float, newValue : Float, percToPoints : Float )
	{
		m_state.StatPoolUpdate( oldValue, newValue );
	}

	public export override function OnStatPoolValueChanged( oldValue : Float, newValue : Float, percToPoints : Float )
	{
		if( m_state.m_listenConstantly )
		{
			m_state.StatPoolConstantUpdate( oldValue, newValue, percToPoints );
		}
	}

	public override function RegisterState( state : PrereqState )
	{
		m_state = ( ( ConstantStatPoolPrereqState )( state ) );
	}

}

class ConstantStatPoolPrereqState extends StatPoolPrereqState
{
	var m_listenConstantly : Bool;

	public function StatPoolConstantUpdate( oldValue : Float, newValue : Float, percToPoints : Float )
	{
		var checkPassed : Bool;
		var currentState : Bool;
		const var prereq : ConstantStatPoolPrereq;
		var valueToCheck : Float;
		prereq = ( ( ConstantStatPoolPrereq )( GetPrereq() ) );
		valueToCheck = RPGManager.CalculateStatModifiers( prereq.m_valueToCheck, m_object.GetGame(), m_object, m_statsObjID );
		if( !( prereq.m_comparePercentage ) )
		{
			newValue *= percToPoints;
		}
		checkPassed = ProcessCompare( prereq.m_comparisonType, newValue, valueToCheck );
		currentState = IsFulfilled();
		if( currentState != checkPassed )
		{
			OnChanged( checkPassed );
		}
	}

	public override function RegisterStatPoolListener( game : GameInstance, statPoolType : gamedataStatPoolType, valueToCheck : Float )
	{
		if( StatsObjectID.IsDefined( m_statsObjID ) )
		{
			m_statPoolListener = new ConstantStatPoolPrereqListener;
			m_statPoolListener.RegisterState( this );
			m_statPoolListener.SetValue( valueToCheck );
			GameInstance.GetStatPoolsSystem( game ).RequestRegisteringListener( m_statsObjID, statPoolType, m_statPoolListener );
		}
	}

}

class ConstantStatPoolPrereq extends StatPoolPrereq
{

	protected export const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var owner : GameObject;
		var castedState : ConstantStatPoolPrereqState;
		owner = ( ( GameObject )( context ) );
		castedState = ( ( ConstantStatPoolPrereqState )( state ) );
		castedState.m_object = GetObject( owner );
		castedState.m_statsObjID = GetStatsObjectID( owner );
		castedState.m_listenConstantly = true;
		castedState.RegisterStatPoolListener( game, m_statPoolType, GetValueToCheck( castedState ) );
		return false;
	}

}

