Sign in
world

Lost Workshops

by Potluck · version 1 · Checked for all ages

Long ago tinkerers worked down in the rock, and some of their workshops are still there. Wander deep enough underground and you may find one: bookshelves, a workbench, a tinker's pot and a vault in riveted iron that no pickaxe can cut. The vault opens with power. The old wire to it is broken, so mend it and pull the lever. Inside are ingots, circuit parts, tools and now and then a clockwork bird for the Curator.

1--!strict
2-- Lost Workshops' own tests: `potluck-server --test=lost-workshop`. The
3-- Circuits creation's blocks aren't here, so the lever and the old wire
4-- aren't put down; a Rust test (`lost_workshops_open_with_circuits`) plays
5-- the wire, the lever and the vault opening with Circuits running too.
6
7local test = require("@potluck/test@0.8")
8local world = require("@potluck/world@0.26")
9local store = require("@potluck/store")
10
11-- the tools creation gives pickaxes their levels; these tests don't run it
12world.digging("Moonsilver pickaxe", { hard = 8, level = 5 })
13
14local function v(x: number, y: number, z: number): vector
15 return vector.create(x, y, z)
16end
17
18-- a little cave dug in the rock under the island, far from the Green, for
19-- a player to stand in, and the workshop that opens near them
20local function down_deep(p): any
21 local g = world.spot("green") :: vector
22 local x, y, z = math.floor(g.x) + 140, -20, math.floor(g.z) - 40
23 for dx = -2, 2 do
24 for dz = -2, 2 do
25 for dy = 0, 2 do
26 world.set_block(v(x + dx, y + dy, z + dz), "Air")
27 end
28 world.set_block(v(x + dx, y - 1, z + dz), "Stone")
29 end
30 end
31 test.move(p, v(x + 0.5, y, z + 0.5))
32 for _ = 1, 40 do
33 test.wait(1)
34 local list = store.get("workshops") :: { any }?
35 if list and list[1] and list[1].built then
36 return list[1]
37 end
38 end
39 return nil
40end
41
42test.case("a workshop opens in the rock near a player deep down, its vault walled in riveted iron", function()
43 local p = test.player("Ada")
44 local w = down_deep(p)
45 test.check(w ~= nil, "a workshop opened")
46 local at = w.at :: vector
47 -- with Circuits in this world (in the base game's own run of every
48 -- creation's tests, say), the old wire runs through the middle
49 local circuits = pcall(world.kind, "Copper wire") and pcall(world.kind, "Lever")
50 test.check(world.block(at) == "Air" or (circuits and world.block(at) == "Copper wire"), "it's dug: " .. world.block(at))
51 test.same(world.block(at - v(0, 1, 0)), "Planks", "on a plank floor")
52 test.same(world.block(at + v(6, 1, 0)), "Mossy brick", "in mossy brick walls")
53 test.same(world.block(at + v(0, 0, -5)), "Vault door", "the vault door")
54 test.same(world.block(at + v(0, 1, -5)), "Vault door", "two blocks high")
55 test.same(world.block(at + v(0, 0, -7)), "Vault chest", "its chest inside")
56 test.same(world.block(at + v(-3 * w.side, 1, 3)), "Clay pot", "the tinker's pot on the table")
57 test.same(world.block(at + v(-3 * w.side, 0, 3)), "Table", "the table")
58 for _, d in { v(0, 0, -9), v(2, 0, -7), v(-2, 1, -7), v(0, 2, -7), v(0, -1, -7), v(1, 0, -5) } do
59 test.same(world.block(at + d), "Riveted iron", "riveted all around")
60 end
61 if circuits then
62 test.same(world.block(at + v(4 * w.side, 0, 2)), "Lever", "a lever, with circuits")
63 else
64 test.same(world.block(at + v(4 * w.side, 0, 2)), "Air", "no lever without circuits")
65 end
66 test.same(w.open, false, "shut")
67 test.wait(6)
68 test.same(#(store.get("workshops") :: { any }), 1, "only one")
69end)
70
71test.case("nothing cuts the vault's iron or its door", function()
72 local p = test.player("Ada", { survival = true, carrying = { ["Moonsilver pickaxe"] = 1 } })
73 test.hold(p, "Moonsilver pickaxe")
74 local x, z = p.position.x + 2, p.position.z
75 local y = world.top(x, z) + 1
76 local iron, door, stone = v(x, y, z), v(x, y, z + 1), v(x, y, z - 1)
77 world.set_block(iron, "Riveted iron")
78 world.set_block(door, "Vault door")
79 world.set_block(stone, "Stone")
80 test.check(test.dig(p, stone), "a moonsilver pickaxe breaks stone")
81 test.check(not test.dig(p, iron), "but not riveted iron")
82 test.check(not test.dig(p, door), "nor the vault door")
83 test.same(world.block(door), "Vault door", "still there")
84end)
85
86test.case("the tinker's pot gives its wire and goggles once, and the vault chest its prizes once", function()
87 local p = test.player("Ada", { survival = true })
88 local w = down_deep(p)
89 test.check(w ~= nil, "a workshop")
90 local at = w.at :: vector
91 local box = at + v(-3 * w.side, 1, 3)
92 test.move(p, at + v(-3 * w.side + 0.5, 0, 1.5))
93 test.use_block(p, box)
94 test.same(world.has(p, "Tinker's goggles"), 1, "the goggles")
95 local circuits = pcall(world.kind, "Copper wire")
96 test.same(test.shown(p, "workshop"), if circuits then "You found 3 copper wire and tinker's goggles." else "You found tinker's goggles.")
97 test.wait(0.5)
98 test.use_block(p, box)
99 test.same(world.has(p, "Tinker's goggles"), 1, "only once")
100 test.same(test.shown(p, "workshop"), "The tinker's pot is empty.")
101 -- in through the open door (as if it had been opened)
102 local chest = at + v(0, 0, -7)
103 test.move(p, at + v(0.5, 0, -5.5))
104 local before = 0
105 for _, n in world.pockets(p) or {} do
106 before += n
107 end
108 test.use_block(p, chest)
109 local after = 0
110 for _, n in world.pockets(p) or {} do
111 after += n
112 end
113 test.check(after > before, "something in their pockets")
114 test.same(test.shown(p, "workshop"), "The vault's treasure is yours.")
115 local card = test.asked(p) :: any
116 test.check(card ~= nil and string.find(card.text, "You found", 1, true) == 1, "what's in it")
117 test.answer(p, 1)
118 test.same((store.get("workshops") :: { any })[1].chest, false, "the chest's empty")
119 test.use_block(p, chest)
120 test.same(test.shown(p, "workshop"), "An empty chest.")
121end)
122
123test.case("creative players can look around but find nothing to take", function()
124 local p = test.player("Bo")
125 local w = down_deep(p)
126 test.check(w ~= nil, "a workshop")
127 test.move(p, w.at + v(-3 * w.side + 0.5, 0, 1.5))
128 test.use_block(p, w.at + v(-3 * w.side, 1, 3))
129 test.same(test.shown(p, "workshop"), "Lost workshops hold prizes for survival.")
130 test.same((store.get("workshops") :: { any })[1].box, true, "the box keeps its things")
131end)
132
133test.case("the clockwork bird is a relic, and sings three notes", function()
134 local it = world.item("Clockwork bird") :: any
135 test.check(it ~= nil and it.by == "lost-workshop", "an item of the workshops'")
136 test.check(type(it.relic) == "string" and #it.relic > 20, "its story")
137 local p = test.player("Ada", { survival = true, carrying = { ["Clockwork bird"] = 1 } })
138 test.hold(p, "Clockwork bird")
139 test.use_item(p)
140 test.wait(1.5)
141 test.same(test.heard("tweet"), 3, "three notes")
142end)
143
144test.case("tinker's goggles are armor for the head", function()
145 local it = world.item("Tinker's goggles") :: any
146 test.same(it.kind, "armor")
147 test.same(it.slot, "head")
148 test.same(it.guard, 1)
149end)