/*
Hold up, bud.
I can see your pokin' through Cheeseboi's files.
That's fine. Use any of the code that was made by me. Just credit me, or Cheeseboi's gonna
find you and snap your neck.
kidding

Anyways, I hope you enjoy this mod as much as we did making it!
(which means i hope you hate it
jk)
*/

freeslot(
"sfx_boost")

addHook("PlayerThink", function(player, mo)
    if (player.mo.skin == "cheeseboi")
	and (player.mo.state == S_PLAY_DEAD)
	player.mo.rollangle = $ + FixedAngle(10*FRACUNIT)
      end
end)         

addHook("PlayerThink", function(player, mo)
    if (player.mo.skin == "cheeseboi")
	and (player.mo.state == S_PLAY_MELEE)
	player.mo.rollangle = FixedAngle(0*FRACUNIT)
      end
end)         

--Hug (Or Pose)
if not Allhugsinit
rawset(_G, "Allhugs", {})
rawset(_G, "Hugbutton", {})
rawset(_G, "Heartbutton", {})
rawset(_G, "Hugsound", {})
rawset(_G, "Yelpsound", {})
rawset(_G, "Tailshug", {})
rawset(_G, "Hearticon", {})
rawset(_G, "Loveparticle", {})
rawset(_G, "InvalidState", {})
end
Allhugs["cheeseboi"] = true--"hug" support :o
Hugsound["cheeseboi"] = sfx_kc5e
Yelpsound["cheeseboi"] = sfx_kc65

--Kirby stuff
if not kirbyabilitytable
    rawset(_G, "kirbyabilitytable", {})
end

kirbyabilitytable["cheeseboi"] = 3

--SLS's Custom Spindash!
addHook("PlayerThink", function(player)
	if (player.mo.skin == "cheeseboi")
		and (player.cmd.buttons & BT_CUSTOM3)
		and (player.cmd.buttons & BT_CUSTOM1 or player.mo.state == S_PLAY_WALK or player.mo.state == S_PLAY_RUN)
		and not (player.mo.state == S_PLAY_PAIN)
		and not (player.mo.state == S_PLAY_DEAD)
		and not (player.mo.state == S_PLAY_DRWN)
		player.charging = true
		player.mo.state = S_PLAY_SPINDASH
		S_StartSound(player.mo, sfx_kc5a)
	end	
end)
--more custom spindash
addHook("PlayerThink", function(player)
	if (player.mo.state == S_PLAY_SPINDASH)
	and player.mo.skin == "cheeseboi"
	and not (player.cmd.buttons & BT_CUSTOM3)
	and not (player.pflags & PF_SPINNING)
		player.charging = false
		player.mo.state = S_PLAY_SPINDASH
		player.pflags = $ | PF_SPINNING
        P_InstaThrust(player.mo, player.drawangle, player.speed + 55*FRACUNIT)--defines how fast cheeseboi goes
		S_StartSound(player.mo, sfx_kc5b)
	end
end)
--EVEN MORE custom spindash
addHook("PlayerThink", function(player)
    if (player.mo.skin == "cheeseboi")
	and (player.mo.state == S_PLAY_SPINDASH)
	P_StartQuake(5*FRACUNIT, 1)	
	local sectorz = R_PointInSubsector(player.mo.x, player.mo.y).sector
	for fof in sectorz.ffloors()
	if (fof.flags & FF_EXISTS) and ((fof.flags & FF_STRONGBUST) or (fof.flags & FF_BUSTUP))
	and not (player.mo.z-99*FRACUNIT >= fof.topheight)
	and not (player.mo.z+99*FRACUNIT+player.mo.height < fof.bottomheight)
	EV_CrumbleChain(sectorz, fof)
	end
end
end
end)         

--death anim from custom player death by TGTLS
addHook("ThinkFrame", do
	for player in players.iterate
	if player.mo and player.mo.valid
	if player.mo.skin == "cheeseboi"
			and not P_CheckDeathPitCollide(player.mo)
			and	player.playerstate == PST_DEAD
			and P_IsObjectOnGround(player.mo)
			player.mo.momz = 0
			player.mo.flags = $ & ~MF_NOCLIP
			player.mo.flags = $ & ~MF_NOCLIPHEIGHT
			player.mo.state = S_PLAY_MELEE
		end
		if player.mo.skin == "cheeseboi"
		and not P_IsObjectOnGround(player.mo)
		and not P_CheckDeathPitCollide(player.mo)
		and player.playerstate == PST_DEAD
		and player.mo.state == S_PLAY_STND or player.mo.state == S_PLAY_FALL
		and player.playerstate == PST_DEAD
			player.mo.state = S_PLAY_MELEE
			player.mo.momz = 0
			player.mo.flags = $ & ~MF_NOCLIP
			player.mo.flags = $ & ~MF_NOCLIPHEIGHT
			player.mo.state = S_PLAY_MELEE
		end
		if player.mo.skin == "cheeseboi"
		and player.playerstate == PST_DEAD
		and not P_IsObjectOnGround(player.mo)
		P_InstaThrust(player.mo, player.mo.angle, 6*FRACUNIT)
		end
	   end	
	end
end)

