Expand CE listings for flowers, tipped arrows, and unstable draughts.
Flower colours and arrow elements get specific buy rows; unstable draughts share one surprise listing; dyed clothing stays unkeyed so colour is a buyer surprise.
@@ -29,6 +29,7 @@ import {
29
29
buildMarketCatalogEntries,
30
30
listingKeyFromOrder,
31
31
listingKeyFromStack,
32
marketBuyListingKeyError,
32
33
marketBuyRequiresListingKey,
33
34
marketOrderDisplayName,
34
35
marketOrdersCompatible,
@@ -313,13 +314,10 @@ export class MarketService
313
314
{ throw userError("Coins cannot be ordered on the marketplace."); }
314
315
const normalizedListingKey = normalizeBuyListingKey(itemId, listingKey);
315
316
if (marketBuyRequiresListingKey(itemId) && !normalizedListingKey)
316
{
317
throw userError(
318
(itemId | 0) === ItemId.recipePaper
319
? "Choose which recipe to buy."
320
: "Choose which potion to buy."
321
);
322
}
317
{ throw userError(marketBuyListingKeyError(itemId)); }
318
const rawListingKey = String(listingKey ?? "").trim();
319
if (rawListingKey && !normalizedListingKey)
320
{ throw userError("That listing is not available."); }
323
321
const escrow = maxPrice * qty;
324
322
const fee = marketOrderListingFee(maxPrice, qty);
325
323
const bag = this.#loadBag(characterId);
@@ -29,6 +29,7 @@ import {29
buildMarketCatalogEntries,29
buildMarketCatalogEntries,30
listingKeyFromOrder,30
listingKeyFromOrder,31
listingKeyFromStack,31
listingKeyFromStack,32
marketBuyListingKeyError,32
marketBuyRequiresListingKey,33
marketBuyRequiresListingKey,33
marketOrderDisplayName,34
marketOrderDisplayName,34
marketOrdersCompatible,35
marketOrdersCompatible,@@ -313,13 +314,10 @@ export class MarketService313
{ throw userError("Coins cannot be ordered on the marketplace."); }314
{ throw userError("Coins cannot be ordered on the marketplace."); }314
const normalizedListingKey = normalizeBuyListingKey(itemId, listingKey);315
const normalizedListingKey = normalizeBuyListingKey(itemId, listingKey);315
if (marketBuyRequiresListingKey(itemId) && !normalizedListingKey)316
if (marketBuyRequiresListingKey(itemId) && !normalizedListingKey)316
{317
{ throw userError(marketBuyListingKeyError(itemId)); }317
throw userError(318
const rawListingKey = String(listingKey ?? "").trim();318
(itemId | 0) === ItemId.recipePaper319
if (rawListingKey && !normalizedListingKey)319
? "Choose which recipe to buy."320
{ throw userError("That listing is not available."); }320
: "Choose which potion to buy."321
);322
}323
const escrow = maxPrice * qty;321
const escrow = maxPrice * qty;324
const fee = marketOrderListingFee(maxPrice, qty);322
const fee = marketOrderListingFee(maxPrice, qty);325
const bag = this.#loadBag(characterId);323
const bag = this.#loadBag(characterId);@@ -15,9 +15,17 @@ import {
15
15
marketOrdersCompatible,
16
16
recipeListingKey,
17
17
recipePaperDisplayName,
18
potionListingKey
18
potionListingKey,
19
flowerListingKey,
20
arrowListingKey,
21
UNSTABLE_POTION_LISTING_KEY,
22
listingKeyFromStack
19
23
} from "../../shared/market/listingKey.js";
20
24
import { alchemyPotionDefinition } from "../../shared/definitions/alchemy.js";
25
import { MagicElement } from "../../shared/definitions/attackTypes.js";
26
import { RangedItemId } from "../../shared/definitions/rangedItems.js";
27
import { ClothItemId } from "../../shared/definitions/clothItems.js";
28
import { FlowerColorId, flowerItemInstance } from "../../shared/definitions/dyes.js";
21
29
import { emptyEquipment, emptySlots, addCoinsToSlots, countCoinsInSlots } from "../../shared/items/inventory.js";
22
30
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
23
31
import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
@@ -276,6 +284,8 @@ test("market catalog lists each drinkable potion brew separately", () =>
276
284
assert.ok(potions.length > 1);
277
285
assert.ok(potions.some((entry) => entry.listingKey === potionListingKey("lesserHealthTonic")));
278
286
assert.ok(potions.some((entry) => entry.displayName === "Lesser health tonic"));
287
assert.ok(potions.some((entry) => entry.listingKey === UNSTABLE_POTION_LISTING_KEY));
288
assert.equal(potions.filter((entry) => entry.listingKey === UNSTABLE_POTION_LISTING_KEY).length, 1);
279
289
assert.equal(potions.some((entry) => !entry.listingKey), false);
280
290
assert.equal(potions.some((entry) => entry.displayName === "Potion"), false);
281
291
assert.equal(
@@ -285,6 +295,135 @@ test("market catalog lists each drinkable potion brew separately", () =>
285
295
);
286
296
});
287
297
298
test("market catalog expands flowers and tipped arrows", () =>
299
{
300
const catalog = buildMarketCatalogEntries({
301
lastSaleFor: () => null,
302
undiscountedMarketCoins: () => 4,
303
now: Date.now(),
304
lerpDurationMs: 0,
305
settings: {}
306
});
307
const flowers = catalog.filter((entry) => entry.itemId === ItemId.flower);
308
assert.ok(flowers.length >= 9);
309
assert.ok(flowers.every((entry) => entry.listingKey));
310
assert.ok(flowers.some((entry) => entry.listingKey === flowerListingKey(FlowerColorId.red)));
311
assert.ok(flowers.some((entry) => entry.displayName === "Red flower"));
312
313
const bronze = catalog.filter((entry) => entry.itemId === RangedItemId.bronzeArrow);
314
assert.ok(bronze.some((entry) => entry.listingKey == null && entry.displayName));
315
assert.ok(bronze.some((entry) => entry.listingKey === arrowListingKey(MagicElement.fire)));
316
assert.ok(bronze.some((entry) => /fire/i.test(entry.displayName)));
317
});
318
319
test("unstable and tipped-arrow stacks carry market listing keys", () =>
320
{
321
const unstable = {
322
itemId: ItemId.potion,
323
quantity: 1,
324
instance: potionItemInstance({
325
potionKey: "unstable:glow",
326
unstable: true,
327
displayName: "Unstable draught",
328
color: { r: 0.95, g: 0.9, b: 0.45 },
329
fillLevel: 3,
330
effectKey: "glow",
331
effect: { type: "glow", lightRadiusTiles: 2, durationMs: 10_000 }
332
})
333
};
334
assert.equal(listingKeyFromStack(unstable), UNSTABLE_POTION_LISTING_KEY);
335
assert.equal(
336
listingKeyFromStack({
337
itemId: RangedItemId.bronzeArrow,
338
quantity: 5,
339
instance: { kind: "tipped-arrow", element: MagicElement.fire }
340
}),
341
arrowListingKey(MagicElement.fire)
342
);
343
assert.equal(
344
listingKeyFromStack({
345
itemId: ItemId.flower,
346
quantity: 1,
347
instance: flowerItemInstance(FlowerColorId.blue)
348
}),
349
flowerListingKey(FlowerColorId.blue)
350
);
351
assert.equal(
352
listingKeyFromStack({
353
itemId: ClothItemId.cottonShirt,
354
quantity: 1,
355
instance: { kind: "clothing", dyeColor: { r: 0.2, g: 0.4, b: 0.8 } }
356
}),
357
null,
358
"dyed clothing stays unkeyed so buyers get a colour surprise"
359
);
360
});
361
362
test("unstable buy orders match any unstable sell effect", () =>
363
{
364
const buy = { itemId: ItemId.potion, listingKey: UNSTABLE_POTION_LISTING_KEY };
365
const glowSell = {
366
itemId: ItemId.potion,
367
listingKey: UNSTABLE_POTION_LISTING_KEY,
368
escrowStack: {
369
itemId: ItemId.potion,
370
quantity: 1,
371
instance: potionItemInstance({
372
potionKey: "unstable:glow",
373
unstable: true,
374
displayName: "Unstable draught",
375
fillLevel: 3,
376
effectKey: "glow"
377
})
378
}
379
};
380
const shrinkSell = {
381
itemId: ItemId.potion,
382
listingKey: UNSTABLE_POTION_LISTING_KEY,
383
escrowStack: {
384
itemId: ItemId.potion,
385
quantity: 1,
386
instance: potionItemInstance({
387
potionKey: "unstable:shrink",
388
unstable: true,
389
displayName: "Unstable draught",
390
fillLevel: 2,
391
effectKey: "shrink"
392
})
393
}
394
};
395
assert.equal(marketOrdersCompatible(buy, glowSell), true);
396
assert.equal(marketOrdersCompatible(buy, shrinkSell), true);
397
assert.equal(
398
marketOrdersCompatible(buy, {
399
itemId: ItemId.potion,
400
listingKey: potionListingKey("lesserHealthTonic")
401
}),
402
false
403
);
404
});
405
406
test("dyed clothing sell matches an undyed clothing buy (colour surprise)", () =>
407
{
408
const buy = { itemId: ClothItemId.cottonShirt, listingKey: null };
409
const dyedSell = {
410
itemId: ClothItemId.cottonShirt,
411
listingKey: null,
412
escrowStack: {
413
itemId: ClothItemId.cottonShirt,
414
quantity: 1,
415
instance: { kind: "clothing", dyeColor: { r: 0.9, g: 0.1, b: 0.2 } }
416
}
417
};
418
const plainSell = {
419
itemId: ClothItemId.cottonShirt,
420
listingKey: null,
421
escrowStack: { itemId: ClothItemId.cottonShirt, quantity: 1, instance: null }
422
};
423
assert.equal(marketOrdersCompatible(buy, dyedSell), true);
424
assert.equal(marketOrdersCompatible(buy, plainSell), true);
425
});
426
288
427
test("recipe paper sell listings carry listing keys", () =>
289
428
{
290
429
const stack = recipePaperStack("lesserHealthTonic");
@@ -15,9 +15,17 @@ import {15
marketOrdersCompatible,15
marketOrdersCompatible,16
recipeListingKey,16
recipeListingKey,17
recipePaperDisplayName,17
recipePaperDisplayName,18
potionListingKey18
potionListingKey,19
flowerListingKey,20
arrowListingKey,21
UNSTABLE_POTION_LISTING_KEY,22
listingKeyFromStack19
} from "../../shared/market/listingKey.js";23
} from "../../shared/market/listingKey.js";20
import { alchemyPotionDefinition } from "../../shared/definitions/alchemy.js";24
import { alchemyPotionDefinition } from "../../shared/definitions/alchemy.js";25
import { MagicElement } from "../../shared/definitions/attackTypes.js";26
import { RangedItemId } from "../../shared/definitions/rangedItems.js";27
import { ClothItemId } from "../../shared/definitions/clothItems.js";28
import { FlowerColorId, flowerItemInstance } from "../../shared/definitions/dyes.js";21
import { emptyEquipment, emptySlots, addCoinsToSlots, countCoinsInSlots } from "../../shared/items/inventory.js";29
import { emptyEquipment, emptySlots, addCoinsToSlots, countCoinsInSlots } from "../../shared/items/inventory.js";22
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";30
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";23
import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";31
import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";@@ -276,6 +284,8 @@ test("market catalog lists each drinkable potion brew separately", () =>276
assert.ok(potions.length > 1);284
assert.ok(potions.length > 1);277
assert.ok(potions.some((entry) => entry.listingKey === potionListingKey("lesserHealthTonic")));285
assert.ok(potions.some((entry) => entry.listingKey === potionListingKey("lesserHealthTonic")));278
assert.ok(potions.some((entry) => entry.displayName === "Lesser health tonic"));286
assert.ok(potions.some((entry) => entry.displayName === "Lesser health tonic"));287
assert.ok(potions.some((entry) => entry.listingKey === UNSTABLE_POTION_LISTING_KEY));288
assert.equal(potions.filter((entry) => entry.listingKey === UNSTABLE_POTION_LISTING_KEY).length, 1);279
assert.equal(potions.some((entry) => !entry.listingKey), false);289
assert.equal(potions.some((entry) => !entry.listingKey), false);280
assert.equal(potions.some((entry) => entry.displayName === "Potion"), false);290
assert.equal(potions.some((entry) => entry.displayName === "Potion"), false);281
assert.equal(291
assert.equal(@@ -285,6 +295,135 @@ test("market catalog lists each drinkable potion brew separately", () =>285
);295
);286
});296
});287
297
298
test("market catalog expands flowers and tipped arrows", () =>299
{300
const catalog = buildMarketCatalogEntries({301
lastSaleFor: () => null,302
undiscountedMarketCoins: () => 4,303
now: Date.now(),304
lerpDurationMs: 0,305
settings: {}306
});307
const flowers = catalog.filter((entry) => entry.itemId === ItemId.flower);308
assert.ok(flowers.length >= 9);309
assert.ok(flowers.every((entry) => entry.listingKey));310
assert.ok(flowers.some((entry) => entry.listingKey === flowerListingKey(FlowerColorId.red)));311
assert.ok(flowers.some((entry) => entry.displayName === "Red flower"));312
313
const bronze = catalog.filter((entry) => entry.itemId === RangedItemId.bronzeArrow);314
assert.ok(bronze.some((entry) => entry.listingKey == null && entry.displayName));315
assert.ok(bronze.some((entry) => entry.listingKey === arrowListingKey(MagicElement.fire)));316
assert.ok(bronze.some((entry) => /fire/i.test(entry.displayName)));317
});318
319
test("unstable and tipped-arrow stacks carry market listing keys", () =>320
{321
const unstable = {322
itemId: ItemId.potion,323
quantity: 1,324
instance: potionItemInstance({325
potionKey: "unstable:glow",326
unstable: true,327
displayName: "Unstable draught",328
color: { r: 0.95, g: 0.9, b: 0.45 },329
fillLevel: 3,330
effectKey: "glow",331
effect: { type: "glow", lightRadiusTiles: 2, durationMs: 10_000 }332
})333
};334
assert.equal(listingKeyFromStack(unstable), UNSTABLE_POTION_LISTING_KEY);335
assert.equal(336
listingKeyFromStack({337
itemId: RangedItemId.bronzeArrow,338
quantity: 5,339
instance: { kind: "tipped-arrow", element: MagicElement.fire }340
}),341
arrowListingKey(MagicElement.fire)342
);343
assert.equal(344
listingKeyFromStack({345
itemId: ItemId.flower,346
quantity: 1,347
instance: flowerItemInstance(FlowerColorId.blue)348
}),349
flowerListingKey(FlowerColorId.blue)350
);351
assert.equal(352
listingKeyFromStack({353
itemId: ClothItemId.cottonShirt,354
quantity: 1,355
instance: { kind: "clothing", dyeColor: { r: 0.2, g: 0.4, b: 0.8 } }356
}),357
null,358
"dyed clothing stays unkeyed so buyers get a colour surprise"359
);360
});361
362
test("unstable buy orders match any unstable sell effect", () =>363
{364
const buy = { itemId: ItemId.potion, listingKey: UNSTABLE_POTION_LISTING_KEY };365
const glowSell = {366
itemId: ItemId.potion,367
listingKey: UNSTABLE_POTION_LISTING_KEY,368
escrowStack: {369
itemId: ItemId.potion,370
quantity: 1,371
instance: potionItemInstance({372
potionKey: "unstable:glow",373
unstable: true,374
displayName: "Unstable draught",375
fillLevel: 3,376
effectKey: "glow"377
})378
}379
};380
const shrinkSell = {381
itemId: ItemId.potion,382
listingKey: UNSTABLE_POTION_LISTING_KEY,383
escrowStack: {384
itemId: ItemId.potion,385
quantity: 1,386
instance: potionItemInstance({387
potionKey: "unstable:shrink",388
unstable: true,389
displayName: "Unstable draught",390
fillLevel: 2,391
effectKey: "shrink"392
})393
}394
};395
assert.equal(marketOrdersCompatible(buy, glowSell), true);396
assert.equal(marketOrdersCompatible(buy, shrinkSell), true);397
assert.equal(398
marketOrdersCompatible(buy, {399
itemId: ItemId.potion,400
listingKey: potionListingKey("lesserHealthTonic")401
}),402
false403
);404
});405
406
test("dyed clothing sell matches an undyed clothing buy (colour surprise)", () =>407
{408
const buy = { itemId: ClothItemId.cottonShirt, listingKey: null };409
const dyedSell = {410
itemId: ClothItemId.cottonShirt,411
listingKey: null,412
escrowStack: {413
itemId: ClothItemId.cottonShirt,414
quantity: 1,415
instance: { kind: "clothing", dyeColor: { r: 0.9, g: 0.1, b: 0.2 } }416
}417
};418
const plainSell = {419
itemId: ClothItemId.cottonShirt,420
listingKey: null,421
escrowStack: { itemId: ClothItemId.cottonShirt, quantity: 1, instance: null }422
};423
assert.equal(marketOrdersCompatible(buy, dyedSell), true);424
assert.equal(marketOrdersCompatible(buy, plainSell), true);425
});426
288
test("recipe paper sell listings carry listing keys", () =>427
test("recipe paper sell listings carry listing keys", () =>289
{428
{290
const stack = recipePaperStack("lesserHealthTonic");429
const stack = recipePaperStack("lesserHealthTonic");