
ACTOR RLHeavyHuntingShotgun : RLWeapon
{
  Obituary "%o was brought down by %k's heavy hunting shotgun."
  Decal BulletChip
  Tag "Heavy Hunting Shotgun"
  Weapon.SelectionOrder 1500
  Weapon.SlotNumber 3
  Weapon.AmmoUse1 2
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLHeavyHuntingShotgunClip"
  Weapon.AmmoType2 "Shell"
  Inventory.Icon "HUNTICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
    HUNT A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
	
  ScavengerDrop:
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop",1,"WeaponDropConfirm")
	TNT1 A 0 A_GiveInventory("RLScavengerDrop",1)
	TNT1 A 0 A_Print("Press again to drop current weapon,\nor press \crAlt Fire\c- to scrap it to retrieve a Mod Pack.")
	Goto AfterModDrop
  WeaponDropConfirm:
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_TakeInventory("RLWeaponDrop",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianBasicDamage", 1)
	TNT1 A 0 A_SpawnItemEx("RLHeavyHuntingShotgunPickup", 0, 0, 40, 12, 0, 0, 0, SXF_SETMASTER)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHeavyHuntingShotgunSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLHeavyHuntingShotgun",1)
	Stop
  AfterModDrop:
    HUNT A 8 A_WeaponReady (WRF_ALLOWRELOAD)
    Goto Ready
  MisfirePrevention:
    HUNT A 1 A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
    Goto Ready
	
  Deselect:
	TNT1 A 0
	TNT1 A 0 A_GiveInventory("RLDeselectionFunction",1)
	TNT1 A 0 A_TakeInventory("RLHeavyHuntingShotgunSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianBasicDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    TNT1 A 0 A_Lower
    HUNT A 1 A_Lower
    Loop
  DeselectRenegade:
    TNT1 A 0 A_Lower
    loop
  SelectRenegade: 
    TNT1 A 0 A_Raise
    loop
  SelectSetWeapon:
	TNT1 A 0 A_GiveInventory("RLSuperiorAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLShotgunTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLHeavyHuntingShotgunSelected", 1)
	TNT1 A 0 A_JumpIfInventory("RLScavengerPerk",1, 1)
    Goto SelectLoop
	TNT1 A 0 A_GiveInventory("PowerRLTechnicianBasicDamage", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    TNT1 A 0 A_Raise
    HUNT A 1 A_Raise
    Loop
  Fire:
	HUNT A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	HUNT A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	HUNT A 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	HUNT A 0 A_JumpIfInventory("RLRestrictionHighTechOnly",1,"HighTechRestricted") // Cannot fire in levels that restrict it
	HUNT A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfInventory("RLHeavyHuntingShotgunClip", 2, 1)
	Goto Reload
	TNT1 A 0 A_AlertMonsters
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "FireRenegade")
	TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_FireBullets (4, 2, -1, (random(2,3)*6), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireRenegade:
	TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_FireBullets (4, 2, -1, (random(2,3)*6), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLDoubleShotgunRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_JumpIfInventory ("RLRenegadeExtraShot", 1, 2)
    TNT1 A 0 A_TakeInventory ("RLHeavyHuntingShotgunClip", 2)
    TNT1 A 0 A_TakeInventory ("RLRenegadeExtraShot", 1)
    TNT1 A 0 A_PlaySound("weapons/heavyhuntingshotgun", CHAN_WEAPON, 1, 0, 0.6)
    TNT1 A 0 A_PlaySound("weapons/heavyhuntingshotgun", 7, 0.05, 0, 0.20)
    HUNT B 3 Bright A_GunFlash
    HUNT C 3 Bright
    HUNT D 3
	TNT1 A 0 A_JumpIf(CallACS("DRLA_AutoReload"), "Reload")
    Goto Ready
  Reload:
	TNT1 A 0 A_JumpIfInventory("Shell",2,1)
	Goto Ready
	TNT1 A 0 A_JumpIfInventory("RLHeavyHuntingShotgunClip",2,"Ready")
	HUNT A 1 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	TNT1 A 0 // Play the reload animation.
    HUNT E 2
    HUNT F 2
    HUNT G 2
    HUNT H 2
    HUNT I 2
    HUNT J 2
    HUNT K 2
	TNT1 A 0 A_PlaySound("weapons/heavyhuntingshotgunopen", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLDoubleShotgunReloadDownRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
	TNT1 A 4
    HUNT L 2
    HUNT M 2
    HUNT N 2
	Goto ReloadWorking
  ReloadWorking:
	TNT1 A 0 A_TakeInventory("Shell", 2, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_GiveInventory("RLHeavyHuntingShotgunClip", 2)
	TNT1 A 0
  ReloadFinish:
    HUNT O 2 A_PlaySound("weapons/heavyhuntingshotgunload", CHAN_WEAPON)
    HUNT P 2
	TNT1 A 4
    TNT1 A 0 A_SpawnItemEx ("RLDoubleShotgunReloadUpRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    HUNT K 2 A_PlaySound("weapons/heavyhuntingshotgunclose", CHAN_ITEM)
    HUNT J 2
    HUNT I 2
    HUNT H 2
    HUNT G 2
    HUNT F 2
    HUNT E 1
    HUNT Q 1
    HUNT A 3
    HUNT A 7 A_ReFire
	Goto Ready
	
  Flash:
    TNT1 A 3 A_Light1
    TNT1 A 3 A_Light2
    TNT1 A 0 A_Light0
    Goto LightDone
	
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLHeavyHuntingShotgunPickup",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION, 0, tid)
    Stop
  Altfire:
	TNT1 A 0 A_JumpIfInventory("RLArmorModItemActivate",1, "ArmorModConversion")
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop",1,"ScavengerTime")
	Goto Ready
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
    TNT1 A 0 A_GiveInventory("RLHeavyShotgunAssemblyLearntToken", 1) // Assembly is now listed in the HUD menus
	TNT1 A 0 A_Print("Mod pack extracted from discarded weapon.")
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHeavyHuntingShotgunSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianBasicDamage", 1)
	TNT1 A 0 A_FireCustomMissile("DroppedRLBulkMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLHeavyHuntingShotgun",1)
	Stop
  }
}

//-------------------------------------------------------------------
//		MECHANICS

Actor RLHeavyHuntingShotgunSelected : RLPermanentInventory {}

ACTOR RLHeavyHuntingShotgunClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 2
   Inventory.Icon ""
}

//-------------------------------------------------------------------
//		PICKUPS

ACTOR RLHeavyHuntingShotgunPickup : RLBasicAssembledWeaponPickup 17406
{
	//$Sprite HUNTX0
	Tag "Heavy Hunting Shotgun [Pickup]"
	States
	{
	SpawnFrame:
		HUNT X 4
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
	SpawnLoop:
		"####" "#" 0 A_JumpIf(Abs(VelZ) <= 0.01 && user_floorhit == 0, "FloorHit")
		"####" "#" 1
		Loop
	FloorHit:
		"####" "#" 0 A_PlaySound("weapons/gundropmedium")
		"####" "#" 0 A_ScaleVelocity (0.5)
		"####" "#" 0 A_ChangeFlag("SPECIAL", true)
		"####" "#" 0 A_ChangeFlag("THRUACTORS", false)
		"####" "#" 0 A_SetUserVar("user_floorhit", 1)
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Stop
	Pickup:
		"####" "#" 0
		"####" "#" 0 A_JumpIfInventory("RLHeavyHuntingShotgun",1,"NotPickup") // If the player already has this weapon, they are not given the weapon
		"####" "#" 0 A_JumpIfInventory("RLWeaponLimit",0,"NotPickupLimit") // The absolute max limit check for weapons
		"####" "#" 0 A_Jump(256, "GiveWeapon")
		Goto GiveWeapon
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLHeavyHuntingShotgun",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvHeavy Hunting Shotgun.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_Jump(256, "NotPickup")
		Goto NotPickup
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= Heavy Hunting Shotgun =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/HeavyHuntingShotgunpickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonShells",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	}
}
