ACTOR PDDragon : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "Dragon"
        Weapon.Ammotype1 "DragonClip"
  Weapon.Ammotype2 "PDRifleAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 30
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a Dragon."
  Obituary  "%k cancelled %o with his Dragon."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKA4 K -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TK59 A 2 
    TK59 B 2
    TK59 C 2
    TK59 D 2
    TK59 E 2
    TK59 F -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TK59 F 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+7
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("DragonClip",30,2)
	 KLBG A 0 A_JumpIfInventory("PDRifleAmmo",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+7

  ReloadStart:
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/DragonReload")
     TK59 YZ 2
	 TK60 ABCDEFGHIJKLMNOPQRS 1
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDRifleAmmo",1)
	 TNT1 A 0 A_GiveInventory("DragonClip",1)
	 TNT1 A 0 A_JumpIfInventory("DragonClip",30,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDRifleAmmo",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TK60 TUVXYZ 1
	 TK61 ABCDEFGHIJKLMNOPQRSTUVXYZ 1
	 Goto Ready+7
	
  Deselect:
    TK59 TUVX 2
    TK08 A 0 A_Lower
    wait
	  Deselect2:
    NULL A 1 A_Lower
    loop
  Select: 
    TK08 A 0 A_Raise 
    Loop  
  Fire: 
  KLBG A 0 A_JumpIfNoAmmo("ReloadCheck")
 	TNT1 A 0 A_PlayWeaponSound ("PerfectDark/Weapons/Dragon")
    TK59 H 1 BRIGHT A_FireBullets(1, 2, 1, 12, "BulletPuff",FBF_USEAMMO)
    TK59 I 2
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDPointedBulletCasing", 25,cos(pitch)*4,sin(-pitch)*0+30, frandom(0.5,1.2),frandom(-2.5,1.2),frandom(1.5,2.5))
	TK59 J 2 A_REFIRE
	TK59 K 2 
	TK59 L 2 
	TK59 M 2
	TK59 NOPQRS 2 
    Goto Ready+7
	AltFire:
	TK59 TUVX 2
	NULL A 10
	TNT1 A 0 A_PlayWeaponSound ("PerfectDark/Weapons/Throw")
    NULL A 2 A_FireCustomMissile ("PDFakeDragonPickup")
    NULL A 20
    NULL A 4 A_TakeInventory ("PDDragon",1)
    goto deselect2
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

ACTOR PDDragonPickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a Dragon."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKA4 K -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDDragon")
	  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 PDFakeDragonPickup
{
  obituary "%o tried to pick up %k's Dragon and it exploded in his face."
  radius 20
  height 5
  speed 30
  damage 20
  bouncefactor 0.0
  Scale 0.050
  PROJECTILE
  +HEXENBOUNCE
  -NOGRAVITY
  +NODAMAGETHRUST
  +FORCERADIUSDMG
  states
  {
  Spawn:
    TKA4 K 1
    loop
  Death:
	MISL B 0 bright A_Explode
	TNT1 A 0 radius_quake(2, 10, 0, 3, 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 ("RollingExplosion3", 0, 0, 0, 0, 0, 0, 0, 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 A 0 A_SpawnItemEx ("ExplosionSmoke", Random(-44, 44), Random(-44, 44), Random(0, 38), 0, 0, 0, 0, 128, 0)
	TNT1 A 3 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	TNT1 AAAAAAA 5 A_SpawnItemEx ("RollingExplosion3", Random(-24, 24), Random(-24, 24), Random(0, 38), 0, 0, 0, Random(-360, 360), 0, 0)
	stop
  }
}
