#region Dosh
//$Color 3

class BaseBringer : Inventory
{
	int ItemToUnlock, MinWorth, MaxWorth;
	bool ItemIsShared;
	String ItemToBring, AltItemToBring, SharedItemMessage, SharedItemSound, MessageToA_Print, RequisiteItem;
	
	property ItemToUnlock: ItemToUnlock;
	property ItemIsShared: ItemIsShared;
	property SharedItemMessage: SharedItemMessage;
	property SharedItemSound: SharedItemSound;
	property ItemToBring: ItemToBring;
	property AltItemToBring: AltItemToBring;
	property MessageToA_Print: MessageToA_Print;
	property RequisiteItem: RequisiteItem;
	property ItemMinWorth: MinWorth;
	property ItemMaxWorth: MaxWorth;
	
	Default
	{
		// Amount is used here to denote how much money this bringer is worth.
		Inventory.Amount 0;
		// The item to unlock in Keks' shop.
		BaseBringer.ItemToUnlock -1;
		// The item to give when collected.
		BaseBringer.ItemToBring "";
		// Secondary item to give, if any - but only the collector.
		BaseBringer.AltItemToBring "";
		// Message that is shared between everyone if this item is shared.
		BaseBringer.SharedItemMessage "";
		// Sound played for everyone when this item is shared.
		BaseBringer.SharedItemSound "";
		// Message that is printed primarily for the collector.
		BaseBringer.MessageToA_Print "";
		// Property for chests - if the collector doesn't have the requisite
		// item for this item, put the artifact into a deferred list instead
		// of the main list.
		BaseBringer.RequisiteItem "";
		// Properties to save some code for randomized gold drops.
		// If they exist, use them to randomize the worth of the item.
		BaseBringer.ItemMinWorth 0;
		BaseBringer.ItemMaxWorth 0;
		// This bringer is never actually given, but make sure the player
		// can collect it anyway.
		Inventory.Amount 1;
		+DONTGIB; // Prevents crushing.
	}
	
	virtual void ToucherEffects(Actor toucher)
	{
		// A blank virtual used by the below TryPickup method
		// to provide various effects on inheriting powerups
		// at their discretion - things like screen flashes,
		// quakes, alternate items, grinning, ...
	}
	
	override void PostBeginPlay()
	{
		if(!Amount && (MinWorth || MaxWorth))
		{
			Amount = Random(MinWorth ? MinWorth : 0, MaxWorth ? MaxWorth : MinWorth ? MinWorth : 0);
		}
	}
	
	// Check first if the item we represent is maxed out, and if so check if the carrier
	// can't carry its amount in gold.
	override bool TryPickup (in out Actor toucher)
	{	
		bool ItemWasGiven;
		
		if (toucher && toucher.Inv)
		{
			if(ItemToBring)
			{
				let BroughtItemClass = Inventory(toucher.FindInventory(ItemToBring));
				// If we don't have the item, or the item's value isn't at maximum...
				if(!BroughtItemClass || BroughtItemClass.Amount < BroughtItemClass.MaxAmount || GetCvar("sv_unlimitedpickup"))
				{
					// If the item has a printable message, also present that
					// to the player. But only if they're not carrying this item.
					if(MessageToA_Print)
					{
						toucher.A_Print(MessageToA_Print);
					}
				
					// Give the inventory item, return success.
					toucher.GiveInventory(ItemToBring, 1);
					// If there's a second item to bring, it is given only to the collector.
					// Used for Powersuit behavior.
					if(AltItemToBring)
					{
						toucher.GiveInventory(AltItemToBring, 1);
					}
					// If the item is shared and the proper CVar is set, everyone receives it.
					if(ItemIsShared && GetCVar("GC_SpecialShare"))
					{
						for(int i = 0; i < MAXPLAYERS; i++)
						{
							if(playeringame[i] && !players[i].mo.FindInventory(ItemToBring))
							{
								players[i].mo.GiveInventory(ItemToBring, 1);
								if(SharedItemSound)
								{
									players[i].mo.A_PlaySound(SharedItemSound);
								}
								if(MessageToA_Print)
								{
									players[i].mo.A_Print(MessageToA_Print);
								}
								if(SharedItemMessage)
								{
									players[i].mo.A_Print(SharedItemMessage);
								}
							}
						}
					}
					// If it brings an item, it makes us happy.
					toucher.A_SetMugshotState("Grin");
					ItemWasGiven = TRUE;
				}
			}
			if(!ItemWasGiven && Amount > 0)
			{
				// Give money instead. Typical for dosh items that don't give artifacts.
				let TouchersGold = Inventory(toucher.FindInventory("Dosh"));
				// If we have enough room in our wallets...
				if(!TouchersGold || TouchersGold.Amount < TouchersGold.MaxAmount || GetCvar("sv_unlimitedpickup"))
				{
					// Gibe money plos.
					if(GetCVar("GC_MoneyShare"))
					{
						for(int i = 0; i < MAXPLAYERS; i++)
						{
							if(playeringame[i])
							{
								players[i].mo.GiveInventory("Dosh", self.Amount);
							}
						}
					}
					else
					{
						toucher.GiveInventory("Dosh", self.Amount);
					}
					ItemWasGiven = TRUE;
				}
			}
		}
		
		// If the above conditions succeed, play any custom effects
		// on the toucher.
		// If the above conditions fail but this CVar is true,
		// remove the picked up item anyway.
		if(ItemWasGiven || GetCVar("GC_HoardingHeadache"))
		{
			// Unlock the item if it was successfully picked up in
			// any way, if it hasn't been so far.
			UnlockSecretItem(ItemToBring);
			// Also grant any sub-effects of an item, if any.
			ToucherEffects(toucher);
			GoAwayAndDie();
			return true;
		}
		// Failed, do nothing.
		return false;
	}
	
