Long dark eels that hunt in deep water at night, and in the dark water of caves at any hour. Swim out there in survival and they come for you, snap and dart back, so climb out or fight. Bop one three times (a sword or a spear bops harder) and it leaves an eel to cook. None on a Peaceful world, and fewer on a Gentle one.
| 1 | --!strict |
| 2 | -- Snapjaw eels' own tests: `potluck-server --test=eels`. |
| 3 | local test = require("@potluck/test@0.9") |
| 4 | local world = require("@potluck/world@0.31") |
| 5 | |
| 6 | local UP = vector.create(0, 1, 0) |
| 7 | |
| 8 | local function pool(depth: number): vector |
| 9 | local g = world.spot("green") |
| 10 | local cx, cz, y = math.floor(g.x) + 80, math.floor(g.z), 90 |
| 11 | for dx = -16, 16 do |
| 12 | for dz = -16, 16 do |
| 13 | local edge = math.abs(dx) == 16 or math.abs(dz) == 16 |
| 14 | world.set_block(vector.create(cx + dx, y, cz + dz), "Stone") |
| 15 | for dy = 1, depth do |
| 16 | world.set_block(vector.create(cx + dx, y + dy, cz + dz), if edge then "Stone" else "Water") |
| 17 | end |
| 18 | end |
| 19 | test.wait(0) |
| 20 | end |
| 21 | return vector.create(cx + 0.5, y + 1, cz + 0.5) |
| 22 | end |
| 23 | |
| 24 | local function eels(): { number } |
| 25 | return world.creatures(test.kind("Snapjaw eel")) |
| 26 | end |
| 27 | |
| 28 | test.case("at night, eels come for a swimmer and snap", function() |
| 29 | test.danger("normal") |
| 30 | test.daytime(0) |
| 31 | local p = test.player("Ada", { survival = true }) |
| 32 | local floor = pool(6) |
| 33 | test.move(p, floor + UP * 2) |
| 34 | test.wait(12) |
| 35 | test.check(#eels() >= 1, "eels came") |
| 36 | test.wait(20) |
| 37 | test.check(test.health(p) < 20, "and one snapped") |
| 38 | for _, id in eels() do |
| 39 | test.same(world.block(test.creature(id).position + UP * 0.15), "Water", "in the water") |
| 40 | end |
| 41 | end) |
| 42 | |
| 43 | test.case("none by day up top, none on Peaceful, none for someone dry", function() |
| 44 | test.danger("normal") |
| 45 | test.daytime(0.5) |
| 46 | local p = test.player("Ada", { survival = true }) |
| 47 | local floor = pool(6) |
| 48 | test.move(p, floor + UP * 2) |
| 49 | test.wait(10) |
| 50 | test.same(#eels(), 0, "none by day") |
| 51 | test.daytime(0) |
| 52 | test.danger("peaceful") |
| 53 | test.wait(10) |
| 54 | test.same(#eels(), 0, "none on Peaceful") |
| 55 | test.danger("hard") |
| 56 | test.move(p, floor + vector.create(0, 8, 0)) |
| 57 | test.wait(10) |
| 58 | test.same(#eels(), 0, "none for someone out of the water") |
| 59 | end) |
| 60 | |
| 61 | test.case("three bops beat one, and it leaves an eel", function() |
| 62 | test.danger("normal") |
| 63 | test.daytime(0) |
| 64 | local p = test.player("Ada", { survival = true }) |
| 65 | local floor = pool(4) |
| 66 | test.move(p, floor + UP * 2) |
| 67 | local id = world.spawn(test.kind("Snapjaw eel"), floor + vector.create(2, 1, 0)) |
| 68 | test.wait(0.2) |
| 69 | for _ = 1, 3 do |
| 70 | test.hit(p, test.creature(id)) |
| 71 | end |
| 72 | test.same(test.creature(id), nil, "beaten") |
| 73 | test.same(world.has(p, "Eel"), 1, "an eel") |
| 74 | test.same(world.xp(p), 3, "and some XP") |
| 75 | end) |