class ZscriptPawnch : actor
{
	Default
	{
		ZscriptPawnch.ThrustForce 10.0;  // Thrust force.
		ZscriptPawnch.ThrustUpward 5.0;  // Bonus thrust force upward, if you hit anywhere between -10 to 90 of your own pitch.
		
		+NOBLOCKMAP
		+NOGRAVITY
		+HITTRACER
		+PUFFGETSOWNER
		+PUFFONACTORS
	}
	
	double thrustforce;
	double thrustupward;
	
	property ThrustForce: thrustforce;
	property ThrustUpward: thrustupward;
	
	int isspawn;
	int ismelee;
	int iscrash;
	int isxdeath;
	
	// Thrust table. it goes as follows:
	// Mass / Thrust Force / Thrust Upward.

	States
	{
	Spawn:
		TNT1 A 0 NoDelay { isspawn = 1; ismelee = 0; iscrash = 0; isxdeath = 0; }
		goto DasMain;
	Melee:
		TNT1 A 0 { isspawn = 0; ismelee = 1; iscrash = 0; isxdeath = 0; }
		goto DasMain;
	Crash:
		TNT1 A 0 { isspawn = 0; ismelee = 0; iscrash = 1; isxdeath = 0;  }
		goto DasMain;
	XDeath:
		TNT1 A 0 { isspawn = 0; ismelee = 0; iscrash = 0; isxdeath = 1; }
		goto DasMain;
	
	DasMain:
		TNT1 A 0 {
			if(CountInv("MastersOfPain",AAPTR_TARGET)) { bFORCEPAIN = 1; }
			if(IsPointerEqual(AAPTR_TRACER, AAPTR_NULL) == False && tracer.bDORMANT == 0 && tracer.bISMONSTER == 1) {
			
				if(tracer.mass <= 100) {  thrustforce = thrustforce;	   thrustupward = thrustupward * 0.6; }
				if(tracer.mass >= 400) {  thrustforce = thrustforce * 0.9; thrustupward = thrustupward * 0.8; }
				if(tracer.mass >= 600) {  thrustforce = thrustforce * 0.9; thrustupward = thrustupward * 0.7; }
				if(tracer.mass >= 1000) { thrustforce = thrustforce * 0.9; thrustupward = thrustupward * 0.7; }

				// so even if you are aiming slightly downwards, it will still try to launch hit thing a bit upward.
				// But don't do it on flying targets, that'd be annoying.

				if(tracer.bFLOAT == 0) { A_ChangeVelocity(0, 0, thrustupward, 0, AAPTR_TRACER); }
				
				// the main beef of the puff.
				A_ChangeVelocity(0, 0, sin(target.Pitch) * -thrustforce, 0, AAPTR_TRACER);
			}
			if(isspawn >= 1) { return ResolveState("SpawnMain"); }
			if(ismelee >= 1) { return ResolveState("MeleeMain"); }
			if(iscrash >= 1) { return ResolveState("CrashMain"); }
			if(isxdeath >= 1) { return ResolveState("XDeathMain"); }
			return ResolveState(null);
		}
		goto spawn;
	}
}

class ZscriptKick : FastProjectile
{
	Default
	{
		ZscriptKick.ThrustForce 20.0;
		ZscriptKick.ThrustUpward 10.0;
		
		+HITTRACER
	}
	
	double thrustforce;
	double thrustupward;
	
	property ThrustForce: thrustforce;
	property ThrustUpward: thrustupward;
	
	int isdeath;
	int isxdeath;
	
