
ACTOR RLPlasmaCannon : RLWeapon
{
  Obituary "%o was atomized by %k's plasma cannon."
  Tag "Plasma Cannon"
  Weapon.SelectionOrder 20
  Weapon.SlotNumber 6
  Weapon.AmmoUse1 5
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "Cell"
  Inventory.Icon "PLSCICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
    PLSC 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("RLPlasmaCannonPickup", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
	TNT1 A 0 A_TakeInventory("RLPlasmaCannonSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 1 A_TakeInventory("RLPlasmaCannon",1)
	Stop
  AfterModDrop:
    PLSC A 8 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
    PLSC 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("RLPlasmaCannonSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    PLSC 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("RLEfficientAmmoTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLPlasmaCannonSelected", 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")
    PLSC A 1 A_Raise
    Loop
  Fire:
	PLSC A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	PLSC A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	PLSC A 0 A_JumpIfInventory("RLRestrictionNoBoom",1,"NoBoomRestricted") // Cannot fire in levels that restrict it
	PLSC A 0 A_JumpIfInventory("RLRestrictionLowTechOnly",1,"LowTechRestricted") // Cannot fire in levels that restrict it
	PLSC A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,2)
	TNT1 A 0 A_JumpIfInventory("Cell",10, 2)
	Goto Ready
	TNT1 A 0 A_JumpIfInventory("Cell",5, 1)
	Goto Ready
	TNT1 A 0 A_AlertMonsters
    PLSC B 2 Bright A_GunFlash
	TNT1 A 0 A_JumpIfInventory("RLXaserPowerArmorToken",1,"XaserFire")
	TNT1 A 0 A_FireCustomMissile ("RLPlasmaCannonBall", frandom(-0.2,0.2), 1)
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,"FireFinish")
	TNT1 A 0 A_TakeInventory ("Cell", 5, TIF_NOTAKEINFINITE)
    Goto FireFinish
  XaserFire:
	TNT1 A 0 A_FireCustomMissile ("RLXaserPlasmaCannonBall", frandom(-0.2,0.2), 1)
	TNT1 A 0 A_FireCustomMissile ("RLXaserSPlasmaCannonBall", frandom(-29,-31), 0)
	TNT1 A 0 A_FireCustomMissile ("RLXaserSPlasmaCannonBall", frandom(29,31), 0)
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,"FireFinish")
	TNT1 A 0 A_TakeInventory ("Cell", 5, TIF_NOTAKEINFINITE)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLPlasmaShotgunRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    PLSC B 2 Bright
    PLSC C 5 Bright
    PLSC DDDEFGA 3
    PLSC A 16 A_Refire
    Goto Ready
  Flash:
    TNT1 A 4 A_Light1
    TNT1 A 4 A_Light(5)
    TNT1 A 0 A_Light0
    Goto LightDone
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLPlasmaCannonPickup",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("RLPlasmaInfusionAssemblyLearntToken", 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("RLPlasmaCannonSelected", 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("DroppedRLPowerMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLAgilityMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLTechnicalMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLTechnicalMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLPlasmaCannon",1)
	Stop
  }
}

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

