ACTOR Weapon_Ak47 : Weapon_Base
{
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 30
  Weapon.AmmoType1 "Weapon_Ak47_Mag"
  Obituary "$OB_MPPISTOL"
  +WEAPON.AMMO_OPTIONAL
  +WEAPON.NOAUTOFIRE
  
  Weapon.SlotNumber 4
  
  States
  {
  Ready:
	PISG A 0
	PISG A 0 A_PlaySound("weapons/equip",CHAN_6)
	  PISG A 1 Offset(0,8)
	  PISG A 1 Offset(0,12)
	  PISG A 1 Offset(0,18)
	  PISG A 1 Offset(0,24)
	  PISG A 1 Offset(0,28)
	  PISG A 0 Offset(0,32)
	  PISG A 1 A_WeaponReady
	  Goto Idle
  
  Idle:
	PISG A 0 A_GiveInventory("YouPlayer_HoldingRifle",1)
    PISG A 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Loop
	
	Empty:
	PISG A 1
	PISG A 0 A_PlaySound("weapons/empty",CHAN_VOICE)
	Goto Reload
	
  Fire:
	PISG A 0 A_JumpIfNoAmmo("Empty")
    PISG A 0
	PISG A 0 A_FireBullets (3, 3, -1, 8, "BulletPuff")
	PISG A 0 A_PlaySound("weapons/ak47/fire", CHAN_WEAPON, 1.0, false, 0.8)
	
	PISG A 0 A_FireCustomMissile ("MuzzleFlash_RifleHandler",0,false,13,5)
	PISG A 0 A_SetPitch(pitch-2.5,SPF_INTERPOLATE)
	
    MDL1 FGHI 1
	MDL1 J 0 A_ReFire
	MDL1 JKLMNOPQ 1 A_WeaponReady(WRF_ALLOWRELOAD)
    PISG A 0
    Goto Idle
	
	Reload:
	PISG A 1 A_WeaponReady
	PISG A 0 A_JumpIfInventory("Weapon_Ak47_Mag",0,"Idle")
	PISG A 0 A_JumpIfInventory("Weapon_Ak47_Ammo",1,"ReloadYes")
	Goto Idle
	ReloadYes:
	PISG A 0
	PISG A 0 A_PlaySound ("weapons/ak47/reload/foley",CHAN_6,1.0,false,5.0)
	PISG A 0 A_PlaySound ("weapons/ak47/reload",CHAN_7)
	MDL1 TUVWXYZ 2 A_WeaponReady(WRF_NOFIRE)
	MDL2 ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 A_WeaponReady(WRF_NOFIRE)
	MDL2 Z 0 A_GunFlash("ReloadSystem",GFF_NOEXTCHANGE)
	MDL3 ABCDEFGHIJKLMNOP 2 A_WeaponReady(WRF_NOFIRE)
	MDL3 QRSTUVWXYZ 2 A_WeaponReady
	MDL4 ABCDEFG 2 A_WeaponReady
	PISG A 0
	Goto Idle
	
	ReloadSystem:
	TNT1 A 0 A_JumpIfInventory("Weapon_Ak47_Mag",0,"ReloadSystemEND")
	TNT1 A 0 A_JumpIfInventory("Weapon_Ak47_Ammo",1,"ReloadSystemConfirm")
	Goto ReloadSystemEND
	ReloadSystemConfirm:
	TNT1 A 0 A_GiveInventory("Weapon_Ak47_Mag",1)
	TNT1 A 0 A_TakeInventory("Weapon_Ak47_Ammo",1)
	Goto ReloadSystem
	
	ReloadSystemEND:
	TNT1 A 1
	Stop
	
  Flash:
    PISF A 7 Bright A_Light1
    Goto LightDone
    PISF A 7 Bright A_Light1
    Goto LightDone
	Done:
	MDL1 A 0
	MDL2 A 0
	MDL3 A 0
	MDL4 A 0
	MDL5 A 0
	MDL6 A 0
	MDL7 A 0
	MDL8 A 0
	MDL9 A 0
	Stop
  Spawn:
    PIST A -1
    Stop
  }
}

ACTOR Weapon_Ak47_Mag : Ammo
{
	Inventory.Amount 1
	Inventory.MaxAmount 30
}

ACTOR Weapon_Ak47_Ammo : Ammo
{
	Inventory.Amount 17
	Inventory.MaxAmount 150
}

ACTOR AmmoPkup_Ak47_single : CustomInventory Replaces Shell
{
	Scale 0.5
	+QUIET
	+COUNTITEM
	States
	{
	Spawn:
	AMMO A -1
	Stop
	Pickup:
	TNT1 A 0 A_JumpIfInventory("Weapon_Ak47_Ammo",0,"FailPickup")
	TNT1 A 0 A_GiveInventory("Weapon_Ak47_Ammo",30)
	TNT1 A 0 ACS_NamedExecute("PlayerPickupMessage",0,2)
	Stop
	FailPickup:
	TNT1 A 1
	Fail
	}
}

ACTOR AmmoPkup_Ak47_double : CustomInventory Replaces ShellBox
{
	Scale 0.5
	+QUIET
	+COUNTITEM
	States
	{
	Spawn:
	AMMO B -1
	Stop
	Pickup:
	TNT1 A 0 A_JumpIfInventory("Weapon_Ak47_Ammo",0,"FailPickup")
	TNT1 A 0 A_GiveInventory("Weapon_Ak47_Ammo",60)
	TNT1 A 0 ACS_NamedExecute("PlayerPickupMessage",0,3)
	Stop
	FailPickup:
	TNT1 A 1
	Fail
	}
}

ACTOR GunPkup_Akm : CustomInventory Replaces Chaingun
{
	Scale 0.5
	+QUIET
	+COUNTITEM
	States
	{
	Spawn:
	GUNN D -1
	Stop
	Pickup:
	TNT1 A 0 A_JumpIfInventory("Weapon_Ak47",0,"FailPickup")
	TNT1 A 0 A_GiveInventory("Weapon_Ak47",1)
	TNT1 A 0 ACS_NamedExecute("PlayerPickupMessage",0,7)
	Fail
	FailPickup:
	TNT1 A 1
	Fail
	}
}