	virtual void UnlockSecretItem (class <Inventory> inv_class) const {
		Gcs_BaseShop.Unlock(inv_class);
	}
}

class Dosh : Ammo
{
	Default
	{
		Height 24;
		Radius 36;
		Inventory.Amount 1;
		Inventory.MaxAmount 999999;
		Ammo.BackpackAmount 0;
		Ammo.BackpackMaxAmount 999999;
		Inventory.PickupMessage "";
		Inventory.PickupSound "";
		Inventory.PickupFlash 'None';
		Inventory.Icon "MONEY";
		Tag "\c[Gold]Gold\c-";
		+INVENTORY.NOSCREENFLASH
		+INVENTORY.IGNORESKILL
		+DONTGIB
		+CANBOUNCEWATER
	}
}

class Dosh1 : BaseBringer
{
	
	Default
	{
		//$Title Dosh (1)
		//$Sprite DOSHA0
		Height 24;
		Radius 36;
		Scale 1.5;
		Inventory.Amount 1;
		Inventory.PickupMessage "";
		Inventory.PickupSound "Money/Pickup";
		Tag "\c[Gold]Gold\c-";
		+INVENTORY.NOSCREENFLASH
		+INVENTORY.IGNORESKILL
		+DONTGIB
		+CANBOUNCEWATER
	}
	
	States
	{
	Spawn:
		TNT1 A 0 A_Jump(256,"SpriteA","SpriteB");
	SpriteA:
		DOSH A -1 Bright;
		Stop;
	SpriteB:
		DOSH B -1 Bright;
		Stop;
	}
}

class Dosh5 : Dosh1
{
	Default
	{
		//$Title Dosh (5)
		//$Sprite DOSHC0
		Inventory.Amount 5;
	}
	
	States
	{
	Spawn:
		DOSH C -1 Bright;
		Stop;
	}
}

class Dosh10 : Dosh1
{
	Default
	{
		//$Title Dosh (10)
		//$Sprite DOSHD0
		// Simulates the random worth of these items.
		BaseBringer.ItemMinWorth 10;
		BaseBringer.ItemMaxWorth 15;
	}
	
	States
	{
	Spawn:
		DOSH D -1 Bright;
		Stop;
	}
}

class Dosh25 : Dosh1
{
	Default
	{
		//$Title Dosh (25)
		//$Sprite CBAGA0
		BaseBringer.ItemMinWorth 25;
		BaseBringer.ItemMaxWorth 35;
	}

	States
	{
	Spawn:
		CBAG A -1 Bright;
		Stop;
	}
}

class Dosh35 : Dosh1
{
	Default
	{
		//$Title Dosh (35)
		//$Sprite DOSHE0
		BaseBringer.ItemMinWorth 35;
		BaseBringer.ItemMaxWorth 45;
	}

	States
	{
	Spawn:
		DOSH E -1 Bright;
		Stop;
	}
}

class GemPickup : Dosh1
{
	Default
	{
		Inventory.PickupSound "Gem/Pickup";
		Tag "Gemstone";
		-INVENTORY.NOSCREENFLASH;
		Scale 1.15;
	}
}

class Amber : GemPickup
{
	Default
	{
		//$Title Amber (50)
		//$Sprite GEMSA0
		Tag "\c[Yellow]Amber\c-";
		Inventory.Amount 50;
		Inventory.PickupMessage "Obtained an amber. (Worth 50 gold pieces)";
	}
	
	States
	{
	Spawn:
		GEMS A -1 Bright;
		Stop;
	}
}

class Ruby : GemPickup
{
	Default
	{
		//$Title Ruby (100)
		//$Sprite GEMSC0
		Tag "\c[Red]Ruby\c-";
		Inventory.Amount 100;
		Inventory.PickupMessage "Obtained a ruby. (Worth 100 gold pieces)";
	}
	
	States
	{
	Spawn:
		GEMS C -1 Bright;
		Stop;
	}
}

class Emerald : GemPickup
{
	Default
	{
		//$Title Emerald (250)
		//$Sprite GEMSB0
		Tag "\c[Green]Emerald\c-";
		Inventory.Amount 250;
		Inventory.PickupMessage "Obtained an emerald. (Worth 250 gold pieces)";
	}
	
	States
	{
	Spawn:
		GEMS B -1 Bright;
		Stop;
	}
}

class Sapphire : GemPickup
{
	Default
	{
		//$Title Sapphire (400)
		//$Sprite GEMSD0
		Tag "\c[Sapphire]Sapphire\c-";
		Inventory.Amount 400;
		Inventory.PickupMessage "Obtained a sapphire. (Worth 400 gold pieces!)";
	}
	
	States
	{
	Spawn:
		GEMS D -1 Bright;
		Stop;
	}
}

class Diamond : GemPickup
{
	Default
	{
		//$Title Diamond (20000)
		//$Sprite GEMSE0
		Tag "\c[White]Diamond\c-";
		Inventory.Amount 20000;
		Inventory.PickupMessage "Obtained a diamond! (Worth a whopping 20000 gold pieces!)";
	}
	States
	{
	Spawn:
		GEMS E -1 Bright;
		Stop;
	}
}

#endregion
