BlueGit

timfa questward

Files

questward / server / tests / npc-equipment.test.js

npc-equipment.test.js

npc-equipment.test.js 3.1 KiB Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import { npcDefaultEquipment, npcClothDyeFromSeed, NPC_CLOTH_DYE_BYTE_MIN } from "../../shared/appearance/npcEquipment.js";
4import { layersFromSpawnerConfig } from "../../shared/appearance/layers.js";
5import { ItemId } from "../../shared/definitions/items.js";
6import { JewelryItemId } from "../../shared/definitions/jewelryItems.js";
7import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
8import { clothTierForItemId } from "../../shared/definitions/clothItems.js";
9import { itemDefinition } from "../../shared/definitions/items.js";
10import { mobComponents } from "../src/simulation/spawners.js";
11import { MobId } from "../../shared/definitions/mobs.js";
12
13test("npcDefaultEquipment picks deterministic garments from display name", () =>
14{
15 const a = npcDefaultEquipment("Ada Lovelace", "female");
16 const b = npcDefaultEquipment("Ada Lovelace", "female");
17 assert.deepEqual(a, b);
18 assert.ok(a.chest?.itemId);
19 assert.ok(clothTierForItemId(a.legs?.itemId));
20 const legsKey = itemDefinition(a.legs.itemId)?.key ?? "";
21 assert.ok(legsKey.endsWith("-shorts") || legsKey.endsWith("-skirt") || legsKey.endsWith("-trousers"));
22 assert.equal(a.boots?.itemId, LeatherItemId.leatherShoes);
23 assert.ok(a.chest.dyeColor);
24 assert.ok(a.legs.dyeColor);
25});
26
27test("npc cloth dyes stay above minimum channel", () =>
28{
29 const dye = npcClothDyeFromSeed("Test NPC", 3);
30 const min = NPC_CLOTH_DYE_BYTE_MIN / 255;
31 assert.ok(dye.r >= min);
32 assert.ok(dye.g >= min);
33 assert.ok(dye.b >= min);
34});
35
36test("humanoid spawner without equipment gets default clothing", () =>
37{
38 const components = mobComponents({
39 mobTypeId: MobId.humanoid,
40 tileX: 8,
41 tileY: 8,
42 displayName: "Village Guard",
43 sex: "male",
44 equipment: {},
45 spawnerId: "test"
46 });
47 const slots = components.equipment?.slots ?? {};
48 assert.ok(slots.chest?.itemId);
49 assert.ok(slots.legs?.itemId);
50 assert.equal(slots.boots?.itemId, LeatherItemId.leatherShoes);
51 assert.equal(slots.chest?.instance?.kind, "clothing");
52 assert.equal(slots.legs?.instance?.kind, "clothing");
53});
54
55test("authored spawner jewelry equips on humanoid NPCs", () =>
56{
57 const components = mobComponents({
58 mobTypeId: MobId.humanoid,
59 tileX: 8,
60 tileY: 8,
61 displayName: "Jeweler",
62 sex: "female",
63 equipment: {
64 ring: JewelryItemId.opalRing,
65 amulet: JewelryItemId.rubyAmulet
66 },
67 spawnerId: "test"
68 });
69 assert.equal(components.equipment.slots.ring.itemId, JewelryItemId.opalRing);
70 assert.equal(components.equipment.slots.amulet.itemId, JewelryItemId.rubyAmulet);
71});
72
73test("layersFromSpawnerConfig previews body gear for humanoid NPCs only", () =>
74{
75 assert.equal(layersFromSpawnerConfig({ mobTypeId: MobId.deer }), null);
76 const layers = layersFromSpawnerConfig({
77 mobTypeId: MobId.humanoid,
78 displayName: "Preview Bob",
79 sex: "male",
80 equipment: { weapon: { itemId: ItemId.stick } }
81 });
82 assert.ok(layers?.length >= 2);
83 assert.match(layers[0].sprite, /player-body-male/);
84 assert.ok(layers.some((layer) => layer.itemId === ItemId.stick));
85 assert.ok(layers.some((layer) => layer.itemId === LeatherItemId.leatherShoes));
86});