ACTOR RLPlasmaCannonBall : PlasmaBall
{
  Radius 12
  Height 8
  Damage 20
  Damagetype "Plasma"
  Alpha 0.85
  Scale 1.4
  Species "Player"
  +THRUSPECIES
  +SKYEXPLODE
  +THRUGHOST
  +FORCEXYBILLBOARD
//  Decal "BlueBFGLightning"
  SeeSound "weapons/plasmacannon"
  DeathSound ""
  States
  {
  Spawn:
    TNT1 A 0
    TNT1 A 0 A_Jump (192, 2)
	TNT1 A 0 A_CustomRailgun (0, 0, "None", "White", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(64,256), 1, 0.2, 0, "None", random(-16,16))
    PLCX ABCD 1 Bright A_SpawnItemEx ("RLPlasmaCannonBallTrail", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
    Loop
  Death:
    TNT1 A 0 A_SetScale (1.5)
    TNT1 A 0 A_SpawnItemEx ("RLPlasmaRefractorShockwave", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION)
    TNT1 A 0 A_Explode (256,128)
	TNT1 A 0 A_JumpIf(CallACS("DRLA_QuakeNShake") == 0, 3)
    TNT1 A 0 A_Quake (1, 14, 0, 1024, "")
    TNT1 A 0 A_Quake (6, 8, 0, 512, "")
    TNT1 A 0 A_PlaySound ("weapons/plasmacannonhit", 7, 1, 0, 0.5)
    TNT1 A 0 A_PlaySound("weapons/plasmacannonhit", CHAN_ITEM, 0.05, 0, 0.05)
	TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile("RLPlasmaCannonElectrofield",random(-height,height),random(-radius,radius),frandom(-359,359),CMF_TRACKOWNER | CMF_AIMDIRECTION,random(-90,90))
	TNT1 AAAAA 0 A_CustomRailgun (0, 0, "None", "White", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(64,256), 1, 0.2, 0, "None", random(-16,16))
    K8B4 I 1 Bright
	TNT1 AAA 0 A_CustomRailgun (0, 0, "None", "White", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(64,256), 1, 0.2, 0, "None", random(-16,16))
    K8B4 I 1 Bright
	TNT1 AA 0 A_CustomRailgun (0, 0, "None", "White", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(64,256), 1, 0.2, 0, "None", random(-16,16))
    K8B4 I 1 Bright
	TNT1 A 0 A_CustomRailgun (0, 0, "None", "White", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(64,256), 1, 0.2, 0, "None", random(-16,16))
    K8B4 J 1 Bright
	TNT1 A 0 A_CustomRailgun (0, 0, "None", "White", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(64,256), 1, 0.2, 0, "None", random(-16,16))
    K8B4 J 1 Bright
	TNT1 A 0 A_CustomRailgun (0, 0, "None", "White", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(64,256), 1, 0.2, 0, "None", random(-16,16))
    K8B4 J 1 Bright
	TNT1 A 0 A_CustomRailgun (0, 0, "None", "White", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(64,256), 1, 0.2, 0, "None", random(-16,16))
    K8B4 K 1 Bright
	TNT1 A 0 A_CustomRailgun (0, 0, "None", "White", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(64,256), 1, 0.2, 0, "None", random(-16,16))
    K8B4 K 2 Bright
    K8B4 LMN 3 Bright
    Stop
  }
}

const int pcefdist = 15;

ACTOR RLPlasmaCannonElectrofield
{
	Radius 5
	Height 5
	Renderstyle Add
	DamageType "Plasma"
	Speed 15
	Scale 0.4
	+MISSILE
	+NOINTERACTION
	+FORCERADIUSDMG
	+PAINLESS
	+DONTSPLASH
	+FORCEXYBILLBOARD
	+DONTSPLASH
	+NOTELEPORT
	States
	{
		Spawn:
//			PLFT ABAB 2 Bright A_ScaleVelocity(0.5)
			TNT1 AAAA 2 A_ScaleVelocity(0.5)
		Spawn.ExtraSparkle:
//			PLFT CD 1 A_FadeOut(0.01)
			TNT1 AA 1 A_FadeOut(0.01)
			"####" "#" 0 A_ScaleVelocity(0.35)
			"####" "#" 0 A_Explode(random(1,3),128, 0)
			"####" "#" 0 A_PlaySound("misc/waterelectrocution",CHAN_AUTO, 0.1, 0, ATTN_NORM)
			"####" "#" 0 A_CustomRailgun (0, 0, "None", "LightBlue", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(2,16), 1, 0.2, 0, "None", random(-16,16))
			"####" "#" 0 A_SpawnItemEx("RLPlasmaCannonElectroPuff", frandom(-pcefdist,pcefdist), frandom(-pcefdist,pcefdist), frandom(-pcefdist,pcefdist), cos(frandom(-pcefdist,pcefdist)), cos(frandom(-pcefdist,pcefdist)), sin(frandom(-pcefdist,pcefdist)))
			Loop
	}
}

ACTOR RLPlasmaticShrapnelPlasmaShotgunElectrofield : RLPlasmaCannonElectrofield
{
	Speed 0
	Scale 0.4
	States
	{
		Spawn:
//			PLFT ABAB 2 Bright A_ScaleVelocity(0.5)
			TNT1 AAAA 2 A_ScaleVelocity(0.5)
		Spawn.ExtraSparkle:
//			PLFT CD 1 A_FadeOut(0.01)
			TNT1 AA 1 A_FadeOut(0.01)
			"####" "#" 0 A_ScaleVelocity(0.35)
			"####" "#" 0 A_Explode(random(0,1),128, 0)
			"####" "#" 0 A_PlaySound("misc/waterelectrocution",CHAN_AUTO, 0.1, 0, ATTN_NORM)
			"####" "#" 0 A_CustomRailgun (0, 0, "None", "LightBlue", RGF_SILENT | RGF_FULLBRIGHT, 0, 25, "RLParticleBeamCannonPuff2", frandom(0,359), frandom(-45,45), random(2,16), 1, 0.2, 0, "None", random(-16,16))
			"####" "#" 0 A_SpawnItemEx("RLPlasmaCannonElectroPuff", frandom(-pcefdist,pcefdist), frandom(-pcefdist,pcefdist), frandom(-pcefdist,pcefdist), cos(frandom(-pcefdist,pcefdist)), cos(frandom(-pcefdist,pcefdist)), sin(frandom(-pcefdist,pcefdist)))
			Loop
	}
}
ACTOR RLPlasmaCannonElectroPuff
{
	Renderstyle Add
	Scale 0.1
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			PLFT ABCD 1 Bright
			Stop
	}
}

