
ACTOR RLMegatonShotgun : RLHeavyWeapon
{
  Obituary "%o was blown into next year by %k's megaton shotgun."
  Decal BulletChip
  Tag "Megaton Shotgun"
  Weapon.SelectionOrder 11
  Weapon.SlotNumber 3
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLMegatonShotgunClip"
  Weapon.AmmoType2 "Shell"
  Inventory.Icon "MEGSICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
    MEGS 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("PowerRLTechnicianMasterDamage", 1)
	TNT1 A 0 A_SpawnItemEx("RLMegatonShotgunPickup", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLMegatonShotgunSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLMegatonShotgun",1)
	Stop
  AfterModDrop:
    MEGS A 8 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
    MEGS 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("RLMegatonShotgunSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    MEGS 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("RLMasterAssemblyTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLShotgunTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLMegatonShotgunSelected", 1)
	TNT1 A 0 A_JumpIfInventory("RLScavengerPerk",1, 1)
    Goto SelectLoop
	TNT1 A 0 A_GiveInventory("PowerRLTechnicianMasterDamage", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    MEGS A 1 A_Raise
    Loop
	
  Fire:
	MEGS A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	MEGS A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	MEGS A 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	MEGS A 0 A_JumpIfInventory("RLRestrictionLowTechOnly",1,"LowTechRestricted") // Cannot fire in levels that restrict it
	MEGS A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfNoAmmo("Reload")
	TNT1 A 0 A_AlertMonsters
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "FireRenegade")
	TNT1 A 0 A_FireBullets (0, 0, 1, 20, "RLShotgunPuffCloseRange", FBF_NORANDOM, 128)
	TNT1 A 0 A_FireBullets (4.5, 1, 13, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireRenegade:
	TNT1 A 0 A_FireBullets (0, 0, 1, 20, "RLShotgunPuffCloseRange", FBF_NORANDOM, 128)
	TNT1 A 0 A_FireBullets (4.5, 1, 20, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLShotgunRecoil", 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 ("RLMegatonShotgunClip", 1, TIF_NOTAKEINFINITE)
    TNT1 A 0 A_TakeInventory ("RLRenegadeExtraShot", 1)
    TNT1 A 0 A_PlaySound("weapons/megatonshotgunsingle", CHAN_WEAPON, 1, 0, 0.6)
    TNT1 A 0 A_PlaySound("weapons/megatonshotgunsingle", 7, 0.05, 0, 0.20)
	TNT1 A 0 A_CheckFloor (2)
	TNT1 A 0 A_Jump(256,5)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingSteelBootsToken",1,4)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingProtectiveBootsToken",1,3)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingPlasteelBootsToken",1,2)
    TNT1 A 0 A_ChangeVelocity (Cos(Pitch) * -0.2, 0, Sin(Pitch) * 0.2, 1)
    MEGS E 2 Bright A_GunFlash
    MEGS F 2 Bright
    MEGS LM 2
  FireFinishContinue:
    TNT1 A 0 A_PlaySound("weapons/megatonshotgunspin", 7, 0.6, 0, 1.8)
    TNT1 A 0 A_SpawnItemEx ("RLMegatonShotgunSpinRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MEGS BCDAAA 1
    MEGS AAAAAAAA 1 A_Refire
    Goto Ready
	
  Reload:
	TNT1 A 0 A_JumpIfInventory("RLMegatonShotgunReloadSequence",1,"ReloadWorking")
	MEGS A 1 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	TNT1 A 0 A_JumpIfInventory("RLMegatonShotgunClip", 9, "Ready")
	TNT1 A 0 A_JumpIfInventory("Shell", 1, 1)
	Goto Ready
	TNT1 A 0 // Play the reload animation.
    MEGS M 2
    MEGS N 2
    MEGS O 2
    MEGS P 2
    MEGS Q 2
    MEGS R 2
    MEGS S 2
	TNT1 A 0 A_PlaySound("weapons/megatonshotgunopen", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MEGS T 2
    MEGS U 2
    MEGS V 2
	Goto ReloadWorking
  ReloadWorking:
	TNT1 A 0 A_GiveInventory("RLMegatonShotgunReloadSequence", 1)
	TNT1 A 0 A_JumpIfInventory("Shell",1,1)
	Goto ReloadFinish
	TNT1 A 0 A_TakeInventory("Shell", 1)
	TNT1 A 0 A_GiveInventory("RLMegatonShotgunClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLMegatonShotgunClip",9, "ReloadLoading")
	Goto ReloadLoading
  ReloadLoading:
	TNT1 A 0 A_PlaySound("weapons/megatonshotgunload", CHAN_ITEM)
    MEG2 A 1
    MEGS V 1
    TNT1 A 0 A_PlaySound("weapons/megatonshotgunspin", 7, 0.6, 0, 1.8)
    TNT1 A 0 A_SpawnItemEx ("RLMegatonShotgunSpinRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MEG2 B 1
    MEG2 C 1
    MEG2 D 1
    MEGS V 2
	TNT1 A 0 A_JumpIfInventory("RLMegatonShotgunClip",9, "ReloadFinish")
	TNT1 A 0 A_JumpIf(CallACS("DRLA_MultiReload") == 0, 2)
	TNT1 A 0 A_JumpIfInventory("RLSynthFireReload",1,"ReloadWorking")
	Goto ReloadFinish
	TNT1 A 0 A_Refire ("ReloadFinish")
	Goto ReloadWorking
  ReloadFinish:
	TNT1 A 0 A_TakeInventory("RLMegatonShotgunReloadSequence", 1)
    MEGS V 2
    MEGS U 2
    MEGS T 2
	TNT1 A 0 A_PlaySound("weapons/megatonshotgunclose", 7)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadInRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MEGS S 2
    MEGS R 2
    MEGS Q 2
    MEGS P 2
    MEGS O 2
    MEGS N 2
    MEGS M 2
    MEGS AAAAAAAA 1 A_Refire
	Goto Ready
	
  Flash:
    TNT1 A 2 A_Light1
    TNT1 A 2 A_Light2
    TNT1 A 0 A_Light0
    Goto LightDone
	
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLMegatonShotgunPickup",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")
	TNT1 A 0 A_JumpIfInventory("RLMegatonShotgunClip", 3, 1)
	Goto Reload
	TNT1 A 0 A_AlertMonsters
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "AltFireRenegade")
	TNT1 A 0 A_FireBullets (0, 0, 3, 80, "RLQuadImpactPuff", FBF_NORANDOM, 128)
	TNT1 A 0 A_FireBullets (12.5, 5.5, 39, 6, "RLBulletPuff", 0)
    Goto AltFireFinish
  AltFireRenegade:
	TNT1 A 0 A_FireBullets (0, 0, 3, 80, "RLQuadImpactPuff", FBF_NORANDOM, 128)
	TNT1 A 0 A_FireBullets (12.5, 5.5, 59, 6, "RLBulletPuff", 0)
    Goto AltFireFinish
  AltFireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLRocketLauncherRecoil", 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 ("RLMegatonShotgunClip", 3, TIF_NOTAKEINFINITE)
    TNT1 A 0 A_TakeInventory ("RLRenegadeExtraShot", 1)
    TNT1 A 0 A_PlaySound("weapons/megatonshotgun", CHAN_WEAPON, 1, 0, 0.4)
    TNT1 A 0 A_PlaySound("weapons/megatonshotgun", 7, 0.05, 0, 0.10)
	TNT1 A 0 A_CheckFloor (2)
	TNT1 A 0 A_Jump(256,5)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingSteelBootsToken",1,4)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingProtectiveBootsToken",1,3)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingPlasteelBootsToken",1,2)
    TNT1 A 0 A_ChangeVelocity (Cos(Pitch) * -20, 0, Sin(Pitch) * 20, 1)
    MEGS I 2 Bright A_GunFlash
    MEGS J 2 Bright
    MEGS KLM 2
  AltFireFinishContinue:
    TNT1 A 0 A_PlaySound("weapons/megatonshotgunspin", 7, 0.6, 0, 1.8)
    TNT1 A 0 A_SpawnItemEx ("RLMegatonShotgunSpinRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MEGS BCDAA 1
    TNT1 A 0 A_PlaySound("weapons/megatonshotgunspin", 7, 0.6, 0, 1.8)
    TNT1 A 0 A_SpawnItemEx ("RLMegatonShotgunSpinRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MEGS BCDAA 1
    TNT1 A 0 A_PlaySound("weapons/megatonshotgunspin", 7, 0.6, 0, 1.8)
    TNT1 A 0 A_SpawnItemEx ("RLMegatonShotgunSpinRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MEGS BCDAAA 1
    MEGS AAAAAAAA 1 A_Refire
	
    Goto Ready
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
    TNT1 A 0 A_GiveInventory("RLMegatonShotgunAssemblyLearntToken", 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("RLMegatonShotgunSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
	TNT1 A 0 A_Jump(256,1,2,3,4)
	TNT1 A 0 A_FireCustomMissile("DroppedRLBulkMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLBulkMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLBulkMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLFirestormMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLMegatonShotgun",1)
	Stop
  }
}

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

Actor RLMegatonShotgunSelected : RLPermanentInventory {}
Actor RLMegatonShotgunReloadSequence : RLPermanentInventory {}

ACTOR RLMegatonShotgunClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 9
   Inventory.Icon ""
}

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

ACTOR RLMegatonShotgunPickup : RLMasterAssembledWeaponPickup
{
	//$Sprite MEGSX0
	Tag "Megaton Shotgun [Pickup]"
	States
	{
	SpawnFrame:
		MEGS 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/gundropbig")
		"####" "#" 0 A_ScaleVelocity (0.25)
		"####" "#" 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("RLMegatonShotgun",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("RLMegatonShotgun",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvMegaton 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= Megaton Shotgun =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/MegatonShotgunpickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonShells",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	SuperweaponStuff:
		"####" "#" 0 A_Jump(256, "NoSpecialStartsStuff")
		Goto NoSpecialStartsStuff
	}
}

ACTOR RLMegatonShotgunWorldSpawnPickup : RLMegatonShotgunPickup 17836
{
	States
	{
	NoSpecialStartsStuff:
		TNT1 A 0 A_JumpIf(CallACS("DRLA_opengl"), 3) // If enabled, rarity beam will be cyan, rather than blue
		TNT1 A 0 A_SpawnItemEx("RLRarityBeamAssembledWorld", 0, 0, 0, 0, 0, 0, 0, SXF_SETMASTER)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_SpawnItemEx("RLRarityBeamAssembledWorldDRPG", 0, 0, 0, 0, 0, 0, 0, SXF_SETMASTER)
		TNT1 A 0 A_JumpIf(CallACS("DRPGCheckTiem"), "DRPGInit")
	SpawnFrame:
		MEGS X 4
		"####" "#" 0 A_GiveInventory("RLMasterItemSpawnMessageSender",1)
		"####" "#" 0 A_PlaySound("weapons/masterspawned", 7, 0.25, 0, 0)
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
		
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLMegatonShotgun",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvMegaton Shotgun.")
		"####" "#" 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
		Goto PickupSound
	}
}
