// --------------------------------------------------------------------------
//
//	Plasma rifle
//
// --------------------------------------------------------------------------

ACTOR U_PlasmaRifle : BaseWeapon
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 50
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "AmmoCell"
	Weapon.AmmoType2 "PlasmaAmmoOld"
	Weapon.SelectionOrder 95
	-WEAPON.CHEATNOTWEAPON
    Inventory.PickupSound "PLSDRAW"
	Inventory.PickupMessage "You got the Plasma Rifle!"
	tag "Plasma Rifle"
	States
	{
	Spawn:
		PROI A -1
		Stop
	
	Select:
	    TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist",1,"PuristGun")
		TNT1 A 0 A_Giveinventory("HasPlasmaWeapon",1)
		TNT1 A 0 A_Giveinventory("PlasmaGunSelected",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 A_Takeinventory("Unloading",1)
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("TossGrenade",1)
		TNT1 A 0 A_Takeinventory("WeapSpecial",1)
		TNT1 A 0 A_Takeinventory("Taunting",1)
		TNT1 A 0 A_Takeinventory("IdleCounter",200)
		TNT1 A 5
		TNT1 A 0 A_Raise
		Wait
		
	Deselect:
        PROS EDCBA 1
		TNT1 A 0 A_Takeinventory("HasPlasmaWeapon",1)
		TNT1 A 0 A_Takeinventory("PlasmaGunSelected",1)
		TNT1 A 0 A_Takeinventory("PlasmaAltfireCharged",1)
		TNT1 A 0 A_Lower
		Wait
	
	Ready:
        TNT1 A 0 A_JumpIfInventory("GoFatality",1,"Steady")
        TNT1 A 0 A_PlaySound("PLSDRAW")
	Ready1:
		PROS ABCDE 1
	Ready2:
        TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        TNT1 A 0 A_JumpIfInventory("Taunting",1,"TauntR")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"Salute")
        TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
		TNT1 A 0 A_JumpIfInventory("Unloading",1,"Unload")
		TNT1 A 0 A_JumpIfInventory("IdleCounter",200,"PlayerIsIdle")
		TNT1 A 0 A_JumpIfInventory("PlasmaAmmoOld",1,2)
		PROR A 1 A_WeaponReady
		Goto Ready2
		PROG A 1 A_WeaponReady
		Goto Ready2

	PuristGun:
		TNT1 A 0 A_GiveInventory("ClassicPlasmaRifle",1)
		TNT1 A 0 A_TakeInventory("U_PlasmaRifle",1)
		Goto Ready	
		
// --------------------------------------------------------------------------
//
//	Fire
//
// --------------------------------------------------------------------------
		
	Fire:
        TNT1 A 0 A_JumpIfInventory("PlasmaAmmoOld",1,1)
        Goto Dryfire
        TNT1 A 0 A_PlaySound("PLSM9",CHAN_WEAPON)
		TNT1 A 0 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		TNT1 A 0 A_FireCustomMissile("GunFireSmoke",0,0,0,0,0,0)
		
		TNT1 A 0 A_jump(128,3)
		PROF A 1 A_FireCustomMissile("PlasmaBallAlt3",0,1,0,0)
		TNT1 A 0 A_jump(256,2)
		PROF C 1 A_FireCustomMissile("PlasmaBallAlt3",0,1,0,0)
		
		TNT1 A 0 A_jump(128,3)
		PROC A 1 A_FireCustomMissile("Shakeyourassminor",0,0,0,0)
		TNT1 A 0 A_jump(256,2)
		PROC C 1 A_FireCustomMissile("Shakeyourassminor",0,0,0,0)
		
		TNT1 A 0 A_jump(128,3)
		PROC B 1 A_AlertMonsters
		TNT1 A 0 A_jump(256,2)
		PROC D 1 A_AlertMonsters

		PROF B 1
		TNT1 A 0 A_Takeinventory("PlasmaAmmoOld",1)
		TNT1 A 0 A_ReFire
        TNT1 A 0 A_PlaySound("PLSCOOL",5)
        PROG BCD 1
		PROG EEEEEE 3 A_FireCustomMissile("SmokeSpawner",0,0,10,2)
		PROG DCB 1
		Goto Ready2
		
// Charging up secondary -------------------------------------------------------

	ChargeShake:
		TNT1 A 1 A_SetPitch(pitch - 0.2)
		TNT1 A 1 A_SetPitch(pitch + 0.3)
		TNT1 A 1 A_SetPitch(pitch - 0.3)
		TNT1 A 1 A_SetPitch(pitch + 0.2)
		Loop
		
	StopShake:
		TNT1 A 1
		Stop
		
	Smoke:
		TNT1 AAAA 1 A_FireCustomMissile("SmokeSpawner",0,0,10,5)
		TNT1 AAAAAAA 2 A_FireCustomMissile("SmokeSpawner",0,0,10,5)
		TNT1 AAAAAAAAAA 3 A_FireCustomMissile("SmokeSpawner",0,0,10,5)
		Stop

	AltFire:
        TNT1 A 0 A_JumpIfInventory("PlasmaAmmoOld",10,1)
        Goto Dryfire
        TNT1 A 0 A_GunFlash("ChargeShake")
		TNT1 A 0 A_PlaySound("PLSCHARG")
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Takeinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1

		TNT1 A 0 A_Giveinventory("PlasmaAltfireCharged",1)
		TNT1 A 0 A_PlaySound("PLSFULL",5,0.8,1)
		TNT1 A 0 A_ReFire

// Holding Charge --------------------------------------------------------------

	AltHold:
		TNT1 A 0 A_JumpIfInventory("PlasmaAltfireCharged",1,2)
		TNT1 A 0 A_JumpIfInventory("PlasmaAmmoOld",10,"AltFire")
		Goto Dryfire
		TNT1 A 0 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Cancel")
		PROF E 1 offset(0,32)
		TNT1 A 0 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Cancel")
		PROF G 1 offset(0,33)
		TNT1 A 0 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Cancel")
		PROF F 1 offset(1,32)
		TNT1 A 0 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Cancel")
		PROF H 1 offset(-1,32)
		TNT1 A 0 A_ReFire

// Let Fly ---------------------------------------------------------------------

		TNT1 A 0 A_Takeinventory("PlasmaAltfireCharged",1)
		TNT1 A 0 A_GunFlash("StopShake")
		TNT1 A 0 A_StopSound(5)
		TNT1 A 0 A_PlaySound("PLSALTFR")
		
		PROF A 1 A_Recoil(1)
		TNT1 AA 0 A_FireCustomMissile("GunFireSmoke",random(-4,4),0,-1,0,0,random(-3,3))
		TNT1 AAA 0 A_FireCustomMissile("PlasmaBallAlt1",frandom(-3,3),0,-1,0,0,frandom(-3,3))
		TNT1 A 0 A_FireCustomMissile("ShakeYourAssMinor",0,0,0,0)
		PROC A 1 A_Recoil(1)
		TNT1 AA 0 A_FireCustomMissile("GunFireSmoke",random(-4,4),0,-1,0,0,random(-3,3))
		TNT1 AAA 0 A_FireCustomMissile("PlasmaBallAlt2",frandom(-3,3),0,-1,0,0,frandom(-3,3))
		TNT1 A 0 A_FireCustomMissile("ShakeYourAssMinor",0,0,0,0)
		PROF A 1 A_Recoil(1)
		TNT1 AA 0 A_FireCustomMissile("GunFireSmoke",random(-4,4),0,-1,0,0,random(-3,3))
		TNT1 AAA 0 A_FireCustomMissile("PlasmaBallAlt3",frandom(-3,3),0,-1,0,0,frandom(-3,3))
		TNT1 A 0 A_FireCustomMissile("ShakeYourAssDouble",0,0,0,0)
		PROC B 1 A_Recoil(1)
		TNT1 AA 0 A_FireCustomMissile("GunFireSmoke",random(-4,4),0,-1,0,0,random(-3,3))
		TNT1 AAA 0 A_FireCustomMissile("PlasmaBallAlt4",frandom(-3,3),0,-1,0,0,frandom(-3,3))
		TNT1 A 0 A_FireCustomMissile("ShakeYourAssQuad",0,0,0,0)
		
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_FireCustomMissile("PlasmaFlareSpawn",-5,0,0,0)
        PROG JKL 1 A_SetPitch(pitch + 0.9)
        PROG KJBCD 1 A_SetPitch(pitch - 0.6)
		TNT1 A 0 A_GunFlash("Smoke")
		PROG EEE 1 A_SetPitch(pitch - 0.4)
		PROG EEEEEEEEEEE 3
		PROG DCB 1
		TNT1 A 0 A_PlaySound("PLSCOOL")
        TNT1 A 0 A_JumpIfInventory("PlasmaAmmoOld",1,1)
        Goto Reload
        TNT1 A 0
		Goto Ready2

// Cancel Charge ---------------------------------------------------------------

	Cancel:
		TNT1 A 0 A_StopSound(5)
		TNT1 A 0 A_PlaySound("plscool",5)

		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1 
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1 
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1 
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1 
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1 
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		//PROC D 1 A_PlaySound("plscool",7)
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1
		PROC A 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC B 1 A_Giveinventory("PlasmaAmmoOld",1)
		PROC C 1 A_FireCustomMissile("PlasmaFlareSpawn",0,0,0,0)
		PROC D 1

		TNT1 A 0 A_GunFlash("StopShake")
		TNT1 A 0 A_TakeInventory("Reloading",1)
		TNT1 A 0 A_PlaySound("BEPBEP",5,1.2)
		TNT1 A 0 A_ClearReFire
		Goto Ready2

//  ----------------------------------------------------------------------------

	Dryfire:
		TNT1 A 0 A_JumpIfInventory("TurboReload",1,"ReloadLoop")
		TNT1 A 0 A_JumpIfInventory("AmmoCell",1,"Reload")
		TNT1 A 0 A_PlaySound("BEP",5)
		PROR A 4 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
		Goto Ready2

// --------------------------------------------------------------------------
//
//	Reload n Unload
//
// --------------------------------------------------------------------------

    Reload:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_ClearReFire
		TNT1 A 0 A_JumpIfInventory("PlasmaAmmoOld",50,"Ready2")
		TNT1 A 0 A_JumpIfInventory("AmmoCell",1,1)
        Goto Ready2
		TNT1 A 0 A_JumpIfInventory("TurboReload",1,"ReloadLoop")
		TNT1 A 0 A_JumpIfInventory("HasUnloaded_Plasma",1,4)
		TNT1 A 0 A_PlaySound("BEPBEP",5)
		PROR MA 4 A_WeaponReady(WRF_NOFIRE)
        TNT1 A 0 A_PlaySound("PLREADY")
        PROR AB 1
		TNT1 A 0 A_JumpIfInventory("HasUnloaded_Plasma",1,2)
		TNT1 A 0 A_FireCustomMissile("PlasmaCaseSpawn",-210,0,20,-20)
		TNT1 A 0 A_TakeInventory("HasUnloaded_Plasma",1)
		PROR CDEEEEEEEEEEEEEEEF 1
        PROR GHHIIIJJJJJJJJIKLBAAAAA 1
		
	ReloadLoop:
		TNT1 A 0 A_JumpIfInventory("PlasmaAmmoOld",50,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("AmmoCell",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("PlasmaAmmoOld",1)
		TNT1 A 0 A_Takeinventory("AmmoCell",1)
		Goto ReloadLoop
		
	ReloadDone:
		TNT1 A 0 A_ClearReFire
		TNT1 A 0 A_Refire
		Goto Ready2

	Unload:
		TNT1 A 0 A_Takeinventory("Unloading",1)
        TNT1 A 0 A_JumpIfInventory("PlasmaAmmoOld",1,1)
        Goto Ready2
		TNT1 A 0 A_PlaySound("BEPBEP",5)
		PROR MA 4 A_WeaponReady(WRF_NOFIRE)
		TNT1 A 0 A_PlaySound("PLREADY",1)
		PROR AAAAABLKIJJJJJJJJIIIHHGFEEEEEEEEEEEEEEEDCBA 1
		TNT1 A 0 A_StopSound(1)
		TNT1 A 0 A_GiveInventory("HasUnloaded_Plasma",1)
		TNT1 A 0 A_Takeinventory("Unloading",1)
		
	UnloadLoop:
		TNT1 A 0 A_JumpIfInventory("PlasmaAmmoOld",1,1)
		Goto Ready2
		TNT1 A 0 A_Takeinventory("PlasmaAmmoOld",1)
		TNT1 A 0 A_Giveinventory("AmmoCell",1)
		Goto UnloadLoop
	
// --------------------------------------------------------------------------
//
//	End Stuff
//
// --------------------------------------------------------------------------
	
	KickFlash:
		PROT ABCD 1
		PROT E 8
		PROT DCBA 1
		PROR M 1
		Stop

	AirKickFlash:
		PROK ABCD 1
		PROK E 10
		PROK DCBA 1
		PROR M 1
		Stop
		
	TauntFlash:
		PROT ABCD 1
		PROT E 35
		PROT DCBA 1
		PROR M 1
		Stop
		
	GrenadeFlash:
		PROS EDCBA 1
		Stop
	}
}

ACTOR PlasmaAmmoOld : Ammo
{
   Inventory.Amount 0
   Inventory.MaxAmount 50
   Ammo.BackpackAmount 0
   Ammo.BackpackMaxAmount 50
   Inventory.Icon "PROIA0"
}

ACTOR PlasmaAltfireCharged : Inventory { Inventory.MaxAmount 1 }

ACTOR U_PlasmaBall: FastProjectile
{
	Radius 10
	Height 2
	Speed 65
	Damage(random(10,25) + random(10,25))
	//Damage 8					20b
	//Damage(random(31,32))	21
	DamageType Plasma
	Decal "SmallerScorch"
	Projectile
	+RANDOMIZE
	-NOBLOCKMAP
	+NOBLOOD
	+NORADIUSDMG
	+THRUSPECIES
	+MTHRUSPECIES
	+FORCEXYBILLBOARD
	Species "Marines"
	renderstyle ADD
	alpha 0.99
	Scale 0.10
	DeathSound "weapons/plasmax"
	SeeSound "PLSM9"
	Obituary "$OB_MPPLASMARIFLE"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 ACS_ExecuteAlways(719,0,0,0,0)//Check if DM
	Spawn1:
		PBAL AB 1 BRIGHT
		TNT1 A 0 A_CheckFloor("Death")
		TNT1 A 0 A_JumpIf((ABS(MomY) < 1) &&(ABS(MomX) < 1),"Death")
		Loop
	DM:
		TNT1 A 0 A_ChangeFLag("THRUSPECIES",0)
		TNT1 A 0 A_ChangeFLag("MTHRUSPECIES",0)
		TNT1 A 0 A_ScaleVelocity(0.85)
		Goto Spawn1
	Xdeath:
		TNT1 A 0 A_Explode(6,50,0)
		TNT1 A 0 A_CustomMissile("BluePlasmaFire",0,0,random(0,360),2,random(0,360))
		TNT1 AAAAA 0 A_CustomMissile("BluePlasmaParticle",0,0,random(0,360),2,random(0,360))
		TNT1 A 2
		TNT1 AA 9 A_CustomMissile("PlasmaSmoke",1,0,random(0,360),2,random(0,160))
		Stop
	Death:
		TNT1 A 0 A_Explode(6,50,1)
		TNT1 A 0 A_CustomMissile("BluePlasmaFire",0,0,random(0,360),2,random(0,360))
		TNT1 AAAAA 0 A_CustomMissile("BluePlasmaParticle",0,0,random(0,360),2,random(0,360))
		TNT1 A 0 A_SpawnItemEx("DetectFloorCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("DetectCeilCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 2
		TNT1 AAAAAAAAA 9 A_CustomMissile("PlasmaSmoke",1,0,random(0,360),2,random(0,160))
		Stop
	}
}

ACTOR HasUnloaded_Plasma : Inventory { Inventory.MaxAmount 1 }

ACTOR PlasmaBallAlt1: U_PlasmaBall
{
	Speed 70
	Damage(random(10,25) + random(10,25) + 5)
}
ACTOR PlasmaBallAlt2: PlasmaBallAlt1
{
	Speed 67
}
ACTOR PlasmaBallAlt3: PlasmaBallAlt1
{
	Speed 64
}
ACTOR PlasmaBallAlt4: PlasmaBallAlt1
{
	Speed 61
}