
ACTOR RLChameleonRifle : RLWeapon
{
  Inventory.Pickupsound "weapons/unique"
  Obituary "%o was confused by %k's chameleon rifle."
  Decal BulletChip
  Tag "Chameleon Rifle"
  Weapon.SelectionOrder 11
  Weapon.SlotNumber 6
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLChameleonRifleClip"
  Weapon.AmmoType2 "Cell"
  Inventory.Icon "CRM1ICON"
  States
  {
  Ready:
	CRM1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleSniperModActive", 1, "ReadyEnergetic")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleFirestormModActive", 1, "ReadyHellish")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoModActive", 1, "ReadyIronWind")
    CRM1 A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
  ReadyIronwind:
    CRM2 AAAAAAAAAAAAAAA 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoSpeed",52)
    Loop
  ReadyHellish:
    CRM3 A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
  ReadyEnergetic:
    CRM4 A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
  ReadyNoReload:
    "####" "#" 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_NOSECONDARY)
    Goto Ready
	
  ScavengerDrop:
	"####" "#" 0 A_JumpIfInventory("RLScavengerDrop",1,"WeaponDropConfirm")
	"####" "#" 0 A_GiveInventory("RLScavengerDrop",1)
	"####" "#" 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:
	"####" "#" 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	"####" "#" 0 A_TakeInventory("RLScavengerDrop",1)
	"####" "#" 0 A_TakeInventory("RLWeaponDrop",1)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleModLimit", 1, "WeaponDropModded")
	"####" "#" 0 A_SpawnItemEx("RLChameleonRiflePickup", 0, 0, 40, 12, 0, 0, 0, SXF_SETMASTER)
	Goto WeaponDropRemoval
  WeaponDropModded:
	"####" "#" 2 A_SpawnItemEx("RLChameleonRiflePickupModded", 0, 0, 40, 12, 0, 0, 0, SXF_SETMASTER)
  WeaponDropRemoval:
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSniperModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoSpeed",52)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleModLimit", 3)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleSniperMod", 1)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormMod", 1)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleNanoMod", 1)
	"####" "#" 0 A_GiveInventory("RLRarityTokenRemover", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSelected", 1)
	"####" "#" 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLChameleonRifle",1)
	Stop
	
  AfterModDrop:
    "####" "#" 8 A_WeaponReady (WRF_NOSECONDARY | WRF_ALLOWRELOAD)
    Goto Ready
  MisfirePrevention:
    CRM1 A 1 A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
    Goto Ready
	
  Deselect:
	"####" "#" 0
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleSniperMod", 1, 2)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSniperModActive", 1)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleFirestormMod", 1, 2)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormModActive", 1)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoMod", 1, 2)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoSpeed",52)
	"####" "#" 0 A_GiveInventory("RLDeselectionFunction",1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSelected", 1)
	"####" "#" 0 A_GiveInventory("RLRarityTokenRemover", 1)
  DeselectLoop:
    "####" "#" 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    "####" "#" 0 A_Lower
    "####" "#" 1 A_Lower
    Goto DeselectLoop
  DeselectRenegade:
    "####" "#" 0 A_Lower
    loop
  SelectRenegade: 
    "####" "#" 0 A_Raise
    loop
  SelectSetWeapon:
	TNT1 A 0 A_GiveInventory("RLRapidfireTypeWeapon", 1)
	"####" "#" 0 A_GiveInventory("RLUniqueWeaponToken", 1)
	"####" "#" 0 A_GiveInventory("RLChameleonRifleSelected", 1)
	CRM4 A 0 A_JumpIfInventory("RLChameleonRifleSniperModActive",1,"SelectLoop")
	CRM3 A 0 A_JumpIfInventory("RLChameleonRifleFirestormModActive",1,"SelectLoop")
	CRM2 A 0 A_JumpIfInventory("RLChameleonRifleNanoModActive",1,"SelectLoop")
	CRM1 A 0
    Goto SelectLoop
  SelectLoop:
    "####" "#" 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    "####" "#" 0 A_Raise
    "####" "#" 1 A_Raise
    Loop
	
  Fire:
	"####" "#" 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	"####" "#" 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	"####" "#" 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	"####" "#" 0 A_JumpIfInventory("RLRestrictionLowTechOnly",1,"LowTechRestricted") // Cannot fire in levels that restrict it
	"####" "#" 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	"####" "#" 0 A_JumpIfNoAmmo("Reload")
	"####" "#" 0 A_AlertMonsters
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleSniperModActive",1,"FireS")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleFirestormModActive",1,"FireF")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoModActive",1,"FireN")
	
