/*
==SHARPSHOOTER RIVET GUN==

The only weapon in Arti's standard loadout that hasn't
been made or modified by himself, the Sharpshooter was
a gift from the Foreman brothers, Allen and Phillip, as 
a token of friendship and a way of saying thanks for
helping the two construction workers out so many times.

Based on the Foreman's own rivet guns, the Sharpshooter's
been modified to fire several rivets out in a single
blast, making it great for bigger targets or crowd 
control. After hitting the ground, the rivets unfold
into sharp caltrops, useful for area denial, and the
weapon is capable of taking it further with the altfire,
sending out a signal to any deployed rivets to explode into 
bouncing shrapnel!

*/


actor SharpShooter : weapon
{
	weapon.slotnumber 3
	Weapon.AmmoUse 2
	weapon.bobstyle smooth
	weapon.bobrangex 0.1
	weapon.bobrangey 0.6
	weapon.bobspeed 2
	Weapon.AmmoType "Shell"
	Inventory.RestrictedTo "Artificer"
	Inventory.PickupMessage "You got the Sharp Shooter!"
	+NOAUTOAIM
	Tag "Sharp Shooter"
	states
	{
	spawn:
		SSPU A -1
		stop
	select:
		TNT1 A 0
		TNT1 A 0 a_playsound ("Sharpshooter/draw",0)
	draw:	
		TNT1 A 0
		SSHO AAAA 0 A_Raise
		SSHO A 1 A_Raise
		loop
	deselect:
		TNT1 A 0
		TNT1 A 0 a_jumpifhealthlower (1, "deadlower")
		TNT1 A 0 a_playsound ("sharpshooter/holster",0)
	holster:
		TNT1 A 0
		SSHO A 1 a_lower
		TNT1 A 0 a_takeinventory ("secretaction", 99)
		TNT1 AA 0 a_lower
		loop
	deadlower:
		TNT1 A 0
		TNT1 A 0
		TNT1 AAAAAAAAAAAAA 0 a_lower
		TNT1 A 1 a_lower
		wait		
	Ready:
		SSHO A 1 A_WeaponReady
		wait
	Fire:
		SSHO A 3
		PSPM AAAAAAAAAAAAAA 0 A_FireCustomMissile("sharppellet", Frandom(-6,7),0,0,0,0,Frandom(-4,4))
		PSPM A 0 A_FireCustomMissile("sharppellet", Frandom(-3,4),1,0,0,0,Frandom(-4,4))
		TNT1 A 0 a_playsound ("sharpshooter/fire",0)
		TNT1 A 0 A_Quake(3, 8, 0, 32)
		SSHO B 2 bright
		SSHO CDE 1 bright
		SSHO FG 1 
		SSHO G 2
		SSHO H 1
		SSHO A 2
		TNT1 A 0 a_jumpifinventory ("shell",2, "Loadshells")
		goto ready
	altfire:
		SSHO A 2
		TNT1 A 0 a_playsound ("sharpshooter/load",CHAN_WEAPON)
		SSDT ABCDE 1
		PSPM A 0 A_giveinventory ("rivetdet",1)
		SSDT FGHIJ 2
		PSPM A 0 A_takeinventory ("rivetdet",1)
		SSDT KL 1
		SSHO A 1
		goto ready
	loadshells:
		TNT1 A 0
		TNT1 A 0 a_playsound ("sharpshooter/open",0)
		SSHO IJKLMN 1
		SSHO N 2
		TNT1 A 0 a_playsound ("sharpshooter/eject",CHAN_WEAPON)
		SSHO OPQR 1
		TNT1 A 0 A_SpawnItemEx("PistolClipDrop",10,15,20)
		SSHO S 2
		SSHO TUVW 2
		TNT1 A 0 a_playsound ("sharpshooter/close",CHAN_WEAPON)
		SSHO XYY 1
		TNT1 A 0 offset (-2,33)
		SSHO Y 2
		TNT1 A 0 offset (-1,32)
		SSHO Z 2 a_weaponready (WRF_NOFIRE|WRF_NOSWITCH)
		SSH1 AB 3
		SSHO LIA 2
		goto ready
	}
}

ACTOR Sharppellet : FastProjectile
{
	Speed 55
	Radius 7
	Height 8
	PROJECTILE
	damage 4
	Scale 0.25
	DeathSound "RivetImpact"
	MissileType "RivetFlyRing"
	decal CADecal
	MissileHeight 8
	+thruspecies
	Species "player"
    +BLOODSPLATTER
	States
	{
	Spawn:
		BBLT A 1 Bright
		Loop
	Death:
		TNT1 A 0
		TNT1 A 0 A_SetScale(0.3)
		TNT1 A 0 A_SpawnItemEx("RivetBoltReboundFX",0,0,3,random(-2,2),random(-2,2),random(3,9),random(0,359),32)
		TNT1 A 0 A_SetTranslucent(0.8)
		RIVP A 2 BRIGHT
		RIVP BCDE 1 BRIGHT
		Stop
	}
}

