The sea keeps what it takes. Out over deep water, shipwrecks lie broken on the bottom and sunken ruins stand in the dark, each with a sunken chest of pearls, metal and old things for the Curator. A pirate map from a chest leads to treasure buried on the land: use it for the way, and dig where you're standing when you get there.
| 1 | --!strict |
| 2 | -- Sea wrecks' own tests: `potluck-server --test=sea-wrecks`. |
| 3 | local test = require("@potluck/test@0.9") |
| 4 | local world = require("@potluck/world@0.34") |
| 5 | local store = require("@potluck/store") |
| 6 | |
| 7 | -- a stone basin of water high in the sky, away from the Green: the middle |
| 8 | -- of its floor |
| 9 | local function pool(depth: number): vector |
| 10 | local g = world.spot("green") |
| 11 | local cx, cz, y = math.floor(g.x) + 80, math.floor(g.z), 90 |
| 12 | for dx = -14, 14 do |
| 13 | for dz = -14, 14 do |
| 14 | local edge = math.abs(dx) == 14 or math.abs(dz) == 14 |
| 15 | world.set_block(vector.create(cx + dx, y, cz + dz), "Stone") |
| 16 | for dy = 1, depth do |
| 17 | world.set_block(vector.create(cx + dx, y + dy, cz + dz), if edge then "Stone" else "Water") |
| 18 | end |
| 19 | end |
| 20 | test.wait(0) |
| 21 | end |
| 22 | return vector.create(cx, y, cz) |
| 23 | end |
| 24 | |
| 25 | local function find_chest(c: vector): vector? |
| 26 | for dx = -9, 9 do |
| 27 | for dz = -9, 9 do |
| 28 | for dy = 1, 5 do |
| 29 | local at = c + vector.create(dx, dy, dz) |
| 30 | if world.block(at) == "Sunken chest" then |
| 31 | return at |
| 32 | end |
| 33 | end |
| 34 | end |
| 35 | end |
| 36 | return nil |
| 37 | end |
| 38 | |
| 39 | local function build(kind: string): (vector, vector) |
| 40 | local c = pool(9) |
| 41 | store.set("plan", { kind = kind, at = c + vector.create(-3, 0, 0) }) |
| 42 | test.wait(8) |
| 43 | local chest = find_chest(c) |
| 44 | test.check(chest ~= nil, "a sunken chest is in the " .. kind) |
| 45 | return c, chest :: vector |
| 46 | end |
| 47 | |
| 48 | test.case("a shipwreck is built on the sea floor with a chest in it", function() |
| 49 | local c, chest = build("wreck") |
| 50 | local planks = 0 |
| 51 | for dx = -9, 9 do |
| 52 | for dz = -9, 9 do |
| 53 | local b = world.block(c + vector.create(dx, 1, dz)) |
| 54 | if string.find(b, "lanks") then |
| 55 | planks += 1 |
| 56 | end |
| 57 | end |
| 58 | end |
| 59 | test.check(planks >= 12, "a hull of planks: " .. planks) |
| 60 | test.check(world.block(chest + vector.create(0, 6, 0)) == "Water", "under the water") |
| 61 | end) |
| 62 | |
| 63 | test.case("a sunken ruin has columns, coral and a chest", function() |
| 64 | local c, chest = build("ruin") |
| 65 | local columns = 0 |
| 66 | for dx = -7, 5 do |
| 67 | for dz = -4, 4 do |
| 68 | if world.block(c + vector.create(dx, 2, dz)) == "Column" then |
| 69 | columns += 1 |
| 70 | end |
| 71 | end |
| 72 | end |
| 73 | test.check(columns >= 2, "columns stand: " .. columns) |
| 74 | end) |
| 75 | |
| 76 | test.case("a survival player opens a chest once for its prizes", function() |
| 77 | local p = test.player("Ada", { survival = true }) |
| 78 | local c, chest = build("wreck") |
| 79 | test.move(p, chest + vector.create(0, 4, 2)) |
| 80 | test.use_block(p, chest) |
| 81 | test.wait(0.5) |
| 82 | local n = 0 |
| 83 | for _, count in world.pockets(p) or {} do |
| 84 | n += count |
| 85 | end |
| 86 | test.check(n >= 1, "found something") |
| 87 | test.check(world.block(chest) ~= "Sunken chest", "and the chest is open") |
| 88 | end) |
| 89 | |
| 90 | test.case("a pirate map points at land, and the cross buries a chest", function() |
| 91 | local p = test.player("Ada", { survival = true, carrying = { ["Pirate map"] = 1 } }) |
| 92 | test.hold(p, "Pirate map") |
| 93 | test.use_item(p) |
| 94 | test.wait(0.3) |
| 95 | local crosses = store.get("crosses") |
| 96 | test.check(crosses ~= nil and crosses["Ada"] ~= nil, "a cross was marked") |
| 97 | local cross = crosses["Ada"] |
| 98 | test.move(p, vector.create(cross.x, world.top(cross.x, cross.z) + 2, cross.z)) |
| 99 | test.wait(3) |
| 100 | test.same(world.has(p, "Pirate map"), 0, "the map's used up") |
| 101 | local y = world.top(cross.x, cross.z) |
| 102 | test.same(world.block(vector.create(cross.x, y - 2, cross.z)), "Sunken chest", "buried under their feet") |
| 103 | end) |