ACTOR PDSniperRifle : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "Sniper Rifle"
        Weapon.Ammotype1 "SniperRifleClip"
  Weapon.Ammotype2 "PDRifleAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 8
  +WEAPON.AMMO_OPTIONAL
  +WEAPON.NOALERT
  Inventory.PickupMessage "Picked up a Sniper Rifle."
  Obituary  "%o was silenced by %k's Sniper Rifle."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKA4 Y -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TK91 A 2 
    TK91 B 2
    TK91 C 2
    TK91 D 2
    TK91 EFGH 2
    TK91 I -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TK91 I 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+7
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("SniperRifleClip",8,2)
	 KLBG A 0 A_JumpIfInventory("PDRifleAmmo",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+9

  ReloadStart:
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/SniperRifleReload")
     TK91 YZ 1
	 TK92 ABCDEFGHIJKLMNOPQRSTUVXYZ 1
	 TK93 ABCDEFGH 1
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDRifleAmmo",1)
	 TNT1 A 0 A_GiveInventory("SniperRifleClip",1)
	 TNT1 A 0 A_JumpIfInventory("SniperRifleClip",8,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDRifleAmmo",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TK93 IJKLMNOPQRSTUVXYZ 1
	 TK94 ABCDEF 1
	 Goto Ready+9
	
  Deselect:
    TK91 RSTUVX 2
    TK08 A 0 A_Lower
    wait
  Select: 
    TK08 A 0 A_Raise 
    Loop  
  Fire: 
  KLBG A 0 A_JumpIfNoAmmo("ReloadCheck")
 	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/SniperRifle","Weapon")
    TK91 J 2 BRIGHT A_FireBullets(0, 0, 1, 20, "BulletPuff",FBF_USEAMMO)
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDPointedBulletCasing", 30,cos(pitch)*12,sin(-pitch)*10+30, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
    TK91 KLMNO 2
	TK91 P 2 
	TK91 Q 2
    Goto Ready+9
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

ACTOR PDSniperRiflePickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a Sniper Rifle."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKA4 Y -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDSniperRifle")
	  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
   }
}
