BlueGit

timfa questward

Merge branch 'feature/potion-descriptions'

timfa Tim Falken · pushed by timfa

Authored 2026-09-04 · 2 months ago

Hash
4cb4ddbec34a3566ae02be3a499667f579192f69
3 files changed +49 −6
server/tests/alchemy.test.js +26 −1
@@ -1,7 +1,7 @@
1 1 import test from "node:test";
2 2 import assert from "node:assert/strict";
3 3 import { BlockType } from "../../shared/definitions/tiles.js";
4 import { ItemId, itemDefinition } from "../../shared/definitions/items.js";
4 import { ItemId, itemDefinition, itemDescription } from "../../shared/definitions/items.js";
5 5 import { flowerItemInstance } from "../../shared/definitions/dyes.js";
6 6 import { AlchemyStepKind } from "../../shared/definitions/alchemy.js";
7 7 import
@@ -68,6 +68,31 @@ test("recipe paper body resolves ingredient keys to display names", () =>
68 68 );
69 69 });
70 70
71 test("potion item descriptions come from alchemy defs without repeating the name", () =>
72 {
73 const stack = {
74 itemId: ItemId.potion,
75 quantity: 1,
76 instance: {
77 kind: "potion",
78 potionKey: "lesserHealthTonic",
79 displayName: "Lesser health tonic",
80 unstable: false
81 }
82 };
83 const desc = itemDescription(stack);
84 assert.equal(desc, alchemyPotionDefinition("lesserHealthTonic").description);
85 assert.doesNotMatch(desc, /Lesser health tonic/i);
86 assert.equal(
87 itemDescription({
88 itemId: ItemId.potion,
89 quantity: 1,
90 instance: { kind: "potion", potionKey: "x", displayName: "Bad", unstable: true }
91 }),
92 "The brew smells wrong — best sipped with caution."
93 );
94 });
95
71 96 test("lesser health tonic ratios and steps evaluate to a success batch", () =>
72 97 {
73 98 const potion = resolvedAlchemyPotions().find((entry) => entry.potionKey === "lesserHealthTonic");
@@ -1,7 +1,7 @@
1import test from "node:test";
1import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import { BlockType } from "../../shared/definitions/tiles.js";
3import { BlockType } from "../../shared/definitions/tiles.js";
4import { ItemId, itemDefinition } from "../../shared/definitions/items.js";
4import { ItemId, itemDefinition, itemDescription } from "../../shared/definitions/items.js";
5import { flowerItemInstance } from "../../shared/definitions/dyes.js";
5import { flowerItemInstance } from "../../shared/definitions/dyes.js";
6import { AlchemyStepKind } from "../../shared/definitions/alchemy.js";
6import { AlchemyStepKind } from "../../shared/definitions/alchemy.js";
7import
7import
@@ -68,6 +68,31 @@ test("recipe paper body resolves ingredient keys to display names", () =>
68 );
68 );
69});
69});
70
70
71test("potion item descriptions come from alchemy defs without repeating the name", () =>
72{
73 const stack = {
74 itemId: ItemId.potion,
75 quantity: 1,
76 instance: {
77 kind: "potion",
78 potionKey: "lesserHealthTonic",
79 displayName: "Lesser health tonic",
80 unstable: false
81 }
82 };
83 const desc = itemDescription(stack);
84 assert.equal(desc, alchemyPotionDefinition("lesserHealthTonic").description);
85 assert.doesNotMatch(desc, /Lesser health tonic/i);
86 assert.equal(
87 itemDescription({
88 itemId: ItemId.potion,
89 quantity: 1,
90 instance: { kind: "potion", potionKey: "x", displayName: "Bad", unstable: true }
91 }),
92 "The brew smells wrong — best sipped with caution."
93 );
94});
95
71test("lesser health tonic ratios and steps evaluate to a success batch", () =>
96test("lesser health tonic ratios and steps evaluate to a success batch", () =>
72{
97{
73 const potion = resolvedAlchemyPotions().find((entry) => entry.potionKey === "lesserHealthTonic");
98 const potion = resolvedAlchemyPotions().find((entry) => entry.potionKey === "lesserHealthTonic");
shared/definitions/alchemy.js +16 −0
@@ -45,6 +45,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
45 45 lesserHealthTonic: Object.freeze({
46 46 potionKey: "lesserHealthTonic",
47 47 displayName: "Lesser health tonic",
48 description: "Warm red liquid that knits small wounds for a short while.",
48 49 minAlchemyLevel: 1,
49 50 color: Object.freeze({ r: 0.95, g: 0.38, b: 0.32 }),
50 51 fillLevel: 4,
@@ -67,6 +68,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
67 68 lesserHasteDraught: Object.freeze({
68 69 potionKey: "lesserHasteDraught",
69 70 displayName: "Lesser haste draught",
71 description: "A cool green sip that steadies the breath and quickens the step.",
70 72 minAlchemyLevel: 1,
71 73 color: Object.freeze({ r: 0.45, g: 0.85, b: 0.75 }),
72 74 fillLevel: 4,
@@ -90,6 +92,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
90 92 strengthPotion: Object.freeze({
91 93 potionKey: "strengthPotion",
92 94 displayName: "Strength potion",
95 description: "Thick and fiery — lends a brief surge of muscle.",
93 96 minAlchemyLevel: 1,
94 97 color: Object.freeze({ r: 0.82, g: 0.32, b: 0.18 }),
95 98 fillLevel: 4,
@@ -112,6 +115,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
112 115 clarityPotion: Object.freeze({
113 116 potionKey: "clarityPotion",
114 117 displayName: "Clarity potion",
118 description: "Pale violet draught that clears the thoughts and steadies the will.",
115 119 minAlchemyLevel: 1,
116 120 color: Object.freeze({ r: 0.55, g: 0.45, b: 0.92 }),
117 121 fillLevel: 4,
@@ -134,6 +138,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
134 138 animalFat: Object.freeze({
135 139 potionKey: "animalFat",
136 140 displayName: "Bottle of Animal Fat",
141 description: "Rendered fat sealed in glass. Useful for tanning work — foul if drunk.",
137 142 minAlchemyLevel: 1,
138 143 color: Object.freeze({ r: 0.92, g: 0.84, b: 0.52 }),
139 144 fillLevel: 4,
@@ -155,6 +160,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
155 160 tanningBrew: Object.freeze({
156 161 potionKey: "tanningBrew",
157 162 displayName: "Tanning brew",
163 description: "A dark, bark-bitter liquor for curing hides into leather.",
158 164 minAlchemyLevel: 10,
159 165 color: Object.freeze({ r: 0.45, g: 0.28, b: 0.14 }),
160 166 fillLevel: 4,
@@ -249,6 +255,15 @@ function buildArrowCoatingPotions ()
249 255 [MagicElement.dark]: "Dark arrow coating",
250 256 [MagicElement.poison]: "Poison arrow coating"
251 257 };
258 const descriptions = {
259 [MagicElement.fire]: "Viscous slurry for arrowheads, steeped in living flame.",
260 [MagicElement.water]: "Cool, clinging slurry that carries the pull of deep water.",
261 [MagicElement.air]: "Light slurry that hums faintly, ready for wind-touched shafts.",
262 [MagicElement.earth]: "Heavy slurry thick with grit, for grounding an arrow's bite.",
263 [MagicElement.light]: "Bright slurry that catches the eye, meant for radiant tips.",
264 [MagicElement.dark]: "Shadow-thick slurry that swallows the gleam of steel.",
265 [MagicElement.poison]: "Bitter slurry for arrowheads — venom waits in every drop."
266 };
252 267 MAGIC_ELEMENT_ORDER.forEach((element, index) =>
253 268 {
254 269 const wood = ASH_WOOD_FOR_ELEMENT[element];
@@ -259,6 +274,7 @@ function buildArrowCoatingPotions ()
259 274 coats[potionKey] = Object.freeze({
260 275 potionKey,
261 276 displayName: names[element] ?? `${element} arrow coating`,
277 description: descriptions[element] ?? "A viscous coating for arrowheads.",
262 278 minAlchemyLevel: 5,
263 279 color: Object.freeze({ r: tint.r, g: tint.g, b: tint.b }),
264 280 fillLevel: 4,
@@ -45,6 +45,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
45 lesserHealthTonic: Object.freeze({
45 lesserHealthTonic: Object.freeze({
46 potionKey: "lesserHealthTonic",
46 potionKey: "lesserHealthTonic",
47 displayName: "Lesser health tonic",
47 displayName: "Lesser health tonic",
48 description: "Warm red liquid that knits small wounds for a short while.",
48 minAlchemyLevel: 1,
49 minAlchemyLevel: 1,
49 color: Object.freeze({ r: 0.95, g: 0.38, b: 0.32 }),
50 color: Object.freeze({ r: 0.95, g: 0.38, b: 0.32 }),
50 fillLevel: 4,
51 fillLevel: 4,
@@ -67,6 +68,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
67 lesserHasteDraught: Object.freeze({
68 lesserHasteDraught: Object.freeze({
68 potionKey: "lesserHasteDraught",
69 potionKey: "lesserHasteDraught",
69 displayName: "Lesser haste draught",
70 displayName: "Lesser haste draught",
71 description: "A cool green sip that steadies the breath and quickens the step.",
70 minAlchemyLevel: 1,
72 minAlchemyLevel: 1,
71 color: Object.freeze({ r: 0.45, g: 0.85, b: 0.75 }),
73 color: Object.freeze({ r: 0.45, g: 0.85, b: 0.75 }),
72 fillLevel: 4,
74 fillLevel: 4,
@@ -90,6 +92,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
90 strengthPotion: Object.freeze({
92 strengthPotion: Object.freeze({
91 potionKey: "strengthPotion",
93 potionKey: "strengthPotion",
92 displayName: "Strength potion",
94 displayName: "Strength potion",
95 description: "Thick and fiery — lends a brief surge of muscle.",
93 minAlchemyLevel: 1,
96 minAlchemyLevel: 1,
94 color: Object.freeze({ r: 0.82, g: 0.32, b: 0.18 }),
97 color: Object.freeze({ r: 0.82, g: 0.32, b: 0.18 }),
95 fillLevel: 4,
98 fillLevel: 4,
@@ -112,6 +115,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
112 clarityPotion: Object.freeze({
115 clarityPotion: Object.freeze({
113 potionKey: "clarityPotion",
116 potionKey: "clarityPotion",
114 displayName: "Clarity potion",
117 displayName: "Clarity potion",
118 description: "Pale violet draught that clears the thoughts and steadies the will.",
115 minAlchemyLevel: 1,
119 minAlchemyLevel: 1,
116 color: Object.freeze({ r: 0.55, g: 0.45, b: 0.92 }),
120 color: Object.freeze({ r: 0.55, g: 0.45, b: 0.92 }),
117 fillLevel: 4,
121 fillLevel: 4,
@@ -134,6 +138,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
134 animalFat: Object.freeze({
138 animalFat: Object.freeze({
135 potionKey: "animalFat",
139 potionKey: "animalFat",
136 displayName: "Bottle of Animal Fat",
140 displayName: "Bottle of Animal Fat",
141 description: "Rendered fat sealed in glass. Useful for tanning work — foul if drunk.",
137 minAlchemyLevel: 1,
142 minAlchemyLevel: 1,
138 color: Object.freeze({ r: 0.92, g: 0.84, b: 0.52 }),
143 color: Object.freeze({ r: 0.92, g: 0.84, b: 0.52 }),
139 fillLevel: 4,
144 fillLevel: 4,
@@ -155,6 +160,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
155 tanningBrew: Object.freeze({
160 tanningBrew: Object.freeze({
156 potionKey: "tanningBrew",
161 potionKey: "tanningBrew",
157 displayName: "Tanning brew",
162 displayName: "Tanning brew",
163 description: "A dark, bark-bitter liquor for curing hides into leather.",
158 minAlchemyLevel: 10,
164 minAlchemyLevel: 10,
159 color: Object.freeze({ r: 0.45, g: 0.28, b: 0.14 }),
165 color: Object.freeze({ r: 0.45, g: 0.28, b: 0.14 }),
160 fillLevel: 4,
166 fillLevel: 4,
@@ -249,6 +255,15 @@ function buildArrowCoatingPotions ()
249 [MagicElement.dark]: "Dark arrow coating",
255 [MagicElement.dark]: "Dark arrow coating",
250 [MagicElement.poison]: "Poison arrow coating"
256 [MagicElement.poison]: "Poison arrow coating"
251 };
257 };
258 const descriptions = {
259 [MagicElement.fire]: "Viscous slurry for arrowheads, steeped in living flame.",
260 [MagicElement.water]: "Cool, clinging slurry that carries the pull of deep water.",
261 [MagicElement.air]: "Light slurry that hums faintly, ready for wind-touched shafts.",
262 [MagicElement.earth]: "Heavy slurry thick with grit, for grounding an arrow's bite.",
263 [MagicElement.light]: "Bright slurry that catches the eye, meant for radiant tips.",
264 [MagicElement.dark]: "Shadow-thick slurry that swallows the gleam of steel.",
265 [MagicElement.poison]: "Bitter slurry for arrowheads — venom waits in every drop."
266 };
252 MAGIC_ELEMENT_ORDER.forEach((element, index) =>
267 MAGIC_ELEMENT_ORDER.forEach((element, index) =>
253 {
268 {
254 const wood = ASH_WOOD_FOR_ELEMENT[element];
269 const wood = ASH_WOOD_FOR_ELEMENT[element];
@@ -259,6 +274,7 @@ function buildArrowCoatingPotions ()
259 coats[potionKey] = Object.freeze({
274 coats[potionKey] = Object.freeze({
260 potionKey,
275 potionKey,
261 displayName: names[element] ?? `${element} arrow coating`,
276 displayName: names[element] ?? `${element} arrow coating`,
277 description: descriptions[element] ?? "A viscous coating for arrowheads.",
262 minAlchemyLevel: 5,
278 minAlchemyLevel: 5,
263 color: Object.freeze({ r: tint.r, g: tint.g, b: tint.b }),
279 color: Object.freeze({ r: tint.r, g: tint.g, b: tint.b }),
264 fillLevel: 4,
280 fillLevel: 4,
shared/definitions/items.js +7 −5
@@ -17,7 +17,7 @@ import { WizardItemId, WIZARD_ITEM_DEFINITIONS } from "./wizardItems.js";
17 17 import { DyeItemId, FLOWER_ITEM_DEFINITION, DYE_ITEM_DEFINITION, FLOWER_COLOR_DISPLAY } from "./dyes.js";
18 18 import { HERB_ITEM_DEFINITIONS, HerbItemId } from "./herbs.js";
19 19 import { RANGED_ITEM_DEFINITIONS, RangedItemId } from "./rangedItems.js";
20 import { POTION_MAX_STACK } from "./alchemy.js";
20 import { POTION_MAX_STACK, alchemyPotionDefinition } from "./alchemy.js";
21 21 import { SpellbookItemId, SPELLBOOK_ITEM_DEFINITIONS } from "./spellItems.js";
22 22 import { FISH_ITEM_DEFINITIONS, FishingToolItemId } from "./fishItems.js";
23 23 import { GemItemId, GEM_ITEM_DEFINITIONS } from "./gemItems.js";
@@ -459,10 +459,12 @@ export function itemDescription (stack, { localCharacterId } = {})
459 459 }
460 460 if (stack.itemId === ItemId.potion && stack.instance?.kind === "potion")
461 461 {
462 const name = stack.instance.displayName ?? "Potion";
463 return stack.instance.unstable
464 ? `${name}. The brew smells wrong — best sipped with caution.`
465 : `${name}. A carefully bottled draught.`;
462 if (stack.instance.unstable)
463 { return "The brew smells wrong — best sipped with caution."; }
464 const potion = alchemyPotionDefinition(stack.instance.potionKey);
465 return potion?.description
466 ?? def.description
467 ?? "A carefully bottled draught.";
466 468 }
467 469 if (stack.itemId === ItemId.recipePaper && stack.instance?.kind === "recipe-paper")
468 470 {
@@ -17,7 +17,7 @@ import { WizardItemId, WIZARD_ITEM_DEFINITIONS } from "./wizardItems.js";
17import { DyeItemId, FLOWER_ITEM_DEFINITION, DYE_ITEM_DEFINITION, FLOWER_COLOR_DISPLAY } from "./dyes.js";
17import { DyeItemId, FLOWER_ITEM_DEFINITION, DYE_ITEM_DEFINITION, FLOWER_COLOR_DISPLAY } from "./dyes.js";
18import { HERB_ITEM_DEFINITIONS, HerbItemId } from "./herbs.js";
18import { HERB_ITEM_DEFINITIONS, HerbItemId } from "./herbs.js";
19import { RANGED_ITEM_DEFINITIONS, RangedItemId } from "./rangedItems.js";
19import { RANGED_ITEM_DEFINITIONS, RangedItemId } from "./rangedItems.js";
20import { POTION_MAX_STACK } from "./alchemy.js";
20import { POTION_MAX_STACK, alchemyPotionDefinition } from "./alchemy.js";
21import { SpellbookItemId, SPELLBOOK_ITEM_DEFINITIONS } from "./spellItems.js";
21import { SpellbookItemId, SPELLBOOK_ITEM_DEFINITIONS } from "./spellItems.js";
22import { FISH_ITEM_DEFINITIONS, FishingToolItemId } from "./fishItems.js";
22import { FISH_ITEM_DEFINITIONS, FishingToolItemId } from "./fishItems.js";
23import { GemItemId, GEM_ITEM_DEFINITIONS } from "./gemItems.js";
23import { GemItemId, GEM_ITEM_DEFINITIONS } from "./gemItems.js";
@@ -459,10 +459,12 @@ export function itemDescription (stack, { localCharacterId } = {})
459 }
459 }
460 if (stack.itemId === ItemId.potion && stack.instance?.kind === "potion")
460 if (stack.itemId === ItemId.potion && stack.instance?.kind === "potion")
461 {
461 {
462 const name = stack.instance.displayName ?? "Potion";
462 if (stack.instance.unstable)
463 return stack.instance.unstable
463 { return "The brew smells wrong — best sipped with caution."; }
464 ? `${name}. The brew smells wrong — best sipped with caution.`
464 const potion = alchemyPotionDefinition(stack.instance.potionKey);
465 : `${name}. A carefully bottled draught.`;
465 return potion?.description
466 ?? def.description
467 ?? "A carefully bottled draught.";
466 }
468 }
467 if (stack.itemId === ItemId.recipePaper && stack.instance?.kind === "recipe-paper")
469 if (stack.itemId === ItemId.recipePaper && stack.instance?.kind === "recipe-paper")
468 {
470 {