Sign in
creature

Hens

by Potluck · version 1 · Checked for all ages

Hens peck about the Green and lay eggs on the grass now and then: pick them up, cook them, or bake them into pies and cakes. Pat one for a feather now and then. Hold seeds and they come to you; feed two of them seeds and they make a chick, which grows into a hen.

1--!strict
2local test = require("@potluck/test@0.6")
3local world = require("@potluck/world@0.20")
4local store = require("@potluck/store")
5
6local function hens(): { number }
7 return world.creatures(test.kind("Hen"))
8end
9
10local function chicks(): { number }
11 return world.creatures(test.kind("Chick"))
12end
13
14test.case("hens peck about the Green and lay eggs", function()
15 test.wait(1)
16 test.same(#hens(), 4, "hens")
17 test.wait(250)
18 local eggs = 0
19 for _, id in hens() do
20 local h = test.creature(id)
21 if h and world.find_block(h.position, 16, "Egg") then
22 eggs += 1
23 end
24 end
25 test.check(eggs > 0, "an egg lies near a hen")
26 local laid = store.get("eggs") or {}
27 test.check(#laid > 0, "the eggs are kept")
28end)
29
30test.case("a pat gives a feather in survival, but not straight away again", function()
31 local p = test.player("Ada", { survival = true })
32 test.wait(1)
33 local h = test.creature(hens()[1])
34 test.use(p, h)
35 test.same(world.has(p, "Feather"), 1, "a feather")
36 test.use(p, h)
37 test.same(world.has(p, "Feather"), 1, "no second feather yet")
38end)
39
40test.case("two hens fed seeds make a chick, which grows up into a hen", function()
41 local p = test.player("Ada", { survival = true, carrying = { Seeds = 6 } })
42 test.wait(1)
43 test.hold(p, "Seeds")
44 local ids = hens()
45 local a, b = test.creature(ids[1]), test.creature(ids[2])
46 test.use(p, a)
47 test.use(p, b)
48 test.same(world.has(p, "Seeds"), 4, "each ate one")
49 test.wait(25)
50 test.same(#chicks(), 1, "a chick")
51 -- both rest a while before another
52 test.use(p, a)
53 test.same(world.has(p, "Seeds"), 4, "a hen that's just made a chick doesn't eat")
54 test.wait(16)
55 local kept = store.get("flock") or {}
56 test.same(#kept, 1, "the chick is kept with the world")
57 -- feeding the chick brings it on a minute
58 local c = test.creature(chicks()[1])
59 local before = c.grow
60 test.use(p, c)
61 test.check(c.grow < before - 50, "fed, it grows faster")
62 test.wait(260)
63 test.same(#chicks(), 0, "no chick now")
64 test.same(#hens(), 5, "it's a hen")
65end)
66
67test.case("a hen not fed doesn't make a chick", function()
68 test.wait(60)
69 test.same(#chicks(), 0, "no chicks")
70end)