/** * 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}.`; }