Экономика v3: доступные дома, аренда, гарантия круток, награды за уровень, подарки за время, ежедневка без сброса
This commit is contained in:
1 parent
0fe8bd35a0
commit
9623681f57
9 files changed
+356
-27
No files matched your search
@@ -340,7 +340,7 @@ local function sendQuests(player)
|
||||
}, {
|
||||
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),
|
||||
nextStreak = (data.daily.last < t) and (data.daily.streak % 7 + 1) or data.daily.streak,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -409,6 +409,8 @@ local function updateStats(player)
|
||||
end
|
||||
end
|
||||
|
||||
local grantLevelRewards -- награды за новый уровень (ниже, после givePotion)
|
||||
|
||||
-- опыт карьеры (единственный источник — ручная поимка; source — для телеметрии)
|
||||
local function addXp(player, data, amount, source)
|
||||
if amount <= 0 then
|
||||
@@ -430,6 +432,10 @@ local function addXp(player, data, amount, source)
|
||||
if table.find(levels, Config.Market.minLevel) then
|
||||
notify(player, "🏪 Открыт рынок игроков: продавай ценную рыбу другим рыбакам", GOLD)
|
||||
end
|
||||
for _, lvl in ipairs(levels) do
|
||||
grantLevelRewards(player, data, lvl)
|
||||
end
|
||||
updateStats(player)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -450,6 +456,88 @@ local function givePotion(player, data, def)
|
||||
return false
|
||||
end
|
||||
|
||||
-- пачка наживки в запас (как при покупке у торговца)
|
||||
local function giveBait(data, baitId)
|
||||
local b = baitId and Config.Find(Config.Baits, baitId)
|
||||
if not b or type(data.bait) ~= "table" then
|
||||
return nil
|
||||
end
|
||||
data.bait.counts[b.id] = (data.bait.counts[b.id] or 0) + b.pack
|
||||
return b
|
||||
end
|
||||
|
||||
-- одна награда: { coins (× tier), pearls, potion, bait }; возвращает текст «+40 ⚪ + 🎯 …» для уведомления
|
||||
local function giveReward(player, data, r, kind, coinsAlreadyScaled)
|
||||
local parts = {}
|
||||
if r.coins then
|
||||
local c = addCoins(player, data, coinsAlreadyScaled and r.coins or r.coins * tierOf(data), kind)
|
||||
table.insert(parts, ("+%d ⚪"):format(c))
|
||||
end
|
||||
if r.pearls then
|
||||
data.pearls += r.pearls
|
||||
table.insert(parts, ("+%d 🦪"):format(r.pearls))
|
||||
end
|
||||
if r.potion then
|
||||
local p = Potions.def(r.potion)
|
||||
if givePotion(player, data, p) then
|
||||
table.insert(parts, p.icon .. " " .. p.name)
|
||||
end
|
||||
end
|
||||
if r.bait then
|
||||
local b = giveBait(data, r.bait)
|
||||
if b then
|
||||
table.insert(parts, ("%s %s ×%d"):format(b.icon, b.name, b.pack))
|
||||
Guild.sendState(player)
|
||||
end
|
||||
end
|
||||
return table.concat(parts, " + ")
|
||||
end
|
||||
|
||||
grantLevelRewards = function(player, data, lvl)
|
||||
local L = Config.LevelRewards
|
||||
local r = { coins = lvl * L.coinsPerLevel }
|
||||
local m = L.milestones[lvl]
|
||||
if m then
|
||||
r.coins += m.coins or 0
|
||||
r.pearls, r.potion, r.bait = m.pearls, m.potion, m.bait
|
||||
end
|
||||
if lvl % L.every == 0 then
|
||||
r.pearls = (r.pearls or 0) + L.everyPearls
|
||||
r.potion = r.potion or L.everyPotion
|
||||
end
|
||||
local text = giveReward(player, data, r, "LevelReward", true)
|
||||
Telemetry.event(player, "LevelReward", lvl)
|
||||
if text ~= "" then
|
||||
notify(player, ("⭐ Награда за уровень %d: %s"):format(lvl, text), GOLD)
|
||||
end
|
||||
end
|
||||
|
||||
-- подарки за время в игре в этот заход (Config.PlaytimeGifts)
|
||||
local sessionStart = {}
|
||||
local giftIndex = {}
|
||||
local function setGiftAttr(player)
|
||||
local g = Config.PlaytimeGifts[(giftIndex[player] or 0) + 1]
|
||||
player:SetAttribute("GiftNextAt", g and math.floor((sessionStart[player] or os.time()) + g.minutes * 60) or 0)
|
||||
end
|
||||
task.spawn(function()
|
||||
while true do
|
||||
task.wait(5)
|
||||
local now = os.time()
|
||||
for player, data in pairs(profiles) do
|
||||
local start = sessionStart[player]
|
||||
local g = start and Config.PlaytimeGifts[(giftIndex[player] or 0) + 1]
|
||||
if g and now - start >= g.minutes * 60 then
|
||||
giftIndex[player] = (giftIndex[player] or 0) + 1
|
||||
local text = giveReward(player, data, g, "PlaytimeGift")
|
||||
Telemetry.event(player, "PlaytimeGift", g.minutes)
|
||||
updateStats(player)
|
||||
notify(player, ("🎁 Подарок за %d мин в игре: %s"):format(g.minutes, text), GOLD)
|
||||
setGiftAttr(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
---------------------------------------------------------------- задания: прогресс цепочки
|
||||
|
||||
-- у старых сохранений вместо цепочки были три случайных задания
|
||||
@@ -508,7 +596,8 @@ local function claimDaily(player)
|
||||
notify(player, "🎁 Приходи завтра", Color3.fromRGB(255, 200, 120))
|
||||
return
|
||||
end
|
||||
local streak = (data.daily.last == t - 1) and (data.daily.streak % 7 + 1) or 1
|
||||
-- пропуск дня не сбрасывает круг: продолжается со следующего дня (Config.DailyRewards)
|
||||
local streak = data.daily.streak % 7 + 1
|
||||
local r = Config.DailyRewards[streak]
|
||||
local coins = addCoins(player, data, r.coins * tierOf(data), "Daily")
|
||||
local extra = ""
|
||||
@@ -2013,6 +2102,8 @@ local function onPlayerAdded(player)
|
||||
end
|
||||
profiles[player] = data
|
||||
loadedOk[player] = status == "ok"
|
||||
sessionStart[player], giftIndex[player] = os.time(), 0
|
||||
setGiftAttr(player)
|
||||
local settings = type(data.settings) == "table" and data.settings or {}
|
||||
player:SetAttribute("VolMusic", tonumber(settings.music) or Config.DefaultVolume.music)
|
||||
player:SetAttribute("VolSfx", tonumber(settings.sfx) or Config.DefaultVolume.sfx)
|
||||
@@ -2059,6 +2150,7 @@ local function finishPlayer(player)
|
||||
profiles[player] = nil
|
||||
loadedOk[player] = nil
|
||||
passes[player] = nil
|
||||
sessionStart[player], giftIndex[player] = nil, nil
|
||||
leaving[player] = nil
|
||||
end
|
||||
Players.PlayerRemoving:Connect(finishPlayer)
|
||||
|
||||
@@ -809,6 +809,9 @@ local function assign(player)
|
||||
local lvl = data and data.houseLevel or 0
|
||||
deps.notify(player, lvl > 0 and ("🏠 Твой дом — участок " .. i .. ". Заходи: внутри компьютер с улучшениями!")
|
||||
or ("🏠 Твой участок — №" .. i .. ". Построй дом у таблички!"), GREEN)
|
||||
if data then
|
||||
Houses.collectRent(player, data)
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -886,6 +889,9 @@ function Houses.defaults(data)
|
||||
local cos = data.houseCos
|
||||
cos.owned = type(cos.owned) == "table" and cos.owned or {}
|
||||
cos.equip = type(cos.equip) == "table" and cos.equip or {}
|
||||
cos.pity = type(cos.pity) == "table" and cos.pity or {}
|
||||
-- аренда считается от этого момента; у старых сохранений — от первого входа после обновления
|
||||
data.houseRentAt = tonumber(data.houseRentAt) or os.time()
|
||||
for _, cat in ipairs(COS.Categories) do
|
||||
local set = type(cos.owned[cat.id]) == "table" and cos.owned[cat.id] or {}
|
||||
for id in pairs(set) do
|
||||
@@ -926,6 +932,21 @@ function Houses.onComputer(player, prompt)
|
||||
end
|
||||
end
|
||||
|
||||
-- аренда: серебро за время с прошлого сбора (не больше HC.Rent.maxHours), забирается при входе на участок.
|
||||
-- Пустой участок аренды не даёт, но отсчёт сбрасывается — нельзя «накопить» до постройки дома
|
||||
function Houses.collectRent(player, data)
|
||||
local now = os.time()
|
||||
local hours = math.min(HC.Rent.maxHours, math.max(0, now - (data.houseRentAt or now)) / 3600)
|
||||
data.houseRentAt = now
|
||||
local amount = math.floor(HC.rentPerHour(data.houseLevel or 0) * hours)
|
||||
if amount > 0 then
|
||||
deps.addCoins(player, data, amount, "HouseRent")
|
||||
deps.updateStats(player)
|
||||
deps.notify(player, ("🏠 Аренда дома: +%d ⚪ (копится до %d ч, пока тебя нет)"):format(amount, HC.Rent.maxHours), GOLD)
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
||||
-- покупка следующего уровня
|
||||
function Houses.upgrade(player)
|
||||
local data = deps.profiles[player]
|
||||
@@ -947,6 +968,8 @@ function Houses.upgrade(player)
|
||||
deps.notify(player, "Не хватает серебра", RED)
|
||||
return
|
||||
end
|
||||
-- накопленное по старой ставке — забрать до повышения (новая ставка не действует задним числом)
|
||||
Houses.collectRent(player, data)
|
||||
data.houseLevel = nextLv
|
||||
deps.updateStats(player)
|
||||
rebuild(i)
|
||||
@@ -978,10 +1001,18 @@ function Houses.spin(player, catId, count)
|
||||
return
|
||||
end
|
||||
local owned = data.houseCos.owned[cat.id]
|
||||
local pity = data.houseCos.pity
|
||||
local results, newOnes, refund = {}, 0, 0
|
||||
local best = nil
|
||||
for _ = 1, count do
|
||||
local it = COS.roll(cat.id, rng)
|
||||
-- гарантия: после COS.Pity.every круток без «Эпического» — следующая не ниже него
|
||||
local guaranteed = (pity[cat.id] or 0) >= COS.Pity.every - 1
|
||||
local it = COS.roll(cat.id, rng, guaranteed and COS.Pity.minRank or nil)
|
||||
if COS.Rarities[it.rarity].rank >= COS.Pity.minRank then
|
||||
pity[cat.id] = 0
|
||||
else
|
||||
pity[cat.id] = (pity[cat.id] or 0) + 1
|
||||
end
|
||||
local isNew = not owned[it.id]
|
||||
if isNew then
|
||||
owned[it.id] = true
|
||||
|
||||
Reference in new issue
Block a user