
ACTOR RLParticleBeamCannon : RLHeavyWeapon
{
  Inventory.Pickupsound "weapons/unique"
  Obituary "%o discombobulated %k with a particle beam."
  Tag "Particle Beam Cannon"
  Weapon.Kickback 100
  Weapon.SelectionOrder 1900
  Weapon.SlotNumber 7
  Weapon.AmmoUse1 15
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLParticleBeamCannonClip"
  Weapon.AmmoType2 "Cell"
  Inventory.Icon "PBCNICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
    TNT1 A 0 A_PlaySound("weapons/particlebeamcannonidle", 6, 1, 1)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonNanoMod",1,"ReadyNano")
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
    PBCN A 5 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
  ReadyNano:
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 30, "ReadyCantAltFire")
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop", 1, "ReadyCanAltFire")
	TNT1 A 0 A_JumpIfInventory("RLArmorModItemActivate", 1, "ReadyCanAltFire")
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
    PBCN A 5 A_WeaponReady (WRF_NOFIRE | WRF_ALLOWZOOM)
	Goto ReadyChargingAmmo
  ReadyCanAltFire:
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
    PBCN A 5 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	Goto ReadyChargingAmmo
  ReadyCantAltFire:
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop", 1, "ReadyCanFire")
	TNT1 A 0 A_JumpIfInventory("RLArmorModItemActivate", 1, "ReadyCanFire")
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
    PBCN A 5 A_WeaponReady (WRF_NOSECONDARY | WRF_ALLOWZOOM)
	Goto ReadyCycleCharged
  ReadyCanFire:
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
    PBCN A 5 A_WeaponReady (WRF_ALLOWZOOM)
	Goto ReadyCycleCharged
//=================================================================================
  ReadyCycleCharging:
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 30, "ReadyBeep")
	Goto ReadyChargingAmmo
  ReadyChargingAmmo:
	TNT1 A 0 A_GiveInventory("RLParticleBeamCannonClip", 1)
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop", 1, "ReadyChargingAmmo2")
	TNT1 A 0 A_JumpIfInventory("RLArmorModItemActivate", 1, "ReadyChargingAmmo2")
    PBCN A 5 A_WeaponReady (WRF_NOFIRE | WRF_ALLOWZOOM)
    Goto ReadyCycleCharging
  ReadyChargingAmmo2:
    PBCN A 5 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
    Goto ReadyCycleCharging
//=================================================================================
  ReadyCycleCharged:
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 90, "Ready")
	Goto ReadyChargedAmmo
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 117, "Ready")
	Goto ReadyChargedAmmo
  ReadyChargedAmmo:
	TNT1 A 0 A_GiveInventory("RLParticleBeamCannonClip", 1)
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop", 1, "ReadyChargedAmmo2")
	TNT1 A 0 A_JumpIfInventory("RLArmorModItemActivate", 1, "ReadyChargedAmmo2")
    PBCN A 5 A_WeaponReady (WRF_NOSECONDARY | WRF_ALLOWZOOM)
    Goto ReadyCycleCharged
  ReadyChargedAmmo2:
    PBCN A 5 A_WeaponReady (WRF_ALLOWZOOM)
    Goto ReadyCycleCharged
