//Flashbangs! wooooooooo
actor Flashbang : AOWWeapon {
    Weapon.BobSpeed 1.75
    Weapon.BobRangeX 0.2
    Weapon.BobRangeY 0.4
    Weapon.BobStyle Alpha
    +NOEXTREMEDEATH
    +NOALERT 
    inventory.pickupmessage "Picked up a flashbang."
    Weapon.kickback 50
    Weapon.AmmoType "FlashbangAmmo"
    Weapon.AmmoUse 1
    Weapon.AmmoGive 1
	Weapon.AmmoType2 "FlashbangPower"
	Weapon.AmmoUse2 0
	Weapon.AmmoGive2 0	
    Weapon.UpSound "weapons/up/flashbang"	
	Weapon.PreferredSkin "MarineFist"
    Obituary "$OB_FLASHBANG"
	DropItem "FlashbangItem"	
    States {
	Select:
	    FLSH A 1 offset (90,100)
		FLSH A 1 offset (80,89)
		FLSH A 1 offset (70,79)
		FLSH A 1 offset (60,70)
		FLSH A 1 offset (50,62)
		FLSH A 1 offset (40,55)
		FLSH A 1 offset (30,49)
		FLSH A 1 offset (20,44)
		FLSH A 1 offset (15,40)
		FLSH A 1 offset (10,37)
		FLSH A 1 offset (5,34)
		FLSH A 1 offset (0,0)
		TNT1 A 0 A_TakeInventory("SelectAnimation",1)
		goto ready
    Deselect:
	    TNT1 A 0 A_TakeInventory("ActionFragGrenade",1)	
        TNT1 A 0 A_TakeInventory("ActionFlashbang",1)
        TNT1 A 0 A_TakeInventory("ActionRemoteC4",1)	
        TNT1 A 0 A_TakeInventory("ActionMeleeAttack",1)
		TNT1 A 0 A_TakeInventory("ActionReload",1)	
	    TNT1 A 0 A_JumpIfNoAmmo ("DeselectNoAmmo")
		FLSH A 1 offset (0,34)
		FLSH A 1 offset (0,40)
		FLSH A 1 offset (0,49)
		FLSH A 1 offset (0,62)
		FLSH A 1 offset (0,79)
		FLSH A 1 offset (0,100)
		TNT1 A 0 offset (0,33)
		TNT1 A 0 A_Lower
		Wait
	DeselectNoAmmo:
    	/*TNT1 A 0 A_Lower
	    TNT1 A 1 A_Lower
	    loop*/	
		TNT1 A 0 A_TakeInventory("Flashbang")
		Stop
	Ready:
	    TNT1 A 0 A_JumpIfInventory("SelectAnimation",1,"Select")
	    TNT1 A 0 A_JumpIfInventory("ActionFragGrenade",1,"UseFragGrenade")
		TNT1 A 0 A_JumpIfInventory("ActionFlashbang",1,"UseFlashbang")
		TNT1 A 0 A_JumpIfInventory("ActionRemoteC4",1,"UseRemoteC4")
		TNT1 A 0 A_JumpIfInventory("ActionMeleeAttack",1,"UseMeleeAttack")
		TNT1 A 0 A_JumpIfNoAmmo ("ReadyNoAmmo")
		FLSH A 1 A_WeaponReady
		loop
	ReadyNoAmmo:
        TNT1 A 0 A_JumpIfInventory("FlashbangAmmo",1,"Ready")		
		TNT1 A 1 A_WeaponReady
		loop
    Fire:
        TNT1 A 0 A_JumpIfInventory("IsInSpawnRoom",1,"Ready")
        TNT1 A 0 A_JumpIfInventory ("InMenu", 1, "Ready") 
		TNT1 A 0 A_TakeInventory ("FlashbangPower", 100)
        FLSH BCDEFGHIJKLMN 1
		FLSH OPQR 1 
		FLSH S 1 A_ReFire
		FSH1 A 1
        FSH1 A 0 A_PlaySound("flash/flashthrow", CHAN_WEAPON)		
		FSH1 A 0 A_FireCustomMissile("FlashbangThrown",0,1,0,0)		
        FSH1 A 0 A_TakeInventory ("FlashbangPower", 100)
        FSH1 BCD 1
        FSH1 E 1 A_CheckReload
        Goto Select
	Hold:
		TNT1 A 0 A_JumpIfInventory ("IsInSpawnRoom", 1, "ClearItem")
		TNT1 A 0 A_JumpIfInventory ("InMenu", 1, "ClearItem")
		TNT1 A 2 A_GiveInventory ("FlashbangPower", 3)
		TNT1 A 1 A_ReFire
		TNT1 A 3
		TNT1 A 0 A_JumpIfInventory ("FlashbangPower", 100, "Throw10")
		TNT1 A 0 A_JumpIfInventory ("FlashbangPower", 90, "Throw9")		
		TNT1 A 0 A_JumpIfInventory ("FlashbangPower", 80, "Throw8")		
		TNT1 A 0 A_JumpIfInventory ("FlashbangPower", 70, "Throw7")		
		TNT1 A 0 A_JumpIfInventory ("FlashbangPower", 60, "Throw6")
		TNT1 A 0 A_JumpIfInventory ("FlashbangPower", 50, "Throw5")		
		TNT1 A 0 A_JumpIfInventory ("FlashbangPower", 40, "Throw4")
		TNT1 A 0 A_JumpIfInventory ("FlashbangPower", 30, "Throw3")		
		TNT1 A 0 A_JumpIfInventory ("FlashbangPower", 20, "Throw2")
        FSH1 A 1
		FLSH D 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FLSH D 0 A_FireCustomMissile ("FlashbangThrown", -1, 1, 10, 5)
	FireEnd:
		TNT1 A 0 A_TakeInventory ("FlashbangPower", 100)
        FSH1 BCD 1
		FSH1 E 1 A_CheckReload
        Goto Ready
	FireEnd2:
		TNT1 A 0 A_TakeInventory ("FlashbangPower", 100)
        FSH2 BCDEFGH 1
		FSH2 I 1 A_CheckReload	
		goto Ready
	ClearItem:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory ("FlashbangPower", 100)
		Goto Ready
	Throw2:
        FSH1 A 1
		FSH1 A 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FSH1 A 0 A_FireCustomMissile ("FlashbangThrown2", -1, 1, 10, 5)
		goto FireEnd
	Throw3:
        FSH1 A 1		
		FSH1 A 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FSH1 A 0 A_FireCustomMissile ("FlashbangThrown3", -1, 1, 10, 5)
		goto FireEnd
	Throw4:
        FSH2 A 1
		FSH2 A 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FSH2 A 0 A_FireCustomMissile ("FlashbangThrown4", -1, 1, 10, 15)
		goto FireEnd2
	Throw5:
	    FSH2 A 1
		FSH2 A 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FSH2 A 0 A_FireCustomMissile ("FlashbangThrown5", -1, 1, 10, 15)
		goto FireEnd2		
	Throw6:
		FSH2 A 1
		FSH2 A 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FSH2 A 0 A_FireCustomMissile ("FlashbangThrown6", -1, 1, 10, 15)
		goto FireEnd2
	Throw7:
	    FSH2 A 1
		FSH2 A 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FSH2 A 0 A_FireCustomMissile ("FlashbangThrown7", -1, 1, 10, 15)
		goto FireEnd2
	Throw8:
	    FSH2 A 1	
		FSH2 A 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FSH2 A 0 A_FireCustomMissile ("FlashbangThrown8", -1, 1, 10, 15)
		goto FireEnd2
	Throw9:
	    FSH2 A 1
		FSH2 A 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FSH2 A 0 A_FireCustomMissile ("FlashbangThrown9", -1, 1, 10, 15)
		goto FireEnd2
	Throw10:
	    FSH2 A 1
		FSH2 A 0 A_PlaySound ("flash/flashthrow", CHAN_WEAPON)
		FSH2 A 0 A_FireCustomMissile ("FlashbangThrown10", -1, 1, 10, 15)
		goto FireEnd2			
	Spawn:
		TNT1 A 0
		stop			
   }
}

