class AntiRadar extends WeaponObject
{
	private var m_colliderComponent : IComponent;
	private editable var m_gameEffectRef : EffectRef;
	private var gameEffectInstance : EffectInstance;
	private var jammedSensorsArray : array< weak< SensorDevice > >;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		EntityRequestComponentsInterface.RequestComponent( ri, 'jammer', 'entColliderComponent', false );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		m_colliderComponent = EntityResolveComponentsInterface.GetComponent( ri, 'jammer' );
	}

	protected event OnChargeStartedEvent( evt : ChargeStartedEvent )
	{
		var player : PlayerPuppet;
		player = GetPlayer( GetGame() );
		gameEffectInstance = GameInstance.GetGameEffectSystem( GetGame() ).CreateEffect( m_gameEffectRef, player, this );
		gameEffectInstance.AttachToEntity( player, GetAllBlackboardDefs().EffectSharedData.position );
		gameEffectInstance.Run();
		ChangeAppearance( 'green' );
	}

	protected event OnChargeEndedEvent( evt : ChargeEndedEvent )
	{
		var i : Int32;
		var jammedEvt : SetJammedEvent;
		jammedEvt = new SetJammedEvent;
		if( gameEffectInstance )
		{
			gameEffectInstance.Terminate();
			if( jammedSensorsArray.Size() != 0 )
			{
				for( i = 0; i < jammedSensorsArray.Size(); i += 1 )
				{
					jammedEvt.newJammedState = false;
					jammedEvt.instigator = this;
					jammedSensorsArray[ i ].QueueEvent( jammedEvt );
				}
				jammedSensorsArray.Clear();
			}
		}
		ChangeAppearance( 'default' );
	}

	protected event OnSensorJammed( evt : SensorJammed )
	{
		var jammedEvt : SetJammedEvent;
		jammedEvt = new SetJammedEvent;
		if( !( jammedSensorsArray.Contains( evt.sensor ) ) )
		{
			jammedSensorsArray.PushBack( evt.sensor );
			jammedEvt.newJammedState = true;
			jammedEvt.instigator = this;
			evt.sensor.QueueEvent( jammedEvt );
		}
	}

	protected function ChangeAppearance( newAppearance : CName )
	{
		var evt : entAppearanceEvent;
		evt = new entAppearanceEvent;
		evt.appearanceName = newAppearance;
		this.QueueEvent( evt );
	}

}

class SensorJammed extends Event
{
	var sensor : weak< SensorDevice >;
}

