Sign in
creature

The Curator

by Potluck · version 1 · Checked for all ages

Hazel keeps the island's collection of relics on the Green. Bring her the old things you find, in the hills, in old chests and deep in the stone, and hear each one's story; the first of each joins the collection, and she gives you something good for it.

1--!strict
2-- The Curator's own tests: `potluck-server --test=curator`. In a test only
3-- this creation runs, so her own old coin is the relic to give (though
4-- items other creations made earlier in the same game are still about).
5
6local test = require("@potluck/test@0.8")
7local world = require("@potluck/world@0.26")
8local store = require("@potluck/store")
9
10-- how many relics there are in this world
11local function relics(): number
12 local n = 0
13 for _, name in world.items() do
14 local it = world.item(name)
15 if it and it.relic then
16 n += 1
17 end
18 end
19 return n
20end
21
22local function hazel(p): number
23 test.wait(1)
24 local id = world.creatures(test.kind("Curator"))[1]
25 test.check(id ~= nil, "Hazel is on the Green")
26 local c = test.creature(id) :: any
27 test.move(p, c.position + vector.create(1.5, 0, 0))
28 return id
29end
30
31test.case("the old coin is a relic, with its story", function()
32 local coin = world.item("Old coin") :: any
33 test.check(coin ~= nil, "an item")
34 test.same(coin.by, "curator")
35 test.check(type(coin.relic) == "string" and #coin.relic > 20, "its story")
36end)
37
38test.case("Hazel takes the first relic into the collection, tells its story and thanks you", function()
39 local p = test.player("Ada", { survival = true, carrying = { ["Old coin"] = 2 } })
40 local id = hazel(p)
41 test.use(p, id)
42 local q = test.asked(p) :: any
43 test.check(q ~= nil, "she asks")
44 test.same(q.choices[1], "Old coin", "which relic")
45 test.same(q.choices[#q.choices], "See the collection")
46 test.answer(p, 1)
47 test.wait(0.2)
48 test.same(world.has(p, "Old coin"), 1, "she took one")
49 test.same((store.get("collection") :: any)["Old coin"], "Ada", "it's in the collection, by who found it")
50 test.same(world.has(p, "Gold ingot"), 2, "the first relic's gift")
51 test.check(world.xp(p) >= 20, "and XP")
52 -- when it's the only relic, that's the collection whole as well
53 local whole = if relics() == 1 then 3 else 0
54 test.same(world.has(p, "Moonsilver ingot"), whole, "the whole collection's gift")
55 local story = test.asked(p) :: any
56 test.check(story ~= nil and string.find(story.text, "joins the collection", 1, true) ~= nil, "the relic's story")
57 test.answer(p, 1)
58 test.wait(0.2)
59 -- another is a spare
60 test.use(p, id)
61 test.answer(p, 1)
62 test.wait(0.2)
63 test.same(world.has(p, "Old coin"), 0, "the spare's taken")
64 test.same(world.has(p, "Gold ingot"), 3, "for a little gold")
65 test.same(world.has(p, "Moonsilver ingot"), whole, "and the collection's thanked for once")
66end)
67
68test.case("the collection says who found what", function()
69 local p = test.player("Ada", { survival = true, carrying = { ["Old coin"] = 1 } })
70 local id = hazel(p)
71 test.use(p, id)
72 test.answer(p, 1)
73 test.wait(0.2)
74 test.answer(p, 2)
75 test.wait(0.2)
76 local q = test.asked(p) :: any
77 test.check(q ~= nil and string.find(q.text, "Old coin (found by Ada)", 1, true) ~= nil, q and q.text or "no question")
78 test.check(string.find(q.text, "1 of " .. relics(), 1, true) ~= nil, "how many: " .. q.text)
79end)
80
81test.case("in creative she shows the collection and takes nothing", function()
82 local p = test.player("Ada", { carrying = { ["Old coin"] = 1 } })
83 local id = hazel(p)
84 test.use(p, id)
85 local q = test.asked(p) :: any
86 test.check(q ~= nil and #q.choices == 1, "only the collection")
87 test.answer(p, 1)
88 test.wait(0.2)
89 local c = test.asked(p) :: any
90 test.check(c ~= nil and string.find(c.text, "empty", 1, true) ~= nil, c and c.text or "no question")
91end)
92
93test.case("with nothing to give, she says where relics turn up", function()
94 local p = test.player("Ada", { survival = true })
95 local id = hazel(p)
96 test.use(p, id)
97 local q = test.asked(p) :: any
98 test.check(q ~= nil and string.find(q.text, "old chests", 1, true) ~= nil, q and q.text or "no question")
99end)