enum EJuryrigTrapState
{
	UNARMED = 0,
	ARMED = 1,
	TRIGGERED = 2,
}

class ChangeJuryrigTrapState extends Event
{
	var newState : EJuryrigTrapState;
}

class TrapComponent extends ScriptableComponent
{

	private export function OnGameAttach() {}

	protected event OnAreaEnter( evt : AreaEnteredEvent )
	{
		var owningDevice : Device;
		var JuryrigEvent : ChangeJuryrigTrapState;
		owningDevice = ( ( Device )( GetOwner() ) );
		JuryrigEvent = new ChangeJuryrigTrapState;
		JuryrigEvent.newState = EJuryrigTrapState.TRIGGERED;
		if( ( evt.componentName == 'TrapTrigger' && ( ( NPCPuppet )( EntityGameInterface.GetEntity( evt.activator ) ) ) ) && owningDevice.GetDevicePS().GetJuryrigTrapState() == EJuryrigTrapState.ARMED )
		{
			SpawnAttack();
			JuryrigEvent.newState = EJuryrigTrapState.TRIGGERED;
			owningDevice.QueueEvent( JuryrigEvent );
		}
	}

	private function SpawnAttack()
	{
		var explosionAttack : Attack_GameEffect;
		var explosionEffect : EffectInstance;
		var attackContext : AttackInitContext;
		var statMods : array< gameStatModifierData >;
		var radius : Float;
		radius = TDB.GetFloat( T"weapons.E3_grenade.damageRadius" );
		attackContext.record = TweakDBInterface.GetAttackRecord( T"Attacks.FragGrenade" );
		attackContext.instigator = GetPlayer( GetOwner().GetGame() );
		attackContext.source = GetOwner();
		explosionAttack = ( ( Attack_GameEffect )( IAttack.Create( attackContext ) ) );
		explosionEffect = explosionAttack.PrepareAttack( GetPlayer( GetOwner().GetGame() ) );
		explosionAttack.GetStatModList( statMods );
		EffectData.SetFloat( explosionEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.radius, radius );
		EffectData.SetVector( explosionEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.position, GetOwner().GetWorldPosition() );
		EffectData.SetVariant( explosionEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.attack, ( ( IAttack )( explosionAttack ) ) );
		EffectData.SetVariant( explosionEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.attackStatModList, statMods );
		explosionAttack.StartAttack();
	}

}

