| 1 | import { LETTER_MAX_BODY_CHARS, itemDefinition, itemDisplayName } from "../definitions/items.js"; |
| 2 | import { formatGiftItemBullet, QUESTWARD_GIFT_AUTHOR, QUESTWARD_GIFT_ORG } from "./giftLetters.js"; |
| 3 | |
| 4 | export { 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 | */ |
| 10 | export 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 | } |