Sign in
creature

The Hush

by Potluck · version 1 · Checked for all ages

Far out in the Long Night a ring of nightglass spires stands on the ice: the Still Court, where a great pale stag, the Hush, sleeps. Make a Star chime from evensteel, starglass and hush silk and ring it at the altar. It gores and charges (hit it while it's dazed), star crystals shield it until you break them, and a cold pulse hurts anyone away from a light. Beat it for its antler, starglass and a Hush crown. Never on Peaceful.

1--!strict
2-- The Hush: a great pale stag of the Long Night, kept by the old star
3-- keepers in a court of nightglass spires on the ice.
4--
5-- Far in the Long Night, away from where anyone has been, a Still Court
6-- opens near a player: a round floor of duskstone bricks, six spires of
7-- nightglass round it, four star crystals standing in it, four sun lamps
8-- on pedestals and, in the middle, the Still altar. The Hush sleeps at its
9-- north end. Make a Star chime at a workbench (evensteel, starglass and
10-- hush silk), ring it at the altar and the Hush wakes, and fights in three
11-- parts:
12-- 1. It gores and charges. A charge is shown first: it lowers its
13-- antlers and stamps. Step aside, and it's dazed after, so hit it
14-- then (a blow counts half as much again).
15-- 2. While star crystals stand in the court the starlight shields it
16-- and a blow counts for a quarter. Break the crystals (an iron
17-- pickaxe breaks starglass). At 66% and 33% the stars gather and some
18-- grow back.
19-- 3. From 66% on it holds its breath and the air goes still: a cold pulse
20-- hurts everyone who isn't near a light (a sun lamp, a torch in hand).
21-- At 33% it rages: quicker, charging more, pulsing sooner.
22-- Beat it and everyone who fought gets its antler (a relic for the
23-- Curator), starglass, XP and, the first time each, a Hush crown. The chime
24-- stays in the altar until the Hush is beaten, so a fight that goes badly
25-- can be tried again. After a minute and a half it gathers again, for
26-- another chime.
27--
28-- How tough it is and how hard it hits go by the world's danger (and grow
29-- with every player who fights it). It never wakes on a Peaceful world, and
30-- fights only players in survival.
31
32local world = require("@potluck/world@0.33")
33local tweak = require("@potluck/tweak")
34local store = require("@potluck/store")
35local ui = require("@potluck/ui@0.2")
36local sound = require("@potluck/sound@0.2")
37
38local knobs = tweak {
39 on = { true, label = "The Hush keeps a court in the Long Night", order = 1 },
40 health = { 300, min = 40, max = 1000, label = "How much it takes to beat (Normal, one player)", order = 2 },
41 hits = { 4, min = 0, max = 12, label = "How hard it gores", order = 3 },
42 cold = { 4, min = 0, max = 12, label = "How hard the cold pulse hurts", order = 4 },
43 apart = { 500, min = 150, max = 2000, label = "How far apart courts are", order = 5 },
44 eyes = { "#bfe8ff", label = "Eye color", order = 6 },
45 coat = { "#dfe6f2", label = "Coat color", order = 7 },
46}
47
48local DANGER: { [string]: { health: number, hurt: number, speed: number } } = {
49 peaceful = { health = 0, hurt = 0, speed = 0 },
50 gentle = { health = 0.6, hurt = 0.5, speed = 0.85 },
51 normal = { health = 1, hurt = 1, speed = 1 },
52 hard = { health = 1.4, hurt = 1.5, speed = 1.2 },
53}
54local function danger()
55 return DANGER[world.danger()] or DANGER.gentle
56end
57
58local SWORDS: { [string]: number } = {
59 ["Wooden sword"] = 2,
60 ["Stone sword"] = 3,
61 ["Copper sword"] = 3,
62 ["Iron sword"] = 4,
63 ["Moonsilver sword"] = 5,
64 ["Evensteel sword"] = 6,
65}
66local function bops(held: string?): number
67 if not held then
68 return 1
69 end
70 if SWORDS[held] then
71 return SWORDS[held]
72 end
73 local it = world.item(held)
74 return if it and it.kind == "weapon" then it.power or 1 else 1
75end
76
77local FLOOR, RIM, SPIRE, CRYSTAL, ALTAR = "Duskstone bricks", "Snow bricks", "Nightglass", "Starglass", "Still altar"
78local CHIME, ANTLER, CROWN = "Star chime", "Hush's antler", "Hush crown"
79local LIGHTS: { [string]: boolean } = { Torch = true, Lantern = true, Candle = true, Brazier = true, ["Sun lamp"] = true }
80
81local R, TALL = 12, 10 -- the court's radius, and how much air over it
82local MOST = 12 -- courts a world keeps track of
83local NEAR, GONE = 48, 64 -- the sleeper comes with a player this close, and goes with none
84local REST = 90 -- seconds before a beaten Hush gathers again
85local SETTLE = 15 -- seconds with nobody fighting before it settles
86local COOL = 0.45 -- a player's blows count at most this often
87local STAR, RAGE = 0.66, 0.33
88local METER = "#9fd8ff"
89local WARM = 4 -- how near a light keeps the cold off
90local EDGE = 29000
91
92-- what may be cleared or filled over
93local NATURAL: { [string]: boolean } = {
94 Air = true, Rime = true, Ice = true, Snow = true, Duskstone = true, Stone = true, Gravel = true, Sand = true,
95 Dirt = true, Water = true, Granite = true, Marble = true, Basalt = true, Slate = true, Starglass = true, Nightglass = true, [FLOOR] = true, [RIM] = true, [ALTAR] = true,
96 ["Sun lamp"] = true, Lantern = true,
97}
98
99local function v(x: number, y: number, z: number): vector
100 return vector.create(x, y, z)
101end
102
103local function flat(a: vector, b: vector): number
104 local dx, dz = a.x - b.x, a.z - b.z
105 return math.sqrt(dx * dx + dz * dz)
106end
107
108local function exists(name: string): boolean
109 return pcall(world.kind, name)
110end
111
112local shown: { [number]: number } = {}
113local function tell(player, text: string)
114 ui.show(player, "hush", text, { at = "bottom" })
115 local mine = (shown[player.id] or 0) + 1
116 shown[player.id] = mine
117 world.after(5, function()
118 if shown[player.id] == mine then
119 shown[player.id] = nil
120 ui.hide(player, "hush")
121 end
122 end)
123end
124
125-- ---- what's kept ----
126
127-- each court: the altar's cell (the middle, over the floor), whether it's
128-- built, whether a chime is in its altar, and how often its Hush was beaten
129type Court = { at: vector, built: boolean, chime: boolean, beaten: number }
130local courts: { Court } = store.get("courts") or {}
131local crowns: { [string]: boolean } = store.get("crowns") or {}
132
133local function save()
134 store.set("courts", courts)
135end
136
137-- ---- where things are in a court ----
138
139local function crystal_cells(c: Court): { vector }
140 return { c.at + v(4, 0, 4), c.at + v(-4, 0, 4), c.at + v(4, 0, -4), c.at + v(-4, 0, -4) }
141end
142
143local function lamp_cells(c: Court): { vector }
144 return { c.at + v(8, 3, 0), c.at + v(-8, 3, 0), c.at + v(0, 3, 8), c.at + v(0, 3, -8) }
145end
146
147-- where the Hush sleeps: the court's north end
148local function bed(c: Court): vector
149 return c.at + v(0.5, 0, -5.5)
150end
151
152local function nearest_court(at: vector, within: number): number?
153 local best, best_d = nil, within
154 for i, c in courts do
155 local d = vector.magnitude(at - c.at)
156 if d < best_d then
157 best, best_d = i, d
158 end
159 end
160 return best
161end
162
163local function in_court(c: Court, at: vector): boolean
164 return flat(at, c.at + v(0.5, 0, 0.5)) < R + 1 and at.y > c.at.y - 3 and at.y < c.at.y + TALL
165end
166
167local function fighters(c: Court)
168 local out = {}
169 for _, p in world.players() do
170 if world.pockets(p) ~= nil and in_court(c, p.position) then
171 table.insert(out, p)
172 end
173 end
174 return out
175end
176
177local function stars(c: Court): number
178 local n = 0
179 for _, at in crystal_cells(c) do
180 if world.block(at) == CRYSTAL then
181 n += 1
182 end
183 end
184 return n
185end
186
187-- a star crystal is a column three high; the cell is its foot, and the
188-- rest goes when the foot does, so no two stand alone
189local function grow_column(at: vector)
190 world.set_block(at, CRYSTAL)
191 world.set_block(at + v(0, 1, 0), CRYSTAL)
192 world.set_block(at + v(0, 2, 0), CRYSTAL)
193end
194
195-- the stars gather: crystals grow back until this many stand
196local function regrow(c: Court, upto: number)
197 local n = stars(c)
198 for _, at in crystal_cells(c) do
199 if n >= upto then
200 break
201 end
202 if world.block(at) ~= CRYSTAL then
203 grow_column(at)
204 n += 1
205 end
206 end
207end
208
209local function warm(p): boolean
210 if world.find_light(p.position + v(0, 1, 0), WARM) then
211 return true
212 end
213 local held = world.held(p)
214 return held ~= nil and LIGHTS[held] == true
215end
216
217-- ---- building it ----
218
219type Work = { at: vector, name: string }
220local work: { Work } = {}
221local done = 0
222local building: number? = nil
223
224local function plan(i: number)
225 local c = courts[i].at
226 work, done = {}, 0
227 local function put(at: vector, name: string)
228 table.insert(work, { at = at, name = name })
229 end
230 local lamp = if exists("Sun lamp") then "Sun lamp" else "Lantern"
231 local inner = (R + 0.5) * (R + 0.5)
232 for dx = -R, R do
233 for dz = -R, R do
234 local d2 = dx * dx + dz * dz
235 if d2 <= inner then
236 local ring = d2 > 9 * 9 and d2 <= 10 * 10 + 4
237 -- under the floor, down to the ground
238 local ground = world.top(c.x + dx, c.z + dz)
239 for y = math.max(ground + 1, c.y - 9), c.y - 2 do
240 put(v(c.x + dx, y, c.z + dz), FLOOR)
241 end
242 put(v(c.x + dx, c.y - 1, c.z + dz), if ring then RIM else FLOOR)
243 for dy = 0, TALL - 1 do
244 put(v(c.x + dx, c.y + dy, c.z + dz), "Air")
245 end
246 end
247 end
248 end
249 -- six spires of nightglass, a starglass cap on each
250 for k = 0, 5 do
251 local a = k * math.pi / 3 + math.pi / 6
252 local x, z = math.floor(math.cos(a) * 10.5 + 0.5), math.floor(math.sin(a) * 10.5 + 0.5)
253 for dy = 0, 6 do
254 put(c + v(x, dy, z), SPIRE)
255 end
256 put(c + v(x, 7, z), CRYSTAL)
257 end
258 -- four lamps on pedestals
259 for _, at in lamp_cells(courts[i]) do
260 for dy = -3, -1 do
261 put(at + v(0, dy, 0), FLOOR)
262 end
263 put(at, lamp)
264 end
265 for _, at in crystal_cells(courts[i]) do
266 for dy = 0, 2 do
267 put(at + v(0, dy, 0), CRYSTAL)
268 end
269 end
270 put(c, ALTAR)
271end
272
273-- puts down a few hundred blocks a tick
274local function step()
275 local last = math.min(done + 250, #work)
276 for k = done + 1, last do
277 local w = work[k]
278 local b = world.block(w.at)
279 if NATURAL[b] and b ~= w.name then
280 world.set_block(w.at, w.name)
281 end
282 end
283 done = last
284 if done >= #work then
285 work, done = {}, 0
286 local i = building
287 building = nil
288 if i then
289 local c = courts[i]
290 c.built = true
291 save()
292 for _, p in world.players() do
293 if vector.magnitude(p.position - c.at) < 60 then
294 tell(p, "A ring of dark glass spires stands on the ice, far off.")
295 end
296 end
297 end
298 end
299end
300
301-- nothing cuts the altar
302world.drops(ALTAR, { gives = false, level = 9 })
303
304-- ---- finding a place ----
305
306local function far_from_others(at: vector, apart: number): boolean
307 for _, c in courts do
308 if flat(c.at, at) < apart then
309 return false
310 end
311 end
312 return true
313end
314
315-- level enough ground for the court, a little way off from a player
316local function site_near(p): vector?
317 local a = world.random() * math.pi * 2
318 local d = world.random(24, 40)
319 local x, z = math.floor(p.position.x + math.cos(a) * d), math.floor(p.position.z + math.sin(a) * d)
320 if math.abs(x) > EDGE or math.abs(z) > EDGE or world.biome(v(x, 0, z)) ~= "long_night" then
321 return nil
322 end
323 local lo, hi = math.huge, -math.huge
324 for dx = -R, R, 6 do
325 for dz = -R, R, 6 do
326 local top = world.top(x + dx, z + dz)
327 local b = world.block(v(x + dx, top, z + dz))
328 if b == "Ice" or b == "Water" or world.biome(v(x + dx, 0, z + dz)) ~= "long_night" then
329 return nil
330 end
331 lo, hi = math.min(lo, top), math.max(hi, top)
332 end
333 end
334 if hi - lo > 5 then
335 return nil
336 end
337 return v(x, hi + 1, z)
338end
339
340local function look(p)
341 if #courts >= MOST or world.pockets(p) == nil then
342 return
343 end
344 if world.place(p.position) ~= "dusk" or world.biome(p.position) ~= "long_night" then
345 return
346 end
347 if not far_from_others(p.position, knobs.apart) then
348 return
349 end
350 local at = site_near(p)
351 if at then
352 table.insert(courts, { at = at, built = false, chime = false, beaten = 0 })
353 building = #courts
354 plan(#courts)
355 save()
356 end
357end
358
359-- ---- the Hush ----
360
361local COAT, FROST, EYE, ANTL = knobs.coat, "#a8b8d4", knobs.eyes, "#9fb0c8"
362local STAR_GLOW = "#9cc4ff"
363
364local function awake_body(lowered: boolean)
365 local head_y = if lowered then 1.7 else 3.1
366 local head_z = if lowered then -2.2 else -1.5
367 local tip_y = if lowered then 1.6 else 4.2
368 local tip_z = if lowered then -3.2 else -1.5
369 return {
370 { "leg_1", size = { 0.5, 1.7, 0.5 }, at = { -0.7, 0.85, -0.9 }, color = FROST, leg = true },
371 { "leg_2", size = { 0.5, 1.7, 0.5 }, at = { 0.7, 0.85, -0.9 }, color = FROST, leg = true },
372 { "leg_3", size = { 0.5, 1.7, 0.5 }, at = { -0.7, 0.85, 1.1 }, color = FROST, leg = true },
373 { "leg_4", size = { 0.5, 1.7, 0.5 }, at = { 0.7, 0.85, 1.1 }, color = FROST, leg = true },
374 { "body", size = { 1.9, 1.5, 3.0 }, at = { 0, 2.2, 0.1 }, color = COAT },
375 { "stars", size = { 0.7, 0.1, 0.7 }, at = { 0.4, 2.95, 0.3 }, color = STAR_GLOW, glow = true },
376 { "stars2", size = { 0.5, 0.1, 0.5 }, at = { -0.5, 2.95, -0.5 }, color = STAR_GLOW, glow = true },
377 { "mane", size = { 1.1, 1.0, 1.0 }, at = { 0, 2.9, -1.3 }, color = FROST },
378 { "neck", size = { 0.8, 1.4, 0.8 }, at = { 0, if lowered then 2.0 else 3.0, -1.3 }, color = COAT },
379 { "head", size = { 0.9, 0.8, 1.1 }, at = { 0, head_y, head_z }, color = COAT, head = true },
380 { "eye_left", size = { 0.2, 0.2, 0.05 }, at = { -0.28, head_y + 0.1, head_z - 0.57 }, color = EYE, glow = true, head = true },
381 { "eye_right", size = { 0.2, 0.2, 0.05 }, at = { 0.28, head_y + 0.1, head_z - 0.57 }, color = EYE, glow = true, head = true },
382 { "antler_left", size = { 0.18, 1.5, 0.18 }, at = { -0.45, tip_y, head_z + 0.1 }, color = ANTL, head = true },
383 { "antler_right", size = { 0.18, 1.5, 0.18 }, at = { 0.45, tip_y, head_z + 0.1 }, color = ANTL, head = true },
384 { "tine_left", size = { 0.7, 0.14, 0.14 }, at = { -0.8, tip_y + 0.3, head_z + 0.1 }, color = ANTL, head = true },
385 { "tine_right", size = { 0.7, 0.14, 0.14 }, at = { 0.8, tip_y + 0.3, head_z + 0.1 }, color = ANTL, head = true },
386 { "tip_left", size = { 0.16, 0.16, 0.16 }, at = { -1.15, tip_y + 0.3, tip_z + 1.7 }, color = EYE, glow = true, head = true },
387 { "tip_right", size = { 0.16, 0.16, 0.16 }, at = { 1.15, tip_y + 0.3, tip_z + 1.7 }, color = EYE, glow = true, head = true },
388 { "tail", size = { 0.3, 0.9, 0.3 }, at = { 0, 2.5, 1.8 }, color = FROST },
389 }
390end
391
392local Still = world.creature {
393 name = "The Hush (still)",
394 speed = 0.5,
395 count = 0,
396 home = "here",
397 size = { 2.4, 1.8, 3.0 },
398 behaviors = { wander = false },
399 body = {
400 { "body", size = { 2.0, 1.1, 3.0 }, at = { 0, 0.55, 0.1 }, color = COAT },
401 { "stars", size = { 0.5, 0.08, 0.5 }, at = { 0.4, 1.1, 0.3 }, color = STAR_GLOW, glow = true },
402 { "stars2", size = { 0.4, 0.08, 0.4 }, at = { -0.5, 1.1, -0.4 }, color = STAR_GLOW, glow = true },
403 { "head", size = { 0.9, 0.7, 1.0 }, at = { 0, 0.4, -1.9 }, color = COAT },
404 { "lid_left", size = { 0.24, 0.05, 0.05 }, at = { -0.28, 0.5, -2.43 }, color = EYE, glow = true },
405 { "lid_right", size = { 0.24, 0.05, 0.05 }, at = { 0.28, 0.5, -2.43 }, color = EYE, glow = true },
406 { "antler_left", size = { 0.16, 0.9, 0.16 }, at = { -0.4, 1.15, -1.9 }, color = ANTL },
407 { "antler_right", size = { 0.16, 0.9, 0.16 }, at = { 0.4, 1.15, -1.9 }, color = ANTL },
408 { "legs", size = { 1.8, 0.3, 1.6 }, at = { 0, 0.15, -0.9 }, color = FROST },
409 },
410}
411
412local Hush = world.creature {
413 name = "The Hush",
414 speed = 1.5,
415 count = 0,
416 home = "here",
417 size = { 2.2, 4.2, 3.0 },
418 behaviors = { wander = false },
419 body = awake_body(false),
420}
421
422-- head down for the charge
423local Charging = world.creature {
424 name = "The Hush (charging)",
425 speed = 0.1,
426 count = 0,
427 home = "here",
428 size = { 2.2, 3.0, 3.0 },
429 behaviors = { wander = false },
430 body = awake_body(true),
431}
432
433-- the fight in each court, outside the creatures so the kinds share it
434local stirred: { [number]: number } = {}
435local awake: { [number]: boolean } = {}
436local waking: { [number]: boolean } = {}
437local hitters: { [number]: { [string]: boolean } } = {}
438local resting: { [number]: number } = {}
439local metered: { [number]: boolean } = {}
440local last_hit: { [number]: number } = {}
441
442local function stale(i: number): boolean
443 return world.time() - (stirred[i] or -10) > 2
444end
445
446local function show_meter(p, self)
447 ui.meter(p, "hush_meter", math.clamp(self.health / self.most, 0, 1), { color = METER })
448 metered[p.id] = true
449end
450
451local function hide_meters(c: Court)
452 for _, p in world.players() do
453 if metered[p.id] and vector.magnitude(p.position - c.at) < 90 then
454 metered[p.id] = nil
455 ui.meter(p, "hush_meter", nil)
456 end
457 end
458end
459
460local function by_id(id: number?)
461 for _, q in world.players() do
462 if q.id == id then
463 return q
464 end
465 end
466 return nil
467end
468
469function Still:spawned()
470 self.court = nearest_court(self.position, 30)
471 self.breath_in = world.random(2, 5)
472end
473
474local function wake(self, c: Court)
475 local d = danger()
476 local crew = math.max(#fighters(c), 1)
477 self:become(Hush)
478 self.phase = 1
479 self.crew = crew
480 self.most = knobs.health * d.health * (1 + 0.6 * (crew - 1))
481 self.health = self.most
482 self.state = "stalk"
483 self.timer = 0
484 self.charge_in = 6
485 self.swipe_in = 1
486 self.cold_in = 1e9
487 self.chill = 0
488 self.look_in = 0
489 self.alone = 0
490 self.rage = false
491 awake[self.court] = true
492 hitters[self.court] = {}
493 sound.play("roar", { at = self, volume = 1 })
494 for _, p in fighters(c) do
495 tell(p, "The Hush wakes! Break the star crystals first.")
496 show_meter(p, self)
497 end
498end
499
500function Still:tick(dt: number)
501 local i = self.court
502 local c = if i then courts[i] else nil
503 if not i or not c or not knobs.on or danger().health == 0 or not world.nearest_player(self.position, GONE) then
504 self:remove()
505 return
506 end
507 stirred[i] = world.time()
508 self:stop()
509 if waking[i] then
510 waking[i] = nil
511 wake(self, c)
512 return
513 end
514 self.breath_in -= dt
515 if self.breath_in <= 0 then
516 self.breath_in = world.random(5, 8)
517 sound.play("breath", { at = self, volume = 0.6 })
518 end
519end
520
521local function settle(self, c: Court)
522 awake[self.court] = nil
523 hide_meters(c)
524 c.chime = true
525 regrow(c, 4)
526 save()
527 for _, p in world.players() do
528 if vector.magnitude(p.position - c.at) < 40 then
529 tell(p, "The Hush settles back to sleep. The chime stays.")
530 end
531 end
532 self:become(Still)
533 self.breath_in = 3
534end
535
536-- the cold pulse: everyone not near a light is hurt
537local function pulse(self, c: Court, d)
538 sound.play("frost", { at = self, volume = 1 })
539 for _, p in fighters(c) do
540 if not warm(p) then
541 world.hurt(p, knobs.cold * d.hurt * (if self.phase == 3 then 1.25 else 1))
542 end
543 end
544end
545
546function Hush:tick(dt: number)
547 local i = self.court
548 local c = if i then courts[i] else nil
549 local d = danger()
550 if not i or not c or not knobs.on or d.health == 0 then
551 if c then
552 hide_meters(c)
553 end
554 if i then
555 awake[i] = nil
556 end
557 self:remove()
558 return
559 end
560 stirred[i] = world.time()
561 awake[i] = true
562 self.look_in -= dt
563 if self.look_in <= 0 then
564 self.look_in = 0.5
565 local all = fighters(c)
566 if #all == 0 then
567 self.alone += 0.5
568 if self.alone >= SETTLE then
569 settle(self, c)
570 return
571 end
572 else
573 self.alone = 0
574 end
575 if #all > self.crew then
576 local more = knobs.health * d.health * 0.6 * (#all - self.crew)
577 self.most += more
578 self.health += more
579 self.crew = #all
580 end
581 local best, best_d = nil, math.huge
582 for _, p in all do
583 show_meter(p, self)
584 local dist = flat(p.position, self.position)
585 if dist < best_d then
586 best, best_d = p, dist
587 end
588 end
589 self.target = if best then best.id else nil
590 end
591 -- the cold: a warning, then the pulse
592 if self.phase >= 2 then
593 if self.chill > 0 then
594 self.chill -= dt
595 if self.chill <= 0 then
596 pulse(self, c, d)
597 self.cold_in = if self.phase == 3 then 8 else 13
598 end
599 else
600 self.cold_in -= dt
601 if self.cold_in <= 0 then
602 self.chill = 2.5
603 sound.play("hush", { at = self, volume = 1 })
604 for _, p in fighters(c) do
605 tell(p, "The air goes still. Get to a light!")
606 end
607 end
608 end
609 end
610 local p = by_id(self.target)
611 local speed = 1.5 * d.speed * (if self.phase == 3 then 1.4 else 1)
612 -- dazed after a charge: stands where it stopped
613 if self.state == "daze" then
614 self.timer -= dt
615 self:stop()
616 if self.timer <= 0 then
617 self.state = "stalk"
618 end
619 return
620 end
621 -- head down and stamping: it charges where you stood
622 if self.state == "wind" then
623 self.timer -= dt
624 self:stop()
625 if self.timer <= 0 then
626 self.state = "dash"
627 self.timer = 1.2
628 self.struck = {}
629 sound.play("charge", { at = self, volume = 1 })
630 end
631 return
632 end
633 if self.state == "dash" then
634 self.timer -= dt
635 self:walk_to(self.lock, 9 * d.speed)
636 for _, q in fighters(c) do
637 if not self.struck[q.id] and flat(q.position, self.position) < 2.8 and math.abs(q.position.y - self.position.y) < 3 then
638 self.struck[q.id] = true
639 world.hurt(q, knobs.hits * 1.8 * d.hurt)
640 end
641 end
642 if self.timer <= 0 or flat(self.position, self.lock) < 1 then
643 self.state = "daze"
644 self.timer = 2.4
645 self:stop()
646 self:become(Hush)
647 sound.play("puff", { at = self, volume = 0.8 })
648 for _, q in fighters(c) do
649 tell(q, "It's dazed! Hit it now.")
650 end
651 end
652 return
653 end
654 if not p then
655 self:stop()
656 return
657 end
658 local dist = flat(p.position, self.position)
659 self.charge_in -= dt
660 if self.charge_in <= 0 and dist > 3 then
661 self.charge_in = if self.phase == 3 then 5 else 8
662 self.state = "wind"
663 self.timer = 1.3
664 local away = vector.create(p.position.x - self.position.x, 0, p.position.z - self.position.z)
665 local to = p.position + vector.normalize(away) * 3
666 local mid = c.at + v(0.5, 0, 0.5)
667 if flat(to, mid) > R - 2 then
668 local off = vector.create(to.x - mid.x, 0, to.z - mid.z)
669 to = mid + vector.normalize(off) * (R - 2)
670 end
671 self.lock = to
672 self:stop()
673 self:face(p.position)
674 self:become(Charging)
675 sound.play("stamp", { at = self, volume = 1 })
676 return
677 end
678 if dist < 4 then
679 self:stop()
680 self:face(p.position)
681 self.swipe_in -= dt
682 if self.swipe_in <= 0 then
683 self.swipe_in = if self.phase == 3 then 1.1 else 1.6
684 sound.play("gore", { at = self, volume = 1 })
685 if knobs.hits > 0 and math.abs(p.position.y - self.position.y) < 3 then
686 world.hurt(p, knobs.hits * d.hurt * (if self.phase == 3 then 1.25 else 1))
687 end
688 end
689 else
690 local to = p.position
691 local mid = c.at + v(0.5, 0, 0.5)
692 if flat(to, mid) > R - 2 then
693 local off = vector.create(to.x - mid.x, 0, to.z - mid.z)
694 to = mid + vector.normalize(off) * (R - 2)
695 end
696 self:walk_to(to, speed)
697 end
698end
699
700local function beaten(self, c: Court)
701 local i = self.court
702 awake[i] = nil
703 sound.play("dawn", { at = self, volume = 1 })
704 hide_meters(c)
705 regrow(c, 4)
706 c.chime = false
707 c.beaten += 1
708 resting[i] = world.time() + REST
709 save()
710 local who = {}
711 local names = hitters[i] or {}
712 for _, p in world.players() do
713 if world.pockets(p) ~= nil and (in_court(c, p.position) or (names[p.name] and vector.magnitude(p.position - c.at) < 50)) then
714 table.insert(who, p)
715 end
716 end
717 for _, p in who do
718 world.reward(p, 150)
719 world.give(p, ANTLER, 1)
720 local shards = math.floor(world.random(3, 6.999))
721 world.give(p, "Starglass shard", shards)
722 local got = string.format("the Hush's antler and %d starglass shards", shards)
723 if world.random() < 0.5 then
724 world.give(p, "Evensteel ingot", 1)
725 got ..= " and an evensteel ingot"
726 end
727 if not crowns[p.name] then
728 crowns[p.name] = true
729 world.give(p, CROWN, 1)
730 got ..= " and a Hush crown"
731 end
732 ui.ask(p, { title = "The Hush is beaten", text = "The court is still. You won " .. got .. ".\nIn time it gathers again, for another chime." }, function() end)
733 end
734 store.set("crowns", crowns)
735 if #who > 0 then
736 local all = {}
737 for k, p in who do
738 if k <= 3 then
739 table.insert(all, p.name)
740 end
741 end
742 world.say("The Hush is beaten, by " .. table.concat(all, ", ") .. (if #who > 3 then " and friends" else "") .. ".")
743 end
744 self:remove()
745end
746
747function Hush:hit(player, shot)
748 local i = self.court
749 local c = if i then courts[i] else nil
750 if not c or not self.most then
751 return
752 end
753 if world.pockets(player) == nil then
754 tell(player, "The Hush fights only players in survival.")
755 return
756 end
757 local now = world.time()
758 if now - (last_hit[player.id] or -10) < COOL then
759 return
760 end
761 last_hit[player.id] = now
762 local bop = if shot then shot.power else bops(world.held(player)) * world.might(player)
763 if stars(c) > 0 then
764 bop *= 0.25
765 if not self.told_veil then
766 self.told_veil = true
767 for _, p in fighters(c) do
768 tell(p, "Starlight shields it. Break the star crystals!")
769 end
770 end
771 else
772 self.told_veil = false
773 end
774 if self.state == "daze" then
775 bop *= 1.5
776 end
777 self.health -= bop
778 hitters[i] = hitters[i] or {}
779 hitters[i][player.name] = true
780 show_meter(player, self)
781 if self.health <= 0 then
782 beaten(self, c)
783 return
784 end
785 local share = self.health / self.most
786 if self.phase == 1 and share <= STAR then
787 self.phase = 2
788 self.cold_in = 6
789 regrow(c, 2)
790 self.told_veil = false
791 sound.play("roar", { at = self, volume = 1 })
792 for _, p in fighters(c) do
793 tell(p, "The stars gather, and the cold with them. Stay by a light.")
794 end
795 elseif self.phase == 2 and share <= RAGE then
796 self.phase = 3
797 regrow(c, 3)
798 self.told_veil = false
799 sound.play("roar", { at = self, volume = 1, pitch = 0.8 })
800 for _, p in fighters(c) do
801 tell(p, "The Hush rages!")
802 end
803 else
804 sound.play("gore", { at = self, volume = 0.5, pitch = 0.6, caption = "The Hush is struck" })
805 end
806end
807
808Charging.tick = Hush.tick
809Charging.hit = Hush.hit
810
811-- ---- the altar, the crystals and the chime ----
812
813world.on("block_used", function(player, at: vector, block: string)
814 if block ~= ALTAR then
815 return
816 end
817 local i = nearest_court(at, 4)
818 local c = if i then courts[i] else nil
819 if not i or not c then
820 return
821 end
822 if world.pockets(player) == nil then
823 tell(player, "The Hush wakes only for players in survival.")
824 elseif danger().health == 0 or not knobs.on then
825 tell(player, "The court is silent. The Hush never wakes on Peaceful.")
826 elseif (awake[i] and not stale(i)) or waking[i] then
827 return
828 elseif (resting[i] or 0) > world.time() then
829 tell(player, "The court is still. Nothing stirs yet.")
830 elseif c.chime or (world.held(player) == CHIME and world.take(player, CHIME, 1)) then
831 c.chime = true
832 save()
833 sound.play("chime", { at = at, volume = 1 })
834 waking[i] = true
835 if stale(i) then
836 world.spawn(Still, bed(c))
837 stirred[i] = world.time()
838 end
839 else
840 tell(player, "A hollow in the shape of a chime. A Star chime rings here.")
841 end
842end)
843
844world.on("block_broken", function(player, at: vector, block: string)
845 if block ~= CRYSTAL then
846 return
847 end
848 -- the whole column goes, whichever block of it was broken
849 for dy = -2, 2 do
850 if world.block(at + v(0, dy, 0)) == CRYSTAL then
851 world.set_block(at + v(0, dy, 0), "Air")
852 end
853 end
854 local i = nearest_court(at, R + 2)
855 if i and awake[i] and not stale(i) then
856 sound.play("crack", { at = at, volume = 1 })
857 local left = stars(courts[i])
858 for _, p in fighters(courts[i]) do
859 tell(p, if left == 0 then "The starlight is gone. Now hit it!" else string.format("%d star crystals left.", left))
860 end
861 end
862end)
863
864-- the chime hums toward the nearest court
865world.on("item_used", function(player, item: string?, _aim)
866 if item ~= CHIME then
867 return
868 end
869 local best, best_d = nil, math.huge
870 for _, c in courts do
871 local d = vector.magnitude(c.at - player.position)
872 if d < best_d then
873 best, best_d = c, d
874 end
875 end
876 sound.play_for(player, "chime", { volume = 0.5 })
877 if not best then
878 tell(player, "The chime is silent. Look for dark glass spires in the Long Night.")
879 return
880 end
881 local to = best.at - player.position
882 local ways = { "east", "south-east", "south", "south-west", "west", "north-west", "north", "north-east" }
883 local a = math.atan2(to.z, to.x)
884 local way = ways[(math.floor(a / (math.pi / 4) + 0.5) % 8) + 1]
885 if best_d < R + 2 then
886 tell(player, "The chime rings clear. Ring it at the altar.")
887 else
888 tell(player, "The chime hums " .. way .. ".")
889 end
890end)
891
892world.on("player_left", function(p)
893 shown[p.id] = nil
894 metered[p.id] = nil
895 last_hit[p.id] = nil
896end)
897
898-- ---- watching players ----
899
900local turn = 0
901world.every(0.1, function()
902 if #work > 0 then
903 step()
904 return
905 end
906 turn += 1
907 if turn % 10 ~= 0 then
908 return
909 end
910 local players = world.players()
911 if #players == 0 then
912 return
913 end
914 -- a court for one player a second
915 look(players[(turn // 10) % #players + 1])
916 if not knobs.on or danger().health == 0 then
917 return
918 end
919 for i, c in courts do
920 if c.built and stale(i) and (resting[i] or 0) <= world.time() and world.nearest_player(c.at, NEAR) then
921 world.spawn(Still, bed(c))
922 stirred[i] = world.time()
923 end
924 end
925end)
926
927-- a court left half built (the world stopped mid-way) is built on
928for i, c in courts do
929 if not c.built then
930 building = i
931 plan(i)
932 break
933 end
934end