| 1 | /** |
| 2 | * Format dialogue step item-reward notices (bag vs bank). |
| 3 | * @param {{ displayName: string, quantity: number }[]} items |
| 4 | * @param {"bag" | "bank"} destination |
| 5 | */ |
| 6 | export function formatDialogueRewardMessage (items, destination) |
| 7 | { |
| 8 | const list = (Array.isArray(items) ? items : []) |
| 9 | .filter((entry) => entry && entry.displayName); |
| 10 | if (!list.length) |
| 11 | { return null; } |
| 12 | const labels = list.map((entry) => |
| 13 | { |
| 14 | const qty = Math.max(1, Number(entry.quantity) || 1); |
| 15 | const name = String(entry.displayName); |
| 16 | return qty > 1 ? `${qty} ${name}` : name; |
| 17 | }); |
| 18 | const subject = labels.length === 1 |
| 19 | ? labels[0] |
| 20 | : labels.length === 2 |
| 21 | ? `${labels[0]} and ${labels[1]}` |
| 22 | : `${labels.slice(0, -1).join(", ")} and ${labels[labels.length - 1]}`; |
| 23 | const plural = labels.length > 1 || (list[0].quantity | 0) > 1; |
| 24 | const verb = plural ? "have" : "has"; |
| 25 | const where = destination === "bank" |
| 26 | ? "sent to your bank" |
| 27 | : "added to your bag"; |
| 28 | return `${subject} ${verb} been ${where}.`; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Format dialogue step item-take notices (removed from bag). |
| 33 | * @param {{ displayName: string, quantity: number }[]} items |
| 34 | */ |
| 35 | export function formatDialogueTakeMessage (items) |
| 36 | { |
| 37 | const list = (Array.isArray(items) ? items : []) |
| 38 | .filter((entry) => entry && entry.displayName && (Number(entry.quantity) || 0) > 0); |
| 39 | if (!list.length) |
| 40 | { return null; } |
| 41 | const labels = list.map((entry) => |
| 42 | { |
| 43 | const qty = Math.max(1, Number(entry.quantity) || 1); |
| 44 | const name = String(entry.displayName); |
| 45 | return qty > 1 ? `${qty} ${name}` : name; |
| 46 | }); |
| 47 | const subject = labels.length === 1 |
| 48 | ? labels[0] |
| 49 | : labels.length === 2 |
| 50 | ? `${labels[0]} and ${labels[1]}` |
| 51 | : `${labels.slice(0, -1).join(", ")} and ${labels[labels.length - 1]}`; |
| 52 | const plural = labels.length > 1 || (list[0].quantity | 0) > 1; |
| 53 | const verb = plural ? "have" : "has"; |
| 54 | return `${subject} ${verb} been removed from your bag.`; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Format dialogue step quest-reward notices (player-facing). |
| 59 | * @param {string[]} questTitles |
| 60 | */ |
| 61 | export function formatDialogueQuestRewardMessage (questTitles) |
| 62 | { |
| 63 | const list = (Array.isArray(questTitles) ? questTitles : []) |
| 64 | .map((title) => String(title ?? "").trim()) |
| 65 | .filter(Boolean); |
| 66 | if (!list.length) |
| 67 | { return null; } |
| 68 | const subject = list.length === 1 |
| 69 | ? `The ${list[0]} quest` |
| 70 | : list.length === 2 |
| 71 | ? `The ${list[0]} and ${list[1]} quests` |
| 72 | : `The ${list.slice(0, -1).join(", ")}, and ${list[list.length - 1]} quests`; |
| 73 | const verb = list.length > 1 ? "have" : "has"; |
| 74 | return `${subject} ${verb} been added to your journal.`; |
| 75 | } |