class FXEnergy expands XEnergy;

#exec TEXTURE IMPORT NAME=FXEnergy FILE=CORONAS\FXEnergy.bmp GROUP=Coronas FLAGS=2

var SphericalBarrier sb;
var bool bSB;

simulated function Timer()
{
local Actor A;

	Super.Timer();

	if (!bSB)
	{
		SpawnBarrier();
		bSB = True;
	}

	ForEach VisibleCollidingActors(Class'Actor', A, 512.0)
	{
		if (A.IsA('StrangeShell') || A.IsA('CybotYDown') || A.IsA('CybotZDown') || A.IsA('CybotX') || A.IsA('Vehicle'))
			CheckActor(A);
		else if (A.IsA('DumbRocket') || A.IsA('WarShell'))
		{
			SpawnEffect(A.Location);
			A.TakeDamage(10000,  Instigator, A.Location, vect(0,0,0), 'BarrierDeath');
		}
		else if (A.IsA('Projectile'))
		{
			SpawnEffect(A.Location);
			Projectile(A).Explode(A.Location, -(Normal(A.Velocity)));
		}
		else if (A.IsA('Pawn'))
			CheckPawn(Pawn(A));
	}
}

function SpawnBarrier()
{
	sb = Spawn(Class'SphericalBarrier');
}

simulated function Destroyed()
{
	if (sb != None)
		sb.Destroy();

	Super.Destroyed();
}

function CheckActor( actor Proj)
{
	If (TeamGamePlus(Level.Game)!= None && !Level.Game.IsA('MonsterHunt'))
	{
		if (Pawn(Proj.Owner) != None && Proj.IsA('Vehicle'))
		{
			If (Pawn(Proj.Owner).PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team || Pawn(Proj.Owner)==Instigator)
				return;
		}
		else If (Proj.Instigator.PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team || Proj.Instigator==Instigator)
			return;
	}
	else if (!Proj.Instigator.IsA('ScriptedPawn') && Level.Game.IsA('MonsterHunt'))
			return;
	else if (!Proj.Owner.IsA('ScriptedPawn') && Level.Game.IsA('MonsterHunt'))
			return;
	else if (Proj.Instigator == Instigator && TeamGamePlus(Level.Game) == None)
			return;
	else if (Proj.Owner == Instigator && TeamGamePlus(Level.Game) == None)
			return;

	SpawnEffect(Proj.Location);
	Proj.TakeDamage(10000,  Instigator, Proj.Location, vect(0,0,150000), 'BarrierDeath');
}

function CheckPawn( pawn P)
{
	
	if (Level.Game.IsA('DeathMatchPlus'))
	{
		If (TeamGamePlus(Level.Game)!= None && !Level.Game.IsA('MonsterHunt'))
		{
			If (P.PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team || P==Instigator)
				return;
		}
		else if (!P.IsA('ScriptedPawn') && Level.Game.IsA('MonsterHunt'))
			return;
		else if (P == Instigator && TeamGamePlus(Level.Game) == None)
			return;
	}
	else
	{
		if (P == Instigator)
			return;
		else if (P.IsA('ScriptedPawn') && Instigator.IsA('ScriptedPawn'))
		{
			if (ScriptedPawn(P).TeamTag == ScriptedPawn(Instigator).TeamTag && ScriptedPawn(P).TeamTag != '')
				return;
		}
		else if (Instigator.IsA('PlayerPawn') && (P.AttitudeToPlayer == ATTITUDE_Friendly || P.AttitudeToPlayer == ATTITUDE_Follow))
			return;
	}
	if (P.Tag == 'NoIntruder')
		return;

	SpawnEffect(P.Location);
	P.TakeDamage(10000,  Instigator, P.Location, vect(0,0,150000), 'BarrierDeath');
}


simulated function SpawnEffect(vector VLoc)
{
	Spawn(Class'BarrierEffect',,, VLoc);
}


defaultproperties
{
	Texture=FXEnergy
	EffectRefreshTime=0.100000
	bTimedEffect=True
	EffectSound=None
	EnergyParticlesType=Class'WhiteRParticles'
}
