/*	kd:

	Here you'll find the prizm lazer handling: The rotating beams, colour and
	damage type assignment. Usage is fairly easy by including the Gc_Prism
	struct in your weapon or something!
	
	*/

class Gc_PrismRaveHandler : EventHandler {
	const cycle_speed	= 16;
	const intensity		= 0.1357;
	
	private uint			tics;
	private bool			is_locally_active;
	private bool			is_extreme_mode;
	private RenderScreen	rscreen;
	
	private void InitRave () {
		rscreen.ToUserScreen();
		tics = 0;
	}
	
	static void StartLocalRave (int player, bool is_extreme = false) {
		if(player == consoleplayer) {
			let handler = Gc_PrismRaveHandler(Find("Gc_PrismRaveHandler"));
			
			if(handler) {
				handler.InitRave();
				handler.is_locally_active = true;
				handler.is_extreme_mode = is_extreme;
			}
		}
	}
	
	static void EndLocalRave (int player) {
		if(player == consoleplayer) {
			let handler = Gc_PrismRaveHandler(Find("Gc_PrismRaveHandler"));
			
			if(handler) {
				handler.is_locally_active = false;
			}
		}
	}
	
	override void WorldTick () {
		if(is_locally_active) {
			tics = Gc_PulseFunc.ModIntoColorCycle(tics + cycle_speed);
		}
	}
	
	override void RenderOverlay (RenderEvent event) {
		if(is_locally_active) {
			Color col = Gc_PulseFunc.RgbCycle(tics + event.fractic * cycle_speed);
			Screen.Dim(col, intensity, 0, 0, rscreen.width, rscreen.height);
			
			if(!is_extreme_mode) {
				return;
			}
			
			
		}
	}
}

class Gc_PrismDamage : FastProjectile {
	class <Actor> impact_class;
	
	default {
		+RIPPER
		+BLOODLESSIMPACT
		+FORCERADIUSDMG
		+NOTIMEFREEZE
		// Speed 10;
		RenderStyle "None";
		Radius 8;
		Height 10;
		MissileHeight 16;
		Damage (2);
	}
	
	states {
	spawn:
		BAL1 A 1337;
		loop;
	death:
		BAL1 A 4; // A_SpawnItemEx(impact_class);
		stop;
	}
}

class Gc_PrismBeam : Actor {
	class <Actor> impact_class;
	
	default {
		+NOINTERACTION
		+INTERPOLATEANGLES
		+NOTIMEFREEZE
		RenderStyle "AddShaded";
		Alpha 0.99;
	}
	
	states {
	spawn:
		TNT1 A 0 nodelay {
			Actor mo = Spawn("Gc_PrismLight", pos);
			
			if(mo) {
				mo.master = self;
				mo.SetShade(fillcolor);
			}
		}
		
		// kd:
		// pls rember that wen u feel like fireing railgun fowrward
		// never forget ttimes wen i set pitch + 90
		
		// wen railgun is misalign alway rember pitch - 90
		BAL1 A 1 bright {
			// pitch -= 90;
			// A_CustomRailgun(
				// 10 * random(6, 10),
				// 0,
				// "White",
				// "White",
				// flags: RGF_CENTERZ | RGF_EXPLICITANGLE,
				// pufftype: "BulletPuff");
			// pitch += 90;
			
			// native Actor A_SpawnProjectile(class<Actor> missiletype, double spawnheight = 32, double spawnofs_xy = 0, double angle = 0, int flags = 0, double pitch = 0, int ptr = AAPTR_TARGET);
			
			// kd:
			// spawn functions suck
			
			let proj = Gc_PrismDamage(Spawn("Gc_PrismDamage", pos));
			
			if(proj) {
				proj.impact_class = impact_class;
				proj.target = target;	// the master sergeant shooter person
				proj.A_SetDamageType(damagetype);
				
				float cosvang	= cos(90 - pitch);
				
				proj.angle = angle;
				proj.pitch = pitch;
				proj.vel = (
					cosvang * cos(angle),
					cosvang * sin(angle),
					sin(90 - pitch)) * 600;
			}
			
			/* Actor proj = A_SpawnProjectile(
				"Gc_PrismDamage",
				spawnheight: 0,
				flags: FPF_NOAUTOAIM,
				pitch: pitch,
				ptr: AAPTR_TARGET);
			
			if(proj) {
				proj.A_SetDamageType(damagetype);
			} */
		}
		
		wait;
	}
}

