Things that hang from the ceilings of deep caves on a thread, with a little glowing lure under them. They creep along the rock toward anyone in survival and drop on them from above to bite, then climb back up. Look up when you see a light where no light should be. Beat one and it leaves its lure, which a Moon bell takes, and sometimes silk. A torch, lantern or candle keeps them from dropping. None on a Peaceful world, and fewer on a Gentle one.
| 1 | --!strict |
| 2 | -- Danglers' own tests: `potluck-server --test=danglers`. |
| 3 | local test = require("@potluck/test@0.9") |
| 4 | local world = require("@potluck/world@0.25") |
| 5 | |
| 6 | local function danglers(): { number } |
| 7 | return world.creatures(test.kind("Dangler")) |
| 8 | end |
| 9 | |
| 10 | -- a cave dug out deep under where a player stands, a row at a time, with a |
| 11 | -- stone roof over it |
| 12 | local function cave(p): vector |
| 13 | local x, z, y = math.floor(p.position.x), math.floor(p.position.z), -60 |
| 14 | for dx = -12, 12 do |
| 15 | for dz = -12, 12 do |
| 16 | world.set_block(vector.create(x + dx, y - 1, z + dz), "Stone") |
| 17 | world.set_block(vector.create(x + dx, y + 4, z + dz), "Stone") |
| 18 | for dy = 0, 3 do |
| 19 | world.set_block(vector.create(x + dx, y + dy, z + dz), "Air") |
| 20 | end |
| 21 | end |
| 22 | test.wait(0) |
| 23 | end |
| 24 | return vector.create(x + 0.5, y, z + 0.5) |
| 25 | end |
| 26 | |
| 27 | test.case("deep down they hang from the rock, creep over and drop on you", function() |
| 28 | test.danger("normal") |
| 29 | local p = test.player("Ada", { survival = true }) |
| 30 | local at = cave(p) |
| 31 | test.move(p, at) |
| 32 | test.wait(12) |
| 33 | test.check(#danglers() >= 1, "danglers came") |
| 34 | local d = test.creature(danglers()[1]) |
| 35 | test.check(d.position.y > at.y + 1.5, "up on the ceiling") |
| 36 | test.wait(30) |
| 37 | test.check(test.health(p) < 20, "and one dropped and bit") |
| 38 | end) |
| 39 | |
| 40 | test.case("none on Peaceful, none by a lantern, and none near the top", function() |
| 41 | test.danger("peaceful") |
| 42 | local p = test.player("Ada", { survival = true }) |
| 43 | local at = cave(p) |
| 44 | test.move(p, at) |
| 45 | test.wait(10) |
| 46 | test.same(#danglers(), 0, "none on Peaceful") |
| 47 | test.danger("hard") |
| 48 | world.set_block(at + vector.create(1, 0, 0), "Lantern") |
| 49 | test.wait(10) |
| 50 | test.same(#danglers(), 0, "none by the lantern") |
| 51 | world.set_block(at + vector.create(1, 0, 0), "Air") |
| 52 | test.move(p, vector.create(at.x, world.top(at.x, at.z) + 1, at.z)) |
| 53 | test.wait(10) |
| 54 | test.same(#danglers(), 0, "none up top") |
| 55 | end) |
| 56 | |
| 57 | test.case("a bop brings one down, and beaten it leaves its lure", function() |
| 58 | test.danger("normal") |
| 59 | local p = test.player("Ada", { survival = true }) |
| 60 | local at = cave(p) |
| 61 | test.move(p, at) |
| 62 | local id = world.spawn(test.kind("Dangler"), at + vector.create(4, 2.7, 0)) |
| 63 | test.wait(0.5) |
| 64 | test.hit(p, test.creature(id)) |
| 65 | test.same(test.creature(id).state, "drop", "it comes down") |
| 66 | for _ = 1, 3 do |
| 67 | test.hit(p, test.creature(id)) |
| 68 | end |
| 69 | test.same(test.creature(id), nil, "beaten") |
| 70 | test.check(world.has(p, "Dangler lure") >= 1, "its lure") |
| 71 | test.same(world.xp(p), 5, "and some XP") |
| 72 | end) |