Sign in
world

Old Greens

by Potluck · version 1 · Checked for all ages

Three old greens lie in ruins around the island: one by the shore, one deep in the woods and one up on the heights. Each hearth has gone cold. Bring it a lantern and something from nearby (sand, logs or stone) and use it to light it again, and it gives you something back. Light all three and the whole island hears of it.

1--!strict
2-- The Old Greens' own tests. Each case plays in a world of its own, with
3-- only this creation in it. Run them with the dev bridge's test tool, or
4-- `potluck-server --test=old-greens`.
5
6local test = require("@potluck/test@0.2")
7local world = require("@potluck/world@0.5")
8local store = require("@potluck/store")
9
10-- the Old Greens, once they're found and built
11local function sites(): { any }
12 for _ = 1, 40 do
13 local all = store.get("sites")
14 local built = all ~= nil and #all > 0
15 for _, s in all or {} do
16 built = built and s.built
17 end
18 if built then
19 return all
20 end
21 test.wait(0.5)
22 end
23 error("the Old Greens were never built")
24end
25
26-- where a site's hearth is
27local function hearth(s: any): vector
28 return s.at + vector.create(0, 1, 0)
29end
30
31local function site(id: string): any
32 for _, s in sites() do
33 if s.id == id then
34 return s
35 end
36 end
37 error("there's no Old Green " .. id)
38end
39
40test.case("three Old Greens stand far from the Green, cold", function()
41 local all = sites()
42 test.same(#all, 3, "Old Greens")
43 local green = world.spot("green")
44 for _, s in all do
45 test.same(world.block(hearth(s)), "Clay pot", s.id .. "'s hearth")
46 local away = vector.magnitude(vector.create(s.at.x - green.x, 0, s.at.z - green.z))
47 test.check(away > 80, s.id .. " is only " .. math.floor(away) .. " blocks from the Green")
48 test.same(world.block(s.at + vector.create(0, 2, 0)), "Air", "nothing over " .. s.id .. "'s hearth")
49 end
50 test.same(world.block(site("shore").at), "Sandstone bricks", "the shore's stones")
51end)
52
53test.case("without what it wants, a hearth stays cold and says so", function()
54 local s = site("woods")
55 local p = test.player("Ada", { survival = true, at = s.at + vector.create(2, 1, 2) })
56 test.wait(1.2)
57 local hint = test.shown(p, "old_green")
58 test.check(hint ~= nil and string.find(hint, "4 Oak log", 1, true) ~= nil, "near it, it says what it wants: " .. tostring(hint))
59 test.use_block(p, hearth(s))
60 test.same(world.block(hearth(s)), "Clay pot", "the hearth")
61 test.check(test.heard("cold") == 1, "it sounds cold")
62end)
63
64test.case("a lantern and what's nearby light one, and it gives something back", function()
65 local s = site("shore")
66 local p = test.player("Ada", { survival = true, carrying = { Lantern = 1, Sand = 8 }, at = s.at + vector.create(2, 1, 2) })
67 test.use_block(p, hearth(s))
68 test.same(world.block(hearth(s)), "Brazier", "the hearth")
69 local pockets = world.pockets(p)
70 test.same(pockets.Lantern, nil, "lanterns left")
71 test.same(pockets.Sand, 2, "sand left")
72 test.same(pockets["Balloon basket"], 1, "what it gave back")
73 test.same(test.heard("relight"), 1, "times it caught")
74 test.check(store.get("sites") ~= nil, "it's kept")
75 for _, kept in store.get("sites") do
76 if kept.id == "shore" then
77 test.check(kept.lit, "kept as lit")
78 end
79 end
80end)
81
82test.case("light all three and the island hears of it", function()
83 local p = test.player("Ada")
84 for _, s in sites() do
85 test.move(p, s.at + vector.create(2, 1, 2))
86 test.use_block(p, hearth(s))
87 test.same(world.block(hearth(s)), "Brazier", s.id .. "'s hearth")
88 end
89 test.wait(2)
90 test.same(test.heard("fanfare"), 1, "fanfares")
91end)