actor Shadow : G2_Ghost
{
	CameraHeight 56
	speed 22
	height 56
	radius 16
	scale 1.25
	alpha 1.0
	renderstyle subtract
	+LOOKALLAROUND
	-FLOORCLIP
	+FLOORHUGGER
	painchance 1
	States
	{
		Dance:
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW ABCD 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW DCBA 3
			
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW ABCD 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW DCBA 3
			
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW EFGH 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW HGFE 3
			
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW EFGH 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW HGFE 3
			loop
		Spawn:
			SHDW A 1
			SHDW A 0 A_PlaySoundEx("Shadow/Idle", "SoundSlot7", 1)
			SHDW A 0 //A_LookEx(LOF_NOJUMP, 0, 0, 0, 360)
			SHDW A 0 A_GiveInventory("G2_LightLover", 1)
			SHDW A 0 A_JumpIfInventory("Clip", 1, "See")
			SHDW A 0 A_GiveInventory("Clip", 1)
			SHDW A 0 ACS_NamedExecuteAlways("shadow_darkness", 0, 0, 0, 0)
			SHDW A 0 ACS_NamedExecuteAlways("G2_Shadow_Script", 0, 0, 0, 0)
		See:
			SHDW ABE 8
			Goto Move
		Waiting:
			SHDW E 0 A_JumpIfCloser(2048, "DoWait")
			Goto MoveForce
			DoWait:
			SHDW E 4 A_JumpIfCloser(384, "Frightened")
			SHDW E 4 A_JumpIfTargetInLos("Retreat")
		Move:	
			SHDW A 0 A_JumpIfInTargetInventory("G2_LightSourcesTotal", 2, "Waiting")
			MoveForce:
			MoveA:
			SHDW AAA 1 A_JumpIf(ACS_NamedExecutewithResult("gd_chase") <= 0, "MoveAltA") //Too lazy to do this using Decorate...
			MoveB:
			SHDW BBB 1 A_JumpIf(ACS_NamedExecutewithResult("gd_chase") <= 0, "MoveAltB")
			MoveC:
			SHDW CCC 1 A_JumpIf(ACS_NamedExecutewithResult("gd_chase") <= 0, "MoveAltC")
			MoveD:
			SHDW DDD 1 A_JumpIf(ACS_NamedExecutewithResult("gd_chase") <= 0, "MoveAltD")

			SHDW D 0 A_LookEx(LOF_NOSOUNDCHECK, 0, 300, 0, 360, "TryHunt")
			/*SHDW D 0 A_Jump(40, "TryStand")
			SHDW D 0 A_JumpIfInventory("Shell", 1, "See")
			SHDW D 0 A_Jump(150, "TryStand")
			SHDW D 0 A_JumpIfCloser(512, "Move")*/
			Goto Move
		MoveAltA:
			SHDW AAA 1 A_Chase
			Goto MoveA
		MoveAltB:
			SHDW BBB 1 A_Chase
			Goto MoveB
		MoveAltC:
			SHDW CCC 1 A_Chase
			Goto MoveC
		MoveAltD:
			SHDW DDD 1 A_Chase
			Goto MoveD

		TryHunt:
			SHDW A 0 A_JumpIfTargetInLOS("Hunt")
			goto See
		
		Hunt:
			SHDW A 0 A_PlaySoundEx("Shadow/Angry", "SoundSlot5")
			SHDW A 0 A_TakeInventory("Shell", 1000)
		Hunting:
			SHDW AAABBBCCCDDD 1 A_Chase
			SHDW D 0 A_JumpIfCloser(250, "Hunting")
			SHDW D 0 A_LookEx(LOF_NOSOUNDCHECK, 0, 320, 0, 360, "Hunt")
			Goto See
		
		Retreat:
			SHDW A 0 A_ChangeFlag("Frightened", 1)
			SHDW A 0 A_GiveInventory("G2_ClearPath", 1)
		Retreating:
			SHDW AAABBBCCCDDD 1 A_Chase
			SHDW D 0 A_JumpIfCloser(512, "Frightened")
			SHDW D 0 A_JumpIfTargetInLos("Retreat")
			SHDW D 0 A_ChangeFlag("Frightened", 0)
			SHDW D 0 A_TakeInventory("G2_ClearPath", 1)
			Goto See

		Frightened:
			SHDW A 0
			SHDW A 0 A_PlaySound("Shadow/Frightened")
			SHDW A 0 A_GiveInventory("RocketAmmo", 1)
		FrightenedLoop:
			SHDW A 0 A_ChangeFlag("Frightened", 1)
			SHDW A 0 A_ChangeFlag("Noclip", 1)
			SHDW AAABBBCCCDDD 1 A_Chase
			
			SHDW D 0 A_JumpIfCloser(900, "FrightenedLoop")
			SHDW D 0 A_LookEx(LOF_NOSOUNDCHECK, 0, 900, 0, 360, "TryHunt")

		FrightenedEnd:
			SHDW D 0 A_TakeInventory("G2_ClearPath", 1)
			SHDW D 0 A_ChangeFlag("Frightened", 0)
			SHDW D 0 A_ChangeFlag("Noclip", 0)
			SHDW D 0 A_TakeInventory("Shell", 1000)
			SHDW A 0 A_TakeInventory("RocketAmmo", 1)
			SHDW D 0 ACS_NamedExecuteAlways("Ghost_Teleport", 0, 0, 0, 0)
		FrightenedWait:
			SHDW D 1
			SHDW D 0 A_JumpIfInventory("Cell", 1, "FrightenedWait")
			SHDW D 0 A_SpawnItemEx("ShadowTeleport", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
			goto See

		Panic:
			SHDW A 0
			SHDW A 0 A_PlaySound("Shadow/Frightened")
			SHDW A 0 A_ChangeFlag("Frightened", 1)
			
			SHDW AAABBBCCCDDD 1 A_Wander

			SHDW D 0 A_JumpIfInventory("G2_OnFire", 1, "Panic")
		PanicEnd:
			SHDW D 0 A_ChangeFlag("Frightened", 0)
			goto See

		TryStand:
			SHDW A 0 A_JumpIfCloser(1600, "Stand")
			goto See
		Stand:
			SHDW E 0 //A_Jump(128, "Cover")
			SHDW E 0 A_JumpIfTargetInLOS("DoStand")
			SHDW E 0 A_JumpIfCloser(384, "DoStand") //Because you might often get slaughtered when going around a corner.
			goto See
		DoStand:
			SHDW E 5 A_FaceTarget
			SHDW E 0 A_GiveInventory("Shell", 1)
			SHDW E 0 A_PlaySound("Shadow/Lurking")
			SHDW E 10 A_GiveInventory("Shell")

			SHDW EEEEEEEEEEE 10 bright A_LookEx(LOF_NOSOUNDCHECK, 0, 300, 0, 360, "TryHunt")

			goto See

		Cover:
			SHDW EFG 2 bright
		CoverLoop:
			SHDW H 35 bright
			loop
		CoverStop:
			SHDW H 4 bright
			SHDW GFE 2 bright
			goto Spawn
		
		Pain.Fire:
			SHDW A 0
			SHDW A 0 ACS_NamedExecuteWithResult("ghost_igniteMe")
		Pain:
			SHDW A 0
			SHDW A 0 A_PlaySound("Shadow/Hurt")
			SHDW A 0 A_JumpIfInventory("RocketAmmo", 1, "Frightened")
			goto Panic
	}
}

actor ShadowShadowA
{
	+CLIENTSIDEONLY
	+NOGRAVITY
	+NOINTERACTION
	+NOBLOCKMAP
	+THRUACTORS
	height 2
	radius 2
	
	renderstyle subtract
	alpha 0.5
	scale 1.25

	States
	{
		Spawn:
			SHDW A 1 A_FadeOut(0.05)
			loop
	}
}

actor ShadowShadowB : ShadowShadowA
{
	States
	{
		Spawn:
			SHDW B 1 A_FadeOut(0.05)
			loop
	}
}

actor ShadowShadowC : ShadowShadowA
{
	States
	{
		Spawn:
			SHDW C 1 A_FadeOut(0.05)
			loop
	}
}

actor ShadowShadowD : ShadowShadowA
{
	States
	{
		Spawn:
			SHDW D 1 A_FadeOut(0.05)
			loop
	}
}

actor DanceShadow : Shadow
{
	States
	{
		Spawn:
			goto Dance
	}
}

actor ShadowVs : Shadow
{
	speed 12
	-FLOORHUGGER
	+NOBLOCKMONST
	+THRUACTORS

	States
	{
		Dance:
			SHDW A 0 ACS_NamedExecuteWithResult("vs_disableControl")
		DanceLoop:
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW ABCD 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW DCBA 3

			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW ABCD 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW DCBA 3

			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW EFGH 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW HGFE 3

			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW EFGH 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW HGFE 3

			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW ABCD 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW DCBA 3

			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW ABCD 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW DCBA 3

			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW EFGH 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW HGFE 3

			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW EFGH 3
			SHDW A 0 ThrustThingZ(0,20,0,0)
			SHDW HGFE 3
			goto DanceEnd
		DanceEnd:
			SHDW A 0 bright ACS_NamedExecuteWithResult("vs_enableControl")
			goto See
		Still:
			SHDW E 4 bright A_JumpIf(ACS_NamedExecuteWithResult("vs_step"), "See")
			loop
		Spawn:
			SHDW A 1
			SHDW A 0 A_PlaySoundEx("Shadow/Idle", "SoundSlot7", 1)
			SHDW A 0 //A_LookEx(LOF_NOJUMP, 0, 0, 0, 360)
			SHDW A 0 A_GiveInventory("G2_LightLover", 1)
			SHDW A 0 A_JumpIfInventory("Clip", 1, "See")
			SHDW A 0 A_GiveInventory("Clip", 1)
			SHDW A 0 ACS_NamedExecuteAlways("shadow_darkness", 0, 0, 0, 0)
			SHDW A 0 ACS_NamedExecuteAlways("G2_Shadow_Script", 0, 0, 0, 0)
		See:
			SHDW AAABBBCCCDDD 1 A_JumpIf(ACS_NamedExecuteWithResult("vs_step") == 0, "Still")
			SHDW D 0 A_LookEx(LOF_NOSOUNDCHECK, 0, 300, 0, 360, "TryHunt")
			SHDW D 0 A_Jump(40, "TryStand")
			SHDW D 0 A_JumpIfInventory("Shell", 1, "See")
			SHDW D 0 A_Jump(150, "TryStand")
			loop
		TryHunt:
			SHDW A 0 A_JumpIfTargetInLOS("Hunt")
			goto See
		Hunt:
			SHDW A 0 A_PlaySoundEx("Shadow/Angry", "SoundSlot5")
			SHDW A 0 A_TakeInventory("Shell", 1000)
			SHDW A 0 bright ACS_NamedExecuteWithResult("vs_enableControl")
		Hunting:
			SHDW AAABBBCCCDDD 1 A_JumpIf(ACS_NamedExecuteWithResult("vs_step") == 0, "Still")

			SHDW D 0 A_JumpIfCloser(250, "Hunting")
			SHDW D 0 //A_LookEx(LOF_NOSOUNDCHECK, 0, 320, 0, 360, "Hunt")
			goto See

		Frightened:
			SHDW A 0
			SHDW A 0 ACS_NamedExecuteWithResult("vs_disableControl")
			SHDW A 0 A_PlaySound("Shadow/Frightened")
			SHDW A 0 A_GiveInventory("RocketAmmo", 1)
		FrightenedLoop:
			SHDW A 0 A_ChangeFlag("Frightened", 1)
			SHDW A 0 A_ChangeFlag("Noclip", 1)
			SHDW AAABBBCCCDDD 1 A_Chase

			SHDW D 0 A_JumpIfCloser(900, "FrightenedLoop")
			SHDW D 0 A_LookEx(LOF_NOSOUNDCHECK, 0, 900, 0, 360, "FrightenedLoop")

		FrightenedEnd:
			SHDW D 0 A_ChangeFlag("Frightened", 0)
			SHDW D 0 A_ChangeFlag("Noclip", 0)
			SHDW D 0 A_TakeInventory("Shell", 1000)
			SHDW D 0 A_TakeInventory("RocketAmmo", 1)
			SHDW D 10 ACS_NamedExecuteAlways("Ghost_Teleport", 0, 0, 0, 0)

		FrightenedWait:
			SHDW D 1
			SHDW D 0 A_JumpIfInventory("Cell", 1, "FrightenedWait")
			SHDW D 0 A_SpawnItemEx("ShadowTeleport", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE)
			SHDW D 0 ACS_NamedExecuteWithResult("shadow_teleportFade")
			SHDW D 0 ACS_NamedExecuteWithResult("vs_enableControl")
			goto See

		Panic:
			SHDW A 0
			SHDW A 0 ACS_NamedExecuteWithResult("vs_disableControl")
			SHDW A 0 A_PlaySound("Shadow/Frightened")
			SHDW A 0 A_ChangeFlag("Frightened", 1)
			SHDW AAABBBCCCDDD 1 A_Wander

			SHDW D 0 A_JumpIfInventory("G2_OnFire", 1, "Panic")
		PanicEnd:
			SHDW D 0 ACS_NamedExecuteWithResult("vs_enableControl")
			SHDW D 0 A_ChangeFlag("Frightened", 0)
			goto See

		TryStand:
			SHDW A 0 A_JumpIfCloser(1600, "Stand")
			goto See
		Stand:
			SHDW E 0 //A_Jump(128, "Cover")
			SHDW E 0 A_JumpIfTargetInLOS("DoStand")
			SHDW E 0 A_JumpIfCloser(384, "DoStand") //Because you might often get slaughtered when going around a corner.
			goto See
		DoStand:
			SHDW E 0 bright ACS_NamedExecuteWithResult("vs_disableControl")
			SHDW E 5 A_FaceTarget
			SHDW E 0 A_GiveInventory("Shell", 1)
			SHDW E 0 A_PlaySound("Shadow/Lurking")
			SHDW E 10 A_GiveInventory("Shell")

			SHDW EEEEEEEEEEE 10 bright //A_LookEx(LOF_NOSOUNDCHECK, 0, 300, 0, 360, "TryHunt")
			SHDW E 0 bright ACS_NamedExecuteWithResult("vs_enableControl")

			goto See

		Cover:
			SHDW E 0 bright ACS_NamedExecuteWithResult("vs_disableControl")
			SHDW EFG 2 bright
		CoverLoop:
			SHDW H 35 bright
			loop
		CoverStop:
			SHDW H 4 bright
			SHDW GFE 2 bright
			SHDW E 0 bright ACS_NamedExecuteWithResult("vs_enableControl")
			goto Spawn
		
		Pain.Fire:
			SHDW A 0
			SHDW A 0 ACS_NamedExecuteWithResult("ghost_igniteMe")
		Pain:
			SHDW A 0
			SHDW A 0 A_PlaySound("Shadow/Hurt")
			SHDW A 0 A_JumpIfInventory("RocketAmmo", 1, "Frightened")
			goto Panic
	}
}

actor ShadowTeleport {
	+NOINTERACTION
	+CLIENTSIDEONLY
	height 1
	radius 1

	States {

		Spawn:
			TNT1 A 2
			TNT1 A 0 Radius_Quake(4, 8, 0, 2, 0)
			TNT1 A 0 A_PlaySound("Shadow/Teleport", CHAN_7)
			TNT1 A 0 A_PlaySound("Shadow/Teleport", CHAN_6)
			TNT1 AAAAAA 0 A_SpawnItemEx("ShadowShadowA", 0, 0, 0, FRandom(-2, 2), FRandom(-2, 2), FRandom(-2, 2), FRandom(0, 360), SXF_CLIENTSIDE)
			TNT1 AAAAAA 0 A_SpawnItemEx("ShadowShadowB", 0, 0, 0, FRandom(-12, 12), FRandom(-12, 12), FRandom(-12, 12), FRandom(0, 360), SXF_CLIENTSIDE)
			TNT1 AAAAAA 1 A_SpawnItemEx("ShadowShadowC", 0, 0, 0, FRandom(-2, 2), FRandom(-2, 2), FRandom(-2, 2), FRandom(0, 360), SXF_CLIENTSIDE)
			TNT1 AAAAAA 1 A_SpawnItemEx("ShadowShadowD", 0, 0, 0, FRandom(-12, 12), FRandom(-12, 12), FRandom(-12, 12), FRandom(0, 360), SXF_CLIENTSIDE)
			TNT1 AAAAAA 1 A_SpawnItemEx("ShadowShadowC", 0, 0, 0, FRandom(-2, 2), FRandom(-2, 2), FRandom(-2, 2), FRandom(0, 360), SXF_CLIENTSIDE)
			TNT1 AAAAAA 1 A_SpawnItemEx("ShadowShadowD", 0, 0, 0, FRandom(-12, 12), FRandom(-12, 12), FRandom(-12, 12), FRandom(0, 360), SXF_CLIENTSIDE)
			stop
	}
}

actor G2_ShadowDarkSpot {
	+NOINTERACTION
	+CLIENTSIDEONLY

	renderstyle none

	States {
		Spawn:
			PUFF A -1
			loop
	}
}