BlueGit

timfa questward

Files

questward / shared / courier / questRewardLetters.js

questRewardLetters.js

change rewards letter
timfa Tim Falken · pushed by timfa · 2 months ago
7654d7bf History
questRewardLetters.js 1.3 KiB Download Raw
1import { LETTER_MAX_BODY_CHARS, itemDefinition, itemDisplayName } from "../definitions/items.js";
2import { formatGiftItemBullet, QUESTWARD_GIFT_AUTHOR, QUESTWARD_GIFT_ORG } from "./giftLetters.js";
3
4export { QUESTWARD_GIFT_AUTHOR, QUESTWARD_GIFT_ORG };
5
6/**
7 * Bank letter when quest completion rewards land in the vault.
8 * Signature is applied separately via author fields (John Questward / CEO).
9 */
10export function formatQuestBankRewardLetterBody ({
11 characterDisplayName,
12 questTitle,
13 items = []
14})
15{
16 const name = String(characterDisplayName ?? "").trim() || "Adventurer";
17 const title = String(questTitle ?? "").trim() || "a quest";
18 const lines = (items ?? []).map((row) =>
19 {
20 const def = row.itemId != null ? itemDefinition(row.itemId) : null;
21 const displayName = row.displayName
22 ?? (def ? itemDisplayName({ itemId: row.itemId, quantity: row.quantity }, def) : null)
23 ?? def?.displayName
24 ?? `Item ${row.itemId ?? "?"}`;
25 return formatGiftItemBullet({ displayName, quantity: row.quantity });
26 });
27 const itemBlock = lines.length
28 ? lines.join("\n")
29 : "• (no items)";
30 return [
31 `Dear ${name},`,
32 "",
33 `Congratulations on your completion of the quest "${title}".`,
34 "",
35 "The following rewards have been added to your bank:",
36 itemBlock
37 ].join("\n").slice(0, LETTER_MAX_BODY_CHARS);
38}