class ConvertDamageToDoTEffector extends ModifyAttackEffector
{
	var m_DamageToDoTConversion : Float;
	var m_DotDistributionTime : Float;
	var m_statMod : gameConstantStatModifierData;
	var m_ownerID : EntityID;

	protected export override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		m_DamageToDoTConversion = TweakDBInterface.GetFloat( record + T".damageConversion", 0.0 );
		m_DotDistributionTime = TweakDBInterface.GetFloat( record + T".dotDistributionTime", 5.0 );
		m_statMod = ( ( gameConstantStatModifierData )( RPGManager.CreateStatModifier( gamedataStatType.AccumulatedDoTDecayRate, gameStatModifierType.Additive, 0.0 ) ) );
	}

	protected export override function Uninitialize( game : GameInstance )
	{
		var statSystem : StatsSystem;
		if( m_statMod )
		{
			statSystem = GameInstance.GetStatsSystem( game );
			statSystem.RemoveModifier( m_ownerID, m_statMod );
		}
	}

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

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

	private function ProcessAction( owner : GameObject )
	{
		var hitEvent : gameHitEvent;
		var dotDmgToApply : Float;
		var tmpValue : Float;
		var poolSys : StatPoolsSystem;
		var statSystem : StatsSystem;
		hitEvent = GetHitEvent();
		if( !( hitEvent ) )
		{
			return;
		}
		if( AttackData.IsDoT( hitEvent.attackData ) )
		{
			return;
		}
		tmpValue = hitEvent.attackComputed.GetTotalAttackValue( gamedataStatPoolType.Health );
		dotDmgToApply = ( tmpValue / ( 1.0 - m_DamageToDoTConversion ) ) - tmpValue;
		if( dotDmgToApply > 0.0 )
		{
			m_ownerID = owner.GetEntityID();
			poolSys = GameInstance.GetStatPoolsSystem( owner.GetGame() );
			tmpValue = poolSys.GetStatPoolValue( m_ownerID, gamedataStatPoolType.AccumulatedDoT, false );
			poolSys.RequestChangingStatPoolValue( m_ownerID, gamedataStatPoolType.AccumulatedDoT, dotDmgToApply, owner, false, false );
			statSystem = GameInstance.GetStatsSystem( owner.GetGame() );
			statSystem.RemoveModifier( m_ownerID, m_statMod );
			m_statMod.value = ( tmpValue + dotDmgToApply ) / m_DotDistributionTime;
			statSystem.AddModifier( m_ownerID, m_statMod );
		}
	}

}

