local A=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local p=A:WaitForChild("\077\111\100\117\108\101\115")local f=p:WaitForChild("\115\114\099")local R=A:WaitForChild("\077\111\100\101\108\115")local u=require(p.Knit.Util.Maid)local K=R.FallItems local d=require(f.utils.Logger)local i=require(p.M)local g={}function dummyPart(A,p)local f=Instance.new("\080\097\114\116")f.Anchored=false f.CanCollide=true f.Size=Vector3.new(.5,.5,.5)f.Position=A f.Parent=p end local S={}function g.fallStuff(f,A,p)local R=u.new()local d=S[A]if not d then local p=K:GetChildren()d=p[math.random(1,#p)]S[A]=d end local i=d:GetChildren()local g=d.Name=="\066\108\111\111\100"and 2 or 0 local T=Vector3.new(0,A.Size.Y/2+g,0)local J=math.min(A.Size.X,A.Size.Z)function randomNum()return math.random()*J-J/2 end local c=50 local s=0 while s<c do local p=Vector3.new(randomNum(),0,randomNum())local f=i[math.random(1,#i)]:Clone()f.PrimaryPart.Position=(A.Position+T)+p f.Parent=workspace R:GiveTask(f)s=s+1 end wait(p)R:Destroy()end return g
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Modules = ReplicatedStorage:WaitForChild('Modules')
local src = Modules:WaitForChild('src')
local Models = ReplicatedStorage:WaitForChild('Models')

local Maid = require(Modules.Knit.Util.Maid)
local FallItems = Models.FallItems
local logger = require(src.utils.Logger)

local M = require(Modules.M)

local FallTriggerManager = {}

function dummyPart(position, folder)
	local newBlock = Instance.new('Part')

	newBlock.Anchored = false
	newBlock.CanCollide = true
	newBlock.Size = Vector3.new(0.5, 0.5, 0.5)
	newBlock.Position = position
	newBlock.Parent = folder
end

local cachedFolders = {}
function FallTriggerManager:fallStuff(triggerPart, waitFor)
	local maid = Maid.new()

	local folder = cachedFolders[triggerPart]
	if not folder then
		local folders = FallItems:GetChildren()
		folder = folders[math.random(1, #folders)]
		cachedFolders[triggerPart] = folder
	end

	local items = folder:GetChildren()

	local addMoreToTop = folder.Name == 'Blood' and 2 or 0

	local toTopSide = Vector3.new(0, triggerPart.Size.Y / 2 + addMoreToTop, 0)

	local diameter = math.min(triggerPart.Size.X, triggerPart.Size.Z)

	function randomNum()
		return math.random() * diameter - diameter / 2
	end

	local maxItems = 50
	local generatedItems = 0
	-- fall 2/3 at once and tripp rest of items
	while generatedItems < maxItems do
		local randomPos = Vector3.new(randomNum(), 0, randomNum())

		local part = items[math.random(1, #items)]:Clone()
		part.PrimaryPart.Position = triggerPart.Position + toTopSide + randomPos
		part.Parent = workspace

		maid:GiveTask(part)

		generatedItems = generatedItems + 1
	end

	wait(waitFor)
	maid:Destroy()
end

return FallTriggerManager