Undergarden mod !
This commit is contained in:
@@ -35,6 +35,7 @@ Deno.test("welcome lists what to download, and nothing happens until ready", asy
|
||||
"artifacts",
|
||||
"farmersdelight",
|
||||
"recipe_viewer",
|
||||
"undergarden",
|
||||
]);
|
||||
assert(welcome.mods.every((m: { sha256: string; file: string }) => m.sha256 && m.file));
|
||||
assert(!("players" in welcome) && !("changes" in welcome), "welcome shouldn't have world state");
|
||||
|
||||
@@ -46,7 +46,7 @@ Deno.test("an entity needs a texture and a size", () => {
|
||||
Deno.test("an entity without a model is drawn as its texture, and a scripted one has no ai", () => {
|
||||
assertEquals(validate_entity({ id: "a:b", texture: "a:b", behavior: "scripted", width: 0.25, height: 0.25 }), []);
|
||||
assertEquals(validate_entity({ id: "a:b", texture: "a:b", behavior: "flying", width: 0.25, height: 0.25 }), [
|
||||
'behavior must be "animal" or "scripted"',
|
||||
'behavior must be "animal", "monster" or "scripted"',
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// "monster" entities go after players and whoever hurts them, like undergarden's rotwalker, see mods/undergarden
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { create_entity } from "$/server/game/entity/entity_types.ts";
|
||||
import { Mob } from "$/server/game/entity/mob.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
// a stone floor with alice on it, and a rotwalker 3 blocks away
|
||||
async function setup() {
|
||||
const t = await test_game("mods");
|
||||
t.join(1, "alice");
|
||||
for (let x = -8; x <= 8; x++) {
|
||||
for (let z = -8; z <= 8; z++) t.game.set_block(x, 99, z, "bworld:stone");
|
||||
}
|
||||
t.send(1, { type: "move", x: 0.5, y: 100, z: 0.5, yaw: 0, pitch: 0 });
|
||||
const rotwalker = create_entity(t.game.entities, "undergarden:rotwalker") as Mob;
|
||||
rotwalker.set_position(0.5, 100, 3.5);
|
||||
t.game.entities.add_entity(rotwalker);
|
||||
t.take(1);
|
||||
const ticks = (n: number) => {
|
||||
for (let i = 0; i < n; i++) t.game.tick();
|
||||
};
|
||||
return { ...t, rotwalker, alice: t.game.players()[0], ticks };
|
||||
}
|
||||
|
||||
Deno.test("a rotwalker has the original's stats, and despawns when nobody is near", async () => {
|
||||
const { rotwalker } = await setup();
|
||||
assert(rotwalker instanceof Mob);
|
||||
assertEquals([rotwalker.width, rotwalker.height, rotwalker.max_health], [0.8, 2.5, 40]);
|
||||
assertEquals(rotwalker.remove_when_far_away(1000), true);
|
||||
});
|
||||
|
||||
Deno.test("a rotwalker walks up to a player it sees and hits them for its attack damage, swinging", async () => {
|
||||
const { rotwalker, alice, ticks, take } = await setup();
|
||||
let swung = false;
|
||||
for (let i = 0; i < 200 && alice.health === 20; i++) {
|
||||
ticks(1);
|
||||
swung ||= take(1).some((m) => m.type === "entity_event" && m.id === rotwalker.id && m.event === "swing");
|
||||
}
|
||||
assertEquals(rotwalker.target, alice);
|
||||
assertEquals(alice.health, 20 - 5);
|
||||
assert(swung, "players nearby see it swing");
|
||||
});
|
||||
|
||||
Deno.test("a monster goes after whoever hurt it, before the nearest player", async () => {
|
||||
const { rotwalker, alice, ticks, join, send, game } = await setup();
|
||||
join(2, "bob");
|
||||
send(2, { type: "move", x: 0.5, y: 100, z: 5.5, yaw: 0, pitch: 0 });
|
||||
const bob = game.players().find((p) => p.name === "bob")!;
|
||||
rotwalker.target = alice;
|
||||
ticks(5);
|
||||
send(2, { type: "attack_entity", id: rotwalker.id });
|
||||
// a bit less than bob's 1, its armor (physical shielding) takes some
|
||||
assert(rotwalker.health < 40);
|
||||
ticks(1);
|
||||
assertEquals(rotwalker.target, bob);
|
||||
});
|
||||
Reference in New Issue
Block a user