--!strict local Text = require(game:GetService("ReplicatedStorage"):WaitForChild("Hunter"):WaitForChild("Strings") :: ModuleScript).interface.ProceduralArena local ReplicatedStorage = game:GetService("ReplicatedStorage") local ServerStorage = game:GetService("ServerStorage") local Mobility = require(ReplicatedStorage:WaitForChild("ArenaMobility") :: ModuleScript) local arena = workspace:WaitForChild("ProceduralArena") :: Model local spawns = arena:WaitForChild("PlayerSpawns") local kit = ServerStorage:WaitForChild("ProceduralArenaKit") local origin = arena:GetPivot().Position local random = Random.new() local cell = kit:GetAttribute("GridCell") :: number local halfX, halfZ = 42 * cell, 49 * cell local flankX = 30 * cell local tile = 2 * cell local clearance = 6 local middle = tile * 3 local deckHalfX, deckHalfZ = 14 * cell, 10 * cell local ringX, ringZ = 13 * cell, 8.5 * cell local roofHalfX = 4 * cell local slab = cell -- The 6:8:10 rise, run and slope keep the incline on whole tiles as well. local rampRun = 8 * cell local function grid(value: number): number return math.round(value / cell) * cell end type Route = {name: string, points: {Vector3}, flat: boolean} type Footprint = {point: Vector3, halfWidth: number, halfLength: number} type Cover = {asset: string, x: number, z: number, turn: number} type Plan = {keep: number, tunnels: number, ramps: number, hand: number, crossing: number} type Layout = { model: Model, markers: Folder, routes: {Route}, bounds: {Footprint}, positions: {[string]: {Vector3}}, covers: number, ramps: number, variant: string, plan: Plan, runes: Folder, boostSurfaces: {[Model]: MeshPart}, } type BoostArt = {model: Model, width: number, length: number} local boostArt: {BoostArt} = {} local jumpArt: Model? = nil local archivedRunes = ServerStorage:WaitForChild("HunterMonolithImport"):WaitForChild("ArenaRunes") for _, rune in archivedRunes:GetChildren() do if not rune:IsA("Model") or not rune.PrimaryPart then continue end local kind = rune:GetAttribute("Kind") if kind == "Jump" then if not jumpArt or rune.Name < jumpArt.Name then jumpArt = rune end elseif kind == "Boost" then local width, length = rune:GetAttribute("HalfWidth"), rune:GetAttribute("HalfLength") if typeof(width) == "number" and width > 0 and typeof(length) == "number" and length > 0 then table.insert(boostArt, {model = rune, width = width, length = length}) end end end assert(jumpArt and #boostArt > 0, "Arena mobility templates are missing") table.sort(boostArt, function(a, b) return a.model.Name < b.model.Name end) local keeps = { {name = Text.bastiony, roofHalfZ = 23, wingX = 12, width = 32, depth = 18, balconyX = -12}, {name = Text.galerei, roofHalfZ = 20, wingX = 0, width = 46, depth = 25, balconyX = 0}, {name = Text.terrasy, roofHalfZ = 27, wingX = -14, width = 24, depth = 13, balconyX = 17}, } local tunnels = { {name = Text.parnyeTonneli, openings = {{x = -37, width = 21}, {x = 37, width = 21}}}, {name = Text.tonnelSoSmescheniem, openings = {{x = -25, width = 27}}}, {name = Text.triProkhoda, openings = {{x = -49, width = 17}, {x = 0, width = 21}, {x = 49, width = 17}}}, } local rampPlans = {Text.bokovyePodYomy, Text.tortsevyePodYomy, Text.uglovyePodYomy} local recentProfiles: {string} = {} local function profileKey(plan: Plan): string return plan.keep .. "/" .. plan.tunnels .. "/" .. plan.ramps end local function selectPlan(rng: Random): Plan return { keep = rng:NextInteger(1, #keeps), tunnels = rng:NextInteger(1, #tunnels), ramps = rng:NextInteger(1, #rampPlans), hand = if rng:NextInteger(0, 1) == 0 then -1 else 1, crossing = rng:NextInteger(23, 24) * cell, } end local function template(asset: string): BasePart local part = kit:FindFirstChild(asset) assert(part and part:IsA("BasePart"), "Missing arena module " .. asset) return part end local function localPoint(x: number, z: number, y: number?): Vector3 return Vector3.new(x, y or 0, z) end local function folder(parent: Instance, name: string): Folder local group = Instance.new("Folder") group.Name = name group.Parent = parent return group end local function extent(position: Vector3, orientation: CFrame, size: Vector3): Footprint local r, b = orientation.RightVector, -orientation.LookVector return { point = position, halfWidth = (math.abs(r.X) * size.X + math.abs(b.X) * size.Z) / 2, halfLength = (math.abs(r.Z) * size.X + math.abs(b.Z) * size.Z) / 2, } end local function fittedVolume(point: Vector3, rotation: CFrame, size: Vector3): (Vector3, Vector3) local rotated = math.abs(rotation.RightVector.Z) > .5 local width, depth = if rotated then size.Z else size.X, if rotated then size.X else size.Z local left, right = grid(point.X - width / 2), grid(point.X + width / 2) local front, back = grid(point.Z - depth / 2), grid(point.Z + depth / 2) if right == left then left, right = grid(point.X - cell / 2), grid(point.X - cell / 2) + cell end if back == front then front, back = grid(point.Z - cell / 2), grid(point.Z - cell / 2) + cell end local bottom = grid(point.Y) local height = math.max(cell, grid(point.Y + size.Y) - bottom) width, depth = right - left, back - front return Vector3.new((left + right) / 2, bottom, (front + back) / 2), Vector3.new(if rotated then depth else width, height, if rotated then width else depth) end local function install(layout: Layout, parent: Instance, asset: string, point: Vector3, rotation: CFrame, dimensions: Vector3?, reserve: boolean?): BasePart local part = template(asset):Clone() local fitted, size = fittedVolume(point, rotation, dimensions or part.Size) part.Size = size part.CFrame = CFrame.new(origin + fitted + Vector3.yAxis * (size.Y / 2)) * rotation part.Parent = parent if reserve then table.insert(layout.bounds, extent(fitted, rotation, size)) end return part end local function transformRoute(points: {Vector3}, rotation: CFrame, reversed: boolean): {Vector3} local result: {Vector3} = {} for i = 1, #points do local point = points[if reversed then #points + 1 - i else i] table.insert(result, rotation * point) end return result end local flip = CFrame.Angles(0, math.pi, 0) local ninety = CFrame.Angles(0, math.pi / 2, 0) local function path(layout: Layout, name: string, points: {Vector3}, flat: boolean) table.insert(layout.routes, {name = name, points = points, flat = flat}) end local function accent(parent: Instance, name: string, size: Vector3, pose: CFrame, tint: Color3): Part local part = Instance.new("Part") part.Name, part.Size, part.CFrame = name, size, pose part.Color, part.Material = tint, Enum.Material.Neon part.Anchored, part.CanCollide, part.CanQuery, part.CanTouch, part.CastShadow = true, false, false, false, false part.Parent = parent return part end local function routeMarks(parent: Instance, start: Vector3, nextPoint: Vector3, tint: Color3) local dir = (nextPoint - start).Unit local right = dir:Cross(Vector3.yAxis) for i = 0, 1 do local center = origin + start + dir * (i * 4) + Vector3.yAxis * .11 local point = center + dir * 1.35 for _, side in {-1, 1} do local tail = center - dir + right * (side * 2.5) local glow = accent(parent, "RouteChevron", Vector3.new(.3, .11, (point - tail).Magnitude), CFrame.lookAt((point + tail) / 2, point), tint) glow.Transparency = .2 + i * .08 end end end local function base(layout: Layout, parent: Folder, side: string, rotation: CFrame) local blue = side == "Blue" local color = if blue then Color3.fromRGB(68, 210, 255) else Color3.fromRGB(255, 147, 66) local group = folder(parent, if blue then "BlueBase" else "OrangeBase") local function place(asset: string, x: number, z: number, size: Vector3) return install(layout, group, asset, rotation * localPoint(x, z), rotation, size, true) end for _, x in {-41, 41} do place("Wall", x, -207, Vector3.new(5, 18, 44)) end place("Wall", 0, -229, Vector3.new(85, 18, 4)) local cap = install(layout, group, "Foundation", rotation * localPoint(0, -216, 18), rotation, Vector3.new(86, cell, 23), true) accent(group, "BaseCanopyEdge", Vector3.new(cap.Size.X - cell, .62, .48), cap.CFrame * CFrame.new(0, 0, cap.Size.Z / 2 + .25), color) for _, x in {-14.5, 14.5} do local screen = place("Screen", x, -187, Vector3.new(16, 16, 6)) local plaque = accent(group, "BaseColor", Vector3.new(9, 1.2, 1), screen.CFrame * CFrame.new(0, screen.Size.Y * .3, -screen.Size.Z / 2 - .45), color) local lamp = Instance.new("PointLight") lamp.Color, lamp.Range, lamp.Brightness = color, 23, 1.15 lamp.Parent = plaque end local shield = place("Wall", 0, -166, Vector3.new(24, 17, 7)) local nameplate = accent(group, "BaseBeacon", Vector3.new(16, 1, 2), shield.CFrame * CFrame.new(0, shield.Size.Y / 2 + .55, 0), color) local sign = Instance.new("BillboardGui") sign.Name = "BaseName" sign.Size = UDim2.fromOffset(175, 32) sign.StudsOffsetWorldSpace = Vector3.yAxis * 2 sign.MaxDistance = 115 sign.LightInfluence = 0 sign.Parent = nameplate local text = Instance.new("TextLabel") text.Size, text.BackgroundTransparency = UDim2.fromScale(1, 1), 1 text.Font, text.TextSize = Enum.Font.GothamBlack, 19 text.TextColor3, text.TextStrokeTransparency = color, .2 text.Text = if blue then Text.bazaSinikh else Text.bazaOranzhevykh text.Parent = sign local points: {Vector3} = {} layout.positions[side] = points for row = 1, 2 do for i = 1, 5 do local point = rotation * localPoint((i - 3) * 12, -211 - (row - 1) * 10) local spawn = Instance.new("SpawnLocation") spawn.Name = side .. "_" .. tostring(#points + 1) spawn.Size = Vector3.new(2, 1, 2) spawn.CFrame = CFrame.lookAt(origin + point + Vector3.yAxis * .35, origin + point + Vector3.yAxis * .35 + rotation * Vector3.zAxis) spawn.Transparency, spawn.Duration = 1, 0 spawn.CanCollide, spawn.CanTouch, spawn.CanQuery, spawn.Anchored = false, false, false, true spawn.Neutral = false spawn.TeamColor = BrickColor.new(if blue then "Cyan" else "Deep orange") spawn:SetAttribute("ArenaTeam", side) spawn.Parent = layout.markers table.insert(points, point) path(layout, spawn.Name .. "_exit", {point, rotation * localPoint(0, -211)}, true) end end end local function placeRune(layout: Layout, rune: Model, name: string, frame: CFrame) rune.Name = name rune:SetAttribute("PulseAt", nil) rune:SetAttribute("Phase", (#layout.runes:GetChildren() + 1) * 1.17) rune:PivotTo(frame) rune.Parent = layout.runes end local function boostRune(layout: Layout, wedge: MeshPart, toe: Vector3, top: Vector3) local forward = (top - toe).Unit local normal = forward:Cross(wedge.CFrame.LookVector).Unit local position = origin + toe:Lerp(top, .33) local goalWidth = wedge.Size.Z * .41 local goalLength = math.min(14, (top - toe).Magnitude * .23) local art, bestScale, bestCoverage = boostArt[1], 1, 0 for _, candidate in boostArt do local scale = math.min(goalWidth / candidate.width, goalLength / candidate.length) local coverage = candidate.width * candidate.length * scale * scale if coverage > bestCoverage then art, bestScale, bestCoverage = candidate, scale, coverage end end local rune = art.model:Clone() rune:ScaleTo(art.model:GetScale() * bestScale) rune:SetAttribute("HalfWidth", art.width * bestScale) rune:SetAttribute("HalfLength", art.length * bestScale) placeRune(layout, rune, "Boost " .. layout.ramps, CFrame.lookAt(position, position + forward, normal)) layout.boostSurfaces[rune] = wedge end local function jumpRune(layout: Layout, name: string, point: Vector3, forward: Vector3) local template = jumpArt assert(template, "Jump rune template is missing") local position = origin + point placeRune(layout, template:Clone(), "Jump " .. name, CFrame.lookAt(position, position + forward)) end local function ramp(layout: Layout, parent: Folder, asset: string, landing: Vector3, uphill: Vector3, width: number): (Vector3, Vector3) local orientation = CFrame.fromMatrix(Vector3.zero, uphill, Vector3.yAxis, uphill:Cross(Vector3.yAxis)) local wedge = install(layout, parent, asset, landing - uphill * (rampRun / 2), orientation, Vector3.new(rampRun, middle, width), true) assert(wedge:IsA("MeshPart"), "Ramp template must be a slope mesh") local center = wedge.Position - origin local toe = center - uphill * (wedge.Size.X / 2) - Vector3.yAxis * (wedge.Size.Y / 2) local top = center + uphill * (wedge.Size.X / 2) + Vector3.yAxis * (wedge.Size.Y / 2) layout.ramps += 1 boostRune(layout, wedge, toe, top) -- Check both seams as part of the incline, including the approach and landing. path(layout, "Incline " .. layout.ramps, {toe - uphill * 2, toe, top}, false) return toe, top end local function installAssembly(layout: Layout, parent: Instance, key: string, point: Vector3, rotate: CFrame): Model local source = kit:FindFirstChild(key) assert(source and source:IsA("Model"), "Missing structure " .. key) local clone = source:Clone() clone:PivotTo(CFrame.new(origin + point) * rotate) clone.Parent = parent for _, item in clone:GetChildren() do if item:IsA("BasePart") then table.insert(layout.bounds, extent(item.Position - origin, item.CFrame, item.Size)) end end return clone end local function light(parent: Instance, point: Vector3, tint: Color3) local strip = accent(parent, "RecessedLight", Vector3.new(5.8, .28, 1.6), CFrame.new(origin + point), tint) local lamp = Instance.new("PointLight") lamp.Color, lamp.Range, lamp.Brightness = tint, 19, 1.5 lamp.Parent = strip end local amber = Color3.fromRGB(255, 198, 102) local cyan = Color3.fromRGB(107, 236, 255) local violet = Color3.fromRGB(202, 125, 255) local function block(layout: Layout, parent: Instance, asset: string, x: number, z: number, bottom: number, size: Vector3) return install(layout, parent, asset, localPoint(x, z, bottom), CFrame.identity, size, true) end local function deck(layout: Layout, parent: Instance, x: number, z: number, height: number, width: number, depth: number) local panel = block(layout, parent, "DeckPanel", x, z, height - slab, Vector3.new(width, slab, depth)) panel.CanCollide = false -- The overlapping collision margins keep touching deck sections continuously walkable. local surface = Instance.new("Part") surface.Name = "DeckCollision" surface.Size = panel.Size + Vector3.new(.02, 0, .02) surface.CFrame = panel.CFrame surface.Anchored, surface.CanTouch, surface.Transparency, surface.CastShadow = true, false, 1, false surface.Parent = parent end local function tunnelLevel(layout: Layout, parent: Folder) local plan = layout.plan local specification = tunnels[plan.tunnels] for _, side in {-1, 1} do local z = side * 30 local multiplier = -side * plan.hand local left = -deckHalfX local tint = if side < 0 then cyan else violet for i = 1, #specification.openings do local opening = specification.openings[if multiplier == 1 then i else #specification.openings + 1 - i] local x = opening.x * multiplier local start, finish = x - opening.width / 2, x + opening.width / 2 block(layout, parent, "Wall", (left + start) / 2, z, 0, Vector3.new(start - left, middle - slab, 9)) left = finish light(parent, localPoint(x, z, middle - slab - .85), tint) path(layout, "Tunnel mouth " .. side .. "/" .. i, {localPoint(0, side * plan.crossing), localPoint(0, side * 47), localPoint(x, side * 47), localPoint(x, 0)}, true) end block(layout, parent, "Wall", (left + deckHalfX) / 2, z, 0, Vector3.new(deckHalfX - left, middle - slab, 9)) for _, edge in {-1, 1} do -- End the side piers on the faces of the portal wall, keeping their outer faces continuous. local outerX = edge * (deckHalfX - cell) local first, frontFace, backFace = grid(19), grid(30 - 4.5), grid(30 + 4.5) for _, span in {{first, frontFace}, {backFace, deckHalfZ}} do block(layout, parent, "Wall", outerX, side * (span[1] + span[2]) / 2, 0, Vector3.new(2 * cell, middle - slab, span[2] - span[1])) end end end end local function citadel(layout: Layout, parent: Folder, rng: Random) local plan = layout.plan local shape = keeps[plan.keep] local structure = folder(parent, "Citadel") local passages = folder(structure, "Tunnels") local gallery = folder(structure, "MiddleGallery") local summit = folder(structure, "Roof") local inclines = folder(structure, "Ramps") local roof = middle * 2 local roofHalfZ = grid(shape.roofHalfZ) local wingDepth = grid(shape.depth) deck(layout, gallery, 0, 0, middle, 2 * deckHalfX, 2 * deckHalfZ) deck(layout, summit, 0, 0, roof, 2 * roofHalfX, 2 * roofHalfZ) tunnelLevel(layout, passages) for _, endSide in {-1, 1} do local balconyX = grid(endSide * plan.hand * shape.balconyX) local balconyWidth = if plan.keep == 2 then 39 else 32 local balconyDepth = (if plan.keep == 2 then 4 else 3) * cell local balconyZ = endSide * (deckHalfZ + balconyDepth / 2) local launchZ = endSide * (deckHalfZ + balconyDepth + 3 * cell) jumpRune(layout, "Citadel " .. endSide, localPoint(balconyX, launchZ), -Vector3.zAxis * endSide) path(layout, "Citadel jump approach " .. endSide, {localPoint(0, launchZ), localPoint(balconyX, launchZ)}, true) deck(layout, gallery, balconyX, balconyZ, middle, balconyWidth, balconyDepth) block(layout, gallery, "Parapet", balconyX, endSide * (deckHalfZ + balconyDepth - 1.5), middle, Vector3.new(balconyWidth - 3, 4, 3)) for _, offset in {-1, 1} do local columnX = balconyX + offset * (balconyWidth / 2 - 4) if math.abs(columnX) >= 13 then block(layout, passages, "Wall", columnX, balconyZ, 0, Vector3.new(7, middle - slab, 8)) end end path(layout, "Gallery balcony " .. endSide, {localPoint(-ringX, ringZ * endSide, middle), localPoint(balconyX, ringZ * endSide, middle), localPoint(balconyX, balconyZ, middle)}, true) local wingX = endSide * plan.hand * shape.wingX local wingZ = endSide * (roofHalfZ + wingDepth / 2) local wingWalkZ = endSide * (roofHalfZ + math.min(wingDepth / 2, wingDepth - cell - 2.2)) deck(layout, summit, wingX, wingZ, roof, shape.width, wingDepth) block(layout, summit, "Parapet", wingX, endSide * (roofHalfZ + wingDepth - 1.5), roof, Vector3.new(shape.width - 2, 4, 3)) for _, offset in {-1, 1} do block(layout, gallery, "Wall", offset * 3 * cell, endSide * (roofHalfZ - cell), middle, Vector3.new(2 * cell, middle - slab, 2 * cell)) block(layout, gallery, "Wall", wingX + offset * (shape.width / 2 - 4), wingZ, middle, Vector3.new(7, middle - slab, 7)) end path(layout, "Roof wing " .. endSide, {localPoint(0, 0, roof), localPoint(wingX, endSide * (roofHalfZ - 3), roof), localPoint(wingX, wingWalkZ, roof)}, true) path(layout, "Gallery crosswalk " .. endSide, {localPoint(-ringX, endSide * ringZ, middle), localPoint(ringX, endSide * ringZ, middle)}, true) end local sideZ = rng:NextInteger(6, 7) * cell local endX = rng:NextInteger(9, 10) * cell local upperZ = (if plan.ramps == 1 then 2 elseif plan.ramps == 2 then 3 else 0) * cell for _, side in {-1, 1} do local edgeX = side * ringX if plan.keep == 2 then local wingX = side * (deckHalfX + 13) deck(layout, gallery, wingX, 0, middle, 26, 32) for _, z in {-11, 11} do block(layout, passages, "Wall", wingX, z, 0, Vector3.new(9, middle - slab, 8)) end block(layout, gallery, "Parapet", side * (deckHalfX + 24), 0, middle, Vector3.new(4, 4, 29)) path(layout, "Side gallery " .. side, {localPoint(edgeX, 0, middle), localPoint(wingX, 0, middle)}, true) end for _, endSide in {-1, 1} do local fromSide = plan.ramps == 1 or (plan.ramps == 3 and side * endSide == plan.hand) local axis = if fromSide then Vector3.xAxis * side else Vector3.zAxis * endSide local landing = if fromSide then localPoint(side * deckHalfX, endSide * sideZ) else localPoint(side * endX, endSide * deckHalfZ) local toe, top = ramp(layout, inclines, "CitadelRamp", landing, -axis, 4 * cell) local entry = toe + axis * 2 local junction = if fromSide then localPoint(side * flankX, toe.Z) else localPoint(toe.X, endSide * plan.crossing) local ring = localPoint(edgeX, endSide * ringZ, middle) local turn = if fromSide then localPoint(edgeX, top.Z, middle) else localPoint(top.X, ring.Z, middle) path(layout, "Lower ramp approach " .. side .. "/" .. endSide, {junction, entry}, true) path(layout, "Lower ramp landing " .. side .. "/" .. endSide, {top, turn, ring}, true) end local outward = side * Vector3.xAxis local z = side * plan.hand * upperZ local topDock = localPoint(side * roofHalfX, z, middle) local toe, top = ramp(layout, inclines, "CitadelRamp", topDock, -outward, 2 * cell) local entry = toe + outward * 2 local across = localPoint(edgeX, 0, middle) path(layout, "Gallery side " .. side, {localPoint(edgeX, -ringZ, middle), across, localPoint(edgeX, ringZ, middle)}, true) path(layout, "Roof ramp approach " .. side, {across, localPoint(edgeX, z, middle), entry}, true) path(layout, "Roof ramp landing " .. side, {top, localPoint(0, z, roof), localPoint(0, 0, roof)}, true) end end local function sectorGate(layout: Layout, parent: Folder, point: Vector3, out: number, offset: number) local group = folder(parent, "FlankGate") installAssembly(layout, group, "Gate", point, CFrame.identity) local roof, halfDepth = tile * 3, tile * 2 local capX = point.X + out * offset local toward = Vector3.zAxis * math.sign(point.Z) jumpRune(layout, (if out < 0 then "West" else "East") .. " flank " .. math.sign(point.Z), point - toward * (halfDepth + 3 * cell), toward) local tops: {Vector3} = {} local tint = if point.Z < 0 then Color3.fromRGB(73, 220, 255) else Color3.fromRGB(255, 157, 84) for _, endSide in {-1, 1} do local dock = localPoint(capX, point.Z + endSide * halfDepth) local toe, top = ramp(layout, group, "Ramp", dock, -Vector3.zAxis * endSide, 4 * cell) table.insert(tops, top) local entry = toe + Vector3.zAxis * (endSide * 2) local staging = toe + Vector3.zAxis * (endSide * 6) local flank = localPoint(point.X, staging.Z) path(layout, "Flank gate approach", {localPoint(point.X, point.Z), flank, staging, entry}, true) end local middle = point + Vector3.yAxis * roof path(layout, "Flank gate roof", {tops[1], middle, tops[2]}, true) install(layout, group, "LowCover", middle - Vector3.xAxis * (out * 24), ninety, Vector3.new(15, 8, 9), false) install(layout, group, "Parapet", middle + Vector3.xAxis * (out * 38), ninety, Vector3.new(35, 4, 4), false) light(group, point + localPoint(-5, -11, tile * 1.45), tint) light(group, point + localPoint(5, 11, tile * 1.45), tint) end local function overlaps(a: Footprint, b: Footprint, padding: number): boolean return math.abs(a.point.X - b.point.X) < a.halfWidth + b.halfWidth + padding and math.abs(a.point.Z - b.point.Z) < a.halfLength + b.halfLength + padding end local function reservePaths(layout: Layout): {Vector3} local reserved: {Vector3} = {} for _, route in layout.routes do for i = 2, #route.points do local from, to = route.points[i - 1], route.points[i] if from.Y > .1 or to.Y > .1 then continue end local count = math.max(1, math.ceil((to - from).Magnitude / 3)) for j = 0, count do table.insert(reserved, from:Lerp(to, j / count)) end end end return reserved end local bays: {{Cover}} = { {{asset = "SquareCover", x = -8, z = -9, turn = 0}, {asset = "LowCover", x = 11, z = 12, turn = 1}}, {{asset = "TallCover", x = 7, z = -9, turn = 0}, {asset = "Crate", x = -9, z = 11, turn = 0}}, {{asset = "LowCover", x = -10, z = -9, turn = 0}, {asset = "Screen", x = 9, z = 12, turn = 1}}, } local function furnish(layout: Layout, parent: Folder, rng: Random) local reserved = reservePaths(layout) local function fitsCover(shape: Footprint): boolean local position = shape.point if math.abs(position.X) + shape.halfWidth > halfX - 8 or math.abs(position.Z) + shape.halfLength > halfZ - 8 then return false end for _, bounds in layout.bounds do if overlaps(shape, bounds, 2) then return false end end for _, safe in reserved do if math.abs(position.X - safe.X) <= shape.halfWidth + clearance and math.abs(position.Z - safe.Z) <= shape.halfLength + clearance then return false end end return true end for _, row in {-39, -69, -94, -127, -159, -190, -217} do for _, laneBay in {-206, -141, -76, -45, 45, 76, 141, 206} do local x = laneBay + rng:NextInteger(-5, 5) local z = row + rng:NextInteger(-8, 8) local start = rng:NextInteger(1, #bays) for attempt = 0, #bays - 1 do local pattern = bays[(start + attempt - 1) % #bays + 1] local staged: {{asset: string, point: Vector3, rotation: CFrame, footprint: Footprint}} = {} local fits = true for _, item in pattern do for _, mirror in {-1, 1} do local point = localPoint((x + item.x) * mirror, (z + item.z) * mirror) local angle = if item.turn == 1 then ninety else CFrame.identity local rotation = if mirror == -1 then flip * angle else angle local fitted, size = fittedVolume(point, rotation, template(item.asset).Size) local shape = extent(fitted, rotation, size) if not fitsCover(shape) then fits = false break end for _, other in staged do if overlaps(shape, other.footprint, 2) then fits = false break end end if not fits then break end table.insert(staged, {asset = item.asset, point = point, rotation = rotation, footprint = shape}) end if not fits then break end end if fits then local group = folder(parent, "CoverGroup" .. tostring(layout.covers // 4 + 1)) for _, item in staged do install(layout, group, item.asset, item.point, item.rotation, nil, true) layout.covers += 1 end break end end end end -- Tight bays may stop fitting after snapping. Fill remaining side pockets with smaller pairs. for _, z in {-23, -54, -85, -111, -145, -174, -202, -235} do for _, x in {-204, -142, -102, -62, 62, 102, 142, 204} do if layout.covers >= 24 then return end local point = localPoint(x + rng:NextInteger(-4, 4), z + rng:NextInteger(-4, 4)) local asset = if rng:NextNumber() < .5 then "Crate" else "TallCover" local size = template(asset).Size local first, firstSize = fittedVolume(point, CFrame.identity, size) local second, secondSize = fittedVolume(-point, flip, size) if not fitsCover(extent(first, CFrame.identity, firstSize)) or not fitsCover(extent(second, flip, secondSize)) then continue end install(layout, parent, asset, point, CFrame.identity, nil, true) install(layout, parent, asset, -point, flip, nil, true) layout.covers += 2 end end end local function build(seed: number): Layout local rng = Random.new(seed) local plan = selectPlan(rng) local model = Instance.new("Model") model.Name = "GeneratedLayout" local markers = Instance.new("Folder") markers.Name = "NextSpawns" local layout: Layout = { model = model, markers = markers, routes = {}, bounds = {}, positions = {}, covers = 0, ramps = 0, runes = folder(model, "ArenaRunes"), boostSurfaces = {}, variant = keeps[plan.keep].name .. " / " .. tunnels[plan.tunnels].name .. " / " .. rampPlans[plan.ramps], plan = plan, } local foundation = folder(model, "Terrain") install(layout, foundation, "Foundation", localPoint(0, 0, -cell), CFrame.identity, Vector3.new(halfX * 2, cell, halfZ * 2), false) for _, side in {-1, 1} do install(layout, foundation, "Boundary", localPoint(0, side * (halfZ - cell / 2)), CFrame.identity, Vector3.new(halfX * 2, 10 * cell, cell), false) install(layout, foundation, "Boundary", localPoint(side * (halfX - cell / 2), 0), ninety, Vector3.new(2 * (halfZ - cell), 10 * cell, cell), false) end local bases = folder(model, "Bases") base(layout, bases, "Blue", CFrame.identity) base(layout, bases, "Orange", flip) local bend = if rng:NextNumber() < .5 then 22 else -22 local center = {localPoint(0, -211), localPoint(0, -183), localPoint(bend, -176), localPoint(bend, -149), localPoint(0, -plan.crossing)} local signs = folder(model, "RouteSigns") path(layout, "Centre", center, true) path(layout, "Centre mirrored", transformRoute(center, flip, true), true) routeMarks(signs, center[4], center[5], cyan) routeMarks(signs, flip * center[4], flip * center[5], cyan) for _, side in {-1, 1} do local flank = {localPoint(0, -211), localPoint(32 * side, -207), localPoint(32 * side, -175), localPoint(89 * side, -191), localPoint(flankX * side, -188), localPoint(flankX * side, 0)} path(layout, "Flank " .. side, flank, true) path(layout, "Flank mirrored " .. side, transformRoute(flank, flip, true), true) routeMarks(signs, flank[5], flank[6], amber) routeMarks(signs, flip * flank[5], flip * flank[6], amber) end for _, z in {-plan.crossing, 0, plan.crossing} do path(layout, "Crosslink " .. z, {localPoint(-flankX, z), localPoint(flankX, z)}, true) end local raised = folder(model, "ElevatedRoutes") citadel(layout, raised, rng) for _, side in {-1, 1} do local gate = localPoint(flankX * side, -rng:NextInteger(29, 30) * cell) local offset = rng:NextInteger(4, 5) * cell sectorGate(layout, raised, gate, side, offset) sectorGate(layout, raised, -gate, -side, offset) end local screens = folder(model, "LaneDividers") for _, side in {-1, 1} do local point = localPoint(112 * side, -rng:NextInteger(79, 96)) local size = Vector3.new(13, 23, rng:NextInteger(20, 30)) install(layout, screens, "Wall", point, CFrame.identity, size, true) install(layout, screens, "Wall", flip * point, flip, size, true) end furnish(layout, folder(model, "Cover"), rng) return layout end local function validate(layout: Layout) assert(layout.covers >= 16 and layout.ramps == 14, "Incomplete cover or upper routes") for _, part in layout.model:GetDescendants() do if not part:IsA("BasePart") or not part.MaterialVariant:match("^HunterArenaGrid") then continue end assert(part:IsA("Part") or part.Name == "Ramp" or part.Name == "CitadelRamp", "Box uses mesh projection: " .. part.Name) local size = part.Size local bbox = extent(part.Position - origin, part.CFrame, size) for _, edge in {bbox.point.X - bbox.halfWidth, bbox.point.X + bbox.halfWidth, bbox.point.Y - size.Y / 2, bbox.point.Y + size.Y / 2, bbox.point.Z - bbox.halfLength, bbox.point.Z + bbox.halfLength} do assert(math.abs(edge - grid(edge)) < .012, "Off-grid volume: " .. part.Name) end end local geometry = RaycastParams.new() geometry.FilterType = Enum.RaycastFilterType.Include geometry.FilterDescendantsInstances = {layout.model} geometry.RespectCanCollide = true local boostCount, jumpCount = 0, 0 for _, rune in layout.runes:GetChildren() do assert(rune:IsA("Model") and rune.PrimaryPart, "Missing rune origin") local pose = rune.PrimaryPart.CFrame local support = layout.boostSurfaces[rune] if support then boostCount += 1 assert(support.MaterialVariant == template("CitadelRamp").MaterialVariant and math.abs(Vector2.new(support.Size.X, support.Size.Y).Magnitude - 10 * cell) < .01, "Ramp must be amber and span ten cells along the slope") local width = rune:GetAttribute("HalfWidth") :: number local length = rune:GetAttribute("HalfLength") :: number for _, x in {-width, 0, width} do for _, z in {-length, 0, length} do local point = pose:PointToWorldSpace(Vector3.new(x, 0, z)) local hit = workspace:Raycast(point + Vector3.yAxis, -Vector3.yAxis * 2, geometry) assert(hit and hit.Instance == support and (hit.Position - point).Magnitude < .12, "Booster does not fit its slope: " .. rune.Name) end end else jumpCount += 1 for _, side in {Vector3.zero, Vector3.xAxis, -Vector3.xAxis, Vector3.zAxis, -Vector3.zAxis} do local point = pose.Position + side * (Mobility.JumpRadius + .2) local hit = workspace:Raycast(point + Vector3.yAxis, -Vector3.yAxis * 2, geometry) assert(hit and hit.Normal.Y > .97 and math.abs(hit.Position.Y - point.Y) < .12, "Jump rune needs a flat floor: " .. rune.Name) assert(not workspace:Raycast(point + Vector3.yAxis * .2, Vector3.yAxis * Mobility.JumpRise, geometry), "Jump rune needs open sky: " .. rune.Name) end local target = pose.Position + pose.LookVector * 30 local landing = workspace:Raycast(target + Vector3.yAxis * Mobility.JumpRise, -Vector3.yAxis * Mobility.JumpRise, geometry) assert(landing and landing.Normal.Y > .97 and math.abs(landing.Position.Y - target.Y - middle) < .2, "Jump rune needs a nearby high landing: " .. rune.Name) end end assert(boostCount == layout.ramps and jumpCount == 6, "Incomplete mobility runes") local avatar = Vector3.new(3.2, 4.5, 3.2) for _, route in layout.routes do for i = 2, #route.points do local from, to = origin + route.points[i - 1], origin + route.points[i] local steps = math.max(1, math.ceil((to - from).Magnitude / 2)) for step = 0, steps do local point = from:Lerp(to, step / steps) local floorHit = workspace:Raycast(point + Vector3.yAxis * .65, -Vector3.yAxis * 1.7, geometry) assert(floorHit and math.abs(floorHit.Position.Y - point.Y) < .35, ("Floor gap on %s near %s"):format(route.name, tostring(point - origin))) assert(not workspace:Raycast(point + Vector3.yAxis * .48, Vector3.yAxis * 5.0, geometry), ("Headroom on %s near %s"):format(route.name, tostring(point - origin))) end if route.flat and (to - from).Magnitude > .1 then local hit = workspace:Blockcast(CFrame.new(from + Vector3.yAxis * 2.87), avatar, to - from, geometry) assert(not hit, ("Blocked route %s by %s"):format(route.name, if hit then hit.Instance:GetFullName() else "")) end end end local blue, orange = layout.positions.Blue, layout.positions.Orange assert(#blue == 10 and #orange == 10, "Expected ten markers per team") for _, start in blue do for _, finish in orange do local aim = origin + start + Vector3.yAxis * 4.2 local delta = finish - start assert(workspace:Raycast(aim, delta, geometry), "Exposed sightline between the bases") end end end local ProceduralArena = {} function ProceduralArena.regenerate(requestedSeed: number?): number local previous = arena:FindFirstChild("GeneratedLayout") local previousSeed = arena:GetAttribute("Seed") local previousKeep = arena:GetAttribute("CitadelProfile") local previousTunnels = arena:GetAttribute("TunnelProfile") local previousRamps = arena:GetAttribute("RampProfile") local function freshSeed(): number while true do local seed = random:NextInteger(1, 2147483646) local plan = selectPlan(Random.new(seed)) if seed ~= previousSeed and plan.keep ~= previousKeep and plan.tunnels ~= previousTunnels and plan.ramps ~= previousRamps and not table.find(recentProfiles, profileKey(plan)) then return seed end end end local seed = requestedSeed or freshSeed() local lastFailure = "" for attempt = 1, if requestedSeed then 1 else 8 do local layout = build(seed) layout.model.Parent = arena local valid, failure = pcall(validate, layout) if valid then if previous then previous:Destroy() end for _, rune in layout.runes:GetChildren() do rune:AddTag(Mobility.ProceduralRuneTag) end spawns:ClearAllChildren() for _, marker in layout.markers:GetChildren() do marker.Parent = spawns end layout.markers:Destroy() arena:SetAttribute("Seed", seed) arena:SetAttribute("LayoutVariant", layout.variant) arena:SetAttribute("CitadelProfile", layout.plan.keep) arena:SetAttribute("TunnelProfile", layout.plan.tunnels) arena:SetAttribute("RampProfile", layout.plan.ramps) if not requestedSeed then table.insert(recentProfiles, profileKey(layout.plan)) if #recentProfiles > 5 then table.remove(recentProfiles, 1) end end arena:SetAttribute("CoverCount", layout.covers) arena:SetAttribute("RampCount", layout.ramps) arena:SetAttribute("Levels", 3) arena:SetAttribute("Generation", ((arena:GetAttribute("Generation") :: number?) or 0) + 1) arena:SetAttribute("CheckedRoutes", #layout.routes) return seed end lastFailure = tostring(failure) layout.model:Destroy() layout.markers:Destroy() if attempt < 8 and not requestedSeed then seed = freshSeed() end end error(lastFailure) end return ProceduralArena