Sign in
mod

Brewing

by Potluck · version 1 · Checked for all ages

Set a clay pot on a brazier, a campfire or a lit furnace and it brews teas, tonics and drafts, each in a glass vial from the workbench: some mend you, some make you dig faster, hit harder or shrug off hurts, and some give you a gift for a while: seeing in the dark, a higher jump, a quicker step, breathing under water, a slow fall, fire resistance, warmth or luck. Drink one (use it on nothing) and a picture on the left says what it's doing and for how long.

1--!strict
2-- Brewing's own tests: `potluck-server --test=brewing`.
3
4local test = require("@potluck/test@0.9")
5local world = require("@potluck/world@0.34")
6
7-- a clay pot on a brazier a little way from where the player stands
8local function pot_on(p, heat: string?): vector
9 local at = p.position + vector.create(2, 0, 0)
10 local x, z = math.floor(at.x), math.floor(at.z)
11 local y = world.top(x, z) + 1
12 if heat then
13 world.set_block(vector.create(x, y, z), heat)
14 y += 1
15 end
16 world.set_block(vector.create(x, y, z), "Clay pot")
17 test.wait(0.1)
18 return vector.create(x + 0.5, y + 0.5, z + 0.5)
19end
20
21local function choice(p, name: string): number?
22 local q = test.asked(p)
23 for i, c in (q and q.choices) or {} do
24 if c == name then
25 return i
26 end
27 end
28 return nil
29end
30
31-- the pot's cards: the shelves, then one shelf's brews
32local function open_shelf(p, at: vector, shelf: string)
33 test.use_block(p, at)
34 local q = test.asked(p)
35 test.check(q ~= nil and q.title == "Brewing pot", "the pot asks what to brew")
36 local i = choice(p, shelf)
37 test.check(i ~= nil, shelf .. " is a shelf")
38 test.answer(p, i :: number)
39 test.wait(0.1)
40end
41
42local function drink(p, name: string)
43 test.hold(p, name)
44 test.use_item(p)
45end
46
47test.case("a clay pot over a brazier brews mending tea into a vial", function()
48 local p = test.player("Ada", { survival = true, carrying = { Berries = 2, Honey = 1, ["Glass vial"] = 1 } })
49 test.wait(0.5)
50 local at = pot_on(p, "Brazier")
51 open_shelf(p, at, "Mending")
52 local q = test.asked(p)
53 test.check(q ~= nil and q.title == "Brewing pot: Mending", "the shelf asks")
54 local tea = choice(p, "Mending tea")
55 test.check(tea ~= nil, "mending tea is on the shelf")
56 test.answer(p, tea :: number)
57 test.wait(0.2)
58 test.same(world.has(p, "Mending tea"), 1, "a mending tea")
59 test.same(world.has(p, "Glass vial"), 0, "in the vial")
60 test.same(world.has(p, "Berries"), 0, "the berries went in")
61 test.same(world.has(p, "Honey"), 0, "and the honey")
62 -- with nothing left to brew from, it says what it needs
63 test.answer(p, (choice(p, "Mending tea")) :: number)
64 test.wait(0.2)
65 local again = test.shown(p, "brewing_said")
66 test.check(again ~= nil and string.find(again, "glass vial", 1, true) ~= nil, "it wants a vial: " .. tostring(again))
67 -- and Back goes to the shelves
68 test.answer(p, (choice(p, "Back")) :: number)
69 test.wait(0.1)
70 test.check(choice(p, "Feet") ~= nil, "the shelves again")
71end)
72
73test.case("every shelf's card fits its words, and has every brew on it", function()
74 local p = test.player("Ed", { survival = true })
75 test.wait(0.5)
76 local at = pot_on(p, "Brazier")
77 test.use_block(p, at)
78 local shelves = {}
79 for _, c in (test.asked(p) :: any).choices do
80 if c ~= "Close" then
81 table.insert(shelves, c)
82 end
83 end
84 test.check(#shelves == 5, "five shelves: " .. #shelves)
85 local brews = 0
86 for _, shelf in shelves do
87 test.answer(p, (choice(p, shelf)) :: number)
88 test.wait(0.1)
89 local q = test.asked(p) :: any
90 test.check(#q.text <= 300, shelf .. "'s card is " .. #q.text .. " letters")
91 for _, name in q.choices do
92 if name ~= "Back" then
93 brews += 1
94 test.check(string.find(q.text, name .. ":", 1, true) ~= nil, name .. " is on the card")
95 test.check(#name <= 30, name .. " fits a button")
96 end
97 end
98 test.check(#q.choices <= 8, shelf .. " has " .. #q.choices .. " choices")
99 -- Back, to the shelves
100 test.answer(p, #q.choices)
101 test.wait(0.1)
102 end
103 test.check(brews == 25, "25 brews in all: " .. brews)
104end)
105
106test.case("a cold clay pot is just a pot", function()
107 local p = test.player("Bo", { survival = true, carrying = { Berries = 2, Honey = 1, ["Glass vial"] = 1 } })
108 test.wait(0.5)
109 local at = pot_on(p, nil)
110 test.use_block(p, at)
111 test.same(test.asked(p), nil, "no brewing without heat")
112end)
113
114test.case("mending tea heals, and the vial comes back", function()
115 local p = test.player("Cy", { survival = true, carrying = { ["Mending tea"] = 1 } })
116 test.wait(0.5)
117 world.hurt(p, 12)
118 test.wait(0.2)
119 local before = test.health(p)
120 drink(p, "Mending tea")
121 test.wait(0.3)
122 test.check(test.health(p) >= before + 7, "healed: " .. before .. " to " .. test.health(p))
123 test.same(world.has(p, "Mending tea"), 0, "drunk")
124 test.same(world.has(p, "Glass vial"), 1, "the vial back")
125end)
126
127test.case("a digger's tonic digs faster for a while, then wears off", function()
128 local p = test.player("Di", { survival = true, carrying = { ["Digger's tonic"] = 1, ["Fireheart draft"] = 1 } })
129 test.wait(0.5)
130 drink(p, "Digger's tonic")
131 drink(p, "Fireheart draft")
132 test.wait(1.5)
133 test.check(math.abs(world.haste(p) - 1.6) < 0.01, "digging faster: " .. world.haste(p))
134 test.check(math.abs(world.might(p) - 1.5) < 0.01, "and hitting harder: " .. world.might(p))
135 -- each brew has its picture and its words, the longest-lasting first
136 local first, second = test.shown(p, "fx1"), test.shown(p, "fx2")
137 test.check(first ~= nil and string.find(first, "Digging\n2:5", 1, true) ~= nil, "it says so: " .. tostring(first))
138 test.check(second ~= nil and string.find(second, "Might\n1:", 1, true) ~= nil, "and the other: " .. tostring(second))
139 test.wait(125)
140 test.same(world.might(p), 1, "the draft's worn off")
141 test.check(math.abs(world.haste(p) - 1.6) < 0.01, "but not the tonic")
142 test.same(test.shown(p, "fx2"), nil, "and its picture's gone")
143 test.wait(60)
144 test.same(world.haste(p), 1, "and now the tonic")
145 test.same(test.shown(p, "fx1"), nil, "nothing left working")
146end)
147
148test.case("night sight, a high jump, gills, a slow fall, fire and luck are perks", function()
149 local p = test.player("Eve", {
150 survival = true,
151 carrying = { ["Cat's-eye tonic"] = 1, ["Owl's brew"] = 1, ["Springheel tonic"] = 1, ["Tidewater tonic"] = 1, ["Featherfall tea"] = 1, ["Cinderward tonic"] = 1, ["Clover tea"] = 1, ["Quickstep tea"] = 1, ["Hearth cider"] = 1 },
152 })
153 test.wait(0.5)
154 drink(p, "Cat's-eye tonic")
155 test.wait(1.2)
156 test.same(world.perk(p, "night_sight"), 1, "cat's eyes")
157 drink(p, "Owl's brew")
158 test.wait(1.2)
159 test.same(world.perk(p, "night_sight"), 2, "the owl's the stronger")
160 for name, perk in { ["Springheel tonic"] = "leap", ["Tidewater tonic"] = "gills", ["Featherfall tea"] = "feather", ["Cinderward tonic"] = "fireproof", ["Clover tea"] = "luck", ["Quickstep tea"] = "stride", ["Hearth cider"] = "warm" } do
161 drink(p, name)
162 test.wait(1.2)
163 test.same(world.perk(p, perk), 1, name .. " gives " .. perk)
164 test.same(world.has(p, name), 0, name .. " is drunk")
165 end
166 -- six chips at most, and the soonest to end drop off first: after the
167 -- owl's brew (3 minutes) and the springheel (3 minutes) end
168 test.wait(185)
169 test.same(world.perk(p, "night_sight"), 1, "the owl's brew has gone, the cat's eyes stay")
170 test.same(world.perk(p, "leap"), 0, "the springheel has gone")
171 test.same(world.perk(p, "luck"), 1, "luck lasts five minutes")
172 test.wait(130)
173 test.same(world.perk(p, "night_sight"), 0, "night sight's gone")
174 test.same(world.perk(p, "luck"), 0, "and luck")
175 test.same(world.perk(p, "warm"), 0, "and warmth")
176end)
177
178test.case("a hero's cordial gives four things at once, and a diver's brew two perks", function()
179 local p = test.player("Fay", { survival = true, carrying = { ["Hero's cordial"] = 1, ["Diver's brew"] = 1 } })
180 test.wait(0.5)
181 drink(p, "Hero's cordial")
182 drink(p, "Diver's brew")
183 test.wait(1.2)
184 test.check(math.abs(world.might(p) - 1.3) < 0.01, "might: " .. world.might(p))
185 test.check(math.abs(world.haste(p) - 1.3) < 0.01, "haste: " .. world.haste(p))
186 test.same(world.perk(p, "gills"), 1, "gills")
187 test.same(world.perk(p, "night_sight"), 1, "and sight")
188 test.wait(185)
189 test.same(world.might(p), 1, "all gone")
190 test.same(world.perk(p, "gills"), 0, "and the gills")
191end)
192
193test.case("scholar's tea and the bigger mending drafts work at once", function()
194 local p = test.player("Gus", { survival = true, carrying = { ["Scholar's tea"] = 1, ["Mender's draft"] = 1, ["Berry cordial"] = 1 } })
195 test.wait(0.5)
196 world.hurt(p, 15)
197 test.wait(0.2)
198 local before = test.health(p)
199 drink(p, "Mender's draft")
200 test.wait(0.3)
201 test.check(test.health(p) >= before + 13, "a big mend: " .. before .. " to " .. test.health(p))
202 local xp = world.xp(p)
203 drink(p, "Scholar's tea")
204 test.wait(0.3)
205 test.check(world.xp(p) >= xp + 80, "XP: " .. xp .. " to " .. world.xp(p))
206 drink(p, "Berry cordial")
207 test.wait(1.2)
208 test.check(test.shown(p, "fx1") ~= nil, "and its chip is up while it works")
209end)