ACTOR PDShotgun : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "Shotgun"
        Weapon.Ammotype1 "ShotgunClip"
  Weapon.Ammotype2 "PDShotgunAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 9
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a Shotgun."
  Obituary  "%k's Shotgun relocated %o's brain to a wall."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKA4 R -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TK76 A 2 
    TK76 B 2
    TK76 C 2
    TK76 D 2
    TK76 EFGHIJ 1
    TK76 K -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TK76 K 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+7
	
		ReloadCheckIftryingtofireit:
		SSRG A 0 A_JumpIfInventory("ShotgunClip",9,4)
		SSRG A 0 A_JumpIfInventory("PDShotgunAmmo",1,"ReloadStart")
		SSRG A 0 A_JumpIfInventory("ShotgunClip",1,2)
		SSRG A 0
		Goto Ready+10
		SSRG A 0
		Goto Ready+10
	
	ReloadStart:
		TK78 LMNOPQRSTUVXYZ 1
		TK79 ABCDEFGHIJ 1
		Goto ReloadCheck
	ReloadCheck:
		SSRG A 0 A_JumpIfInventory("ShotgunClip",9,"ReloadEnd")
		SSRG A 0 A_JumpIfInventory("PDShotgunAmmo",1,"ReloadSystem")
		SSRG A 0
		Goto ReloadEnd
	ReloadSystem:
		TK79 KLMNOPQRS 1
		D3SR H 0 A_PlaySound("PerfectDark/Weapons/ShotgunShellLoad")
		TK79 TUVXYZ 1
		TK80 AB 1
		SSRG A 0 A_TakeInventory("PDShotgunAmmo",1)
		SSRG A 0 A_GiveInventory("ShotgunClip",1)
		SSRG A 0 A_JumpIfInventory("ShotgunClip",9,"ReloadEnd")
		SSRG A 0 A_JumpIfInventory("PDShotgunAmmo",1,1)
		Goto ReloadEnd
		TK80 C 2 
		Goto ReloadCheck
	ReloadEnd:
		TK80 DEFGHIJK 1
		D3SR H 0 A_PlaySound("PerfectDark/Weapons/ShotgunReloadDone")
		TK80 LMNOPQRSTUV 1
		Goto Ready+11
	
  Deselect:
    TK78 IJK 2
    TK08 A 0 A_Lower
    wait
  Select: 
    TK08 A 0 A_Raise 
    Loop  
  Fire: 
  KLBG A 0 A_JumpIfNoAmmo("ReloadCheckIftryingtofireit")
	TK76 L 2
 	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/Shotgun","Weapon")
    TK76 M 1 BRIGHT A_FireBullets (4,5,6,10,"BulletPuff",FBF_USEAMMO)
    TK76 NOPQR 1
	TK76 STUVXYZ 1
	TK77 ABCDEFGHIJKLMN 1
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDShellCasing", 20,cos(pitch)*4,sin(-pitch)*10+30, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
	TK77 OPQRSTUVXYZ 1
	TK78 ABCDE 1
	TK78 FGH 1 A_refire
    Goto Ready+11
	 AltFire: 
	 NULL A 0 A_JumpIfInventory("ShotgunClip",2,1)
	goto Ready+11
	TK80 X 2
 	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/ShotgunAlt","Weapon")
    TK80 Y 1 BRIGHT A_FireBullets (4,5,6,10,"BulletPuff",FBF_USEAMMO)
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDShellCasing", 30,cos(pitch)*12,sin(-pitch)*10+30, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
	TNT1 A 0 A_TakeInventory("ShotgunClip",1,TIF_NOTAKEINFINITE)
    TK80 Z 1
	TK81 ABCDEFGH 1
	TK81 I 1 BRIGHT A_FireBullets (4,5,6,10,"BulletPuff",FBF_USEAMMO)
	TNT1 A 0 A_TakeInventory("ShotgunClip",1,TIF_NOTAKEINFINITE)
	TK81 JKLMNOPQRSTUVXYZ 1
	TK82 ABCDEFGIJKLMNOPQRST 1
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDShellCasing", 20,cos(pitch)*4,sin(-pitch)*10+30, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
	TK82 UVXYZ 1
	TK83 ABCDEFGIJKL 1
	TK83 MNOP 1 A_REFIRE
    Goto Ready+11
		Reload:
		TK04 A 0
		goto ReloadCheckIftryingtofireit
  }
}

ACTOR ShotgunClip : Ammo
{
Inventory.MaxAmount 9 // size of the clip
Ammo.BackpackAmount 0
Ammo.BackpackMaxAmount 9 //MUST be the same as Inventory.MaxAmmount
+INVENTORY.IGNORESKILL
}

ACTOR PDShotgunPickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a Shotgun."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKA4 R -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDShotgun")
	  TNT1 A 0 A_JumpIfInventory("PlayingasPerfectKirby",1,"PickupPerfectKirby")
	  TNT1 A 0 A_JumpIfInventory("PlayingasRED",1,"PickupRED")
	  stop
	  PickupPerfectKirby:
	 	TNT1 A 0 A_PlaySound ("PerfectDark/Player/PerfectKirby/PerfectKirbyWeaponPickup")
		Stop
	  PickupRED:
	 	TNT1 A 0 A_PlaySound ("PerfectDark/Player/RED/REDWeaponPickup")
		Stop
   }
}
