

ACTOR ElectricShock: CustomInventory  // for radiusgive effects
{
	+INVENTORY.AUTOACTIVATE
	+INVENTORY.ALWAYSPICKUP
	inventory.maxamount 1
    States
    {
		Pickup:
			// inventory item's states executes in the context of the actor that item is in inventory of
			TNT1 A 0
			TNT1 A 0 A_JumpIf(CallAcs("BD_CheckIfOverAnyLiquid_I"), 2)
			TNT1 A 0 A_JumpIf(waterlevel < 1, "Nope")
			TNT1 A 0 A_SpawnItemEx("ElectricShockDamage",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_MarkMonsterAsBeingAimedAt")
			TNT1 A 1 A_RailWait // without this, pickup fails to register and GZDoom hangs up then crashes when you fire Demon Tech rifle's short circuit ball
			Stop
		Nope:
			TNT1 A 1 A_RailWait
			Stop
    }
}

ACTOR ShockAOEGiver15: ElectricShock
{
    States
    {
		Pickup:
			// inventory item's states executes in the context of the actor that item is in inventory of
			TNT1 A 0
			TNT1 A 0 A_SpawnItemEx("ElectricShock15",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_MarkMonsterAsBeingAimedAt")
			TNT1 A 1 A_RailWait
			Stop
		Nope:
			TNT1 A 1 A_RailWait
			Stop
    }	
}

ACTOR ElectricShockDamage
{
	Projectile
	Height 1
	Radius 1
	Speed 0
	+NOINTERACTION
	+NOBLOCKMAP
	-SHOOTABLE
	+NOCLIP
	DamageType "Electric"
	States
	{
		Spawn:
			TNT1 A 0 NODELAY A_Explode(5, 10)
			TNT1 AAAA 3 A_PlaySound("KYBFGSPR")
			Stop
	
	}
}

ACTOR ElectricShock15: ElectricShockDamage
{
	+NOBLOCKMAP
	States
	{
		Spawn:
			TNT1 A 0 NODELAY A_Explode(15, 10)
			TNT1 AAAA 3 A_PlaySound("KYBFGSPR")
			Stop
	}
} 

ACTOR Plasma_Ball: FastProjectile
{
	Radius 10
	Height 2
	Speed 60
	Damage (random(40, 40))
    DamageType Plasma
	Decal "SmallerScorch"
	Projectile
	+RANDOMIZE
	+SPECTRAL
	-NOBLOCKMAP
	+NOBLOOD
	+NORADIUSDMG
	+THRUSPECIES
	+MTHRUSPECIES
	+FORCEXYBILLBOARD
	Species "Marines"
	damagefactor "Blood", 0.0 damagefactor "BlueBlood", 0.0 damagefactor "GreenBlood", 0.0 damagefactor "Taunt", 0.0 damagefactor "KillMe", 0.0 damagefactor "Shrapnel", 0.0
	Health 5
	Scale 1.0
	renderstyle ADD
	alpha 0.99
	DeathSound "weapons/plasmax"
	//SeeSound "PLSM9"
    SeeSound "None"
	Obituary "$OB_MPPLASMARIFLE"
	
	-NOBLOCKMAP // without this, A_RadiusGive does not see them and so projectile-destroying effects do not work. 	
	
	States
	{

	Spawn:
		TNT1 A 0 NODELAY ACS_NamedExecuteWithResult("PlasmaBallTrails")
	Fly:
		PLSS ABAB 1 BRIGHT A_JumpIf(waterlevel > 0, "Underwater") //A_SpawnItem("BlueFlareSmall")
		Loop
	Underwater:
		TNT1 A 0 A_Stop
		TNT1 A 0 A_PlaySound("KYBFGSPR", 7)
		TNT1 A 0 A_RadiusGive("ElectricShock", 60, RGF_MONSTERS | RGF_PLAYERS) 
		//TNT1 AAAAAA 0 A_CustomMissile ("EXPLOSIONBUBULZ", 0, 0, random (0, 360), 2, random (180, 360))
	Death:
	    PLSN A 0
		PLSN 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 B 1 //A_Explode(5,50,0)
		
		//***Che: uncommenting AOE damage. Reason: various smasheables do not smash from plasma!
		TNT1 B 1 A_Explode(5,50,0)
		PLSE ABC 2 BRIGHT A_SpawnItem("BlueFlare")
		PLSE DE 2 Bright A_SpawnItem("BlueFlareSmall")
		TNT2 AAA 9 A_CustomMissile ("PlasmaSmoke", 1, 0, random (0, 360), 2, random (0, 160))
		Stop
		
	Crash:
	XDeath:
	DefaultHitActorDeath:
	    PLSN A 0
		PLSN 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 B 1 A_Explode(5,50,0)
		PLSE ABC 2 BRIGHT A_SpawnItem("BlueFlare")
		PLSE DE 2 Bright A_SpawnItem("BlueFlareSmall")
		Stop
	}
}

ACTOR FBD_DeflectedPlasmaBall: Plasma_Ball
{
	Damage (random(22, 22))
	SeeSound None
	+THRUACTORS // for the first tic, then clears
	States {
		Spawn:
			PLSS A 1 BRIGHT
			TNT1 A 0 A_ChangeFlag("THRUACTORS", 0)
			Goto Fly
	}
}

ACTOR FBD_PlayersPlasmaBall: Plasma_Ball
{
	Damage 0
	+HITMASTER
	var int user_deflection_spread;
	States {
		Crash: // hit a non-bleeding actor
		XDeath: // hit a bleeding actor
			TNT1 A 0
			TNT1 A 0 A_JumpIf(!CallAcs("FBD_MissileDeflected", 20), "ReallyHit") 
			TNT1 A 0 A_SetUserVar("user_deflection_spread", CallAcs("FBD_GetMastersMissileDeflectionSpread")) // default is 25
			TNT1 A 0 A_RearrangePointers(AAPTR_Master, AAPTR_Null, AAPTR_Null) // make the one we hit our target (who is the bastard that shot this?!)
			TNT1 A 0 A_CustomMissile("FBD_DeflectedPlasmaBall", 6, 0, 180 + Random(-user_deflection_spread, user_deflection_spread), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0-pitch + Random(-user_deflection_spread, user_deflection_spread))
			TNT1 A 0 A_SpawnItemEx("DeflectorShieldReflectingEffect", 0,0,-15, 0,0,0, 0,SXF_NOCHECKPOSITION)
			TNT1 A 60 A_Stop
			Stop
		ReallyHit:
			TNT1 A 0 A_DamageMaster(40, "Plasma") // this IGNORES ARMOR!!! (also, Zandronum doesn't support the Flags parameter so can't turn that feature off)
			Goto DefaultHitActorDeath // make a boom, radius damage & stuff	
	}
}

//ACTOR PlasmaBall75
ACTOR FBD_PlayersPlasmaBall50: FBD_PlayersPlasmaBall // fired in alt fire shotgun-like mode
{
	SeeSound "PLSM9"
	States {
		Crash: // hit a non-bleeding actor
		XDeath: // hit a bleeding actor
			TNT1 A 0
			TNT1 A 0 A_JumpIf(!CallAcs("FBD_MissileDeflected", 20), "ReallyHit") 
			TNT1 A 0 A_SetUserVar("user_deflection_spread", CallAcs("FBD_GetMastersMissileDeflectionSpread")) // default is 60
			TNT1 A 0 A_RearrangePointers(AAPTR_Master, AAPTR_Null, AAPTR_Null) // make the one we hit our target (who is the bastard that shot this?!)
			TNT1 A 0 A_CustomMissile("FBD_DeflectedPlasmaBall", 6, 0, 180 + Random(-user_deflection_spread, user_deflection_spread), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0-pitch + Random(-user_deflection_spread, user_deflection_spread))
			TNT1 A 0 A_SpawnItemEx("DeflectorShieldReflectingEffect", 0,0,-15, 0,0,0, 0,SXF_NOCHECKPOSITION)
			TNT1 A 60 A_Stop
			Stop
		ReallyHit:
			TNT1 A 0 A_DamageMaster(50, "Plasma") // this IGNORES ARMOR!!! (also, Zandronum doesn't support the Flags parameter so can't turn that feature off)
			Goto DefaultHitActorDeath // make a boom, radius damage & stuff	
	}	
}


ACTOR NPCPlasmaBall: Plasma_Ball
{
	SeeSound "PLSM9"
	Damage 0
	+HITMASTER
	var int user_deflection_spread;
	States {
		// cannot use splash damage: hurts player!
		Death:
			PLSN A 0
			PLSN 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))
			PLSE ABC 2 BRIGHT A_SpawnItem("BlueFlare")
			PLSE DE 2 Bright A_SpawnItem("BlueFlareSmall")
			TNT2 AAA 9 A_CustomMissile ("PlasmaSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Stop
		Crash: // hit a non-bleeding actor
		XDeath: // hit a bleeding actor
			TNT1 A 0
			TNT1 A 0 A_JumpIf(CallAcs("FBD_GetMastersIsPlayer"), "Nope") // just disappear silently on hitting the player
			TNT1 A 0 A_JumpIf(!CallAcs("FBD_MissileDeflected", 20), "ReallyHit") 
			TNT1 A 0 A_SetUserVar("user_deflection_spread", CallAcs("FBD_GetMastersMissileDeflectionSpread")) // default is 60
			TNT1 A 0 A_RearrangePointers(AAPTR_Master, AAPTR_Null, AAPTR_Null) // make the one we hit our target (who is the bastard that shot this?!)
			TNT1 A 0 A_CustomMissile("FBD_DeflectedPlasmaBall", 6, 0, 180 + Random(-user_deflection_spread, user_deflection_spread), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0-pitch + Random(-user_deflection_spread, user_deflection_spread))
			TNT1 A 0 A_SpawnItemEx("DeflectorShieldReflectingEffect", 0,0,-15, 0,0,0, 0,SXF_NOCHECKPOSITION)
			TNT1 A 60 A_Stop
			Stop
		ReallyHit:
			TNT1 A 0 A_DamageMaster(22, "Plasma") // this IGNORES ARMOR!!! (also, Zandronum doesn't support the Flags parameter so can't turn that feature off)
			Goto DefaultHitActorDeath // make a boom, radius damage & stuff				
		Nope:
			TNT1 A 0
			Stop
	}
}


ACTOR PlasmaBall99: Plasma_Ball // no use cases
{
	Damage (random(60, 60))
	SeeSound "PLSM9"
}

ACTOR PlasmaBallDM: Plasma_Ball Replaces PlasmaBall
{
	Speed 50
	-THRUSPECIES
	-MTHRUSPECIES
	Species "None"
	Damage (random(40, 40))
}








ACTOR InvisiblePLasmaAmmo: CustomInventory
{
 scale 1.0
 radius 16
 height 4
 damage 0
   Mass 1
   Inventory.PickupMessage "Plasma Cells."
    States
    {

	 Spawn:
		CELL D -1
		Stop
	Pickup:
	    PLSN A 0
		PLSN A 0 A_GiveInventory("AmmoCell", 50)
		Stop
}}