Soft lights that bob over the marshes at night, just out of reach. Follow one and it drifts away, and when you catch up a mossy head with a mouthful of teeth rises under it and bites. Bop or shoot the light and it opens up in surprise; beat it and it leaves its fen glow, which a Moon bell takes. Being lights themselves, they keep other night creatures away. None on a Peaceful world, and fewer on a Gentle one.
| 1 | --!strict |
| 2 | -- Fenlures' own tests: `potluck-server --test=fenlures`. |
| 3 | local test = require("@potluck/test@0.9") |
| 4 | local world = require("@potluck/world@0.30") |
| 5 | |
| 6 | local function lures(): { number } |
| 7 | local out = {} |
| 8 | for _, k in { "Fenlure", "Fenlure (open)" } do |
| 9 | for _, id in world.creatures(test.kind(k)) do |
| 10 | table.insert(out, id) |
| 11 | end |
| 12 | end |
| 13 | return out |
| 14 | end |
| 15 | |
| 16 | local function find(lands: { [string]: boolean }): vector |
| 17 | local g = world.spot("green") |
| 18 | for r = 400, 4000, 150 do |
| 19 | for i = 0, 31 do |
| 20 | local a = i / 32 * 2 * math.pi |
| 21 | local at = vector.create(math.floor(g.x + math.cos(a) * r) + 0.5, 0, math.floor(g.z + math.sin(a) * r) + 0.5) |
| 22 | if lands[world.biome(at)] then |
| 23 | return at |
| 24 | end |
| 25 | end |
| 26 | end |
| 27 | error("no such land near the island") |
| 28 | end |
| 29 | |
| 30 | -- a player in survival on a patch of firm ground out in these lands |
| 31 | local function out_in(p, lands: { [string]: boolean }): vector |
| 32 | local at = find(lands) |
| 33 | test.move(p, vector.create(at.x, world.top(at.x, at.z) + 1, at.z)) |
| 34 | local y = world.top(at.x, at.z) |
| 35 | for dx = -6, 6 do |
| 36 | for dz = -6, 6 do |
| 37 | local c = vector.create(at.x + dx, y, at.z + dz) |
| 38 | world.set_block(c, "Grass") |
| 39 | for dy = 1, 3 do |
| 40 | world.set_block(c + vector.create(0, dy, 0), "Air") |
| 41 | end |
| 42 | end |
| 43 | end |
| 44 | local there = vector.create(at.x, y + 1.02, at.z) |
| 45 | test.move(p, there) |
| 46 | return there |
| 47 | end |
| 48 | |
| 49 | test.case("at night lights bob over the marsh, and one bites when you catch up", function() |
| 50 | test.danger("normal") |
| 51 | test.daytime(0) |
| 52 | local p = test.player("Ada", { survival = true }) |
| 53 | local at = out_in(p, { marsh = true }) |
| 54 | test.wait(14) |
| 55 | local ids = lures() |
| 56 | test.check(#ids >= 1, "fenlures came") |
| 57 | local l = test.creature(ids[1]) |
| 58 | test.move(p, vector.create(l.position.x + 1, at.y, l.position.z)) |
| 59 | test.wait(4) |
| 60 | test.check(test.health(p) < 20, "and one bit") |
| 61 | test.daytime(0.4) |
| 62 | test.wait(2) |
| 63 | test.same(#lures(), 0, "gone by day") |
| 64 | end) |
| 65 | |
| 66 | test.case("a bop opens one up, and beaten it leaves its glow", function() |
| 67 | test.danger("normal") |
| 68 | test.daytime(0) |
| 69 | local p = test.player("Ada", { survival = true, carrying = { ["Stone sword"] = 1 } }) |
| 70 | local at = out_in(p, { marsh = true }) |
| 71 | local id = world.spawn(test.kind("Fenlure"), at + vector.create(4, 1.2, 0)) |
| 72 | test.wait(0.2) |
| 73 | test.hit(p, test.creature(id)) |
| 74 | test.same(test.creature(id).kind, "Fenlure (open)", "it opens up") |
| 75 | test.hold(p, "Stone sword") |
| 76 | test.hit(p, test.creature(id)) |
| 77 | test.same(test.creature(id), nil, "beaten") |
| 78 | test.check(world.has(p, "Fen glow") >= 1, "its glow") |
| 79 | test.same(world.xp(p), 5, "and some XP") |
| 80 | end) |
| 81 | |
| 82 | test.case("none on Peaceful, and none away from the marsh", function() |
| 83 | test.danger("peaceful") |
| 84 | test.daytime(0) |
| 85 | local p = test.player("Ada", { survival = true }) |
| 86 | out_in(p, { marsh = true }) |
| 87 | test.wait(10) |
| 88 | test.same(#lures(), 0, "none on Peaceful") |
| 89 | test.danger("hard") |
| 90 | out_in(p, { desert = true }) |
| 91 | test.wait(10) |
| 92 | test.same(#lures(), 0, "none in the desert") |
| 93 | end) |