| 1 | import { itemDefinition } from "../definitions/items.js"; |
| 2 | import { isLetterStack } from "./letters.js"; |
| 3 | |
| 4 | /** Whether this stack may be listed as a marketplace sell order. */ |
| 5 | export function canSellOnMarketplace (stack, characterId = null) |
| 6 | { |
| 7 | void characterId; |
| 8 | const def = itemDefinition(stack?.itemId); |
| 9 | if (!def || !stack) |
| 10 | { return false; } |
| 11 | if (def.marketplaceSellable === false) |
| 12 | { return false; } |
| 13 | // Belt-and-suspenders: letters never list, even if a def flag is missing. |
| 14 | if (isLetterStack(stack)) |
| 15 | { return false; } |
| 16 | return true; |
| 17 | } |
| 18 | |
| 19 | /** @throws {Error & { userFacing?: boolean }} */ |
| 20 | export function assertMarketplaceSellable (stack, characterId = null) |
| 21 | { |
| 22 | if (canSellOnMarketplace(stack, characterId)) |
| 23 | { return; } |
| 24 | const def = itemDefinition(stack?.itemId); |
| 25 | const error = new Error( |
| 26 | def?.marketplaceSellBlockedReason |
| 27 | ?? (isLetterStack(stack) |
| 28 | ? "Letters cannot be sold on the marketplace." |
| 29 | : "That item cannot be sold on the marketplace.") |
| 30 | ); |
| 31 | error.userFacing = true; |
| 32 | throw error; |
| 33 | } |