Woolly, long-necked and curious, humming to each other on the hill where everyone starts, in cream, fawn and brown. Hold wheat and they come to you. In survival, Interact with one to shear it for alpaca fleece (more with shears in hand), which grows back after a while. A workbench makes fleece into a warm hat and a poncho that keep the cold off at night. Bop one and it spits at you.
| 1 | --!strict |
| 2 | -- Alpacas: woolly, long-necked and curious, humming to each other on the |
| 3 | -- hill where everyone starts, in cream, fawn and brown. Hold wheat and |
| 4 | -- they come to you; Interact with one and it follows you a while (all |
| 5 | -- behaviors, no code). In survival, Interact shears it too: you get |
| 6 | -- alpaca fleece (more with shears in hand), and it's shorn (self:become) |
| 7 | -- until its fleece grows back. A workbench makes fleece into a warm hat |
| 8 | -- and poncho, which keep the cold off at night like wool. Bop one and it |
| 9 | -- spits at you, and stalks off. They give only fleece. |
| 10 | |
| 11 | local world = require("@potluck/world@0.25") |
| 12 | local tweak = require("@potluck/tweak") |
| 13 | local sound = require("@potluck/sound@0.2") |
| 14 | |
| 15 | local knobs = tweak { |
| 16 | herd = { 4, min = 1, max = 8, label = "How many", order = 1 }, |
| 17 | fleece = { 1, min = 1, max = 4, label = "Fleece from shearing one", order = 2 }, |
| 18 | shears = { 2, min = 0, max = 4, label = "More fleece with shears", order = 3 }, |
| 19 | regrow = { 4, min = 0.5, max = 20, label = "Minutes for its fleece to grow back", order = 4 }, |
| 20 | } |
| 21 | |
| 22 | local FOOD = "Wheat" |
| 23 | local FLEECE = "Alpaca fleece" |
| 24 | local EYE, PUPIL = "#f4f2e8", "#141414" |
| 25 | |
| 26 | -- one alpaca's body in a coat, fluffy or shorn |
| 27 | local function alpaca(coat: string, dark: string, fluffy: boolean): { any } |
| 28 | local f = if fluffy then 1 else 0.78 |
| 29 | local b: { any } = { |
| 30 | { "body", size = { 0.62 * f, 0.6 * f, 1.0 * f }, at = { 0, 0.92, 0.08 }, color = coat }, |
| 31 | { "neck", size = { 0.3 * f, 0.8, 0.3 * f }, at = { 0, 1.5, -0.34 }, color = coat, head = true }, |
| 32 | { "head", size = { 0.3, 0.3, 0.38 }, at = { 0, 1.98, -0.42 }, color = coat, head = true }, |
| 33 | { "muzzle", size = { 0.2, 0.16, 0.14 }, at = { 0, 1.9, -0.66 }, color = dark, head = true }, |
| 34 | { "ear_left", size = { 0.07, 0.2, 0.06 }, at = { -0.1, 2.22, -0.36 }, color = coat, head = true }, |
| 35 | { "ear_right", size = { 0.07, 0.2, 0.06 }, at = { 0.1, 2.22, -0.36 }, color = coat, head = true }, |
| 36 | { "tail", size = { 0.14, 0.18, 0.12 }, at = { 0, 1.04, 0.6 }, color = coat }, |
| 37 | } |
| 38 | if fluffy then |
| 39 | table.insert(b, { "topknot", size = { 0.26, 0.14, 0.24 }, at = { 0, 2.18, -0.4 }, color = coat, head = true }) |
| 40 | end |
| 41 | for _, s in { -1, 1 } do |
| 42 | local n = if s < 0 then "left" else "right" |
| 43 | table.insert(b, { "eye_" .. n, size = { 0.04, 0.09, 0.09 }, at = { s * 0.16, 2.02, -0.52 }, color = EYE, head = true }) |
| 44 | table.insert(b, { "pupil_" .. n, size = { 0.04, 0.065, 0.065 }, at = { s * 0.175, 2.015, -0.535 }, color = PUPIL, head = true }) |
| 45 | table.insert(b, { "leg_front_" .. n, size = { 0.14, 0.64, 0.14 }, at = { s * 0.18, 0.32, -0.3 }, color = if fluffy then coat else dark, leg = true }) |
| 46 | table.insert(b, { "leg_back_" .. n, size = { 0.14, 0.64, 0.14 }, at = { s * 0.18, 0.32, 0.42 }, color = if fluffy then coat else dark, leg = true }) |
| 47 | table.insert(b, { "foot_front_" .. n, size = { 0.16, 0.08, 0.18 }, at = { s * 0.18, 0.04, -0.32 }, color = dark, leg = true }) |
| 48 | table.insert(b, { "foot_back_" .. n, size = { 0.16, 0.08, 0.18 }, at = { s * 0.18, 0.04, 0.4 }, color = dark, leg = true }) |
| 49 | end |
| 50 | return b |
| 51 | end |
| 52 | |
| 53 | local ALPACA = { |
| 54 | follow_food = FOOD, |
| 55 | follow_when_used = 20, |
| 56 | flee_when_hit = 7, |
| 57 | chatter = { "Hmmmm.", "Mm-hmm?", "Hmmm-mm." }, |
| 58 | sound = "hum", |
| 59 | } |
| 60 | |
| 61 | type Coat = { name: string, coat: string, dark: string, share: number } |
| 62 | local COATS: { Coat } = { |
| 63 | { name = "Alpaca", coat = "#ece4d0", dark = "#6a5a48", share = 0.5 }, |
| 64 | { name = "Fawn alpaca", coat = "#c8a070", dark = "#5a4028", share = 0.25 }, |
| 65 | { name = "Brown alpaca", coat = "#6a4a30", dark = "#2e2018", share = 0.25 }, |
| 66 | } |
| 67 | |
| 68 | -- how many of each coat: shares of the herd, the cream ones first |
| 69 | local function counts(): { number } |
| 70 | local h = math.floor(knobs.herd) |
| 71 | local out, left = {}, h |
| 72 | for i, c in COATS do |
| 73 | local n = if i == #COATS then left else math.min(left, math.max(if i == 1 then 1 else 0, math.floor(h * c.share + 0.5))) |
| 74 | out[i] = n |
| 75 | left -= n |
| 76 | end |
| 77 | return out |
| 78 | end |
| 79 | |
| 80 | local fluffy_kinds, shorn_kinds = {}, {} |
| 81 | local shorn_of: { [string]: any } = {} |
| 82 | local fluffy_of: { [string]: any } = {} |
| 83 | do |
| 84 | local n = counts() |
| 85 | for i, c in COATS do |
| 86 | local fluffy = world.creature { |
| 87 | name = c.name, |
| 88 | speed = 1.8, |
| 89 | count = n[i], |
| 90 | home = "start", |
| 91 | behaviors = ALPACA, |
| 92 | body = alpaca(c.coat, c.dark, true), |
| 93 | } |
| 94 | local shorn = world.creature { |
| 95 | name = "Shorn " .. string.lower(c.name), |
| 96 | speed = 1.9, |
| 97 | count = 0, |
| 98 | home = "start", |
| 99 | behaviors = ALPACA, |
| 100 | body = alpaca(c.coat, c.dark, false), |
| 101 | } |
| 102 | fluffy_kinds[i], shorn_kinds[i] = fluffy, shorn |
| 103 | shorn_of[c.name] = shorn |
| 104 | fluffy_of[shorn.name] = fluffy |
| 105 | end |
| 106 | end |
| 107 | |
| 108 | local function used(self, player) |
| 109 | if world.held(player) == FOOD then |
| 110 | return -- it follows the wheat, and that's all |
| 111 | end |
| 112 | local shorn = shorn_of[self.kind] |
| 113 | if not shorn or world.pockets(player) == nil then |
| 114 | return |
| 115 | end |
| 116 | local n = math.floor(knobs.fleece) + (if world.held(player) == "Shears" then math.floor(knobs.shears) else 0) |
| 117 | if world.give(player, FLEECE, n) > 0 then |
| 118 | self:become(shorn) |
| 119 | self.regrow = knobs.regrow * 60 |
| 120 | sound.play("snip", { at = self }) |
| 121 | self:say("Hmm! Breezy.") |
| 122 | end |
| 123 | end |
| 124 | |
| 125 | local function tick(self, dt: number) |
| 126 | if self.regrow then |
| 127 | self.regrow -= dt |
| 128 | if self.regrow <= 0 then |
| 129 | self.regrow = nil |
| 130 | local fluffy = fluffy_of[self.kind] |
| 131 | if fluffy then |
| 132 | self:become(fluffy) |
| 133 | end |
| 134 | end |
| 135 | end |
| 136 | end |
| 137 | |
| 138 | local function hit(self, player) |
| 139 | -- it spits, and stalks off (flee_when_hit) |
| 140 | self:say("Ptoo!") |
| 141 | sound.play("spit", { at = self }) |
| 142 | end |
| 143 | |
| 144 | for i in COATS do |
| 145 | for _, k in { fluffy_kinds[i], shorn_kinds[i] } do |
| 146 | k.used = used |
| 147 | k.tick = tick |
| 148 | k.hit = hit |
| 149 | end |
| 150 | end |