Sign in
creature

Glimmerflies

by Potluck · version 1 · Checked for all ages

A glimmer cocoon turns up now and then in a gloom nest or a crystal bud. Hold it and Interact looking at the sky, and a glimmerfly comes out: a little moth that glows, follows you around and lights the dark around you, so gloomlings keep away. Use it to have it stay and light a spot, or follow again.

1--!strict
2-- Glimmerflies' own tests: `potluck-server --test=glimmerfly`.
3
4local test = require("@potluck/test@0.8")
5local world = require("@potluck/world@0.27")
6
7local SKY = vector.create(0, 1, 0)
8
9-- a player well away from the Green's lanterns, with a cocoon in hand
10local function out_with_cocoon(name: string, n: number?)
11 local x, z = 200, 200
12 local p = test.player(name, { at = vector.create(x, world.top(x, z) + 1, z), survival = true, carrying = { ["Glimmer cocoon"] = n or 1 } })
13 test.hold(p, "Glimmer cocoon")
14 return p
15end
16
17local function flies()
18 return world.creatures(test.kind("Glimmerfly"))
19end
20
21test.case("a cocoon used in hand hatches a glimmerfly", function()
22 local p = out_with_cocoon("Ada")
23 test.use_item(p, SKY)
24 test.wait(0.3)
25 test.same(#flies(), 1, "one glimmerfly")
26 test.same(world.has(p, "Glimmer cocoon"), 0, "the cocoon's used")
27 test.same(test.shown(p, "glimmer"), "A glimmerfly comes out of the cocoon to light your way.")
28 test.same(test.creature(flies()[1]).owner, "Ada", "it's hers")
29end)
30
31test.case("it lights the dark around it", function()
32 local p = out_with_cocoon("Ada")
33 test.use_item(p, SKY)
34 test.wait(1)
35 local fly = test.creature(flies()[1])
36 local light = world.find_light(fly.position, 4)
37 test.check(light ~= nil, "a light is found")
38 test.check(vector.magnitude((light :: vector) - fly.position) < 1, "and it's the glimmerfly's")
39 test.same(world.find_light(fly.position + vector.create(9, 0, 0), 4), nil, "not far off")
40end)
41
42test.case("it follows its player, a little over their head", function()
43 local p = out_with_cocoon("Ada")
44 test.use_item(p, SKY)
45 test.wait(1)
46 local to = p.position + vector.create(8, 0, 0)
47 to = vector.create(to.x, world.top(to.x, to.z) + 1, to.z)
48 test.move(p, to)
49 test.wait(6)
50 local fly = test.creature(flies()[1])
51 local off = fly.position - p.position
52 test.check(vector.magnitude(vector.create(off.x, 0, off.z)) < 2.5, "it came along")
53 test.check(off.y > 0.8 and off.y < 3, "over their head")
54end)
55
56test.case("left far behind, it finds its player again", function()
57 local p = out_with_cocoon("Ada")
58 test.use_item(p, SKY)
59 test.wait(0.5)
60 local to = p.position + vector.create(0, 0, 60)
61 to = vector.create(to.x, world.top(to.x, to.z) + 1, to.z)
62 test.move(p, to)
63 test.wait(0.5)
64 local all = flies()
65 test.same(#all, 1, "still one")
66 test.check(vector.magnitude(test.creature(all[1]).position - p.position) < 4, "by them again")
67end)
68
69test.case("used, it stays and lights the spot; used again, it follows", function()
70 local p = out_with_cocoon("Ada")
71 test.use_item(p, SKY)
72 test.wait(1)
73 local fly = test.creature(flies()[1])
74 test.use(p, fly)
75 test.same(test.shown(p, "glimmer"), "Your glimmerfly stays here. Use it again to bring it.")
76 local spot = fly.position
77 local to = p.position + vector.create(10, 0, 0)
78 to = vector.create(to.x, world.top(to.x, to.z) + 1, to.z)
79 test.move(p, to)
80 test.wait(4)
81 test.check(vector.magnitude(fly.position - spot) < 1, "it stayed")
82 test.use(p, fly)
83 test.same(test.shown(p, "glimmer"), "Your glimmerfly follows you again.")
84 test.wait(6)
85 local off = fly.position - p.position
86 test.check(vector.magnitude(vector.create(off.x, 0, off.z)) < 2.5, "and came to them")
87end)
88
89test.case("one each: a second cocoon waits", function()
90 local p = out_with_cocoon("Ada", 2)
91 test.use_item(p, SKY)
92 test.wait(0.3)
93 test.use_item(p, SKY)
94 test.wait(0.3)
95 test.same(#flies(), 1, "one glimmerfly")
96 test.same(world.has(p, "Glimmer cocoon"), 1, "the second is kept")
97 test.same(test.shown(p, "glimmer"), "Your glimmerfly is with you already.")
98end)
99
100test.case("someone else's glimmerfly says whose it is", function()
101 local p = out_with_cocoon("Ada")
102 test.use_item(p, SKY)
103 test.wait(1)
104 local q = test.player("Bo", { at = p.position + vector.create(1, 0, 0) })
105 local fly = test.creature(flies()[1])
106 test.use(q, fly)
107 test.same(test.shown(q, "glimmer"), "Ada's glimmerfly.")
108 test.same(fly.owner, "Ada", "still hers")
109end)