	States
	{
	Death:
		TNT1 A 0 { isdeath = 1; isxdeath = 0; }
		goto DasMain;
	XDeath:
		TNT1 A 0 { isdeath = 0; isxdeath = 1; }
		goto DasMain;
	DasMain:
		TNT1 A 0 {
			if(CountInv("MastersOfPain",AAPTR_TARGET)) { bFORCEPAIN = 1; }
			if(IsPointerEqual(AAPTR_TRACER, AAPTR_NULL) == False && tracer.bDORMANT == 0 && tracer.bISMONSTER == 1) {
			
				if(tracer.mass <= 100) {  thrustforce = thrustforce;	   thrustupward = thrustupward * 0.6; }
				if(tracer.mass >= 400) {  thrustforce = thrustforce * 0.9; thrustupward = thrustupward * 0.8; }
				if(tracer.mass >= 600) {  thrustforce = thrustforce * 0.9; thrustupward = thrustupward * 0.7; }
				if(tracer.mass >= 1000) { thrustforce = thrustforce * 0.9; thrustupward = thrustupward * 0.7; }

				// so even if you are aiming slightly downwards, it will still try to launch hit thing a bit upward.
				// But don't do it on flying targets, that'd be annoying.
				
				if(tracer.bFLOAT == 0) { A_ChangeVelocity(0, 0, thrustupward, 0, AAPTR_TRACER); }
				
				// the main beef of the projectile.
				A_ChangeVelocity(0, 0, sin(target.Pitch) * -thrustforce, 0, AAPTR_TRACER);
			}
			if(isdeath >= 1) { return ResolveState("DeathMain"); }
			if(isxdeath >= 1) { return ResolveState("XDeathMain"); }
			return ResolveState(null);
		}
		Stop;
	}
}

class ZscriptPowerPunch : FastProjectile
{
	Default
	{
		ZscriptPowerPunch.ThrustForce 40.0;  // Thrust force.
		ZscriptPowerPunch.ThrustUpward 20.0;  // Bonus thrust force upward, if you hit anywhere between -10 to 90 of your own pitch.
		Species "Rrerr";
		
		+NOBLOCKMAP
		+NOGRAVITY
		+HITTRACER
		+MTHRUSPECIES
	}
	
	double thrustforce;
	double thrustupward;
	
	property ThrustForce: thrustforce;
	property ThrustUpward: thrustupward;
	
	// Thrust table. it goes as follows:
	// Mass / Thrust Force / Thrust Upward.

	bool IsDeath;
	bool IsXDeath;
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay { if(CountInv("MastersOfPain",AAPTR_TARGET)) { bFORCEPAIN = 1; } }
		TNT1 A 0 A_Jump(256,"SpawnMain");
		Stop;
	Death:
		TNT1 A 0 { IsDeath = 1; IsXDeath = 0; }
		Goto Main;
	XDeath:
		TNT1 A 0 { IsDeath = 0; IsXDeath = 1; }
		Goto Main;
	
	//Dummy states.
	SpawnMain:
		TNT1 A 0;
		Stop;
	DeathMain:
		TNT1 A 0;
		Stop;
	XDeathMain:
		TNT1 A 0;
		Stop;
		
	Main:
		TNT1 A 0 {
			if(IsPointerEqual(AAPTR_TRACER, AAPTR_NULL) == False && tracer.bDORMANT == 0 && tracer.bISMONSTER == 1) {
			
				if(tracer.mass <= 100) {  thrustforce = thrustforce;	   thrustupward = thrustupward * 0.6; }
				if(tracer.mass >= 400) {  thrustforce = thrustforce * 0.9; thrustupward = thrustupward * 0.8; }
				if(tracer.mass >= 600) {  thrustforce = thrustforce * 0.9; thrustupward = thrustupward * 0.7; }
				if(tracer.mass >= 1000) { thrustforce = thrustforce * 0.9; thrustupward = thrustupward * 0.7; }

				// so even if you are aiming slightly downwards, it will still try to launch hit thing a bit upward.
				// But don't do it on flying targets, that'd be annoying.

				if(tracer.bFLOAT == 0) { A_ChangeVelocity(0, 0, thrustupward, 0, AAPTR_TRACER); }
				
				// the main beef of the puff.
				A_ChangeVelocity(0, 0, sin(target.Pitch) * -thrustforce, 0, AAPTR_TRACER);
			}
			if(IsDeath >= 1) { return ResolveState("DeathMain"); }
			if(IsXDeath >= 1) { return ResolveState("XDeathMain"); }
			return ResolveState(null);
		}
		Stop;
	}
}

