#region Ammo
//$Color 6

class HBackpack : CustomInventory
{
	// The list of ammotypes NOT to raise the MaxAmount for.
	static const string GC_AmmoBlacklist[] = {
	"Dosh",			// Money, for which you already have a ridiculous wallet
	"Mana",			// Mana reserves, like a backpack's gonna do anything to that
	"EmperorAmmo"	// An addon weapon's magazine
	};
	
	bool SkipThisType;
	
	Default
	{
		//$Title Hammerspace Backpack
		Tag "Hammerspace Backpack";
		Inventory.PickupSound "Backpack/Pickup";
		Inventory.PickupMessage "Obtained a stylish hammerspace backpack!";
		+COUNTITEM
		+INVENTORY.ALWAYSPICKUP
	}
	States
	{
	Spawn:
		BPAK B -1;
		Loop;
	Pickup:
		TNT1 A 0 //ACS_NamedExecuteAlways("HammerspaceBackpack");
		{
			// Only augment ammo max amount if the CVar is set.
			if(GC_Hammerspace)
			{	
				// Just in case.
				invoker.SkipThisType = FALSE;
				// Search through the picker-upper's inventory.
				for(Inventory item = self.inv; item != null; item = item.inv)
				{
					// If it's of type Ammo...
					if(item is "Ammo")
					{
						// Cast to access Ammo methods.
						let thisammotype = Ammo(item);
						// Check for if this inventory item's type is blacklisted.
						for(int blacklist = 0; blacklist < invoker.GC_AmmoBlacklist.Size(); blacklist++)
						{
							if(thisammotype.GetClassName() == invoker.GC_AmmoBlacklist[blacklist])
							{
								// Blacklisted ammotype, skip it.
								invoker.SkipThisType = TRUE;
							}
						}
						
						// If it's not blacklisted, increase its max!
						if(!invoker.SkipThisType)
						{
							// Only increase max ammo with hammerspace if we're above backpack max.
							if(thisammotype.MaxAmount >= thisammotype.BackpackMaxAmount)
							{
								// Plus 10% of backpack max.
								thisammotype.MaxAmount += thisammotype.BackpackMaxAmount * 0.1;
							}
						}
						// Reset the bool on each ammotype run.
						invoker.SkipThisType = FALSE;
					}
				}
			}
			A_GiveInventory("Backpack", 1); // Always hand off a backpack.
		}
		Stop;
	}
}

class BackpackSpawner : actor
{
	Default
	{
		+NOINTERACTION
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay A_Jump(256,"Backpack","PhilosophersTome","ManaShieldTome");
	Backpack:
		TNT1 A 0 A_SpawnItemEx("HBackpack");
		Stop;
	PhilosophersTome:
		TNT1 A 0 A_JumpIf(random(1,13) >= 12, 1);
		Goto Backpack;
		TNT1 A 0 A_SpawnItemEx("PhilosophersTomeBringer");
		Stop;
	ManaShieldTome:
		TNT1 A 0 A_JumpIf(random(1,13) >= 12, 1);
		Goto Backpack;
		TNT1 A 0 A_SpawnItemEx("ManaShieldTomeBringer");
		Stop;
	}
}

#endregion
