Six kinds of ruin wait out in the far lands, each in a land of its own: sun shrines on the Glare's salt, lamplighters' rests in the Gold, starwatches in the Gloaming, frozen cairns in the Long Night, vine shrines in the rainforest and bog huts in the swamps. Each keeps a ruin cache with what its people left: ore and ingots, starglass, food, a lamp, and a relic for the Curator.
| 1 | --!strict |
| 2 | -- Far Ruins' own tests: `potluck-server --test=far-ruins`. |
| 3 | local test = require("@potluck/test@0.9") |
| 4 | local world = require("@potluck/world@0.33") |
| 5 | |
| 6 | local function v(x: number, y: number, z: number): vector |
| 7 | return vector.create(x, y, z) |
| 8 | end |
| 9 | |
| 10 | local function pos(p): vector |
| 11 | for _, q in world.players() do |
| 12 | if q.id == p.id then |
| 13 | return q.position |
| 14 | end |
| 15 | end |
| 16 | error("no such player") |
| 17 | end |
| 18 | |
| 19 | -- find_block sees 16 round a point: look over a grid round the player |
| 20 | local function seek(at: vector, name: string): vector? |
| 21 | for dx = -48, 48, 24 do |
| 22 | for dz = -48, 48, 24 do |
| 23 | test.wait(0) |
| 24 | for dy = -16, 16, 16 do |
| 25 | local found = world.find_block(at + v(dx, dy, dz), 16, name) |
| 26 | if found then |
| 27 | return found |
| 28 | end |
| 29 | end |
| 30 | end |
| 31 | end |
| 32 | return nil |
| 33 | end |
| 34 | |
| 35 | -- dry ground in a land, scanning from a start |
| 36 | local function land(name: string, from: number, z0: number): vector |
| 37 | for x = from, from + 6000, 53 do |
| 38 | for z = z0, z0 + 900, 97 do |
| 39 | local at = v(x + 0.5, 0, z + 0.5) |
| 40 | local top = world.top(at.x, at.z) |
| 41 | if world.biome(at) == name and top > 22 and world.block(v(at.x, top, at.z)) ~= "Water" then |
| 42 | return v(at.x, top + 1.02, at.z) |
| 43 | end |
| 44 | end |
| 45 | end |
| 46 | error("no " .. name .. " found") |
| 47 | end |
| 48 | |
| 49 | local function ruin(p, name: string, from: number, z0: number): vector |
| 50 | test.move(p, land(name, from, z0)) |
| 51 | for _ = 1, 40 do |
| 52 | test.wait(1) |
| 53 | local cache = seek(pos(p), "Ruin cache") |
| 54 | if cache then |
| 55 | test.wait(3) |
| 56 | return cache |
| 57 | end |
| 58 | end |
| 59 | error("no ruin in " .. name) |
| 60 | end |
| 61 | |
| 62 | for _, spec in { |
| 63 | { "glare", 21000, 200, "Duskstone bricks" }, |
| 64 | { "gold", 24600, 200, "Duskwood planks" }, |
| 65 | { "gloaming", 25000, 200, "Duskstone bricks" }, |
| 66 | { "long_night", 26500, 200, "Snow bricks" }, |
| 67 | { "rainforest", 400, 400, "Mossy cobblestone" }, |
| 68 | { "swamp", 400, -400, "Cypress planks" }, |
| 69 | } do |
| 70 | test.case("a ruin comes up in the " .. spec[1] .. " and its cache gives a relic", function() |
| 71 | local p = test.player("Ada", { survival = true }) |
| 72 | local cache = ruin(p, spec[1], spec[2], spec[3]) |
| 73 | test.check(world.find_block(cache, 6, spec[4]) ~= nil, "built of " .. spec[4]) |
| 74 | test.move(p, cache + v(0, 0, 3)) |
| 75 | test.use_block(p, cache) |
| 76 | test.wait(1) |
| 77 | -- the walled ruins have a way in, two blocks high, in the wall |
| 78 | local door = ({ gold = 3, gloaming = 2, long_night = 1, swamp = 3 })[spec[1]] |
| 79 | if door then |
| 80 | for _, dy in { 0, 1 } do |
| 81 | test.same(world.block(cache + v(0, dy, door)), "Air", "the doorway is open at " .. dy) |
| 82 | end |
| 83 | end |
| 84 | test.same(world.block(cache), "Air", "the cache is used up") |
| 85 | local relics = 0 |
| 86 | for _, n in { "Salt idol", "Lamplighter's pin", "Star plate", "Frozen bell", "Vine idol", "Bog lantern" } do |
| 87 | relics += world.has(p, n) |
| 88 | end |
| 89 | test.same(relics, 1, "a relic") |
| 90 | end) |
| 91 | end |
| 92 | |
| 93 | test.case("no ruins for players not in survival", function() |
| 94 | local p = test.player("Ada") |
| 95 | test.move(p, land("glare", 21000, 200)) |
| 96 | test.wait(8) |
| 97 | test.check(seek(pos(p), "Ruin cache") == nil, "none") |
| 98 | end) |