/// Passive Ability: Speed-Booster
// go beyond your speed limit by running fast

// CUSTOMIZE SECTION START
local skin = "sbagnewborn" // your character here
local sound = sfx_s23c // the sound that plays when you enter speed booster mode
local sound2 = sfx_cdfm00 // the sound that plays when you enter speed booster mode
local runtime = 1465 // how long you need to run to get your speed boost
local sbspeed = 55 // how fast the speed boost is
local hasdust = true // if this is true, you will spawn dust while boosting
local hasghost = false // if this is true, you will have a after effect while boosting
local invulframes = false // if this is true, you will have invul frames while dashing
// CUSTOMIZE SECTION END PROCCED BELOW IF YOU KNOW WHAT YOUR DOING

local function SpeedBoost_Reset(player)
	player.mo.sbruntime = 0
	player.normalspeed = skins[skin].normalspeed
	player.charflags = $1 & ~SF_RUNONWATER
	player.camerascale = skins[skin].camerascale
end

addHook("PlayerThink", function(player)
	if player.mo.sbruntime == nil
		player.mo.sbruntime = 0
	end
	if player.mo.skin == skin 
	and player.speed > player.runspeed
		player.mo.sbruntime = $ + 1
	end
	if player.mo.skin == skin 
	and player.speed < player.runspeed
	and P_IsObjectOnGround(player.mo)
	and player.mo.sbruntime > 0
		SpeedBoost_Reset(player)
	end
	if player.mo.skin == skin 
	and player.speed < player.runspeed
	and P_IsObjectOnGround(player.mo)
	and player.mo.sbruntime > runtime
		S_StartSound(player.mo, sound2)
		SpeedBoost_Reset(player)
	end
	if player.mo.skin == skin 
	and player.mo.sbruntime == runtime
		S_StartSound(player.mo, sound)
	end
	if player.mo.skin == skin 
	and player.mo.sbruntime > runtime
		player.charflags = $1|SF_RUNONWATER
		player.normalspeed = sbspeed*FRACUNIT
		if invulframes == true
			player.powers[pw_invulnerability] = TICRATE / 2
		end
		if hasdust == true and P_IsObjectOnGround(player.mo)
			P_SpawnSkidDust(player, player.mo.radius, true)
		end
		if hasghost == true
			local speedtrail = P_SpawnGhostMobj(player.mo) 
			speedtrail.colorized = true
			speedtrail.color = player.mo.color
			speedtrail.fuse = 10
			speedtrail.blendmode = AST_ADD 
		end
	end
end)

