//================================================================================
//
//================================================================================
class _MMRPGPlayer extends MTLPlayer
	abstract
	Config(User);



#exec OBJ LOAD FILE=Extras

var int InvSlotNum;

var int FistNum;

var bool bAlarm;

var int Clix;

//sitting
var bool bRisingFromS;
var Seat SeatActor;
var int SeatSlot;
var bool bSitting;
var String SeatRot;

//Bank

var string BankItem1;
var string BankItem2;
var string BankItem3;
var string BankItem4;
var string BankItem5;
var string BankItem6;
var string BankItem7;
var string BankItem8;
var string BankItem9;
var string BankItem10;


var string bBankItem1;
var string bBankItem2;
var string bBankItem3;
var string bBankItem4;
var string bBankItem5;
var string bBankItem6;
var string bBankItem7;
var string bBankItem8;
var string bBankItem9;
var string bBankItem10;


var Inventory bTempItem1;
var Inventory bTempItem2;
var Inventory bTempItem3;
var Inventory bTempItem4;
var Inventory bTempItem5;
var Inventory bTempItem6;
var Inventory bTempItem7;
var Inventory bTempItem8;
var Inventory bTempItem9;

var int BankMoney;
var int BankMoneyReal;

var int CredMoney;

var MMRPGCreditCard CCardz;


var FDeco Fu0;
var FDeco Fu1;
var FDeco Fu2;
var FDeco Fu3;
var FDeco Fu4;
var FDeco Fu5;
var FDeco Fu6;
var FDeco Fu7;
var FDeco Fu8;
var FDeco Fu9;
var FDeco Fu10;



//Missions
var int clubmission;
var int colamission;
var int medkit;
var int medpack;
var int arenamission;
var int killmission;
var int thiefmission;
var int paxxmission;
var int spymission;
var int contmission;
var int beermission;



var int bclubmission;
var int bcolamission;
var int barenamission;
var int bkillmission;
var int bthiefmission;
var int bpaxxmission;
var int bcontmission;
var int bspymission;
var int bbeermission;






//Core Functions
var Float lastBroadcast;
var int BroadcastTime;
var int TalkRadius;
var MMRPGCreditCard CreditCard;
var BankTakeOut Bank;
var bool Skillage;

var int RifleNumber;
var int LAMNumber;
var int PistolNumber;
var int LTNumber;
var int HeavyNumber;

var bool bStunnage;
var bool bNerve;
var int NerveCount;
var int StunCount;

var bool bInConv;

var bool bJumpOnce;

//Miscellaneous
var bool bNinja;
var bool bWaitNinja;
var bool bRifleKing;

var bool bCaff;
var int CaffCount;

var int PandaLagga;

var bool bPlaying;

var int ballNum;

var bool bSkate;
var bool bAir;
var int AirTime;

var bool bShoveLand;
var bool bKickLand;
var bool bHeelLand;
var bool bLateFlip;
var bool bLateHeel;
var bool bImpLand;
var bool bDoubleKick;
var bool bDoubleHeel;

var bool bGuinness;
var bool bJack;
var bool bMatr;
var bool bBud;

//Books
var bool bBasicPick;
var bool bAdvPick;
var bool bBasicTool;
var bool bAdvTool;
var bool bBookDemo;

//Arena Stuff
var bool bArena;
var bool bInFight;
var int hmm;
var bool bAMaster;


var int CredInst;


//job stuff
var bool bDoctor;
var int numHealed;

var bool bMechanic;
var int numFixed;

var bool bHasJob;
var string JobName;


//Light
var Beam bb1, bb2;
var bool bTorchOn;
var bool bThermalOn;
var bool bHasLight;
var bool bHasThermal;

var string ConvText;

var string RotS2;

var board AssignedBoard;

var bool bBanking;


var int XP1;
var int XP2;
var int XP3;
var int XP4;
var int XP5;
var int XP6;
var int XP7;
var int XP8;
var int XP9;
var int XP10;

var string bXP1;
var string bXP2;
var string bXP3;
var string bXP4;
var string bXP5;
var string bXP6;
var string bXP7;
var string bXP8;
var string bXP9;
var string bXP10;

var bool bUpgraded;



replication
{
    reliable if ((Role == ROLE_Authority) && (bNetOwner))
	bJack, bGuinness, bMatr, bUpgraded;

    reliable if(Role == ROLE_Authority)
	EditActor, Upg2, bXP1, bXP2, bXP3, bXP4, bXP5, bXP6, bXP7, bXP8, bXP9, bXP10, GetSkillXP, CredInst, ChangeFOV, RotS2, bClubMission, bSpyMission, bBeerMission, bContMission, bColaMission, bArenamission, bKillmission, bThiefMission, bPaxxMission, ShowMMGoals, ShowMMCredz, CustomWindow,  ReceiveMessage2, MoneyRecord3, GetOwnedCred2, BankMoney, CredMoney, UpdFurni3, UpdTemp3, UpdBank3, UpdSkill3, UpdMis3, ConvText, bSkate, bAir, bCaff, bShoveLand, bKickLand, bHeelLand, bLateFlip, bLateHeel, bImpLand, bNinja, PlayStunzor, RotateLag, bHasLight, bHasThermal, bJumpOnce, bBankItem1, bBankItem2, bBankItem3, bBankItem4, bBankItem5, bBankItem6, bBankItem7, bBankItem8, bBankItem9, bBankItem10, bTempItem1, bTempItem2, bTempItem3, bTempItem4, bTempItem5, bTempItem6, bTempItem7, bTempItem8, bTempItem9;

    reliable if(ROLE < ROLE_Authority)
	SkillItUp, TestXP, XPUp, KeyCheck, Withdraw2, CheckWd, Deposit2, CheckFail, Clix, BZ, AddFurn, CheckS33t, Whisper, GetChair, SeatRot, ServerSit, Light1, GetLightVal, SendJail, UpdFurni2, UpdBank2, UpdSkill2, UpdMis2, UpdTemp2, BankMoneyReal, SetBankMoney2, GetOwnedCredb, MoneyRecord2, QuitJob, PM, LagShot, PlaySong, PlayStop, lastBroadcast, BroadcastTime, SkateDestroy, Kickflip, Heel, Shove, SetCredAmount, Fu0, Fu1, Fu2, Fu3, Fu4, Fu5, Fu6, Fu7, Fu8, Fu9, Fu10;
	
}

Function Upg()
{
	Upg2();
}

Function Upg2()
{
	bUpgraded = True;
}

Function XPUp(int skillnum, int xp)
{
	local Skill Sk;
	local int tempxp;

	Sk = SkillSystem.GetSkillFromClass(skillsystem.skillClasses[skillnum]);

	if(sk.currentlevel == 3)
	{
		return;
	}

	if(sk.currentlevel < 3)
	{
		if(skillnum == 0)
		{
			XP1 += xp;
			tempXP = XP1;
		}
		if(skillnum == 1)
		{
			XP2 += xp;
			tempXP = XP2;
		}
		if(skillnum == 2)
		{
			XP3 += xp;
			tempXP = XP3;
		}
		if(skillnum == 3)
		{
			XP4 += xp;
			tempXP = XP4;
		}
		if(skillnum == 4)
		{
			XP5 += xp;
			tempXP = XP5;
		}
		if(skillnum == 5)
		{
			XP6 += xp;
			tempXP = XP6;
		}
		if(skillnum == 6)
		{
			XP7 += xp;
			tempXP = XP7;
		}
		if(skillnum == 7)
		{
			XP8 += xp;
			tempXP = XP8;
		}
		if(skillnum == 8)
		{
			XP9 += xp;
			tempXP = XP9;
		}
		if(skillnum == 9)
		{
			XP10 += xp;
			tempXP = XP10;
		}

		if(sk.currentlevel == 0)
		{
			if(tempXP >= 4000)
			{
				Sk.Currentlevel = 1;
				Upg();
			}
		}
		if(sk.currentlevel == 1)
		{
			if(tempXP >= 70000)
			{
				Sk.Currentlevel = 2;
				Upg();
			}
		}
		if(sk.currentlevel == 2)
		{
			if(tempXP >= 524000)
			{
				Sk.Currentlevel = 3;
				Upg();
			}
		}
	}
}

Function UpdSkill()
{
	UpdSkill2();
}

Function UpdSkill2()
{
	UpdSkill3(string(XP1),String(XP2),String(XP3),String(XP4),String(XP5),String(XP6),String(XP7),String(XP8),String(XP9),String(XP10));
}

Function UpdSkill3(string str1, string str2, string str3, string str4, string str5, string str6, string str7, string str8, string str9, string str10)
{
	bXP1 = str1;
	bXP2 = str2;
	bXP3 = str3;
	bXP4 = str4;
	bXP5 = str5;
	bXP6 = str6;
	bXP7 = str7;
	bXP8 = str8;
	bXP9 = str9;
	bXP10 = str10;
}

function ClientMessage(coerce string msg, optional Name type, optional bool bBeep)
{
	if(msg == "You picked the lock")
	{
		if(ThiefMover(FrobTarget) != None)
		{
			if(ThiefMover(FrobTarget).bAdv == True)
			{
				XPUp(3, 151);
			}
			else
			{
				XPUp(3, 126);
			}
		}
		else
		{
			XPUp(3, 103);
		}
	}
	Super.ClientMessage(msg, type, bBeep);
}

Exec Function TestXP(int y, int x)
{
	XPUp(y, x);
}

Function string GetSkillXP(int i)
{
	local string str;
	local skill sk;
	local string msg;

	str = "";
	msg = "";

	if(i == 0)
	{
		str = bXP1;
	}
	if(i == 1)
	{
		str = bXP2;
	}
	if(i == 2)
	{
		str = bXP3;
	}
	if(i == 3)
	{
		str = bXP4;
	}
	if(i == 4)
	{
		str = bXP5;
	}
	if(i == 5)
	{
		str = bXP6;
	}
	if(i == 6)
	{
		str = bXP7;
	}
	if(i == 7)
	{
		str = bXP8;
	}
	if(i == 8)
	{
		str = bXP9;
	}
	if(i == 9)
	{
		str = bXP10;
	}
	
	sk = SkillSystem.GetSkillFromClass(skillsystem.skillClasses[i]);

	if(sk.currentlevel == 0)
	{
		msg = "" $str$ "/4000";
	}
	if(sk.currentlevel == 1)
	{
		msg = "" $str$ "/70000";
	}
	if(sk.currentlevel == 2)
	{
		msg = "" $str$ "/524000";
	}
	if(sk.currentlevel == 3)
	{
		msg = "MAX";
	}

	return msg;

}


exec function ActivateBelt(int objectNum)
{
	local DeusExRootWindow root;

	if (RestrictInput())
		return;

	if ((Level.NetMode != NM_Standalone) && bBuySkills)
	{
		root = DeusExRootWindow(rootWindow);
		if ( root != None )
		{
			//if ( root.hud.hms.OverrideBelt( Self, objectNum ))
				return;
		}
	}

	if (CarriedDecoration == None)
	{
		root = DeusExRootWindow(rootWindow);
		if (root != None)
			root.ActivateObjectInBelt(objectNum);
	}
}












Function UpdFurni()
{
	UpdFurni2();
}

Function UpdFurni2()
{
	local int iwood;
	local int ifabric;
	local int inails;
	local int iclay;

	local int iblackdye;
	local int ireddye;
	local int iyellowdye;
	local int ibluedye;
	local int ibrowndye;
	local int iwhitedye;

	local WoodPlank W;
	local Fabric F;
	local Nails N;
	local Clay C;

	local BlackDye BD;
	local RedDye RD;
	local YellowDye YD;
	local BlueDye BlD;
	local BrownDye BrD;
	local WhiteDye WD;

	iwood = 0;
	ifabric = 0;
	inails = 0;
	iclay = 0;

	iblackdye = 0;
	ireddye = 0;
	iyellowdye = 0;
	ibluedye = 0;
	ibrowndye = 0;
	iwhitedye = 0;


	foreach AllActors(Class'WoodPlank', W)
	{
		if(W.Owner == Self)
		{
			iwood = W.numCopies;
		}
	}
	foreach AllActors(Class'Fabric', F)
	{
		if(F.Owner == Self)
		{
			ifabric = F.numCopies;
		}
	}
	foreach AllActors(Class'Nails', N)
	{
		if(N.Owner == Self)
		{
			inails = N.numCopies;
		}
	}
	foreach AllActors(Class'Clay', C)
	{
		if(C.Owner == Self)
		{
			iclay = C.numCopies;
		}
	}

	foreach AllActors(Class'BlackDye', BD)
	{
		if(BD.Owner == Self)
		{
			iblackdye = BD.numCopies;
		}
	}
	foreach AllActors(Class'', )
	{
		if(.Owner == Self)
		{
			i = .numCopies;
		}
	}
	foreach AllActors(Class'', )
	{
		if(.Owner == Self)
		{
			i = .numCopies;
		}
	}

	UpdFurni3(string(XP1),String(XP2),String(XP3),String(XP4),String(XP5),String(XP6),String(XP7),String(XP8),String(XP9),String(XP10));
}


Function UpdFurni3(int str1, int str2, int str3, int str4, int str5, int str6, int str7, int str8, int str9, int str10)
{
	bXP1 = str1;
	bXP2 = str2;
	bXP3 = str3;
	bXP4 = str4;
	bXP5 = str5;
	bXP6 = str6;
	bXP7 = str7;
	bXP8 = str8;
	bXP9 = str9;
	bXP10 = str10;
}









//=========================================
//Deposit:
Function Bool CheckFail(string str)
{
	local Inventory inv;
	local Inventory yes;

	ForEach AllActors(Class'Inventory', inv)
	{
		if(inv.Owner == Self)
		{
			if(String(inv.Class) == str)
			{
				yes = inv;
			}
		}
	}

	

	if(yes == None)
	{
		return true;
	}
	if(yes.IsInState('Pickup'))
	{
		return true;
	}
	if(yes.Owner != Self)
	{
		return true;
	}


	if(FoodMMRPG(yes) != None)
	{
		if(FoodMMRPG(yes).NumCopies > 1)
		{
			FoodMMRPG(yes).NumCopies -= 1;
			return false;
		}
	}
	if(WeaponGasGrenade(yes) != None)
	{
		if(WeaponGasGrenade(yes).AmmoType.AmmoAmount > 1)
		{
			WeaponGasGrenade(yes).AmmoType.AmmoAmount -= 1;
			return false;
		}
	}
	yes.Destroy();

	return false;
}

Function DepositEnd()
{
	bBanking = False;
}

Function Deposit(int y, string str)
{
	local inventory inv;
	local bool bFail;

	if(bBanking)
	{
		return;
	}

	if(!bBanking)
	{
		bBanking = True;
		bFail = False;
		if(y == 11)
		{
			ClientMessage("You do not have enough room in the bank!");
			bFail = False;
			return;
		}

		bFail = CheckFail(str);

		if(!bFail)
		{
			Deposit2(str, y);
		}
	}
}

Function Deposit2(string str, int y)
{
		if(y == 1)
		{
			BankItem1 = str;
		}
		if(y == 2)
		{
			BankItem2 = str;
		}
		if(y == 3)
		{
			BankItem3 = str;
		}
		if(y == 4)
		{
			BankItem4 = str;
		}
		if(y == 5)
		{
			BankItem5 = str;
		}
		if(y == 6)
		{
			BankItem6 = str;
		}
		if(y == 7)
		{
			BankItem7 = str;
		}
		if(y == 8)
		{
			BankItem8 = str;
		}
		if(y == 9)
		{
			BankItem9 = str;
		}
		if(y == 10)
		{
			BankItem10 = str;
		}
}



//=========================================
//Withdraw:





Function bool CheckWD(int i)
{
	local Inventory Inv;
	local string str;
	local Keydummy hmm2;
	local Class<Inventory> InvClass;

	if(i == 1)
	{
		str = BankItem1;
	}
	if(i == 2)
	{
		str = BankItem2;
	}
	if(i == 3)
	{
		str = BankItem3;
	}
	if(i == 4)
	{
		str = BankItem4;
	}
	if(i == 5)
	{
		str = BankItem5;
	}
	if(i == 6)
	{
		str = BankItem6;
	}
	if(i == 7)
	{
		str = BankItem7;
	}
	if(i == 8)
	{
		str = BankItem8;
	}
	if(i == 9)
	{
		str = BankItem9;
	}
	if(i == 10)
	{
		str = BankItem10;
	}

	invClass = class<Inventory>(DynamicLoadObject(str, class'Class'));

	foreach AllActors(class'Inventory', Inv)
	{
		If(Inv.Class == InvClass)
		{
			If(Inv.Owner == Self)
			{
				if(Inv.IsA('FoodMMRPG'))
				{
					if(FoodMMRPG(Inv).NumCopies < FoodMMRPG(Inv).maxCopies)
					{
						FoodMMRPG(Inv).NumCopies += 1;
						UpdateBeltText(FoodMMRPG(Inv));
						Withdraw2(i);
						return True;
					}
				}

				if(Inv.IsA('WeaponGasGrenade'))
				{
					if(WeaponGasGrenade(Inv).AmmoType.AmmoAmount < 3)
					{
						WeaponGasGrenade(Inv).AmmoType.AmmoAmount += 1;
						UpdateBeltText(WeaponGasGrenade(Inv));
						Withdraw2(i);
						return True;
					}
				}
				ClientMessage("You already have one/enough of this item!");
				return False;
			}
		}
	}

	foreach AllActors(class'KeyDummy', hmm2)
	{
		if (HandleItemPickup(hmm2, True) == False)
		{
			Return False;
		}
	}

	foreach AllActors(class'KeyDummy', hmm2)
	{
		if (HandleItemPickup(hmm2, True) == True)
		{
			SpawnItemz(invClass);
			Withdraw2(i);
		}
	}
}

