Make durability work like sunlit valley

This commit is contained in:
2026-09-29 18:00:32 -03:00
parent 8fe581ea93
commit f76cf2bf38
30 changed files with 70 additions and 28 deletions
+21
View File
@@ -2,6 +2,8 @@
import { assert, assertAlmostEquals, assertEquals } from "@std/assert";
import { MAX_HEALTH, Vitals } from "$/server/game/vitals.ts";
import { test_game } from "./helpers.ts";
import { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
import { ItemStack } from "$/common/inventory.ts";
// deno-lint-ignore no-explicit-any
type Msg = any;
@@ -147,6 +149,25 @@ Deno.test("dying drops everything, tells everyone, and respawns with full health
assertEquals(t.game.item_entities().map((e) => e.item.to_data()), [{ id: "bworld:coal", count: 5 }]);
});
Deno.test("dying takes 1 durability off every tool carried, and ones that run out break", async () => {
const t = await setup();
const max = EverythingRegistry.get<ItemRegistry>("items", "bworld:iron_pickaxe")!.tool!.durability;
const pickaxe = new ItemStack("bworld:iron_pickaxe");
pickaxe.damage(max - 2);
t.player.inventory.set_item(0, pickaxe);
t.player.inventory.set_item(1, new ItemStack("bworld:coal", 5));
t.game.damage_player(t.player, 25, "fall");
const dropped = t.game.item_entities().map((e) => e.item);
assertEquals(dropped.map((item) => item.durability()), [1, undefined]);
assertEquals(dropped[1].to_data(), { id: "bworld:coal", count: 5 });
for (const e of t.game.item_entities()) e.remove();
t.player.inventory.set_item(0, dropped[0]);
t.game.damage_player(t.player, 25, "fall");
assertEquals(t.game.item_entities(), []);
});
Deno.test("mods can stop or change damage, and hurt, heal and feed players", async () => {
const t = await setup();
t.game.mods.before.player_damage.for_mod("test").subscribe((event) => {