// Normal bullet firing, althought the bullets are being nano fabricated.
	CRM1 "#" 0 A_JumpIfInventory("RLChameleonRifleAmmochain",3,2)
	"####" "#" 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	"####" "#" 0 A_FireBullets (3, 1, -1, 8, "RLBulletPuff")
    Goto FireFinish
	"####" "#" 0 A_FireBullets (3, 1, -1, 8, "RLBulletPuff", 0)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLUziRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleAmmochain",3,6)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleAmmochain",2,4)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleAmmochain",1,2)
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", CHAN_WEAPON, 1, 0, 0.7)
    Goto FireFinishSoundDone
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", CHAN_ITEM, 1, 0, 0.7)
    Goto FireFinishSoundDone
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", CHAN_BODY, 1, 0, 0.7)
    Goto FireFinishSoundDone
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", CHAN_VOICE, 1, 0, 0.7)
    Goto FireFinishSoundDone
  FireFinishSoundDone:
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", 7, 0.05, 0, 0.20)
    CRM1 B 1 Bright A_GunFlash
    CRM1 C 1 Bright
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,"FireFinishPowerupCheck") // Check for powerups.
  FireFinishPowerupCheckDone: // No valid powerups detected.
    CRM1 A 2
	Goto FireFinishContinue
  FireFinishContinue:
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleAmmochain",3,2)
	"####" "#" 0 A_Jump(256,3)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleAmmochain",3)
    "####" "#" 0 A_ReFire
    Goto Ready
	"####" "#" 0 A_GiveInventory("RLChameleonRifleAmmochain",1)
    "####" "#" 0 A_ReFire
    Goto Ready

//-------------------------------------------------------------------------------------------------
  FireFinishPowerupCheck: // Marine fires one Firestorm's worth faster while affected by powerups.
	TNT1 A 0 A_JumpIfInventory("PowerInvulnerable",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerInvisibility",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerIronFeet",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerLightAmp",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerInfiniteAmmo",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerDrain",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerRLBerserkResistance",1,"FireFinishPowerupCheckConfirmed")
	Goto FireFinishPowerupCheckDone
  FireFinishPowerupCheckConfirmed:
    CRM1 A 1
	Goto FireFinishContinue
