class UR_DeployedActor_Mine extends UTDeployedActor;

var SoundCue ExplosionSound;
var ParticleSystem ExplosionEffect;
var float EMPRadius;
/** used to tell client to play explosion effect */
var repnotify byte ExplosionCount;
var int DamageExplode;

replication
{
	if (bNetDirty)
		ExplosionCount;
}

event Landed(vector HitNormal, Actor HitActor)
{
	if ( Pawn(HitActor) != None )
	{
		LifeSpan = FMin(LifeSpan, 30.0);
	}
	PerformDeploy();
	if ( !bDeleteMe )
	{
		SetTimer(0.1, true, 'CheckEMP');
	}
}

simulated function PerformDeploy()
{
	bDeployed = true;
	SkeletalMeshComponent(Mesh).PlayAnim('Deploy');
}

function CheckEmp()
{
	local Pawn V;
	local bool bActivated;

	ForEach CollidingActors(class'Pawn', V, EMPRadius,, true)
	{
		if (!WorldInfo.GRI.OnSameTeam(self, V) || ((UTTeamGame(WorldInfo.Game) != None) && (UTTeamGame(WorldInfo.Game).FriendlyFireScale > 0)))
		{
			bActivated = true;
			PlayerController(V.Controller).ClientPlaySound(ExplosionSound);
			V.TakeDamage(DamageExplode, Instigator.Controller, Location, vect(0,0,0), class'UR_DmgType_LandMine', ,);
		}
	}

	if (bActivated)
	{
		SetTimer(3.0, false, 'ClearExplosionCount');
		PlayExplosionEffect();
		MakeNoise(1.0);
		Destroy();
	}
}

simulated function PlayExplosionEffect()
{
	local vector SpawnLocation;
	local rotator SpawnRotation;

	if (WorldInfo.NetMode != NM_DedicatedServer)
	{
		PlaySound(ExplosionSound, true);
		SkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation( 'EMPBurst', SpawnLocation, SpawnRotation );
		WorldInfo.MyEmitterPool.SpawnEmitter(ExplosionEffect, SpawnLocation, SpawnRotation);
	}
}

simulated event ReplicatedEvent(name VarName)
{
	if (VarName == 'ExplosionCount')
	{
		if (ExplosionCount != 0)
		{
			PlayExplosionEffect();
		}
	}
	else
	{
		Super.ReplicatedEvent(VarName);
	}
}

event TakeDamage(int DamageAmount, Controller EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
{
	PlayExplosionEffect();
	Destroy();
}

defaultproperties
{
	DamageExplode = 100;

   ExplosionSound=SoundCue'A_Vehicle_Goliath.SoundCues.A_Vehicle_Goliath_Explode'
   ExplosionEffect=ParticleSystem'VH_Goliath.Effects.PS_Goliath_Cannon_Impact_MID'
   EMPRadius=250.000000
      Begin Object Name=DeployedLightEnvironment ObjName=DeployedLightEnvironment Archetype=DynamicLightEnvironmentComponent'UTGame.Default__UTDeployedActor:DeployedLightEnvironment'
      ObjectArchetype=DynamicLightEnvironmentComponent'UTGame.Default__UTDeployedActor:DeployedLightEnvironment'
   End Object
   Begin Object Class=SkeletalMeshComponent Name=DeployableMesh ObjName=DeployableMesh Archetype=SkeletalMeshComponent'Engine.Default__SkeletalMeshComponent'
      SkeletalMesh=SkeletalMesh'PICKUPS.Deployables.Mesh.SK_Deployables_EMP_Mine'
      Begin Object Class=AnimNodeSequence Name=MeshSequenceA ObjName=MeshSequenceA Archetype=AnimNodeSequence'Engine.Default__AnimNodeSequence'
         Name="MeshSequenceA"
         ObjectArchetype=AnimNodeSequence'Engine.Default__AnimNodeSequence'
      End Object
      Animations=AnimNodeSequence'UTGameContent.Default__UTEMPMine:MeshSequenceA'
      AnimSets(0)=AnimSet'PICKUPS.Deployables.Anims.K_Deployables_EMP_Mine'
      LightEnvironment=DeployedLightEnvironment
      bUseAsOccluder=False
      Translation=(X=0.000000,Y=0.000000,Z=-20.000000)
      Name="DeployableMesh"
      ObjectArchetype=SkeletalMeshComponent'Engine.Default__SkeletalMeshComponent'
   End Object
   Mesh=DeployableMesh

   LightEnvironment=DeployedLightEnvironment
   Components(0)=DeployedLightEnvironment
   Components(1)=DeployableMesh
   Begin Object Class=CylinderComponent Name=ColComp ObjName=ColComp Archetype=CylinderComponent'Engine.Default__CylinderComponent'
      Name="ColComp"
      ObjectArchetype=CylinderComponent'Engine.Default__CylinderComponent'
   End Object
   Components(2)=ColComp
   bOrientOnSlope=True
   LifeSpan=360.000000
   CollisionComponent=ColComp
   Name="Default__UTEMPMine"
   ObjectArchetype=UTDeployedActor'UTGame.Default__UTDeployedActor'
}
