Giant chesplate

This commit is contained in:
2026-10-01 16:58:30 -03:00
parent a7835261e1
commit 1fc92a7b00
21 changed files with 148 additions and 51 deletions
+44 -7
View File
@@ -1,6 +1,6 @@
// curios: accessory slots for items in the curios tags, next to the player's inventory, see
// mods/bworld/scripts/curios.ts
import { assertEquals } from "@std/assert";
import { assert, assertEquals } from "@std/assert";
import { PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
import { copy_dir, test_game } from "./helpers.ts";
import type { WorldSave } from "$/server/game/saves.ts";
@@ -47,9 +47,11 @@ Deno.test("the slot types some item goes in are in 2 columns left of the invento
const t = await setup();
t.game.on_disconnect(1);
const join = t.join(1, "alice");
// the body slot is there because the base game's giant chestplate goes in it
assertEquals(join.player_menu, [
{ x: -45, y: 7, icon: "bworld:empty_curio_slot" },
{ x: -27, y: 7, icon: "bworld:empty_ring_slot" },
{ x: -27, y: 7, icon: "bworld:empty_body_slot" },
{ x: -45, y: 25, icon: "bworld:empty_ring_slot" },
]);
});
@@ -62,11 +64,11 @@ Deno.test("items only go in the slots they fit, and fall out when the player die
const messages = t.take(1);
assertEquals(last_container(messages, "inventory").slice(0, 3), [null, null, null]);
assertEquals(last_container(messages, "inventory")[9], { id: "bworld:coal", count: 1 });
assertEquals(curios_items(messages), [{ id: "jewelry:amulet", count: 1 }, { id: "jewelry:ring", count: 1 }]);
assertEquals(curios_items(messages), [{ id: "jewelry:amulet", count: 1 }, null, { id: "jewelry:ring", count: 1 }]);
// and they come back out with a shift click, into the inventory
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA + 1, button: 0, shift: true });
assertEquals(curios_items(t.take(1))[1], null);
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA + 2, button: 0, shift: true });
assertEquals(curios_items(t.take(1))[2], null);
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
const player = t.game.players()[0];
@@ -74,7 +76,7 @@ Deno.test("items only go in the slots they fit, and fall out when the player die
const dropped = t.game.item_entities().map((e) => e.item.type_id).sort();
assertEquals(dropped, ["bworld:coal", "jewelry:amulet", "jewelry:ring"]);
t.game.tick();
assertEquals(curios_items(t.take(1)), [null, null]);
assertEquals(curios_items(t.take(1)), [null, null, null]);
});
Deno.test("curios worn when curios was a mod of its own are still worn", async () => {
@@ -89,7 +91,42 @@ Deno.test("curios worn when curios was a mod of its own are still worn", async (
delete level.mod_storage.bworld.curios;
const loaded = await setup({ ...save, level: JSON.stringify(level) });
const [ring] = loaded.game.players()[0].inventory_menu.extra.slice(1);
const [ring] = loaded.game.players()[0].inventory_menu.extra.slice(2);
assertEquals(ring.container.get_item(ring.index)?.to_data(), { id: "jewelry:ring", count: 1 });
assertEquals(loaded.game.mods.storage.curios, undefined);
});
Deno.test("the giant chestplate goes in the body slot and gives 20 more health while worn", async () => {
const t = await setup();
t.send(1, { type: "chat", text: "/give bworld:giant_chestplate" });
const slot = last_container(t.take(1), "inventory").findIndex((i: Msg) => i?.id === "bworld:giant_chestplate");
const alice = t.game.players()[0];
t.send(1, { type: "click", menu: 0, slot, button: 0, shift: true });
// what curios give is worked out each tick, from what changed
t.game.tick();
assertEquals(curios_items(t.take(1))[1], {
id: "bworld:giant_chestplate",
count: 1,
lore: "When worn:\n+20 Max Health",
});
assertEquals(alice.max_health, 40);
// like minecraft, more max health doesn't heal, regenerating fills it
assertEquals(alice.health, 20);
for (let i = 0; i < 20 * 20; i++) t.game.tick();
assert(alice.health > 20, `regenerated to ${alice.health}`);
const vitals = t.take(1).findLast((m: Msg) => m.type === "vitals");
assertEquals(vitals.max_health, 40);
// it's kept over rejoining, the chestplate's health comes back before the health is checked against it
const health = alice.health;
t.game.on_disconnect(1);
t.join(1, "alice");
assertEquals(t.game.players()[0].health, health);
// taking it off takes the health over 20 away
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA + 1, button: 0, shift: true });
t.game.tick();
assertEquals(t.game.players()[0].max_health, 20);
assertEquals(t.game.players()[0].health, 20);
});