Two gardeners who keep the Green in flowers. Ask one and they'll tell you how things work around here.
| 1 | --!strict |
| 2 | -- Gnome Gardener: keeps the Green in flowers, a few at a time, and tells |
| 3 | -- anyone who asks how things work around here (a question with choices, |
| 4 | -- from @potluck/ui). Players in survival hear how to get by instead of how |
| 5 | -- to play together (world.pockets is nil in creative). |
| 6 | |
| 7 | local world = require("@potluck/world@0.3") |
| 8 | local tweak = require("@potluck/tweak") |
| 9 | local ui = require("@potluck/ui@0.1") |
| 10 | local sound = require("@potluck/sound@0.1") |
| 11 | |
| 12 | local knobs = tweak { |
| 13 | hat = { "#c0392b", label = "Hat color", order = 1 }, |
| 14 | coat = { "#2f6f8f", label = "Coat color", order = 2 }, |
| 15 | plant = { true, label = "Plants flowers", order = 3 }, |
| 16 | } |
| 17 | |
| 18 | local Gnome = world.creature { |
| 19 | name = "Gnome Gardener", |
| 20 | speed = 1.6, |
| 21 | count = 2, |
| 22 | home = "green", |
| 23 | body = { |
| 24 | { "boots", size = { 0.44, 0.16, 0.34 }, at = { 0, 0.08, -0.02 }, color = "#4a3424" }, |
| 25 | { "coat", size = { 0.5, 0.5, 0.4 }, at = { 0, 0.41, 0 }, color = knobs.coat }, |
| 26 | { "belt", size = { 0.52, 0.06, 0.42 }, at = { 0, 0.42, 0 }, color = "#2b1f16" }, |
| 27 | { "head", size = { 0.38, 0.34, 0.34 }, at = { 0, 0.83, -0.02 }, color = "#f0c9a6", head = true }, |
| 28 | { "beard", size = { 0.34, 0.28, 0.1 }, at = { 0, 0.68, -0.2 }, color = "#f4f1e8", head = true }, |
| 29 | { "nose", size = { 0.1, 0.1, 0.08 }, at = { 0, 0.82, -0.22 }, color = "#e8a888", head = true }, |
| 30 | { "hat", size = { 0.42, 0.18, 0.4 }, at = { 0, 1.07, 0 }, color = knobs.hat, head = true }, |
| 31 | { "hat_tip", size = { 0.24, 0.22, 0.24 }, at = { 0, 1.26, 0.04 }, color = knobs.hat, head = true }, |
| 32 | { "arm_left", size = { 0.12, 0.36, 0.14 }, at = { -0.31, 0.42, 0 }, color = knobs.coat, leg = true }, |
| 33 | { "arm_right", size = { 0.12, 0.36, 0.14 }, at = { 0.31, 0.42, 0 }, color = knobs.coat, leg = true }, |
| 34 | }, |
| 35 | } |
| 36 | |
| 37 | local FLOWERS = { "Red flower", "Blue flower", "White flower", "Violet flower" } |
| 38 | |
| 39 | -- what to ask about, and what a gardener says |
| 40 | local TOPICS = { |
| 41 | { |
| 42 | "Making things", |
| 43 | "Everything here is a creation someone made. Even me!\n\nLook inside anything to read how it works (L, or hold Y on a pad). Tweak turns its knobs, no code needed, and Remix gives you a copy of your own to change in any editor.", |
| 44 | }, |
| 45 | { |
| 46 | "Sharing", |
| 47 | "Share a creation from Look inside and you get a code. Your friends type it in Load a creation from a code.\n\nShare it to Everyone and it goes on the market, once a moderator has had a look.", |
| 48 | }, |
| 49 | { |
| 50 | "The arches", |
| 51 | "The four arches on the north side of the Green show what friends brought into this world, and what the market has: favorites of the jams, this week's jam and what's trending.\n\nWalk up to one and Interact to bring it in.", |
| 52 | }, |
| 53 | { |
| 54 | "Exploring", |
| 55 | "Far out from here lie three Old Greens, gone cold long ago: one by the shore, one in the woods and one up on the heights.\n\nTake a lantern and something from nearby to a hearth, and use it to light it again. Each gives you something back.", |
| 56 | }, |
| 57 | { |
| 58 | "Playing together", |
| 59 | "Host a world for friends from the title screen, or join theirs. Servers on the market are always on.\n\nRide a mossback if you dare, and try the Rodeo Ram by the paddock.", |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | -- for survival players, in place of the last |
| 64 | local GETTING_BY = { |
| 65 | "Getting by", |
| 66 | "Break blocks to gather them. Any table is a workbench: Interact on it to make planks, lights, tools, even a hot air balloon. Crates keep your things.\n\nInteract on grass to dig farmland, and plant wheat or carrots. Keep food with you, and a lantern by your door: Gloomlings can't bear light.", |
| 67 | } |
| 68 | |
| 69 | local function ask(gnome, player) |
| 70 | local topics = table.clone(TOPICS) |
| 71 | if world.pockets(player) ~= nil then |
| 72 | topics[#topics] = GETTING_BY |
| 73 | end |
| 74 | local choices = {} |
| 75 | for _, t in topics do |
| 76 | table.insert(choices, t[1]) |
| 77 | end |
| 78 | ui.ask(player, { title = "Gnome Gardener", text = "Hello! What would you like to know?", choices = choices }, function(who, choice) |
| 79 | local topic = choice and topics[choice] |
| 80 | if not topic then |
| 81 | gnome:say("Happy gardening!") |
| 82 | return |
| 83 | end |
| 84 | ui.ask(who, { title = topic[1], text = topic[2], choices = { "Something else", "Thanks!" } }, function(again, more) |
| 85 | if more == 1 then |
| 86 | ask(gnome, again) |
| 87 | else |
| 88 | gnome:say("Happy gardening!") |
| 89 | end |
| 90 | end) |
| 91 | end) |
| 92 | end |
| 93 | |
| 94 | function Gnome:spawned() |
| 95 | self.chore = world.random(5, 20) |
| 96 | end |
| 97 | |
| 98 | -- a flower on bare grass near the middle of the Green, if there's room |
| 99 | local function plant_near(center: vector): vector? |
| 100 | for _ = 1, 4 do |
| 101 | local x = math.floor(center.x + world.random(-10, 10)) |
| 102 | local z = math.floor(center.z + world.random(-10, 10)) |
| 103 | local y = world.top(x, z) |
| 104 | local ground = vector.create(x, y, z) |
| 105 | local above = vector.create(x, y + 1, z) |
| 106 | if world.block(ground) == "Grass" and world.block(above) == "Air" then |
| 107 | -- keep it a garden, not a meadow: one flower in each patch |
| 108 | local crowded = false |
| 109 | for _, f in FLOWERS do |
| 110 | if world.find_block(above, 3, f) then |
| 111 | crowded = true |
| 112 | break |
| 113 | end |
| 114 | end |
| 115 | if not crowded then |
| 116 | world.set_block(above, FLOWERS[math.floor(world.random(1, #FLOWERS + 1))]) |
| 117 | return above |
| 118 | end |
| 119 | end |
| 120 | end |
| 121 | return nil |
| 122 | end |
| 123 | |
| 124 | function Gnome:tick(dt: number) |
| 125 | self.chore -= dt |
| 126 | if self.chore <= 0 then |
| 127 | self.chore = world.random(30, 60) |
| 128 | if knobs.plant then |
| 129 | local spot = plant_near(world.spot("green") or self.position) |
| 130 | if spot then |
| 131 | self:walk_to(spot, 1.6) |
| 132 | self:say("There we are.") |
| 133 | sound.play("dig", { at = self, volume = 0.5 }) |
| 134 | return |
| 135 | end |
| 136 | end |
| 137 | end |
| 138 | local p = world.nearest_player(self.position, 5) |
| 139 | if p then |
| 140 | self:stop() |
| 141 | self:face(p.position) |
| 142 | else |
| 143 | self:wander() |
| 144 | end |
| 145 | end |
| 146 | |
| 147 | function Gnome:used(player) |
| 148 | self:face(player.position) |
| 149 | self:say("Hello there!") |
| 150 | sound.play("chime", { at = self, volume = 0.5 }) |
| 151 | ask(self, player) |
| 152 | end |
| 153 | |
| 154 | function Gnome:hit(player) |
| 155 | self:hop(0.6) |
| 156 | self:say("Mind the petunias!") |
| 157 | end |