
ACTOR RLOverchargedBlaster : RLPistolWeapon
{
  Obituary "%o was pierced by %k's overcharged blaster."
  Decal BulletChip
  Tag "Overcharged Blaster"
  Weapon.SelectionOrder 1899
  Weapon.SlotNumber 2
  Weapon.AmmoUse1 0
  Weapon.AmmoGive1 0
  Inventory.Icon "OBLAICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
    OBLA A 1 A_WeaponReady (WRF_ALLOWZOOM)
	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("PowerRLTechnicianAdvancedDamage", 1)
	TNT1 A 0 A_JumpIfInventory("RLOverchargedBlasterModLimit", 1, "WeaponDropModded")
	TNT1 A 0 A_SpawnItemEx("RLOverchargedBlasterPickup", 0, 0, 40, 16, 0, 0, 0, SXF_SETMASTER)
	Goto WeaponDropRemoval
  WeaponDropModded:
	TNT1 A 2 A_SpawnItemEx("RLOverchargedBlasterPickupModded", 0, 0, 40, 16, 0, 0, 0, SXF_SETMASTER)
  WeaponDropRemoval:
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterModLimit", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterPowerMod", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterAgilityMod", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterSniperMod", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterFirestormMod", 1)
	TNT1 A 0 A_TakeInventory("RLOverchargedBlasterSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 1 A_TakeInventory("RLOverchargedBlaster",1)
	Stop
  AfterModDrop:
    OBLA A 8 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
    OBLA 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_TakeInventory("RLArmorModItemActivate",1)
	TNT1 A 0 A_GiveInventory("RLDeselectionFunction",1)
	TNT1 A 0 A_TakeInventory("RLOverchargedBlasterSelected", 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
    OBLA 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("RLRechargingAmmoWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLOverchargedBlasterSelected", 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
    OBLA D 1 A_Raise
    Loop
// 8x damage with Scout, half spread
  Fire:
	OBLA A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	OBLA A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	OBLA A 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	OBLA A 0 A_JumpIfInventory("RLRestrictionLowTechOnly",1,"LowTechRestricted") // Cannot fire in levels that restrict it
	OBLA A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	OBLA A 0 A_JumpIfInventory("RLRestrictionNoRecharge",1,"RechargeRestricted") // Cannot recharge in levels that restrict it
	
	TNT1 A 0 A_AlertMonsters
	TNT1 A 0 A_JumpIfInventory("RLOverchargedBlasterSniperMod",1,"FireS")
	TNT1 A 0 A_JumpIfInventory("RLOverchargedBlasterPowerMod",1,"FireP")
	TNT1 A 0 A_JumpIfInventory("RLOverchargedBlasterAgilityMod",1,"FireA")
	TNT1 A 0 A_JumpIfInventory("RLSharpshooterPerk",1,2)
	TNT1 A 0 A_RailAttack ((random(1,7)*24), 0, 0, "none", "Red", RGF_NOPIERCING | RGF_SILENT | RGF_FULLBRIGHT, 0, "RLLaserPuff", 2, 1, 0, 3, 1, 10)
    Goto FireFinish
	TNT1 A 0 A_RailAttack ((192), 0, 0, "none", "Red", RGF_NOPIERCING | RGF_SILENT | RGF_FULLBRIGHT, 0, "RLLaserPuff", 1, 0.5, 0, 3, 1, 10)
    Goto FireFinish
  FireP:
	TNT1 A 0 A_JumpIfInventory("RLSharpshooterPerk",1,2)
	TNT1 A 0 A_RailAttack ((random(1,7)*28), 0, 0, "none", "Red", RGF_NOPIERCING | RGF_SILENT | RGF_FULLBRIGHT, 0, "RLLaserPuff", 2, 1, 0, 3, 1, 10)
    Goto FireFinish
	TNT1 A 0 A_RailAttack ((224), 0, 0, "none", "Red", RGF_NOPIERCING | RGF_SILENT | RGF_FULLBRIGHT, 0, "RLLaserPuff", 1, 0.5, 0, 3, 1, 10)
    Goto FireFinish
  FireA:
	TNT1 A 0 A_JumpIfInventory("RLSharpshooterPerk",1,2)
	TNT1 A 0 A_RailAttack ((random(1,7)*24), 0, 0, "none", "Red", RGF_NOPIERCING | RGF_SILENT | RGF_FULLBRIGHT, 0, "RLLaserPuff", 1.5, 0.5, 0, 3, 1, 10)
    Goto FireFinish
	TNT1 A 0 A_RailAttack ((192), 0, 1, "none", "Red", RGF_NOPIERCING | RGF_SILENT | RGF_FULLBRIGHT, 0, "RLLaserPuff", 0.75, 0.25, 0, 3, 1, 10)
    Goto FireFinish
  FireS:
	TNT1 A 0 A_JumpIfInventory("RLSharpshooterPerk",1,2)
	TNT1 A 0 A_RailAttack ((random(1,7)*24), 0, 0, "none", "Red", RGF_NOPIERCING | RGF_SILENT | RGF_FULLBRIGHT, 0, "RLLaserPuff", 0, 0, 0, 3, 1, 10)
    Goto FireFinish
	TNT1 A 0 A_RailAttack ((192), 0, 0, "none", "Red", RGF_NOPIERCING | RGF_SILENT | RGF_FULLBRIGHT, 0, "RLLaserPuff", 0, 0, 0, 3, 1, 10)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_PlaySound("weapons/overchargedblaster", CHAN_WEAPON)
	TNT1 A 0 A_JumpIfInventory("RLOverchargedBlasterFirestormMod",1,"FireFinishF1")
    OBLA E 4 Bright A_GunFlash
    OBLA A 2
    OBLA B 2
    OBLA C 2
    OBLA D 4
    OBLA C 6
    OBLA D 4
    OBLA C 6
    OBLA D 4
    OBLA C 6
    OBLA B 2
    OBLA A 4
	Goto Ready
  FireFinishF1:
    OBLA E 2 Bright A_GunFlash
    OBLA A 2
    OBLA B 2
    OBLA C 2
    OBLA D 3
    OBLA C 5
    OBLA D 3
    OBLA C 5
    OBLA D 3
    OBLA C 5
    OBLA B 2
    OBLA A 1
	Goto Ready
  Flash:
    TNT1 A 2 A_Light2
    TNT1 A 1 A_Light1
    Goto LightDone
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLOverchargedBlasterPickup",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("RLOverchargedBlasterModLimit", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterPowerMod", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterAgilityMod", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterSniperMod", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterFirestormMod", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLOverchargedBlasterSelected", 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("RLPlasmaPistolAssemblyLearntToken", 1) // Assembly is now listed in the HUD menus
	TNT1 A 0 A_JumpIfInventory("RLOverchargedBlasterModLimit",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("RLOverchargedBlasterModLimit", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterPowerMod", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterAgilityMod", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterSniperMod", 1)
    TNT1 A 0 A_TakeInventory("RLOverchargedBlasterFirestormMod", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLOverchargedBlasterSelected", 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("DroppedRLPowerMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLPowerMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLTechnicalMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLOverchargedBlaster",1)
	Stop
  }
}

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

Actor RLOverchargedBlasterSelected : RLPermanentInventory {}
Actor RLOverchargedBlasterModLimit : RLAdvancedAssemblyModAmount {}
Actor RLOverchargedBlasterPowerMod : RLAdvancedAssemblyModAmount {}
Actor RLOverchargedBlasterAgilityMod : RLAdvancedAssemblyModAmount {}
Actor RLOverchargedBlasterFirestormMod : RLAdvancedAssemblyModAmount {}
Actor RLOverchargedBlasterSniperMod : RLAdvancedAssemblyModAmount {}

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

ACTOR RLOverchargedBlasterPickup : RLAdvancedAssembledWeaponPickup 17632
{
	//$Sprite OBLAX0
	Tag "Overcharged Blaster [Pickup]"
	States
	{
	SpawnFrame:
		OBLA 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("RLOverchargedBlaster",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("RLOverchargedBlaster",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up an \cvOvercharged 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= Overcharged Blaster =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/OverchargedBlasterpickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonShells",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	}
}

ACTOR RLOverchargedBlasterPickupModded : RLOverchargedBlasterPickup
{
	+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:
		OBLA 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("RLOverchargedBlaster",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cbmodded \cvOvercharged Blaster.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= Overcharged Blaster =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("RLOverchargedBlasterModLimit", 1, "NotPickup_Modded")
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= Overcharged 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= Overcharged Blaster =\n\n\caYou are already carrying a modded\n\caweapon of this type", 5, "CONFONT")
		Fail
	}
}
