Long ago the Gnome Gardeners' people dug into the hills. Walk far from the Green and you'll come upon their diggings in a steep hillside: a timbered tunnel with old cart tracks, a slope down into the rock, a forge room, a store room and a long dark drift beyond. Bring a light. Burnt-out lanterns light again with a piece of coal, and gnome crates hold what the diggers left behind: tools, ore, ingots, seeds, a brass compass for collectors, and torn maps that lead to a crate buried out on the land.
| 1 | --!strict |
| 2 | -- The Gnome Diggings' own tests: `potluck-server --test=diggings`. |
| 3 | |
| 4 | local test = require("@potluck/test@0.8") |
| 5 | local world = require("@potluck/world@0.26") |
| 6 | local store = require("@potluck/store") |
| 7 | |
| 8 | local function on_ground(x: number, z: number): vector |
| 9 | return vector.create(x, world.top(x, z) + 1, z) |
| 10 | end |
| 11 | |
| 12 | -- Walks a player around the island, far from the Green, until a diggings |
| 13 | -- opens near them; says where its first crate is. |
| 14 | local function find_diggings(p): (any, vector?) |
| 15 | local green = world.spot("green") :: vector |
| 16 | for i = 0, 23 do |
| 17 | local a = i * math.pi / 12 |
| 18 | for _, d in { 130, 100, 160 } do |
| 19 | local x, z = math.floor(green.x + math.cos(a) * d), math.floor(green.z + math.sin(a) * d) |
| 20 | if world.top(x, z) > 21 then |
| 21 | test.move(p, on_ground(x, z)) |
| 22 | test.wait(4.5) |
| 23 | local sites = store.get("sites") :: { any }? |
| 24 | if sites and #sites > 0 then |
| 25 | -- let it finish digging |
| 26 | test.wait(3) |
| 27 | local crates = store.get("crates") :: { [string]: string }? |
| 28 | for k, room in crates or {} do |
| 29 | local x, y, z = string.match(k, "(-?%d+),(-?%d+),(-?%d+)") |
| 30 | return sites[1], vector.create(tonumber(x) :: number, tonumber(y) :: number, tonumber(z) :: number) |
| 31 | end |
| 32 | return sites[1], nil |
| 33 | end |
| 34 | end |
| 35 | end |
| 36 | end |
| 37 | return nil, nil |
| 38 | end |
| 39 | |
| 40 | test.case("diggings open in a hillside far from the Green, and their crates give prizes once", function() |
| 41 | local p = test.player("Ada", { survival = true }) |
| 42 | test.wait(3) |
| 43 | test.same(#(store.get("sites") or {}), 0, "none by the Green") |
| 44 | local site, crate = find_diggings(p) |
| 45 | test.check(site ~= nil, "a diggings opened somewhere on the island") |
| 46 | local s = site :: any |
| 47 | test.check(s.built, "and it's all dug") |
| 48 | -- the mouth is a frame of logs, with the way in clear |
| 49 | local f = ({ vector.create(1, 0, 0), vector.create(0, 0, 1), vector.create(-1, 0, 0), vector.create(0, 0, -1) })[s.dir] |
| 50 | local r = vector.create(-f.z, 0, f.x) |
| 51 | test.same(world.block(s.at + r * 2 + vector.create(0, 1, 0)), "Oak log", "a post at the mouth") |
| 52 | test.same(world.block(s.at + f * 6 + vector.create(0, 2, 0)), "Air", "the gallery's dug") |
| 53 | local crates = store.get("crates") :: { [string]: string } |
| 54 | local rooms: { [string]: number } = {} |
| 55 | for _, room in crates do |
| 56 | rooms[room] = (rooms[room] or 0) + 1 |
| 57 | end |
| 58 | test.same(rooms.store, 3, "three crates in the store room") |
| 59 | test.same(rooms.forge, 2, "two in the forge") |
| 60 | test.same(rooms.deep, 1, "one at the end of the drift") |
| 61 | -- opening one |
| 62 | test.check(crate ~= nil, "a crate") |
| 63 | local at = crate :: vector |
| 64 | test.same(world.block(at), "Gnome crate") |
| 65 | test.move(p, at + vector.create(1, 0, 0)) |
| 66 | test.use_block(p, at) |
| 67 | local got = 0 |
| 68 | for _, n in world.pockets(p) or {} do |
| 69 | got += n |
| 70 | end |
| 71 | test.check(got > 0, "something in their pockets") |
| 72 | test.check(string.find(test.shown(p, "diggings") or "", "You found", 1, true) ~= nil, test.shown(p, "diggings") or "") |
| 73 | test.same(world.block(at), "Air", "the crate's opened") |
| 74 | test.same((store.get("crates") :: { [string]: string })[string.format("%d,%d,%d", at.x, at.y, at.z)], nil, "and it's gone from the list") |
| 75 | -- no more diggings near this one |
| 76 | test.wait(6) |
| 77 | test.same(#(store.get("sites") :: { any }), 1, "only one") |
| 78 | end) |
| 79 | |
| 80 | test.case("a burnt-out lantern lights again with a piece of coal", function() |
| 81 | local p = test.player("Ada", { survival = true, carrying = { Coal = 1 } }) |
| 82 | local at = p.position + vector.create(2, 1, 0) |
| 83 | world.set_block(at, "Burnt-out lantern") |
| 84 | test.use_block(p, at) |
| 85 | test.same(world.block(at), "Lantern", "lit") |
| 86 | test.same(world.has(p, "Coal"), 0, "the coal's used") |
| 87 | local again = p.position + vector.create(-2, 1, 0) |
| 88 | world.set_block(again, "Burnt-out lantern") |
| 89 | test.use_block(p, again) |
| 90 | test.same(world.block(again), "Burnt-out lantern", "no coal, no light") |
| 91 | test.check(string.find(test.shown(p, "diggings") or "", "coal", 1, true) ~= nil, "says what it wants") |
| 92 | end) |
| 93 | |
| 94 | test.case("a torn map leads to a crate buried out on the land", function() |
| 95 | local p = test.player("Ada", { survival = true, carrying = { ["Torn map"] = 1 } }) |
| 96 | test.hold(p, "Torn map") |
| 97 | test.use_item(p) |
| 98 | local says = test.shown(p, "diggings") or "" |
| 99 | test.check(string.find(says, "The map shows a cross about", 1, true) ~= nil, says) |
| 100 | local cross = (store.get("crosses") :: { [string]: vector })["Ada"] |
| 101 | test.check(cross ~= nil, "a cross") |
| 102 | -- read again, it's the same cross |
| 103 | test.use_item(p) |
| 104 | test.same((store.get("crosses") :: { [string]: vector })["Ada"], cross) |
| 105 | -- walk there (a dry spot near it, off the Green) |
| 106 | local at = on_ground(cross.x, cross.z) |
| 107 | test.move(p, at) |
| 108 | test.wait(1.5) |
| 109 | local here = test.shown(p, "diggings") or "" |
| 110 | if string.find(here, "water", 1, true) then |
| 111 | -- the cross fell in the sea: the map's used up all the same |
| 112 | test.same(world.has(p, "Torn map"), 0) |
| 113 | return |
| 114 | end |
| 115 | test.check(string.find(here, "Dig down", 1, true) ~= nil, here) |
| 116 | test.same(world.has(p, "Torn map"), 0, "the map's done its work") |
| 117 | local x, z = math.floor(at.x), math.floor(at.z) |
| 118 | local found = false |
| 119 | for y = at.y - 1, at.y - 6, -1 do |
| 120 | if world.block(vector.create(x, y, z)) == "Gnome crate" then |
| 121 | found = true |
| 122 | end |
| 123 | end |
| 124 | test.check(found, "a crate under their feet") |
| 125 | end) |
| 126 | |
| 127 | test.case("the brass compass points to the nearest diggings", function() |
| 128 | local p = test.player("Ada", { survival = true, carrying = { ["Brass compass"] = 1 } }) |
| 129 | test.hold(p, "Brass compass") |
| 130 | test.use_item(p) |
| 131 | test.check(string.find(test.shown(p, "diggings") or "", "spins", 1, true) ~= nil, "none yet") |
| 132 | end) |
| 133 | |
| 134 | test.case("the diggers' pick digs stone as a copper pickaxe does", function() |
| 135 | local pick = world.item("Gnome's pick") |
| 136 | test.check(pick ~= nil, "the pick is an item") |
| 137 | local it = pick :: any |
| 138 | test.same(it.kind, "tool") |
| 139 | test.same(it.digs.level, 3) |
| 140 | test.same(it.stack, 1) |
| 141 | test.same(it.by, "diggings") |
| 142 | end) |
| 143 | |
| 144 | test.case("the compass, the teapot and the carved gnome are relics", function() |
| 145 | for _, name in { "Brass compass", "Gnome's teapot", "Carved gnome" } do |
| 146 | local it = world.item(name) :: any |
| 147 | test.check(it ~= nil and type(it.relic) == "string", name .. " has a story") |
| 148 | end |
| 149 | end) |