// oh no not yol
// a large amount of states are copied in full unfortunately, due to all his
// sprites needing to be redefined. Not ideal, but whatever.

actor Gildmaster : Cybermancer
{
	Obituary "%o was spent by the Gildmaster."
	States
	{
	Spawn:
		RND0 A 0
		TNT1 A 0 A_JumpIfInventory("CyberdemonIsAwake", 1, "IdleTaunt")
		RND0 AB 10 A_Look
		Loop
// If Gildmaster has the "CyberdemonIsAwake" item, he's already been woken up,
// so if he's re-entered his spawn state it's usually because he's killed
// something. So let's have him mouth off a bit.
	IdleTaunt:
		RND0 A 0
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlaseranger", 0)
		RND0 A 0 A_TakeInventory("CyberdemonIsAwake", 999)
		RND0 A 10
		RND0 E 10 A_PlaySound("cybermancer/taunt", CHAN_VOICE, 1, 0, 0)
		RND0 GEGE 10
		goto Spawn
		
	See:
// This is a hacky way of making him play a specific see sound only once.
// Just to make sure Zandromeda can use it.
		TNT1 A 0 A_JumpIfInventory("CyberdemonIsAwake", 1, "HuntinDownMagets")
		TNT1 A 0 A_GiveInventory("CyberdemonIsAwake", 1)
		TNT1 A 0 A_JumpIfInventory("CyberdemonIsApproachingAtFullThrottleNOREFUGE", 1, "AlreadyActive")
		TNT1 A 0 A_GiveInventory("CyberdemonIsApproachingAtFullThrottleNOREFUGE", 1)
		TNT1 A 0 A_PlaySound("cybermancer/spawn", CHAN_VOICE, 1, 0, 0)
		Goto HuntinDownMagets
	AlreadyActive:
		TNT1 A 0 A_PlaySound("cybermancer/see", CHAN_VOICE, 1, 0,0.5)
		Goto HuntinDownMagets
	HuntinDownMagets:
// This part should be very obvious.
		RND0 DD 4 A_Chase
		TNT1 A 0 A_PlaySound("cyberdemony/step", 7, 1, 0, 0.7)
		TNT1 A 0 A_Quake(2, 6, 0, 512, "")
		RND0 AA 4 A_Chase ("Missile", "Missile", CHF_DONTMOVE)
		TNT1 A 0 A_PlaySound("cyberdemony/startmetalstep", 5, 1, 0, 1.2)
		RND0 BB 4 A_Chase
		TNT1 A 0 A_PlaySound("cyberdemony/metalstep", 5, 1, 0, 0.7)
		TNT1 A 0 A_Quake(2, 6, 0, 512, "")
		RND0 CC 4 A_Chase ("Missile", "Missile", CHF_DONTMOVE)
		Loop
		
	Missile:
// Plays a stepping sound as he moves his legs into the firing position.
// Then he chooses an attack to use.
		TNT1 A 0 A_StopSound(5)
		TNT1 A 0 A_PlaySound("cyberdemony/firingstep", 7, 1, 0, 0.7)
		TNT1 A 0 A_JumpIfCloser(1024, "CloseCombat")
		Goto LongRange
	LongRange:
		TNT1 A 0
		TNT1 A 0 A_Jump(220, "FireProxBall") // a fast, long range missile proximity explosive
		Goto ChargeGoldLaser // gigantic gold explosive energy beam
	CloseCombat:
		TNT1 A 0
		TNT1 A 0 A_JumpIfCloser(512, "CloserCombat")
		TNT1 A 0 A_Jump(200, "GoldPulseShots", "GoldPulseShots2") // a trio of gold energy blasts
		TNT1 A 0 A_Jump(200, "ChargeGoldScatterLaser", "RedEyeBlasts") // huge swarm of inaccurate weak gold energy blasts
		Goto ChargeGoldLaser // gigantic gold explosive energy beam
	CloserCombat:
		TNT1 A 0
		TNT1 A 0 A_Jump(120, "RedEyeBlasts", "GoldPulseShots") // redirecting eye beam that chases the player
		TNT1 A 0 A_JumpIfCloser(300, "GoldShockwave") // slow random direction gold earthquake
		Goto GoldPulseShots // a trio of gold energy blasts
		
	GoldPulseShots:
// Slightly inaccurate pew pew blasts. Far weaker than rockets, but whatever.
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlaseranger", 0)
		RND0 E 6 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlastMain", 55, -25, 0)
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlast", 55, -25, frandom(15,0))
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlast", 55, -25, frandom(0,-15))
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlast", 55, -25, frandom(15,0))
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlast", 55, -25, frandom(0,-15))
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlast", 55, -25, frandom(15,0))
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlast", 55, -25, frandom(0,-15))
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlast", 55, -25, frandom(15,0))
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlast", 55, -25, frandom(0,-15))
		RND0 E 12 A_FaceTarget
		TNT1 A 0 A_MonsterRefire (0, "See")
		TNT1 A 0 A_Jump(128, "GoldPulseShots", "GoldPulseShots2")
		Goto See
	GoldPulseShots2:
// accurate pew pew blasts. Far weaker than rockets, but whatever.
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlaseranger", 0)
		RND0 E 6 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlastMain", 55, -25, 0)
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlastMain", 55, -25, 0)
		RND0 E 2 A_FaceTarget
		RND0 F 4 Bright A_CustomMissile("GildmasterPulseBlastMain", 55, -25, 0)
		RND0 E 2 A_FaceTarget
		TNT1 A 0 A_MonsterRefire (0, "See")
		TNT1 A 0 A_Jump(128, "GoldPulseShots", "GoldPulseShots2")
		Goto See
		
	FireProxBall:
// A golden cannon ball that explodes if it gets too close to its tracer. The coins are cosmetic and harmless.
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlaseranger", 0)
		TNT1 A 0 a_playsound ("cybermancer/attack", CHAN_VOICE, 1, 0, 0.3)
		RND0 EEEEEE 6 A_FaceTarget
		RND0 F 12 Bright A_CustomMissile("GildmasterProxBall", 53, -23)
		RND0 E 12 A_FaceTarget
		Goto See
		
	ChargeGoldLaser:
// Here comes the pain express! All aboard the laser train to hell!
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlaseranger", 0)
		TNT1 A 0 A_PlaySound("cyberdemony/chargemainlaser", CHAN_WEAPON, 1, 0, 0.5)
		TNT1 A 0 a_playsound ("cybermancer/attack", CHAN_VOICE, 1, 0, 0.3)
		RND0 EEEEEE 6 A_FaceTarget
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlasertimer", 20)
		TNT1 A 0 A_PlaySound("cyberdemony/mainlaser", CHAN_WEAPON, 1, 0, 0.1)
		RND0 E 1 Bright A_CustomMissile("GildmasterMainLaserStart", 55, -25)
		Goto FireGoldLaser
	FireGoldLaser:
		TNT1 A 0 A_JumpIf (user_gmotacyberdemonlasertimer <= 0, "CeaseGoldLaseringFacesOff")
		TNT1 A 0 A_FaceTarget
		RND0 F 1 Bright A_CustomMissile("GildmasterMainLaserCore", 55, -25)
		TNT1 A 0 A_FaceTarget
		RND0 E 1 A_CustomMissile("GildmasterMainLaserCore", 55, -25)
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlasertimer", user_gmotacyberdemonlasertimer - 1)
		Goto FireGoldLaser
		
	ChargeGoldScatterLaser:
// Embrace the wind! Oh wait no that's a dispersal laser don't do that.
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlaseranger", 0)
		TNT1 A 0 A_PlaySound("cyberdemony/chargescatterlaser", CHAN_WEAPON, 1, 0, 0.5)
		TNT1 A 0 a_playsound ("cybermancer/attack", CHAN_VOICE, 1, 0, 0.3)
		RND0 EEEEEE 6 A_FaceTarget
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlasertimer", 40)
		TNT1 A 0 A_PlaySound("cyberdemony/scatterlaser", CHAN_WEAPON, 1, 0, 0.1)
		Goto FireGoldScatterLaser
	FireGoldScatterLaser:
		TNT1 A 0 A_JumpIf (user_gmotacyberdemonlasertimer <= 0, "CeaseGoldLaseringFacesOff")
		TNT1 A 0 A_FaceTarget
		TNT1 A 0 A_Jump (128, 2)
		TNT1 AAAA 0 A_CustomMissile("GildmasterScatterBlast", 55, -25, frandom(-8,8))
		RND0 F 1 Bright A_CustomMissile("GildmasterScatterLaserCore", 55, -25)
		TNT1 A 0 A_Jump (128, 2)
		TNT1 AAAA 0 A_CustomMissile("GildmasterScatterBlast", 55, -25, frandom(-8,8))
		RND0 E 1 A_FaceTarget
		TNT1 A 0 A_SetUserVar("user_gmotacyberdemonlasertimer", user_gmotacyberdemonlasertimer - 1)
		Goto FireGoldScatterLaser
	CeaseGoldLaseringFacesOff:
		RND0 E 12 A_FaceTarget
		Goto See

	RedEyeBlasts:
// Try not to let him stare at you too much, it's bad for your health.
		TNT1 A 0 A_FaceTarget
		RND0 G 1
		TNT1 A 0 A_PlaySound("cybermancer/eyebeam", CHAN_WEAPON, 1, 0, 0.8)
		RND0 H 4 BRIGHT A_CustomMissile("GildmasterEyeBeam", 104, -3, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, -10)
		RND0 G 12
		TNT1 A 0 A_PlaySound("cybermancer/eyebeam", CHAN_WEAPON, 1, 0, 0.8)
		RND0 H 4 BRIGHT A_CustomMissile("GildmasterEyeBeam", 104, -3, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, -10)
		RND0 G 12
		TNT1 A 0 A_PlaySound("cybermancer/eyebeam", CHAN_WEAPON, 1, 0, 0.8)
		RND0 H 4 BRIGHT A_CustomMissile("GildmasterEyeBeam", 104, -3, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, -10)
		RND0 G 12
		TNT1 A 0 A_PlaySound("cybermancer/eyebeam", CHAN_WEAPON, 1, 0, 0.8)
		RND0 H 4 BRIGHT A_CustomMissile("GildmasterEyeBeam", 104, -3, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, -10)
		RND0 G 12
		Goto See
		
	GoldShockwave:
// Makes golden shockwaves surge across the ground like lightning, doing damage and launching things upwards.
		TNT1 A 0 A_FaceTarget
		RND0 G 1
		TNT1 A 0 A_PlaySound("cyberdemony/chargemainlaser", CHAN_WEAPON, 0.8, 0, 1.2)
		RND0 G 24
		TNT1 AAAAAAAAAAAAAAA 0 A_CustomMissile("GildmasterGoldShockwave", 0,0,random(0,359), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, 0)
		RND0 G 12
		Goto See
		
	Pain:
		TNT1 A 0 A_StopSound(CHAN_WEAPON)
		TNT1 A 0 A_TakeInventory ("PowerTerrorStatus",999)
 		TNT1 A 0 A_TakeInventory ("PowerKickedStatus",999)
		RND0 I 10 A_PlaySound("cybermancer/pain",CHAN_VOICE,1.0,0,0.3)
		TNT1 A 0 A_Jump(192, "See")
		Goto See
	Pain.Dazer:
	Pain.Superkick:
		RND0 I 2 
		TNT1 A 0 A_GiveInventory ("KickDazer",1)
		RND0 I 8 A_Pain
		goto Dazed
    Dazed:
		RND0 I 2
		RND0 I 1 A_SetAngle (angle+15)
		RND0 I 1 A_JumpIfInventory ("PowerKickedStatus",1,"Dazed")
		Goto See
	
	Death:
		RND0 J 0
		//RND0 J 0 A_Jump(256, "Death_Silly") // Rare SILLY DEATH
		RND0 J 0 A_Jump(16, "Death_Silly") // Rare SILLY DEATH
// Supaaa explodo tiem.
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_PlaySound("cybermancer/death",CHAN_VOICE,1.0,0,ATTN_NONE)
		TNT1 A 0 A_BossDeath
		TNT1 A 0 A_SetUserVar("user_gmotabossexplosiontimer", 40)
	DeathExplosionLoop:
		TNT1 A 0 A_JumpIf (user_gmotabossexplosiontimer <= 0, "DeathFinish")
		TNT1 A 0 A_Quake(4, 4, 0, 768, "")
		RND0 J 1 Bright
		TNT1 A 0 A_Jump (10, 3)
		TNT1 A 0 A_PlaySound("cyberdemony/blowingup", 7, 1, 0, 0.3)
		TNT1 A 0 A_SpawnItemEx ("GoldMMBossExplosion", frandom(-56,56),frandom(-56,56),frandom(4,90), 0,0,0, 0, SXF_NOCHECKPOSITION)
		TNT1 A 1
		RND0 J 1 Bright
		TNT1 A 1
		TNT1 A 0 A_SetUserVar("user_gmotabossexplosiontimer", user_gmotabossexplosiontimer - 1)
		Goto DeathExplosionLoop
	DeathFinish:
		TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx ("GoldMMBossExplosionSlow", frandom(-56,56),frandom(-56,56),frandom(4,32), 0,0,0, 0, SXF_NOCHECKPOSITION)
		TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx ("GoldMMBossExplosionSlow", frandom(-56,56),frandom(-56,56),frandom(33,64), 0,0,0, 0, SXF_NOCHECKPOSITION)
		TNT1 AAAAAAAAAAAA 0 A_SpawnItemEx ("GoldMMBossExplosionSlow", frandom(-56,56),frandom(-56,56),frandom(65,128), 0,0,0, 0, SXF_NOCHECKPOSITION)
		TNT1 A 0 A_Quake(7, 25, 0, 1024, "")
		RND0 J 6 Bright A_PlaySound("cyberdemony/kablooie",CHAN_AUTO,1.0,0,ATTN_NONE)
		TNT1 A 0 A_FaceTarget
		TNT1 A 0 A_CustomMissile ("GildmasterHand", 32, 16, -90, 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterGunArm", 32, -16, 90, 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterArmorChunk", 28, 16, random (90,140), 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterArmorChunk", 28, -16, random (-90,-140), 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterShoulderChunk", 34, 16, random (85,165), 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterShoulderChunk", 34, -16, random (-85,-165), 2, 150)
		RND0 KL 6 Bright
		TNT1 A 0 A_Quake(4, 18, 0, 1024, "")
		CYMN M 6 Bright A_NoBlocking
		CYMN M 6
		CYMN M 30
		goto ded
	ded:
		TNT1 A 0
		TNT1 A 0
		CYMN M -1 A_BossDeath
		Stop
// A rare "silly death". It's strange, implementing other people's in-jokes
// without being at ground zero for their creation... It's like being an
// archeologist who finds a cave drawing of a dong.
	Death_Silly:
		RND0 JK 8
		RND0 L 32 A_PlaySound("cybermancer/headhands",CHAN_BODY,1.0,0,ATTN_NONE)
		RND0 L 64 A_PlaySound("cybermancer/sorryimdead",CHAN_VOICE,1.0,0,ATTN_NONE)
		TNT1 A 0 A_FaceTarget
		TNT1 A 0 A_SpawnItem("MMBossExplosionSilly",0,16)
		TNT1 A 0 a_playsound ("treeboom",5)
		TNT1 A 0 Radius_Quake (3,20,0,32,0)
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_CustomMissile ("GildmasterHand", 32, 16, -90, 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterGunArm", 32, -16, 90, 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterArmorChunk", 28, 16, random (90,140), 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterArmorChunk", 28, -16, random (-90,-140), 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterShoulderChunk", 34, 16, random (85,165), 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterShoulderChunk", 34, -16, random (-85,-165), 2, 150)
		CYMN M 6
		CYMN M 30
		goto ded
	Death.superkick:	
		RND0 L 1 A_NoBlocking
		RND0 L 1 a_scalevelocity (0.1)
 		RND0 L 1 a_stop
		RND0 L 1 A_BossDeath
		TNT1 A 0 a_changeflag ("NOCLIP",1)
		TNT1 A 0 a_changeflag ("NOGRAVITY",1)
		RND0 L 1 a_facetarget
		TNT1 A 0 a_stopsound (CHAN_VOICE)
		TNT1 A 0 thrustthingz (0,80,0,1)
		TNT1 A 0 ThrustThing(angle*256/360+128, 110, 1, 0)
		TNT1 A 0 A_SpawnItemEx ("bosskickdeathsound")
		RND0 L 1
		RND0 L 2		
	kickfly:
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		RND0 L 1 A_SpawnItemEx ("KustamParticle",random(-8,8),random(-8,8),random(-10,10),random(-120,120)/15.0,random(-130,130)/12.0,random(-110,110)/17.0,0)
		TNT1 A 0 A_SpawnItem("MMBossExplosionSilly",0,16)
		TNT1 A 0 a_playsound ("treeboom",5,1,0,0.3)
		TNT1 A 0 Radius_Quake (3,20,0,32,0)
		TNT1 A 0 A_CustomMissile ("GildmasterHand", 32, 16, -90, 2, 150)
		TNT1 A 0 A_CustomMissile ("GildmasterGunArm", 32, -16, 90, 2, 150)
		stop		
	}
}


//Gildmaster attacks
ACTOR GildmasterPulseBlast : CyberdemonPulseBlast
{
	Speed 27
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 ThrustThingZ (0, random(0,3), random(0,1), 1)
		TNT1 A 0 A_PlaySound("cyberdemony/pulseshot", CHAN_VOICE, 1, 0, 0.7)
		Goto SpawnLoop
	SpawnLoop:
		TNT1 A 0 A_SpawnItemEx ("GildmasterPulseBlastTrail", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
		GMBL B 1 Bright
		Loop
	Death:
		TNT1 A 0 A_PlaySound("cyberdemony/pulseshothit", CHAN_VOICE, 1, 0, 0.6)
		TNT1 A 0 A_SpawnItemEx ("GildmasterPulseBlastHit", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
		TNT1 A 10
		Stop
	}
}

ACTOR GildmasterPulseBlastMain : GildmasterPulseBlast
{
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_PlaySound("cyberdemony/pulseshot", CHAN_VOICE, 1, 0, 0.7)
		Goto SpawnLoop
	}
}

ACTOR GildmasterScatterBlast : GildmasterPulseBlast
{
	Speed 35
	Damage (15)
	Decal ""
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 ThrustThingZ (0, random(0,8), random(0,1), 1)
		Goto SpawnLoop
	SpawnLoop:
		TNT1 A 0 A_SpawnItemEx ("GildmasterPulseBlastTrail", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
		GMBL B 1 Bright
		Loop
	Death:
		TNT1 A 0 A_PlaySound("cyberdemony/pulseshothit", CHAN_VOICE, 1, 0, 0.6)
		TNT1 A 0 A_SpawnItemEx ("GildmasterPulseBlastHit", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
		TNT1 A 10
		Stop
	}
}

ACTOR GildmasterPulseBlastTrail
{
	Radius 4
	Height 4
	+NOCLIP
	+NOGRAVITY
	+CLIENTSIDEONLY
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 2
		CYS2 BC 2 Bright
		Stop
	}
}

ACTOR GildmasterPulseBlastHit
{
	Radius 4
	Height 4
	Scale 3.25
	+NOCLIP
	+NOGRAVITY
	+CLIENTSIDEONLY
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		CYS3 ABCDE 3 Bright
		Stop
	}
}

ACTOR GildmasterScatterLaserCore
{
	Radius 4
	Height 4
	Speed 35
	Damage (0)
	RenderStyle Add
	Alpha 0.10
	Scale 4.0
	Projectile
	+THRUACTORS
	+CLIENTSIDEONLY
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx ("GildmasterScatterLaserCoreTrail", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
		CYS1 A 1 Bright
		Loop
	Death:
		TNT1 A 5
		Stop
	}
}

ACTOR GildmasterScatterLaserCoreTrail
{
	Radius 4
	Height 4
	RenderStyle Add
	Alpha 0.05
	Scale 4.0
	+NOCLIP
	+NOGRAVITY
	+CLIENTSIDEONLY
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 2
		CYS1 ABCDEFGHIJ 1 Bright
		Stop
	}
}

