//===========================================================================
//
// Makoto Arms Type 919 Modified
//
// by Marty Kirra
// Sprites by Marty Kirra
//
//===========================================================================

ACTOR Mel919mPistol : Weapon
{
	Weapon.Kickback 110
	Weapon.AmmoType	"AutoPistolMag"
	Weapon.AmmoGive	0
	Weapon.AmmoUse	1
	Weapon.AmmoType2 "TSPPistolAmmo"
	Weapon.AmmoGive2 0
	Weapon.AmmoUse2	0
	//Weapon.BobStyle InverseSmooth
	//Weapon.BobSpeed 2.2
	//Weapon.BobRangeY 0.5
	//Weapon.BobRangeX 0.7
	Inventory.PickupMessage "[Makoto Type 919 Mod.0] [Class: Pistol, Slot 2]"
	Obituary "Target %o has been taken out by %k. Assignment Complete."
	+NOAUTOFIRE
	+AMMO_OPTIONAL
	+NOEXTREMEDEATH
	+WEAPON.NoAlert
	Tag "Makoto Arms 919M.0"
   States
   {
   Spawn:
	  919P A -1
	  Stop
   Ready:
      TNT1 A 0 A_JumpIfInventory("MelPistolCombo", 1, "ComboIdle")
      MPTG A 0 A_JumpIfInventory("AutoPistolFullAuto", 1, "AutoReady")
	  TNT1 A 0 A_JumpIfInventory("MeleePressed",1,"SPMeleePistol")
      TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
	  MPTG A 1 A_WeaponReady
      LOOP
   AutoReady:
      TNT1 A 0 A_JumpIfInventory("MeleePressed",1,"AutoModeMelee")
	  TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
      ASTG A 1 A_WeaponReady
	  Loop
   ComboIdle:
      TNT1 A 8 A_WeaponReady
	  TNT1 A 0 A_TakeInventory("MelPistolCombo", 99)
	  Goto Select
   Deselect:
      TNT1 A 0 A_TakeInventory("ComboCoolDown", 99)
   	  TNT1 A 0 A_TakeInventory("MelPistolCombo", 99)
      TNT1 A 0 A_PlaySound("919m/deselect", 5)
      TNT1 A 0 A_JumpIfInventory("AutoPistolFullAuto", 1, "AutoDeselect")
	  MPTD ABCD 1
   DeselectLoop:
	  TNT1 A 3 A_Lower
      Loop
   AutoDeselect:
      ASTD ABCD 1
   AutoDeselectLoop:
	  TNT1 A 3 A_Lower
      Loop
   Select:
	  TNT1 A 0 A_TakeInventory("MeleeSelected", 1)
	  TNT1 A 0 A_TakeInventory("ZekeSelected", 1)
	  TNT1 A 0 A_TakeInventory("DahliaSelected", 1)
	  TNT1 A 0 A_TakeInventory("AmmoBoxSelected", 1)
	  TNT1 A 0 A_TakeInventory("ToolBoxSelected", 1)
	  TNT1 A 0 A_TakeInventory("MP40Selected", 1)
	  TNT1 A 0 A_GiveInventory("919Selected", 1)
	  TNT1 A 0 A_PlaySound("919m/select", 5)
	  TNT1 A 0 A_JumpIfInventory("MelPistolCombo", 1, "PistolComboStart")
      TNT1 A 3 SetPlayerProperty(0,1,2)
	  TNT1 A 0 A_JumpIfInventory("AutoPistolFullAuto", 1, "AutoSelect")
      MPTS ABCD 1
   SelectLoop:
	  MPTG A 1 A_Raise
	  Loop
   AutoSelect:
      ASTU ABCD 1
   AutoSelectLoop:
	  ASTG A 1 A_Raise
	  Loop
   Fire:
      TNT1 A 0 A_JumpIfInventory("MelPistolCombo", 1, "PistolCombo1")
      TNT1 A 0 A_JumpIfInventory("AutoPistolFullAuto", 1, "AutoFire")
	  TNT1 A 0 A_JumpIfNoAmmo("Empty")
	  MPTF A 0 A_AlertMonsters
	  MPTF A 1 A_GunFlash
	  MPTF B 0 A_PlaySound("919m/fire", 6)
	  MPTF B 0 A_Light2
      TNT1 A 0 A_JumpIfInventory("GameIsCoop", 1, "FireCoop")
	  Goto FireDM
	FireCoop:
	  MPTF B 1 BRIGHT A_FireCustomMissile("919CoopBullet",(random(-300, 300)/100.00), 1, 0, 1, 0,(random(-200, 200)/100.00))
	  Goto FireFinish
	FireDM:
	  MPTF B 1 BRIGHT A_FireBullets(3,2,-1,8,"BulletPuff",1)
	  Goto FireFinish
	FireFinish:
	  MPTF C 1 BRIGHT A_Light1
	  MPTG B 1 A_Light0
	  MPTG C 0 A_FireCustomMissile("9mmCasingSpawner",-3,0,0,0)
	  TNT1 A 0 A_GiveInventory("ShotsFiredPewPew", 1)
	  MPTG CDEF 1 A_WeaponReady(WRF_NOBOB)
	  Goto Ready
	AutoFire:
	  TNT1 A 0 A_JumpIfInventory("MeleePressed",1,"AutoModeMelee")
	  TNT1 A 0 A_JumpIfNoAmmo("AutoEmpty")
	  ASTF A 1 BRIGHT
      ASTG A 0 A_GunFlash
	  ASTG A 0 A_AlertMonsters
	  MPTG A 0 A_SetPitch(pitch - 0.8)
	  MPTG A 0 A_SetAngle(angle + (random(-3,3)/10))
      ASTG A 0 A_PlaySound("919m/fire", 5)
	  TNT1 A 0 A_GiveInventory("ShotsFiredPewPew", 1)
	AFire0:
      TNT1 A 0 A_JumpIfInventory("GameIsCoop", 1, "AutoFireCoop")
	  Goto AutoFireDM
	AutoFireCoop:
	  ASTF A 0 BRIGHT A_FireCustomMissile("919CoopBullet2",(random(-600, 600)/100.00), 1, 0, 1, 0,(random(-600, 600)/100.00))
	  Goto AutoFireFinish
	AutoFireDM:
	  ASTF A 0 BRIGHT A_FireBullets(6,6,-1,9,"919mBulletPuff",1)
	  Goto AutoFireFinish
	AutoFireFinish:
      ASTF A 0 A_Jump(64,"AFire3")
	  ASTF A 0 A_Jump(88,"Afire2")
	AFire1:
	  ASTF B 0 A_FireCustomMissile("9mmCasingSpawner",-4,0,0,0)
	  ASTF B 0 A_Light2
      ASTF B 1 BRIGHT A_Light1
	  ASTF B 0 A_Light0
      ASTF B 0 A_Refire
      Goto FireEnd
	AFire2:
	  ASTF B 0 A_FireCustomMissile("9mmCasingSpawner",-3,0,0,0)
	  ASTF C 0 A_Light2
      ASTF C 1 BRIGHT A_Light1
	  ASTF C 0 A_Light0
      ASTF C 0 A_Refire
      Goto FireEnd
	AFire3:
	  ASTF B 0 A_FireCustomMissile("9mmCasingSpawner",-5,0,0,0)
	  ASTF D 0 A_Light2
      ASTF D 1 BRIGHT A_Light1
	  ASTF D 0 A_Light0
      ASTF D 0 A_Refire
	FireEnd:
	  TNT1 A 0 A_GiveInventory("ShotsFiredPewPew", 1)
	  ASTG D 1
	  ASTG C 1
	  ASTG B 1
	  Goto Ready
	AltFire:
	  TNT1 A 0 A_PlaySound("919m/autoselect", 5)
	  TNT1 A 0 A_JumpIfInventory("AutoPistolFullAuto", 1, "AutoPistolSingle")
	  ASTS ABCDE 1
	  ASTS F 3
	  ASTS GHIJ 1
	  ASTG A 1
	  ASTS Q 0 A_GiveInventory("AutoPistolFullAuto",1)
	  Goto AutoReady
    AutoPistolSingle:
	  TNT1 A 0 A_PlaySound("919m/autodeselect", 5)
	  ASTS QQQPPONMLKJIHG 1
	  ASTS F 3
	  ASTS EDCBA 1
	  ASTS A 0 A_TakeInventory("AutoPistolFullAuto", 99)
	  ASTS A 1
	  Goto Ready
	AutoEmpty:
	  ASTF A 5 A_PlaySound("919m/dry", 6)
	  Goto AutoPistolReload
	Empty:
	  MPTF A 5 A_PlaySound("919m/dry", 6)
	  Goto Reload
	AutoPistolReload:
	  ASTG A 0 A_JumpIfInventory("AutoPistolMag", 15, 2)
	  ASTG A 0 A_JumpIfInventory("TSPPistolAmmo", 1, 2)
//	  ASTG A 0 A_JumpIfInventory("AutoPistolMag", 0, "APReloadAni")
	  ASTG A 1 A_WeaponReady(WRF_NOFIRE)
	  Goto Ready
	APReloadAni:
	  ASTG A 1
	  ASTS JI 1
	Reload:
	  TNT1 A 0 A_TakeInventory("Reloading",9)
	  MPTG A 0 A_JumpIfInventory("AutoPistolMag", 15, "3")
	  MPTG A 0 A_JumpIfInventory("TSPPistolAmmo", 1, "3")
	  MPTG A 0 A_JumpIfInventory("AutoPistolFullAuto", 1, "AutoEmptyReady")
	  MPTG A 1 A_WeaponReady(WRF_NOFIRE)
	  Goto Ready
	ReloadStart:
	  TNT1 A 0 A_TakeInventory("ShotsFiredPewPew", 99)
      MPTG BCD 1
	  MPTG D 0 A_FireCustomMissile("SpentClip1",3,0,5,0)
	  MPTR A 1 A_PlaySound("919m/magout", 5)
	  MPTR BCD 1
	  MPTR EEEEEEEEEEEEEEEEEEEE 1
	  TNT1 A 0 A_PlaySound("919m/magin1", 6)
	  MPTR FGH 1
	  MPTR I 1
	ReloadWork:
	  MPTR I 0 A_TakeInventory("TSPPistolAmmo",1)
	  MPTR I 0 A_GiveInventory("AutoPistolMag",1)
	  MPTR I 0 A_JumpIfInventory("AutoPistolMag",15,"ReloadFinish")
	  MPTR I 0 A_JumpifInventory("TSPPistolAmmo",1,"ReloadWork")
	ReloadFinish:
	  MPTR JKLMNNNNOP 1
	  MPTR Q 1 A_PlaySound("919m/magin2", 5)
	  MPTR QRSTUVWX 1
	  MPTG A 3
	  TNT1 A 0 A_JumpIfInventory("AutoPistolFullAuto", 1, "AutoPistolFinish")
	  Goto Ready
	AutoPistolFinish:
	  ASTS IJ 1
	  Goto AutoReady
	AutoEmptyReady:
	  ASTG A 1 A_WeaponReady(WRF_NOFIRE)
	  Goto AutoReady
	PistolComboStart:
	  TNT1 A 0 A_Raise
	  TNT1 A 0 A_JumpIfInventory("ShotsFiredPewPew", 11, "Select")
	  TNT1 AAAAAAAAAA 1 A_WeaponReady
	  TNT1 A 0 A_TakeInventory("MelPistolCombo", 99)
	  Goto Select
	PistolCombo1:
	  TNT1 A 0 A_JumpIfInventory("ShotsFiredPewPew", 11, "AfterCombo")
	  TNT1 A 0 A_TakeInventory("AutoPistolFullAuto", 99)
	  TNT1 A 0 A_GiveInventory("AutoPistolFullAuto", 1)
	  TNT1 A 3 A_PlaySoundEX("basicmelee/miss", "SoundSlot5")
	  MPCF ABCD 1
	  ASTG A 0 A_GunFlash
	  ASTG A 0 A_AlertMonsters
	  MPTG A 0 A_SetPitch(pitch - 1.6)
	  MPTG A 0 A_SetAngle(angle + (random(-6,6)/10))
      ASTG A 0 A_PlaySound("919m/fire", 5)
      ASTF A 0 BRIGHT A_FireBullets(6,6,-1,7,"BulletPuff",1)
      MPCF EF 1
	  ASTG A 0 A_GunFlash
	  ASTG A 0 A_AlertMonsters
	  MPTG A 0 A_SetPitch(pitch - 1.6)
	  MPTG A 0 A_SetAngle(angle + (random(-6,6)/10))
      ASTG A 0 A_PlaySound("919m/fire", 5)
      ASTF A 0 BRIGHT A_FireBullets(6,6,-1,7,"BulletPuff",1)
	  MPCF GH 1
	  ASTG A 0 A_GunFlash
	  ASTG A 0 A_AlertMonsters
	  MPTG A 0 A_SetPitch(pitch - 1.6)
	  MPTG A 0 A_SetAngle(angle + (random(-6,6)/10))
      ASTG A 0 A_PlaySound("919m/fire", 5)
      ASTF A 0 BRIGHT A_FireBullets(6,6,-1,7,"BulletPuff",1)
	  MPCF IJ 1
	  ASTG A 0 A_GunFlash
	  ASTG A 0 A_AlertMonsters
	  MPTG A 0 A_SetPitch(pitch - 1.6)
	  MPTG A 0 A_SetAngle(angle + (random(-6,6)/10))
      ASTG A 0 A_PlaySound("919m/fire", 5)
      ASTF A 0 BRIGHT A_FireBullets(6,6,-1,7,"BulletPuff",1)
	  MPCF KL 1
	  ASTG A 0 A_GunFlash
	  ASTG A 0 A_AlertMonsters
	  MPTG A 0 A_SetPitch(pitch - 1.6)
	  MPTG A 0 A_SetAngle(angle + (random(-6,6)/10))
      ASTG A 0 A_PlaySound("919m/fire", 5)
      ASTF A 0 BRIGHT A_FireBullets(6,6,-1,7,"BulletPuff",1)
	  MPCF MN 1
	  TNT1 A 0 A_GiveInventory("ShotsFiredPewPew", 5)
	  TNT1 A 8
	AfterCombo:
	  TNT1 A 0 A_TakeInventory("MelPistolCombo", 99)
	  TNT1 A 0 A_TakeInventory("MelPrimaryCombo", 99)
	  TNT1 A 0 A_TakeInventory("MelAlternateCombo", 99)
	  TNT1 A 0 A_TakeInventory("MelMachCombo", 99)
	  ASTU ABCD 1
	  Goto Ready
	SPMeleePistol:
	  TNT1 A 0 A_JumpIfInventory("AutoPistolFullAuto",1,"AutoModeMelee")
	  TNT1 A 0 A_Jump(88,"Melee2")
	  MPTD ABCD 1
	  TNT1 A 7
	  TNT1 A 0 A_PlaySound("strongmelee/miss", 5)
	  MPTM ABCDE 1
	  ML1F D 0 A_JumpIfInventory("PowerStrength",1,"SPMeleeBerserk")
	  MPTM F 1 A_CustomPunch(8,0,0,"StrongMeleePuff",90)
	  Goto SPMeleeA
	SPMeleeBerserk:
	  MPTM F 1 A_CustomPunch(16,0,0,"StrongMeleePuff",90)
	  Goto SPMeleeA
	SPMeleeA: 	  
	  MPTM GHI 1
	  TNT1 A 8
	  MPTS ABCD 1
	  Goto Ready
	Melee2:
	  MPTD ABCD 1
	  TNT1 A 7
	  TNT1 A 0 A_PlaySound("strongmelee/miss", 5)
	  MPTM JKLM 1
	  ML1F D 0 A_JumpIfInventory("PowerStrength",1,"Melee2Berserk")
	  MPTM N 1 A_CustomPunch(8,0,0,"StrongMeleePuff",90)
	  Goto Melee2A
	Melee2Berserk:
	  MPTM N 1 A_CustomPunch(16,0,0,"StrongMeleePuff",90)
	  Goto Melee2A
	Melee2A: 
	  MPTM OPQR 1
	  TNT1 A 8
	  MPTS ABCD 1
	  Goto Ready
	AutoModeMelee:
	  TNT1 A 0 A_Jump(88,"AutoModeMelee2")
	  ASTD ABCD 1
	  TNT1 A 7
	  TNT1 A 0 A_PlaySound("strongmelee/miss", 5)
	  MPTM ABCDE 1
	  ML1F D 0 A_JumpIfInventory("PowerStrength",1,"AutoModeMeleeBerserk")
	  MPTM F 1 A_CustomPunch(8,0,0,"StrongMeleePuff",90)
	  Goto AutoModeMeleeA
	AutoModeMeleeBerserk:
	  MPTM F 1 A_CustomPunch(16,0,0,"StrongMeleePuff",90)
	  Goto AutoModeMeleeA
	AutoModeMeleeA:  
	  MPTM GHI 1
	  TNT1 A 8
	  ASTU ABCD 1
	  Goto AutoReady
    AutoModeMelee2:
	  ASTD ABCD 1
	  TNT1 A 7
	  TNT1 A 0 A_PlaySound("strongmelee/miss", 5)
	  MPTM JKLM 1
	  ML1F D 0 A_JumpIfInventory("PowerStrength",1,"AutoModeMelee2Berserk")
	  MPTM N 1 A_CustomPunch(8,0,0,"StrongMeleePuff",90)
	  Goto AutoModeMelee2A
	AutoModeMelee2Berserk:
	  MPTM N 1 A_CustomPunch(16,0,0,"StrongMeleePuff",90)
	  Goto AutoModeMelee2A
	AutoModeMelee2A:
	  MPTM OPQR 1
	  TNT1 A 8
	  ASTU ABCD 1
	  Goto AutoReady
   }
}

