Jester and coilhead sounds
This commit is contained in:
@@ -30,6 +30,8 @@ export function register_coilhead(ctx: ServerContext) {
|
||||
start: () => {
|
||||
mob.stop();
|
||||
mob.set_client_data("frozen", true);
|
||||
mob.play_sound("dangerous_business:coilhead/stop");
|
||||
mob.play_sound("dangerous_business:coilhead/seen");
|
||||
},
|
||||
stop: () => mob.set_client_data("frozen", undefined),
|
||||
});
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
// the jester: a box on legs that wanders until it sees a player. it follows them for a while, stops to wind its crank,
|
||||
// and pops open, then runs down every player in the facility, faster and faster, until there's nobody left inside
|
||||
import type { MobRef, Player, ScriptGoal, ServerContext } from "cubi/server";
|
||||
import { type AnimatedEntity, AnimationState, type ClientContext, type Clip, type EntityPose } from "cubi/client";
|
||||
import {
|
||||
type AnimatedEntity,
|
||||
AnimationState,
|
||||
type ClientContext,
|
||||
type Clip,
|
||||
type EntityPose,
|
||||
type PlayingSound,
|
||||
} from "cubi/client";
|
||||
import { opens_doors } from "./coilhead.ts";
|
||||
import { in_facility } from "./interior.ts";
|
||||
|
||||
@@ -29,6 +36,8 @@ const MAX_SPEED_STEPS = 8;
|
||||
const CHASE_SPEED = "dangerous_business:jester_chase";
|
||||
// it only waits a moment at a closed door
|
||||
const OPEN_DOOR_TICKS = 20;
|
||||
// the crank turns once a second while it cranks, clicking this many ticks into each, where its crank clip has it
|
||||
const CRANK_CLICK_TICK = 12;
|
||||
|
||||
export function register_jester(ctx: ServerContext) {
|
||||
const builtin = ctx.entities.goals;
|
||||
@@ -47,6 +56,7 @@ export function register_jester(ctx: ServerContext) {
|
||||
state = next;
|
||||
ticks = 0;
|
||||
mob.set_client_data("state", next);
|
||||
if (next === AGGRO) mob.play_sound("dangerous_business:jester/pop");
|
||||
};
|
||||
|
||||
// what it's doing, which the goals after it follow
|
||||
@@ -67,6 +77,7 @@ export function register_jester(ctx: ServerContext) {
|
||||
set_state(CRANKING);
|
||||
}
|
||||
} else if (state === CRANKING) {
|
||||
if (ticks % 20 === CRANK_CLICK_TICK) mob.play_sound("dangerous_business:jester/turn_crank");
|
||||
if (ticks >= CRANK_TICKS) set_state(AGGRO);
|
||||
} else {
|
||||
const target = nearest_player(ctx, mob);
|
||||
@@ -148,7 +159,8 @@ function nearest_player(ctx: ServerContext, mob: MobRef) {
|
||||
}
|
||||
|
||||
// what bedrock's animation controller did: idle and walk while it roams, crank, then pop, then its chase. what its
|
||||
// clips did with expressions is here as code
|
||||
// clips did with expressions is here as code. its music box plays while it cranks, and it screams while it's popped,
|
||||
// for whoever is near then, even if they came after it started
|
||||
export function register_jester_animator(ctx: ClientContext) {
|
||||
const clip = (name: string) => ctx.render.clip(`dangerous_business:jester/${name}`);
|
||||
const idle = clip("idle");
|
||||
@@ -163,12 +175,24 @@ export function register_jester_animator(ctx: ClientContext) {
|
||||
const cranking = new AnimationState();
|
||||
const popped = new AnimationState();
|
||||
const attacking = new AnimationState();
|
||||
let theme: PlayingSound | undefined;
|
||||
let scream: PlayingSound | undefined;
|
||||
return {
|
||||
on_data(field, time) {
|
||||
if (field !== "state") return;
|
||||
const state = jester.get_client_data<number>("state");
|
||||
cranking.animate_when(state === CRANKING, time);
|
||||
popped.animate_when(state === AGGRO, time);
|
||||
theme = sound_while(
|
||||
state === CRANKING,
|
||||
theme,
|
||||
() => ctx.sounds.play("dangerous_business:jester/theme", { follow: jester.id }),
|
||||
);
|
||||
scream = sound_while(
|
||||
state === AGGRO,
|
||||
scream,
|
||||
() => ctx.sounds.play("dangerous_business:jester/scream", { follow: jester.id, loop: true }),
|
||||
);
|
||||
},
|
||||
pose(pose, time) {
|
||||
if (cranking.started) {
|
||||
@@ -200,6 +224,15 @@ export function register_jester_animator(ctx: ClientContext) {
|
||||
});
|
||||
}
|
||||
|
||||
// a sound that goes with a state: played once it holds, stopped once it doesn't
|
||||
function sound_while(holds: boolean, sound: PlayingSound | undefined, play: () => PlayingSound) {
|
||||
if (!holds) {
|
||||
sound?.stop();
|
||||
return undefined;
|
||||
}
|
||||
return sound ?? play();
|
||||
}
|
||||
|
||||
// clip as it walks, a second of it for ticks of walk_position, and standing as strongly as it isn't walking
|
||||
function walking(
|
||||
pose: EntityPose,
|
||||
|
||||
@@ -110,13 +110,16 @@ function register_facility_door(ctx: SharedContext) {
|
||||
});
|
||||
}
|
||||
|
||||
// the door component's params: "pairs_with" is the tag of doors it makes double doors with
|
||||
// the door component's params: "pairs_with" is the tag of doors it makes double doors with, and the sounds it makes
|
||||
// opening and closing
|
||||
export interface DoorParams {
|
||||
pairs_with: string;
|
||||
open_sound: string;
|
||||
close_sound: string;
|
||||
}
|
||||
|
||||
// what set_door_open needs, which shared, server and client phases all have
|
||||
type DoorContext = Pick<SharedContext, "tags"> & {
|
||||
// what set_door_open needs, which shared and server phases both have
|
||||
type DoorContext = Pick<SharedContext, "tags" | "sounds"> & {
|
||||
world: Pick<SharedContext["world"], "get_block" | "get_state" | "set_state">;
|
||||
};
|
||||
|
||||
@@ -128,11 +131,14 @@ function door_at(ctx: DoorContext, x: number, y: number, z: number, params: Door
|
||||
}
|
||||
|
||||
// opens (open 1) or closes (open 0) the door with a half at x y z: both its halves, and the other door of a double
|
||||
// door with it when it's open or closed like this one. players do it by clicking, monsters from their goals. returns
|
||||
// whether it changed
|
||||
// door with it when it's open or closed like this one, with its sound. players do it by clicking, monsters from their
|
||||
// goals. returns whether it changed
|
||||
export function set_door_open(ctx: DoorContext, x: number, y: number, z: number, open: number, params: DoorParams) {
|
||||
const lower = ctx.world.get_state(x, y, z, "half") ? y - 1 : y;
|
||||
const state = (name: string, at_x = x, at_z = z) => ctx.world.get_state(at_x, lower, at_z, name);
|
||||
if (state("open") !== open) {
|
||||
ctx.sounds.play(open ? params.open_sound : params.close_sound, x + 0.5, lower + 1, z + 0.5);
|
||||
}
|
||||
// both halves of the door whose lower half is at x z
|
||||
const set_halves = (at_x: number, at_z: number) => {
|
||||
if (ctx.world.get_block(at_x, lower + 1, at_z) === ctx.world.get_block(at_x, lower, at_z)) {
|
||||
|
||||
Reference in New Issue
Block a user