Change curios to always show on inventory

This commit is contained in:
2026-10-01 16:35:41 -03:00
parent deba36260e
commit 3dc7d2adee
24 changed files with 244 additions and 159 deletions
+9 -13
View File
@@ -1,7 +1,8 @@
// artifacts: items worn in curios slots that change the wearer's attributes, see mods/artifacts
import { assertEquals } from "@std/assert";
import { ATTRIBUTES } from "$/server/game/entity/attributes.ts";
import { menu_items, opened_menu, test_game } from "./helpers.ts";
import { PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
import { test_game } from "./helpers.ts";
// deno-lint-ignore no-explicit-any
type Msg = any;
@@ -17,18 +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();
t.send(1, { type: "mod", channel: "curios:open", data: {} });
const menu = opened_menu(t.take(1));
// the hands slot, then the inventory's
assertEquals(menu.slots.map((s: Msg) => s.icon).filter(Boolean), ["curios:empty_hands_slot"]);
t.send(1, { type: "click", menu: menu.id, slot: 1, button: 0, shift: true });
// the hands slot is the only curios one, 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: menu.id, slot: 2, button: 0 });
t.send(1, { type: "click", menu: menu.id, slot: 0, button: 0 });
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.game.tick();
assertEquals(t.alice.attribute(ATTRIBUTES.attack_damage), 1);
assertEquals(t.alice.attribute(ATTRIBUTES.attack_speed), 4 * 1.3);
@@ -36,10 +33,9 @@ Deno.test("the power glove and feral claws go in the hands slot, and only work w
Deno.test("worn artifacts work again after rejoining, and say what they do", async () => {
const t = await setup();
t.send(1, { type: "mod", channel: "curios:open", data: {} });
const { id } = opened_menu(t.take(1));
t.send(1, { type: "click", menu: id, slot: 1, button: 0, shift: true });
assertEquals(menu_items(t.take(1))[0].lore, "When worn:\n+4 Attack Damage");
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");
t.game.on_disconnect(1);
t.join(1, "alice");
+3 -1
View File
@@ -199,6 +199,8 @@ Deno.test("a smithing table upgrades a wooden pickaxe with 5 stone, using up exa
const pickaxe = slot_of(messages, "bworld:wood_pickaxe");
const stone = slot_of(messages, "bworld:stone");
// mods' own, like the player's curios
const containers = t.game.containers.size;
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
const opened = opened_menu(t.take(1));
assertEquals(opened.slots.slice(0, 4).map((s: Msg) => s.output ?? false), [false, false, false, true]);
@@ -225,7 +227,7 @@ Deno.test("a smithing table upgrades a wooden pickaxe with 5 stone, using up exa
inventory.sort((a: Msg, b: Msg) => a.id.localeCompare(b.id)),
[{ id: "bworld:stone", count: 2 }, { id: "bworld:stone_pickaxe", count: 1 }],
);
assertEquals(t.game.containers.size, 0);
assertEquals(t.game.containers.size, containers, "its slots are gone");
});
Deno.test("a smithing result can't be taken once its inputs are gone, even before it updates", async () => {
+26 -31
View File
@@ -1,6 +1,7 @@
// curios: accessory slots for items in the curios tags, opened over mod channels, see mods/curios
import { assert, assertEquals } from "@std/assert";
import { copy_dir, menu_items, opened_menu, test_game } from "./helpers.ts";
// curios: accessory slots for items in the curios tags, next to the player's inventory, see mods/curios
import { assertEquals } from "@std/assert";
import { PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
import { copy_dir, test_game } from "./helpers.ts";
// deno-lint-ignore no-explicit-any
type Msg = any;
@@ -32,45 +33,39 @@ async function setup() {
return t;
}
Deno.test("the curios screen shows the slot types some item goes in, with their icons", async () => {
// what's in the curios slots, the ones curios added to the player's own menu, as last synced
const curios_items = (messages: Msg[]) => last_container(messages, "extra");
Deno.test("the slot types some item goes in are in 2 columns left of the inventory, with their icons", async () => {
const t = await setup();
t.send(1, { type: "mod", channel: "curios:open", data: {} });
const menu = opened_menu(t.take(1));
assertEquals(menu.menu_type, "curios:curios");
// in the middle of the row, then the player's inventory
assertEquals(menu.slots.slice(0, 2), [
{ x: 70, y: 17, icon: "curios:empty_curio_slot" },
{ x: 88, y: 17, icon: "curios:empty_ring_slot" },
t.game.on_disconnect(1);
const join = t.join(1, "alice");
assertEquals(join.player_menu, [
{ x: -45, y: 7, icon: "curios:empty_curio_slot" },
{ x: -27, y: 7, icon: "curios:empty_ring_slot" },
]);
assertEquals(menu.slots.length, 2 + 36);
});
Deno.test("items only go in the slots they fit, and fall out when the player dies", async () => {
const t = await setup();
t.send(1, { type: "mod", channel: "curios:open", data: {} });
const { id } = opened_menu(t.take(1));
// coal fits nowhere, the ring only in the ring slot, and #curios:curio items in any slot, the curio slot first.
// the inventory's slots come after the 2 curios ones
for (const index of [2, 0, 1]) t.send(1, { type: "click", menu: id, slot: 2 + index, button: 0, shift: true });
// coal fits nowhere so it moves to the rest of the inventory, the ring only goes in the ring slot, and
// #curios:curio items in any slot, the curio slot first
for (const slot of [2, 0, 1]) t.send(1, { type: "click", menu: 0, slot, button: 0, shift: true });
const messages = t.take(1);
assertEquals(last_container(messages, "inventory").slice(0, 3), [null, null, { id: "bworld:coal", count: 1 }]);
const curios = menu_items(messages);
assertEquals(curios[0], { id: "jewelry:amulet", count: 1 });
assertEquals(curios[1], { id: "jewelry:ring", count: 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 }]);
// 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: 0, button: 0, shift: true });
const player = t.game.players()[0];
t.game.damage_player(player, 100, "fall");
const dropped = t.game.item_entities().map((e) => e.item.type_id).sort();
assertEquals(dropped, ["bworld:coal", "jewelry:amulet", "jewelry:ring"]);
t.send(1, { type: "mod", channel: "curios:open", data: {} });
assertEquals(menu_items(t.take(1)).filter(Boolean), []);
});
Deno.test("mod messages that are too big or too many are dropped", async () => {
const t = await setup();
t.send(1, { type: "mod", channel: "curios:open", data: "x".repeat(20_000) });
assertEquals(t.take(1).filter((m) => m.type === "open_menu"), []);
for (let i = 0; i < 100; i++) t.send(1, { type: "mod", channel: "curios:open", data: {} });
assert(t.take(1).filter((m) => m.type === "open_menu").length < 100);
t.game.tick();
assertEquals(curios_items(t.take(1)), [null, null]);
});
+12
View File
@@ -57,6 +57,8 @@ export function setup(ctx: ServerContext) {
on_use(item, params: { power: number }, player) { log("use", [item.id, params.power, player.name]); },
});
ctx.net.on("testmod:ping", () => log("ping"));
ctx.system.run_timeout(() => log("timeout", ctx.system.current_tick), 5);
const interval = ctx.system.run_interval(() => {
log("interval", ctx.system.current_tick);
@@ -391,3 +393,13 @@ Deno.test("menus: filters, data, buttons, closing, saving, and dropping what's i
assertEquals(loaded.game.containers.size, 0);
Deno.removeSync(dir, { recursive: true });
});
Deno.test("mod messages that are too big or too many are dropped", async () => {
const { send, log, dir } = await setup();
send(1, { type: "mod", channel: "testmod:ping", data: "x".repeat(20_000) });
assertEquals(log().ping, undefined);
for (let i = 0; i < 100; i++) send(1, { type: "mod", channel: "testmod:ping", data: {} });
// 60 a second, counting the big one, and this could be split over two seconds
assert(log().ping.length > 0 && log().ping.length < 100);
Deno.removeSync(dir, { recursive: true });
});