class Gc_PrismLight : Gc_PrismBeam {
	default {
		-INTERPOLATEANGLES
		Alpha 0.99;
		Scale 0.28;
		// RenderStyle "AddStencil";
		// StencilColor "White";
	}
	
	override void Tick () {
		if(!master) {
			Destroy();
			return;
		}
		
		SetOrigin(master.pos, true);
		super.Tick();
	}
	
	states {
	spawn:
		1SPK A 0;
	loop_this:
		1SPK "#" 1 bright {
			alpha = frandom(0.5, 0.6);
		}
		
		1SPK "#" 1 bright {
			frame = random(0, 7);
			alpha = frandom(0.8, 0.99);
		}
		loop;
	}
}

class Gc_Prism play {
	private	Gc_Sphere			aim;
	private float				rotation;
	private float				radius;
	private float				width;
	private float				scale;
	private float				offset_hor;
	private float				offset_ver;
	private float				attack_z_offset;
	private float				ver_f;	// Reciprocal default height
	
	private int					beam_count;
	private Array <Color>		colors;
	// private Array <int>			col_r;
	// private Array <int>			col_g;
	// private Array <int>			col_b;
	private Array <int>			col_mod;
	private Array <Gc_PrismBeam>beams;
	private float				start_radius;
	private float				end_radius;
	private float				start_width;
	private float				end_width;
	private float				start_scale;
	private float				end_scale;
	
	const color_dist			= 4 * 0x100;
	
	static const Name damage_types [] = {
		"Breath"		// Red
	,	"Fire"			// Orange
	,	"Lightning"		// Yellow
	,	"Acid"			// Lime
	,	"Tiberium"		// Green
	,	"Ice"			// Cyan
	,	"LightningBlue"	// Blue
	,	"Flesh"			// Purple
	};
	
	static const Name impact_class [] = {
		"PrismImpactRed"
	,	"PrismImpactOrange"
	,	"PrismImpactYellow"
	,	"PrismImpactLime"
	,	"PrismImpactGreen"
	,	"PrismImpactCyan"
	,	"PrismImpactBlue"
	,	"PrismImpactPurple"
	};
	
	/* static const Name decal_bullet_class [] = {
		"PrismDecalRed"
	,	"PrismDecalOrange"
	,	"PrismDecalYellow"
	,	"PrismDecalLime"
	,	"PrismDecalGreen"
	,	"PrismDecalCyan"
	,	"PrismDecalBlue"
	,	"PrismDecalPurple"
	}; */
	