--fallswitch recreation.
addHook("AbilitySpecial", function(player, mo, momz)
	if player.mo.skin != "cheeseboi"
		return
	end
	if player.pflags&PF_THOKKED
	or not player.state == S_PLAY_RUN
		return true
	end
	local dust1 = P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_SPINDUST)
	local dust2 = P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_SPINDUST)
	local dust3 = P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_SPINDUST)
	local dust4 = P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_SPINDUST)
	local dust5 = P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_SPINDUST)
	local dust6 = P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_SPINDUST)
	local dust7 = P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_SPINDUST)
	local dust8 = P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_SPINDUST)
	dust1.momx = 25*FRACUNIT
	dust2.momx = -25*FRACUNIT
	dust3.momy = 25*FRACUNIT
	dust4.momy = -25*FRACUNIT
	dust5.momx = 20*FRACUNIT
	dust5.momy = 20*FRACUNIT
	dust6.momx = -20*FRACUNIT
	dust6.momy = 20*FRACUNIT
	dust7.momx = 20*FRACUNIT
	dust7.momy = -20*FRACUNIT
	dust8.momx = -20*FRACUNIT
	dust8.momy = -20*FRACUNIT
	player.pflags = $|PF_THOKKED
	P_SetObjectMomZ(player.mo, -player.mo.momz, false)
	S_StartSound(player.mo, sfx_kc52)
	return true
end)
-- thanks to K_Nooby007 for the dust effect!

--the ball boost!
local function BallBoost(player)
if player.mo.skin == "cheeseboi" then
if (player.cmd.buttons & BT_CUSTOM1) then
		if not (player.pflags & PF_STASIS) 
		and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
		and not (player.mo.state == S_PLAY_SUPER_TRANS1)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
	    and not (player.mo.state == S_PLAY_STND)
		and not (player.mo.state == S_PLAY_ROLL)
		and not (player.mo.state == S_PLAY_SPINDASH)
	    and not (player.mo.state == S_PLAY_WAIT)
		and not (player.mo.state == S_PLAY_RIDE)
	    and not (player.mo.state == S_PLAY_PAIN)
	    and not (player.mo.state == S_PLAY_GASP)
	    and not (player.mo.state == S_PLAY_GLIDE_LANDING)
	    and not (player.mo.state == S_PLAY_DEAD)
	    and not (player.mo.state == S_PLAY_DRWN)
		and not (player.pflags & PF_FINISHED)
        P_InstaThrust(player.mo, player.drawangle, player.normalspeed + 25*FRACUNIT)--defines how fast cheeseboi goes
        local boststart = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_THOK)
		boststart.state = S_FACESTABBERSPEAR
		boststart.angle = player.drawangle+ANGLE_90
		boststart.scale = player.mo.scale
		boststart.fuse = 7
		boststart.frame = $ & ~FF_TRANSMASK | TR_TRANS30
		boststart.tics = 20
		boststart.blendmode = AST_ADD
		boststart.destscale = $*2
		boststart.color = SKINCOLOR_GOLD--color of circle
		boststart.colorized = true
        local ghost = P_SpawnGhostMobj(player.mo)
        ghost.fuse = 10
        ghost.colorized = true
        ghost.color = SKINCOLOR_GOLD--color of ghost
		end
	end
end
end
addHook("PlayerThink", BallBoost)


addHook("PlayerCanDamage", function(player, mobj)
	if player.mo and player.mo.skin == "cheeseboi" and player.cmd.buttons & BT_CUSTOM1 and not P_PlayerInPain(player)
	and (mobj.flags&MF_ENEMY or mobj.flags&MF_BOSS) return true end
end, MT_PLAYER)--ball boost lets you plough through enemies.

addHook("PlayerThink", function(p)
        if not (p and p.mo and p.mo.valid and p.mo.skin == "cheeseboi") return end
		 p.powers[pw_spacetime] = 30*TICRATE
end)--cheeseboi's an alien, he should breathe in space


