/*

==REIGN STORM==
A gilded chaingun was the last thing you were expecting
with these repairs. A little flashier than what you're used
to, but you can't argue with the results. This regal
rotary cannon fires golden bullets that tear demons 
up just as good as lead, and even better: Laying onto
the trigger causes the motor to ramp up, spewing out
even more royal pain!

This comes at a cost though, this monster monarch's 
motor slows you down when you start firing it, so
you should plan ahead before you pull the trigger.
*/


actor ReignStorm : Rend
{
	Weapon.SelectionOrder 800
	Weapon.AmmoType "SlayerGrit"
	Weapon.AmmoUse 1
	-UNDROPPABLE
	-CHEATNOTWEAPON
	Inventory.RestrictedTo "DoomSlayer"
	Tag "Reign Storm"
	states
	{
	Spawn:
		SHOT A 1
		loop
	Select:
		TNT1 A 0
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormUp",0,0.60)
		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 
		RNS1 AB 2 A_WeaponReady
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormHandle",0,0.90)
		RNS1 CDEFGHIJK 2 A_WeaponReady
		Goto RealReady
	RealReady:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory ("BarrelToken",1, "BarrelGet")
		TNT1 A 0 A_JumpIfInventory ("GoldenBarrelToken",1, "GoldenBarrelGet")
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS2 A 1 A_WeaponReady
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		loop
	Deselect:
		TNT1 A 0
		TNT1 A 0 A_JumpIfHealthLower (1, "DeadLower")
		TNT1 A 0 A_PlaySound ("doomslayer/holster",0)
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormDown",0,0.80)
		//TNT1 A 0 A_TakeInventory ("ReignSlower",99)
		RNS1 IHGFED 1
		RNS1 CBA 2
	Holster:
		TNT1 A 0
		TNT1 AAAAAAAA 0 A_Lower
		TNT1 A 1 A_Lower
		loop

	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")
		RNS2 A 1 A_JumpIfInventory ("SlayerGrit", 1, "ReignStartUp")
	DryFire:
		TNT1 A 0 A_StopSound (7)
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormWindDown",7)
		TNT1 A 0 A_JumpIfInventory ("ReignStack", 10, "FastDryFireStart")
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		RNS2 D 1 A_TakeInventory ("ReignStack",999)
		Goto DryFireLoop
	FastDryFireStart:
		TNT1 A 0 A_StopSound (7)
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormFastWindDown",7)
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		RNS2 D 1 A_TakeInventory ("ReignStack",999)
		Goto DryFireLoop
	
	DryFireLoop:
		TNT1 A 0 A_PlaySound ("DoomSlayer/click",0)
		RNS2 ABCD 1
		TNT1 A 0 A_JumpIfInventory ("SlayerGrit", 1, "ReignStartUp")
		TNT1 A 0 A_Refire ("DryFireLoop")
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		RNS2 BBCCCDD 2 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		RNS2 DD 2 A_WeaponReady
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormStop",0)		
		RNS2 A 2 A_WeaponReady
		Goto RealReady
		
	ReignStartUp:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory ("ReignStack", 10, "ReignStormStartUp")
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormStart",7)
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		RNS2 AAABBBCCDDABCD 1 
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		TNT1 A 0 A_GiveInventory ("ReignStart",1)
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormLoop",7,1,1)
		TNT1 A 0 A_Jump (256, "NormalShot1", "NormalShot2", "NormalShot3", "NormalShot4")
	
		
	NormalShot1:
		RNS3 A 1 
		TNT1 A 0 A_PlaySound("doomslayer/ReignStormShot", CHAN_WEAPON)
		TNT1 A 0 A_FireCustomMissile ("ReignBullet",FRandom(-1,1),1,0,0,0,Frandom(-1,1))
		TNT1 A 0 A_GiveInventory ("ReignStack",1)
		TNT1 A 0 A_ChangeVelocity(Cos(Pitch)*-0.20,0,Sin(Pitch)*1,1)
		TNT1 A 0 A_Quake(1, 2, 0, 10)
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		RNS2 BCD 1
		TNT1 A 0 A_JumpIfInventory ("ReignStart", 1, "AmmoCheck")
		TNT1 A 0 A_Refire ("AmmoCheck")
		Goto NormalWindDown
	NormalShot2:
		RNS4 A 1 
		TNT1 A 0 A_PlaySound("doomslayer/ReignStormShot", CHAN_WEAPON)
		TNT1 A 0 A_FireCustomMissile ("ReignBullet",FRandom(-1,1),1,0,0,0,Frandom(-1,1))
		TNT1 A 0 A_GiveInventory ("ReignStack",1)
		TNT1 A 0 A_ChangeVelocity(Cos(Pitch)*-0.20,0,Sin(Pitch)*1,1)
		TNT1 A 0 A_Quake(1, 2, 0, 10)
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		RNS2 BCD 1
		TNT1 A 0 A_JumpIfInventory ("ReignStart", 1, "AmmoCheck")
		TNT1 A 0 A_Refire ("AmmoCheck")
		Goto NormalWindDown
	NormalShot3:
		RNS5 A 1 
		TNT1 A 0 A_PlaySound("doomslayer/ReignStormShot", CHAN_WEAPON)
		TNT1 A 0 A_FireCustomMissile ("ReignBullet",FRandom(-1,1),1,0,0,0,Frandom(-1,1))
		TNT1 A 0 A_GiveInventory ("ReignStack",1)
		TNT1 A 0 A_ChangeVelocity(Cos(Pitch)*-0.20,0,Sin(Pitch)*1,1)
		TNT1 A 0 A_Quake(1, 2, 0, 10)
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		RNS2 BCD 1
		TNT1 A 0 A_JumpIfInventory ("ReignStart", 1, "AmmoCheck")
		TNT1 A 0 A_Refire ("AmmoCheck")
		Goto NormalWindDown
	NormalShot4:
		RNS6 A 1
		TNT1 A 0 A_PlaySound("doomslayer/ReignStormShot", CHAN_WEAPON)
		TNT1 A 0 A_FireCustomMissile ("ReignBullet",FRandom(-1,1),1,0,0,0,Frandom(-1,1))
		TNT1 A 0 A_GiveInventory ("ReignStack",1)
		TNT1 A 0 A_ChangeVelocity(Cos(Pitch)*-0.20,0,Sin(Pitch)*1,1)
		TNT1 A 0 A_Quake(1, 2, 0, 10)
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		RNS2 BCD 1
		TNT1 A 0 A_JumpIfInventory ("ReignStart", 1, "AmmoCheck")
		TNT1 A 0 A_Refire ("AmmoCheck")
		Goto NormalWindDown
	NormalWindDown:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory ("ReignStack",999)
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormWindDown",7)
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS2 BB 2 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS2 CCC 2 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		RNS2 DD 2 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS2 DD 2 A_WeaponReady
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormStop",0)		
		RNS2 A 2 A_WeaponReady
		Goto RealReady
	
	//Checking for ammo before it loops!
	AmmoCheck:
		TNT1 A 0 
		RNS2 A 1 A_JumpIfInventory ("SlayerGrit", 1, "ReignLoop")
		Goto Fire
	ReignLoop:
		TNT1 A 0 
		TNT1 A 0 A_JumpIfInventory ("ReignStack", 14, "ReignStormStartUp")
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		TNT1 A 0 A_Jump (256, "NormalShot1", "NormalShot2", "NormalShot3", "NormalShot4")
		RNS2 A 1
		Goto NormalWindDown
		
	
	ReignStormStartUp:
		TNT1 A 0
		
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormFastLoop",7,1,1)
		RNS7 D 1 A_FireCustomMissile ("ReignBullet",FRandom(-4,5),0,0,0,0,Frandom(-2,2))
		
	//High speed firing mode
	//breaking this up a little so it's easier to read 
	ReignStormLoop:
		//TNT1 A 0 A_GiveInventory ("ReignSlower",1)
		RNS7 A 1 A_FireCustomMissile ("ReignBullet",FRandom(-4,5),0,0,0,0,Frandom(-2,2))

		RNS7 B 1 A_FireCustomMissile ("ReignBullet",FRandom(-4,5),0,0,0,0,Frandom(-2,2))

		TNT1 A 0 A_ChangeVelocity(Cos(Pitch)*-0.35,0,Sin(Pitch)*1,1)
		TNT1 A 0 A_Quake(2, 2, 0, 10)
		TNT1 A 0 A_FireCustomMissile ("ReignBullet",FRandom(-2,3),0,0,0,0,Frandom(-1,1))
		
		RNS7 C 1 A_FireCustomMissile ("ReignBullet",FRandom(-3,3),0,0,0,0,Frandom(-3,4))

		RNS7 D 1 A_FireCustomMissile ("ReignBullet",FRandom(-3,3),1,0,0,0,Frandom(-3,4))

		TNT1 A 0 A_ChangeVelocity(Cos(Pitch)*-0.35,0,Sin(Pitch)*1,1)
		TNT1 A 0 A_Quake(2, 2, 0, 10)
		TNT1 A 0 A_Refire ("AmmoCheck")
		Goto FastWindDown
	FastWindDown:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory ("ReignStack",999)
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormFastWindDown",7)
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS8 ABCD 1 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS8 ABCCDD 1 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS2 AC 1 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		RNS2 DB 1 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS2 AC 1 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		RNS2 DB 1 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS2 ABCD 1 A_WeaponReady (WRF_NOBOB|WRF_NOPRIMARY)
		RNS2 ABCD 1 A_WeaponReady
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS2 ABCD 1 A_WeaponReady
		RNS2 ABCD 2 A_WeaponReady
		TNT1 A 0 A_JumpIfInventory ("BFGReady", 1, "DrawBFG")
		RNS2 ABCD 3 A_WeaponReady
		RNS2 ABBBCCCCDDDDD 2 A_WeaponReady 
		TNT1 A 0 A_PlaySound ("DoomSlayer/ReignStormStop",0)		
		RNS2 A 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")
		TNT1 A 0 A_StopSound (7)
		//TNT1 A 0 A_TakeInventory ("ReignSlower",99)
		RNS9 ABCDD 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_StopSound (7)
		TNT1 A 0 A_ClearReFire
		//TNT1 A 0 A_TakeInventory ("ReignSlower",99)
		RNS9 ABCDD 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 A_WeaponReady
		RNSY ABCDD 1
		goto RealReady
	ToolEnd:
		TNT1 A 1 A_ClearReFire
		TNT1 A 4 A_WeaponReady
		RNSY ABCDD 1
		goto RealReady

	}
}

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

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

