class PlayVFXEffector extends Effector
{
	var m_vfxName : CName;
	var m_startOnUninitialize : Bool;
	var m_fireAndForget : Bool;
	var m_owner : weak< GameObject >;

	protected export override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		m_vfxName = TweakDBInterface.GetCName( record + T".vfxName", '' );
		m_startOnUninitialize = TweakDBInterface.GetBool( record + T".startOnUninitialize", false );
		m_fireAndForget = TweakDBInterface.GetBool( record + T".fireAndForget", false );
	}

	protected export override function ActionOn( owner : GameObject )
	{
		m_owner = owner;
		if( !( m_startOnUninitialize ) )
		{
			GameObjectEffectHelper.StartEffectEvent( m_owner, m_vfxName );
		}
	}

	protected override function ActionOff( owner : GameObject )
	{
		Deactivate();
	}

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

	protected override function RepeatedAction( owner : GameObject )
	{
		if( m_fireAndForget )
		{
			ActionOn( owner );
		}
	}

	protected function Deactivate()
	{
		if( m_startOnUninitialize )
		{
			GameObjectEffectHelper.StartEffectEvent( m_owner, m_vfxName );
		}
		else
		{
			GameObjectEffectHelper.BreakEffectLoopEvent( m_owner, m_vfxName );
		}
	}

}

class PlaySFXEffector extends Effector
{
	var activationSFXName : CName;
	var deactivationSFXName : CName;
	var m_startOnUninitialize : Bool;
	var m_unique : Bool;
	var m_fireAndForget : Bool;
	var m_stopActiveSfxOnDeactivate : Bool;
	var m_owner : weak< GameObject >;

	protected export override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		activationSFXName = TweakDBInterface.GetCName( record + T".activationSFXName", '' );
		deactivationSFXName = TweakDBInterface.GetCName( record + T".deactivationSFXName", '' );
		m_startOnUninitialize = TweakDBInterface.GetBool( record + T".startOnUninitialize", false );
		m_unique = TweakDBInterface.GetBool( record + T".unique", false );
		m_fireAndForget = TweakDBInterface.GetBool( record + T".fireAndForget", false );
		m_stopActiveSfxOnDeactivate = TweakDBInterface.GetBool( record + T".stopActiveSfxOnDeactivate", true );
	}

	protected export override function ActionOn( owner : GameObject )
	{
		m_owner = owner;
		if( !( m_startOnUninitialize ) && IsNameValid( activationSFXName ) )
		{
			if( !( m_unique ) )
			{
				GameObject.PlaySound( m_owner, activationSFXName, 'PlaySFXEffector' );
			}
			else
			{
				GameObject.PlaySoundWithParams( m_owner, activationSFXName, 'PlaySFXEffector', audioAudioEventFlags.Unique );
			}
		}
	}

	protected export override function ActionOff( owner : GameObject )
	{
		Deactivate();
	}

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

	protected override function RepeatedAction( owner : GameObject )
	{
		if( m_fireAndForget )
		{
			ActionOn( owner );
		}
	}

	protected function Deactivate()
	{
		if( IsNameValid( activationSFXName ) )
		{
			if( m_startOnUninitialize )
			{
				GameObject.PlaySound( m_owner, activationSFXName, 'PlaySFXEffector' );
			}
			else if( m_stopActiveSfxOnDeactivate )
			{
				GameObject.StopSound( m_owner, activationSFXName, 'PlaySFXEffector' );
			}
		}
		if( IsNameValid( deactivationSFXName ) )
		{
			GameObject.PlaySound( m_owner, deactivationSFXName, 'PlaySFXEffector' );
		}
	}

}