	void Start (
		Actor user,
		int count		= 6,
		float start_rad	= 1,	float end_rad	= 0,
		float start_w	= 50,	float end_w		= 5,
		float start_s	= 0,	float end_s		= 4.5,
		float offset_h	= -25,	float attackzoffset	= 0) {
		
		rotation		= 0;
		start_radius	= start_rad;
		end_radius		= end_rad;
		start_width		= start_w;
		end_width		= end_w;
		start_scale		= start_s;
		end_scale		= end_s;
		radius			= start_radius;
		width			= start_width;
		scale			= start_scale;
		beam_count		= max(1, count);
		offset_hor		= offset_h;
		ver_f			= 1.0 / max(1, user.height);
		offset_ver		= 0.5 * user.height + attackzoffset;
		
		if(user is 'PlayerPawn') {
			offset_ver += PlayerPawn(user).attackzoffset;
		}
		
		// kd: Now do the colour interpolation and give each colour the damage
		// modifier.
		
		uint dmg_count		= damage_types.size();
		int color_x			= 0;
		int color_step		= Gc_PulseFunc.color_cycle_len / beam_count;
		int r, g, b;
		
		colors.clear();
		// col_r.clear();
		// col_g.clear();
		// col_b.clear();
		col_mod.clear();
		colors.reserve(beam_count);
		// col_r.reserve(beam_count);
		// col_g.reserve(beam_count);
		// col_b.reserve(beam_count);
		col_mod.reserve(beam_count);
		
		for(int i = 0; i < beam_count; i++) {
			[r, g, b] = Gc_PulseFunc.Rgb255Cycle(color_x);
			
			// col_r	[i] = r;
			// col_g	[i] = g;
			// col_b	[i] = b;
			col_mod	[i] = (color_x * dmg_count / color_dist) % dmg_count;
			colors	[i] = Color(0xff, r, g, b);
			color_x += color_step;
		}
		
		// Spawn the beams.
		vector3 init_pos = user.pos; // dunno, should be the shooting pos
		
		beams.clear();
		beams.reserve(beam_count);
		
		for(int i = 0; i < beam_count; i++) {
			beams [i] = Gc_PrismBeam(Actor.Spawn("Gc_PrismBeam"));
			beams [i].SetShade(colors [i]);
			beams [i].master = user;
			beams [i].target = user;
			beams [i].A_SetDamageType(damage_types [col_mod [i]]);
			beams [i].impact_class = impact_class [col_mod [i]];
		}
	}
	
	void Tick (Actor user, float rot_speed = 10, float closing_f = 0.05, float scaling_f = 0.01) {
		aim.Orient(user.angle, -user.pitch);
		rotation	+= rot_speed;
		
		radius		+= closing_f * (end_radius	- radius);
		width		+= closing_f * (end_width	- width);
		scale		+= scaling_f * (end_scale	- scale);
		
		// Pillow: smol fix for the fact there's powersuit\deadmaker and they
		// switch this shit dynamically. PLZ DONT KEEL ME~
		
		if(user is 'PlayerPawn') {
			offset_ver = PlayerPawn(user).attackzoffset;
		}
		
		// Arrange the beams:
		
		for(int i = 0; i < beam_count; i++) {
			// check if beam exists (cuz you never know with gzd)
			// A_GnuGoesPewpewpew
			// beams [i].scale.z = lololololol
			// etc. etc.
			
			float	ang;
			float	vang;
			vector3	shoot_pos;
			
			[shoot_pos, ang, vang] = aim.PrismPosAnglePitch(
				50,
				offset_hor,
				width,
				radius,
				i * 360.0 / beam_count + rotation);
			
			shoot_pos += (0, 0, offset_ver * ver_f * user.height);
			
			beams [i].SetOrigin(user.pos + shoot_pos, true);
			beams [i].A_SetAngle(ang,  SPF_INTERPOLATE);
			beams [i].A_SetPitch(90 - vang, SPF_INTERPOLATE);
			
			FLineTraceData data;
			beams [i].LineTrace(
				ang,
				666999.666,
				-vang,
				TRF_THRUACTORS | TRF_THRUHITSCAN | TRF_THRUBLOCK,
				data: data);
			
			// Actor decal = Actor.Spawn(decal_bullet_class [col_mod [i]], data.hitlocation);
			Actor impact = Actor.Spawn(beams [i].impact_class, data.hitlocation);
			
			if(impact) {
				impact.target = user;
				impact.master = user;
				impact.angle = ang;
				impact.pitch = -vang;
			}
			
			beams [i].A_SetScale(scale, 0.02 * data.distance);
		}
	}
	
	void End () {
		for(int i = beam_count; 0 <= --i;) {
			if(beams [i]) {
				beams [i].Destroy();
				// might replace with disappear anim but will need tick to run
				// in background meaning should be thinker meaning I have to
				// change the entire setup because OOP is gay
			}
			
			beams.delete(i);
		}
		
		beams.clear();
		colors.clear();
		// col_r.clear();
		// col_g.clear();
		// col_b.clear();
		col_mod.clear();
		beam_count = 0;
	}
}

