// --------------------------------------------------------------------------
//
// MP9 (Weapon)
//
// --------------------------------------------------------------------------


//Weapon Auxiliar
Actor MP9Refire : Inventory
{
Inventory.MaxAmount 2
}


ACTOR "MP9" : CSDMOWeapon //5010
{
	Weapon.SisterWeapon mp9_rat

+AMMO_OPTIONAL

	Weapon.SelectionOrder 300
  weapon.ammotype "MP9Clip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "9mmAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0 //30
	obituary "%k killed %o with MP9."
	+WEAPON.WIMPY_WEAPON
	Inventory.Pickupmessage "Pickep up a MP9"
	Tag "MP9"
	Weapon.UpSound "MP9/Ready"
	//AttackSound "MP9/Fire"
	Scale 0.16

	States
	{
	Ready:
		W27E E 1 A_WeaponReady
		Loop



	Deselect:
	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 2, 0, 0)
    TNT1 A 1 
	Goto DeselectLoop


	Select:
	TNT1 A 1 A_Raise
	TNT1 AA 0 A_Raise
	TNT1 A 0 ACS_ExecuteAlways(798, 0, 240, 0, 0)//Weapon Weight
	TNT1 A 1 A_TakeInventory("CrosshairType",2)

	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 1, 0, 0)
    TNT1 A 0 A_JumpIfInventory("RAT_Trigger",1,"RAT_TriggerSelect")
	
		W27A CDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W27B ABCDEFGHIJKLM 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready

	Rat_TriggerSelect:
    TNT1 A 0 A_TakeInventory("Rat_Trigger",1)
	
		W27A CDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W27B ABCDEFGHIJKLM 1 A_WEAPONREADY//(WRF_NOFIRE)
		Goto Ready

	Fire:

	W04E D 0 A_JumpIfNoAmmo("AltFire")
	
	    TNT1 A 0 A_JumpIfInventory("MP9Refire", 2, "Fire3")
		TNT1 A 0 A_JumpIfInventory("MP9Refire", 1, "Fire2")
	
		W27D A 1 A_GunFlash
				TNT1 A 0 A_GiveInventory("MP9Refire", 1)
		W27D B 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
				TNT1 A 0 A_TakeInventory("MP9Refire", 3)

		W27D CDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WeaponReady
		W27E ABCD 1 A_WeaponReady
		Goto Ready



	Fire2:	
		W27D C 1 A_GunFlash
				TNT1 A 0 A_GiveInventory("MP9Refire", 1)
		W27D A 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
				TNT1 A 0 A_TakeInventory("MP9Refire", 3)

		W27D BCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WeaponReady
		W27E ABCD 1 A_WeaponReady
		Goto Ready


	Fire3:	
		W27D B 1 A_GunFlash
				TNT1 A 0 A_TakeInventory("MP9Refire", 3)
		W27D C 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
				TNT1 A 0 A_TakeInventory("MP9Refire", 3)

		W27D DEFGHIJKLMNOPQRSTUVWXYZ 1 A_WeaponReady
		W27E ABCD 1 A_WeaponReady
		Goto Ready






  Altfire:
    TNT1 A 0 A_JumpIfInventory("MP9Clip",30,"Ready")
    TNT1 A 0 A_JumpIfInventory("9mmAmmo",1,"ReloadStart")
    goto Ready


	ReloadStart:
		W27F ABCDEFGHIJ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		TNT1 A 0 A_PlaySound("MP9/Reload", 6)
		W27F KLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W27G ABCDE 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		Goto ReloadAmmo

  ReloadAmmo:
    TNT1 A 0 A_GiveInventory("MP9Clip",1)
    TNT1 A 0 A_TakeInventory("9mmAmmo",1)
    TNT1 A 0 A_JumpIfInventory("MP9Clip",0,"ReloadEnd")
    TNT1 A 0 A_JumpIfInventory("9mmAmmo",1,"ReloadAmmo")
    goto ReloadEnd
	
	
	ReloadEnd:
		W27G FGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W27H ABCDEFGHIJKLMNOPQ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W27H RSTUVWX 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready	
	
	



	Flash:
	TNT1 A 0 ACS_ExecuteAlways(799, 0, 0, 0, 0)
	TNT1 A 0 A_GiveInventory("CrosshairGrow", 6)
	TNT1 A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,17,2)
		TNT1 A 0 Bright A_Light1
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_PlaySound ("MP9/FIRE")
		TNT1 A 0 A_PlaySound("MP9/Distant", 7)
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,12,-6)
        TNT1 A 0 BRIGHT A_FireCustomMissile("Tracer", frandom(-1.5,1.5), 0, 11, 0, 0, frandom(-1.5,1.5))
		TNT1 A 2 A_FireBullets(4.3, 4.3, 1, 30.0, "mp9Bullet")//6.15
		Goto LightDone
 	Spawn:
		W27Z A -1
		Stop
	}
}