ACTOR PDCrossbow : Weapon
{
  Weapon.Kickback 100
  Scale 0.1
  
  Tag "Crossbow"
        Weapon.Ammotype1 "CrossbowClip"
  Weapon.Ammotype2 "PDBolts"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 5
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a Crossbow."
  Obituary  "%k's Crossbow popped %o's juicy, watermelon-like head."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKA4 Z -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/Crossbowup","Weapon")
    TL15 ABCDEFGHIJKLMNOPQRSTUVXYZ 1
	TL16 ABCDEFGH 1
    TL16 I -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TL16 I 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+7
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("CrossbowClip",5,2)
	 KLBG A 0 A_JumpIfInventory("PDBolts",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+34

  ReloadStart:
     TL17 VXYZ 1
	 TL18 ABCDEFGHIJKLMNOPQRSTUVX 1
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/CrossbowReload")
	 TL18 YZ 1
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDBolts",1)
	 TNT1 A 0 A_GiveInventory("CrossbowClip",1)
	 TNT1 A 0 A_JumpIfInventory("CrossbowClip",1,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDBolts",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TL19 ABCDEFGHIJKLMNOPQRSTUVXYZ 1
	 TL20 A 1
	 Goto Ready+34
	
  Deselect:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/CrossbowAway","Weapon")
    TL17 GHIJKLMNOPQRSTU 1
    TK08 A 0 A_Lower
    wait
  Select: 
    TK08 A 0 A_Raise 
    Loop  
  Fire: 
  KLBG A 0 A_JumpIfNoAmmo("ReloadCheck")
 	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/CrossbowFire","Weapon")
    TL16 J 1 A_FireCustomMissile ("PDBoltFired")
    TL16 JKLMNOPQRSTUVXYZ 1
	TL17 ABCDEF 2
    Goto Ready+34
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

ACTOR PDCrossbowPickup : Custominventory
{
   Scale 0.1
  Inventory.PickupMessage "Picked up a Crossbow."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKA4 Z -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDCrossbow")
	  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 PDBoltFired
{
  obituary "%k's Crossbow popped %o's juicy, watermelon-like head."
  radius 8
  height 8
  speed 100
  damage 15
  Scale 0.030
  PROJECTILE
  +FORCEXYBILLBOARD
  +BLOODSPLATTER
  states
  {
  Spawn:
    TF03 A 6
    loop
  Death:
NULL A 0 A_SPAWNITEMEX("BulletPuff",0,0,0,random(0,0),random(0,0),0)
Stop
  }
}