-- Dummy Ring Bomb (A modified version of "Bomb Throw for Fang" by Simon_T) --

if srb2p return end

local autoaim
local monitor

addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo.skin ~= "tails" then //If you're Tails...
			continue
		end
		
		if not (player.exiting) then //If you're not exiting the level...
			if not (P_PlayerInPain(player) or (player.playerstate == PST_DEAD)) then //If you're not in pain or not dead...
				if ((player.powers[pw_carry] == CR_NONE) and not (player.pflags == PF_SPINNING)) then //If you're not being carried and not spinning...
					if not (player.cmd.buttons & BT_CUSTOM1) then //If Custom 1 is pressed...
						player.cust1tapready = true
						player.cust1tapping = false
					elseif player.cust1tapready then
						player.cust1tapping = true
						player.cust1tapready = false
					else
						player.cust1tapping = false
					end
					
					if player.cust1tapping and not (player.weapondelay) then //If the first function is true after the weapon delay...
						monitor = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z + (player.mo.height/2), MT_DUMMYBOMB) -- Spawns the monitor
						monitor.target = player.mo -- The monitor can't hurt its user
						S_StartSound(fruit, sfx_s3k51) -- Plays a throwing sound
						if (player.mo.momz > 0) and not (player.powers[pw_tailsfly]) then //If you're jumping, but not flying...
							monitor.momz = (player.mo.momz)+(7*FRACUNIT) -- The monitor gets a height boost
						else
							if (player.powers[pw_tailsfly]) then //If you're flying...
								monitor.momz = 0*FRACUNIT -- Drops the monitor
							else //If you're not...
								monitor.momz = 7*FRACUNIT -- Lobs the monitor
							end
						end
						if (player.mo.eflags & MFE_VERTICALFLIP) then //If you're upside down...
							monitor.eflags = $1|MFE_VERTICALFLIP -- Flips the monitor vertically
							monitor.flags2 = $1|MF2_OBJECTFLIP -- ^
							if (player.powers[pw_tailsfly]) then //If you're flying..
								monitor.momz = 0*FRACUNIT -- This is just in case the monitors do something funny without it
							else //If you're not...
								monitor.momz = -7*FRACUNIT -- Lobs the monitor in the relative direction
							end
						end
						if not (player.powers[pw_tailsfly]) then //If you're not flying...
							P_InstaThrust(monitor, player.mo.angle, ((player.speed)+(7*FRACUNIT))) -- The monitors will travel in an arc affected by your speed
						end
						if (player.powers[pw_tailsfly]) or All7Emeralds(emeralds) then //If you're flying or you have all 7 emeralds...
							player.weapondelay = TICRATE*0 -- You can fire off monitors faster
						else //If not...
							player.weapondelay = TICRATE*2 -- You'll have to wait 2 seconds between attacks
						end
					end
					
					if not (player.cmd.buttons & BT_CUSTOM2) then //If Custom 2 is pressed...
						player.cust2tapready = true
						player.cust2tapping = false
					elseif player.cust2tapready then
						player.cust2tapping = true
						player.cust2tapready = false
					else
						player.cust2tapping = false
					end
					
					if player.cust2tapping and not (player.powers[pw_tailsfly]) then //If the above function is true while not flying...
						autoaim = P_LookForEnemies(player, false, true) -- Looks for enemies
					end
					
					if player.cust2tapping and not (player.weapondelay) then //If the above function is true after the delay
						monitor = P_SpawnMissile(player.mo, autoaim, MT_DUMMYBOMB2) -- "Meet the Sniper"
						monitor.target = player.mo -- Monitors still can't hurt the user
						S_StartSound(player.mo, sfx_s3k51) -- Plays a throwing sound
						if (player.mo.eflags & MFE_VERTICALFLIP) then //If you're upside down...
							monitor.eflags = $1|MFE_VERTICALFLIP -- Flips the monitor vertically
							monitor.flags2 = $1|MF2_OBJECTFLIP -- ^
						end
						player.weapondelay = TICRATE*2 -- You have to wait 2 seconds between attacks
					end
				end
			end
		end
	end
end)

addHook("MobjThinker", function(mo)
	if (mo.state == S_DBOMB_EXPL1) then //If the bomb explodes...
		S_StartSound(mo, sfx_altow1) -- Plays what's supposed to be the SeeSound in case it doesn't work
	end
end, MT_DUMMYBOMB)

addHook("MobjThinker", function(mo)
	if (mo.state == S_DBOMB_EXPL1) then //If the bomb explodes...
		S_StartSound(mo, sfx_altow1) -- Plays what's supposed to be the SeeSound in case it doesn't work
	end
end, MT_DUMMYBOMB2)