Sign in
creature

Hot air balloon

by Potluck · version 1 · Checked for all ages

Put a balloon basket down and it fills up. Climb in, hold Burner to rise and let go to sink slowly, and steer as you walk. It climbs and turns gently and never tips. Bop it once it's landed to pack it back into a basket. Make the basket at a workbench.

1--!strict
2-- The balloon's own tests. Each case plays in a world of its own, with only
3-- this creation in it; nothing here reaches the world anyone plays in. Run
4-- them with the dev bridge's test tool, or `potluck-server --test=balloon`.
5
6local test = require("@potluck/test@0.3")
7local world = require("@potluck/world@0.9")
8
9local BASKET = "Balloon basket"
10
11-- a player on the Green, and the open ground three blocks east of them
12local function setup(opts: any?)
13 local p = test.player("Ada", opts)
14 local x, z = p.position.x + 3, p.position.z
15 local at = vector.create(x, world.top(x, z) + 1, z)
16 return p, at
17end
18
19local function only(kind: string): any
20 local ids = world.creatures(test.kind(kind))
21 test.same(#ids, 1, "how many of " .. kind)
22 return test.creature(ids[1])
23end
24
25-- put a basket down and wait for it to fill
26local function filled(p, at)
27 test.place(p, at, BASKET)
28 test.wait(4)
29 return only("Hot air balloon")
30end
31
32test.case("a basket put down fills up into a balloon", function()
33 local p, at = setup()
34 test.place(p, at, BASKET)
35 test.same(world.block(at), "Air", "where the basket went")
36 only("Balloon (empty)")
37 test.wait(2)
38 only("Balloon (filling)")
39 test.check(test.heard("burner") > 0, "the burner roars as it fills")
40 test.wait(2)
41 only("Hot air balloon")
42end)
43
44test.case("the burner lifts it and Vent brings it back down", function()
45 local p, at = setup()
46 local b = filled(p, at)
47 local ground = b.position.y
48 test.ride(p, b)
49 test.check(test.shown(p, "aboard") ~= nil, "riders are told how to fly it")
50 test.press(p, "burner")
51 test.same(only("Hot air balloon (burner on)").id, b.id, "the burner's lit")
52 local roars = test.heard("burner")
53 test.wait(4)
54 test.check(test.heard("burner") >= roars + 4, "it roars while it's lit")
55 test.release(p, "burner")
56 local high = test.creature(b.id).position.y
57 test.check(high > ground + 2, string.format("it rose from %.1f to only %.1f", ground, high))
58 test.press(p, "vent")
59 for _ = 1, 30 do
60 test.wait(1)
61 if test.creature(b.id).position.y < ground + 0.2 then
62 break
63 end
64 end
65 test.check(test.creature(b.id).position.y < ground + 0.2, "it came back down")
66end)
67
68test.case("a landed balloon packs back into a basket", function()
69 local p, at = setup({ survival = true, carrying = { [BASKET] = 1 } })
70 local b = filled(p, at)
71 test.same(world.pockets(p)[BASKET], nil, "baskets carried once it's down")
72 test.hit(p, b)
73 test.same(#world.creatures(test.kind("Hot air balloon")), 0, "balloons left")
74 test.same(world.pockets(p)[BASKET], 1, "baskets carried once it's packed")
75end)
76
77test.case("nobody packs it up while someone's aboard", function()
78 local p, at = setup()
79 local friend = test.player("Bo")
80 local b = filled(p, at)
81 test.ride(p, b)
82 test.hit(friend, b)
83 only("Hot air balloon")
84end)
85
86test.case("a rider's client half is told when they're aboard", function()
87 local p, at = setup()
88 local b = filled(p, at)
89 test.same(test.sent(p, "aboard"), nil, "told before they climb in")
90 test.ride(p, b)
91 test.wait(0.2)
92 test.same(test.sent(p, "aboard"), true, "told once they're in")
93 local _, times = test.sent(p, "aboard")
94 test.same(times, 1, "times told while they ride")
95 test.from_half(p, "hello")
96 local again, more = test.sent(p, "aboard")
97 test.same(again, true, "what the half's told when it asks")
98 test.same(more, 2, "times told after it asks")
99 test.get_off(p)
100 test.wait(0.2)
101 test.same(test.sent(p, "aboard"), false, "told once they're out")
102end)