ACTOR GildmasterMainLaserCore
{
	Radius 16
	Height 12
	Speed 45
	Damage (4)
	RenderStyle Add
	Alpha 0.98
	Scale 3.0
	Projectile
	+RIPPER
	Damagetype "BigCyberLaser"
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx ("GildmasterMainLaserCoreTrail", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
		CYS1 A 1 Bright
		Loop
	Death:
		TNT1 A 5
		Stop
	}
}

ACTOR GildmasterMainLaserStart : GildmasterMainLaserCore
{
	Damage (100)
	Scale 4.0
	Damagetype "BigCyberLaser"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx ("GildmasterMainLaserCoreTrail", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
		CYS1 A 1 Bright
		Loop
	Death:
		TNT1 A 0 A_Explode (25,256)
		TNT1 A 0 A_PlaySound("cyberdemony/mainlaserhit", CHAN_VOICE, 1, 0, 0.1)
		TNT1 A 0 A_SpawnItemEx ("GildmasterMainLaserHit", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
		TNT1 A 5
		Stop
	}
}

ACTOR GildmasterMainLaserCoreTrail
{
	Radius 4
	Height 4
	RenderStyle Add
	Alpha 0.65
	Scale 3.0
	+NOCLIP
	+NOGRAVITY
	+CLIENTSIDEONLY
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		CYS1 ABCDEFGHIJ 1 Bright
		Stop
	}
}

