
ACTOR RLInfusionLauncher : RLWeapon
{
  Obituary "%o was scalded by %k's rocket."
  Tag "Plascharge Launcher"
  Weapon.SelectionOrder 3900
  Weapon.SlotNumber 5
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLInfusionLauncherClip"
  Weapon.AmmoType2 "RocketAmmo"
  Inventory.Icon "PCHLICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
    PCHL 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("RLInfusionLauncherPickup", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
	TNT1 A 0 A_TakeInventory("RLInfusionLauncherSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 1 A_TakeInventory("RLInfusionLauncher",1)
	Stop
	
  AfterModDrop:
    PCHL A 8 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
    PCHL 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("RLInfusionLauncherSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    PCHL 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("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLInfusionLauncherSelected", 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")
    PCHL A 1 A_Raise
    Loop
	
  Fire:
	PCHL A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	PCHL A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	PCHL A 0 A_JumpIfInventory("RLRestrictionNoBoom",1,"NoBoomRestricted") // Cannot fire in levels that restrict it
	PCHL A 0 A_JumpIfInventory("RLRestrictionLowTechOnly",1,"LowTechRestricted") // Cannot fire in levels that restrict it
	PCHL A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfInventory("RLInfusionLauncherClip", 1, 1)
	Goto Reload
    PCHL B 4 Bright A_GunFlash
	TNT1 A 0 A_AlertMonsters
	PCHL C 4 Bright A_FireCustomMissile ("RLInfusionRocket", frandom(-0.2,0.2), 0)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLRocketLauncherRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
	TNT1 A 0 A_TakeInventory("RLInfusionLauncherClip", 1)
    PCHL D 4 Bright
    PCHL EFGH 2
    TNT1 A 0 A_Refire
	TNT1 A 0 A_JumpIf(CallACS("DRLA_AutoReload"), "Reload")
    Goto Ready
	
  Reload:
    PCHL A 1 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	TNT1 A 0 A_JumpIfInventory("RocketAmmo",1,1)
	Goto Ready
	TNT1 A 0 A_JumpIfInventory("RLInfusionLauncherClip",1,"Ready")
	TNT1 A 0 // Play the reload animation.
    PCHL H 3
    PCHL G 3
    PCHL I 3
    PCHL J 3
    PCHL K 3
    TNT1 A 0 A_SpawnItemEx ("RLHeavyReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 13
	Goto ReloadWorking
  ReloadWorking:
	TNT1 A 0 A_TakeInventory("RocketAmmo", 1, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_GiveInventory("RLInfusionLauncherClip", 1)
	TNT1 A 0
	Goto ReloadFinish
	TNT1 A 0
	Goto ReloadWorking
  ReloadFinish:
	TNT1 A 0 A_PlaySound("weapons/rocketload", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLHeavyReloadInRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    PCHL K 2
    PCHL J 2
    PCHL I 2
    PCHL G 2
    PCHL H 2
    PCHL A 3
    PCHL A 7 A_ReFire
	Goto Ready
	
  Flash:
    TNT1 A 4 A_Light1
    TNT1 A 4 A_Light2
    TNT1 A 4 A_Light (5)
    TNT1 A 1 A_Light2
    TNT1 A 1 A_Light1
    TNT1 A 0 A_Light0
    Goto LightDone
	
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLInfusionLauncherPickup",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("RLInfusionLauncherSelected", 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("RLInfusionLauncher",1)
	Stop
  }
}

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

ACTOR RLInfusionRocket : Rocket
{
	Species "Player"
	+THRUSPECIES
	+THRUGHOST
	+FORCEXYBILLBOARD
	Speed 20
	Decal "Scorch"
	Damage 20
	Damagetype "Plasma"
	SeeSound "weapons/plaschargelauncher"
	DeathSound ""
	States
	{
		Spawn:
			IDLX A 0 NoDelay A_JumpIf(CallACS("DRLA_Fancyprojectiles") == 1, "Spawn.Fancy")
		Spawn.Normal:
			IDLX A 1 Bright
			Loop
		Spawn.Fancy:
			IDLX A 1 Bright A_SpawnItemEx("RLInfusionRocketTrail", -5,0,5)
			Loop
		Death:
			TNT1 A 0 A_SetTranslucent (0.95, 1)
			TNT1 A 0 A_Explode (384,128)
			TNT1 A 0 A_JumpIf(CallACS("DRLA_QuakeNShake") == 0, 3)
			TNT1 A 0 A_Quake (1, 18, 0, 1024, "")
			TNT1 A 0 A_Quake (6, 8, 0, 512, "")
			TNT1 A 0 A_PlaySound ("weapons/rocklx", CHAN_WEAPON, 1, 0, 0.5)
			TNT1 A 0 A_PlaySound("weapons/rocklx", CHAN_ITEM, 0.05, 0, 0.05)
			TNT1 A 0 A_PlaySound ("weapons/plaschargelauncherhit", 7, 1, 0, 0.7)
			TNT1 A 0 A_PlaySound ("weapons/bfgx", 6, 0.5, 0, 1.8)
			TNT1 A 0 A_Jump (256, "DeathAnimation")
			Goto DeathAnimation
		DeathAnimation:
			TNT1 AAAAAAA 0 A_SpawnItemEx ("RLPlaschargeExplosion", random(-128,128), random(-128,128), random(-64,64), 0,0,0, 0, SXF_TRANSFERPOINTERS | SXF_NOCHECKPOSITION)
			K8B4 IIIIJJJJ 1 Bright A_SpawnItemEx ("RLPlaschargeExplosion", random(-128,128), random(-128,128), random(-64,64), 0,0,0, 0, SXF_TRANSFERPOINTERS | SXF_NOCHECKPOSITION)
			K8B4 KKKLLL 1 Bright A_SpawnItemEx ("RLPlaschargeExplosion", random(-128,128), random(-128,128), random(-64,64), 0,0,0, 0, SXF_TRANSFERPOINTERS | SXF_NOCHECKPOSITION)
			K8B4 MMNN 1 Bright A_SpawnItemEx ("RLPlaschargeExplosion", random(-128,128), random(-128,128), random(-64,64), 0,0,0, 0, SXF_TRANSFERPOINTERS | SXF_NOCHECKPOSITION)
			Stop
	}
}

ACTOR RLInfusionRocketTrail
{
	Translation "192:207=169:184", "240:247=40:47"
	Renderstyle Add
	Scale 0.1
	Alpha 0.7
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			HRX1 GG 2 A_FadeOut
			"####" "#" 0 A_SetScale(scalex + 0.05)
			HRX1 HH 2 A_FadeOut
			"####" "#" 0 A_SetScale(scalex + 0.1)
			HRX1 III 2 A_FadeOut
			"####" "#" 0 A_SetScale(scalex + 0.1)
			Stop
	}
}

ACTOR RLPlaschargeExplosion
{
   Damagetype "Plasma"
   RENDERSTYLE ADD
   Alpha 0.95
   Scale 0.7
   Species "Player"
   +THRUSPECIES
   +THRUGHOST
   +NOGRAVITY
   +FORCEXYBILLBOARD
   +DONTSPLASH
   States
   {
   Spawn:
   TNT1 A 0
   TNT1 A 0 A_SetScale (frandom(0.1,0.7))
   TNT1 A 0 A_Explode (30 * ScaleX,100 * ScaleX)
   TNT1 A 0 A_JumpIf (ScaleX >= 0.55, "Animation2")
   Animation1:
   K8B4 IJKLMN 2 Bright
   Stop
   Animation2:
   K8B4 IJKLMN 1 Bright
   Stop
   }
}

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

Actor RLInfusionLauncherSelected : RLPermanentInventory {}

ACTOR RLInfusionLauncherClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 1
   Inventory.Icon ""
}

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

ACTOR RLInfusionLauncherPickup : RLMasterAssembledWeaponPickup
{
	//$Sprite PCHLX0
	Tag "Plascharge Launcher [Pickup]"
	States
	{
	SpawnFrame:
		PCHL 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("RLInfusionLauncher",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("RLInfusionLauncher",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvPlascharge Launcher.")
		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= Plascharge Launcher =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/InfusionLauncherpickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonGrenades",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	SuperweaponStuff:
		"####" "#" 0 A_Jump(256, "NoSpecialStartsStuff")
		Goto NoSpecialStartsStuff
	}
}

ACTOR RLInfusionLauncherWorldSpawnPickup : RLInfusionLauncherPickup 17800
{
	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:
		PCHL 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("RLInfusionLauncher",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvPlascharge Launcher.")
		"####" "#" 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
		Goto PickupSound
	}
}
