BlueGit

timfa questward

Files

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

npc-equipment.test.js

npc-equipment.test.js 2.3 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 { ItemId } from "../../shared/definitions/items.js";
5import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
6import { clothTierForItemId } from "../../shared/definitions/clothItems.js";
7import { itemDefinition } from "../../shared/definitions/items.js";
8import { mobComponents } from "../src/simulation/spawners.js";
9import { MobId } from "../../shared/definitions/mobs.js";
10
11test("npcDefaultEquipment picks deterministic garments from display name", () =>
12{
13 const a = npcDefaultEquipment("Ada Lovelace", "female");
14 const b = npcDefaultEquipment("Ada Lovelace", "female");
15 assert.deepEqual(a, b);
16 assert.ok(a.chest?.itemId);
17 assert.ok(clothTierForItemId(a.legs?.itemId));
18 const legsKey = itemDefinition(a.legs.itemId)?.key ?? "";
19 assert.ok(legsKey.endsWith("-shorts") || legsKey.endsWith("-skirt") || legsKey.endsWith("-trousers"));
20 assert.equal(a.boots?.itemId, LeatherItemId.leatherShoes);
21 assert.ok(a.chest.dyeColor);
22 assert.ok(a.legs.dyeColor);
23});
24
25test("npc cloth dyes stay above minimum channel", () =>
26{
27 const dye = npcClothDyeFromSeed("Test NPC", 3);
28 const min = NPC_CLOTH_DYE_BYTE_MIN / 255;
29 assert.ok(dye.r >= min);
30 assert.ok(dye.g >= min);
31 assert.ok(dye.b >= min);
32});
33
34test("humanoid spawner without equipment gets default clothing", () =>
35{
36 const components = mobComponents({
37 mobTypeId: MobId.humanoid,
38 tileX: 8,
39 tileY: 8,
40 displayName: "Village Guard",
41 sex: "male",
42 equipment: {},
43 spawnerId: "test"
44 });
45 const slots = components.equipment?.slots ?? {};
46 assert.ok(slots.chest?.itemId);
47 assert.ok(slots.legs?.itemId);
48 assert.equal(slots.boots?.itemId, LeatherItemId.leatherShoes);
49 assert.equal(slots.chest?.instance?.kind, "clothing");
50 assert.equal(slots.legs?.instance?.kind, "clothing");
51});
52
53test("authored spawner chest overrides default clothing", () =>
54{
55 const components = mobComponents({
56 mobTypeId: MobId.humanoid,
57 tileX: 8,
58 tileY: 8,
59 displayName: "Tailor",
60 sex: "female",
61 equipment: { chest: ItemId.clothShirt },
62 spawnerId: "test"
63 });
64 assert.equal(components.equipment.slots.chest.itemId, ItemId.clothShirt);
65 assert.equal(components.equipment.slots.chest.instance, undefined);
66});