local O=game:GetService("\083\101\114\118\101\114\083\116\111\114\097\103\101")local U=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local m=require(U.Dependencies.LuaUtils.TableUtils)local Z=require(O.Source.Managers.RoomManager)local v=require(U.Source.Common.Constants)local K=require(O.Source.Managers.MonsterManager)local M=U.MonstersEnabled.Value math.randomseed(tick())return function()local O=Z.getRooms()local U=m.filter(O,function(O)if#O:getWindows()>0 then return true end end)if#U>0 then local O=U[math.random(1,#U)]local m=O:getWindows()local Z=math.random(1,#m)for O=1,Z,1 do local U=m[O]if not U then return end if U:getState()==v.State.Window.Normal then U:breach()else Z=Z+1 end end if M then K.spawnMonsterInRoom(O)end end end

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