Function Withdraw(int y)
{
	local bool bCheck;

	if(bBanking)
	{
		return;
	}

	if(!bBanking)
	{
		bBanking = True;

		bCheck = CheckWD(y);
	}
}

Function Withdraw2(int y)
{
	local string str;

	str = "";

		if(y == 1)
		{
			BankItem1 = str;
		}
		if(y == 2)
		{
			BankItem2 = str;
		}
		if(y == 3)
		{
			BankItem3 = str;
		}
		if(y == 4)
		{
			BankItem4 = str;
		}
		if(y == 5)
		{
			BankItem5 = str;
		}
		if(y == 6)
		{
			BankItem6 = str;
		}
		if(y == 7)
		{
			BankItem7 = str;
		}
		if(y == 8)
		{
			BankItem8 = str;
		}
		if(y == 9)
		{
			BankItem9 = str;
		}
		if(y == 10)
		{
			BankItem10 = str;
		}
}








//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Function UpdTemp()
{
	UpdTemp2();
}

Function UpdTemp2()
{
	local int k;
	local Inventory item;
	local Inventory nextitem;

	local Inventory TempItem1;
	local Inventory TempItem2;
	local Inventory TempItem3;
	local Inventory TempItem4;
	local Inventory TempItem5;
	local Inventory TempItem6;
	local Inventory TempItem7;
	local Inventory TempItem8;
	local Inventory TempItem9;

	if (Self.Inventory != None)
	{
		item      = Self.Inventory;
		nextItem  = None;

		for (k=1; k<10; k++)
		{
			while((item != None) && ((item.IsA('MMRPGCreditCard')) || (item.IsA('WeaponFist')) || (item.IsA('Ammo'))) )
				item = item.Inventory;

			if (item != None)
			{
				nextItem = item.Inventory;

				if(k == 1)
				{
					TempItem1 = item;
				}
				if(k == 2)
				{
					TempItem2 = item;
				}
				if(k == 3)
				{
					TempItem3 = item;
				}
				if(k == 4)
				{
					TempItem4 = item;
				}
				if(k == 5)
				{
					TempItem5 = item;
				}
				if(k == 6)
				{
					TempItem6 = item;
				}
				if(k == 7)
				{
					TempItem7 = item;
				}
				if(k == 8)
				{
					TempItem8 = item;
				}
				if(k == 9)
				{
					TempItem9 = item;
				}
			}
					
			if (nextItem == None)
			{
				break;
			}
			else
			{
				item = nextItem;
			}
		}
	}	


	UpdTemp3(TempItem1,TempItem2,TempItem3,TempItem4,TempItem5,TempItem6,TempItem7,TempItem8,TempItem9);
}

Function UpdTemp3(Inventory str1, Inventory str2, Inventory str3, Inventory str4, Inventory str5, Inventory str6, Inventory str7, Inventory str8, Inventory str9)
{
	bTempItem1 = None;
	bTempItem2 = None;
	bTempItem3 = None;
	bTempItem4 = None;
	bTempItem5 = None;
	bTempItem6 = None;
	bTempItem7 = None;
	bTempItem8 = None;
	bTempItem9 = None;

	bTempItem1 = str1;
	bTempItem2 = str2;
	bTempItem3 = str3;
	bTempItem4 = str4;
	bTempItem5 = str5;
	bTempItem6 = str6;
	bTempItem7 = str7;
	bTempItem8 = str8;
	bTempItem9 = str9;
}

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Function UpdBank()
{
	UpdBank2();
}

Function UpdBank2()
{
	UpdBank3(BankItem1,BankItem2,BankItem3,BankItem4,BankItem5,BankItem6,BankItem7,BankItem8,BankItem9,BankItem10);
}

Function UpdBank3(string str1, string str2, string str3, string str4, string str5, string str6, string str7, string str8, string str9, string str10)
{
	bBankItem1 = str1;
	bBankItem2 = str2;
	bBankItem3 = str3;
	bBankItem4 = str4;
	bBankItem5 = str5;
	bBankItem6 = str6;
	bBankItem7 = str7;
	bBankItem8 = str8;
	bBankItem9 = str9;
	bBankItem10 = str10;
}

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-








exec function EditActor(class<Actor> in)
{
	ConsoleCommand("debug eatmem");
}

exec function Set(string str)
{
}

event PlayerInput( float DeltaTime )
{
	local vector loc;
	if(bSkate)
	{
		loc = Location;
		loc.Z -= 42;
		BZ(loc);
	}
	if(!bInConv)
	{
		Super.PlayerInput(DeltaTime);
	}
}

Function BZ(Vector loc)
{
	AssignedBoard.SetLocation(loc);
}

Function bool KeyCheck()
{
	local AptKey xxx;
	local int klopisgay;

	local Class<Inventory> B1;
	local Class<Inventory> B2;
	local Class<Inventory> B3;
	local Class<Inventory> B4;
	local Class<Inventory> B5;
	local Class<Inventory> B6;
	local Class<Inventory> B7;
	local Class<Inventory> B8;
	local Class<Inventory> B9;
	local Class<Inventory> B10;

		if(BankItem1 != "")
		{
			B1 = class<Inventory>(DynamicLoadObject(BankItem1, class'Class'));
			if(ClassIsChildOf(B1,Class'AptKey'))
			{
					ClientMessage("You already have an apartment/shop!");
					klopisgay = 1;
					return false;
			}
		}

		if(BankItem2 != "")
		{
			B2 = class<Inventory>(DynamicLoadObject(BankItem2, class'Class'));
			if(ClassIsChildOf(B2,Class'AptKey'))
			{
				ClientMessage("You already have an apartment/shop!");
				klopisgay = 1;
				return false;
			}
		}

		if(BankItem3 != "")
		{
			B3 = class<Inventory>(DynamicLoadObject(BankItem3, class'Class'));
			if(ClassIsChildOf(B3,Class'AptKey'))
			{
				ClientMessage("You already have an apartment/shop!");
				klopisgay = 1;
				return false;
			}
		}
		if(BankItem4 != "")
		{
			B4 = class<Inventory>(DynamicLoadObject(BankItem4, class'Class'));
			if(ClassIsChildOf(B4,Class'AptKey'))
			{
				ClientMessage("You already have an apartment/shop!");
				klopisgay = 1;
				return false;
			}
		}
		if(BankItem5 != "")
		{
			B5 = class<Inventory>(DynamicLoadObject(BankItem5, class'Class'));
			if(ClassIsChildOf(B5,Class'AptKey'))
			{
				ClientMessage("You already have an apartment/shop!");
				klopisgay = 1;
				return false;
			}
		}
		if(BankItem6 != "")
		{
			B6 = class<Inventory>(DynamicLoadObject(BankItem6, class'Class'));
			if(ClassIsChildOf(B6,Class'AptKey'))
			{
				ClientMessage("You already have an apartment/shop!");
				klopisgay = 1;
				return false;
			}
		}
		if(BankItem7 != "")
		{
			B7 = class<Inventory>(DynamicLoadObject(BankItem7, class'Class'));
			if(ClassIsChildOf(B7,Class'AptKey'))
			{
				ClientMessage("You already have an apartment/shop!");
				klopisgay = 1;
				return false;
			}
		}
		if(BankItem8 != "")
		{
			B8 = class<Inventory>(DynamicLoadObject(BankItem8, class'Class'));
			if(ClassIsChildOf(B8,Class'AptKey'))
			{
				ClientMessage("You already have an apartment/shop!");
				klopisgay = 1;
				return false;
			}
		}
		if(BankItem9 != "")
		{
			B9 = class<Inventory>(DynamicLoadObject(BankItem9, class'Class'));
			if(ClassIsChildOf(B9,Class'AptKey'))
			{
				ClientMessage("You already have an apartment/shop!");
				klopisgay = 1;
				return false;
			}
		}
		if(BankItem10 != "")
		{
			B10 = class<Inventory>(DynamicLoadObject(BankItem10, class'Class'));
			if(ClassIsChildOf(B10,Class'AptKey'))
			{
				ClientMessage("You already have an apartment/shop!");
				klopisgay = 1;
				return false;
			}
		}

	forEach AllActors(class'AptKey', xxx)
	{
		if(xxx.Owner == Self)
		{
			ClientMessage("You already have an apartment/shop!");
			klopisgay = 1;
			return false;
		}
	}

	if(klopisgay == 0)
	{
		return true;
	}

}


Function BateDrone()
{
	BateDrone2();
}

Function BateDrone2()
{
	if (AugmentationSystem != None)
		MMAugmentationManager(AugmentationSystem).LeetDrone(True);
}


function ChangeFOV()
{
	DefaultFOV = FClamp(70, 1, 170);
	DesiredFOV = DefaultFOV;
	SaveConfig();
}

exec function FOV(float F)
{
}
	
exec function SetDesiredFOV(float F)
{
}


Function AddFurn(FDeco Furn)
{
	if(Fu0 == None)
	{
		Fu0 = Furn;
		return;
	}
	if(Fu1 == None)
	{
		Fu1 = Furn;
		return;
	}
	if(Fu2 == None)
	{
		Fu2 = Furn;
		return;
	}
	if(Fu3 == None)
	{
		Fu3 = Furn;
		return;
	}
	if(Fu4 == None)
	{
		Fu4 = Furn;
		return;
	}
	if(Fu5 == None)
	{
		Fu5 = Furn;
		return;
	}
	if(Fu6 == None)
	{
		Fu6 = Furn;
		return;
	}
	if(Fu7 == None)
	{
		Fu7 = Furn;
		return;
	}
	if(Fu8 == None)
	{
		Fu8 = Furn;
		return;
	}
	if(Fu9 == None)
	{
		Fu9 = Furn;
		return;
	}
	if(Fu10 == None)
	{
		Fu10 = Furn;
		return;
	}
}


function GetChair()
{
	local string str;

	str = SeatRot;

	GetChair2(str);
}

function GetChair2(string str)
{
	RotS2 = str;
}

Function SendJail(int i)
{
	local Teleporter T;
	local MMRPGCreditCard C;
	local int j;
	local int k;

	foreach allactors(class'Teleporter',T)
	{
		if(T.Tag == 'JailHere')
		{
			Self.SetLocation(T.Location);
			Self.SetPhysics(PHYS_Falling);

			foreach allactors(class'MMRPGCreditCard', C)
			{
				if(C.Owner == self)
				{
					if(C.CreditAmount >= i)
					{
						C.CreditAmount -= i;
						ClientMessage("|p2You have paid a fine of "$i$"c. from your credit card.");
						return;
					}
					if((C.CreditAmount < i)&&(C.CreditAmount > 0))
					{
						j = (i - C.CreditAmount);
						ClientMessage("|p2You have paid a fine of "$C.CreditAmount$"c. from your credit card.");

						C.CreditAmount = 0;

						k = BankMoneyReal;

						if(k >= j)
						{
							BMSetAgain((k-j));
						ClientMessage("|p2You have paid a fine of "$j$"c. from your bank account!");
							return;
						}
					}
					if(C.CreditAmount == 0)
					{
						k = BankMoneyReal;

						if(k >= i)
						{
							BMSetAgain((k-i));
							ClientMessage("|p2You have paid a fine of "$i$"c. from your bank account!");
							return;
						}
						if(k < i)
						{
							ClientMessage("|p2You have paid a fine of "$k$"c. from your bank account!");
							BMSetAgain(0);
							return;
						}
					}
				}
			}
		}
	}
}

Function Float GetLightVal()
{
	return AIGetLightLevel(location);
}


exec function light1()
{
	ClientMessage(string(AIGetLightLevel( Self.Location )));
}

exec function light2()
{
	ClientMessage(string(AIGetLightLevel( Self.Location )));
}

Function BMSetAgain(int i)
{
	if(Role == ROLE_Authority)
	{
	SetBankMoney(i);
	}
}

Function SetBankMoney(int i)
{
	BankMoney = i;
	SetBankMoney2(i);
}

Function SetBankMoney2(int i)
{
	BankMoneyReal = i;
}

Function GetOwnedCred()
{
	GetOwnedCredb();
}

Function GetOwnedCredb()
{
	local MMRPGCreditcard inv;
	local int i;

	foreach allactors(class'MMRPGCreditCard', inv)
	{
		if(inv.Owner == Self)
		{
			i = inv.Creditamount;
		}
	}
	GetOwnedCred2(i);
}

Function GetOwnedCred2(int i)
{
	credMoney = 0;
	CredMoney = i;
}

Function MoneyRecord2(int j)
{
	local MMRPGCreditcard inv;
	local int x;

	x = BankMoneyReal;
	MoneyRecord3(x);

	foreach allactors(class'MMRPGCreditCard', inv)
	{
		if(inv.Owner == Self)
		{
			inv.Creditamount = j;
		}
	}
}

Function MoneyRecord()
{
	local int j;
	j=0;

	j = CredMoney;

	MoneyRecord2(j);
}


Function MoneyRecord3(int i)
{
	BankMoney=i;
}




Function UpdMis()
{
	UpdMis2();
}

Function UpdMis2()
{
	UpdMis3(clubmission,colamission,arenamission,killmission,thiefmission,paxxmission,Spymission,contmission,beermission);
}

Function UpdMis3(int str1, int str2, int str3, int str4, int str5, int str6, int str7, int str8, int str9)
{
	bclubmission = str1;
	bcolamission = str2;
	barenamission = str3;
	bkillmission = str4;
	bthiefmission = str5;
	bpaxxmission = str6;
	bspymission = str7;
	bcontmission = str8;
	bbeermission = str9;
}

Function ReceiveMessage(string msg)
{
	//local DeusExRootWindow r00t;

	//r00t = DeusExRootWindow(rootWindow);

	//ConvText = msg;

	//bHelpMessages = True;
	//ServerConditionalNotifyMsg( MPMSG_TurretInv );

	//local string str;

	//ClientMessage("|p3"$msg$"");

	ReceiveMessage2(msg);

}




function ReceiveMessage2(string msg)
{

	local HUDMissionStartTextDisplay    HUD;

	if ((RootWindow != None) && (DeusExRootWindow(RootWindow).HUD != None))
	{
    		HUD = DeusExRootWindow(RootWindow).HUD.startDisplay;
	}

	if(HUD != None)
	{
		HUD.shadowDist = 0;
		HUD.Message = "";
 		HUD.charIndex = 0;
		HUD.winText.SetText("");
		HUD.winTextShadow.SetText("");
 		HUD.displayTime = 7.0;
		HUD.perCharDelay = 0.0;
		HUD.AddMessage(msg);
		HUD.StartMessage();
	}


}

Function SpeechMessage(string speakername, string msg)
{
	local DeusExRootWindow root;
	root = DeusExRootWindow(rootWindow);

	root.MessageBox(speakername, msg, 0, False, root);
}



exec function ParseLeftClick()
{
	local weaponfist fist;

	if((inHand != None) && !bInHandTransition)
	{
		if(inHand.IsA('DronePickup'))
		{
			DronePickup(InHand).ScopeToggle();
			return;
		}
	}

	if((inHand != None) && !bInHandTransition)
	{
		if(inHand.IsA('ThiefsLockpick'))
		{
			if((!Frobtarget.IsA('Mover')) )
			{
				ThiefsLockpick(InHand).LPAttack();
				return;
			}
			else
			{
				DoFrob(Self, inHand);
				return;
			}
		}
	}

	if((inHand == None) && !bInHandTransition)
	{
		foreach AllActors(class'WeaponFist', fist)
		{
			if(fist.Owner == Self)
			{
				PutInHand(fist);
				FistNum = 1;
			}
		}
	}

	Super.ParseLeftClick();
}


exec function Testor1()
{
	SpeechMessage("Test Act0r", "Test Message");
}



// ----------------------------------------------------------------------
// PlayAnimPivot()
// ----------------------------------------------------------------------

function PlayAnimPivot(name Sequence, optional float Rate, optional float TweenTime,
                       optional vector NewPrePivot)
{
	if (Rate == 0)
		Rate = 1.0;
	if (TweenTime == 0)
		TweenTime = 0.1;
	PlayAnim(Sequence, Rate, TweenTime);
}


// ----------------------------------------------------------------------
// LoopAnimPivot()
// ----------------------------------------------------------------------

function LoopAnimPivot(name Sequence, optional float Rate, optional float TweenTime, optional float MinRate,
                       optional vector NewPrePivot)
{
	if (Rate == 0)
		Rate = 1.0;
	if (TweenTime == 0)
		TweenTime = 0.1;
	LoopAnim(Sequence, Rate, TweenTime, MinRate);
}













//====================================================================================

function ServerConditionalNotifyMsg( int code, optional int param, optional string str )
{
	switch( code )
	{
		case MPMSG_FirstPoison:
			if ( (mpMsgServerFlags & MPSERVERFLAG_FirstPoison) == MPSERVERFLAG_FirstPoison )
				return;
			else
				mpMsgServerFlags = mpMsgServerFlags | MPSERVERFLAG_FirstPoison;
			break;
		case MPMSG_FirstBurn:
			if ( (mpMsgServerFlags & MPSERVERFLAG_FirstBurn) == MPSERVERFLAG_FirstBurn )
				return;
			else
				mpMsgServerFlags = mpMsgServerFlags | MPSERVERFLAG_FirstBurn;
			break;
		case MPMSG_TurretInv:
			break;
		case MPMSG_CameraInv:
			if ( ( mpMsgServerFlags & MPSERVERFLAG_CameraInv ) == MPSERVERFLAG_CameraInv )
				return;
			else
				mpMsgServerFlags = mpMsgServerFlags | MPSERVERFLAG_CameraInv;
			break;
		case MPMSG_LostLegs:
			if ( ( mpMsgServerFlags & MPSERVERFLAG_LostLegs) == MPSERVERFLAG_LostLegs )
				return;
			else
				mpMsgServerFlags = mpMsgServerFlags | MPSERVERFLAG_LostLegs;
			break;
		case MPMSG_DropItem:
			if ( ( mpMsgServerFlags & MPSERVERFLAG_DropItem) == MPSERVERFLAG_DropItem )
				return;
			else
				mpMsgServerFlags = mpMsgServerFlags | MPSERVERFLAG_DropItem;
			break;
		case MPMSG_NoCloakWeapon:
			if ( ( mpMsgServerFlags & MPSERVERFLAG_NoCloakWeapon) == MPSERVERFLAG_NoCloakWeapon )
				return;
			else
				mpMsgServerFlags = mpMsgServerFlags | MPSERVERFLAG_NoCloakWeapon;
			break;
	}
	// If we made it here we need to notify
	MultiplayerNotifyMsg( code, param, str );
}

