296 lines
12 KiB
Lua
296 lines
12 KiB
Lua
-- Сад Гильдии (assets/props/guild_garden.bbmodel) и пасхалки: меч в камне, круглая дверь в холме, резиновая уточка.
|
|
-- Собирается tools/build-guild-garden.js, запускать в Edit ПОСЛЕ Гильдии v2 (сад в её системе координат).
|
|
-- Повторный запуск пересобирает только FishingMap.GuildGarden; то, что стояло на месте сада, — в ServerStorage.Backup.
|
|
|
|
local map = workspace:FindFirstChild("FishingMap")
|
|
assert(map, "Нет Workspace.FishingMap")
|
|
local hallModel = map:FindFirstChild("GuildHall") and map.GuildHall:FindFirstChild("GuildHallBuilding")
|
|
assert(hallModel, "Сначала соберите Гильдию v2 (tools/build-guild-hall3.js)")
|
|
local V = Vector3.new
|
|
local PIV = hallModel:GetPivot() -- та же точка и поворот, что у Гильдии
|
|
local TITLE_FONT = Font.new("rbxasset://fonts/families/Merriweather.json", Enum.FontWeight.Heavy)
|
|
|
|
local backup = game.ServerStorage:FindFirstChild("Backup") or Instance.new("Folder")
|
|
backup.Name = "Backup"
|
|
backup.Parent = game.ServerStorage
|
|
local old = map:FindFirstChild("GuildGarden")
|
|
if old then
|
|
old:Destroy()
|
|
end
|
|
local garden = Instance.new("Folder")
|
|
garden.Name = "GuildGarden"
|
|
garden.Parent = map
|
|
|
|
local function boundsOf(p)
|
|
local h = p.CFrame:VectorToWorldSpace(p.Size / 2)
|
|
h = V(math.abs(h.X), math.abs(h.Y), math.abs(h.Z))
|
|
return p.Position - h, p.Position + h
|
|
end
|
|
|
|
---------------------------------------------------------------- 1) сад
|
|
|
|
local model = BUILD.garden(garden)
|
|
model.Name = "GardenModel"
|
|
model:PivotTo(PIV)
|
|
|
|
-- участок сада в мире (по забору) — всё постороннее, что в него залезает, в архив
|
|
local fmn, fmx = V(math.huge, math.huge, math.huge), V(-math.huge, -math.huge, -math.huge)
|
|
for _, p in ipairs((model:FindFirstChild("Fence", true) or model):GetDescendants()) do
|
|
if p:IsA("BasePart") then
|
|
local a, b = boundsOf(p)
|
|
fmn, fmx = fmn:Min(a), fmx:Max(b)
|
|
end
|
|
end
|
|
local function inGarden(obj)
|
|
local cf, size
|
|
if obj:IsA("Model") then
|
|
cf, size = obj:GetBoundingBox()
|
|
elseif obj:IsA("BasePart") then
|
|
cf, size = obj.CFrame, obj.Size
|
|
else
|
|
return false
|
|
end
|
|
local c, h = cf.Position, size / 2
|
|
if size.Magnitude > 120 then
|
|
return false -- земля лобби, скалы целиком
|
|
end
|
|
return c.X + h.X > fmn.X and c.X - h.X < fmx.X and c.Z + h.Z > fmn.Z and c.Z - h.Z < fmx.Z and c.Y - h.Y < PIV.Position.Y + 8
|
|
end
|
|
local stashed = {}
|
|
local function stash(obj)
|
|
table.insert(stashed, obj:GetFullName())
|
|
obj.Name = obj.Name .. "_garden"
|
|
obj.Parent = backup
|
|
end
|
|
for _, c in ipairs(workspace:GetChildren()) do
|
|
if (c:IsA("Model") or c:IsA("BasePart")) and c ~= map and not c:IsA("Terrain") and inGarden(c) then
|
|
stash(c)
|
|
end
|
|
end
|
|
-- подножие скал: трава, цветы и камни лежат кучками внутри папок — переносим только задевающие сад
|
|
for _, f in ipairs({ "LobbyCliffFoot", "LobbyDecor", "LobbyTrees", "LobbyRockPlants" }) do
|
|
local folder = map:FindFirstChild(f)
|
|
for _, c in ipairs(folder and folder:GetDescendants() or {}) do
|
|
if (c:IsA("Model") or (c:IsA("BasePart") and not c:FindFirstAncestorWhichIsA("Model"))) and c.Parent and inGarden(c) then
|
|
stash(c)
|
|
end
|
|
end
|
|
end
|
|
|
|
-- материалы и столкновения: ходить по траве, дорожкам, мостику и дну пруда; забор, стволы, беседка,
|
|
-- лодка, улей, огород — твёрдые; растения, листва, вода, фонари — проходимые
|
|
local SOLID = { Grass = true, Paths = true, Bridge = true, Pond = true }
|
|
local SOFT = { PondWater = true, FishSpots = true, PondPlants = true, Lanterns = true, Beds = true, Bushes = true }
|
|
local water
|
|
local parts, collide = 0, 0
|
|
for _, p in ipairs(model:GetDescendants()) do
|
|
if p:IsA("BasePart") then
|
|
parts += 1
|
|
p.Anchored = true
|
|
local group = p.Parent and p.Parent.Name or ""
|
|
local s = { p.Size.X, p.Size.Y, p.Size.Z }
|
|
table.sort(s)
|
|
local localY = PIV:PointToObjectSpace(p.Position).Y
|
|
local solid
|
|
if SOLID[group] then
|
|
solid = s[3] >= 0.6
|
|
elseif SOFT[group] then
|
|
solid = false
|
|
elseif group == "Trees" then
|
|
solid = s[2] >= 0.8 and localY < 2.5 -- стволы; кроны — над головой
|
|
else
|
|
solid = s[2] >= 1
|
|
end
|
|
p.CanCollide, p.CanQuery, p.CanTouch = solid, solid, false
|
|
p.CastShadow = s[3] >= 3
|
|
if solid then
|
|
collide += 1
|
|
end
|
|
if group == "PondWater" then
|
|
-- вода как в фонтане лобби
|
|
p.Material = Enum.Material.Glass
|
|
p.Color = Color3.fromRGB(110, 190, 235)
|
|
p.Transparency = 0.3
|
|
p.CastShadow = false
|
|
water = water or p
|
|
elseif group == "FishSpots" then
|
|
p.Transparency = 1
|
|
elseif p.Name:find("_Glow") then
|
|
p.Material = Enum.Material.Neon
|
|
p.CastShadow = false
|
|
local l = Instance.new("PointLight")
|
|
l.Range, l.Brightness, l.Color = 12, 0.8, Color3.fromRGB(255, 205, 150)
|
|
l.Parent = p
|
|
end
|
|
end
|
|
end
|
|
if model.PrimaryPart then
|
|
model.PrimaryPart.CanCollide, model.PrimaryPart.CanQuery, model.PrimaryPart.Transparency = false, false, 1
|
|
end
|
|
local waterTop = -math.huge
|
|
for _, p in ipairs((model:FindFirstChild("PondWater", true) or model):GetDescendants()) do
|
|
if p:IsA("BasePart") then
|
|
local _, b = boundsOf(p)
|
|
waterTop = math.max(waterTop, b.Y)
|
|
end
|
|
end
|
|
model:SetAttribute("WaterTop", waterTop)
|
|
|
|
---------------------------------------------------------------- 2) пасхалки
|
|
|
|
local rp = RaycastParams.new()
|
|
rp.FilterType = Enum.RaycastFilterType.Exclude
|
|
rp.RespectCanCollide = true
|
|
local function groundY(pos, exclude)
|
|
rp.FilterDescendantsInstances = exclude
|
|
local hit = workspace:Raycast(pos + V(0, 8, 0), V(0, -20, 0), rp)
|
|
return hit and hit.Position.Y or PIV.Position.Y
|
|
end
|
|
|
|
-- место свободно, если в прямоугольнике нет твёрдых или крупных деталей сада (кроме травы и дорожек)
|
|
local function blockers(cf, size)
|
|
local list = {}
|
|
local half = size / 2
|
|
for _, p in ipairs(model:GetDescendants()) do
|
|
if p:IsA("BasePart") and p.Transparency < 1 then
|
|
local g = p.Parent.Name
|
|
if g ~= "Grass" and g ~= "Paths" then
|
|
local lp = cf:PointToObjectSpace(p.Position)
|
|
local a, b = boundsOf(p)
|
|
local r = (b - a) / 2
|
|
if math.abs(lp.X) < half.X + r.X * 0.5 and math.abs(lp.Z) < half.Z + r.Z * 0.5 and b.Y > cf.Position.Y + 0.35 then
|
|
table.insert(list, p)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return list
|
|
end
|
|
-- из нескольких мест (x, z, поворот — в системе сада) берём самое свободное; мелочь, что всё равно мешает
|
|
-- (кусты, цветы, грядки), убираем
|
|
local function placeEgg(egg, candidates, footprint)
|
|
local best, bestList
|
|
for _, c in ipairs(candidates) do
|
|
local cf = PIV * CFrame.new(c[1], 0, c[2]) * CFrame.Angles(0, math.rad(c[3] or 0), 0)
|
|
local list = blockers(cf, footprint)
|
|
if not best or #list < #bestList then
|
|
best, bestList = cf, list
|
|
end
|
|
if #list == 0 then
|
|
break
|
|
end
|
|
end
|
|
local removed = 0
|
|
for _, p in ipairs(bestList) do
|
|
local g = p.Parent.Name
|
|
if g == "Bushes" or g == "Beds" or g == "PondPlants" or g == "Trees" and p.Size.Magnitude < 3 then
|
|
p:Destroy()
|
|
removed += 1
|
|
end
|
|
end
|
|
local y = groundY(best.Position, { egg, garden:FindFirstChild("Eggs") })
|
|
egg:PivotTo(CFrame.new(best.Position.X, y, best.Position.Z) * (best - best.Position))
|
|
return removed, #bestList - removed
|
|
end
|
|
local function eggPhysics(egg, softGroups)
|
|
for _, p in ipairs(egg:GetDescendants()) do
|
|
if p:IsA("BasePart") then
|
|
p.Anchored = true
|
|
local s = { p.Size.X, p.Size.Y, p.Size.Z }
|
|
table.sort(s)
|
|
local solid = s[2] >= 0.8 and not softGroups[p.Parent.Name]
|
|
p.CanCollide, p.CanQuery, p.CanTouch = solid, solid, false
|
|
p.CastShadow = s[3] >= 2
|
|
if p.Name:find("_Glow") then
|
|
p.Material = Enum.Material.Neon
|
|
p.CastShadow = false
|
|
end
|
|
end
|
|
end
|
|
if egg.PrimaryPart then
|
|
egg.PrimaryPart.CanCollide, egg.PrimaryPart.CanQuery, egg.PrimaryPart.Transparency = false, false, 1
|
|
end
|
|
end
|
|
local function find(root, name)
|
|
for _, d in ipairs(root:GetDescendants()) do
|
|
if d:IsA("BasePart") and d.Name == name then
|
|
return d
|
|
end
|
|
end
|
|
end
|
|
local function prompt(part, actionText, objectText, egg)
|
|
local pp = Instance.new("ProximityPrompt")
|
|
pp.ActionText, pp.ObjectText = actionText, objectText
|
|
pp.HoldDuration, pp.MaxActivationDistance, pp.RequiresLineOfSight = 0, 8, false
|
|
pp:SetAttribute("Egg", egg) -- обрабатывает LobbyLife.client.lua (только на экране игрока)
|
|
pp.Parent = part
|
|
return pp
|
|
end
|
|
|
|
local eggs = Instance.new("Folder")
|
|
eggs.Name = "Eggs"
|
|
eggs.Parent = garden
|
|
local notes = {}
|
|
|
|
-- меч в камне — в дальнем правом углу сада (за ульем), лицом к саду
|
|
local sword = BUILD.sword(eggs)
|
|
sword.Name = "EggSwordStone"
|
|
eggPhysics(sword, { Plaque = true })
|
|
local r1, left1 = placeEgg(sword, { { 25, 24.5, 0 }, { 23.5, 22, 0 }, { 25.5, 17.5, 0 }, { -12, 25.5, 0 } }, V(3.8, 4, 4.4))
|
|
table.insert(notes, ("меч: убрано кустов %d, рядом осталось %d"):format(r1, left1))
|
|
local plaque = find(sword, "Plaque_Face")
|
|
if plaque then
|
|
local sg = Instance.new("SurfaceGui")
|
|
sg.Face = Enum.NormalId.Top
|
|
sg.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
|
|
sg.PixelsPerStud = 120
|
|
sg.LightInfluence = 0.3
|
|
sg.Parent = plaque
|
|
local t = Instance.new("TextLabel")
|
|
t.Size = UDim2.fromScale(0.94, 0.9)
|
|
t.Position = UDim2.fromScale(0.03, 0.05)
|
|
t.BackgroundTransparency = 1
|
|
t.FontFace = TITLE_FONT
|
|
t.TextScaled = true
|
|
t.TextColor3 = Color3.fromRGB(58, 38, 22)
|
|
t.Text = "Кто вытащит меч — станет королём рыбаков"
|
|
t.TextWrapped = true
|
|
t.Parent = sg
|
|
-- текст должен читаться со стороны зрителя: если «верх» таблички смотрит от него — развернуть
|
|
local look = plaque.CFrame.LookVector
|
|
local toViewer = (plaque.Position - sword:GetPivot().Position) * V(1, 0, 1)
|
|
if look:Dot(toViewer) < 0 then
|
|
t.Rotation = 180
|
|
end
|
|
end
|
|
local blade = find(sword, "Grip") or find(sword, "Blade")
|
|
prompt(blade, "Вытащить меч", "Меч в камне", "Sword")
|
|
|
|
-- круглая дверь в холме — в дальнем левом углу, за беседкой, спиной к забору
|
|
local door = BUILD.door(eggs)
|
|
door.Name = "EggRoundDoor"
|
|
eggPhysics(door, { Glow = true, Mailbox = false })
|
|
local r2, left2 = placeEgg(door, { { -25.5, 23.4, 0 }, { -25.5, 20.5, 0 }, { 24, 20, 0 }, { -9, 24, 0 } }, V(7.4, 4, 9.6))
|
|
table.insert(notes, ("дверь: убрано кустов %d, рядом осталось %d"):format(r2, left2))
|
|
local knob = find(door, "RoundDoor") or find(door, "DoorKnob")
|
|
prompt(knob, "Постучать", "Круглая дверь", "Door")
|
|
|
|
-- резиновая уточка — в пруду, на воде
|
|
local duck = BUILD.duck(eggs)
|
|
duck.Name = "EggRubberDuck"
|
|
eggPhysics(duck, { Duck = true })
|
|
do
|
|
local spot = PIV * V(12.4, 0, 23.4)
|
|
local y = waterTop - 0.45
|
|
duck:PivotTo(CFrame.new(spot.X, y, spot.Z) * (PIV - PIV.Position) * CFrame.Angles(0, math.rad(-35), 0))
|
|
duck:SetAttribute("Bobbing", true) -- качается на воде (FountainFish.client.lua)
|
|
-- рыба с этой точки уходит в другое место
|
|
local fs = find(model, "FishSpot_5")
|
|
if fs then
|
|
fs:Destroy()
|
|
end
|
|
end
|
|
|
|
return ("Сад: деталей %d, с коллизией %d, вода на Y=%.2f; в архив: %d (%s); %s"):format(parts, collide, waterTop, #stashed,
|
|
table.concat(stashed, ", "):sub(1, 400), table.concat(notes, "; "))
|