version "3.2"

/*	kd:
	
	This is an idea from older Guncaster versions. I don't remember why we did
	away with the weapon and ammo shop, but sure enough, you can optionally add
	it back in like this.
	
	*/

class Gc_WeaponShopHandler : EventHandler {
	protected Gc_WeaponShop	weapon_shop;
	
	override void NewGame () {
		weapon_shop = new("Gc_WeaponShop");
		
		if(weapon_shop) {
			weapon_shop.TurnaboutGnuFleaMarket();
			// https://www.youtube.com/watch?v=IP9PoBlFDp4
		}
	}
}

class Gc_WeaponShop : Thinker {
	protected Gcs_BaseShop			base_shop;
	protected Gcs_BaseShopPack		shops;
	protected Gcs_ShopList			shop_list;
	protected Gcs_BaseItemTypes		types;
	protected Gc_Shop_Inv			weapon_shop;
	
	void TurnaboutGnuFleamarket () {
		TheOneWhoActuallyCommittedTheCrimeIsYou();
		
		if(NoAlibiNoJusticeNoDreamNoHope()) {
			ItsTimeToPayForYourCrime();
			TAKETHAT();
			// (LAWYERSPLOSION)
		}
	}
	
	protected void TheOneWhoActuallyCommittedTheCrimeIsYou () {
		ChangeStatNum(stat_static);
	}
	
	protected bool NoAlibiNoJusticeNoDreamNoHope () {
		base_shop = Gcs_BaseShop.Find();
		
		if(base_shop) {
			shops			= base_shop.ShopPack();
			shop_list		= base_shop.ShopList();
			types			= base_shop.ItemTypes();
			weapon_shop	= new("Gc_Shop_Inv");
			
			if(weapon_shop) {
				return true;
			}
			
			return false;
		}
		
		return false;
	}
	
	protected void ItsTimeToPayForYourCrime () {
		shop_list.push(weapon_shop);
		
		let sandman_str		= "Sandman";
		let is_addon_loaded	= NULL != (class <Actor>)(sandman_str);
		
		weapon_shop.SetNameLang("weapon_shop");
		weapon_shop.AddForSale("Brimstone", types.weapon, 4000);
		weapon_shop.AddForSale("Strucker", types.weapon, 800);
		weapon_shop.AddForSale("Ironblast", types.weapon, 6000);
		weapon_shop.AddForSale("ShotgunAmmo", types.ammo, 200, 20);
		weapon_shop.AddForSale("Pulverizer", types.weapon, 2500);
		
		if(is_addon_loaded) {
			weapon_shop.AddSoft("Sandman", types.weapon, 8000);
		}
		
		weapon_shop.AddForSale("PulverizerAmmo", types.ammo, 200, 100);
		weapon_shop.AddForSale("Matriarch", types.weapon, 6000);
		weapon_shop.AddForSale("MatriarchAmmo", types.ammo, 400, 10);
		
		if(is_addon_loaded) {
			weapon_shop.AddSoft("MourningGlory", types.weapon, 9000);
			weapon_shop.AddSoft("MourningAmmo", types.ammo, 800, 5);
		}
		
		weapon_shop.AddForSale("TntAmmo", types.ammo, 800, 10);
		weapon_shop.AddForSale("Augur", types.weapon, 8000);
		weapon_shop.AddForSale("AugurAmmo", types.ammo, 800, 6);
		
		weapon_shop.AddForSale("OldDreadful", types.weapon, 15000);
		weapon_shop.AddForSale("TiberiumAmmo", types.ammo, 1000, 4);
		
		if(is_addon_loaded) {
			weapon_shop.AddSoft("GoldenEmperor", types.weapon, 15000);
		}
	}
	
	// kd: Gotta call this to notify the ACTIVE shop list something got added
	// (this isn't really in my control cuz gzd is lulzy about the order of
	// event handling).
	
	protected void TAKETHAT () {
		if(base_shop) {
			base_shop.ForceActiveShopListUpdate();
		}
	}
}
