ACTOR PDFarSightXR20 : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "FarSight XR-20"
        Weapon.Ammotype1 "FarSightXR20Clip"
  Weapon.Ammotype2 "PDFarsightOrbs"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 8
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a FarSight XR-20."
  Obituary  "%o was shredded like a gigantic piece of cheese by %k's amazingly awesome FarSight XR-20."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKA4 X -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TK95 A 2 
    TK95 B 2
    TK95 C 2
    TK95 D 2
    TK95 EFG 2
    TK95 H -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TK95 H 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+7
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("FarSightXR20Clip",8,2)
	 KLBG A 0 A_JumpIfInventory("PDFarsightOrbs",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+7

  ReloadStart:
     TK96 ABCDEFGHIJKLMNOPQRSTUVXYZ 1
	 TK97 ABCDEFGHI 1
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/FarSightXR20Reload")
	 TK97 JKLMNOPQRSTUVXYZ 1
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDFarsightOrbs",1)
	 TNT1 A 0 A_GiveInventory("FarSightXR20Clip",1)
	 TNT1 A 0 A_JumpIfInventory("FarSightXR20Clip",8,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDFarsightOrbs",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TK98 ABCDEFGHIJKLMN 1
	 Goto Ready+8
	
  Deselect:
    TK95 VXYZ 2
    TK08 A 0 A_Lower
    wait
  Select: 
    TK08 A 0 A_Raise 
    Loop  
  Fire: 
  KLBG A 0 A_JumpIfNoAmmo("ReloadCheck")
	TK95 I 2
 	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/FarSightXR20","Weapon")
    TK95 J 1 BRIGHT A_FireCustomMissile ("PDFarSightXR20Shot")
    TK95 KL 2
	TK95 MN 2 
	TK95 OPQRST 2
	TK95 U 50
    Goto Ready+8
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

ACTOR PDFarSightXR20Pickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a FarSight XR-20."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKA4 X -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDFarSightXR20")
	  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
   }
}


Actor PDFarSightXR20Shot : Fastprojectile
{
	Height 1
	Radius 1
	Speed 3000
	Damage 300
	Projectile
	+BLOODSPLATTER
	+RIPPER
	-PUFFONACTORS
	  Obituary  "%o was shredded like a gigantic piece of cheese by %k's amazingly awesome FarSight XR-20."
	states
		{
		Spawn:
			TNT1 A 1
			loop
		Crash:
		Death:
			TNT1 A 0 A_SpawnItemEx("PDGreenPuff")
			stop
		}
		
}