//Here starts Pillowy mountains of madness.
//Basis
class PrismRadius : Inventory { Default { Inventory.MaxAmount 70; } }
class PrismSpin   : Inventory { Default { Inventory.MaxAmount 360; } }
class PrismPower  : Inventory { Default { Inventory.MaxAmount 70; } }

//The particles proved to be too lag-inducing to be spawned during beam's activity, so I decided to reuse them as impact stuff instead.
class PrismParticleBase : Actor
{
	Default
	{
		Renderstyle "Add";
		Scale 0.02;
		Alpha 0.1;
		+NOINTERACTION
		+NOTIMEFREEZE //You'd better leave this intact if you value your computational power.
	}
	
	Int User_Counter;
	
	States
	{
	PhaseOne:
		"####" "#" 1 Bright {
			A_SetScale(Scale.X + frandom(0.005,0.001));
			A_FadeIn(0.045);
			A_ChangeVelocity(frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(0.3,-0.2),CVF_RELATIVE);
			If(Alpha >= 0.99) { Return ResolveState("PhaseTwo"); }
			Return ResolveState(Null);
		}
		Loop;
	PhaseTwo:
		"####" "#" 1 Bright {
			A_SetScale(Scale.X - frandom(0.005,0.001));
			A_FadeOut(0.045);
			A_ChangeVelocity(frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(0.3,-0.2),CVF_RELATIVE);
			A_JumpIf(Scale.X <= 0, "Null");
		}
		Loop;
	}
}

class PrismBeamBase : Actor
{
	Default
	{
		Renderstyle "Add";
		Scale 0.3;
		Alpha 0.8;
		+NOINTERACTION
		+NOTIMEFREEZE
	}
	
	Int User_Counter;
	Int User_TM;
	
	States
	{
	PhaseOne:
		"####" "#" 0 { User_Counter = 1; }
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	PhaseTwoEnter:
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	PhaseTwo:
		"####" "#" 1 Bright { User_Counter--; }
		"####" "#" 0 A_JumpIf(User_Counter >= 1, "PhaseTwo");
	PhaseThree:
		"####" "#" 0;
		Stop;
	}
}

class PrismBloodless : Actor
{
	Default
	{
		+BLOODLESSIMPACT
	}
}

class PrismImpactBase : Actor
{
	Default
	{
		Renderstyle "Add";
		ProjectileKickback 0;
		Scale 0.2;
		Alpha 0.8;
		+NOEXTREMEDEATH
		+PUFFONACTORS
		+NODAMAGETHRUST
		+ALWAYSPUFF
		+NOBLOCKMAP
		+BLOODLESSIMPACT
		+PUFFGETSOWNER
		+NOINTERACTION
		+DONTSPLASH
		+NOTIMEFREEZE
		+FORCERADIUSDMG
		+ALLOWTHRUFLAGS
		+MTHRUSPECIES
	}
	
	Int User_Counter;
	Int User_TM;
	
	States
	{
	PhaseOne:
		"####" "#" 0 {
			A_Explode((8),128,0);
			User_Counter = random(1,3);
		}
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	PhaseTwoEnter:
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	PhaseTwo:
		"####" "#" 1 Bright {
			User_Counter--;
			Return A_JumpIf(User_Counter >= 1, "PhaseTwo");
		}
	PhaseThree:
		"####" "#" 1 Bright {
			A_SetScale(Scale.X + 0.2);
			A_FadeOut(0.1);
		}
		Loop;
	}
}

//Possibly stupidest way to hack in decals in railgun, ever.
class PrismDecalBase : Actor
{
	Default
	{
		+NOBLOCKMAP
		+NOEXTREMEDEATH
		+ALWAYSPUFF
		+BLOODLESSIMPACT
		+DONTSPLASH
		+NOTIMEFREEZE
		+ALLOWTHRUFLAGS
		+MTHRUSPECIES
	}
}

//Light actor for rotator
class PrismLightBase : Actor
{
	Default
	{
		Projectile;
		+NOINTERACTION
		+NOTIMEFREEZE
	}
	
	Float User_Angle;
	