//=================================================================================
  ReadyBeep:
	TNT1 A 0 A_PlaySound("weapons/particlebeamcannonbeep", 7)
    TNT1 A 0
    Goto ReadyCycleCharged
	
  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_StopSound(6)
    TNT1 A 0 A_GunFlash ("FlashDrop", GFF_NOEXTCHANGE)
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_TakeInventory("RLWeaponDrop",1)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonModLimit", 1, "WeaponDropModded")
	TNT1 A 0 A_SpawnItemEx("RLParticleBeamCannonPickup", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
	Goto WeaponDropRemoval
  WeaponDropModded:
	TNT1 A 2 A_SpawnItemEx("RLParticleBeamCannonPickupModded", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
  WeaponDropRemoval:
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonModLimit", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonPowerMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonBulkMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonAgilityMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonTechnicalMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonSniperMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonFirestormMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonNanoMod", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLParticleBeamCannonSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLParticleBeamCannon",1)
	Stop
	
  AfterModDrop:
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
    PBCN A 5 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
    PBCN 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_StopSound(6)
    TNT1 A 0 A_GunFlash ("FlashDrop", GFF_NOEXTCHANGE)
	TNT1 A 0 A_GiveInventory("RLDeselectionFunction",1)
	TNT1 A 0 A_TakeInventory("RLParticleBeamCannonSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    PBCN A 1 A_Lower
    Goto DeselectLoop
  DeselectRenegade:
    TNT1 A 0 A_Lower
    loop
  SelectRenegade: 
    TNT1 A 0 A_Raise
    loop
  SelectSetWeapon:
	TNT1 A 0 A_GiveInventory("RLEfficientAmmoTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLUniqueWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLParticleBeamCannonSelected", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    PBCN A 1 A_Raise
    Loop
	
  Fire:
	
	PBCN A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	PBCN A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	PBCN A 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	PBCN A 0 A_JumpIfInventory("RLRestrictionLowTechOnly",1,"LowTechRestricted") // Cannot fire in levels that restrict it
	PBCN A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonSniperMod",1,4)
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1, 2)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 30, "FireAmmoCheckDone")
	Goto Reload
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 15, "FireAmmoCheckDone")
	Goto Reload
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1, 2)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 90, "FireAmmoCheckDone")
	Goto Reload
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 45, "FireAmmoCheckDone")
	Goto Reload
  FireAmmoCheckDone:
    TNT1 A 0 A_PlaySound("weapons/particlebeamcannoncharge", 5)
    TNT1 A 0 A_GunFlash ("FlashCharge", GFF_NOEXTCHANGE)
	TNT1 A 0 A_JumpIf(CallACS("DRLA_Fancyprojectiles") == 1, "FireAmmoCheckDone.Fancy")
    PBCN C 3
    PBCN D 3
    PBCN E 3
    PBCN F 3
    PBCN G 3
    TNT1 A 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN H 3
    TNT1 A 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN G 1
    TNT1 A 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN H 1
    PBCN G 1
    TNT1 A 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN H 1
    TNT1 AA 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN G 1
    TNT1 AAA 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN H 1
	Goto FireStart
  FireAmmoCheckDone.Fancy:
    PBCN C 3
    PBCN D 3 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN E 3 
    PBCN F 3 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN G 3
    PBCN H 3 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN G 1
    PBCN H 1 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    "####" "##" 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.85, 0, "none", -2)
    PBCN G 1
    "####" "###" 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.95, 0, "none", -2)
    PBCN H 1 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 1, 0, "RLParticleBeamCannonFocusingLaser1", 4)
    "####" "####" 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 1.15, 0, "none", -2)
    PBCN G 1 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 1, 0, "RLParticleBeamCannonFocusingLaser2", 4)
    "####" "#####" 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 1.25, 0, "none", -2)
    PBCN H 1 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 1, 0, "RLParticleBeamCannonFocusingLaser3", 4)
    "####" "#######" 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 1.45, 0, "none", -2)
	Goto FireStart
  FireStart:
	TNT1 A 0 A_AlertMonsters
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonFirestormMod",1,"FireF")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonSniperMod",1,"FireS")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonPowerMod",1,"FireP")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonAgilityMod",1,"FireA")
	
	TNT1 A 0 A_JumpIf(CallACS("DRLA_Fancyprojectiles") == 0, 4)
	TNT1 A 0 //A_SpawnItemEx("RLParticleBeamCannonFinalFlash",25,0,45+(sin(-pitch)*pitch))
	TNT1 A 0 A_RailAttack (random(800,1000), 0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff", 0, 0, 0, 1, 0.75, 0, "RLParticleBeamCannonFancyCore", -2)
	TNT1 A 0 A_RailAttack (0,				  0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.8, 0, "RLParticleBeamCannonFancyTrail", -2)
	Goto FireMoreFiring
    TNT1 A 0 A_RailAttack (random(800,1000), 0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff", 0, 0, 0, 1, 0.1, 1, "RLParticleBeamCannonCore", -2)
	Goto FireMoreFiring
  FireMoreFiring:
	TNT1 A 0 A_TakeInventory ("RLParticleBeamCannonClip", 15, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,"FireFinish")
	TNT1 A 0 A_TakeInventory ("RLParticleBeamCannonClip", 15, TIF_NOTAKEINFINITE)
    Goto FireFinish
  FireF:
	TNT1 A 0 A_JumpIf(CallACS("DRLA_Fancyprojectiles") == 0, 4)
	TNT1 A 0 //A_SpawnItemEx("RLParticleBeamCannonFinalFlash",25,0,45)
	TNT1 A 0 A_RailAttack (random(400,500), 0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff", 0, 0, 0, 1, 0.75, 0, "RLParticleBeamCannonFancyCore", -2)
	TNT1 A 0 A_RailAttack (0,				0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.8, 0, "RLParticleBeamCannonFancyTrail", -2)
	Goto FMFF
    TNT1 A 0 A_RailAttack (random(400,500), 0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff", 0, 0, 0, 1, 0.1, 1, "RLParticleBeamCannonCore", -2)
	Goto FMFF
  FMFF:
	TNT1 A 0 A_FireCustomMissile("RLParticleBeamCannonSingularity", 0, 0)
	TNT1 A 0 A_TakeInventory ("RLParticleBeamCannonClip", 15, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,"FireFinish")
	TNT1 A 0 A_TakeInventory ("RLParticleBeamCannonClip", 15, TIF_NOTAKEINFINITE)
    Goto FireFinish
  FireA:
  FireP:
	TNT1 A 0 A_JumpIf(CallACS("DRLA_Fancyprojectiles") == 0, 4)
	TNT1 A 0 //A_SpawnItemEx("RLParticleBeamCannonFinalFlash",25,0,45)
	TNT1 A 0 A_RailAttack (random(960,1200), 0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff", 0, 0, 0, 1, 0.75, 0, "RLParticleBeamCannonFancyCore", -2)
	TNT1 A 0 A_RailAttack (0,				  0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.8, 0, "RLParticleBeamCannonFancyTrail", -2)
	Goto FMFP
    TNT1 A 0 A_RailAttack (random(960,1200), 0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff", 0, 0, 0, 1, 0.1, 1, "RLParticleBeamCannonCore", -2)
	Goto FMFP
  FMFP:
	TNT1 A 0 A_TakeInventory ("RLParticleBeamCannonClip", 15, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,"FireFinish")
	TNT1 A 0 A_TakeInventory ("RLParticleBeamCannonClip", 15, TIF_NOTAKEINFINITE)
    Goto FireFinish
  FireS:
	TNT1 A 0 A_JumpIf(CallACS("DRLA_Fancyprojectiles") == 0, 4)
	TNT1 A 0 //A_SpawnItemEx("RLParticleBeamCannonFinalFlash",25,0,45)
	TNT1 A 0 A_RailAttack (random(2400,3000), 0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonSniperPuff", 0, 0, 0, 1, 0.98, 0, "RLParticleBeamCannonFancyBigCore", -2)
	TNT1 A 0 A_RailAttack (0,				  0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.8, 0, "RLParticleBeamCannonFancyTrail", -2)
	Goto FMFS
    TNT1 A 0 A_RailAttack (random(2400,3000), 0, 0, "None", White, RGF_SILENT | RGF_FULLBRIGHT, 0, "RLParticleBeamCannonPuff", 0, 0, 0, 1, 0.1, 1, "RLParticleBeamCannonCore", -2)
	Goto FMFS
  FMFS:
	TNT1 A 0 A_TakeInventory ("RLParticleBeamCannonClip", 45, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,"FireFinish")
	TNT1 A 0 A_TakeInventory ("RLParticleBeamCannonClip", 45, TIF_NOTAKEINFINITE)
    Goto FireFinish
	
  FireFinish:
    TNT1 A 0 A_PlaySound("weapons/particlebeamcannon", CHAN_WEAPON)
    TNT1 A 0 A_SpawnItemEx ("RLBFG9000Recoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 AAAAAAAA 0 A_RailAttack (0, 0, 0, "none", White, RGF_SILENT | RGF_FULLBRIGHT, 50, "RLParticleBeamCannonPuff2", 0, 0, 0, 1, 0.75, 0, "none", -2)
    PBCN I 4 Bright A_GunFlash
    PBCN JK 4 Bright
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
    PBCN A 5
    Goto Ready
	
  Reload:
    TNT1 A 0 A_GunFlash ("FlashAmmo", GFF_NOEXTCHANGE)
	PBCN A 5 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonNanoMod",1,"Ready")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 90, "Ready")
	Goto ReloadStartingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 171, "Ready")
  ReloadStartingAmmoCheck:
	TNT1 A 0 A_JumpIfInventory("Cell", 1, 1)
	Goto Ready
  ReloadSequence:
	TNT1 A 0 // Play the reload animation.
	TNT1 A 0 A_StopSound(6)
    TNT1 A 0 A_SpawnItemEx ("RLHeavyReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonTechnicalMod",1,"Reload1")
    TNT1 A 0 A_PlaySound("weapons/particlebeamcannonunload", CHAN_ITEM)
    PBCN L 2
    PBCN A 2
    PBCN M 2
    PBCN N 2
    PBCN O 2
    PBCN P 2
    PBCN Q 2
    TNT1 A 35
	Goto ReloadWorking
  Reload1:
    TNT1 A 0 A_PlaySound("weapons/particlebeamcannonunload", CHAN_ITEM)
    PBCN L 2
    PBCN A 2
    PBCN M 2
    PBCN N 2
    PBCN O 2
    PBCN P 2
    PBCN Q 2
    TNT1 A 32
  ReloadWorking:
	TNT1 A 0 A_TakeInventory("Cell", 1)
	TNT1 A 0 A_GiveInventory("RLParticleBeamCannonClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip",90,3)
	Goto ReloadWorkingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip",171,2)
  ReloadWorkingAmmoCheck:
	TNT1 A 0 A_JumpIfInventory("Cell",1,2)
	TNT1 A 0
	Goto ReloadFinish
	TNT1 A 0
	Goto ReloadWorking
  ReloadFinish:
    TNT1 A 0 A_PlaySound("weapons/particlebeamcannonactivate", 7)
    TNT1 A 0 A_SpawnItemEx ("RLHeavyReloadInRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonTechnicalMod",1,"ReloadFinish1")
	PBCN Q 2
	PBCN P 2
	PBCN O 2
    PBCN N 2
    PBCN M 2
    PBCN A 2
    PBCN L 2
    PBCN A 2
	Goto Ready
  ReloadFinish1:
	PBCN Q 2
	PBCN P 2
	PBCN O 2
    PBCN N 2
    PBCN M 2
    PBCN A 2
    PBCN L 2
    PBCN A 2
	Goto Ready
	
  Flash:
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 90, "Flash7")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 80, "Flash6")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 70, "Flash5")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 60, "Flash4")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 45, "Flash3")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 30, "Flash2")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 15, "Flash1")
    Goto LightDone
  Flash1:
    PBCG H 4 Bright A_Light (5)
    PBCG A 4 Bright A_Light (3)
    PBCG A 4 Bright A_Light (1)
    Goto LightDone
  Flash2:
    PBCG I 4 Bright A_Light (5)
    PBCG B 4 Bright A_Light (3)
    PBCG B 4 Bright A_Light (1)
    Goto LightDone
  Flash3:
    PBCG J 4 Bright A_Light (5)
    PBCG C 4 Bright A_Light (3)
    PBCG C 4 Bright A_Light (1)
    Goto LightDone
  Flash4:
    PBCG K 4 Bright A_Light (5)
    PBCG D 4 Bright A_Light (3)
    PBCG D 4 Bright A_Light (1)
    Goto LightDone
  Flash5:
    PBCG L 4 Bright A_Light (5)
    PBCG E 4 Bright A_Light (3)
    PBCG E 4 Bright A_Light (1)
    Goto LightDone
  Flash6:
    PBCG M 4 Bright A_Light (5)
    PBCG F 4 Bright A_Light (3)
    PBCG F 4 Bright A_Light (1)
    Goto LightDone
  Flash7:
    PBCG N 4 Bright A_Light (5)
    PBCG G 4 Bright A_Light (3)
    PBCG G 4 Bright A_Light (1)
    Goto LightDone
	
  FlashAmmo:
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 90, 13)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 80, 11)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 70, 9)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 60, 7)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 45, 5)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 30, 3)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 15, 1)
    Goto LightDone
    PBCG A 5 Bright A_Light0
    Goto LightDone
    PBCG B 5 Bright A_Light0
    Goto LightDone
    PBCG C 5 Bright A_Light0
    Goto LightDone
    PBCG D 5 Bright A_Light0
    Goto LightDone
    PBCG E 5 Bright A_Light0
    Goto LightDone
    PBCG F 5 Bright A_Light0
    Goto LightDone
    PBCG G 5 Bright A_Light0
    Goto LightDone
  FlashCharge:
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 90, "FlashCharge6")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 80, "FlashCharge5")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 70, "FlashCharge4")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 60, "FlashCharge3")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 45, "FlashCharge2")
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonClip", 30, "FlashCharge1")
    Goto LightDone
  FlashCharge1:
    PBC1 A 3 Bright A_Light0
    PBC2 A 3 Bright A_Light0
    PBC3 A 3 Bright A_Light0
    PBC4 A 3 Bright A_Light0
    PBC5 A 3 Bright A_Light0
    PBC6 A 3 Bright A_Light0
    PBC5 A 1 Bright A_Light0
    PBC6 A 1 Bright A_Light0
    PBC5 A 1 Bright A_Light0
    PBC6 A 1 Bright A_Light0
    PBC5 A 1 Bright A_Light0
    PBC6 A 1 Bright A_Light0
    Goto LightDone
  FlashCharge2:
    PBC1 B 3 Bright A_Light0
    PBC2 B 3 Bright A_Light0
    PBC3 B 3 Bright A_Light0
    PBC4 B 3 Bright A_Light0
    PBC5 B 3 Bright A_Light0
    PBC6 B 3 Bright A_Light0
    PBC5 B 1 Bright A_Light0
    PBC6 B 1 Bright A_Light0
    PBC5 B 1 Bright A_Light0
    PBC6 B 1 Bright A_Light0
    PBC5 B 1 Bright A_Light0
    PBC6 B 1 Bright A_Light0
    Goto LightDone
  FlashCharge3:
    PBC1 C 3 Bright A_Light0
    PBC2 C 3 Bright A_Light0
    PBC3 C 3 Bright A_Light0
    PBC4 C 3 Bright A_Light0
    PBC5 C 3 Bright A_Light0
    PBC6 C 3 Bright A_Light0
    PBC5 C 1 Bright A_Light0
    PBC6 C 1 Bright A_Light0
    PBC5 C 1 Bright A_Light0
    PBC6 C 1 Bright A_Light0
    PBC5 C 1 Bright A_Light0
    PBC6 C 1 Bright A_Light0
    Goto LightDone
  FlashCharge4:
    PBC1 D 3 Bright A_Light0
    PBC2 D 3 Bright A_Light0
    PBC3 D 3 Bright A_Light0
    PBC4 D 3 Bright A_Light0
    PBC5 D 3 Bright A_Light0
    PBC6 D 3 Bright A_Light0
    PBC5 D 1 Bright A_Light0
    PBC6 D 1 Bright A_Light0
    PBC5 D 1 Bright A_Light0
    PBC6 D 1 Bright A_Light0
    PBC5 D 1 Bright A_Light0
    PBC6 D 1 Bright A_Light0
    Goto LightDone
  FlashCharge5:
    PBC1 E 3 Bright A_Light0
    PBC2 E 3 Bright A_Light0
    PBC3 E 3 Bright A_Light0
    PBC4 E 3 Bright A_Light0
    PBC5 E 3 Bright A_Light0
    PBC6 E 3 Bright A_Light0
    PBC5 E 1 Bright A_Light0
    PBC6 E 1 Bright A_Light0
    PBC5 E 1 Bright A_Light0
    PBC6 E 1 Bright A_Light0
    PBC5 E 1 Bright A_Light0
    PBC6 E 1 Bright A_Light0
    Goto LightDone
  FlashCharge6:
    PBC1 F 3 Bright A_Light0
    PBC2 F 3 Bright A_Light0
    PBC3 F 3 Bright A_Light0
    PBC4 F 3 Bright A_Light0
    PBC5 F 3 Bright A_Light0
    PBC6 F 3 Bright A_Light0
    PBC5 F 1 Bright A_Light0
    PBC6 F 1 Bright A_Light0
    PBC5 F 1 Bright A_Light0
    PBC6 F 1 Bright A_Light0
    PBC5 F 1 Bright A_Light0
    PBC6 F 1 Bright A_Light0
    Goto LightDone
  FlashDrop:
    TNT1 A 0 A_Light0
    Goto LightDone
	
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLParticleBeamCannonPickup",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 0 A_StopSound(6)
    TNT1 A 0 A_GunFlash ("FlashDrop", GFF_NOEXTCHANGE)
	TNT1 A 3
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonModLimit", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonPowerMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonBulkMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonAgilityMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonTechnicalMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonSniperMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonFirestormMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonNanoMod", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLParticleBeamCannonSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	Goto ScavengerTimeEnd
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
	TNT1 A 0 A_JumpIfInventory("RLParticleBeamCannonModLimit",1,"ModDiscombobulation")
	TNT1 A 0 A_Print("Mod pack extracted from discarded weapon.")
	TNT1 A 0 A_StopSound(6)
    TNT1 A 0 A_GunFlash ("FlashDrop", GFF_NOEXTCHANGE)
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonModLimit", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonPowerMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonBulkMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonAgilityMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonTechnicalMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonSniperMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonFirestormMod", 1)
    TNT1 A 0 A_TakeInventory("RLParticleBeamCannonNanoMod", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLParticleBeamCannonSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_GiveInventory("RLEmitScavengedModUnique", 1) // Determines what mods this can generate when scavenged.
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLParticleBeamCannon",1)
	Stop
  }
}