ACTOR RivetFlyRing //Rivet projectile flight effect.
{
	+NOINTERACTION
	+NOCLIP
    +BRIGHT
	+clientsideonly
	Radius 1
	Height 1
	Renderstyle Add
	Alpha 0.06
	Scale 0.30
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 2
		RIVF AAA 1
		RIVF A 1 A_SetScale(0.25)
		RIVF A 1 A_SetScale(0.20)
		RIVF A 1 A_SetScale(0.15)
		Stop
	}
}

ACTOR RivetBoltReboundFX
{
	Radius 1
	Height 1
	Speed 15
	PROJECTILE
	-NOGRAVITY
	+THRUACTORS
	Gravity 0.6
	Scale 0.25
	BounceType Doom
	BounceFactor 0.4
	BounceCount 3
	BounceSound "RivetRebound"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_Jump(255,"Var1","Var2")
		TNT1 A 1
		Loop 
	Var1: //Horizontal
		RBLT ABCDEFGH 1
		Loop
	Var2: //Vertical
		VRLT ABCDEFGH 1
		Loop
	Death:
		BBLT A 38
		BBLT A 2 a_playsound ("sharpshooter/caltrop",0,0.60,0,1.25)
		TNT1 A 0 A_SpawnItemEx("CaltropSpawner",0,0,3,random(-1,1),random(-1,1),random(2,4),random(0,359),SXF_NOCHECKPOSITION)
		TNT1 A 0 a_spawnitemex ("Caltropflash",0,0,5)
		stop
	}
}

actor caltropflash
{
	+NOINTERACTION
	+NOCLIP
    +BRIGHT
	+clientsideonly
	Radius 1
	Height 1
	Scale 0.80
	states
	{
	spawn:
		CLSD FGHI 2
		stop
	}
}


actor caltropblast
{
	+NOINTERACTION
	+NOCLIP
    +BRIGHT
	+clientsideonly
	Radius 1
	Height 1
	Scale 1
	states
	{
	spawn:
		CLSD ABCDE 2
		stop
	}
}


actor caltropspawner : RivetBoltReboundFX
{
	bouncecount 1
	+bright
	scale 0.35
	gravity 0.80
	states
	{
	spawn:
		CALT A 1
		loop
	death:
		TNT1 A 0
		TNT1 A 1 A_SpawnItemEx("Rivetcaltrop",0,0,2,0,0,0,0,SXF_NOCHECKPOSITION)
		stop
	}
}

actor Rivetcaltrop
{
	PROJECTILE
	+notimefreeze
	+bright
	+bloodsplatter
	+floorhugger
	-nogravity
	damage (10)
	speed 0
	+thruspecies
	species "Player"
	+FORCEXYBILLBOARD
	radius 12
	height 16
	scale 0.50
	gravity 0.8
	Projectilekickback 100

	
	reactiontime 900
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 1
		CALT A 1
		goto waiting
	waiting:
		TNT1 A 0 a_jumpifintargetinventory ("RivetDet",1,"CaltropBlast")
		CALT A 1 a_jumpifintargetinventory ("RivetDet",1,"CaltropBlast")
		TNT1 A 0 a_jumpifintargetinventory ("RivetDet",1,"CaltropBlast")
		TNT1 A 0 a_countdown
		loop
	fading:
		TNT1 A 0 a_jumpifintargetinventory ("RivetDet",1,"CaltropBlast")
		CALT A 10
		TNT1 A 0 a_jumpifintargetinventory ("RivetDet",1,"CaltropBlast")
		CALT A 1 a_fadeout (0.10)
		loop
	death:
		TNT1 A 1
		stop
	xdeath:
		TNT1 A 0
		TNT1 A 0
		NLPJ B 0 A_PlaySound("Weapons/NailHit")
		NLPJ BCDEFG 2
		stop
	Caltropblast:
		TNT1 A 0
		TNT1 A 0 a_spawnitemex ("caltropblast",0,0,4)
		TNT1 A 0 a_playsound ("sharpshooter/caltropexplode",0)
		TNT1 AA 0 a_spawnitemex ("MiniCaltrop",0,0,frandom(-15,18),random(-15,24),random(-8,8),frandom(5,10)) 
		TNT1 AAA 0 a_spawnitemex ("Minicaltrop",0,0,frandom(-18,20),random(-24,18),random(-15,15),frandom(7,11)) 
		TNT1 A 1
		stop
	}
}

actor minicaltrop : Rivetcaltrop
{
	PROJECTILE
	+notimefreeze
	+bright
	+bloodsplatter
	-floorhugger
	-nogravity
	damage (6)
	speed 10
	+thruspecies
	+doombounce
	species "Player"
	+FORCEXYBILLBOARD
	radius 12
	height 16
	scale 0.35
	gravity 0.9
	bouncefactor 1.2
	bouncecount 10
	
	states
	{
	spawn:
		CALT A 350
		stop
	death:
		TNT1 A 1
		stop
	xdeath:
		TNT1 A 0
		TNT1 A 0
		NLPJ B 0 A_PlaySound("Weapons/NailHit",0,0.60,0,1.4)
		NLPJ BCDEFG 2
		stop
	}
}

actor rivetdet : inventory
{inventory.maxamount 1}
