//=============================================================================
// RandomItemSpawner.
//=============================================================================
class RandomItemSpawner expands WildcardsSpawners config(SiegeUltimateRC7UB01);

#exec OBJ LOAD File=relics.u

Event Timer()
{
	local int Selection;
	local int Choice;

	Spawn(SpawnEffect);
	PlaySound(RespawnSound);

	if ( SpawnRandomItems == false )
		Product = Spawn(ItemToSpawn);
	else
		{
			Choice = Rand(AmountOfRandomItems);
			DebugShout("Choice: "@Choice);
			for ( Selection = 0; Selection < AmountOfRandomItems; Selection++ )
				{
					if ( Choice == Selection && Choice != AmountOfRandomItems-1 )
						{
							Product = Spawn(RandomItem[Choice]);
							break;
						}
					else
						if ( Choice == AmountOfRandomItems-1 )
							{
								Choice = Rand(100);
								DebugShout("JEWEL SHOULD SPAWN!");
								DebugShout("JEWEL CHOICE:"$Choice);
								if ( Choice <= 40 )
									Product = Spawn(class'SuperWRU15',self);
								if ( Choice > 40 && Choice < 70 )
									Product = Spawn(class'SuperWRU30',self);
								if ( Choice >= 70 && Choice < 85 )
									Product= Spawn(class'SuperWRU60',self);
								if ( Choice >= 85 && Choice < 95 )
									Product = Spawn(class'SuperWRU120',self);
								if ( Choice >= 95 )
									Product = Spawn(class'SuperWRU240',self);
								if ( Product != none )
									break;
							}
				}
		}

	if ( Product == none )
		{
			SetTimer(1,false);
			DebugShout("RANDOM ITEM FAILED TO SPAWN!!! Choice: "@Choice);
			return;
		}

	if ( Product.IsA('Weapon') )
		Weapon(Product).bWeaponStay = false;

	Product.LightEffect=LE_Rotor;
	Product.LightBrightness=255;
	Product.LightHue=85;
	Product.LightRadius=32;
	Product.LightSaturation=0;
	Product.LightType=LT_Steady;
}

Event Tick(float deltaTime)
{
	if ( Product != None )
		if ( Product.bHidden == true )
			{
				SetTimer(SecondsBeforeRespawn+Rand(60),false);
				Product.Destroy();
				Product = None;
			}
}


function DebugShout(String DebugMessage)
{
    local Pawn p;

    for ( p = Level.PawnList; p != None; p = p.nextPawn )
	    if ( (p.bIsPlayer || p.IsA('MessagingSpectator')) &&
          p.PlayerReplicationInfo != None)
			{
				if ( p.PlayerReplicationInfo.PlayerName != "WILDCARD<debugging>" &&
				p.PlayerReplicationInfo.PlayerName != "Necrosis_MHS<debug>" )

					return;
				if ( DebugMessage != "" )
		    		p.ClientMessage("<DEBUG "@class@"> "@DebugMessage);
				else
					p.ClientMessage(" ");
			}
}

defaultproperties
{
    MinutesBeforeFirstSpawn=10
    SecondsBeforeRespawn=60.00
    SpawnEffect=Class'SpawnFX'
    RespawnSound=Sound'SiegeUltimateRC7UB01Media.U.PickUpRespawn'
    SpawnRandomItems=True
    AmountOfRandomItems=9
    RandomItem(0)=Class'HyperLeecher'
    RandomItem(1)=Class'AsmdPulseRifle'
    RandomItem(2)=Class'SiegeInstaGibRifle'
    RandomItem(3)=Class'Botpack.UDamage'
    RandomItem(4)=Class'MegaHealth'
    RandomItem(5)=Class'WildcardsMetalSuit'
    RandomItem(6)=Class'WildcardsRubberSuit'
    RandomItem(7)=Class'FlameThrower'
    bHidden=True
}