actor FlashbangPower : Ammo {
	+IGNORESKILL
	inventory.amount 0
	inventory.maxamount 100
	ammo.backpackamount 0
	ammo.backpackmaxamount 100
}

actor Flashed : Inventory
{
    inventory.amount 0
    inventory.maxamount 1
}

//Check this to use Flashbang Grenades
actor ThrowFlashbang : Inventory
{
    inventory.amount 0
    inventory.maxamount 1
}

// =============================================================================
actor FlashbangThrown {
    Obituary "$OB_FLASHBANG"
    Radius 5
    Height 5	
    Speed 17	
    Damage (0)	
    PROJECTILE
    -NOGRAVITY
    +HEXENBOUNCE
    +NOEXTREMEDEATH
    +FORCERADIUSDMG
    +CANBOUNCEWATER
    +BOUNCEONACTORS
    +ROCKETTRAIL
    +FORCEXYBILLBOARD	
    Scale 0.16
    Gravity 0.4	
    Bouncefactor 0.4
    Wallbouncefactor 0.5
	ReactionTime 2
    Seesound "flash/flashbounce"
    DamageType "Flash"
    States {
    Spawn:
        FBGT ABCDEFG 3
        FBGT H 3 A_Countdown
        loop
    Death:
 	    TNT1 A 0 A_PlaySound ("flash/flash")
        TNT1 A 0 A_Explode(20,384)
        TNT1 A 0 A_SpawnItemEx("FlashbangFlare", 0, 0, 0, 0, 0, 0, 0, 128, 0)
        TNT1 A 5 A_SpawnItemEx("FlashbangFlare", 0, 0, 0, 0, 0, 0, 0, 128, 0)
        stop
  }
}

