class AptKey extends DeusExPickup;

var() int keynumber;
var sound useSound;

state Activated
{
	function Activate()
	{
	Super.Activate();
	}

	function BeginState()
	{
	Super.BeginState();
	OpenCheck();
	}
Begin:
}

state DeActivated
{
	function BeginState()
	{
	Super.BeginState();
	OpenCheck();
	}
Begin:
}


function OpenCheck()
{
	local Vector StartTrace, EndTrace, HitLocation, HitNormal;
	local Actor HitActor;


	// trace out one foot in front of the pawn
	StartTrace = Owner.Location;
	EndTrace = StartTrace + Vector(Pawn(Owner).ViewRotation) * 64;

	StartTrace.Z += Pawn(Owner).BaseEyeHeight;
	EndTrace.Z += Pawn(Owner).BaseEyeHeight;

	HitActor = Trace(HitLocation, HitNormal, EndTrace, StartTrace);
	if(HitActor != None)
	{
		if (HitActor.IsA('AptMover'))
		{
			if (AptMover(HitActor).locknumber == keynumber)
			{
				AptMover(HitActor).Trigger(HitActor, Pawn(Owner));
				DeusExPlayer(Owner).ClientMessage("Your key unlocked it");
			}
		}
	}
	GotoState('UseIt');
}



simulated function bool TestMPBeltSpot(int BeltSpot)
{
   return ( (BeltSpot >= 1) && (BeltSpot <=9) );
}









state UseIt
{
	function PutDown()
	{
		
	}

Begin:
	PlaySound(useSound, SLOT_None);
	PlayAnim('UseBegin',, 0.1);
	FinishAnim();
	LoopAnim('UseLoop',, 0.1);
	GotoState('StopIt');
}


state StopIt
{
	function PutDown()
	{
		
	}

Begin:
	PlayAnim('UseEnd',, 0.1);
	GotoState('Idle', 'DontPlaySelect');
}


function DropFrom(vector StartLocation)
{
	LifeSpan = 5.0;
	Super.DropFrom(StartLocation);
}


function BecomeItem()
{
	LifeSpan = 0.0;
	Super.BecomeItem();
}


defaultproperties
{
     bActivatable=True
     ItemName="Key to Apartment"
     ItemArticle="the"
//     RespawnTime=0.000000
     M_Activated=""
     M_Deactivated=""
     PlayerViewOffset=(X=16.000000,Y=15.000000,Z=-16.000000)
     PlayerViewMesh=LodMesh'DeusExItems.NanoKeyRingPOV'
     PickupViewMesh=LodMesh'DeusExItems.Nanokeyring'
     UseSound=Sound'DeusExSounds.Generic.KeysRattling'
     ThirdPersonMesh=LodMesh'DeusExItems.Nanokeyring'
     LandSound=Sound'DeusExSounds.Generic.PlasticHit1'
     Icon=Texture'DeusExUI.Icons.BeltIconNanokeyring'
     beltDescription="APT KEY"
     Mesh=LodMesh'DeusExItems.Nanokeyring'
     CollisionRadius=7.000000
     CollisionHeight=0.550000
     Mass=2.000000
     Buoyancy=3.000000
}
