Let world-editor gifts pick specific alchemy recipe papers.
Mirror the CE catalog: expand recipe papers by potion, and credit written recipe instances (not blank Recipe paper) into the bank.
@@ -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 @@1
import { listAllItemPickerEntries, itemDefinition } from "/shared/definitions/items.js";1
import { listAllItemPickerEntries, itemDefinition, ItemId } from "/shared/definitions/items.js";2
import {3
listRecipePaperPickerEntries,4
potionKeyFromListingKey5
} from "/shared/market/listingKey.js";2
import {6
import {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";7
import { formatLetterSignature } from "/shared/courier/systemLetters.js";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: null22
}));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
export function initGiftsModal ({ socket, MessageType })36
export 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.potionKey90
?? 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.displayName103
displayName: item.displayName72
|| itemDefinition(item.itemId)?.displayName104
|| itemDefinition(item.itemId)?.displayName73
|| `Item ${item.itemId}`105
|| `Item ${item.itemId}`,106
listingKey,107
potionKey74
});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.listingKey154
? `${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.quantity348
quantity: row.quantity,349
listingKey: row.listingKey ?? null,350
potionKey: row.potionKey ?? null312
}))351
}))313
});352
});314
});353
});@@ -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 @@1
import { randomUUID } from "node:crypto";1
import { randomUUID } from "node:crypto";2
import { ItemId, itemDefinition, LETTER_MAX_BODY_CHARS } from "../../../shared/definitions/items.js";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
recipePaperDisplayName9
} from "../../../shared/market/listingKey.js";3
import { insertStackGrowable, normalizeVault } from "../../../shared/items/inventory.js";10
import { insertStackGrowable, normalizeVault } from "../../../shared/items/inventory.js";11
import { stackRulesFor } from "../../../shared/items/stackRules.js";4
import { attachOrigins, writtenOrigin } from "../../../shared/items/origin.js";12
import { attachOrigins, writtenOrigin } from "../../../shared/items/origin.js";5
import {13
import {6
formatGiftLetterBody,14
formatGiftLetterBody,@@ -40,7 +48,11 @@ export class GiftService40
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 }> }} payload51
* @param {{52
* characterId: number,53
* message?: string,54
* items?: Array<{ itemId: number, quantity: number, listingKey?: string|null, potionKey?: string|null }>55
* }} payload44
*/56
*/45
sendGift (payload)57
sendGift (payload)46
{58
{@@ -64,12 +76,63 @@ export class GiftService64
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.potionKey110
});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
else128
{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
else251
{252
merged.set(key, {253
itemId,254
quantity,255
potionKey256
});257
}258
continue;259
}260
const key = `item:${itemId}`;261
const prev = merged.get(key);262
if (prev)263
{ prev.quantity += quantity; }264
else265
{ merged.set(key, { itemId, quantity, potionKey: null }); }176
}266
}177
return [...merged.entries()].map(([itemId, quantity]) => ({ itemId, quantity }));267
return [...merged.values()];178
}268
}@@ -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 "18
import { BlockType } from "../../shared/definitions/tiles.js";18
import { BlockType } from "../../shared/definitions/tiles.js";19
import { createEmptyChunkData, encodeChunkBlob, decodeChunkBlob } from "../src/world/chunkData.js";19
import { createEmptyChunkData, encodeChunkBlob, decodeChunkBlob } from "../src/world/chunkData.js";20
import { GiftService } from "../src/gifts/service.js";20
import { GiftService } from "../src/gifts/service.js";21
import { recipeListingKey, recipePaperDisplayName } from "../../shared/market/listingKey.js";21
import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";22
import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";22
23
23
function placeBank (worldDb, tileX, tileY)24
function placeBank (worldDb, tileX, tileY)@@ -199,3 +200,69 @@ test("admin gift credits bank and queues a system letter", () =>199
finally200
finally200
{ harness.close(); }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
try208
{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.recipePaper233
&& 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_AUTHOR243
);244
assert.ok(giftHold);245
assert.match(giftHold.cargo.stack.instance.body, /Lesser health tonic recipe/i);246
}247
finally248
{ harness.close(); }249
});250
251
test("admin gift rejects blank recipe paper without a potion key", () =>252
{253
const harness = makeSimulation({ workerCount: 1 });254
try255
{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/i264
);265
}266
finally267
{ harness.close(); }268
});