--[[
    Server side script that listens to client bomb throw requests, validates them, and then executes the request
]]

local ServerStorage = game:GetService("ServerStorage")

local createThrownBomb = require(ServerStorage.Source.MinigameUtilities.createThrownBomb)

local tool = script.Parent
local fireEvent = tool:FindFirstChild("Fire")
local cooldown = tool:FindFirstChild("Cooldown").Value

local lastThrow = 0
fireEvent.OnServerEvent:Connect(
	function(player, origin, target)
		if player and player.Character then
			if script:IsDescendantOf(player.Character) then
				local nowTick = tick()
				if nowTick - lastThrow > cooldown then
					lastThrow = nowTick
					createThrownBomb(player, origin, target)
				end
			end
		end
	end
)
