//=====================================//
// DEAGLE AMMO (Primary)
//=====================================//

ACTOR DeaglePrimary : Ammo
{
  // Inventory.PickupMessage "$GOTCLIP" // "Picked up a clip."
  Inventory.Amount 1
  Inventory.MaxAmount 20
  Inventory.Icon "CLIPA0"
  +IGNORESKILL
}

//=====================================//
// DEAGLE AMMO (Secondary)
//=====================================//

ACTOR DeagleSecondary : Ammo
{
  // Inventory.PickupMessage "$GOTCLIP" // "Picked up a clip."
  Inventory.Amount 1
  Inventory.MaxAmount 100
  Ammo.BackpackAmount 1
  Ammo.BackpackMaxAmount 100
  Inventory.Icon "CLIPA0"
  +IGNORESKILL
}

//=====================================//
// DEAGLE WEAPON
//=====================================//

ACTOR DeagleEmpty : Inventory
{
	Inventory.MaxAmount 1
}

ACTOR DWDeagle : Weapon
{
  +WEAPON.NOAUTOAIM
  Weapon.BobStyle Smooth
  Weapon.BobSpeed 2.5
  Weapon.BobRangeX 0.5
  Weapon.BobRangeY 0.3
  Weapon.SelectionOrder 1900
  Weapon.AmmoUse 0
  Weapon.AmmoUse2 0
  Weapon.AmmoGive 0
  Weapon.AmmoGive2 20
  Weapon.AmmoType "DeaglePrimary"
  Weapon.AmmoType2 "DeagleSecondary"
  Obituary "%o was blasted by %k's Deagle."
  Inventory.Pickupmessage "Picked up a Desert Eagle."
  Tag "Desert Eagle"
  -DONTBOB
  States
  {
//--------------------------------//
// IDLE
//--------------------------------//
	Ready:
		DEGI A 0 A_JumpIfInventory("DeaglePrimary",1,1)
		Goto Ready_Empty
		PPSS A 0 A_JumpIfInventory("IsReloading",1,"ReloadCheck")
		DEGI A 1 A_WeaponReady
		Loop
	Ready_Empty:
		PPSS A 0 A_JumpIfInventory("IsReloading",1,"ReloadCheck")
		DEEI A 1 A_WeaponReady
		DEEI A 0 A_JumpIfInventory("DeaglePrimary",1,"Ready")
		Loop
//================================================================
  // RELOAD CHECKING
  //================================================================
  ReloadCheck:
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_JumpIfInventory("Perk_Rifleman",1,"RCP")
	 TNT1 A 0 A_JumpIfInventory("DeaglePrimary",10,"Ready")
	 TNT1 A 0 A_JumpIfInventory("DeagleSecondary",1,"Reloading")
	 Goto Ready
  RCP:
	 TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"RCP10")
	 TNT1 A 0 A_JumpIfInventory("DeaglePrimary",15,"Ready")
	 TNT1 A 0 A_JumpIfInventory("DeagleSecondary",1,"Reloading")
	 Goto Ready
  RCP10:
	 TNT1 A 0 A_JumpIfInventory("DeaglePrimary",20,"Ready")
	 TNT1 A 0 A_JumpIfInventory("DeagleSecondary",1,"Reloading")
	 Goto Ready
  //================================================================
//--------------------------------//
// SPRINTING
//--------------------------------//
	SprintStart:
		DEFI A 0 A_TakeInventory("StartSprint",1)
		DEFI A 0 A_GiveInventory("InSprintAnim",1)
		DESP ABC 1
		DESQ EDC 1
		Goto SprintLoop
		
	SprintLoop:
		DESQ BCDEFGHGFEDC 2 A_JumpIfInventory("StopSprint",1,"SprintEnd")
		Loop
		
	SprintEnd:
		TNT1 A 0 A_TakeInventory("StartSprint",1)
		TNT1 A 0 A_TakeInventory("StopSprint",1)
		MBPD A 0 A_TakeInventory("InSprintAnim",1)
		DESP CBA 1
		Goto ResetItems
//--------------------------------//
// SELECT / DESELECT
//--------------------------------//
	Deselect:
	DESS CBA 1
	TNT1 AAAAAAAAAAAAAAAAA 0 A_Lower
	TNT1 A 1 A_Lower
	Goto Deselect+3
	
	Select:
	TNT1 AA 0 A_Raise
	TNT1 A 1 A_WeaponReady
	Goto SelectAnim
	
	SelectAnim:
	TNT1 A 0 A_JumpIfInventory("DeaglePrimary",1,1)
	Goto SelectAnim_Empty
	TNT1 A 0 A_PlaySoundEx("deagle/deploy","SoundSlot6")
	DESS ABC 1 A_WeaponReady(WRF_NOFIRE)
	DESS D 2 A_WeaponReady(WRF_NOFIRE)
	Goto Ready
	
	SelectAnim_Empty:
	TNT1 A 0 A_PlaySoundEx("deagle/deploy","SoundSlot6")
	DESS ABC 1 A_WeaponReady(WRF_NOFIRE)
	DESS E 2 A_WeaponReady(WRF_NOFIRE)
	Goto Ready
//--------------------------------//
// FIRING
//--------------------------------//
	Fire:
	TNT1 A 0 A_JumpIfInventory("DeaglePrimary",1,"ActualFire")
	Goto Ready
	
	ActualFire:
	TNT1 A 0 A_JumpIfInventory("DeaglePrimary",2,1)
	Goto ActualFire_Empty
	TNT1 A 0 A_TakeInventory("DeaglePrimary",1)
    TNT1 A 0 A_FireBullets (1.6, 1.6, 1, 40, "BulletPuff2")
	TNT1 A 0 A_SpawnItemEx("ShakeYourAss",0,0,0)
	TNT1 A 0 A_PlaySoundEx("deagle/fire","Weapon")
	TNT1 A 0 A_AlertMonsters
	
	DEFI A 0 A_SetPitch(pitch-7.0)
    DEFI A 1 bright A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFI A 0 A_SetPitch(pitch+1.0)
	DEFI B 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFI A 0 A_SetPitch(pitch+1.0)
	DEFI B 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFI A 0 A_SetPitch(pitch+1.0)
	DEFI B 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFI A 0 A_SetPitch(pitch+1.0)
	DEFI C 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFI A 0 A_SetPitch(pitch+1.0)
	DEFI C 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFI A 0 A_SetPitch(pitch+1.0)
	DEFI D 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFI A 0 A_SetPitch(pitch-1.0)
	DEFI EFG 1 A_WeaponReady
    Goto ResetItems
	
	ActualFire_Empty:
	TNT1 A 0 A_FireBullets (2.6, 2.6, 1, 40, "BulletPuff2")
	TNT1 A 0 A_SpawnItemEx("ShakeYourAss",0,0,0)
	TNT1 A 0 A_PlaySoundEx("deagle/fire","Weapon")
	TNT1 A 0 A_TakeInventory("DeaglePrimary",1)
	TNT1 A 0 A_AlertMonsters
	
	DEFJ A 0 A_SetPitch(pitch-7.0)
    DEFJ A 1 bright A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFJ A 0 A_SetPitch(pitch+1.0)
	DEFJ B 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFJ A 0 A_SetPitch(pitch+1.0)
	DEFJ B 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFJ A 0 A_SetPitch(pitch+1.0)
	DEFJ B 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFJ A 0 A_SetPitch(pitch+1.0)
	DEFJ C 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFJ A 0 A_SetPitch(pitch+1.0)
	DEFJ C 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFJ A 0 A_SetPitch(pitch+1.0)
	DEFJ D 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	DEFJ A 0 A_SetPitch(pitch-1.0)
	DEFJ EFG 1 A_WeaponReady
    Goto ResetItems
//--------------------------------//
// RELOADING
//--------------------------------//
	AltFire:
	TNT1 A 0 A_JumpIfInventory("DeagleSecondary",1,1)
	Goto Ready
	TNT1 A 0 A_JumpIfInventory("DeaglePrimary",10,"Ready")
	TNT1 A 0 A_JumpIfInventory("DeaglePrimary",1,"Reloading")
	Goto Reloading_Empty
	
	Reloading:
	DERL A 0 A_JumpIfInventory("DeaglePrimary",1,1)
	Goto Reloading_Empty
	DERL ABCD 1
	DERL E 2
	DERL F 0 A_PlaySoundEx("deagle/clipout","SoundSlot6")
	DERL FGH 1
	DERL I 2
	DERL JKL 1
	DERL MNO 1
	DERL F 0 A_PlaySoundEx("deagle/deploy","SoundSlot6")
	DERL PQRS 1
	DERL TU 2
	DERL F 0 A_PlaySoundEx("deagle/clipin","SoundSlot6")
	Goto CalcAmmo
	
	Reloading_End:
	DERL VWXY 1
	DERL Z 3
	DERM A 2
	DERM BCDE 1
	Goto ResetItems
	
	Reloading_Empty:
	DESL A 0 A_GiveInventory("DeagleEmpty",1)
	DESL ABCD 1
	DESL E 2
	DESL F 0 A_PlaySoundEx("deagle/clipout","SoundSlot6")
	DESL FGH 1
	DESL I 2
	DESL JKL 1
	DESL MNO 1
	DESL F 0 A_PlaySoundEx("deagle/deploy","SoundSlot6")
	DESL PQRS 1
	DESL TU 2
	DESL F 0 A_PlaySoundEx("deagle/clipin","SoundSlot6")
	Goto CalcAmmo
	
	Reloading_Empty_End:
	DESL VWXY 1
	DESL Z 3
	DESM ACDEF 1
	DESM GH 2
	DESM I 0 A_PlaySoundEx("deagle/slideback","SoundSlot6")
	DESM IJ 1
	DESM K 4
	DESM I 0 A_PlaySoundEx("deagle/slidefwd","SoundSlot6")
	DESM MN 1
	DESM O 3
	DESM P 2
	DESM Q 3
	DERL Y 1
	DERM A 2
	DERM BCDE 1
	Goto ResetItems
	
	CalcAmmo:
	TNT1 A 0 A_JumpIfInventory("Perk_Rifleman",1,"CAP")
	TNT1 A 0 A_JumpIfInventory("DeaglePrimary",10,"EndReload")
	TNT1 A 0 A_JumpIfInventory("DeagleSecondary",1,1)
	Goto EndReload
	TNT1 A 0 A_TakeInventory("DeagleSecondary",1)
	TNT1 A 0 A_GiveInventory("DeaglePrimary",1)
	Loop
	
	CAP:
	TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"CAP10")
	TNT1 A 0 A_JumpIfInventory("DeaglePrimary",15,"EndReload")
	TNT1 A 0 A_JumpIfInventory("DeagleSecondary",1,1)
	Goto EndReload
	TNT1 A 0 A_TakeInventory("DeagleSecondary",1)
	TNT1 A 0 A_GiveInventory("DeaglePrimary",1)
	Loop
	
	CAP10:
	TNT1 A 0 A_JumpIfInventory("DeaglePrimary",20,"EndReload")
	TNT1 A 0 A_JumpIfInventory("DeagleSecondary",1,1)
	Goto EndReload
	TNT1 A 0 A_TakeInventory("DeagleSecondary",1)
	TNT1 A 0 A_GiveInventory("DeaglePrimary",1)
	Loop
	
	EndReload:
	TNT1 A 0 A_JumpIfInventory("DeagleEmpty",1,"Reloading_Empty_End")
	Goto Reloading_End
//--------------------------------//
// INVENTORY SHIT
//--------------------------------//

	ResetItems:
	TNT1 A 0 A_TakeInventory("IsMeleeing",1)
	TNT1 A 0 A_TakeInventory("StartSprint",1)
	TNT1 A 0 A_TakeInventory("StopSprint",1)
	TNT1 A 0 A_TakeInventory("IsReloading",1)
	TNT1 A 0 A_TakeInventory("DeagleEmpty",1)
	Goto Ready
	
	ResetItemsKnife:
	TNT1 A 0 A_TakeInventory("IsMeleeing",1)
	TNT1 A 0 A_TakeInventory("StartSprint",1)
	TNT1 A 0 A_TakeInventory("StopSprint",1)
	Goto SelectAnim

//--------------------------------//
// SPAWN STATE
//--------------------------------//
  Spawn:
    DGLE Z -1
    Stop
  }
}