ACTOR GildmasterMainLaserHit
{
	Radius 4
	Height 4
	Scale 6.75
	+NOCLIP
	+NOGRAVITY
	+CLIENTSIDEONLY
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		MMXP ABCDEFGHIJKL 2 Bright
		Stop
	}
}

// Detonates if you get near it, making it less likely to murderkill your face
// but more likely to discombobulate you over a thousand years
actor GildmasterProxBall : fastprojectile
{
	alpha 1
	height 12
	radius 5
	speed 35
	damage (35)
	scale 2
	species "enemyshot"
	+NOTIMEFREEZE
	+FORCEXYBILLBOARD	
	+LOOKALLAROUND
	+SEEKERMISSILE
	seesound ""
	deathsound ""
	translation "192:207=169:190", "96:111=180:180"
	states
	{
	spawn:
		TNT1 A 0
		// TODO FOR KEGAN: probably give this a different sound
		TNT1 A 0 A_PlaySound("cyberdemony/missile", CHAN_VOICE, 1, 0, 0.5)
	SpawnLoop:
		TNT1 A 0 A_JumpIfTracerCloser (140, "Detonate")
		TNT1 A 0 A_ScaleVelocity (1.03)
		GLML A 4 Bright 
		TNT1 A 0 a_spawnitem ("GildmasterEyeBeamTrail")
		loop
		
	Detonate: // detonate in midair if it gets too close to the tracer
		TNT1 A 0 A_ChangeFlag ("THRUACTORS", 1)
		TNT1 A 0 A_ChangeFlag ("NOCLIP", 1)
		TNT1 A 0 A_Stop
		TNT1 A 0 A_Die
	death:
		TNT1 A 0 A_SetScale (2.5)
		TNT1 A 0 A_PlaySound("cyberdemony/missilehit", CHAN_VOICE, 1, 0, 0.3)
		TNT1 A 0 A_Explode (15,150,0,0,150)
		TNT1 A 0 A_Explode (50,180,0,0,50)
		TNT1 A 0 Radius_Quake (5,10,0,30,0)
		// TODO FOR KEGAN: make these into a spray of tiny gold coins or something
		TNT1 AAA 0 a_spawndebris ("Coindebris")
		TNT1 AAAAAA 0 A_SpawnItemEx ("CoinDebris",random(-16,16),random(-16,16),random(-10,10),random(-100,100)/20.0,random(-100,100)/20.0,random(-100,100)/20.0,0,160)
		TNT1 A 0 a_fadeout (0.10)
		MMXP ABCDEFGHIJKL 2 Bright
		stop
	}
}


