ACTOR PDK7Avenger : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "K7 Avenger"
        Weapon.Ammotype1 "K7AvengerClip"
  Weapon.Ammotype2 "PDRifleAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 25
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a K7 Avenger."
  Obituary  "%k's K7 Avenger rounds snaked their way into %o's skull."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKA4 M -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TK62 A 2 
    TK62 B 2
    TK62 C 2
    TK62 D 2
    TK62 EFGHIJ 2
    TK62 K -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TK62 K 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+7
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("K7AvengerClip",25,2)
	 KLBG A 0 A_JumpIfInventory("PDRifleAmmo",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+11

  ReloadStart:
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/K7AvengerReload")
     TK63 HIJKLMNOPQRSTUVXYZ 1
	 TK64 ABCDEFGHIJKLMNOPQRSTUVXYZ 1
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDRifleAmmo",1)
	 TNT1 A 0 A_GiveInventory("K7AvengerClip",1)
	 TNT1 A 0 A_JumpIfInventory("K7AvengerClip",25,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDRifleAmmo",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TK65 GHIJKLMNOPQRSTUVX 1
	 Goto Ready+11
	
  Deselect:
    TK63 DEFG 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/K7Avenger","Weapon")
    TK62 M 2 BRIGHT A_FireBullets(2, 2, 1, 16, "BulletPuff",FBF_USEAMMO)
	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/K7Avenger","Weapon")
    TK62 N 2 BRIGHT A_FireBullets(2, 2, 1, 16, "BulletPuff",FBF_USEAMMO)
	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/K7Avenger","Weapon")
	TK62 O 2 BRIGHT A_FireBullets(2, 2, 1, 16, "BulletPuff",FBF_USEAMMO)
	TK62 P 2
	TK62 QRSTUVXYZ 2 A_REFIRE
	TK63 AB 2
    Goto Ready+11
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

ACTOR PDK7AvengerPickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a K7 Avenger."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKA4 M -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDK7Avenger")
	  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
   }
}
