
ACTOR RLStormBlaster : RLPistolWeapon
{
  Obituary "%o was jolted by %k's storm blaster."
  Decal BulletChip
  Tag "Storm Blaster"
  Weapon.SelectionOrder 1899
  Weapon.SlotNumber 3
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLStormBlasterClip"
  Inventory.Icon "BLASICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
    Goto NanoRegenCheck
  NanoRegenCheck:
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",1,2)
    SBLA C 70 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	Goto NanoRegenCheckBegin
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",10,4)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",5,2)
    SBLA C 10 A_WeaponReady (WRF_ALLOWZOOM)
	Goto NanoRegenCheckBegin
    SBLA B 10 A_WeaponReady (WRF_ALLOWZOOM)
	Goto NanoRegenCheckBegin
    SBLA A 10 A_WeaponReady (WRF_ALLOWZOOM)
	Goto NanoRegenCheckBegin
  NanoRegenCheckBegin:
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip", 15, "Ready")
	Goto NanoRegen
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip", 20, "Ready")
	Goto NanoRegen
  NanoRegen:
	TNT1 A 0 A_GiveInventory("RLStormBlasterClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",10,4)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",5,2)
    SBLA C 6 A_WeaponReady (WRF_ALLOWZOOM)
	Goto NanoRegenCheckBegin
    SBLA B 6 A_WeaponReady (WRF_ALLOWZOOM)
	Goto NanoRegenCheckBegin
    SBLA A 6 A_WeaponReady (WRF_ALLOWZOOM)
    Goto NanoRegenCheckBegin
	
  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("PowerRLTechnicianAdvancedDamage", 1)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterModLimit", 1, "WeaponDropModded")
	TNT1 A 0 A_SpawnItemEx("RLStormBlasterPickup", 0, 0, 40, 16, 0, 0, 0, SXF_SETMASTER)
	Goto WeaponDropRemoval
  WeaponDropModded:
	TNT1 A 2 A_SpawnItemEx("RLStormBlasterPickupModded", 0, 0, 40, 16, 0, 0, 0, SXF_SETMASTER)
  WeaponDropRemoval:
    TNT1 A 0 A_TakeInventory("RLStormBlasterModLimit", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterPowerMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterBulkMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterAgilityMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterSniperMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterFirestormMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterNanoMod", 1)
	TNT1 A 0 A_TakeInventory("RLStormBlasterSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 1 A_TakeInventory("RLStormBlaster",1)
	Stop
  AfterModDrop:
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",10,4)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",5,2)
    SBLA C 8 A_WeaponReady (16)
	Goto Ready
    SBLA B 8 A_WeaponReady (16)
	Goto Ready
    SBLA A 8 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",10,6)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",5,3)
    SBLA C 1 A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
	Goto Ready
    SBLA B 1 A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
	Goto Ready
    SBLA 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("RLStormBlasterSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianAdvancedDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    TNT1 AA 0 A_Lower
    SBLA D 1 A_Lower
    Loop
  DeselectRenegade:
    TNT1 A 0 A_Lower
    loop
  SelectRenegade: 
    TNT1 A 0 A_Raise
    loop
  SelectSetWeapon:
	TNT1 A 0 A_GiveInventory("RLAdvancedAssemblyTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLPistolTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLShotgunTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLRechargingAmmoWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLStormBlasterSelected", 1)
	TNT1 A 0 A_JumpIfInventory("RLScavengerPerk",1, 1)
    Goto SelectLoop
	TNT1 A 0 A_GiveInventory("PowerRLTechnicianAdvancedDamage", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    TNT1 AA 0 A_Raise
    SBLA D 1 A_Raise
    Loop
// 7x damage with Scout, half spread
  Fire:
	SBLA A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	SBLA A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	SBLA A 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	SBLA A 0 A_JumpIfInventory("RLRestrictionLowTechOnly",1,"LowTechRestricted") // Cannot fire in levels that restrict it
	SBLA A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfNoAmmo("Ready")
	Goto FireBegin
  FireBegin:
	TNT1 A 0 A_AlertMonsters
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterSniperMod",1,"FireS")
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterPowerMod",1,"FireP")
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterAgilityMod",1,"FireA")
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "FireRenegade")
	TNT1 A 0 A_JumpIfInventory("RLSharpshooterPerk",1,2)
	TNT1 A 0 A_FireBullets (6.5, 4, 2, (random(1,7)*6), "RLLaserPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (3.25, 2, 2, (42), "RLLaserPuff", FBF_NORANDOM | FBF_USEAMMO)
    Goto FireFinish
  FireRenegade:
	TNT1 A 0 A_FireBullets (6.5, 4, 3, (random(1,7)*6), "RLLaserPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
  FireP:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "FireRenegadeP")
	TNT1 A 0 A_JumpIfInventory("RLSharpshooterPerk",1,2)
	TNT1 A 0 A_FireBullets (6.5, 4, 2, (random(1,7)*7), "RLLaserPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (3.25, 2, 2, (49), "RLLaserPuff", FBF_NORANDOM | FBF_USEAMMO)
    Goto FireFinish
  FireRenegadeP:
	TNT1 A 0 A_FireBullets (6.5, 4, 3, (random(1,7)*7), "RLLaserPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
  FireA:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "FireRenegadeA")
	TNT1 A 0 A_JumpIfInventory("RLSharpshooterPerk",1,2)
	TNT1 A 0 A_FireBullets (6, 4, 2, (random(1,7)*6), "RLLaserPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (3, 2, 2, (42), "RLLaserPuff", FBF_NORANDOM | FBF_USEAMMO)
    Goto FireFinish
  FireRenegadeA:
	TNT1 A 0 A_FireBullets (6, 4, 3, (random(1,7)*6), "RLLaserPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
  FireS:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "FireRenegadeS")
	TNT1 A 0 A_JumpIfInventory("RLSharpshooterPerk",1,2)
	TNT1 A 0 A_FireBullets (4.5, 2, 2, (random(1,7)*6), "RLLaserPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (2.25, 1, 2, (42), "RLLaserPuff", FBF_NORANDOM | FBF_USEAMMO)
    Goto FireFinish
  FireRenegadeS:
	TNT1 A 0 A_FireBullets (4.5, 2, 3, (random(1,7)*6), "RLLaserPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_PlaySound("weapons/blaster", CHAN_WEAPON)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterFirestormMod",1,"FireFinishF1")
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",10,4)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",5,2)
    SBLA G 3 Bright A_GunFlash
	Goto FireFinishFinal
    SBLA F 3 Bright A_GunFlash
	Goto FireFinishFinal
    SBLA E 3 Bright A_GunFlash
	Goto FireFinishFinal
  FireFinishF1:
	TNT1 A 0 A_JumpIfInventory("RLBlasterClip",10,4)
	TNT1 A 0 A_JumpIfInventory("RLBlasterClip",5,2)
    SBLA G 2 Bright A_GunFlash
	Goto FireFinishFinal
    SBLA F 2 Bright A_GunFlash
	Goto FireFinishFinal
    SBLA E 2 Bright A_GunFlash
	Goto FireFinishFinal
  FireFinishFinal:
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterFirestormMod",1,"FireFinishFinalF1")
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",10,4)
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterClip",5,2)
    SBLA C 8
	Goto Ready
    SBLA B 8
	Goto Ready
    SBLA A 8
	Goto Ready
  FireFinishFinalF1:
	TNT1 A 0 A_JumpIfInventory("RLBlasterClip",10,4)
	TNT1 A 0 A_JumpIfInventory("RLBlasterClip",5,2)
    SBLA C 6
	Goto Ready
    SBLA B 6
	Goto Ready
    SBLA A 6
	Goto Ready
  Flash:
    TNT1 A 2 A_Light2
    TNT1 A 1 A_Light1
    Goto LightDone
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLStormBlasterPickup",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
  ModDiscombobulation:
	TNT1 A 0 A_Print("Applied Mod pack extracted from discarded weapon.")
	TNT1 A 0 ACS_NamedExecuteAlways("ScavengeMods", 0)
	TNT1 A 3
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterModLimit", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterPowerMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterBulkMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterAgilityMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterSniperMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterFirestormMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterNanoMod", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLStormBlasterSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianAdvancedDamage", 1)
	Goto ScavengerTimeEnd
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
    TNT1 A 0 A_GiveInventory("RLStormPistolAssemblyLearntToken", 1) // Assembly is now listed in the HUD menus
	TNT1 A 0 A_JumpIfInventory("RLStormBlasterModLimit",1,"ModDiscombobulation")
	TNT1 A 0 A_Print("Mod pack extracted from discarded weapon.")
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterModLimit", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterPowerMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterBulkMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterAgilityMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterSniperMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterFirestormMod", 1)
    TNT1 A 0 A_TakeInventory("RLStormBlasterNanoMod", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLStormBlasterSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianAdvancedDamage", 1)
	TNT1 A 0 A_Jump(256,1,2,3)
	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("DroppedRLTechnicalMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLStormBlaster",1)
	Stop
  }
}

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

Actor RLStormBlasterSelected : RLPermanentInventory {}
Actor RLStormBlasterModLimit : RLAdvancedAssemblyModAmount {}
Actor RLStormBlasterPowerMod : RLAdvancedAssemblyModAmount {}
Actor RLStormBlasterBulkMod : RLAdvancedAssemblyModAmount {}
Actor RLStormBlasterAgilityMod : RLAdvancedAssemblyModAmount {}
Actor RLStormBlasterNanoMod : RLAdvancedAssemblyModAmount {}
Actor RLStormBlasterFirestormMod : RLAdvancedAssemblyModAmount {}
Actor RLStormBlasterSniperMod : RLAdvancedAssemblyModAmount {}

ACTOR RLStormBlasterClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 20
   Inventory.Icon ""
}

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

ACTOR RLStormBlasterPickup : RLAdvancedAssembledWeaponPickup 17625
{
	//$Sprite BLASX0
	Tag "Storm Blaster [Pickup]"
	States
	{
	SpawnFrame:
		BLAS 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/gundropsmall")
		"####" "#" 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("RLStormBlaster",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("RLStormBlaster",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvStorm Blaster.")
		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= Storm Blaster =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/StormBlasterpickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonShells",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	}
}

ACTOR RLStormBlasterPickupModded : RLStormBlasterPickup
{
	+INVENTORY.TRANSFER
	+DONTGIB
	States
	{
	Spawn:
		TNT1 A 0 NoDelay ACS_NamedExecuteAlways("GetWeaponMods", 0)
		TNT1 A 0 A_JumpIf(CallACS("DRLA_specialstarts") == 0, "NoSpecialStartsStuff")
		"####" "#" 0 A_Jump(256, "SpecialStartsStuff")
		Goto SpecialStartsStuff
		
	SpawnFrame:
		BLAS X 4
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
	SpawnLoop:
		"####" "#" 0 A_JumpIf(VelZ <= 0.01 && user_floorhit == 0, "FloorHit")
		"####" "#" 0 ACS_NamedExecuteAlways("RLWeaponModDisplay", 0)
		"####" "#" 1
		Loop
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLStormBlaster",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cbmodded \cvStorm Blaster.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= Storm Blaster =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("RLStormBlasterModLimit", 1, "NotPickup_Modded")
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= Storm Blaster =\n\n\ccYou replace your unmodded\n\ccweapon with the one you picked up.", 5, "CONFONT")
		Goto PickupSound
	NotPickup_Modded:
		"####" "#" 0 A_Print("\cv= Storm Blaster =\n\n\caYou are already carrying a modded\n\caweapon of this type", 5, "CONFONT")
		Fail
	}
}
