//------------------------------------------------------------
//Pickup class for Ricochet Burst
//------------------------------------------------------------
Actor DiscSpherePickup : CustomInventory 12100
{
	//Doom Builder things category
	//$Category Lightscape Pickups
	
	//Propreties
	Radius 24
	Height 48
	Inventory.Amount 1
	Inventory.MaxAmount 1
	Inventory.PickupMessage "Disc Sphere - Fires a barrage of bouncing projectiles"
	Inventory.PickupSound "Pickups/Sphere"
	Inventory.RespawnTics 700 // 20 seconds
	//Scale 0.5
	Tag "Disc Sphere"
	
	//Flags
	+FLOATBOB
	+BRIGHT
	+SERVERNETID
	+INVBAR
	
	//States
	States
	{
	Spawn:
		SPHP A 1
		loop
	Pickup:
		TNT1 A 0 A_JumpIf(CallACS("CheckForSphere") == 0, "Success") //Only allow pickup if no other active items are held.
		fail
	Success:
		TNT1 A 0 ACS_NamedExecuteAlways("HoldingSphere", 0, 0)
		TNT1 A 0 A_GiveInventory("DiscSphereReady", 1)
		stop
	}
}

//------------------------------------------------------------
//Inventory class for Ricochet Burst
//------------------------------------------------------------
Actor DiscSphereReady : Inventory
{
	//Propreties
	Inventory.Amount 1
	Inventory.MaxAmount 1
	Tag "Disc Sphere"
	
	//Flags
	+SERVERNETID
}


Actor DiscSphereInUse : Inventory
{
	//Propreties
	Inventory.Amount 1
	Inventory.MaxAmount 1
	
	//Flags
	+SERVERNETID
}

//------------------------------------------------------------
//Held sphere in front of player
//------------------------------------------------------------
Actor DiscSphereReadyFX : SphereReadyBase
{
	//States
	States
	{
	Spawn:
		SPHR A 1 nodelay A_Warp(AAPTR_TARGET, 32.0, -24.0, 20.0, 0, WARPF_NOCHECKPOSITION|WARPF_INTERPOLATE)
		loop
	Using:
		TNT1 A 0 A_Warp(AAPTR_TARGET, 32.0 + frandom(-4.0, 4.0), -24.0 + frandom(-4.0, 4.0), 20.0 + frandom(-4.0, 4.0), 0, WARPF_NOCHECKPOSITION)
		SPHR A 1 A_SetScale(scalex + 0.05, scaley + 0.05)
		loop
	Death:
		TNT1 A 0 A_SetScale(scalex * 0.8 , scaley * 0.8)
		SPHR A 1 A_FadeOut(0.05)
		loop
	}
}

//------------------------------------------------------------
//Fires one richochet burst upon entering inventory
//------------------------------------------------------------
Actor DiscSphereFire : CustomInventory
{
	//Flags
	+INVENTORY.AUTOACTIVATE
	+SERVERNETID
	
	//States
	States
	{
	Pickup:
	Use:
		TNT1 A 0 A_SpawnItemEX("BlueLightShoot", 0, 0, 0, 0, 0, 0, 0, SXF_SKIPOWNER)
		TNT1 A 0 A_FireCustomMissile("DiscSphereProjectile", 0.0, false, -8.0, -2.0, FPF_SKIPOWNER)
		TNT1 A 35
		stop
	}
}

//------------------------------------------------------------
//Ricochet Burst projectile
//------------------------------------------------------------
ACTOR DiscSphereProjectile
{
	//Properties
	Radius 12
	Height 6
	Speed 64
	XScale 1.2
	YScale 0.2
	Damage (0)
	Projectile
	BounceCount 2
	RenderStyle Add
	BounceType Hexen
	SeeSound "Items/DiscSphere/Fire"
	BounceSound "Items/DiscSphere/Bounce"
	Obituary "%k > \chDisc Sphere\c- > %o"
	
	//Flags
	+BOUNCEONFLOORS
	+BOUNCEONCEILINGS
	+BOUNCEONWALLS
	+BRIGHT
	+SEEKERMISSILE //For hit sounds
	
	//Constants
	const int RADIUS_OUTER = 160;
	
	//States
	States
	{
	Spawn:
		BGRN A 1 A_SpawnItemEx("DiscSphereProjectileTrail",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION)
		loop
	Bounce:
		TNT1 AAAAAAAAAAAAAAAA 0 A_SpawnItemEx("DiscSphereProjectileImpactFX", 0, 0, 0, frandom(-16.0, 16.0), frandom(-16.0, 16.0), frandom(-16.0, 16.0), 0, SXF_NOCHECKPOSITION)
		Goto Spawn
	XDeath:
		TNT1 A 0 A_SpawnItemEx("ExplosionSpawner")
		TNT1 AAAAAAAAAAAAAAAA 0 A_SpawnItemEx("DiscSphereProjectileImpactFX", 0, 0, 0, frandom(-16.0, 16.0), frandom(-16.0, 16.0), frandom(-16.0, 16.0), 0, SXF_NOCHECKPOSITION)
		TNT1 A 0 A_Quake(2, 8, 0, 384)
		TNT1 A 0 A_Explode(10, RADIUS_OUTER, XF_HURTSOURCE)
		TNT1 A 0 A_Explode(8, RADIUS_OUTER, XF_HURTSOURCE, true, RADIUS_OUTER)
		TNT1 A 0 A_GiveToTarget("HitSoundLarge", 1)
		Goto FinishDeath
	Death:
		TNT1 A 0 A_SpawnItemEx("ExplosionSpawner")
		TNT1 AAAAAAAAAAAAAAAA 0 A_SpawnItemEx("DiscSphereProjectileImpactFX", 0, 0, 0, frandom(-16.0, 16.0), frandom(-16.0, 16.0), frandom(-16.0, 16.0), 0, SXF_NOCHECKPOSITION)
		TNT1 A 0 A_Quake(2, 8, 0, 384)
		TNT1 A 0 A_Explode(10, RADIUS_OUTER, XF_HURTSOURCE)
		TNT1 A 0 A_Explode(8, RADIUS_OUTER, XF_HURTSOURCE, true, RADIUS_OUTER)
		TNT1 A 0 A_SeekerMissile(360, 360, SMF_LOOK, 256, RADIUS_OUTER / 128)
		TNT1 A 0 A_RearrangePointers(AAPTR_DEFAULT, AAPTR_TRACER)
		TNT1 A 0 A_JumpIfMasterCloser(RADIUS_OUTER - radius, "HitSoft")
		Goto FinishDeath
	HitSoft:
		TNT1 A 0 A_GiveToTarget("HitSoundSmall", 1)
		Goto FinishDeath
	FinishDeath:
		TNT1 A 105 //Required for unlagged
		stop
	}
}

ACTOR DiscSphereProjectileTrail : LSParticleBase
{
	XScale 0.3
	YScale 0.05
	States
	{
	Spawn:
		BRNG A 4
	Spawn1:
		BRNG A 1 A_FadeOut(0.05)
		Loop
	}
}
Actor DiscSphereProjectileImpactFX : LSParticleBase
{
	States
	{
		Spawn:
		TNT1 A 0 A_SetScale(scalex - 0.05, scaley - 0.05)
		BSPK A 1 A_FadeOut(0.05)
		loop
	}
}