	States
	{
	Spawn:
		TNT1 A 0 A_Jump(256,"Looplet");
	Looplet:
		"####" "#" 1 Bright A_Warp(AAPTR_TARGET, 56.0+frandom(12.0,-12.0),
							frandom(12.0,-12.0), 25.0+frandom(12.0,-12.0),
							8.0, WARPF_NOCHECKPOSITION|WARPF_INTERPOLATE|WARPF_USECALLERANGLE);
		"####" "#" 0 A_JumpIf(CountInv("PrismRadius",AAPTR_TARGET),"Looplet");
		Stop;
		
	}
}

//Beam variations

//Blue
class PrismBeamBlue : PrismBeamBase
{
	states
	{
	Spawn:
		PRSP A 0 {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			Return ResolveState("PhaseOne");
		}
		Goto PhaseOne;
	PhaseTwoEnter:
		"####" "#" 0 A_SpawnItemEx("PrismParticleBlue",frandom(15.0,-15.0),
			frandom(15.0,-15.0),frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
			frandom(2.0,-2.0),frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	}
}

class PrismParticleBlue : PrismParticleBase
{
	states
	{
	Spawn:
		BPRT B 0 A_Jump(256,"PhaseOne");
		Goto PhaseOne;
	}
}

class PrismImpactBlue : PrismImpactBase
{
	Default
	{
		DamageType "LightningBlue";
	}
	
	States
	{
	Spawn:
		PRSP A 0 NoDelay {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			A_SpawnItemEx("PrismParticleBlue",frandom(15.0,-15.0),frandom(15.0,-15.0),
				frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
				frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
			A_CustomBulletAttack(0,0,1,0,"PrismDecalBlue",0,CBAF_AIMFACING);
		}
		Goto PhaseOne;
	}
}

class PrismDecalBlue : PrismDecalBase
{
	Default
	{
		Decal "PrismBlueScorch";
	}
}

class PrismLightBlue : PrismLightBase
{
}

//Cyan
class PrismBeamCyan : PrismBeamBase
{
	states
	{
	Spawn:
		PRSP B 0 {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			Return ResolveState("PhaseOne");
		}
		Goto PhaseOne;
	PhaseTwoEnter:
		"####" "#" 0 A_SpawnItemEx("PrismParticleCyan",frandom(15.0,-15.0),
			frandom(15.0,-15.0),frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
			frandom(2.0,-2.0),frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	}
}

class PrismParticleCyan : PrismParticleBase
{
	states
	{
	Spawn:
		CPRT A 0 A_Jump(256,"PhaseOne");
		Goto PhaseOne;
	}
}

class PrismImpactCyan : PrismImpactBase
{
	Default
	{
		DamageType "Ice";
	}
	
	States
	{
	Spawn:
		PRSP B 0 NoDelay {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			A_SpawnItemEx("PrismParticleCyan",frandom(15.0,-15.0),frandom(15.0,-15.0),
				frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
				frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
			A_CustomBulletAttack(0,0,1,0,"PrismDecalCyan",0,CBAF_AIMFACING);
		}
		Goto PhaseOne;
	}
}

class PrismDecalCyan : PrismDecalBase
{
	Default
	{
		Decal "PrisCyanScorch";
	}
}

class PrismLightCyan : PrismLightBase
{
}

//Green
class PrismBeamGreen : PrismBeamBase
{
	states
	{
	Spawn:
		PRSP C 0 {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			Return ResolveState("PhaseOne");
		}
		Goto PhaseOne;
	PhaseTwoEnter:
		"####" "#" 0 A_SpawnItemEx("PrismParticleCyan",frandom(15.0,-15.0),
			frandom(15.0,-15.0),frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
			frandom(2.0,-2.0),frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	}
}

class PrismParticleGreen : PrismParticleBase
{
	states
	{
	Spawn:
		GPRT A 0 A_Jump(256,"PhaseOne");
		Goto PhaseOne;
	}
}

class PrismImpactGreen : PrismImpactBase
{
	Default
	{
		DamageType "Tiberium";
	}
	
