Sign in
world

Gloom Hollow

by Potluck · version 1 · Checked for all ages

Where do Gloomlings go by day? Deep in the rock, wander far enough underground and you may find a hollow where they sleep, curled up on gloom moss around their nests of shiny things. Bring a light and they fade away; creep in without one and they wake and nip. Their nests hold gold, crystal, old coins and, now and then, a gloom pearl for the Curator.

1--!strict
2-- Gloom Hollow's own tests: `potluck-server --test=gloom-hollow`.
3
4local test = require("@potluck/test@0.8")
5local world = require("@potluck/world@0.26")
6local store = require("@potluck/store")
7
8local function sleepers(): { number }
9 return world.creatures(test.kind("Sleeping gloomling"))
10end
11
12-- Takes a player deep under the island, far from the Green, into a little
13-- room dug in the rock, and waits for a hollow to open near them and its
14-- gloomlings to settle in it. Says the hollow.
15local function down_deep(p): any
16 local g = world.spot("green") :: vector
17 local x, y, z = math.floor(g.x) + 110, -30, math.floor(g.z) + 20
18 for dx = -2, 2 do
19 for dz = -2, 2 do
20 for dy = 0, 2 do
21 world.set_block(vector.create(x + dx, y + dy, z + dz), "Air")
22 end
23 world.set_block(vector.create(x + dx, y - 1, z + dz), "Stone")
24 end
25 end
26 test.move(p, vector.create(x + 0.5, y, z + 0.5))
27 for _ = 1, 30 do
28 test.wait(1)
29 local hollows = store.get("hollows") :: { any }?
30 if hollows and hollows[1] and hollows[1].built and #sleepers() > 0 then
31 return hollows[1]
32 end
33 end
34 return nil
35end
36
37test.case("a hollow opens deep in the rock near a player, with moss, nests and sleepers", function()
38 local p = test.player("Ada")
39 local h = down_deep(p)
40 test.check(h ~= nil, "a hollow opened and its gloomlings came")
41 test.same(world.block(h.at), "Air", "it's dug")
42 test.same(world.block(h.at + vector.create(0, -3, 0)), "Gloom moss", "on a floor of moss")
43 local nests = 0
44 for k in (store.get("nests") or {}) :: { [string]: number } do
45 local a, b, c = string.match(k, "(-?%d+),(-?%d+),(-?%d+)")
46 test.same(world.block(vector.create(tonumber(a) :: number, tonumber(b) :: number, tonumber(c) :: number)), "Gloom nest")
47 nests += 1
48 end
49 test.check(nests >= 1, "nests in it")
50 test.same(#sleepers(), 4, "four asleep")
51 -- no more right next to it
52 test.wait(6)
53 test.same(#(store.get("hollows") :: { any }), 1, "only one")
54end)
55
56test.case("bring a light and the sleepers fade away", function()
57 local p = test.player("Ada", { survival = true, carrying = { Lantern = 1 } })
58 local h = down_deep(p)
59 test.check(h ~= nil, "a hollow")
60 test.hold(p, "Lantern")
61 -- in the middle, on the moss
62 test.move(p, vector.create(h.at.x + 0.5, h.at.y - 2, h.at.z + 0.5))
63 test.wait(2)
64 test.same(#sleepers(), 0, "they've gone")
65 test.same(#world.creatures(test.kind("Woken gloomling")), 0, "none woke")
66 test.same((store.get("hollows") :: { any })[1].sleeping, 0, "and they don't come back")
67 test.same(test.health(p), 20, "nobody nipped")
68end)
69
70test.case("creep in without one and they wake and nip", function()
71 test.danger("normal")
72 local p = test.player("Ada", { survival = true })
73 local h = down_deep(p)
74 test.check(h ~= nil, "a hollow")
75 local c = test.creature(sleepers()[1]) :: any
76 test.move(p, c.position + vector.create(1.2, 0, 0))
77 for _ = 1, 12 do
78 test.wait(0.25)
79 if (test.health(p) :: number) < 20 then
80 break
81 end
82 end
83 test.check((test.health(p) :: number) < 20, "nipped")
84 test.check(string.find(test.shown(p, "hollow") or "", "wakes", 1, true) ~= nil, test.shown(p, "hollow") or "nothing said")
85end)
86
87test.case("on a Peaceful world nobody wakes", function()
88 test.danger("peaceful")
89 local p = test.player("Ada", { survival = true })
90 local h = down_deep(p)
91 test.check(h ~= nil, "a hollow")
92 local c = test.creature(sleepers()[1]) :: any
93 test.move(p, c.position + vector.create(1.2, 0, 0))
94 test.wait(2)
95 test.same(test.health(p), 20, "not nipped")
96 test.same(#world.creatures(test.kind("Woken gloomling")), 0, "still asleep")
97end)
98
99test.case("a nest gives its shiny things once", function()
100 test.danger("peaceful")
101 local p = test.player("Ada", { survival = true })
102 local h = down_deep(p)
103 test.check(h ~= nil, "a hollow")
104 local at: vector? = nil
105 for k in (store.get("nests") or {}) :: { [string]: number } do
106 local a, b, c = string.match(k, "(-?%d+),(-?%d+),(-?%d+)")
107 at = vector.create(tonumber(a) :: number, tonumber(b) :: number, tonumber(c) :: number)
108 break
109 end
110 test.check(at ~= nil, "a nest")
111 local nest = at :: vector
112 test.move(p, nest + vector.create(1.5, 0, 0.5))
113 test.use_block(p, nest)
114 local got = 0
115 for _, n in world.pockets(p) or {} do
116 got += n
117 end
118 test.check(got > 0, "something in their pockets")
119 test.check(string.find(test.shown(p, "hollow") or "", "You found", 1, true) ~= nil, test.shown(p, "hollow") or "")
120 test.same(world.block(nest), "Air", "the nest's taken")
121 test.same((store.get("nests") :: { [string]: number })[string.format("%d,%d,%d", nest.x, nest.y, nest.z)], nil, "and gone from the list")
122end)
123
124test.case("the gloom pearl is a relic, with its story", function()
125 local it = world.item("Gloom pearl") :: any
126 test.check(it ~= nil and it.by == "gloom-hollow", "an item of the hollow's")
127 test.check(type(it.relic) == "string" and #it.relic > 20, "its story")
128end)