BlueGit

timfa questward

Files

questward / shared / quests / dialogueRewards.js

dialogueRewards.js

dialogueRewards.js 983 B Download Raw
1/**
2 * Format dialogue step item-reward notices (bag vs bank).
3 * @param {{ displayName: string, quantity: number }[]} items
4 * @param {"bag" | "bank"} destination
5 */
6export 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}