class ModifyStatPoolValueEffector extends HitEventEffector
{
	var m_statPoolUpdates : array< weak< StatPoolUpdate_Record > >;
	var m_usePercent : Bool;
	var m_applicationTarget : CName;
	var m_setValue : Bool;

	protected export override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		var statPoolrecord : ModifyStatPoolValueEffector_Record;
		statPoolrecord = TweakDBInterface.GetModifyStatPoolValueEffectorRecord( record );
		statPoolrecord.StatPoolUpdates( m_statPoolUpdates );
		m_usePercent = statPoolrecord.UsePercent();
		m_applicationTarget = statPoolrecord.ApplicationTarget();
		m_setValue = statPoolrecord.SetValue();
	}

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

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

	protected function ProcessEffector( owner : GameObject )
	{
		var poolSys : StatPoolsSystem;
		var statPoolType : gamedataStatPoolType;
		var statPoolValue : Float;
		var i : Int32;
		var applicationTargetID : EntityID;
		if( !( GetApplicationTarget( owner, m_applicationTarget, applicationTargetID ) ) )
		{
			return;
		}
		poolSys = GameInstance.GetStatPoolsSystem( owner.GetGame() );
		for( i = 0; i < m_statPoolUpdates.Size(); i += 1 )
		{
			statPoolType = m_statPoolUpdates[ i ].StatPoolType().StatPoolType();
			statPoolValue = GetStatPoolValue( owner, m_statPoolUpdates[ i ], applicationTargetID );
			if( m_setValue )
			{
				poolSys.RequestSettingStatPoolValue( applicationTargetID, statPoolType, statPoolValue, owner, m_usePercent );
			}
			else
			{
				poolSys.RequestChangingStatPoolValue( applicationTargetID, statPoolType, statPoolValue, owner, false, m_usePercent );
			}
		}
	}

	protected virtual function GetStatPoolValue( owner : GameObject, record : weak< StatPoolUpdate_Record >, applicationTargetID : EntityID ) : Float
	{
		var statModifiers : array< weak< StatModifier_Record > >;
		var statPoolValue : Float;
		statPoolValue = record.StatPoolValue();
		if( record.GetStatModifiersCount() > 0 )
		{
			statModifiers.Clear();
			record.StatModifiers( statModifiers );
			statPoolValue = GameInstance.GetStatsSystem( owner.GetGame() ).CalculateModifierListValue( applicationTargetID, statModifiers );
		}
		return statPoolValue;
	}

}

class ModifyStatPoolValuePerHitEffector extends ModifyStatPoolValueEffector
{
	var m_damageScaleFactor : Float;

	protected export override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		super.Initialize( record, game, parentRecord );
		m_damageScaleFactor = TweakDBInterface.GetFloat( record + T".damageScaleFactor", 0.0 );
	}

	protected override function GetStatPoolValue( owner : GameObject, record : weak< StatPoolUpdate_Record >, applicationTargetID : EntityID ) : Float
	{
		var statPoolValue : Float;
		var hitEvent : gameHitEvent;
		var totalAttackValue : Float;
		var targetMaxHealth : Float;
		var totalAttackPerc : Float;
		statPoolValue = super.GetStatPoolValue( owner, record, applicationTargetID );
		hitEvent = GetHitEvent();
		if( hitEvent )
		{
			totalAttackValue = hitEvent.attackComputed.GetTotalAttackValue( gamedataStatPoolType.Health );
			targetMaxHealth = GameInstance.GetStatPoolsSystem( owner.GetGame() ).GetStatPoolMaxPointValue( hitEvent.target.GetEntityID(), gamedataStatPoolType.Health );
			totalAttackPerc = ( 100.0 * totalAttackValue ) / targetMaxHealth;
			statPoolValue += ( totalAttackPerc * m_damageScaleFactor );
		}
		return statPoolValue;
	}

}

