//=============================================================================
// SpyDrone.
//=============================================================================
class SpyDroneMM extends SpyDrone;

var int onetime;

replication
{
    reliable if ( Role < ROLE_Authority )
    GetLoc;
}

auto state Flying
{
	function ProcessTouch (Actor Other, Vector HitLocation)
	{

	}

	event Touch( Actor Other )
	{
		// do nothing
		if(SpyTrigger(Other) != None)
		{
			if(_MMRPGPlayer(Owner).SpyMission == 2)
			{
				if(onetime == 0)
				{
					onetime = 1;
				}
			}
		}
	}

	simulated function HitWall (vector HitNormal, actor HitWall)
	{
		// do nothing
	}

	simulated function Explode(vector HitLocation, vector HitNormal)
	{
		local DeusExPlayer P;
		local inventory inv;
		foreach VisibleCollidingActors( class 'DeusExPlayer', P, BlastRadius, HitLocation )
		{
			if(P != None)
			{
				If( (!P.Region.Zone.IsA('MMRPGSafeArea')) && (!P.Region.Zone.IsA('MMRPGRoomArea')) )
				{
					if(P.InHand != None)
					{
						inv=P.InHand;
				
					}

					if(P.InHand == None)
					{
						if(P.LastinHand != None)
						{
							inv=P.LastinHand;
						}
					}
					if (Inv.IsA('DeusExWeapon'))
					{
						DeusExWeapon(Inv).ScopeOff();
						DeusExWeapon(Inv).LaserOff();
					}
					if( Inv != None && !Inv.IsA('MMRPGCreditCard') && !Inv.IsA('WeaponFist') )
					{
						Inv.DropFrom(P.Location);
					}
					If(P.IsA('_MMRPGPlayer'))
					{
						_MMRPGPlayer(P).bNerve = True;
					}
           	 			P.FeignDeath();
           				P.PlaySound(Sound'DeusExSounds.Player.MaleDrown');
				}
			}
		}
		Super(ThrownProjectile).Explode(HitLocation, HitNormal);
	}
}

Function Vector GetLoc()
{
	Return Location;

}

function Tick(float deltaTime)
{
	local SpyTrigger J;

	SetLocation(GetLoc());

	// do nothing
	if(onetime > 0)
	{
		foreach RadiusActors(class'SpyTrigger', J, CollisionRadius)
		{
			onetime += 1;

			if(onetime == 2)
			{
				_MMRPGPlayer(Owner).ReceiveMessage("What is your |p2*NO SIGNAL*|p1 the situation so far?");
			}
			if(onetime == 16)
			{
				_MMRPGPlayer(Owner).ReceiveMessage("I |p2*NO SIGNAL*|p1 we need to involve Agent X |p2*NO SIGNAL*|p1");
			}
			if(onetime == 30)
			{
				_MMRPGPlayer(Owner).ReceiveMessage("|p2*NO SIGNAL*|p1 Yes, |p2*NO SIGNAL*|p1 he also needs to be terminated.");
			}
			if(onetime > 40)
			{
				_MMRPGPlayer(Owner).SpyMission = 3;
				onetime = 0;
			}
			return;
		}
		onetime = 0;

	}	
}

function TakeDamage(int Damage, Pawn instigatedBy, Vector HitLocation, Vector Momentum, name damageType)
{
	// fall to the ground if EMP'ed
	//if ((DamageType == 'EMP') && !bDisabled)
	if(!bDisabled)
	{
		SetPhysics(PHYS_Falling);
		bBounce = True;
		LifeSpan = 10.0;
	}

	if ( Level.NetMode != NM_Standalone )
	{
		if ( DeusExPlayer(Owner) != None )
			DeusExPlayer(Owner).ForceDroneOff();
		else
			log("Warning:Drone with no owner?" );
	}
	Super(ThrownProjectile).TakeDamage(Damage, instigatedBy, HitLocation, Momentum, damageType);
}


function BeginPlay()
{
	// do nothing
}

function Destroyed()
{
	if ( DeusExPlayer(Owner) != None )
		DeusExPlayer(Owner).aDrone = None;

	Super(ThrownProjectile).Destroyed();
}

defaultproperties
{
     elasticity=0.200000
     fuseLength=0.000000
     proxRadius=128.000000
     bHighlight=False
     bBlood=False
     bDebris=False
     blastRadius=128.000000
     DamageType=HalonGas
     bEmitDanger=False
     ItemName="Spy Drone"
     DrawScale=0.5
     MaxSpeed=0.000000
     Damage=10.000000
     ImpactSound=Sound'DeusExSounds.Generic.SmallExplosion2'
     Physics=PHYS_Projectile
     //RemoteRole=ROLE_DumbProxy
     LifeSpan=0.000000
     Mesh=LodMesh'DeusExCharacters.SpyDrone'
     SoundRadius=24
     SoundVolume=192
     AmbientSound=None
     Mass=10.000000
     Buoyancy=2.000000
}
