class ConsumableChargesPrereqListener extends ScriptStatPoolsListener
{
	protected var m_state : weak< ConsumableChargesPrereqState >;

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

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

}

class ConsumableChargesPrereqState extends PrereqState
{
	var m_owner : weak< PlayerPuppet >;
	var m_statPoolListener : ConsumableChargesPrereqListener;
	var m_object : weak< GameObject >;
	var m_statsObjID : StatsObjectID;

	public function StatPoolUpdate( oldValue : Float, newValue : Float )
	{
		var checkPassed : Bool;
		var currentCharges : Float;
		const var prereq : StatPoolPrereq;
		var valueToCheck : Float;
		prereq = ( ( StatPoolPrereq )( GetPrereq() ) );
		valueToCheck = RPGManager.CalculateStatModifiers( prereq.m_valueToCheck, m_owner.GetGame(), m_object, m_statsObjID );
		currentCharges = ( ( Float )( m_owner.GetHealingItemCharges() ) );
		checkPassed = ProcessCompare( prereq.m_comparisonType, currentCharges, valueToCheck );
		OnChanged( checkPassed );
	}

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

	public virtual function UnregisterStatPoolListener( game : GameInstance, statPoolType : gamedataStatPoolType )
	{
		if( m_statPoolListener )
		{
			GameInstance.GetStatPoolsSystem( game ).RequestUnregisteringListener( m_statsObjID, statPoolType, m_statPoolListener );
		}
		m_statPoolListener = NULL;
	}

}

class ConsumableChargesPrereq extends StatPoolPrereq
{

	protected export const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var owner : PlayerPuppet;
		var castedState : ConsumableChargesPrereqState;
		var valueToCheck : Float;
		owner = ( ( PlayerPuppet )( context ) );
		castedState = ( ( ConsumableChargesPrereqState )( state ) );
		valueToCheck = RPGManager.CalculateStatModifiers( m_valueToCheck, owner.GetGame(), castedState.m_object, castedState.m_statsObjID );
		castedState.m_owner = owner;
		castedState.m_statsObjID = GetStatsObjectID( owner );
		castedState.RegisterStatPoolListener( game, m_statPoolType, valueToCheck );
		return false;
	}

}

