ACTOR PDDevastator : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "Devastator"
        Weapon.Ammotype1 "DevastatorClip"
  Weapon.Ammotype2 "PDGrenadeRoundAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 8
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a Devastator."
  Obituary  "%k detonated %o's fucking stupid FACE."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKA4 U -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TK99 A 2 
    TK99 B 2
    TK99 C 2
    TK99 D 2
    TK99 EFG 2
    TK99 H -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TK99 H 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+9
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("DevastatorClip",8,2)
	 KLBG A 0 A_JumpIfInventory("PDGrenadeRoundAmmo",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+9

  ReloadStart:
	 
     TL01 VXYZ 1
	 TL02 ABCDE 1
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/DevastatorReload")
	 TL02 FGHIJKLMNOPQRSTUVXYZ 1
	 TL52 ABCDEFGHIJKLMNOPQRST 1
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDGrenadeRoundAmmo",1)
	 TNT1 A 0 A_GiveInventory("DevastatorClip",1)
	 TNT1 A 0 A_JumpIfInventory("DevastatorClip",8,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDGrenadeRoundAmmo",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TL52 UVXYZ 1
	 TL03 ABCDEFGHIJK 1
	 Goto Ready+9
	
  Deselect:
    TL01 RSTU 2
    TK08 A 0 A_Lower
    wait
  Select: 
    TK08 A 0 A_Raise 
    Loop  
  Fire: 
  KLBG A 0 A_JumpIfNoAmmo("ReloadCheck")
  TK99 IJ 2
 	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/Devastator","Weapon")
    TK99 K 1 Bright A_FireCustomMissile ("PDDevastatorGrenade")
    TK99 LMNOPQRSTUVXYZ 1
	TL01 ABCDEFGHIJKLMNOPQ 1 
    Goto Ready+9
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

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

actor PDDevastatorGrenade
{
  Radius 8
  Height 8
  PROJECTILE
  Speed 30
  Damage 100
  Scale 0.030
  BounceCount 3
  BounceFactor 0.5
  Gravity 0.6
  DamageType Grenade
  +HEXENBOUNCE
  +FORCEXYBILLBOARD
  -NOGRAVITY
    Obituary  "%k detonated %o's fucking stupid FACE."
  States
  {
  Spawn:
	TF04 A 0
	TF04 A 0 Thing_ChangeTID(0, 255)
	TF04 A 0 ThrustThingZ(0, 10, 0, 1)
	TF04 A 0 A_StopSound
	TF04 A 1 A_SpawnItemEx("PDDevastatorGrenadeTrail", Random(-2,2), Random(-2,2), Random(-2,2), 0, 0, 0, 0, 128, 0)
	goto Spawn+4
  Death:
	MISL B 0 bright A_Explode(64, 128, 1)
	MISL B 0 A_NoGravity
	TNT1 A 0 radius_quake(2, 10, 0, 3, 0)
	TNT1 A 0 A_PlaySoundEx("PerfectDark/Weapons/Boom", "Auto", 0)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris1", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-5, 5), Random(-5, 5), Random(-6, 7), Random(-360, 360), 128, 24)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris2", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-5, 5), Random(-5, 5), Random(-6, 7), Random(-360, 360), 128, 24)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris3", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-5, 5), Random(-5, 5), Random(-6, 7), Random(-360, 360), 128, 24)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris4", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-5, 5), Random(-5, 5), Random(-6, 7), Random(-360, 360), 128, 24)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris5", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-5, 5), Random(-5, 5), Random(-6, 7), Random(-360, 360), 128, 24)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris1", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-3, 3), Random(-3, 3), Random(1, 6), Random(-360, 360), 128, 24)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris2", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-3, 3), Random(-3, 3), Random(1, 6), Random(-360, 360), 128, 24)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris3", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-3, 3), Random(-3, 3), Random(1, 6), Random(-360, 360), 128, 24)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris4", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-3, 3), Random(-3, 3), Random(1, 6), Random(-360, 360), 128, 24)
	TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx("Debris5", Random(-8, 8), Random(-8, 8), Random(-8, 8), Random(-3, 3), Random(-3, 3), Random(1, 6), Random(-360, 360), 128, 24)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", 0, 0, 0, 0, 0, 0, 0, 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke2", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke2", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke2", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke2", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke2", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke2", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke2", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke2", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke2", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 AAAAAAA 5 A_SpawnItemEx ("RollingExplosion2", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	stop
  }
}

actor PDDevastatorGrenadeTrail
{
  Projectile
  Radius 1
  Height 1
  Damage 0
  Speed 0
  Scale 0.08
  RenderStyle Add
  Alpha 0.6
  +NOCLIP
  +FORCEXYBILLBOARD
  States
  {
   Spawn:
   TNT1 A 0
   TNT1 A 2
   SMOK ABCDEFGHIJKLMNOPQ 1
   stop
  }
}