//Punchin'
class PawnchPuff : ZscriptPawnch
{ 
	Default
	{
		DamageType "CloseCombat";
		Decal "PunchStamp";
		ZscriptPawnch.ThrustForce 10.0;
		ZscriptPawnch.ThrustUpward 5.0;
		ProjectileKickback 125;
		+NOBLOCKMAP
		+NOGRAVITY
		+NOEXTREMEDEATH
		//+BLOODLESSIMPACT //If I don't get that visual input that shit's being beaten hard, it's not funny.
		+PUFFGETSOWNER
		+ALLOWTHRUFLAGS
		+MTHRUSPECIES
		+PUFFONACTORS
	}
	
	States
	{
	SpawnMain:
		TNT1 A 15 {
			A_AlertMonsters(128);
			A_PlaySound("Punch/Hit",5,0.65);
			A_QuakeEx(1,1,1,4,0,96,"none",QF_SCALEDOWN);
			//A_SpawnItemEx("PunchPuff_Shock",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
		}
		Stop;
	CrashMain:
		TNT1 A 15 {
			A_AlertMonsters(128);
			A_PlaySound("Punch/Hit",5,0.65);
			A_PlaySound("Punch/Wall",6,1.0);
			A_QuakeEx(1,1,1,4,0,96,"none",QF_SCALEDOWN);
		}
		Stop;
	XDeathMain:
		TNT1 A 3 {
			A_AlertMonsters(128);
			A_PlaySound("Punch/Flesh",5,1.0);
			A_QuakeEx(1,1,1,4,0,96,"none",QF_SCALEDOWN);
		}
		TNT1 A 12 A_PlaySound("Punch/Flavor",6,1.0);
		Stop;
	}
}

class PawnchPuff2 : PawnchPuff //Alternate
{
	Default
	{
		Decal "PunchStamp2";
	}
}

class PawnchPuffLeft : PawnchPuff //Standard Punch
{
	Default
	{
		Decal "PunchStampLeft";
	}
}

class PawnchPuffLeft2 : PawnchPuff //Alternate
{
	Default
	{
		Decal "PunchStampLeft2";
	}
}

class ScratchPuffLeft : PawnchPuff
{ 
	Default
	{
		Decal "ClawStampLeft";
	}
	
	States
	{
	SpawnMain:
		TNT1 A 0 {
			A_AlertMonsters(64);
			A_PlaySound("Claw/Wall",5,0.5);
		}
		Stop;
	CrashMain:
		TNT1 A 0 {
			A_AlertMonsters(64);
			A_PlaySound("Claw/Wall",5,0.5);
		}
		Stop;
	XDeathMain:
		TNT1 A 0 A_PlaySound("Claw/Hit",5,0.8);
		Stop;
   }
}

class ScratchPuffAltLeft : ScratchPuffLeft
{
	Default
	{
		Decal "ClawStampAltLeft";
	}
}

class ScratchPuffRight : ScratchPuffLeft
{
	Default
	{
		Decal "ClawStampRight";
	}
}

class ScratchPuffAltRight : ScratchPuffRight
{
	Default
	{
		Decal "ClawStampAltRight";
	}
}

class PunchPuff_Shock : Actor
{
	Default
	{
		RenderStyle "Add";
		Scale 0.025;
		+NOINTERACTION
		+FORCEXYBILLBOARD
	}
	
	States
	{
		Spawn:
			SHCK B 1 NoDelay Bright {
				A_SetScale(Scale.X + FRandom(0.025, 0.035));
				A_FadeOut(0.15);
			}
			Loop;
	}
}

//Kickin'
class KickDecalBase : BulletPuff
{
	Default
	{
		VSpeed 0;
		Alpha 0;
		-RANDOMIZE
		+NOEXTREMEDEATH
		-ALLOWPARTICLES
		+ALWAYSPUFF
		+BLOODLESSIMPACT
		+DONTSPLASH
		+NOTIMEFREEZE
		+ALLOWTHRUFLAGS
		+MTHRUSPECIES
	}
}

