Caps, helmets, coats, leggings, boots and shields for survival, in wool, copper, iron and moonsilver. Hold a piece and use it on nothing (Interact looking at the sky or far off) to put it on; each keeps off part of every hurt, more the better it's made. Use an empty hand on nothing to take a piece off. Wool and leather keep winter nights' cold off. Make wool and copper ones and shields at a workbench, and iron and moonsilver ones at an anvil.
| 1 | --!strict |
| 2 | -- Armor's own tests: `potluck-server --test=armor`. |
| 3 | |
| 4 | local test = require("@potluck/test@0.9") |
| 5 | local world = require("@potluck/world@0.34") |
| 6 | local sky = require("@potluck/sky@0.1") |
| 7 | |
| 8 | test.case("using a piece on nothing puts it on, and it keeps off part of a hurt", function() |
| 9 | local p = test.player("Ada", { survival = true, carrying = { ["Iron coat"] = 1 } }) |
| 10 | world.hurt(p, 10) |
| 11 | test.wait(0.6) |
| 12 | test.same(test.health(p), 10, "the whole hurt, with nothing on") |
| 13 | world.heal(p, 10) |
| 14 | test.hold(p, "Iron coat") |
| 15 | test.use_item(p, vector.create(0, 1, 0)) |
| 16 | test.same(world.has(p, "Iron coat"), 0, "it's on, not in the pockets") |
| 17 | test.check(string.find(test.shown(p, "armor") or "", "put on the iron coat", 1, true) ~= nil, test.shown(p, "armor") or "") |
| 18 | test.wait(0.6) |
| 19 | world.hurt(p, 10) |
| 20 | test.wait(0.6) |
| 21 | -- six points keep off 21% |
| 22 | local h = test.health(p) |
| 23 | test.check(h > 11.5 and h < 12.5, "about 12 left, not " .. h) |
| 24 | end) |
| 25 | |
| 26 | test.case("a new piece swaps for the old one", function() |
| 27 | local p = test.player("Ada", { survival = true, carrying = { ["Wool cap"] = 1, ["Moonsilver helmet"] = 1 } }) |
| 28 | test.hold(p, "Wool cap") |
| 29 | test.use_item(p) |
| 30 | test.hold(p, "Moonsilver helmet") |
| 31 | test.use_item(p) |
| 32 | test.same(world.has(p, "Wool cap"), 1, "the cap's back in the pockets") |
| 33 | test.same(world.has(p, "Moonsilver helmet"), 0, "the helmet's on") |
| 34 | end) |
| 35 | |
| 36 | test.case("an empty hand on nothing takes a piece off", function() |
| 37 | local p = test.player("Ada", { survival = true, carrying = { Shield = 1, ["Copper boots"] = 1 } }) |
| 38 | test.hold(p, "Shield") |
| 39 | test.use_item(p) |
| 40 | test.hold(p, "Copper boots") |
| 41 | test.use_item(p) |
| 42 | test.hold(p, nil) |
| 43 | test.use_item(p) |
| 44 | local q = test.asked(p) |
| 45 | test.check(q ~= nil, "a question") |
| 46 | local choices = (q :: any).choices |
| 47 | test.same(choices[1], "Take off copper boots") |
| 48 | test.same(choices[2], "Take off shield") |
| 49 | test.answer(p, 1) |
| 50 | test.same(world.has(p, "Copper boots"), 1, "the boots are back") |
| 51 | test.same(world.has(p, "Shield"), 0, "the shield's still on") |
| 52 | end) |
| 53 | |
| 54 | test.case("only armor goes on", function() |
| 55 | local p = test.player("Ada", { survival = true, carrying = { ["Iron pickaxe"] = 1 } }) |
| 56 | test.hold(p, "Iron pickaxe") |
| 57 | test.use_item(p) |
| 58 | test.same(world.has(p, "Iron pickaxe"), 1, "still in hand") |
| 59 | end) |
| 60 | |
| 61 | -- a player out on a stone floor high in the sky, on a winter's night |
| 62 | local function out_on_a_winter_night(carrying: { [string]: number }): any |
| 63 | test.danger("normal") |
| 64 | sky.set_season("winter", 0.5) |
| 65 | test.daytime(0) |
| 66 | local mid = vector.create(300.5, 110, 300.5) |
| 67 | for dx = -2, 2 do |
| 68 | for dz = -2, 2 do |
| 69 | world.set_block(mid + vector.create(dx, 0, dz), "Stone") |
| 70 | end |
| 71 | end |
| 72 | local p = test.player("Ada", { survival = true, carrying = carrying }) |
| 73 | return test.move(p, mid + vector.create(0, 1, 0)) |
| 74 | end |
| 75 | |
| 76 | test.case("winter nights are cold out under the sky, but wool keeps them off", function() |
| 77 | local p = out_on_a_winter_night({ ["Wool cap"] = 1, ["Wool coat"] = 1 }) |
| 78 | local told = false |
| 79 | for _ = 1, 32 do |
| 80 | test.wait(0.5) |
| 81 | told = told or string.find(test.shown(p, "armor") or "", "cold", 1, true) ~= nil |
| 82 | end |
| 83 | local h = test.health(p) :: number |
| 84 | test.check(h < 20 and h >= 6, "the cold hurts, a little: " .. h) |
| 85 | test.check(told, "and they're told why") |
| 86 | test.hold(p, "Wool cap") |
| 87 | test.use_item(p) |
| 88 | test.hold(p, "Wool coat") |
| 89 | test.use_item(p) |
| 90 | test.wait(6) |
| 91 | h = test.health(p) :: number |
| 92 | test.wait(16) |
| 93 | test.same(test.health(p), h, "dressed in wool, it doesn't") |
| 94 | end) |
| 95 | |
| 96 | test.case("a light, a roof or the day keep the cold off too, and it never takes the last of your health", function() |
| 97 | local p = out_on_a_winter_night({}) |
| 98 | world.set_block(p.position + vector.create(2, 0, 0), "Lantern") |
| 99 | test.wait(16) |
| 100 | test.same(test.health(p), 20, "a lantern beside them") |
| 101 | world.set_block(p.position + vector.create(2, 0, 0), "Air") |
| 102 | world.set_block(p.position + vector.create(0, 3, 0), "Stone") |
| 103 | test.wait(16) |
| 104 | test.same(test.health(p), 20, "a roof over them") |
| 105 | world.set_block(p.position + vector.create(0, 3, 0), "Air") |
| 106 | test.daytime(0.5) |
| 107 | test.wait(16) |
| 108 | test.same(test.health(p), 20, "and by day") |
| 109 | test.daytime(0) |
| 110 | test.wait(120) |
| 111 | test.same(test.health(p), 6, "never below 6") |
| 112 | end) |
| 113 | |
| 114 | test.case("a Stout piece keeps more off", function() |
| 115 | local p = test.player("Ada", { survival = true, carrying = { ["Iron coat"] = 1 } }) |
| 116 | world.charm(p, "Iron coat", { "Stout" }) |
| 117 | test.hold(p, "Iron coat") |
| 118 | test.use_item(p, vector.create(0, 1, 0)) |
| 119 | test.wait(0.6) |
| 120 | world.hurt(p, 20) |
| 121 | test.wait(0.6) |
| 122 | -- seven points keep off 24.5%, not six's 21% |
| 123 | local h = test.health(p) |
| 124 | test.check(h > 4.6 and h < 5.2, "about 4.9 left, not " .. h) |
| 125 | end) |
| 126 | |
| 127 | |
| 128 | test.case("armor with a perk charm gives its perk while it's worn, and pieces add up", function() |
| 129 | local p = test.player("Hal", { survival = true, carrying = { ["Iron boots"] = 1, ["Wool boots"] = 1, ["Iron helmet"] = 1 } }) |
| 130 | world.charm(p, "Iron boots", { "Springy", "Fleet" }) |
| 131 | world.charm(p, "Wool boots", { "Springy" }) |
| 132 | world.charm(p, "Iron helmet", { "Owl-eyed", "Gilled", "Fortunate" }) |
| 133 | test.wait(1) |
| 134 | test.same(world.perk(p, "leap"), 0, "nothing worn, nothing given") |
| 135 | test.hold(p, "Iron boots") |
| 136 | test.use_item(p, vector.create(0, 1, 0)) |
| 137 | test.hold(p, "Iron helmet") |
| 138 | test.use_item(p, vector.create(0, 1, 0)) |
| 139 | test.wait(1) |
| 140 | test.same(world.perk(p, "leap"), 1, "springy boots") |
| 141 | test.same(world.perk(p, "stride"), 1, "fleet boots") |
| 142 | test.same(world.perk(p, "night_sight"), 1, "an owl-eyed helmet") |
| 143 | test.same(world.perk(p, "gills"), 1, "gills") |
| 144 | test.same(world.perk(p, "luck"), 1, "luck") |
| 145 | test.same(world.perk(p, "feather"), 0, "no slow fall") |
| 146 | -- take the boots off: the jump goes |
| 147 | test.hold(p, nil) |
| 148 | test.use_item(p) |
| 149 | test.wait(0.2) |
| 150 | local q = test.asked(p) :: any |
| 151 | test.check(q ~= nil, "what you wear") |
| 152 | for i, c in q.choices do |
| 153 | if string.find(c, "boots", 1, true) then |
| 154 | test.answer(p, i) |
| 155 | break |
| 156 | end |
| 157 | end |
| 158 | test.wait(1) |
| 159 | test.same(world.perk(p, "leap"), 0, "the boots are off") |
| 160 | test.same(world.perk(p, "night_sight"), 1, "the helmet's on") |
| 161 | end) |
| 162 | |
| 163 | test.case("a hearth cider's warmth keeps the cold off, as a roof would", function() |
| 164 | local p = out_on_a_winter_night({}) |
| 165 | world.perk(p, "warm", 1) |
| 166 | test.wait(20) |
| 167 | test.same(test.health(p), 20, "warm, so no cold") |
| 168 | end) |