local function BoostJump(player)
	if player.mo.skin == "cheeseboi" and player.cmd.buttons & BT_CUSTOM1
	if not player.powers[pw_super] then
    if not P_IsObjectOnGround(player.mo) then
		player.mo.state = S_PLAY_JUMP
		end
	end
end
end
addHook("PlayerThink", BoostJump)--simple code

local function BoostFly(player)
	if player.mo.skin == "cheeseboi" and (player.cmd.buttons & BT_CUSTOM1)
	if  player.powers[pw_super] then
    if not P_IsObjectOnGround(player.mo) then
		P_SetObjectMomZ(player.mo, 0*FRACUNIT)
		player.mo.state = S_PLAY_RUN
		end
	end
end
end
addHook("PlayerThink", BoostFly)

local function BoostFlyDown(player)
	if player.mo.skin == "cheeseboi" and (player.cmd.buttons & BT_CUSTOM1) and (player.cmd.buttons & BT_USE)
	if  player.powers[pw_super] then
    if not P_IsObjectOnGround(player.mo) then
		P_SetObjectMomZ(player.mo, -20*FRACUNIT)
		player.pflags = $1|PF_THOKKED
		end
	end
end
end
addHook("PlayerThink", BoostFlyDown)

local function BoostFlyUp(player)
	if player.mo.skin == "cheeseboi" and (player.cmd.buttons & BT_CUSTOM1) and (player.cmd.buttons & BT_JUMP)
	if  player.powers[pw_super] then
    if not P_IsObjectOnGround(player.mo) then
		P_SetObjectMomZ(player.mo, 20*FRACUNIT)
		player.pflags = $1|PF_THOKKED
		end
	end
end
end
addHook("PlayerThink", BoostFlyUp)

--spike killer
addHook ("MobjMoveCollide", function (player, spike)
	if player.skin == "cheeseboi" 
		if (spike.type == MT_SPIKE
		or spike.type == MT_WALLSPIKE)
			if (player.z + player.height < spike.z) 
			or (player.z > spike.z + spike.height)
				return false
			else
				P_KillMobj(spike,player,player)
			end
		end
	end
end)

--creds to cosmic emerald
addHook("PlayerThink", function(p) 
if not (pmo and p.mo.valid) and not (p.mo.skin == "cheeseboi")--slide :o
return
	end

	
	if p.mo.usetics != nil and (p.cmd.buttons & BT_CUSTOM2)--button that lets cheeseboi slide 
		p.mo.usetics = $ + 1 
	else
		p.mo.usetics = 0 
	end
	
	local crouchheight = 30*FRACUNIT
	
	if P_IsObjectOnGround(p.mo) and not (p.pflags&PF_SPINNING)
		if (p.mo.usetics ~= 0)
			p.mo.state = S_PLAY_GLIDE_LANDING--state change 
			p.pflags = $|PF_STASIS--make sure the stinky little thing cant move 
			p.height = crouchheight
		else 
			if (p.mo.state == S_PLAY_GLIDE_LANDING)
				p.height = 48*FRACUNIT
				if  p.pflags&PF_STASIS
					p.pflags = $ & ~PF_STASIS 
				end
			end
		end
		
		if ((p.mo.state == S_PLAY_GLIDE_LANDING) and (p.mo.usetics)) and (p.speed >= p.runspeed/10) 
			P_SpawnSkidDust(p, 15*FRACUNIT, sfx_kc51)--sound to play when sliding
		end
     end
end)

hud.add(function(v,player)
	if player.mo and player.mo.skin == "cheeseboi" and player.weapondelay
		local xpos = hudinfo[HUD_LIVES].x
		local ypos = hudinfo[HUD_LIVES].y
		v.drawString(xpos, (ypos - 35), ("THROW COOLDOWN:" + (player.weapondelay)), V_PERPLAYER|V_YELLOWMAP|V_SNAPTOBOTTOM|V_SNAPTOLEFT)
	end
end)

addHook("PlayerThink", function(player)
if player.mo
and player.mo.skin == "cheeseboi"
and player.mo.cancheesethrow == false
if not (leveltime % 15)
player.mo.cancheesethrow = true
end
end
end)

