//class sgSpawnProt expands Inventory config(SiegeUltimateRC7UB01);
class sgSpawnProt expands TournamentPickup config(SiegeUltimateRC7UB01);

var int Count;
var config int SpawnProtSecs;
var Weapon WhosGun;
var int WhosAmmoCount;
var bool bActivated;

function Activate()
{
 if( Pawn(Owner) == None )
 {
  destroy();
  return;
 }
	if (SpawnProtSecs>0)
		Pawn(Owner).ClientMessage("Siege spawn protection on");
	WhosGun = Pawn(Owner).Weapon;
	if (WhosGun != None)
		WhosAmmoCount = Pawn(Owner).Weapon.AmmoType.AmmoAmount;
	bActivated=true;
	SetTimer(1, True);
}

simulated function Timer()
{
	if (Pawn(Owner)==None){ Destroy(); return; }
	if (!bActivated) return;
	Count++;
	if (WhosGun == None)
	{
	 WhosGun = Pawn(Owner).Weapon;
	 if( WhosGun != None && WhosGun.AmmoType != None )
	 {
	  WhosAmmoCount = Pawn(Owner).Weapon.AmmoType.AmmoAmount;
	 }
	}
	if (WhosGun != None)
	{
	 if ( Pawn(Owner).Weapon != WhosGun ||
	      Pawn(Owner).Weapon != None && Pawn(Owner).Weapon.AmmoType != None && Pawn(Owner).Weapon.AmmoType.AmmoAmount != WhosAmmoCount)
	 {
	  DisableProt();
	 }
	}
	if ((Count >= SpawnProtSecs) || ( Level.Game.bGameEnded || Pawn(Owner) == None || !Pawn(Owner).bIsPlayer ))
		DisableProt();
}

function DisableProt()
{
	if (SpawnProtSecs>0 && Pawn(Owner) != None)
		Pawn(Owner).ClientMessage("Siege spawn protection off");
	Destroy();
}

defaultproperties
{
    SpawnProtSecs=8
}
