freeslot("MT_STOMPER", "S_STOMPER", "SPR_STMP")
mobjinfo[MT_STOMPER] = {
	spawnstate = S_STOMPER,
	flags = MF_NOGRAVITY|MF_NOCLIP|MF_SCENERY|MF_NOBLOCKMAP,
	dispoffset = 1,
	radius = FU,
	height = FU
}
states[S_STOMPER] = {
	sprite = SPR_STMP,
	frame = FF_FULLBRIGHT|FF_ADD|FF_ANIMATE,
	var1 = 3,
	var2 = 1,
	tics = -1
}

addHook("PlayerThink", function(p)
	if not _G["stomp_enabled"] or p.menu_open or not (p.mo and p.mo.valid) then return end
	if p.stomp_cooldown == nil then p.stomp_cooldown = 0 end
	if p.stomp_cooldown > 0 then
		p.stomp_cooldown = $ - 1
	end
	if (p.cmd.buttons & BT_CUSTOM1)
	and not P_IsObjectOnGround(p.mo)
	and not p.exiting
	and not p.stompin 
	and p.stomp_cooldown == 0 
	and not (p.mo.eflags & MFE_SPRUNG)
	and not p.powers[pw_carry]
	and not P_IsObjectInGoop(p.mo)
	and not (P_PlayerInPain(p) or p.playerstate == PST_DEAD)
		p.mo.state = S_PLAY_FALL
		p.pflags = $|PF_JUMPED|PF_STASIS
		S_StartSound(p.mo, sfx_stm)	
		p.stompin = true
		p.stompeffect = false
		P_InstaThrust(p.mo, 0,0)
		P_SetObjectMomZ(p.mo, -25*FRACUNIT, false)
		p.powers[pw_strong] = STR_ANIM|STR_FLOOR|STR_SPRING
	end
end)


addHook("PlayerThink", function(player)
	if not (player.mo and player.mo.valid) or player.stompin ~= true then return end
	local vfxColor = player.chosenbvfxcolor or player.mo.color
	player.mo.state = S_PLAY_FALL
	player.pflags = $|PF_STASIS
	P_InstaThrust(player.mo, 0, 0)
	if FixedHypot(player.mo.momx, player.mo.momy) > 0 then
		player.mo.momx = $ - ($/40)
		player.mo.momy = $ - ($/40)
	else
		player.mo.momx = 0
		player.mo.momy = 0
	end
	if player.mo.momz <= -25*FRACUNIT then P_SetObjectMomZ(player.mo, -FRACUNIT, true)
	else P_SetObjectMomZ(player.mo, -25*FRACUNIT, false) end
	local adventurerip2 = P_SpawnMobjFromMobj(player.mo, player.mo.momx/2, player.mo.momy/2 , player.mo.momz, MT_THOK)  
	if adventurerip2 and adventurerip2.valid then
		adventurerip2.colorized = true
		adventurerip2.blendmode = AST_ADD
		adventurerip2.sprite = SPR_TMPE
		adventurerip2.frame = (leveltime*2 % 4) | FF_TRANS40
		adventurerip2.tics = 5
		adventurerip2.tracer = player.mo
		adventurerip2.destscale = FRACUNIT/3
		adventurerip2.scale = FRACUNIT
		adventurerip2.rollangle = player.mo.rollangle + FixedMul(player.mo.momz, sin(player.mo.angle - (player.mo.momx + player.mo.momy)))
		adventurerip2.angle = player.drawangle
		adventurerip2.color = vfxColor
	end
	if player.stompeffect == false then
		local stompeffect = P_SpawnMobjFromMobj(player.mo, 0,0,0, MT_STOMPER)
		stompeffect.colorized = true
		stompeffect.color = vfxColor
		stompeffect.blendmode = AST_ADD
		stompeffect.frame = $|FF_FULLBRIGHT|FF_TRANS40
		stompeffect.scale = FRACUNIT*6/7
		stompeffect.target = player.mo
		stompeffect.tics = -1
		stompeffect.momz = player.mo.momz
		stompeffect.momx = player.mo.momx
		stompeffect.momy = player.mo.momy
		player.stompeffect = true
		P_MoveOrigin(stompeffect, player.mo.x, player.mo.y, player.mo.z)
		if not player.mo.state == S_PLAY_FALL then P_KillMobj(stompeffect) end
	end
end)