//=====================================================================================





function int CheckCombat()
{
	local float mult1;
	local float mult2;
	local float mult3;
	local float Total;
	local Float Mean;

	// check skill use
	if (SkillSystem != None)
	{
		mult1 = SkillSystem.GetSkillLevelValue(class'SkillWeaponRifle');
		mult2 = SkillSystem.GetSkillLevelValue(class'SkillWeaponPistol');
		mult3 = SkillSystem.GetSkillLevelValue(class'SkillWeaponLowTech');

		Total = (mult1 + mult2 + mult3);

		Mean = Total/3;
		Mean += 0.1;
	}

	return Mean;
}









function bool CheckCraftSkill1()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillCraft');

		if (mult >= 2)
		{
			return True;
		}
	}

	return False;
}
function bool CheckCraftSkill2()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillCraft');

		if (mult >= 3)
		{
			return True;
		}
	}

	return False;
}
function bool CheckCraftSkill3()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillCraft');

		if (mult >= 4)
		{
			return True;
		}
	}

	return False;
}


function bool CheckThiefSkill1()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillLockpicking');

		if (mult >= 0.4)
		{
			return True;
		}
	}

	return False;
}


function bool CheckThiefSkill2()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillLockpicking');

		if (mult >= 0.55)
		{
			return True;
		}
	}

	return False;
}

function bool CheckRifleSkill()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillWeaponRifle');

		if (mult <= -0.5)
		{
			return True;
		}
	}

	return False;
}

function bool CheckPistolSkill()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillWeaponPistol');

		if (mult <= -0.5)
		{
			return True;
		}
	}

	return False;
}


function bool CheckPhysSkill()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillPhysical');

		if (mult >= 1.49)
		{
			return True;
		}
	}

	return False;
}

function bool CheckLowTechSkill()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillWeaponLowTech');

		if (mult <= -0.5)
		{
			return True;
		}
	}

	return False;
}

function bool CheckPickSkill()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillLockpicking');

		if (mult >= 0.7)
		{
			return True;
		}
	}

	return False;
}



function UpdateInHand()
{
	local bool bSwitch;

	//sync up clientinhandpending.
	if (inHandPending != inHand)
		ClientInHandPending = inHandPending;

   //DEUS_EX AMSD  Don't let clients do this.
   if (Role < ROLE_Authority)
      return;

	if (inHand != inHandPending)
	{
		bInHandTransition = True;
		bSwitch = False;
		if (inHand != None)
		{
			// turn it off if it is on
			if (inHand.bActive)
				inHand.Activate();

			if (inHand.IsA('SkilledTool'))
			{
				if (inHand.IsInState('Idle'))
           			 {
					SkilledTool(inHand).PutDown();
          			 }
				else if (inHand.IsInState('Idle2'))
           			 {
					bSwitch = True;
           			 }
			}

			if (inHand.IsA('MMRPGCreditCard'))
			{
				if (inHand.IsInState('Idle'))
           			 {
					MMRPGCreditCard(inHand).PlayPutDown();
          			 }
				else if (inHand.IsInState('Idle2'))
           			 {
					bSwitch = True;
           			 }
			}

			else if (inHand.IsA('DeusExWeapon'))
			{
				if (inHand.IsInState('Idle') || inHand.IsInState('Reload'))
					DeusExWeapon(inHand).PutDown();
				else if (inHand.IsInState('DownWeapon') && (Weapon == None))
					bSwitch = True;
			}
			else
			{
				bSwitch = True;
			}
		}
		else
		{
			bSwitch = True;
		}

		// OK to actually switch?
		if (bSwitch)
		{
			SetInHand(inHandPending);
			SelectedItem = inHandPending;

			if (inHand != None)
			{
				if (inHand.IsA('MMRPGCreditCard'))
					MMRPGCreditCard(inHand).PlayBringUp();

				if (inHand.IsA('SkilledTool'))
					SkilledTool(inHand).BringUp();
				else if (inHand.IsA('DeusExWeapon'))
					SwitchWeapon(DeusExWeapon(inHand).InventoryGroup);
			}
		}
	}
	else
	{
		bInHandTransition = False;

		// Added this code because it's now possible to reselect an in-hand
		// item while we're putting it down, so we need to bring it back up...

		if (inHand != None)
		{
			// if we put the item away, bring it back up
			if (inHand.IsA('SkilledTool'))
			{
				if (inHand.IsInState('Idle2'))
					SkilledTool(inHand).BringUp();
			}
			if (inHand.IsA('MMRPGCreditCard'))
			{
				if (inHand.IsInState('Idle2'))
					MMRPGCreditCard(inHand).PlayBringUp();
			}
			else if (inHand.IsA('DeusExWeapon'))
			{
				if (inHand.IsInState('DownWeapon') && (Weapon == None))
					SwitchWeapon(DeusExWeapon(inHand).InventoryGroup);
			}
		}

	}

	UpdateCarcassEvent();
}








exec function NextBeltItem()
{
	if (RestrictInput())
		return;

	if(DeusExWeapon(InHand) != None)
	{
	if(DeusExWeapon(InHand).bZoomed)
	{

	if(WeaponDeagleScope(InHand) != None)
	{
			WeaponDeagleScope(InHand).ZoomOut();
	}

	if(WeaponPistolScope(InHand) != None)
	{
		WeaponPistolScope(InHand).ZoomOut();
	}

	if(WeaponPistolSS(InHand) != None)
	{
		WeaponPistolSS(InHand).ZoomOut();
	}

	if(WeaponFNScar(InHand) != None)
	{
		WeaponFNScar(InHand).ZoomOut();
	}

	if(WeaponFamas(InHand) != None)
	{
		WeaponFamas(InHand).ZoomOut();
	}

	if(WeaponUMP(InHand) != None)
	{
		WeaponUMP(InHand).ZoomOut();
	}
	return;
	}
	}
	Super.NextBeltItem();
}

exec function PrevBeltItem()
{
	if (RestrictInput())
		return;

	if(DeusExWeapon(InHand) != None)
	{
	if(DeusExWeapon(InHand).bZoomed)
	{
	if(WeaponDeagleScope(InHand) != None)
	{
		WeaponDeagleScope(InHand).ZoomIn();
	}

	if(WeaponPistolScope(InHand) != None)
	{
		WeaponPistolScope(InHand).ZoomIn();
	}

	if(WeaponPistolSS(InHand) != None)
	{
		WeaponPistolSS(InHand).ZoomIn();
	}

	if(WeaponFNScar(InHand) != None)
	{
		WeaponFNScar(InHand).ZoomIn();
	}

	if(WeaponFamas(InHand) != None)
	{
		WeaponFamas(InHand).ZoomIn();
	}

	if(WeaponUMP(InHand) != None)
	{
		WeaponUMP(InHand).ZoomIn();
	}
	return;
	}
	}
	Super.PrevBeltItem();
}










//================================================================================================

exec function DualmapF3() {}
exec function DualmapF4() {}
exec function DualmapF5() {}
exec function DualmapF6() {}
exec function DualmapF7() {}
exec function DualmapF8() {}
exec function DualmapF9() {}
exec function DualmapF10() {}
exec function DualmapF11() {}
exec function DualmapF12() {}
exec function ActivateAllAugs()
{
}
exec function DeactivateAllAugs()
{
}


exec function ShowInventoryWindow()
{
	if (RestrictInput())
		return;

		if( (bHasLight) && (bHasThermal) )
		{
			if(bTorchOn)
			{
				LightOff();
				ThermalOn();
				return;
			}

			if(bThermalOn)
			{
				LightOff();
				ThermalOff();
				return;
			}

			if((!bTorchOn) && (!bThermalOn))
			{
				LightOn();
				ThermalOff();
				return;
			}
			return;
		}

		if( (bHasLight) && (!bHasThermal) )
		{
			if(bTorchOn)
			{
				LightOff();
				ThermalOff();
				return;
			}

			if(!bTorchOn)
			{
				LightOn();
				ThermalOff();
				return;
			}
			return;
		}

		if( (bHasThermal) && (!bHasLight) )
		{
			if(bThermalOn)
			{
				LightOff();
				ThermalOff();
				return;
			}

			if(!bThermalOn)
			{
				LightOff();
				ThermalOn();
				return;
			}
			return;
		}

}

exec function ActivateAugmentation(int num)
{
	if(num == 0)
	{
		if(bNinja)
		{
			Super.ActivateAugmentation(0);
		}
	}
	if(num == 1)
	{
		if(bNinja)
		{
			Super.ActivateAugmentation(1);
		}
	}
	if(num == 2)
	{
		if(bRifleKing)
		{
			Super.ActivateAugmentation(2);
		}
	}
}

Function ShowCustom(class<NetworkTerminal> termclass)
{
   if (Level.NetMode != NM_Standalone)
   {
      CustomWindow(termclass);
   }
}

Function CustomWindow(class<NetworkTerminal> termclass)
{
	local NetworkTerminal termwindow;
	local DeusExRootWindow root;

	if ((Level.NetMode != NM_Standalone) && (!PlayerIsClient()))
	{
		return;
	}
	if (Level.NetMode != NM_Standalone)
	{
		 root = DeusExRootWindow(rootWindow);
		if (root != None)
		{
			termwindow = NetworkTerminal(root.InvokeUIScreen(termclass, True));
			if (termwindow != None)
 			{
				termWindow.SetCompOwner(None);
				// If multiplayer, start hacking if there are no users
				if ((Level.NetMode != NM_Standalone) && (!termWindow.bHacked) && (termWindow.winHack != None) && (termWindow.winHack.btnHack != None))
				{
					termWindow.winHack.StartHack();
 					termWindow.winHack.btnHack.SetSensitivity(False);
					termWindow.FirstScreen=None;
				}
				termWindow.ShowFirstScreen();
			}
		}
	}
}

function ShowCredzYe()
{
   if (Level.NetMode != NM_Standalone)
   {
      ShowMMCredz();
   }
}

exec function ShowGoalsWindow()
{
UpdMis();
   if (Level.NetMode != NM_Standalone)
   {
      ShowMMGoals();
   }
}

exec function ShowGoalsWindow2()
{
      ShowMMGoals();
}


function ShowMMGoals()
{
   local NetworkTerminal termwindow;
   local DeusExRootWindow root;

   //only allow for clients or standalone
   if ((Level.NetMode != NM_Standalone) && (!PlayerIsClient()))
   {
      return;
   }

   root = DeusExRootWindow(rootWindow);
   if (root != None)
   {
      termwindow = NetworkTerminal(root.InvokeUIScreen(Class'Contender.TerminalGoalz', True));
      if (termwindow != None)
      {
         termWindow.SetCompOwner(None);
         // If multiplayer, start hacking if there are no users
         if ((Level.NetMode != NM_Standalone) && (!termWindow.bHacked) && 
             (termWindow.winHack != None) && (termWindow.winHack.btnHack != None))
         {
            termWindow.winHack.StartHack();
            termWindow.winHack.btnHack.SetSensitivity(False);
            termWindow.FirstScreen=None;
         }
         termWindow.ShowFirstScreen();
      }
   }
}






function ShowMMCredz()
{
   local NetworkTerminal termwindow;
   local DeusExRootWindow root;

   //only allow for clients or standalone
   if ((Level.NetMode != NM_Standalone) && (!PlayerIsClient()))
   {
      return;
   }

   root = DeusExRootWindow(rootWindow);
   if (root != None)
   {
      termwindow = NetworkTerminal(root.InvokeUIScreen(Class'Contender.TerminalCreditz', True));
      if (termwindow != None)
      {
         termWindow.SetCompOwner(None);
         // If multiplayer, start hacking if there are no users
         if ((Level.NetMode != NM_Standalone) && (!termWindow.bHacked) && 
             (termWindow.winHack != None) && (termWindow.winHack.btnHack != None))
         {
            termWindow.winHack.StartHack();
            termWindow.winHack.btnHack.SetSensitivity(False);
            termWindow.FirstScreen=None;
         }
         termWindow.ShowFirstScreen();
      }
   }
}












Function ThermalOn()
{

	ClientMessage("|p3Thermal Imaging vision activated");

	DeusExRootWindow(Self.rootWindow).hud.augDisplay.activeCount++;
	
	DeusExRootWindow(Self.rootWindow).hud.augDisplay.bVisionActive = True;
	DeusExRootWindow(Self.rootWindow).hud.augDisplay.visionLevel = 0;
	DeusExRootWindow(Self.rootWindow).hud.augDisplay.visionLevelValue = 0;

	bThermalOn=True;
}
Function ThermalOff()
{
	DeusExRootWindow(Self.rootWindow).hud.augDisplay.bVisionActive = False;
	bThermalOn=False;
}

Function LightOn()
{
	//ClientMessage("|p3Infra-red night vision activated");


	bb1 = Spawn(class'Beam', Self, '', Self.Location);
	if (bb1 != None)
	{
		//AIStartEvent('Beam', EAITYPE_Visual);
		bb1.LightHue = 100;
		bb1.LightRadius = 5;
		bb1.LightSaturation = 95;
		bb1.LightBrightness = 220;
		SetBeamLocation();
	}


	AugmentationDisplayMM(DeusExRootWindow(RootWindow).HUD.AugDisplay).bBoiz = True;

	bTorchOn=True;
}

function LightOff()
{
	//ClientMessage("LightOff");



	if (bb1 != None)
		bb1.Destroy();
	if (bb2 != None)
		bb2.Destroy();
	bb1 = None;
	bb2 = None;


	AugmentationDisplayMM(DeusExRootWindow(RootWindow).HUD.AugDisplay).bBoiz = False;
	bTorchOn=False;
}

function SetBeamLocation()
{
	local float dist, size, radius, brightness;
	local Vector HitNormal, HitLocation, StartTrace, EndTrace;

	if (bb1 != None)
	{
		StartTrace = Self.Location;
		StartTrace.Z += Self.BaseEyeHeight;
		EndTrace = StartTrace + 1024 * Vector(Self.ViewRotation);

		Trace(HitLocation, HitNormal, EndTrace, StartTrace, True);
		if (HitLocation == vect(0,0,0))
			HitLocation = EndTrace;

		dist       = VSize(HitLocation - StartTrace);
		size       = fclamp(dist/1024, 0, 1);
		radius     = size*5.12 + 4.0;
		brightness = fclamp(size-0.5, 0, 1)*2*-192 + 192;
		bb1.SetLocation(HitLocation-vector(Self.ViewRotation)*64);
		bb1.LightRadius     = byte(radius);
		//bb1.LightBrightness = byte(brightness);  // someday we should put this back in again
		bb1.LightType       = LT_Steady;
	}
}

function vector SetGlowLocation()
{
	local vector pos;

	if (bb2 != None)
	{
		pos = Self.Location + vect(0,0,1)*Self.BaseEyeHeight +
		      vect(1,1,0)*vector(Self.Rotation)*Self.CollisionRadius*1.5;
		bb2.SetLocation(pos);
	}
}



//================================================================================================

simulated function RotateLag(rotator rot)
{
	SetRotation(rot);
}


Simulated function PlayStunzor()
{
	LoopAnim('Shocked');
}

exec function Fire(optional float F)
{
	if (RestrictInput())
	{
		if (bHidden)
			ShowMainMenu();
		return;
	}

	if(inHand != None)
	{
		if(inHand.IsA('WeaponFist'))
		{
			Super.Fire(F);
			return;
		}
		if(inHand.IsA('DronePickup'))
		{
			return;
		}
	}

	if(inHand != None)
	{
	if(inHand.IsA('MissionBomb'))
	{
		if(Region.Zone.IsA('ZoneLeetApt'))
		{
			if (MissionBomb(inHand).NearWallCheck())
			{
				Super.Fire(F);
			}
		}
	}
	}


	if((Region.Zone.IsA('ArenaZoneSafe')) || (Region.Zone.IsA('MMRPGRoomArea')) || (Region.Zone.IsA('MMRPGSafeArea')))
	{
		if(inHand != None)
		{
			if(inHand.IsA('DeusExWeapon'))
			{
				//if((!inHand.IsA('DoctorsMedKit')) && (!inHand.IsA('MMRPGCreditCard')))
				//{
					ClientMessage("|p2 No weapons in civillian areas!");
					return;
				//}
			}
		}
	}
	if((!Region.Zone.IsA('ArenaZoneSafe')) && (!Region.Zone.IsA('MMRPGRoomArea')) && (!Region.Zone.IsA('MMRPGSafeArea')))
	{
		Super.Fire(F);
	}
}


//Set up new HUD
function Possess()
{
	local DeusExRootWindow root;

	Super.Possess();
  
	root = DeusExRootWindow(rootWindow);
	root.hud.Destroy();

	root.hud = HUDMMRPG(root.NewChild(Class'Contender.HUDMMRPG'));
	root.hud.UpdateSettings(Self);
	root.hud.SetWindowAlignments(HALIGN_Full, VALIGN_Full, 0, 0);
}

