Sign in
creature

Woolly

by Potluck · version 1 · Checked for all ages

Sheep that graze the Green. Hold wheat and they come to you, pat one and it follows you around for a while, bop one and it's off. In survival, patting one shears it for wool (more with shears in hand), which grows back in a few minutes. Feed two of them wheat and they have a lamb, which grows into a woolly.

1--!strict
2-- The woolly's own tests. Each case plays in a world of its own, with only
3-- this creation in it. Run them with the dev bridge's test tool, or
4-- `potluck-server --test=woolly`.
5
6local test = require("@potluck/test@0.1")
7local world = require("@potluck/world@0.10")
8
9local function sheep(kind: string?): { any }
10 local all = {}
11 for _, id in world.creatures(if kind then test.kind(kind) else nil) do
12 table.insert(all, test.creature(id))
13 end
14 return all
15end
16
17local function far(a: vector, b: vector): number
18 return vector.magnitude(vector.create(a.x - b.x, 0, a.z - b.z))
19end
20
21test.case("a flock grazes the Green", function()
22 test.same(#sheep("Woolly"), 4, "woollies")
23 local p = test.player("Ada")
24 for _, s in sheep() do
25 test.check(far(s.position, p.position) < 20, "one wandered off to " .. tostring(s.position))
26 end
27end)
28
29test.case("used, one follows you around", function()
30 local p = test.player("Ada")
31 local s = sheep("Woolly")[1]
32 test.move(p, s.position)
33 test.use(p, s)
34 local x, z = s.position.x + 8, s.position.z
35 p = test.move(p, vector.create(x, world.top(x, z) + 1, z))
36 test.wait(6)
37 test.check(far(test.creature(s.id).position, p.position) < 3.5, "it kept up")
38end)
39
40test.case("holding wheat, they come to you, and wander off when you put it away", function()
41 local p = test.player("Ada")
42 local s = sheep("Woolly")[1]
43 local x, z = s.position.x + 7, s.position.z
44 test.move(p, vector.create(x, world.top(x, z) + 1, z))
45 test.wait(2)
46 test.check(far(test.creature(s.id).position, p.position) > 4, "it came before the wheat came out")
47 test.hold(p, "Wheat")
48 test.wait(6)
49 test.check(far(test.creature(s.id).position, p.position) < 3.5, "it came for the wheat")
50 test.hold(p, nil)
51 local here = test.creature(s.id).position
52 x, z = here.x + 10, here.z
53 test.move(p, vector.create(x, world.top(x, z) + 1, z))
54 test.wait(5)
55 test.check(far(test.creature(s.id).position, p.position) > 4, "it went after them with no wheat")
56end)
57
58test.case("hit, one runs off", function()
59 local p = test.player("Ada")
60 local s = sheep("Woolly")[1]
61 test.move(p, s.position + vector.create(1, 0, 0))
62 local before = far(s.position, p.position)
63 test.hit(p, s)
64 test.wait(2)
65 test.check(far(test.creature(s.id).position, p.position) > before + 4, "it got away")
66end)
67
68test.case("sheared in survival, its wool grows back and the flock stays the same", function()
69 local p = test.player("Ada", { survival = true })
70 local s = sheep("Woolly")[1]
71 test.use(p, s)
72 test.same(world.pockets(p)["Cream wool"], 1, "wool from shearing")
73 test.same(test.creature(s.id).kind, "Shorn woolly", "what it is now")
74 test.wait(1)
75 test.same(#sheep(), 4, "sheep, shorn or not, just after")
76 test.use(p, s)
77 test.same(world.pockets(p)["Cream wool"], 1, "a shorn one gives no more")
78 test.wait(181)
79 test.same(test.creature(s.id).kind, "Woolly", "what it is once it's grown back")
80 test.same(#sheep(), 4, "sheep once it's grown back")
81end)
82
83test.case("shears get more wool", function()
84 local p = test.player("Ada", { survival = true, carrying = { Shears = 1 } })
85 test.hold(p, "Shears")
86 local s = sheep("Woolly")[1]
87 test.use(p, s)
88 test.same(world.pockets(p)["Cream wool"], 3, "wool from shearing with shears")
89end)
90
91test.case("two woollies fed wheat have a lamb, which grows up into a woolly", function()
92 local p = test.player("Ada", { survival = true, carrying = { Wheat = 4 } })
93 test.wait(1)
94 test.hold(p, "Wheat")
95 local two = sheep("Woolly")
96 test.use(p, two[1])
97 test.use(p, two[2])
98 test.same(world.has(p, "Wheat"), 2, "each ate one")
99 test.same(world.has(p, "Cream wool"), 0, "feeding isn't shearing")
100 test.wait(25)
101 test.same(#sheep("Lamb"), 1, "a lamb")
102 test.wait(320)
103 test.same(#sheep("Lamb"), 0, "no lamb now")
104 test.same(#sheep("Woolly"), 5, "it's a woolly")
105end)