// Fires Darkseid-esque red energy bolts that move in increments and redirects itself at its tracer a few times
ACTOR GildmasterEyeBeam
{
	Radius 8
	Height 8
	Speed 32
	Damage (15)
	RenderStyle Add
	Projectile
	species "enemyshot"
	scale 0.7
	Obituary "%o gazed into the Gildmaster's eye"
	+SEEKERMISSILE
	+FORCEXYBILLBOARD
	+NOTELEPORT
	Translation "192:192=4:4", "192:207=169:191"
  
	var int user_redirectcounter;
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SeekerMissile (90, 90, SMF_PRECISE)
	SpawnLoop:
		CYS1 JJJJJJJJJJ 1 Bright A_SpawnItemEx("GildmasterEyeBeamTrail", frandom(-0.3,0.3),frandom(-0.3,0.3),frandom(-0.3,0.3), 0,0,0, 0, SXF_NOCHECKPOSITION)
	Redirect:
		TNT1 A 0 A_JumpIf (user_redirectcounter >= 3, "Detonate")
		TNT1 A 0 A_SetUserVar("user_redirectcounter", user_redirectcounter + 1)
		TNT1 A 0 A_PlaySound("cybermancer/eyebeam", CHAN_WEAPON, 0.7, 0, 1.5)
//		TNT1 A 0 A_SetSpeed (speed+6) // darm, zadnostrom no workie
		TNT1 A 0 A_Stop
		TNT1 A 0 A_SpawnItemEx("GildmasterEyeBeamRedirectionShockwave", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION)
		CYS1 EDEDEDEDEDE 1 Bright
		CYS1 EDEDEDEDE 1 Bright
		TNT1 AAA 0 A_SeekerMissile (90, 90, SMF_PRECISE)
		Goto SpawnLoop
		
	Detonate: // detonate in midair if it reaches max redirects
		TNT1 A 0 A_ChangeFlag ("THRUACTORS", 1)
		TNT1 A 0 A_ChangeFlag ("NOCLIP", 1)
		TNT1 A 0 A_Stop
		TNT1 A 0 A_Die
	Death:
		TNT1 A 0
		TNT1 A 0 A_PlaySound("cyberdemony/pulseshothit", CHAN_VOICE, 1, 0, 0.6)
		TNT1 A 0 Radius_Quake (1,10,0,30,0)
		MMXP ABCDEFGHIJKL 1 Bright
		Stop
	}
}