actor ReignBullet
{
	+notimefreeze
	projectile
	+THRUSPECIES
	species "friendly"
	+FORCEXYBILLBOARD
	+Bloodsplatter
	+LOOKALLAROUND
	+bright
	height 12
	radius 5
	speed 90
	damage (15)
	scale 0.60
	Gravity 0.90
	decal bulletchip
	
	var int User_ReignDrop;	
	states
	{
	spawn:
		R8NB A 1
		TNT1 A 0 A_SpawnItemEx("ReignSparkle",frandom(-4,4),frandom(-4,4),frandom(-2,2),0,0,0,0,SXF_NOCHECKPOSITION,180)
		TNT1 A 0 A_SetUserVar("User_ReignDrop", User_ReignDrop+1)
		TNT1 A 0 A_JumpIf (User_ReignDrop >= 5, "ReignFall")
		loop
	ReignFall:
		R8NB A 1
		TNT1 A 0 A_ChangeFlag ("NOGRAVITY",0)
		TNT1 A 0 A_SpawnItemEx("ReignSparkle",frandom(-4,4),frandom(-4,4),frandom(-2,2),0,0,0,0,SXF_NOCHECKPOSITION,180)
	ReignFallLoop:
		R8NB A 1
		TNT1 A 0 A_SpawnItemEx("ReignSparkle",frandom(-4,4),frandom(-4,4),frandom(-2,2),0,0,0,0,SXF_NOCHECKPOSITION,180)
		Loop
	death:
		TNT1 A 0
		TNT1 A 0 A_PlaySound ("doomslayer/ReignStormMiss",0,0.80,0,1.20)
		TNT1 A 1 A_SpawnItemEx ("Bulletpuff")
		stop
	xdeath:
		TNT1 A 0
		TNT1 A 0 A_PlaySound ("doomslayer/ReignStormHit",0)
		TNT1 A 0 A_GiveInventory ("SlayerToolCharger",1, AAPTR_TARGET)
		TNT1 A 0 A_SetScale (0.80,0.80)
		GB1X ABCD 1 
		stop
	}
}


ACTOR ReignSparkle
{
	+NOBLOCKMAP
	+NOGRAVITY
	+ALLOWPARTICLES
	+RANDOMIZE
	+DONTBLAST
	+NOCLIP
	+NOTELEPORT
	Renderstyle add
	Alpha 0.70
	Scale 0.80
	+clientsideonly
	Mass 5
	States
	{
	Spawn:
		R8KL A 2 Bright 
		R8KL B 2 Bright 
		R8KL A 2 Bright 
		R8KL B 3 Bright 
		R8KL C 3 Bright 
		goto death
	Death:
		TNT1 A 1
		stop
	}
}

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

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

actor ReignStack : inventory
{inventory.maxamount 20}

actor ReignStart : powerup
{
	powerup.duration 16
}


actor ReignSlower : powerspeed
{
	Speed 0.50
	powerup.duration 10
	+PowerSpeed.NoTrail
}