//-------------------------------------------------------------------
//		PROJECTILES

ACTOR RLParticleBeamCannonFocusingLaser1
{
	//Translation "192:207=168:184"
	Renderstyle Add
	Scale 0.15
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			NKON I 2
			Stop
	}
}
ACTOR RLParticleBeamCannonFocusingLaser2 : RLParticleBeamCannonFocusingLaser1
{
	States
	{
		Spawn:
			NKOS C 2
			Stop
	}
}
ACTOR RLParticleBeamCannonFocusingLaser3 : RLParticleBeamCannonFocusingLaser1
{
	States
	{
		Spawn:
			NKOS B 2
			Stop
	}
}

ACTOR RLParticleBeamCannonPuffBase : BulletPuff
{
  -ALLOWPARTICLES
  -RANDOMIZE
  +PUFFONACTORS
  +ALWAYSPUFF
  +PUFFGETSOWNER
  +THRUGHOST
  +MTHRUSPECIES
  +FORCEXYBILLBOARD
  VSpeed 0
  Mass 5
  States
  {
  Spawn:
    TNT1 A 0
	Stop
  Melee:
    Goto Spawn
  }
}

ACTOR RLParticleBeamCannonPuff : RLParticleBeamCannonPuffBase
{
  Decal "BlueBFGLightning"
  Damagetype "Plasma"
  States
  {
  Spawn:
    TNT1 A 0
    TNT1 A 0 A_PlaySound("weapons/bfgx", CHAN_BODY, 1, 0, 0.7)
	Stop
  }
}

