/// Ability: Air Spindash
// charges a spindash in air

// CUSTOMIZE SECTION START
local skin = "kaydensonic" // your character here
local thebutton = BT_CUSTOM3 // the button needed to do the air spindash
local sound = sfx_cdfm62 // the sound of starting the air spindash
local sound2 = sfx_spndsh // the sound of charging the air spindash
local sound3 = sfx_s3kb6 // the sound of releasing the air spindash
local hasthok = true // if this is true, you will spawn a thok mobj while charging
local hasghost = false // if this is true, you will spawna  ghost while charging
local mode = 1 /*
changes the mode of the air spindash
1: stops you in place in mid air to charge a spindash, release when you want
2: charges without stopping, releases when it hits the floor
*/
local thestate = S_PLAY_SPINDASH // the state you switch to while air spindashing

// CUSTOMIZE SECTION END PROCCED BELOW IF YOU KNOW WHAT YOUR DOING

local function AirSpindash_Reset(player)
	player.airspindash = false
	player.ascharge = 0
	player.asrecharge = 0
	player.pflags = $1 & ~PF_FULLSTASIS
end


addHook("PlayerThink", function(player)
	if player.airspindash == nil
		player.airspindash = true
	end
	if player.ascharge == nil
		player.ascharge = 0
	end
	if player.asrecharge == nil
		player.asrecharge = 0
	end
	if player.ascharge == 1
	end
	if player.mo and player.mo.skin == skin
	and (player.cmd.buttons & thebutton)
	and not P_IsObjectOnGround(player.mo)
	and player.airspindash == false
	and player.ascharge == 0
	and not (player.pflags & PF_SPINNING)
		player.airspindash = true
	end
	if player.mo and player.mo.skin == skin
	and (player.cmd.buttons & thebutton)
	and player.airspindash == true
	and mode == 1
		player.mo.state = thestate
		player.pflags = $|PF_FULLSTASIS
		player.momz = 0
		player.momy = 0
		player.momx = 0
		P_InstaThrust(player.mo, player.mo.angle, 0)
		P_SetObjectMomZ(player.mo, 0)
		player.asrecharge = $ + 1
		if hasghost == true
			local ghost = P_SpawnGhostMobj(player.mo) 
			ghost.scale = player.mo.scale*player.asrecharge/5
			ghost.destscale = player.mo.scale
			ghost.scalespeed = $*1
			ghost.z = player.mo.z-ghost.scale
		end
		if hasthok == true
			local thokeffect = P_SpawnThokMobj(player) 
		end
	end
	if player.mo and player.mo.skin == skin
	and (player.cmd.buttons & thebutton)
	and player.airspindash == true
	and mode == 2
		player.mo.state = thestate
		player.asrecharge = $ + 1
		if hasghost == true
			local ghost = P_SpawnGhostMobj(player.mo) 
			ghost.scale = player.mo.scale*player.asrecharge/5
			ghost.destscale = player.mo.scale
			ghost.scalespeed = $*1
			ghost.z = player.mo.z-ghost.scale
		end
		if hasthok == true
			local thokeffect = P_SpawnThokMobj(player) 
		end
	end
	if player.asrecharge == 10
	and (player.cmd.buttons & thebutton)
	and player.airspindash == true
	and mode == 1
		player.asrecharge = 0
		S_StartSound(player.mo,sound2)
		player.ascharge = $ + 10
	end
	if player.asrecharge == 5
	and (player.cmd.buttons & thebutton)
	and player.airspindash == true
	and mode == 2
		player.asrecharge = 0
		S_StartSound(player.mo,sound2)
		player.ascharge = $ + 10
	end
	if player.mo and player.mo.skin == skin
	and not (player.cmd.buttons & thebutton)
	and player.airspindash == true
	and mode == 1
		P_InstaThrust(player.mo, player.mo.angle, FRACUNIT*player.ascharge)
		player.pflags = $ |PF_SPINNING
		player.mo.state = S_PLAY_ROLL
		AirSpindash_Reset(player)
	end
	if player.mo and player.mo.skin == skin
	and player.airspindash == true
	and P_IsObjectOnGround(player.mo)
	and mode == 2
		P_InstaThrust(player.mo, player.mo.angle, FRACUNIT*player.ascharge)
		player.pflags = $ |PF_SPINNING
		player.mo.state = S_PLAY_ROLL
		AirSpindash_Reset(player)
	end
end)	