/*

==THUNDERBUSS==
Out of all the guns that you wound up breaking during your
extended vacation in Hell, you were the most heartbroken
when the Super Shotgun fell apart. So imagine your joy
to see it restored as an electrified cannon!
The twin barrels fire the same steel pellets the 
Mourning Star fires, except now they're super charged 
with lightning, it feels and sounds like God slamming 
his car door every time you fire this thing. This gun
sounds so mean that it causes nearby demons to lose it for
a few moments, causing them to scatter and panic!
*/


actor Thunderbuss : Rend
{
	Weapon.SelectionOrder 700
	Weapon.AmmoType "SlayerGrit"
	Weapon.AmmoUse 10
	Inventory.RestrictedTo "DoomSlayer"
	-UNDROPPABLE
	-CHEATNOTWEAPON
	Tag "Thunderbuss"
	states
	{
	Spawn:
		SHOT A 1
		loop
	Select:
		TNT1 A 0
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGclose")
		TNT1 A 1 A_GunFlash ("GadgetStarter",GFF_NOEXTCHANGE)
	Draw:
		TNT1 AAAAAA 0 A_Raise
		TNT1 A 0 A_GiveInventory ("UsingSlayerGun",1)
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1, "BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_GiveInventory ("UsingSlayerGun",1)
		TNT1 A 1 A_Raise
		loop
	Ready:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory ("EjectedShells", 1, "NoPrimaryRaise")
		TNT1 A 0 A_JumpIfInventory ("FireThunderbuss", 1, "NoPrimaryRaise")
		TBS5 ABCDEF 1 A_WeaponReady
		TNT1 A 0 A_JumpIfInventory ("SlayerGrit",10,"HammerSlap")
		Goto EmptyBuss
	NoPrimaryRaise:
		TBS5 ABCDEF 1 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory ("SlayerGrit", 10, "EmptyBuss")
		TNT1 A 0 A_TakeInventory ("FireThunderbuss",99)
		TNT1 A 0 A_TakeInventory ("EjectedShells",99)
		Goto EmptyBuss
	EmptyBuss:
		TNT1 A 0 A_JumpIfInventory ("FireThunderbuss", 1, "EjectShells")
		TNT1 A 0 A_JumpIfInventory ("EjectedShells", 1, "OpenEmptyGun")
		TBS2 P 1 A_WeaponReady
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TNT1 A 0 A_JumpIfInventory ("FireThunderbuss", 1, "EjectShells")
		TNT1 A 0 A_JumpIfInventory ("EjectedShells", 1, "OpenEmptyGun")
		TNT1 A 0 A_JumpIfInventory ("SlayerGrit",10,"OpenEmptyGun")
		loop
		
	
	LoadedReady:
		TBS5 ABCD 1 A_WeaponReady
		TBS6 EF 1 A_WeaponReady
		goto RealReady
	Deselect:
		TNT1 A 0
		TNT1 A 0 A_JumpIfHealthLower (1, "DeadLower")
		TNT1 A 0 A_PlaySound ("DoomSlayer/holster",0)
		TBS5 FEDCBA 1
	Holster:
		TNT1 A 0
		TNT1 AAAAAAAA 0 A_Lower
		TNT1 A 1 A_Lower
		loop
	
	//Ugh, I hate doing this crap, but flash states are reserved for the casters.
	
	RealReady:
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TBS1 A 2 A_WeaponReady
		TNT1 A 0 A_Jump (15, "Zappy1","Zappy2","Zappy3","Zappy4","Zappy5")
		loop
	Zappy1:
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGIdleZap",0,0.10)
		TBS1 BC 2 A_WeaponReady
		Goto RealReady
	Zappy2:
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGIdleZap",0,0.10)
		TBS1 D 2 A_WeaponReady
		Goto RealReady
	Zappy3:
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGIdleZap",0,0.10)
		TBS1 EF 2 A_WeaponReady
		Goto RealReady
	Zappy4:
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGIdleZap",0,0.10)
		TBS1 EF 2 A_WeaponReady
		Goto RealReady
	Zappy5:
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGIdleZap",0,0.10)
		TBS1 GHI 2 A_WeaponReady
		Goto RealReady
		
		
	Fire:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory ("BarrelToken", 1, "BarrelToss")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelToss")
		TNT1 A 0 A_JumpIfInventory ("BFGArmed", 1, "FireBFG")
		TNT1 A 0 A_JumpIfInventory ("EjectedShells", 1, "NoPrimaryRaise")
		TNT1 A 0 A_JumpIfInventory ("FireThunderbuss", 1, "NoPrimaryRaise")
		TNT1 A 0 A_JumpIfInventory ("SlayerGrit",10,"realfire")
		TBS2 P 1 
		TNT1 A 0 A_PlaySound ("DoomSlayer/click",0)
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TBS2 P 1 offset (0,35)
		TBS2 P 1 offset (0,36)
		TBS2 P 1 offset (0,32)
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TBS2 P 3
		goto EmptyBuss
	RealFire:
		TNT1 A 0
		TBS2 A 1 
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGpin",0)
		TBS2 B 1
		TNT1 A 0 A_Jump (50,"AltWindup")
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGzap",CHAN_WEAPON)
		TBS2 DE 1
		Goto ThunderShot
	AltWindup:
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGzap",CHAN_WEAPON)
		TBS2 DF 1
		Goto ThunderShot
	ThunderShot:
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGzap",CHAN_WEAPON)
		TBS2 G 1
		TNT1 A 0 A_Quake(4, 13, 0, 10)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGfire",CHAN_WEAPON)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGfire",0,0.70)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGThunder",7,1,0,0.20)	
		TBS2 H 1 bright
		TNT1 A 0 A_FireBullets (0,0,1,0,"flickpuff",FBF_NOFLASH)
		TNT1 AAAAA 0 A_FireCustomMissile("ThunderPellet", Frandom(-5,5),0,0,5,0,Frandom(-5,5))
		TNT1 AAAAA 0 A_FireCustomMissile("ThunderPellet", Frandom(-6,7),0,0,5,0,Frandom(-4,4))
		TNT1 AAAAAAAAA 0 A_FireCustomMissile("ThunderPellet", Frandom(-8,8),0,0,5,0,Frandom(-3,3))
		TNT1 A 0 A_FireCustomMissile("ThunderPellet",0,1)
		TNT1 A 0 A_SetPitch (pitch-6)
		TNT1 A 0 A_ChangeVelocity(Cos(Pitch)*-15,0,Sin(Pitch)*10,1)
		TNT1 A 0 A_RadiusGive ("TerrorEffect",300,RGF_MONSTERS,1)
		TNT1 A 0 A_GiveInventory ("FireThunderbuss",1)
		TBS2 II 1 bright 
		TNT1 A 0 A_SetPitch (pitch-4,SPF_INTERPOLATE)
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TBS2 JKL 2
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TBS2 M 2 A_WeaponReady (WRF_NOPRIMARY)
		TBS2 NOP 1 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1,"BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TNT1 A 0 A_JumpIfInventory ("SlayerGrit",10,"EjectShells")
		TNT1 A 0 A_TakeInventory ("FireThunderbuss",99)
		goto EmptyBuss
	
	//Dev note: Because I'm going cross-eyed staring at all of the
	//A_Weaponready calls, I'm going to add some space between the lines
	//Where the Give/Take inventory stuff happens
	
	EjectShells:
		TBS3 A 1 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 B 2 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 CD 1 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 DE 1 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGIdleZap",0,0.30)
		TBS3 EF 2 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGIdleZap",0,0.30)
		TBS3 GGH 1 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGopen",0)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGIdleZap",0,0.70)
		TNT1 A 0 A_FireCustomMissile ("GMOTASlayerCasingSpawner3",0,0,-3,-2)

		TNT1 A 0 A_TakeInventory ("FireThunderbuss",99)
		TNT1 A 0 A_GiveInventory ("EjectedShells",1)

		TBS3 II 1 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 JK 2 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 LM 1 A_WeaponReady (WRF_NOPRIMARY)
		Goto LoadShells
	OpenEmptyGun:
		TBS3 A 1 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 B 2 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 CDD 1 A_WeaponReady (WRF_NOPRIMARY)
		TBS7 E 1 A_WeaponReady (WRF_NOPRIMARY)
		TBS7 EF 2 A_WeaponReady (WRF_NOPRIMARY)
		TBS7 GGH 1 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGopen",0)

		TNT1 A 0 A_TakeInventory ("FireThunderbuss",99)
		TNT1 A 0 A_GiveInventory ("EjectedShells",1)

		TBS7 II 1 A_WeaponReady (WRF_NOPRIMARY)
		TBS7 JK 2 A_WeaponReady (WRF_NOPRIMARY)
		TBS7 LM 1 A_WeaponReady (WRF_NOPRIMARY)
		Goto LoadShells
		
	LoadShells:
		TBS3 NO 2 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 P 1 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGload",0)

		TNT1 A 0 A_TakeInventory ("EjectedShells",99)

		TBS3 QR 1 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 S 2 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 4 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 TU 2 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 V 1 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGclose",0)		
		TBS3 WXWX 1 A_WeaponReady (WRF_NOPRIMARY)
		TBS3 YZ 2 A_WeaponReady (WRF_NOPRIMARY)
		Goto HammerSlap
	HammerSlap:
		TBS4 A 2 A_WeaponReady
		TBS4 BCD 1 A_WeaponReady
		TBS4 EE 1 A_WeaponReady
		TNT1 A 0 A_PlaySound ("DoomSlayer/SSGHammers",0)
		TBS4 FFGG 1 A_WeaponReady
		TBS4 HHII 1 A_WeaponReady
		TBS4 JKLM 2 A_WeaponReady
		goto RealReady
	Altfire:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory ("BarrelToken", 1, "BarrelCancel")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelCancel")
		TNT1 A 0 A_JumpIfInventory ("BFGArmed", 1, "HolsterBFG")
		TBS5 FEDCBA 1
		TNT1 A 0 A_PlaySound ("DoomSlayer/SwordUp")
		TNT1 A 0 A_Jump (256, "StartSlash")
		Goto AltfireEnd
	BarrelGet:
		TNT1 A 0
		TNT1 A 0 A_ClearReFire
		TBS5 FEDCBA 1
		TNT1 A 0 A_PlaySound ("DoomSlayer/holster",0)
		TNT1 A 0 a_takeinventory ("UsingSlayerGun",99)
		TNT1 A 2
		TNT1 A 0 A_Jump (256, "BarrelStart")
		Goto ToolEnd


	AltfireEnd:
		TNT1 A 0 A_PlaySound ("DoomSlayer/SwordDown")
		TNT1 A 4
		TNT1 A 0 A_JumpIfInventory ("FireThunderbuss", 1, "NoPrimaryRaise")
		TNT1 A 0 A_JumpIfInventory ("EjectedShells", 1, "NoPrimaryRaise")
		TNT1 A 0 A_JumpIfInventory ("SlayerGrit", 10, "LoadedReady")
		goto Ready
	ToolEnd:
		TNT1 A 1 A_ClearReFire
		TNT1 A 4
		goto RealReady
	GadgetStarter:
		TNT1 A 0
		TNT1 A 1
		TNT1 A 0 A_Jump (256, "GadgetReady")
		goto Ready
	}
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//========================
//======PROJECTILE========
//========================