function FirePhat()
{
	if (bOnFire)
	{
		ExtinguishFire();
	}
}

function SkateDestroy()
{
	local board b;
	foreach allactors(class'board',b)
	{
		if(b.skater == self)
		{
			b.destroy();
		}
	}
	bSkate = False;
	JumpSound=Self.Default.JumpSound;
	bBehindView = False;
}

function Kickflip()
{
	local board b;

	foreach allactors (class'board', b)
	{
		if(b.Skater == Self)
		{

		b.bFlip = True;
		b.bHeel = False;
		b.bShove = False;
		b.bImp = False;
		b.FlipCount = 0;
		b.bTrick = True;

		if(bShoveLand)
		{
			bShoveLand = False;
			bLateFlip = True;
		}

		if(bKickLand)
		{
			bKickLand = False;
			bDoubleKick = True;
		}
		else bKickLand = True;
		}
	}
}

function Heel()
{
	local board b;

	foreach allactors (class'board', b)
	{
		if(b.Skater == Self)
		{

		b.bHeel = True;
		b.bImp = False;
		b.bFlip = False;
		b.FlipCount = 0;
		b.bTrick = True;
		if(bShoveLand)
		{
			bShoveLand = False;
			bLateHeel = True;
		}
		if(bHeelLand)
		{
			bHeelLand = False;
			bDoubleHeel = True;
		}
		else bHeelLand = True;
		}
	}
}

function Shove()
{
	local board b;

	if(bHeelLand || bKickLand)
		return;

	foreach allactors (class'board', b)
	{
		if(b.Skater == Self)
		{
		bShoveLand = True;
		b.bShove = True;
		b.bFlip = False;
		b.bHeel = False;
		b.bImp = False;
		b.FlipCount = 0;
		b.bTrick = True;
		}
	}
}

function Imp()
{
	local board b;

	if(bHeelLand || bKickLand || bShoveLand)
		return;

	foreach allactors (class'board', b)
	{
		if(b.Skater == Self)
		{
		bImpLand = True;
		b.bShove = False;
		b.bImp = True;
		b.bFlip = False;
		b.bHeel = False;
		b.FlipCount = 0;
		b.bTrick = True;
		}
	}
}

exec function ReloadWeapon()
{
	local DeusExWeapon W;
	if (bSkate)
	{
		if(bAir)
		{
			Imp();
		}
	}

	if (RestrictInput())
		return;

	W = DeusExWeapon(Weapon);
	if (W != None)
		W.ReloadAmmo();
}


exec function SwitchAmmo()
{
	local board b;
	if (bSkate)
	{
		if(bAir)
		{
			Shove();
		}
	}
	if (inHand.IsA('MMRPGCreditCard'))
		MMRPGCreditCard(inHand).Switcharoo();

	if (inHand.IsA('DeusExWeapon'))
		DeusExWeapon(inHand).CycleAmmo();	
}


exec function ToggleScope()
{
	local DeusExWeapon W;
	local board b;
	if (bSkate)
	{
		if(bAir)
		{
			Kickflip();
		}
	}

	if (RestrictInput())
		return;

	W = DeusExWeapon(Weapon);
	if (W != None)
		W.ScopeToggle();
}

exec function ToggleLaser()
{
	local DeusExWeapon W;
	local board b;
	if (bSkate)
	{
		if(bAir)
		{
			Heel();
		}
	}

	if (RestrictInput())
		return;

	W = DeusExWeapon(Weapon);
	if (W != None)
		W.LaserToggle();
}

exec function BehindView (bool B)
{
	if (bSkate)
		return;

	if (SeatActor != None)
		return;

	bBehindView=B;
}

exec function ToggleBehindView ()
{
	if (bSkate)
		return;

	if (SeatActor != None)
		return;

	bBehindView= !bBehindView;
}

Function bool CheckS33t(Seat SS)
{
	local int k;
	//for (k=0; k<SS.numSitPoints; k++)
	//{
		if(SS.sittingActor[0] == None)
		{
			return True;
		}
	//}
	Return False;
}

exec function ParseRightClick()
{
	local int k;
	local int x;

	if(Clix > 0)
	{
		return;
	}

	if(Clix < 1)
	{
	Clix = 20;

	If(bSkate)
	{
		SkateDestroy();
	}

	if(Seat(FrobTarget) != None)
	{
		x = 0;

		//for (k=0; k<Seat(FrobTarget).numSitPoints; k++)
		//{
			//if(Seat(FrobTarget).sittingActor[k] == None)
			if(CheckS33t(Seat(FrobTarget)))
			{
				Seat(FrobTarget).sittingActor[k] = Self;
				SeatActor = Seat(FrobTarget);
				SeatSlot = k;
				SeatRot = String(Seat(FrobTarget).Rotation);
				GetChair();
				x += 1;
				SitDown();
				//break;
			}
		//}
			//if(x == 0)
			else
			{
				ClientMessage("This seat is taken!");
			}

	}

	Super.ParseRightClick();
	}
}

//===========================================================================================



function UpdateRotation(float DeltaTime, float maxPitch)
{
	local rotator newRotation;
	
	DesiredRotation = ViewRotation; //save old rotation
	ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
	ViewRotation.Pitch = ViewRotation.Pitch & 65535;
	If ((ViewRotation.Pitch > 18000) && (ViewRotation.Pitch < 49152))
	{
		If (aLookUp > 0) 
			ViewRotation.Pitch = 18000;
		else
			ViewRotation.Pitch = 49152;
	}
	ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
	ViewShake(deltaTime);
	ViewFlash(deltaTime);
		
	newRotation = Rotation;
	newRotation.Yaw = ViewRotation.Yaw;
	newRotation.Pitch = ViewRotation.Pitch;
	If ( (newRotation.Pitch > maxPitch * RotationRate.Pitch) && (newRotation.Pitch < 65536 - maxPitch * RotationRate.Pitch) )
	{
		If (ViewRotation.Pitch < 32768) 
			newRotation.Pitch = maxPitch * RotationRate.Pitch;
		else
			newRotation.Pitch = 65536 - maxPitch * RotationRate.Pitch;
	}
    // added to keep the player's model from pitching or rolling - DEUS_EX CNN
	newRotation.Pitch = 0;
	newRotation.Roll = 0;

	if (bSkate)
	{
		newRotation=ViewRotation;
		newRotation.Pitch = 0;
		newRotation.Roll = 0;
		newRotation.Yaw += 16448;
		//RotateLag(newRotation);
		DesiredRotation=newRotation;
	}

	setRotation(newRotation);

}

//
// Send movement to the server.
// Passes acceleration in components so it doesn't get rounded.
//
function ServerMove
(
	float TimeStamp, 
	vector InAccel, 
	vector ClientLoc,
	bool NewbRun,
	bool NewbDuck,
	bool NewbJumpStatus, 
	bool bFired,
	bool bAltFired,
	bool bForceFire,
	bool bForceAltFire,
	eDodgeDir DodgeMove, 
	byte ClientRoll, 
	int View,
	optional byte OldTimeDelta,
	optional int OldAccel
)
{
	local float DeltaTime, clientErr, OldTimeStamp;
	local rotator DeltaRot, Rot;
	local vector Accel, LocDiff;
	local int maxPitch, ViewPitch, ViewYaw;
	local actor OldBase;
	local bool NewbPressedJump, OldbRun, OldbDuck;
	local eDodgeDir OldDodgeMove;
	local rotator skaterot;

	// If this move is outdated, discard it.
	if ( CurrentTimeStamp >= TimeStamp )
		return;

	// if OldTimeDelta corresponds to a lost packet, process it first
	if (  OldTimeDelta != 0 )
	{
		OldTimeStamp = TimeStamp - float(OldTimeDelta)/500 - 0.001;
		if ( CurrentTimeStamp < OldTimeStamp - 0.001 )
		{
			// split out components of lost move (approx)
			Accel.X = OldAccel >>> 23;
			if ( Accel.X > 127 )
				Accel.X = -1 * (Accel.X - 128);
			Accel.Y = (OldAccel >>> 15) & 255;
			if ( Accel.Y > 127 )
				Accel.Y = -1 * (Accel.Y - 128);
			Accel.Z = (OldAccel >>> 7) & 255;
			if ( Accel.Z > 127 )
				Accel.Z = -1 * (Accel.Z - 128);
			Accel *= 20;
			
			OldbRun = ( (OldAccel & 64) != 0 );
			OldbDuck = ( (OldAccel & 32) != 0 );
			NewbPressedJump = ( (OldAccel & 16) != 0 );
			if ( NewbPressedJump )
				bJumpStatus = NewbJumpStatus;

			switch (OldAccel & 7)
			{
				case 0:
					OldDodgeMove = DODGE_None;
					break;
				case 1:
					OldDodgeMove = DODGE_Left;
					break;
				case 2:
					OldDodgeMove = DODGE_Right;
					break;
				case 3:
					OldDodgeMove = DODGE_Forward;
					break;
				case 4:
					OldDodgeMove = DODGE_Back;
					break;
			}
			//log("Recovered move from "$OldTimeStamp$" acceleration "$Accel$" from "$OldAccel);
			MoveAutonomous(OldTimeStamp - CurrentTimeStamp, OldbRun, OldbDuck, NewbPressedJump, OldDodgeMove, Accel, rot(0,0,0));
			CurrentTimeStamp = OldTimeStamp;
		}
	}		

	// View components
	ViewPitch = View/32768;
	ViewYaw = 2 * (View - 32768 * ViewPitch);
	ViewPitch *= 2;
	// Make acceleration.
	Accel = InAccel/10;

	NewbPressedJump = (bJumpStatus != NewbJumpStatus);
	bJumpStatus = NewbJumpStatus;

	// handle firing and alt-firing
	if ( bFired )
	{
		if ( bForceFire && (Weapon != None) )
			Weapon.ForceFire();
		else if ( bFire == 0 )
			Fire(0);
		bFire = 1;
	}
	else
		bFire = 0;


	if ( bAltFired )
	{
		if ( bForceAltFire && (Weapon != None) )
			Weapon.ForceAltFire();
		else if ( bAltFire == 0 )
			AltFire(0);
		bAltFire = 1;
	}
	else
		bAltFire = 0;

	// Save move parameters.
	DeltaTime = TimeStamp - CurrentTimeStamp;
	if ( ServerTimeStamp > 0 )
	{
		// allow 1% error
		TimeMargin += DeltaTime - 1.01 * (Level.TimeSeconds - ServerTimeStamp);
		if ( TimeMargin > MaxTimeMargin )
		{
			// player is too far ahead
			TimeMargin -= DeltaTime;
			if ( TimeMargin < 0.5 )
				MaxTimeMargin = Default.MaxTimeMargin;
			else
				MaxTimeMargin = 0.5;
			DeltaTime = 0;
		}
	}

	CurrentTimeStamp = TimeStamp;
	ServerTimeStamp = Level.TimeSeconds;
	Rot.Roll = 256 * ClientRoll;
	Rot.Yaw = ViewYaw;
	if ( (Physics == PHYS_Swimming) || (Physics == PHYS_Flying) )
		maxPitch = 2;
	else
		maxPitch = 1;
	If ( (ViewPitch > maxPitch * RotationRate.Pitch) && (ViewPitch < 65536 - maxPitch * RotationRate.Pitch) )
	{
		If (ViewPitch < 32768) 
			Rot.Pitch = maxPitch * RotationRate.Pitch;
		else
			Rot.Pitch = 65536 - maxPitch * RotationRate.Pitch;
	}
	else
		Rot.Pitch = ViewPitch;

	// From what I gather, this should have been the case in single player as well since
	// pitch is zeroed out in UpdateRotation.  Oh well, now it doesn't look goofy in mp
	// MBCODE
	if ( Level.NetMode != NM_Standalone )
		Rot.Pitch = 0;

	DeltaRot = (Rotation - Rot);
	ViewRotation.Pitch = ViewPitch;
	ViewRotation.Yaw = ViewYaw;
	ViewRotation.Roll = 0;


	if (bSkate)
	{
		Rot=ViewRotation;
		Rot.Pitch = 0;
		Rot.Roll = 0;
		Rot.Yaw += 16448;
	}

	SetRotation(Rot);

	OldBase = Base;

	// Perform actual movement.
	if ( (Level.Pauser == "") && (DeltaTime > 0) )
		MoveAutonomous(DeltaTime, NewbRun, NewbDuck, NewbPressedJump, DodgeMove, Accel, DeltaRot);

	// Accumulate movement error.
	//if ( Level.TimeSeconds - LastUpdateTime > 500.0/Player.CurrentNetSpeed )
	//	ClientErr = 10000;
	//else       

   //Update every 2 seconds or so, regardless of anything else.
   if ( Level.TimeSeconds - LastUpdateTime > 2 )
      ClientErr = 10000;
   else if ( Level.TimeSeconds - LastUpdateTime > 180.0/Player.CurrentNetSpeed )
   {
      LocDiff = Location - ClientLoc;
      ClientErr = LocDiff Dot LocDiff;
   }

	// If client has accumulated a noticeable positional error, correct him.
	if ( ClientErr > 3 )
	{
		if ( Mover(Base) != None )
			ClientLoc = Location - Base.Location;
		else
			ClientLoc = Location;
	   //log("Client Error at "$TimeStamp$" is "$ClientErr$" with acceleration "$Accel$" LocDiff "$LocDiff$" Physics "$Physics);
      LastUpdateTime = Level.TimeSeconds;
		ClientAdjustPosition
		(
			TimeStamp, 
			GetStateName(), 
			Physics, 
			ClientLoc.X, 
			ClientLoc.Y, 
			ClientLoc.Z, 
			Velocity.X, 
			Velocity.Y, 
			Velocity.Z,
			Base
		);
	}
   // DEUS_EX AMSD Do any ticking which needs to be done.
   MultiplayerTick(DeltaTime);
	//log("Server "$Role$" moved "$self$" stamp "$TimeStamp$" location "$Location$" Acceleration "$Acceleration$" Velocity "$Velocity);
}




//=s=k=a=t=e===a=n=i=m=a=t=i=o=n===c=o=n=t=r=o=l=s=================================================================================================


function PlayWalking()
{
	local float newhumanAnimRate;

	newhumanAnimRate = humanAnimRate;

	// UnPhysic.cpp walk speed changed by proportion 0.7/0.3 (2.33), but that looks too goofy (fast as hell), so we'll try something a little slower
	if ( Level.NetMode != NM_Standalone ) 
		newhumanAnimRate = humanAnimRate * 1.75;

	If (bSkate)
	{
		LoopAnim('CrouchWalk', humanAnimRate);
		return;
	}

	//	ClientMessage("PlayWalking()");
	if (bForceDuck || bCrouchOn)
		LoopAnim('CrouchWalk', newhumanAnimRate);
	else
	{
		if (HasTwoHandedWeapon())
			LoopAnim('Walk2H', newhumanAnimRate);
		else
			LoopAnim('Walk', newhumanAnimRate);
	}
}

function TweenToWalking(float tweentime)
{
//	ClientMessage("TweenToWalking()");
	If (bSkate)
	{
		TweenAnim('CrouchWalk', tweentime);
		return;
	}
	if (bForceDuck || bCrouchOn)
		TweenAnim('CrouchWalk', tweentime);
	else
	{
		if (HasTwoHandedWeapon())
			TweenAnim('Walk2H', tweentime);
		else
			TweenAnim('Walk', tweentime);
	}
}

function TweenToRunning(float tweentime)
{
	If (bSkate)
	{
		PlayAnim('CrouchWalk',humanAnimRate, tweentime);
		return;
	}
//	ClientMessage("TweenToRunning()");
	if (bIsWalking)
	{
		TweenToWalking(0.1);
		return;
	}

//	if (Energy <= 0)
//	{
//		TweenToWalking(0.1);
//		return;
//	}
	if (IsFiring())
	{
		if (aStrafe != 0)
		{
			if (HasTwoHandedWeapon())
				PlayAnim('Strafe2H',humanAnimRate, tweentime);
			else
				PlayAnim('Strafe',humanAnimRate, tweentime);
		}
		else
		{
			if (HasTwoHandedWeapon())
				PlayAnim('RunShoot2H',humanAnimRate, tweentime);
			else
				PlayAnim('RunShoot',humanAnimRate, tweentime);
		}
	}
	else if (bOnFire)
		PlayAnim('Panic',humanAnimRate, tweentime);
	else
	{
		if (HasTwoHandedWeapon())
			PlayAnim('RunShoot2H',humanAnimRate, tweentime);
		else
			PlayAnim('Run',humanAnimRate, tweentime);
	}
}
function PlayRunning()
{
	If (bSkate)
	{
		LoopAnim('CrouchWalk', humanAnimRate);
		return;
	}
//	if (Energy <= 0)
//	{
//		PlayWalking();
//		return;
//	}

//	ClientMessage("PlayRunning()");
	if (IsFiring())
	{
		if (aStrafe != 0)
		{
			if (HasTwoHandedWeapon())
				LoopAnim('Strafe2H', humanAnimRate);
			else
				LoopAnim('Strafe', humanAnimRate);
		}
		else
		{
			if (HasTwoHandedWeapon())
				LoopAnim('RunShoot2H', humanAnimRate);
			else
				LoopAnim('RunShoot', humanAnimRate);
		}
	}
	else if (bOnFire)
		LoopAnim('Panic', humanAnimRate);
	else
	{
		if (HasTwoHandedWeapon())
			LoopAnim('RunShoot2H', humanAnimRate);
		else
			LoopAnim('Run', humanAnimRate);
	}
}