ACTOR GildmasterEyeBeamTrail
{
	Radius 4
	Height 4
	scale 0.5
	+NOCLIP
	+NOGRAVITY
	+CLIENTSIDEONLY
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SetScale(scalex * frandom(0.8,1.2))
		TNT1 A 0 A_Jump (256, 1,2,3,4,5)
		CYS1 A 1 Bright A_FadeOut(0.1)
		Wait
		CYS1 B 1 Bright A_FadeOut(0.1)
		Wait
		CYS1 C 1 Bright A_FadeOut(0.1)
		Wait
		CYS1 D 1 Bright A_FadeOut(0.1)
		Wait
		CYS1 E 1 Bright A_FadeOut(0.1)
		Wait
	}
}

// Spawns shockwaves whenever the eyebeams change direction, visual effect
ACTOR GildmasterEyeBeamRedirectionShockwave
{
	Radius 4
	Height 4
	scale 2.5
	+NOCLIP
	+NOGRAVITY
	+CLIENTSIDEONLY
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SetScale(scalex * 1.15)
		CYS3 A 1 Bright A_FadeOut(0.2)
		Loop
	}
}

ACTOR GildmasterGoldShockwave
{
	Radius 16
	Height 6
	Speed 22
	Damage (0)
	RenderStyle Add
	Alpha 0.28
	XScale 3.0
	YScale 0.25
	species "enemyshot"
	Projectile
	+THRUACTORS
	+FLOORHUGGER
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_Jump(256, 1,2,3)
		CYS1 AAAAAA 1 Bright A_ChangeVelocity (velx+frandom(-1.0,1.0), vely+frandom(-1.0,1.0), 0, CVF_REPLACE)
		TNT1 A 0 A_PlaySound("cyberdemony/missilehit", CHAN_WEAPON, 0.8, 0, 1.1)
		TNT1 A 0 A_Explode (30, 70, 0)
		TNT1 A 0 A_RadiusGive ("CybermancerEyeBeamEffect", 100, RGF_PLAYERS|RGF_MONSTERS, 1)
		TNT1 A 0 A_SpawnItemEx ("GildmasterGoldShockwaveBlast", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION)
		TNT1 AAA 0 a_spawndebris ("Coindebris2")
		TNT1 AAAAA 0 A_SpawnItemEx ("CoinDebris2",random(-16,16),random(-16,16),random(3,10),random(-100,100)/20.0,random(-100,100)/20.0,random (5,15),0,160)
		Loop
	Death:
		TNT1 A 5
		Stop
	}
}

