//=============================================================================
// 
//=============================================================================
class MMRPGBuyButton extends DeusExDecoration;

var(loser) int CreditCost;
var(loser) class<Inventory> SpawnClass;
var int PandaLagga;

Function Tick(Float DeltaTime)
{
	if(PandaLagga > 0)
	{
		PandaLagga -= 1;
	}

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

	Super.Tick(DeltaTime);
		
}

function Frob(Actor Frobber, Inventory frobWith)
{
	local Inventory hmm;
	local KeyDummy hmm2;

	local Hax fananny;
	local int HaxCount;

	local Inventory Test;
	local RPGSpawn SpawnObject;
	local MMRPGCreditCard Inv;
	local DeusExPlayer Player;
	Player = DeusExPlayer(Frobber);


	If(PandaLagga > 0)
	{
		//PandaLagga = 30;
		//Player.Clientmessage("|p2-Please Wait-");
		//_MMRPGPlayer(Frobber).PandaLagga = 30;
		return;
	}

	if(_MMRPGPlayer(Frobber).PandaLagga > 0)
	{
		Player.Clientmessage("|p2-Please Wait-");
		_MMRPGPlayer(Frobber).PandaLagga = 30;
		return;
	}

	if(_MMRPGPlayer(Frobber).PandaLagga == 0)
	{

	If(PandaLagga == 0)
	{
		PandaLagga = 30;
		_MMRPGPlayer(Frobber).PandaLagga = 30;

	//Super.Frob(Frobber, frobwith);
		foreach AllActors(class'MMRPGCreditCard', Inv)
		{
			if (Inv.Owner == Player)
			{
				if (Inv.CreditAmount >= CreditCost)
				{
					foreach AllActors(class'Inventory', Test)
					{
						If(Test.Class == SpawnClass)
						{
							If(Test.Owner == Player)
							{
								if(Test.IsA('FoodMMRPG'))
								{
									if(FoodMMRPG(Test).NumCopies >= FoodMMRPG(Test).maxCopies)
									{
										Player.Clientmessage("You already have enough of these!");
										return;
									}

									Inv.CreditAmount -= CreditCost;
									Player.ClientMessage(""$CreditCost$" credits deducted from your credit card.");
									FoodMMRPG(Test).NumCopies += 1;
									Player.UpdateBeltText(FoodMMRPG(Test));
									return;
								}
								if(Test.IsA('HaxAmmo20mm'))
								{
									HaxCount = 0;
									ForEach AllActors(Class'Hax', fananny)
									{
										if(fananny.Owner == Player)
										{
											HaxCount = 1;
										}
									}
									If(HaxCount ==0)
									{
										Player.ClientMessage("You don't have a ZHL-U1953 Automatic Rifle");
										return;
									}
								}
										
								if(Test.IsA('WeaponGasGrenade'))
								{
									if(WeaponGasGrenade(Test).AmmoType.AmmoAmount >= WeaponGasGrenade(Test).AmmoType.MaxAmmo)
									{
										Player.Clientmessage("You already have enough of these!");
										return;
									}

									Inv.CreditAmount -= CreditCost;
									Player.ClientMessage(""$CreditCost$" credits deducted from your credit card.");
									WeaponGasGrenade(Test).AmmoType.AmmoAmount += 1;
									Player.UpdateBeltText(WeaponGasGrenade(Test));
									return;
								}
								Player.Clientmessage("You already have one!");
								return;
							}
						}
					}

					foreach AllActors(class'KeyDummy', hmm2)
					{
						//if (Player.FindInventorySlot(hmm2, False) == False)
						if (Player.HandleItemPickup(hmm2, True) == False)
						{
							//Player.ClientMessage("You do not have enough room");
							return;
						}
					}


					foreach AllActors(class'KeyDummy', hmm2)
					{
						//if (Player.FindInventorySlot(hmm2, False) == True)
						if (Player.HandleItemPickup(hmm2, True) == True)
						{
							Inv.CreditAmount -= CreditCost;
							Player.ClientMessage(""$CreditCost$" credits deducted from your credit card.");

							//Da new system.

							_MMRPGPlayer(Player).SpawnItemz(SpawnClass);


							//foreach AllActors(class'RPGSpawn', Spawnobject)
							//{
							//	SpawnObject.SpawnClass = SpawnClass;
							//	SpawnObject.Player = Player;
							//	SpawnObject.SpawnIt();
							//}

							return;
						}
					}
				}
				else Player.ClientMessage("You do not have enough money");
			}
		}
	}
	}
}	


defaultproperties
{
     bInvincible=True
     ItemName="Purchase"
     bPushable=False
     Skin=Texture'DeusExDeco.Button1Tex0'
     Physics=PHYS_None
     RemoteRole=ROLE_SimulatedProxy
     Mesh=LodMesh'DeusExDeco.Button1'
     CollisionRadius=2.000000
     CollisionHeight=2.000000
     bCollideWorld=False
     bBlockActors=False
     Mass=5.000000
     Buoyancy=2.000000
}
