BlueGit

timfa questward

Add world-settings initial quests for new and existing characters.

Authors pick starter quests under Settings → Quests; they grant on create/login and when the list is saved, unless already started or completed.

timfa Tim Falken · pushed by timfa

Authored 2026-09-06 · 2 months ago

Hash
409992f3b8ba1aaf301f89fc94faf1da8ca636d7
Parent
e528f767
12 files changed +283 −6
client/src/editor/main.js +4 −1
@@ -1372,7 +1372,10 @@ async function main ()
1372 1372 applyDimensionsList(message);
1373 1373 }
1374 1374 else if (message.type === MessageType.editorQuests)
1375 { questsModal?.handleMessage(message); }
1375 {
1376 questsModal?.handleMessage(message);
1377 settingsModal?.handleMessage(message);
1378 }
1376 1379 else if (message.type === MessageType.editorDialogues)
1377 1380 {
1378 1381 dialoguesModal?.handleMessage(message);
@@ -1372,7 +1372,10 @@ async function main ()
1372 applyDimensionsList(message);
1372 applyDimensionsList(message);
1373 }
1373 }
1374 else if (message.type === MessageType.editorQuests)
1374 else if (message.type === MessageType.editorQuests)
1375 { questsModal?.handleMessage(message); }
1375 {
1376 questsModal?.handleMessage(message);
1377 settingsModal?.handleMessage(message);
1378 }
1376 else if (message.type === MessageType.editorDialogues)
1379 else if (message.type === MessageType.editorDialogues)
1377 {
1380 {
1378 dialoguesModal?.handleMessage(message);
1381 dialoguesModal?.handleMessage(message);
client/src/editor/settingsModal.js +143 −1
@@ -22,6 +22,12 @@ import
22 22 DEFAULT_STARTER_EQUIPMENT,
23 23 DEFAULT_STARTER_INVENTORY
24 24 } from "/shared/items/starterLoadout.js";
25 import
26 {
27 normalizeInitialQuests,
28 initialQuestsEqual
29 } from "/shared/quests/initialQuests.js";
30 import { normalizeQuestDef } from "/shared/quests/normalize.js";
25 31 import
26 32 {
27 33 EQUIPMENT_STAT_CATEGORIES,
@@ -70,6 +76,11 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
70 76 starterInventory: DEFAULT_STARTER_INVENTORY
71 77 });
72 78 let starterPanel = null;
79 /** @type {string[]} */
80 let draftInitialQuests = [];
81 /** @type {{ questId: string, title: string }[]} */
82 let questCatalog = [];
83 let initialQuestsPanel = null;
73 84 let draftEquipmentStats = normalizeEquipmentStatBonuses(null);
74 85 let equipmentStatsPanel = null;
75 86 let equipmentStatsCategoryId = EQUIPMENT_STAT_CATEGORIES[0]?.id ?? null;
@@ -87,6 +98,11 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
87 98 { renderSeedPanel(); }
88 99 if (id === "starterEquipment")
89 100 { renderStarterPanel(); }
101 if (id === "initialQuests")
102 {
103 socket.send({ type: MessageType.editorLoadQuests });
104 renderInitialQuestsPanel();
105 }
90 106 if (id === "equipmentStats")
91 107 { renderEquipmentStatsPanel(); }
92 108 if (id === "gameAdmins")
@@ -108,6 +124,10 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
108 124 {
109 125 starterPanel = panel;
110 126 },
127 onInitialQuestsPanelReady (panel)
128 {
129 initialQuestsPanel = panel;
130 },
111 131 onEquipmentStatsPanelReady (panel)
112 132 {
113 133 equipmentStatsPanel = panel;
@@ -150,6 +170,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
150 170 refreshDirty();
151 171 });
152 172 form.addEventListener("starter-changed", () => refreshDirty());
173 form.addEventListener("initial-quests-changed", () => refreshDirty());
153 174 form.addEventListener("equipment-stats-changed", () => refreshDirty());
154 175 form.addEventListener("equip-stats-category", (event) =>
155 176 {
@@ -168,6 +189,15 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
168 189 renderStarterPanel();
169 190 form.dispatchEvent(new CustomEvent("starter-changed"));
170 191 });
192 form.addEventListener("initial-quests-add", () =>
193 {
194 const available = questCatalog.find((q) => !draftInitialQuests.includes(q.questId));
195 if (!available)
196 { return; }
197 draftInitialQuests = normalizeInitialQuests([...draftInitialQuests, available.questId]);
198 renderInitialQuestsPanel();
199 form.dispatchEvent(new CustomEvent("initial-quests-changed"));
200 });
171 201 form.addEventListener("game-admin-grant", (event) =>
172 202 {
173 203 const username = String(event.detail?.username ?? "").trim();
@@ -244,6 +274,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
244 274 fillForm(form, baseline);
245 275 draftSeeds = { ...normalizeItemSeedValues(baseline.itemSeedValues) };
246 276 draftStarter = normalizeStarterLoadout(baseline);
277 draftInitialQuests = normalizeInitialQuests(baseline.initialQuests);
247 278 draftEquipmentStats = normalizeEquipmentStatBonuses(baseline.equipmentStatBonuses);
248 279 seedQuery = "";
249 280 seedPage = 0;
@@ -251,6 +282,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
251 282 { seedPanel.search.value = ""; }
252 283 renderSeedPanel();
253 284 renderStarterPanel();
285 renderInitialQuestsPanel();
254 286 renderEquipmentStatsPanel();
255 287 refreshDirty();
256 288 }
@@ -286,6 +318,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
286 318 itemSeedValues: draftSeeds,
287 319 starterEquipment: draftStarter.equipment,
288 320 starterInventory: draftStarter.inventory,
321 initialQuests: draftInitialQuests,
289 322 equipmentStatBonuses: draftEquipmentStats
290 323 };
291 324 }
@@ -306,6 +339,9 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
306 339 changed.starterEquipment = nextStarter.equipment;
307 340 changed.starterInventory = nextStarter.inventory;
308 341 }
342 const nextInitialQuests = normalizeInitialQuests(draftInitialQuests);
343 if (!initialQuestsEqual(baseline.initialQuests, nextInitialQuests))
344 { changed.initialQuests = nextInitialQuests; }
309 345 const nextEquip = normalizeEquipmentStatBonuses(draftEquipmentStats);
310 346 if (!equipmentStatBonusMapsEqual(baseline.equipmentStatBonuses, nextEquip))
311 347 { changed.equipmentStatBonuses = nextEquip; }
@@ -529,6 +565,72 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
529 565 refreshDirty();
530 566 }
531 567
568 function renderInitialQuestsPanel ()
569 {
570 if (!initialQuestsPanel)
571 { return; }
572 const { listRoot, addBtn } = initialQuestsPanel;
573 listRoot.replaceChildren();
574 const taken = new Set(draftInitialQuests);
575 const available = questCatalog.filter((q) => !taken.has(q.questId));
576 addBtn.disabled = available.length === 0;
577 if (!draftInitialQuests.length)
578 {
579 const empty = document.createElement("p");
580 empty.className = "hint";
581 empty.textContent = "No initial quests.";
582 listRoot.append(empty);
583 }
584 draftInitialQuests.forEach((questId, index) =>
585 {
586 const row = document.createElement("div");
587 row.className = "initial-quest-row";
588 const select = document.createElement("select");
589 const catalog = questCatalog.length
590 ? questCatalog
591 : [{ questId, title: questId }];
592 for (const quest of catalog)
593 {
594 if (taken.has(quest.questId) && quest.questId !== questId)
595 { continue; }
596 const opt = document.createElement("option");
597 opt.value = quest.questId;
598 opt.textContent = quest.title
599 ? `${quest.title} (${quest.questId})`
600 : quest.questId;
601 select.append(opt);
602 }
603 if (![...select.options].some((o) => o.value === questId))
604 {
605 const missing = document.createElement("option");
606 missing.value = questId;
607 missing.textContent = `${questId} (missing)`;
608 select.append(missing);
609 }
610 select.value = questId;
611 select.addEventListener("change", () =>
612 {
613 const next = draftInitialQuests.slice();
614 next[index] = select.value;
615 draftInitialQuests = normalizeInitialQuests(next);
616 renderInitialQuestsPanel();
617 form.dispatchEvent(new CustomEvent("initial-quests-changed"));
618 });
619 const remove = document.createElement("button");
620 remove.type = "button";
621 remove.textContent = "Remove";
622 remove.addEventListener("click", () =>
623 {
624 draftInitialQuests = draftInitialQuests.filter((_, i) => i !== index);
625 renderInitialQuestsPanel();
626 form.dispatchEvent(new CustomEvent("initial-quests-changed"));
627 });
628 row.append(select, remove);
629 listRoot.append(row);
630 });
631 refreshDirty();
632 }
633
532 634 function setRowIcon (img, itemId)
533 635 {
534 636 if (!img)
@@ -734,21 +836,34 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
734 836 renderGameAdminsPanel();
735 837 return;
736 838 }
839 if (message.type === MessageType.editorQuests)
840 {
841 questCatalog = (message.quests ?? []).map((q) =>
842 {
843 const def = normalizeQuestDef(q);
844 return { questId: def.questId, title: def.title };
845 });
846 renderInitialQuestsPanel();
847 return;
848 }
737 849 loaded = true;
738 850 baseline = {
739 851 ...message.settings,
740 852 itemSeedValues: normalizeItemSeedValues(message.settings?.itemSeedValues),
741 equipmentStatBonuses: normalizeEquipmentStatBonuses(message.settings?.equipmentStatBonuses)
853 equipmentStatBonuses: normalizeEquipmentStatBonuses(message.settings?.equipmentStatBonuses),
854 initialQuests: normalizeInitialQuests(message.settings?.initialQuests)
742 855 };
743 856 itemLastSales = message.itemLastSales && typeof message.itemLastSales === "object"
744 857 ? message.itemLastSales
745 858 : {};
746 859 draftSeeds = { ...baseline.itemSeedValues };
747 860 draftStarter = normalizeStarterLoadout(baseline);
861 draftInitialQuests = normalizeInitialQuests(baseline.initialQuests);
748 862 draftEquipmentStats = normalizeEquipmentStatBonuses(baseline.equipmentStatBonuses);
749 863 fillForm(form, baseline);
750 864 renderSeedPanel();
751 865 renderStarterPanel();
866 renderInitialQuestsPanel();
752 867 renderEquipmentStatsPanel();
753 868 refreshDirty();
754 869 renderLog(log, message.changelog ?? []);
@@ -763,6 +878,7 @@ function buildForm (form, {
763 878 onFieldInput,
764 879 onSeedPanelReady,
765 880 onStarterPanelReady,
881 onInitialQuestsPanelReady,
766 882 onEquipmentStatsPanelReady,
767 883 onGameAdminsPanelReady
768 884 })
@@ -810,6 +926,15 @@ function buildForm (form, {
810 926 section.append(panel.root);
811 927 onStarterPanelReady?.(panel);
812 928 }
929 else if (category.panel === "initialQuests")
930 {
931 const panel = buildInitialQuestsPanel({
932 onAdd ()
933 { form.dispatchEvent(new CustomEvent("initial-quests-add")); }
934 });
935 section.append(panel.root);
936 onInitialQuestsPanelReady?.(panel);
937 }
813 938 else if (category.panel === "equipmentStats")
814 939 {
815 940 const panel = buildEquipmentStatsPanel({
@@ -1016,6 +1141,23 @@ function buildStarterEquipmentPanel ({ onAddInventory })
1016 1141 return { root, equipRoot, invRoot };
1017 1142 }
1018 1143
1144 function buildInitialQuestsPanel ({ onAdd })
1145 {
1146 const root = document.createElement("div");
1147 root.className = "initial-quests-panel";
1148 const hint = document.createElement("p");
1149 hint.className = "hint";
1150 hint.textContent = "These quests are granted to new characters. Existing characters also receive them on save or login unless the quest is already started or completed.";
1151 const listRoot = document.createElement("div");
1152 listRoot.className = "initial-quests-list";
1153 const addBtn = document.createElement("button");
1154 addBtn.type = "button";
1155 addBtn.textContent = "Add quest";
1156 addBtn.addEventListener("click", () => onAdd?.());
1157 root.append(hint, listRoot, addBtn);
1158 return { root, listRoot, addBtn };
1159 }
1160
1019 1161 function listAllItems ()
1020 1162 {
1021 1163 return Object.values(ITEM_DEFINITIONS)
@@ -22,6 +22,12 @@ import
22 DEFAULT_STARTER_EQUIPMENT,
22 DEFAULT_STARTER_EQUIPMENT,
23 DEFAULT_STARTER_INVENTORY
23 DEFAULT_STARTER_INVENTORY
24 } from "/shared/items/starterLoadout.js";
24 } from "/shared/items/starterLoadout.js";
25import
26 {
27 normalizeInitialQuests,
28 initialQuestsEqual
29 } from "/shared/quests/initialQuests.js";
30import { normalizeQuestDef } from "/shared/quests/normalize.js";
25import
31import
26 {
32 {
27 EQUIPMENT_STAT_CATEGORIES,
33 EQUIPMENT_STAT_CATEGORIES,
@@ -70,6 +76,11 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
70 starterInventory: DEFAULT_STARTER_INVENTORY
76 starterInventory: DEFAULT_STARTER_INVENTORY
71 });
77 });
72 let starterPanel = null;
78 let starterPanel = null;
79 /** @type {string[]} */
80 let draftInitialQuests = [];
81 /** @type {{ questId: string, title: string }[]} */
82 let questCatalog = [];
83 let initialQuestsPanel = null;
73 let draftEquipmentStats = normalizeEquipmentStatBonuses(null);
84 let draftEquipmentStats = normalizeEquipmentStatBonuses(null);
74 let equipmentStatsPanel = null;
85 let equipmentStatsPanel = null;
75 let equipmentStatsCategoryId = EQUIPMENT_STAT_CATEGORIES[0]?.id ?? null;
86 let equipmentStatsCategoryId = EQUIPMENT_STAT_CATEGORIES[0]?.id ?? null;
@@ -87,6 +98,11 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
87 { renderSeedPanel(); }
98 { renderSeedPanel(); }
88 if (id === "starterEquipment")
99 if (id === "starterEquipment")
89 { renderStarterPanel(); }
100 { renderStarterPanel(); }
101 if (id === "initialQuests")
102 {
103 socket.send({ type: MessageType.editorLoadQuests });
104 renderInitialQuestsPanel();
105 }
90 if (id === "equipmentStats")
106 if (id === "equipmentStats")
91 { renderEquipmentStatsPanel(); }
107 { renderEquipmentStatsPanel(); }
92 if (id === "gameAdmins")
108 if (id === "gameAdmins")
@@ -108,6 +124,10 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
108 {
124 {
109 starterPanel = panel;
125 starterPanel = panel;
110 },
126 },
127 onInitialQuestsPanelReady (panel)
128 {
129 initialQuestsPanel = panel;
130 },
111 onEquipmentStatsPanelReady (panel)
131 onEquipmentStatsPanelReady (panel)
112 {
132 {
113 equipmentStatsPanel = panel;
133 equipmentStatsPanel = panel;
@@ -150,6 +170,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
150 refreshDirty();
170 refreshDirty();
151 });
171 });
152 form.addEventListener("starter-changed", () => refreshDirty());
172 form.addEventListener("starter-changed", () => refreshDirty());
173 form.addEventListener("initial-quests-changed", () => refreshDirty());
153 form.addEventListener("equipment-stats-changed", () => refreshDirty());
174 form.addEventListener("equipment-stats-changed", () => refreshDirty());
154 form.addEventListener("equip-stats-category", (event) =>
175 form.addEventListener("equip-stats-category", (event) =>
155 {
176 {
@@ -168,6 +189,15 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
168 renderStarterPanel();
189 renderStarterPanel();
169 form.dispatchEvent(new CustomEvent("starter-changed"));
190 form.dispatchEvent(new CustomEvent("starter-changed"));
170 });
191 });
192 form.addEventListener("initial-quests-add", () =>
193 {
194 const available = questCatalog.find((q) => !draftInitialQuests.includes(q.questId));
195 if (!available)
196 { return; }
197 draftInitialQuests = normalizeInitialQuests([...draftInitialQuests, available.questId]);
198 renderInitialQuestsPanel();
199 form.dispatchEvent(new CustomEvent("initial-quests-changed"));
200 });
171 form.addEventListener("game-admin-grant", (event) =>
201 form.addEventListener("game-admin-grant", (event) =>
172 {
202 {
173 const username = String(event.detail?.username ?? "").trim();
203 const username = String(event.detail?.username ?? "").trim();
@@ -244,6 +274,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
244 fillForm(form, baseline);
274 fillForm(form, baseline);
245 draftSeeds = { ...normalizeItemSeedValues(baseline.itemSeedValues) };
275 draftSeeds = { ...normalizeItemSeedValues(baseline.itemSeedValues) };
246 draftStarter = normalizeStarterLoadout(baseline);
276 draftStarter = normalizeStarterLoadout(baseline);
277 draftInitialQuests = normalizeInitialQuests(baseline.initialQuests);
247 draftEquipmentStats = normalizeEquipmentStatBonuses(baseline.equipmentStatBonuses);
278 draftEquipmentStats = normalizeEquipmentStatBonuses(baseline.equipmentStatBonuses);
248 seedQuery = "";
279 seedQuery = "";
249 seedPage = 0;
280 seedPage = 0;
@@ -251,6 +282,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
251 { seedPanel.search.value = ""; }
282 { seedPanel.search.value = ""; }
252 renderSeedPanel();
283 renderSeedPanel();
253 renderStarterPanel();
284 renderStarterPanel();
285 renderInitialQuestsPanel();
254 renderEquipmentStatsPanel();
286 renderEquipmentStatsPanel();
255 refreshDirty();
287 refreshDirty();
256 }
288 }
@@ -286,6 +318,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
286 itemSeedValues: draftSeeds,
318 itemSeedValues: draftSeeds,
287 starterEquipment: draftStarter.equipment,
319 starterEquipment: draftStarter.equipment,
288 starterInventory: draftStarter.inventory,
320 starterInventory: draftStarter.inventory,
321 initialQuests: draftInitialQuests,
289 equipmentStatBonuses: draftEquipmentStats
322 equipmentStatBonuses: draftEquipmentStats
290 };
323 };
291 }
324 }
@@ -306,6 +339,9 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
306 changed.starterEquipment = nextStarter.equipment;
339 changed.starterEquipment = nextStarter.equipment;
307 changed.starterInventory = nextStarter.inventory;
340 changed.starterInventory = nextStarter.inventory;
308 }
341 }
342 const nextInitialQuests = normalizeInitialQuests(draftInitialQuests);
343 if (!initialQuestsEqual(baseline.initialQuests, nextInitialQuests))
344 { changed.initialQuests = nextInitialQuests; }
309 const nextEquip = normalizeEquipmentStatBonuses(draftEquipmentStats);
345 const nextEquip = normalizeEquipmentStatBonuses(draftEquipmentStats);
310 if (!equipmentStatBonusMapsEqual(baseline.equipmentStatBonuses, nextEquip))
346 if (!equipmentStatBonusMapsEqual(baseline.equipmentStatBonuses, nextEquip))
311 { changed.equipmentStatBonuses = nextEquip; }
347 { changed.equipmentStatBonuses = nextEquip; }
@@ -529,6 +565,72 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
529 refreshDirty();
565 refreshDirty();
530 }
566 }
531
567
568 function renderInitialQuestsPanel ()
569 {
570 if (!initialQuestsPanel)
571 { return; }
572 const { listRoot, addBtn } = initialQuestsPanel;
573 listRoot.replaceChildren();
574 const taken = new Set(draftInitialQuests);
575 const available = questCatalog.filter((q) => !taken.has(q.questId));
576 addBtn.disabled = available.length === 0;
577 if (!draftInitialQuests.length)
578 {
579 const empty = document.createElement("p");
580 empty.className = "hint";
581 empty.textContent = "No initial quests.";
582 listRoot.append(empty);
583 }
584 draftInitialQuests.forEach((questId, index) =>
585 {
586 const row = document.createElement("div");
587 row.className = "initial-quest-row";
588 const select = document.createElement("select");
589 const catalog = questCatalog.length
590 ? questCatalog
591 : [{ questId, title: questId }];
592 for (const quest of catalog)
593 {
594 if (taken.has(quest.questId) && quest.questId !== questId)
595 { continue; }
596 const opt = document.createElement("option");
597 opt.value = quest.questId;
598 opt.textContent = quest.title
599 ? `${quest.title} (${quest.questId})`
600 : quest.questId;
601 select.append(opt);
602 }
603 if (![...select.options].some((o) => o.value === questId))
604 {
605 const missing = document.createElement("option");
606 missing.value = questId;
607 missing.textContent = `${questId} (missing)`;
608 select.append(missing);
609 }
610 select.value = questId;
611 select.addEventListener("change", () =>
612 {
613 const next = draftInitialQuests.slice();
614 next[index] = select.value;
615 draftInitialQuests = normalizeInitialQuests(next);
616 renderInitialQuestsPanel();
617 form.dispatchEvent(new CustomEvent("initial-quests-changed"));
618 });
619 const remove = document.createElement("button");
620 remove.type = "button";
621 remove.textContent = "Remove";
622 remove.addEventListener("click", () =>
623 {
624 draftInitialQuests = draftInitialQuests.filter((_, i) => i !== index);
625 renderInitialQuestsPanel();
626 form.dispatchEvent(new CustomEvent("initial-quests-changed"));
627 });
628 row.append(select, remove);
629 listRoot.append(row);
630 });
631 refreshDirty();
632 }
633
532 function setRowIcon (img, itemId)
634 function setRowIcon (img, itemId)
533 {
635 {
534 if (!img)
636 if (!img)
@@ -734,21 +836,34 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
734 renderGameAdminsPanel();
836 renderGameAdminsPanel();
735 return;
837 return;
736 }
838 }
839 if (message.type === MessageType.editorQuests)
840 {
841 questCatalog = (message.quests ?? []).map((q) =>
842 {
843 const def = normalizeQuestDef(q);
844 return { questId: def.questId, title: def.title };
845 });
846 renderInitialQuestsPanel();
847 return;
848 }
737 loaded = true;
849 loaded = true;
738 baseline = {
850 baseline = {
739 ...message.settings,
851 ...message.settings,
740 itemSeedValues: normalizeItemSeedValues(message.settings?.itemSeedValues),
852 itemSeedValues: normalizeItemSeedValues(message.settings?.itemSeedValues),
741 equipmentStatBonuses: normalizeEquipmentStatBonuses(message.settings?.equipmentStatBonuses)
853 equipmentStatBonuses: normalizeEquipmentStatBonuses(message.settings?.equipmentStatBonuses),
854 initialQuests: normalizeInitialQuests(message.settings?.initialQuests)
742 };
855 };
743 itemLastSales = message.itemLastSales && typeof message.itemLastSales === "object"
856 itemLastSales = message.itemLastSales && typeof message.itemLastSales === "object"
744 ? message.itemLastSales
857 ? message.itemLastSales
745 : {};
858 : {};
746 draftSeeds = { ...baseline.itemSeedValues };
859 draftSeeds = { ...baseline.itemSeedValues };
747 draftStarter = normalizeStarterLoadout(baseline);
860 draftStarter = normalizeStarterLoadout(baseline);
861 draftInitialQuests = normalizeInitialQuests(baseline.initialQuests);
748 draftEquipmentStats = normalizeEquipmentStatBonuses(baseline.equipmentStatBonuses);
862 draftEquipmentStats = normalizeEquipmentStatBonuses(baseline.equipmentStatBonuses);
749 fillForm(form, baseline);
863 fillForm(form, baseline);
750 renderSeedPanel();
864 renderSeedPanel();
751 renderStarterPanel();
865 renderStarterPanel();
866 renderInitialQuestsPanel();
752 renderEquipmentStatsPanel();
867 renderEquipmentStatsPanel();
753 refreshDirty();
868 refreshDirty();
754 renderLog(log, message.changelog ?? []);
869 renderLog(log, message.changelog ?? []);
@@ -763,6 +878,7 @@ function buildForm (form, {
763 onFieldInput,
878 onFieldInput,
764 onSeedPanelReady,
879 onSeedPanelReady,
765 onStarterPanelReady,
880 onStarterPanelReady,
881 onInitialQuestsPanelReady,
766 onEquipmentStatsPanelReady,
882 onEquipmentStatsPanelReady,
767 onGameAdminsPanelReady
883 onGameAdminsPanelReady
768})
884})
@@ -810,6 +926,15 @@ function buildForm (form, {
810 section.append(panel.root);
926 section.append(panel.root);
811 onStarterPanelReady?.(panel);
927 onStarterPanelReady?.(panel);
812 }
928 }
929 else if (category.panel === "initialQuests")
930 {
931 const panel = buildInitialQuestsPanel({
932 onAdd ()
933 { form.dispatchEvent(new CustomEvent("initial-quests-add")); }
934 });
935 section.append(panel.root);
936 onInitialQuestsPanelReady?.(panel);
937 }
813 else if (category.panel === "equipmentStats")
938 else if (category.panel === "equipmentStats")
814 {
939 {
815 const panel = buildEquipmentStatsPanel({
940 const panel = buildEquipmentStatsPanel({
@@ -1016,6 +1141,23 @@ function buildStarterEquipmentPanel ({ onAddInventory })
1016 return { root, equipRoot, invRoot };
1141 return { root, equipRoot, invRoot };
1017}
1142}
1018
1143
1144function buildInitialQuestsPanel ({ onAdd })
1145{
1146 const root = document.createElement("div");
1147 root.className = "initial-quests-panel";
1148 const hint = document.createElement("p");
1149 hint.className = "hint";
1150 hint.textContent = "These quests are granted to new characters. Existing characters also receive them on save or login unless the quest is already started or completed.";
1151 const listRoot = document.createElement("div");
1152 listRoot.className = "initial-quests-list";
1153 const addBtn = document.createElement("button");
1154 addBtn.type = "button";
1155 addBtn.textContent = "Add quest";
1156 addBtn.addEventListener("click", () => onAdd?.());
1157 root.append(hint, listRoot, addBtn);
1158 return { root, listRoot, addBtn };
1159}
1160
1019function listAllItems ()
1161function listAllItems ()
1020{
1162{
1021 return Object.values(ITEM_DEFINITIONS)
1163 return Object.values(ITEM_DEFINITIONS)
client/ui/editor.css +18 −0
@@ -728,6 +728,24 @@ label {
728 728 align-items: center;
729 729 }
730 730
731 .initial-quests-panel .hint {
732 margin: 0 0 0.6rem;
733 }
734
735 .initial-quests-list {
736 display: flex;
737 flex-direction: column;
738 gap: 0.4rem;
739 margin-bottom: 0.6rem;
740 }
741
742 .initial-quest-row {
743 display: grid;
744 grid-template-columns: 1fr auto;
745 gap: 0.4rem;
746 align-items: center;
747 }
748
731 749 .equip-stats-panel {
732 750 display: flex;
733 751 flex-direction: column;
@@ -728,6 +728,24 @@ label {
728 align-items: center;
728 align-items: center;
729}
729}
730
730
731.initial-quests-panel .hint {
732 margin: 0 0 0.6rem;
733}
734
735.initial-quests-list {
736 display: flex;
737 flex-direction: column;
738 gap: 0.4rem;
739 margin-bottom: 0.6rem;
740}
741
742.initial-quest-row {
743 display: grid;
744 grid-template-columns: 1fr auto;
745 gap: 0.4rem;
746 align-items: center;
747}
748
731.equip-stats-panel {
749.equip-stats-panel {
732 display: flex;
750 display: flex;
733 flex-direction: column;
751 flex-direction: column;
server/src/editor/service.js +26 −2
@@ -13,6 +13,11 @@ import {
13 13 starterLoadoutsEqual,
14 14 diffStarterLoadout
15 15 } from "../../../shared/items/starterLoadout.js";
16 import {
17 normalizeInitialQuests,
18 initialQuestsEqual,
19 diffInitialQuests
20 } from "../../../shared/quests/initialQuests.js";
16 21 import {
17 22 normalizeEquipmentStatBonuses,
18 23 diffEquipmentStatBonuses,
@@ -289,6 +294,10 @@ export class EditorService
289 294 {
290 295 next.equipmentStatBonuses = normalizeEquipmentStatBonuses(current.equipmentStatBonuses);
291 296 }
297 if (Object.prototype.hasOwnProperty.call(partial, "initialQuests"))
298 { next.initialQuests = normalizeInitialQuests(partial.initialQuests); }
299 else
300 { next.initialQuests = normalizeInitialQuests(current.initialQuests); }
292 301 const { bullets: scalarBullets, changed } = diffSettings(current, next);
293 302 const seedBullets = Object.prototype.hasOwnProperty.call(partial, "itemSeedValues")
294 303 ? diffItemSeedValues(
@@ -324,7 +333,20 @@ export class EditorService
324 333 (itemId) => itemDefinition(itemId)?.displayName ?? null
325 334 )
326 335 : [];
327 const bullets = [...scalarBullets, ...seedBullets, ...starterBullets, ...equipmentStatBullets];
336 const initialQuestsChanged = Object.prototype.hasOwnProperty.call(partial, "initialQuests")
337 && !initialQuestsEqual(current.initialQuests, next.initialQuests);
338 if (initialQuestsChanged)
339 { changed.initialQuests = next.initialQuests; }
340 const initialQuestBullets = initialQuestsChanged
341 ? diffInitialQuests(current.initialQuests, next.initialQuests)
342 : [];
343 const bullets = [
344 ...scalarBullets,
345 ...seedBullets,
346 ...starterBullets,
347 ...equipmentStatBullets,
348 ...initialQuestBullets
349 ];
328 350 if (Object.keys(changed).length === 0)
329 351 {
330 352 return {
@@ -344,7 +366,9 @@ export class EditorService
344 366 starterInventory: changed.starterInventory ?? current.starterInventory
345 367 ?? DEFAULT_WORLD_SETTINGS.starterInventory,
346 368 equipmentStatBonuses: changed.equipmentStatBonuses
347 ?? normalizeEquipmentStatBonuses(current.equipmentStatBonuses)
369 ?? normalizeEquipmentStatBonuses(current.equipmentStatBonuses),
370 initialQuests: changed.initialQuests
371 ?? normalizeInitialQuests(current.initialQuests)
348 372 };
349 373 const normalized = normalizeStarterLoadout(settings);
350 374 settings.starterEquipment = normalized.equipment;
@@ -13,6 +13,11 @@ import {
13 starterLoadoutsEqual,
13 starterLoadoutsEqual,
14 diffStarterLoadout
14 diffStarterLoadout
15} from "../../../shared/items/starterLoadout.js";
15} from "../../../shared/items/starterLoadout.js";
16import {
17 normalizeInitialQuests,
18 initialQuestsEqual,
19 diffInitialQuests
20} from "../../../shared/quests/initialQuests.js";
16import {
21import {
17 normalizeEquipmentStatBonuses,
22 normalizeEquipmentStatBonuses,
18 diffEquipmentStatBonuses,
23 diffEquipmentStatBonuses,
@@ -289,6 +294,10 @@ export class EditorService
289 {
294 {
290 next.equipmentStatBonuses = normalizeEquipmentStatBonuses(current.equipmentStatBonuses);
295 next.equipmentStatBonuses = normalizeEquipmentStatBonuses(current.equipmentStatBonuses);
291 }
296 }
297 if (Object.prototype.hasOwnProperty.call(partial, "initialQuests"))
298 { next.initialQuests = normalizeInitialQuests(partial.initialQuests); }
299 else
300 { next.initialQuests = normalizeInitialQuests(current.initialQuests); }
292 const { bullets: scalarBullets, changed } = diffSettings(current, next);
301 const { bullets: scalarBullets, changed } = diffSettings(current, next);
293 const seedBullets = Object.prototype.hasOwnProperty.call(partial, "itemSeedValues")
302 const seedBullets = Object.prototype.hasOwnProperty.call(partial, "itemSeedValues")
294 ? diffItemSeedValues(
303 ? diffItemSeedValues(
@@ -324,7 +333,20 @@ export class EditorService
324 (itemId) => itemDefinition(itemId)?.displayName ?? null
333 (itemId) => itemDefinition(itemId)?.displayName ?? null
325 )
334 )
326 : [];
335 : [];
327 const bullets = [...scalarBullets, ...seedBullets, ...starterBullets, ...equipmentStatBullets];
336 const initialQuestsChanged = Object.prototype.hasOwnProperty.call(partial, "initialQuests")
337 && !initialQuestsEqual(current.initialQuests, next.initialQuests);
338 if (initialQuestsChanged)
339 { changed.initialQuests = next.initialQuests; }
340 const initialQuestBullets = initialQuestsChanged
341 ? diffInitialQuests(current.initialQuests, next.initialQuests)
342 : [];
343 const bullets = [
344 ...scalarBullets,
345 ...seedBullets,
346 ...starterBullets,
347 ...equipmentStatBullets,
348 ...initialQuestBullets
349 ];
328 if (Object.keys(changed).length === 0)
350 if (Object.keys(changed).length === 0)
329 {
351 {
330 return {
352 return {
@@ -344,7 +366,9 @@ export class EditorService
344 starterInventory: changed.starterInventory ?? current.starterInventory
366 starterInventory: changed.starterInventory ?? current.starterInventory
345 ?? DEFAULT_WORLD_SETTINGS.starterInventory,
367 ?? DEFAULT_WORLD_SETTINGS.starterInventory,
346 equipmentStatBonuses: changed.equipmentStatBonuses
368 equipmentStatBonuses: changed.equipmentStatBonuses
347 ?? normalizeEquipmentStatBonuses(current.equipmentStatBonuses)
369 ?? normalizeEquipmentStatBonuses(current.equipmentStatBonuses),
370 initialQuests: changed.initialQuests
371 ?? normalizeInitialQuests(current.initialQuests)
348 };
372 };
349 const normalized = normalizeStarterLoadout(settings);
373 const normalized = normalizeStarterLoadout(settings);
350 settings.starterEquipment = normalized.equipment;
374 settings.starterEquipment = normalized.equipment;
server/src/gateway/websocket.js +3 −1
@@ -1048,7 +1048,9 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1048 1048 requireAdmin(session);
1049 1049 {
1050 1050 const saved = editor.saveSettings(message.settings ?? {}, session.authSubject);
1051 simulation.applySettings(saved.settings);
1051 simulation.applySettings(saved.settings, {
1052 grantInitialQuests: Object.prototype.hasOwnProperty.call(saved.changed ?? {}, "initialQuests")
1053 });
1052 1054 broadcastStatus();
1053 1055 broadcastSettings(saved);
1054 1056 }
@@ -1048,7 +1048,9 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1048 requireAdmin(session);
1048 requireAdmin(session);
1049 {
1049 {
1050 const saved = editor.saveSettings(message.settings ?? {}, session.authSubject);
1050 const saved = editor.saveSettings(message.settings ?? {}, session.authSubject);
1051 simulation.applySettings(saved.settings);
1051 simulation.applySettings(saved.settings, {
1052 grantInitialQuests: Object.prototype.hasOwnProperty.call(saved.changed ?? {}, "initialQuests")
1053 });
1052 broadcastStatus();
1054 broadcastStatus();
1053 broadcastSettings(saved);
1055 broadcastSettings(saved);
1054 }
1056 }
server/src/persistence/stateDb.js +8 −0
@@ -553,6 +553,14 @@ export class StateDatabase
553 553 return this.db.prepare("SELECT * FROM characters WHERE character_id = ?").get(characterId) ?? null;
554 554 }
555 555
556 /** All character ids (for world-settings fan-out such as initial quests). */
557 listAllCharacterIds ()
558 {
559 return this.db.prepare("SELECT character_id FROM characters").all()
560 .map((row) => row.character_id | 0)
561 .filter((id) => id > 0);
562 }
563
556 564 findSurnameClaim (surnameNormalized)
557 565 {
558 566 return this.db.prepare("SELECT * FROM surname_claims WHERE surname_normalized = ?").get(surnameNormalized) ?? null;
@@ -553,6 +553,14 @@ export class StateDatabase
553 return this.db.prepare("SELECT * FROM characters WHERE character_id = ?").get(characterId) ?? null;
553 return this.db.prepare("SELECT * FROM characters WHERE character_id = ?").get(characterId) ?? null;
554 }
554 }
555
555
556 /** All character ids (for world-settings fan-out such as initial quests). */
557 listAllCharacterIds ()
558 {
559 return this.db.prepare("SELECT character_id FROM characters").all()
560 .map((row) => row.character_id | 0)
561 .filter((id) => id > 0);
562 }
563
556 findSurnameClaim (surnameNormalized)
564 findSurnameClaim (surnameNormalized)
557 {
565 {
558 return this.db.prepare("SELECT * FROM surname_claims WHERE surname_normalized = ?").get(surnameNormalized) ?? null;
566 return this.db.prepare("SELECT * FROM surname_claims WHERE surname_normalized = ?").get(surnameNormalized) ?? null;
server/src/persistence/worldDb.js +2 −0
@@ -1,6 +1,7 @@
1 1 import { DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";
2 2 import { normalizeStarterLoadout } from "../../../shared/items/starterLoadout.js";
3 3 import { normalizeEquipmentStatBonuses } from "../../../shared/definitions/equipmentStatCategories.js";
4 import { normalizeInitialQuests } from "../../../shared/quests/initialQuests.js";
4 5 import {
5 6 OVERWORLD_ID,
6 7 DIMENSION_PURGE_MS,
@@ -267,6 +268,7 @@ export class WorldDatabase
267 268 merged.starterEquipment = loadout.equipment;
268 269 merged.starterInventory = loadout.inventory;
269 270 merged.equipmentStatBonuses = normalizeEquipmentStatBonuses(merged.equipmentStatBonuses);
271 merged.initialQuests = normalizeInitialQuests(merged.initialQuests);
270 272 return merged;
271 273 }
272 274
@@ -1,6 +1,7 @@
1import { DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";
1import { DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";
2import { normalizeStarterLoadout } from "../../../shared/items/starterLoadout.js";
2import { normalizeStarterLoadout } from "../../../shared/items/starterLoadout.js";
3import { normalizeEquipmentStatBonuses } from "../../../shared/definitions/equipmentStatCategories.js";
3import { normalizeEquipmentStatBonuses } from "../../../shared/definitions/equipmentStatCategories.js";
4import { normalizeInitialQuests } from "../../../shared/quests/initialQuests.js";
4import {
5import {
5 OVERWORLD_ID,
6 OVERWORLD_ID,
6 DIMENSION_PURGE_MS,
7 DIMENSION_PURGE_MS,
@@ -267,6 +268,7 @@ export class WorldDatabase
267 merged.starterEquipment = loadout.equipment;
268 merged.starterEquipment = loadout.equipment;
268 merged.starterInventory = loadout.inventory;
269 merged.starterInventory = loadout.inventory;
269 merged.equipmentStatBonuses = normalizeEquipmentStatBonuses(merged.equipmentStatBonuses);
270 merged.equipmentStatBonuses = normalizeEquipmentStatBonuses(merged.equipmentStatBonuses);
271 merged.initialQuests = normalizeInitialQuests(merged.initialQuests);
270 return merged;
272 return merged;
271 }
273 }
272
274
server/src/quests/runtime.js +21 −0
@@ -1,4 +1,5 @@
1 1 import { evaluateConditionSet, EffectKind } from "../../../shared/quests/conditions.js";
2 import { normalizeInitialQuests } from "../../../shared/quests/initialQuests.js";
2 3 import { countItemInSlots, insertStack, takeMatchingFromSlots, insertStackGrowable } from "../../../shared/items/inventory.js";
3 4 import { attachOrigins, godsOrigin } from "../../../shared/items/origin.js";
4 5 import { itemDefinition } from "../../../shared/definitions/items.js";
@@ -555,6 +556,26 @@ export class QuestRuntime
555 556 this.#reevaluateQuests(characterId, playerView, events);
556 557 }
557 558
559 /**
560 * Grant world-settings initial quests when the character has not started or completed them.
561 */
562 ensureInitialQuests (characterId, playerView = null, events = [])
563 {
564 const list = normalizeInitialQuests(this.simulation?.settings?.initialQuests);
565 for (const questId of list)
566 { this.startQuest(characterId, questId, playerView, events); }
567 return events;
568 }
569
570 /** Apply initial quests to every character in state (settings save / apply). */
571 grantInitialQuestsToAllCharacters ()
572 {
573 const events = [];
574 for (const characterId of this.stateDb.listAllCharacterIds())
575 { this.ensureInitialQuests(characterId, null, events); }
576 return events;
577 }
578
558 579 #reevaluateQuests (characterId, playerView, events)
559 580 {
560 581 const states = this.stateDb.listQuestStates(characterId)
@@ -1,4 +1,5 @@
1import { evaluateConditionSet, EffectKind } from "../../../shared/quests/conditions.js";
1import { evaluateConditionSet, EffectKind } from "../../../shared/quests/conditions.js";
2import { normalizeInitialQuests } from "../../../shared/quests/initialQuests.js";
2import { countItemInSlots, insertStack, takeMatchingFromSlots, insertStackGrowable } from "../../../shared/items/inventory.js";
3import { countItemInSlots, insertStack, takeMatchingFromSlots, insertStackGrowable } from "../../../shared/items/inventory.js";
3import { attachOrigins, godsOrigin } from "../../../shared/items/origin.js";
4import { attachOrigins, godsOrigin } from "../../../shared/items/origin.js";
4import { itemDefinition } from "../../../shared/definitions/items.js";
5import { itemDefinition } from "../../../shared/definitions/items.js";
@@ -555,6 +556,26 @@ export class QuestRuntime
555 this.#reevaluateQuests(characterId, playerView, events);
556 this.#reevaluateQuests(characterId, playerView, events);
556 }
557 }
557
558
559 /**
560 * Grant world-settings initial quests when the character has not started or completed them.
561 */
562 ensureInitialQuests (characterId, playerView = null, events = [])
563 {
564 const list = normalizeInitialQuests(this.simulation?.settings?.initialQuests);
565 for (const questId of list)
566 { this.startQuest(characterId, questId, playerView, events); }
567 return events;
568 }
569
570 /** Apply initial quests to every character in state (settings save / apply). */
571 grantInitialQuestsToAllCharacters ()
572 {
573 const events = [];
574 for (const characterId of this.stateDb.listAllCharacterIds())
575 { this.ensureInitialQuests(characterId, null, events); }
576 return events;
577 }
578
558 #reevaluateQuests (characterId, playerView, events)
579 #reevaluateQuests (characterId, playerView, events)
559 {
580 {
560 const states = this.stateDb.listQuestStates(characterId)
581 const states = this.stateDb.listQuestStates(characterId)
server/src/simulation/simulation.js +4 −1
@@ -150,10 +150,12 @@ export class Simulation
150 150 return this.nowFn();
151 151 }
152 152
153 applySettings (settings)
153 applySettings (settings, { grantInitialQuests = false } = {})
154 154 {
155 155 this.settings = { ...this.settings, ...settings };
156 156 this.#configureWorkers();
157 if (grantInitialQuests)
158 { this.quests?.grantInitialQuestsToAllCharacters?.(); }
157 159 }
158 160
159 161 /** Sparse last-sale map for editor base-price readouts. */
@@ -539,6 +541,7 @@ export class Simulation
539 541 this.#recalculateActivation(this.now);
540 542 this.#syncGhosts();
541 543 this.courier?.onCharacterEnteredWorld(character.character_id, tileX, tileY);
544 this.quests?.ensureInitialQuests?.(character.character_id ?? row.character_id);
542 545 return entityId;
543 546 }
544 547
@@ -150,10 +150,12 @@ export class Simulation
150 return this.nowFn();
150 return this.nowFn();
151 }
151 }
152
152
153 applySettings (settings)
153 applySettings (settings, { grantInitialQuests = false } = {})
154 {
154 {
155 this.settings = { ...this.settings, ...settings };
155 this.settings = { ...this.settings, ...settings };
156 this.#configureWorkers();
156 this.#configureWorkers();
157 if (grantInitialQuests)
158 { this.quests?.grantInitialQuestsToAllCharacters?.(); }
157 }
159 }
158
160
159 /** Sparse last-sale map for editor base-price readouts. */
161 /** Sparse last-sale map for editor base-price readouts. */
@@ -539,6 +541,7 @@ export class Simulation
539 this.#recalculateActivation(this.now);
541 this.#recalculateActivation(this.now);
540 this.#syncGhosts();
542 this.#syncGhosts();
541 this.courier?.onCharacterEnteredWorld(character.character_id, tileX, tileY);
543 this.courier?.onCharacterEnteredWorld(character.character_id, tileX, tileY);
544 this.quests?.ensureInitialQuests?.(character.character_id ?? row.character_id);
542 return entityId;
545 return entityId;
543 }
546 }
544
547
shared/definitions/worldSettings.js +7 −0
@@ -194,6 +194,13 @@ export const WORLD_SETTING_CATEGORIES = [
194 194 panel: "starterEquipment",
195 195 fields: []
196 196 },
197 {
198 id: "initialQuests",
199 label: "Quests",
200 /** Custom panel: quests granted to new characters (and existing if not started/completed). */
201 panel: "initialQuests",
202 fields: []
203 },
197 204 {
198 205 id: "communication",
199 206 label: "Communication",
@@ -194,6 +194,13 @@ export const WORLD_SETTING_CATEGORIES = [
194 panel: "starterEquipment",
194 panel: "starterEquipment",
195 fields: []
195 fields: []
196 },
196 },
197 {
198 id: "initialQuests",
199 label: "Quests",
200 /** Custom panel: quests granted to new characters (and existing if not started/completed). */
201 panel: "initialQuests",
202 fields: []
203 },
197 {
204 {
198 id: "communication",
205 id: "communication",
199 label: "Communication",
206 label: "Communication",
shared/protocol/constants.js +2 −0
@@ -74,6 +74,8 @@ export const DEFAULT_WORLD_SETTINGS = Object.freeze({
74 74 starterEquipment: DEFAULT_STARTER_EQUIPMENT,
75 75 /** New characters only: inventory stacks `{ itemId, quantity }[]`. */
76 76 starterInventory: DEFAULT_STARTER_INVENTORY,
77 /** Quest ids granted on create / login / settings apply if not already started or completed. */
78 initialQuests: Object.freeze([]),
77 79 /** Piece×tier worn stat bonuses (editor Equipment Stats tab). */
78 80 equipmentStatBonuses: defaultEquipmentStatBonuses()
79 81 });
@@ -74,6 +74,8 @@ export const DEFAULT_WORLD_SETTINGS = Object.freeze({
74 starterEquipment: DEFAULT_STARTER_EQUIPMENT,
74 starterEquipment: DEFAULT_STARTER_EQUIPMENT,
75 /** New characters only: inventory stacks `{ itemId, quantity }[]`. */
75 /** New characters only: inventory stacks `{ itemId, quantity }[]`. */
76 starterInventory: DEFAULT_STARTER_INVENTORY,
76 starterInventory: DEFAULT_STARTER_INVENTORY,
77 /** Quest ids granted on create / login / settings apply if not already started or completed. */
78 initialQuests: Object.freeze([]),
77 /** Piece×tier worn stat bonuses (editor Equipment Stats tab). */
79 /** Piece×tier worn stat bonuses (editor Equipment Stats tab). */
78 equipmentStatBonuses: defaultEquipmentStatBonuses()
80 equipmentStatBonuses: defaultEquipmentStatBonuses()
79});
81});
shared/quests/initialQuests.js added +45 −0
@@ -0,0 +1,45 @@
1 /** Normalize world-settings list of quests granted to new (and existing) characters. */
2
3 export function normalizeInitialQuests (raw)
4 {
5 if (!Array.isArray(raw))
6 { return []; }
7 const out = [];
8 const seen = new Set();
9 for (const entry of raw)
10 {
11 const id = String(entry?.questId ?? entry ?? "").trim().slice(0, 80);
12 if (!id || seen.has(id))
13 { continue; }
14 seen.add(id);
15 out.push(id);
16 }
17 return out;
18 }
19
20 export function initialQuestsEqual (a, b)
21 {
22 const left = normalizeInitialQuests(a);
23 const right = normalizeInitialQuests(b);
24 if (left.length !== right.length)
25 { return false; }
26 return left.every((id, index) => id === right[index]);
27 }
28
29 export function diffInitialQuests (prev, next)
30 {
31 const before = new Set(normalizeInitialQuests(prev));
32 const after = normalizeInitialQuests(next);
33 const bullets = [];
34 for (const id of after)
35 {
36 if (!before.has(id))
37 { bullets.push(`Initial quest +${id}`); }
38 }
39 for (const id of before)
40 {
41 if (!after.includes(id))
42 { bullets.push(`Initial quest −${id}`); }
43 }
44 return bullets;
45 }
@@ -0,0 +1,45 @@
1/** Normalize world-settings list of quests granted to new (and existing) characters. */
2
3export function normalizeInitialQuests (raw)
4{
5 if (!Array.isArray(raw))
6 { return []; }
7 const out = [];
8 const seen = new Set();
9 for (const entry of raw)
10 {
11 const id = String(entry?.questId ?? entry ?? "").trim().slice(0, 80);
12 if (!id || seen.has(id))
13 { continue; }
14 seen.add(id);
15 out.push(id);
16 }
17 return out;
18}
19
20export function initialQuestsEqual (a, b)
21{
22 const left = normalizeInitialQuests(a);
23 const right = normalizeInitialQuests(b);
24 if (left.length !== right.length)
25 { return false; }
26 return left.every((id, index) => id === right[index]);
27}
28
29export function diffInitialQuests (prev, next)
30{
31 const before = new Set(normalizeInitialQuests(prev));
32 const after = normalizeInitialQuests(next);
33 const bullets = [];
34 for (const id of after)
35 {
36 if (!before.has(id))
37 { bullets.push(`Initial quest +${id}`); }
38 }
39 for (const id of before)
40 {
41 if (!after.includes(id))
42 { bullets.push(`Initial quest −${id}`); }
43 }
44 return bullets;
45}