BlueGit

timfa questward

Keep ring/bracelet/amulet when normalizing spawner equipment.

Spawner save used a clothing-only equipment template, so jewelry slots set in the editor were stripped on normalize.

timfa Tim Falken · pushed by timfa

Authored 2026-09-02 · 2 months ago

Hash
2b51d15677226cee86f4dca1bae1fa883176a3cf
Parent
c2178a80
3 files changed +30 −13
server/tests/npc-equipment.test.js +9 −5
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
3 3 import { npcDefaultEquipment, npcClothDyeFromSeed, NPC_CLOTH_DYE_BYTE_MIN } from "../../shared/appearance/npcEquipment.js";
4 4 import { layersFromSpawnerConfig } from "../../shared/appearance/layers.js";
5 5 import { ItemId } from "../../shared/definitions/items.js";
6 import { JewelryItemId } from "../../shared/definitions/jewelryItems.js";
6 7 import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
7 8 import { clothTierForItemId } from "../../shared/definitions/clothItems.js";
8 9 import { itemDefinition } from "../../shared/definitions/items.js";
@@ -51,19 +52,22 @@ test("humanoid spawner without equipment gets default clothing", () =>
51 52 assert.equal(slots.legs?.instance?.kind, "clothing");
52 53 });
53 54
54 test("authored spawner chest overrides default clothing", () =>
55 test("authored spawner jewelry equips on humanoid NPCs", () =>
55 56 {
56 57 const components = mobComponents({
57 58 mobTypeId: MobId.humanoid,
58 59 tileX: 8,
59 60 tileY: 8,
60 displayName: "Tailor",
61 displayName: "Jeweler",
61 62 sex: "female",
62 equipment: { chest: ItemId.clothShirt },
63 equipment: {
64 ring: JewelryItemId.opalRing,
65 amulet: JewelryItemId.rubyAmulet
66 },
63 67 spawnerId: "test"
64 68 });
65 assert.equal(components.equipment.slots.chest.itemId, ItemId.clothShirt);
66 assert.equal(components.equipment.slots.chest.instance, undefined);
69 assert.equal(components.equipment.slots.ring.itemId, JewelryItemId.opalRing);
70 assert.equal(components.equipment.slots.amulet.itemId, JewelryItemId.rubyAmulet);
67 71 });
68 72
69 73 test("layersFromSpawnerConfig previews body gear for humanoid NPCs only", () =>
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
3import { npcDefaultEquipment, npcClothDyeFromSeed, NPC_CLOTH_DYE_BYTE_MIN } from "../../shared/appearance/npcEquipment.js";
3import { npcDefaultEquipment, npcClothDyeFromSeed, NPC_CLOTH_DYE_BYTE_MIN } from "../../shared/appearance/npcEquipment.js";
4import { layersFromSpawnerConfig } from "../../shared/appearance/layers.js";
4import { layersFromSpawnerConfig } from "../../shared/appearance/layers.js";
5import { ItemId } from "../../shared/definitions/items.js";
5import { ItemId } from "../../shared/definitions/items.js";
6import { JewelryItemId } from "../../shared/definitions/jewelryItems.js";
6import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
7import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
7import { clothTierForItemId } from "../../shared/definitions/clothItems.js";
8import { clothTierForItemId } from "../../shared/definitions/clothItems.js";
8import { itemDefinition } from "../../shared/definitions/items.js";
9import { itemDefinition } from "../../shared/definitions/items.js";
@@ -51,19 +52,22 @@ test("humanoid spawner without equipment gets default clothing", () =>
51 assert.equal(slots.legs?.instance?.kind, "clothing");
52 assert.equal(slots.legs?.instance?.kind, "clothing");
52});
53});
53
54
54test("authored spawner chest overrides default clothing", () =>
55test("authored spawner jewelry equips on humanoid NPCs", () =>
55{
56{
56 const components = mobComponents({
57 const components = mobComponents({
57 mobTypeId: MobId.humanoid,
58 mobTypeId: MobId.humanoid,
58 tileX: 8,
59 tileX: 8,
59 tileY: 8,
60 tileY: 8,
60 displayName: "Tailor",
61 displayName: "Jeweler",
61 sex: "female",
62 sex: "female",
62 equipment: { chest: ItemId.clothShirt },
63 equipment: {
64 ring: JewelryItemId.opalRing,
65 amulet: JewelryItemId.rubyAmulet
66 },
63 spawnerId: "test"
67 spawnerId: "test"
64 });
68 });
65 assert.equal(components.equipment.slots.chest.itemId, ItemId.clothShirt);
69 assert.equal(components.equipment.slots.ring.itemId, JewelryItemId.opalRing);
66 assert.equal(components.equipment.slots.chest.instance, undefined);
70 assert.equal(components.equipment.slots.amulet.itemId, JewelryItemId.rubyAmulet);
67});
71});
68
72
69test("layersFromSpawnerConfig previews body gear for humanoid NPCs only", () =>
73test("layersFromSpawnerConfig previews body gear for humanoid NPCs only", () =>
server/tests/shop.test.js +16 −0
@@ -16,6 +16,7 @@ import
16 16 lerp
17 17 } from "../../shared/shop/pricing.js";
18 18 import { ItemId, listAllItemPickerEntries } from "../../shared/definitions/items.js";
19 import { JewelryItemId } from "../../shared/definitions/jewelryItems.js";
19 20 import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";
20 21 import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js";
21 22 import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
@@ -254,6 +255,21 @@ test("humanoid spawner config keeps sex equipment sells quantities and buysItems
254 255 assert.equal(config.maxAlive, 1);
255 256 });
256 257
258 test("humanoid spawner config keeps jewelry equipment slots", () =>
259 {
260 const config = normalizeSpawnerConfig({
261 mobTypeId: MobId.humanoid,
262 equipment: {
263 ring: JewelryItemId.opalRing,
264 bracelet: JewelryItemId.diamondBracelet,
265 amulet: JewelryItemId.rubyAmulet
266 }
267 }, "jeweler-npc");
268 assert.equal(config.equipment.ring, JewelryItemId.opalRing);
269 assert.equal(config.equipment.bracelet, JewelryItemId.diamondBracelet);
270 assert.equal(config.equipment.amulet, JewelryItemId.rubyAmulet);
271 });
272
257 273 test("shopkeeper with buysItems accepts paper from the player", () =>
258 274 {
259 275 const harness = makeSimulation({ workerCount: 1 });
@@ -16,6 +16,7 @@ import
16 lerp
16 lerp
17 } from "../../shared/shop/pricing.js";
17 } from "../../shared/shop/pricing.js";
18import { ItemId, listAllItemPickerEntries } from "../../shared/definitions/items.js";
18import { ItemId, listAllItemPickerEntries } from "../../shared/definitions/items.js";
19import { JewelryItemId } from "../../shared/definitions/jewelryItems.js";
19import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";
20import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";
20import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js";
21import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js";
21import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
22import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
@@ -254,6 +255,21 @@ test("humanoid spawner config keeps sex equipment sells quantities and buysItems
254 assert.equal(config.maxAlive, 1);
255 assert.equal(config.maxAlive, 1);
255});
256});
256
257
258test("humanoid spawner config keeps jewelry equipment slots", () =>
259{
260 const config = normalizeSpawnerConfig({
261 mobTypeId: MobId.humanoid,
262 equipment: {
263 ring: JewelryItemId.opalRing,
264 bracelet: JewelryItemId.diamondBracelet,
265 amulet: JewelryItemId.rubyAmulet
266 }
267 }, "jeweler-npc");
268 assert.equal(config.equipment.ring, JewelryItemId.opalRing);
269 assert.equal(config.equipment.bracelet, JewelryItemId.diamondBracelet);
270 assert.equal(config.equipment.amulet, JewelryItemId.rubyAmulet);
271});
272
257test("shopkeeper with buysItems accepts paper from the player", () =>
273test("shopkeeper with buysItems accepts paper from the player", () =>
258{
274{
259 const harness = makeSimulation({ workerCount: 1 });
275 const harness = makeSimulation({ workerCount: 1 });
shared/definitions/mobs.js +5 −8
@@ -6,6 +6,7 @@ import { RangedItemId } from "./rangedItems.js";
6 6 import { ArmourItemId } from "./armourItems.js";
7 7 import { WoodItemId } from "./woodItems.js";
8 8 import { ItemId } from "./items.js";
9 import { EQUIPMENT_SLOTS } from "../items/inventory.js";
9 10 import { spellDefinition } from "./spells.js";
10 11 import { ClothTier } from "./materialTiers.js";
11 12 import { ClothItemId } from "./clothItems.js";
@@ -534,14 +535,10 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
534 535
535 536 function emptySpawnerEquipment ()
536 537 {
537 return {
538 head: null,
539 chest: null,
540 legs: null,
541 boots: null,
542 weapon: null,
543 offhand: null
544 };
538 const equipment = {};
539 for (const slot of EQUIPMENT_SLOTS)
540 { equipment[slot] = null; }
541 return equipment;
545 542 }
546 543
547 544 /**
@@ -6,6 +6,7 @@ import { RangedItemId } from "./rangedItems.js";
6import { ArmourItemId } from "./armourItems.js";
6import { ArmourItemId } from "./armourItems.js";
7import { WoodItemId } from "./woodItems.js";
7import { WoodItemId } from "./woodItems.js";
8import { ItemId } from "./items.js";
8import { ItemId } from "./items.js";
9import { EQUIPMENT_SLOTS } from "../items/inventory.js";
9import { spellDefinition } from "./spells.js";
10import { spellDefinition } from "./spells.js";
10import { ClothTier } from "./materialTiers.js";
11import { ClothTier } from "./materialTiers.js";
11import { ClothItemId } from "./clothItems.js";
12import { ClothItemId } from "./clothItems.js";
@@ -534,14 +535,10 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
534
535
535function emptySpawnerEquipment ()
536function emptySpawnerEquipment ()
536{
537{
537 return {
538 const equipment = {};
538 head: null,
539 for (const slot of EQUIPMENT_SLOTS)
539 chest: null,
540 { equipment[slot] = null; }
540 legs: null,
541 return equipment;
541 boots: null,
542 weapon: null,
543 offhand: null
544 };
545}
542}
546
543
547/**
544/**