const float PZ_SPEED_SCALAR = 0.01;

actor PlasmaSparkWep_NormalBar : NormalBar { args 202, 117 }
actor PlasmaSparkWep_ScriptBar : ScriptBar {}

actor PlasmaSparkWep : BaseMM8BDMWep
{
	Weapon.AmmoUse 1
	Weapon.AmmoGive 28
	weapon.ammotype "PlasmaSparkAmmo"

	Weapon.SlotNumber 5

	Inventory.Pickupmessage "$PU_PLASMASPARK"
	Obituary "$OB_PLASMASPARK"
	Tag "$TAG_PLASMASPARK"

	inventory.icon "PLASSHOK"

	States
	{
		SpawnLoop:
			PZSK Z -1
			loop
			
		Ready:
			PZSB A 0 ACS_NamedExecuteWithResult("core_weaponcolor",CLR_PlasmaSpark)
			PZSB A 0 ACS_NamedExecuteWithResult("KB_DirectionPlasma")
			PZSB A 0 A_GunFlash
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",12,"Ready2")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",6,"Ready1")
			PZSB A 1 A_WeaponReady
			Goto Ready+3
		Ready1:
			PZS0 A 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",12,"Ready2")
			PZS0 A 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",12,"Ready2")
			PZS0 B 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",12,"Ready2")
			PZS0 B 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",12,"Ready2")
		Ready1Loop:
			PZS0 C 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",12,"Ready2")
			loop
		Ready2:
			PZS0 D 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			PZS0 D 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			PZS0 E 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			PZS0 E 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
		Ready2Loop:
			PZS0 F 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Ready3")
			loop
		Ready3:
			PZS0 G 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZS0 G 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZS0 H 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			PZS0 H 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
		Ready3Loop:
			PZS0 I 1 A_WeaponReady
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Ready4")
			loop
		Ready4:
			PZS0 IIJJKKLLLLKKJJII 1 A_WeaponReady
			LOOP
			
		Deselect:
			PZSB A 0 A_TakeInventory("PlasmaSparkFlag",999)
			PZSB A 0
			goto DeselectSwap
			
		Select:
			PZSB A 0
			goto SelectSwap
			
		Fire:
			PZSB A 0 A_JumpIfNoAmmo("NoAmmo")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",24,"Fire4")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",18,"Fire3")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",12,"Fire2")
			PZSB AAAAAAAAAAAAA 0 A_JumpIfInventory("PlasmaSparkFlag",6,"Fire1")
			PZSB A 0 A_TakeInventory("PlasmaSparkFlag",999)
			PZSB A 0 A_PlaySoundEx("ib/plasmasparkfire1","Weapon")
			PZSB A 0 A_FireCustomMissile("PlasmaSparkShot1",0,1,8,0)
			PZSB BC 2
			PZSB A 3
			PZSB A 1 A_Refire
			Goto Ready+3
		Fire1:
			PZSB A 0 A_JumpIfInventory("PlasmaSparkAmmo",2,"Fire1Cont")
			PZSB A 0 A_TakeInventory("PlasmaSparkFlag",999)
			goto Fire
		Fire1Cont:
			PZSB A 0 A_TakeInventory("PlasmaSparkFlag",999)
			PZSB A 0 A_PlaySoundEx("ib/plasmasparkfire2","Weapon")
			PZSB A 0 A_TakeInventory("PlasmaSparkAmmo",2)
			PZSB A 0 A_FireCustomMissile("PlasmaSparkShot2",0,0,8,0)
			PZSB BC 2
			PZSB A 5
			PZSB A 1 A_Refire
			Goto Ready+3
		Fire2:
			PZSB A 0 A_JumpIfInventory("PlasmaSparkAmmo",4,"Fire2Cont")
			PZSB A 0 A_TakeInventory("PlasmaSparkFlag",999)
			goto Fire1
		Fire2Cont:
			PZSB J 0 A_TakeInventory("PlasmaSparkFlag",999)
			PZSB A 0 A_TakeInventory("PlasmaSparkAmmo",4)
			PZSB A 0 A_PlaySoundEx("ib/plasmasparkfire3","Weapon")
			PZSB A 0 A_FireCustomMissile("PlasmaSparkShot3",0,0,8,0)
			PZSB BC 3
			PZSB A 16
			PZSB A 1 A_Refire
			Goto Ready+3
		Fire3:
			PZSB A 0 A_JumpIfInventory("PlasmaSparkAmmo",5,"Fire3Cont")
			PZSB A 0 A_TakeInventory("PlasmaSparkFlag",999)
			goto Fire2
		Fire3Cont:
			PZSB A 0 A_TakeInventory("PlasmaSparkFlag",999)
			PZSB A 0 A_TakeInventory("PlasmaSparkAmmo",5)
			PZSB A 0 A_PlaySoundEx("ib/plasmasparkfire4","Weapon")
			PZSB A 0 A_FireCustomMissile("PlasmaSparkShot4",0,0,8,0)
			PZSB DEFGHI 2
			PZSB A 6
			PZSB A 1 A_Refire
			Goto Ready+3
		Fire4:
			PZSB A 0 A_JumpIfInventory("PlasmaSparkAmmo",7,"Fire4Cont")
			PZSB A 0 A_TakeInventory("PlasmaSparkFlag",999)
			goto Fire3
		Fire4Cont:
			PZSB A 0 A_TakeInventory("PlasmaSparkFlag",999)
			PZSB A 0 A_TakeInventory("PlasmaSparkAmmo",7)
			PZSB A 0 A_PlaySoundEx("ib/plasmasparkfire5","Weapon")
			PZSB A 0 A_FireCustomMissile("PlasmaSparkShot5",0,0,8,0)
			PZSB DEFGHI 2
			PZSB A 12
			PZSB A 1 A_Refire
			Goto Ready+3
			
			
		NoAmmo:
			PZSB A 1 ACS_NamedExecuteAlways("core_noammo",0)
			Goto Ready+3
			
		Flash:
			TNT1 A 1 A_JumpIfInventory("PlasmaSparkFlag",6,"FlashStartStart")
			loop
		FlashStartStart:
			TNT1 A 0 A_SpawnItemEX("PlasmaSparkWatcher")
		FlashStates:
			TNT1 A 1 A_JumpIfInventory("PlasmaSparkFlag",24,"FlashSoundStart")
			TNT1 A 0 A_JumpIfInventory("PlasmaSparkFlag",6,"FlashStates")
			goto Flash
		FlashSoundStart:
			TNT1 A 0 A_SpawnItemEX("PlasmaSparkWarpEffect",0,0,0,0,0,0)
		FlashSound:
			TNT1 A 2 A_PlaySoundEx("ib/plasmasparkfullcharge","Weapon",0)
			TNT1 A 0 A_JumpIfInventory("PlasmaSparkFlag",24,"FlashSound")
			goto Flash
			
	}
}