//-------------------------------------------------------------------------------------------------
  
	
// Firing bursts of 5 plasma bolts.
  FireS:
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleBurst",4,2)
	"####" "#" 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	"####" "#" 0 A_FireCustomMissile ("RLChameleonRiflePlasmaBall", frandom(-4,4), 1, 0, 0, 0, frandom(-1,1))
    Goto FireFinishS
	"####" "#" 0 A_FireCustomMissile ("RLChameleonRiflePlasmaBall", frandom(-4,4), 0, 0, 0, 0, frandom(-1,1))
    Goto FireFinishS
  FireFinishS:
    TNT1 A 0 A_SpawnItemEx ("RLUziRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    CRM4 B 1 Bright A_GunFlash
    CRM4 C 1 Bright
    CRM4 A 1
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleBurst",4,2)
	"####" "#" 0 A_Jump(256,3)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleBurst",4)
    CRM4 A 12
    Goto Ready
	"####" "#" 0 A_GiveInventory("RLChameleonRifleBurst",1)
    Goto Fire
	
// Slow inaccurate firespeed, that builds up the longer you fire.
  FireN:
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleAmmochain",3,2)
	"####" "#" 0 A_JumpIfInventory("RLAmmochainPerk",1,3)
// 50/50 chance of not using ammo.
	"####" "#" 0 A_Jump(128,2)
	"####" "#" 0 A_FireBullets (8, 5, -1, 8, "RLBulletPuff")
    Goto FireFinishN
	"####" "#" 0 A_FireBullets (8, 5, -1, 8, "RLBulletPuff", 0)
    Goto FireFinishN
  FireFinishN:
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleAmmochain",3,6)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleAmmochain",2,4)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleAmmochain",1,2)
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", CHAN_WEAPON, 1, 0, 0.7)
    Goto FireFinishNSoundDone
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", CHAN_ITEM, 1, 0, 0.7)
    Goto FireFinishNSoundDone
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", CHAN_BODY, 1, 0, 0.7)
    Goto FireFinishNSoundDone
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", CHAN_VOICE, 1, 0, 0.7)
    Goto FireFinishNSoundDone
  FireFinishNSoundDone:
    "####" "#" 0 A_PlaySound("weapons/chameleonrifle", 7, 0.05, 0, 0.20)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoSpeed",52,"FireFinishN5")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoSpeed",34,"FireFinishN4")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoSpeed",22,"FireFinishN3")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoSpeed",13,"FireFinishN2")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoSpeed",6,"FireFinishN1")
	"####" "#" 0 A_GiveInventory("RLChameleonRifleNanoSpeed",1)
    "####" "#" 0 A_SpawnItemEx ("RLBattleRifleRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    CRM2 B 1 Bright A_GunFlash
    CRM2 C 1 Bright
    CRM2 A 10
	Goto FireFinishContinue
  FireFinishN1:
// Fire 6 shots without resetting to reach level 1 firerate.
	"####" "#" 0 A_GiveInventory("RLChameleonRifleNanoSpeed",1)
    "####" "#" 0 A_SpawnItemEx ("RLBattleRifleRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    CRM2 B 1 Bright A_GunFlash
    CRM2 C 1 Bright
    CRM2 A 8
	Goto FireFinishContinue
  FireFinishN2:
// Fire 13 shots without resetting to reach level 2 firerate.
	"####" "#" 0 A_GiveInventory("RLChameleonRifleNanoSpeed",1)
    "####" "#" 0 A_SpawnItemEx ("RLBattleRifleRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    CRM2 B 1 Bright A_GunFlash
    CRM2 C 1 Bright
    CRM2 A 6
	Goto FireFinishContinue
  FireFinishN3:
// Fire 22 shots without resetting to reach level 3 firerate.
	"####" "#" 0 A_GiveInventory("RLChameleonRifleNanoSpeed",1)
    "####" "#" 0 A_SpawnItemEx ("RLBattleRifleRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    CRM2 B 1 Bright A_GunFlash
    CRM2 C 1 Bright
    CRM2 A 4
	Goto FireFinishContinue
  FireFinishN4:
// Fire 34 shots without resetting to reach level 4 firerate.
	"####" "#" 0 A_GiveInventory("RLChameleonRifleNanoSpeed",1)
    "####" "#" 0 A_SpawnItemEx ("RLBattleRifleRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    CRM2 B 1 Bright A_GunFlash
    CRM2 C 1 Bright
    CRM2 A 2
	Goto FireFinishContinue
  FireFinishN5:
// Fire 52 shots without resetting to reach level 5 firerate.
	"####" "#" 0 A_GiveInventory("RLChameleonRifleNanoSpeed",1)
    "####" "#" 0 A_SpawnItemEx ("RLThompsonRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    CRM2 B 1 Bright A_GunFlash
    CRM2 C 1 Bright
	Goto FireFinishContinue
	
// Slow firing mini flame grenades.
  FireF:
    "####" "#" 0 A_SpawnItemEx ("RLPistolRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
	"####" "#" 0 A_FireCustomMissile ("RLChameleonRifleGrenade", frandom(-1,1), 1, 0, 0, 0, frandom(0,2))
	"####" "#" 0 A_TakeInventory ("RLChameleonRifleClip", 1, TIF_NOTAKEINFINITE)
	"####" "#" 0 A_JumpIfInventory("RLFireangelPerk",1,4)
	"####" "#" 0 A_TakeInventory ("RLChameleonRifleClip", 3, TIF_NOTAKEINFINITE)
    CRM3 B 2 Bright A_GunFlash
    CRM3 C 2 Bright
    CRM3 A 14
	Goto Ready
	
  Reload:
	"####" "#" 1 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleClip", 50, "Ready")
	"####" "#" 0 A_JumpIfInventory("Cell", 1, 1)
	Goto Ready
	"####" "#" 0 // Play the reload animation.
	"####" "#" 0 A_TakeInventory("RLChameleonRifleBurst",4)
    "####" D 2
    "####" E 2
    "####" F 2
    "####" G 2
    "####" H 2
    "####" I 2
	"####" "#" 0 A_PlaySound("weapons/chameleonrifleunload", 7)
    "####" "#" 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    "####" J 2
    "####" K 2
    "####" L 13
    "####" M 2
    "####" N 2
	Goto ReloadWorking
  ReloadWorking:
	"####" "#" 0 A_TakeInventory("Cell", 1)
	"####" "#" 0 A_GiveInventory("RLChameleonRifleClip", 1)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleClip",50,"ReloadFinish")
  ReloadWorkingAmmoCheck:
	"####" "#" 0 A_JumpIfInventory("Cell",1,"ReloadWorking")
	Goto ReloadFinish
  ReloadFinish:
	"####" "#" 0 A_PlaySound("weapons/chameleonrifleload", CHAN_ITEM)
    "####" "#" 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    "####" O 2
    "####" P 2
    "####" G 2
    "####" F 2
    "####" E 2
    "####" D 2
    "####" A 7 A_ReFire
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoSpeed",52)
	Goto Ready
  Flash:
    TNT1 A 1 A_Light1
    TNT1 A 1 A_Light2
    TNT1 A 0 A_Light0
    Goto LightDone
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLChameleonRiflePickup",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION, 0, tid)
    Stop
  Altfire:
	"####" "#" 0 A_JumpIfInventory("RLArmorModItemActivate",1, "ArmorModConversion")
	"####" "#" 0 A_JumpIfInventory("RLScavengerDrop",1,"ScavengerTime")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleSniperMod", 1, "ModeSelect")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleFirestormMod", 1, "ModeSelect")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoMod", 1, "ModeSelect")
    Goto ReadyNoReload
  ModeSelect:
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoSpeed",52)
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleSniperModActive", 1, "ModeSelectHellish")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleFirestormModActive", 1, "ModeSelectIronWind")
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoModActive", 1, "ModeSelectDefault")
    Goto ModeSelectEnergetic
	
  ModeSelectEnergetic:
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleSniperMod", 1, 1)
    Goto ModeSelectHellish
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSniperModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoModActive", 1)
	"####" "#" 0 A_GiveInventory("RLChameleonRifleSniperModActive", 1)
    "####" "#" 0 A_Print("\ch< ENERGETIC CONFIGURATION >", 2, "CONFONT")
	"####" "#" 0 A_PlaySound("weapons/chameleonriflechangemode", 7, 1, 0, 1.8)
	"####" "#" 35
    CRM4 A 8
    Goto ReadyNoReload
  ModeSelectHellish:
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleFirestormMod", 1, 1)
    Goto ModeSelectIronWind
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSniperModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoModActive", 1)
	"####" "#" 0 A_GiveInventory("RLChameleonRifleFirestormModActive", 1)
    "####" "#" 0 A_Print("\cg< HELLISH CONFIGURATION >", 2, "CONFONT")
	"####" "#" 0 A_PlaySound("weapons/chameleonriflechangemode", 7, 1, 0, 1.8)
	"####" "#" 35
    CRM3 A 8
    Goto ReadyNoReload
  ModeSelectIronWind:
	"####" "#" 0 A_JumpIfInventory("RLChameleonRifleNanoMod", 1, 1)
    Goto ModeSelectDefault
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSniperModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoModActive", 1)
	"####" "#" 0 A_GiveInventory("RLChameleonRifleNanoModActive", 1)
    "####" "#" 0 A_Print("\cc< IRONWIND CONFIGURATION >", 2, "CONFONT")
	"####" "#" 0 A_PlaySound("weapons/chameleonriflechangemode", 7, 1, 0, 1.8)
	"####" "#" 35
    CRM2 A 8
    Goto ReadyNoReload
  ModeSelectDefault:
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSniperModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoModActive", 1)
    "####" "#" 0 A_Print("\cj< STANDARD CONFIGURATION >", 2, "CONFONT")
	"####" "#" 0 A_PlaySound("weapons/chameleonriflechangemode", 7, 1, 0, 1.8)
	"####" "#" 35
    CRM1 A 8
    Goto ReadyNoReload
  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)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSniperModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoModActive", 1)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleModLimit", 3)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleSniperMod", 1)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormMod", 1)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleNanoMod", 1)
	"####" "#" 0 A_GiveInventory("RLRarityTokenRemover", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	Goto ScavengerTimeEnd
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
	TNT1 A 0 A_JumpIfInventory("RLChameleonRifleModLimit",1,"ModDiscombobulation")
	"####" "#" 0 A_Print("Mod pack extracted from discarded weapon.")
	"####" "#" 0 A_TakeInventory("RLScavengerDrop",1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSniperModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormModActive", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleNanoModActive", 1)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleModLimit", 3)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleSniperMod", 1)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleFirestormMod", 1)
    "####" "#" 0 A_TakeInventory("RLChameleonRifleNanoMod", 1)
	"####" "#" 0 A_GiveInventory("RLRarityTokenRemover", 1)
	"####" "#" 0 A_TakeInventory("RLChameleonRifleSelected", 1)
	"####" "#" 0 A_TakeInventory("RLWeaponLimit",1)
	"####" "#" 0 A_FireCustomMissile("DroppedRLNanoMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	"####" "#" 1 A_TakeInventory("RLChameleonRifle",1)
	Stop
  }
}

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

actor RLChameleonRifleGrenade
{
    Decal Scorch
    Radius 6
    Height 8
    Mass 1
    Speed 15
    Damage (45)
    DamageType "Fire"
    Scale 0.65
    Species "Player"
    Projectile
    +THRUSPECIES
    -NOGRAVITY
    +LOWGRAVITY
	+EXTREMEDEATH
	+FORCEXYBILLBOARD
    States
    {
      Spawn:
        TNT1 A 0
		TNT1 A 0 A_PlaySound ("weapons/chameleonriflegrenade", 7, 1, 0, 0.9)
		TNT1 A 0 A_PlaySound("weapons/chameleonriflegrenade", CHAN_ITEM, 0.05, 0, 0.20)
      Spawn2:
        GREX A 3 Bright A_SpawnItem("RLChameleonRifleGrenadeSmoke")
        TNT1 A 0 A_JumpIf((Z - FloorZ) <= 32, "Death")
        Loop
      Death:
        TNT1 A 0 A_NoGravity
        TNT1 A 0 A_Stop
		TNT1 A 0 A_GiveToTarget ("RLFireangelBonusCheck", 1)
		TNT1 A 0 A_RadiusGive ("RLFireangelRadiusBonusCheck", 128, RGF_PLAYERS)
		TNT1 A 0 A_SetTranslucent (0.95, 1)
		TNT1 A 0 A_Explode(10+random(0, 20), 96, XF_HURTSOURCE, 1)
		TNT1 A 0 A_JumpIf(CallACS("DRLA_QuakeNShake") == 0, 3)
		TNT1 A 0 A_Quake (1, 5, 0, 368, "")
		TNT1 A 0 A_Quake (3, 3, 0, 96, "")
		TNT1 A 0 A_PlaySound ("weapons/chameleonriflegrenadehit", 7, 0.8, 0, 0.6)
		TNT1 A 0 A_PlaySound("weapons/chameleonriflegrenadehit", CHAN_ITEM, 0.05, 0, 0.05)
		TNT1 A 0 A_SetScale (0.35)
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -180, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -170, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -160, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -150, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -140, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -130, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -120, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -110, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -100, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -90, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -80, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -70, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -60, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -50, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -40, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -30, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -20, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, -10, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 10, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 20, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 30, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 40, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 50, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 60, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 70, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 80, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 90, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 100, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 110, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 120, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 130, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 140, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 150, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 160, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
		TNT1 A 0 A_CustomMissile ("RLChameleonRifleGrenadeFlame", 0, 0, 170, CMF_AIMDIRECTION | CMF_TRACKOWNER, frandom(0.1,-0.1))
        TNT1 A 15 A_SpawnItem("RLChameleonRifleGrenadeSmoke2")
        Stop
    }
}

ACTOR RLChameleonRifleGrenadeSmoke : RLGenericSmokeCloud
{
   VSpeed 0
   Scale 0.1
   Alpha 0.1
   States
   {
   Spawn:
   SMK2 ABCDEFGHIJKLMNOPQ 1
   Stop
   }
}

ACTOR RLChameleonRifleGrenadeSmoke2 : RLGenericSmokeCloud
{
   VSpeed 0
   Scale 0.3
   Alpha 0.2
   States
   {
   Spawn:
   SMK2 ABCDEFGHIJKLMNOPQ 2
   Stop
   }
}

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

Actor RLChameleonRifleSelected : RLPermanentInventory {}
Actor RLChameleonRifleAmmochain : RLAmmochainDefault {}
Actor RLChameleonRifleBurst : RLPermanentInventory
{
inventory.maxamount 4
}

Actor RLChameleonRifleNanoSpeed : RLPermanentInventory
{
inventory.maxamount 52
}

Actor RLChameleonRifleModLimit : RLPermanentInventory
{
inventory.maxamount 3
}

Actor RLChameleonRifleNanoMod : RLUniqueModAmount {}
Actor RLChameleonRifleFirestormMod : RLUniqueModAmount {}
Actor RLChameleonRifleSniperMod : RLUniqueModAmount {}

Actor RLChameleonRifleNanoModActive : RLPermanentInventory {}
Actor RLChameleonRifleFirestormModActive : RLPermanentInventory {}
Actor RLChameleonRifleSniperModActive : RLPermanentInventory {}

ACTOR RLChameleonRifleClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 50
   Inventory.Icon ""
}

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

