class scavengerLoot : EventHandler
{
	override void WorldThingDied(WorldEvent e)
	{
		super.WorldThingDied(e);
		
		Actor a = e.Thing;
		if(!a) { Return; }
		
		if (a.bIsMonster)
		{
			if ((random(1, 100) <= lootChance) || (a.bBoss))
			{
				int _sum = healthWeight + armorWeight + ammoWeight;
				int _rnd = random(1, _sum);
				string _spawn = "";
				
				if ((healthWeight) && (_rnd <= healthWeight))
				{
					_spawn = "healthLoot";
				}
				else
				{
					_rnd -= healthWeight;
					
					if ((armorWeight) && (_rnd <= armorWeight))
					{
						_spawn = "armorLoot";
					}
					else
					{
						_rnd -= armorWeight;
						
						if ((ammoWeight) && (_rnd <= ammoWeight))
						{
							PlayerInfo player   = players[consoleplayer];
							PlayerPawn mo      = player.mo;
							Class<Actor> _ammo;
							Array<Class<Actor> > ammos;
							Class<Actor> a1;
													
								for(Inventory item = mo.inv; item != null; item = item.inv)
								{
									if (item is "Weapon")
									{
										a1 = Weapon(item).ammotype1;
										
										if (a1)
										{
											ammos.Push(a1);
										}
									}
								}
							if (ammos.Size())
							{
								_ammo = ammos[random(0, ammos.Size() - 1)];
							}
						
						if (_ammo.GetClassName() == "Clip")
							_spawn = "scavengeClip";
							
						if (_ammo.GetClassName() == "Shell")
							_spawn = "scavengeShell";
							
						if (_ammo.GetClassName() == "RocketAmmo")
							_spawn = "scavengeRocketAmmo";
							
						if (_ammo.GetClassName() == "Cell")
							_spawn = "scavengeCell";
						}
					}
				}
				
				if (_spawn)
				{
					if (lootSound)
						a.A_StartSound("diablosound", CHAN_ITEM);
					
					a.A_SpawnItemEx(_spawn, 0, 0, 24, 0, 0, random(1,6), random(0,360));
				}
			}
		}
	}
}

class scavengeClip : Clip
{
	Default
	{
		Radius 20;
		Height 16;
		Inventory.PickupMessage "Scavenged some bullets.";
		Inventory.PickupSound "DIABPP";
		Inventory.Amount 40;
		+INVENTORY.AUTOACTIVATE;
	}
	
	override void BeginPlay()
	{
		switch(loot_AmmoAmount)
			{
				case 0:
					Amount = 10;
					break;
				case 1:
					Amount = 25;
					break;
				case 2:
					Amount = 35;
					break;
				case 3:
					Amount = 45;
					break;
				case 4:
					Amount = 60;
					break;
			}
		
		return;
	}
	
	States
	{
		Spawn:
			BAMO A 8;
			BAMO A 8 BRIGHT;
			Loop;
		Pickup:
			TNT1 A 0;
			Stop;
	}
}

class scavengeShell : Shell
{
	Default
	{
		Radius 20;
		Height 16;
		Inventory.PickupMessage "Scavenged some shells.";
		Inventory.PickupSound "DIABPP";
		Inventory.Amount 10;
		+INVENTORY.AUTOACTIVATE;
	}
	
	override void BeginPlay()
	{
		switch(loot_AmmoAmount)
			{
				case 0:
					Amount = 2;
					break;
				case 1:
					Amount = 4;
					break;
				case 2:
					Amount = 7;
					break;
				case 3:
					Amount = 10;
					break;
				case 4:
					Amount = 15;
					break;
			}
		
		return;
	}
	
	States
	{
		Spawn:
			SAMO A 8;
			SAMO A 8 BRIGHT;
			Loop;
		Pickup:
			TNT1 A 0;
			Stop;
	}
}

class scavengeRocketAmmo : RocketAmmo
{
	Default
	{
		Radius 20;
		Height 16;
		Inventory.PickupMessage "Scavenged some rockets.";
		Inventory.PickupSound "DIABPP";
		Inventory.Amount 5;
		+INVENTORY.AUTOACTIVATE;
	}
	
	override void BeginPlay()
	{
		switch(loot_AmmoAmount)
			{
				case 0:
					Amount = 1;
					break;
				case 1:
					Amount = 2;
					break;
				case 2:
					Amount = 3;
					break;
				case 3:
					Amount = 5;
					break;
				case 4:
					Amount = 7;
					break;
			}
		
		return;
	}
	
	States
	{
		Spawn:
			RAMO A 8;
			RAMO A 8 BRIGHT;
			Loop;
		Pickup:
			TNT1 A 0;
			Stop;
	}
}

class scavengeCell : Cell
{
	Default
	{
		Radius 20;
		Height 16;
		Inventory.PickupMessage "Scavenged some energy.";
		Inventory.PickupSound "DIABPP";
		Inventory.Amount 20;
		+INVENTORY.AUTOACTIVATE;
	}
	
	override void BeginPlay()
	{
		switch(loot_AmmoAmount)
			{
				case 0:
					Amount = 10;
					break;
				case 1:
					Amount = 15;
					break;
				case 2:
					Amount = 20;
					break;
				case 3:
					Amount = 25;
					break;
				case 4:
					Amount = 30;
					break;
			}
		
		return;
	}
	
	States
	{
		Spawn:
			CAMO A 8;
			CAMO A 8 BRIGHT;
			Loop;
		Pickup:
			TNT1 A 0;
			Stop;
	}
}

class healthLoot : Health
{
	Default
	{
		Radius 20;
		Height 16;
		Inventory.Amount 40;
		Inventory.MaxAmount 150;
		Inventory.PickupMessage "Scavenged some health.";
		Inventory.PickupSound "DIABPP";
		//-INVENTORY.ALWAYSPICKUP
	}
	
	override void BeginPlay()
	{
		Amount = loot_HealthRestored;
		MaxAmount = loot_HealthMax;
		return;
	}
	
	
	States
	{
		Spawn:
			HALO A 8;
			HALO A 8 BRIGHT;
			Loop;
	}
}

class armorLoot : BasicArmorBonus
{
	Default
	{
		Radius 20;
		Height 16;
		Inventory.PickupMessage "Scavenged some armor.";
		Inventory.PickupSound "DIABPP";
		Armor.SavePercent 33.335;
		Armor.SaveAmount 35;
		Armor.MaxSaveAmount 150;
		-INVENTORY.ALWAYSPICKUP
	}
	
	override void BeginPlay()
	{
		SaveAmount = loot_ArmorRestored;
		MaxSaveAmount = loot_ArmorMax;
		return;
	}
	
	States
	{
		Spawn:
			ARMO A 8;
			ARMO A 8 BRIGHT;
			Loop;
	}
}