ACTOR RLParticleBeamCannonSniperPuff : RLParticleBeamCannonPuffBase
{
	Decal "BlueBFGLightning"
	Damagetype "Plasma"
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 AAAA 0 A_SpawnItemEx("RLParticleBeamCannonHeavyBlast")
			TNT1 A 0 A_PlaySound("weapons/largeexp", CHAN_AUTO, 1, 0, 0.5)
			TNT1 A 0 A_PlaySound("weapons/bfgx", CHAN_BODY, 1, 0, 0.7)
			Stop
	}
}

ACTOR RLParticleBeamCannonHeavyBlast
{
	Renderstyle Add
	Alpha 1.0
	Scale 1.4
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			PEXP A 2 Bright
			PEXP B 3 Bright A_SetScale(scalex + 0.1)
			PEXP C 3 Bright A_SetScale(scalex + 0.1)
			PEXP D 4 Bright A_SetScale(scalex + 0.1)
			"####" "#" 0 A_FadeOut
			PEXP E 4 A_SetScale(scalex + 0.1)
			"####" "#" 0 A_FadeOut
			PEXP F 4 A_SetScale(scalex + 0.1)
			"####" "#" 0 A_FadeOut
			Stop
	}
}

ACTOR RLParticleBeamCannonPuff2 : RLParticleBeamCannonPuffBase
{
  +BLOODLESSIMPACT
  +PAINLESS
  +NODECAL
  Damagetype "NullDamage"
  States
  {
  Spawn:
    TNT1 A 0
	Stop
  }
}