actor PlasmaSparkAmmo : Ammo
{
	inventory.amount 1
	inventory.maxamount 28
	+INVENTORY.IGNORESKILL
}

actor PlasmaSparkFlag : Inventory
{
	inventory.amount 1
	inventory.maxamount 24
}

actor PlasmaSparkDirSFX : CustomInventory
{
states
{
Pickup:
TNT1 A 0
TNT1 A 0 A_PlaySoundEx("ib/plasmasparkdirection","SoundSlot5")
stop
}
}

actor PlasmaSparkShot1 : BasicFastProjectile
{
damagetype "PlasmaSpark1"
Obituary "$OB_PLASMASPARK"
Speed 70
Damage (CallACS("burst_cbm_damage",13))
radius 11
height 7
translation "210:215=196:196"
States
{
Spawn:
TNT1 A 1
PZSK A 1
PZSK A 4
goto Death
Death:
PZSK A 0 A_Stop
PZSK BCD 1
stop
}
}

actor PlasmaSparkShot2 : BasicFastProjectile
{
damagetype "PlasmaSpark2"
Obituary "$OB_PLASMASPARK"
Speed 70
Damage (CallACS("burst_cbm_damage",25))
radius 11
height 7
translation "161:161=196:196","229:229=197:197", "210:215=196:196"
States
{
Spawn:
TNT1 A 1
PZSK E 1
PZSK EE 4
goto Death
Death:
PZSK A 0 A_Stop
PZSK A 2
PZSK BCD 1
stop
}
}


