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
+3 -3
View File
@@ -18,14 +18,14 @@ async function setup() {
Deno.test("the power glove and feral claws go in the hands slot, and only work while worn", async () => {
const t = await setup();
// the hands slot is the only curios one, after the player's own menu's
// the hands slot is the second curios one, after the body slot, which are after the player's own menu's
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
t.game.tick();
assertEquals(t.alice.attribute(ATTRIBUTES.attack_damage), 1 + 4);
// swapped for the claws by hand: the glove's damage goes, the claws' speed comes
t.send(1, { type: "click", menu: 0, slot: 1, button: 0 });
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA, button: 0 });
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA + 1, button: 0 });
t.game.tick();
assertEquals(t.alice.attribute(ATTRIBUTES.attack_damage), 1);
assertEquals(t.alice.attribute(ATTRIBUTES.attack_speed), 4 * 1.3);
@@ -35,7 +35,7 @@ Deno.test("worn artifacts work again after rejoining, and say what they do", asy
const t = await setup();
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
const worn = t.take(1).findLast((m: Msg) => m.type === "container" && m.container === "extra").items;
assertEquals(worn[0].lore, "When worn:\n+4 Attack Damage");
assertEquals(worn[1].lore, "When worn:\n+4 Attack Damage");
t.game.on_disconnect(1);
t.join(1, "alice");
+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);
});
+1 -1
View File
@@ -28,7 +28,7 @@ Deno.test("the base game loads from mods/bworld", async () => {
// 7 kinds of log, planks and leaves
assertEquals(bworld(EverythingRegistry.entries("blocks")), 42);
// 42 items (25 of them tools) plus the item forms of the 37 blocks that have one
assertEquals(bworld(EverythingRegistry.entries("items")), 79);
assertEquals(bworld(EverythingRegistry.entries("items")), 80);
// bworld's 18 (4 wood tools, the wood watering can, 7 planks, the fishing rod, the smithing table), the cooking pot,
// stove, cutting board and wood knife are farmersdelight's
assertEquals(game.recipes.shaped.length, 22);
+2 -1
View File
@@ -384,13 +384,14 @@ Deno.test("menus: filters, data, buttons, closing, saving, and dropping what's i
assertEquals(menu_data(loaded.take(1)), undefined, "data is only sent again when it changes");
// breaking it closes the menu, runs on_close, and drops what was inside
const containers = loaded.game.containers.size;
loaded.send(1, { type: "break_block", x: 1, y: 100, z: 0 });
assert(loaded.take(1).some((m) => m.type === "close_menu"));
const logged = loaded.game.mods.storage.testmod.log as Record<string, unknown[]>;
assertEquals(logged.closed, [false, false, false]);
const dropped = loaded.game.item_entities().map((e) => e.item.to_data().id).sort();
assertEquals(dropped, ["bworld:coal", "bworld:stone"]);
assertEquals(loaded.game.containers.size, 0);
assertEquals(loaded.game.containers.size, containers - 1, "its container is gone");
Deno.removeSync(dir, { recursive: true });
});
+6 -6
View File
@@ -12,12 +12,12 @@ Deno.test("exhaustion eats saturation first, then hunger", () => {
const vitals = new Vitals();
const noop = () => {};
vitals.add_exhaustion(4.1);
vitals.tick(20, noop, noop);
vitals.tick(20, 20, noop, noop);
assertEquals([vitals.food, vitals.saturation], [20, 4]);
vitals.saturation = 0;
vitals.add_exhaustion(4);
vitals.tick(20, noop, noop);
vitals.tick(20, 20, noop, noop);
assertEquals([vitals.food, vitals.saturation], [19, 0]);
});
@@ -29,7 +29,7 @@ Deno.test("a full stomach heals, fast with saturation and slowly without, and st
// full hunger and saturation: every 10 ticks, up to a whole heart, paid for with exhaustion
const fast = new Vitals();
for (let i = 0; i < 10; i++) fast.tick(10, heal, damage);
for (let i = 0; i < 10; i++) fast.tick(10, 20, heal, damage);
assertAlmostEquals(healed, 5 / 6);
assertEquals(fast.exhaustion, 5);
@@ -38,7 +38,7 @@ Deno.test("a full stomach heals, fast with saturation and slowly without, and st
const slow = new Vitals();
slow.food = 18;
slow.saturation = 0;
for (let i = 0; i < 80; i++) slow.tick(10, heal, damage);
for (let i = 0; i < 80; i++) slow.tick(10, 20, heal, damage);
assertEquals(healed, 1);
// starving: 1 every 4 seconds, never below 1 health
@@ -46,9 +46,9 @@ Deno.test("a full stomach heals, fast with saturation and slowly without, and st
starving.food = 0;
starving.saturation = 0;
let health = 2;
for (let i = 0; i < 80; i++) starving.tick(health, heal, (amount) => health -= amount);
for (let i = 0; i < 80; i++) starving.tick(health, 20, heal, (amount) => health -= amount);
assertEquals(health, 1);
for (let i = 0; i < 400; i++) starving.tick(health, heal, (amount) => health -= amount);
for (let i = 0; i < 400; i++) starving.tick(health, 20, heal, (amount) => health -= amount);
assertEquals(health, 1);
assertEquals(hurt, 0);
});