ACTOR GildmasterGoldShockwaveBlast
{
	Radius 4
	Height 4
	RenderStyle Add
	Alpha 0.98
	XScale 1.0
	YScale 3.0
	+THRUACTORS
	+NOCLIP
	+NOINTERACTION
	+CLIENTSIDEONLY
	Translation "192:192=4:4", "192:207=169:191"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SetScale (scalex*1.01, scaley*1.07)
		CYS1 A 1 Bright A_FadeTo(0, 0.05, 1)
		Loop
	}
}

// Gibs for the Death Sequence
actor GildmasterHand : CybermancerHand
{
    States
    {
    Spawn:
        GMHN A 0 
        GMHN A 0 ThrustThingZ (0, 45, 0, 1)
		GMHN A 0 A_Jump(64, "SeeRare")
        goto See 
    See:
        GMHN A 5 A_Custommissile("Blood", -5,0,0)
        GMHN B 5 ThrustThingZ(0,6,1,1)
        GMHN CD 5 
		GMHN E 5 A_Custommissile("Blood", -5,0,0)
        GMHN F 5 ThrustThingZ(0,6,1,1)
        GMHN GH 5 
        loop
    SeeRare: // rude
        GMHN I 5 A_Custommissile("Blood", -5,0,0)
        GMHN J 5 ThrustThingZ(0,6,1,1)
        GMHN KL 5 
		GMHN M 5 A_Custommissile("Blood", -5,0,0)
        GMHN N 5 ThrustThingZ(0,6,1,1)
        GMHN OP 5 
        loop
    Death:
        GMHN A -1 
        Stop
    }
}