actor PlasmaSparkShot3 : BasicFastProjectile
{
damagetype "PlasmaSpark3"
Obituary "$OB_PLASMASPARK"
Speed 70
Damage (CallACS("burst_cbm_damage",44))
radius 14
height 14
reactiontime 25
States
{
Spawn:
TNT1 A 1 
PZSK K 1 A_SpawnItemEx("PlasmaSparkShot5RandomFX",0,0,0,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM)
PZSK G 1
PZSK K 1 A_SpawnItemEx("PlasmaSparkShot5RandomFX",0,0,0,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM)
PZSK H 1
PZSK K 1 A_SpawnItemEx("PlasmaSparkShot5RandomFX",0,0,0,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM) 
SpawnLoop:
PZSK I 1 A_ScaleVelocity(0.85)
PZSK A 0 A_SpawnItemEx("PlasmaSparkShot5RandomFX",0,0,0,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM)
PZSK K 0 A_CountDown
TNT1 A 0 A_GiveInventory("PlasmaSparkFlag",1)
TNT1 A 0 A_JumpIfInventory("PlasmaSparkFlag",14,"DyingLoop")
PZSK J 1 A_ScaleVelocity(0.85)
PZSK K 0 A_CountDown
TNT1 A 0 A_GiveInventory("PlasmaSparkFlag",1)
TNT1 A 0 A_JumpIfInventory("PlasmaSparkFlag",14,"DyingLoop")
PZSK G 1 A_ScaleVelocity(0.85)
PZSK A 0 A_SpawnItemEx("PlasmaSparkShot5RandomFX",0,0,0,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM)
PZSK K 0 A_CountDown
TNT1 A 0 A_GiveInventory("PlasmaSparkFlag",1)
TNT1 A 0 A_JumpIfInventory("PlasmaSparkFlag",14,"DyingLoop")
PZSK H 1 A_ScaleVelocity(0.85)
PZSK K 0 A_CountDown
TNT1 A 0 A_GiveInventory("PlasmaSparkFlag",1)
TNT1 A 0 A_JumpIfInventory("PlasmaSparkFlag",14,"DyingLoop")
goto SpawnLoop
DyingLoop:
PZSK L 1 A_ScaleVelocity(0.85)
PZSK A 0 A_SpawnItemEx("PlasmaSparkShot5RandomFX",0,0,0,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM)
PZSK K 0 A_CountDown
PZSK M 1 A_ScaleVelocity(0.85)
PZSK K 0 A_CountDown
goto DyingLoop
Death:
PZSK A 0 A_Stop
PZSK LKML 1
stop
}
}

actor PlasmaSparkShot4 : BasicProjectile
{
+DONTREFLECT
damagetype "PlasmaSpark4"
Obituary "$OB_PLASMASPARK"
Speed 50
Damage (0)
radius 5
height 5
reactiontime 4
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_ScaleVelocity(PZ_SPEED_SCALAR)
Spawn2:
TNT1 A 0 A_SpawnItemEx("PlasmaSparkShot4Damager",0,0,0,(momx/PZ_SPEED_SCALAR),(momy/PZ_SPEED_SCALAR),(momz/PZ_SPEED_SCALAR),0,SXF_ABSOLUTEMOMENTUM)
TNT1 A 0 A_CountDown
TNT1 A 1
loop
Death:
TNT1 A 0
stop
}
}

actor PlasmaSparkShot4Damager : BasicProjectile
{
+RIPPER
damagetype "PlasmaSpark4"
Obituary "$OB_PLASMASPARK"
Speed 50
Damage (CallACS("burst_cbm_damage",14))
radius 14
height 14
reactiontime 25
var int user_PierceRipper;
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_GiveInventory("PierceRipperLimit", 1)
SpawnLoop:
PZSK F 1
wait
}
}

actor PlasmaSparkShot5 : BasicProjectile
{
+NOCLIP
+NOINTERACTION
+THRUGHOST
damagetype "PlasmaSpark5"
Obituary "$OB_PLASMASPARK"
Speed 60
Damage (0)
radius 1
height 1
var int user_PierceRipper;
reactiontime 25
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_GiveInventory("PierceRipperLimit", 1)
SpawnLoop:
PZSK A 0 A_PlaySoundEX("ib/plasmasparkshot5travel","Body")
PZSK K 1 A_SpawnItemEx("PlasmaSparkShot5Damager",0,0,0,2,0,0)
PZSK K 0 A_SpawnItemEx("PlasmaSparkShot5RandomFX",0,0,0,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM)
PZSK A 0 A_CountDown
PZSK G 1 A_SpawnItemEx("PlasmaSparkShot5Damager",0,0,0,2,0,0)
PZSK A 0 A_CountDown
PZSK A 0 A_PlaySoundEX("ib/plasmasparkshot5travel","Body")
PZSK H 1 A_SpawnItemEx("PlasmaSparkShot5Damager",0,0,0,2,0,0)
PZSK A 0 A_CountDown
PZSK K 1 A_SpawnItemEx("PlasmaSparkShot5Damager",0,0,0,2,0,0)
PZSK K 0 A_SpawnItemEx("PlasmaSparkShot5RandomFX",0,0,0,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM)
PZSK A 0 A_CountDown
PZSK A 0 A_PlaySoundEX("ib/plasmasparkshot5travel","Body")
PZSK I 1 A_SpawnItemEx("PlasmaSparkShot5Damager",0,0,0,2,0,0)
PZSK A 0 A_CountDown
PZSK J 1 A_SpawnItemEx("PlasmaSparkShot5Damager",0,0,0,2,0,0)
PZSK A 0 A_CountDown
loop
Death:
PZSK A 0 A_Stop
PZSK LKML 1
stop
}
}

