//=============================================================================
// BeamTrigger.
//=============================================================================
class LaserTrap extends BeamTrigger;

var() int penalty;

function Tick(float deltaTime)
{
	local Actor A;
	local bool bTrigger;

	if (emitter != None)
	{
		// if we've been EMP'ed, act confused
		if (bConfused && bIsOn)
		{
			confusionTimer += deltaTime;

				emitter.TurnOff();

			if (confusionTimer > confusionDuration)
			{
				bConfused = False;
				confusionTimer = 0;
				emitter.TurnOn();
			}

			return;
		}

		emitter.SetLocation(Location);
		emitter.SetRotation(Rotation);

		if ((emitter.HitActor != None) && (LastHitActor != emitter.HitActor))
		{
			if (IsRelevant(emitter.HitActor))
			{
				bTrigger = True;

				if (bTrigger)
				{
					// play "beam broken" sound
					PlaySound(sound'Beep2',,,, 1280, 3.0);

					if (!bAlreadyTriggered)
					{
						// only be triggered once?
						if (bTriggerOnceOnly)
							bAlreadyTriggered = True;

						_MMRPGPlayer(emitter.HitActor).SendJail(Penalty);

						// Trigger event
						//if(Event != '')
						//	foreach AllActors(class 'Actor', A, Event)
						//		A.Trigger(Self, Pawn(emitter.HitActor));
					}
				}
			}
		}

		LastHitActor = emitter.HitActor;
	}
}

// if we are triggered, turn us on
function Trigger(Actor Other, Pawn Instigator)
{
	if (bConfused)
		return;

	if (emitter != None)
	{
		if (!bIsOn)
		{
			emitter.TurnOn();
			bIsOn = True;
			LastHitActor = None;
			MultiSkins[1] = Texture'LaserSpot1';
		}
	}

	Super(Trigger).Trigger(Other, Instigator);
}

// if we are untriggered, turn us off
function UnTrigger(Actor Other, Pawn Instigator)
{
	if (bConfused)
		return;

	if (emitter != None)
	{
		if (bIsOn)
		{
			emitter.TurnOff();
			bIsOn = False;
			LastHitActor = None;
			MultiSkins[1] = Texture'BlackMaskTex';
		}
	}

	Super(Trigger).UnTrigger(Other, Instigator);
}

function BeginPlay()
{
	Super(Trigger).BeginPlay();

	LastHitActor = None;
	emitter = Spawn(class'LaserEmitter');

	if (emitter != None)
	{
		emitter.SetBlueBeam();
		emitter.TurnOn();
		bIsOn = True;
	}
	else
		bIsOn = False;
}

function TakeDamage(int Damage, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType)
{
}

function Destroyed()
{
	if (emitter != None)
	{
		emitter.Destroy();
		emitter = None;
	}

	Super(Trigger).Destroyed();
}

defaultproperties
{
     bIsOn=True
     confusionDuration=30.000000
     HitPoints=9000
     minDamageThreshold=50
     TriggerType=TT_AnyProximity
     bHidden=False
     bDirectional=True
     DrawType=DT_Mesh
     Mesh=LodMesh'DeusExDeco.LaserEmitter'
     CollisionRadius=2.500000
     CollisionHeight=2.500000
}