ACTOR AutoPistolMag : Ammo
{
	+IGNORESKILL
	Inventory.MaxAmount 15
}

ACTOR AutoPistolFullAuto : Inventory
{
	Inventory.MaxAmount 1
}

ACTOR ShotsFiredPewPew : Ammo
{
	+IGNORESKILL
	Inventory.MaxAmount 15
}


ACTOR TSPPistolAmmo : Ammo Replaces Clip
{
	+IGNORESKILL
	Inventory.Amount 5
	Inventory.MaxAmount 150
	Ammo.BackpackAmount 15
	Ammo.BackpackMaxAmount 300
	Ammo.DropAmount 5
	Inventory.Icon "919AA0"
	Inventory.PickupMessage "Picked up a pistol magazine. [+5 Pistol Ammo]"
	Inventory.PickupSound "919m/magout"
	States
	{
	Spawn:
		919A A -1
		Stop
	}
}

ACTOR PistolPickup : CustomInventory Replaces Pistol 
{
    Inventory.PickupMessage "[Makoto Type 919 Mod.0] [Class: Pistol, Slot 2]"
	Inventory.PickupSound "misc/w_pkup"
	+INVENTORY.AUTOACTIVATE
	States
	{
	Spawn:
      919P A -1
	  Stop
	Pickup:
	  TNT1 A 0 A_JumpIfInventory("IsMel",1,"MelPickup")
	  TNT1 A 0 A_JumpIfInventory("IsVexler",1,"MelPickup")
	  Fail
	VexlerPickup:
	  TNT1 A 0 A_JumpIfInventory("Mel919mPistol", 1, "AmmoCheck")
	  TNT1 A 0 A_GiveInventory("Mel919mPistol", 1)
	  TNT1 A 0 A_GiveInventory("TSPPistolAmmo", 15)
	  TNT1 A 0 ACS_ExecuteAlways(859)
	  TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(860,1) >= 1,"PretendPickupFail")
	  TNT1 A 1 
	  Stop
	MelPickup:
	  TNT1 A 0 A_JumpIfInventory("Mel919mPistol", 1, "AmmoCheck")
	  TNT1 A 0 A_GiveInventory("Mel919mPistol", 1)
	  TNT1 A 0 A_GiveInventory("TSPPistolAmmo", 15)
	  TNT1 A 0 ACS_ExecuteAlways(859)
	  TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(860,1) >= 1,"PretendPickupFail")
	  TNT1 A 1 
	  Stop
	AmmoCheck:
      TNT1 A 1 A_JumpIf(ACS_ExecuteWithResult(860,1) >= 1,"PickupFail")
	  TNT1 A 0 A_JumpIfInventory("TSPPistolAmmo", 0, "PickupFail")
	  TNT1 A 0 A_GiveInventory("TSPPistolAmmo", 15)
	  Stop
	PretendPickupFail:
	  TNT1 A 0 ACS_ExecuteAlways(857,0,13)
      DCBP A 1
      Fail
	PickupFail:
      919P A 1
      Fail
	}
}

actor 919CoopBullet : FastProjectile
{
  Damage (Random(1, 3)*8)
  Radius 2
  Height 2
  Speed 320
  Projectile
  Renderstyle "Normal"
  Species "Player"
  +BLOODSPLATTER
  +THRUSPECIES
  +NOTIMEFREEZE
  +NOEXTREMEDEATH
  Alpha 1.0
  Decal Bulletchip
  States
  {
  Spawn:
    TNT1 A 1
    Loop
  Death:
    TNT1 A 1 A_SpawnItem("919mBulletPuff")
    Stop
  XDeath:
    TNT1 A 1
    Stop
  }
}

actor 919CoopBullet2 : 919CoopBullet
{
  Damage (Random(1, 3)*9)
}

ACTOR 919mBulletPuff : BulletPuff
{
    Decal BulletChip
    +NOEXTREMEDEATH
	+CLIENTSIDEONLY
}