This commit is contained in:
Leshyi committed 2026-11-03 14:47:14 +03:00
1 parent eade0cd2ae
commit 860a6d2220
3 files changed
+780 -120

No files matched your search

+243 -73
View File
@@ -41,7 +41,7 @@ local function defaultData()
rod = "Basic", rods = { Basic = true }, rodLevels = {},
bag = "Pouch", bags = { Pouch = true },
items = {}, discovered = {}, claimed = {},
quests = {}, daily = { last = 0, streak = 0 },
chain = { index = 1, step = 1, progress = 0, tier = 0 }, daily = { last = 0, streak = 0 },
boostUntil = 0, boostBonus = 0,
totalCaught = 0, nextUid = 1, receipts = {},
}
@@ -168,13 +168,58 @@ local function sendInventory(player)
end
end
---------------------------------------------------------------- цепочки заданий
local function levelMult(data)
return 1 + (data.level - 1) * 0.25
end
local function currentChain(data)
local c = data.chain
local chain = Config.QuestChains[(c.index - 1) % #Config.QuestChains + 1]
return chain, chain.steps[c.step]
end
local function stepGoal(data, step)
local kind = Config.QuestKinds[step[1]]
local g = step[2] * (1 + Config.QuestTierGrowth * data.chain.tier)
if kind.byLevel then
g *= levelMult(data)
end
g = math.ceil(g)
return kind.max and math.min(g, kind.max) or g
end
local function stepReward(data, step, goal)
local kind = Config.QuestKinds[step[1]]
local m = levelMult(data)
return math.max(10, math.floor(kind.coins * goal * m)), math.max(10, math.floor(kind.xp * goal * m))
end
local function chainBonus(data)
local b = Config.ChainBonus
local m = levelMult(data) * (1 + Config.QuestTierGrowth * data.chain.tier)
return math.floor(b.coins * m), math.floor(b.xp * m), b.potion and Config.Find(Config.Potions, b.potion)
end
local function sendQuests(player)
local data = profiles[player]
if not data then
return
end
local chain = currentChain(data)
local steps = {}
for i, st in ipairs(chain.steps) do
local goal = stepGoal(data, st)
local coins, xp = stepReward(data, st, goal)
steps[i] = { kind = st[1], goal = goal, coins = coins, xp = xp }
end
local bCoins, bXp, potion = chainBonus(data)
local t = today()
remote:FireClient(player, "Quests", data.quests, {
remote:FireClient(player, "Quests", {
name = chain.name, round = data.chain.tier + 1, step = data.chain.step, progress = data.chain.progress,
steps = steps, bonus = { coins = bCoins, xp = bXp, potion = potion and potion.name },
}, {
available = data.daily.last < t,
streak = data.daily.streak,
nextStreak = (data.daily.last == t - 1) and (data.daily.streak % 7 + 1) or ((data.daily.last < t) and 1 or data.daily.streak),
@@ -255,79 +300,54 @@ local function applyPotion(data, bonus, duration)
data.boostUntil = math.max(os.time(), data.boostUntil) + duration
end
---------------------------------------------------------------- задания
---------------------------------------------------------------- задания: прогресс цепочки
local function makeQuest(data, exclude)
local pool = {}
for _, q in ipairs(Config.Quests) do
if not exclude[q.kind] then
table.insert(pool, q)
end
-- у старых сохранений вместо цепочки были три случайных задания
local function ensureChain(data)
if type(data.chain) ~= "table" then
data.chain = { index = 1, step = 1, progress = 0, tier = 0 }
end
if #pool == 0 then
pool = Config.Quests
end
local t = pool[rng:NextInteger(1, #pool)]
local goal = t.goals[rng:NextInteger(1, #t.goals)]
local mult = 1 + (data.level - 1) * 0.25
return {
kind = t.kind, goal = goal, progress = 0,
coins = math.max(10, math.floor(t.coins * goal * mult)),
xp = math.max(10, math.floor(t.xp * goal * mult)),
}
data.quests = nil
end
local function ensureQuests(data)
local kinds = {}
for _, q in ipairs(data.quests) do
kinds[q.kind] = true
end
while #data.quests < Config.QuestSlots do
local q = makeQuest(data, kinds)
kinds[q.kind] = true
table.insert(data.quests, q)
end
end
local function questProgress(player, kind, amount)
-- absolute = true: amount — текущее значение (серия), а не прибавка
local function questProgress(player, kind, amount, absolute)
local data = profiles[player]
if not data then
return
end
local changed = false
for _, q in ipairs(data.quests) do
if q.kind == kind and q.progress < q.goal then
q.progress = math.min(q.goal, q.progress + amount)
changed = true
if q.progress >= q.goal then
notify(player, "📜 Задание готово! (Q)", GOLD)
end
end
end
if changed then
sendQuests(player)
end
end
local function claimQuest(player, index)
local data = profiles[player]
local q = data and type(index) == "number" and data.quests[index]
if not q or q.progress < q.goal then
local chain, step = currentChain(data)
if step[1] ~= kind then
return
end
data.coins += q.coins
addXp(player, data, q.xp)
local kinds = {}
for i, other in ipairs(data.quests) do
if i ~= index then
kinds[other.kind] = true
local c = data.chain
c.progress = absolute and math.max(c.progress, amount) or c.progress + amount
local goal = stepGoal(data, step)
if c.progress >= goal then
-- награда сразу, следующий шаг тоже сразу
local coins, xp = stepReward(data, step, goal)
data.coins += coins
addXp(player, data, xp)
remote:FireClient(player, "QuestDone", kind, goal, coins, xp)
c.step += 1
c.progress = 0
if c.step > #chain.steps then
local bCoins, bXp, potion = chainBonus(data)
data.coins += bCoins
addXp(player, data, bXp)
if potion then
applyPotion(data, potion.bonus, potion.duration)
end
remote:FireClient(player, "ChainDone", chain.name, bCoins, bXp, potion and potion.name)
c.index += 1
c.step = 1
if (c.index - 1) % #Config.QuestChains == 0 then
c.tier += 1
end
end
updateStats(player)
end
kinds[q.kind] = true
data.quests[index] = makeQuest(data, kinds)
updateStats(player)
sendQuests(player)
notify(player, ("📜 Награда: +%d 💰 +%d XP"):format(q.coins, q.xp), GREEN)
end
local function claimDaily(player)
@@ -608,6 +628,34 @@ end
local fishing = {}
-- серия улова (на время игры, не сохраняется)
local combo, comboUntil = {}, {}
local function setCombo(player, n)
combo[player] = n
comboUntil[player] = n > 0 and os.time() + Config.Combo.timeout or nil
player:SetAttribute("Combo", n)
player:SetAttribute("ComboEnds", n > 0 and workspace:GetServerTimeNow() + Config.Combo.timeout or nil)
end
local function breakCombo(player)
if (combo[player] or 0) >= 2 then
remote:FireClient(player, "ComboLost", combo[player])
end
setCombo(player, 0)
end
-- босс озера: { world, def, hp, max, dmg = { [player] = урон } }
local boss = nil
local function bossHit(player, world, dmg)
if not boss or boss.hp <= 0 or not world or world.id ~= boss.world.id then
return
end
boss.hp = math.max(0, boss.hp - dmg)
boss.dmg[player] = (boss.dmg[player] or 0) + dmg
workspace:SetAttribute("BossHP", boss.hp)
remote:FireClient(player, "BossHit", dmg)
questProgress(player, "boss", dmg)
end
-- ищем воду по карте мира из FishConfig (не зависит от террейна) в сторону центра ближайшего озера:
-- сначала на дальности, которую задала сила заброса, потом всё дальше от неё
local function findWater(hrp, world, power)
@@ -812,7 +860,7 @@ local function onCast(player, power)
remote:FireClient(player, "CastFail")
return
end
local s = { stage = "casting", fish = fish, tool = tool }
local s = { stage = "casting", fish = fish, tool = tool, perfect = perfect }
fishing[player] = s
-- замах игрок уже сделал, пока держал кнопку (у себя на клиенте); здесь только бросок вперёд
local throw = { windup = 0.15, flight = 0.35 + dist * 0.018, arc = 2 + dist * 0.3, perfect = perfect }
@@ -875,6 +923,7 @@ local function onCast(player, power)
stopFishing(player, false)
remote:FireClient(player, "Escaped")
notify(player, "🐟 Рыба ушла", RED)
breakCombo(player)
end
end)
end
@@ -903,11 +952,18 @@ local function onCatch(player, success, misses)
gripSequence(tool, { { REST_ANGLE, 0.3 } })
remote:FireClient(player, "Escaped")
notify(player, "🐟 Сорвалась!", RED)
breakCombo(player)
return
end
gripSequence(tool, { { 85, 0.15 }, { REST_ANGLE, 0.45 } })
-- серия: каждая рыба подряд дороже и даёт больше опыта
local fish = s.fish
local streak = combo[player] or 0
local comboMult = math.min(Config.Combo.max, 1 + Config.Combo.step * streak)
fish.value = math.floor(fish.value * comboMult + 0.5)
fish.xp = math.floor(fish.xp * comboMult + 0.5)
setCombo(player, streak + 1)
table.insert(data.items, {
uid = data.nextUid, id = fish.id, name = fish.name, rarity = fish.rarity,
weight = fish.weight, value = fish.value, mutation = fish.mutation,
@@ -933,22 +989,26 @@ local function onCatch(player, success, misses)
if fromPos then
showFishFlight(player, fish, fromPos)
end
remote:FireClient(player, "Caught", fish, { new = isNew, record = isRecord })
remote:FireClient(player, "Caught", fish, { new = isNew, record = isRecord, combo = comboMult, streak = streak + 1 })
local rank = Config.Rarities[fish.rarity].rank
questProgress(player, "catch", 1)
if rank >= 2 then
questProgress(player, "uncommon", 1)
end
if rank >= 3 then
questProgress(player, "rare", 1)
end
if rank >= 4 then
questProgress(player, "epic", 1)
end
if fish.mutation then
questProgress(player, "mutation", 1)
end
if misses == 0 then
questProgress(player, "perfect", 1)
end
if s.perfect then
questProgress(player, "perfectCast", 1)
end
questProgress(player, "combo", streak + 1, true)
local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
bossHit(player, hrp and Config.WorldAt(hrp.Position), rank + (misses == 0 and 1 or 0))
end
---------------------------------------------------------------- скупка
@@ -1004,6 +1064,7 @@ local function sellItems(player, filterUid)
updateStats(player)
sendInventory(player)
remote:FireClient(player, "Sold", total, count)
questProgress(player, "sell", count)
questProgress(player, "earn", total)
end
@@ -1037,6 +1098,7 @@ local function buy(player, kind, id)
end
updateStats(player)
notify(player, ("✨ %s улучшена до +%d!"):format(rod.name, lvl + 1), GOLD)
questProgress(player, "buy", 1)
return
end
if kind == "Potion" then
@@ -1056,6 +1118,7 @@ local function buy(player, kind, id)
applyPotion(data, potion.bonus, potion.duration)
updateStats(player)
notify(player, ("🍀 +%d%% удачи, %d мин"):format(potion.bonus * 100, potion.duration / 60), GREEN)
questProgress(player, "buy", 1)
return
end
local list, owned
@@ -1070,6 +1133,7 @@ local function buy(player, kind, id)
if not item then
return
end
local bought = false
if not owned[id] then
if data.level < item.level then
notify(player, "🔒 Нужен ур. " .. item.level, RED)
@@ -1081,6 +1145,7 @@ local function buy(player, kind, id)
end
data.coins -= item.price
owned[id] = true
bought = true
notify(player, "✅ " .. item.name, GREEN)
end
if kind == "Rod" then
@@ -1092,6 +1157,9 @@ local function buy(player, kind, id)
attachBag(player)
end
updateStats(player)
if bought then
questProgress(player, "buy", 1)
end
end
---------------------------------------------------------------- телепорт
@@ -1214,8 +1282,6 @@ remote.OnServerEvent:Connect(function(player, action, a, b)
teleportTo(player, a)
elseif action == "ClaimCollection" then
claimCollection(player, a, b)
elseif action == "ClaimQuest" then
claimQuest(player, a)
elseif action == "ClaimDaily" then
claimDaily(player)
elseif action == "RequestInventory" then
@@ -1303,6 +1369,105 @@ task.spawn(function()
end
end)
---------------------------------------------------------------- босс озера
local function playerWorld(p)
local hrp = p.Character and p.Character:FindFirstChild("HumanoidRootPart")
return hrp and Config.WorldAt(hrp.Position)
end
local function setBossAttrs()
workspace:SetAttribute("BossWorld", boss and boss.world.id or nil)
workspace:SetAttribute("BossName", boss and boss.def.name or nil)
workspace:SetAttribute("BossHP", boss and boss.hp or nil)
workspace:SetAttribute("BossMax", boss and boss.max or nil)
workspace:SetAttribute("BossEnds", boss and boss.ends or nil)
end
local function finishBoss(won)
local b = boss
boss = nil
setBossAttrs()
local helpers, best, bestDmg = 0, nil, 0
for p, d in pairs(b.dmg) do
if p.Parent then
helpers += 1
if d > bestDmg then
best, bestDmg = p, d
end
end
end
if not won then
for _, p in ipairs(Players:GetPlayers()) do
remote:FireClient(p, "BossDone", false, b.def.name)
end
return
end
local R = Config.Boss.reward
local fair = b.max / math.max(1, helpers) -- «честная доля» урона на одного
local potion = R.potion and Config.Find(Config.Potions, R.potion)
for p, d in pairs(b.dmg) do
local data = p.Parent and profiles[p]
if data then
local share = 0.4 + 0.6 * math.min(1, d / fair)
local coins = math.floor(R.coins * b.world.mult * share * levelMult(data))
local xp = math.floor(R.xp * b.world.mult * share)
data.coins += coins
addXp(p, data, xp)
if potion then
applyPotion(data, potion.bonus, potion.duration)
end
updateStats(p)
remote:FireClient(p, "BossReward", coins, xp, potion and potion.name)
end
end
for _, p in ipairs(Players:GetPlayers()) do
remote:FireClient(p, "BossDone", true, b.def.name, best and best.DisplayName, bestDmg)
end
end
task.spawn(function()
task.wait(Config.Boss.firstDelay)
while true do
-- мир, где сейчас больше всего игроков
local counts = {}
for _, p in ipairs(Players:GetPlayers()) do
local w = playerWorld(p)
if w and Config.Boss.worlds[w.id] then
counts[w.id] = (counts[w.id] or 0) + 1
end
end
local bestId, n = nil, 0
for id, c in pairs(counts) do
if c > n then
bestId, n = id, c
end
end
if not bestId then
task.wait(30) -- никого нет в мирах: попробуем позже
else
local world = Config.Find(Config.Worlds, bestId)
local max = Config.Boss.hpPerPlayer * n
boss = {
world = world, def = Config.Boss.worlds[bestId], hp = max, max = max, dmg = {},
ends = workspace:GetServerTimeNow() + Config.Boss.duration,
}
setBossAttrs()
for _, p in ipairs(Players:GetPlayers()) do
remote:FireClient(p, "BossStart", boss.def.name, world.icon .. " " .. world.name)
end
local t0 = os.clock()
while boss and boss.hp > 0 and os.clock() - t0 < Config.Boss.duration do
task.wait(0.25)
end
if boss then
finishBoss(boss.hp <= 0)
end
task.wait(Config.Boss.interval)
end
end
end)
---------------------------------------------------------------- игроки
local function onPlayerAdded(player)
@@ -1320,7 +1485,7 @@ local function onPlayerAdded(player)
return
end
loadPasses(player)
ensureQuests(data)
ensureChain(data)
profiles[player] = data
loadedOk[player] = ok
updateStats(player)
@@ -1347,6 +1512,7 @@ end
Players.PlayerRemoving:Connect(function(player)
stopFishing(player, false)
combo[player], comboUntil[player] = nil, nil
saveData(player)
profiles[player] = nil
loadedOk[player] = nil
@@ -1370,6 +1536,10 @@ task.spawn(function()
if data and data.boostUntil > os.time() - 2 then
updateStats(p)
end
-- серия сгорает, если долго нет улова (пока рыба на крючке — ждём)
if comboUntil[p] and os.time() > comboUntil[p] and not fishing[p] then
breakCombo(p)
end
end
if t % 60 == 0 then
for _, p in ipairs(Players:GetPlayers()) do