ACTOR RLParticleBeamCannonPuffNoSpecial : RLParticleBeamCannonPuffBase
{
  Damagetype "Plasma"
  States
  {
  Spawn:
    TNT1 A 0
	Stop
  }
}

ACTOR RLParticleBeamCannonCore
{   
   +NOINTERACTION
   +NOGRAVITY
   +FORCEXYBILLBOARD
   RenderStyle ADD
   Alpha 0.95
   Scale 1.7
   States
   {
   Spawn:
      TNT1 A 0
      BBAL A 1 Bright A_SetScale (1.2)
      BBAL B 1 Bright A_SetScale (1)
      BBAL C 1 Bright A_SetScale (0.4)
      BBAL DABCDAB 1 Bright
      BBAL CD 1 Bright A_FadeTo (0, 0.35, 1)
      Stop
   }
}

ACTOR RLParticleBeamCannonFinalFlash
{
	Renderstyle Add
	Alpha 0.9
	Scale 0.4
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			PCFT AB 1
			PCFT BCD 2
			PCFT EFG 3 A_FadeOut
			Stop
	}
}

ACTOR RLParticleBeamCannonFancyCore
{
	RenderStyle ADD
	Alpha 0.95
	Scale 1.0
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 1 A_ChangeVelocity(0.06,0,0,CVF_RELATIVE)
			TNT1 A 1 A_ChangeVelocity(0.0,0,0,CVF_RELATIVE)
			BBAL A 1 Bright A_SetScale (1)
			BBAL B 2 Bright A_SetScale (0.8)
			BBAL C 3 Bright A_SetScale (0.6)
			PULS T 1 A_SetScale (0.3)
			PULS SRQPONMLKIJ 1
			PULS J 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS I 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS K 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS L 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS M 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS N 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			Stop
	}
}