actor FlashbangFlare
{
  RenderStyle Add
  alpha 0.9
  -RANDOMIZE
  +NOCLIP
  +NOGRAVITY
  Scale 5.0
  states
  {
    Spawn:
        PPCX AAAAAAAAA 2 bright A_FadeOut(0.15)
        stop
  }
}

ACTOR FlashbangItem : CustomInventory
{
   Inventory.Amount 1
   Inventory.MaxAmount 1
   Inventory.PickupSound "frag/pinpull"
   Inventory.PickupMessage "Picked up a flashbang."
   Scale 0.15
   +FLOORCLIP
   States
   {
   Spawn:
      FLSH X 1
      Loop
   Pickup:
	  TNT1 A 0 A_JumpIfInventory("Flashbang",1,"GiveAmmo")
	  Goto GiveItem
   GiveAmmo:
      TNT1 A 0 A_GiveInventory("FlashbangAmmo",1)
      Stop
   GiveItem:
      TNT1 A 0 A_GiveInventory("Flashbang")
	  Stop
   } 
}

// =============================================================================
actor FlashbangDropped : FlashbangThrown {Speed 10}
actor FlashbangThrown2 : FlashbangThrown {Speed 21}
actor FlashbangThrown3 : FlashbangThrown {Speed 24}
actor FlashbangThrown4 : FlashbangThrown {Speed 27}
actor FlashbangThrown5 : FlashbangThrown {Speed 30}
actor FlashbangThrown6 : FlashbangThrown {Speed 33}
actor FlashbangThrown7 : FlashbangThrown {Speed 36}
actor FlashbangThrown8 : FlashbangThrown {Speed 39}
actor FlashbangThrown9 : FlashbangThrown {Speed 42}
actor FlashbangThrown10 : FlashbangThrown {Speed 45}