Jester time

This commit is contained in:
2026-11-21 23:07:42 -03:00
parent 0c711b8163
commit f308ab52f1
14 changed files with 3317 additions and 395 deletions
+70
View File
@@ -19,6 +19,7 @@ const FLOOR = "dangerous_business:concrete_floor";
const DEATH = "dangerous_business:death";
const PIPE = "dangerous_business:double_steel_pipes";
const COILHEAD = "dangerous_business:coilhead";
const JESTER = "dangerous_business:jester";
const FACTORY_DOOR = "dangerous_business:factory_door";
// alice on a concrete floor at y 100, south of 0 100 0 and looking north, holding each of the blocks. it's a game of
@@ -256,6 +257,51 @@ Deno.test("a coilhead seen while it waits at a closed door stops waiting, and do
assertEquals(coilhead.navigation.blocked_by, undefined);
});
// a jester 6 blocks north of alice, in a state from its client data like one that was saved
function spawn_jester(t: Awaited<ReturnType<typeof setup>>["t"], state?: number) {
const jester = create_entity(t.game.entities, JESTER)! as Mob;
jester.set_position(0.5, 100, -2.5);
if (state !== undefined) jester.client_data = { state };
t.game.entities.add_entity(jester);
return jester;
}
Deno.test("a jester follows a player it sees without hurting them, then winds its crank standing still", async () => {
const { t } = await setup();
const alice = t.game.players()[0];
const jester = spawn_jester(t);
for (let i = 0; i < 100; i++) t.game.tick();
assert(jester.z > -1, `it stayed at z ${jester.z}, away from her`);
assertEquals(alice.health, alice.max_health);
for (let i = 0; i < 2000 && jester.client_data.state !== 2; i++) t.game.tick();
assertEquals(jester.client_data.state, 2);
const at = [jester.x, jester.z];
t.send(1, { type: "move", x: -2.5, y: 100, z: 3.5, yaw: 0, pitch: 0 });
for (let i = 0; i < 100; i++) t.game.tick();
assertEquals([jester.x, jester.z], at);
});
Deno.test("a popped jester runs down the nearest player faster and faster, and boxes up once they're out", async () => {
const { t } = await setup();
const alice = t.game.players()[0];
const jester = spawn_jester(t, 3);
const speed = () => t.game.mods.mob(jester).attribute("cubi:movement_speed");
const walking = speed();
for (let i = 0; i < 200 && alice.health === alice.max_health; i++) t.game.tick();
assert(alice.health < alice.max_health, "it never got to her");
assert(speed() > walking);
const chasing = speed();
for (let i = 0; i < 300; i++) t.game.tick();
assert(speed() > chasing, "it didn't get any faster");
// up on the surface, out of the facility
alice.set_position(0.5, 160, 3.5);
t.game.tick();
assertEquals(jester.client_data.state, 1);
assertEquals(speed(), walking);
});
// last, since it loads the mod the way a player gets it, in place of the server's
Deno.test("a coilhead's head springs back and forth when it freezes, and stays still when it stands", async () => {
const dir = Deno.makeTempDirSync({ prefix: "dangerous_business_client_" });
@@ -279,3 +325,27 @@ Deno.test("a coilhead's head springs back and forth when it freezes, and stays s
assertEquals(head(true, 1200), head(false, 1200));
Deno.removeSync(dir, { recursive: true });
});
Deno.test("a jester keeps its tendrils in the box until it pops, and turns its crank while it winds", async () => {
const dir = Deno.makeTempDirSync({ prefix: "dangerous_business_client_" });
copy_dir("mods/dangerous_business", `${dir}/dangerous_business`);
await load_as_player(dir);
const pose = (state: number | undefined, time: number) => {
const jester = {
id: "e1",
type: JESTER,
data: state === undefined ? {} : { client_data: { state } },
age: 0,
yaw: 0,
head_yaw: 0,
pitch: 0,
walk_animation: () => ({ position: 0, speed: 0 }),
attack_animation: () => 0,
};
return animation_for(jester)!.pose(time)!;
};
assertEquals(pose(undefined, 10).get("tendrils")!.scale, [0, 0, 0]);
assertNotEquals(pose(3, 100).get("tendrils")!.scale, [0, 0, 0]);
assertNotEquals(pose(2, 5).get("crank")!.rotation, pose(2, 15).get("crank")!.rotation);
Deno.removeSync(dir, { recursive: true });
});
+13
View File
@@ -4,6 +4,7 @@
// mobs following paths, see server/game/entity/navigation.ts
import { assert, assertEquals } from "@std/assert";
import { test_game, test_mob } from "./helpers.ts";
import { MeleeAttackGoal } from "@/server/game/entity/goals.ts";
// two rooms on a stone floor at y 99, split by a wall at x 3 with a doorway 2 high at z 4. a goal-less mob in the
// west room at 0.5 100 0.5, and alice in its corner, so it thinks
@@ -81,3 +82,15 @@ Deno.test("a script's mob walks its way, and stops when told", async () => {
assert(Math.hypot(ref.position.x - x, ref.position.z - z) < 0.5);
assertEquals(ref.blocked_by, undefined);
});
Deno.test("a mob going after its target stops when a script lets the target go partway through its thinking", async () => {
const { game, mob } = await rooms();
const melee = new MeleeAttackGoal(mob);
mob.target = game.players()[0];
assert(melee.can_use());
melee.start();
melee.tick();
mob.target = undefined;
melee.tick();
assert(!melee.can_continue_to_use());
});