	States
	{
	Spawn:
		PRSP C 0 NoDelay {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			A_SpawnItemEx("PrismParticleGreen",frandom(15.0,-15.0),frandom(15.0,-15.0),
				frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
				frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
			A_CustomBulletAttack(0,0,1,0,"PrismDecalGreen",0,CBAF_AIMFACING);
		}
		Goto PhaseOne;
	}
}

class PrismDecalGreen : PrismDecalBase
{
	Default
	{
		Decal "PrismGreenScorch";
	}
}

class PrismLightGreen : PrismLightBase
{
}

//Lime
class PrismBeamLime : PrismBeamBase
{
	states
	{
	Spawn:
		PRSP D 0 {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			Return ResolveState("PhaseOne");
		}
		Goto PhaseOne;
	PhaseTwoEnter:
		"####" "#" 0 A_SpawnItemEx("PrismParticleLime",frandom(15.0,-15.0),frandom(15.0,-15.0),frandom(15.0,-15.0),
		frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(0.0,360.0),SXF_CLIENTSIDE);
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	}
}

class PrismParticleLime : PrismParticleBase
{
	states
	{
	Spawn:
		LPRT A 0 A_Jump(256,"PhaseOne");
		Goto PhaseOne;
	}
}

class PrismImpactLime : PrismImpactBase
{
	Default
	{
		DamageType "Acid";
	}
	
	States
	{
	Spawn:
		PRSP D 0 NoDelay {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			A_SpawnItemEx("PrismParticleLime",frandom(15.0,-15.0),frandom(15.0,-15.0),
				frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
				frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
			A_CustomBulletAttack(0,0,1,0,"PrismDecalLime",0,CBAF_AIMFACING);
		}
		Goto PhaseOne;
	}
}

class PrismDecalLime : PrismDecalBase
{
	Default
	{
		Decal "PrismLimeScorch";
	}
}

class PrismLightLime : PrismLightBase
{
}

//Yellow
class PrismBeamYellow : PrismBeamBase
{
	states
	{
	Spawn:
		PRSP E 0 {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			Return ResolveState("PhaseOne");
		}
		Goto PhaseOne;
	PhaseTwoEnter:
		"####" "#" 0 A_SpawnItemEx("PrismParticleYellow",frandom(15.0,-15.0),frandom(15.0,-15.0),frandom(15.0,-15.0),
		frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(0.0,360.0),SXF_CLIENTSIDE);
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	}
}

class PrismParticleYellow : PrismParticleBase
{
	states
	{
	Spawn:
		YPRT A 0 A_Jump(256,"PhaseOne");
		Goto PhaseOne;
	}
}

class PrismImpactYellow : PrismImpactBase
{
	Default
	{
		DamageType "Lightning";
	}
	
	States
	{
	Spawn:
		PRSP E 0 NoDelay {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			A_SpawnItemEx("PrismParticleYellow",frandom(15.0,-15.0),frandom(15.0,-15.0),
				frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
				frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
			A_CustomBulletAttack(0,0,1,0,"PrismDecalYellow",0,CBAF_AIMFACING);
		}
		Goto PhaseOne;
	}
}

class PrismDecalYellow : PrismDecalBase
{
	Default
	{
		Decal "PrismYellowScorch";
	}
}

class PrismLightYellow : PrismLightBase
{
}

//Orange
class PrismBeamOrange : PrismBeamBase
{
	states
	{
	Spawn:
		PRSP F 0 {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			Return ResolveState("PhaseOne");
		}
		Goto PhaseOne;
	PhaseTwoEnter:
		"####" "#" 0 A_SpawnItemEx("PrismParticleOrange",frandom(15.0,-15.0),frandom(15.0,-15.0),frandom(15.0,-15.0),
		frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(0.0,360.0),SXF_CLIENTSIDE,user_tm);
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	}
}

class PrismParticleOrange : PrismParticleBase
{
	states
	{
	Spawn:
		OPRT A 0 A_Jump(256,"PhaseOne");
		Goto PhaseOne;
	}
}

class PrismImpactOrange : PrismImpactBase
{
	Default
	{
		DamageType "Fire";
	}
	
