class ModifyStatPoolCustomLimitEffector extends Effector
{
	var m_statPoolType : gamedataStatPoolType;
	var m_value : Float;
	var m_usePercent : Bool;
	var m_previousLimit : Float;
	var m_owner : weak< GameObject >;

	protected export override function Initialize( recordID : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		var record : ModifyStatPoolCustomLimitEffector_Record;
		record = TweakDBInterface.GetModifyStatPoolCustomLimitEffectorRecord( recordID );
		m_statPoolType = record.StatPoolType().StatPoolType();
		m_value = record.Value();
		m_usePercent = record.UsePercent();
	}

	protected export override function Uninitialize( game : GameInstance )
	{
		UninitializeEffector( game );
	}

	protected export override function ActionOn( owner : GameObject )
	{
		ProcessEffector( owner );
	}

	protected export override function RepeatedAction( owner : GameObject )
	{
		ProcessEffector( owner );
	}

	protected export override function ActionOff( owner : GameObject )
	{
		UninitializeEffector( owner.GetGame() );
	}

	private function ProcessEffector( owner : GameObject )
	{
		var statPoolsSystem : StatPoolsSystem;
		statPoolsSystem = GameInstance.GetStatPoolsSystem( owner.GetGame() );
		m_owner = owner;
		m_previousLimit = statPoolsSystem.GetStatPoolValueCustomLimit( owner.GetEntityID(), m_statPoolType, true );
		statPoolsSystem.RequestSettingStatPoolValueCustomLimit( owner.GetEntityID(), m_statPoolType, m_value, owner, m_usePercent );
	}

	private function UninitializeEffector( game : GameInstance )
	{
		var statPoolsSystem : StatPoolsSystem;
		statPoolsSystem = GameInstance.GetStatPoolsSystem( game );
		if( m_owner )
		{
			statPoolsSystem.RequestSettingStatPoolValueCustomLimit( m_owner.GetEntityID(), m_statPoolType, m_previousLimit, m_owner, m_usePercent );
		}
	}

}

