-- Sls by Sls64LGamingBro (an OC I created)
-- This was created for all though in SLADE
-- Also, i created some of the stuff as well
-- Cleary I updated the code now, which means it's good now.
-- I am also adding support for gamingchars anyway, because
-- since this mod didn't had support, I decided to do that.


--------------------------


-- This is kinda NOT reusable at all
-- Which is the same thing staromentum,
-- this is techincally a old mod now,
-- since gamingchars is replacing the original mod's place,
-- there is clearly no choice but to call him legacysls now.
-- Anyways, enjoy the script!


//Legacy Sls Color
freeslot("SKINCOLOR_LEGACYSLS")
skincolors[SKINCOLOR_LEGACYSLS] = {
    name = "LegacySls",
    ramp = {1,2,3,4,6,8,9,10,11,13,14,15,16,17,18,19},
    invcolor = SKINCOLOR_WHITE,
    invshade = 9,
    chatcolor = V_GRAYMAP,
    accessible = true
}


//Air Boost
addHook("PlayerThink", function(player)
	if player.mo.skin == "legacysls"
	    if (player.mo.state == S_PLAY_JUMP)
		and (player.cmd.buttons & BT_SPIN)
		and not (player.powers[pw_shield])
           P_SpawnGhostMobj(player.mo)
		   player.mo.state = S_PLAY_SPRING
		   P_SetObjectMomZ(player.mo, 14*FRACUNIT)
		   player.pflags = $ & ~PF_STARTJUMP
		   S_StartSound(player.mo, sfx_zoom)
		end
	end
end)


//Dash Fall
addHook("PlayerThink", function(player)
	if player.mo.skin == "legacysls"
	    if (player.mo.state == S_PLAY_JUMP)
		and (player.cmd.buttons & BT_CUSTOM1)
           P_SpawnGhostMobj(player.mo)
		   player.mo.state = S_PLAY_FALL
		   S_StartSound(player.mo, sfx_thok)
		   S_StartSound(player.mo, sfx_zoom)
		   P_Thrust(player.mo, player.mo.angle, 12*FRACUNIT)
		end
	end
end)


//Fly and Swim Cancel
addHook("PlayerThink", function(player)
    if (player.mo.skin == "legacysls")
		if (player.mo.state == S_PLAY_FLY) 
		and (player.cmd.buttons & BT_CUSTOM1)
		   S_StartSound(player.mo, sfx_s3k42)
		   player.mo.state = S_PLAY_ROLL
		end
	end
end)


addHook("PlayerThink", function(player)
    if (player.mo.skin == "legacysls")
		if (player.mo.state == S_PLAY_FLY_TIRED)
		and (player.cmd.buttons & BT_CUSTOM1)
		   S_StartSound(player.mo, sfx_s3k42)
		   player.mo.state = S_PLAY_ROLL
		end
	end
end)


addHook("PlayerThink", function(player)
    if (player.mo.skin == "legacysls")
		if (player.mo.state == S_PLAY_SWIM)
		and (player.cmd.buttons & BT_CUSTOM1)
		   S_StartSound(player.mo, sfx_s3k42)
		   player.mo.state = S_PLAY_ROLL
		end
	end
end)


addHook("PlayerCanDamage", function(player)
    if (player.mo.skin == "legacysls")
    and (player.mo.state == S_PLAY_ROLL)
        return true
    end
end)


//Super Sparkles
addHook("PlayerThink", function(player)
	if leveltime % 3 == 0 then
		if player.powers[pw_super]
		and player.mo.skin == "legacysls"
			local supersparkle = P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_SUPERSPARK)
	        supersparkle.momx = P_RandomRange(-14, 14) * FRACUNIT + FixedMul(-12, 12, player.mo.scale)
	        supersparkle.momy = P_RandomRange(-14, 14) * FRACUNIT + FixedMul(-12, 12, player.mo.scale)
	        supersparkle.momz = P_RandomRange(-1, 9) * FRACUNIT + FixedMul(-12, 12, player.mo.scale)
	        supersparkle.fuse = 7
	        supersparkle.scale = player.mo.scale
	        supersparkle.source = player.mo
			supersparkle.color = player.mo.color
			supersparkle.colorized = true
	     end
	 end 
end)


//No Drowning when being Super
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "legacysls"
			if player.powers[pw_super] == 0
				player.powers[pw_underwater] = 0
				player.powers[pw_spacetime] = 0
			end
		end
	end
end)