	States
	{
	Spawn:
		PRSP F 0 NoDelay {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			A_SpawnItemEx("PrismParticleOrange",frandom(15.0,-15.0),frandom(15.0,-15.0),
				frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
				frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
			A_CustomBulletAttack(0,0,1,0,"PrismDecalOrange",0,CBAF_AIMFACING);
		}
		Goto PhaseOne;
	}
}

class PrismDecalOrange : PrismDecalBase
{
	Default
	{
		Decal "PrismOrangeScorch";
	}
}

class PrismLightOrange : PrismLightBase
{
}

//Red
class PrismBeamRed : PrismBeamBase
{
	states
	{
	Spawn:
		PRSP G 0 {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			Return ResolveState("PhaseOne");
		}
		Goto PhaseOne;
	PhaseTwoEnter:
		"####" "#" 0 A_SpawnItemEx("PrismParticleRed",frandom(15.0,-15.0),frandom(15.0,-15.0),frandom(15.0,-15.0),
		frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(0.0,360.0),SXF_CLIENTSIDE);
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	}
}

class PrismParticleRed : PrismParticleBase
{
	states
	{
	Spawn:
		RPRT A 0 A_Jump(256,"PhaseOne");
		Goto PhaseOne;
	}
}

class PrismImpactRed : PrismImpactBase
{
	Default
	{
		DamageType "Breath";
	}
	
	States
	{
	Spawn:
	PRSP G 0 NoDelay {
		if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
		else { User_TM = 0; }
		A_SpawnItemEx("PrismParticleRed",frandom(15.0,-15.0),frandom(15.0,-15.0),
			frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
			frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
		A_CustomBulletAttack(0,0,1,0,"PrismDecalRed",0,CBAF_AIMFACING);
	}
	Goto PhaseOne;
	}
}

class PrismDecalRed : PrismDecalBase
{
	Default
	{
		Decal "PrismRedScorch";
	}
}

class PrismLightRed : PrismLightBase
{
}

//Purple
class PrismBeamPurple : PrismBeamBase
{
	states
	{
	Spawn:
		PRSP H 0 {
			if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
			else { User_TM = 0; }
			Return ResolveState("PhaseOne");
		}
		Goto PhaseOne;
	PhaseTwoEnter:
		"####" "#" 0 A_SpawnItemEx("PrismParticlePurple",frandom(15.0,-15.0),frandom(15.0,-15.0),frandom(15.0,-15.0),
		frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(0.0,360.0),SXF_CLIENTSIDE);
		"####" "#" 0 A_Jump(256,"PhaseTwo");
		Goto PhaseTwo;
	}
}

class PrismParticlePurple : PrismParticleBase
{
	states
	{
	Spawn:
		PPRT A 0 A_Jump(256,"PhaseOne");
		Goto PhaseOne;
	}
}

class PrismImpactPurple : PrismImpactBase
{
	Default
	{
		DamageType "Flesh";
	}
	
	States
	{
	Spawn:
	PRSP H 0 NoDelay {
		if(random(0,25) == 0) { A_RadiusGive("CorpseBlaster", 64, RGF_MONSTERS|RGF_CORPSES, 1); } //Perhaps making that effect more occasional will make it less broken.
		if(GetCvar("GC_ToasterMode")) { User_TM = 256; }
		else { User_TM = 0; }
		A_SpawnItemEx("PrismParticlePurple",frandom(15.0,-15.0),frandom(15.0,-15.0),
			frandom(15.0,-15.0),frandom(2.0,-2.0),frandom(2.0,-2.0),frandom(2.0,-2.0),
			frandom(0.0,360.0),SXF_CLIENTSIDE,User_TM);
		A_CustomBulletAttack(0,0,1,0,"PrismDecalPurple",0,CBAF_AIMFACING);
	}
	Goto PhaseOne;
	}
}

class PrismDecalPurple : PrismDecalBase
{
	Default
	{
		Decal "PrismPurpleScorch";
	}
}

class PrismLightPurple : PrismLightBase
{
}
