-- Зелья: сумка, одно действующее, замена только с подтверждением, слабое не продлевает сильное, -- трата попытки при поклёвке, перенос старого зелья. (T — из tests/lib.lua) local Potions = T.fresh("Potions") local Config = require(game:GetService("ReplicatedStorage").FishConfig) local function fresh() return { potions = nil, boostUntil = 0, boostBonus = 0 } end T.test("награда кладётся в сумку и не пьётся сама", function() local d = fresh() T.ok(Potions.add(d, "Focus", 1)) T.eq(Potions.count(d, "Focus"), 1) T.eq(Potions.active(d), nil, "ничего не действует") end) T.test("выпить: попытки и минус из сумки", function() local d = fresh() Potions.add(d, "Focus", 2) local ok, code = Potions.activate(d, "Focus") T.ok(ok) T.eq(code, "started") local _, a = Potions.active(d) T.eq(a.left, 20) T.eq(Potions.count(d, "Focus"), 1) end) T.test("другое зелье без подтверждения — отказ, ничего не меняется", function() local d = fresh() Potions.add(d, "Mutation", 1) Potions.add(d, "Focus", 1) Potions.activate(d, "Mutation") local ok, code, info = Potions.activate(d, "Focus", false) T.eq(ok, false) T.eq(code, "needConfirm") T.eq(info.activeId, "Mutation") local def, a = Potions.active(d) T.eq(def.id, "Mutation", "сильное не тронуто") T.eq(a.left, 20, "слабое не продлило сильное") T.eq(Potions.count(d, "Focus"), 1, "слабое осталось в сумке") end) T.test("замена с подтверждением: сообщаем, что пропало", function() local d = fresh() Potions.add(d, "Mutation", 1) Potions.add(d, "Focus", 1) Potions.activate(d, "Mutation") Potions.consumeAttempt(d, "Mutation") local ok, code, info = Potions.activate(d, "Focus", true) T.ok(ok) T.eq(code, "replaced") T.eq(info.lostId, "Mutation") T.eq(info.lostLeft, 19) T.eq((Potions.active(d)).id, "Focus") end) T.test("то же зелье поверх продлевает, но не выше предела", function() local d = fresh() Potions.add(d, "Trophy", 5) Potions.activate(d, "Trophy") T.eq(select(2, Potions.activate(d, "Trophy")), "extended") T.eq(select(2, Potions.active(d)).left, 40) Potions.activate(d, "Trophy") T.eq(select(2, Potions.active(d)).left, Config.PotionMaxCharges) local ok, code = Potions.activate(d, "Trophy") T.eq(ok, false) T.eq(code, "full") T.eq(Potions.count(d, "Trophy"), 2, "лишнее не списано") end) T.test("попытка тратится только для зелья, действовавшего при забросе", function() local d = fresh() Potions.add(d, "Swift", 1) Potions.activate(d, "Swift") T.eq(Potions.consumeAttempt(d, "Focus"), false, "чужой снимок") T.eq(Potions.consumeAttempt(d, nil), false, "без зелья при забросе") T.eq(select(2, Potions.active(d)).left, 20) for _ = 1, 20 do T.ok(Potions.consumeAttempt(d, "Swift")) end T.eq(Potions.active(d), nil, "кончилось") end) T.test("отмена до поклёвки не тратит (consume не вызывается) — эффект берётся снимком", function() local d = fresh() Potions.add(d, "Research", 1) Potions.activate(d, "Research") local snap = Potions.effect(d) T.eq(snap.newSpecies, 3) -- игрок отменил до поклёвки: сервер не зовёт consumeAttempt T.eq(select(2, Potions.active(d)).left, 20) end) T.test("зелья на время тикают, на попытки — нет", function() local d = fresh() Potions.add(d, "SuperLuck", 1) Potions.activate(d, "SuperLuck") T.eq(Potions.effect(d).luck, 2.0) Potions.tick(d, 899) T.eq(select(2, Potions.active(d)).left, 1) T.eq(Potions.tick(d, 1), true, "закончилось") local d2 = fresh() Potions.add(d2, "Focus", 1) Potions.activate(d2, "Focus") Potions.tick(d2, 1000) T.eq(select(2, Potions.active(d2)).left, 20) end) T.test("перенос старого зелья удачи: остаток секунд и сила сохраняются", function() local d = { boostUntil = 1000 + 420, boostBonus = 1.0 } Potions.migrateLegacy(d, 1000) local def, a = Potions.active(d) T.eq(def.id, "Legacy") T.eq(a.left, 420) T.eq(Potions.effect(d).luck, 1.0) T.eq(d.boostUntil, 0) local d2 = { boostUntil = 500, boostBonus = 2 } Potions.migrateLegacy(d2, 1000) T.eq(Potions.active(d2), nil, "истёкшее не переносится") end) T.test("старое и неизвестное нельзя добавить или выпить", function() local d = fresh() T.eq(Potions.add(d, "Legacy", 1), false) T.eq(Potions.add(d, "Nope", 1), false) T.eq(Potions.add(d, "Focus", -3), false) T.eq((Potions.activate(d, "Legacy")), false) T.eq(select(2, Potions.activate(d, "Focus")), "none") end) T.test("нет зелий на опыт карьеры", function() for _, p in ipairs(Config.Potions) do T.eq(p.xp, nil, p.id) end end) return T.report("potions")