/** * Format dialogue step item-reward notices (bag vs bank). * @param {{ displayName: string, quantity: number }[]} items * @param {"bag" | "bank"} destination */ export function formatDialogueRewardMessage (items, destination) { const list = (Array.isArray(items) ? items : []) .filter((entry) => entry && entry.displayName); if (!list.length) { return null; } const labels = list.map((entry) => { const qty = Math.max(1, Number(entry.quantity) || 1); const name = String(entry.displayName); return qty > 1 ? `${qty} ${name}` : name; }); const subject = labels.length === 1 ? labels[0] : labels.length === 2 ? `${labels[0]} and ${labels[1]}` : `${labels.slice(0, -1).join(", ")} and ${labels[labels.length - 1]}`; const plural = labels.length > 1 || (list[0].quantity | 0) > 1; const verb = plural ? "have" : "has"; const where = destination === "bank" ? "sent to your bank" : "added to your bag"; return `${subject} ${verb} been ${where}.`; } /** * Format dialogue step item-take notices (removed from bag). * @param {{ displayName: string, quantity: number }[]} items */ export function formatDialogueTakeMessage (items) { const list = (Array.isArray(items) ? items : []) .filter((entry) => entry && entry.displayName && (Number(entry.quantity) || 0) > 0); if (!list.length) { return null; } const labels = list.map((entry) => { const qty = Math.max(1, Number(entry.quantity) || 1); const name = String(entry.displayName); return qty > 1 ? `${qty} ${name}` : name; }); const subject = labels.length === 1 ? labels[0] : labels.length === 2 ? `${labels[0]} and ${labels[1]}` : `${labels.slice(0, -1).join(", ")} and ${labels[labels.length - 1]}`; const plural = labels.length > 1 || (list[0].quantity | 0) > 1; const verb = plural ? "have" : "has"; return `${subject} ${verb} been removed from your bag.`; } /** * Format dialogue step quest-reward notices (player-facing). * @param {string[]} questTitles */ export function formatDialogueQuestRewardMessage (questTitles) { const list = (Array.isArray(questTitles) ? questTitles : []) .map((title) => String(title ?? "").trim()) .filter(Boolean); if (!list.length) { return null; } const subject = list.length === 1 ? `The ${list[0]} quest` : list.length === 2 ? `The ${list[0]} and ${list[1]} quests` : `The ${list.slice(0, -1).join(", ")}, and ${list[list.length - 1]} quests`; const verb = list.length > 1 ? "have" : "has"; return `${subject} ${verb} been added to your journal.`; }