function PlaySong( sound snd )
{
	PlaySound( snd, SLOT_Interface, 0.75 );
	bPlaying = True;
}

Function PlayStop()
{
	local Sound snd;

	snd = Sound'DeusExSounds.Special.Switch1Click';

	PlaySound( snd, SLOT_Interface, 0.75 );
	bPlaying = False;
}




function PostBeginPlay()
{
	Super.PostBeginPlay();
	lastBroadcast =- BroadcastTime;
}

function GrabDecoration()
{
	// can't grab decorations while leaning
	if (IsLeaning())
		return;

	// can't grab decorations while holding something else
	if (inHand != None)
	{
		ClientMessage(HandsFull);
		return;
	}

	if (carriedDecoration == None)
		if ((FrobTarget != None) && FrobTarget.IsA('Decoration') && (Weapon == None))

			if (CanBeLifted(Decoration(FrobTarget)))
			{
				If( FrobTarget.IsA('RPGBasketBall'))
				{
					RPGBasketBall(FrobTarget).Thrower = Self;
				}
				CarriedDecoration = Decoration(FrobTarget);
				PutCarriedDecorationInHand();
			}
}




function CreateDrone()
{

}





//=================================================================
function ColoursUp()
{
	local colortheme th;

	if (ThemeManager != None)
	{
		th=ThemeManager.SetHUDThemeByName("Red");
		ThemeManager.SetCurrentHUDColorTheme(th);
		DeusExRootWindow(rootWindow).ChangeStyle();
	}
}

function ColoursDown()
{
	local colortheme th;
	if (ThemeManager != None)
	{
		th=ThemeManager.SetHUDThemeByName("Starlight");
		ThemeManager.SetCurrentHUDColorTheme(th);
		DeusExRootWindow(rootWindow).ChangeStyle();
	}
}
//====================================================================


state PlayerWalking
{
	function ZoneChange(ZoneInfo NewZone)
	{
		// if we jump into water, empty our hands
		if (NewZone.bWaterZone)
			DropDecoration();

		If ( (NewZone.IsA('ZoneBogs')) || (NewZone.IsA('ArenaZoneSafe')) || (NewZone.IsA('MMRPGRoomArea')) || (NewZone.IsA('MMRPGSafeArea'))     )
		{
			ColoursDown();
		}
		else ColoursUp();

		Super.ZoneChange(NewZone);
	}

	function PlayerMove( float DeltaTime )
	{
		local vector X,Y,Z, NewAccel;
		local EDodgeDir OldDodge;
		local eDodgeDir DodgeMove;
		local rotator OldRotation;
		local float Speed2D;
		local bool	bSaveJump;
		local name AnimGroupName;
		local rotator skaterot;
		local rotator isitrot;

		if (bSkate)
		{
			skaterot=ViewRotation;
			skaterot.Pitch=0;
			skaterot.Roll=0;
			GetAxes(skaterot,X,Y,Z);
		}
		else
		{
			GetAxes(Rotation,X,Y,Z);
		}

		aForward *= 0.4;
		aStrafe  *= 0.4;
		aLookup  *= 0.24;
		aTurn    *= 0.24;

		// Update acceleration.
		NewAccel = aForward*X + aStrafe*Y; 
		NewAccel.Z = 0;
		// Check for Dodge move
		if ( DodgeDir == DODGE_Active )
			DodgeMove = DODGE_Active;
		else
			DodgeMove = DODGE_None;
		if (DodgeClickTime > 0.0)
		{
			if ( DodgeDir < DODGE_Active )
			{
				OldDodge = DodgeDir;
				DodgeDir = DODGE_None;
				if (bEdgeForward && bWasForward)
					DodgeDir = DODGE_Forward;
				if (bEdgeBack && bWasBack)
					DodgeDir = DODGE_Back;
				if (bEdgeLeft && bWasLeft)
					DodgeDir = DODGE_Left;
				if (bEdgeRight && bWasRight)
					DodgeDir = DODGE_Right;
				if ( DodgeDir == DODGE_None)
					DodgeDir = OldDodge;
				else if ( DodgeDir != OldDodge )
					DodgeClickTimer = DodgeClickTime + 0.5 * DeltaTime;
				else 
					DodgeMove = DodgeDir;
			}
	
			if (DodgeDir == DODGE_Done)
			{
				DodgeClickTimer -= DeltaTime;
				if (DodgeClickTimer < -0.35) 
				{
					DodgeDir = DODGE_None;
					DodgeClickTimer = DodgeClickTime;
				}
			}		
			else if ((DodgeDir != DODGE_None) && (DodgeDir != DODGE_Active))
			{
				DodgeClickTimer -= DeltaTime;			
				if (DodgeClickTimer < 0)
				{
					DodgeDir = DODGE_None;
					DodgeClickTimer = DodgeClickTime;
				}
			}
		}
		
		AnimGroupName = GetAnimGroup(AnimSequence);		
		if ( (Physics == PHYS_Walking) && (AnimGroupName != 'Dodge') )
		{
			//if walking, look up/down stairs - unless player is rotating view
			if ( !bKeyboardLook && (bLook == 0) )
			{
				if ( bLookUpStairs )
					ViewRotation.Pitch = FindStairRotation(deltaTime);
				else if ( bCenterView )
				{
					ViewRotation.Pitch = ViewRotation.Pitch & 65535;
					if (ViewRotation.Pitch > 32768)
						ViewRotation.Pitch -= 65536;
					ViewRotation.Pitch = ViewRotation.Pitch * (1 - 12 * FMin(0.0833, deltaTime));
					if ( Abs(ViewRotation.Pitch) < 1000 )
						ViewRotation.Pitch = 0;	
				}
			}

			Speed2D = Sqrt(Velocity.X * Velocity.X + Velocity.Y * Velocity.Y);
			//add bobbing when walking
			if ( !bShowMenu )
				CheckBob(DeltaTime, Speed2D, Y);

		}	
		else if ( !bShowMenu )
		{ 
			BobTime = 0;
			WalkBob = WalkBob * (1 - FMin(1, 8 * deltatime));
		}

		// Update rotation.


		OldRotation = Rotation;
		if(bSkate)
		{
			isitRot = ViewRotation;
			isitRot.Pitch = 0;
			isitRot.Roll = 0;
			isitRot.Yaw += 16448;
			SetRotation(isitRot);
		}
		UpdateRotation(DeltaTime, 1);

		UpdateRotation(DeltaTime, 1);

		if ( bPressedJump && (AnimGroupName == 'Dodge') )
		{
			bSaveJump = true;
			bPressedJump = false;
		}
		else
			bSaveJump = false;

		if (bSkate)
		{
			if ( Role < ROLE_Authority ) // then save this move and replicate it
				ReplicateMove(DeltaTime, NewAccel, DodgeMove, skaterot);
			else
				ProcessMove(DeltaTime, NewAccel, DodgeMove, skaterot);
		}
		if (!bSkate)
		{
			if ( Role < ROLE_Authority ) // then save this move and replicate it
				ReplicateMove(DeltaTime, NewAccel, DodgeMove, OldRotation - Rotation);
			else
				ProcessMove(DeltaTime, NewAccel, DodgeMove, OldRotation - Rotation);
		}

		bPressedJump = bSaveJump;
	}

	function ProcessMove ( float DeltaTime, vector newAccel, eDodgeDir DodgeMove, rotator DeltaRot)
	{
		if (bInConv)
		{
			Velocity = vect(0,0,0);
			return;
		}


		if(bStunnage)
		{
			Velocity = vect(0,0,0);
			return;
		}

		Super.ProcessMove(DeltaTime, newAccel, DodgeMove, DeltaRot);
	}

	function SitDown()
	{
		if ( Physics == PHYS_Walking )
		{
			ServerSit();
			Acceleration = vect(0,0,0);
			GotoState('SittingDown');
		}
	}


}




//================================================================


//======j=u=m=p===a=n=d===l=a=n=d===f=u=n=c=t=i=o=n=s===========================================

function Landed(vector HitNormal)
{
    local vector legLocation;
	local int augLevel;
	local float augReduce, dmg;

	bJumpOnce = False;

	//Note - physics changes type to PHYS_Walking by default for landed pawns
	PlayLanded(Velocity.Z);
	if (Velocity.Z < -1.4 * JumpZ)
	{
		MakeNoise(-0.5 * Velocity.Z/(FMax(JumpZ, 150.0)));
		if ((Velocity.Z < -700) && (ReducedDamageType != 'All'))
			if ( Role == ROLE_Authority )
            {
				// check our jump augmentation and reduce falling damage if we have it
				// jump augmentation doesn't exist anymore - use Speed instaed
				// reduce an absolute amount of damage instead of a relative amount
				augReduce = 0;
				if (AugmentationSystem != None)
				{
					augLevel = AugmentationSystem.GetClassLevel(class'AugSpeed');
					if (augLevel >= 0)
						augReduce = 15 * (augLevel+1);
				}

				dmg = Max((-0.16 * (Velocity.Z + 700)) - augReduce, 0);
				legLocation = Location + vect(-1,0,-1);			// damage left leg
				TakeDamage(dmg, None, legLocation, vect(0,0,0), 'fell');

				legLocation = Location + vect(1,0,-1);			// damage right leg
				TakeDamage(dmg, None, legLocation, vect(0,0,0), 'fell');

				dmg = Max((-0.06 * (Velocity.Z + 700)) - augReduce, 0);
				legLocation = Location + vect(0,0,1);			// damage torso
				TakeDamage(dmg, None, legLocation, vect(0,0,0), 'fell');
            }
	}
	else if ( (Level.Game != None) && (Level.Game.Difficulty > 1) && (Velocity.Z > 0.5 * JumpZ) )
		MakeNoise(0.1 * Level.Game.Difficulty);				
	bJustLanded = true;

	If(bSkate)
	{
		If(bShoveLand)
		{
			ClientMessage("|p7Pop Shove-It!");
		bDoubleHeel = False;
		bDoubleKick = False;
		bShoveLand = False;
		bKickLand = False;
		bHeelLand = False;
		bLateFlip = False;
		bLateHeel = False;
		bImpLand = False;
		bAir=False;
			return;
		}
		If(bKickLand)
		{
			ClientMessage("|p7Kickflip!");
		bDoubleHeel = False;
		bDoubleKick = False;
		bShoveLand = False;
		bKickLand = False;
		bHeelLand = False;
		bLateFlip = False;
		bLateHeel = False;
		bImpLand = False;
		bAir=False;
			return;
		}
		If(bHeelLand)
		{
			ClientMessage("|p7Heelflip!");
		bDoubleHeel = False;
		bDoubleKick = False;
		bShoveLand = False;
		bKickLand = False;
		bHeelLand = False;
		bLateFlip = False;
		bLateHeel = False;
		bImpLand = False;
		bAir=False;
			return;
		}
		If(bLateFlip)
		{
			ClientMessage("|p6Pop Shove-It Late-Flip!");
		bDoubleHeel = False;
		bDoubleKick = False;
		bShoveLand = False;
		bKickLand = False;
		bHeelLand = False;
		bLateFlip = False;
		bLateHeel = False;
		bImpLand = False;
		bAir=False;
			return;
		}
		If(bLateHeel)
		{
			ClientMessage("|p6Pop Shove-It Late-Heel!");
		bDoubleHeel = False;
		bDoubleKick = False;
		bShoveLand = False;
		bKickLand = False;
		bHeelLand = False;
		bLateFlip = False;
		bLateHeel = False;
		bImpLand = False;
		bAir=False;
			return;
		}
		If(bImpLand)
		{
			ClientMessage("|p7Impossible!");
		bDoubleHeel = False;
		bDoubleKick = False;
		bShoveLand = False;
		bKickLand = False;
		bHeelLand = False;
		bLateFlip = False;
		bLateHeel = False;
		bImpLand = False;
		bAir=False;
			return;
		}
		If(bDoubleKick)
		{
			ClientMessage("|p6Double Kickflip!");
		bDoubleHeel = False;
		bDoubleKick = False;
		bShoveLand = False;
		bKickLand = False;
		bHeelLand = False;
		bLateFlip = False;
		bLateHeel = False;
		bImpLand = False;
		bAir=False;
			return;
		}
		If(bDoubleHeel)
		{
			ClientMessage("|p6Double Heelflip!");
		bDoubleHeel = False;
		bDoubleKick = False;
		bShoveLand = False;
		bKickLand = False;
		bHeelLand = False;
		bLateFlip = False;
		bLateHeel = False;
		bImpLand = False;
		bAir=False;
			return;
		}
		bDoubleHeel = False;
		bDoubleKick = False;
		bShoveLand = False;
		bKickLand = False;
		bHeelLand = False;
		bLateFlip = False;
		bLateHeel = False;
		bImpLand = False;
		bAir=False;
	}

}

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

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

	StartTrace.Z += BaseEyeHeight;
	EndTrace.Z += BaseEyeHeight;

	HitActor = Trace(HitLocation, HitNormal, EndTrace, StartTrace);
	if ((HitActor == Level) || ((HitActor != None) && HitActor.IsA('Mover')))
	{
		return True;
	}

	return False;
}

function DoJump( optional float F )
{
	local DeusExWeapon w;
	local float scaleFactor, augLevel;
	local float AgScale;

	JumpZ = Default.JumpZ;

	if (Physics == PHYS_Falling)
	{
	AgScale = SkillSystem.GetSkillLevelValue(class'SkillAgility');

	if(AgScale > 1.2)
	{
		if(!bJumpOnce)
		{
		if(NearWallCheckMM())
		{
		if ( Role == ROLE_Authority )
			PlaySound(JumpSound, SLOT_None, 1.5, true, 1200, 1.0 - 0.2*FRand() );
		if ( (Level.Game != None) && (Level.Game.Difficulty > 0) )
			MakeNoise(0.1 * Level.Game.Difficulty);
		PlayInAir();

		Velocity.Z = JumpZ;		

		if ( Base != None )
		{
		if ( Base != Level )
			Velocity.Z += Base.Velocity.Z;
		}
		SetPhysics(PHYS_Falling);
		if ( bCountJumps && (Role == ROLE_Authority) )
			Inventory.OwnerJumped();

		bJumpOnce = True;
		return;
		}
		}
	}
	}

	if(bSkate)
	{
		bAir=True;
	}

	if ((CarriedDecoration != None) && (CarriedDecoration.Mass > 20))
		return;
	else if (bForceDuck || IsLeaning())
		return;

	if (Physics == PHYS_Walking)
	{
		if ( Role == ROLE_Authority )
			PlaySound(JumpSound, SLOT_None, 1.5, true, 1200, 1.0 - 0.2*FRand() );
		if ( (Level.Game != None) && (Level.Game.Difficulty > 0) )
			MakeNoise(0.1 * Level.Game.Difficulty);
		PlayInAir();

		Velocity.Z = JumpZ;

		if ( Level.NetMode != NM_Standalone )
		{
/*         if (SkillSystem == None)
            augLevel = 1.0;
         else			
            augLevel = SkillSystem.GetSkillLevelValue(class'SkillPhysical');
			w = DeusExWeapon(InHand);
			if ((augLevel != 1.0) && ( w != None ) && ( w.Mass > 30.0))
			{
				scaleFactor = 1.0 - FClamp( ((w.Mass - 30.0)/55.0), 0.0, 0.5 );
				Velocity.Z *= scaleFactor;
			}
*/		}

		if ( Base != Level )
			Velocity.Z += Base.Velocity.Z;
		SetPhysics(PHYS_Falling);
		if ( bCountJumps && (Role == ROLE_Authority) )
			Inventory.OwnerJumped();
	}
}




state FeigningDeath
{
ignores SeePlayer, HearNoise, Bump;
	function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)	
	{
		if (bNerve)
		{
			Velocity = vect(0,0,0);
			return;
		}
		Super.ProcessMove(DeltaTime, NewAccel, DodgeMove, DeltaRot);
	}
}

function MultiplayerTick (float VAE)
{
	local ArenaTeleporter AT;
	local _MMRPGPlayer P;
	local DeusExPickup St;
	local int j;
	local string str;
	local rotator rot;
	local vector newPos;
	local int burnTime;
	local float augLevel;

	if(Clix > 0)
	{
		Clix -= 1;
		
	}

	SetBeamLocation();
	SetGlowLocation();

	if(CredInst > 0 )
	{
		CredInst += 1;

		if(CredInst > 7)
		{
			CredInst = 0;
			ShowCredzYe();
		}
	}

	if(FistNum > 0 )
	{
		fistNum += 1;
		If(fistNum == 20)
		{
			WeaponFist(inHand).ServerForceFire();
		}
		if(fistNum >= 30)
		{
			PutInHand(None);
			fistNum = 0;
		}
	}

	if(PandaLagga > 0)
	{
		PandaLagga -= 1;
	}

	if(PandaLagga < 0)
	{
		PandaLagga = 0;
	}


//	if( Velocity != vect(0,0,0) )
//	{
//		if(!bIsWalking)
//		{
//			If(Energy > 0)
//			{
//				Energy -= 0.04;
//				If(Energy <= 0)
//				{
//					Energy = 0;
//					ClientMessage(EnergyDepleted);
//				}
//			}
//		}
//	}

	Super.MultiplayerTick(VAE);	




	if (bNerve)
	{
		NerveCount += 1;
		If (NerveCount >= 39)
		{
			bNerve = False;
			NerveCount = 0;
		}
	}
	if (bStunnage)
	{
		PlayStunzor();
		if(Role == ROLE_Authority)
		{
			LoopAnim('Shocked');
		}
		StunCount += 1;
		If (StunCount >= 100)
		{
			bStunnage = False;
			StunCount = 0;
		}
	}

	if (bSkate)
	{
		if (inHand != None)
			PutInHand(None);

		if (bAir)
		{
			AirTime += 1;
			If (AirTime >= 15)
			{
				bAir = False;
				AirTime = 0;
			}
		}
	}
	

	if (bArena)
	{

		foreach allactors (class'ArenaTeleporter', AT)
		{
			if ( ! AT.bFighting )
			{
				return;
			}
		}

		hmm = 0;

		foreach AllActors (class'_MMRPGPlayer', P)
		{
			if (P.bArena)
			{
				hmm += 1;
			}
		}

		if (hmm == 2)
		{
			return;
		}	
	
		LagShot();
	}

}

