Files
Fishing/tools/widen-garden.lua
T

261 lines
8.1 KiB
Lua

-- Расчистка места под большой сад за Гильдией: скалы, лес и край лобби на севере уходят назад.
-- Запуск в Edit, потом сад: tools/build-guild-garden.js. Откат: поставить UNDO = true
-- (у каждого сдвинутого объекта в атрибуте GardenWideOrig лежит прежнее место, рельеф — в ServerStorage.Backup).
-- Новый край: прямая z = −138 при |x| ≤ 58, дальше диагонали к старому кольцу у (±92, −52).
local UNDO = false
local map = workspace.FishingMap
local V = Vector3.new
local TAG = "GardenWideOrig"
local backup = game.ServerStorage.Backup
local function pivotOf(o)
return o:IsA("Model") and o:GetPivot() or o.CFrame
end
local function setPivot(o, cf)
if o:IsA("Model") then
o:PivotTo(cf)
else
o.CFrame = cf
end
end
if UNDO then
assert(map:GetAttribute("GardenWide"), "Расчистки не было")
for _, root in ipairs({ map, workspace }) do
for _, d in ipairs(root:GetDescendants()) do
if d:GetAttribute("GardenWideClone") then
d:Destroy()
elseif d:GetAttribute(TAG) then
setPivot(d, d:GetAttribute(TAG))
d:SetAttribute(TAG, nil)
end
end
end
local walls = backup:FindFirstChild("GardenWideWalls")
for _, w in ipairs(walls and walls:GetChildren() or {}) do
w.Parent = map
end
if walls then
walls:Destroy()
end
local tr = backup:FindFirstChild("GardenWideTerrain")
if tr then
workspace.Terrain:PasteRegion(tr, Vector3int16.new(-28, -2, -42), true)
tr:Destroy()
end
map:SetAttribute("GardenWide", nil)
return "откат готов"
end
if map:GetAttribute("GardenWide") then
return "уже расчищено"
end
local R0, TOP, XF, XE, ZE = 106, -138, 58, 92, -52
local function target(ax)
if ax <= XF then
return TOP
end
return TOP + (ZE - TOP) * math.min(1, (ax - XF) / (XE - XF))
end
local function dzAt(x)
local ax = math.abs(x)
if ax >= XE then
return 0
end
local zc = -math.sqrt(R0 * R0 - ax * ax)
return math.min(0, target(ax) - zc)
end
local moved = 0
local function push(o, dz)
if dz > -0.01 then
return
end
if o:GetAttribute(TAG) == nil then
o:SetAttribute(TAG, pivotOf(o))
end
setPivot(o, pivotOf(o) + V(0, 0, dz))
moved += 1
end
local function eachLeaf(folder, fn)
for _, c in ipairs(folder:GetChildren()) do
if c:IsA("Folder") then
eachLeaf(c, fn)
elseif c:IsA("Model") or c:IsA("BasePart") then
fn(c)
end
end
end
-- рельеф: копия и вырез
local terrain = workspace.Terrain
local copy = terrain:CopyRegion(Region3int16.new(Vector3int16.new(-28, -2, -42), Vector3int16.new(28, 24, -8)))
copy.Name = "GardenWideTerrain"
copy.Parent = backup
for x = -96, 96, 4 do
local z1 = target(math.abs(x)) + 2
if z1 < -36 then
terrain:FillBlock(CFrame.new(x, 41, (z1 - 36) / 2), V(4.5, 80, -36 - z1), Enum.Material.Air)
end
end
-- скалы
local cliffs = map.LobbyCliffs
local list = {}
for _, m in ipairs(cliffs:GetChildren()) do
local p = pivotOf(m).Position
if p.Z < -30 and math.abs(p.X) < XE then
local dz = dzAt(p.X)
table.insert(list, { pos = p, dz = dz })
push(m, dz)
end
end
-- декор на скалах едет вместе со своей скалой
if map:FindFirstChild("LobbyCliffDecor") then
eachLeaf(map.LobbyCliffDecor, function(o)
local p = pivotOf(o).Position
if p.Z < -30 and math.abs(p.X) < XE + 15 then
local best, bd = nil, math.huge
for _, c in ipairs(list) do
local d = (V(p.X, 0, p.Z) - V(c.pos.X, 0, c.pos.Z)).Magnitude
if d < bd then
best, bd = c, d
end
end
if best and bd < 45 then
push(o, best.dz)
end
end
end)
end
-- подножие, деревья, лес; лес с дальних холмов — только если стоял на вырезанном месте
local reseat = {}
for name, minR in pairs({ LobbyCliffFoot = 66, LobbyForest = 74, LobbyTrees = 74, LobbyRockPlants = 74 }) do
local f = map:FindFirstChild(name)
if f then
eachLeaf(f, function(o)
local p = pivotOf(o).Position
if p.Z < -30 and math.abs(p.X) < XE and V(p.X, 0, p.Z).Magnitude >= minR then
push(o, dzAt(p.X))
if name ~= "LobbyCliffFoot" and o:IsA("Model") then
table.insert(reseat, o)
end
end
end)
end
end
if map:FindFirstChild("LobbyHillForest") then
eachLeaf(map.LobbyHillForest, function(o)
local p = pivotOf(o).Position
if p.Z < -30 and math.abs(p.X) < 96 and p.Z > target(math.abs(p.X)) - 8 then
push(o, target(math.abs(p.X)) - 12 - p.Z)
if o:IsA("Model") then
table.insert(reseat, o)
end
end
end)
end
for _, c in ipairs(workspace:GetChildren()) do
if c ~= map and (c:IsA("Model") or c:IsA("BasePart")) and not c:IsA("Terrain") then
local p = pivotOf(c).Position
local r = V(p.X, 0, p.Z).Magnitude
if p.Z < -38 and r >= 74 and r <= 150 and math.abs(p.X) < XE then
push(c, dzAt(p.X))
end
end
end
-- дыры в стене скал: вдоль нового края, где рядом нет скалы, ставим копию ближайшей
local function cliffNear(p, r)
local best, bd = nil, math.huge
for _, m in ipairs(cliffs:GetChildren()) do
local q = pivotOf(m).Position
local d = (V(q.X, 0, q.Z) - p).Magnitude
local _, size = m:GetBoundingBox()
if d < bd and math.max(size.X, size.Z) < 36 then
best, bd = m, d
end
end
return bd < r, best
end
local clones = 0
for s = -1, 1, 2 do
for t = 0, 1, 0.12 do
local x = XF + (XE - XF) * t
local p = V(s * x, 0, target(x) - 3)
local near, src = cliffNear(p, 15)
if not near and src then
local c = src:Clone()
c:SetAttribute("GardenWideClone", true)
c:SetAttribute(TAG, nil)
local y = src:GetPivot().Y
local out = V(p.X, 0, p.Z).Unit
c:PivotTo(CFrame.lookAt(V(p.X, y, p.Z), V(p.X, y, p.Z) + out))
c.Parent = cliffs
clones += 1
end
end
end
-- углы: две скалы заходили за забор сада (x ±52) — ещё немного наружу
for _, m in ipairs(cliffs:GetChildren()) do
local p = pivotOf(m).Position
if math.abs(p.X) > 45 and math.abs(p.X) < 75 and p.Z < -112 and p.Z > -140 and not m:GetAttribute("GardenWideClone") then
setPivot(m, pivotOf(m) + V(p.X > 0 and 8 or -8, 0, 0))
end
end
-- деревья — на то, что теперь под ними
local rp = RaycastParams.new()
rp.FilterType = Enum.RaycastFilterType.Include
rp.FilterDescendantsInstances = { cliffs, terrain }
for _, m in ipairs(reseat) do
local cf, size = m:GetBoundingBox()
local hit = workspace:Raycast(V(cf.X, 220, cf.Z), V(0, -300, 0), rp)
if hit then
m:PivotTo(m:GetPivot() + V(0, hit.Position.Y - (cf.Y - size.Y / 2), 0))
end
end
-- невидимая стена — по новому краю
local walls = Instance.new("Folder")
walls.Name = "GardenWideWalls"
walls.Parent = backup
local sample
for _, c in ipairs(map:GetChildren()) do
if c:IsA("BasePart") and c.Size.Y == 60 and c.Size.Z == 2 and c.Position.Z < -51.5 and V(c.Position.X, 0, c.Position.Z).Magnitude < 104 then
sample = c
c.Parent = walls
end
end
local pts = { V(-91, 30, -46), V(-XF, 30, TOP + 4), V(XF, 30, TOP + 4), V(91, 30, -46) }
for i = 1, #pts - 1 do
local a, b = pts[i], pts[i + 1]
local w = sample:Clone()
w.Name = "GardenWall"
w:SetAttribute("GardenWideClone", true)
w.Size = V((b - a).Magnitude + 2, 60, 2)
w.CFrame = CFrame.lookAt((a + b) / 2, (a + b) / 2 + (b - a).Unit) * CFrame.Angles(0, math.rad(90), 0)
w.Parent = map
end
-- продолжение мостовой: чуть ниже диска, чтобы края не мерцали
local disk
for _, c in ipairs(map:GetChildren()) do
if c:IsA("BasePart") and c.Material == Enum.Material.Cobblestone and c.Size.Y > 200 then
disk = c
end
end
local slab = Instance.new("Part")
slab.Name = "GardenGround"
slab:SetAttribute("GardenWideClone", true)
slab.Anchored = true
slab.Material, slab.Color = disk.Material, disk.Color
slab.TopSurface, slab.BottomSurface = Enum.SurfaceType.Smooth, Enum.SurfaceType.Smooth
slab.Size = V(196, 1, 118)
slab.CFrame = CFrame.new(0, 0.48, -97)
slab.Parent = map
map:SetAttribute("GardenWide", true)
return ("сдвинуто %d, копий скал %d, деревьев пересажено %d"):format(moved, clones, #reseat)