ACTOR RLParticleBeamCannonFancyBigCore
{
	RenderStyle ADD
	Alpha 0.95
	Scale 1.5
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 1 A_ChangeVelocity(0.06,0,0,CVF_RELATIVE)
			TNT1 A 1 A_ChangeVelocity(0.0,0,0,CVF_RELATIVE)
			BBAL A 1 Bright A_SetScale (1.4)
			BBAL B 2 Bright A_SetScale (1.0)
			BBAL C 3 Bright A_SetScale (0.8)
			PULS T 1 A_SetScale (0.5)
			PULS SRQPONMLKIJ 1
			PULS J 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS I 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS K 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS L 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS M 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			PULS N 2 A_FadeOut(0.2)
			"####" "#" 0 A_SetScale(scalex - 0.04)
			Stop
	}
}

ACTOR RLParticleBeamCannonFancyTrail
{
	RenderStyle ADD
	Alpha 0.95
	Scale 1.0
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			TNT1 A 1
			PEXP C 2 Bright A_FadeTo (0, 0.35, 1)
			PEXP C 0 Bright A_SetScale(0.5)
			PEXP D 2 Bright A_FadeTo (0, 0.35, 1)
			PEXP D 0 Bright A_SetScale(0.4)
			PEXP E 3 Bright A_FadeTo (0, 0.35, 1)
			PEXP E 0 Bright A_SetScale(0.3)
			PEXP F 3 Bright A_FadeTo (0, 0.35, 1)
			PEXP F 0 Bright A_SetScale(0.2)
			Stop
	}
}

ACTOR RLParticleBeamCannonSingularity : FastProjectile
{ 
   +THRUGHOST
   +FORCEXYBILLBOARD
   Height 1
   Radius 1
   Projectile
   RenderStyle Add
   Alpha 0.99
   Scale 1.0
   Speed 32000
   Decal "Scorch"
   Damagetype "Plasma"
   
   var int user_singularitysize;
   States
   {
   Spawn:
      TNT1 A 1
	  Loop
   Death:
      TNT1 A 0 A_SetUserVar(user_singularitysize,   random(100,350))
      TNT1 A 0 A_SetScale ((user_singularitysize/300.0))
      TNT1 A 0 A_PlaySound("weapons/bfgx", CHAN_BODY, 1, 0, 0.7)
      PULS ABCD 1 Bright
   SingularityLoop:
      TNT1 A 0 A_PlaySound("weapons/particlebeamcannonsingularity", 7, 1, 1, 0.5)
	  TNT1 A 0 A_JumpIf(CallACS("DRLA_QuakeNShake") >= 2, 3)
      TNT1 A 0 A_Quake (1, 2, 0, user_singularitysize*8.0, "")
      TNT1 A 0 A_Quake (2, 2, 0, user_singularitysize*3.0, "")
      TNT1 A 0 A_JumpIf(scalex <= 0.05, 2)
      TNT1 A 0 A_SetScale (scalex * 0.99)
      TNT1 A 0 A_RadiusThrust (-50, user_singularitysize*4.0, RTF_NOIMPACTDAMAGE)
      TNT1 A 0 A_SetUserVar("user_singularitysize",   user_singularitysize -1)
      TNT1 A 0 A_JumpIf (user_singularitysize <= 70, 4)
      TNT1 AAA 0 A_SpawnItemEx ("RLParticleBeamCannonSingularityProjectile", frandom(-3.0,3.0),frandom(-3.0,3.0),frandom(-3.0,3.0), 0,0,0, frandom(0.0,359.9), SXF_TRANSFERSCALE | SXF_NOCHECKPOSITION | SXF_TRANSFERPOINTERS)
      PULS E 1 Bright A_SpawnItemEx ("RLParticleBeamCannonSingularityAfterImage", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_TRANSFERSPRITEFRAME | SXF_TRANSFERSCALE)
      TNT1 A 0 A_JumpIf(scalex <= 0.05, 2)
      TNT1 A 0 A_SetScale (scalex * 0.99)
      TNT1 A 0 A_JumpIf (user_singularitysize <= 70, 4)
      TNT1 AAA 0 A_SpawnItemEx ("RLParticleBeamCannonSingularityProjectile", frandom(-3.0,3.0),frandom(-3.0,3.0),frandom(-3.0,3.0), 0,0,0, frandom(0.0,359.9), SXF_TRANSFERSCALE | SXF_NOCHECKPOSITION | SXF_TRANSFERPOINTERS)
      PULS F 1 Bright A_SpawnItemEx ("RLParticleBeamCannonSingularityAfterImage", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_TRANSFERSPRITEFRAME | SXF_TRANSFERSCALE)
      TNT1 A 0 A_JumpIf (user_singularitysize <= 25, "Dissipate")
      Goto SingularityLoop
   Dissipate:
      PULS DCBA 1 Bright
      TNT1 A 0 A_PlaySound("weapons/bfgx", 7, 1, 0, 0.7)
      TNT1 A 0 A_SpawnItemEx ("RLRailBlastShockwave", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION)
	  Stop
   }
}

