/// Ability: Stomp
// allow you to go down very quickly

// CUSTOMIZE SECTION START
local skin = "sparrow" // your character here
local thebutton = BT_CUSTOM1 // the button needed to use the move
local dropspeed = 40 // how fast you want to drop to the ground
local forwardthrusting = false // if this is true, then you will be thrusted based on the forwardthrust factor 
local forwardthrust = 20 // if you don't want any forward thrust while doing the move make this 0
local sound = sfx_rocks1 // the sound of the stomp
local circlespawneffect = true // make this true to enable a circle spawn effect when your done stomping
local objectspawned = MT_SPINDUST // if circle spawn is on, this is what you will spawn when your done stomping
local objectspeed = 20 // if circle spawn is on, this is how fast the object will go outwards when spawned
local thestate = S_PLAY_TWINSPIN // the state to change to while stomping
local mode = 1 /*
changes the mode of the stomp
1: when your finished, nothing happens
2: when your finished, your get rebounded into the air
*/
local upthrustheight = 20 // if mode is 2, then this is how far you will be launched into the air
// CUSTOMIZE SECTION END PROCCED BELOW IF YOU KNOW WHAT YOUR DOING

addHook("PlayerThink", function(player)
	if player.lestomping == nil
		player.lestomping = 0
	end
    if player.mo and player.mo.skin == skin
	and player.lestomping == 1
	and P_IsObjectOnGround(player.mo)
		player.lestomping = 0
		S_StartSound(player.mo,	sound)
		if mode == 2
			P_SetObjectMomZ(player.mo,upthrustheight*FRACUNIT)
			player.mo.state = S_PLAY_ROLL
		end
		if mode == 1
			player.mo.state = S_PLAY_WALK
		end
		if circlespawneffect == true
			for i = 1, 16 
				local object = P_SpawnMobjFromMobj(player.mo, 0,0,0,objectspawned)
				object.target = player.mo
				object.fuse = TICRATE
				object.scale = player.mo.scale
				object.destscale = player.mo.scale/8
				P_InstaThrust(object, i*ANGLE_22h, objectspeed*FRACUNIT)
				object.momz = 0
				object.flags = $ |MF_MISSILE
			end
		end
	end
	if player.mo and player.mo.skin == skin
	and player.lestomping == 1
	and P_PlayerInPain(player)
		player.lestomping = 0
	end
	if player.mo and player.mo.skin == skin
	and player.lestomping == 1
	and P_CheckDeathPitCollide(player.mo)
		player.lestomping = 0
	end
	if player.mo and player.mo.skin == skin
	and player.lestomping == 1
	and player.mo.state == S_PLAY_SPRING
		player.lestomping = 0
	end
	if player.mo and player.mo.skin == skin
	and player.lestomping == 1
		player.mo.state = thestate
		P_SetObjectMomZ(player.mo,-dropspeed*FRACUNIT)
		player.powers[pw_flashing] = TICRATE / 2
		if forwardthrusting == true
			P_InstaThrust(player.mo,player.mo.angle,forwardthrust*FRACUNIT)
		end
		local stomptrail = P_SpawnGhostMobj(player.mo) 
		stomptrail.colorized = true
		stomptrail.color = player.mo.color
		stomptrail.fuse = 10
		stomptrail.blendmode = AST_ADD 
	end
	if player.mo and player.mo.skin == skin
	and (player.cmd.buttons & thebutton)
	and not P_IsObjectOnGround(player.mo)
	and player.lestomping == 0
		player.lestomping = 1
	end
end)

addHook("PlayerCanDamage", function(player)
    if player.skin == skin
	and player.lestomping == 1
		return true
    end
end)