actor ThunderPellet : macepellet
{
	-NOEXTREMEDEATH
	+EXTREMEDEATH
	damage (20)
	RenderStyle translucent
	decal DoomimpScorch
	Alpha 0.75
	scale 0.50
	states
	{
	Spawn:
		TBPL A 1 bright A_SpawnItemex("TeslaBlastTrail")
		TNT1 A 0 A_ChangeFlag ("EXTREMEDEATH",0)
		TNT1 A 0 A_ChangeFlag ("NOEXTREMEDEATH",1)
		TBPL B 1 bright A_SpawnItemex("TeslaBlastTrail")
		TBPL C 1 bright A_SpawnItemex("TeslaBlastTrail")
		TBPL A 1 bright A_SpawnItemex("TeslaBlastTrail")
		TBPL B 1 bright A_SpawnItemex("TeslaBlastTrail")
		TBPL C 1 bright A_SpawnItemex("TeslaBlastTrail")
		TNT1 A 0 A_Stop
		stop
	Death:
		TNT1 A 0
		TNT1 A 1 A_PlaySound ("DoomSlayer/SSGMiss",0,0.70,0,1.20)
		FAXE RS Random (2,4) bright
		TNT1 A 0 A_SetScale (0.20)
		FAXE TUVWX 1 bright
		stop
	Crash:
	Xdeath:
		TNT1 A 0
		TNT1 A 0
		TNT1 A 1 A_PlaySound ("DoomSlayer/SSGHit",0)
		TNT1 A 0 A_GiveInventory ("SlayerToolCharger",1, AAPTR_TARGET)
		FAXE R Random (1,3) bright
		FAXE STUVWX 2 bright
		stop		
	}
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//========================
//=======VISUALS==========
//========================

actor TeslaBlastTrail
{
	Radius 13
	Height 8
	Speed 20
	Damage 0
	scale 0.25
	Projectile
	+NOINTERACTION
	+RANDOMIZE
	+clientsideonly
	RenderStyle Add
	Alpha 0.75
	States
	{
	Spawn:
		TBPL ABC 3 bright
		goto death
	Death:
		TBPL ABC 4 bright A_FadeOut(0.5)
		loop
	}
}

actor SparkFX
{
	Radius 13
	Height 8
	Speed 40
	Damage 0
	scale 1
	Projectile
	+NOINTERACTION
	+RANDOMIZE
	+bright
	+clientsideonly
	RenderStyle Add
	reactiontime 2
	Alpha 0.75
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0
		TNT1 AAAAAA 0  A_SpawnItemEx("SparkFXTrail")
		GRLT ABC 1 A_ChangeVelocity (random(-15, 15), random(-15, 15), random(-15,15), CVF_REPLACE)
		TNT1 AAAAAAA 0  A_SpawnItemEx("SparkFXTrail")
		TNT1 A 0 a_countdown
		loop
	Death:
		TNT1 A 1
		stop
	}
}

actor SparkFXTrail
{
	speed 0
	scale 0.75
	alpha 0.50
	+NOINTERACTION
	+bright
	+nogravity
	+clientsideonly
	states
	{
	Spawn:
		GRLT ABC 1
		TNT1 A 0 a_fadeout (0.20)
		loop
	Death:
		TNT1 A 1
		stop
	}
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//========================
//========TOKENS==========
//========================

actor FireThunderbuss : inventory
{
	Inventory.RestrictedTo "DoomSlayer"
	inventory.maxamount 1
}

actor EjectedShells : inventory
{
	Inventory.RestrictedTo "DoomSlayer"
	inventory.maxamount 1
}

