local t=game:GetService("\083\101\114\118\101\114\083\116\111\114\097\103\101")local y=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local S=require(y.Dependencies.LuaUtils.TableUtils)local g=require(t.Source.Managers.RoomManager)local W=require(y.Source.Common.Constants)local R=require(t.Source.Managers.MonsterManager)local e=y.MonstersEnabled.Value math.randomseed(tick())return function()local t=g.getRooms()local y=S.filter(t,function(t)if#t:getWindows()>0 then return true end end)if#y>0 then local t=y[math.random(1,#y)]local S=t:getWindows()local g=math.random(1,#S)for t=1,g,1 do local y=S[t]if not y then return end if y:getState()==W.State.Window.Normal then y:breach()else g=g+1 end end if e then R.spawnMonsterInRoom(t)end end end
--[[
	This function creates a meteor in a random room with windows, breaching a number of them, as well as the room.
	This is also where monsters would be spawned, if the spawn line of code were to be commented out. 
]]
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local TableUtils = require(ReplicatedStorage.Dependencies.LuaUtils.TableUtils)
local RoomManager = require(ServerStorage.Source.Managers.RoomManager)
local Constants = require(ReplicatedStorage.Source.Common.Constants)
local MonsterManager = require(ServerStorage.Source.Managers.MonsterManager)

local monstersEnabled = ReplicatedStorage.MonstersEnabled.Value

math.randomseed(tick())

return function()
	local rooms = RoomManager.getRooms()

	local roomsWithWindows = TableUtils.filter(rooms, function(room)
		if #room:getWindows() > 0 then
			return true
		end
	end)

	if #roomsWithWindows > 0 then
		local room = roomsWithWindows[math.random(1, #roomsWithWindows)]
		local windows = room:getWindows()
		local windowsToBreak = math.random(1, #windows)

		for i = 1, windowsToBreak do
			local window = windows[i]

			if not window then
				return
			end

			if window:getState() == Constants.State.Window.Normal then
				window:breach()
			else
				windowsToBreak = windowsToBreak + 1
			end
		end

		if monstersEnabled then
			MonsterManager.spawnMonsterInRoom(room)
		end
	end
end
