-- functions


local function HandleDrop(d)
	local drop	= {
		Model	= nil;
		Outline	= nil;
		Parts	= {};
	}
	
	local model	= ITEMS[d.Name]:Clone()
		model.Parent	= EFFECTS
		model:BreakJoints()
		
	local config	= require(model:WaitForChild("Config"))
	local base		= ITEMS[d.Name]
	
	if base:FindFirstChild("Attachments") then
		local attachments	= d:WaitForChild("Attachments")
		
		for _, attach in pairs(attachments:GetChildren()) do
			local attachment	= ITEMS[attach.Name]:Clone()
			local config		= require(attachment.Config)
			attachment:SetPrimaryPartCFrame(model.PrimaryPart.CFrame * model.PrimaryPart[config.Attach .. "Attach"].CFrame * attachment.PrimaryPart.Attach.CFrame:inverse())
			attachment.Parent	= model
			attachment:BreakJoints()
		end
	end
	
	local outline	= Instance.new("Model")
		outline.Name	= "Outline"
		outline.Parent	= EFFECTS
		
	drop.Model		= model
	drop.Outline	= outline
				
	local center	= model.PrimaryPart:FindFirstChild("Center")
	
	for _, v in pairs(model:GetDescendants()) do
		if v:IsA("BasePart") then
			v.CFrame		= CFrame.new(0, -100, 0)
			v.Anchored		= true
			v.CanCollide	= false
		
			local o	= v:Clone()
				o.Name		= "Outline"
				o.Material	= Enum.Material.Neon
				o.Color		= OUTLINE_COLOR
				o.Size		= o.Size + Vector3.new(OUTLINE_WIDTH, OUTLINE_WIDTH, OUTLINE_WIDTH)
				if o:IsA("MeshPart") then
					o.TextureID	= ""
				end
				o.Parent	= outline
		
			local info	= {
				Part		= v;
				Outline		= o;
				Offset		= CFrame.new();
			}
			
			if center then
				info.Offset	= center.WorldCFrame:toObjectSpace(v.CFrame)
			else
				info.Offset	= model.PrimaryPart.CFrame:toObjectSpace(v.CFrame)
			end
			
			table.insert(drop.Parts, info)
		end
	end
	
	drops[d]	= drop
	
	d.AncestryChanged:connect(function()
		if d.Parent ~= DROPS then
			if drops[d] then
				drops[d].Model:Destroy()
				drops[d].Outline:Destroy()
				drops[d]	= nil
			end
		end
	end)
end
