BlueGit

timfa questward

Files

questward / shared / courier / systemLetters.js

systemLetters.js

systemLetters.js 2.1 KiB Download Raw
1/** Shared helpers for system-authored letters (CE, bank, bounty, …). */
2
3import { LETTER_MAX_BODY_CHARS } from "../definitions/items.js";
4
5export const CENTRAL_EXCHANGE_ORG = "Central Exchange";
6export const BANK_LETTER_AUTHOR = "The Bank";
7export const BOUNTY_OFFICE_AUTHOR = "Bounty Office";
8export const CHURCH_LETTER_AUTHOR = "The Church";
9export {
10 QUESTWARD_GIFT_AUTHOR,
11 QUESTWARD_GIFT_ORG,
12 formatGiftLetterBody,
13 formatGiftItemBullet
14} from "./giftLetters.js";
15export { giftItemOrigin } from "./giftOrigin.js";
16
17export const CHURCH_OFFLINE_RESURRECTION_BODY = [
18 "The priesthood found your lifeless body on the ground and have resurrected you at the church altar while you were offline."
19].join("\n");
20
21export const COMBAT_LOGOUT_COWARDICE_BODY = [
22 "Your cowardice in honourable combat has not gone unnoticed. A temporary skull mark of shame has been placed on your character.",
23 "In the future, please do not log out while in combat with another player."
24].join("\n");
25
26export function formatChurchOfflineResurrectionBody ()
27{
28 return CHURCH_OFFLINE_RESURRECTION_BODY.slice(0, LETTER_MAX_BODY_CHARS);
29}
30
31export function formatCombatLogoutCowardiceBody ()
32{
33 return COMBAT_LOGOUT_COWARDICE_BODY.slice(0, LETTER_MAX_BODY_CHARS);
34}
35
36export function isCentralExchangeLetter (instance)
37{
38 if (instance?.kind !== "letter")
39 { return false; }
40 if (instance.centralExchange === true)
41 { return true; }
42 return instance.authorOrganization === CENTRAL_EXCHANGE_ORG;
43}
44
45export function isBankRestNoticeLetter (instance)
46{
47 return instance?.kind === "letter" && instance.bankRestNotice === true;
48}
49
50/**
51 * Format the UI "Signed:" block. Optional organization is a second line under the name.
52 * @param {{ authorDisplayName?: string, authorOrganization?: string|null }} instance
53 * @param {string} [fallbackName]
54 */
55export function formatLetterSignature (instance, fallbackName = "Unknown")
56{
57 const name = String(instance?.authorDisplayName ?? "").trim() || fallbackName;
58 const org = String(instance?.authorOrganization ?? "").trim();
59 return org ? `Signed:\n${name}\n${org}` : `Signed:\n${name}`;
60}