Files
Fishing/tools/build-guild-garden2.lua

444 lines
16 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Спокойный сад Гильдии v2 (assets/props/guild_garden_v2.bbmodel, настоящий размер, не масштабируется) и пасхалки.
-- Собирается tools/build-guild-garden2.js, запускать в Edit после Гильдии v2 и tools/widen-garden.lua.
-- Прежний большой сад — в ServerStorage.Backup.GuildGarden_big; повторный запуск пересобирает только этот сад.
local map = workspace:FindFirstChild("FishingMap")
assert(map, "Нет Workspace.FishingMap")
local hallModel = map:FindFirstChild("GuildHall") and map.GuildHall:FindFirstChild("GuildHallBuilding")
assert(hallModel, "Сначала соберите Гильдию v2")
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.Backup
local old = map:FindFirstChild("GuildGarden")
if old and old:GetAttribute("GardenV2") then
old:Destroy()
elseif old then
old.Name = "GuildGarden_big"
old.Parent = backup
end
local garden = Instance.new("Folder")
garden.Name = "GuildGarden"
garden:SetAttribute("GardenV2", true)
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
local function partsIn(g)
local t = {}
for _, p in ipairs(g and g:GetDescendants() or {}) do
if p:IsA("BasePart") then
table.insert(t, p)
end
end
return t
end
local function ext(list)
local mn, mx = V(math.huge, math.huge, math.huge), V(-math.huge, -math.huge, -math.huge)
for _, p in ipairs(list) do
local a, b = boundsOf(p)
mn, mx = mn:Min(a), mx:Max(b)
end
return mn, mx
end
local model = BUILD.garden(garden)
model.Name = "GardenModel"
model:PivotTo(PIV)
local function g(name)
return model:FindFirstChild(name, true)
end
---------------------------------------------------------------- материалы и столкновения
-- твёрдые: земля, тропинка, мостик, беседка, стволы, крупные камни; всё остальное — проходимо и без теней
local GROUND = { Grass = true, Banks = true, Pond = true, Path = true, Bridge = true, Gazebo = true }
local parts, collide = 0, 0
for _, p in ipairs(model:GetDescendants()) do
if p:IsA("BasePart") then
parts += 1
p.Anchored, p.CanTouch = true, false
local group = p.Parent and p.Parent.Name or ""
local s = { p.Size.X, p.Size.Y, p.Size.Z }
table.sort(s)
local solid = false
if GROUND[group] then
solid = s[3] >= 0.6
elseif group == "Trees" then
solid = p.Name:find("Trunk") ~= nil
elseif group == "Rocks" or group == "StoneWall" then
solid = s[2] >= 1.8 and s[1] >= 1
end
p.CanCollide, p.CanQuery = solid, solid
p.CastShadow = (group == "Trees" or group == "Gazebo") and 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.CanCollide, p.CanQuery = false, false
elseif group == "FishSpots" or p.Name:match("^Spot_") then
p.Transparency = 1
p.CanCollide, p.CanQuery = false, false
elseif p.Name:find("_Glow") then
p.Material = Enum.Material.Neon
p.CastShadow = false
end
end
end
if model.PrimaryPart then
model.PrimaryPart.CanCollide, model.PrimaryPart.CanQuery, model.PrimaryPart.Transparency = false, false, 1
end
local _, wmx = ext(partsIn(g("PondWater")))
local waterTop = wmx.Y
---------------------------------------------------------------- мостик: положе, шире, перила ниже (без пересборки модели)
do
local K, WIDE, DROP = 0.6, 1.3, 1.1 -- подъём, ширина, насколько ниже перила
local list = partsIn(g("Bridge"))
local mn, mx = ext(list)
local cx = PIV:PointToObjectSpace((mn + mx) / 2).X
local baseY = math.huge
for _, p in ipairs(list) do
if p.Name == "BridgePlank" then
baseY = math.min(baseY, p.Position.Y)
end
end
for _, p in ipairs(list) do
local l = PIV:ToObjectSpace(p.CFrame)
local rx, ry, rz = l:ToEulerAnglesYXZ()
local pos = l.Position
local y = pos.Y + PIV.Position.Y
local ny = y > baseY and baseY + (y - baseY) * K or y
local size = p.Size
if p.Name == "BridgePost" then
size = V(size.X, size.Y - DROP, size.Z)
ny -= DROP / 2
elseif p.Name == "BridgeRail" then
ny -= DROP
elseif p.Name == "BridgePlank" then
size = V(size.X * WIDE, size.Y, size.Z)
end
p.Size = size
p.CFrame = PIV * CFrame.new(cx + (pos.X - cx) * WIDE, ny - PIV.Position.Y, pos.Z) * CFrame.fromEulerAnglesYXZ(rx * K, ry, rz)
end
end
-- камни берега, лежащие на проходе: мостик стал шире, полоса по его оси и на 5 стадов за концами — свободна
do
local bm, bx = ext(partsIn(g("Bridge")))
for _, p in ipairs(partsIn(g("Rocks"))) do
local a2, b2 = boundsOf(p)
if b2.X > bm.X and a2.X < bx.X and b2.Z > bm.Z - 5 and a2.Z < bx.Z + 5 then
p:Destroy()
end
end
end
---------------------------------------------------------------- до скал — ровная трава цвета края сада
-- Один цвет и одна высота: большой пласт уходит под сад и скалы, спереди — круги внахлёст, поэтому нет ни щелей,
-- ни прямого края. Слой ниже всего в модели сада. Вырез рельефа — чтобы земля не торчала сквозь траву.
local fillParts = 0
do
local edgePart, low = nil, math.huge
for _, p in ipairs(partsIn(g("Grass"))) do
local a, b = boundsOf(p)
local area = (b.X - a.X) * (b.Z - a.Z)
if area > 20 and b.Y < low then
edgePart, low = p, b.Y
end
end
local function edgeZ(ax)
local TOP, XF, XE, ZE = -146, 58, 92, -52
return ax <= XF and TOP or TOP + (ZE - TOP) * math.min(1, (ax - XF) / (XE - XF))
end
for x = -100, 100, 4 do
local z1 = edgeZ(math.abs(x))
if z1 < -56 then
workspace.Terrain:FillBlock(CFrame.new(x, 38, (z1 - 56) / 2), V(4.5, 84, -56 - z1), Enum.Material.Air)
end
end
local fill = Instance.new("Folder")
fill.Name = "EdgeFill"
fill.Parent = garden
local TOPY = PIV.Y + 0.08
local function mk(size, cf, cyl)
local p = Instance.new("Part")
p.Name = "EdgeGrass"
p.Shape = cyl and Enum.PartType.Cylinder or Enum.PartType.Block
p.Anchored, p.CanTouch, p.CastShadow = true, false, false
p.TopSurface, p.BottomSurface = Enum.SurfaceType.Smooth, Enum.SurfaceType.Smooth
p.Material, p.Color = edgePart.Material, edgePart.Color
p.Size, p.CFrame = size, cf
p.Parent = fill
fillParts += 1
end
-- пласт режем по контуру сада: под садом его нет (ряды по 4 стада, полоса — там, где ячейка не закрыта травой сада)
local grassOnly = RaycastParams.new()
grassOnly.FilterType = Enum.RaycastFilterType.Include
grassOnly.FilterDescendantsInstances = { g("Grass") }
local function covered(x, z, r)
for _, o in ipairs({ V(0, 0, 0), V(r, 0, r), V(-r, 0, r), V(r, 0, -r), V(-r, 0, -r) }) do
if not workspace:Raycast(V(x + o.X, PIV.Y + 12, z + o.Z), V(0, -20, 0), grassOnly) then
return false
end
end
return true
end
for z = -74, -150, -4 do
local start
for x = -104, 104, 4 do
local cell = x < 104 and not covered(x + 2, z, 2.4)
if cell and not start then
start = x
elseif not cell and start then
mk(V(x - start, 0.3, 4), CFrame.new((x + start) / 2, TOPY - 0.15, z))
start = nil
end
end
end
local rng = Random.new(5)
for _, s in ipairs({ -1, 1 }) do
for _, x in ipairs({ 42, 55, 68, 81, 94, 106 }) do
local d = rng:NextNumber(24, 32)
local dz = rng:NextNumber(-74, -70)
if not covered(s * x, dz, d * 0.34) then
mk(V(0.3, d, d), CFrame.new(s * x, TOPY - 0.15, dz) * CFrame.Angles(0, 0, math.rad(90)), true)
end
end
end
end
---------------------------------------------------------------- чёрные пятна на площади (траву-меш не прорисовывает)
local patches = 0
do
for _, d in ipairs(workspace:GetDescendants()) do
if d:IsA("MeshPart") and d.MeshId:find("8656563403") and V(d.Position.X, 0, d.Position.Z).Magnitude < 75 then
d.Name = "BlackPatch_garden"
d.Parent = backup
patches += 1
end
end
-- деревья стояли на этих холмиках — на землю
local rp = RaycastParams.new()
rp.FilterType = Enum.RaycastFilterType.Exclude
rp.RespectCanCollide = true
for _, c in ipairs(workspace:GetChildren()) do
if c:IsA("Model") and c.Name == "ForestTree_RoundCanopy" then
local cf, size = c:GetBoundingBox()
if V(cf.X, 0, cf.Z).Magnitude < 75 then
rp.FilterDescendantsInstances = { c }
local hit = workspace:Raycast(cf.Position, V(0, -60, 0), rp)
if hit then
c:PivotTo(c:GetPivot() + V(0, hit.Position.Y - 0.2 - (cf.Y - size.Y / 2), 0))
end
end
end
end
end
---------------------------------------------------------------- пасхалки по меткам
local eggs = Instance.new("Folder")
eggs.Name = "Eggs"
eggs.Parent = garden
local function spotPos(name)
local m = g(name)
local p = (m and (m:IsA("BasePart") and m or m:FindFirstChildWhichIsA("BasePart", true))) or nil
assert(p, "Нет метки " .. name)
return p.Position
end
local rp = RaycastParams.new()
rp.FilterType = Enum.RaycastFilterType.Exclude
rp.RespectCanCollide = true
local ROT = PIV - PIV.Position
local function placeGround(egg, spot, yaw)
rp.FilterDescendantsInstances = { egg, eggs }
local hit = workspace:Raycast(spot + V(0, 12, 0), V(0, -30, 0), rp)
egg:PivotTo(CFrame.new(spot.X, hit and hit.Position.Y or PIV.Y, spot.Z) * ROT * CFrame.Angles(0, math.rad(yaw or 0), 0))
end
local function eggPhysics(egg, soft)
for _, p in ipairs(egg:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored, p.CanTouch = true, false
local s = { p.Size.X, p.Size.Y, p.Size.Z }
table.sort(s)
local solid = s[2] >= 0.8 and not soft[p.Parent.Name]
p.CanCollide, p.CanQuery = solid, solid
p.CastShadow = s[3] >= 4
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, action, object, kind, worldPos)
local att = Instance.new("Attachment")
att.Name = "PromptPoint"
att.WorldPosition = worldPos
att.Parent = part
att.WorldPosition = worldPos
local pp = Instance.new("ProximityPrompt")
pp.ActionText, pp.ObjectText = action, object
pp.HoldDuration, pp.MaxActivationDistance, pp.RequiresLineOfSight = 0, 7.5, true
pp:SetAttribute("Egg", kind)
pp.Parent = att
end
-- невидимый столб: на него нельзя запрыгнуть (высокий), камере и лучам не мешает
local function blocker(name, mn, mx)
local p = Instance.new("Part")
p.Name = name
p.Anchored, p.CanCollide, p.CanQuery, p.CanTouch, p.CastShadow = true, true, false, false, false
p.Transparency = 1
p.Size = mx - mn
p.CFrame = CFrame.new((mn + mx) / 2)
p.Parent = garden
end
-- меч: выше персонажа (8.5 при росте 6)
local sword = BUILD.sword(eggs)
sword.Name = "EggSwordStone"
sword:ScaleTo(1.9)
eggPhysics(sword, { Plaque = true })
placeGround(sword, spotPos("Spot_Sword"), 0)
do
local post = find(sword, "PlaquePost")
if post then
post.Size -= V(0, 0.57, 0)
post.CFrame -= V(0, 0.285, 0)
end
local plaque = find(sword, "Plaque_Face")
plaque.Size = V(plaque.Size.X * 1.3, plaque.Size.Y, plaque.Size.Z * 1.5)
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")
local long, short = math.max(plaque.Size.X, plaque.Size.Z), math.min(plaque.Size.X, plaque.Size.Z)
t.AnchorPoint = Vector2.new(0.5, 0.5)
t.Position = UDim2.fromScale(0.5, 0.5)
t.Size = UDim2.fromScale(long / short * 0.94, short / long * 0.86)
t.BackgroundTransparency = 1
t.FontFace = TITLE_FONT
t.TextScaled = true
t.TextColor3 = Color3.fromRGB(58, 38, 22)
t.Text = "Кто вытащит меч —\nстанет королём\nрыбаков" -- строки заданы, чтобы перенос не прыгал
t.TextWrapped = true
t.Parent = sg
local toViewer = (plaque.Position - sword:GetPivot().Position) * V(1, 0, 1)
t.Rotation = (plaque.CFrame.LookVector:Dot(toViewer) < 0 and 180 or 0) - 90
local front = sword:GetPivot().LookVector -- у Model LookVector — это −Z, сторона лица
prompt(plaque, "Вытащить меч", "Меч в камне", "Sword", plaque.Position + front * 1.2 + V(0, 1.2, 0))
end
-- холм с круглой дверью: дверь выше персонажа, задняя часть врезана в край у скал
local door = BUILD.door(eggs)
door.Name = "EggRoundDoor"
door:ScaleTo(3.4)
eggPhysics(door, { Glow = true })
placeGround(door, spotPos("Spot_RoundDoor"), 0)
do
local rd = {}
for _, p in ipairs(partsIn(door)) do
if p.Name == "RoundDoor" then
table.insert(rd, p)
end
end
local a, b = ext(rd)
prompt(rd[1], "Постучать", "Круглая дверь", "Door", (a + b) / 2 + door:GetPivot().LookVector * 2.2)
-- окошко — тёплое стекло без сияния
for _, p in ipairs(partsIn(door:FindFirstChild("Glow", true))) do
p.Material = Enum.Material.SmoothPlastic
p.Color = Color3.fromRGB(240, 210, 150)
end
end
do
local hm, hx = ext(partsIn(door:FindFirstChild("Hill", true)))
blocker("BlockHill", hm - V(0.6, 0, 0.6), V(hx.X + 0.6, hx.Y + 60, hx.Z + 0.6))
local dm, dx = ext(partsIn(door:FindFirstChild("Door", true)))
blocker("BlockDoorTop", V(dm.X - 0.5, dx.Y - 1.2, dm.Z - 0.5), V(dx.X + 0.5, dx.Y + 60, dx.Z + 0.5))
end
-- крыша беседки: столб от верха стоек вверх
do
local gz = g("Gazebo")
local top = -math.huge
for _, p in ipairs(partsIn(gz)) do
if p.Name:find("Post") then
local _, b = boundsOf(p)
top = math.max(top, b.Y)
end
end
local mn, mx = ext(partsIn(gz))
blocker("BlockGazeboRoof", V(mn.X - 1, top - 0.4, mn.Z - 1), V(mx.X + 1, mx.Y + 60, mx.Z + 1))
end
-- уточка и капибара на воде
local duck = BUILD.duck(eggs)
duck.Name = "EggRubberDuck"
duck:ScaleTo(1.5)
eggPhysics(duck, { Duck = true })
do
local c = spotPos("Spot_Duck")
duck:PivotTo(CFrame.new(c.X, waterTop - 0.5, c.Z) * ROT * CFrame.Angles(0, math.rad(90), 0))
duck.ModelStreamingMode = Enum.ModelStreamingMode.Persistent
end
local capy = BUILD.capy(eggs)
capy.Name = "EggCapybara"
local cw = capy:FindFirstChild("Water", true)
if cw then
cw:Destroy()
end
capy:ScaleTo(2)
eggPhysics(capy, { Capybara = true, Mandarin = true })
do
local c = spotPos("Spot_Capybara")
capy:PivotTo(CFrame.new(c.X, waterTop - 1.5, c.Z) * ROT * CFrame.Angles(0, math.rad(90), 0))
end
-- рыбы: у уточки и капибары не плавают
do
local spots = {}
for _, p in ipairs(partsIn(g("FishSpots"))) do
if p.Name ~= "FishSpot_3" and p.Name ~= "FishSpot_5" then
table.insert(spots, ("%.2f,%.2f"):format(p.Position.X, p.Position.Z))
end
end
garden:SetAttribute("PondSpots", table.concat(spots, ";"))
garden:SetAttribute("PondWaterY", waterTop)
end
-- невидимые детали сада не отбрасывают тень
local shadowOff = 0
for _, p in ipairs(garden:GetDescendants()) do
if p:IsA("BasePart") and p.Transparency >= 0.95 and p.CastShadow then
p.CastShadow = false
shadowOff += 1
end
end
return ("Сад v2: деталей %d, твёрдых %d, вода Y=%.2f; трава по краю: %d; чёрных пятен убрано: %d; теней снято: " .. shadowOff):format(parts, collide, waterTop, fillParts, patches)