ACTOR RLPlasmaCannonBallTrail
{
   Scale 1.2
   RENDERSTYLE ADD
   Alpha 0.75
   +NOGRAVITY
   +NOINTERACTION
   +DONTSPLASH
   +FORCEXYBILLBOARD
   States
   {
   Spawn:
   TNT1 A 0
   PLCX EFGHI 1 Bright A_SetScale (ScaleX + frandom(0.08,0.22))
   Stop
   }
}

//-------------------------------------------------------------------
//		MYSTERIOUS MAGNUM

ACTOR RLPlasmaCannonBallSharpshooter : RLPlasmaCannonBall
{
  Damage (160)
}

ACTOR RLWWPlasmaCannonBall : RLPlasmaCannonBall
{
  Damage 30
}

ACTOR RLWWPlasmaCannonBallSharpshooter : RLPlasmaCannonBall
{
  Damage (240)
}

//-------------------------------------------------------------------
//		XASER PROJECTILES

ACTOR RLXaserPlasmaCannonBall : RLPlasmaCannonBall
{
  Scale 1.1
  SeeSound "weapons/xaserplasmacannon"
}

ACTOR RLXaserSPlasmaCannonBall : RLPlasmaCannonBall
{
  Scale 0.95
  SeeSound ""
}

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

Actor RLPlasmaCannonSelected : RLPermanentInventory {}

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

ACTOR RLPlasmaCannonPickup : RLMasterAssembledWeaponPickup
{
	//$Sprite PLSCX0
	Tag "Plasma Cannon [Pickup]"
	States
	{
	SpawnFrame:
		PLSC 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("RLPlasmaCannon",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("RLPlasmaCannon",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvPlasma 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("\cv= Plasma Cannon =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/PlasmaCannonpickup")
		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 RLPlasmaCannonWorldSpawnPickup : RLPlasmaCannonPickup 17801
{
	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:
		PLSC 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("RLPlasmaCannon",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvPlasma Cannon.")
		"####" "#" 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
		Goto PickupSound
	}
}
