//Kirby Support

local abilityadded = false
addHook("ThinkFrame", function()
    if not(abilityadded)
        and(K_AddAbility)
		print ("Netflix and Chill B)")
		kirbyabilitytable["rafael"] = K_AddAbility(K_Chill, true, "CHILL")*-1
        abilityadded = true
    end
end)

rawset(_G, "K_AddCustomFeet", function(kirbysprite, feetsprite)
	overlaysprites[SPR2_CHLL] = SPR2_CHLL
end)


rawset(_G, "K_Chill", function(checkflags, destroy, late, player)
	if (checkflags) then 
		return 0
	end
	
	if (player.cmd.buttons & BT_SPIN)
		player.pflags = $ |PF_FULLSTASIS
		if player.mo.state != S_PLAY_RAFACHILL then
			player.mo.state = S_PLAY_RAFACHILL
		end
		
		--[[local ghosty = P_SpawnGhostMobj(player.mo)
		ghosty.colorized = true
		ghosty.color = player.mo.color
		ghosty.destscale = player.mo.scale*5
		if (player.followmobj)
			local ghosty2 = P_SpawnGhostMobj(player.followmobj)
			ghosty2.colorized = true
			ghosty2.color = player.followmobj.color
			ghosty2.destscale = player.mo.scale*5
		end]]
		
		local enemy = P_LookForEnemies(player)
		if not (enemy) return end
		if (enemy.valid)
		and (enemy.flags & MF_ENEMY)
		and (player.mo and player.mo.valid)
			P_KillMobj(enemy)
		end
	elseif player.spinreleaseping then
		player.mo.state = S_PLAY_WALK
	end
end)



//spin release check
addHook("PlayerThink", function(player)
	if player.mo.valid and player.mo.skin == "kirby" then
		if (player.cmd.buttons & BT_SPIN) then
			player.spinreleaseready = true
			player.spinreleaseping = false
		elseif player.spinreleaseready then
			player.spinreleaseping = true
			player.spinreleaseready = false
		else
			player.spinreleaseping = false
		end
	end
end)