BlueGit

timfa questward

Merge branch 'feature/gift-recipe-papers'

timfa Tim Falken · pushed by timfa

Authored 2026-09-04 · 2 months ago

Hash
4178b902b08ab9c7237b21acd696dc56bc3770ff
6 files changed +273 −23
client/src/editor/giftsModal.js +49 −10
@@ -1,4 +1,8 @@
1 import { listAllItemPickerEntries, itemDefinition } from "/shared/definitions/items.js";
1 import { listAllItemPickerEntries, itemDefinition, ItemId } from "/shared/definitions/items.js";
2 import {
3 listRecipePaperPickerEntries,
4 potionKeyFromListingKey
5 } from "/shared/market/listingKey.js";
2 6 import {
3 7 formatGiftLetterBody,
4 8 QUESTWARD_GIFT_AUTHOR,
@@ -6,6 +10,29 @@ import {
6 10 } from "/shared/courier/giftLetters.js";
7 11 import { formatLetterSignature } from "/shared/courier/systemLetters.js";
8 12
13 function giftItemPickerEntries ()
14 {
15 const recipes = listRecipePaperPickerEntries();
16 const base = listAllItemPickerEntries()
17 .filter((item) => item.itemId !== ItemId.recipePaper)
18 .map((item) => ({
19 ...item,
20 listingKey: null,
21 potionKey: null
22 }));
23 return [...base, ...recipes]
24 .sort((a, b) => a.displayName.localeCompare(b.displayName) || (a.itemId - b.itemId));
25 }
26
27 function giftRowKey (row)
28 {
29 if (row?.listingKey)
30 { return `listing:${row.listingKey}`; }
31 if (row?.potionKey)
32 { return `recipe:${row.potionKey}`; }
33 return `item:${row?.itemId | 0}`;
34 }
35
9 36 export function initGiftsModal ({ socket, MessageType })
10 37 {
11 38 const backdrop = document.getElementById("gifts-backdrop");
@@ -20,7 +47,7 @@ export function initGiftsModal ({ socket, MessageType })
20 47 let characters = [];
21 48 /** @type {any|null} */
22 49 let selected = null;
23 /** @type {Array<{ itemId: number, quantity: number, displayName: string }>} */
50 /** @type {Array<{ itemId: number, quantity: number, displayName: string, listingKey?: string|null, potionKey?: string|null }>} */
24 51 let giftItems = [];
25 52 let messageText = "";
26 53 /** @type {null | { resultsEl: HTMLElement, inputEl: HTMLInputElement }} */
@@ -58,7 +85,12 @@ export function initGiftsModal ({ socket, MessageType })
58 85 {
59 86 if (!item?.itemId)
60 87 { return; }
61 const existing = giftItems.find((row) => row.itemId === item.itemId);
88 const listingKey = item.listingKey ?? null;
89 const potionKey = item.potionKey
90 ?? potionKeyFromListingKey(listingKey)
91 ?? null;
92 const key = giftRowKey({ itemId: item.itemId, listingKey, potionKey });
93 const existing = giftItems.find((row) => giftRowKey(row) === key);
62 94 if (existing)
63 95 {
64 96 existing.quantity = Math.min(100000, (existing.quantity | 0) + 1);
@@ -70,7 +102,9 @@ export function initGiftsModal ({ socket, MessageType })
70 102 quantity: 1,
71 103 displayName: item.displayName
72 104 || itemDefinition(item.itemId)?.displayName
73 || `Item ${item.itemId}`
105 || `Item ${item.itemId}`,
106 listingKey,
107 potionKey
74 108 });
75 109 }
76 110 closeInlineItemSearch();
@@ -80,16 +114,17 @@ export function initGiftsModal ({ socket, MessageType })
80 114 function filterItemMatches (query)
81 115 {
82 116 const q = String(query ?? "").trim().toLowerCase();
83 const taken = new Set(giftItems.map((row) => row.itemId));
84 return listAllItemPickerEntries().filter((item) =>
117 const taken = new Set(giftItems.map((row) => giftRowKey(row)));
118 return giftItemPickerEntries().filter((item) =>
85 119 {
86 if (taken.has(item.itemId))
120 if (taken.has(giftRowKey(item)))
87 121 { return false; }
88 122 if (!q)
89 123 { return true; }
90 124 return item.displayName.toLowerCase().includes(q)
91 125 || item.key.toLowerCase().includes(q)
92 || String(item.itemId).includes(q);
126 || String(item.itemId).includes(q)
127 || String(item.potionKey ?? "").toLowerCase().includes(q);
93 128 }).slice(0, 40);
94 129 }
95 130
@@ -115,7 +150,9 @@ export function initGiftsModal ({ socket, MessageType })
115 150 name.textContent = item.displayName;
116 151 const key = document.createElement("span");
117 152 key.className = "shop-item-search-row-key";
118 key.textContent = `${item.key} (#${item.itemId})`;
153 key.textContent = item.listingKey
154 ? `${item.key} (${item.listingKey})`
155 : `${item.key} (#${item.itemId})`;
119 156 row.append(name, key);
120 157 row.addEventListener("click", () => addGiftItem(item));
121 158 pickResults.append(row);
@@ -308,7 +345,9 @@ export function initGiftsModal ({ socket, MessageType })
308 345 message: messageText,
309 346 items: giftItems.map((row) => ({
310 347 itemId: row.itemId,
311 quantity: row.quantity
348 quantity: row.quantity,
349 listingKey: row.listingKey ?? null,
350 potionKey: row.potionKey ?? null
312 351 }))
313 352 });
314 353 });
@@ -1,4 +1,8 @@
1import { listAllItemPickerEntries, itemDefinition } from "/shared/definitions/items.js";
1import { listAllItemPickerEntries, itemDefinition, ItemId } from "/shared/definitions/items.js";
2import {
3 listRecipePaperPickerEntries,
4 potionKeyFromListingKey
5} from "/shared/market/listingKey.js";
2import {
6import {
3 formatGiftLetterBody,
7 formatGiftLetterBody,
4 QUESTWARD_GIFT_AUTHOR,
8 QUESTWARD_GIFT_AUTHOR,
@@ -6,6 +10,29 @@ import {
6} from "/shared/courier/giftLetters.js";
10} from "/shared/courier/giftLetters.js";
7import { formatLetterSignature } from "/shared/courier/systemLetters.js";
11import { formatLetterSignature } from "/shared/courier/systemLetters.js";
8
12
13function giftItemPickerEntries ()
14{
15 const recipes = listRecipePaperPickerEntries();
16 const base = listAllItemPickerEntries()
17 .filter((item) => item.itemId !== ItemId.recipePaper)
18 .map((item) => ({
19 ...item,
20 listingKey: null,
21 potionKey: null
22 }));
23 return [...base, ...recipes]
24 .sort((a, b) => a.displayName.localeCompare(b.displayName) || (a.itemId - b.itemId));
25}
26
27function giftRowKey (row)
28{
29 if (row?.listingKey)
30 { return `listing:${row.listingKey}`; }
31 if (row?.potionKey)
32 { return `recipe:${row.potionKey}`; }
33 return `item:${row?.itemId | 0}`;
34}
35
9export function initGiftsModal ({ socket, MessageType })
36export function initGiftsModal ({ socket, MessageType })
10{
37{
11 const backdrop = document.getElementById("gifts-backdrop");
38 const backdrop = document.getElementById("gifts-backdrop");
@@ -20,7 +47,7 @@ export function initGiftsModal ({ socket, MessageType })
20 let characters = [];
47 let characters = [];
21 /** @type {any|null} */
48 /** @type {any|null} */
22 let selected = null;
49 let selected = null;
23 /** @type {Array<{ itemId: number, quantity: number, displayName: string }>} */
50 /** @type {Array<{ itemId: number, quantity: number, displayName: string, listingKey?: string|null, potionKey?: string|null }>} */
24 let giftItems = [];
51 let giftItems = [];
25 let messageText = "";
52 let messageText = "";
26 /** @type {null | { resultsEl: HTMLElement, inputEl: HTMLInputElement }} */
53 /** @type {null | { resultsEl: HTMLElement, inputEl: HTMLInputElement }} */
@@ -58,7 +85,12 @@ export function initGiftsModal ({ socket, MessageType })
58 {
85 {
59 if (!item?.itemId)
86 if (!item?.itemId)
60 { return; }
87 { return; }
61 const existing = giftItems.find((row) => row.itemId === item.itemId);
88 const listingKey = item.listingKey ?? null;
89 const potionKey = item.potionKey
90 ?? potionKeyFromListingKey(listingKey)
91 ?? null;
92 const key = giftRowKey({ itemId: item.itemId, listingKey, potionKey });
93 const existing = giftItems.find((row) => giftRowKey(row) === key);
62 if (existing)
94 if (existing)
63 {
95 {
64 existing.quantity = Math.min(100000, (existing.quantity | 0) + 1);
96 existing.quantity = Math.min(100000, (existing.quantity | 0) + 1);
@@ -70,7 +102,9 @@ export function initGiftsModal ({ socket, MessageType })
70 quantity: 1,
102 quantity: 1,
71 displayName: item.displayName
103 displayName: item.displayName
72 || itemDefinition(item.itemId)?.displayName
104 || itemDefinition(item.itemId)?.displayName
73 || `Item ${item.itemId}`
105 || `Item ${item.itemId}`,
106 listingKey,
107 potionKey
74 });
108 });
75 }
109 }
76 closeInlineItemSearch();
110 closeInlineItemSearch();
@@ -80,16 +114,17 @@ export function initGiftsModal ({ socket, MessageType })
80 function filterItemMatches (query)
114 function filterItemMatches (query)
81 {
115 {
82 const q = String(query ?? "").trim().toLowerCase();
116 const q = String(query ?? "").trim().toLowerCase();
83 const taken = new Set(giftItems.map((row) => row.itemId));
117 const taken = new Set(giftItems.map((row) => giftRowKey(row)));
84 return listAllItemPickerEntries().filter((item) =>
118 return giftItemPickerEntries().filter((item) =>
85 {
119 {
86 if (taken.has(item.itemId))
120 if (taken.has(giftRowKey(item)))
87 { return false; }
121 { return false; }
88 if (!q)
122 if (!q)
89 { return true; }
123 { return true; }
90 return item.displayName.toLowerCase().includes(q)
124 return item.displayName.toLowerCase().includes(q)
91 || item.key.toLowerCase().includes(q)
125 || item.key.toLowerCase().includes(q)
92 || String(item.itemId).includes(q);
126 || String(item.itemId).includes(q)
127 || String(item.potionKey ?? "").toLowerCase().includes(q);
93 }).slice(0, 40);
128 }).slice(0, 40);
94 }
129 }
95
130
@@ -115,7 +150,9 @@ export function initGiftsModal ({ socket, MessageType })
115 name.textContent = item.displayName;
150 name.textContent = item.displayName;
116 const key = document.createElement("span");
151 const key = document.createElement("span");
117 key.className = "shop-item-search-row-key";
152 key.className = "shop-item-search-row-key";
118 key.textContent = `${item.key} (#${item.itemId})`;
153 key.textContent = item.listingKey
154 ? `${item.key} (${item.listingKey})`
155 : `${item.key} (#${item.itemId})`;
119 row.append(name, key);
156 row.append(name, key);
120 row.addEventListener("click", () => addGiftItem(item));
157 row.addEventListener("click", () => addGiftItem(item));
121 pickResults.append(row);
158 pickResults.append(row);
@@ -308,7 +345,9 @@ export function initGiftsModal ({ socket, MessageType })
308 message: messageText,
345 message: messageText,
309 items: giftItems.map((row) => ({
346 items: giftItems.map((row) => ({
310 itemId: row.itemId,
347 itemId: row.itemId,
311 quantity: row.quantity
348 quantity: row.quantity,
349 listingKey: row.listingKey ?? null,
350 potionKey: row.potionKey ?? null
312 }))
351 }))
313 });
352 });
314 });
353 });
server/src/gifts/service.js +100 −10
@@ -1,6 +1,14 @@
1 1 import { randomUUID } from "node:crypto";
2 2 import { ItemId, itemDefinition, LETTER_MAX_BODY_CHARS } from "../../../shared/definitions/items.js";
3 import { alchemyPotionDefinition } from "../../../shared/definitions/alchemy.js";
4 import { recipePaperBody } from "../../../shared/alchemy/recipes.js";
5 import {
6 normalizeBuyListingKey,
7 potionKeyFromListingKey,
8 recipePaperDisplayName
9 } from "../../../shared/market/listingKey.js";
3 10 import { insertStackGrowable, normalizeVault } from "../../../shared/items/inventory.js";
11 import { stackRulesFor } from "../../../shared/items/stackRules.js";
4 12 import { attachOrigins, writtenOrigin } from "../../../shared/items/origin.js";
5 13 import {
6 14 formatGiftLetterBody,
@@ -40,7 +48,11 @@ export class GiftService
40 48
41 49 /**
42 50 * Credit gift items to the character bank and queue a signed Questward letter.
43 * @param {{ characterId: number, message?: string, items?: Array<{ itemId: number, quantity: number }> }} payload
51 * @param {{
52 * characterId: number,
53 * message?: string,
54 * items?: Array<{ itemId: number, quantity: number, listingKey?: string|null, potionKey?: string|null }>
55 * }} payload
44 56 */
45 57 sendGift (payload)
46 58 {
@@ -64,12 +76,63 @@ export class GiftService
64 76 const def = itemDefinition(entry.itemId);
65 77 if (!def)
66 78 { throw userError(`Unknown item ${entry.itemId}.`); }
67 const stack = attachOrigins({
68 itemId: entry.itemId,
69 quantity: entry.quantity,
70 origins: [{ origin: giftItemOrigin(entry.itemId), quantity: entry.quantity }]
71 });
72 this.#creditBank(characterId, stack, def);
79 if (entry.itemId === ItemId.recipePaper)
80 {
81 const potion = alchemyPotionDefinition(entry.potionKey);
82 if (!potion)
83 { throw userError("Pick a specific alchemy recipe, not blank recipe paper."); }
84 const paperName = recipePaperDisplayName(entry.potionKey);
85 for (let i = 0; i < entry.quantity; i++)
86 {
87 const stack = attachOrigins({
88 itemId: ItemId.recipePaper,
89 quantity: 1,
90 origins: [{ origin: writtenOrigin(QUESTWARD_GIFT_AUTHOR), quantity: 1 }],
91 instance: {
92 kind: "recipe-paper",
93 recipeId: randomUUID(),
94 potionKey: entry.potionKey,
95 displayName: paperName,
96 authorCharacterId: 0,
97 authorDisplayName: QUESTWARD_GIFT_AUTHOR,
98 minAlchemyLevel: potion.minAlchemyLevel ?? 1,
99 body: recipePaperBody(potion),
100 writtenAt: Date.now()
101 }
102 });
103 this.#creditBank(characterId, stack, def);
104 }
105 credited.push({
106 itemId: entry.itemId,
107 quantity: entry.quantity,
108 displayName: paperName,
109 potionKey: entry.potionKey
110 });
111 continue;
112 }
113
114 const rules = stackRulesFor(def, { inVault: true });
115 if (rules.uniqueInstance || !rules.stackable)
116 {
117 for (let i = 0; i < entry.quantity; i++)
118 {
119 const stack = attachOrigins({
120 itemId: entry.itemId,
121 quantity: 1,
122 origins: [{ origin: giftItemOrigin(entry.itemId), quantity: 1 }]
123 });
124 this.#creditBank(characterId, stack, def);
125 }
126 }
127 else
128 {
129 const stack = attachOrigins({
130 itemId: entry.itemId,
131 quantity: entry.quantity,
132 origins: [{ origin: giftItemOrigin(entry.itemId), quantity: entry.quantity }]
133 });
134 this.#creditBank(characterId, stack, def);
135 }
73 136 credited.push({
74 137 itemId: entry.itemId,
75 138 quantity: entry.quantity,
@@ -164,7 +227,7 @@ function normalizeGiftItems (raw)
164 227 {
165 228 if (!Array.isArray(raw))
166 229 { return []; }
167 /** @type {Map<number, number>} */
230 /** @type {Map<string, { itemId: number, quantity: number, potionKey?: string|null }>} */
168 231 const merged = new Map();
169 232 for (const row of raw)
170 233 {
@@ -172,7 +235,34 @@ function normalizeGiftItems (raw)
172 235 const quantity = Math.max(1, Math.min(100_000, row?.quantity | 0 || 1));
173 236 if (!itemId || !itemDefinition(itemId))
174 237 { continue; }
175 merged.set(itemId, (merged.get(itemId) ?? 0) + quantity);
238 if (itemId === ItemId.recipePaper)
239 {
240 const listingKey = normalizeBuyListingKey(itemId, row?.listingKey ?? null);
241 const potionKey = String(row?.potionKey ?? "").trim()
242 || potionKeyFromListingKey(listingKey)
243 || "";
244 if (!potionKey || !alchemyPotionDefinition(potionKey))
245 { continue; }
246 const key = `recipe:${potionKey}`;
247 const prev = merged.get(key);
248 if (prev)
249 { prev.quantity += quantity; }
250 else
251 {
252 merged.set(key, {
253 itemId,
254 quantity,
255 potionKey
256 });
257 }
258 continue;
259 }
260 const key = `item:${itemId}`;
261 const prev = merged.get(key);
262 if (prev)
263 { prev.quantity += quantity; }
264 else
265 { merged.set(key, { itemId, quantity, potionKey: null }); }
176 266 }
177 return [...merged.entries()].map(([itemId, quantity]) => ({ itemId, quantity }));
267 return [...merged.values()];
178 268 }
@@ -1,6 +1,14 @@
1import { randomUUID } from "node:crypto";
1import { randomUUID } from "node:crypto";
2import { ItemId, itemDefinition, LETTER_MAX_BODY_CHARS } from "../../../shared/definitions/items.js";
2import { ItemId, itemDefinition, LETTER_MAX_BODY_CHARS } from "../../../shared/definitions/items.js";
3import { alchemyPotionDefinition } from "../../../shared/definitions/alchemy.js";
4import { recipePaperBody } from "../../../shared/alchemy/recipes.js";
5import {
6 normalizeBuyListingKey,
7 potionKeyFromListingKey,
8 recipePaperDisplayName
9} from "../../../shared/market/listingKey.js";
3import { insertStackGrowable, normalizeVault } from "../../../shared/items/inventory.js";
10import { insertStackGrowable, normalizeVault } from "../../../shared/items/inventory.js";
11import { stackRulesFor } from "../../../shared/items/stackRules.js";
4import { attachOrigins, writtenOrigin } from "../../../shared/items/origin.js";
12import { attachOrigins, writtenOrigin } from "../../../shared/items/origin.js";
5import {
13import {
6 formatGiftLetterBody,
14 formatGiftLetterBody,
@@ -40,7 +48,11 @@ export class GiftService
40
48
41 /**
49 /**
42 * Credit gift items to the character bank and queue a signed Questward letter.
50 * Credit gift items to the character bank and queue a signed Questward letter.
43 * @param {{ characterId: number, message?: string, items?: Array<{ itemId: number, quantity: number }> }} payload
51 * @param {{
52 * characterId: number,
53 * message?: string,
54 * items?: Array<{ itemId: number, quantity: number, listingKey?: string|null, potionKey?: string|null }>
55 * }} payload
44 */
56 */
45 sendGift (payload)
57 sendGift (payload)
46 {
58 {
@@ -64,12 +76,63 @@ export class GiftService
64 const def = itemDefinition(entry.itemId);
76 const def = itemDefinition(entry.itemId);
65 if (!def)
77 if (!def)
66 { throw userError(`Unknown item ${entry.itemId}.`); }
78 { throw userError(`Unknown item ${entry.itemId}.`); }
67 const stack = attachOrigins({
79 if (entry.itemId === ItemId.recipePaper)
68 itemId: entry.itemId,
80 {
69 quantity: entry.quantity,
81 const potion = alchemyPotionDefinition(entry.potionKey);
70 origins: [{ origin: giftItemOrigin(entry.itemId), quantity: entry.quantity }]
82 if (!potion)
71 });
83 { throw userError("Pick a specific alchemy recipe, not blank recipe paper."); }
72 this.#creditBank(characterId, stack, def);
84 const paperName = recipePaperDisplayName(entry.potionKey);
85 for (let i = 0; i < entry.quantity; i++)
86 {
87 const stack = attachOrigins({
88 itemId: ItemId.recipePaper,
89 quantity: 1,
90 origins: [{ origin: writtenOrigin(QUESTWARD_GIFT_AUTHOR), quantity: 1 }],
91 instance: {
92 kind: "recipe-paper",
93 recipeId: randomUUID(),
94 potionKey: entry.potionKey,
95 displayName: paperName,
96 authorCharacterId: 0,
97 authorDisplayName: QUESTWARD_GIFT_AUTHOR,
98 minAlchemyLevel: potion.minAlchemyLevel ?? 1,
99 body: recipePaperBody(potion),
100 writtenAt: Date.now()
101 }
102 });
103 this.#creditBank(characterId, stack, def);
104 }
105 credited.push({
106 itemId: entry.itemId,
107 quantity: entry.quantity,
108 displayName: paperName,
109 potionKey: entry.potionKey
110 });
111 continue;
112 }
113
114 const rules = stackRulesFor(def, { inVault: true });
115 if (rules.uniqueInstance || !rules.stackable)
116 {
117 for (let i = 0; i < entry.quantity; i++)
118 {
119 const stack = attachOrigins({
120 itemId: entry.itemId,
121 quantity: 1,
122 origins: [{ origin: giftItemOrigin(entry.itemId), quantity: 1 }]
123 });
124 this.#creditBank(characterId, stack, def);
125 }
126 }
127 else
128 {
129 const stack = attachOrigins({
130 itemId: entry.itemId,
131 quantity: entry.quantity,
132 origins: [{ origin: giftItemOrigin(entry.itemId), quantity: entry.quantity }]
133 });
134 this.#creditBank(characterId, stack, def);
135 }
73 credited.push({
136 credited.push({
74 itemId: entry.itemId,
137 itemId: entry.itemId,
75 quantity: entry.quantity,
138 quantity: entry.quantity,
@@ -164,7 +227,7 @@ function normalizeGiftItems (raw)
164{
227{
165 if (!Array.isArray(raw))
228 if (!Array.isArray(raw))
166 { return []; }
229 { return []; }
167 /** @type {Map<number, number>} */
230 /** @type {Map<string, { itemId: number, quantity: number, potionKey?: string|null }>} */
168 const merged = new Map();
231 const merged = new Map();
169 for (const row of raw)
232 for (const row of raw)
170 {
233 {
@@ -172,7 +235,34 @@ function normalizeGiftItems (raw)
172 const quantity = Math.max(1, Math.min(100_000, row?.quantity | 0 || 1));
235 const quantity = Math.max(1, Math.min(100_000, row?.quantity | 0 || 1));
173 if (!itemId || !itemDefinition(itemId))
236 if (!itemId || !itemDefinition(itemId))
174 { continue; }
237 { continue; }
175 merged.set(itemId, (merged.get(itemId) ?? 0) + quantity);
238 if (itemId === ItemId.recipePaper)
239 {
240 const listingKey = normalizeBuyListingKey(itemId, row?.listingKey ?? null);
241 const potionKey = String(row?.potionKey ?? "").trim()
242 || potionKeyFromListingKey(listingKey)
243 || "";
244 if (!potionKey || !alchemyPotionDefinition(potionKey))
245 { continue; }
246 const key = `recipe:${potionKey}`;
247 const prev = merged.get(key);
248 if (prev)
249 { prev.quantity += quantity; }
250 else
251 {
252 merged.set(key, {
253 itemId,
254 quantity,
255 potionKey
256 });
257 }
258 continue;
259 }
260 const key = `item:${itemId}`;
261 const prev = merged.get(key);
262 if (prev)
263 { prev.quantity += quantity; }
264 else
265 { merged.set(key, { itemId, quantity, potionKey: null }); }
176 }
266 }
177 return [...merged.entries()].map(([itemId, quantity]) => ({ itemId, quantity }));
267 return [...merged.values()];
178}
268}
server/src/simulation/workerWorld.js +9 −3
@@ -1,4 +1,4 @@
1 import { GAIT, VISIBLE_CHUNK_RADIUS, DEFAULT_WORLD_SETTINGS, NAV_STUCK_MS } from "../../../shared/protocol/constants.js";
1 import { GAIT, VISIBLE_CHUNK_RADIUS, STATIC_CHUNK_RADIUS, DEFAULT_WORLD_SETTINGS, NAV_STUCK_MS } from "../../../shared/protocol/constants.js";
2 2 import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";
3 3 import {
4 4 chunkKey,
@@ -979,7 +979,8 @@ export class WorkerWorld
979 979 let path = this.ecs.get(handle, Component.path);
980 980 if (!path)
981 981 { path = this.ecs.add(handle, Component.path, { tiles: [] }); }
982 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
982 // Match the static map ring (long vision): clicks outside the 3×3 entity view still path.
983 const bounds = chunkBoundsAround(position.tileX, position.tileY, STATIC_CHUNK_RADIUS);
983 984 path.tiles = findPath(
984 985 position.tileX,
985 986 position.tileY,
@@ -1661,8 +1662,13 @@ export class WorkerWorld
1661 1662 path.stuckSince = null;
1662 1663 return;
1663 1664 }
1664 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
1665 1665 const stuckHandle = this.ecs.handleOf(entityId);
1666 const isCharacter = stuckHandle != null && this.ecs.has(stuckHandle, Component.character);
1667 const bounds = chunkBoundsAround(
1668 position.tileX,
1669 position.tileY,
1670 isCharacter ? STATIC_CHUNK_RADIUS : VISIBLE_CHUNK_RADIUS
1671 );
1666 1672 const inCombat = stuckHandle != null
1667 1673 && this.ecs.get(stuckHandle, Component.combat)?.targetEntityId != null;
1668 1674 path.tiles = findPath(
@@ -1,4 +1,4 @@
1import { GAIT, VISIBLE_CHUNK_RADIUS, DEFAULT_WORLD_SETTINGS, NAV_STUCK_MS } from "../../../shared/protocol/constants.js";
1import { GAIT, VISIBLE_CHUNK_RADIUS, STATIC_CHUNK_RADIUS, DEFAULT_WORLD_SETTINGS, NAV_STUCK_MS } from "../../../shared/protocol/constants.js";
2import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";
2import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";
3import {
3import {
4 chunkKey,
4 chunkKey,
@@ -979,7 +979,8 @@ export class WorkerWorld
979 let path = this.ecs.get(handle, Component.path);
979 let path = this.ecs.get(handle, Component.path);
980 if (!path)
980 if (!path)
981 { path = this.ecs.add(handle, Component.path, { tiles: [] }); }
981 { path = this.ecs.add(handle, Component.path, { tiles: [] }); }
982 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
982 // Match the static map ring (long vision): clicks outside the 3×3 entity view still path.
983 const bounds = chunkBoundsAround(position.tileX, position.tileY, STATIC_CHUNK_RADIUS);
983 path.tiles = findPath(
984 path.tiles = findPath(
984 position.tileX,
985 position.tileX,
985 position.tileY,
986 position.tileY,
@@ -1661,8 +1662,13 @@ export class WorkerWorld
1661 path.stuckSince = null;
1662 path.stuckSince = null;
1662 return;
1663 return;
1663 }
1664 }
1664 const bounds = chunkBoundsAround(position.tileX, position.tileY, VISIBLE_CHUNK_RADIUS);
1665 const stuckHandle = this.ecs.handleOf(entityId);
1665 const stuckHandle = this.ecs.handleOf(entityId);
1666 const isCharacter = stuckHandle != null && this.ecs.has(stuckHandle, Component.character);
1667 const bounds = chunkBoundsAround(
1668 position.tileX,
1669 position.tileY,
1670 isCharacter ? STATIC_CHUNK_RADIUS : VISIBLE_CHUNK_RADIUS
1671 );
1666 const inCombat = stuckHandle != null
1672 const inCombat = stuckHandle != null
1667 && this.ecs.get(stuckHandle, Component.combat)?.targetEntityId != null;
1673 && this.ecs.get(stuckHandle, Component.combat)?.targetEntityId != null;
1668 path.tiles = findPath(
1674 path.tiles = findPath(
server/tests/follow.test.js +25 −0
@@ -155,6 +155,31 @@ test("move-to clears follow", () =>
155 155 { harness.close(); }
156 156 });
157 157
158 test("move-to paths into the static chunk ring outside the 3x3 entity view", () =>
159 {
160 const harness = makeSimulation({ workerCount: 1 });
161 try
162 {
163 // Player in chunk 0,0: VISIBLE bounds end at tile 31; STATIC at 47.
164 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
165 const playerId = harness.simulation.spawnCharacter(1, character);
166 harness.simulation.enqueue(1, {
167 type: "move-to",
168 characterId: character.character_id,
169 tileX: 40,
170 tileY: 8
171 });
172 harness.simulation.step();
173 const path = componentsOf(harness.simulation, playerId).path?.tiles ?? [];
174 assert.ok(path.length > 0, "expected a path into the static map ring");
175 const goal = path[path.length - 1];
176 assert.equal(goal.x, 40);
177 assert.equal(goal.y, 8);
178 }
179 finally
180 { harness.close(); }
181 });
182
158 183 test("follower reuses the target vacated trail and waits off their tile", () =>
159 184 {
160 185 const harness = makeSimulation({ workerCount: 1 });
@@ -155,6 +155,31 @@ test("move-to clears follow", () =>
155 { harness.close(); }
155 { harness.close(); }
156});
156});
157
157
158test("move-to paths into the static chunk ring outside the 3x3 entity view", () =>
159{
160 const harness = makeSimulation({ workerCount: 1 });
161 try
162 {
163 // Player in chunk 0,0: VISIBLE bounds end at tile 31; STATIC at 47.
164 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
165 const playerId = harness.simulation.spawnCharacter(1, character);
166 harness.simulation.enqueue(1, {
167 type: "move-to",
168 characterId: character.character_id,
169 tileX: 40,
170 tileY: 8
171 });
172 harness.simulation.step();
173 const path = componentsOf(harness.simulation, playerId).path?.tiles ?? [];
174 assert.ok(path.length > 0, "expected a path into the static map ring");
175 const goal = path[path.length - 1];
176 assert.equal(goal.x, 40);
177 assert.equal(goal.y, 8);
178 }
179 finally
180 { harness.close(); }
181});
182
158test("follower reuses the target vacated trail and waits off their tile", () =>
183test("follower reuses the target vacated trail and waits off their tile", () =>
159{
184{
160 const harness = makeSimulation({ workerCount: 1 });
185 const harness = makeSimulation({ workerCount: 1 });
server/tests/gifts.test.js +67 −0
@@ -18,6 +18,7 @@ import { originLabel, ItemOriginKind, CraftOriginVerb, GatherOriginVerb } from "
18 18 import { BlockType } from "../../shared/definitions/tiles.js";
19 19 import { createEmptyChunkData, encodeChunkBlob, decodeChunkBlob } from "../src/world/chunkData.js";
20 20 import { GiftService } from "../src/gifts/service.js";
21 import { recipeListingKey, recipePaperDisplayName } from "../../shared/market/listingKey.js";
21 22 import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";
22 23
23 24 function placeBank (worldDb, tileX, tileY)
@@ -199,3 +200,69 @@ test("admin gift credits bank and queues a system letter", () =>
199 200 finally
200 201 { harness.close(); }
201 202 });
203
204 test("admin gift can credit a specific alchemy recipe paper", () =>
205 {
206 const harness = makeSimulation({ workerCount: 1 });
207 try
208 {
209 placeBank(harness.worldDb, 8, 8);
210 harness.simulation.courier.refreshBankIndex();
211 const character = makeCharacter(harness.stateDb, {
212 tileX: 8,
213 tileY: 8,
214 firstName: "Brew",
215 lastName: "Student"
216 });
217 const gifts = new GiftService(harness.stateDb, harness.simulation);
218 const result = gifts.sendGift({
219 characterId: character.character_id,
220 message: "Study well.",
221 items: [{
222 itemId: ItemId.recipePaper,
223 quantity: 2,
224 listingKey: recipeListingKey("lesserHealthTonic")
225 }]
226 });
227 assert.equal(result.ok, true);
228 assert.equal(result.items[0].displayName, recipePaperDisplayName("lesserHealthTonic"));
229
230 const vault = harness.stateDb.getBag(character.character_id).vault ?? [];
231 const papers = vault.filter((slot) =>
232 slot?.itemId === ItemId.recipePaper
233 && slot.instance?.potionKey === "lesserHealthTonic"
234 );
235 assert.equal(papers.length, 2);
236 assert.equal(papers[0].instance.kind, "recipe-paper");
237 assert.ok(papers[0].instance.body?.includes("Alchemy level required"));
238 assert.notEqual(papers[0].instance.recipeId, papers[1].instance.recipeId);
239
240 const held = harness.stateDb.listHeldCourierDeliveries(character.character_id);
241 const giftHold = held.find((row) =>
242 row.cargo?.stack?.instance?.authorDisplayName === QUESTWARD_GIFT_AUTHOR
243 );
244 assert.ok(giftHold);
245 assert.match(giftHold.cargo.stack.instance.body, /Lesser health tonic recipe/i);
246 }
247 finally
248 { harness.close(); }
249 });
250
251 test("admin gift rejects blank recipe paper without a potion key", () =>
252 {
253 const harness = makeSimulation({ workerCount: 1 });
254 try
255 {
256 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
257 const gifts = new GiftService(harness.stateDb, harness.simulation);
258 assert.throws(
259 () => gifts.sendGift({
260 characterId: character.character_id,
261 items: [{ itemId: ItemId.recipePaper, quantity: 1 }]
262 }),
263 /at least one item/i
264 );
265 }
266 finally
267 { harness.close(); }
268 });
@@ -18,6 +18,7 @@ import { originLabel, ItemOriginKind, CraftOriginVerb, GatherOriginVerb } from "
18import { BlockType } from "../../shared/definitions/tiles.js";
18import { BlockType } from "../../shared/definitions/tiles.js";
19import { createEmptyChunkData, encodeChunkBlob, decodeChunkBlob } from "../src/world/chunkData.js";
19import { createEmptyChunkData, encodeChunkBlob, decodeChunkBlob } from "../src/world/chunkData.js";
20import { GiftService } from "../src/gifts/service.js";
20import { GiftService } from "../src/gifts/service.js";
21import { recipeListingKey, recipePaperDisplayName } from "../../shared/market/listingKey.js";
21import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";
22import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";
22
23
23function placeBank (worldDb, tileX, tileY)
24function placeBank (worldDb, tileX, tileY)
@@ -199,3 +200,69 @@ test("admin gift credits bank and queues a system letter", () =>
199 finally
200 finally
200 { harness.close(); }
201 { harness.close(); }
201});
202});
203
204test("admin gift can credit a specific alchemy recipe paper", () =>
205{
206 const harness = makeSimulation({ workerCount: 1 });
207 try
208 {
209 placeBank(harness.worldDb, 8, 8);
210 harness.simulation.courier.refreshBankIndex();
211 const character = makeCharacter(harness.stateDb, {
212 tileX: 8,
213 tileY: 8,
214 firstName: "Brew",
215 lastName: "Student"
216 });
217 const gifts = new GiftService(harness.stateDb, harness.simulation);
218 const result = gifts.sendGift({
219 characterId: character.character_id,
220 message: "Study well.",
221 items: [{
222 itemId: ItemId.recipePaper,
223 quantity: 2,
224 listingKey: recipeListingKey("lesserHealthTonic")
225 }]
226 });
227 assert.equal(result.ok, true);
228 assert.equal(result.items[0].displayName, recipePaperDisplayName("lesserHealthTonic"));
229
230 const vault = harness.stateDb.getBag(character.character_id).vault ?? [];
231 const papers = vault.filter((slot) =>
232 slot?.itemId === ItemId.recipePaper
233 && slot.instance?.potionKey === "lesserHealthTonic"
234 );
235 assert.equal(papers.length, 2);
236 assert.equal(papers[0].instance.kind, "recipe-paper");
237 assert.ok(papers[0].instance.body?.includes("Alchemy level required"));
238 assert.notEqual(papers[0].instance.recipeId, papers[1].instance.recipeId);
239
240 const held = harness.stateDb.listHeldCourierDeliveries(character.character_id);
241 const giftHold = held.find((row) =>
242 row.cargo?.stack?.instance?.authorDisplayName === QUESTWARD_GIFT_AUTHOR
243 );
244 assert.ok(giftHold);
245 assert.match(giftHold.cargo.stack.instance.body, /Lesser health tonic recipe/i);
246 }
247 finally
248 { harness.close(); }
249});
250
251test("admin gift rejects blank recipe paper without a potion key", () =>
252{
253 const harness = makeSimulation({ workerCount: 1 });
254 try
255 {
256 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
257 const gifts = new GiftService(harness.stateDb, harness.simulation);
258 assert.throws(
259 () => gifts.sendGift({
260 characterId: character.character_id,
261 items: [{ itemId: ItemId.recipePaper, quantity: 1 }]
262 }),
263 /at least one item/i
264 );
265 }
266 finally
267 { harness.close(); }
268});
shared/market/listingKey.js +23 −0
@@ -58,6 +58,29 @@ export function recipePaperDisplayName (potionKey)
58 58 return `${def.displayName} recipe`;
59 59 }
60 60
61 /**
62 * Editor / gift picker rows: one entry per alchemy recipe (same as CE buy catalog).
63 * @returns {Array<{ itemId: number, listingKey: string, potionKey: string, displayName: string, key: string }>}
64 */
65 export function listRecipePaperPickerEntries ()
66 {
67 const entries = [];
68 for (const potion of listAlchemyPotions())
69 {
70 const listingKey = recipeListingKey(potion.potionKey);
71 if (!listingKey)
72 { continue; }
73 entries.push({
74 itemId: ItemId.recipePaper,
75 listingKey,
76 potionKey: potion.potionKey,
77 displayName: recipePaperDisplayName(potion.potionKey),
78 key: `recipe-paper:${potion.potionKey}`
79 });
80 }
81 return entries;
82 }
83
61 84 export function marketOrderDisplayName (order)
62 85 {
63 86 const listingKey = listingKeyFromOrder(order);
@@ -58,6 +58,29 @@ export function recipePaperDisplayName (potionKey)
58 return `${def.displayName} recipe`;
58 return `${def.displayName} recipe`;
59}
59}
60
60
61/**
62 * Editor / gift picker rows: one entry per alchemy recipe (same as CE buy catalog).
63 * @returns {Array<{ itemId: number, listingKey: string, potionKey: string, displayName: string, key: string }>}
64 */
65export function listRecipePaperPickerEntries ()
66{
67 const entries = [];
68 for (const potion of listAlchemyPotions())
69 {
70 const listingKey = recipeListingKey(potion.potionKey);
71 if (!listingKey)
72 { continue; }
73 entries.push({
74 itemId: ItemId.recipePaper,
75 listingKey,
76 potionKey: potion.potionKey,
77 displayName: recipePaperDisplayName(potion.potionKey),
78 key: `recipe-paper:${potion.potionKey}`
79 });
80 }
81 return entries;
82}
83
61export function marketOrderDisplayName (order)
84export function marketOrderDisplayName (order)
62{
85{
63 const listingKey = listingKeyFromOrder(order);
86 const listingKey = listingKeyFromOrder(order);