class ModifyStatPoolModifierEffector extends Effector
{
	var m_owner : weak< GameObject >;
	var m_ownerEntityID : EntityID;
	var m_poolType : gamedataStatPoolType;
	var m_modType : gameStatPoolModificationTypes;
	var m_recordId : TweakDBID;
	var m_cachedModifier : StatPoolModifier;

	protected export override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		var poolModRecord : PoolValueModifier_Record;
		poolModRecord = TweakDBInterface.GetPoolValueModifierRecord( TweakDBInterface.GetModifyStatPoolModifierEffectorRecord( record ).PoolModifier().GetID() );
		m_recordId = poolModRecord.GetID();
		m_poolType = ( ( gamedataStatPoolType )( ( ( Int32 )( EnumValueFromString( "gamedataStatPoolType", TweakDBInterface.GetString( record + T".statPoolType", "" ) ) ) ) ) );
		m_modType = ( ( gameStatPoolModificationTypes )( ( ( Int32 )( EnumValueFromString( "gameStatPoolModificationTypes", TweakDBInterface.GetString( record + T".modificationType", "" ) ) ) ) ) );
	}

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

	protected export override function ActionOn( owner : GameObject )
	{
		var poolSys : StatPoolsSystem;
		m_owner = owner;
		m_ownerEntityID = owner.GetEntityID();
		poolSys = GameInstance.GetStatPoolsSystem( owner.GetGame() );
		poolSys.GetModifier( m_ownerEntityID, m_poolType, m_modType, m_cachedModifier );
		poolSys.RequestSettingModifierWithRecord( m_ownerEntityID, m_poolType, m_modType, m_recordId );
	}

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

	private function RevertPoolModifier( gameInstance : GameInstance )
	{
		var statPoolsSystem : StatPoolsSystem;
		statPoolsSystem = GameInstance.GetStatPoolsSystem( gameInstance );
		if( m_owner && m_owner.IsAttached() )
		{
			if( m_owner.IsPlayer() && m_poolType == gamedataStatPoolType.Health )
			{
				if( ( ( PlayerPuppet )( m_owner ) ).IsInCombat() )
				{
					statPoolsSystem.RequestSettingModifierWithRecord( m_ownerEntityID, gamedataStatPoolType.Health, gameStatPoolModificationTypes.Regeneration, T"BaseStatPools.PlayerBaseInCombatHealthRegen" );
				}
				else
				{
					statPoolsSystem.RequestSettingModifierWithRecord( m_ownerEntityID, gamedataStatPoolType.Health, gameStatPoolModificationTypes.Regeneration, T"BaseStatPools.PlayerBaseOutOfCombatHealthRegen" );
				}
			}
			else
			{
				if( m_owner.IsPlayer() && ( ( PlayerPuppet )( m_owner ) ).IsInCombat() )
				{
					statPoolsSystem.RequestSettingModifier( m_ownerEntityID, m_poolType, m_modType, m_cachedModifier );
				}
				else
				{
					statPoolsSystem.RequestResetingModifier( m_ownerEntityID, m_poolType, m_modType );
				}
			}
		}
		else
		{
			statPoolsSystem.RequestResetingModifier( m_ownerEntityID, m_poolType, m_modType );
		}
	}

}

