Scale worn tinderbox prices by remaining uses and show charge frames.
Merchant buyback and shop resale track charge fraction; worn charge tools stay off the CE. Tinderboxes now have six uses matching a 3×2 sprite sheet, with legacy high-charge boxes clamped to six.
@@ -1,5 +1,6 @@
1
1
import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitions/items.js";
2
2
import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
3
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
3
4
import
4
5
{
5
6
applyMagentaTintToImageData,
@@ -122,6 +123,29 @@ export async function dualTintedItemIconDataUrl (assetPath, dualTint)
122
123
return url;
123
124
}
124
125
126
/** Crop one frame from a multi-frame item sheet for UI icons. */
127
export async function framedItemIconDataUrl (assetPath, frameIndex, framesPerRow = 1, frameCount = 1)
128
{
129
const index = Math.max(0, Math.min((frameCount | 0 || 1) - 1, frameIndex | 0));
130
const perRow = Math.max(1, framesPerRow | 0 || 1);
131
const key = `frame|${assetPath}|${index}|${perRow}|${frameCount}`;
132
if (urlCache.has(key))
133
{ return urlCache.get(key); }
134
const img = await loadImage(assetPath);
135
const canvas = document.createElement("canvas");
136
canvas.width = SPRITE_SIZE_PX;
137
canvas.height = SPRITE_SIZE_PX;
138
const ctx = canvas.getContext("2d");
139
ctx.imageSmoothingEnabled = false;
140
ctx.clearRect(0, 0, canvas.width, canvas.height);
141
const sx = (index % perRow) * SPRITE_SIZE_PX;
142
const sy = Math.floor(index / perRow) * SPRITE_SIZE_PX;
143
ctx.drawImage(img, sx, sy, SPRITE_SIZE_PX, SPRITE_SIZE_PX, 0, 0, SPRITE_SIZE_PX, SPRITE_SIZE_PX);
144
const url = canvas.toDataURL("image/png");
145
urlCache.set(key, url);
146
return url;
147
}
148
125
149
export function isPotionStack (stack)
126
150
{
127
151
return (stack?.itemId === ItemId.potion && stack.instance?.kind === "potion")
@@ -133,17 +157,31 @@ export function applyItemIcon (img, stack, fallbackPath)
133
157
{
134
158
if (!img)
135
159
{ return; }
136
img.src = fallbackPath;
160
const path = fallbackPath || itemAssetPathForStack(stack);
161
img.src = path;
137
162
const def = itemDefinition(stack?.itemId);
163
const frames = def?.frames | 0 || 1;
164
if (frames > 1 && itemMaxCharges(def) != null)
165
{
166
const frameIndex = chargeSpriteFrameIndex(stack);
167
framedItemIconDataUrl(path, frameIndex, def.framesPerRow ?? 1, frames).then((url) =>
168
{
169
img.src = url;
170
}).catch(() =>
171
{
172
img.src = path;
173
});
174
return;
175
}
138
176
const dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);
139
177
if (dualTint)
140
178
{
141
dualTintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), dualTint).then((url) =>
179
dualTintedItemIconDataUrl(path, dualTint).then((url) =>
142
180
{
143
181
img.src = url;
144
182
}).catch(() =>
145
183
{
146
img.src = fallbackPath;
184
img.src = path;
147
185
});
148
186
return;
149
187
}
@@ -152,12 +190,12 @@ export function applyItemIcon (img, stack, fallbackPath)
152
190
{ return; }
153
191
const work = isPotionStack(stack)
154
192
? potionIconDataUrl(stack.instance)
155
: tintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), tint);
193
: tintedItemIconDataUrl(path, tint);
156
194
work.then((url) =>
157
195
{
158
196
img.src = url;
159
197
}).catch(() =>
160
198
{
161
img.src = fallbackPath;
199
img.src = path;
162
200
});
163
201
}
@@ -1,5 +1,6 @@1
import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitions/items.js";1
import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitions/items.js";2
import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";2
import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";3
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";3
import4
import4
{5
{5
applyMagentaTintToImageData,6
applyMagentaTintToImageData,@@ -122,6 +123,29 @@ export async function dualTintedItemIconDataUrl (assetPath, dualTint)122
return url;123
return url;123
}124
}124
125
126
/** Crop one frame from a multi-frame item sheet for UI icons. */127
export async function framedItemIconDataUrl (assetPath, frameIndex, framesPerRow = 1, frameCount = 1)128
{129
const index = Math.max(0, Math.min((frameCount | 0 || 1) - 1, frameIndex | 0));130
const perRow = Math.max(1, framesPerRow | 0 || 1);131
const key = `frame|${assetPath}|${index}|${perRow}|${frameCount}`;132
if (urlCache.has(key))133
{ return urlCache.get(key); }134
const img = await loadImage(assetPath);135
const canvas = document.createElement("canvas");136
canvas.width = SPRITE_SIZE_PX;137
canvas.height = SPRITE_SIZE_PX;138
const ctx = canvas.getContext("2d");139
ctx.imageSmoothingEnabled = false;140
ctx.clearRect(0, 0, canvas.width, canvas.height);141
const sx = (index % perRow) * SPRITE_SIZE_PX;142
const sy = Math.floor(index / perRow) * SPRITE_SIZE_PX;143
ctx.drawImage(img, sx, sy, SPRITE_SIZE_PX, SPRITE_SIZE_PX, 0, 0, SPRITE_SIZE_PX, SPRITE_SIZE_PX);144
const url = canvas.toDataURL("image/png");145
urlCache.set(key, url);146
return url;147
}148
125
export function isPotionStack (stack)149
export function isPotionStack (stack)126
{150
{127
return (stack?.itemId === ItemId.potion && stack.instance?.kind === "potion")151
return (stack?.itemId === ItemId.potion && stack.instance?.kind === "potion")@@ -133,17 +157,31 @@ export function applyItemIcon (img, stack, fallbackPath)133
{157
{134
if (!img)158
if (!img)135
{ return; }159
{ return; }136
img.src = fallbackPath;160
const path = fallbackPath || itemAssetPathForStack(stack);161
img.src = path;137
const def = itemDefinition(stack?.itemId);162
const def = itemDefinition(stack?.itemId);163
const frames = def?.frames | 0 || 1;164
if (frames > 1 && itemMaxCharges(def) != null)165
{166
const frameIndex = chargeSpriteFrameIndex(stack);167
framedItemIconDataUrl(path, frameIndex, def.framesPerRow ?? 1, frames).then((url) =>168
{169
img.src = url;170
}).catch(() =>171
{172
img.src = path;173
});174
return;175
}138
const dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);176
const dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);139
if (dualTint)177
if (dualTint)140
{178
{141
dualTintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), dualTint).then((url) =>179
dualTintedItemIconDataUrl(path, dualTint).then((url) =>142
{180
{143
img.src = url;181
img.src = url;144
}).catch(() =>182
}).catch(() =>145
{183
{146
img.src = fallbackPath;184
img.src = path;147
});185
});148
return;186
return;149
}187
}@@ -152,12 +190,12 @@ export function applyItemIcon (img, stack, fallbackPath)152
{ return; }190
{ return; }153
const work = isPotionStack(stack)191
const work = isPotionStack(stack)154
? potionIconDataUrl(stack.instance)192
? potionIconDataUrl(stack.instance)155
: tintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), tint);193
: tintedItemIconDataUrl(path, tint);156
work.then((url) =>194
work.then((url) =>157
{195
{158
img.src = url;196
img.src = url;159
}).catch(() =>197
}).catch(() =>160
{198
{161
img.src = fallbackPath;199
img.src = path;162
});200
});163
}201
}@@ -6,6 +6,7 @@ import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSpr
6
6
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
7
7
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";
8
8
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
9
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
9
10
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
10
11
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";
11
12
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
@@ -1191,6 +1192,8 @@ export class WorldView
1191
1192
const def = itemDefinition(payload.itemId);
1192
1193
item.dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);
1193
1194
item.tintColor = item.dualTint ? null : resolveItemTint(stack, def);
1195
if (item.object?.renderer && itemMaxCharges(def) != null)
1196
{ item.object.renderer.setSubImage?.(chargeSpriteFrameIndex(stack)); }
1194
1197
this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);
1195
1198
this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);
1196
1199
}
@@ -6,6 +6,7 @@ import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSpr6
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";6
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";7
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";7
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";8
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";8
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";9
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";9
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";10
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";10
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";11
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";11
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";12
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";@@ -1191,6 +1192,8 @@ export class WorldView1191
const def = itemDefinition(payload.itemId);1192
const def = itemDefinition(payload.itemId);1192
item.dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);1193
item.dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);1193
item.tintColor = item.dualTint ? null : resolveItemTint(stack, def);1194
item.tintColor = item.dualTint ? null : resolveItemTint(stack, def);1195
if (item.object?.renderer && itemMaxCharges(def) != null)1196
{ item.object.renderer.setSubImage?.(chargeSpriteFrameIndex(stack)); }1194
this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);1197
this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);1195
this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);1198
this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);1196
}1199
}@@ -395,7 +395,10 @@ function shopStockView (world, shop, now)
395
395
listingId: `bought:${lot.stockKey}`,
396
396
itemId,
397
397
displayName: itemDisplayName(stack, def),
398
unitPrice: shopBoughtResalePrice(itemId, lastSaleOpts(itemId)),
398
unitPrice: shopBoughtResalePrice(itemId, {
399
...lastSaleOpts(itemId),
400
stack
401
}),
399
402
available: lot.quantity,
400
403
source: "bought",
401
404
instance: lot.instance ? structuredClone(lot.instance) : null
@@ -538,7 +541,12 @@ export function buyFromShop (world, sessionId, characterId, npcEntityId, itemId,
538
541
lastSale: lastSaleFor(world, buyItemId),
539
542
now,
540
543
lerpDurationMs: lerpDuration(world),
541
settings: world.settings ?? null
544
settings: world.settings ?? null,
545
stack: {
546
itemId: buyItemId,
547
quantity: 1,
548
instance: boughtLot(shop, listing.stockKey)?.instance ?? null
549
}
542
550
})
543
551
: shopUnitPrice(buyItemId, {
544
552
lastSale: lastSaleFor(world, buyItemId),
@@ -395,7 +395,10 @@ function shopStockView (world, shop, now)395
listingId: `bought:${lot.stockKey}`,395
listingId: `bought:${lot.stockKey}`,396
itemId,396
itemId,397
displayName: itemDisplayName(stack, def),397
displayName: itemDisplayName(stack, def),398
unitPrice: shopBoughtResalePrice(itemId, lastSaleOpts(itemId)),398
unitPrice: shopBoughtResalePrice(itemId, {399
...lastSaleOpts(itemId),400
stack401
}),399
available: lot.quantity,402
available: lot.quantity,400
source: "bought",403
source: "bought",401
instance: lot.instance ? structuredClone(lot.instance) : null404
instance: lot.instance ? structuredClone(lot.instance) : null@@ -538,7 +541,12 @@ export function buyFromShop (world, sessionId, characterId, npcEntityId, itemId,538
lastSale: lastSaleFor(world, buyItemId),541
lastSale: lastSaleFor(world, buyItemId),539
now,542
now,540
lerpDurationMs: lerpDuration(world),543
lerpDurationMs: lerpDuration(world),541
settings: world.settings ?? null544
settings: world.settings ?? null,545
stack: {546
itemId: buyItemId,547
quantity: 1,548
instance: boughtLot(shop, listing.stockKey)?.instance ?? null549
}542
})550
})543
: shopUnitPrice(buyItemId, {551
: shopUnitPrice(buyItemId, {544
lastSale: lastSaleFor(world, buyItemId),552
lastSale: lastSaleFor(world, buyItemId),@@ -0,0 +1,49 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { CraftingItemId, TINDERBOX_MAX_CHARGES, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";
4
import
5
{
6
chargeFractionRemaining,
7
chargeSpriteFrameIndex,
8
isChargeWorn,
9
normalizeChargeStack,
10
stackChargesRemaining
11
} from "../../shared/items/charges.js";
12
import { normalizeInventorySlots } from "../../shared/items/inventory.js";
13
14
test("tinderbox max charges is 6 and frames map 1:1 to uses left", () =>
15
{
16
assert.equal(TINDERBOX_MAX_CHARGES, 6);
17
assert.equal(chargeSpriteFrameIndex({
18
itemId: CraftingItemId.tinderbox,
19
instance: tinderboxItemInstance(6)
20
}), 5);
21
assert.equal(chargeSpriteFrameIndex({
22
itemId: CraftingItemId.tinderbox,
23
instance: tinderboxItemInstance(5)
24
}), 4);
25
assert.equal(chargeSpriteFrameIndex({
26
itemId: CraftingItemId.tinderbox,
27
instance: tinderboxItemInstance(1)
28
}), 0);
29
});
30
31
test("legacy tinderboxes with more than max charges clamp to max", () =>
32
{
33
const raw = {
34
itemId: CraftingItemId.tinderbox,
35
quantity: 1,
36
instance: { kind: "tinderbox", charges: 20 }
37
};
38
const normalized = normalizeChargeStack(raw);
39
assert.equal(normalized.instance.charges, 6);
40
assert.equal(stackChargesRemaining(normalized), 6);
41
assert.equal(isChargeWorn(normalized), false);
42
assert.equal(chargeFractionRemaining({
43
itemId: CraftingItemId.tinderbox,
44
instance: tinderboxItemInstance(3)
45
}), 0.5);
46
47
const slots = normalizeInventorySlots([raw]);
48
assert.equal(slots[0].instance.charges, 6);
49
});
@@ -0,0 +1,49 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { CraftingItemId, TINDERBOX_MAX_CHARGES, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";4
import5
{6
chargeFractionRemaining,7
chargeSpriteFrameIndex,8
isChargeWorn,9
normalizeChargeStack,10
stackChargesRemaining11
} from "../../shared/items/charges.js";12
import { normalizeInventorySlots } from "../../shared/items/inventory.js";13
14
test("tinderbox max charges is 6 and frames map 1:1 to uses left", () =>15
{16
assert.equal(TINDERBOX_MAX_CHARGES, 6);17
assert.equal(chargeSpriteFrameIndex({18
itemId: CraftingItemId.tinderbox,19
instance: tinderboxItemInstance(6)20
}), 5);21
assert.equal(chargeSpriteFrameIndex({22
itemId: CraftingItemId.tinderbox,23
instance: tinderboxItemInstance(5)24
}), 4);25
assert.equal(chargeSpriteFrameIndex({26
itemId: CraftingItemId.tinderbox,27
instance: tinderboxItemInstance(1)28
}), 0);29
});30
31
test("legacy tinderboxes with more than max charges clamp to max", () =>32
{33
const raw = {34
itemId: CraftingItemId.tinderbox,35
quantity: 1,36
instance: { kind: "tinderbox", charges: 20 }37
};38
const normalized = normalizeChargeStack(raw);39
assert.equal(normalized.instance.charges, 6);40
assert.equal(stackChargesRemaining(normalized), 6);41
assert.equal(isChargeWorn(normalized), false);42
assert.equal(chargeFractionRemaining({43
itemId: CraftingItemId.tinderbox,44
instance: tinderboxItemInstance(3)45
}), 0.5);46
47
const slots = normalizeInventorySlots([raw]);48
assert.equal(slots[0].instance.charges, 6);49
});@@ -124,7 +124,7 @@ test("start-fire places campfire and expiry drops ash", () =>
124
124
worker.world.rng = () => 0.999;
125
125
setSkillLevel(worker, playerId, SkillId.firestarting, 1);
126
126
giveInventory(harness, playerId, [
127
{ itemId: CraftingItemId.tinderbox, quantity: 1, instance: tinderboxItemInstance(20) }
127
{ itemId: CraftingItemId.tinderbox, quantity: 1, instance: tinderboxItemInstance(6) }
128
128
]);
129
129
130
130
const groundItemId = 9001;
@@ -152,7 +152,7 @@ test("start-fire places campfire and expiry drops ash", () =>
152
152
153
153
const bag = harness.simulation.bagOf(playerId);
154
154
const tinder = bag.inventory.find((s) => s?.itemId === CraftingItemId.tinderbox);
155
assert.equal(tinder?.instance?.charges, 19);
155
assert.equal(tinder?.instance?.charges, 5);
156
156
157
157
const entry = worker.world.campfireExpires.get("9,8");
158
158
entry.expiresAt = 0;
@@ -124,7 +124,7 @@ test("start-fire places campfire and expiry drops ash", () =>124
worker.world.rng = () => 0.999;124
worker.world.rng = () => 0.999;125
setSkillLevel(worker, playerId, SkillId.firestarting, 1);125
setSkillLevel(worker, playerId, SkillId.firestarting, 1);126
giveInventory(harness, playerId, [126
giveInventory(harness, playerId, [127
{ itemId: CraftingItemId.tinderbox, quantity: 1, instance: tinderboxItemInstance(20) }127
{ itemId: CraftingItemId.tinderbox, quantity: 1, instance: tinderboxItemInstance(6) }128
]);128
]);129
129
130
const groundItemId = 9001;130
const groundItemId = 9001;@@ -152,7 +152,7 @@ test("start-fire places campfire and expiry drops ash", () =>152
152
153
const bag = harness.simulation.bagOf(playerId);153
const bag = harness.simulation.bagOf(playerId);154
const tinder = bag.inventory.find((s) => s?.itemId === CraftingItemId.tinderbox);154
const tinder = bag.inventory.find((s) => s?.itemId === CraftingItemId.tinderbox);155
assert.equal(tinder?.instance?.charges, 19);155
assert.equal(tinder?.instance?.charges, 5);156
156
157
const entry = worker.world.campfireExpires.get("9,8");157
const entry = worker.world.campfireExpires.get("9,8");158
entry.expiresAt = 0;158
entry.expiresAt = 0;@@ -1,6 +1,7 @@
1
1
import test from "node:test";
2
2
import assert from "node:assert/strict";
3
3
import { ItemId } from "../../shared/definitions/items.js";
4
import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";
4
5
import { BlockType } from "../../shared/definitions/tiles.js";
5
6
import { canSellOnMarketplace, assertMarketplaceSellable } from "../../shared/items/marketplace.js";
6
7
import { midpointTradePrice, MARKET_ORDER_MAX_AGE_MS, soldLetterBody, marketOrderListingFee, orderCancelledLetterBody, orderExpiredLetterBody } from "../../shared/market/exchange.js";
@@ -38,6 +39,26 @@ test("normal items are marketplace sellable by default", () =>
38
39
assert.equal(canSellOnMarketplace({ itemId: ItemId.apple, quantity: 3 }), true);
39
40
});
40
41
42
test("fully charged tinderbox can list on CE; worn cannot", () =>
43
{
44
const fresh = {
45
itemId: CraftingItemId.tinderbox,
46
quantity: 1,
47
instance: tinderboxItemInstance(6)
48
};
49
const worn = {
50
itemId: CraftingItemId.tinderbox,
51
quantity: 1,
52
instance: tinderboxItemInstance(1)
53
};
54
assert.equal(canSellOnMarketplace(fresh), true);
55
assert.equal(canSellOnMarketplace(worn), false);
56
assert.throws(
57
() => assertMarketplaceSellable(worn),
58
(err) => /partially used/i.test(err.message)
59
);
60
});
61
41
62
test("letters cannot be listed on the marketplace", () =>
42
63
{
43
64
const own = {
@@ -1,6 +1,7 @@1
import test from "node:test";1
import test from "node:test";2
import assert from "node:assert/strict";2
import assert from "node:assert/strict";3
import { ItemId } from "../../shared/definitions/items.js";3
import { ItemId } from "../../shared/definitions/items.js";4
import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";4
import { BlockType } from "../../shared/definitions/tiles.js";5
import { BlockType } from "../../shared/definitions/tiles.js";5
import { canSellOnMarketplace, assertMarketplaceSellable } from "../../shared/items/marketplace.js";6
import { canSellOnMarketplace, assertMarketplaceSellable } from "../../shared/items/marketplace.js";6
import { midpointTradePrice, MARKET_ORDER_MAX_AGE_MS, soldLetterBody, marketOrderListingFee, orderCancelledLetterBody, orderExpiredLetterBody } from "../../shared/market/exchange.js";7
import { midpointTradePrice, MARKET_ORDER_MAX_AGE_MS, soldLetterBody, marketOrderListingFee, orderCancelledLetterBody, orderExpiredLetterBody } from "../../shared/market/exchange.js";@@ -38,6 +39,26 @@ test("normal items are marketplace sellable by default", () =>38
assert.equal(canSellOnMarketplace({ itemId: ItemId.apple, quantity: 3 }), true);39
assert.equal(canSellOnMarketplace({ itemId: ItemId.apple, quantity: 3 }), true);39
});40
});40
41
42
test("fully charged tinderbox can list on CE; worn cannot", () =>43
{44
const fresh = {45
itemId: CraftingItemId.tinderbox,46
quantity: 1,47
instance: tinderboxItemInstance(6)48
};49
const worn = {50
itemId: CraftingItemId.tinderbox,51
quantity: 1,52
instance: tinderboxItemInstance(1)53
};54
assert.equal(canSellOnMarketplace(fresh), true);55
assert.equal(canSellOnMarketplace(worn), false);56
assert.throws(57
() => assertMarketplaceSellable(worn),58
(err) => /partially used/i.test(err.message)59
);60
});61
41
test("letters cannot be listed on the marketplace", () =>62
test("letters cannot be listed on the marketplace", () =>42
{63
{43
const own = {64
const own = {@@ -16,7 +16,7 @@ import
16
16
lerp
17
17
} from "../../shared/shop/pricing.js";
18
18
import { ItemId, listAllItemPickerEntries } from "../../shared/definitions/items.js";
19
import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
19
import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";
20
20
import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js";
21
21
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
22
22
import { Component } from "../src/ecs/components.js";
@@ -175,6 +175,34 @@ test("shop prices fall back to seedValue and apply hidden discount", () =>
175
175
assert.equal(chequeQuote.payout, chequeQuote.baseTotal - chequeQuote.adminFee);
176
176
});
177
177
178
test("charge-worn tools scale merchant buy and resale prices by remaining uses", () =>
179
{
180
const full = {
181
itemId: CraftingItemId.tinderbox,
182
quantity: 1,
183
instance: tinderboxItemInstance(6)
184
};
185
const worn = {
186
itemId: CraftingItemId.tinderbox,
187
quantity: 1,
188
instance: tinderboxItemInstance(1)
189
};
190
const fullBuy = shopBuyFromPlayerPrice(CraftingItemId.tinderbox, { stack: full });
191
const wornBuy = shopBuyFromPlayerPrice(CraftingItemId.tinderbox, { stack: worn });
192
assert.equal(fullBuy, shopBuyFromPlayerPrice(CraftingItemId.tinderbox));
193
assert.equal(wornBuy, marketValueAsCoins(
194
undiscountedMarketValue(CraftingItemId.tinderbox) * 0.8 * (1 / 6)
195
));
196
const fullResale = shopBoughtResalePrice(CraftingItemId.tinderbox, { stack: full });
197
const wornResale = shopBoughtResalePrice(CraftingItemId.tinderbox, { stack: worn });
198
assert.equal(fullResale, shopBoughtResalePrice(CraftingItemId.tinderbox));
199
assert.equal(wornResale, marketValueAsCoins(
200
undiscountedMarketValue(CraftingItemId.tinderbox) * 1.2 * (1 / 6)
201
));
202
const quote = resolveShopSellQuote(worn);
203
assert.equal(quote.unitPrice, wornBuy);
204
});
205
178
206
test("market value display and shop use ceil fractional lerps", () =>
179
207
{
180
208
const now = 1_000_000;
@@ -16,7 +16,7 @@ import16
lerp16
lerp17
} from "../../shared/shop/pricing.js";17
} from "../../shared/shop/pricing.js";18
import { ItemId, listAllItemPickerEntries } from "../../shared/definitions/items.js";18
import { ItemId, listAllItemPickerEntries } from "../../shared/definitions/items.js";19
import { CraftingItemId } from "../../shared/definitions/craftingItems.js";19
import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";20
import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js";20
import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js";21
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";21
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";22
import { Component } from "../src/ecs/components.js";22
import { Component } from "../src/ecs/components.js";@@ -175,6 +175,34 @@ test("shop prices fall back to seedValue and apply hidden discount", () =>175
assert.equal(chequeQuote.payout, chequeQuote.baseTotal - chequeQuote.adminFee);175
assert.equal(chequeQuote.payout, chequeQuote.baseTotal - chequeQuote.adminFee);176
});176
});177
177
178
test("charge-worn tools scale merchant buy and resale prices by remaining uses", () =>179
{180
const full = {181
itemId: CraftingItemId.tinderbox,182
quantity: 1,183
instance: tinderboxItemInstance(6)184
};185
const worn = {186
itemId: CraftingItemId.tinderbox,187
quantity: 1,188
instance: tinderboxItemInstance(1)189
};190
const fullBuy = shopBuyFromPlayerPrice(CraftingItemId.tinderbox, { stack: full });191
const wornBuy = shopBuyFromPlayerPrice(CraftingItemId.tinderbox, { stack: worn });192
assert.equal(fullBuy, shopBuyFromPlayerPrice(CraftingItemId.tinderbox));193
assert.equal(wornBuy, marketValueAsCoins(194
undiscountedMarketValue(CraftingItemId.tinderbox) * 0.8 * (1 / 6)195
));196
const fullResale = shopBoughtResalePrice(CraftingItemId.tinderbox, { stack: full });197
const wornResale = shopBoughtResalePrice(CraftingItemId.tinderbox, { stack: worn });198
assert.equal(fullResale, shopBoughtResalePrice(CraftingItemId.tinderbox));199
assert.equal(wornResale, marketValueAsCoins(200
undiscountedMarketValue(CraftingItemId.tinderbox) * 1.2 * (1 / 6)201
));202
const quote = resolveShopSellQuote(worn);203
assert.equal(quote.unitPrice, wornBuy);204
});205
178
test("market value display and shop use ceil fractional lerps", () =>206
test("market value display and shop use ceil fractional lerps", () =>179
{207
{180
const now = 1_000_000;208
const now = 1_000_000;