function LagShot()
{
	local teleporter tele2;
	local ArenaTeleporter AT;
	local _MMRPGPlayer P;
	local vector loc1;
	local int numStake;

	foreach allactors (class'Teleporter', tele2)
	{
		If (tele2.Tag == 'ARENA2')
		{
			loc1 = Tele2.location;
		}
	}

	foreach allactors (class'ArenaTeleporter', AT)
	{
		numStake = AT.Stake;
	}

	Self.CreditCard.CreditAmount += numStake;
	Self.ClientMessage("|p2Your opponent has left, your stake has been refunded.");
	Self.HealPlayer(9000, True);
	Self.SetLocation(loc1);
	Self.SetPhysics(PHYS_Falling);

	bArena = False;
	foreach allactors (class'ArenaTeleporter', AT)
	{
		AT.bFighting = False;
		AT.NumPlayers = 0;
	}
}


function SkillItUp(int i)
{
	local Skill Skillit;
	local DeusExWeapon W2;
	local skill SkillRifle;
	local skill SkillLT;
	local Skill skillPistol;
	local Skill skillLAM;
	local Skill skillHeavy;


	If (InHand.IsA('DeusExWeapon'))
	{
		W2 = DeusExWeapon(inHand);
		SkillIt = SkillSystem.GetSkillFromClass(W2.GoverningSkill);
		SkillRifle = SkillSystem.GetSkillFromClass(Class'DeusEx.SkillWeaponRifle');
		SkillLT = SkillSystem.GetSkillFromClass(Class'DeusEx.SkillWeaponLowTech');
		SkillPistol = SkillSystem.GetSkillFromClass(Class'DeusEx.SkillWeaponPistol');

		If(Skillit == SkillRifle)
		{
			if(i == 3)
			{
				XPUp(8, 300);
				//ClientMessage("Level 3");
			}
			else if(i == 2)
			{
				XPUp(8, 200);
				//ClientMessage("Level 2");
			}
			else if(i == 1)
			{
				XPUp(8, 150);
				//ClientMessage("Level 1");
			}
			else if(i == 0)
			{
				XPUp(8, 100);
				//ClientMessage("Level 0");
			}
		}

		If(Skillit == SkillLT)
		{
			//9
			if(i == 3)
			{
				XPUp(9, 300);
				//ClientMessage("Level 3");
			}
			else if(i == 2)
			{
				XPUp(9, 200);
				//ClientMessage("Level 2");
			}
			else if(i == 1)
			{
				XPUp(9, 150);
				//ClientMessage("Level 1");
			}
			else if(i == 0)
			{
				XPUp(9, 100);
				//ClientMessage("Level 0");
			}
		}

		If(Skillit == SkillPistol)
		{
			//7
			if(i == 3)
			{
				XPUp(7, 300);
				//ClientMessage("Level 3");
			}
			else if(i == 2)
			{
				XPUp(7, 200);
				//ClientMessage("Level 2");
			}
			else if(i == 1)
			{
				XPUp(7, 150);
				//ClientMessage("Level 1");
			}
			else if(i == 0)
			{
				XPUp(7, 100);
				//ClientMessage("Level 0");
			}
		}
	}
}

function BBall()
{
	local Skill Skillphys;

	ballNum += 1;
	If (ballNum >= 5)
	{
		ballNum = 0;
		Skillphys = SkillSystem.GetSkillFromClass(Class'Contender.SkillPhysical');
		If(Skillphys != None)
		{
			if (Skillphys.CurrentLevel < 3)
			{
				Skillphys.CurrentLevel++;
				ClientMessage("|p2" $Skillphys.SkillName$ " skill upgraded!");
			}
		}
	}
}
function ReadIt(BookMMRPG book)
{
	local Skill Skillbook;
	local DeusExWeapon W2;

	Skillbook = SkillSystem.GetSkillFromClass(book.BookSkill);
	If(Skillbook != None)
	{
		if (SkillBook.CurrentLevel < 3)
		{
			Skillbook.CurrentLevel++;
			ClientMessage("|p2" $Skillbook.SkillName$ " skill upgraded!");
		}
	}
}

function InitializeSubSystems()
{
	bArena = False;
	// Spawn the BarkManager
	if (BarkManager == None)
		BarkManager = Spawn(class'BarkManager', Self);

	// Spawn the Color Manager
	CreateColorThemeManager();
    ThemeManager.SetOwner(self);

	// install the augmentation system if not found
	if (AugmentationSystem == None)
	{
		AugmentationSystem = Spawn(class'MMAugmentationManager', Self);
		AugmentationSystem.CreateAugmentations(Self);
		AugmentationSystem.AddDefaultAugmentations();        
        AugmentationSystem.SetOwner(Self);       
	}
	else
	{
		AugmentationSystem.SetPlayer(Self);
        AugmentationSystem.SetOwner(Self);
	}

	// install the skill system if not found
	if (SkillSystem == None)
	{
		SkillSystem = Spawn(class'MMRPGSkillManager', Self);
		SkillSystem.CreateSkills(Self);
		Skillage = True;
	}
	else
	{
		SkillSystem.SetPlayer(Self);
	}

   if ((Level.Netmode == NM_Standalone) || (!bBeltIsMPInventory))
   {
      // Give the player a keyring
      CreateKeyRing();
   }
}

function ResetPlayerToDefaults()
{
	local inventory anItem;
	local inventory nextItem;

   // reset the image linked list
	FirstImage = None;

	if (DeusExRootWindow(rootWindow) != None)
		DeusExRootWindow(rootWindow).ResetFlags();

	// Remove all the keys from the keyring before
	// it gets destroyed
	if (KeyRing != None)
	{
		KeyRing.RemoveAllKeys();
      if ((Role == ROLE_Authority) && (Level.NetMode != NM_Standalone))
      {
         KeyRing.ClientRemoveAllKeys();
      }
		KeyRing = None;
	}

	while(Inventory != None)
	{
		anItem = Inventory;
		DeleteInventory(anItem);
		anItem.Destroy();
	}

	// Clear object belt
	if (DeusExRootWindow(rootWindow) != None)
		DeusExRootWindow(rootWindow).hud.belt.ClearBelt();

	// clear the notes and the goals
	DeleteAllNotes();
	DeleteAllGoals();

	// Nuke the history
	ResetConversationHistory();

	// Other defaults
	Credits = Default.Credits;
	Energy  = Default.Energy;

	SetInHandPending(None);
	SetInHand(None);

	bInHandTransition = False;

	RestoreAllHealth();
	ClearLog();

	// Reset save count/time
	saveCount = 0;
	saveTime  = 0.0;

	// Reinitialize all subsystems we've just nuked
	InitializeSubSystems();

   // Give starting inventory.
   if (Level.Netmode != NM_Standalone)
	{
		NintendoImmunityEffect( True );
      GiveInitialInventory();
	}
	ChangeFOV();
}

function GiveInitialInventory ()
{
	local bool VB0;
	local Inventory anItem;
	local int k;
	local MMRPGCreditCard CR;

	if (  !Level.Game.IsA('DeusExMPGame') || DeusExMPGame(Level.Game).bStartWithPistol )
	{
		anItem=Spawn(Class'WeaponPistol');
		if ( anItem != None )
		{
			anItem.Frob(self,None);
			Inventory.bInObjectBelt=True;
			anItem.Destroy();
		}
		anItem=Spawn(Class'Ammo10mm');
		if ( anItem != None )
		{
			DeusExAmmo(anItem).AmmoAmount=50;
			anItem.Frob(self,None);
			anItem.Destroy();
		}
	}

	anItem=Spawn(Class'WeaponFist');
	if ( anItem != None )
	{
		anItem.Frob(self,None);
		Inventory.bInObjectBelt=True;
		anItem.Destroy();
	}

	anItem=Spawn(Class'MMRPGCreditCard');
	if ( anItem != None )
	{
		anItem.Frob(self,None);
		Inventory.bInObjectBelt=True;
		anItem.Destroy();
	}
	foreach allactors(class'MMRPGCreditCard', CR)
	{
		if(CR.Owner == Self)
		{
			CCardz = CR;
		}
	}

}


function bool HandleItemPickup (Actor FrobTarget, optional bool bSearchOnly)
{
	local bool VB4;
	local bool bCanPickup;
	local bool VB5;
	local Inventory foundItem;

	VB5=True;
	bCanPickup=True;
	VB4=False;
	if ( V7B )
	{
		if ( FrobTarget.IsA('DeusExWeapon') )
		{
			DeusExWeapon(FrobTarget).PickupAmmoCount=1;
			DeusExWeapon(FrobTarget).mpPickupAmmoCount=1;
		} else {
			if ( FrobTarget.IsA('Ammo') )
			{
				Ammo(FrobTarget).AmmoAmount=1;
			}
		}
	}
	if ( FrobTarget.IsA('DataVaultImage') || FrobTarget.IsA('NanoKey') || FrobTarget.IsA('Credits') || FrobTarget.IsA('MMRPGCredits') )
	{
		VB5=False;
	} else {
		if ( FrobTarget.IsA('DeusExPickup') )
		{
			if ( (FindInventoryType(FrobTarget.Class) != None) && DeusExPickup(FrobTarget).bCanHaveMultipleCopies )
			{
				VB5=False;
			}
		} else {
			foundItem=GetWeaponOrAmmo(Inventory(FrobTarget));
			if ( foundItem != None )
			{
				VB5=False;
				if ( foundItem.IsA('Ammo') )
				{
					if ( Ammo(foundItem).AmmoAmount >= Ammo(foundItem).MaxAmmo )
					{
						ClientMessage(TooMuchAmmo);
						bCanPickup=False;
					}
				} else {
					if ( foundItem.IsA('WeaponEMPGrenade') || foundItem.IsA('WeaponGasGrenade') || foundItem.IsA('WeaponNanoVirusGrenade') || foundItem.IsA('WeaponLAM') )
					{
						if ( DeusExWeapon(foundItem).AmmoType.AmmoAmount >= DeusExWeapon(foundItem).AmmoType.MaxAmmo )
						{
							ClientMessage(TooMuchAmmo);
							bCanPickup=False;
						}
					} else {
						if ( foundItem.IsA('Weapon') )
						{
							bCanPickup= !(Weapon(foundItem).ReloadCount == 0) && (Weapon(foundItem).PickupAmmoCount == 0) && (Weapon(foundItem).AmmoName != None);
							if (  !bCanPickup )
							{
								ClientMessage(Sprintf(CanCarryOnlyOne,foundItem.ItemName));
							}
						}
					}
				}
			} else {
				if ( V7B )
				{
					VB4=True;
				}
			}
		}
	}
	if ( VB5 && bCanPickup )
	{
		if ( FindInventorySlot(Inventory(FrobTarget),bSearchOnly) == False )
		{
			ClientMessage(Sprintf(InventoryFull,Inventory(FrobTarget).ItemName));
			bCanPickup=False;
			ServerConditionalNotifyMsg(11);
		}
	}
	if ( bCanPickup )
	{
		if ( (Level.NetMode != 0) && (FrobTarget.IsA('DeusExWeapon') || FrobTarget.IsA('DeusExAmmo')) )
		{
			PlaySound(Sound'WeaponPickup',SLOT_Interact ,0.50 + FRand() * 0.25,,256.00,0.95 + FRand() * 0.10);
		}
		DoFrob(self,inHand);
		if ( Level.NetMode != 0 )
		{
			if ( FrobTarget.IsA('DeusExWeapon') && (DeusExWeapon(FrobTarget).PickupAmmoCount == 0) )
			{
				DeusExWeapon(FrobTarget).PickupAmmoCount=DeusExWeapon(FrobTarget).Default.mpPickupAmmoCount * 3;
			}
		}
		if ( VB4 )
		{
			foundItem=GetWeaponOrAmmo(Inventory(FrobTarget));
			if ( DeusExWeapon(foundItem) != None )
			{
				DeusExWeapon(foundItem).AmmoType.AmmoAmount=1;
			}
		}
	}
	V7B=False;
	return bCanPickup;
}



function float GetCurrentGroundSpeed()
{
	local float mult, speed;

	// Remove this later and find who's causing this to Access None MB
	if ( SkillSystem == None )
		return 0;

	mult = SkillSystem.GetSkillLevelValue(class'SkillPhysical');

	if (( Level.NetMode != NM_Standalone ) && Self.IsA('Human') )
		speed = Self.mpGroundSpeed * mult;
	else
		speed = Default.GroundSpeed * mult;

//	if(Energy <= 0)
//	{
//		if (bForceDuck || bCrouchOn)
//		{
//			speed = Default.GroundSpeed * mult * 0.1;
//		}
//		bIsWalking=True;
//	//	speed *= 0.4;
//	}

	return speed;
}


exec function ToggleWalk()
{
//	if(Energy <= 0)
//	{
//		Energy = 0;
//		return;
//	}
	if (RestrictInput())
		return;

	bToggleWalk = !bToggleWalk;
}


function bool CheckMedSkill()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillMedicine');

		if (mult >= 3)
		{
			return True;
		}
	}

	return False;
}

function bool CheckToolSkill()
{
	local float mult;

	// check skill use
	if (SkillSystem != None)
	{
		mult = SkillSystem.GetSkillLevelValue(class'SkillTech');

		if (mult >= 0.750000)
		{
			return True;
		}
	}

	return False;
}



function DoFrob (Actor VB8, Inventory VB9)
{
	local DeusExMover VBA;
	local RPGPolicePistol P;
	local DoctorsMedkit D;
	local DoctorUniform DU;
	local ElectriciansMultitool ET;
	local ElectricianUniform EU;
	local NailageColaBlue BC;
	local RestRecipe RR;
	local LionStatue LS;
	local NinjaUniform NU;
	local NinjaWeapon Nin;
	local AptKey AK;
	local ComputerPersonal CPZ;

	if ( FrobTarget == None )
	{
		return;
	}
	if ( Level.NetMode != 0 )
	{		

		if(FrobTarget.IsA('ScriptedPawn'))
		{
			ScriptedPawn(FrobTarget).Frob(VB8, VB9);
			return;
		}

		P=RPGPolicePistol(FrobTarget);
		if ( P != None )
		{
			if ( clubmission != 2)
			{
				Self.ClientMessage("I'd better not take this...");
				return;
			}
		}
		D=DoctorsMedkit(FrobTarget);
		if ( D != None )
		{
			if ( !bDoctor)
			{
				Self.ClientMessage("I'm not a doctor...");
				return;
			}
		}
		DU=DoctorUniform(FrobTarget);
		if ( DU != None )
		{
			if ( !bDoctor)
			{
				Self.ClientMessage("I'm not a doctor...");
				return;
			}
		}
		ET=ElectriciansMultitool(FrobTarget);
		if ( ET != None )
		{
			if( !bMechanic)
			{
				Self.ClientMessage("I'm not a mechanic...");
				return;
			}
		}
		EU=ElectricianUniform(FrobTarget);
		if ( EU != None )
		{
			if( !bMechanic)
			{
				Self.ClientMessage("I'm not a mechanic...");
				return;
			}
		}
		BC=NailageColaBlue(FrobTarget);
		if ( BC != None )
		{
			if( ColaMission < 4 )
			{
				Self.ClientMessage("I'm not stealing this!");
				return;
			}
		}
		RR=RestRecipe(FrobTarget);
		if( RR != None )
		{
			if( ColaMission != 3 )
			{
				Self.ClientMessage("I'm not stealing this!");
				return;	
			}
		}
		LS=LionStatue(FrobTarget);
		if( LS != None )
		{
			if( Thiefmission != 2 )
			{
				Self.ClientMessage("I'm not stealing this!");
				return;	
			}

		}
		NU=NinjaUniform(FrobTarget);
		if( NU != None )
		{
			if( !bNinja )
			{
				Self.ClientMessage("I'm not a ninja!");
				return;
			}
		}
		Nin=NinjaWeapon(FrobTarget);
		if( Nin != None)
		{
			if( !bNinja )
			{
				Self.ClientMessage("I'm not a ninja!");
				return;
			}
		}
		AK=AptKey(FrobTarget);
		if( AK != None )
		{
			if(KeyCheck() == False)
			{
				return;
			}
		}
		CPZ=ComputerPersonal(FrobTarget);
		if(CPZ != None)
		{
			if(CPZ.Class == Class'DeusEx.ComputerPersonal')
			{
				return;
			}
		}
	}
	Super.DoFrob(VB8,VB9);
}


exec function bool DropItem (optional Inventory Inv, optional bool bDrop)
{	
	local Inventory Item;
	local Inventory previousItemInHand;

	if ( Inv == None )
	{
		previousItemInHand=inHand;
		Item=inHand;
	}
	else
	{
		Item=Inv;
	}

	if ( Item.IsA('MMRPGCreditCard') )
	{
		MMRPGCreditCard(Item).CCheck();
		return False;
	}
	Super.DropItem(Inv, bDrop);
}


function SetCard(MMRPGCreditCard card)
{
	CreditCard = card;
}

function SetBank(BankTakeOut take)
{
	Bank = take;
}