actor PlasmaSparkShot5Damager : BasicProjectile
{
+DONTSPLASH
+DONTBLAST
+THRUGHOST
+DONTREFLECT
Damagetype "PlasmaSpark5" 
Obituary "$OB_PLASMASPARK"
radius 28
height 16
Damage (CallACS("burst_cbm_damage",60))
States
{
Spawn:
TNT1 A 2
stop
}
}

actor PlasmaSparkShot5RandomFX : BasicGraphicEffect
{
speed 80
States
{
SpawnFrame:
TNT1 A 0
TNT1 A 0 A_Jump(255,"FrameQ","FrameR","FrameS","FrameT","FrameU","FrameV")
goto FrameQ
FrameQ:
PZSK Q 2
stop
FrameR:
PZSK R 2
stop
FrameS:
PZSK S 2
stop
FrameT:
PZSK T 2
stop
FrameU:
PZSK U 2
stop
FrameV:
PZSK V 2
stop
}
}

actor PlasmaSparkProtect : PowerProtection
{
    powerup.duration 3
    damagefactor "PlasmaSpark5", 0.0
}

actor PlasmaSparkWarpEffect : BasicExplosion
{
damagetype "PlasmaSparkField"
Obituary "$OB_PLASMASPARK"
radius 5
height 5
speed 80
+FORCEXYBILLBOARD
+BRIGHT
+NOTIMEFREEZE
scale 2.5
alpha 0.6
renderstyle "translucent"
States
{
Spawn:
TNT1 A 0
TNT1 A 1 A_Warp(AAPTR_TARGET,0,0,0,0,WARPF_NOCHECKPOSITION)
TNT1 A 0 A_JumpIf(CallACS("KB_PlasmaWarper_Check")==0,"Death")
PZSK P 1 A_Warp(AAPTR_TARGET,0,0,0,0,WARPF_NOCHECKPOSITION)
TNT1 A 0 A_JumpIf(CallACS("KB_PlasmaWarper_Check")==0,"Death")
TNT1 A 1 A_Warp(AAPTR_TARGET,0,0,0,0,WARPF_NOCHECKPOSITION)
TNT1 A 1 A_Explode(CallACS("burst_cbm_damage",5),64,0)
TNT1 A 0 A_JumpIf(CallACS("KB_PlasmaWarper_Check")==0,"Death")
loop
Death:
//TNT1 A 0 A_ClearTarget
//TNT1 AAAAA  0 A_SpawnItemEX("MetalBlade",0,0,15)
TNT1 A 0
stop
}
}

actor PlasmaSparkWatcher : BasicWatcher
{
states
{
Spawn:
TNT1 A 0
SpawnCheck:
TNT1 A 1
TNT1 A 0 A_JumpIfInTargetInventory("PlasmaSparkFlag", 24, "Charge4")
TNT1 A 0 A_JumpIfInTargetInventory("PlasmaSparkFlag", 18, "Charge3")
TNT1 A 0 A_JumpIfInTargetInventory("PlasmaSparkFlag", 12, "Charge2")
TNT1 A 0 A_JumpIfInTargetInventory("PlasmaSparkFlag", 6, "Charge1")
PLY1 A 0 A_JumpIfInTargetInventory("PlasmaSparkFlag", 1, "SpawnCheck")
stop
Charge1:
PLY1 A 1 A_GiveToTarget("PlasmaSparkFXSPawner")
PLY1 A 8
PLY1 A 0 A_JumpIfInTargetInventory("PlasmaSparkFlag", 1, "SpawnCheck")
stop
Charge2:
PLY1 A 1 A_GiveToTarget("PlasmaSparkFXSPawner")
PLY1 A 5
PLY1 A 0 A_JumpIfInTargetInventory("PlasmaSparkFlag", 1, "SpawnCheck")
stop
Charge3:
PLY1 A 1 A_GiveToTarget("PlasmaSparkFXSPawner")
PLY1 A 2
PLY1 A 0 A_JumpIfInTargetInventory("PlasmaSparkFlag", 1, "SpawnCheck")
stop
Charge4:
PLY1 A 1 A_GiveToTarget("PlasmaSparkFXSPawner")
PLY1 A 0 A_JumpIfInTargetInventory("PlasmaSparkFlag", 1, "SpawnCheck")
stop
}
}


actor PlasmaSparkFXSPawner : CustomInventory
{
states
{
Pickup:
TNT1 A 0
TNT1 A 0 A_SpawnItemEx("PlasmaSparkShot5RandomFX",random(-8,8),random(-8,8),25,momx,momy,momz,0,SXF_ABSOLUTEMOMENTUM)
stop
}
}