Update
This commit is contained in:
1 parent
f316a9bf0c
commit
9fcbd8bc0b
38 files changed
+29208
-4904
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,838 @@
|
||||
-- Guild (ModuleScript) -> ServerScriptService
|
||||
-- Гильдия рыбаков: ранги F–S, печати и жемчуг, испытания у Старейшины, личные заказы на доске,
|
||||
-- наживка, ловушки-вентери, бонус отдыха и жетон ранга над головой.
|
||||
-- Данные игрока хранит GameServer (profiles); он же вызывает отсюда хуки (улов, вход, статы).
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local Config = require(ReplicatedStorage:WaitForChild("FishConfig"))
|
||||
|
||||
local Guild = {}
|
||||
local api -- функции GameServer: profiles, notify, updateStats, addXp, sendInventory, bagCapacity, isNight, weather, remote
|
||||
local RANKS = Config.Guild.ranks
|
||||
local GOLD = Color3.fromRGB(255, 214, 120)
|
||||
local RED = Color3.fromRGB(255, 120, 120)
|
||||
local GREEN = Color3.fromRGB(150, 230, 130)
|
||||
|
||||
function Guild.init(a)
|
||||
api = a
|
||||
-- только в Studio: проверки из командной строки/MCP (ServerStorage.GuildDebug:Invoke("get", player, "seals"))
|
||||
if game:GetService("RunService"):IsStudio() then
|
||||
local f = Instance.new("BindableFunction")
|
||||
f.Name = "GuildDebug"
|
||||
f.OnInvoke = function(op, player, key, value, extra)
|
||||
local data = api.profiles[player]
|
||||
if not data then
|
||||
return nil
|
||||
end
|
||||
if op == "get" then
|
||||
return data[key]
|
||||
elseif op == "set" then
|
||||
data[key] = value
|
||||
api.updateStats(player)
|
||||
elseif op == "addItem" then
|
||||
key.uid = data.nextUid
|
||||
data.nextUid += 1
|
||||
table.insert(data.items, key)
|
||||
api.sendInventory(player)
|
||||
api.updateStats(player)
|
||||
elseif op == "action" then
|
||||
Guild.onAction(player, key, value, extra)
|
||||
elseif op == "orders" then
|
||||
Guild.refreshOrders(data, player)
|
||||
return data.orders.list
|
||||
end
|
||||
return true
|
||||
end
|
||||
f.Parent = game:GetService("ServerStorage")
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- данные
|
||||
|
||||
-- новые поля (старые сохранения грузятся: чего нет — дополняем)
|
||||
function Guild.defaults(data)
|
||||
data.pearls = data.pearls or 0
|
||||
data.seals = data.seals or 0
|
||||
data.trial = data.trial -- { rank = номер ранга, progress = n } или nil
|
||||
if type(data.orders) ~= "table" then
|
||||
data.orders = { window = -1, list = {} }
|
||||
end
|
||||
if type(data.bait) ~= "table" then
|
||||
data.bait = { equipped = nil, counts = {} }
|
||||
end
|
||||
data.bait.counts = data.bait.counts or {}
|
||||
if type(data.traps) ~= "table" then
|
||||
data.traps = {}
|
||||
end
|
||||
data.rest = data.rest or 0
|
||||
if not data.rank then
|
||||
-- сохранение до гильдии: кто уже дошёл до дальних миров, сохраняет к ним доступ
|
||||
local lvl = data.level or 1
|
||||
data.rank = (lvl >= 18 and 5) or (lvl >= 8 and 3) or 1
|
||||
if data.rank > 1 then
|
||||
data.seals = math.max(data.seals, RANKS[data.rank].seals)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- данные игрока (для проверок из Studio)
|
||||
function Guild.profile(player)
|
||||
return api.profiles[player]
|
||||
end
|
||||
|
||||
function Guild.rank(data)
|
||||
return RANKS[math.clamp(data.rank or 1, 1, #RANKS)], data.rank or 1
|
||||
end
|
||||
|
||||
local function nearSpot(player, attr)
|
||||
local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
|
||||
local map = workspace:FindFirstChild("FishingMap")
|
||||
if not hrp or not map then
|
||||
return false
|
||||
end
|
||||
for _, d in ipairs(map:GetDescendants()) do
|
||||
if d:IsA("BasePart") and d:GetAttribute(attr) then
|
||||
if (d.Position - hrp.Position).Magnitude <= Config.Guild.elderDistance then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- жетон ранга над головой
|
||||
|
||||
function Guild.badge(player)
|
||||
local data = api.profiles[player]
|
||||
local head = player.Character and player.Character:FindFirstChild("Head")
|
||||
if not data or not head then
|
||||
return
|
||||
end
|
||||
local r = Guild.rank(data)
|
||||
local bb = head:FindFirstChild("RankBadge")
|
||||
if not bb then
|
||||
bb = Instance.new("BillboardGui")
|
||||
bb.Name = "RankBadge"
|
||||
bb.Size = UDim2.fromOffset(46, 52)
|
||||
bb.StudsOffset = Vector3.new(0, 2.4, 0)
|
||||
bb.MaxDistance = 70
|
||||
bb.LightInfluence = 0
|
||||
bb.Parent = head
|
||||
-- щит: ромб с золотой каймой и буквой
|
||||
local shield = Instance.new("Frame")
|
||||
shield.Name = "Shield"
|
||||
shield.Size = UDim2.fromOffset(34, 34)
|
||||
shield.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
shield.Position = UDim2.fromScale(0.5, 0.5)
|
||||
shield.Rotation = 45
|
||||
shield.Parent = bb
|
||||
local c = Instance.new("UICorner")
|
||||
c.CornerRadius = UDim.new(0, 6)
|
||||
c.Parent = shield
|
||||
local s = Instance.new("UIStroke")
|
||||
s.Color = Color3.fromRGB(218, 172, 92)
|
||||
s.Thickness = 3
|
||||
s.Parent = shield
|
||||
local g = Instance.new("UIGradient")
|
||||
g.Color = ColorSequence.new(Color3.new(1, 1, 1), Color3.fromRGB(150, 150, 150))
|
||||
g.Rotation = 45
|
||||
g.Parent = shield
|
||||
local t = Instance.new("TextLabel")
|
||||
t.Name = "Letter"
|
||||
t.Size = UDim2.fromScale(1, 1)
|
||||
t.BackgroundTransparency = 1
|
||||
t.FontFace = Font.new("rbxasset://fonts/families/Merriweather.json", Enum.FontWeight.Heavy)
|
||||
t.TextScaled = true
|
||||
t.TextColor3 = Color3.new(1, 1, 1)
|
||||
t.TextStrokeTransparency = 0.2
|
||||
t.TextStrokeColor3 = Color3.fromRGB(40, 28, 20)
|
||||
t.ZIndex = 2
|
||||
t.Parent = bb
|
||||
end
|
||||
bb.Shield.BackgroundColor3 = r.color
|
||||
bb.Shield.UIGradient.Color = r.id == "S"
|
||||
and ColorSequence.new({
|
||||
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 120, 120)), ColorSequenceKeypoint.new(0.35, Color3.fromRGB(255, 230, 120)),
|
||||
ColorSequenceKeypoint.new(0.7, Color3.fromRGB(120, 230, 255)), ColorSequenceKeypoint.new(1, Color3.fromRGB(220, 130, 255)),
|
||||
})
|
||||
or ColorSequence.new(Color3.new(1, 1, 1), Color3.fromRGB(150, 150, 150))
|
||||
bb.Shield.UIStroke.Color = (r.id == "S" or r.id == "A") and Color3.fromRGB(255, 225, 130) or Color3.fromRGB(218, 172, 92)
|
||||
bb.Letter.Text = r.id
|
||||
-- корона VIP — над жетоном
|
||||
local vip = head:FindFirstChild("VipTag")
|
||||
if vip then
|
||||
vip.StudsOffset = Vector3.new(0, 4, 0)
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- состояние для клиента
|
||||
|
||||
local function orderText(o)
|
||||
local f = o.fish and Config.FindFish(o.fish)
|
||||
if o.kind == "deliver" then
|
||||
return ("Сдай %d × %s"):format(o.count, f and f.name or "?")
|
||||
elseif o.kind == "heavy" then
|
||||
return ("Принеси %s тяжелее %.1f кг"):format(f and f.name or "?", o.minW)
|
||||
elseif o.kind == "weather" then
|
||||
return ("Поймай %d рыб в дождь или грозу"):format(o.count)
|
||||
elseif o.kind == "night" then
|
||||
return ("Поймай %d «Необычных» или реже ночью"):format(o.count)
|
||||
elseif o.kind == "combo" then
|
||||
return ("Набери серию из %d рыб"):format(o.count)
|
||||
elseif o.kind == "perfect" then
|
||||
return ("Сделай %d забросов в зелёную зону"):format(o.count)
|
||||
end
|
||||
return o.kind
|
||||
end
|
||||
Guild.orderText = orderText
|
||||
|
||||
local function trialState(data)
|
||||
local nextRank = RANKS[(data.rank or 1) + 1]
|
||||
if not nextRank then
|
||||
return nil
|
||||
end
|
||||
local active = data.trial and data.trial.rank == data.rank + 1
|
||||
local t = nextRank.trial
|
||||
local goal = t.count or 1
|
||||
local progress = active and data.trial.progress or 0
|
||||
if t.kind == "dex" then
|
||||
local zone = Config.Zones[t.world]
|
||||
goal, progress = #zone.fish, 0
|
||||
for _, f in ipairs(zone.fish) do
|
||||
if data.discovered[f.id] then
|
||||
progress += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return {
|
||||
rank = data.rank + 1, text = t.text, active = active, progress = progress, goal = goal,
|
||||
ready = data.seals >= nextRank.seals,
|
||||
}
|
||||
end
|
||||
|
||||
function Guild.sendState(player)
|
||||
local data = api.profiles[player]
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
Guild.refreshOrders(data, player)
|
||||
local list = {}
|
||||
for i, o in ipairs(data.orders.list) do
|
||||
list[i] = {
|
||||
kind = o.kind, text = orderText(o), progress = o.progress, count = o.count, done = o.done,
|
||||
seals = o.seals, coins = o.coins, pearls = o.pearls, deliver = (o.kind == "deliver" or o.kind == "heavy"),
|
||||
}
|
||||
end
|
||||
local now = os.time()
|
||||
local traps = {}
|
||||
for i, t0 in ipairs(data.traps) do
|
||||
traps[i] = math.min(Config.Traps.max, math.floor((now - t0) / Config.Traps.every))
|
||||
end
|
||||
api.remote:FireClient(player, "Guild", {
|
||||
trial = trialState(data),
|
||||
orders = list,
|
||||
ordersEnd = (data.orders.window + 1) * Config.Orders.period,
|
||||
traps = traps, trapSlots = Guild.rank(data).traps or 0, trapEvery = Config.Traps.every, trapMax = Config.Traps.max,
|
||||
baits = data.bait.counts, bait = data.bait.equipped,
|
||||
})
|
||||
end
|
||||
|
||||
-- атрибуты игрока (HUD и окна читают их)
|
||||
function Guild.attrs(player, data)
|
||||
local r, idx = Guild.rank(data)
|
||||
player:SetAttribute("Pearls", data.pearls)
|
||||
player:SetAttribute("Seals", data.seals)
|
||||
player:SetAttribute("GuildRank", r.id)
|
||||
player:SetAttribute("RankIdx", idx)
|
||||
local nextRank = RANKS[idx + 1]
|
||||
player:SetAttribute("SealsNext", nextRank and nextRank.seals or nil)
|
||||
player:SetAttribute("RestLeft", math.floor(data.rest))
|
||||
player:SetAttribute("Bait", data.bait.equipped)
|
||||
player:SetAttribute("BaitCount", data.bait.equipped and (data.bait.counts[data.bait.equipped] or 0) or 0)
|
||||
local ready = 0
|
||||
for _, t0 in ipairs(data.traps) do
|
||||
ready += math.min(Config.Traps.max, math.floor((os.time() - t0) / Config.Traps.every))
|
||||
end
|
||||
player:SetAttribute("TrapFish", ready)
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- ранги и испытания
|
||||
|
||||
local function rankUp(player, data)
|
||||
data.rank += 1
|
||||
data.trial = nil
|
||||
data.pearls += Config.Pearls.rankUp
|
||||
local r = RANKS[data.rank]
|
||||
-- новые ловушки начинают копить с этого момента
|
||||
while #data.traps < (r.traps or 0) do
|
||||
table.insert(data.traps, os.time())
|
||||
end
|
||||
api.remote:FireClient(player, "RankUp", r.id, r.name, r.unlocks, Config.Pearls.rankUp)
|
||||
for _, p in ipairs(Players:GetPlayers()) do
|
||||
api.notify(p, ("⚔ %s получил ранг %s — «%s»!"):format(player.DisplayName, r.id, r.name), GOLD)
|
||||
end
|
||||
Guild.badge(player)
|
||||
api.updateStats(player)
|
||||
Guild.sendState(player)
|
||||
end
|
||||
|
||||
local function trialProgress(player, data, amount)
|
||||
local st = data.trial
|
||||
local nextRank = RANKS[data.rank + 1]
|
||||
if not st or not nextRank or st.rank ~= data.rank + 1 then
|
||||
return
|
||||
end
|
||||
st.progress = (st.progress or 0) + amount
|
||||
if st.progress >= (nextRank.trial.count or 1) then
|
||||
rankUp(player, data)
|
||||
else
|
||||
Guild.sendState(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function checkDexTrial(player, data)
|
||||
local st = data.trial
|
||||
local nextRank = RANKS[data.rank + 1]
|
||||
if st and nextRank and st.rank == data.rank + 1 and nextRank.trial.kind == "dex" then
|
||||
local s = trialState(data)
|
||||
if s.progress >= s.goal then
|
||||
rankUp(player, data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function takeTrial(player, data)
|
||||
local nextRank = RANKS[data.rank + 1]
|
||||
if not nextRank then
|
||||
api.notify(player, "👑 Ты уже Легенда гильдии!", GOLD)
|
||||
return
|
||||
end
|
||||
if data.seals < nextRank.seals then
|
||||
api.notify(player, ("📜 Нужно %d печатей (у тебя %d)"):format(nextRank.seals, data.seals), RED)
|
||||
return
|
||||
end
|
||||
if not nearSpot(player, "GuildElder") then
|
||||
api.notify(player, "⚔ Испытание выдаёт " .. Config.Guild.elder .. " — он в здании гильдии в лобби", Color3.fromRGB(255, 200, 120))
|
||||
return
|
||||
end
|
||||
local t = nextRank.trial
|
||||
if t.kind == "deliver" then
|
||||
-- сдать рыбу из сумки сразу, если она есть
|
||||
local have, keep = 0, {}
|
||||
for _, item in ipairs(data.items) do
|
||||
if item.id == t.fish and have < t.count then
|
||||
have += 1
|
||||
else
|
||||
table.insert(keep, item)
|
||||
end
|
||||
end
|
||||
if have < t.count then
|
||||
local f = Config.FindFish(t.fish)
|
||||
api.notify(player, ("🐟 Принеси %d × %s (в сумке %d)"):format(t.count, f and f.name or t.fish, have), RED)
|
||||
data.trial = { rank = data.rank + 1, progress = 0 }
|
||||
Guild.sendState(player)
|
||||
return
|
||||
end
|
||||
data.items = keep
|
||||
api.sendInventory(player)
|
||||
data.trial = { rank = data.rank + 1, progress = 0 }
|
||||
trialProgress(player, data, t.count)
|
||||
return
|
||||
end
|
||||
if not (data.trial and data.trial.rank == data.rank + 1) then
|
||||
data.trial = { rank = data.rank + 1, progress = 0 }
|
||||
api.notify(player, "⚔ Испытание принято: " .. t.text, GOLD)
|
||||
end
|
||||
if t.kind == "dex" then
|
||||
checkDexTrial(player, data)
|
||||
end
|
||||
Guild.sendState(player)
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- заказы
|
||||
|
||||
local function pick(rng, weights)
|
||||
local total = 0
|
||||
for _, w in pairs(weights) do
|
||||
total += w
|
||||
end
|
||||
local roll = rng:NextNumber() * total
|
||||
for k, w in pairs(weights) do
|
||||
roll -= w
|
||||
if roll <= 0 then
|
||||
return k
|
||||
end
|
||||
end
|
||||
return next(weights)
|
||||
end
|
||||
|
||||
-- рыба для заказов: из миров, куда игрок уже может попасть
|
||||
local function fishPool(data, rarities)
|
||||
local pool = {}
|
||||
for _, w in ipairs(Config.Worlds) do
|
||||
local zone = Config.Zones[w.id]
|
||||
local needRank = Config.Guild.worldRank[w.id] or 1
|
||||
if zone and not w.soon and data.level >= w.level and data.rank >= needRank then
|
||||
for _, f in ipairs(zone.fish) do
|
||||
if rarities[f.rarity] then
|
||||
table.insert(pool, f)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return pool
|
||||
end
|
||||
|
||||
local function makeOrder(data, rng)
|
||||
local O = Config.Orders
|
||||
local weights = {}
|
||||
for k, v in pairs(O.kinds) do
|
||||
weights[k] = v.weight
|
||||
end
|
||||
-- порядок ключей в pairs не задан: сортируем, чтобы при одном зерне выпадало одно и то же
|
||||
local kind
|
||||
do
|
||||
local keys = {}
|
||||
for k in pairs(weights) do
|
||||
table.insert(keys, k)
|
||||
end
|
||||
table.sort(keys)
|
||||
local total = 0
|
||||
for _, k in ipairs(keys) do
|
||||
total += weights[k]
|
||||
end
|
||||
local roll = rng:NextNumber() * total
|
||||
for _, k in ipairs(keys) do
|
||||
roll -= weights[k]
|
||||
if roll <= 0 then
|
||||
kind = k
|
||||
break
|
||||
end
|
||||
end
|
||||
kind = kind or keys[1]
|
||||
end
|
||||
local r = data.rank or 1
|
||||
local hard = rng:NextNumber() -- сложность заказа 0..1
|
||||
local o = { kind = kind, progress = 0, done = false }
|
||||
if kind == "deliver" then
|
||||
local pool = fishPool(data, r >= 3 and { Common = true, Uncommon = true, Rare = true } or { Common = true, Uncommon = true })
|
||||
local f = pool[rng:NextInteger(1, #pool)]
|
||||
local rank = Config.Rarities[f.rarity].rank
|
||||
o.fish = f.id
|
||||
o.count = math.max(1, math.floor((rank == 1 and 5 or (rank == 2 and 3 or 1)) * (0.7 + hard * 0.8) + 0.5))
|
||||
elseif kind == "heavy" then
|
||||
local pool = fishPool(data, { Uncommon = true, Rare = true })
|
||||
local f = pool[rng:NextInteger(1, #pool)]
|
||||
o.fish = f.id
|
||||
o.count = 1
|
||||
o.minW = math.floor((f.minW + (f.maxW - f.minW) * (0.25 + hard * 0.3)) * 10) / 10
|
||||
elseif kind == "weather" then
|
||||
o.count = 2 + math.floor(hard * 3) + r
|
||||
elseif kind == "night" then
|
||||
o.count = 1 + math.floor(hard * 2) + math.floor(r / 2)
|
||||
elseif kind == "combo" then
|
||||
o.count = math.min(15, 4 + math.floor(hard * 4) + r)
|
||||
elseif kind == "perfect" then
|
||||
o.count = 3 + math.floor(hard * 4) + r
|
||||
end
|
||||
local s = O.kinds[kind].seals
|
||||
o.seals = math.floor(s[1] + (s[2] - s[1]) * hard + 0.5) + (r - 1) * 2
|
||||
o.coins = math.floor(o.seals * O.coinsPerSeal * (1 + 0.5 * (r - 1)))
|
||||
o.pearls = rng:NextNumber() < O.pearlChance and rng:NextInteger(O.pearlsMin, O.pearlsMax) or 0
|
||||
return o
|
||||
end
|
||||
|
||||
-- новое окно (каждые 3 часа) — новые заказы; на ранге E и выше их 4
|
||||
function Guild.refreshOrders(data, player)
|
||||
local window = math.floor(os.time() / Config.Orders.period)
|
||||
local want = Guild.rank(data).orders
|
||||
if data.orders.window ~= window then
|
||||
local seed = ((player and player.UserId or 0) % 100000) * 7919 + window
|
||||
local rng = Random.new(seed)
|
||||
data.orders = { window = window, list = {} }
|
||||
local seen = {}
|
||||
for i = 1, want do
|
||||
-- без повторов: один и тот же тип с той же рыбой не выпадает дважды
|
||||
local o
|
||||
for _ = 1, 6 do
|
||||
o = makeOrder(data, rng)
|
||||
if not seen[o.kind .. (o.fish or "")] then
|
||||
break
|
||||
end
|
||||
end
|
||||
seen[o.kind .. (o.fish or "")] = true
|
||||
data.orders.list[i] = o
|
||||
end
|
||||
else
|
||||
-- ранг вырос посреди окна: добавляем недостающий заказ
|
||||
local seen = {}
|
||||
for _, o in ipairs(data.orders.list) do
|
||||
seen[o.kind .. (o.fish or "")] = true
|
||||
end
|
||||
while #data.orders.list < want do
|
||||
local o
|
||||
for _ = 1, 6 do
|
||||
o = makeOrder(data, Random.new())
|
||||
if not seen[o.kind .. (o.fish or "")] then
|
||||
break
|
||||
end
|
||||
end
|
||||
seen[o.kind .. (o.fish or "")] = true
|
||||
table.insert(data.orders.list, o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function finishOrder(player, data, o)
|
||||
o.done = true
|
||||
data.seals += o.seals
|
||||
data.coins += o.coins
|
||||
data.pearls += o.pearls
|
||||
api.notify(player, ("📜 Заказ выполнен! +%d печатей +%d ⚪%s"):format(o.seals, o.coins, o.pearls > 0 and (" +" .. o.pearls .. " 🦪") or ""), GOLD)
|
||||
api.remote:FireClient(player, "OrderDone")
|
||||
local nextRank = RANKS[data.rank + 1]
|
||||
if nextRank and data.seals >= nextRank.seals and data.seals - o.seals < nextRank.seals then
|
||||
api.notify(player, ("⚔ Печатей хватает на ранг %s! Иди к Старейшине за испытанием"):format(nextRank.id), GOLD)
|
||||
end
|
||||
api.updateStats(player)
|
||||
Guild.sendState(player)
|
||||
end
|
||||
|
||||
local function deliverOrder(player, data, i)
|
||||
Guild.refreshOrders(data, player)
|
||||
local o = data.orders.list[i]
|
||||
if not o or o.done or (o.kind ~= "deliver" and o.kind ~= "heavy") then
|
||||
return
|
||||
end
|
||||
if not nearSpot(player, "OrderBoard") then
|
||||
api.notify(player, "📜 Рыбу сдают у доски заказов в здании гильдии", Color3.fromRGB(255, 200, 120))
|
||||
return
|
||||
end
|
||||
local need = o.count - o.progress
|
||||
local keep = {}
|
||||
-- сдаём сначала самую дешёвую подходящую рыбу
|
||||
local fit = {}
|
||||
for _, item in ipairs(data.items) do
|
||||
if item.id == o.fish and (not o.minW or item.weight >= o.minW) then
|
||||
table.insert(fit, item)
|
||||
end
|
||||
end
|
||||
table.sort(fit, function(a, b)
|
||||
return a.value < b.value
|
||||
end)
|
||||
local take = {}
|
||||
for k = 1, math.min(need, #fit) do
|
||||
take[fit[k].uid] = true
|
||||
end
|
||||
local given = 0
|
||||
for _, item in ipairs(data.items) do
|
||||
if take[item.uid] then
|
||||
given += 1
|
||||
else
|
||||
table.insert(keep, item)
|
||||
end
|
||||
end
|
||||
if given == 0 then
|
||||
local f = Config.FindFish(o.fish)
|
||||
api.notify(player, ("🎒 В сумке нет подходящей рыбы: %s"):format(f and f.name or o.fish), RED)
|
||||
return
|
||||
end
|
||||
data.items = keep
|
||||
o.progress += given
|
||||
api.sendInventory(player)
|
||||
if o.progress >= o.count then
|
||||
finishOrder(player, data, o)
|
||||
else
|
||||
api.updateStats(player)
|
||||
Guild.sendState(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function rerollOrder(player, data, i)
|
||||
Guild.refreshOrders(data, player)
|
||||
local o = data.orders.list[i]
|
||||
if not o or o.done then
|
||||
return
|
||||
end
|
||||
local cost = Config.Orders.rerollPearls
|
||||
if data.pearls < cost then
|
||||
api.notify(player, ("🦪 Нужно %d жемчуга"):format(cost), RED)
|
||||
return
|
||||
end
|
||||
data.pearls -= cost
|
||||
data.orders.list[i] = makeOrder(data, Random.new())
|
||||
api.updateStats(player)
|
||||
Guild.sendState(player)
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- улов: заказы, испытания, жемчуг
|
||||
|
||||
-- ctx: { weather = id, night = bool, perfect = bool (заброс в зелёную зону), streak = n, auto = bool }
|
||||
function Guild.onCatch(player, data, fish, ctx)
|
||||
local rank = Config.Rarities[fish.rarity].rank
|
||||
-- жемчуг за мутацию
|
||||
local pearls = fish.mutation and Config.Pearls.mutation[fish.mutation] or 0
|
||||
if pearls > 0 then
|
||||
data.pearls += pearls
|
||||
api.notify(player, ("🦪 +%d жемчуга за мутацию!"):format(pearls), Color3.fromRGB(235, 225, 245))
|
||||
end
|
||||
local rainy = ctx.weather == "Rain" or ctx.weather == "Storm"
|
||||
-- заказы «по ходу»
|
||||
Guild.refreshOrders(data, player)
|
||||
local changed = false
|
||||
for _, o in ipairs(data.orders.list) do
|
||||
if not o.done then
|
||||
local add = 0
|
||||
if o.kind == "weather" and rainy then
|
||||
add = 1
|
||||
elseif o.kind == "night" and ctx.night and rank >= 2 then
|
||||
add = 1
|
||||
elseif o.kind == "perfect" and ctx.perfect then
|
||||
add = 1
|
||||
elseif o.kind == "combo" and (ctx.streak or 0) > o.progress then
|
||||
o.progress = math.min(o.count, ctx.streak)
|
||||
changed = true
|
||||
if o.progress >= o.count then
|
||||
finishOrder(player, data, o)
|
||||
end
|
||||
end
|
||||
if add > 0 then
|
||||
o.progress = math.min(o.count, o.progress + add)
|
||||
changed = true
|
||||
if o.progress >= o.count then
|
||||
finishOrder(player, data, o)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- испытание
|
||||
local nextRank = RANKS[data.rank + 1]
|
||||
if data.trial and nextRank and data.trial.rank == data.rank + 1 then
|
||||
local t = nextRank.trial
|
||||
if t.kind == "catch" and rank >= (t.minRank or 1)
|
||||
and (not t.weathers or t.weathers[ctx.weather])
|
||||
and (not t.night or ctx.night) then
|
||||
trialProgress(player, data, 1)
|
||||
elseif t.kind == "dex" then
|
||||
checkDexTrial(player, data)
|
||||
end
|
||||
end
|
||||
if changed or pearls > 0 then
|
||||
Guild.sendState(player)
|
||||
end
|
||||
end
|
||||
|
||||
-- победа над боссом: испытание ранга C и жемчуг
|
||||
function Guild.onBossWin(player, data)
|
||||
data.pearls += Config.Pearls.boss
|
||||
api.notify(player, ("🦪 +%d жемчуга за босса!"):format(Config.Pearls.boss), Color3.fromRGB(235, 225, 245))
|
||||
local nextRank = RANKS[data.rank + 1]
|
||||
if data.trial and nextRank and data.trial.rank == data.rank + 1 and nextRank.trial.kind == "bossWin" then
|
||||
trialProgress(player, data, 1)
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- миры, скидки
|
||||
|
||||
function Guild.canEnter(data, worldId)
|
||||
local need = Config.Guild.worldRank[worldId]
|
||||
if need and (data.rank or 1) < need then
|
||||
return false, ("🔒 Нужен ранг гильдии %s"):format(RANKS[need].id)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function Guild.price(data, price)
|
||||
local d = Guild.rank(data).discount or 0
|
||||
return math.floor(price * (1 - d) + 0.5)
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- наживка
|
||||
|
||||
function Guild.bait(data)
|
||||
local id = data.bait.equipped
|
||||
if id and (data.bait.counts[id] or 0) > 0 then
|
||||
return Config.Find(Config.Baits, id)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- тратим 1 штуку на заброс; кончилась — слот пустеет
|
||||
function Guild.useBait(player, data)
|
||||
local b = Guild.bait(data)
|
||||
if not b then
|
||||
return nil
|
||||
end
|
||||
data.bait.counts[b.id] -= 1
|
||||
if data.bait.counts[b.id] <= 0 then
|
||||
data.bait.counts[b.id] = nil
|
||||
data.bait.equipped = nil
|
||||
api.notify(player, b.icon .. " " .. b.name .. " закончился", Color3.fromRGB(255, 200, 120))
|
||||
end
|
||||
player:SetAttribute("BaitCount", data.bait.equipped and (data.bait.counts[data.bait.equipped] or 0) or 0)
|
||||
player:SetAttribute("Bait", data.bait.equipped)
|
||||
return b
|
||||
end
|
||||
|
||||
local function buyBait(player, data, id)
|
||||
local b = Config.Find(Config.Baits, id)
|
||||
if not b then
|
||||
return
|
||||
end
|
||||
if b.rank and data.rank < b.rank then
|
||||
api.notify(player, ("🔒 Нужен ранг гильдии %s"):format(RANKS[b.rank].id), RED)
|
||||
return
|
||||
end
|
||||
if b.currency == "pearls" then
|
||||
if data.pearls < b.price then
|
||||
api.notify(player, ("Нужно %d 🦪"):format(b.price), RED)
|
||||
return
|
||||
end
|
||||
data.pearls -= b.price
|
||||
else
|
||||
local price = Guild.price(data, b.price)
|
||||
if data.coins < price then
|
||||
api.notify(player, ("Нужно %d ⚪"):format(price), RED)
|
||||
return
|
||||
end
|
||||
data.coins -= price
|
||||
end
|
||||
data.bait.counts[b.id] = (data.bait.counts[b.id] or 0) + b.pack
|
||||
if not Guild.bait(data) then
|
||||
data.bait.equipped = b.id
|
||||
end
|
||||
api.notify(player, ("%s +%d × %s"):format(b.icon, b.pack, b.name), GREEN)
|
||||
api.updateStats(player)
|
||||
Guild.sendState(player)
|
||||
end
|
||||
|
||||
local function equipBait(player, data, id)
|
||||
if id == nil or id == "" then
|
||||
data.bait.equipped = nil
|
||||
elseif (data.bait.counts[id] or 0) > 0 then
|
||||
data.bait.equipped = id
|
||||
else
|
||||
return
|
||||
end
|
||||
api.updateStats(player)
|
||||
Guild.sendState(player)
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- ловушки
|
||||
|
||||
local function rollTrapFish(rng)
|
||||
local T = Config.Traps
|
||||
local rarity = pick(rng, T.rarities)
|
||||
local pool = {}
|
||||
for _, f in ipairs(Config.Zones[T.world].fish) do
|
||||
if f.rarity == rarity then
|
||||
table.insert(pool, f)
|
||||
end
|
||||
end
|
||||
local f = pool[rng:NextInteger(1, #pool)]
|
||||
local wf = rng:NextNumber() ^ 2.2
|
||||
return {
|
||||
id = f.id, name = f.name, rarity = f.rarity,
|
||||
weight = math.floor((f.minW + (f.maxW - f.minW) * wf) * 100) / 100,
|
||||
value = math.floor(f.price * (0.75 + 0.9 * wf) + 0.5),
|
||||
}
|
||||
end
|
||||
|
||||
local function collectTraps(player, data)
|
||||
local T = Config.Traps
|
||||
local now = os.time()
|
||||
local cap = api.bagCapacity(player, data)
|
||||
local rng = Random.new()
|
||||
local got = 0
|
||||
for i, t0 in ipairs(data.traps) do
|
||||
local ready = math.min(T.max, math.floor((now - t0) / T.every))
|
||||
local take = math.min(ready, cap - #data.items)
|
||||
for _ = 1, take do
|
||||
local f = rollTrapFish(rng)
|
||||
f.uid = data.nextUid
|
||||
data.nextUid += 1
|
||||
table.insert(data.items, f)
|
||||
local rec = data.discovered[f.id]
|
||||
if not rec then
|
||||
data.discovered[f.id] = { count = 1, best = f.weight }
|
||||
else
|
||||
rec.count += 1
|
||||
end
|
||||
end
|
||||
got += take
|
||||
-- что не влезло, остаётся в ловушке; полная ловушка дальше не копит
|
||||
local left = ready - take
|
||||
data.traps[i] = now - left * T.every
|
||||
end
|
||||
if got == 0 then
|
||||
api.notify(player, #data.traps == 0 and "🧺 Ловушки — с ранга D" or ((#data.items >= cap) and "🎒 Сумка полна!" or "🧺 В ловушках пока пусто"), Color3.fromRGB(255, 200, 120))
|
||||
else
|
||||
data.totalCaught += got
|
||||
api.notify(player, ("🧺 Из ловушек: +%d рыб"):format(got), GREEN)
|
||||
api.sendInventory(player)
|
||||
end
|
||||
api.updateStats(player)
|
||||
Guild.sendState(player)
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- отдых
|
||||
|
||||
function Guild.onJoin(player, data)
|
||||
local last = data.lastOnline
|
||||
if last and last > 0 then
|
||||
local away = os.time() - last
|
||||
data.rest = math.min(Config.Rest.max, (data.rest or 0) + away / Config.Rest.perOffline)
|
||||
end
|
||||
-- ловушки по рангу (старые сохранения, ранг выдан миграцией)
|
||||
while #data.traps < (Guild.rank(data).traps or 0) do
|
||||
table.insert(data.traps, os.time())
|
||||
end
|
||||
end
|
||||
|
||||
function Guild.onLeave(data)
|
||||
data.lastOnline = os.time()
|
||||
end
|
||||
|
||||
-- множитель опыта: двойной, пока есть отдых
|
||||
function Guild.xpMult(data)
|
||||
return (data.rest or 0) > 0 and Config.Rest.mult or 1
|
||||
end
|
||||
|
||||
-- отдых тратится секундами, пока игрок рыбачит
|
||||
function Guild.spendRest(player, data, seconds)
|
||||
if (data.rest or 0) > 0 then
|
||||
data.rest = math.max(0, data.rest - seconds)
|
||||
player:SetAttribute("RestLeft", math.floor(data.rest))
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- события от клиента
|
||||
|
||||
function Guild.onAction(player, action, a, b)
|
||||
local data = api.profiles[player]
|
||||
if not data then
|
||||
return false
|
||||
end
|
||||
if action == "GuildState" then
|
||||
Guild.sendState(player)
|
||||
elseif action == "TakeTrial" then
|
||||
takeTrial(player, data)
|
||||
elseif action == "DeliverOrder" then
|
||||
deliverOrder(player, data, tonumber(a))
|
||||
elseif action == "RerollOrder" then
|
||||
rerollOrder(player, data, tonumber(a))
|
||||
elseif action == "BuyBait" then
|
||||
buyBait(player, data, a)
|
||||
elseif action == "EquipBait" then
|
||||
equipBait(player, data, a)
|
||||
elseif action == "CollectTraps" then
|
||||
collectTraps(player, data)
|
||||
else
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return Guild
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,46 @@
|
||||
-- WeatherServer (Script) -> ServerScriptService
|
||||
-- Общие для всего сервера время суток и погода. Ничего не рисует — только выставляет атрибуты workspace:
|
||||
-- DayStart — серверное время начала суток (часы считает Config.ClockAt)
|
||||
-- Weather — id погоды из Config.Weathers
|
||||
-- WeatherEnds — когда сменится (workspace:GetServerTimeNow())
|
||||
-- Небо, дождь, звуки и свет делает клиент (Ambience), бонусы к рыбалке учитывает GameServer.
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Config = require(ReplicatedStorage:WaitForChild("FishConfig"))
|
||||
|
||||
local rng = Random.new()
|
||||
|
||||
if Config.DayNight.enabled then
|
||||
workspace:SetAttribute("DayStart", workspace:GetServerTimeNow())
|
||||
end
|
||||
|
||||
local function pickWeather(previous)
|
||||
local total = 0
|
||||
for _, w in ipairs(Config.Weathers) do
|
||||
if w.id ~= previous then
|
||||
total += w.weight
|
||||
end
|
||||
end
|
||||
local roll = rng:NextNumber() * total
|
||||
for _, w in ipairs(Config.Weathers) do
|
||||
if w.id ~= previous then
|
||||
roll -= w.weight
|
||||
if roll <= 0 then
|
||||
return w
|
||||
end
|
||||
end
|
||||
end
|
||||
return Config.Weathers[1]
|
||||
end
|
||||
|
||||
task.spawn(function()
|
||||
-- первая погода всегда ясная: новичок видит мир чистым
|
||||
local current = Config.Weathers[1]
|
||||
while true do
|
||||
local duration = rng:NextInteger(current.duration[1], current.duration[2])
|
||||
workspace:SetAttribute("Weather", current.id)
|
||||
workspace:SetAttribute("WeatherEnds", workspace:GetServerTimeNow() + duration)
|
||||
task.wait(duration)
|
||||
current = pickWeather(current.id)
|
||||
end
|
||||
end)
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user