addHook("MobjThinker", function(mo)
	if mo and mo.valid then
		local pmo = mo.target
		if pmo and pmo.valid then
			P_MoveOrigin(mo, pmo.x, pmo.y, pmo.z)
			if P_IsObjectOnGround(pmo) or pmo.state ~= S_PLAY_FALL or P_IsObjectInGoop(pmo) then P_KillMobj(mo) end
		else P_KillMobj(mo) end
	end
end, MT_STOMPER)

addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid and player.stompin and (player.mo.eflags & MFE_JUSTHITFLOOR) then
		S_StartSound(player.mo, sfx_lan)
		player.stomp_cooldown = 12
		local dashpart1 = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z + player.mo.height/9, MT_BOOSTVFX) 
		dashpart1.tics = 10
		dashpart1.blendmode = AST_ADD
		dashpart1.momx = 0
		dashpart1.momy = 0
		dashpart1.colorized = true
		dashpart1.destscale = FRACUNIT*7
		dashpart1.scale = FRACUNIT*7/2
		dashpart1.scalespeed = FRACUNIT/3
		dashpart1.momz = 0
		dashpart1.frame = $|FF_FLOORSPRITE
		dashpart1.color = player.chosenbvfxcolor or player.mo.color
		for i = 0, 20 do
			local particle_angle = ANGLE_22h * i 
			local radius_offset = 20 * player.mo.scale
			local offset_x = P_ReturnThrustX(nil, particle_angle, radius_offset)
			local offset_y = P_ReturnThrustY(nil, particle_angle, radius_offset)
			local offset_z = player.mo.z + (player.mo.height / 2) + (P_RandomRange(-10, 10) * player.mo.scale)
			local fast2 = P_SpawnMobj(player.mo.x + offset_x, player.mo.y + offset_y, offset_z, MT_SMOKE)
			if fast2 and fast2.valid then
				fast2.state = S_BOOSTPARTICLE
				fast2.frame = $|FF_FULLBRIGHT|FF_TRANS40|FF_PAPERSPRITE
				fast2.angle = particle_angle
				fast2.momx = player.mo.momx/2 + P_ReturnThrustX(nil, particle_angle, 6 * player.mo.scale)
				fast2.momy = player.mo.momy/2 + P_ReturnThrustY(nil, particle_angle, 6 * player.mo.scale)
				fast2.momz = player.mo.momz/2
				fast2.colorized = true
				fast2.blendmode = AST_ADD
				fast2.scale = player.mo.scale
				fast2.tics = 10
				fast2.color = player.chosenbvfxcolor or player.mo.color
			end
		end
		P_Telekinesis(player, 25*FRACUNIT, 175*FRACUNIT)
		player.stompin = false
		player.stompeffect = false
		player.pflags = $ & ~PF_SPINNING
		player.mo.state = S_PLAY_STND
	end
end)



local L_ZCollide = function(mo1,mo2)
	if mo1.z > mo2.height+mo2.z then return false end
	if mo2.z > mo1.height+mo1.z then return false end
	return true
end



local function SpringRollCollide(mo, inf)
	if not (mo and mo.valid) or not (inf and inf.valid) then return end
	if not L_ZCollide(mo, inf) then return end
	local ShadowisStomping = (mo.valid and mo.state == S_PLAY_FALL)
	local isSpring = (inf.flags & MF_SPRING) ~= 0
	if isSpring and ShadowisStomping then
		mo.player.stompin = false
		mo.player.stompeffect = false
		mo.player.springed = true
	end
end


addHook("MobjCollide", SpringRollCollide, MT_PLAYER)
addHook("MobjMoveCollide", SpringRollCollide, MT_PLAYER)
addHook("PlayerThink", function(p)
	if p.powers[pw_justsprung] or (p.mo and p.mo.valid and (p.mo.eflags & MFE_SPRUNG)) then p.springed = true end
	if P_IsObjectOnGround(p.mo) and p.springed then p.springed = false end
	if p.mo and p.mo.valid and p.mo.state == S_PLAY_FALL and P_IsObjectInGoop(p.mo) then
		p.stompin = false
		p.stompeffect = false
	end
	if p.mo and p.mo.valid and p.stompin and P_IsObjectOnGround(p.mo) and p.springed then
		p.stompin = false
	end
end)
addHook("PlayerThink", function(p)
	if p.mo and p.mo.valid and p.stompin == true then
		if P_IsObjectOnGround(p.mo) and p.springed then p.stompin = false end
	end
end)
