BlueGit

timfa questward

Files

questward / shared / items / marketplace.js

marketplace.js

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