Track time on jester windup
This commit is contained in:
@@ -47,14 +47,16 @@ export function register_jester(ctx: ServerContext) {
|
||||
|
||||
ctx.entities.register_behavior(JESTER, (mob, goals) => {
|
||||
let state = mob.get_client_data<number>("state") ?? ROAMING;
|
||||
// ticks in its state
|
||||
let ticks = 0;
|
||||
// ticks in its state, going on from where one that was saved had got to
|
||||
let ticks = Math.max(0, ctx.world.time - (mob.get_client_data<number>("since") ?? ctx.world.time));
|
||||
// ticks left until it cranks, from when it first noticed someone
|
||||
let countdown: number | undefined;
|
||||
let followed: Player | undefined;
|
||||
const set_state = (next: number) => {
|
||||
state = next;
|
||||
ticks = 0;
|
||||
// when it started, by the world's time, so a client that comes upon it partway knows how far it's got
|
||||
mob.set_client_data("since", ctx.world.time);
|
||||
mob.set_client_data("state", next);
|
||||
if (next === AGGRO) mob.play_sound("dangerous_business:jester/pop");
|
||||
};
|
||||
@@ -159,8 +161,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. 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
|
||||
// clips did with expressions is here as code. its music box plays while it cranks, and it screams while it's popped.
|
||||
// a player who comes upon it partway sees and hears it from as far as it's got, by when its state started
|
||||
export function register_jester_animator(ctx: ClientContext) {
|
||||
const clip = (name: string) => ctx.render.clip(`dangerous_business:jester/${name}`);
|
||||
const idle = clip("idle");
|
||||
@@ -179,20 +181,19 @@ export function register_jester_animator(ctx: ClientContext) {
|
||||
let scream: PlayingSound | undefined;
|
||||
return {
|
||||
on_data(field, time) {
|
||||
if (field !== "state") return;
|
||||
if (field !== "state" && field !== "since") 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 }),
|
||||
);
|
||||
const since = jester.get_client_data<number>("since");
|
||||
// ticks it's been in its state
|
||||
const ticks = since === undefined ? 0 : Math.max(0, ctx.world.time - since);
|
||||
cranking.animate_when(state === CRANKING, time - ticks);
|
||||
popped.animate_when(state === AGGRO, time - ticks);
|
||||
// loops, so one played out of range comes in where it would be when the player comes near. the music box
|
||||
// is longer than the cranking, so it never goes around
|
||||
const play = (sound: string) =>
|
||||
ctx.sounds.play(sound, { follow: jester.id, loop: true, offset: ticks / 20 });
|
||||
theme = sound_while(state === CRANKING, theme, () => play("dangerous_business:jester/theme"));
|
||||
scream = sound_while(state === AGGRO, scream, () => play("dangerous_business:jester/scream"));
|
||||
},
|
||||
pose(pose, time) {
|
||||
if (cranking.started) {
|
||||
|
||||
Reference in New Issue
Block a user