class BarbedWire extends ActivatedDeviceTrap
{
	default m_controllerTypeName = 'BarbedWireController';

	protected const override function GetController() : BarbedWireController
	{
		return ( ( BarbedWireController )( m_controller ) );
	}

	public const override function GetDevicePS() : BarbedWireControllerPS
	{
		return GetController().GetPS();
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		super.OnTakeControl( ri );
		m_controller = ( ( BarbedWireController )( EntityResolveComponentsInterface.GetComponent( ri, 'controller' ) ) );
	}

	protected event OnAreaEnter( evt : AreaEnteredEvent )
	{
		var activator : weak< GameObject >;
		activator = ( ( GameObject )( EntityGameInterface.GetEntity( evt.activator ) ) );
		if( ( activator && CanAttackActivator( activator ) ) && ( ( PlayerPuppet )( activator ) ) )
		{
			super.OnAreaEnter( evt );
		}
	}

	protected function CanAttackActivator( activator : weak< GameObject > ) : Bool
	{
		var validVehicle : weak< VehicleObject >;
		if( VehicleComponent.GetVehicle( activator.GetGame(), activator, validVehicle ) )
		{
			return false;
		}
		return true;
	}

}

import abstract class worldITriggerAreaNotifer extends IScriptable
{
}

import class TriggerNotifier_Script extends worldITriggerAreaNotifer
{
}

import abstract class worldITriggerAreaNotiferInstance extends IScriptable
{
}

import class TriggerNotifier_ScriptInstance extends worldITriggerAreaNotiferInstance
{
	public import final function GetNotifier() : TriggerNotifier_Script;
}

class TriggerNotifier_BarbedWire extends TriggerNotifier_Script
{
	[ customEditor = "TweakDBGroupInheritance;Attacks.Trap_Attack_Base" ]
	instanceeditable var attackType : TweakDBID;

	protected event OnAreaEnter( evt : AreaEnteredEvent ) {}

	protected event OnAreaExit( evt : AreaExitedEvent ) {}

	protected constexpr export function GetInstanceClassName() : CName
	{
		return 'TriggerNotifier_BarbedWireInstance';
	}

}

class TriggerNotifier_BarbedWireInstance extends TriggerNotifier_ScriptInstance
{

	protected event OnAreaEnter( evt : AreaEnteredEvent )
	{
		var activator : weak< GameObject >;
		activator = ( ( GameObject )( EntityGameInterface.GetEntity( evt.activator ) ) );
		if( activator && CanAttackActivator( activator ) )
		{
			DoAttack( ( ( TriggerNotifier_BarbedWire )( GetNotifier() ) ).attackType, activator );
		}
	}

	protected function CanAttackActivator( activator : weak< GameObject > ) : Bool
	{
		if( VehicleComponent.IsMountedToVehicle( activator.GetGame(), activator ) )
		{
			return false;
		}
		return true;
	}

	protected event OnAreaExit( evt : AreaExitedEvent ) {}

	protected function DoAttack( attackRecord : TweakDBID, target : GameObject )
	{
		var attack : Attack_GameEffect;
		var hitFlags : array< SHitFlag >;
		attack = RPGManager.PrepareGameEffectAttack( target.GetGame(), target, target, attackRecord, , hitFlags, target );
		if( attack )
		{
			attack.StartAttack();
		}
	}

}

