ACTOR PDMagSec4 : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "MagSec 4"
        Weapon.Ammotype1 "MagSec4Clip"
  Weapon.Ammotype2 "PDPistolAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 9
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a MagSec 4."
  Obituary  "%o was brought down by %k's MagSec 4."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKA4 B -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TK13 A 1 
    TK13 B 1
    TK13 C 1
    TK13 D 1
    TK13 EFGHIJKL 1
    TK13 M -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TK13 M 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+14
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("MagSec4Clip",9,2)
	 KLBG A 0 A_JumpIfInventory("PDPistolAmmo",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+14

  ReloadStart:
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/MagSec4Reload")
     TK14 TUVXYZ 2
	 TK15 ABCDEFGHIJKLMNOPQRSTUVXYZ 1
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDPistolAmmo",1)
	 TNT1 A 0 A_GiveInventory("MagSec4Clip",1)
	 TNT1 A 0 A_JumpIfInventory("MagSec4Clip",9,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDPistolAmmo",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TK16 ABCDEFGHIJKLMN 1
	 Goto Ready+14
	
  Deselect:
    TK13 YZ 1
	 TK14 AB 1
    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/MagSec4","Weapon")
    TK13 N 1 BRIGHT A_FireBullets(1, 1, 1, 9, "BulletPuff",FBF_USEAMMO)
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDBulletCasing", 30,cos(pitch)*12,sin(-pitch)*10+30, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
    TK13 OPQRS 1
	TK13 T 1 
	TK13 UV 1
	TK13 X 1 A_REFIRE
    Goto Ready+14
	Altfire:
  NULL A 0 A_JumpIfInventory("MagSec4Clip",3,1)
  goto Ready+14
 	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/MagSec4Alt","Weapon")
	TNT1 A 0 A_TakeInventory("MagSec4Clip",1)
    TK14 C 1 BRIGHT A_FireBullets(3, 3, 1, 9, "BulletPuff",FBF_USEAMMO)
	TK14 D 1 
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDBulletCasing", 30,cos(pitch)*12,sin(-pitch)*10+30, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
    TK14 E 1 BRIGHT A_FireBullets(3, 3, 1, 9, "BulletPuff",FBF_USEAMMO)
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDBulletCasing", 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("MagSec4Clip",1)
	TK14 F 1 
    TK14 G 1 BRIGHT A_FireBullets(3, 3, 1, 9, "BulletPuff",FBF_USEAMMO)
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDBulletCasing", 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("MagSec4Clip",1)
	TK14 HIJKLMNOPQRS 1 
	Goto Ready+14
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

ACTOR PDMagSec4Pickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a MagSec 4."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKA4 B -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDMagSec4")
	  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
   }
}