class KickProjectile : ZscriptKick
{
	Default
	{
		Radius 16;
		Height 18;
		Speed 170;
		Projectile;
		ZscriptKick.ThrustForce 30.0;
		ZscriptKick.ThrustUpward 12.0;
		ProjectileKickback 500;
		DamageFunction (10*random(1,3));
		DamageType "Shoelaces";
		Decal "BootStamp";
		+BLOODSPLATTER
		+DONTREFLECT
		+DONTBLAST
		+MTHRUSPECIES
	}
	
	States
	{
	Spawn:
		TNT1 A 1;
		Stop;
	DeathMain:
	XDeathMain:
		TNT1 A 15 {
			//A_SpawnItemEx("Kick_Shock",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			//A_QuakeEx(2,2,2,8,0,192,"none",QF_SCALEDOWN);
			if(BlockingLine)
			{
				BlockingLine.Activate(target, 0, SPAC_Use);
			}
			A_GiveInventory("KickethThyHappend",1,AAPTR_TARGET);
			A_AlertMonsters(128);
			A_ChangeVelocity(-4.0,0,0,CVF_RELATIVE,AAPTR_TARGET);
			A_Explode((40*random(1,3)),96,0);
			A_PlaySound("Kick/Hit");
		}
		Stop;
	}
}

class FootProjectile : KickProjectile
{
	Default
	{
		Decal "FootStamp";
	}
}

//Left
class KickProjectileLeft : KickProjectile
{
	Default
	{
		ProjectileKickback 1000; //By the logic of Chuck Norris movies - Roundhouse sends people OFF THE HOOK.
		DamageType "Shoelaces";
		Decal "LeftBootStamp";
	}
	
	States
	{
	Spawn:
		TNT1 A 1 ;
		Stop;
	DeathMain:
	XDeathMain:
		TNT1 A 15 {
			//A_SpawnItemEx("Kick_Shock",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			//A_QuakeEx(2,2,2,8,0,192,"none",QF_SCALEDOWN);
			if(BlockingLine)
			{
				BlockingLine.Activate(target, 0, SPAC_Use);
			}
			A_GiveInventory("KickethThyHappend",1,AAPTR_TARGET);
			A_AlertMonsters(128);
			A_ChangeVelocity(-2.0,0,0,CVF_RELATIVE,AAPTR_TARGET);
			A_Explode((50*random(1,3)),128,0);
			A_PlaySound("Kick/Hit");
		}
		Stop;
	}
}

class FootProjectileLeft : KickProjectileLeft
{
	Default
	{
		Decal "LeftFootStamp";
	}
}

//Right
class KickProjectileRight : KickProjectileLeft
{
	Default
	{
		Decal "RightBootStamp";
	}
}

class FootProjectileRight : KickProjectileRight
{
	Default
	{
		Decal "RightFootStamp";
	}
}

class Kick_Shock : Actor
{
	Default
	{
		RenderStyle "Add";
		Scale 0.05;
		Alpha 0.6;
		+NOINTERACTION
		+FORCEXYBILLBOARD
	}
	
	States
	{
	Spawn:
		SHCK B 1 NoDelay Bright {
			A_SetScale(Scale.X + FRandom(0.025, 0.035));
			A_FadeOut(0.1);
		}
		Loop;
	}
}

class MidasKick_Shock : Kick_Shock
{
	States
	{
	Spawn:
		SHCK C 1 NoDelay Bright {
			A_SetScale(Scale.X + FRandom(0.025, 0.035));
			A_FadeOut(0.1);
		}
		Loop;
	}
}

//Melee - Berserk edition

class SuperPawnchPuff : PawnchPuff
{ 
	Default
	{
		ZscriptPawnch.ThrustForce 20.0;
		ZscriptPawnch.ThrustUpward 9.0;
		DamageType "SuperCloseCombat";
		Decal "SuperPunchStamp";
		-NOEXTREMEDEATH
		+FORCERADIUSDMG
		+FOILINVUL
	}
	