actor GildmasterGunArm : CybermancerGunArm
{
    States
    {
    Spawn:
        GMHN Q 0 
        GMHN Q 0 ThrustThingZ (0, 45, 0, 1)
        goto See 
    See:
        GMHN Q 5 A_Custommissile("Blood", -5,0,0)
        GMHN R 5 ThrustThingZ(0,6,1,1)
        GMHN ST 5 
		GMHN U 5 A_Custommissile("Blood", -5,0,0)
        GMHN V 5 ThrustThingZ(0,6,1,1)
        GMHN WX 5 
        loop
    Death:
        GMHN U -1 
        Stop
    }
}

actor Gildmasterarmorchunk : CybermancerHand
{
    States
    {
    Spawn:
        GMA1 A 0 
        GMA1 A 0 ThrustThingZ (0, 45, 0, 1)
        goto See 
    See:
        GMA1 A 2 
        GMA1 B 2 ThrustThingZ(0,6,1,1)
        GMA1 CD 2 
		GMA1 E 2 
        GMA1 F 2 ThrustThingZ(0,6,1,1)
        GMA1 GH 2 
        loop
    Death:
		TNT1 A 0
		TNT1 A 0 a_jump (180, "Altdeath1","AltDeath2")
        GMA1 B -1 
        Stop
	AltDeath1:
        GMA1 D -1 
        Stop
	AltDeath2:
        GMA1 H -1 
        Stop	
    }
}

