class StatBonusFromFactEffector extends Effector
{
	var m_applicationTarget : CName;
	var m_stat : Stat_Record;
	var m_bonusPerStack : Float;
	var m_fact : CName;
	var m_modifier : gameConstantStatModifierData;

	protected export override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		m_stat = TweakDBInterface.GetStatRecord( TweakDBInterface.GetForeignKeyDefault( record + T".targetStat" ) );
		m_bonusPerStack = TweakDBInterface.GetFloat( record + T".bonusPerStack", 0.0 );
		m_applicationTarget = TweakDBInterface.GetCName( record + T".applicationTarget", '' );
		m_fact = TweakDBInterface.GetCName( record + T".fact", '' );
		m_modifier = ( ( gameConstantStatModifierData )( RPGManager.CreateStatModifier( m_stat.StatType(), gameStatModifierType.Additive, 0.0 ) ) );
	}

	protected export override function ActionOn( owner : GameObject )
	{
		var targetID : EntityID;
		var stack : Int32;
		if( !( GetApplicationTarget( owner, m_applicationTarget, targetID ) ) )
		{
			return;
		}
		stack = GameInstance.GetQuestsSystem( GetGameInstance() ).GetFact( m_fact );
		m_modifier.value = ( ( Float )( stack ) ) * m_bonusPerStack;
		GameInstance.GetStatsSystem( owner.GetGame() ).AddModifier( targetID, m_modifier );
	}

	protected export override function ActionOff( owner : GameObject )
	{
		var targetID : EntityID;
		if( !( GetApplicationTarget( owner, m_applicationTarget, targetID ) ) )
		{
			return;
		}
		GameInstance.GetStatsSystem( owner.GetGame() ).RemoveModifier( targetID, m_modifier );
	}

	protected export override function RepeatedAction( owner : GameObject )
	{
		var targetID : EntityID;
		var stack : Int32;
		if( !( GetApplicationTarget( owner, m_applicationTarget, targetID ) ) )
		{
			return;
		}
		stack = GameInstance.GetQuestsSystem( GetGameInstance() ).GetFact( m_fact );
		GameInstance.GetStatsSystem( owner.GetGame() ).RemoveModifier( targetID, m_modifier );
		m_modifier.value = ( ( Float )( stack ) ) * m_bonusPerStack;
		GameInstance.GetStatsSystem( owner.GetGame() ).AddModifier( targetID, m_modifier );
	}

}