	States
	{
	SpawnMain:
	CrashMain:
	XDeathMain:
		TNT1 A 1 {
			A_AlertMonsters(256);
			A_PlaySound("SuperPunch/Hit",0,0.7);
			A_PlaySound("Punch/Flavor",6,1.0);
			A_SpawnItemEx("SuperPunchPuff_Shock",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			A_SpawnItemEx("SuperPunchPuff_Impact",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			A_SpawnItemEx("SuperPunchPuff_Wave",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			A_QuakeEx(3,3,3,10,0,384,"none",QF_SCALEDOWN);
		}
		TNT1 A 14 A_Explode(20,48,0); //This weird setup is so the puff's damage gets applied before the explosion, so the lifedrain effect kicks in beforehand.
		Stop;
   }
}

class SuperPawnchPuff2 : SuperPawnchPuff //Alternate
{
	Default
	{
		Decal "SuperPunchStamp2";
	}
}

class SuperPawnchPuffLeft : SuperPawnchPuff //Standard punch
{
	Default
	{
		Decal "SuperPunchStampLeft";
	}
}

class SuperPawnchPuffLeft2 : SuperPawnchPuff //Alternate
{
	Default
	{
		Decal "SuperPunchStampLeft2";
	}
}

class SuperPunchPuff_Shock : Actor
{
	Default
	{
		RenderStyle "Add";
		Scale 0.015;
		+NOINTERACTION
		+FORCEXYBILLBOARD
	}
	
	States
	{
	Spawn:
		SHCK D 1 Bright {
			A_SetScale(Scale.X + FRandom(0.01, 0.02));
			A_FadeOut(0.1);
		}
		Loop;
	}
}

class SuperPunchPuff_Impact : SuperPunchPuff_Shock
{
	Default
	{
		Scale 0.025;
	}
	
	States
	{
	Spawn:
		BLST C 0 NoDelay A_Jump(128,"AltSprite");
		Goto Looplet;
	AltSprite:
		BLST D 0;
	Looplet:
		"####" "#" 1 Bright { 
			A_SetScale(Scale.X + FRandom(0.01, 0.015));
			A_FadeOut(0.125);
		}
		Loop;
	}
}

class SuperPunchPuff_Wave : SuperPunchPuff_Shock
{
	Default
	{
		Scale 0.05;
	}
	
	States
	{
		Spawn:
			TNT1 A 0 NoDelay A_Jump(256,"SpriteA","SpriteB","SpriteC","SpriteD");
		SpriteA:
			BRWV A 0;
			Goto Looplet;
		SpriteB:
			BRWV B 0;
			Goto Looplet;
		SpriteC:
			BRWV C 0;
			Goto Looplet;
		SpriteD:
			BRWV D 0;
			Goto Looplet;
		Looplet:
			"####" "#" 1 Bright {
				A_SetScale(Scale.X + FRandom(0.01, 0.015));
				A_FadeOut(0.1);
			}
			Loop;
		}
}

class SuperScratchPuffLeft : ScratchPuffLeft
{
	Default
	{
		DamageType "SuperCloseCombat";
		Decal "SuperClawStampLeft";
		+PUFFONACTORS
		+FOILINVUL
	}
	
	States
	{
	SpawnMain:
	CrashMain:
		TNT1 A 15 {
			A_AlertMonsters(256);
			A_PlaySound("Claw/Wall",5,0.6);
		}
		Stop;
	XDeathMain:
		TNT1 A 15 {
			A_AlertMonsters(256);
			A_PlaySound("Claw/Hit",5,0.6);
		}
		Stop;
	}
}

class SuperScratchPuffAltLeft : SuperScratchPuffLeft
{
	Default
	{
		Decal "SuperClawStampAltLeft";
	}
}

class SuperScratchPuffRight : SuperScratchPuffLeft
{
	Default
	{
		Decal "SuperClawStampRight";
	}
}

class SuperScratchPuffAltRight : SuperScratchPuffLeft
{
	Default
	{
		Decal "SuperClawStampAltRight";
	}
}

//Berserk Kickin'
class SuperKickProjectile : KickProjectile
{
	Default
	{
		ZscriptKick.ThrustForce 40.0;
		ZscriptKick.ThrustUpward 20.0;
		DamageType "SuperShoelaces";
		Decal "SuperBootStamp";
		+FORCERADIUSDMG
		+FOILINVUL
	}
	
	States
	{
	Spawn:
		TNT1 A 1;
		Stop;
	DeathMain:
	XDeathMain:
		TNT1 A 25 {
			if(BlockingLine)
			{
				BlockingLine.Activate(target, 0, SPAC_Use);
			}
			A_GiveInventory("KickethThyHappend",1,AAPTR_TARGET);
			A_AlertMonsters(768);
			A_ChangeVelocity(-8.0,0,0,CVF_RELATIVE,AAPTR_TARGET);
			A_PlaySound("SuperKick/Hit",5,0.9);
			A_Explode((40*random(1,3)),128,0);
			A_SpawnItemEx("SuperKick_Shock",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			A_SpawnItemEx("SuperKick_Impact",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			A_SpawnItemEx("SuperKick_Wave",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			A_SpawnItemEx("SuperKick_Gldef",0,0,0,0,0,0,0,SXF_CLIENTSIDE,0);
			A_QuakeEx(4,4,4,25,0,512,"none",QF_SCALEDOWN);
		}
		Stop;
	}
}

class SuperFootProjectile : SuperKickProjectile
{
	Default
	{
		Decal "SuperFootStamp";
	}
}

//Left
class SuperKickProjectileLeft : SuperKickProjectile
{
	Default
	{
		Decal "SuperLeftBootStamp";
	}
}

class SuperFootProjectileLeft : SuperKickProjectileLeft
{
	Default
	{
		Decal "SuperLeftFootStamp";
	}
}

//Right
class SuperKickProjectileRight : SuperKickProjectileLeft
{
	Default
	{
		Decal "SuperRightBootStamp";
	}
}

class SuperFootProjectileRight : SuperKickProjectileLeft
{
	Default
	{
		Decal "SuperRightFootStamp";
	}
}


class SuperKick_Shock : SuperPunchPuff_Shock
{
	Default
	{
		Scale 0.05;
	}
	
	States
	{
	Spawn:
		SHCK D 1 NoDelay Bright {
			A_SetScale(Scale.X + FRandom(0.025, 0.035));
			A_FadeOut(0.05);
		}
		Loop;
	}
}

class SuperKick_Impact : SuperPunchPuff_Shock
{
	Default
	{
		Scale 0.05;
	}
	
	States
	{
	Spawn:
		BLST C 0 NoDelay A_Jump(128,"AltSprite");
		Goto Looplet;
	AltSprite:
		BLST D 0;
	Looplet:
		"####" "#" 1 Bright {
			A_SetScale(Scale.X + FRandom(0.03, 0.04));
			A_FadeOut(0.075);
		}
		Loop;
	}
}

class SuperKick_Wave : SuperPunchPuff_Shock
{
	Default
	{
		Scale 0.2;
	}
	
	States
	{
		Spawn:
			TNT1 A 0 NoDelay A_Jump(256,"SpriteA","SpriteB","SpriteC","SpriteD");
		SpriteA:
			BRWV A 0;
			Goto Looplet;
		SpriteB:
			BRWV B 0;
			Goto Looplet;
		SpriteC:
			BRWV C 0;
			Goto Looplet;
		SpriteD:
			BRWV D 0;
			Goto Looplet;
		Looplet:
			"####" "#" 1 Bright {
				A_FadeOut(0.05);
				A_SetScale(Scale.X + FRandom(0.015, 0.025));
			}
			Loop;
	}
}

class SuperKick_Gldef : Actor
{
	Default
	{
		+NOINTERACTION;
	}
	
	States
	{
	Spawn:
		TNT1 A 35;
		Stop;
	}
}

//Uppercut
class UppercutPuff : PawnchPuff
{
	Default
	{
		DamageType "CloseCombat";
		Decal "UppercutStamp";
		ZscriptPawnch.ThrustForce 10.0;
		ZscriptPawnch.ThrustUpward 20.0;
		ProjectileKickback 800;
	}
}

class SuperUppercutPuff : SuperPawnchPuff
{
	Default
	{
		Decal "SuperUppercutStamp";
		ZscriptPawnch.ThrustForce 10.0;
		ZscriptPawnch.ThrustUpward 30.0;
		ProjectileKickback 800;
		-NOEXTREMEDEATH
		+FORCERADIUSDMG
		+FOILINVUL
	}
}