diff --git a/Fishing.rbxlx b/Fishing.rbxlx index d44c1c1..d4c9b4d 100644 --- a/Fishing.rbxlx +++ b/Fishing.rbxlx @@ -59,6 +59,35 @@ function Config.WorldAt(pos) return nil end +-- куда бросать из этой точки (единичный вектор по горизонтали): к центру ближайшего озера или лунки, +-- а если ближе море — от центра острова к морю +function Config.CastDirection(world, pos) + if not world then + return nil + end + local x, z = pos.X - world.center.X, pos.Z - world.center.Z + local best, bestGap + local function consider(dir, gap) + if dir.Magnitude > 0.1 and (not bestGap or gap < bestGap) then + best, bestGap = dir.Unit, gap + end + end + if world.holes then + for _, h in ipairs(world.holes) do + consider(Vector3.new(h[1] - x, 0, h[2] - z), math.sqrt((h[1] - x) ^ 2 + (h[2] - z) ^ 2) - (world.holeRadius or 6)) + end + end + for _, l in ipairs(world.lakes or {}) do + if not world.holes then -- в Мире 3 озёра подо льдом, бросаем только в лунки + consider(Vector3.new(l[1] - x, 0, l[2] - z), math.sqrt((l[1] - x) ^ 2 + (l[2] - z) ^ 2) - l[3]) + end + end + if world.sea then + consider(Vector3.new(x, 0, z), world.sea - math.sqrt(x * x + z * z)) + end + return best +end + -- есть ли вода в этой точке мира (озеро, море или лунка) function Config.IsWater(world, pos) if not world then @@ -265,6 +294,15 @@ Config.BiteTimeMin = 3 Config.BiteTimeMax = 7 Config.BiteTimeout = 12 Config.MaxMisses = 2 +-- заброс: держишь ЛКМ — сила растёт от 0 до 1; от силы зависит дальность +Config.CastChargeTime = 1.3 -- секунд до полной силы +Config.CastMinDist, Config.CastMaxDist = 6, 28 +Config.CastPerfect = { 0.72, 0.86 } -- зелёная зона шкалы +Config.CastPerfectLuck = 1.2 -- множитель удачи за попадание в зелёную зону + +-- обучение: линия-подсказка ведёт по шагам 0 → 1 → 2 → 3, на 4 обучение пройдено +-- 0 — табличка «Как играть», 1 — портал в Мир 1, 2 — причал (поймать рыбу), 3 — скупка (продать) +Config.TutorialDone = 4 function Config.HitsNeeded(rank) return math.ceil(rank / 2) end @@ -1547,6 +1585,9 @@ for i, w in ipairs(Config.Worlds) do local a = math.rad(90 - (i - 1) * 90) -- 90° = сторона спавна (+Z) local pos = V(math.cos(a) * PORTAL_R, FLOOR, math.sin(a) * PORTAL_R) portal(CFrame.lookAt(pos, V(pos.X * 2, FLOOR, pos.Z * 2)), title, w.color, w.id, w.soon) + if i == 1 then + marker("GuidePortal", CFrame.new(pos.X * 1.3, FLOOR, pos.Z * 1.3)) -- точка перед порталом для линии-подсказки + end end -- невидимая стена по кругу: из лобби не уйти @@ -1631,12 +1672,13 @@ do local pos = V(-12, FLOOR, 48) local cf = CFrame.lookAt(pos, V(0, FLOOR, 64)) lamp((cf * CFrame.new(0, 0, 2.5)).Position) + marker("GuideBoard", cf * CFrame.new(0, 0, -6)) -- перед табличкой, для линии-подсказки for _, x in ipairs({ -6.5, 6.5 }) do P({ Size = V(0.8, 9, 0.8), CFrame = cf * CFrame.new(x, 4.5, 0.3), Material = Enum.Material.Wood, Color = Color3.fromRGB(90, 60, 40) }) end local board = P({ Size = V(14, 8, 0.5), CFrame = cf * CFrame.new(0, 6, 0), Material = Enum.Material.WoodPlanks, Color = Color3.fromRGB(70, 48, 32) }) surfaceText(board, Enum.NormalId.Front, - "КАК ИГРАТЬ\n1. Портал «Мир 1» или кнопка 🌍 Миры\n2. Удочка — клавиша 1, клик у воды\n3. Клюёт → кликай в зелёную зону\n4. 🎒 Сумка — B, 📜 Задания — Q\n5. Собирай коллекцию — получай награды!", + "КАК ИГРАТЬ\n1. Портал «Мир 1» или кнопка 🌍 Миры\n2. Удочка — клавиша 1, у воды зажми ЛКМ и отпусти\n3. Клюёт → кликай в зелёную зону\n4. 🎒 Сумка — B, 📜 Задания — Q\n5. Собирай коллекцию — получай награды!", Color3.fromRGB(255, 245, 225), { TextXAlignment = Enum.TextXAlignment.Left }) end @@ -1657,6 +1699,9 @@ local arrive = W + V(0, GROUND_Y, 94) marker("World1Spawn", CFrame.lookAt(arrive + V(0, 1, 0), arrive + V(0, 1, -10))) arch(CFrame.new(W + V(0, GROUND_Y, 82)), 14, 11, "🌊 ТИХОЕ ОЗЕРО", Color3.fromRGB(80, 200, 255)) portal(CFrame.lookAt(W + V(-22, GROUND_Y, 96), arrive), "🏠 В лобби", Color3.fromRGB(255, 200, 80), "Lobby") +-- точки для линии-подсказки: конец главного причала и место перед скупкой +marker("GuideFishSpot", CFrame.new(W + V(0, GROUND_Y + 0.5, 42))) +marker("GuideSell", CFrame.lookAt(W + V(26, GROUND_Y, 98), arrive) * CFrame.new(0, 0, -10)) stall(CFrame.lookAt(W + V(26, GROUND_Y, 98), arrive), { title = "💰 СКУПКА", titleColor = Color3.fromRGB(150, 255, 160), @@ -2633,6 +2678,8 @@ local function updateStats(player) player:SetAttribute("BoostBonus", boostActive(data)) player:SetAttribute("BoostLeft", math.max(0, data.boostUntil - os.time())) player:SetAttribute("TotalCaught", data.totalCaught) + -- шаг обучения (линия-подсказка); у старых игроков без поля, уже ловивших рыбу, обучение пройдено + player:SetAttribute("Tutorial", data.tutorial or (data.totalCaught > 0 and Config.TutorialDone or 0)) player:SetAttribute("Mastery", masteryCount(data)) player:SetAttribute("Passes", table.concat(ps, ",")) @@ -2955,6 +3002,28 @@ local function splash(part, count) end -- рыба вылетает из воды, летит к игроку и показывается над головой +-- шлейф за летящим предметом — эффект быстрого движения (ширина — расстояние между точками крепления) +local TRAIL_COLOR = Color3.fromRGB(215, 245, 255) +local function addTrail(part, width) + local a0 = Instance.new("Attachment") + a0.Position = Vector3.new(0, width / 2, 0) + a0.Parent = part + local a1 = Instance.new("Attachment") + a1.Position = Vector3.new(0, -width / 2, 0) + a1.Parent = part + local trail = Instance.new("Trail") + trail.Attachment0, trail.Attachment1 = a0, a1 + trail.FaceCamera = true + trail.Lifetime = 0.35 + trail.MinLength = 0.05 + trail.LightEmission = 0.7 + trail.Color = ColorSequence.new(TRAIL_COLOR) + trail.Transparency = NumberSequence.new({ NumberSequenceKeypoint.new(0, 0.1), NumberSequenceKeypoint.new(1, 1) }) + trail.WidthScale = NumberSequence.new({ NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(1, 0) }) + trail.Parent = part + return trail +end + local function showFishFlight(player, fish, fromPos) local head = player.Character and player.Character:FindFirstChild("Head") if not head then @@ -2963,6 +3032,14 @@ local function showFishFlight(player, fish, fromPos) local model = Models.buildFish(fish.id, fish.mutation, 0.9, true) model:PivotTo(CFrame.new(fromPos)) model.Parent = workspace + -- шлейф на отдельной невидимой детали: рыба крутится, а шлейф должен оставаться ровным + local carrier = Instance.new("Part") + carrier.Anchored, carrier.CanCollide, carrier.CanQuery, carrier.CanTouch = true, false, false, false + carrier.Transparency = 1 + carrier.Size = Vector3.new(0.2, 0.2, 0.2) + carrier.CFrame = CFrame.new(fromPos) + carrier.Parent = model + local trail = addTrail(carrier, 1.8) task.spawn(function() local t0, dur = os.clock(), 0.55 while head.Parent do @@ -2970,11 +3047,13 @@ local function showFishFlight(player, fish, fromPos) local target = head.Position + Vector3.new(0, 2.8, 0) local p = fromPos:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * 8, 0) model:PivotTo(CFrame.new(p) * CFrame.Angles(0, 0, a * math.pi * 2)) + carrier.CFrame = CFrame.new(p) if a >= 1 then break end RunService.Heartbeat:Wait() end + trail.Enabled = false local t1 = os.clock() while head.Parent and os.clock() - t1 < 1.8 do model:PivotTo(CFrame.new(head.Position + Vector3.new(0, 2.8, 0)) * CFrame.Angles(0, os.clock() * 3, math.rad(-15))) @@ -2988,22 +3067,59 @@ end local fishing = {} --- ищем воду перед игроком по карте мира из FishConfig (не зависит от террейна) -local function findWater(hrp, world) - local look = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) - if look.Magnitude < 0.01 then - look = Vector3.new(0, 0, -1) +-- ищем воду по карте мира из FishConfig (не зависит от террейна) в сторону центра ближайшего озера: +-- сначала на дальности, которую задала сила заброса, потом всё дальше от неё +local function findWater(hrp, world, power) + local look = Config.CastDirection(world, hrp.Position) + if not look then + look = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) + look = look.Magnitude > 0.01 and look.Unit or Vector3.new(0, 0, -1) end - look = look.Unit - for _, d in ipairs({ 14, 11, 17, 8, 20, 6, 24, 4 }) do - local p = hrp.Position + look * d - if Config.IsWater(world, p) then - return Vector3.new(p.X, world.waterY or 0, p.Z) + local want = Config.CastMinDist + (Config.CastMaxDist - Config.CastMinDist) * power + for off = 0, 26, 2 do + for _, d in ipairs({ want - off, want + off }) do + if d >= 4 and d <= Config.CastMaxDist + 2 then + local p = hrp.Position + look * d + if Config.IsWater(world, p) then + return Vector3.new(p.X, world.waterY or 0, p.Z), d + end + end end end return nil end +-- вытягивание пустого поплавка: быстро летит к кончику удочки со шлейфом и исчезает +local function reelBobber(bobber, tool) + local root = bobber and bobber.PrimaryPart + local tip = tool and tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") + if not root or not tip then + if bobber then + bobber:Destroy() + end + return + end + local trail = bobber:FindFirstChildWhichIsA("Trail", true) + if trail then + trail.Enabled = true + else + addTrail(root, 1.2) + end + local from = root.Position + task.spawn(function() + local t0, dur = os.clock(), 0.3 + while bobber.Parent and tip.Parent do + local a = math.min(1, (os.clock() - t0) / dur) + bobber:PivotTo(CFrame.new(from:Lerp(tip.WorldPosition, a) + Vector3.new(0, math.sin(a * math.pi) * 2.5, 0))) + if a >= 1 then + break + end + RunService.Heartbeat:Wait() + end + bobber:Destroy() + end) +end + local function stopFishing(player, tellClient) local s = fishing[player] if not s then @@ -3014,7 +3130,11 @@ local function stopFishing(player, tellClient) s.tween:Cancel() end if s.bobber then - s.bobber:Destroy() + if s.stage == "casting" then + s.bobber:Destroy() -- ещё летит: его двигает flyBobber + else + reelBobber(s.bobber, s.tool) + end end if s.tool then tweenGrip(s.tool, REST_ANGLE, 0.3) @@ -3024,12 +3144,12 @@ local function stopFishing(player, tellClient) end end -local function rollFish(player, data, worldId) +local function rollFish(player, data, worldId, luckMult) local zone = Config.Zones[worldId] if not zone then return nil end - local luck = totalLuck(player, data) + local luck = totalLuck(player, data) * (luckMult or 1) local bonus = luck - 1 local weights, total = {}, 0 for i, f in ipairs(zone.fish) do @@ -3071,13 +3191,14 @@ local function rollFish(player, data, worldId) } end -local function flyBobber(s, tool, target) +local function flyBobber(s, tool, target, dur, arc) local tip = tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") local start = tip and tip.WorldPosition or (target + Vector3.new(0, 6, 0)) local bobber = Models.buildBobber() bobber:PivotTo(CFrame.new(start)) bobber.Parent = workspace s.bobber = bobber + local trail = addTrail(bobber.PrimaryPart, 1.2) if tip then local a1 = Instance.new("Attachment") a1.Position = Vector3.new(0, 0.9, 0) @@ -3091,22 +3212,24 @@ local function flyBobber(s, tool, target) line.Color = ColorSequence.new(Color3.fromRGB(245, 245, 245)) line.Parent = bobber end - local t0, dur = os.clock(), 0.55 + local t0 = os.clock() while bobber.Parent do local a = math.min(1, (os.clock() - t0) / dur) - bobber:PivotTo(CFrame.new(start:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * 6, 0))) + bobber:PivotTo(CFrame.new(start:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * arc, 0))) if a >= 1 then break end RunService.Heartbeat:Wait() end + trail.Enabled = false -- на воде поплавок качается, шлейф уже не нужен if bobber.Parent then splash(bobber.PrimaryPart, 18) playSound(bobber.PrimaryPart, SPLASH_SOUND, 0.5) end end -local function onCast(player) +local function onCast(player, power) + power = math.clamp(tonumber(power) or 0.6, 0, 1) local data = profiles[player] if not data then return @@ -3123,10 +3246,13 @@ local function onCast(player) return end local world = Config.WorldAt(hrp.Position) - local target = world and findWater(hrp, world) + local target, dist = nil, 0 + if world then + target, dist = findWater(hrp, world, power) + end if not target then remote:FireClient(player, "CastFail") - notify(player, world and "Повернись лицом к воде (или к лунке)!" or "Здесь нет рыбы — иди в один из миров 🌍", Color3.fromRGB(255, 200, 120)) + notify(player, world and "Подойди ближе к воде (или к лунке)!" or "Здесь нет рыбы — иди в один из миров 🌍", Color3.fromRGB(255, 200, 120)) return end if #data.items >= bagCapacity(player, data) then @@ -3136,29 +3262,28 @@ local function onCast(player) end local stats = Config.RodStats(data.rod, rodLevel(data)) - local fish = rollFish(player, data, world.id) + local perfect = power >= Config.CastPerfect[1] and power <= Config.CastPerfect[2] + local fish = rollFish(player, data, world.id, perfect and Config.CastPerfectLuck or 1) if not fish then remote:FireClient(player, "CastFail") return end local s = { stage = "casting", fish = fish, tool = tool } fishing[player] = s - remote:FireClient(player, "Cast", target + Vector3.new(0, 0.15, 0)) -- клиенту для камеры + -- замах игрок уже сделал, пока держал кнопку (у себя на клиенте); здесь только бросок вперёд + local throw = { windup = 0.15, flight = 0.35 + dist * 0.018, arc = 2 + dist * 0.3, perfect = perfect } + local splashAt = target + Vector3.new(0, 0.15, 0) + remote:FireClient(player, "Cast", splashAt, throw) -- клиенту для камеры task.spawn(function() - -- замах назад и бросок вперёд - local tw = tweenGrip(tool, 100, 0.25) - if tw then - tw.Completed:Wait() - end - tw = tweenGrip(tool, 8, 0.15) + local tw = tweenGrip(tool, 8, throw.windup) if tw then tw.Completed:Wait() end if fishing[player] ~= s then return end - flyBobber(s, tool, target + Vector3.new(0, 0.15, 0)) + flyBobber(s, tool, splashAt, throw.flight, throw.arc) tweenGrip(tool, REST_ANGLE - 5, 0.4) if fishing[player] ~= s then if s.bobber then @@ -3223,11 +3348,14 @@ local function onCatch(player, success, misses) if s.tween then s.tween:Cancel() end - if s.bobber then - s.bobber:Destroy() + local failed = success ~= true or os.clock() - s.biteAt > Config.BiteTimeout + 1 + if failed then + reelBobber(s.bobber, tool) + elseif s.bobber then + s.bobber:Destroy() -- вместо поплавка к игроку летит рыба end - if success ~= true or os.clock() - s.biteAt > Config.BiteTimeout + 1 then + if failed then gripSequence(tool, { { REST_ANGLE, 0.3 } }) remote:FireClient(player, "Escaped") notify(player, "Рыба сорвалась!", RED) @@ -3508,7 +3636,15 @@ end) remote.OnServerEvent:Connect(function(player, action, a, b) if action == "Cast" then - onCast(player) + onCast(player, a) + elseif action == "Tutorial" then + -- шаги обучения идут только вперёд + local data = profiles[player] + local step = math.floor(tonumber(a) or 0) + if data and step > (player:GetAttribute("Tutorial") or 0) and step <= Config.TutorialDone then + data.tutorial = step + player:SetAttribute("Tutorial", step) + end elseif action == "Catch" then onCatch(player, a, b) elseif action == "Cancel" then @@ -4749,8 +4885,15 @@ refreshHud() local state = "idle" local mg = { pos = 0, dir = 1, speed = 1, zoneStart = 0.4, zoneWidth = 0.25, hits = 0, need = 1, misses = 0, maxMisses = 2, deadline = 0, timeout = 10 } --- пока удочка заброшена, ходить и прыгать нельзя +-- с начала зарядки и до конца рыбалки персонажем не управляем: не ходит, не прыгает, не поворачивается +local ContextActionService = game:GetService("ContextActionService") +local MOVE_KEYS = { + Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D, Enum.KeyCode.Space, + Enum.KeyCode.Up, Enum.KeyCode.Down, Enum.KeyCode.Left, Enum.KeyCode.Right, + Enum.KeyCode.Thumbstick1, Enum.KeyCode.ButtonA, +} local controls +local movementLocked = false local function setMovementLocked(locked) if not controls then local pm = player:FindFirstChild("PlayerScripts") and player.PlayerScripts:FindFirstChild("PlayerModule") @@ -4764,17 +4907,26 @@ local function setMovementLocked(locked) controls:Enable() end end + if locked ~= movementLocked then + movementLocked = locked + if locked then + ContextActionService:BindActionAtPriority("FishingLock", function() + return Enum.ContextActionResult.Sink + end, false, Enum.ContextActionPriority.High.Value + 100, table.unpack(MOVE_KEYS)) + else + ContextActionService:UnbindAction("FishingLock") + end + end + local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid") + if hum then + hum.AutoRotate = not locked + hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, not locked) + if locked then + hum:Move(Vector3.zero) + end + end end ----------------------------------------------------------------- камера при забросе --- замах: камера отъезжает и расширяется обзор; полёт: камера разгоняется за поплавком; --- потом смотрит на поплавок, пока рыбалка не закончится, и плавно возвращается - -local CAST_WINDUP, CAST_FLIGHT = 0.4, 0.55 -- как в GameServer: замах и полёт поплавка -local CAM_SETTLE, CAM_RETURN = 0.7, 0.6 -local UP = Vector3.new(0, 1, 0) -local fishCam = nil - local function easeInOut(a) return a < 0.5 and 4 * a * a * a or 1 - (-2 * a + 2) ^ 3 / 2 end @@ -4782,6 +4934,100 @@ local function easeOut(a) return 1 - (1 - a) ^ 3 end +---------------------------------------------------------------- заброс: зарядка, шкала силы, наклон удочки +-- держишь ЛКМ — сила растёт, удочка уходит назад; отпустил — бросок на дальность по силе + +local REST_ANGLE, BACK_ANGLE = 30, 110 -- удочка в покое (как в GameServer) и в полном замахе +local function gripCF(angle) + return (CFrame.Angles(math.rad(angle), 0, 0) * CFrame.new(0, 0, -0.3)):Inverse() +end + +local charge = nil -- { t0, tool } +local castTool = nil -- удочка последнего броска: вернуть её в покой, если бросок не удался +local function chargePower() + return charge and math.min(1, (os.clock() - charge.t0) / Config.CastChargeTime) or 0 +end +local function inPerfect(v) + return v >= Config.CastPerfect[1] and v <= Config.CastPerfect[2] +end + +-- шкала-дуга справа от персонажа: внизу слабый бросок, вверху сильный, зелёная зона — бонус удачи +local GAUGE_R, GAUGE_DEG, GAUGE_N = 190, 110, 32 +local gauge = new("Frame", { + Size = UDim2.fromOffset(150, 280), AnchorPoint = Vector2.new(0, 0.5), Position = UDim2.new(0.57, 0, 0.48, 0), + BackgroundTransparency = 1, Visible = false, Parent = gui, +}) +local GAUGE_C = Vector2.new(110 - GAUGE_R, 140) -- центр окружности левее рамки: дуга выгнута вправо +local function arcPoint(v, r) + local th = math.rad(-GAUGE_DEG / 2 + GAUGE_DEG * v) + return GAUGE_C + Vector2.new(math.cos(th) * r, -math.sin(th) * r), -math.deg(th) +end +do + local segLen = 2 * math.pi * GAUGE_R * (GAUGE_DEG / 360) / GAUGE_N + for _, layer in ipairs({ { 46, 4, BLACK }, { 34, 1 } }) do -- чёрная обводка, потом цветные секции + for i = 0, GAUGE_N - 1 do + local v = (i + 0.5) / GAUGE_N + local pos, rot = arcPoint(v, GAUGE_R) + local color = layer[3] + or ((v < 0.12 or v > 0.94) and C.red) + or (inPerfect(v) and Color3.fromRGB(110, 235, 60)) + or Color3.fromRGB(40, 70, 95) + new("Frame", { + Size = UDim2.fromOffset(layer[1], segLen + layer[2]), AnchorPoint = Vector2.new(0.5, 0.5), + Position = UDim2.fromOffset(pos.X, pos.Y), Rotation = rot, BorderSizePixel = 0, + BackgroundColor3 = color, Parent = gauge, + }) + end + end +end +local needle = new("Frame", { + Size = UDim2.fromOffset(64, 8), AnchorPoint = Vector2.new(0.5, 0.5), BackgroundColor3 = WHITE, + BorderSizePixel = 0, ZIndex = 3, Parent = gauge, +}, { corner(4), stroke(BLACK, 2) }) +local multLabel = text({ + Size = UDim2.fromOffset(110, 40), AnchorPoint = Vector2.new(0.5, 1), Font = TITLE, TextSize = 34, + Text = "×" .. Config.CastPerfectLuck, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 4, + Visible = false, Parent = gauge, +}) +new("UIStroke", { Color = BLACK, Thickness = 3, Parent = multLabel }) +do + local top = arcPoint(1, GAUGE_R) + multLabel.Position = UDim2.fromOffset(top.X + 10, top.Y - 18) +end + +local function updateCharge() + local p = chargePower() + local pos, rot = arcPoint(p, GAUGE_R) + needle.Position = UDim2.fromOffset(pos.X, pos.Y) + needle.Rotation = rot + local good = inPerfect(p) + multLabel.Visible = good + needle.BackgroundColor3 = good and Color3.fromRGB(190, 255, 150) or WHITE + if charge.tool and charge.tool.Parent then + charge.tool.Grip = gripCF(REST_ANGLE + (BACK_ANGLE - REST_ANGLE) * easeOut(p)) + end +end + +---------------------------------------------------------------- камера при забросе +-- зарядка: камера уходит в сторону от персонажа и отъезжает тем дальше, чем сильнее замах; +-- бросок: камера сбоку разгоняется за поплавком; потом сверху-сбоку держит в кадре игрока и поплавок + +local CAM_IN, CAM_SETTLE, CAM_RETURN = 0.35, 0.8, 0.6 +local UP = Vector3.new(0, 1, 0) +local fishCam = nil + +local function sideCF(fc, p) + return CFrame.lookAt(fc.hrp + fc.r * (9 + 3 * p) - fc.f * (3 + 2 * p) + UP * (3 + 1.5 * p), fc.hrp + fc.f * 6 + UP) +end +local function chaseCF(fc, p) + return CFrame.lookAt(p + fc.r * 9 - fc.f * 5 + UP * 3, p + fc.f * 3) +end +local function restCF(fc) + local d = ((fc.target - fc.hrp) * Vector3.new(1, 0, 1)).Magnitude + local mid = fc.hrp:Lerp(fc.target, 0.5) + return CFrame.lookAt(mid + fc.r * (8 + d * 0.55) - fc.f * 4 + UP * (6 + d * 0.25), fc.hrp:Lerp(fc.target, 0.6)) +end + local function fishCamStep() local fc = fishCam local cam = workspace.CurrentCamera @@ -4800,62 +5046,80 @@ local function fishCamStep() end return end - local t = os.clock() - fc.t0 + local now = os.clock() local cf, fov - if t < CAST_WINDUP then - local e = easeOut(t / CAST_WINDUP) - cf = fc.origCF:Lerp(fc.windupCF, e) - fov = fc.origFov + 14 * e - elseif t < CAST_WINDUP + CAST_FLIGHT then - if not fc.start then - fc.start = (fc.tip and fc.tip.Parent and fc.tip.WorldPosition) or fc.fallbackStart - end - local a = (t - CAST_WINDUP) / CAST_FLIGHT - local p = fc.start:Lerp(fc.target, a) + UP * (math.sin(a * math.pi) * 6) -- та же дуга, что у поплавка - local chase = CFrame.lookAt(p - fc.flat * 9 + UP * 3.5, p + fc.flat * 4) - local e = easeInOut(a) - cf = fc.windupCF:Lerp(chase, e) - fov = fc.origFov + 14 - 22 * e + if not fc.castT0 then + -- зарядка: плавно уходим в вид сбоку; чем сильнее замах, тем дальше камера и шире обзор + -- после отпускания ЛКМ, пока ждём ответ сервера, держим набранную силу + local p = charge and chargePower() or (fc.power or 0) + fc.power = p + local e = easeOut(math.min(1, (now - fc.t0) / CAM_IN)) + cf = fc.origCF:Lerp(sideCF(fc, p), e) + fov = fc.origFov + 12 * p * e else - local e = easeOut(math.min(1, (t - CAST_WINDUP - CAST_FLIGHT) / CAM_SETTLE)) - local now = os.clock() - local sway = Vector3.new(math.sin(now * 0.7) * 0.5, math.sin(now * 1.1) * 0.25, 0) - if state == "bite" then - sway += Vector3.new(math.random() - 0.5, math.random() - 0.5, 0) * 0.15 + local th = fc.throw + local t = now - fc.castT0 + local lunge = fc.fromCF + fc.f * 1.5 + if t < th.windup then + -- рывок удочки вперёд: камера подаётся следом + local e = easeOut(t / th.windup) + cf = fc.fromCF:Lerp(lunge, e) + fov = fc.fromFov + 4 * e + elseif t < th.windup + th.flight then + if not fc.start then + fc.start = (fc.tip and fc.tip.Parent and fc.tip.WorldPosition) or (fc.hrp + fc.f * 2 + UP * 4) + end + local a = (t - th.windup) / th.flight + local p = fc.start:Lerp(fc.target, a) + UP * (math.sin(a * math.pi) * th.arc) -- та же дуга, что у поплавка + local e = easeInOut(a) + cf = lunge:Lerp(chaseCF(fc, p), e) + fov = (fc.fromFov + 4) + ((fc.origFov - 6) - (fc.fromFov + 4)) * e + else + local e = easeOut(math.min(1, (t - th.windup - th.flight) / CAM_SETTLE)) + local sway = Vector3.new(math.sin(now * 0.7) * 0.5, math.sin(now * 1.1) * 0.25, 0) + if state == "bite" then + sway += Vector3.new(math.random() - 0.5, math.random() - 0.5, 0) * 0.15 + end + cf = chaseCF(fc, fc.target):Lerp(restCF(fc) + sway, e) + fov = fc.origFov - 6 + 6 * e end - cf = fc.landCF:Lerp(fc.restCF + sway, e) - fov = fc.origFov - 8 + 8 * e end cam.CFrame = cf cam.FieldOfView = fov end -local function startFishCam(target) +-- начало зарядки: dir — куда полетит поплавок (к центру озера) +local function startChargeCam(tool, dir) local cam = workspace.CurrentCamera - local char = player.Character - local hrp = char and char:FindFirstChild("HumanoidRootPart") - if not cam or not hrp or typeof(target) ~= "Vector3" then + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + if not cam or not hrp then return end - local flat = (target - hrp.Position) * Vector3.new(1, 0, 1) - flat = flat.Magnitude > 0.1 and flat.Unit or hrp.CFrame.LookVector - local tool = char:FindFirstChildOfClass("Tool") - local tip = tool and tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") fishCam = { - t0 = os.clock(), target = target, flat = flat, tip = tip, - fallbackStart = hrp.Position + flat * 2 + UP * 4, + t0 = os.clock(), hrp = hrp.Position, f = dir, r = dir:Cross(UP), + tip = tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip"), -- если камера ещё возвращалась с прошлого заброса, возвращаться будем туда же origCF = fishCam and fishCam.origCF or cam.CFrame, origFov = fishCam and fishCam.origFov or cam.FieldOfView, - windupCF = CFrame.lookAt(hrp.Position - flat * 13 + UP * 7, hrp.Position:Lerp(target, 0.5)), - landCF = CFrame.lookAt(target - flat * 9 + UP * 3.5, target + flat * 4), - restCF = CFrame.lookAt(target - flat * 11 + UP * 5.5, target), } cam.CameraType = Enum.CameraType.Scriptable RunService:UnbindFromRenderStep("FishCam") RunService:BindToRenderStep("FishCam", Enum.RenderPriority.Camera.Value + 1, fishCamStep) end +-- сервер принял бросок: target — куда упадёт поплавок, throw — тайминги и высота дуги +local function startCastCam(target, throw) + local cam = workspace.CurrentCamera + if not fishCam or fishCam.returning or not cam or typeof(target) ~= "Vector3" or type(throw) ~= "table" then + return + end + fishCam.castT0 = os.clock() + fishCam.target = target + fishCam.throw = throw + fishCam.fromCF = cam.CFrame + fishCam.fromFov = cam.FieldOfView +end + local function stopFishCam() local cam = workspace.CurrentCamera if not fishCam or fishCam.returning or not cam then @@ -4868,9 +5132,17 @@ end local reelToken local function setState(s) + if s ~= "charging" and charge then + -- зарядку прервали (убрал удочку и т.п.): удочку обратно в покой + if charge.tool.Parent then + charge.tool.Grip = gripCF(REST_ANGLE) + end + charge = nil + end state = s statusLabel.Visible = (s == "waiting") mgFrame.Visible = (s == "bite") + gauge.Visible = (s == "charging") setMovementLocked(s ~= "idle") if s == "idle" then stopFishCam() @@ -4899,11 +5171,39 @@ local function placeZone() zoneF.Position = UDim2.fromScale(mg.zoneStart, 0) end +-- ЛКМ зажата: персонаж разворачивается к центру озера, начинается зарядка +local function startCharge(tool) + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + if not hrp then + return + end + local world = Config.WorldAt(hrp.Position) + local dir = world and Config.CastDirection(world, hrp.Position) + if not dir then + dir = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) + dir = dir.Magnitude > 0.01 and dir.Unit or Vector3.new(0, 0, -1) + end + hrp.CFrame = CFrame.lookAt(hrp.Position, hrp.Position + dir) + charge = { t0 = os.clock(), tool = tool } + setState("charging") + startChargeCam(tool, dir) + updateCharge() +end + +-- ЛКМ отпущена: бросок с набранной силой +local function releaseCast() + if state ~= "charging" or not charge then + return + end + local power = chargePower() + castTool = charge.tool + charge = nil -- удочку не возвращаем: сервер сам сделает рывок вперёд + setState("casting") + remote:FireServer("Cast", power) +end + local function onActivate() - if state == "idle" then - setState("casting") - remote:FireServer("Cast") - elseif state == "waiting" then + if state == "waiting" then remote:FireServer("Cancel") setState("idle") elseif state == "bite" then @@ -4937,7 +5237,14 @@ local function hookTool(tool) return end hooked[tool] = true - tool.Activated:Connect(onActivate) + tool.Activated:Connect(function() + if state == "idle" then + startCharge(tool) + else + onActivate() + end + end) + tool.Deactivated:Connect(releaseCast) tool.Unequipped:Connect(function() if state == "waiting" or state == "bite" or state == "casting" then remote:FireServer("Cancel") @@ -4967,6 +5274,12 @@ if player.Character then watch(player.Character) end +RunService.RenderStepped:Connect(function() + if state == "charging" and charge then + updateCharge() + end +end) + RunService.RenderStepped:Connect(function(dt) if state ~= "bite" then return @@ -5062,6 +5375,170 @@ task.spawn(function() end end) +---------------------------------------------------------------- обучение: линия-подсказка +-- белые «стрелки» бегут по земле от игрока к цели текущего шага (см. Config.TutorialDone) + +local GUIDE_N, GUIDE_GAP, GUIDE_SPEED = 32, 3, 7 -- сколько стрелок, шаг между ними, скорость бега +local W1 = Config.Worlds[1].center +local guideStep = 0 -- шаг, отправленный на сервер (атрибут Tutorial может прийти чуть позже) + +local guideHint = text({ + Size = UDim2.fromOffset(560, 42), AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, 64), + BackgroundTransparency = 0.2, BackgroundColor3 = C.bg, Font = TITLE, TextSize = 20, + TextXAlignment = Enum.TextXAlignment.Center, Visible = false, Parent = gui, +}, nil) +corner(12).Parent = guideHint +stroke(C.gold, 2).Parent = guideHint + +local guideFolder = new("Folder", { Name = "TutorialGuide", Parent = workspace }) +local chevrons = {} +for i = 1, GUIDE_N do + local arms = {} + for k = 1, 2 do + arms[k] = new("Part", { + Anchored = true, CanCollide = false, CanQuery = false, CanTouch = false, CastShadow = false, + Material = Enum.Material.Neon, Color = WHITE, Size = Vector3.new(0.32, 0.06, 1.35), Transparency = 1, + Parent = guideFolder, + }) + end + chevrons[i] = arms +end +-- две «палочки» стрелки «>» острием вперёд (по -Z) +local ARM_CF = {} +for k, s in ipairs({ -1, 1 }) do + local center = Vector3.new(s * 0.45, 0, -0.1) + ARM_CF[k] = CFrame.lookAt(center, center + Vector3.new(s * 0.9, 0, 1)) +end +local function hideChevrons(from) + for i = from, GUIDE_N do + chevrons[i][1].Transparency = 1 + chevrons[i][2].Transparency = 1 + end +end + +local guideRay = RaycastParams.new() +guideRay.FilterType = Enum.RaycastFilterType.Exclude +guideRay.RespectCanCollide = true +guideRay.IgnoreWater = false + +local function tutorialStep() + return math.max(player:GetAttribute("Tutorial") or 0, guideStep) +end +local function advanceTutorial(step) + if step > tutorialStep() then + guideStep = step + remote:FireServer("Tutorial", step) + if step >= Config.TutorialDone then + notify("🎓 Обучение пройдено! Дальше — сам: лови, улучшай удочку, открывай миры", C.gold) + end + end +end + +local function guideMarker(name) + local map = workspace:FindFirstChild("FishingMap") + local m = map and map:FindFirstChild(name) + return m and m.Position +end + +-- маршрут для текущего шага: точки ломаной (без игрока) и подсказка; nil — линию не показываем +local function guideRoute(step, pos, world) + local inW1 = world and world.id == "World1" + if step == 0 and not world then + return { guideMarker("GuideBoard") }, "📋 Прочитай табличку «Как играть»" + elseif not world then -- шаги 1–3 из лобби: сначала в портал + return { guideMarker("GuidePortal") }, "🌊 Иди в портал «Тихое озеро»" + elseif step == 2 and inW1 then + return { guideMarker("GuideFishSpot") }, "🎣 Иди на причал, зажми ЛКМ и отпусти — заброс!" + elseif step == 3 and inW1 then + local route = {} + local rel = pos - W1 + if math.abs(rel.X) < 6 and rel.Z < 80 then + table.insert(route, W1 + Vector3.new(0, 4.5, 84)) -- сначала сойти с причала + end + table.insert(route, guideMarker("GuideSell")) + return route, "💰 Продай рыбу в скупке" + end + return nil +end + +RunService.RenderStepped:Connect(function() + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + local step = tutorialStep() + -- пока сервер не прислал шаг (данные ещё грузятся), ничего не показываем + if not hrp or player:GetAttribute("Tutorial") == nil or step >= Config.TutorialDone then + guideHint.Visible = false + hideChevrons(1) + return + end + local pos = hrp.Position + local world = Config.WorldAt(pos) + + -- переходы между шагами + if step <= 1 and world and world.id == "World1" then + advanceTutorial(2) + elseif step == 0 then + local board = guideMarker("GuideBoard") + if board and (board - pos).Magnitude < 9 then + advanceTutorial(1) + end + elseif step == 2 and (player:GetAttribute("TotalCaught") or 0) > 0 then + advanceTutorial(3) + end + step = tutorialStep() + + local route, hint = guideRoute(step, pos, world) + guideHint.Text = hint or "" + guideHint.Visible = hint ~= nil and state == "idle" + if not route or #route == 0 or state ~= "idle" then + hideChevrons(1) + return + end + + -- ломаная от ног игрока через точки маршрута + local pts = { pos - Vector3.new(0, 3, 0) } + for _, p in ipairs(route) do + table.insert(pts, p) + end + local lens, total = {}, 0 + for i = 2, #pts do + local d = ((pts[i] - pts[i - 1]) * Vector3.new(1, 0, 1)).Magnitude + lens[i] = math.max(d, 0.001) + total += d + end + if total < 4 then + hideChevrons(1) -- уже на месте + return + end + + guideRay.FilterDescendantsInstances = { player.Character, guideFolder } + local phase = (os.clock() * GUIDE_SPEED) % GUIDE_GAP + local seg, segStart = 2, 0 + for i = 1, GUIDE_N do + local d = 2 + phase + (i - 1) * GUIDE_GAP + if d > total - 1 then + hideChevrons(i) + break + end + while seg < #pts and d > segStart + lens[seg] do + segStart += lens[seg] + seg += 1 + end + local a, b = pts[seg - 1], pts[seg] + local p = a:Lerp(b, (d - segStart) / lens[seg]) + local dir = (b - a) * Vector3.new(1, 0, 1) + local hit = workspace:Raycast(p + Vector3.new(0, 4, 0), Vector3.new(0, -12, 0), guideRay) + local y = hit and hit.Position.Y or p.Y + local base = CFrame.lookAt(Vector3.new(p.X, y + 0.08, p.Z), Vector3.new(p.X, y + 0.08, p.Z) + dir) + -- у игрока и у цели стрелки плавно проявляются и гаснут + local fade = math.max(0, 1 - math.min(d - 2, total - 1 - d) / 2.5) + local tr = 0.1 + 0.9 * fade + for k = 1, 2 do + chevrons[i][k].CFrame = base * ARM_CF[k] + chevrons[i][k].Transparency = tr + end + end +end) + ---------------------------------------------------------------- события от сервера remote.OnClientEvent:Connect(function(action, a, b, c) @@ -5069,8 +5546,11 @@ remote.OnClientEvent:Connect(function(action, a, b, c) notify(a, b) elseif action == "Cast" then setState("waiting") - startFishCam(a) + startCastCam(a, b) elseif action == "CastFail" or action == "Cancel" or action == "Escaped" then + if action == "CastFail" and castTool and castTool.Parent then + castTool.Grip = gripCF(REST_ANGLE) -- сервер удочку не трогал, а у нас она в замахе + end setState("idle") elseif action == "Bite" then mg.speed = a.speed @@ -5090,6 +5570,9 @@ remote.OnClientEvent:Connect(function(action, a, b, c) showCatch(a, b) playUiSound(DING, 0.5) elseif action == "Sold" then + if tutorialStep() == 3 then + advanceTutorial(Config.TutorialDone) + end floatText("+" .. fmt(a) .. " 💰", C.gold) notify(("Продано рыб: %d → +%s 💰"):format(b, fmt(a)), Color3.fromRGB(120, 255, 140)) elseif action == "Inventory" then diff --git a/install/1_FishConfig_ReplicatedStorage.rbxmx b/install/1_FishConfig_ReplicatedStorage.rbxmx index 7cfdb12..9a2918a 100644 --- a/install/1_FishConfig_ReplicatedStorage.rbxmx +++ b/install/1_FishConfig_ReplicatedStorage.rbxmx @@ -58,6 +58,35 @@ function Config.WorldAt(pos) return nil end +-- куда бросать из этой точки (единичный вектор по горизонтали): к центру ближайшего озера или лунки, +-- а если ближе море — от центра острова к морю +function Config.CastDirection(world, pos) + if not world then + return nil + end + local x, z = pos.X - world.center.X, pos.Z - world.center.Z + local best, bestGap + local function consider(dir, gap) + if dir.Magnitude > 0.1 and (not bestGap or gap < bestGap) then + best, bestGap = dir.Unit, gap + end + end + if world.holes then + for _, h in ipairs(world.holes) do + consider(Vector3.new(h[1] - x, 0, h[2] - z), math.sqrt((h[1] - x) ^ 2 + (h[2] - z) ^ 2) - (world.holeRadius or 6)) + end + end + for _, l in ipairs(world.lakes or {}) do + if not world.holes then -- в Мире 3 озёра подо льдом, бросаем только в лунки + consider(Vector3.new(l[1] - x, 0, l[2] - z), math.sqrt((l[1] - x) ^ 2 + (l[2] - z) ^ 2) - l[3]) + end + end + if world.sea then + consider(Vector3.new(x, 0, z), world.sea - math.sqrt(x * x + z * z)) + end + return best +end + -- есть ли вода в этой точке мира (озеро, море или лунка) function Config.IsWater(world, pos) if not world then @@ -264,6 +293,15 @@ Config.BiteTimeMin = 3 Config.BiteTimeMax = 7 Config.BiteTimeout = 12 Config.MaxMisses = 2 +-- заброс: держишь ЛКМ — сила растёт от 0 до 1; от силы зависит дальность +Config.CastChargeTime = 1.3 -- секунд до полной силы +Config.CastMinDist, Config.CastMaxDist = 6, 28 +Config.CastPerfect = { 0.72, 0.86 } -- зелёная зона шкалы +Config.CastPerfectLuck = 1.2 -- множитель удачи за попадание в зелёную зону + +-- обучение: линия-подсказка ведёт по шагам 0 → 1 → 2 → 3, на 4 обучение пройдено +-- 0 — табличка «Как играть», 1 — портал в Мир 1, 2 — причал (поймать рыбу), 3 — скупка (продать) +Config.TutorialDone = 4 function Config.HitsNeeded(rank) return math.ceil(rank / 2) end diff --git a/install/3_MapBuilder_ServerScriptService.rbxmx b/install/3_MapBuilder_ServerScriptService.rbxmx index b966c47..5ccd8ce 100644 --- a/install/3_MapBuilder_ServerScriptService.rbxmx +++ b/install/3_MapBuilder_ServerScriptService.rbxmx @@ -678,6 +678,9 @@ for i, w in ipairs(Config.Worlds) do local a = math.rad(90 - (i - 1) * 90) -- 90° = сторона спавна (+Z) local pos = V(math.cos(a) * PORTAL_R, FLOOR, math.sin(a) * PORTAL_R) portal(CFrame.lookAt(pos, V(pos.X * 2, FLOOR, pos.Z * 2)), title, w.color, w.id, w.soon) + if i == 1 then + marker("GuidePortal", CFrame.new(pos.X * 1.3, FLOOR, pos.Z * 1.3)) -- точка перед порталом для линии-подсказки + end end -- невидимая стена по кругу: из лобби не уйти @@ -762,12 +765,13 @@ do local pos = V(-12, FLOOR, 48) local cf = CFrame.lookAt(pos, V(0, FLOOR, 64)) lamp((cf * CFrame.new(0, 0, 2.5)).Position) + marker("GuideBoard", cf * CFrame.new(0, 0, -6)) -- перед табличкой, для линии-подсказки for _, x in ipairs({ -6.5, 6.5 }) do P({ Size = V(0.8, 9, 0.8), CFrame = cf * CFrame.new(x, 4.5, 0.3), Material = Enum.Material.Wood, Color = Color3.fromRGB(90, 60, 40) }) end local board = P({ Size = V(14, 8, 0.5), CFrame = cf * CFrame.new(0, 6, 0), Material = Enum.Material.WoodPlanks, Color = Color3.fromRGB(70, 48, 32) }) surfaceText(board, Enum.NormalId.Front, - "КАК ИГРАТЬ\n1. Портал «Мир 1» или кнопка 🌍 Миры\n2. Удочка — клавиша 1, клик у воды\n3. Клюёт → кликай в зелёную зону\n4. 🎒 Сумка — B, 📜 Задания — Q\n5. Собирай коллекцию — получай награды!", + "КАК ИГРАТЬ\n1. Портал «Мир 1» или кнопка 🌍 Миры\n2. Удочка — клавиша 1, у воды зажми ЛКМ и отпусти\n3. Клюёт → кликай в зелёную зону\n4. 🎒 Сумка — B, 📜 Задания — Q\n5. Собирай коллекцию — получай награды!", Color3.fromRGB(255, 245, 225), { TextXAlignment = Enum.TextXAlignment.Left }) end @@ -788,6 +792,9 @@ local arrive = W + V(0, GROUND_Y, 94) marker("World1Spawn", CFrame.lookAt(arrive + V(0, 1, 0), arrive + V(0, 1, -10))) arch(CFrame.new(W + V(0, GROUND_Y, 82)), 14, 11, "🌊 ТИХОЕ ОЗЕРО", Color3.fromRGB(80, 200, 255)) portal(CFrame.lookAt(W + V(-22, GROUND_Y, 96), arrive), "🏠 В лобби", Color3.fromRGB(255, 200, 80), "Lobby") +-- точки для линии-подсказки: конец главного причала и место перед скупкой +marker("GuideFishSpot", CFrame.new(W + V(0, GROUND_Y + 0.5, 42))) +marker("GuideSell", CFrame.lookAt(W + V(26, GROUND_Y, 98), arrive) * CFrame.new(0, 0, -10)) stall(CFrame.lookAt(W + V(26, GROUND_Y, 98), arrive), { title = "💰 СКУПКА", titleColor = Color3.fromRGB(150, 255, 160), diff --git a/install/4_GameServer_ServerScriptService.rbxmx b/install/4_GameServer_ServerScriptService.rbxmx index 7fbfa3b..535cdf0 100644 --- a/install/4_GameServer_ServerScriptService.rbxmx +++ b/install/4_GameServer_ServerScriptService.rbxmx @@ -220,6 +220,8 @@ local function updateStats(player) player:SetAttribute("BoostBonus", boostActive(data)) player:SetAttribute("BoostLeft", math.max(0, data.boostUntil - os.time())) player:SetAttribute("TotalCaught", data.totalCaught) + -- шаг обучения (линия-подсказка); у старых игроков без поля, уже ловивших рыбу, обучение пройдено + player:SetAttribute("Tutorial", data.tutorial or (data.totalCaught > 0 and Config.TutorialDone or 0)) player:SetAttribute("Mastery", masteryCount(data)) player:SetAttribute("Passes", table.concat(ps, ",")) @@ -542,6 +544,28 @@ local function splash(part, count) end -- рыба вылетает из воды, летит к игроку и показывается над головой +-- шлейф за летящим предметом — эффект быстрого движения (ширина — расстояние между точками крепления) +local TRAIL_COLOR = Color3.fromRGB(215, 245, 255) +local function addTrail(part, width) + local a0 = Instance.new("Attachment") + a0.Position = Vector3.new(0, width / 2, 0) + a0.Parent = part + local a1 = Instance.new("Attachment") + a1.Position = Vector3.new(0, -width / 2, 0) + a1.Parent = part + local trail = Instance.new("Trail") + trail.Attachment0, trail.Attachment1 = a0, a1 + trail.FaceCamera = true + trail.Lifetime = 0.35 + trail.MinLength = 0.05 + trail.LightEmission = 0.7 + trail.Color = ColorSequence.new(TRAIL_COLOR) + trail.Transparency = NumberSequence.new({ NumberSequenceKeypoint.new(0, 0.1), NumberSequenceKeypoint.new(1, 1) }) + trail.WidthScale = NumberSequence.new({ NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(1, 0) }) + trail.Parent = part + return trail +end + local function showFishFlight(player, fish, fromPos) local head = player.Character and player.Character:FindFirstChild("Head") if not head then @@ -550,6 +574,14 @@ local function showFishFlight(player, fish, fromPos) local model = Models.buildFish(fish.id, fish.mutation, 0.9, true) model:PivotTo(CFrame.new(fromPos)) model.Parent = workspace + -- шлейф на отдельной невидимой детали: рыба крутится, а шлейф должен оставаться ровным + local carrier = Instance.new("Part") + carrier.Anchored, carrier.CanCollide, carrier.CanQuery, carrier.CanTouch = true, false, false, false + carrier.Transparency = 1 + carrier.Size = Vector3.new(0.2, 0.2, 0.2) + carrier.CFrame = CFrame.new(fromPos) + carrier.Parent = model + local trail = addTrail(carrier, 1.8) task.spawn(function() local t0, dur = os.clock(), 0.55 while head.Parent do @@ -557,11 +589,13 @@ local function showFishFlight(player, fish, fromPos) local target = head.Position + Vector3.new(0, 2.8, 0) local p = fromPos:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * 8, 0) model:PivotTo(CFrame.new(p) * CFrame.Angles(0, 0, a * math.pi * 2)) + carrier.CFrame = CFrame.new(p) if a >= 1 then break end RunService.Heartbeat:Wait() end + trail.Enabled = false local t1 = os.clock() while head.Parent and os.clock() - t1 < 1.8 do model:PivotTo(CFrame.new(head.Position + Vector3.new(0, 2.8, 0)) * CFrame.Angles(0, os.clock() * 3, math.rad(-15))) @@ -575,22 +609,59 @@ end local fishing = {} --- ищем воду перед игроком по карте мира из FishConfig (не зависит от террейна) -local function findWater(hrp, world) - local look = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) - if look.Magnitude < 0.01 then - look = Vector3.new(0, 0, -1) +-- ищем воду по карте мира из FishConfig (не зависит от террейна) в сторону центра ближайшего озера: +-- сначала на дальности, которую задала сила заброса, потом всё дальше от неё +local function findWater(hrp, world, power) + local look = Config.CastDirection(world, hrp.Position) + if not look then + look = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) + look = look.Magnitude > 0.01 and look.Unit or Vector3.new(0, 0, -1) end - look = look.Unit - for _, d in ipairs({ 14, 11, 17, 8, 20, 6, 24, 4 }) do - local p = hrp.Position + look * d - if Config.IsWater(world, p) then - return Vector3.new(p.X, world.waterY or 0, p.Z) + local want = Config.CastMinDist + (Config.CastMaxDist - Config.CastMinDist) * power + for off = 0, 26, 2 do + for _, d in ipairs({ want - off, want + off }) do + if d >= 4 and d <= Config.CastMaxDist + 2 then + local p = hrp.Position + look * d + if Config.IsWater(world, p) then + return Vector3.new(p.X, world.waterY or 0, p.Z), d + end + end end end return nil end +-- вытягивание пустого поплавка: быстро летит к кончику удочки со шлейфом и исчезает +local function reelBobber(bobber, tool) + local root = bobber and bobber.PrimaryPart + local tip = tool and tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") + if not root or not tip then + if bobber then + bobber:Destroy() + end + return + end + local trail = bobber:FindFirstChildWhichIsA("Trail", true) + if trail then + trail.Enabled = true + else + addTrail(root, 1.2) + end + local from = root.Position + task.spawn(function() + local t0, dur = os.clock(), 0.3 + while bobber.Parent and tip.Parent do + local a = math.min(1, (os.clock() - t0) / dur) + bobber:PivotTo(CFrame.new(from:Lerp(tip.WorldPosition, a) + Vector3.new(0, math.sin(a * math.pi) * 2.5, 0))) + if a >= 1 then + break + end + RunService.Heartbeat:Wait() + end + bobber:Destroy() + end) +end + local function stopFishing(player, tellClient) local s = fishing[player] if not s then @@ -601,7 +672,11 @@ local function stopFishing(player, tellClient) s.tween:Cancel() end if s.bobber then - s.bobber:Destroy() + if s.stage == "casting" then + s.bobber:Destroy() -- ещё летит: его двигает flyBobber + else + reelBobber(s.bobber, s.tool) + end end if s.tool then tweenGrip(s.tool, REST_ANGLE, 0.3) @@ -611,12 +686,12 @@ local function stopFishing(player, tellClient) end end -local function rollFish(player, data, worldId) +local function rollFish(player, data, worldId, luckMult) local zone = Config.Zones[worldId] if not zone then return nil end - local luck = totalLuck(player, data) + local luck = totalLuck(player, data) * (luckMult or 1) local bonus = luck - 1 local weights, total = {}, 0 for i, f in ipairs(zone.fish) do @@ -658,13 +733,14 @@ local function rollFish(player, data, worldId) } end -local function flyBobber(s, tool, target) +local function flyBobber(s, tool, target, dur, arc) local tip = tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") local start = tip and tip.WorldPosition or (target + Vector3.new(0, 6, 0)) local bobber = Models.buildBobber() bobber:PivotTo(CFrame.new(start)) bobber.Parent = workspace s.bobber = bobber + local trail = addTrail(bobber.PrimaryPart, 1.2) if tip then local a1 = Instance.new("Attachment") a1.Position = Vector3.new(0, 0.9, 0) @@ -678,22 +754,24 @@ local function flyBobber(s, tool, target) line.Color = ColorSequence.new(Color3.fromRGB(245, 245, 245)) line.Parent = bobber end - local t0, dur = os.clock(), 0.55 + local t0 = os.clock() while bobber.Parent do local a = math.min(1, (os.clock() - t0) / dur) - bobber:PivotTo(CFrame.new(start:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * 6, 0))) + bobber:PivotTo(CFrame.new(start:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * arc, 0))) if a >= 1 then break end RunService.Heartbeat:Wait() end + trail.Enabled = false -- на воде поплавок качается, шлейф уже не нужен if bobber.Parent then splash(bobber.PrimaryPart, 18) playSound(bobber.PrimaryPart, SPLASH_SOUND, 0.5) end end -local function onCast(player) +local function onCast(player, power) + power = math.clamp(tonumber(power) or 0.6, 0, 1) local data = profiles[player] if not data then return @@ -710,10 +788,13 @@ local function onCast(player) return end local world = Config.WorldAt(hrp.Position) - local target = world and findWater(hrp, world) + local target, dist = nil, 0 + if world then + target, dist = findWater(hrp, world, power) + end if not target then remote:FireClient(player, "CastFail") - notify(player, world and "Повернись лицом к воде (или к лунке)!" or "Здесь нет рыбы — иди в один из миров 🌍", Color3.fromRGB(255, 200, 120)) + notify(player, world and "Подойди ближе к воде (или к лунке)!" or "Здесь нет рыбы — иди в один из миров 🌍", Color3.fromRGB(255, 200, 120)) return end if #data.items >= bagCapacity(player, data) then @@ -723,29 +804,28 @@ local function onCast(player) end local stats = Config.RodStats(data.rod, rodLevel(data)) - local fish = rollFish(player, data, world.id) + local perfect = power >= Config.CastPerfect[1] and power <= Config.CastPerfect[2] + local fish = rollFish(player, data, world.id, perfect and Config.CastPerfectLuck or 1) if not fish then remote:FireClient(player, "CastFail") return end local s = { stage = "casting", fish = fish, tool = tool } fishing[player] = s - remote:FireClient(player, "Cast", target + Vector3.new(0, 0.15, 0)) -- клиенту для камеры + -- замах игрок уже сделал, пока держал кнопку (у себя на клиенте); здесь только бросок вперёд + local throw = { windup = 0.15, flight = 0.35 + dist * 0.018, arc = 2 + dist * 0.3, perfect = perfect } + local splashAt = target + Vector3.new(0, 0.15, 0) + remote:FireClient(player, "Cast", splashAt, throw) -- клиенту для камеры task.spawn(function() - -- замах назад и бросок вперёд - local tw = tweenGrip(tool, 100, 0.25) - if tw then - tw.Completed:Wait() - end - tw = tweenGrip(tool, 8, 0.15) + local tw = tweenGrip(tool, 8, throw.windup) if tw then tw.Completed:Wait() end if fishing[player] ~= s then return end - flyBobber(s, tool, target + Vector3.new(0, 0.15, 0)) + flyBobber(s, tool, splashAt, throw.flight, throw.arc) tweenGrip(tool, REST_ANGLE - 5, 0.4) if fishing[player] ~= s then if s.bobber then @@ -810,11 +890,14 @@ local function onCatch(player, success, misses) if s.tween then s.tween:Cancel() end - if s.bobber then - s.bobber:Destroy() + local failed = success ~= true or os.clock() - s.biteAt > Config.BiteTimeout + 1 + if failed then + reelBobber(s.bobber, tool) + elseif s.bobber then + s.bobber:Destroy() -- вместо поплавка к игроку летит рыба end - if success ~= true or os.clock() - s.biteAt > Config.BiteTimeout + 1 then + if failed then gripSequence(tool, { { REST_ANGLE, 0.3 } }) remote:FireClient(player, "Escaped") notify(player, "Рыба сорвалась!", RED) @@ -1095,7 +1178,15 @@ end) remote.OnServerEvent:Connect(function(player, action, a, b) if action == "Cast" then - onCast(player) + onCast(player, a) + elseif action == "Tutorial" then + -- шаги обучения идут только вперёд + local data = profiles[player] + local step = math.floor(tonumber(a) or 0) + if data and step > (player:GetAttribute("Tutorial") or 0) and step <= Config.TutorialDone then + data.tutorial = step + player:SetAttribute("Tutorial", step) + end elseif action == "Catch" then onCatch(player, a, b) elseif action == "Cancel" then diff --git a/install/5_FishingClient_StarterPlayerScripts.rbxmx b/install/5_FishingClient_StarterPlayerScripts.rbxmx index 5b648fc..885046a 100644 --- a/install/5_FishingClient_StarterPlayerScripts.rbxmx +++ b/install/5_FishingClient_StarterPlayerScripts.rbxmx @@ -1046,8 +1046,15 @@ refreshHud() local state = "idle" local mg = { pos = 0, dir = 1, speed = 1, zoneStart = 0.4, zoneWidth = 0.25, hits = 0, need = 1, misses = 0, maxMisses = 2, deadline = 0, timeout = 10 } --- пока удочка заброшена, ходить и прыгать нельзя +-- с начала зарядки и до конца рыбалки персонажем не управляем: не ходит, не прыгает, не поворачивается +local ContextActionService = game:GetService("ContextActionService") +local MOVE_KEYS = { + Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D, Enum.KeyCode.Space, + Enum.KeyCode.Up, Enum.KeyCode.Down, Enum.KeyCode.Left, Enum.KeyCode.Right, + Enum.KeyCode.Thumbstick1, Enum.KeyCode.ButtonA, +} local controls +local movementLocked = false local function setMovementLocked(locked) if not controls then local pm = player:FindFirstChild("PlayerScripts") and player.PlayerScripts:FindFirstChild("PlayerModule") @@ -1061,17 +1068,26 @@ local function setMovementLocked(locked) controls:Enable() end end + if locked ~= movementLocked then + movementLocked = locked + if locked then + ContextActionService:BindActionAtPriority("FishingLock", function() + return Enum.ContextActionResult.Sink + end, false, Enum.ContextActionPriority.High.Value + 100, table.unpack(MOVE_KEYS)) + else + ContextActionService:UnbindAction("FishingLock") + end + end + local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid") + if hum then + hum.AutoRotate = not locked + hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, not locked) + if locked then + hum:Move(Vector3.zero) + end + end end ----------------------------------------------------------------- камера при забросе --- замах: камера отъезжает и расширяется обзор; полёт: камера разгоняется за поплавком; --- потом смотрит на поплавок, пока рыбалка не закончится, и плавно возвращается - -local CAST_WINDUP, CAST_FLIGHT = 0.4, 0.55 -- как в GameServer: замах и полёт поплавка -local CAM_SETTLE, CAM_RETURN = 0.7, 0.6 -local UP = Vector3.new(0, 1, 0) -local fishCam = nil - local function easeInOut(a) return a < 0.5 and 4 * a * a * a or 1 - (-2 * a + 2) ^ 3 / 2 end @@ -1079,6 +1095,100 @@ local function easeOut(a) return 1 - (1 - a) ^ 3 end +---------------------------------------------------------------- заброс: зарядка, шкала силы, наклон удочки +-- держишь ЛКМ — сила растёт, удочка уходит назад; отпустил — бросок на дальность по силе + +local REST_ANGLE, BACK_ANGLE = 30, 110 -- удочка в покое (как в GameServer) и в полном замахе +local function gripCF(angle) + return (CFrame.Angles(math.rad(angle), 0, 0) * CFrame.new(0, 0, -0.3)):Inverse() +end + +local charge = nil -- { t0, tool } +local castTool = nil -- удочка последнего броска: вернуть её в покой, если бросок не удался +local function chargePower() + return charge and math.min(1, (os.clock() - charge.t0) / Config.CastChargeTime) or 0 +end +local function inPerfect(v) + return v >= Config.CastPerfect[1] and v <= Config.CastPerfect[2] +end + +-- шкала-дуга справа от персонажа: внизу слабый бросок, вверху сильный, зелёная зона — бонус удачи +local GAUGE_R, GAUGE_DEG, GAUGE_N = 190, 110, 32 +local gauge = new("Frame", { + Size = UDim2.fromOffset(150, 280), AnchorPoint = Vector2.new(0, 0.5), Position = UDim2.new(0.57, 0, 0.48, 0), + BackgroundTransparency = 1, Visible = false, Parent = gui, +}) +local GAUGE_C = Vector2.new(110 - GAUGE_R, 140) -- центр окружности левее рамки: дуга выгнута вправо +local function arcPoint(v, r) + local th = math.rad(-GAUGE_DEG / 2 + GAUGE_DEG * v) + return GAUGE_C + Vector2.new(math.cos(th) * r, -math.sin(th) * r), -math.deg(th) +end +do + local segLen = 2 * math.pi * GAUGE_R * (GAUGE_DEG / 360) / GAUGE_N + for _, layer in ipairs({ { 46, 4, BLACK }, { 34, 1 } }) do -- чёрная обводка, потом цветные секции + for i = 0, GAUGE_N - 1 do + local v = (i + 0.5) / GAUGE_N + local pos, rot = arcPoint(v, GAUGE_R) + local color = layer[3] + or ((v < 0.12 or v > 0.94) and C.red) + or (inPerfect(v) and Color3.fromRGB(110, 235, 60)) + or Color3.fromRGB(40, 70, 95) + new("Frame", { + Size = UDim2.fromOffset(layer[1], segLen + layer[2]), AnchorPoint = Vector2.new(0.5, 0.5), + Position = UDim2.fromOffset(pos.X, pos.Y), Rotation = rot, BorderSizePixel = 0, + BackgroundColor3 = color, Parent = gauge, + }) + end + end +end +local needle = new("Frame", { + Size = UDim2.fromOffset(64, 8), AnchorPoint = Vector2.new(0.5, 0.5), BackgroundColor3 = WHITE, + BorderSizePixel = 0, ZIndex = 3, Parent = gauge, +}, { corner(4), stroke(BLACK, 2) }) +local multLabel = text({ + Size = UDim2.fromOffset(110, 40), AnchorPoint = Vector2.new(0.5, 1), Font = TITLE, TextSize = 34, + Text = "×" .. Config.CastPerfectLuck, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 4, + Visible = false, Parent = gauge, +}) +new("UIStroke", { Color = BLACK, Thickness = 3, Parent = multLabel }) +do + local top = arcPoint(1, GAUGE_R) + multLabel.Position = UDim2.fromOffset(top.X + 10, top.Y - 18) +end + +local function updateCharge() + local p = chargePower() + local pos, rot = arcPoint(p, GAUGE_R) + needle.Position = UDim2.fromOffset(pos.X, pos.Y) + needle.Rotation = rot + local good = inPerfect(p) + multLabel.Visible = good + needle.BackgroundColor3 = good and Color3.fromRGB(190, 255, 150) or WHITE + if charge.tool and charge.tool.Parent then + charge.tool.Grip = gripCF(REST_ANGLE + (BACK_ANGLE - REST_ANGLE) * easeOut(p)) + end +end + +---------------------------------------------------------------- камера при забросе +-- зарядка: камера уходит в сторону от персонажа и отъезжает тем дальше, чем сильнее замах; +-- бросок: камера сбоку разгоняется за поплавком; потом сверху-сбоку держит в кадре игрока и поплавок + +local CAM_IN, CAM_SETTLE, CAM_RETURN = 0.35, 0.8, 0.6 +local UP = Vector3.new(0, 1, 0) +local fishCam = nil + +local function sideCF(fc, p) + return CFrame.lookAt(fc.hrp + fc.r * (9 + 3 * p) - fc.f * (3 + 2 * p) + UP * (3 + 1.5 * p), fc.hrp + fc.f * 6 + UP) +end +local function chaseCF(fc, p) + return CFrame.lookAt(p + fc.r * 9 - fc.f * 5 + UP * 3, p + fc.f * 3) +end +local function restCF(fc) + local d = ((fc.target - fc.hrp) * Vector3.new(1, 0, 1)).Magnitude + local mid = fc.hrp:Lerp(fc.target, 0.5) + return CFrame.lookAt(mid + fc.r * (8 + d * 0.55) - fc.f * 4 + UP * (6 + d * 0.25), fc.hrp:Lerp(fc.target, 0.6)) +end + local function fishCamStep() local fc = fishCam local cam = workspace.CurrentCamera @@ -1097,62 +1207,80 @@ local function fishCamStep() end return end - local t = os.clock() - fc.t0 + local now = os.clock() local cf, fov - if t < CAST_WINDUP then - local e = easeOut(t / CAST_WINDUP) - cf = fc.origCF:Lerp(fc.windupCF, e) - fov = fc.origFov + 14 * e - elseif t < CAST_WINDUP + CAST_FLIGHT then - if not fc.start then - fc.start = (fc.tip and fc.tip.Parent and fc.tip.WorldPosition) or fc.fallbackStart - end - local a = (t - CAST_WINDUP) / CAST_FLIGHT - local p = fc.start:Lerp(fc.target, a) + UP * (math.sin(a * math.pi) * 6) -- та же дуга, что у поплавка - local chase = CFrame.lookAt(p - fc.flat * 9 + UP * 3.5, p + fc.flat * 4) - local e = easeInOut(a) - cf = fc.windupCF:Lerp(chase, e) - fov = fc.origFov + 14 - 22 * e + if not fc.castT0 then + -- зарядка: плавно уходим в вид сбоку; чем сильнее замах, тем дальше камера и шире обзор + -- после отпускания ЛКМ, пока ждём ответ сервера, держим набранную силу + local p = charge and chargePower() or (fc.power or 0) + fc.power = p + local e = easeOut(math.min(1, (now - fc.t0) / CAM_IN)) + cf = fc.origCF:Lerp(sideCF(fc, p), e) + fov = fc.origFov + 12 * p * e else - local e = easeOut(math.min(1, (t - CAST_WINDUP - CAST_FLIGHT) / CAM_SETTLE)) - local now = os.clock() - local sway = Vector3.new(math.sin(now * 0.7) * 0.5, math.sin(now * 1.1) * 0.25, 0) - if state == "bite" then - sway += Vector3.new(math.random() - 0.5, math.random() - 0.5, 0) * 0.15 + local th = fc.throw + local t = now - fc.castT0 + local lunge = fc.fromCF + fc.f * 1.5 + if t < th.windup then + -- рывок удочки вперёд: камера подаётся следом + local e = easeOut(t / th.windup) + cf = fc.fromCF:Lerp(lunge, e) + fov = fc.fromFov + 4 * e + elseif t < th.windup + th.flight then + if not fc.start then + fc.start = (fc.tip and fc.tip.Parent and fc.tip.WorldPosition) or (fc.hrp + fc.f * 2 + UP * 4) + end + local a = (t - th.windup) / th.flight + local p = fc.start:Lerp(fc.target, a) + UP * (math.sin(a * math.pi) * th.arc) -- та же дуга, что у поплавка + local e = easeInOut(a) + cf = lunge:Lerp(chaseCF(fc, p), e) + fov = (fc.fromFov + 4) + ((fc.origFov - 6) - (fc.fromFov + 4)) * e + else + local e = easeOut(math.min(1, (t - th.windup - th.flight) / CAM_SETTLE)) + local sway = Vector3.new(math.sin(now * 0.7) * 0.5, math.sin(now * 1.1) * 0.25, 0) + if state == "bite" then + sway += Vector3.new(math.random() - 0.5, math.random() - 0.5, 0) * 0.15 + end + cf = chaseCF(fc, fc.target):Lerp(restCF(fc) + sway, e) + fov = fc.origFov - 6 + 6 * e end - cf = fc.landCF:Lerp(fc.restCF + sway, e) - fov = fc.origFov - 8 + 8 * e end cam.CFrame = cf cam.FieldOfView = fov end -local function startFishCam(target) +-- начало зарядки: dir — куда полетит поплавок (к центру озера) +local function startChargeCam(tool, dir) local cam = workspace.CurrentCamera - local char = player.Character - local hrp = char and char:FindFirstChild("HumanoidRootPart") - if not cam or not hrp or typeof(target) ~= "Vector3" then + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + if not cam or not hrp then return end - local flat = (target - hrp.Position) * Vector3.new(1, 0, 1) - flat = flat.Magnitude > 0.1 and flat.Unit or hrp.CFrame.LookVector - local tool = char:FindFirstChildOfClass("Tool") - local tip = tool and tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") fishCam = { - t0 = os.clock(), target = target, flat = flat, tip = tip, - fallbackStart = hrp.Position + flat * 2 + UP * 4, + t0 = os.clock(), hrp = hrp.Position, f = dir, r = dir:Cross(UP), + tip = tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip"), -- если камера ещё возвращалась с прошлого заброса, возвращаться будем туда же origCF = fishCam and fishCam.origCF or cam.CFrame, origFov = fishCam and fishCam.origFov or cam.FieldOfView, - windupCF = CFrame.lookAt(hrp.Position - flat * 13 + UP * 7, hrp.Position:Lerp(target, 0.5)), - landCF = CFrame.lookAt(target - flat * 9 + UP * 3.5, target + flat * 4), - restCF = CFrame.lookAt(target - flat * 11 + UP * 5.5, target), } cam.CameraType = Enum.CameraType.Scriptable RunService:UnbindFromRenderStep("FishCam") RunService:BindToRenderStep("FishCam", Enum.RenderPriority.Camera.Value + 1, fishCamStep) end +-- сервер принял бросок: target — куда упадёт поплавок, throw — тайминги и высота дуги +local function startCastCam(target, throw) + local cam = workspace.CurrentCamera + if not fishCam or fishCam.returning or not cam or typeof(target) ~= "Vector3" or type(throw) ~= "table" then + return + end + fishCam.castT0 = os.clock() + fishCam.target = target + fishCam.throw = throw + fishCam.fromCF = cam.CFrame + fishCam.fromFov = cam.FieldOfView +end + local function stopFishCam() local cam = workspace.CurrentCamera if not fishCam or fishCam.returning or not cam then @@ -1165,9 +1293,17 @@ end local reelToken local function setState(s) + if s ~= "charging" and charge then + -- зарядку прервали (убрал удочку и т.п.): удочку обратно в покой + if charge.tool.Parent then + charge.tool.Grip = gripCF(REST_ANGLE) + end + charge = nil + end state = s statusLabel.Visible = (s == "waiting") mgFrame.Visible = (s == "bite") + gauge.Visible = (s == "charging") setMovementLocked(s ~= "idle") if s == "idle" then stopFishCam() @@ -1196,11 +1332,39 @@ local function placeZone() zoneF.Position = UDim2.fromScale(mg.zoneStart, 0) end +-- ЛКМ зажата: персонаж разворачивается к центру озера, начинается зарядка +local function startCharge(tool) + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + if not hrp then + return + end + local world = Config.WorldAt(hrp.Position) + local dir = world and Config.CastDirection(world, hrp.Position) + if not dir then + dir = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) + dir = dir.Magnitude > 0.01 and dir.Unit or Vector3.new(0, 0, -1) + end + hrp.CFrame = CFrame.lookAt(hrp.Position, hrp.Position + dir) + charge = { t0 = os.clock(), tool = tool } + setState("charging") + startChargeCam(tool, dir) + updateCharge() +end + +-- ЛКМ отпущена: бросок с набранной силой +local function releaseCast() + if state ~= "charging" or not charge then + return + end + local power = chargePower() + castTool = charge.tool + charge = nil -- удочку не возвращаем: сервер сам сделает рывок вперёд + setState("casting") + remote:FireServer("Cast", power) +end + local function onActivate() - if state == "idle" then - setState("casting") - remote:FireServer("Cast") - elseif state == "waiting" then + if state == "waiting" then remote:FireServer("Cancel") setState("idle") elseif state == "bite" then @@ -1234,7 +1398,14 @@ local function hookTool(tool) return end hooked[tool] = true - tool.Activated:Connect(onActivate) + tool.Activated:Connect(function() + if state == "idle" then + startCharge(tool) + else + onActivate() + end + end) + tool.Deactivated:Connect(releaseCast) tool.Unequipped:Connect(function() if state == "waiting" or state == "bite" or state == "casting" then remote:FireServer("Cancel") @@ -1264,6 +1435,12 @@ if player.Character then watch(player.Character) end +RunService.RenderStepped:Connect(function() + if state == "charging" and charge then + updateCharge() + end +end) + RunService.RenderStepped:Connect(function(dt) if state ~= "bite" then return @@ -1359,6 +1536,170 @@ task.spawn(function() end end) +---------------------------------------------------------------- обучение: линия-подсказка +-- белые «стрелки» бегут по земле от игрока к цели текущего шага (см. Config.TutorialDone) + +local GUIDE_N, GUIDE_GAP, GUIDE_SPEED = 32, 3, 7 -- сколько стрелок, шаг между ними, скорость бега +local W1 = Config.Worlds[1].center +local guideStep = 0 -- шаг, отправленный на сервер (атрибут Tutorial может прийти чуть позже) + +local guideHint = text({ + Size = UDim2.fromOffset(560, 42), AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, 64), + BackgroundTransparency = 0.2, BackgroundColor3 = C.bg, Font = TITLE, TextSize = 20, + TextXAlignment = Enum.TextXAlignment.Center, Visible = false, Parent = gui, +}, nil) +corner(12).Parent = guideHint +stroke(C.gold, 2).Parent = guideHint + +local guideFolder = new("Folder", { Name = "TutorialGuide", Parent = workspace }) +local chevrons = {} +for i = 1, GUIDE_N do + local arms = {} + for k = 1, 2 do + arms[k] = new("Part", { + Anchored = true, CanCollide = false, CanQuery = false, CanTouch = false, CastShadow = false, + Material = Enum.Material.Neon, Color = WHITE, Size = Vector3.new(0.32, 0.06, 1.35), Transparency = 1, + Parent = guideFolder, + }) + end + chevrons[i] = arms +end +-- две «палочки» стрелки «>» острием вперёд (по -Z) +local ARM_CF = {} +for k, s in ipairs({ -1, 1 }) do + local center = Vector3.new(s * 0.45, 0, -0.1) + ARM_CF[k] = CFrame.lookAt(center, center + Vector3.new(s * 0.9, 0, 1)) +end +local function hideChevrons(from) + for i = from, GUIDE_N do + chevrons[i][1].Transparency = 1 + chevrons[i][2].Transparency = 1 + end +end + +local guideRay = RaycastParams.new() +guideRay.FilterType = Enum.RaycastFilterType.Exclude +guideRay.RespectCanCollide = true +guideRay.IgnoreWater = false + +local function tutorialStep() + return math.max(player:GetAttribute("Tutorial") or 0, guideStep) +end +local function advanceTutorial(step) + if step > tutorialStep() then + guideStep = step + remote:FireServer("Tutorial", step) + if step >= Config.TutorialDone then + notify("🎓 Обучение пройдено! Дальше — сам: лови, улучшай удочку, открывай миры", C.gold) + end + end +end + +local function guideMarker(name) + local map = workspace:FindFirstChild("FishingMap") + local m = map and map:FindFirstChild(name) + return m and m.Position +end + +-- маршрут для текущего шага: точки ломаной (без игрока) и подсказка; nil — линию не показываем +local function guideRoute(step, pos, world) + local inW1 = world and world.id == "World1" + if step == 0 and not world then + return { guideMarker("GuideBoard") }, "📋 Прочитай табличку «Как играть»" + elseif not world then -- шаги 1–3 из лобби: сначала в портал + return { guideMarker("GuidePortal") }, "🌊 Иди в портал «Тихое озеро»" + elseif step == 2 and inW1 then + return { guideMarker("GuideFishSpot") }, "🎣 Иди на причал, зажми ЛКМ и отпусти — заброс!" + elseif step == 3 and inW1 then + local route = {} + local rel = pos - W1 + if math.abs(rel.X) < 6 and rel.Z < 80 then + table.insert(route, W1 + Vector3.new(0, 4.5, 84)) -- сначала сойти с причала + end + table.insert(route, guideMarker("GuideSell")) + return route, "💰 Продай рыбу в скупке" + end + return nil +end + +RunService.RenderStepped:Connect(function() + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + local step = tutorialStep() + -- пока сервер не прислал шаг (данные ещё грузятся), ничего не показываем + if not hrp or player:GetAttribute("Tutorial") == nil or step >= Config.TutorialDone then + guideHint.Visible = false + hideChevrons(1) + return + end + local pos = hrp.Position + local world = Config.WorldAt(pos) + + -- переходы между шагами + if step <= 1 and world and world.id == "World1" then + advanceTutorial(2) + elseif step == 0 then + local board = guideMarker("GuideBoard") + if board and (board - pos).Magnitude < 9 then + advanceTutorial(1) + end + elseif step == 2 and (player:GetAttribute("TotalCaught") or 0) > 0 then + advanceTutorial(3) + end + step = tutorialStep() + + local route, hint = guideRoute(step, pos, world) + guideHint.Text = hint or "" + guideHint.Visible = hint ~= nil and state == "idle" + if not route or #route == 0 or state ~= "idle" then + hideChevrons(1) + return + end + + -- ломаная от ног игрока через точки маршрута + local pts = { pos - Vector3.new(0, 3, 0) } + for _, p in ipairs(route) do + table.insert(pts, p) + end + local lens, total = {}, 0 + for i = 2, #pts do + local d = ((pts[i] - pts[i - 1]) * Vector3.new(1, 0, 1)).Magnitude + lens[i] = math.max(d, 0.001) + total += d + end + if total < 4 then + hideChevrons(1) -- уже на месте + return + end + + guideRay.FilterDescendantsInstances = { player.Character, guideFolder } + local phase = (os.clock() * GUIDE_SPEED) % GUIDE_GAP + local seg, segStart = 2, 0 + for i = 1, GUIDE_N do + local d = 2 + phase + (i - 1) * GUIDE_GAP + if d > total - 1 then + hideChevrons(i) + break + end + while seg < #pts and d > segStart + lens[seg] do + segStart += lens[seg] + seg += 1 + end + local a, b = pts[seg - 1], pts[seg] + local p = a:Lerp(b, (d - segStart) / lens[seg]) + local dir = (b - a) * Vector3.new(1, 0, 1) + local hit = workspace:Raycast(p + Vector3.new(0, 4, 0), Vector3.new(0, -12, 0), guideRay) + local y = hit and hit.Position.Y or p.Y + local base = CFrame.lookAt(Vector3.new(p.X, y + 0.08, p.Z), Vector3.new(p.X, y + 0.08, p.Z) + dir) + -- у игрока и у цели стрелки плавно проявляются и гаснут + local fade = math.max(0, 1 - math.min(d - 2, total - 1 - d) / 2.5) + local tr = 0.1 + 0.9 * fade + for k = 1, 2 do + chevrons[i][k].CFrame = base * ARM_CF[k] + chevrons[i][k].Transparency = tr + end + end +end) + ---------------------------------------------------------------- события от сервера remote.OnClientEvent:Connect(function(action, a, b, c) @@ -1366,8 +1707,11 @@ remote.OnClientEvent:Connect(function(action, a, b, c) notify(a, b) elseif action == "Cast" then setState("waiting") - startFishCam(a) + startCastCam(a, b) elseif action == "CastFail" or action == "Cancel" or action == "Escaped" then + if action == "CastFail" and castTool and castTool.Parent then + castTool.Grip = gripCF(REST_ANGLE) -- сервер удочку не трогал, а у нас она в замахе + end setState("idle") elseif action == "Bite" then mg.speed = a.speed @@ -1387,6 +1731,9 @@ remote.OnClientEvent:Connect(function(action, a, b, c) showCatch(a, b) playUiSound(DING, 0.5) elseif action == "Sold" then + if tutorialStep() == 3 then + advanceTutorial(Config.TutorialDone) + end floatText("+" .. fmt(a) .. " 💰", C.gold) notify(("Продано рыб: %d → +%s 💰"):format(b, fmt(a)), Color3.fromRGB(120, 255, 140)) elseif action == "Inventory" then diff --git a/install/INSTALL.lua b/install/INSTALL.lua index 6504490..da0bbcc 100644 --- a/install/INSTALL.lua +++ b/install/INSTALL.lua @@ -67,6 +67,35 @@ function Config.WorldAt(pos) return nil end +-- куда бросать из этой точки (единичный вектор по горизонтали): к центру ближайшего озера или лунки, +-- а если ближе море — от центра острова к морю +function Config.CastDirection(world, pos) + if not world then + return nil + end + local x, z = pos.X - world.center.X, pos.Z - world.center.Z + local best, bestGap + local function consider(dir, gap) + if dir.Magnitude > 0.1 and (not bestGap or gap < bestGap) then + best, bestGap = dir.Unit, gap + end + end + if world.holes then + for _, h in ipairs(world.holes) do + consider(Vector3.new(h[1] - x, 0, h[2] - z), math.sqrt((h[1] - x) ^ 2 + (h[2] - z) ^ 2) - (world.holeRadius or 6)) + end + end + for _, l in ipairs(world.lakes or {}) do + if not world.holes then -- в Мире 3 озёра подо льдом, бросаем только в лунки + consider(Vector3.new(l[1] - x, 0, l[2] - z), math.sqrt((l[1] - x) ^ 2 + (l[2] - z) ^ 2) - l[3]) + end + end + if world.sea then + consider(Vector3.new(x, 0, z), world.sea - math.sqrt(x * x + z * z)) + end + return best +end + -- есть ли вода в этой точке мира (озеро, море или лунка) function Config.IsWater(world, pos) if not world then @@ -273,6 +302,15 @@ Config.BiteTimeMin = 3 Config.BiteTimeMax = 7 Config.BiteTimeout = 12 Config.MaxMisses = 2 +-- заброс: держишь ЛКМ — сила растёт от 0 до 1; от силы зависит дальность +Config.CastChargeTime = 1.3 -- секунд до полной силы +Config.CastMinDist, Config.CastMaxDist = 6, 28 +Config.CastPerfect = { 0.72, 0.86 } -- зелёная зона шкалы +Config.CastPerfectLuck = 1.2 -- множитель удачи за попадание в зелёную зону + +-- обучение: линия-подсказка ведёт по шагам 0 → 1 → 2 → 3, на 4 обучение пройдено +-- 0 — табличка «Как играть», 1 — портал в Мир 1, 2 — причал (поймать рыбу), 3 — скупка (продать) +Config.TutorialDone = 4 function Config.HitsNeeded(rank) return math.ceil(rank / 2) end @@ -1553,6 +1591,9 @@ for i, w in ipairs(Config.Worlds) do local a = math.rad(90 - (i - 1) * 90) -- 90° = сторона спавна (+Z) local pos = V(math.cos(a) * PORTAL_R, FLOOR, math.sin(a) * PORTAL_R) portal(CFrame.lookAt(pos, V(pos.X * 2, FLOOR, pos.Z * 2)), title, w.color, w.id, w.soon) + if i == 1 then + marker("GuidePortal", CFrame.new(pos.X * 1.3, FLOOR, pos.Z * 1.3)) -- точка перед порталом для линии-подсказки + end end -- невидимая стена по кругу: из лобби не уйти @@ -1637,12 +1678,13 @@ do local pos = V(-12, FLOOR, 48) local cf = CFrame.lookAt(pos, V(0, FLOOR, 64)) lamp((cf * CFrame.new(0, 0, 2.5)).Position) + marker("GuideBoard", cf * CFrame.new(0, 0, -6)) -- перед табличкой, для линии-подсказки for _, x in ipairs({ -6.5, 6.5 }) do P({ Size = V(0.8, 9, 0.8), CFrame = cf * CFrame.new(x, 4.5, 0.3), Material = Enum.Material.Wood, Color = Color3.fromRGB(90, 60, 40) }) end local board = P({ Size = V(14, 8, 0.5), CFrame = cf * CFrame.new(0, 6, 0), Material = Enum.Material.WoodPlanks, Color = Color3.fromRGB(70, 48, 32) }) surfaceText(board, Enum.NormalId.Front, - "КАК ИГРАТЬ\n1. Портал «Мир 1» или кнопка 🌍 Миры\n2. Удочка — клавиша 1, клик у воды\n3. Клюёт → кликай в зелёную зону\n4. 🎒 Сумка — B, 📜 Задания — Q\n5. Собирай коллекцию — получай награды!", + "КАК ИГРАТЬ\n1. Портал «Мир 1» или кнопка 🌍 Миры\n2. Удочка — клавиша 1, у воды зажми ЛКМ и отпусти\n3. Клюёт → кликай в зелёную зону\n4. 🎒 Сумка — B, 📜 Задания — Q\n5. Собирай коллекцию — получай награды!", Color3.fromRGB(255, 245, 225), { TextXAlignment = Enum.TextXAlignment.Left }) end @@ -1663,6 +1705,9 @@ local arrive = W + V(0, GROUND_Y, 94) marker("World1Spawn", CFrame.lookAt(arrive + V(0, 1, 0), arrive + V(0, 1, -10))) arch(CFrame.new(W + V(0, GROUND_Y, 82)), 14, 11, "🌊 ТИХОЕ ОЗЕРО", Color3.fromRGB(80, 200, 255)) portal(CFrame.lookAt(W + V(-22, GROUND_Y, 96), arrive), "🏠 В лобби", Color3.fromRGB(255, 200, 80), "Lobby") +-- точки для линии-подсказки: конец главного причала и место перед скупкой +marker("GuideFishSpot", CFrame.new(W + V(0, GROUND_Y + 0.5, 42))) +marker("GuideSell", CFrame.lookAt(W + V(26, GROUND_Y, 98), arrive) * CFrame.new(0, 0, -10)) stall(CFrame.lookAt(W + V(26, GROUND_Y, 98), arrive), { title = "💰 СКУПКА", titleColor = Color3.fromRGB(150, 255, 160), @@ -2639,6 +2684,8 @@ local function updateStats(player) player:SetAttribute("BoostBonus", boostActive(data)) player:SetAttribute("BoostLeft", math.max(0, data.boostUntil - os.time())) player:SetAttribute("TotalCaught", data.totalCaught) + -- шаг обучения (линия-подсказка); у старых игроков без поля, уже ловивших рыбу, обучение пройдено + player:SetAttribute("Tutorial", data.tutorial or (data.totalCaught > 0 and Config.TutorialDone or 0)) player:SetAttribute("Mastery", masteryCount(data)) player:SetAttribute("Passes", table.concat(ps, ",")) @@ -2961,6 +3008,28 @@ local function splash(part, count) end -- рыба вылетает из воды, летит к игроку и показывается над головой +-- шлейф за летящим предметом — эффект быстрого движения (ширина — расстояние между точками крепления) +local TRAIL_COLOR = Color3.fromRGB(215, 245, 255) +local function addTrail(part, width) + local a0 = Instance.new("Attachment") + a0.Position = Vector3.new(0, width / 2, 0) + a0.Parent = part + local a1 = Instance.new("Attachment") + a1.Position = Vector3.new(0, -width / 2, 0) + a1.Parent = part + local trail = Instance.new("Trail") + trail.Attachment0, trail.Attachment1 = a0, a1 + trail.FaceCamera = true + trail.Lifetime = 0.35 + trail.MinLength = 0.05 + trail.LightEmission = 0.7 + trail.Color = ColorSequence.new(TRAIL_COLOR) + trail.Transparency = NumberSequence.new({ NumberSequenceKeypoint.new(0, 0.1), NumberSequenceKeypoint.new(1, 1) }) + trail.WidthScale = NumberSequence.new({ NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(1, 0) }) + trail.Parent = part + return trail +end + local function showFishFlight(player, fish, fromPos) local head = player.Character and player.Character:FindFirstChild("Head") if not head then @@ -2969,6 +3038,14 @@ local function showFishFlight(player, fish, fromPos) local model = Models.buildFish(fish.id, fish.mutation, 0.9, true) model:PivotTo(CFrame.new(fromPos)) model.Parent = workspace + -- шлейф на отдельной невидимой детали: рыба крутится, а шлейф должен оставаться ровным + local carrier = Instance.new("Part") + carrier.Anchored, carrier.CanCollide, carrier.CanQuery, carrier.CanTouch = true, false, false, false + carrier.Transparency = 1 + carrier.Size = Vector3.new(0.2, 0.2, 0.2) + carrier.CFrame = CFrame.new(fromPos) + carrier.Parent = model + local trail = addTrail(carrier, 1.8) task.spawn(function() local t0, dur = os.clock(), 0.55 while head.Parent do @@ -2976,11 +3053,13 @@ local function showFishFlight(player, fish, fromPos) local target = head.Position + Vector3.new(0, 2.8, 0) local p = fromPos:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * 8, 0) model:PivotTo(CFrame.new(p) * CFrame.Angles(0, 0, a * math.pi * 2)) + carrier.CFrame = CFrame.new(p) if a >= 1 then break end RunService.Heartbeat:Wait() end + trail.Enabled = false local t1 = os.clock() while head.Parent and os.clock() - t1 < 1.8 do model:PivotTo(CFrame.new(head.Position + Vector3.new(0, 2.8, 0)) * CFrame.Angles(0, os.clock() * 3, math.rad(-15))) @@ -2994,22 +3073,59 @@ end local fishing = {} --- ищем воду перед игроком по карте мира из FishConfig (не зависит от террейна) -local function findWater(hrp, world) - local look = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) - if look.Magnitude < 0.01 then - look = Vector3.new(0, 0, -1) +-- ищем воду по карте мира из FishConfig (не зависит от террейна) в сторону центра ближайшего озера: +-- сначала на дальности, которую задала сила заброса, потом всё дальше от неё +local function findWater(hrp, world, power) + local look = Config.CastDirection(world, hrp.Position) + if not look then + look = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) + look = look.Magnitude > 0.01 and look.Unit or Vector3.new(0, 0, -1) end - look = look.Unit - for _, d in ipairs({ 14, 11, 17, 8, 20, 6, 24, 4 }) do - local p = hrp.Position + look * d - if Config.IsWater(world, p) then - return Vector3.new(p.X, world.waterY or 0, p.Z) + local want = Config.CastMinDist + (Config.CastMaxDist - Config.CastMinDist) * power + for off = 0, 26, 2 do + for _, d in ipairs({ want - off, want + off }) do + if d >= 4 and d <= Config.CastMaxDist + 2 then + local p = hrp.Position + look * d + if Config.IsWater(world, p) then + return Vector3.new(p.X, world.waterY or 0, p.Z), d + end + end end end return nil end +-- вытягивание пустого поплавка: быстро летит к кончику удочки со шлейфом и исчезает +local function reelBobber(bobber, tool) + local root = bobber and bobber.PrimaryPart + local tip = tool and tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") + if not root or not tip then + if bobber then + bobber:Destroy() + end + return + end + local trail = bobber:FindFirstChildWhichIsA("Trail", true) + if trail then + trail.Enabled = true + else + addTrail(root, 1.2) + end + local from = root.Position + task.spawn(function() + local t0, dur = os.clock(), 0.3 + while bobber.Parent and tip.Parent do + local a = math.min(1, (os.clock() - t0) / dur) + bobber:PivotTo(CFrame.new(from:Lerp(tip.WorldPosition, a) + Vector3.new(0, math.sin(a * math.pi) * 2.5, 0))) + if a >= 1 then + break + end + RunService.Heartbeat:Wait() + end + bobber:Destroy() + end) +end + local function stopFishing(player, tellClient) local s = fishing[player] if not s then @@ -3020,7 +3136,11 @@ local function stopFishing(player, tellClient) s.tween:Cancel() end if s.bobber then - s.bobber:Destroy() + if s.stage == "casting" then + s.bobber:Destroy() -- ещё летит: его двигает flyBobber + else + reelBobber(s.bobber, s.tool) + end end if s.tool then tweenGrip(s.tool, REST_ANGLE, 0.3) @@ -3030,12 +3150,12 @@ local function stopFishing(player, tellClient) end end -local function rollFish(player, data, worldId) +local function rollFish(player, data, worldId, luckMult) local zone = Config.Zones[worldId] if not zone then return nil end - local luck = totalLuck(player, data) + local luck = totalLuck(player, data) * (luckMult or 1) local bonus = luck - 1 local weights, total = {}, 0 for i, f in ipairs(zone.fish) do @@ -3077,13 +3197,14 @@ local function rollFish(player, data, worldId) } end -local function flyBobber(s, tool, target) +local function flyBobber(s, tool, target, dur, arc) local tip = tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") local start = tip and tip.WorldPosition or (target + Vector3.new(0, 6, 0)) local bobber = Models.buildBobber() bobber:PivotTo(CFrame.new(start)) bobber.Parent = workspace s.bobber = bobber + local trail = addTrail(bobber.PrimaryPart, 1.2) if tip then local a1 = Instance.new("Attachment") a1.Position = Vector3.new(0, 0.9, 0) @@ -3097,22 +3218,24 @@ local function flyBobber(s, tool, target) line.Color = ColorSequence.new(Color3.fromRGB(245, 245, 245)) line.Parent = bobber end - local t0, dur = os.clock(), 0.55 + local t0 = os.clock() while bobber.Parent do local a = math.min(1, (os.clock() - t0) / dur) - bobber:PivotTo(CFrame.new(start:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * 6, 0))) + bobber:PivotTo(CFrame.new(start:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * arc, 0))) if a >= 1 then break end RunService.Heartbeat:Wait() end + trail.Enabled = false -- на воде поплавок качается, шлейф уже не нужен if bobber.Parent then splash(bobber.PrimaryPart, 18) playSound(bobber.PrimaryPart, SPLASH_SOUND, 0.5) end end -local function onCast(player) +local function onCast(player, power) + power = math.clamp(tonumber(power) or 0.6, 0, 1) local data = profiles[player] if not data then return @@ -3129,10 +3252,13 @@ local function onCast(player) return end local world = Config.WorldAt(hrp.Position) - local target = world and findWater(hrp, world) + local target, dist = nil, 0 + if world then + target, dist = findWater(hrp, world, power) + end if not target then remote:FireClient(player, "CastFail") - notify(player, world and "Повернись лицом к воде (или к лунке)!" or "Здесь нет рыбы — иди в один из миров 🌍", Color3.fromRGB(255, 200, 120)) + notify(player, world and "Подойди ближе к воде (или к лунке)!" or "Здесь нет рыбы — иди в один из миров 🌍", Color3.fromRGB(255, 200, 120)) return end if #data.items >= bagCapacity(player, data) then @@ -3142,29 +3268,28 @@ local function onCast(player) end local stats = Config.RodStats(data.rod, rodLevel(data)) - local fish = rollFish(player, data, world.id) + local perfect = power >= Config.CastPerfect[1] and power <= Config.CastPerfect[2] + local fish = rollFish(player, data, world.id, perfect and Config.CastPerfectLuck or 1) if not fish then remote:FireClient(player, "CastFail") return end local s = { stage = "casting", fish = fish, tool = tool } fishing[player] = s - remote:FireClient(player, "Cast", target + Vector3.new(0, 0.15, 0)) -- клиенту для камеры + -- замах игрок уже сделал, пока держал кнопку (у себя на клиенте); здесь только бросок вперёд + local throw = { windup = 0.15, flight = 0.35 + dist * 0.018, arc = 2 + dist * 0.3, perfect = perfect } + local splashAt = target + Vector3.new(0, 0.15, 0) + remote:FireClient(player, "Cast", splashAt, throw) -- клиенту для камеры task.spawn(function() - -- замах назад и бросок вперёд - local tw = tweenGrip(tool, 100, 0.25) - if tw then - tw.Completed:Wait() - end - tw = tweenGrip(tool, 8, 0.15) + local tw = tweenGrip(tool, 8, throw.windup) if tw then tw.Completed:Wait() end if fishing[player] ~= s then return end - flyBobber(s, tool, target + Vector3.new(0, 0.15, 0)) + flyBobber(s, tool, splashAt, throw.flight, throw.arc) tweenGrip(tool, REST_ANGLE - 5, 0.4) if fishing[player] ~= s then if s.bobber then @@ -3229,11 +3354,14 @@ local function onCatch(player, success, misses) if s.tween then s.tween:Cancel() end - if s.bobber then - s.bobber:Destroy() + local failed = success ~= true or os.clock() - s.biteAt > Config.BiteTimeout + 1 + if failed then + reelBobber(s.bobber, tool) + elseif s.bobber then + s.bobber:Destroy() -- вместо поплавка к игроку летит рыба end - if success ~= true or os.clock() - s.biteAt > Config.BiteTimeout + 1 then + if failed then gripSequence(tool, { { REST_ANGLE, 0.3 } }) remote:FireClient(player, "Escaped") notify(player, "Рыба сорвалась!", RED) @@ -3514,7 +3642,15 @@ end) remote.OnServerEvent:Connect(function(player, action, a, b) if action == "Cast" then - onCast(player) + onCast(player, a) + elseif action == "Tutorial" then + -- шаги обучения идут только вперёд + local data = profiles[player] + local step = math.floor(tonumber(a) or 0) + if data and step > (player:GetAttribute("Tutorial") or 0) and step <= Config.TutorialDone then + data.tutorial = step + player:SetAttribute("Tutorial", step) + end elseif action == "Catch" then onCatch(player, a, b) elseif action == "Cancel" then @@ -4752,8 +4888,15 @@ refreshHud() local state = "idle" local mg = { pos = 0, dir = 1, speed = 1, zoneStart = 0.4, zoneWidth = 0.25, hits = 0, need = 1, misses = 0, maxMisses = 2, deadline = 0, timeout = 10 } --- пока удочка заброшена, ходить и прыгать нельзя +-- с начала зарядки и до конца рыбалки персонажем не управляем: не ходит, не прыгает, не поворачивается +local ContextActionService = game:GetService("ContextActionService") +local MOVE_KEYS = { + Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D, Enum.KeyCode.Space, + Enum.KeyCode.Up, Enum.KeyCode.Down, Enum.KeyCode.Left, Enum.KeyCode.Right, + Enum.KeyCode.Thumbstick1, Enum.KeyCode.ButtonA, +} local controls +local movementLocked = false local function setMovementLocked(locked) if not controls then local pm = player:FindFirstChild("PlayerScripts") and player.PlayerScripts:FindFirstChild("PlayerModule") @@ -4767,17 +4910,26 @@ local function setMovementLocked(locked) controls:Enable() end end + if locked ~= movementLocked then + movementLocked = locked + if locked then + ContextActionService:BindActionAtPriority("FishingLock", function() + return Enum.ContextActionResult.Sink + end, false, Enum.ContextActionPriority.High.Value + 100, table.unpack(MOVE_KEYS)) + else + ContextActionService:UnbindAction("FishingLock") + end + end + local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid") + if hum then + hum.AutoRotate = not locked + hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, not locked) + if locked then + hum:Move(Vector3.zero) + end + end end ----------------------------------------------------------------- камера при забросе --- замах: камера отъезжает и расширяется обзор; полёт: камера разгоняется за поплавком; --- потом смотрит на поплавок, пока рыбалка не закончится, и плавно возвращается - -local CAST_WINDUP, CAST_FLIGHT = 0.4, 0.55 -- как в GameServer: замах и полёт поплавка -local CAM_SETTLE, CAM_RETURN = 0.7, 0.6 -local UP = Vector3.new(0, 1, 0) -local fishCam = nil - local function easeInOut(a) return a < 0.5 and 4 * a * a * a or 1 - (-2 * a + 2) ^ 3 / 2 end @@ -4785,6 +4937,100 @@ local function easeOut(a) return 1 - (1 - a) ^ 3 end +---------------------------------------------------------------- заброс: зарядка, шкала силы, наклон удочки +-- держишь ЛКМ — сила растёт, удочка уходит назад; отпустил — бросок на дальность по силе + +local REST_ANGLE, BACK_ANGLE = 30, 110 -- удочка в покое (как в GameServer) и в полном замахе +local function gripCF(angle) + return (CFrame.Angles(math.rad(angle), 0, 0) * CFrame.new(0, 0, -0.3)):Inverse() +end + +local charge = nil -- { t0, tool } +local castTool = nil -- удочка последнего броска: вернуть её в покой, если бросок не удался +local function chargePower() + return charge and math.min(1, (os.clock() - charge.t0) / Config.CastChargeTime) or 0 +end +local function inPerfect(v) + return v >= Config.CastPerfect[1] and v <= Config.CastPerfect[2] +end + +-- шкала-дуга справа от персонажа: внизу слабый бросок, вверху сильный, зелёная зона — бонус удачи +local GAUGE_R, GAUGE_DEG, GAUGE_N = 190, 110, 32 +local gauge = new("Frame", { + Size = UDim2.fromOffset(150, 280), AnchorPoint = Vector2.new(0, 0.5), Position = UDim2.new(0.57, 0, 0.48, 0), + BackgroundTransparency = 1, Visible = false, Parent = gui, +}) +local GAUGE_C = Vector2.new(110 - GAUGE_R, 140) -- центр окружности левее рамки: дуга выгнута вправо +local function arcPoint(v, r) + local th = math.rad(-GAUGE_DEG / 2 + GAUGE_DEG * v) + return GAUGE_C + Vector2.new(math.cos(th) * r, -math.sin(th) * r), -math.deg(th) +end +do + local segLen = 2 * math.pi * GAUGE_R * (GAUGE_DEG / 360) / GAUGE_N + for _, layer in ipairs({ { 46, 4, BLACK }, { 34, 1 } }) do -- чёрная обводка, потом цветные секции + for i = 0, GAUGE_N - 1 do + local v = (i + 0.5) / GAUGE_N + local pos, rot = arcPoint(v, GAUGE_R) + local color = layer[3] + or ((v < 0.12 or v > 0.94) and C.red) + or (inPerfect(v) and Color3.fromRGB(110, 235, 60)) + or Color3.fromRGB(40, 70, 95) + new("Frame", { + Size = UDim2.fromOffset(layer[1], segLen + layer[2]), AnchorPoint = Vector2.new(0.5, 0.5), + Position = UDim2.fromOffset(pos.X, pos.Y), Rotation = rot, BorderSizePixel = 0, + BackgroundColor3 = color, Parent = gauge, + }) + end + end +end +local needle = new("Frame", { + Size = UDim2.fromOffset(64, 8), AnchorPoint = Vector2.new(0.5, 0.5), BackgroundColor3 = WHITE, + BorderSizePixel = 0, ZIndex = 3, Parent = gauge, +}, { corner(4), stroke(BLACK, 2) }) +local multLabel = text({ + Size = UDim2.fromOffset(110, 40), AnchorPoint = Vector2.new(0.5, 1), Font = TITLE, TextSize = 34, + Text = "×" .. Config.CastPerfectLuck, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 4, + Visible = false, Parent = gauge, +}) +new("UIStroke", { Color = BLACK, Thickness = 3, Parent = multLabel }) +do + local top = arcPoint(1, GAUGE_R) + multLabel.Position = UDim2.fromOffset(top.X + 10, top.Y - 18) +end + +local function updateCharge() + local p = chargePower() + local pos, rot = arcPoint(p, GAUGE_R) + needle.Position = UDim2.fromOffset(pos.X, pos.Y) + needle.Rotation = rot + local good = inPerfect(p) + multLabel.Visible = good + needle.BackgroundColor3 = good and Color3.fromRGB(190, 255, 150) or WHITE + if charge.tool and charge.tool.Parent then + charge.tool.Grip = gripCF(REST_ANGLE + (BACK_ANGLE - REST_ANGLE) * easeOut(p)) + end +end + +---------------------------------------------------------------- камера при забросе +-- зарядка: камера уходит в сторону от персонажа и отъезжает тем дальше, чем сильнее замах; +-- бросок: камера сбоку разгоняется за поплавком; потом сверху-сбоку держит в кадре игрока и поплавок + +local CAM_IN, CAM_SETTLE, CAM_RETURN = 0.35, 0.8, 0.6 +local UP = Vector3.new(0, 1, 0) +local fishCam = nil + +local function sideCF(fc, p) + return CFrame.lookAt(fc.hrp + fc.r * (9 + 3 * p) - fc.f * (3 + 2 * p) + UP * (3 + 1.5 * p), fc.hrp + fc.f * 6 + UP) +end +local function chaseCF(fc, p) + return CFrame.lookAt(p + fc.r * 9 - fc.f * 5 + UP * 3, p + fc.f * 3) +end +local function restCF(fc) + local d = ((fc.target - fc.hrp) * Vector3.new(1, 0, 1)).Magnitude + local mid = fc.hrp:Lerp(fc.target, 0.5) + return CFrame.lookAt(mid + fc.r * (8 + d * 0.55) - fc.f * 4 + UP * (6 + d * 0.25), fc.hrp:Lerp(fc.target, 0.6)) +end + local function fishCamStep() local fc = fishCam local cam = workspace.CurrentCamera @@ -4803,62 +5049,80 @@ local function fishCamStep() end return end - local t = os.clock() - fc.t0 + local now = os.clock() local cf, fov - if t < CAST_WINDUP then - local e = easeOut(t / CAST_WINDUP) - cf = fc.origCF:Lerp(fc.windupCF, e) - fov = fc.origFov + 14 * e - elseif t < CAST_WINDUP + CAST_FLIGHT then - if not fc.start then - fc.start = (fc.tip and fc.tip.Parent and fc.tip.WorldPosition) or fc.fallbackStart - end - local a = (t - CAST_WINDUP) / CAST_FLIGHT - local p = fc.start:Lerp(fc.target, a) + UP * (math.sin(a * math.pi) * 6) -- та же дуга, что у поплавка - local chase = CFrame.lookAt(p - fc.flat * 9 + UP * 3.5, p + fc.flat * 4) - local e = easeInOut(a) - cf = fc.windupCF:Lerp(chase, e) - fov = fc.origFov + 14 - 22 * e + if not fc.castT0 then + -- зарядка: плавно уходим в вид сбоку; чем сильнее замах, тем дальше камера и шире обзор + -- после отпускания ЛКМ, пока ждём ответ сервера, держим набранную силу + local p = charge and chargePower() or (fc.power or 0) + fc.power = p + local e = easeOut(math.min(1, (now - fc.t0) / CAM_IN)) + cf = fc.origCF:Lerp(sideCF(fc, p), e) + fov = fc.origFov + 12 * p * e else - local e = easeOut(math.min(1, (t - CAST_WINDUP - CAST_FLIGHT) / CAM_SETTLE)) - local now = os.clock() - local sway = Vector3.new(math.sin(now * 0.7) * 0.5, math.sin(now * 1.1) * 0.25, 0) - if state == "bite" then - sway += Vector3.new(math.random() - 0.5, math.random() - 0.5, 0) * 0.15 + local th = fc.throw + local t = now - fc.castT0 + local lunge = fc.fromCF + fc.f * 1.5 + if t < th.windup then + -- рывок удочки вперёд: камера подаётся следом + local e = easeOut(t / th.windup) + cf = fc.fromCF:Lerp(lunge, e) + fov = fc.fromFov + 4 * e + elseif t < th.windup + th.flight then + if not fc.start then + fc.start = (fc.tip and fc.tip.Parent and fc.tip.WorldPosition) or (fc.hrp + fc.f * 2 + UP * 4) + end + local a = (t - th.windup) / th.flight + local p = fc.start:Lerp(fc.target, a) + UP * (math.sin(a * math.pi) * th.arc) -- та же дуга, что у поплавка + local e = easeInOut(a) + cf = lunge:Lerp(chaseCF(fc, p), e) + fov = (fc.fromFov + 4) + ((fc.origFov - 6) - (fc.fromFov + 4)) * e + else + local e = easeOut(math.min(1, (t - th.windup - th.flight) / CAM_SETTLE)) + local sway = Vector3.new(math.sin(now * 0.7) * 0.5, math.sin(now * 1.1) * 0.25, 0) + if state == "bite" then + sway += Vector3.new(math.random() - 0.5, math.random() - 0.5, 0) * 0.15 + end + cf = chaseCF(fc, fc.target):Lerp(restCF(fc) + sway, e) + fov = fc.origFov - 6 + 6 * e end - cf = fc.landCF:Lerp(fc.restCF + sway, e) - fov = fc.origFov - 8 + 8 * e end cam.CFrame = cf cam.FieldOfView = fov end -local function startFishCam(target) +-- начало зарядки: dir — куда полетит поплавок (к центру озера) +local function startChargeCam(tool, dir) local cam = workspace.CurrentCamera - local char = player.Character - local hrp = char and char:FindFirstChild("HumanoidRootPart") - if not cam or not hrp or typeof(target) ~= "Vector3" then + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + if not cam or not hrp then return end - local flat = (target - hrp.Position) * Vector3.new(1, 0, 1) - flat = flat.Magnitude > 0.1 and flat.Unit or hrp.CFrame.LookVector - local tool = char:FindFirstChildOfClass("Tool") - local tip = tool and tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") fishCam = { - t0 = os.clock(), target = target, flat = flat, tip = tip, - fallbackStart = hrp.Position + flat * 2 + UP * 4, + t0 = os.clock(), hrp = hrp.Position, f = dir, r = dir:Cross(UP), + tip = tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip"), -- если камера ещё возвращалась с прошлого заброса, возвращаться будем туда же origCF = fishCam and fishCam.origCF or cam.CFrame, origFov = fishCam and fishCam.origFov or cam.FieldOfView, - windupCF = CFrame.lookAt(hrp.Position - flat * 13 + UP * 7, hrp.Position:Lerp(target, 0.5)), - landCF = CFrame.lookAt(target - flat * 9 + UP * 3.5, target + flat * 4), - restCF = CFrame.lookAt(target - flat * 11 + UP * 5.5, target), } cam.CameraType = Enum.CameraType.Scriptable RunService:UnbindFromRenderStep("FishCam") RunService:BindToRenderStep("FishCam", Enum.RenderPriority.Camera.Value + 1, fishCamStep) end +-- сервер принял бросок: target — куда упадёт поплавок, throw — тайминги и высота дуги +local function startCastCam(target, throw) + local cam = workspace.CurrentCamera + if not fishCam or fishCam.returning or not cam or typeof(target) ~= "Vector3" or type(throw) ~= "table" then + return + end + fishCam.castT0 = os.clock() + fishCam.target = target + fishCam.throw = throw + fishCam.fromCF = cam.CFrame + fishCam.fromFov = cam.FieldOfView +end + local function stopFishCam() local cam = workspace.CurrentCamera if not fishCam or fishCam.returning or not cam then @@ -4871,9 +5135,17 @@ end local reelToken local function setState(s) + if s ~= "charging" and charge then + -- зарядку прервали (убрал удочку и т.п.): удочку обратно в покой + if charge.tool.Parent then + charge.tool.Grip = gripCF(REST_ANGLE) + end + charge = nil + end state = s statusLabel.Visible = (s == "waiting") mgFrame.Visible = (s == "bite") + gauge.Visible = (s == "charging") setMovementLocked(s ~= "idle") if s == "idle" then stopFishCam() @@ -4902,11 +5174,39 @@ local function placeZone() zoneF.Position = UDim2.fromScale(mg.zoneStart, 0) end +-- ЛКМ зажата: персонаж разворачивается к центру озера, начинается зарядка +local function startCharge(tool) + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + if not hrp then + return + end + local world = Config.WorldAt(hrp.Position) + local dir = world and Config.CastDirection(world, hrp.Position) + if not dir then + dir = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) + dir = dir.Magnitude > 0.01 and dir.Unit or Vector3.new(0, 0, -1) + end + hrp.CFrame = CFrame.lookAt(hrp.Position, hrp.Position + dir) + charge = { t0 = os.clock(), tool = tool } + setState("charging") + startChargeCam(tool, dir) + updateCharge() +end + +-- ЛКМ отпущена: бросок с набранной силой +local function releaseCast() + if state ~= "charging" or not charge then + return + end + local power = chargePower() + castTool = charge.tool + charge = nil -- удочку не возвращаем: сервер сам сделает рывок вперёд + setState("casting") + remote:FireServer("Cast", power) +end + local function onActivate() - if state == "idle" then - setState("casting") - remote:FireServer("Cast") - elseif state == "waiting" then + if state == "waiting" then remote:FireServer("Cancel") setState("idle") elseif state == "bite" then @@ -4940,7 +5240,14 @@ local function hookTool(tool) return end hooked[tool] = true - tool.Activated:Connect(onActivate) + tool.Activated:Connect(function() + if state == "idle" then + startCharge(tool) + else + onActivate() + end + end) + tool.Deactivated:Connect(releaseCast) tool.Unequipped:Connect(function() if state == "waiting" or state == "bite" or state == "casting" then remote:FireServer("Cancel") @@ -4970,6 +5277,12 @@ if player.Character then watch(player.Character) end +RunService.RenderStepped:Connect(function() + if state == "charging" and charge then + updateCharge() + end +end) + RunService.RenderStepped:Connect(function(dt) if state ~= "bite" then return @@ -5065,6 +5378,170 @@ task.spawn(function() end end) +---------------------------------------------------------------- обучение: линия-подсказка +-- белые «стрелки» бегут по земле от игрока к цели текущего шага (см. Config.TutorialDone) + +local GUIDE_N, GUIDE_GAP, GUIDE_SPEED = 32, 3, 7 -- сколько стрелок, шаг между ними, скорость бега +local W1 = Config.Worlds[1].center +local guideStep = 0 -- шаг, отправленный на сервер (атрибут Tutorial может прийти чуть позже) + +local guideHint = text({ + Size = UDim2.fromOffset(560, 42), AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, 64), + BackgroundTransparency = 0.2, BackgroundColor3 = C.bg, Font = TITLE, TextSize = 20, + TextXAlignment = Enum.TextXAlignment.Center, Visible = false, Parent = gui, +}, nil) +corner(12).Parent = guideHint +stroke(C.gold, 2).Parent = guideHint + +local guideFolder = new("Folder", { Name = "TutorialGuide", Parent = workspace }) +local chevrons = {} +for i = 1, GUIDE_N do + local arms = {} + for k = 1, 2 do + arms[k] = new("Part", { + Anchored = true, CanCollide = false, CanQuery = false, CanTouch = false, CastShadow = false, + Material = Enum.Material.Neon, Color = WHITE, Size = Vector3.new(0.32, 0.06, 1.35), Transparency = 1, + Parent = guideFolder, + }) + end + chevrons[i] = arms +end +-- две «палочки» стрелки «>» острием вперёд (по -Z) +local ARM_CF = {} +for k, s in ipairs({ -1, 1 }) do + local center = Vector3.new(s * 0.45, 0, -0.1) + ARM_CF[k] = CFrame.lookAt(center, center + Vector3.new(s * 0.9, 0, 1)) +end +local function hideChevrons(from) + for i = from, GUIDE_N do + chevrons[i][1].Transparency = 1 + chevrons[i][2].Transparency = 1 + end +end + +local guideRay = RaycastParams.new() +guideRay.FilterType = Enum.RaycastFilterType.Exclude +guideRay.RespectCanCollide = true +guideRay.IgnoreWater = false + +local function tutorialStep() + return math.max(player:GetAttribute("Tutorial") or 0, guideStep) +end +local function advanceTutorial(step) + if step > tutorialStep() then + guideStep = step + remote:FireServer("Tutorial", step) + if step >= Config.TutorialDone then + notify("🎓 Обучение пройдено! Дальше — сам: лови, улучшай удочку, открывай миры", C.gold) + end + end +end + +local function guideMarker(name) + local map = workspace:FindFirstChild("FishingMap") + local m = map and map:FindFirstChild(name) + return m and m.Position +end + +-- маршрут для текущего шага: точки ломаной (без игрока) и подсказка; nil — линию не показываем +local function guideRoute(step, pos, world) + local inW1 = world and world.id == "World1" + if step == 0 and not world then + return { guideMarker("GuideBoard") }, "📋 Прочитай табличку «Как играть»" + elseif not world then -- шаги 1–3 из лобби: сначала в портал + return { guideMarker("GuidePortal") }, "🌊 Иди в портал «Тихое озеро»" + elseif step == 2 and inW1 then + return { guideMarker("GuideFishSpot") }, "🎣 Иди на причал, зажми ЛКМ и отпусти — заброс!" + elseif step == 3 and inW1 then + local route = {} + local rel = pos - W1 + if math.abs(rel.X) < 6 and rel.Z < 80 then + table.insert(route, W1 + Vector3.new(0, 4.5, 84)) -- сначала сойти с причала + end + table.insert(route, guideMarker("GuideSell")) + return route, "💰 Продай рыбу в скупке" + end + return nil +end + +RunService.RenderStepped:Connect(function() + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + local step = tutorialStep() + -- пока сервер не прислал шаг (данные ещё грузятся), ничего не показываем + if not hrp or player:GetAttribute("Tutorial") == nil or step >= Config.TutorialDone then + guideHint.Visible = false + hideChevrons(1) + return + end + local pos = hrp.Position + local world = Config.WorldAt(pos) + + -- переходы между шагами + if step <= 1 and world and world.id == "World1" then + advanceTutorial(2) + elseif step == 0 then + local board = guideMarker("GuideBoard") + if board and (board - pos).Magnitude < 9 then + advanceTutorial(1) + end + elseif step == 2 and (player:GetAttribute("TotalCaught") or 0) > 0 then + advanceTutorial(3) + end + step = tutorialStep() + + local route, hint = guideRoute(step, pos, world) + guideHint.Text = hint or "" + guideHint.Visible = hint ~= nil and state == "idle" + if not route or #route == 0 or state ~= "idle" then + hideChevrons(1) + return + end + + -- ломаная от ног игрока через точки маршрута + local pts = { pos - Vector3.new(0, 3, 0) } + for _, p in ipairs(route) do + table.insert(pts, p) + end + local lens, total = {}, 0 + for i = 2, #pts do + local d = ((pts[i] - pts[i - 1]) * Vector3.new(1, 0, 1)).Magnitude + lens[i] = math.max(d, 0.001) + total += d + end + if total < 4 then + hideChevrons(1) -- уже на месте + return + end + + guideRay.FilterDescendantsInstances = { player.Character, guideFolder } + local phase = (os.clock() * GUIDE_SPEED) % GUIDE_GAP + local seg, segStart = 2, 0 + for i = 1, GUIDE_N do + local d = 2 + phase + (i - 1) * GUIDE_GAP + if d > total - 1 then + hideChevrons(i) + break + end + while seg < #pts and d > segStart + lens[seg] do + segStart += lens[seg] + seg += 1 + end + local a, b = pts[seg - 1], pts[seg] + local p = a:Lerp(b, (d - segStart) / lens[seg]) + local dir = (b - a) * Vector3.new(1, 0, 1) + local hit = workspace:Raycast(p + Vector3.new(0, 4, 0), Vector3.new(0, -12, 0), guideRay) + local y = hit and hit.Position.Y or p.Y + local base = CFrame.lookAt(Vector3.new(p.X, y + 0.08, p.Z), Vector3.new(p.X, y + 0.08, p.Z) + dir) + -- у игрока и у цели стрелки плавно проявляются и гаснут + local fade = math.max(0, 1 - math.min(d - 2, total - 1 - d) / 2.5) + local tr = 0.1 + 0.9 * fade + for k = 1, 2 do + chevrons[i][k].CFrame = base * ARM_CF[k] + chevrons[i][k].Transparency = tr + end + end +end) + ---------------------------------------------------------------- события от сервера remote.OnClientEvent:Connect(function(action, a, b, c) @@ -5072,8 +5549,11 @@ remote.OnClientEvent:Connect(function(action, a, b, c) notify(a, b) elseif action == "Cast" then setState("waiting") - startFishCam(a) + startCastCam(a, b) elseif action == "CastFail" or action == "Cancel" or action == "Escaped" then + if action == "CastFail" and castTool and castTool.Parent then + castTool.Grip = gripCF(REST_ANGLE) -- сервер удочку не трогал, а у нас она в замахе + end setState("idle") elseif action == "Bite" then mg.speed = a.speed @@ -5093,6 +5573,9 @@ remote.OnClientEvent:Connect(function(action, a, b, c) showCatch(a, b) playUiSound(DING, 0.5) elseif action == "Sold" then + if tutorialStep() == 3 then + advanceTutorial(Config.TutorialDone) + end floatText("+" .. fmt(a) .. " 💰", C.gold) notify(("Продано рыб: %d → +%s 💰"):format(b, fmt(a)), Color3.fromRGB(120, 255, 140)) elseif action == "Inventory" then diff --git a/src/ReplicatedStorage/FishConfig.lua b/src/ReplicatedStorage/FishConfig.lua index 72b78fe..5e0f607 100644 --- a/src/ReplicatedStorage/FishConfig.lua +++ b/src/ReplicatedStorage/FishConfig.lua @@ -57,6 +57,35 @@ function Config.WorldAt(pos) return nil end +-- куда бросать из этой точки (единичный вектор по горизонтали): к центру ближайшего озера или лунки, +-- а если ближе море — от центра острова к морю +function Config.CastDirection(world, pos) + if not world then + return nil + end + local x, z = pos.X - world.center.X, pos.Z - world.center.Z + local best, bestGap + local function consider(dir, gap) + if dir.Magnitude > 0.1 and (not bestGap or gap < bestGap) then + best, bestGap = dir.Unit, gap + end + end + if world.holes then + for _, h in ipairs(world.holes) do + consider(Vector3.new(h[1] - x, 0, h[2] - z), math.sqrt((h[1] - x) ^ 2 + (h[2] - z) ^ 2) - (world.holeRadius or 6)) + end + end + for _, l in ipairs(world.lakes or {}) do + if not world.holes then -- в Мире 3 озёра подо льдом, бросаем только в лунки + consider(Vector3.new(l[1] - x, 0, l[2] - z), math.sqrt((l[1] - x) ^ 2 + (l[2] - z) ^ 2) - l[3]) + end + end + if world.sea then + consider(Vector3.new(x, 0, z), world.sea - math.sqrt(x * x + z * z)) + end + return best +end + -- есть ли вода в этой точке мира (озеро, море или лунка) function Config.IsWater(world, pos) if not world then @@ -263,6 +292,15 @@ Config.BiteTimeMin = 3 Config.BiteTimeMax = 7 Config.BiteTimeout = 12 Config.MaxMisses = 2 +-- заброс: держишь ЛКМ — сила растёт от 0 до 1; от силы зависит дальность +Config.CastChargeTime = 1.3 -- секунд до полной силы +Config.CastMinDist, Config.CastMaxDist = 6, 28 +Config.CastPerfect = { 0.72, 0.86 } -- зелёная зона шкалы +Config.CastPerfectLuck = 1.2 -- множитель удачи за попадание в зелёную зону + +-- обучение: линия-подсказка ведёт по шагам 0 → 1 → 2 → 3, на 4 обучение пройдено +-- 0 — табличка «Как играть», 1 — портал в Мир 1, 2 — причал (поймать рыбу), 3 — скупка (продать) +Config.TutorialDone = 4 function Config.HitsNeeded(rank) return math.ceil(rank / 2) end diff --git a/src/ServerScriptService/GameServer.server.lua b/src/ServerScriptService/GameServer.server.lua index a38b49b..a918dbb 100644 --- a/src/ServerScriptService/GameServer.server.lua +++ b/src/ServerScriptService/GameServer.server.lua @@ -219,6 +219,8 @@ local function updateStats(player) player:SetAttribute("BoostBonus", boostActive(data)) player:SetAttribute("BoostLeft", math.max(0, data.boostUntil - os.time())) player:SetAttribute("TotalCaught", data.totalCaught) + -- шаг обучения (линия-подсказка); у старых игроков без поля, уже ловивших рыбу, обучение пройдено + player:SetAttribute("Tutorial", data.tutorial or (data.totalCaught > 0 and Config.TutorialDone or 0)) player:SetAttribute("Mastery", masteryCount(data)) player:SetAttribute("Passes", table.concat(ps, ",")) @@ -541,6 +543,28 @@ local function splash(part, count) end -- рыба вылетает из воды, летит к игроку и показывается над головой +-- шлейф за летящим предметом — эффект быстрого движения (ширина — расстояние между точками крепления) +local TRAIL_COLOR = Color3.fromRGB(215, 245, 255) +local function addTrail(part, width) + local a0 = Instance.new("Attachment") + a0.Position = Vector3.new(0, width / 2, 0) + a0.Parent = part + local a1 = Instance.new("Attachment") + a1.Position = Vector3.new(0, -width / 2, 0) + a1.Parent = part + local trail = Instance.new("Trail") + trail.Attachment0, trail.Attachment1 = a0, a1 + trail.FaceCamera = true + trail.Lifetime = 0.35 + trail.MinLength = 0.05 + trail.LightEmission = 0.7 + trail.Color = ColorSequence.new(TRAIL_COLOR) + trail.Transparency = NumberSequence.new({ NumberSequenceKeypoint.new(0, 0.1), NumberSequenceKeypoint.new(1, 1) }) + trail.WidthScale = NumberSequence.new({ NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(1, 0) }) + trail.Parent = part + return trail +end + local function showFishFlight(player, fish, fromPos) local head = player.Character and player.Character:FindFirstChild("Head") if not head then @@ -549,6 +573,14 @@ local function showFishFlight(player, fish, fromPos) local model = Models.buildFish(fish.id, fish.mutation, 0.9, true) model:PivotTo(CFrame.new(fromPos)) model.Parent = workspace + -- шлейф на отдельной невидимой детали: рыба крутится, а шлейф должен оставаться ровным + local carrier = Instance.new("Part") + carrier.Anchored, carrier.CanCollide, carrier.CanQuery, carrier.CanTouch = true, false, false, false + carrier.Transparency = 1 + carrier.Size = Vector3.new(0.2, 0.2, 0.2) + carrier.CFrame = CFrame.new(fromPos) + carrier.Parent = model + local trail = addTrail(carrier, 1.8) task.spawn(function() local t0, dur = os.clock(), 0.55 while head.Parent do @@ -556,11 +588,13 @@ local function showFishFlight(player, fish, fromPos) local target = head.Position + Vector3.new(0, 2.8, 0) local p = fromPos:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * 8, 0) model:PivotTo(CFrame.new(p) * CFrame.Angles(0, 0, a * math.pi * 2)) + carrier.CFrame = CFrame.new(p) if a >= 1 then break end RunService.Heartbeat:Wait() end + trail.Enabled = false local t1 = os.clock() while head.Parent and os.clock() - t1 < 1.8 do model:PivotTo(CFrame.new(head.Position + Vector3.new(0, 2.8, 0)) * CFrame.Angles(0, os.clock() * 3, math.rad(-15))) @@ -574,22 +608,59 @@ end local fishing = {} --- ищем воду перед игроком по карте мира из FishConfig (не зависит от террейна) -local function findWater(hrp, world) - local look = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) - if look.Magnitude < 0.01 then - look = Vector3.new(0, 0, -1) +-- ищем воду по карте мира из FishConfig (не зависит от террейна) в сторону центра ближайшего озера: +-- сначала на дальности, которую задала сила заброса, потом всё дальше от неё +local function findWater(hrp, world, power) + local look = Config.CastDirection(world, hrp.Position) + if not look then + look = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) + look = look.Magnitude > 0.01 and look.Unit or Vector3.new(0, 0, -1) end - look = look.Unit - for _, d in ipairs({ 14, 11, 17, 8, 20, 6, 24, 4 }) do - local p = hrp.Position + look * d - if Config.IsWater(world, p) then - return Vector3.new(p.X, world.waterY or 0, p.Z) + local want = Config.CastMinDist + (Config.CastMaxDist - Config.CastMinDist) * power + for off = 0, 26, 2 do + for _, d in ipairs({ want - off, want + off }) do + if d >= 4 and d <= Config.CastMaxDist + 2 then + local p = hrp.Position + look * d + if Config.IsWater(world, p) then + return Vector3.new(p.X, world.waterY or 0, p.Z), d + end + end end end return nil end +-- вытягивание пустого поплавка: быстро летит к кончику удочки со шлейфом и исчезает +local function reelBobber(bobber, tool) + local root = bobber and bobber.PrimaryPart + local tip = tool and tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") + if not root or not tip then + if bobber then + bobber:Destroy() + end + return + end + local trail = bobber:FindFirstChildWhichIsA("Trail", true) + if trail then + trail.Enabled = true + else + addTrail(root, 1.2) + end + local from = root.Position + task.spawn(function() + local t0, dur = os.clock(), 0.3 + while bobber.Parent and tip.Parent do + local a = math.min(1, (os.clock() - t0) / dur) + bobber:PivotTo(CFrame.new(from:Lerp(tip.WorldPosition, a) + Vector3.new(0, math.sin(a * math.pi) * 2.5, 0))) + if a >= 1 then + break + end + RunService.Heartbeat:Wait() + end + bobber:Destroy() + end) +end + local function stopFishing(player, tellClient) local s = fishing[player] if not s then @@ -600,7 +671,11 @@ local function stopFishing(player, tellClient) s.tween:Cancel() end if s.bobber then - s.bobber:Destroy() + if s.stage == "casting" then + s.bobber:Destroy() -- ещё летит: его двигает flyBobber + else + reelBobber(s.bobber, s.tool) + end end if s.tool then tweenGrip(s.tool, REST_ANGLE, 0.3) @@ -610,12 +685,12 @@ local function stopFishing(player, tellClient) end end -local function rollFish(player, data, worldId) +local function rollFish(player, data, worldId, luckMult) local zone = Config.Zones[worldId] if not zone then return nil end - local luck = totalLuck(player, data) + local luck = totalLuck(player, data) * (luckMult or 1) local bonus = luck - 1 local weights, total = {}, 0 for i, f in ipairs(zone.fish) do @@ -657,13 +732,14 @@ local function rollFish(player, data, worldId) } end -local function flyBobber(s, tool, target) +local function flyBobber(s, tool, target, dur, arc) local tip = tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") local start = tip and tip.WorldPosition or (target + Vector3.new(0, 6, 0)) local bobber = Models.buildBobber() bobber:PivotTo(CFrame.new(start)) bobber.Parent = workspace s.bobber = bobber + local trail = addTrail(bobber.PrimaryPart, 1.2) if tip then local a1 = Instance.new("Attachment") a1.Position = Vector3.new(0, 0.9, 0) @@ -677,22 +753,24 @@ local function flyBobber(s, tool, target) line.Color = ColorSequence.new(Color3.fromRGB(245, 245, 245)) line.Parent = bobber end - local t0, dur = os.clock(), 0.55 + local t0 = os.clock() while bobber.Parent do local a = math.min(1, (os.clock() - t0) / dur) - bobber:PivotTo(CFrame.new(start:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * 6, 0))) + bobber:PivotTo(CFrame.new(start:Lerp(target, a) + Vector3.new(0, math.sin(a * math.pi) * arc, 0))) if a >= 1 then break end RunService.Heartbeat:Wait() end + trail.Enabled = false -- на воде поплавок качается, шлейф уже не нужен if bobber.Parent then splash(bobber.PrimaryPart, 18) playSound(bobber.PrimaryPart, SPLASH_SOUND, 0.5) end end -local function onCast(player) +local function onCast(player, power) + power = math.clamp(tonumber(power) or 0.6, 0, 1) local data = profiles[player] if not data then return @@ -709,10 +787,13 @@ local function onCast(player) return end local world = Config.WorldAt(hrp.Position) - local target = world and findWater(hrp, world) + local target, dist = nil, 0 + if world then + target, dist = findWater(hrp, world, power) + end if not target then remote:FireClient(player, "CastFail") - notify(player, world and "Повернись лицом к воде (или к лунке)!" or "Здесь нет рыбы — иди в один из миров 🌍", Color3.fromRGB(255, 200, 120)) + notify(player, world and "Подойди ближе к воде (или к лунке)!" or "Здесь нет рыбы — иди в один из миров 🌍", Color3.fromRGB(255, 200, 120)) return end if #data.items >= bagCapacity(player, data) then @@ -722,29 +803,28 @@ local function onCast(player) end local stats = Config.RodStats(data.rod, rodLevel(data)) - local fish = rollFish(player, data, world.id) + local perfect = power >= Config.CastPerfect[1] and power <= Config.CastPerfect[2] + local fish = rollFish(player, data, world.id, perfect and Config.CastPerfectLuck or 1) if not fish then remote:FireClient(player, "CastFail") return end local s = { stage = "casting", fish = fish, tool = tool } fishing[player] = s - remote:FireClient(player, "Cast", target + Vector3.new(0, 0.15, 0)) -- клиенту для камеры + -- замах игрок уже сделал, пока держал кнопку (у себя на клиенте); здесь только бросок вперёд + local throw = { windup = 0.15, flight = 0.35 + dist * 0.018, arc = 2 + dist * 0.3, perfect = perfect } + local splashAt = target + Vector3.new(0, 0.15, 0) + remote:FireClient(player, "Cast", splashAt, throw) -- клиенту для камеры task.spawn(function() - -- замах назад и бросок вперёд - local tw = tweenGrip(tool, 100, 0.25) - if tw then - tw.Completed:Wait() - end - tw = tweenGrip(tool, 8, 0.15) + local tw = tweenGrip(tool, 8, throw.windup) if tw then tw.Completed:Wait() end if fishing[player] ~= s then return end - flyBobber(s, tool, target + Vector3.new(0, 0.15, 0)) + flyBobber(s, tool, splashAt, throw.flight, throw.arc) tweenGrip(tool, REST_ANGLE - 5, 0.4) if fishing[player] ~= s then if s.bobber then @@ -809,11 +889,14 @@ local function onCatch(player, success, misses) if s.tween then s.tween:Cancel() end - if s.bobber then - s.bobber:Destroy() + local failed = success ~= true or os.clock() - s.biteAt > Config.BiteTimeout + 1 + if failed then + reelBobber(s.bobber, tool) + elseif s.bobber then + s.bobber:Destroy() -- вместо поплавка к игроку летит рыба end - if success ~= true or os.clock() - s.biteAt > Config.BiteTimeout + 1 then + if failed then gripSequence(tool, { { REST_ANGLE, 0.3 } }) remote:FireClient(player, "Escaped") notify(player, "Рыба сорвалась!", RED) @@ -1094,7 +1177,15 @@ end) remote.OnServerEvent:Connect(function(player, action, a, b) if action == "Cast" then - onCast(player) + onCast(player, a) + elseif action == "Tutorial" then + -- шаги обучения идут только вперёд + local data = profiles[player] + local step = math.floor(tonumber(a) or 0) + if data and step > (player:GetAttribute("Tutorial") or 0) and step <= Config.TutorialDone then + data.tutorial = step + player:SetAttribute("Tutorial", step) + end elseif action == "Catch" then onCatch(player, a, b) elseif action == "Cancel" then diff --git a/src/ServerScriptService/MapBuilder.server.lua b/src/ServerScriptService/MapBuilder.server.lua index 9d17df2..7c599f0 100644 --- a/src/ServerScriptService/MapBuilder.server.lua +++ b/src/ServerScriptService/MapBuilder.server.lua @@ -677,6 +677,9 @@ for i, w in ipairs(Config.Worlds) do local a = math.rad(90 - (i - 1) * 90) -- 90° = сторона спавна (+Z) local pos = V(math.cos(a) * PORTAL_R, FLOOR, math.sin(a) * PORTAL_R) portal(CFrame.lookAt(pos, V(pos.X * 2, FLOOR, pos.Z * 2)), title, w.color, w.id, w.soon) + if i == 1 then + marker("GuidePortal", CFrame.new(pos.X * 1.3, FLOOR, pos.Z * 1.3)) -- точка перед порталом для линии-подсказки + end end -- невидимая стена по кругу: из лобби не уйти @@ -761,12 +764,13 @@ do local pos = V(-12, FLOOR, 48) local cf = CFrame.lookAt(pos, V(0, FLOOR, 64)) lamp((cf * CFrame.new(0, 0, 2.5)).Position) + marker("GuideBoard", cf * CFrame.new(0, 0, -6)) -- перед табличкой, для линии-подсказки for _, x in ipairs({ -6.5, 6.5 }) do P({ Size = V(0.8, 9, 0.8), CFrame = cf * CFrame.new(x, 4.5, 0.3), Material = Enum.Material.Wood, Color = Color3.fromRGB(90, 60, 40) }) end local board = P({ Size = V(14, 8, 0.5), CFrame = cf * CFrame.new(0, 6, 0), Material = Enum.Material.WoodPlanks, Color = Color3.fromRGB(70, 48, 32) }) surfaceText(board, Enum.NormalId.Front, - "КАК ИГРАТЬ\n1. Портал «Мир 1» или кнопка 🌍 Миры\n2. Удочка — клавиша 1, клик у воды\n3. Клюёт → кликай в зелёную зону\n4. 🎒 Сумка — B, 📜 Задания — Q\n5. Собирай коллекцию — получай награды!", + "КАК ИГРАТЬ\n1. Портал «Мир 1» или кнопка 🌍 Миры\n2. Удочка — клавиша 1, у воды зажми ЛКМ и отпусти\n3. Клюёт → кликай в зелёную зону\n4. 🎒 Сумка — B, 📜 Задания — Q\n5. Собирай коллекцию — получай награды!", Color3.fromRGB(255, 245, 225), { TextXAlignment = Enum.TextXAlignment.Left }) end @@ -787,6 +791,9 @@ local arrive = W + V(0, GROUND_Y, 94) marker("World1Spawn", CFrame.lookAt(arrive + V(0, 1, 0), arrive + V(0, 1, -10))) arch(CFrame.new(W + V(0, GROUND_Y, 82)), 14, 11, "🌊 ТИХОЕ ОЗЕРО", Color3.fromRGB(80, 200, 255)) portal(CFrame.lookAt(W + V(-22, GROUND_Y, 96), arrive), "🏠 В лобби", Color3.fromRGB(255, 200, 80), "Lobby") +-- точки для линии-подсказки: конец главного причала и место перед скупкой +marker("GuideFishSpot", CFrame.new(W + V(0, GROUND_Y + 0.5, 42))) +marker("GuideSell", CFrame.lookAt(W + V(26, GROUND_Y, 98), arrive) * CFrame.new(0, 0, -10)) stall(CFrame.lookAt(W + V(26, GROUND_Y, 98), arrive), { title = "💰 СКУПКА", titleColor = Color3.fromRGB(150, 255, 160), diff --git a/src/StarterPlayer/StarterPlayerScripts/FishingClient.client.lua b/src/StarterPlayer/StarterPlayerScripts/FishingClient.client.lua index 6961083..be1d402 100644 --- a/src/StarterPlayer/StarterPlayerScripts/FishingClient.client.lua +++ b/src/StarterPlayer/StarterPlayerScripts/FishingClient.client.lua @@ -1045,8 +1045,15 @@ refreshHud() local state = "idle" local mg = { pos = 0, dir = 1, speed = 1, zoneStart = 0.4, zoneWidth = 0.25, hits = 0, need = 1, misses = 0, maxMisses = 2, deadline = 0, timeout = 10 } --- пока удочка заброшена, ходить и прыгать нельзя +-- с начала зарядки и до конца рыбалки персонажем не управляем: не ходит, не прыгает, не поворачивается +local ContextActionService = game:GetService("ContextActionService") +local MOVE_KEYS = { + Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D, Enum.KeyCode.Space, + Enum.KeyCode.Up, Enum.KeyCode.Down, Enum.KeyCode.Left, Enum.KeyCode.Right, + Enum.KeyCode.Thumbstick1, Enum.KeyCode.ButtonA, +} local controls +local movementLocked = false local function setMovementLocked(locked) if not controls then local pm = player:FindFirstChild("PlayerScripts") and player.PlayerScripts:FindFirstChild("PlayerModule") @@ -1060,17 +1067,26 @@ local function setMovementLocked(locked) controls:Enable() end end + if locked ~= movementLocked then + movementLocked = locked + if locked then + ContextActionService:BindActionAtPriority("FishingLock", function() + return Enum.ContextActionResult.Sink + end, false, Enum.ContextActionPriority.High.Value + 100, table.unpack(MOVE_KEYS)) + else + ContextActionService:UnbindAction("FishingLock") + end + end + local hum = player.Character and player.Character:FindFirstChildOfClass("Humanoid") + if hum then + hum.AutoRotate = not locked + hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, not locked) + if locked then + hum:Move(Vector3.zero) + end + end end ----------------------------------------------------------------- камера при забросе --- замах: камера отъезжает и расширяется обзор; полёт: камера разгоняется за поплавком; --- потом смотрит на поплавок, пока рыбалка не закончится, и плавно возвращается - -local CAST_WINDUP, CAST_FLIGHT = 0.4, 0.55 -- как в GameServer: замах и полёт поплавка -local CAM_SETTLE, CAM_RETURN = 0.7, 0.6 -local UP = Vector3.new(0, 1, 0) -local fishCam = nil - local function easeInOut(a) return a < 0.5 and 4 * a * a * a or 1 - (-2 * a + 2) ^ 3 / 2 end @@ -1078,6 +1094,100 @@ local function easeOut(a) return 1 - (1 - a) ^ 3 end +---------------------------------------------------------------- заброс: зарядка, шкала силы, наклон удочки +-- держишь ЛКМ — сила растёт, удочка уходит назад; отпустил — бросок на дальность по силе + +local REST_ANGLE, BACK_ANGLE = 30, 110 -- удочка в покое (как в GameServer) и в полном замахе +local function gripCF(angle) + return (CFrame.Angles(math.rad(angle), 0, 0) * CFrame.new(0, 0, -0.3)):Inverse() +end + +local charge = nil -- { t0, tool } +local castTool = nil -- удочка последнего броска: вернуть её в покой, если бросок не удался +local function chargePower() + return charge and math.min(1, (os.clock() - charge.t0) / Config.CastChargeTime) or 0 +end +local function inPerfect(v) + return v >= Config.CastPerfect[1] and v <= Config.CastPerfect[2] +end + +-- шкала-дуга справа от персонажа: внизу слабый бросок, вверху сильный, зелёная зона — бонус удачи +local GAUGE_R, GAUGE_DEG, GAUGE_N = 190, 110, 32 +local gauge = new("Frame", { + Size = UDim2.fromOffset(150, 280), AnchorPoint = Vector2.new(0, 0.5), Position = UDim2.new(0.57, 0, 0.48, 0), + BackgroundTransparency = 1, Visible = false, Parent = gui, +}) +local GAUGE_C = Vector2.new(110 - GAUGE_R, 140) -- центр окружности левее рамки: дуга выгнута вправо +local function arcPoint(v, r) + local th = math.rad(-GAUGE_DEG / 2 + GAUGE_DEG * v) + return GAUGE_C + Vector2.new(math.cos(th) * r, -math.sin(th) * r), -math.deg(th) +end +do + local segLen = 2 * math.pi * GAUGE_R * (GAUGE_DEG / 360) / GAUGE_N + for _, layer in ipairs({ { 46, 4, BLACK }, { 34, 1 } }) do -- чёрная обводка, потом цветные секции + for i = 0, GAUGE_N - 1 do + local v = (i + 0.5) / GAUGE_N + local pos, rot = arcPoint(v, GAUGE_R) + local color = layer[3] + or ((v < 0.12 or v > 0.94) and C.red) + or (inPerfect(v) and Color3.fromRGB(110, 235, 60)) + or Color3.fromRGB(40, 70, 95) + new("Frame", { + Size = UDim2.fromOffset(layer[1], segLen + layer[2]), AnchorPoint = Vector2.new(0.5, 0.5), + Position = UDim2.fromOffset(pos.X, pos.Y), Rotation = rot, BorderSizePixel = 0, + BackgroundColor3 = color, Parent = gauge, + }) + end + end +end +local needle = new("Frame", { + Size = UDim2.fromOffset(64, 8), AnchorPoint = Vector2.new(0.5, 0.5), BackgroundColor3 = WHITE, + BorderSizePixel = 0, ZIndex = 3, Parent = gauge, +}, { corner(4), stroke(BLACK, 2) }) +local multLabel = text({ + Size = UDim2.fromOffset(110, 40), AnchorPoint = Vector2.new(0.5, 1), Font = TITLE, TextSize = 34, + Text = "×" .. Config.CastPerfectLuck, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 4, + Visible = false, Parent = gauge, +}) +new("UIStroke", { Color = BLACK, Thickness = 3, Parent = multLabel }) +do + local top = arcPoint(1, GAUGE_R) + multLabel.Position = UDim2.fromOffset(top.X + 10, top.Y - 18) +end + +local function updateCharge() + local p = chargePower() + local pos, rot = arcPoint(p, GAUGE_R) + needle.Position = UDim2.fromOffset(pos.X, pos.Y) + needle.Rotation = rot + local good = inPerfect(p) + multLabel.Visible = good + needle.BackgroundColor3 = good and Color3.fromRGB(190, 255, 150) or WHITE + if charge.tool and charge.tool.Parent then + charge.tool.Grip = gripCF(REST_ANGLE + (BACK_ANGLE - REST_ANGLE) * easeOut(p)) + end +end + +---------------------------------------------------------------- камера при забросе +-- зарядка: камера уходит в сторону от персонажа и отъезжает тем дальше, чем сильнее замах; +-- бросок: камера сбоку разгоняется за поплавком; потом сверху-сбоку держит в кадре игрока и поплавок + +local CAM_IN, CAM_SETTLE, CAM_RETURN = 0.35, 0.8, 0.6 +local UP = Vector3.new(0, 1, 0) +local fishCam = nil + +local function sideCF(fc, p) + return CFrame.lookAt(fc.hrp + fc.r * (9 + 3 * p) - fc.f * (3 + 2 * p) + UP * (3 + 1.5 * p), fc.hrp + fc.f * 6 + UP) +end +local function chaseCF(fc, p) + return CFrame.lookAt(p + fc.r * 9 - fc.f * 5 + UP * 3, p + fc.f * 3) +end +local function restCF(fc) + local d = ((fc.target - fc.hrp) * Vector3.new(1, 0, 1)).Magnitude + local mid = fc.hrp:Lerp(fc.target, 0.5) + return CFrame.lookAt(mid + fc.r * (8 + d * 0.55) - fc.f * 4 + UP * (6 + d * 0.25), fc.hrp:Lerp(fc.target, 0.6)) +end + local function fishCamStep() local fc = fishCam local cam = workspace.CurrentCamera @@ -1096,62 +1206,80 @@ local function fishCamStep() end return end - local t = os.clock() - fc.t0 + local now = os.clock() local cf, fov - if t < CAST_WINDUP then - local e = easeOut(t / CAST_WINDUP) - cf = fc.origCF:Lerp(fc.windupCF, e) - fov = fc.origFov + 14 * e - elseif t < CAST_WINDUP + CAST_FLIGHT then - if not fc.start then - fc.start = (fc.tip and fc.tip.Parent and fc.tip.WorldPosition) or fc.fallbackStart - end - local a = (t - CAST_WINDUP) / CAST_FLIGHT - local p = fc.start:Lerp(fc.target, a) + UP * (math.sin(a * math.pi) * 6) -- та же дуга, что у поплавка - local chase = CFrame.lookAt(p - fc.flat * 9 + UP * 3.5, p + fc.flat * 4) - local e = easeInOut(a) - cf = fc.windupCF:Lerp(chase, e) - fov = fc.origFov + 14 - 22 * e + if not fc.castT0 then + -- зарядка: плавно уходим в вид сбоку; чем сильнее замах, тем дальше камера и шире обзор + -- после отпускания ЛКМ, пока ждём ответ сервера, держим набранную силу + local p = charge and chargePower() or (fc.power or 0) + fc.power = p + local e = easeOut(math.min(1, (now - fc.t0) / CAM_IN)) + cf = fc.origCF:Lerp(sideCF(fc, p), e) + fov = fc.origFov + 12 * p * e else - local e = easeOut(math.min(1, (t - CAST_WINDUP - CAST_FLIGHT) / CAM_SETTLE)) - local now = os.clock() - local sway = Vector3.new(math.sin(now * 0.7) * 0.5, math.sin(now * 1.1) * 0.25, 0) - if state == "bite" then - sway += Vector3.new(math.random() - 0.5, math.random() - 0.5, 0) * 0.15 + local th = fc.throw + local t = now - fc.castT0 + local lunge = fc.fromCF + fc.f * 1.5 + if t < th.windup then + -- рывок удочки вперёд: камера подаётся следом + local e = easeOut(t / th.windup) + cf = fc.fromCF:Lerp(lunge, e) + fov = fc.fromFov + 4 * e + elseif t < th.windup + th.flight then + if not fc.start then + fc.start = (fc.tip and fc.tip.Parent and fc.tip.WorldPosition) or (fc.hrp + fc.f * 2 + UP * 4) + end + local a = (t - th.windup) / th.flight + local p = fc.start:Lerp(fc.target, a) + UP * (math.sin(a * math.pi) * th.arc) -- та же дуга, что у поплавка + local e = easeInOut(a) + cf = lunge:Lerp(chaseCF(fc, p), e) + fov = (fc.fromFov + 4) + ((fc.origFov - 6) - (fc.fromFov + 4)) * e + else + local e = easeOut(math.min(1, (t - th.windup - th.flight) / CAM_SETTLE)) + local sway = Vector3.new(math.sin(now * 0.7) * 0.5, math.sin(now * 1.1) * 0.25, 0) + if state == "bite" then + sway += Vector3.new(math.random() - 0.5, math.random() - 0.5, 0) * 0.15 + end + cf = chaseCF(fc, fc.target):Lerp(restCF(fc) + sway, e) + fov = fc.origFov - 6 + 6 * e end - cf = fc.landCF:Lerp(fc.restCF + sway, e) - fov = fc.origFov - 8 + 8 * e end cam.CFrame = cf cam.FieldOfView = fov end -local function startFishCam(target) +-- начало зарядки: dir — куда полетит поплавок (к центру озера) +local function startChargeCam(tool, dir) local cam = workspace.CurrentCamera - local char = player.Character - local hrp = char and char:FindFirstChild("HumanoidRootPart") - if not cam or not hrp or typeof(target) ~= "Vector3" then + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + if not cam or not hrp then return end - local flat = (target - hrp.Position) * Vector3.new(1, 0, 1) - flat = flat.Magnitude > 0.1 and flat.Unit or hrp.CFrame.LookVector - local tool = char:FindFirstChildOfClass("Tool") - local tip = tool and tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip") fishCam = { - t0 = os.clock(), target = target, flat = flat, tip = tip, - fallbackStart = hrp.Position + flat * 2 + UP * 4, + t0 = os.clock(), hrp = hrp.Position, f = dir, r = dir:Cross(UP), + tip = tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Tip"), -- если камера ещё возвращалась с прошлого заброса, возвращаться будем туда же origCF = fishCam and fishCam.origCF or cam.CFrame, origFov = fishCam and fishCam.origFov or cam.FieldOfView, - windupCF = CFrame.lookAt(hrp.Position - flat * 13 + UP * 7, hrp.Position:Lerp(target, 0.5)), - landCF = CFrame.lookAt(target - flat * 9 + UP * 3.5, target + flat * 4), - restCF = CFrame.lookAt(target - flat * 11 + UP * 5.5, target), } cam.CameraType = Enum.CameraType.Scriptable RunService:UnbindFromRenderStep("FishCam") RunService:BindToRenderStep("FishCam", Enum.RenderPriority.Camera.Value + 1, fishCamStep) end +-- сервер принял бросок: target — куда упадёт поплавок, throw — тайминги и высота дуги +local function startCastCam(target, throw) + local cam = workspace.CurrentCamera + if not fishCam or fishCam.returning or not cam or typeof(target) ~= "Vector3" or type(throw) ~= "table" then + return + end + fishCam.castT0 = os.clock() + fishCam.target = target + fishCam.throw = throw + fishCam.fromCF = cam.CFrame + fishCam.fromFov = cam.FieldOfView +end + local function stopFishCam() local cam = workspace.CurrentCamera if not fishCam or fishCam.returning or not cam then @@ -1164,9 +1292,17 @@ end local reelToken local function setState(s) + if s ~= "charging" and charge then + -- зарядку прервали (убрал удочку и т.п.): удочку обратно в покой + if charge.tool.Parent then + charge.tool.Grip = gripCF(REST_ANGLE) + end + charge = nil + end state = s statusLabel.Visible = (s == "waiting") mgFrame.Visible = (s == "bite") + gauge.Visible = (s == "charging") setMovementLocked(s ~= "idle") if s == "idle" then stopFishCam() @@ -1195,11 +1331,39 @@ local function placeZone() zoneF.Position = UDim2.fromScale(mg.zoneStart, 0) end +-- ЛКМ зажата: персонаж разворачивается к центру озера, начинается зарядка +local function startCharge(tool) + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + if not hrp then + return + end + local world = Config.WorldAt(hrp.Position) + local dir = world and Config.CastDirection(world, hrp.Position) + if not dir then + dir = hrp.CFrame.LookVector * Vector3.new(1, 0, 1) + dir = dir.Magnitude > 0.01 and dir.Unit or Vector3.new(0, 0, -1) + end + hrp.CFrame = CFrame.lookAt(hrp.Position, hrp.Position + dir) + charge = { t0 = os.clock(), tool = tool } + setState("charging") + startChargeCam(tool, dir) + updateCharge() +end + +-- ЛКМ отпущена: бросок с набранной силой +local function releaseCast() + if state ~= "charging" or not charge then + return + end + local power = chargePower() + castTool = charge.tool + charge = nil -- удочку не возвращаем: сервер сам сделает рывок вперёд + setState("casting") + remote:FireServer("Cast", power) +end + local function onActivate() - if state == "idle" then - setState("casting") - remote:FireServer("Cast") - elseif state == "waiting" then + if state == "waiting" then remote:FireServer("Cancel") setState("idle") elseif state == "bite" then @@ -1233,7 +1397,14 @@ local function hookTool(tool) return end hooked[tool] = true - tool.Activated:Connect(onActivate) + tool.Activated:Connect(function() + if state == "idle" then + startCharge(tool) + else + onActivate() + end + end) + tool.Deactivated:Connect(releaseCast) tool.Unequipped:Connect(function() if state == "waiting" or state == "bite" or state == "casting" then remote:FireServer("Cancel") @@ -1263,6 +1434,12 @@ if player.Character then watch(player.Character) end +RunService.RenderStepped:Connect(function() + if state == "charging" and charge then + updateCharge() + end +end) + RunService.RenderStepped:Connect(function(dt) if state ~= "bite" then return @@ -1358,6 +1535,170 @@ task.spawn(function() end end) +---------------------------------------------------------------- обучение: линия-подсказка +-- белые «стрелки» бегут по земле от игрока к цели текущего шага (см. Config.TutorialDone) + +local GUIDE_N, GUIDE_GAP, GUIDE_SPEED = 32, 3, 7 -- сколько стрелок, шаг между ними, скорость бега +local W1 = Config.Worlds[1].center +local guideStep = 0 -- шаг, отправленный на сервер (атрибут Tutorial может прийти чуть позже) + +local guideHint = text({ + Size = UDim2.fromOffset(560, 42), AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, 64), + BackgroundTransparency = 0.2, BackgroundColor3 = C.bg, Font = TITLE, TextSize = 20, + TextXAlignment = Enum.TextXAlignment.Center, Visible = false, Parent = gui, +}, nil) +corner(12).Parent = guideHint +stroke(C.gold, 2).Parent = guideHint + +local guideFolder = new("Folder", { Name = "TutorialGuide", Parent = workspace }) +local chevrons = {} +for i = 1, GUIDE_N do + local arms = {} + for k = 1, 2 do + arms[k] = new("Part", { + Anchored = true, CanCollide = false, CanQuery = false, CanTouch = false, CastShadow = false, + Material = Enum.Material.Neon, Color = WHITE, Size = Vector3.new(0.32, 0.06, 1.35), Transparency = 1, + Parent = guideFolder, + }) + end + chevrons[i] = arms +end +-- две «палочки» стрелки «>» острием вперёд (по -Z) +local ARM_CF = {} +for k, s in ipairs({ -1, 1 }) do + local center = Vector3.new(s * 0.45, 0, -0.1) + ARM_CF[k] = CFrame.lookAt(center, center + Vector3.new(s * 0.9, 0, 1)) +end +local function hideChevrons(from) + for i = from, GUIDE_N do + chevrons[i][1].Transparency = 1 + chevrons[i][2].Transparency = 1 + end +end + +local guideRay = RaycastParams.new() +guideRay.FilterType = Enum.RaycastFilterType.Exclude +guideRay.RespectCanCollide = true +guideRay.IgnoreWater = false + +local function tutorialStep() + return math.max(player:GetAttribute("Tutorial") or 0, guideStep) +end +local function advanceTutorial(step) + if step > tutorialStep() then + guideStep = step + remote:FireServer("Tutorial", step) + if step >= Config.TutorialDone then + notify("🎓 Обучение пройдено! Дальше — сам: лови, улучшай удочку, открывай миры", C.gold) + end + end +end + +local function guideMarker(name) + local map = workspace:FindFirstChild("FishingMap") + local m = map and map:FindFirstChild(name) + return m and m.Position +end + +-- маршрут для текущего шага: точки ломаной (без игрока) и подсказка; nil — линию не показываем +local function guideRoute(step, pos, world) + local inW1 = world and world.id == "World1" + if step == 0 and not world then + return { guideMarker("GuideBoard") }, "📋 Прочитай табличку «Как играть»" + elseif not world then -- шаги 1–3 из лобби: сначала в портал + return { guideMarker("GuidePortal") }, "🌊 Иди в портал «Тихое озеро»" + elseif step == 2 and inW1 then + return { guideMarker("GuideFishSpot") }, "🎣 Иди на причал, зажми ЛКМ и отпусти — заброс!" + elseif step == 3 and inW1 then + local route = {} + local rel = pos - W1 + if math.abs(rel.X) < 6 and rel.Z < 80 then + table.insert(route, W1 + Vector3.new(0, 4.5, 84)) -- сначала сойти с причала + end + table.insert(route, guideMarker("GuideSell")) + return route, "💰 Продай рыбу в скупке" + end + return nil +end + +RunService.RenderStepped:Connect(function() + local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") + local step = tutorialStep() + -- пока сервер не прислал шаг (данные ещё грузятся), ничего не показываем + if not hrp or player:GetAttribute("Tutorial") == nil or step >= Config.TutorialDone then + guideHint.Visible = false + hideChevrons(1) + return + end + local pos = hrp.Position + local world = Config.WorldAt(pos) + + -- переходы между шагами + if step <= 1 and world and world.id == "World1" then + advanceTutorial(2) + elseif step == 0 then + local board = guideMarker("GuideBoard") + if board and (board - pos).Magnitude < 9 then + advanceTutorial(1) + end + elseif step == 2 and (player:GetAttribute("TotalCaught") or 0) > 0 then + advanceTutorial(3) + end + step = tutorialStep() + + local route, hint = guideRoute(step, pos, world) + guideHint.Text = hint or "" + guideHint.Visible = hint ~= nil and state == "idle" + if not route or #route == 0 or state ~= "idle" then + hideChevrons(1) + return + end + + -- ломаная от ног игрока через точки маршрута + local pts = { pos - Vector3.new(0, 3, 0) } + for _, p in ipairs(route) do + table.insert(pts, p) + end + local lens, total = {}, 0 + for i = 2, #pts do + local d = ((pts[i] - pts[i - 1]) * Vector3.new(1, 0, 1)).Magnitude + lens[i] = math.max(d, 0.001) + total += d + end + if total < 4 then + hideChevrons(1) -- уже на месте + return + end + + guideRay.FilterDescendantsInstances = { player.Character, guideFolder } + local phase = (os.clock() * GUIDE_SPEED) % GUIDE_GAP + local seg, segStart = 2, 0 + for i = 1, GUIDE_N do + local d = 2 + phase + (i - 1) * GUIDE_GAP + if d > total - 1 then + hideChevrons(i) + break + end + while seg < #pts and d > segStart + lens[seg] do + segStart += lens[seg] + seg += 1 + end + local a, b = pts[seg - 1], pts[seg] + local p = a:Lerp(b, (d - segStart) / lens[seg]) + local dir = (b - a) * Vector3.new(1, 0, 1) + local hit = workspace:Raycast(p + Vector3.new(0, 4, 0), Vector3.new(0, -12, 0), guideRay) + local y = hit and hit.Position.Y or p.Y + local base = CFrame.lookAt(Vector3.new(p.X, y + 0.08, p.Z), Vector3.new(p.X, y + 0.08, p.Z) + dir) + -- у игрока и у цели стрелки плавно проявляются и гаснут + local fade = math.max(0, 1 - math.min(d - 2, total - 1 - d) / 2.5) + local tr = 0.1 + 0.9 * fade + for k = 1, 2 do + chevrons[i][k].CFrame = base * ARM_CF[k] + chevrons[i][k].Transparency = tr + end + end +end) + ---------------------------------------------------------------- события от сервера remote.OnClientEvent:Connect(function(action, a, b, c) @@ -1365,8 +1706,11 @@ remote.OnClientEvent:Connect(function(action, a, b, c) notify(a, b) elseif action == "Cast" then setState("waiting") - startFishCam(a) + startCastCam(a, b) elseif action == "CastFail" or action == "Cancel" or action == "Escaped" then + if action == "CastFail" and castTool and castTool.Parent then + castTool.Grip = gripCF(REST_ANGLE) -- сервер удочку не трогал, а у нас она в замахе + end setState("idle") elseif action == "Bite" then mg.speed = a.speed @@ -1386,6 +1730,9 @@ remote.OnClientEvent:Connect(function(action, a, b, c) showCatch(a, b) playUiSound(DING, 0.5) elseif action == "Sold" then + if tutorialStep() == 3 then + advanceTutorial(Config.TutorialDone) + end floatText("+" .. fmt(a) .. " 💰", C.gold) notify(("Продано рыб: %d → +%s 💰"):format(b, fmt(a)), Color3.fromRGB(120, 255, 140)) elseif action == "Inventory" then