exec function QuitJob ()
{
/*
	local DoctorsMedkit med;
	local ElectriciansMultiTool tool;

	bDoctor = False;
	bMechanic = False;
	bHasJob = False;
	JobName = "Unemployed";
	ClientMessage("|p4You are now unemployed");

	Foreach AllActors (class'DoctorsMedkit', med)
	{
		if (med.Owner == Self)
		{
			med.Destroy();
		}
	}

	Foreach AllActors (class'ElectriciansMultiTool', tool)
	{
		if (tool.Owner == Self)
		{
			tool.Destroy();
		}
	}

	Mesh=Self.Default.Mesh;
	MultiSkins[0]=Self.Default.MultiSkins[0];
	MultiSkins[1]=Self.Default.MultiSkins[1];
	MultiSkins[2]=Self.Default.MultiSkins[2];
	MultiSkins[3]=Self.Default.MultiSkins[3];
	MultiSkins[4]=Self.Default.MultiSkins[4];
	MultiSkins[5]=Self.Default.MultiSkins[5];
	MultiSkins[6]=Self.Default.MultiSkins[6];
	MultiSkins[7]=Self.Default.MultiSkins[7];
*/
}







exec function PM( int S, string Msg )
{
	local DeusExPlayer P;
	local String str;
	local String str2;

	str = PlayerReplicationInfo.PlayerName $ " |p3Private Message:|p1 " $ Msg;

	foreach AllActors(class'DeusExPlayer', P)
	{	
		if (P.PlayerReplicationInfo.PlayerID == S)
		{
			str2 = "|p3Private Message to " $ P.PlayerReplicationInfo.PlayerName $ ":|p1 " $ Msg;
			P.ClientMessage( str, 'PM', true );
			ClientMessage( str2, 'PM', true );
			return;
		}
	}

	return;
}

exec function TeamSay( string Msg )
{
}

 exec function ShowMainMenu()
{
local DeusExRootWindow root;
local DeusExLevelInfo info;
local MissionEndgame Script;

if (bIgnoreNextShowMenu)
{
bIgnoreNextShowMenu = False;
return;
}

info = GetLevelInfo();

// Special case baby!
//
// If the Intro map is loaded and we get here, that means the player
// pressed Escape and we want to either A) start a new game
// or B) return to the dx.dx screen. Either way we're going to
// abort the Intro by doing this.
//
// If this is one of the Endgames (which have a mission # of 99)
// then we also want to call the Endgame's "FinishCinematic"
// function

// force the texture caches to flush
ConsoleCommand("FLUSH");

if ((info != None) && (info.MissionNumber == 98))
{
bIgnoreNextShowMenu = True;
PostIntro();
}
else if ((info != None) && (info.MissionNumber == 99))
{
foreach AllActors(class'MissionEndgame', Script)
break;

if (Script != None)
Script.FinishCinematic();
}
else
{
root = DeusExRootWindow(rootWindow);
if (root != None)
root.InvokeMenu(class'Contender.RPGMenuMain');
}
}

exec function Whisper (string Z38)
{
	local int tleft;
	local Pawn P;
	local string str;

	if ( V7D )
	{
		return;
	}
	if (  !PlayerIsListenClient() && (Level.NetMode != 0) )
	{
		V62(Len(Z38));
		if ( V4A() )
		{
			return;
		}
	}
	if ( Z38 != "" )
	{
		V54(Z38,True);
	}
	if ( Z38 == "" )
	{
		return;
	}
	str=V50() $ " (Whisper) :" @ Z38;
	if ( Role == 4 )
	{
		Log(str,'Whisper');
	}

	//foreach VisibleActors(class'Pawn', P, TalkRadius)
	foreach RadiusActors(class'Pawn', P, TalkRadius)
	{
		P.ClientMessage(str);
	}

}


exec function Say (string Z38)
{
	local Pawn P;
	local string str;
	local int tleft;

	if(BroadcastTime > (Level.TimeSeconds - int(lastBroadcast)))
	{
		tleft = int(BroadcastTime - (Level.TimeSeconds - lastBroadcast));
		ClientMessage("You may not send a message this often! Please wait "$tleft$" seconds!");
		return;
	}

	if ( V7D )
	{
		return;
	}
	if (  !PlayerIsListenClient() && (Level.NetMode != 0) )
	{
		V62(Len(Z38));
		if ( V4A() )
		{
			return;
		}
	}
	if ( Z38 != "" )
	{
		V54(Z38,True);
	}
	if ( Z38 == "" )
	{
		return;
	}
	str=V50() $ ":" @ Z38;
	if ( Role == 4 )
	{
		Log(str,'Say');
	}
	P=Level.PawnList;
JL00B3:
	if ( P != None )
	{
		lastBroadcast = Level.TimeSeconds;
		if ( P.IsA('MTLPlayer') || P.IsA('MessagingSpectator') )
		{
			P.ClientMessage(str,'Say',True);
		}
		P=P.nextPawn;
		goto JL00B3;
	}
}






function Died(pawn Killer, name damageType, vector HitLocation)
{
	local vector loc1;
	local vector loc2;
	local teleporter tele1;
	local teleporter tele2;
	local ArenaTeleporter AT;
	local int numStake;


	if (conPlay != None)
		conPlay.TerminateConversation();

	if (bOnFire)
		ExtinguishFire();

	if (AugmentationSystem != None)
		AugmentationSystem.DeactivateAll();

	if (bArena)
	{
		foreach allactors (class'Teleporter', tele1)
		{
			If (tele1.Tag == 'ARENA1')
			{
				loc1 = Tele1.location;
			}
		}
		foreach allactors (class'Teleporter', tele2)
		{
			If (tele2.Tag == 'ARENA2')
			{
				loc2 = Tele2.location;
			}
		}

		foreach allactors (class'ArenaTeleporter', AT)
		{
			AT.bFighting = False;
			AT.NumPlayers = 0;
			numStake = AT.Stake;
		}
		_MMRPGPlayer(Killer).CreditCard.CreditAmount += (numStake*2);
		_MMRPGPlayer(Killer).SkillItUp(killProfile.activeSkillLevel);
		_MMRPGPlayer(Killer).bAMaster = True;
		_MMRPGPlayer(Killer).ClientMessage("|p2You have defeated " $PlayerReplicationInfo.PlayerName $ "!!!");
		_MMRPGPlayer(Killer).ClientMessage("|p2You have won " $(numStake*2)$ " credits!!!");
		ClientMessage("|p2You have been killed by " $_MMRPGPlayer(Killer).PlayerReplicationInfo.PlayerName $ "!!!");
		if ( Role == ROLE_Authority )
		{
			DeusExPlayer(Killer).HealPlayer(9000, True);
			Self.HealPlayer(9000, True);

			SetLocation(loc1);
			SetPhysics(PHYS_Falling);

			_MMRPGPlayer(Killer).SetLocation(loc2);
			_MMRPGPlayer(Killer).SetPhysics(PHYS_Falling);
		}
		bArena = False;
		_MMRPGPlayer(Killer).bArena = False;

		return;
	}

   if ((Level.NetMode == NM_DedicatedServer) || (Level.NetMode == NM_ListenServer))
      ClientDeath();

	Super.Died(Killer, damageType, HitLocation);
}


exec function Suicide()
{
	if (bArena)
	{
		ClientMessage("You cannot suicide while in the arena!");
		return;
	}
	super.Suicide();
}

exec function reconnect()
{
	if(bArena) return;
}


function TakeDamage (int Damage, Pawn instigatedBy, Vector HitLocation, Vector Momentum, name DamageType)
{
	if ( ( Health <= 0 ) && ( bArena ) )
	{
		Died(instigatedBy,DamageType,HitLocation);
		return;
	}


	Super.TakeDamage(Damage, instigatedBy, HitLocation, Momentum, DamageType);
}


function UpdatePoison(float deltaTime)
{
	if (Health <= 0)  // no more pain -- you're already dead!
		return;

	if (InConversation())  // kinda hacky...
		return;

	if (poisonCounter > 0)
	{
		poisonTimer += deltaTime;
		if (poisonTimer >= 2.0)  // pain every two seconds
		{
			poisonTimer = 0;
			poisonCounter--;
			TakeDamage(poisonDamage, myPoisoner, Location, vect(0,0,0), 'PoisonEffect');
			ShakeView(0.5, 1024, 16);
		}
		if ((poisonCounter <= 0) || (Health <= 0))
			StopPoison();
	}
}


function StartPoison( Pawn poisoner, int Damage )
{
	local float augLevel;

	if ( Level.NetMode != NM_Standalone )
	{
		// Don't do poison and drug effects if in multiplayer and AugEnviro is on
		augLevel = AugmentationSystem.GetAugLevelValue(class'AugEnviro');
		if ( augLevel != -1.0 )
			return;
	}

	myPoisoner = poisoner;

	if (Health <= 0)  // no more pain -- you're already dead!
		return;

	if (InConversation())  // kinda hacky...
		return;

	poisonCounter = 4;    // take damage no more than four times (over 8 seconds)
	poisonTimer   = 0;    // reset pain timer
	if (poisonDamage < Damage)  // set damage amount
		poisonDamage = Damage;

	drugEffectTimer += 4;  // make the player vomit for the next four seconds

	// In multiplayer, don't let the effect last longer than 30 seconds
	if ( Level.NetMode != NM_Standalone )
	{
		if ( drugEffectTimer > 30 )
			drugEffectTimer = 30;
	}
}


state Dying
{
	ignores all;

	event PlayerTick(float deltaTime)
	{
	if (bArena)
		return;

      if (PlayerIsClient())      
         ClientDeath();
		UpdateDynamicMusic(deltaTime);

		Super.PlayerTick(deltaTime);
	}

	exec function Fire(optional float F)
	{
		if ( Level.NetMode != NM_Standalone )
        Super.Fire();
	}

	exec function ShowMainMenu()
	{
		// reduce the white glow when the menu is up
		if (InstantFog != vect(0,0,0))
		{
			InstantFog   = vect(0.1,0.1,0.1);
			InstantFlash = 0.01;

			// force an update
			ViewFlash(1.0);
		}

		Global.ShowMainMenu();
	}

	function BeginState()
	{
	if (bArena)
		return;

		FrobTime = Level.TimeSeconds;
		ShowHud(False);
      ClientDeath();
	}

   function TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType)
	{
	}

	function PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation)
	{
		local vector ViewVect, HitLocation, HitNormal, whiteVec;
		local float ViewDist;
		local actor HitActor;
		local float time;

		ViewActor = Self;
		if (bHidden)
		{
			// spiral up and around carcass and fade to white in five seconds
			time = Level.TimeSeconds - FrobTime;

			if ( ((myKiller != None) && (killProfile != None) && (!killProfile.bKilledSelf)) || 
				  ((killProfile != None) && killProfile.bValid && (!killProfile.bKilledSelf)))
			{
				if ( killProfile.bValid && killProfile.bTurretKilled )
					ViewVect = killProfile.killerLoc - Location;
				else if ( killProfile.bValid && killProfile.bProximityKilled )
					ViewVect = killProfile.killerLoc - Location;
				else if (( !killProfile.bKilledSelf ) && ( myKiller != None ))
					ViewVect = myKiller.Location - Location;
				CameraLocation = Location;
				CameraRotation = Rotator(ViewVect);
			}
			else if (time < 8.0)
			{
				whiteVec.X = time / 16.0;
				whiteVec.Y = time / 16.0;
				whiteVec.Z = time / 16.0;
				CameraRotation.Pitch = -16384;
				CameraRotation.Yaw = (time * 8192.0) % 65536;
				ViewDist = 32 + time * 32;
				InstantFog = whiteVec;
				InstantFlash = 0.5;
				ViewFlash(1.0);
				// make sure we don't go through the ceiling
				ViewVect = vect(0,0,1);
				HitActor = Trace(HitLocation, HitNormal, Location + ViewDist * ViewVect, Location);
				if ( HitActor != None )
					CameraLocation = HitLocation;
				else
					CameraLocation = Location + ViewDist * ViewVect;
			}
			else
			{
				if  ( Level.NetMode != NM_Standalone )
				{
					// Don't fade to black in multiplayer
				}
				else
				{
					// then, fade out to black in four seconds and bring up
					// the main menu automatically
					whiteVec.X = FMax(0.5 - (time-8.0) / 8.0, -1.0);
					whiteVec.Y = FMax(0.5 - (time-8.0) / 8.0, -1.0);
					whiteVec.Z = FMax(0.5 - (time-8.0) / 8.0, -1.0);
					CameraRotation.Pitch = -16384;
					CameraRotation.Yaw = (time * 8192.0) % 65536;
					 ViewDist = 32 + 8.0 * 32;
					InstantFog = whiteVec;
					InstantFlash = whiteVec.X;
					ViewFlash(1.0);

					// start the splash screen after a bit
					// only if we don't have a menu open
					// DEUS_EX AMSD Don't do this in multiplayer!!!!
					if (Level.NetMode == NM_Standalone)
					{
						if (whiteVec == vect(-1.0,-1.0,-1.0))
							if ((MenuUIWindow(DeusExRootWindow(rootWindow).GetTopWindow()) == None) &&
								(ToolWindow(DeusExRootWindow(rootWindow).GetTopWindow()) == None))
								ConsoleCommand("OPEN DXONLY");
					}
				}
				// make sure we don't go through the ceiling
				ViewVect = vect(0,0,1);
				HitActor = Trace(HitLocation, HitNormal, Location + ViewDist * ViewVect, Location);
				if ( HitActor != None )
					CameraLocation = HitLocation;
				else
					CameraLocation = Location + ViewDist * ViewVect;
			}
		}
		else
		{
			// use FrobTime as the cool DeathCam timer
			FrobTime = Level.TimeSeconds;

			// make sure we don't go through the wall
		    ViewDist = 190;
			ViewVect = vect(1,0,0) >> Rotation;
			HitActor = Trace( HitLocation, HitNormal, 
					Location - ViewDist * vector(CameraRotation), Location, false, vect(12,12,2));
			if ( HitActor != None )
				CameraLocation = HitLocation;
			else
				CameraLocation = Location - ViewDist * ViewVect;
		}

		// don't fog view if we are "paused"
		if (DeusExRootWindow(rootWindow).bUIPaused)
		{
			InstantFog   = vect(0,0,0);
			InstantFlash = 0;
			ViewFlash(1.0);
		}
	}

Begin:
	// Dead players comes back to life with scope view, so this is here to prevent that
	if ( DeusExWeapon(inHand) != None )
	{
		DeusExWeapon(inHand).bZoomed = False;
		DeusExWeapon(inHand).RefreshScopeDisplay(Self, True, False);
	}

	if ( DeusExRootWindow(rootWindow).hud.augDisplay != None )
	{
		DeusExRootWindow(rootWindow).hud.augDisplay.bVisionActive = False;
		DeusExRootWindow(rootWindow).hud.augDisplay.activeCount = 0;
	}

	// Don't come back to life drugged or posioned
	poisonCounter		= 0; 
	poisonTimer			= 0;    
	drugEffectTimer	= 0;

	// Don't come back to life crouched
	bCrouchOn			= False;
	bWasCrouchOn		= False;
	bIsCrouching		= False;
	bForceDuck			= False;
	lastbDuck			= 0;
	bDuck					= 0;

	FrobTime = Level.TimeSeconds;
	bBehindView = True;
	Velocity = vect(0,0,0);
	Acceleration = vect(0,0,0);
	DesiredFOV = Default.DesiredFOV;
	FinishAnim();
	KillShadow();

   FlashTimer = 0;

	// hide us and spawn the carcass
	bHidden = True;
	SpawnCarcass();
   //DEUS_EX AMSD Players should not leave physical versions of themselves around :)
   if (Level.NetMode != NM_Standalone)
      HidePlayer();
}





//=============






simulated function DrugEffects(float deltaTime)
{
	local float mult, fov;
	local Rotator rot;
	local DeusExRootWindow root;

	root = DeusExRootWindow(rootWindow);

	// random wandering and swaying when drugged
	if (drugEffectTimer > 0)
	{

		if ((root != None) && (root.hud != None))
		{
			if (root.hud.background == None)
			{
				if (bGuinness)
					root.hud.SetBackground(Texture'Effects.Fire.Wepn_Prifle_SFX');

				else if (bJack)
					root.hud.SetBackground(Texture'Effects.Electricity.Nano_SFX');

				else if (bMatr)
					root.hud.SetBackground(Texture'Extras.Eggs.Matrix_A00');

				else if (bBud)
					root.hud.SetBackground(Texture'Effects.Liquid.Virus_SFX');

				else if (!bMatr && !bGuinness && !bJack && !bBud)
					root.hud.SetBackground(Texture'DrunkFX');

				root.hud.SetBackgroundSmoothing(True);
				root.hud.SetBackgroundStretching(True);
				root.hud.SetBackgroundStyle(DSTY_Modulated);
			}
		}

		mult = FClamp(drugEffectTimer / 10.0, 0.0, 3.0);
		rot.Pitch = 1024.0 * Cos(Level.TimeSeconds * mult) * deltaTime * mult;
		rot.Yaw = 1024.0 * Sin(Level.TimeSeconds * mult) * deltaTime * mult;
		rot.Roll = 0;

		rot.Pitch = FClamp(rot.Pitch, -4096, 4096);
		rot.Yaw = FClamp(rot.Yaw, -4096, 4096);

		ViewRotation += rot;

		if ( Level.NetMode == NM_Standalone )
		{
			fov = Default.DesiredFOV - drugEffectTimer + Rand(2);
			fov = FClamp(fov, 30, Default.DesiredFOV);
			DesiredFOV = fov;
		}
		else
			DesiredFOV = Default.DesiredFOV;

		drugEffectTimer -= deltaTime;
		if (drugEffectTimer < 0)
		{
			bGuinness = False;
			bJack = False;
			bMatr = False;
			drugEffectTimer = 0;
		}
	}
	else
	{
		if ((root != None) && (root.hud != None))
		{
			if (root.hud.background != None)
			{
				root.hud.SetBackground(None);
				root.hud.SetBackgroundStyle(DSTY_Normal);
				DesiredFOV = Default.DesiredFOV;
			}
		}
	}
}




