freeslot("S_PLAY_TAUNT", "SPR2_TUNT")

states[S_PLAY_TAUNT] = {
		sprite = SPR_PLAY,
		frame = SPR2_TUNT|A,
		tics = 35,
		action = A_None,
		nextstate = S_PLAY_STND
	}
local function SpinAbility(player)
	if player.mo.skin ~= "jayt" then
		return
	end

	if (player.cmd.buttons & BT_TOSSFLAG) then
		if not player.pressedtossflag
		and player.rings >= 0
		and not (player.powers[pw_shield] & SH_NOSTACK)
		and not (player.powers[pw_super])
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_ARMAGEDDON and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_PITY and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_PINK and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_BUBBLEWRAP and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_FLAMEAURA and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_THUNDERCOIN and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_WHIRLWIND and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_ELEMENTAL and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_ATTRACT and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.powers[pw_shield] == SH_FORCE and not (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif (player.powers[pw_super]) and player.rings >= 0 and not player.pressedtossflag then
		player.mo.state = S_PLAY_TAUNT
			P_SpawnPlayerMissile(player.mo, MT_TAUNTBUBBLE)
		
		elseif player.rings <= 0 then return
		end

		
		player.pressedtossflag = true
	else
		player.pressedtossflag = false
	end

end

addHook("PlayerThink", SpinAbility)

addHook("ThinkFrame", do
	for player in players.iterate do
		if player.mo and player.mo.skin == "jayt"
			if player.mo.state == S_PLAY_TAUNT
				player.mo.momx = 0*FRACUNIT
				player.mo.momy = 0*FRACUNIT
				player.mo.momz = 0*FRACUNIT
				player.powers[pw_invulnerability] = 1
			end
		end
	end
end)