BlueGit

timfa questward

Allow dialogue steps to grant quests like item rewards.

Normalize questRewards on steps, start them with item gifts after lines, and show a journal notice in the same reward UI.

timfa Tim Falken · pushed by timfa

Authored 2026-09-06 · 2 months ago

Hash
dd910fe61bd538c1cb3fbb8ec259da66426adbb0
Parent
409992f3
6 files changed +157 −8
client/src/editor/dialoguesModal.js +80 −1
@@ -1,4 +1,4 @@
1 import { normalizeDialogueTree } from "/shared/quests/normalize.js";
1 import { normalizeDialogueTree, normalizeQuestDef } from "/shared/quests/normalize.js";
2 2 import { emptyConditionSet, normalizeConditionSet } from "/shared/quests/conditions.js";
3 3 import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";
4 4
@@ -13,6 +13,8 @@ export function initDialoguesModal ({ socket, MessageType })
13 13 let open = false;
14 14 /** @type {any[]} */
15 15 let dialogues = [];
16 /** @type {{ questId: string, title: string }[]} */
17 let questCatalog = [];
16 18 /** @type {any|null} */
17 19 let draft = null;
18 20 let selectedId = null;
@@ -135,6 +137,7 @@ export function initDialoguesModal ({ socket, MessageType })
135 137 stepId: `step-${draft.steps.length + 1}`,
136 138 lines: [{ speaker: "npc", text: "…", effects: [] }],
137 139 itemRewards: [],
140 questRewards: [],
138 141 exit: { kind: "end" }
139 142 });
140 143 renderEditor();
@@ -197,6 +200,7 @@ export function initDialoguesModal ({ socket, MessageType })
197 200 stepId: "greeting",
198 201 lines: [{ speaker: "npc", text: "…", effects: [] }],
199 202 itemRewards: [],
203 questRewards: [],
200 204 exit: { kind: "end" }
201 205 });
202 206 }
@@ -300,6 +304,69 @@ export function initDialoguesModal ({ socket, MessageType })
300 304 });
301 305 box.append(searchWrap);
302 306
307 if (!Array.isArray(step.questRewards))
308 { step.questRewards = []; }
309 const questRewardsHead = sectionHeader("Quest rewards", () =>
310 {
311 const available = questCatalog.find((q) => !step.questRewards.includes(q.questId));
312 if (!available)
313 { return; }
314 step.questRewards.push(available.questId);
315 renderEditor();
316 });
317 box.append(questRewardsHead);
318 const questHint = document.createElement("p");
319 questHint.className = "content-editor-hint";
320 questHint.textContent = "Started after all lines (with item rewards), before triggers/branches.";
321 box.append(questHint);
322 if (!step.questRewards.length)
323 {
324 const empty = document.createElement("p");
325 empty.className = "content-editor-hint";
326 empty.textContent = "No quest rewards.";
327 box.append(empty);
328 }
329 step.questRewards.forEach((questId, rewardIndex) =>
330 {
331 const row = document.createElement("div");
332 row.className = "spawner-drops-row";
333 const select = document.createElement("select");
334 const taken = new Set(step.questRewards);
335 const catalog = questCatalog.length
336 ? questCatalog
337 : [{ questId, title: questId }];
338 for (const quest of catalog)
339 {
340 if (taken.has(quest.questId) && quest.questId !== questId)
341 { continue; }
342 const opt = document.createElement("option");
343 opt.value = quest.questId;
344 opt.textContent = quest.title
345 ? `${quest.title} (${quest.questId})`
346 : quest.questId;
347 select.append(opt);
348 }
349 if (![...select.options].some((o) => o.value === questId))
350 {
351 const missing = document.createElement("option");
352 missing.value = questId;
353 missing.textContent = `${questId} (missing)`;
354 select.append(missing);
355 }
356 select.value = questId;
357 select.addEventListener("change", () =>
358 {
359 step.questRewards[rewardIndex] = select.value;
360 renderEditor();
361 });
362 row.append(select, removeButton(() =>
363 {
364 step.questRewards.splice(rewardIndex, 1);
365 renderEditor();
366 }));
367 box.append(row);
368 });
369
303 370 const exitKind = document.createElement("select");
304 371 for (const k of ["end", "triggers", "branches"])
305 372 {
@@ -433,6 +500,7 @@ export function initDialoguesModal ({ socket, MessageType })
433 500 document.getElementById("open-dialogues").addEventListener("click", () =>
434 501 {
435 502 socket.send({ type: MessageType.editorLoadDialogues });
503 socket.send({ type: MessageType.editorLoadQuests });
436 504 show(true);
437 505 render();
438 506 });
@@ -469,6 +537,17 @@ export function initDialoguesModal ({ socket, MessageType })
469 537 getDialogues: () => dialogues,
470 538 handleMessage (message)
471 539 {
540 if (message.type === MessageType.editorQuests)
541 {
542 questCatalog = (message.quests ?? []).map((q) =>
543 {
544 const def = normalizeQuestDef(q);
545 return { questId: def.questId, title: def.title };
546 });
547 if (open)
548 { render(); }
549 return;
550 }
472 551 if (message.type !== MessageType.editorDialogues)
473 552 { return; }
474 553 dialogues = (message.dialogues ?? []).map((d) =>
@@ -1,4 +1,4 @@
1import { normalizeDialogueTree } from "/shared/quests/normalize.js";
1import { normalizeDialogueTree, normalizeQuestDef } from "/shared/quests/normalize.js";
2import { emptyConditionSet, normalizeConditionSet } from "/shared/quests/conditions.js";
2import { emptyConditionSet, normalizeConditionSet } from "/shared/quests/conditions.js";
3import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";
3import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";
4
4
@@ -13,6 +13,8 @@ export function initDialoguesModal ({ socket, MessageType })
13 let open = false;
13 let open = false;
14 /** @type {any[]} */
14 /** @type {any[]} */
15 let dialogues = [];
15 let dialogues = [];
16 /** @type {{ questId: string, title: string }[]} */
17 let questCatalog = [];
16 /** @type {any|null} */
18 /** @type {any|null} */
17 let draft = null;
19 let draft = null;
18 let selectedId = null;
20 let selectedId = null;
@@ -135,6 +137,7 @@ export function initDialoguesModal ({ socket, MessageType })
135 stepId: `step-${draft.steps.length + 1}`,
137 stepId: `step-${draft.steps.length + 1}`,
136 lines: [{ speaker: "npc", text: "…", effects: [] }],
138 lines: [{ speaker: "npc", text: "…", effects: [] }],
137 itemRewards: [],
139 itemRewards: [],
140 questRewards: [],
138 exit: { kind: "end" }
141 exit: { kind: "end" }
139 });
142 });
140 renderEditor();
143 renderEditor();
@@ -197,6 +200,7 @@ export function initDialoguesModal ({ socket, MessageType })
197 stepId: "greeting",
200 stepId: "greeting",
198 lines: [{ speaker: "npc", text: "…", effects: [] }],
201 lines: [{ speaker: "npc", text: "…", effects: [] }],
199 itemRewards: [],
202 itemRewards: [],
203 questRewards: [],
200 exit: { kind: "end" }
204 exit: { kind: "end" }
201 });
205 });
202 }
206 }
@@ -300,6 +304,69 @@ export function initDialoguesModal ({ socket, MessageType })
300 });
304 });
301 box.append(searchWrap);
305 box.append(searchWrap);
302
306
307 if (!Array.isArray(step.questRewards))
308 { step.questRewards = []; }
309 const questRewardsHead = sectionHeader("Quest rewards", () =>
310 {
311 const available = questCatalog.find((q) => !step.questRewards.includes(q.questId));
312 if (!available)
313 { return; }
314 step.questRewards.push(available.questId);
315 renderEditor();
316 });
317 box.append(questRewardsHead);
318 const questHint = document.createElement("p");
319 questHint.className = "content-editor-hint";
320 questHint.textContent = "Started after all lines (with item rewards), before triggers/branches.";
321 box.append(questHint);
322 if (!step.questRewards.length)
323 {
324 const empty = document.createElement("p");
325 empty.className = "content-editor-hint";
326 empty.textContent = "No quest rewards.";
327 box.append(empty);
328 }
329 step.questRewards.forEach((questId, rewardIndex) =>
330 {
331 const row = document.createElement("div");
332 row.className = "spawner-drops-row";
333 const select = document.createElement("select");
334 const taken = new Set(step.questRewards);
335 const catalog = questCatalog.length
336 ? questCatalog
337 : [{ questId, title: questId }];
338 for (const quest of catalog)
339 {
340 if (taken.has(quest.questId) && quest.questId !== questId)
341 { continue; }
342 const opt = document.createElement("option");
343 opt.value = quest.questId;
344 opt.textContent = quest.title
345 ? `${quest.title} (${quest.questId})`
346 : quest.questId;
347 select.append(opt);
348 }
349 if (![...select.options].some((o) => o.value === questId))
350 {
351 const missing = document.createElement("option");
352 missing.value = questId;
353 missing.textContent = `${questId} (missing)`;
354 select.append(missing);
355 }
356 select.value = questId;
357 select.addEventListener("change", () =>
358 {
359 step.questRewards[rewardIndex] = select.value;
360 renderEditor();
361 });
362 row.append(select, removeButton(() =>
363 {
364 step.questRewards.splice(rewardIndex, 1);
365 renderEditor();
366 }));
367 box.append(row);
368 });
369
303 const exitKind = document.createElement("select");
370 const exitKind = document.createElement("select");
304 for (const k of ["end", "triggers", "branches"])
371 for (const k of ["end", "triggers", "branches"])
305 {
372 {
@@ -433,6 +500,7 @@ export function initDialoguesModal ({ socket, MessageType })
433 document.getElementById("open-dialogues").addEventListener("click", () =>
500 document.getElementById("open-dialogues").addEventListener("click", () =>
434 {
501 {
435 socket.send({ type: MessageType.editorLoadDialogues });
502 socket.send({ type: MessageType.editorLoadDialogues });
503 socket.send({ type: MessageType.editorLoadQuests });
436 show(true);
504 show(true);
437 render();
505 render();
438 });
506 });
@@ -469,6 +537,17 @@ export function initDialoguesModal ({ socket, MessageType })
469 getDialogues: () => dialogues,
537 getDialogues: () => dialogues,
470 handleMessage (message)
538 handleMessage (message)
471 {
539 {
540 if (message.type === MessageType.editorQuests)
541 {
542 questCatalog = (message.quests ?? []).map((q) =>
543 {
544 const def = normalizeQuestDef(q);
545 return { questId: def.questId, title: def.title };
546 });
547 if (open)
548 { render(); }
549 return;
550 }
472 if (message.type !== MessageType.editorDialogues)
551 if (message.type !== MessageType.editorDialogues)
473 { return; }
552 { return; }
474 dialogues = (message.dialogues ?? []).map((d) =>
553 dialogues = (message.dialogues ?? []).map((d) =>
client/src/editor/main.js +1 −0
@@ -1375,6 +1375,7 @@ async function main ()
1375 1375 {
1376 1376 questsModal?.handleMessage(message);
1377 1377 settingsModal?.handleMessage(message);
1378 dialoguesModal?.handleMessage(message);
1378 1379 }
1379 1380 else if (message.type === MessageType.editorDialogues)
1380 1381 {
@@ -1375,6 +1375,7 @@ async function main ()
1375 {
1375 {
1376 questsModal?.handleMessage(message);
1376 questsModal?.handleMessage(message);
1377 settingsModal?.handleMessage(message);
1377 settingsModal?.handleMessage(message);
1378 dialoguesModal?.handleMessage(message);
1378 }
1379 }
1379 else if (message.type === MessageType.editorDialogues)
1380 else if (message.type === MessageType.editorDialogues)
1380 {
1381 {
server/src/quests/runtime.js +27 −6
@@ -5,7 +5,7 @@ import { attachOrigins, godsOrigin } from "../../../shared/items/origin.js";
5 5 import { itemDefinition } from "../../../shared/definitions/items.js";
6 6 import { applySkillXp } from "../../../shared/skills/state.js";
7 7 import { skillLevel } from "../../../shared/definitions/skills.js";
8 import { formatDialogueRewardMessage } from "../../../shared/quests/dialogueRewards.js";
8 import { formatDialogueRewardMessage, formatDialogueQuestRewardMessage } from "../../../shared/quests/dialogueRewards.js";
9 9 import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
10 10 import { floorDiv } from "../world/coordinates.js";
11 11 import { WorkerMessage } from "../simulation/protocol.js";
@@ -307,11 +307,10 @@ export class QuestRuntime
307 307 if (session.phase === "lines")
308 308 {
309 309 const step = tree.steps.find((s) => s.stepId === session.stepId);
310 const rewardMessages = this.#grantStepItemRewards(
311 characterId,
312 step,
313 events
314 );
310 const rewardMessages = [
311 ...this.#grantStepItemRewards(characterId, step, events),
312 ...this.#grantStepQuestRewards(characterId, step, playerView, events)
313 ];
315 314 this.#reevaluateQuests(characterId, playerView, events);
316 315 if (rewardMessages.length > 0)
317 316 {
@@ -448,6 +447,28 @@ export class QuestRuntime
448 447 return messages;
449 448 }
450 449
450 /** Start step.questRewards; returns player-facing notices for newly started quests. */
451 #grantStepQuestRewards (characterId, step, playerView, events)
452 {
453 const rewards = step?.questRewards ?? [];
454 if (!rewards.length)
455 { return []; }
456 const titles = [];
457 for (const questId of rewards)
458 {
459 const current = this.stateDb.getQuestState(characterId, questId);
460 if (current.state !== "not-started")
461 { continue; }
462 const def = this.content.quest(questId);
463 if (!def)
464 { continue; }
465 this.startQuest(characterId, questId, playerView, events);
466 titles.push(def.title || def.questId);
467 }
468 const message = formatDialogueQuestRewardMessage(titles);
469 return message ? [message] : [];
470 }
471
451 472 #loadBag (characterId)
452 473 {
453 474 const onlineId = this.simulation.characterEntities.get(characterId | 0);
@@ -5,7 +5,7 @@ import { attachOrigins, godsOrigin } from "../../../shared/items/origin.js";
5import { itemDefinition } from "../../../shared/definitions/items.js";
5import { itemDefinition } from "../../../shared/definitions/items.js";
6import { applySkillXp } from "../../../shared/skills/state.js";
6import { applySkillXp } from "../../../shared/skills/state.js";
7import { skillLevel } from "../../../shared/definitions/skills.js";
7import { skillLevel } from "../../../shared/definitions/skills.js";
8import { formatDialogueRewardMessage } from "../../../shared/quests/dialogueRewards.js";
8import { formatDialogueRewardMessage, formatDialogueQuestRewardMessage } from "../../../shared/quests/dialogueRewards.js";
9import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
9import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
10import { floorDiv } from "../world/coordinates.js";
10import { floorDiv } from "../world/coordinates.js";
11import { WorkerMessage } from "../simulation/protocol.js";
11import { WorkerMessage } from "../simulation/protocol.js";
@@ -307,11 +307,10 @@ export class QuestRuntime
307 if (session.phase === "lines")
307 if (session.phase === "lines")
308 {
308 {
309 const step = tree.steps.find((s) => s.stepId === session.stepId);
309 const step = tree.steps.find((s) => s.stepId === session.stepId);
310 const rewardMessages = this.#grantStepItemRewards(
310 const rewardMessages = [
311 characterId,
311 ...this.#grantStepItemRewards(characterId, step, events),
312 step,
312 ...this.#grantStepQuestRewards(characterId, step, playerView, events)
313 events
313 ];
314 );
315 this.#reevaluateQuests(characterId, playerView, events);
314 this.#reevaluateQuests(characterId, playerView, events);
316 if (rewardMessages.length > 0)
315 if (rewardMessages.length > 0)
317 {
316 {
@@ -448,6 +447,28 @@ export class QuestRuntime
448 return messages;
447 return messages;
449 }
448 }
450
449
450 /** Start step.questRewards; returns player-facing notices for newly started quests. */
451 #grantStepQuestRewards (characterId, step, playerView, events)
452 {
453 const rewards = step?.questRewards ?? [];
454 if (!rewards.length)
455 { return []; }
456 const titles = [];
457 for (const questId of rewards)
458 {
459 const current = this.stateDb.getQuestState(characterId, questId);
460 if (current.state !== "not-started")
461 { continue; }
462 const def = this.content.quest(questId);
463 if (!def)
464 { continue; }
465 this.startQuest(characterId, questId, playerView, events);
466 titles.push(def.title || def.questId);
467 }
468 const message = formatDialogueQuestRewardMessage(titles);
469 return message ? [message] : [];
470 }
471
451 #loadBag (characterId)
472 #loadBag (characterId)
452 {
473 {
453 const onlineId = this.simulation.characterEntities.get(characterId | 0);
474 const onlineId = this.simulation.characterEntities.get(characterId | 0);
server/tests/quests-conditions.test.js +10 −1
@@ -6,7 +6,7 @@ import {
6 6 ConditionKind
7 7 } from "../../shared/quests/conditions.js";
8 8 import { normalizeQuestDef, normalizeDialogueTree } from "../../shared/quests/normalize.js";
9 import { formatDialogueRewardMessage } from "../../shared/quests/dialogueRewards.js";
9 import { formatDialogueRewardMessage, formatDialogueQuestRewardMessage } from "../../shared/quests/dialogueRewards.js";
10 10
11 11 test("ConditionSet AND + NOT", () =>
12 12 {
@@ -56,6 +56,7 @@ test("normalize quest and dialogue", () =>
56 56 assert.equal(tree.unique, true);
57 57 assert.equal(tree.steps[0].exit.kind, "end");
58 58 assert.deepEqual(tree.steps[0].itemRewards, [{ itemId: 10, quantity: 2 }]);
59 assert.deepEqual(tree.steps[0].questRewards, []);
59 60 });
60 61
61 62 test("dialogue reward messages bag vs bank and lists", () =>
@@ -83,4 +84,12 @@ test("dialogue reward messages bag vs bank and lists", () =>
83 84 ], "bag"),
84 85 "A, B and C have been added to your bag."
85 86 );
87 assert.equal(
88 formatDialogueQuestRewardMessage(["Tin Delivery"]),
89 "The Tin Delivery quest has been added to your journal."
90 );
91 assert.equal(
92 formatDialogueQuestRewardMessage(["Alpha", "Beta"]),
93 "The Alpha and Beta quests have been added to your journal."
94 );
86 95 });
@@ -6,7 +6,7 @@ import {
6 ConditionKind
6 ConditionKind
7} from "../../shared/quests/conditions.js";
7} from "../../shared/quests/conditions.js";
8import { normalizeQuestDef, normalizeDialogueTree } from "../../shared/quests/normalize.js";
8import { normalizeQuestDef, normalizeDialogueTree } from "../../shared/quests/normalize.js";
9import { formatDialogueRewardMessage } from "../../shared/quests/dialogueRewards.js";
9import { formatDialogueRewardMessage, formatDialogueQuestRewardMessage } from "../../shared/quests/dialogueRewards.js";
10
10
11test("ConditionSet AND + NOT", () =>
11test("ConditionSet AND + NOT", () =>
12{
12{
@@ -56,6 +56,7 @@ test("normalize quest and dialogue", () =>
56 assert.equal(tree.unique, true);
56 assert.equal(tree.unique, true);
57 assert.equal(tree.steps[0].exit.kind, "end");
57 assert.equal(tree.steps[0].exit.kind, "end");
58 assert.deepEqual(tree.steps[0].itemRewards, [{ itemId: 10, quantity: 2 }]);
58 assert.deepEqual(tree.steps[0].itemRewards, [{ itemId: 10, quantity: 2 }]);
59 assert.deepEqual(tree.steps[0].questRewards, []);
59});
60});
60
61
61test("dialogue reward messages bag vs bank and lists", () =>
62test("dialogue reward messages bag vs bank and lists", () =>
@@ -83,4 +84,12 @@ test("dialogue reward messages bag vs bank and lists", () =>
83 ], "bag"),
84 ], "bag"),
84 "A, B and C have been added to your bag."
85 "A, B and C have been added to your bag."
85 );
86 );
87 assert.equal(
88 formatDialogueQuestRewardMessage(["Tin Delivery"]),
89 "The Tin Delivery quest has been added to your journal."
90 );
91 assert.equal(
92 formatDialogueQuestRewardMessage(["Alpha", "Beta"]),
93 "The Alpha and Beta quests have been added to your journal."
94 );
86});
95});
shared/quests/dialogueRewards.js +20 −0
@@ -27,3 +27,23 @@ export function formatDialogueRewardMessage (items, destination)
27 27 : "added to your bag";
28 28 return `${subject} ${verb} been ${where}.`;
29 29 }
30
31 /**
32 * Format dialogue step quest-reward notices (player-facing).
33 * @param {string[]} questTitles
34 */
35 export function formatDialogueQuestRewardMessage (questTitles)
36 {
37 const list = (Array.isArray(questTitles) ? questTitles : [])
38 .map((title) => String(title ?? "").trim())
39 .filter(Boolean);
40 if (!list.length)
41 { return null; }
42 const subject = list.length === 1
43 ? `The ${list[0]} quest`
44 : list.length === 2
45 ? `The ${list[0]} and ${list[1]} quests`
46 : `The ${list.slice(0, -1).join(", ")}, and ${list[list.length - 1]} quests`;
47 const verb = list.length > 1 ? "have" : "has";
48 return `${subject} ${verb} been added to your journal.`;
49 }
@@ -27,3 +27,23 @@ export function formatDialogueRewardMessage (items, destination)
27 : "added to your bag";
27 : "added to your bag";
28 return `${subject} ${verb} been ${where}.`;
28 return `${subject} ${verb} been ${where}.`;
29}
29}
30
31/**
32 * Format dialogue step quest-reward notices (player-facing).
33 * @param {string[]} questTitles
34 */
35export function formatDialogueQuestRewardMessage (questTitles)
36{
37 const list = (Array.isArray(questTitles) ? questTitles : [])
38 .map((title) => String(title ?? "").trim())
39 .filter(Boolean);
40 if (!list.length)
41 { return null; }
42 const subject = list.length === 1
43 ? `The ${list[0]} quest`
44 : list.length === 2
45 ? `The ${list[0]} and ${list[1]} quests`
46 : `The ${list.slice(0, -1).join(", ")}, and ${list[list.length - 1]} quests`;
47 const verb = list.length > 1 ? "have" : "has";
48 return `${subject} ${verb} been added to your journal.`;
49}
shared/quests/normalize.js +19 −0
@@ -85,6 +85,7 @@ function normalizeDialogueStep (raw, index)
85 85 label: String(raw?.label ?? stepId).trim().slice(0, 80) || stepId,
86 86 lines: lines.length > 0 ? lines : [{ speaker: "npc", text: "…", effects: [] }],
87 87 itemRewards: normalizeItemRewards(raw?.itemRewards),
88 questRewards: normalizeQuestRewards(raw?.questRewards),
88 89 exit
89 90 };
90 91 }
@@ -112,6 +113,24 @@ function normalizeItemRewards (raw)
112 113 return out;
113 114 }
114 115
116 /** Step-level quests started after lines (same moment as item rewards). */
117 function normalizeQuestRewards (raw)
118 {
119 if (!Array.isArray(raw))
120 { return []; }
121 const out = [];
122 const seen = new Set();
123 for (const entry of raw)
124 {
125 const questId = String(entry?.questId ?? entry ?? "").trim().slice(0, 80);
126 if (!questId || seen.has(questId))
127 { continue; }
128 seen.add(questId);
129 out.push(questId);
130 }
131 return out;
132 }
133
115 134 function normalizeDialogueLine (raw)
116 135 {
117 136 if (!raw || typeof raw !== "object")
@@ -85,6 +85,7 @@ function normalizeDialogueStep (raw, index)
85 label: String(raw?.label ?? stepId).trim().slice(0, 80) || stepId,
85 label: String(raw?.label ?? stepId).trim().slice(0, 80) || stepId,
86 lines: lines.length > 0 ? lines : [{ speaker: "npc", text: "…", effects: [] }],
86 lines: lines.length > 0 ? lines : [{ speaker: "npc", text: "…", effects: [] }],
87 itemRewards: normalizeItemRewards(raw?.itemRewards),
87 itemRewards: normalizeItemRewards(raw?.itemRewards),
88 questRewards: normalizeQuestRewards(raw?.questRewards),
88 exit
89 exit
89 };
90 };
90}
91}
@@ -112,6 +113,24 @@ function normalizeItemRewards (raw)
112 return out;
113 return out;
113}
114}
114
115
116/** Step-level quests started after lines (same moment as item rewards). */
117function normalizeQuestRewards (raw)
118{
119 if (!Array.isArray(raw))
120 { return []; }
121 const out = [];
122 const seen = new Set();
123 for (const entry of raw)
124 {
125 const questId = String(entry?.questId ?? entry ?? "").trim().slice(0, 80);
126 if (!questId || seen.has(questId))
127 { continue; }
128 seen.add(questId);
129 out.push(questId);
130 }
131 return out;
132}
133
115function normalizeDialogueLine (raw)
134function normalizeDialogueLine (raw)
116{
135{
117 if (!raw || typeof raw !== "object")
136 if (!raw || typeof raw !== "object")