ACTOR RLParticleBeamCannonSingularityProjectile
{
   Radius 6
   Height 5
   Speed 34
   
   Projectile
   +THRUACTORS
   +NOTIMEFREEZE
   +BLOODSPLATTER
   +SKYEXPLODE
   +FORCEXYBILLBOARD
   +DONTSPLASH
   
   var int user_countdown;
   var int user_ohnoesmath;
   var int user_velwhy;
   var int user_velzee;
   
   states
   {
   Spawn:
      TNT1 A 0
      TNT1 A 0 A_SetUserVar("user_countdown",   random(5,35))
	  Goto SpawnLoop
   SpawnLoop:
      TNT1 A 0 A_Explode (6, 64)
      TNT1 A 0 A_JumpIf(scalex <= 0.05, "SetYVel")
      TNT1 A 0 A_SetScale (scalex * frandom(0.7,0.9))

   SetYVel:
      TNT1 A 0 A_JumpIf(user_velwhy >= 45, "SetYVelDown")
      TNT1 A 0 A_JumpIf(user_velwhy <= -45, "SetYVelUp")
      TNT1 A 0 A_SetUserVar("user_ohnoesmath",   random(-5,5))
      TNT1 A 0 A_SetUserVar("user_velwhy",   user_velwhy + user_ohnoesmath)
      TNT1 A 0 A_ChangeVelocity (0, user_ohnoesmath, 0, CVF_RELATIVE)
      goto SetZVel
   SetYVelDown:
      TNT1 A 0 A_SetUserVar("user_ohnoesmath",   random(-5,0))
      TNT1 A 0 A_SetUserVar("user_velwhy",   user_velwhy + user_ohnoesmath)
      TNT1 A 0 A_ChangeVelocity (0, user_ohnoesmath, 0, CVF_RELATIVE)
      goto SetZVel
   SetYVelUp:
      TNT1 A 0 A_SetUserVar("user_ohnoesmath",   random(0,5))
      TNT1 A 0 A_SetUserVar("user_velwhy",   user_velwhy + user_ohnoesmath)
      TNT1 A 0 A_ChangeVelocity (0, user_ohnoesmath, 0, CVF_RELATIVE)
      goto SetZVel
	  
   SetZVel:
      TNT1 A 0 A_JumpIf(user_velzee >= 30, "SetZVelDown")
      TNT1 A 0 A_JumpIf(user_velzee <= -30, "SetZVelUp")
      TNT1 A 0 A_SetUserVar("user_ohnoesmath",   random(-1,1))
      TNT1 A 0 A_SetUserVar("user_velzee",   user_velzee + user_ohnoesmath)
      TNT1 A 0 A_ChangeVelocity (0, 0, user_ohnoesmath, CVF_RELATIVE)
      goto TheLonelySingleFrame
   SetZVelDown:
      TNT1 A 0 A_SetUserVar("user_ohnoesmath",   random(-1,0))
      TNT1 A 0 A_SetUserVar("user_velzee",   user_velzee + user_ohnoesmath)
      TNT1 A 0 A_ChangeVelocity (0, 0, user_ohnoesmath, CVF_RELATIVE)
      goto TheLonelySingleFrame
   SetZVelUp:
      TNT1 A 0 A_SetUserVar("user_ohnoesmath",   random(0,1))
      TNT1 A 0 A_SetUserVar("user_velzee",   user_velzee + user_ohnoesmath)
      TNT1 A 0 A_ChangeVelocity (0, 0, user_ohnoesmath, CVF_RELATIVE)
      goto TheLonelySingleFrame
	  
   TheLonelySingleFrame:
      TNT1 A 1 A_SpawnItemEx ("RLParticleBeamCannonSingularityExplosion", 0,0,0, 0,0,0, 0, SXF_TRANSFERSCALE | SXF_NOCHECKPOSITION)
      TNT1 A 0 A_SetUserVar("user_countdown",   user_countdown-1)
      TNT1 A 0 A_JumpIf(user_countdown <= 0, "Death")
      goto SpawnLoop
   Death:
      TNT1 A 0
      stop
   }
}