--cheese throw. lua borrowed from plasma metal sonic
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "cheeseboi"
			if not (player.mo.cheese)
				player.mo.cheese = 0
			end
			if not (player.powers[pw_carry] == CR_NIGHTSMODE) 
			and player.mo.cancheesethrow == true
			and not (player.powers[pw_carry]) 
			and not (player.pflags & PF_STASIS) 
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
		and not (player.mo.state == S_PLAY_SUPER_TRANS1)
		and not (player.mo.state == S_PLAY_SWIM)
		and not (player.cmd.buttons & BT_CUSTOM1)
		and not (player.mo.state == S_PLAY_SPINDASH)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
		and not (player.mo.state == S_PLAY_SWIM)
		and not (player.mo.state == S_PLAY_JUMP)
		and not (player.pflags & PF_FINISHED)
		and P_PlayerInPain(player) == false
		    and player.playerstate == PST_LIVE
			 and (player.cmd.buttons & BT_USE)
			and player.mo.cheese == 0
            player.mo.cheese = 1
			P_StartQuake(15*FRACUNIT, 1)	
			S_StartSound(player.mo, sfx_kc31)
		       local throw = P_SpawnPlayerMissile(player.mo, MT_CHEESEROCKET)
			end
			if not (player.cmd.buttons & BT_USE)
				player.mo.cheese = 0
				player.mo.cancheesethrow = false
			end
		end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "cheeseboi"
			if  player.powers[pw_super] then
			if not (player.mo.fires)
				player.mo.fires = 0
			end
			if (player.cmd.buttons & BT_FIRENORMAL)
			 or (player.cmd.buttons & BT_CUSTOM1)
			and not (player.powers[pw_carry] == CR_NIGHTSMODE)
			and not (player.powers[pw_carry]) 
			and not (player.pflags & PF_STASIS)
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
		and not (player.mo.state == S_PLAY_SUPER_TRANS1)
		and not (player.mo.state == S_PLAY_SWIM)
		and not (player.cmd.buttons & BT_CUSTOM1)
		and not (player.mo.state == S_PLAY_SPINDASH)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
		and not (player.mo.state == S_PLAY_SWIM)
		and not (player.mo.state == S_PLAY_JUMP)
		and not (player.pflags & PF_FINISHED)
		and P_PlayerInPain(player) == false
	    and player.playerstate == PST_LIVE
			and player.mo.fires == 0
				player.mo.fires = 1 
				P_StartQuake(20*FRACUNIT, 1)
				S_StartSound(player.mo, sfx_kc31)
		       local flame = P_SpawnPlayerMissile(player.mo, MT_CHEESEROCKET)
				end
			if not (player.cmd.buttons & BT_USE)
				player.mo.fires = 0
			end
		end
	end
	end
end)

--credits to kirby anniv for 10-line momentum
addHook("PlayerThink", function(player) // Make sure that it runs
	if (player.speed >= player.runspeed) // Check if the player is moving faster than their run
	and (player.mo.skin == "cheeseboi")
	and (player.cmd.forwardmove or player.cmd.sidemove) // Is the player purposely moving?
		player.mo.friction = FRACUNIT // Make the momentum happen
	end // Finish this if statement
end) // Close this hook

--super music by BGVC*
addHook("PlayerThink", function(player, mo)
    if (player.mo.skin == "cheeseboi")
    and player.powers[pw_super] then
	S_ChangeMusic("CHSBSP",true,player,0)
      end
end)         

--this is what u need!
addHook("PlayerThink", function(player, mo)
    if (P_IsObjectOnGround(player.mo) == true) and (player.mo.skin == "cheeseboi")
	and (player.mo.state == S_PLAY_STND or player.mo.state == S_PLAY_WAIT)
    and (player.cmd.buttons & BT_TOSSFLAG) then
	S_StartSound(player.mo, sfx_kc5d)
	P_PlayJingleMusic(player, "WTUND", nil, true, JT_OTHER)
         player.mo.state = S_PLAY_SPOOKY
      end
end)         

addHook("PlayerThink", function(player)
    if (player.mo.skin == "cheeseboi")
	and (player.mo.state == S_PLAY_SPOOKY)
	player.pflags = $|PF_STASIS 
      end
end)         

addHook("PlayerThink", function(player, mo)
    if (player.mo.skin == "cheeseboi")
	and not (player.mo.state == S_PLAY_SPOOKY)
	and not player.powers[pw_super]
		P_RestoreMusic(player)
      end
end)         

--spawn dust
addHook("PlayerThink", function(player) 
if not(player.mo) then return end 	
if (player.mo.skin == "cheeseboi")
	if (P_IsObjectOnGround(player.mo)) 
	and (player.mo.state == S_PLAY_RUN) or (player.mo.state == S_PLAY_DASH) or (player.mo.state == S_PLAY_SPINDASH)
	and not player.powers[pw_super]
		P_SpawnSkidDust(player, 13*FRACUNIT, sfx_none)
		end
	end
end)