ACTOR RLChameleonRiflePickup : RLUniqueWeaponPickup
{
	//$Sprite CRM1X0
	Tag "Chameleon Rifle [Pickup]"
	States
	{
	SpawnFrame:
		CRM1 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/gundropmedium")
		"####" "#" 0 A_ScaleVelocity (0.5)
		"####" "#" 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("RLChameleonRifle",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("RLChameleonRifle",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_GiveInventory("RLUniqueItemFound",1, AAPTR_PLAYER1)
		"####" "#" 0 A_Print("\ccPicked up the \cdChameleon Rifle.")
		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= Chameleon Rifle =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/chameleonriflepickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonClip",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	SuperweaponStuff:
		"####" "#" 0 A_Jump(256, "NoSpecialStartsStuff")
		Goto NoSpecialStartsStuff
	}
}

ACTOR RLChameleonRifleWorldSpawnPickup : RLChameleonRiflePickup 17123
{
	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:
		CRM1 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("RLChameleonRifle",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_GiveInventory("RLUniqueItemFound",1, AAPTR_PLAYER1)
		"####" "#" 0 A_Print("\ccPicked up the \cdChameleon Rifle.")
		"####" "#" 0 A_GiveInventory("RLDangerLevelUniqueGiver",1, AAPTR_PLAYER1)
		Goto PickupSound
	}
}

ACTOR RLChameleonRiflePickupModded : RLChameleonRiflePickup
{
	+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:
		CRM1 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("RLChameleonRifle",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cbmodded \cdChameleon Rifle.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cd= Chameleon Rifle =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("RLChameleonRifleModLimit", 1, "NotPickup_Modded")
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cd= Chameleon Rifle =\n\n\ccYou replace your unmodded\n\ccweapon with the one you picked up.", 5, "CONFONT")
		"####" "#" 0 A_GiveInventory("Cell",50)
		Goto PickupSound
	NotPickup_Modded:
		"####" "#" 0 A_Print("\cd= Chameleon Rifle =\n\n\caYou are already carrying a modded\n\caweapon of this type", 5, "CONFONT")
		Fail
	}
}