ACTOR RLParticleBeamCannonSingularityExplosion
{
   Radius 1
   Height 1
   +NOCLIP
   +NOBLOCKMAP
   +THRUACTORS
   +FORCEXYBILLBOARD
   Gravity 0.02
   RenderStyle Add
   Alpha 0.99
  States
  {
  Spawn:
    TNT1 A 0
    TNT1 A 1 A_SetScale (scalex * frandom(6.0,8.0))
  SpawnLoop:
    TNT1 A 0 A_CheckFloor("GroundFade")
    PBCF A 1 Bright A_FadeTo (0, 0.03, 1)
    Loop
  GroundFade:
    PBCF A 1 Bright A_FadeTo (0, 0.06, 1)
    Loop
  }
}

ACTOR RLParticleBeamCannonSingularityAfterImage
{
   Radius 1
   Height 1
   +NOCLIP
   +NOBLOCKMAP
   +THRUACTORS
   +FORCEXYBILLBOARD
   RenderStyle Add
   Alpha 0.99
  States
  {
  Spawn:
    "####" "#" 0
    "####" "#" 1 Bright A_FadeTo (0, 0.4, 1)
    Loop
  }
}

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

Actor RLParticleBeamCannonSelected : RLPermanentInventory {}
Actor RLParticleBeamCannonAmmochain : RLAmmochainDefault {}
Actor RLParticleBeamCannonModLimit : RLUniqueModAmount {}
Actor RLParticleBeamCannonPowerMod : RLUniqueModAmount {}
Actor RLParticleBeamCannonBulkMod : RLUniqueModAmount {}
Actor RLParticleBeamCannonAgilityMod : RLUniqueModAmount {}
Actor RLParticleBeamCannonTechnicalMod : RLUniqueModAmount {}
Actor RLParticleBeamCannonNanoMod : RLUniqueModAmount {}
Actor RLParticleBeamCannonFirestormMod : RLUniqueModAmount {}
Actor RLParticleBeamCannonSniperMod : RLUniqueModAmount {}

ACTOR RLParticleBeamCannonClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 171
   Inventory.Icon ""
}

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

ACTOR RLParticleBeamCannonPickup : RLUniqueWeaponPickup
{
	//$Sprite PBCNX0
	Tag "Particle Beam Cannon [Pickup]"
	States
	{
	SpawnFrame:
		PBCN 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("RLParticleBeamCannon",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("RLParticleBeamCannon",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_GiveInventory("RLUniqueItemFound",1, AAPTR_PLAYER1)
		"####" "#" 0 A_Print("\ccPicked up the \cdParticle Beam Cannon.")
		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("\cd= Particle Beam Cannon =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/ParticleBeamCannonpickup")
		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 RLParticleBeamCannonWorldSpawnPickup : RLParticleBeamCannonPickup 17115
{
	States
	{
	NoSpecialStartsStuff:
		TNT1 A 0 A_SpawnItemEx("RLRarityBeamUniqueWorld", 0,0,0, 0,0,0, 0, SXF_SETMASTER)
		TNT1 A 0 A_JumpIf(CallACS("DRPGCheckTiem"), "DRPGInit")
		"####" "#" 0 A_Jump(256, "SpawnFrame")
		Goto SpawnFrame
		
	SpawnFrame:
		PBCN X 4
		"####" "#" 0 A_GiveInventory("RLUniqueItemSpawnMessageSender",1)
		"####" "#" 0 A_PlaySound("weapons/uniquespawned", 7, 0.25, 0, 0)
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
		
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLParticleBeamCannon",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_GiveInventory("RLUniqueItemFound",1, AAPTR_PLAYER1)
		"####" "#" 0 A_Print("\ccPicked up the \cdParticle Beam Cannon.")
		"####" "#" 0 A_GiveInventory("RLDangerLevelUniqueGiver",1, AAPTR_PLAYER1)
		Goto PickupSound
	}
}

ACTOR RLParticleBeamCannonPickupModded : RLParticleBeamCannonPickup
{
	+INVENTORY.TRANSFER
	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:
		PBCN 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("RLParticleBeamCannon",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cbmodded \cdParticle Beam Cannon.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cd= Particle Beam Cannon =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("RLParticleBeamCannonModLimit", 1, "NotPickup_Modded")
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cd= Particle Beam Cannon =\n\n\ccYou replace your unmodded\n\ccweapon with the one you picked up.", 5, "CONFONT")
		"####" "#" 0 A_GiveInventory("Cell",90)
		Goto PickupSound
	NotPickup_Modded:
		"####" "#" 0 A_Print("\cd= Particle Beam Cannon =\n\n\caYou are already carrying a modded\n\caweapon of this type", 5, "CONFONT")
		Fail
	}
}