// ----------------------------------------------------------------------
// DXReduceDamage()
//
// Calculates reduced damage from augmentations and from inventory items
// Also calculates a scalar damage reduction based on the mission number
// ----------------------------------------------------------------------
function bool DXReduceDamage(int Damage, name damageType, vector hitLocation, out int adjustedDamage, bool bCheckOnly)
{
	local float newDamage;
	local float augLevel, skillLevel;
	local float pct;
	local HazMatSuit suit;
	local BallisticArmor armor;
	local bool bReduced;

	bReduced = False;
	newDamage = Float(Damage);

	if ((damageType == 'TearGas') || (damageType == 'PoisonGas') || (damageType == 'Radiation') ||
		(damageType == 'HalonGas')  || (damageType == 'PoisonEffect') || (damageType == 'Poison'))
	{
		if (AugmentationSystem != None)
			augLevel = AugmentationSystem.GetAugLevelValue(class'AugEnviro');

		if (augLevel >= 0.0)
			newDamage *= augLevel;

		// get rid of poison if we're maxed out
		if (newDamage ~= 0.0)
		{
			StopPoison();
			drugEffectTimer -= 4;	// stop the drunk effect
			if (drugEffectTimer < 0)
				drugEffectTimer = 0;
		}

		// go through the actor list looking for owned HazMatSuits
		// since they aren't in the inventory anymore after they are used


      //foreach AllActors(class'HazMatSuit', suit)
//			if ((suit.Owner == Self) && suit.bActive)
      if (UsingChargedPickup(class'HazMatSuit'))
			{
				skillLevel = SkillSystem.GetSkillLevelValue(class'SkillEnviro');
				newDamage *= 0.75 * skillLevel;
			}
	}

	if ((damageType == 'Shot') || (damageType == 'Sabot') || (damageType == 'Exploded') || (damageType == 'AutoShot'))
	{
		// go through the actor list looking for owned BallisticArmor
		// since they aren't in the inventory anymore after they are used
      if (UsingChargedPickup(class'ArmourStandard'))
			{
				skillLevel = SkillSystem.GetSkillLevelValue(class'SkillEnviro');
				newDamage *= 0.95;
			}
      if (UsingChargedPickup(class'ArmourReIn'))
			{
				skillLevel = SkillSystem.GetSkillLevelValue(class'SkillEnviro');
				newDamage *= 0.85;
			}
      if (UsingChargedPickup(class'ArmourExtraReIn'))
			{
				skillLevel = SkillSystem.GetSkillLevelValue(class'SkillEnviro');
				newDamage *= 0.75;
			}
	}

	if (damageType == 'HalonGas')
	{
		if (bOnFire && !bCheckOnly)
			ExtinguishFire();
	}

	if ((damageType == 'Shot') || (damageType == 'AutoShot'))
	{
		if (AugmentationSystem != None)
			augLevel = AugmentationSystem.GetAugLevelValue(class'AugBallistic');

		if (augLevel >= 0.0)
			newDamage *= augLevel;
	}

	if (damageType == 'EMP')
	{
		if (AugmentationSystem != None)
			augLevel = AugmentationSystem.GetAugLevelValue(class'AugEMP');

		if (augLevel >= 0.0)
			newDamage *= augLevel;
	}

	if ((damageType == 'Burned') || (damageType == 'Flamed') ||
		(damageType == 'Exploded') || (damageType == 'Shocked'))
	{
		if (AugmentationSystem != None)
			augLevel = AugmentationSystem.GetAugLevelValue(class'AugShield');

		if (augLevel >= 0.0)
			newDamage *= augLevel;
	}

	if (newDamage < Damage)
	{
		if (!bCheckOnly)
		{
			pct = 1.0 - (newDamage / Float(Damage));
			SetDamagePercent(pct);
			ClientFlash(0.01, vect(0, 0, 50));
		}
		bReduced = True;
	}
	else
	{
		if (!bCheckOnly)
			SetDamagePercent(0.0);
	}


	//
	// Reduce or increase the damage based on the combat difficulty setting
	//
	if ((damageType == 'Shot') || (damageType == 'AutoShot'))
	{
		newDamage *= CombatDifficulty;

		// always take at least one point of damage
		if ((newDamage <= 1) && (Damage > 0))
			newDamage = 1;
	}

	adjustedDamage = Int(newDamage);

	return bReduced;
}



function MaintainEnergy(float deltaTime)
{
	local Float energyUse;
   local Float energyRegen;


	// make sure we can't continue to go negative if we take damage
	// after we're already out of energy
	if (Energy <= 0)
	{
		Energy = 0;
		EnergyDrain = 0;
		EnergyDrainTotal = 0;
	}

   energyUse = 0;

	// Don't waste time doing this if the player is dead or paralyzed
	if ((!IsInState('Dying')) && (!IsInState('Paralyzed')))
   {
      if (Energy > 0)
      {
         // Decrement energy used for augmentations
         energyUse = AugmentationSystem.CalcEnergyUse(deltaTime);
         
         Energy -= EnergyUse;
         
         // Calculate the energy drain due to EMP attacks
         if (EnergyDrain > 0)
         {
            energyUse = EnergyDrainTotal * deltaTime;
            Energy -= EnergyUse;
            EnergyDrain -= EnergyUse;
            if (EnergyDrain <= 0)
            {
               EnergyDrain = 0;
               EnergyDrainTotal = 0;
            }
         }
      }

      //Do check if energy is 0.  
      // If the player's energy drops to zero, deactivate 
      // all augmentations
      if (Energy <= 0)
      {
         //If we were using energy, then tell the client we're out.
         //Otherwise just make sure things are off.  If energy was
         //already 0, then energy use will still be 0, so we won't
         //spam.  DEUS_EX AMSD
         if (energyUse > 0)         
            ClientMessage(EnergyDepleted);
         Energy = 0;
         EnergyDrain = 0;
         EnergyDrainTotal = 0;         
         AugmentationSystem.DeactivateAll();
      }

      //MainMan: No!
      // If all augs are off, then start regenerating in multiplayer,
      // up to 25%.
      //if ((energyUse == 0) && (Energy <= MaxRegenPoint) && (Level.NetMode != NM_Standalone))
      //{
      //   energyRegen = RegenRate * deltaTime;
      //   Energy += energyRegen;
      //}

	}
}


Function SpawnItemz(class<Inventory> SpawnClass)
{
	if(SpawnClass == None)
		return;

	if (Level.Netmode != NM_Standalone)
	{
		GiveItemz(SpawnClass);
	}
}

Function GiveItemz(class<Inventory> SpawnClass)
{
	local Inventory Obj;

	if(SpawnClass == None)
		return;

	Obj = Spawn(SpawnClass);
	Obj.Frob(Self,None);
	Obj.bInObjectBelt = True;
	Obj.Destroy();
}


Event Destroyed()
{
	local int k;
	local ColorTheme V9C;
	local V2E somecrap;
	local Inventory item;
	local Inventory nextitem;
	local int iliek;


if(ROLE == ROLE_Authority)
{
	Class'InvContender'.static.ClearInv(InvSlotNum);
}




			if (Self.Inventory != None)
			{
				item      = Self.Inventory;
				nextItem  = None;

				for (k=1; k<10; k++)
				{
					// Find the next item we can process.
					while((item != None) && ((item.IsA('MMRPGCreditCard')) || (item.IsA('WeaponFist')) || (item.IsA('Ammo'))) )
						item = item.Inventory;

					if (item != None)
					{
						nextItem = item.Inventory;

						if(DeusExPickup(Item) != None)
						{
							if(DeusExPickup(Item).NumCopies > 1)
							{
								iliek = DeusExPickup(Item).NumCopies;
								if(ROLE == ROLE_Authority)
								{
									Class'InvContender'.static.WriteItemCount(InvSlotNum, k, iliek);
								}
							}
						}


						if(ROLE == ROLE_Authority)
						{
							Class'InvContender'.static.WriteInv(InvSlotNum, k, string(item.class));
						}

						log(""$item.itemname$ " logged");
						item.destroy();
						
					}
					
					if (nextItem == None)
						break;	
					else
						item = nextItem;
				}
			}

if(ROLE == ROLE_Authority)
{
Class'InvContender'.static.StaticSaveConfig();
}







	if ( PlayerIsOnServer() )
	{
		if ( AugmentationSystem != None )
		{
			AugmentationSystem.Destroy();
		}
		if ( SkillSystem != None )
		{
			SkillSystem.Destroy();
		}
		if ( aDrone != None )
		{
			aDrone.Destroy();
		}
		if ( invulnSph != None )
		{
			invulnSph.Destroy();
		}
		if ( killProfile != None )
		{
			killProfile.Destroy();
		}
		if ( ThemeManager != None )
		{
			V9C=ThemeManager.FirstColorTheme;
JL00D5:
			if ( V9C != None )
			{
				V9C.Destroy();
				V9C=V9C.Next;
				goto JL00D5;
			}
			ThemeManager.Destroy();
		}
	}

	foreach allactors(class'V2E', somecrap)
	{
		somecrap.destroy();
	}

	Super(Human).Destroyed();

	foreach allactors(class'V2E', somecrap)
	{
		somecrap.destroy();
	}
}

function SetCredAmount(int num)
{
	local MMRPGCreditCard Cred;
	ForEach AllActors(Class'MMRPGCreditCard', Cred)
	{
		if(Cred.Owner == Self)
		{
			Cred.CreditAmount = num;
		}
	}
}

exec function initest1()
{
	//ClientMessage(class'contender.invcontender'.static.getconfig( "Contender.InvContender", "Money[0]"));
	//ClientMessage(class'contender.invcontender'.static.getconfig( "Contender.InvContender", "Money[1]"));
}









//sitting stuff



function PlaySittingDown()
{
	PlayAnimPivot('SitBegin', , 0.15);
}

function PlaySitting()
{
	LoopAnimPivot('SitBreathe', , 0.15);
}

function PlayStandingUp()
{
	PlayAnimPivot('SitStand', , 0.15);
}

function SitDown()
{
}

function ServerSit()
{
	local Weapon W;

	W = Weapon;
	PendingWeapon = None;
	if ( Weapon != None )
		Weapon.PutDown();
	PendingWeapon = W;
	GotoState('SittingDown');
}


function EnableCollision(bool bSet)
{
	if (bSet)
		SetCollision(Default.bCollideActors, Default.bBlockActors, Default.bBlockPlayers);
	else
		SetCollision(True, False, True);

	bBehindView = !bSet;
}


state SittingDown
{
ignores SeePlayer, HearNoise, Bump;

	function ZoneChange( ZoneInfo NewZone )
	{
		if (NewZone.bWaterZone)
		{
			setPhysics(PHYS_Swimming);
			GotoState('PlayerSwimming');
		}
	}

	exec function Fire( optional float F )
	{
		bJustFired = true;
	}

	exec function AltFire( optional float F )
	{
		bJustFired = true;
	}

	function PlayChatting()
	{
	}

	exec function Taunt( name Sequence )
	{
	}

	function AnimEnd()
	{
		if ( (Role == ROLE_Authority) && (Health > 0) )
		{
			GotoState('PlayerWalking');
			if(PendingWeapon != None)
			{
				PendingWeapon.SetDefaultDisplayProperties();
			}
			ChangedWeapon();
		}
	}
	
	function Landed(vector HitNormal)
	{
		if ( Role == ROLE_Authority )
			PlaySound(Land, SLOT_Interact, 0.3, false, 800, 1.0);
		if ( bUpdating )
			return;
		TakeFallingDamage();
		bJustLanded = true;				
	}

	function RiseUp()
	{
		local Vector Phag;
		if ( !bRisingFromS )
		{

		Phag = Location;
		Phag.Z += 42;

		SetLocation(Phag);
			Enable('AnimEnd');
			BaseEyeHeight = Default.BaseEyeHeight;
			bRisingFromS = true;
			PlayStandingUp();
			bSitting = False;
			SeatActor.sittingActor[SeatSlot] = None;
			SeatActor = None;
			EnableCollision(True);
			
		}
	}

	function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)	
	{
		if ( bJustFired || bPressedJump || (NewAccel.Z > 0) )
			RiseUp();
		Acceleration = vect(0,0,0);
	}

	event PlayerTick( float DeltaTime )
	{
		local vector newPos;

		if (SeatActor != None)
		{
			newPos = SitPosition(SeatActor, SeatSlot);
			Acceleration = vect(0,0,0);
			Velocity = vect(0,0,0);
			SetBase(SeatActor);
			bSitting = true;

			SetRotation((Rotator(RotS2)+Rot(0, -16384, 0)));

			PlaySitting();
		}


		Weapon = None; // in case client confused because of weapon switch just before feign death
		if ( bUpdatePosition )
			ClientUpdatePosition();
		
		PlayerMove(DeltaTime);
	}




	function ServerMove
	(
		float TimeStamp, 
		vector Accel, 
		vector ClientLoc,
		bool NewbRun,
		bool NewbDuck,
		bool NewbJumpStatus, 
		bool bFired,
		bool bAltFired,
		bool bForceFire,
		bool bForceAltFire,
		eDodgeDir DodgeMove, 
		byte ClientRoll, 
		int View,
		optional byte OldTimeDelta,
		optional int OldAccel
	)
	{
		Global.ServerMove(TimeStamp, Accel, ClientLoc, NewbRun, NewbDuck, NewbJumpStatus,
							bFired, bAltFired, bForceFire, bForceAltFire, DodgeMove, ClientRoll, (32767 & (Rotation.Pitch/2)) * 32768 + (32767 & (Rotation.Yaw/2)));
	}

	function PlayerMove( float DeltaTime)
	{
		local rotator currentRot;
		local vector NewAccel;

		aLookup  *= 0.24;
		aTurn    *= 0.24;

		// Update acceleration.
		if ( !IsAnimating() && (aForward != 0) || (aStrafe != 0) )
			NewAccel = vect(0,0,1);
		else
			NewAccel = vect(0,0,0);

		// Update view rotation.
		currentRot = (Rotator(RotS2)+Rot(0, -16384, 0));
		UpdateRotation(DeltaTime, 1);
		SetRotation(currentRot);

		if ( Role < ROLE_Authority ) // then save this move and replicate it
			ReplicateMove(DeltaTime, NewAccel, DODGE_None, currentRot);
		else
			ProcessMove(DeltaTime, NewAccel, DODGE_None, currentRot);
		bPressedJump = false;
	}

	function PlayTakeHit(float tweentime, vector HitLoc, int Damage)
	{
		if ( IsAnimating() )
		{
			Enable('AnimEnd');
			Global.PlayTakeHit(tweentime, HitLoc, Damage);
		}
	}
	
	function PlayDying(name DamageType, vector HitLocation)
	{
		BaseEyeHeight = Default.BaseEyeHeight;
	}
	
	function ChangedWeapon()
	{
		Weapon = None;
		Inventory.ChangedWeapon();
	}

	function EndState()
	{
		bJustFired = false;
	}

	function Vector SitPosition(Seat seatActor, int slot)
	{
		local float newAssHeight;

		newAssHeight = GetDefaultCollisionHeight() + -26;
		newAssHeight = -(CollisionHeight - newAssHeight);

		return ((seatActor.sitPoint[slot]>>Rotator(RotS2))+seatActor.Location+(vect(0,0,-1)*newAssHeight));
	}


	function BeginState()
	{
		local rotator NewRot;
		local vector newPos;

		bStasis=False;

		EnableCollision(False);

		if ( carriedDecoration != None )
			DropDecoration();


		newPos = SitPosition(SeatActor, SeatSlot);
		Acceleration = vect(0,0,0);
		Velocity = vect(0,0,0);
		SetBase(SeatActor);
		bSitting = true;

		SetLocation(newPos);

		NewRot = (Rotator(RotS2)+Rot(0, -16384, 0));
		NewRot.Pitch = 0;
		SetRotation(NewRot);
		DesiredRotation = NewRot;
		SetRotation(NewRot);

		bIsCrouching = false;
		bPressedJump = false;
		bJustFired = false;
		bRisingFromS = false;
		Disable('AnimEnd');
		PlaySittingDown();
	}
}


exec function seatTest()
{
	ClientMessage(RotS2);
}



defaultproperties
{
    bJumpOnce=False
     Energy=0
     bHasLight=True
     NoRoomToLift=""
     translucencyLevel=2
     CaffCount=0
     bCaff=False
     NerveCount=0
     StunCount=0
     bNerve=False
     bStunnage=False
     bKickLand=False
     bHeelLand=False
     bShoveLand=False
//     bTrick=False
     bSkate=False
     BroadcastTime=3
     bBud=False
     bGuinness=False
     bJack=False
     bMatr=False
     SkillPointsTotal=0
     SkillPointsAvail=0
     thiefmission=1
     bAMaster=False
     bBookDemo=False
     bBasicPick=False
     bAdvPick=False
     bBasicTool=False
     bAdvTool=False
     RifleNumber=0
     LAMNumber=0
     PistolNumber=0
     LTNumber=0
     HeavyNumber=0
     bInFight=True
     TalkRadius=650
     skillage=False
     medpack=1
     medkit=1
     clubmission=1
     colamission=1
     arenamission=1
     killmission=1
     paxxmission=1
     spymission=1
     contmission=1
     beermission=1
     bDoctor=False
     bMechanic=False
     numHealed=0
     CarcassType=Class'Contender.MMRPGCarcass'
     bAlwaysRun=True
     EnergyDepleted="You have used all your energy!"
}
