//=============================================================================
//
//=============================================================================
class RPGMechanicJob extends HumanCivilian;

var _MMRPGPlayer talkto;
var int talked;
var bool bTrade;

function Frob(Actor Frobber, Inventory frobWith)
{
	local MMRPGCreditCard Cred;
	local _MMRPGPlayer Player;
	local keydummy2 hmm2;

	If (Frobber.IsA('DeusExPlayer'))
	{
		If(talked != 0)
		{
			if(bTrade)
			{
				Super(Actor).Frob(Frobber, Frobwith);
			}
			if(!bTrade)
			{
				_MMRPGPlayer(Frobber).ReceiveMessage("Someone is already talking to this person!");
				return;
			}
		}
	}

	Player = _MMRPGPlayer(Frobber);
	talkto = Player;

	Player.bInConv = True;
		LookAtActor(Frobber, True, True, False);
	talked = 1;

	if (_MMRPGPlayer(Frobber).bMechanic)
	{
		If ( ! CheckMechTool() )
		{
			foreach AllActors(class'keydummy2', hmm2)
			{
					if (Player.HandleItemPickup(hmm2, True) == False)
					{
						Player.ReceiveMessage("MECHANIC: Make some room for an Electrician's Tool.");
						Player.bInConv = False;
						talked = 0;
						return;
					}
			}

			foreach AllActors(class'keydummy2', hmm2)
			{
					if (Player.HandleItemPickup(hmm2, True) == True)
					{
						Player.ReceiveMessage("MECHANIC: Have another Electrician's Tool");
						bTrade=True;
						talkto.SpawnItemz(Class'ElectriciansMultitool');
						Player.bInConv = False;
						bTrade=False;
						talked = 0;
						return;
					}
			}
		}
		if (talkto.numFixed == 1)
		{
			Player.ReceiveMessage(""$Player.PlayerReplicationInfo.PlayerName$": I have fixed "$talkto.numFixed$" device.");
		}
		else
		{
			Player.ReceiveMessage(""$Player.PlayerReplicationInfo.PlayerName$": I have fixed "$talkto.numFixed$" devices.");
		}
		talked = 9;
		SetTimer(2.9,False);
		return;
	}

	if (_MMRPGPlayer(Frobber).bHasJob)
	{
		Player.ReceiveMessage("MECHANIC: You already have a job; you are a "$Player.JobName$"");
		Player.bInConv = False;
		talked = 0;
		return;
	}

	if (!_MMRPGPlayer(Frobber).bMechanic)
	{
		Player.ReceiveMessage(""$Player.PlayerReplicationInfo.PlayerName$": Are there any jobs avaliable?");
		talked = 1;
		SetTimer(1.9,False);
		return;
	}
}

function bool CheckMechTool()
{
	local ElectriciansMultitool too;
	foreach allactors(class'ElectriciansMultitool', too)
	{
		if (too.Owner == talkto)
		{
			return true;
		}
	}
	return false;
}

function Timer()
{
	local int wages;
	local keydummy2 hmm2;
	local MMRPGCreditCard cred;

	if (talked == 1)
	{
		if ( talkto.CheckToolSkill() )
		{
			talkto.ReceiveMessage("MECHANIC: You can begin working as an electrician straight away.");
			talked = 3;
			SetTimer(2.7,False);
			return;
		}
		else if (! talkto.CheckToolskill() )
		{
			talkto.ReceiveMessage("MECHANIC: Not for you with that kind of multitool experience, mate.");
			talkto.bInConv = False;
			talked = 0;
			return;
		}
	}

	else if (talked == 3)
	{
		foreach AllActors(class'keydummy2', hmm2)
		{
				if (talkto.HandleItemPickup(hmm2, True) == False)
				{
					talkto.ReceiveMessage("MECHANIC: Make some room for an Electrician's Tool.");
					talkto.bInConv = False;
					talked = 0;
					return;
				}
		}

		foreach AllActors(class'keydummy2', hmm2)
		{
				if (talkto.HandleItemPickup(hmm2, True) == True)
				{
					talkto.ReceiveMessage("MECHANIC: Take this Electrician's Tool and fix anything that needs fixing");
					bTrade=True;
					talkto.SpawnItemz(Class'ElectriciansMultitool');
					talkto.bMechanic = True;
					talkto.bHasJob = True;
					talkto.JobName = "Mechanic";
					bTrade=False;
					talked = 4;
					SetTimer(3.9,False);
					return;
				}
		}
	}
	else if (talked == 4)
	{
		talkto.ReceiveMessage("MECHANIC: For example fuseboxes");
		talked = 5;
		SetTimer(3.0,False);
		return;
	}
	else if (talked == 5)
	{
		talkto.ReceiveMessage("MECHANIC: Afterwards, come back here to collect your wages.");
		talkto.bInConv = False;
		talked = 0;
		return;
	}
	else if (talked == 9)
	{
		if (talkto.numFixed == 1)
		{
			wages = ( talkto.numFixed * 15 );
			Cred = talkto.CreditCard;
			talkto.ReceiveMessage("MECHANIC: "$talkto.numFixed$" device, 15c each, that's "$wages$" credits!");
			talkto.numFixed = 0;
			Cred.CreditAmount += wages;
			talkto.bInConv = False;
			talked = 0;
			return;
		}
		else
		{
			wages = ( talkto.numFixed * 15 );
			Cred = talkto.CreditCard;
			talkto.ReceiveMessage("MECHANIC: "$talkto.numFixed$" devices, 15c each, that's "$wages$" credits!");
			talkto.numFixed = 0;
			Cred.CreditAmount += wages;
			talkto.bInConv = False;
			talked = 0;
			return;
		}
	}
}

defaultproperties
{
     bfearAlarm=False
     bFearCarcass=False
     bFearDistress=False
     bFearShot=False
     bFearIndirectInjury=False
     Orders=Sitting
     bInvincible=True
     bHateShot=False
     bHateInjury=False
     bReactPresence=False
     bEmitDistress=False
     MinHealth=0.000000
     CarcassType=Class'DeusEx.MechanicCarcass'
     WalkingSpeed=0.296000
     walkAnimMult=0.780000
     GroundSpeed=200.000000
     Texture=Texture'DeusExItems.Skins.PinkMaskTex'
     Mesh=LodMesh'DeusExCharacters.GM_Jumpsuit'
     MultiSkins(0)=Texture'DeusExCharacters.Skins.SkinTex4'
     MultiSkins(1)=Texture'DeusExCharacters.Skins.MechanicTex2'
     MultiSkins(2)=Texture'DeusExCharacters.Skins.MechanicTex1'
     MultiSkins(3)=Texture'DeusExCharacters.Skins.SkinTex4'
     MultiSkins(4)=Texture'DeusExItems.Skins.PinkMaskTex'
     MultiSkins(5)=Texture'DeusExItems.Skins.GrayMaskTex'
     MultiSkins(6)=Texture'DeusExCharacters.Skins.MechanicTex3'
     MultiSkins(7)=Texture'DeusExItems.Skins.PinkMaskTex'
     CollisionRadius=20.000000
     CollisionHeight=47.500000
     BindName="Mechanic"
     FamiliarName="Mechanic"
     UnfamiliarName="Mechanic"
}
