class ApplyRandomStatusEffectEffector extends Effector
{
	var m_targetEntityID : EntityID;
	var m_applicationTarget : CName;
	var m_effects : array< TweakDBID >;
	var m_appliedEffect : TweakDBID;

	protected override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		var i : Int32;
		var strs : array< String >;
		strs = TDB.GetStringArray( record + T".statusEffects" );
		for( i = 0; i < strs.Size(); i += 1 )
		{
			m_effects.PushBack( TDBID.Create( strs[ i ] ) );
		}
		m_applicationTarget = TweakDBInterface.GetCName( record + T".applicationTarget", '' );
	}

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

	protected override function ActionOn( owner : GameObject )
	{
		var ses : StatusEffectSystem;
		if( !( GetApplicationTarget( owner, m_applicationTarget, m_targetEntityID ) ) )
		{
			return;
		}
		SetRandomStatusEffect();
		ses = GameInstance.GetStatusEffectSystem( owner.GetGame() );
		ses.ApplyStatusEffect( m_targetEntityID, m_appliedEffect );
	}

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

	private function RemoveStatusEffect( gameInstance : GameInstance )
	{
		var ses : StatusEffectSystem;
		if( !( EntityID.IsDefined( m_targetEntityID ) ) )
		{
			return;
		}
		ses = GameInstance.GetStatusEffectSystem( gameInstance );
		ses.RemoveStatusEffect( m_targetEntityID, m_appliedEffect );
	}

	private function SetRandomStatusEffect()
	{
		var i : Int32;
		i = RandRange( 0, m_effects.Size() );
		m_appliedEffect = m_effects[ i ];
	}

}

