ACTOR StenSilenced : Inventory
{
	Inventory.MaxAmount 1
}
ACTOR StenSilencerHUD : Inventory
{
	Inventory.MaxAmount 1
}

// Whether or not we have the silencer upgrade
ACTOR "Sten MK II Silencer" : Inventory
{
	Inventory.MaxAmount 1
}

ACTOR StenPrimary : Ammo
{
  Inventory.Amount 1
  Inventory.MaxAmount 48
  Inventory.Icon "CLIPA0"
  +INVENTORY.IGNORESKILL
}

ACTOR StenSecondary : Ammo
{
  Inventory.PickupMessage "You picked up a magazine of Sten MK II ammunition." // "Picked up a clip."
  Inventory.PickupSound "sten/magin"
  Inventory.Amount 32
  Inventory.MaxAmount 192
  Ammo.BackpackAmount 64
  Ammo.BackpackMaxAmount 192
  Inventory.Icon "CLIPA0"
  +INVENTORY.IGNORESKILL
  States
  {
  Spawn:
    CLIP A -1
    Stop
  }
}

ACTOR "Sten MK II" : Weapon 11501
{
  +WEAPON.NOAUTOAIM
  Weapon.AmmoUse 1
  Weapon.AmmoGive2 32
  Weapon.BobStyle Smooth
  Weapon.BobSpeed 2.5
  Weapon.BobRangeX 0.5
  Weapon.BobRangeY 0.3
  Weapon.AmmoType "StenPrimary"
  Weapon.AmmoType2 "StenSecondary"
  Obituary "\cJ%k \cG> \cKSten MK II \cG> \cJ%o"
  Inventory.Pickupmessage "You picked up the Sten MK II."
  Inventory.PickupSound "ppsh/pickup"
	//$Category ZT2 - Weapons
	//$Title Sten MK II
	//$Sprite STENL0
  Tag "STEN MK II"
  Scale 0.75
  +WEAPON.NOAUTOFIRE
  +WEAPON.NOALERT
  States
  {
  Ready:
	PPSS A 0 A_JumpIfInventory("StenSilenced",1,"ReadySilenced")
	PPSS A 0 A_PlaySoundEx("sten/select","SoundSlot6")
	STSS ABCD 1
	Goto Idling
   ToGrenade:
	TNT1 A 0 A_JumpIfInventory("QuickGrenading",1,2)
	TNT1 A 0 A_Print("Why the fuck are you getting this?")
	GoTo Idling
	TNT1 A 0 A_JumpIfInventory("Type97Primary", 1, 3)
	TNT1 A 0 A_TakeInventory("QuickGrenading",999)
	TNT1 A 0 A_Print("No Grenades Left!")
	GoTo Idling
	TNT1 A 0 A_JumpIfInventory("StenSilenced",1,1)
	Goto ToNadeUnSilenced
	STSS HGFE 1
	TNT1 AAA 0
	TNT1 A 0 A_TakeInventory("QuickGrenading",999)
	TNT1 AAA 3
	97FI ABC 1
	97FI D 1
	97FI D 1 A_WeaponReady(WRF_NOPRIMARY | WRF_NOSECONDARY)
	//97FI D 0 A_JumpIfInventory("QuickGrenading",1,1)
	//97FI D 0 A_ReFire
	97FI E 0 A_PlaySoundEx("type97/pinpull","SoundSlot6")
	97FI EG 1
	97FI I 3
	97FI J 0 A_PlaySoundEx("type97/throw","SoundSlot6")
	97FI JKL 1
	TNT1 A 0 A_TakeInventory("Type97Primary",1)
	FRGN A 0 A_FireCustomMissile("Thrown97",random(-200,200)/100.00,0,0,16,0,random(-150,150)/100.00)
	TNT1 AAA 3
	TNT1 A 0 A_JumpIfInventory("StenSilenced",1,6)
	STSS ABCD 1
	TNT1 A 0 A_TakeInventory("QuickGrenading",999)
	GoTo Idling
	STSS EFGH 1
	TNT1 A 0 A_TakeInventory("QuickGrenading",999)
	Goto Idling
  QuickMeleeUnSilenced:
	 STSS DCBA 1
	 GoTo QuickMelee+6
  ToNadeUnSilenced:
	 STSS DCBA 1
	 GoTo ToGrenade+11
  QuickMelee:
	ORDS A 0 A_JumpIfInventory("StenSilenced",1,1)
	Goto QuickMeleeUnSilenced
	STSS HGFE 1
	TNT1 AAA 3
	MCFI E 1
	MCFI E 0 A_PlaySoundEx("machete/fire","Weapon")
	MCFI FG 1
    MCFI H 0 A_CustomPunch(2*random(1, 10), TRUE, 0, "ZTMeleePuff")
	MCFI HIJ 1
	MCFI K 2
	TNT1 AAA 3
	TNT1 A 0 A_JumpIfInventory("StenSilenced",1,6)
	STSS ABCD 1
	TNT1 A 0 A_TakeInventory("DoBlocking",999)
	GoTo Idling
	STSS EFGH 1
	TNT1 A 0 A_TakeInventory("DoBlocking",999)
	Goto Idling
  ReadySilenced:
	PPSS A 0 A_PlaySoundEx("sten/select","SoundSlot6")
	STSS EFGH 1
	Goto Idling
  Idling:
	PPSS A 0 A_JumpIfInventory("StenSilenced",1,"IdlingSilenced")
	PPSS A 0 A_JumpIfInventory("TertiaryFire",1,"SwapSilencer")
	PPSS A 0 A_JumpIfInventory("DoBlocking",1,"QuickMelee")
	PPSS A 0 A_JumpIfInventory("QuickGrenading",1,"ToGrenade")
	PPSS A 0 A_JumpIfInventory("IsReloading",1,"ReloadCheck")
    STID A 1 A_WeaponReady
    Loop
  IdlingSilenced:
	PPSS A 0 A_JumpIfInventory("TertiaryFire",1,"SwapSilencer")
	PPSS A 0 A_JumpIfInventory("QuickGrenading",1,"ToGrenade")
	PPSS A 0 A_JumpIfInventory("DoBlocking",1,"QuickMelee")
    PPSS A 0 A_JumpIfInventory("IsReloading",1,"ReloadCheck")
    STID B 1 A_WeaponReady
    Loop
  SwapSilencer:
	STSS A 0 A_TakeInventory("TertiaryFire",1)
	STSS A 0 A_JumpIfInventory("Sten MK II Silencer",1,2)
	STSS A 0 A_Print("You need the silencer upgrade to do that.")
	Goto Idling
	TNT1 A 0 A_JumpIfInventory("StenSilenced",1,"SilencerOff")
	Goto SilencerOn
  SilencerOff:
	STSS HGFE 1
	TNT1 A 4
	TNT1 A 0 A_PlaySoundEx("sten/silenceroff","SoundSlot6")
	STSS A 0 A_TakeInventory("StenSilenced",1)
	TNT1 A 12
	STSS ABCD 1
	STSS A 0 A_TakeInventory("TertiaryFire",1)
	Goto Idling
  SilencerOn:
	STSS DCBA 1
	TNT1 A 4
	TNT1 A 0 A_PlaySoundEx("sten/silenceron","SoundSlot6")
	TNT1 A 8
	TNT1 A 0 A_PlaySoundEx("sten/silencerpush","SoundSlot6")
	STSS A 0 A_GiveInventory("StenSilenced",1)
	TNT1 A 12
	STSS EFGH 1
	STSS A 0 A_TakeInventory("TertiaryFire",1)
	Goto IdlingSilenced
  ToReady:
	NULL A 0
	Goto Idling
	NULL AAA 0
	NULL A 0 A_PlaySoundEx("dryfire/smg","SoundSlot6")
	Goto Idling
  Deselect:
	 PPSS A 0 A_JumpIfInventory("StenSilenced",1,"DeselectSilenced")
	 STSS DCBA 1
	 PPFI A 0 A_TakeInventory("HasFiringModes",1)
	 PPFI A 0 A_TakeInventory("SemiAutomatic",1)
	 PPFI A 0 A_TakeInventory("StenSilencerHUD",1)
     TNT1 AAAAAAAAAA 0 A_Lower
	 TNT1 A 1 A_Lower
     Goto Deselect+8
  DeselectSilenced:
     STSS HGFE 1
	 PPFI A 0 A_TakeInventory("HasFiringModes",1)
	 PPFI A 0 A_TakeInventory("StenSilencerHUD",1)
	 PPFI A 0 A_TakeInventory("SemiAutomatic",1)
     TNT1 AAAAAAAAAA 0 A_Lower
	 TNT1 A 1 A_Lower
     Goto DeselectSilenced+7
  HasSilencer:
	 TNT1 A 0 A_GiveInventory("StenSilencerHUD",1)
	 Goto Select+2
  Select:
     TNT1 A 0 A_SetCrosshair(17)
	 TNT1 A 0 A_JumpIfInventory("Sten MK II Silencer",1,"HasSilencer")
	 TNT1 A 0 A_GiveInventory("HasFiringModes",1)
     TNT1 A 0 A_Raise
     Wait
  //================================================================
  // RELOAD CHECKING
  //================================================================
  ReloadCheck:
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"RCP")
	 TNT1 A 0 A_JumpIfInventory("StenPrimary",32,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("StenSecondary",1,"BoltCheck")
	 Goto ToReady
  RCP:
	 TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"RCP10")
	 TNT1 A 0 A_JumpIfInventory("StenPrimary",40,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("StenSecondary",1,"BoltCheck")
	 Goto ToReady
  RCP10:
	 TNT1 A 0 A_JumpIfInventory("StenPrimary",48,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("StenSecondary",1,"BoltCheck")
	 Goto ToReady
  //================================================================
  BoltCheck:
	 TNT1 A 0 A_JumpIfInventory("StenPrimary",1,"ReloadAnim")
	 TNT1 A 0 A_GiveInventory("PullBolt",1)
	 Goto ReloadAnim
  ReloadAnim:
     9MRL A 0 ACS_ExecuteAlways(820,0,0,0,0)
	 STRL A 0 A_JumpIfInventory("StenSilenced",1,"ReloadAnimSilenced")
	 STRL ABCD 1
	 STRL E 2
	 STRL F 6
	 STRL F 0 A_PlaySoundEx("sten/magout","SoundSlot6")
	 STRL GHIJK 2
	 STRL L 4
	 STRL MNO 1
	 STRL P 4
	 STRL QRST 1
	 STRL U 0 A_PlaySoundEx("sten/magin","SoundSlot6")
	 STRL U 4
	 STRL V 3
	 STRL W 0 A_JumpIfInventory("PullBolt",1,"BoltPull")
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_TakeInventory("TertiaryFire",1)
	 Goto CalculateAmmo
  BoltPull:
	 STBP A 0 A_JumpIfInventory("StenSilenced",1,"BoltPullSilenced")
     STBP ABCDEF 1
	 STBP G 8
	 STBP H 0 A_PlaySoundEx("sten/boltback","SoundSlot6")
	 STBP H 2
	 STBP I 7
	 STBP J 0 A_PlaySoundEx("sten/boltfwd","SoundSlot6")
	 STBP I 1
	 STBP J 2
	 STBP KLM 1
	 TNT1 A 0 A_TakeInventory("PullBolt",1)
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_TakeInventory("TertiaryFire",1)
	 Goto CalculateAmmo
  BoltPullSilenced:
	 STBQ ABCDEF 1
	 STBQ G 8
	 STBQ H 0 A_PlaySoundEx("sten/boltback","SoundSlot6")
	 STBQ H 2
	 STBQ I 7
	 STBQ J 0 A_PlaySoundEx("sten/boltfwd","SoundSlot6")
	 STBQ I 1
	 STBQ J 2
	 STBQ KLM 1
	 TNT1 A 0 A_TakeInventory("PullBolt",1)
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_TakeInventory("TertiaryFire",1)
	 Goto CalculateAmmo
  ReloadAnimSilenced:
     STRM ABCD 1
	 STRM E 2
	 STRM F 6
	 STRM F 0 A_PlaySoundEx("sten/magout","SoundSlot6")
	 STRM GHIJK 2
	 STRM L 4
	 STRM MNO 1
	 STRM P 4
	 STRM QRST 1
	 STRM U 0 A_PlaySoundEx("sten/magin","SoundSlot6")
	 STRM U 4
	 STRM V 3
	 STRL W 0 A_JumpIfInventory("PullBolt",1,"BoltPull")
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_TakeInventory("TertiaryFire",1)
	 Goto CalculateAmmo
  //================================================================
  // AMMO CALCULATION
  //================================================================
  CalculateAmmo:
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"CalculateAmmoPerk")
     TNT1 A 0 A_JumpIfInventory("StenSecondary",1,2)
	 Goto Idling
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("StenPrimary",32,"ToReady")
	 TNT1 A 0 A_TakeInventory("StenSecondary",1)
	 TNT1 A 0 A_GiveInventory("StenPrimary",1)
	 Loop
  CalculateAmmoPerk:
	 TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"CalculateAmmoPerk10")
     TNT1 A 0 A_JumpIfInventory("StenSecondary",1,2)
	 Goto Idling
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("StenPrimary",40,"ToReady")
	 TNT1 A 0 A_TakeInventory("StenSecondary",1)
	 TNT1 A 0 A_GiveInventory("StenPrimary",1)
	 Loop
  CalculateAmmoPerk10:
     TNT1 A 0 A_JumpIfInventory("StenSecondary",1,2)
	 Goto Idling
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("StenPrimary",48,"ToReady")
	 TNT1 A 0 A_TakeInventory("StenSecondary",1)
	 TNT1 A 0 A_GiveInventory("StenPrimary",1)
	 Loop
  //================================================================
  Fire:
	 PPFI A 0 A_JumpIfInventory("StenPrimary",1,1)
	 Goto ToReady+2
	 PPFI A 0 A_JumpIfInventory("StenSilenced",1,"FireSilenced")
	 //PPFI A 0 A_TakeInventory("StenPrimary",1)
	 PPFI A 0 A_AlertMonsters
	 PPFI A 0 A_FireBullets (ACS_ExecuteWithResult(566,3,0,0), ACS_ExecuteWithResult(566,3,0,0), 1, 5, "BulletPuff2")
	 BPSS A 0 A_FireCustomMissile("LongRifleCaseSpawn",5,0,16,-3)
	 PPFI A 0 A_PlaySound("sten/fire", CHAN_WEAPON)
	 TNT1 A 0 A_SpawnItemEx("ShooterLight",0,0,0)
	 PPFI A 0 A_SetPitch(pitch+0.5)
	 STFI A 1 bright
	 PPFI A 0 A_SetPitch(pitch-0.4)
	 STFI B 2
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"ToReady")
	 PPFI A 0 A_ReFire
	 Goto Idling
  FireSilenced:
     //PPFI A 0 A_TakeInventory("StenPrimary",1)
	 PPFI A 0 A_FireBullets (ACS_ExecuteWithResult(566,3,0,0), ACS_ExecuteWithResult(566,3,0,0), 1, 5, "BulletPuff2")
	 BPSS A 0 A_FireCustomMissile("LongRifleCaseSpawn",5,0,16,-3)
	 PPFI A 0 A_PlaySound("sten/silencerfire", CHAN_WEAPON)
	 TNT1 A 0 A_SpawnItemEx("ShooterLight",0,0,0)
	 PPFI A 0 A_SetPitch(pitch+0.5)
	 STFI C 1 bright
	 PPFI A 0 A_SetPitch(pitch-0.4)
	 STFI D 2
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"ToReady")
	 PPFI A 0 A_ReFire
	 Goto Idling
  AltFire:
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"ToFull")
	 Goto ToSemi
  ToFull:
     TNT1 A 0 A_SetCrosshair(17)
	 PPFI A 0 A_TakeInventory("SemiAutomatic",1)
	 PPFI A 0 A_Print("Switched to Fully Automatic mode.")
	 Goto Idling
  ToSemi:
     TNT1 A 0 A_SetCrosshair(18)
	 PPFI A 0 A_GiveInventory("SemiAutomatic",1)
	 PPFI A 0 A_Print("Switched to Semi Automatic mode.")
	 Goto Idling
  Spawn:
    STEN L -1
    Stop
  }
}