actor GildmasterShoulderchunk : CybermancerHand
{
    States
    {
    Spawn:
        GMA2 A 0 
        GMA2 A 0 ThrustThingZ (0, 45, 0, 1)
        goto See 
    See:
        GMA2 A 2 
        GMA2 B 2 ThrustThingZ(0,6,1,1)
        GMA2 CD 2 
		GMA2 E 2 
        GMA2 F 2 ThrustThingZ(0,6,1,1)
        GMA2 GH 2 
        loop
    Death:
		TNT1 A 0
		TNT1 A 0 a_jump (180, "Altdeath1","AltDeath2")
        GMA2 B -1 
        Stop
	AltDeath1:
        GMA2 C -1 
        Stop
	AltDeath2:
        GMA2 E -1 
        Stop	
    }
}



//Altered death explosion sprites
ACTOR GoldMMBossExplosion : MMBossExplosion
{
	translation "192:207=169:190", "96:111=180:180"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx ("CoinDebris",random(-16,16),random(-16,16),random(-10,10),random(-100,100)/10.0,random(-100,100)/10.0,random(-100,100)/10.0,0,160)
		MMXP ABCDEFGHIJKL 1 Bright
		Stop
	}
}

ACTOR GoldMMBossExplosionSlow : MMBossExplosionSlow
{
	translation "192:207=169:190", "96:111=180:180"
	states
	{
	Spawn:
		TNT1 A 0
		TNT1 AA 0 A_SpawnItemEx ("CoinDebris",random(-16,16),random(-16,16),random(-10,10),random(-100,100)/5.0,random(-100,100)/5.0,random(-100,100)/5.0,0,160)
		MMXP ABCDEFGHIJKL 4 Bright
		Stop
	}
}



//Cosmetic coins and shit
actor CoinDebris
{
	Health 4
	radius 3
	height 6
	speed .1
	scale 0.5
	Mass	0
	+missile
	+clientsideonly
	+doombounce
	+FLOORCLIP
	+DONTSPLASH
	+NOTELEPORT
	+BRIGHT
	States
	{
	Spawn:	
		TNT1 A 0
		GMCO ABCD 2
		GMCO ABCD 2
		GMCO ABCD 2
		GMCO ABCD 2
		GMCO ABCD 2
		TNT1 A 2
		GMCO ABCD 2
		TNT1 A 2
		GMCO ABCD 2
		TNT1 A 2
		GMCO ABCD 2
		Stop
	death:
		TNT1 A 1
		stop
	}
}

actor CoinDebris2 : CoinDebris
{
	states
	{
	Spawn:	
		TNT1 A 0
		GMCO ABCD 1
		GMCO ABCD 1
		GMCO ABCD 1
		TNT1 A 2
		GMCO ABCD 1
		TNT1 A 2
		GMCO ABCD 1
		Stop
	death:
		TNT1 A 1
		stop
	}
}