Sign in
world

Rainbows and the lucky pot

by Potluck · version 1 · Checked for all ages

When the rain stops and the sun comes out, a rainbow may rise over the land for a few minutes. Follow it to its foot, and there's a lucky pot: an iron pot full of gold and shiny things. Every player can open it once for a handful of finds, beads, ingots, crystal, old coins and, now and then, a piece of rainbow glass for the Curator. The rainbow fades, and the pot sinks away soon after, so don't dawdle.

1--!strict
2-- Rainbows and the lucky pot's own tests: `potluck-server --test=rainbows`.
3
4local test = require("@potluck/test@0.9")
5local world = require("@potluck/world@0.35")
6local sky = require("@potluck/sky@0.2")
7local store = require("@potluck/store")
8
9-- Rain, then sun: tries a few times (the chance isn't certain) until a bow
10-- is kept. Says it.
11local function after_rain(): any
12 for _ = 1, 24 do
13 sky.set_weather("rain", { strength = 0.7, over = 0 })
14 test.wait(2)
15 sky.set_weather("clear", { over = 0 })
16 test.wait(2)
17 if store.get("bow") then
18 return store.get("bow")
19 end
20 end
21 return nil
22end
23
24local function pot_at(b: any): vector
25 return vector.create(b.at.x, b.at.y, b.at.z)
26end
27
28test.case("a rainbow comes out when the rain stops in the day, with a pot at its foot", function()
29 test.daytime(0.5)
30 local p = test.player("Ada", { survival = true })
31 local b = after_rain()
32 test.check(b ~= nil, "a rainbow came out")
33 local now = sky.rainbow()
34 test.check(now ~= nil, "the sky has it")
35 test.check((now :: any).strength > 0, "and it shows")
36 local at = pot_at(b)
37 test.same(world.block(at), "Lucky pot", "the pot stands at its foot")
38 local d = math.sqrt((at.x - p.position.x) ^ 2 + (at.z - p.position.z) ^ 2)
39 test.check(d >= 34 and d <= 58, "a walk away: " .. d)
40 test.check(string.find(test.shown(p, "rainbow") or "", "rainbow", 1, true) ~= nil, "players are told")
41end)
42
43test.case("none at night, and none when it was never raining", function()
44 test.daytime(0.0)
45 local p = test.player("Ada", { survival = true })
46 test.same(p.name, "Ada")
47 test.check(after_rain() == nil, "not at night")
48 test.daytime(0.5)
49 sky.set_weather("clear", { over = 0 })
50 test.wait(8)
51 test.same(sky.rainbow(), nil, "no rain, no rainbow")
52end)
53
54test.case("each survival player opens the pot once, and it gives finds", function()
55 test.daytime(0.5)
56 local ada = test.player("Ada", { survival = true })
57 local bo = test.player("Bo", { survival = true })
58 local b = after_rain()
59 test.check(b ~= nil, "a rainbow")
60 local at = pot_at(b)
61 test.move(ada, at + vector.create(1.5, 0, 0.5))
62 test.use_block(ada, at)
63 local got = 0
64 for _, n in world.pockets(ada) or {} do
65 got += n
66 end
67 test.check(got >= 3, "finds in their pockets: " .. got)
68 test.check(string.find(test.shown(ada, "rainbow") or "", "You found", 1, true) ~= nil, test.shown(ada, "rainbow") or "nothing said")
69 test.use_block(ada, at)
70 test.check(string.find(test.shown(ada, "rainbow") or "", "share", 1, true) ~= nil, "once only")
71 test.move(bo, at + vector.create(-1.5, 0, 0.5))
72 test.use_block(bo, at)
73 local theirs = 0
74 for _, n in world.pockets(bo) or {} do
75 theirs += n
76 end
77 test.check(theirs >= 3, "and Bo has their own: " .. theirs)
78 test.same(world.block(at), "Lucky pot", "the pot's still there for others")
79end)
80
81test.case("a creative player is told it's for survival", function()
82 test.daytime(0.5)
83 local p = test.player("Ada")
84 local b = after_rain()
85 test.check(b ~= nil, "a rainbow")
86 local at = pot_at(b)
87 test.move(p, at + vector.create(1.5, 0, 0.5))
88 test.use_block(p, at)
89 test.check(string.find(test.shown(p, "rainbow") or "", "survival", 1, true) ~= nil, test.shown(p, "rainbow") or "")
90end)
91
92test.case("the rainbow fades and the pot sinks away after", function()
93 test.daytime(0.5)
94 local p = test.player("Ada", { survival = true })
95 test.same(p.name, "Ada")
96 local b = after_rain()
97 test.check(b ~= nil, "a rainbow")
98 local at = pot_at(b)
99 test.wait(320)
100 test.same(sky.rainbow(), nil, "the bow's gone")
101 test.same(world.block(at), "Lucky pot", "the pot waits a while")
102 test.wait(130)
103 test.same(world.block(at), "Air", "then it's gone")
104 test.same(store.get("bow"), nil, "and forgotten")
105end)
106
107test.case("rainbow glass is a relic, with its story", function()
108 local it = world.item("Rainbow glass") :: any
109 test.check(it ~= nil and it.by == "rainbows", "an item of the rainbows'")
110 test.check(type(it.relic) == "string" and #it.relic > 20, "its story")
111end)