Merge branch 'feature/tanning-ingredients'
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -12,6 +12,7 @@ import {
12
12
CAULDRON_EMPTY_FLAVOR
13
13
} from "/shared/definitions/alchemy.js";
14
14
import { FLOWER_MAX_STACK } from "/shared/definitions/dyes.js";
15
import { isFullPotionBottle } from "/shared/items/charges.js";
15
16
import { applyItemIcon } from "../render/potionIcon.js";
16
17
17
18
export function initAlchemy ({
@@ -114,6 +115,8 @@ export function initAlchemy ({
114
115
{ continue; }
115
116
if (id === ItemId.flower && !sameClaimInstance(claim.instance, instance))
116
117
{ continue; }
118
if (id === ItemId.potion && !sameClaimInstance(claim.instance, instance))
119
{ continue; }
117
120
total += claim.quantity | 0;
118
121
}
119
122
return total;
@@ -358,7 +361,7 @@ export function initAlchemy ({
358
361
{ continue; }
359
362
const def = itemDefinition(slot.itemId);
360
363
if (!def || def.uniqueInstance || def.equipment
361
|| slot.itemId === ItemId.potion || slot.itemId === ItemId.glassBottle)
364
|| slot.itemId === ItemId.glassBottle)
362
365
{ continue; }
363
366
if (mode === "dye")
364
367
{
@@ -367,8 +370,13 @@ export function initAlchemy ({
367
370
}
368
371
else if (slot.itemId === ItemId.flower || slot.itemId === ItemId.dye || def.flower || def.dye)
369
372
{ continue; }
373
else if (slot.itemId === ItemId.potion)
374
{
375
if (!isFullPotionBottle(slot))
376
{ continue; }
377
}
370
378
371
const identity = slot.itemId === ItemId.flower
379
const identity = (slot.itemId === ItemId.flower || slot.itemId === ItemId.potion)
372
380
? `${slot.itemId}|${JSON.stringify(slot.instance ?? null)}`
373
381
: String(slot.itemId);
374
382
const prev = counts.get(identity);
@@ -456,6 +464,8 @@ export function initAlchemy ({
456
464
{ continue; }
457
465
if (pickItemId === ItemId.flower && !sameClaimInstance(slot.instance, pickInstance))
458
466
{ continue; }
467
if (pickItemId === ItemId.potion && !sameClaimInstance(slot.instance, pickInstance))
468
{ continue; }
459
469
bagQty += slot.quantity | 0;
460
470
}
461
471
return bagQty - claimedQuantityFor(pickItemId, pickInstance, {
@@ -12,6 +12,7 @@ import {12
CAULDRON_EMPTY_FLAVOR12
CAULDRON_EMPTY_FLAVOR13
} from "/shared/definitions/alchemy.js";13
} from "/shared/definitions/alchemy.js";14
import { FLOWER_MAX_STACK } from "/shared/definitions/dyes.js";14
import { FLOWER_MAX_STACK } from "/shared/definitions/dyes.js";15
import { isFullPotionBottle } from "/shared/items/charges.js";15
import { applyItemIcon } from "../render/potionIcon.js";16
import { applyItemIcon } from "../render/potionIcon.js";16
17
17
export function initAlchemy ({18
export function initAlchemy ({@@ -114,6 +115,8 @@ export function initAlchemy ({114
{ continue; }115
{ continue; }115
if (id === ItemId.flower && !sameClaimInstance(claim.instance, instance))116
if (id === ItemId.flower && !sameClaimInstance(claim.instance, instance))116
{ continue; }117
{ continue; }118
if (id === ItemId.potion && !sameClaimInstance(claim.instance, instance))119
{ continue; }117
total += claim.quantity | 0;120
total += claim.quantity | 0;118
}121
}119
return total;122
return total;@@ -358,7 +361,7 @@ export function initAlchemy ({358
{ continue; }361
{ continue; }359
const def = itemDefinition(slot.itemId);362
const def = itemDefinition(slot.itemId);360
if (!def || def.uniqueInstance || def.equipment363
if (!def || def.uniqueInstance || def.equipment361
|| slot.itemId === ItemId.potion || slot.itemId === ItemId.glassBottle)364
|| slot.itemId === ItemId.glassBottle)362
{ continue; }365
{ continue; }363
if (mode === "dye")366
if (mode === "dye")364
{367
{@@ -367,8 +370,13 @@ export function initAlchemy ({367
}370
}368
else if (slot.itemId === ItemId.flower || slot.itemId === ItemId.dye || def.flower || def.dye)371
else if (slot.itemId === ItemId.flower || slot.itemId === ItemId.dye || def.flower || def.dye)369
{ continue; }372
{ continue; }373
else if (slot.itemId === ItemId.potion)374
{375
if (!isFullPotionBottle(slot))376
{ continue; }377
}370
378
371
const identity = slot.itemId === ItemId.flower379
const identity = (slot.itemId === ItemId.flower || slot.itemId === ItemId.potion)372
? `${slot.itemId}|${JSON.stringify(slot.instance ?? null)}`380
? `${slot.itemId}|${JSON.stringify(slot.instance ?? null)}`373
: String(slot.itemId);381
: String(slot.itemId);374
const prev = counts.get(identity);382
const prev = counts.get(identity);@@ -456,6 +464,8 @@ export function initAlchemy ({456
{ continue; }464
{ continue; }457
if (pickItemId === ItemId.flower && !sameClaimInstance(slot.instance, pickInstance))465
if (pickItemId === ItemId.flower && !sameClaimInstance(slot.instance, pickInstance))458
{ continue; }466
{ continue; }467
if (pickItemId === ItemId.potion && !sameClaimInstance(slot.instance, pickInstance))468
{ continue; }459
bagQty += slot.quantity | 0;469
bagQty += slot.quantity | 0;460
}470
}461
return bagQty - claimedQuantityFor(pickItemId, pickInstance, {471
return bagQty - claimedQuantityFor(pickItemId, pickInstance, {@@ -43,6 +43,7 @@ import { formatQuantity } from "/shared/items/formatQuantity.js";
43
43
import { ItemId, itemDefinition } from "/shared/definitions/items.js";
44
44
import { CraftingItemId, TINDERBOX_MAX_CHARGES } from "/shared/definitions/craftingItems.js";
45
45
import { ItemFamilyId } from "/shared/definitions/tierFamilies.js";
46
import { isLogDebarked } from "/shared/definitions/woodItems.js";
46
47
import { EquipmentKind } from "/shared/definitions/equipmentKinds.js";
47
48
import { countCoinsInSlots } from "/shared/items/inventory.js";
48
49
@@ -529,6 +530,24 @@ function requestStartFire (ground)
529
530
{ approachAdjacentTile(ground.tileX, ground.tileY); }
530
531
}
531
532
533
function requestDebarkLog (ground)
534
{
535
if (!ground)
536
{ return; }
537
clearAllPendingActions();
538
pendingInteract = {
539
kind: "debark-log",
540
groundItemId: ground.groundItemId,
541
tileX: ground.tileX,
542
tileY: ground.tileY
543
};
544
const local = view?.entities.get(view.localEntityId);
545
if (local && isAdjacentTile(local.tileX, local.tileY, ground.tileX, ground.tileY))
546
{ flushPendingInteract(); }
547
else
548
{ approachAdjacentTile(ground.tileX, ground.tileY); }
549
}
550
532
551
function requestFish (tileX, tileY)
533
552
{
534
553
clearAllPendingActions();
@@ -867,6 +886,19 @@ function flushPendingInteract ()
867
886
return;
868
887
}
869
888
889
if (pendingInteract.kind === "debark-log")
890
{
891
if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY)
892
&& !(local.tileX === pendingInteract.tileX && local.tileY === pendingInteract.tileY))
893
{ return; }
894
socket.send({
895
type: MessageType.debarkLog,
896
groundItemId: pendingInteract.groundItemId
897
});
898
clearPendingInteract();
899
return;
900
}
901
870
902
if (pendingInteract.kind === "fish")
871
903
{
872
904
if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
@@ -1259,6 +1291,13 @@ function handleRightClick (event, mouseX, mouseY)
1259
1291
onSelect: () => requestStartFire(ground)
1260
1292
});
1261
1293
}
1294
if (isGroundWoodLog(ground) && !isLogDebarked(ground))
1295
{
1296
items.push({
1297
label: "Debark",
1298
onSelect: () => requestDebarkLog(ground)
1299
});
1300
}
1262
1301
}
1263
1302
1264
1303
if (isBankTile(view, tile.tileX, tile.tileY))
@@ -43,6 +43,7 @@ import { formatQuantity } from "/shared/items/formatQuantity.js";43
import { ItemId, itemDefinition } from "/shared/definitions/items.js";43
import { ItemId, itemDefinition } from "/shared/definitions/items.js";44
import { CraftingItemId, TINDERBOX_MAX_CHARGES } from "/shared/definitions/craftingItems.js";44
import { CraftingItemId, TINDERBOX_MAX_CHARGES } from "/shared/definitions/craftingItems.js";45
import { ItemFamilyId } from "/shared/definitions/tierFamilies.js";45
import { ItemFamilyId } from "/shared/definitions/tierFamilies.js";46
import { isLogDebarked } from "/shared/definitions/woodItems.js";46
import { EquipmentKind } from "/shared/definitions/equipmentKinds.js";47
import { EquipmentKind } from "/shared/definitions/equipmentKinds.js";47
import { countCoinsInSlots } from "/shared/items/inventory.js";48
import { countCoinsInSlots } from "/shared/items/inventory.js";48
49
@@ -529,6 +530,24 @@ function requestStartFire (ground)529
{ approachAdjacentTile(ground.tileX, ground.tileY); }530
{ approachAdjacentTile(ground.tileX, ground.tileY); }530
}531
}531
532
533
function requestDebarkLog (ground)534
{535
if (!ground)536
{ return; }537
clearAllPendingActions();538
pendingInteract = {539
kind: "debark-log",540
groundItemId: ground.groundItemId,541
tileX: ground.tileX,542
tileY: ground.tileY543
};544
const local = view?.entities.get(view.localEntityId);545
if (local && isAdjacentTile(local.tileX, local.tileY, ground.tileX, ground.tileY))546
{ flushPendingInteract(); }547
else548
{ approachAdjacentTile(ground.tileX, ground.tileY); }549
}550
532
function requestFish (tileX, tileY)551
function requestFish (tileX, tileY)533
{552
{534
clearAllPendingActions();553
clearAllPendingActions();@@ -867,6 +886,19 @@ function flushPendingInteract ()867
return;886
return;868
}887
}869
888
889
if (pendingInteract.kind === "debark-log")890
{891
if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY)892
&& !(local.tileX === pendingInteract.tileX && local.tileY === pendingInteract.tileY))893
{ return; }894
socket.send({895
type: MessageType.debarkLog,896
groundItemId: pendingInteract.groundItemId897
});898
clearPendingInteract();899
return;900
}901
870
if (pendingInteract.kind === "fish")902
if (pendingInteract.kind === "fish")871
{903
{872
if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))904
if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))@@ -1259,6 +1291,13 @@ function handleRightClick (event, mouseX, mouseY)1259
onSelect: () => requestStartFire(ground)1291
onSelect: () => requestStartFire(ground)1260
});1292
});1261
}1293
}1294
if (isGroundWoodLog(ground) && !isLogDebarked(ground))1295
{1296
items.push({1297
label: "Debark",1298
onSelect: () => requestDebarkLog(ground)1299
});1300
}1262
}1301
}1263
1302
1264
if (isBankTile(view, tile.tileX, tile.tileY))1303
if (isBankTile(view, tile.tileX, tile.tileY))@@ -19,7 +19,7 @@ import {
19
19
FLOWER_MAX_STACK,
20
20
mixFlowersForDye
21
21
} from "../../../shared/definitions/dyes.js";
22
import { bagView } from "../items/bags.js";
22
import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";
23
23
import {
24
24
countItemInSlots,
25
25
emptySlots,
@@ -28,6 +28,7 @@ import {
28
28
takeMatchingFromSlots,
29
29
stackQuantity
30
30
} from "../../../shared/items/inventory.js";
31
import { isFullPotionBottle } from "../../../shared/items/charges.js";
31
32
import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";
32
33
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
33
34
import {
@@ -296,12 +297,22 @@ function insertIngredient (world, sessionId, command)
296
297
{ throw userError("Nothing to insert."); }
297
298
298
299
const def = itemDefinition(itemId);
300
const instance = command.instance ? structuredClone(command.instance) : null;
301
const isPotion = itemId === ItemId.potion && instance?.kind === "potion";
302
299
303
if (!def || def.uniqueInstance || def.equipment
300
|| itemId === ItemId.potion || itemId === ItemId.glassBottle
304
|| itemId === ItemId.glassBottle
301
305
|| itemId === ItemId.flower || itemId === ItemId.dye || def.flower || def.dye)
302
306
{ throw userError("Use the Dyes tab for flowers."); }
303
307
304
const instance = command.instance ? structuredClone(command.instance) : null;
308
if (itemId === ItemId.potion && !isPotion)
309
{ throw userError("That is not a bottled brew."); }
310
if (isPotion)
311
{
312
if (!isFullPotionBottle({ itemId, instance }))
313
{ throw userError("Only full bottles can be used as ingredients."); }
314
}
315
305
316
const inventory = ensureInventory(world, handle);
306
317
const have = instance
307
318
? countMatchingInstance(inventory.slots, itemId, instance)
@@ -310,8 +321,16 @@ function insertIngredient (world, sessionId, command)
310
321
if (have < alreadyClaimed + quantity)
311
322
{ throw userError("Not enough of that item in your inventory."); }
312
323
313
const uniqueIds = new Set((session.pendingBrew ?? []).map((row) => row.itemId | 0));
314
if (!uniqueIds.has(itemId) && uniqueIds.size >= CAULDRON_SLOT_COUNT)
324
const uniqueKeys = new Set((session.pendingBrew ?? []).map((row) =>
325
{
326
if ((row.itemId | 0) === ItemId.potion && row.instance?.potionKey)
327
{ return `potion:${row.instance.potionKey}`; }
328
return `item:${row.itemId | 0}`;
329
}));
330
const claimKey = isPotion
331
? `potion:${instance.potionKey}`
332
: `item:${itemId}`;
333
if (!uniqueKeys.has(claimKey) && uniqueKeys.size >= CAULDRON_SLOT_COUNT)
315
334
{
316
335
throw userError(
317
336
`A brew can use at most ${CAULDRON_SLOT_COUNT} different ingredients.`
@@ -319,7 +338,11 @@ function insertIngredient (world, sessionId, command)
319
338
}
320
339
321
340
addPendingBrew(session, { itemId, quantity, instance });
322
session.steps.push({ kind: AlchemyStepKind.insert, itemId });
341
session.steps.push({
342
kind: AlchemyStepKind.insert,
343
itemId,
344
...(isPotion ? { potionKey: instance.potionKey } : {})
345
});
323
346
session.lastSuccessRecipe = null;
324
347
325
348
return {
@@ -350,6 +373,51 @@ function action (world, sessionId, command)
350
373
};
351
374
}
352
375
376
function grantEmptyGlassBottles (world, handle, characterId, quantity, events, now = Date.now())
377
{
378
const want = Math.max(0, quantity | 0);
379
if (want <= 0)
380
{ return; }
381
const inventory = ensureInventory(world, handle);
382
const bottleDef = itemDefinition(ItemId.glassBottle);
383
const inserted = insertStack(inventory.slots, {
384
itemId: ItemId.glassBottle,
385
quantity: want
386
}, bottleDef);
387
inventory.slots = inserted.slots;
388
const remainder = inserted.remainder | 0;
389
if (remainder <= 0)
390
{ return; }
391
const position = world.ecs.get(handle, Component.position);
392
const groundItemId = (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1);
393
const item = {
394
groundItemId,
395
tileX: position.tileX,
396
tileY: position.tileY,
397
stack: { itemId: ItemId.glassBottle, quantity: remainder },
398
droppedAt: now,
399
expiresAt: now + (world.settings.groundItemDespawnDurationMs ?? 600_000),
400
source: "alchemy-overflow",
401
droppedByCharacterId: characterId
402
};
403
addGroundItem(world, item);
404
events.push({
405
type: "ground-item-appear",
406
...publicGroundItem(item),
407
stack: item.stack,
408
droppedAt: item.droppedAt,
409
source: item.source,
410
droppedByCharacterId: item.droppedByCharacterId,
411
expiresAt: item.expiresAt
412
});
413
events.push({
414
type: "toast",
415
sessionId: null,
416
characterId,
417
message: "Glass bottle dropped on the ground"
418
});
419
}
420
353
421
function bottle (world, sessionId, command)
354
422
{
355
423
const { handle, entityId } = world.requireOwnedEntity(sessionId, command.characterId);
@@ -369,13 +437,17 @@ function bottle (world, sessionId, command)
369
437
});
370
438
371
439
const wanted = Math.max(1, evaluation.batch | 0);
440
const requiresEmptyBottles = evaluation.result?.requiresEmptyBottles !== false;
372
441
const bottles = countItemInSlots(inventory.slots, ItemId.glassBottle);
373
const produced = Math.min(wanted, bottles);
374
if (produced <= 0)
442
const produced = requiresEmptyBottles ? Math.min(wanted, bottles) : wanted;
443
if (requiresEmptyBottles && produced <= 0)
375
444
{ throw userError("You need glass bottles to bottle the brew."); }
376
445
377
446
for (const row of session.pendingBrew ?? [])
378
447
{
448
if (row.itemId === ItemId.potion && row.instance?.kind === "potion"
449
&& !isFullPotionBottle({ itemId: row.itemId, instance: row.instance }))
450
{ throw userError("Only full bottles can be used as ingredients."); }
379
451
const have = row.instance
380
452
? countMatchingInstance(inventory.slots, row.itemId, row.instance)
381
453
: countItemInSlots(inventory.slots, row.itemId);
@@ -402,39 +474,90 @@ function bottle (world, sessionId, command)
402
474
consumed.push(pulled.taken);
403
475
}
404
476
405
const takeBottles = takeMatchingFromSlots(inventory.slots, {
406
itemId: ItemId.glassBottle,
407
quantity: produced,
408
compact: false
409
});
410
if (!takeBottles.ok)
477
let takeBottles = null;
478
if (requiresEmptyBottles)
411
479
{
412
refundStacks(inventory, consumed);
413
throw userError("You need glass bottles to bottle the brew.");
480
takeBottles = takeMatchingFromSlots(inventory.slots, {
481
itemId: ItemId.glassBottle,
482
quantity: produced,
483
compact: false
484
});
485
if (!takeBottles.ok)
486
{
487
refundStacks(inventory, consumed);
488
throw userError("You need glass bottles to bottle the brew.");
489
}
490
inventory.slots = takeBottles.slots;
414
491
}
415
inventory.slots = takeBottles.slots;
416
492
417
const instance = potionItemInstance(evaluation.result);
418
const potionDef = itemDefinition(ItemId.potion);
419
493
const origin = craftOrigin(CraftOriginVerb.brewed, characterDisplayName(world, handle));
420
const inserted = insertStack(inventory.slots, attachOrigins({
421
itemId: ItemId.potion,
422
quantity: produced,
423
instance,
424
origins: [{ origin, quantity: produced }]
425
}), potionDef);
426
if (!inserted.ok)
494
const outputItemId = evaluation.result?.outputItemId | 0;
495
let alchemyPotionView = null;
496
497
if (outputItemId && evaluation.success)
427
498
{
428
refundStacks(inventory, consumed);
429
refundStacks(inventory, [takeBottles.taken]);
430
throw userError("Not enough inventory space for potions.");
499
const outQty = Math.max(1, (evaluation.result.outputQuantity | 0) || 1) * produced;
500
const outDef = itemDefinition(outputItemId);
501
const inserted = insertStack(inventory.slots, attachOrigins({
502
itemId: outputItemId,
503
quantity: outQty,
504
origins: [{ origin, quantity: outQty }]
505
}), outDef);
506
if (!inserted.ok)
507
{
508
refundStacks(inventory, consumed);
509
if (takeBottles)
510
{ refundStacks(inventory, [takeBottles.taken]); }
511
throw userError("Not enough inventory space for the brew.");
512
}
513
inventory.slots = inserted.slots;
514
alchemyPotionView = {
515
potionKey: evaluation.result.potionKey,
516
displayName: evaluation.result.displayName,
517
unstable: false,
518
color: evaluation.result.color,
519
fillLevel: null
520
};
521
}
522
else
523
{
524
const instance = potionItemInstance(evaluation.result);
525
const potionDef = itemDefinition(ItemId.potion);
526
const inserted = insertStack(inventory.slots, attachOrigins({
527
itemId: ItemId.potion,
528
quantity: produced,
529
instance,
530
origins: [{ origin, quantity: produced }]
531
}), potionDef);
532
if (!inserted.ok)
533
{
534
refundStacks(inventory, consumed);
535
if (takeBottles)
536
{ refundStacks(inventory, [takeBottles.taken]); }
537
throw userError("Not enough inventory space for potions.");
538
}
539
inventory.slots = inserted.slots;
540
alchemyPotionView = {
541
potionKey: instance.potionKey,
542
displayName: instance.displayName,
543
unstable: instance.unstable,
544
color: instance.color,
545
fillLevel: instance.fillLevel
546
};
431
547
}
432
inventory.slots = inserted.slots;
433
548
434
549
session.lastSuccessRecipe = evaluation.success ? evaluation.recipe : null;
435
550
clearAlchemy(session);
436
551
437
552
const events = [];
553
let returnedBottles = 0;
554
for (const row of consumed)
555
{
556
if ((row.itemId | 0) === ItemId.potion)
557
{ returnedBottles += stackQuantity(row.quantity); }
558
}
559
grantEmptyGlassBottles(world, handle, command.characterId, returnedBottles, events);
560
438
561
if (evaluation.success && skills?.xp)
439
562
{
440
563
const xpInputs = (consumed ?? []).map((row) => ({
@@ -475,13 +598,7 @@ function bottle (world, sessionId, command)
475
598
produced,
476
599
wanted,
477
600
lost: Math.max(0, wanted - produced),
478
potion: {
479
potionKey: instance.potionKey,
480
displayName: instance.displayName,
481
unstable: instance.unstable,
482
color: instance.color,
483
fillLevel: instance.fillLevel
484
}
601
potion: alchemyPotionView
485
602
}
486
603
};
487
604
}
@@ -19,7 +19,7 @@ import {19
FLOWER_MAX_STACK,19
FLOWER_MAX_STACK,20
mixFlowersForDye20
mixFlowersForDye21
} from "../../../shared/definitions/dyes.js";21
} from "../../../shared/definitions/dyes.js";22
import { bagView } from "../items/bags.js";22
import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";23
import {23
import {24
countItemInSlots,24
countItemInSlots,25
emptySlots,25
emptySlots,@@ -28,6 +28,7 @@ import {28
takeMatchingFromSlots,28
takeMatchingFromSlots,29
stackQuantity29
stackQuantity30
} from "../../../shared/items/inventory.js";30
} from "../../../shared/items/inventory.js";31
import { isFullPotionBottle } from "../../../shared/items/charges.js";31
import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";32
import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";32
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";33
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";33
import {34
import {@@ -296,12 +297,22 @@ function insertIngredient (world, sessionId, command)296
{ throw userError("Nothing to insert."); }297
{ throw userError("Nothing to insert."); }297
298
298
const def = itemDefinition(itemId);299
const def = itemDefinition(itemId);300
const instance = command.instance ? structuredClone(command.instance) : null;301
const isPotion = itemId === ItemId.potion && instance?.kind === "potion";302
299
if (!def || def.uniqueInstance || def.equipment303
if (!def || def.uniqueInstance || def.equipment300
|| itemId === ItemId.potion || itemId === ItemId.glassBottle304
|| itemId === ItemId.glassBottle301
|| itemId === ItemId.flower || itemId === ItemId.dye || def.flower || def.dye)305
|| itemId === ItemId.flower || itemId === ItemId.dye || def.flower || def.dye)302
{ throw userError("Use the Dyes tab for flowers."); }306
{ throw userError("Use the Dyes tab for flowers."); }303
307
304
const instance = command.instance ? structuredClone(command.instance) : null;308
if (itemId === ItemId.potion && !isPotion)309
{ throw userError("That is not a bottled brew."); }310
if (isPotion)311
{312
if (!isFullPotionBottle({ itemId, instance }))313
{ throw userError("Only full bottles can be used as ingredients."); }314
}315
305
const inventory = ensureInventory(world, handle);316
const inventory = ensureInventory(world, handle);306
const have = instance317
const have = instance307
? countMatchingInstance(inventory.slots, itemId, instance)318
? countMatchingInstance(inventory.slots, itemId, instance)@@ -310,8 +321,16 @@ function insertIngredient (world, sessionId, command)310
if (have < alreadyClaimed + quantity)321
if (have < alreadyClaimed + quantity)311
{ throw userError("Not enough of that item in your inventory."); }322
{ throw userError("Not enough of that item in your inventory."); }312
323
313
const uniqueIds = new Set((session.pendingBrew ?? []).map((row) => row.itemId | 0));324
const uniqueKeys = new Set((session.pendingBrew ?? []).map((row) =>314
if (!uniqueIds.has(itemId) && uniqueIds.size >= CAULDRON_SLOT_COUNT)325
{326
if ((row.itemId | 0) === ItemId.potion && row.instance?.potionKey)327
{ return `potion:${row.instance.potionKey}`; }328
return `item:${row.itemId | 0}`;329
}));330
const claimKey = isPotion331
? `potion:${instance.potionKey}`332
: `item:${itemId}`;333
if (!uniqueKeys.has(claimKey) && uniqueKeys.size >= CAULDRON_SLOT_COUNT)315
{334
{316
throw userError(335
throw userError(317
`A brew can use at most ${CAULDRON_SLOT_COUNT} different ingredients.`336
`A brew can use at most ${CAULDRON_SLOT_COUNT} different ingredients.`@@ -319,7 +338,11 @@ function insertIngredient (world, sessionId, command)319
}338
}320
339
321
addPendingBrew(session, { itemId, quantity, instance });340
addPendingBrew(session, { itemId, quantity, instance });322
session.steps.push({ kind: AlchemyStepKind.insert, itemId });341
session.steps.push({342
kind: AlchemyStepKind.insert,343
itemId,344
...(isPotion ? { potionKey: instance.potionKey } : {})345
});323
session.lastSuccessRecipe = null;346
session.lastSuccessRecipe = null;324
347
325
return {348
return {@@ -350,6 +373,51 @@ function action (world, sessionId, command)350
};373
};351
}374
}352
375
376
function grantEmptyGlassBottles (world, handle, characterId, quantity, events, now = Date.now())377
{378
const want = Math.max(0, quantity | 0);379
if (want <= 0)380
{ return; }381
const inventory = ensureInventory(world, handle);382
const bottleDef = itemDefinition(ItemId.glassBottle);383
const inserted = insertStack(inventory.slots, {384
itemId: ItemId.glassBottle,385
quantity: want386
}, bottleDef);387
inventory.slots = inserted.slots;388
const remainder = inserted.remainder | 0;389
if (remainder <= 0)390
{ return; }391
const position = world.ecs.get(handle, Component.position);392
const groundItemId = (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1);393
const item = {394
groundItemId,395
tileX: position.tileX,396
tileY: position.tileY,397
stack: { itemId: ItemId.glassBottle, quantity: remainder },398
droppedAt: now,399
expiresAt: now + (world.settings.groundItemDespawnDurationMs ?? 600_000),400
source: "alchemy-overflow",401
droppedByCharacterId: characterId402
};403
addGroundItem(world, item);404
events.push({405
type: "ground-item-appear",406
...publicGroundItem(item),407
stack: item.stack,408
droppedAt: item.droppedAt,409
source: item.source,410
droppedByCharacterId: item.droppedByCharacterId,411
expiresAt: item.expiresAt412
});413
events.push({414
type: "toast",415
sessionId: null,416
characterId,417
message: "Glass bottle dropped on the ground"418
});419
}420
353
function bottle (world, sessionId, command)421
function bottle (world, sessionId, command)354
{422
{355
const { handle, entityId } = world.requireOwnedEntity(sessionId, command.characterId);423
const { handle, entityId } = world.requireOwnedEntity(sessionId, command.characterId);@@ -369,13 +437,17 @@ function bottle (world, sessionId, command)369
});437
});370
438
371
const wanted = Math.max(1, evaluation.batch | 0);439
const wanted = Math.max(1, evaluation.batch | 0);440
const requiresEmptyBottles = evaluation.result?.requiresEmptyBottles !== false;372
const bottles = countItemInSlots(inventory.slots, ItemId.glassBottle);441
const bottles = countItemInSlots(inventory.slots, ItemId.glassBottle);373
const produced = Math.min(wanted, bottles);442
const produced = requiresEmptyBottles ? Math.min(wanted, bottles) : wanted;374
if (produced <= 0)443
if (requiresEmptyBottles && produced <= 0)375
{ throw userError("You need glass bottles to bottle the brew."); }444
{ throw userError("You need glass bottles to bottle the brew."); }376
445
377
for (const row of session.pendingBrew ?? [])446
for (const row of session.pendingBrew ?? [])378
{447
{448
if (row.itemId === ItemId.potion && row.instance?.kind === "potion"449
&& !isFullPotionBottle({ itemId: row.itemId, instance: row.instance }))450
{ throw userError("Only full bottles can be used as ingredients."); }379
const have = row.instance451
const have = row.instance380
? countMatchingInstance(inventory.slots, row.itemId, row.instance)452
? countMatchingInstance(inventory.slots, row.itemId, row.instance)381
: countItemInSlots(inventory.slots, row.itemId);453
: countItemInSlots(inventory.slots, row.itemId);@@ -402,39 +474,90 @@ function bottle (world, sessionId, command)402
consumed.push(pulled.taken);474
consumed.push(pulled.taken);403
}475
}404
476
405
const takeBottles = takeMatchingFromSlots(inventory.slots, {477
let takeBottles = null;406
itemId: ItemId.glassBottle,478
if (requiresEmptyBottles)407
quantity: produced,408
compact: false409
});410
if (!takeBottles.ok)411
{479
{412
refundStacks(inventory, consumed);480
takeBottles = takeMatchingFromSlots(inventory.slots, {413
throw userError("You need glass bottles to bottle the brew.");481
itemId: ItemId.glassBottle,482
quantity: produced,483
compact: false484
});485
if (!takeBottles.ok)486
{487
refundStacks(inventory, consumed);488
throw userError("You need glass bottles to bottle the brew.");489
}490
inventory.slots = takeBottles.slots;414
}491
}415
inventory.slots = takeBottles.slots;416
492
417
const instance = potionItemInstance(evaluation.result);418
const potionDef = itemDefinition(ItemId.potion);419
const origin = craftOrigin(CraftOriginVerb.brewed, characterDisplayName(world, handle));493
const origin = craftOrigin(CraftOriginVerb.brewed, characterDisplayName(world, handle));420
const inserted = insertStack(inventory.slots, attachOrigins({494
const outputItemId = evaluation.result?.outputItemId | 0;421
itemId: ItemId.potion,495
let alchemyPotionView = null;422
quantity: produced,496
423
instance,497
if (outputItemId && evaluation.success)424
origins: [{ origin, quantity: produced }]425
}), potionDef);426
if (!inserted.ok)427
{498
{428
refundStacks(inventory, consumed);499
const outQty = Math.max(1, (evaluation.result.outputQuantity | 0) || 1) * produced;429
refundStacks(inventory, [takeBottles.taken]);500
const outDef = itemDefinition(outputItemId);430
throw userError("Not enough inventory space for potions.");501
const inserted = insertStack(inventory.slots, attachOrigins({502
itemId: outputItemId,503
quantity: outQty,504
origins: [{ origin, quantity: outQty }]505
}), outDef);506
if (!inserted.ok)507
{508
refundStacks(inventory, consumed);509
if (takeBottles)510
{ refundStacks(inventory, [takeBottles.taken]); }511
throw userError("Not enough inventory space for the brew.");512
}513
inventory.slots = inserted.slots;514
alchemyPotionView = {515
potionKey: evaluation.result.potionKey,516
displayName: evaluation.result.displayName,517
unstable: false,518
color: evaluation.result.color,519
fillLevel: null520
};521
}522
else523
{524
const instance = potionItemInstance(evaluation.result);525
const potionDef = itemDefinition(ItemId.potion);526
const inserted = insertStack(inventory.slots, attachOrigins({527
itemId: ItemId.potion,528
quantity: produced,529
instance,530
origins: [{ origin, quantity: produced }]531
}), potionDef);532
if (!inserted.ok)533
{534
refundStacks(inventory, consumed);535
if (takeBottles)536
{ refundStacks(inventory, [takeBottles.taken]); }537
throw userError("Not enough inventory space for potions.");538
}539
inventory.slots = inserted.slots;540
alchemyPotionView = {541
potionKey: instance.potionKey,542
displayName: instance.displayName,543
unstable: instance.unstable,544
color: instance.color,545
fillLevel: instance.fillLevel546
};431
}547
}432
inventory.slots = inserted.slots;433
548
434
session.lastSuccessRecipe = evaluation.success ? evaluation.recipe : null;549
session.lastSuccessRecipe = evaluation.success ? evaluation.recipe : null;435
clearAlchemy(session);550
clearAlchemy(session);436
551
437
const events = [];552
const events = [];553
let returnedBottles = 0;554
for (const row of consumed)555
{556
if ((row.itemId | 0) === ItemId.potion)557
{ returnedBottles += stackQuantity(row.quantity); }558
}559
grantEmptyGlassBottles(world, handle, command.characterId, returnedBottles, events);560
438
if (evaluation.success && skills?.xp)561
if (evaluation.success && skills?.xp)439
{562
{440
const xpInputs = (consumed ?? []).map((row) => ({563
const xpInputs = (consumed ?? []).map((row) => ({@@ -475,13 +598,7 @@ function bottle (world, sessionId, command)475
produced,598
produced,476
wanted,599
wanted,477
lost: Math.max(0, wanted - produced),600
lost: Math.max(0, wanted - produced),478
potion: {601
potion: alchemyPotionView479
potionKey: instance.potionKey,480
displayName: instance.displayName,481
unstable: instance.unstable,482
color: instance.color,483
fillLevel: instance.fillLevel484
}485
}602
}486
};603
};487
}604
}@@ -0,0 +1,162 @@
1
import { Component } from "../ecs/components.js";
2
import {
3
barkItemIdForWood,
4
debarkedLogInstance,
5
isLogDebarked
6
} from "../../../shared/definitions/woodItems.js";
7
import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";
8
import { itemDefinition } from "../../../shared/definitions/items.js";
9
import { resolveWoodcuttingAxe } from "../../../shared/definitions/gathering.js";
10
import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";
11
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
12
import { attachOrigins, craftOrigin, CraftOriginVerb } from "../../../shared/items/origin.js";
13
import { stackQuantity } from "../../../shared/items/inventory.js";
14
15
function userError (message)
16
{
17
const error = new Error(message);
18
error.userFacing = true;
19
return error;
20
}
21
22
function characterDisplayName (world, handle)
23
{
24
const appearance = world.ecs.get(handle, Component.appearance);
25
const name = [appearance?.firstName, appearance?.lastName].filter(Boolean).join(" ").trim();
26
return name || "someone";
27
}
28
29
function woodTierFromLogItemId (itemId)
30
{
31
const def = itemDefinition(itemId);
32
if (!def || def.familyId !== ItemFamilyId.log)
33
{ return null; }
34
return def.tier ?? null;
35
}
36
37
function axeForWood (world, handle, woodTier)
38
{
39
const inventory = world.ecs.get(handle, Component.inventory);
40
const equipment = world.ecs.get(handle, Component.equipment);
41
const skills = world.ecs.get(handle, Component.skills);
42
return resolveWoodcuttingAxe({
43
inventorySlots: inventory?.slots,
44
equipmentSlots: equipment?.slots,
45
skills,
46
woodTier
47
});
48
}
49
50
function publishGround (item)
51
{
52
return {
53
type: "ground-item-appear",
54
...publicGroundItem(item),
55
stack: item.stack,
56
droppedAt: item.droppedAt,
57
source: item.source,
58
droppedByCharacterId: item.droppedByCharacterId,
59
expiresAt: item.expiresAt
60
};
61
}
62
63
/**
64
* Strip bark from a ground wood log. Requires an axe of the same tier gate as chopping
65
* that wood. Leaves a debarked log (same itemId + instance flag) and bark.
66
*/
67
export function debarkLog (world, sessionId, characterId, groundItemId, now = Date.now())
68
{
69
const { handle } = world.requireOwnedEntity(sessionId, characterId);
70
const item = world.groundItems.get(groundItemId);
71
if (!item?.stack)
72
{ throw userError("That item is no longer on the ground."); }
73
74
const woodTier = woodTierFromLogItemId(item.stack.itemId);
75
if (!woodTier)
76
{ throw userError("That is not a log."); }
77
if (isLogDebarked(item.stack))
78
{ throw userError("That log is already stripped of bark."); }
79
80
const position = world.ecs.get(handle, Component.position);
81
if (!isAdjacentTile(position.tileX, position.tileY, item.tileX, item.tileY)
82
&& !(position.tileX === item.tileX && position.tileY === item.tileY))
83
{ throw userError("Stand next to the log."); }
84
85
const axe = axeForWood(world, handle, woodTier);
86
if (!axe.ok)
87
{ throw userError(axe.reason || "You need an axe to strip this bark."); }
88
89
const barkId = barkItemIdForWood(woodTier);
90
if (barkId == null)
91
{ throw userError("That bark cannot be stripped."); }
92
93
const qty = stackQuantity(item.stack.quantity);
94
if (qty <= 0)
95
{ throw userError("That item is no longer on the ground."); }
96
97
const events = [];
98
const despawnMs = world.settings.groundItemDespawnDurationMs ?? 600_000;
99
const origin = craftOrigin(CraftOriginVerb.made, characterDisplayName(world, handle));
100
const debarkedStack = attachOrigins({
101
itemId: item.stack.itemId,
102
quantity: 1,
103
instance: debarkedLogInstance(),
104
origins: item.stack.origins ?? []
105
});
106
107
if (qty === 1)
108
{
109
item.stack = debarkedStack;
110
events.push(publishGround(item));
111
}
112
else
113
{
114
item.stack = {
115
...item.stack,
116
quantity: qty - 1
117
};
118
events.push(publishGround(item));
119
120
const debarkedItem = {
121
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),
122
tileX: item.tileX,
123
tileY: item.tileY,
124
stack: debarkedStack,
125
droppedAt: now,
126
expiresAt: now + despawnMs,
127
source: "debark",
128
droppedByCharacterId: characterId
129
};
130
addGroundItem(world, debarkedItem);
131
events.push(publishGround(debarkedItem));
132
}
133
134
const barkItem = {
135
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),
136
tileX: item.tileX,
137
tileY: item.tileY,
138
stack: attachOrigins({
139
itemId: barkId,
140
quantity: 1,
141
origins: [{ origin, quantity: 1 }]
142
}),
143
droppedAt: now,
144
expiresAt: now + despawnMs,
145
source: "debark",
146
droppedByCharacterId: characterId
147
};
148
addGroundItem(world, barkItem);
149
events.push(publishGround(barkItem));
150
151
return {
152
events,
153
private: bagView(world.ecs, handle)
154
};
155
}
156
157
export function handleDebarkCommand (world, sessionId, command, now = Date.now())
158
{
159
if (command.type !== "debark-log")
160
{ return null; }
161
return debarkLog(world, sessionId, command.characterId, command.groundItemId, now);
162
}
@@ -0,0 +1,162 @@1
import { Component } from "../ecs/components.js";2
import {3
barkItemIdForWood,4
debarkedLogInstance,5
isLogDebarked6
} from "../../../shared/definitions/woodItems.js";7
import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";8
import { itemDefinition } from "../../../shared/definitions/items.js";9
import { resolveWoodcuttingAxe } from "../../../shared/definitions/gathering.js";10
import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";11
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";12
import { attachOrigins, craftOrigin, CraftOriginVerb } from "../../../shared/items/origin.js";13
import { stackQuantity } from "../../../shared/items/inventory.js";14
15
function userError (message)16
{17
const error = new Error(message);18
error.userFacing = true;19
return error;20
}21
22
function characterDisplayName (world, handle)23
{24
const appearance = world.ecs.get(handle, Component.appearance);25
const name = [appearance?.firstName, appearance?.lastName].filter(Boolean).join(" ").trim();26
return name || "someone";27
}28
29
function woodTierFromLogItemId (itemId)30
{31
const def = itemDefinition(itemId);32
if (!def || def.familyId !== ItemFamilyId.log)33
{ return null; }34
return def.tier ?? null;35
}36
37
function axeForWood (world, handle, woodTier)38
{39
const inventory = world.ecs.get(handle, Component.inventory);40
const equipment = world.ecs.get(handle, Component.equipment);41
const skills = world.ecs.get(handle, Component.skills);42
return resolveWoodcuttingAxe({43
inventorySlots: inventory?.slots,44
equipmentSlots: equipment?.slots,45
skills,46
woodTier47
});48
}49
50
function publishGround (item)51
{52
return {53
type: "ground-item-appear",54
...publicGroundItem(item),55
stack: item.stack,56
droppedAt: item.droppedAt,57
source: item.source,58
droppedByCharacterId: item.droppedByCharacterId,59
expiresAt: item.expiresAt60
};61
}62
63
/**64
* Strip bark from a ground wood log. Requires an axe of the same tier gate as chopping65
* that wood. Leaves a debarked log (same itemId + instance flag) and bark.66
*/67
export function debarkLog (world, sessionId, characterId, groundItemId, now = Date.now())68
{69
const { handle } = world.requireOwnedEntity(sessionId, characterId);70
const item = world.groundItems.get(groundItemId);71
if (!item?.stack)72
{ throw userError("That item is no longer on the ground."); }73
74
const woodTier = woodTierFromLogItemId(item.stack.itemId);75
if (!woodTier)76
{ throw userError("That is not a log."); }77
if (isLogDebarked(item.stack))78
{ throw userError("That log is already stripped of bark."); }79
80
const position = world.ecs.get(handle, Component.position);81
if (!isAdjacentTile(position.tileX, position.tileY, item.tileX, item.tileY)82
&& !(position.tileX === item.tileX && position.tileY === item.tileY))83
{ throw userError("Stand next to the log."); }84
85
const axe = axeForWood(world, handle, woodTier);86
if (!axe.ok)87
{ throw userError(axe.reason || "You need an axe to strip this bark."); }88
89
const barkId = barkItemIdForWood(woodTier);90
if (barkId == null)91
{ throw userError("That bark cannot be stripped."); }92
93
const qty = stackQuantity(item.stack.quantity);94
if (qty <= 0)95
{ throw userError("That item is no longer on the ground."); }96
97
const events = [];98
const despawnMs = world.settings.groundItemDespawnDurationMs ?? 600_000;99
const origin = craftOrigin(CraftOriginVerb.made, characterDisplayName(world, handle));100
const debarkedStack = attachOrigins({101
itemId: item.stack.itemId,102
quantity: 1,103
instance: debarkedLogInstance(),104
origins: item.stack.origins ?? []105
});106
107
if (qty === 1)108
{109
item.stack = debarkedStack;110
events.push(publishGround(item));111
}112
else113
{114
item.stack = {115
...item.stack,116
quantity: qty - 1117
};118
events.push(publishGround(item));119
120
const debarkedItem = {121
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),122
tileX: item.tileX,123
tileY: item.tileY,124
stack: debarkedStack,125
droppedAt: now,126
expiresAt: now + despawnMs,127
source: "debark",128
droppedByCharacterId: characterId129
};130
addGroundItem(world, debarkedItem);131
events.push(publishGround(debarkedItem));132
}133
134
const barkItem = {135
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),136
tileX: item.tileX,137
tileY: item.tileY,138
stack: attachOrigins({139
itemId: barkId,140
quantity: 1,141
origins: [{ origin, quantity: 1 }]142
}),143
droppedAt: now,144
expiresAt: now + despawnMs,145
source: "debark",146
droppedByCharacterId: characterId147
};148
addGroundItem(world, barkItem);149
events.push(publishGround(barkItem));150
151
return {152
events,153
private: bagView(world.ecs, handle)154
};155
}156
157
export function handleDebarkCommand (world, sessionId, command, now = Date.now())158
{159
if (command.type !== "debark-log")160
{ return null; }161
return debarkLog(world, sessionId, command.characterId, command.groundItemId, now);162
}@@ -452,6 +452,14 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
452
452
groundItemId: message.groundItemId | 0
453
453
});
454
454
break;
455
case MessageType.debarkLog:
456
requirePlaying(session);
457
simulation.enqueue(session.id, {
458
type: "debark-log",
459
characterId: session.characterId,
460
groundItemId: message.groundItemId | 0
461
});
462
break;
455
463
case MessageType.shear:
456
464
requirePlaying(session);
457
465
simulation.enqueue(session.id, {
@@ -452,6 +452,14 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,452
groundItemId: message.groundItemId | 0452
groundItemId: message.groundItemId | 0453
});453
});454
break;454
break;455
case MessageType.debarkLog:456
requirePlaying(session);457
simulation.enqueue(session.id, {458
type: "debark-log",459
characterId: session.characterId,460
groundItemId: message.groundItemId | 0461
});462
break;455
case MessageType.shear:463
case MessageType.shear:456
requirePlaying(session);464
requirePlaying(session);457
simulation.enqueue(session.id, {465
simulation.enqueue(session.id, {@@ -58,7 +58,12 @@ export function publicGroundItem (item)
58
58
quantity: item.stack.quantity,
59
59
displayName: itemDisplayName(item.stack),
60
60
sprite: itemSpriteNameForStack(item.stack),
61
instance: instance && (instance.kind === "potion" || instance.kind === "letter" || instance.kind === "recipe-paper")
61
instance: instance && (
62
instance.kind === "potion"
63
|| instance.kind === "letter"
64
|| instance.kind === "recipe-paper"
65
|| instance.kind === "log"
66
)
62
67
? instance
63
68
: null,
64
69
expiresAt: item.expiresAt,
@@ -668,6 +673,8 @@ function applyPotionEffect (ecs, handle, effect)
668
673
669
674
const timed = {
670
675
[StatusEffectType.healthRegen]: true,
676
[StatusEffectType.healthDrain]: true,
677
[StatusEffectType.foodPoisoning]: true,
671
678
[StatusEffectType.staminaRegen]: true,
672
679
[StatusEffectType.strengthBonus]: true,
673
680
[StatusEffectType.mindBonus]: true,
@@ -58,7 +58,12 @@ export function publicGroundItem (item)58
quantity: item.stack.quantity,58
quantity: item.stack.quantity,59
displayName: itemDisplayName(item.stack),59
displayName: itemDisplayName(item.stack),60
sprite: itemSpriteNameForStack(item.stack),60
sprite: itemSpriteNameForStack(item.stack),61
instance: instance && (instance.kind === "potion" || instance.kind === "letter" || instance.kind === "recipe-paper")61
instance: instance && (62
instance.kind === "potion"63
|| instance.kind === "letter"64
|| instance.kind === "recipe-paper"65
|| instance.kind === "log"66
)62
? instance67
? instance63
: null,68
: null,64
expiresAt: item.expiresAt,69
expiresAt: item.expiresAt,@@ -668,6 +673,8 @@ function applyPotionEffect (ecs, handle, effect)668
673
669
const timed = {674
const timed = {670
[StatusEffectType.healthRegen]: true,675
[StatusEffectType.healthRegen]: true,676
[StatusEffectType.healthDrain]: true,677
[StatusEffectType.foodPoisoning]: true,671
[StatusEffectType.staminaRegen]: true,678
[StatusEffectType.staminaRegen]: true,672
[StatusEffectType.strengthBonus]: true,679
[StatusEffectType.strengthBonus]: true,673
[StatusEffectType.mindBonus]: true,680
[StatusEffectType.mindBonus]: true,@@ -53,6 +53,7 @@ import {
53
53
} from "../gathering/service.js";
54
54
import { handleCraftCommand, stepCrafting } from "../crafting/service.js";
55
55
import { handleFirestartingCommand, stepFirestarting } from "../firestarting/service.js";
56
import { handleDebarkCommand } from "../debark/service.js";
56
57
import { handleFishingCommand, stepFishing } from "../fishing/service.js";
57
58
import { handleShearingCommand, stepShearing, originIsBusyPinned } from "../shearing/service.js";
58
59
import { handleAlchemyCommand } from "../alchemy/service.js";
@@ -538,6 +539,9 @@ export class WorkerWorld
538
539
const fire = handleFirestartingCommand(this, sessionId, command, message.now ?? Date.now());
539
540
if (fire)
540
541
{ return fire; }
542
const debark = handleDebarkCommand(this, sessionId, command, message.now ?? Date.now());
543
if (debark)
544
{ return debark; }
541
545
const fishing = handleFishingCommand(this, sessionId, command, message.now ?? Date.now());
542
546
if (fishing)
543
547
{ return fishing; }
@@ -53,6 +53,7 @@ import {53
} from "../gathering/service.js";53
} from "../gathering/service.js";54
import { handleCraftCommand, stepCrafting } from "../crafting/service.js";54
import { handleCraftCommand, stepCrafting } from "../crafting/service.js";55
import { handleFirestartingCommand, stepFirestarting } from "../firestarting/service.js";55
import { handleFirestartingCommand, stepFirestarting } from "../firestarting/service.js";56
import { handleDebarkCommand } from "../debark/service.js";56
import { handleFishingCommand, stepFishing } from "../fishing/service.js";57
import { handleFishingCommand, stepFishing } from "../fishing/service.js";57
import { handleShearingCommand, stepShearing, originIsBusyPinned } from "../shearing/service.js";58
import { handleShearingCommand, stepShearing, originIsBusyPinned } from "../shearing/service.js";58
import { handleAlchemyCommand } from "../alchemy/service.js";59
import { handleAlchemyCommand } from "../alchemy/service.js";@@ -538,6 +539,9 @@ export class WorkerWorld538
const fire = handleFirestartingCommand(this, sessionId, command, message.now ?? Date.now());539
const fire = handleFirestartingCommand(this, sessionId, command, message.now ?? Date.now());539
if (fire)540
if (fire)540
{ return fire; }541
{ return fire; }542
const debark = handleDebarkCommand(this, sessionId, command, message.now ?? Date.now());543
if (debark)544
{ return debark; }541
const fishing = handleFishingCommand(this, sessionId, command, message.now ?? Date.now());545
const fishing = handleFishingCommand(this, sessionId, command, message.now ?? Date.now());542
if (fishing)546
if (fishing)543
{ return fishing; }547
{ return fishing; }@@ -61,6 +61,17 @@ export function stepStatusEffects (world, now = Date.now(), dt = 1 / 20)
61
61
healthChanged = true;
62
62
}
63
63
}
64
if (entry.type === StatusEffectType.foodPoisoning && health)
65
{
66
const beforeInt = health.current | 0;
67
const next = Math.max(0, (Number(health.current) || 0) - rate * dt);
68
health.current = next;
69
if ((next | 0) !== beforeInt)
70
{
71
markHealthDamaged(health, now);
72
healthChanged = true;
73
}
74
}
64
75
if (entry.type === StatusEffectType.staminaRegen && stamina)
65
76
{
66
77
const before = Number(stamina.current) || 0;
@@ -61,6 +61,17 @@ export function stepStatusEffects (world, now = Date.now(), dt = 1 / 20)61
healthChanged = true;61
healthChanged = true;62
}62
}63
}63
}64
if (entry.type === StatusEffectType.foodPoisoning && health)65
{66
const beforeInt = health.current | 0;67
const next = Math.max(0, (Number(health.current) || 0) - rate * dt);68
health.current = next;69
if ((next | 0) !== beforeInt)70
{71
markHealthDamaged(health, now);72
healthChanged = true;73
}74
}64
if (entry.type === StatusEffectType.staminaRegen && stamina)75
if (entry.type === StatusEffectType.staminaRegen && stamina)65
{76
{66
const before = Number(stamina.current) || 0;77
const before = Number(stamina.current) || 0;@@ -0,0 +1,272 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { BlockType } from "../../shared/definitions/tiles.js";
4
import { ItemId, itemDefinition, itemDisplayName, itemSpriteNameForStack } from "../../shared/definitions/items.js";
5
import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
6
import {
7
WoodItemId,
8
debarkedLogInstance,
9
isLogDebarked,
10
barkItemIdForWood
11
} from "../../shared/definitions/woodItems.js";
12
import { WoodTier, GatherMaterialId, MaterialTier, oreBoulderState } from "../../shared/definitions/materialTiers.js";
13
import { SkillId } from "../../shared/definitions/skills.js";
14
import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
15
import { AlchemyStepKind } from "../../shared/definitions/alchemy.js";
16
import { canMineMaterial, oreItemIdForMaterial } from "../../shared/definitions/gathering.js";
17
import {
18
clearResolvedAlchemyPotionsCache,
19
resolvedAlchemyPotions,
20
evaluateAlchemyBottle,
21
potionItemInstance
22
} from "../../shared/alchemy/recipes.js";
23
import { StatusEffectType } from "../../shared/statusEffects/rules.js";
24
import { isFullPotionBottle } from "../../shared/items/charges.js";
25
import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js";
26
import { totalXpForLevel } from "../../shared/skills/progression.js";
27
import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
28
import { addGroundItem } from "../src/items/bags.js";
29
import { Component } from "../src/ecs/components.js";
30
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
31
32
function placeCauldron (worldDb, tileX, tileY)
33
{
34
const chunkX = Math.floor(tileX / 16);
35
const chunkY = Math.floor(tileY / 16);
36
const data = createEmptyChunkData();
37
data.open = true;
38
const localX = tileX - chunkX * 16;
39
const localY = tileY - chunkY * 16;
40
data.blocks[localY * 16 + localX] = { typeId: BlockType.cauldron, state: 0 };
41
worldDb.saveChunkVersion(
42
chunkX,
43
chunkY,
44
worldDb.getActiveRevisionId(),
45
true,
46
encodeChunkBlob(data)
47
);
48
}
49
50
function countItem (slots, itemId)
51
{
52
return (slots ?? [])
53
.filter((slot) => slot?.itemId === itemId)
54
.reduce((sum, slot) => sum + (slot.quantity | 0), 0);
55
}
56
57
function setSkillLevel (harness, characterId, skillId, level)
58
{
59
const skills = harness.stateDb.getSkills(characterId);
60
skills.xp[skillId] = totalXpForLevel(level);
61
harness.stateDb.saveSkills(characterId, skills);
62
}
63
64
test("rock salt mines with bronze pick and uses salt-ore boulder state", () =>
65
{
66
assert.equal(oreBoulderState(GatherMaterialId.salt), "salt-ore");
67
assert.equal(oreItemIdForMaterial(GatherMaterialId.salt), CraftingItemId.salt);
68
assert.equal(canMineMaterial(1, MaterialTier.bronze, GatherMaterialId.salt).ok, true);
69
const def = itemDefinition(CraftingItemId.salt);
70
assert.equal(def.key, "rock-salt");
71
assert.equal(def.iconKey, "ash");
72
assert.equal(def.tier, GatherMaterialId.salt);
73
});
74
75
test("debarked logs keep oak itemId but change name and sprite", () =>
76
{
77
const plain = { itemId: WoodItemId.oakLog, quantity: 1 };
78
const stripped = { itemId: WoodItemId.oakLog, quantity: 1, instance: debarkedLogInstance() };
79
assert.equal(isLogDebarked(plain), false);
80
assert.equal(isLogDebarked(stripped), true);
81
assert.equal(itemDisplayName(plain), "Oak log");
82
assert.equal(itemDisplayName(stripped), "Debarked Oak log");
83
assert.match(itemSpriteNameForStack(stripped), /log-debarked/);
84
assert.equal(barkItemIdForWood(WoodTier.oak), WoodItemId.oakBark);
85
});
86
87
test("debark-log on ground oak log yields bark and debarked flag", () =>
88
{
89
const harness = makeSimulation({ workerCount: 1 });
90
try
91
{
92
harness.simulation.reloadWorld();
93
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
94
setSkillLevel(harness, character.character_id, SkillId.woodcutting, 20);
95
const inventory = emptySlots();
96
inventory[0] = { itemId: ItemId.ironAxe, quantity: 1 };
97
harness.stateDb.saveBag(character.character_id, {
98
inventory,
99
equipment: emptyEquipment(),
100
vault: [],
101
vaultReserved: []
102
});
103
const entityId = harness.simulation.spawnCharacter(1, character);
104
const record = harness.simulation.entityRecord(entityId);
105
const worker = harness.simulation.workers[record.workerId];
106
107
const groundItemId = (worker.world.nextGroundItemId = (worker.world.nextGroundItemId ?? 1) + 1);
108
addGroundItem(worker.world, {
109
groundItemId,
110
tileX: 8,
111
tileY: 9,
112
stack: { itemId: WoodItemId.oakLog, quantity: 1 },
113
droppedAt: Date.now(),
114
expiresAt: Date.now() + 600_000,
115
source: "test"
116
});
117
118
harness.simulation.enqueue(1, {
119
type: "debark-log",
120
characterId: character.character_id,
121
groundItemId
122
});
123
harness.simulation.step();
124
125
const item = worker.world.groundItems.get(groundItemId);
126
assert.ok(item);
127
assert.equal(isLogDebarked(item.stack), true);
128
assert.equal(item.stack.itemId, WoodItemId.oakLog);
129
130
const bark = [...worker.world.groundItems.values()]
131
.find((row) => row.stack?.itemId === WoodItemId.oakBark);
132
assert.ok(bark);
133
assert.equal(bark.stack.quantity, 1);
134
}
135
finally
136
{ harness.close(); }
137
});
138
139
test("animal fat and tanning brew alchemy recipes resolve", () =>
140
{
141
clearResolvedAlchemyPotionsCache();
142
const potions = resolvedAlchemyPotions();
143
const fat = potions.find((row) => row.potionKey === "animalFat");
144
const tan = potions.find((row) => row.potionKey === "tanningBrew");
145
assert.ok(fat);
146
assert.equal(fat.effect?.type, StatusEffectType.foodPoisoning);
147
assert.ok(tan);
148
assert.equal(tan.outputItemId, LeatherItemId.tanningBrew);
149
assert.equal(tan.requiresEmptyBottles, false);
150
151
const fatEval = evaluateAlchemyBottle({
152
skills: { levels: { [SkillId.alchemy]: 1 } },
153
brewStacks: [{ itemId: CraftingItemId.rawMeat, quantity: 1 }],
154
takenSteps: fat.steps
155
});
156
assert.equal(fatEval.success, true);
157
assert.equal(fatEval.result.potionKey, "animalFat");
158
159
const fatBottle = potionItemInstance(fatEval.result);
160
assert.equal(isFullPotionBottle({ itemId: ItemId.potion, instance: fatBottle }), true);
161
162
const tanEval = evaluateAlchemyBottle({
163
skills: { levels: { [SkillId.alchemy]: 10 } },
164
brewStacks: [
165
{ itemId: WoodItemId.oakBark, quantity: 2 },
166
{ itemId: CraftingItemId.salt, quantity: 1 },
167
{ itemId: ItemId.potion, quantity: 1, instance: fatBottle }
168
],
169
takenSteps: tan.steps
170
});
171
assert.equal(tanEval.success, true);
172
assert.equal(tanEval.result.outputItemId, LeatherItemId.tanningBrew);
173
});
174
175
test("cauldron bottles animal fat then tanning brew returns the empty bottle", () =>
176
{
177
const harness = makeSimulation({ workerCount: 1 });
178
try
179
{
180
placeCauldron(harness.worldDb, 8, 8);
181
harness.simulation.reloadWorld();
182
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 9 });
183
setSkillLevel(harness, character.character_id, SkillId.alchemy, 10);
184
const inventory = emptySlots();
185
inventory[0] = { itemId: CraftingItemId.rawMeat, quantity: 1 };
186
inventory[1] = { itemId: ItemId.glassBottle, quantity: 1 };
187
inventory[2] = { itemId: WoodItemId.oakBark, quantity: 2 };
188
inventory[3] = { itemId: CraftingItemId.salt, quantity: 1 };
189
harness.stateDb.saveBag(character.character_id, {
190
inventory,
191
equipment: emptyEquipment(),
192
vault: [],
193
vaultReserved: []
194
});
195
const entityId = harness.simulation.spawnCharacter(1, character);
196
const cid = character.character_id;
197
198
harness.simulation.enqueue(1, { type: "open-cauldron", characterId: cid });
199
harness.simulation.step();
200
harness.simulation.enqueue(1, {
201
type: "cauldron-insert",
202
characterId: cid,
203
itemId: CraftingItemId.rawMeat,
204
quantity: 1
205
});
206
for (const action of [AlchemyStepKind.heat, AlchemyStepKind.stir, AlchemyStepKind.cool])
207
{
208
harness.simulation.enqueue(1, {
209
type: "cauldron-action",
210
characterId: cid,
211
action
212
});
213
}
214
harness.simulation.enqueue(1, { type: "cauldron-bottle", characterId: cid });
215
harness.simulation.step();
216
217
let bag = harness.simulation.bagOf(entityId);
218
assert.equal(countItem(bag.inventory, CraftingItemId.rawMeat), 0);
219
assert.equal(countItem(bag.inventory, ItemId.potion), 1);
220
const fatSlot = bag.inventory.find((slot) => slot?.itemId === ItemId.potion);
221
assert.equal(fatSlot.instance.potionKey, "animalFat");
222
assert.equal(countItem(bag.inventory, ItemId.glassBottle), 0);
223
224
harness.simulation.enqueue(1, { type: "cauldron-clear", characterId: cid });
225
harness.simulation.step();
226
harness.simulation.enqueue(1, {
227
type: "cauldron-insert",
228
characterId: cid,
229
itemId: WoodItemId.oakBark,
230
quantity: 2
231
});
232
harness.simulation.enqueue(1, {
233
type: "cauldron-action",
234
characterId: cid,
235
action: AlchemyStepKind.heat
236
});
237
harness.simulation.enqueue(1, {
238
type: "cauldron-insert",
239
characterId: cid,
240
itemId: CraftingItemId.salt,
241
quantity: 1
242
});
243
harness.simulation.enqueue(1, {
244
type: "cauldron-action",
245
characterId: cid,
246
action: AlchemyStepKind.stir
247
});
248
harness.simulation.enqueue(1, {
249
type: "cauldron-insert",
250
characterId: cid,
251
itemId: ItemId.potion,
252
quantity: 1,
253
instance: structuredClone(fatSlot.instance)
254
});
255
harness.simulation.enqueue(1, {
256
type: "cauldron-action",
257
characterId: cid,
258
action: AlchemyStepKind.cool
259
});
260
harness.simulation.enqueue(1, { type: "cauldron-bottle", characterId: cid });
261
harness.simulation.step();
262
263
bag = harness.simulation.bagOf(entityId);
264
assert.equal(countItem(bag.inventory, LeatherItemId.tanningBrew), 1);
265
assert.equal(countItem(bag.inventory, ItemId.potion), 0);
266
assert.equal(countItem(bag.inventory, ItemId.glassBottle), 1);
267
assert.equal(countItem(bag.inventory, WoodItemId.oakBark), 0);
268
assert.equal(countItem(bag.inventory, CraftingItemId.salt), 0);
269
}
270
finally
271
{ harness.close(); }
272
});
@@ -0,0 +1,272 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { BlockType } from "../../shared/definitions/tiles.js";4
import { ItemId, itemDefinition, itemDisplayName, itemSpriteNameForStack } from "../../shared/definitions/items.js";5
import { CraftingItemId } from "../../shared/definitions/craftingItems.js";6
import {7
WoodItemId,8
debarkedLogInstance,9
isLogDebarked,10
barkItemIdForWood11
} from "../../shared/definitions/woodItems.js";12
import { WoodTier, GatherMaterialId, MaterialTier, oreBoulderState } from "../../shared/definitions/materialTiers.js";13
import { SkillId } from "../../shared/definitions/skills.js";14
import { LeatherItemId } from "../../shared/definitions/leatherItems.js";15
import { AlchemyStepKind } from "../../shared/definitions/alchemy.js";16
import { canMineMaterial, oreItemIdForMaterial } from "../../shared/definitions/gathering.js";17
import {18
clearResolvedAlchemyPotionsCache,19
resolvedAlchemyPotions,20
evaluateAlchemyBottle,21
potionItemInstance22
} from "../../shared/alchemy/recipes.js";23
import { StatusEffectType } from "../../shared/statusEffects/rules.js";24
import { isFullPotionBottle } from "../../shared/items/charges.js";25
import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js";26
import { totalXpForLevel } from "../../shared/skills/progression.js";27
import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";28
import { addGroundItem } from "../src/items/bags.js";29
import { Component } from "../src/ecs/components.js";30
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";31
32
function placeCauldron (worldDb, tileX, tileY)33
{34
const chunkX = Math.floor(tileX / 16);35
const chunkY = Math.floor(tileY / 16);36
const data = createEmptyChunkData();37
data.open = true;38
const localX = tileX - chunkX * 16;39
const localY = tileY - chunkY * 16;40
data.blocks[localY * 16 + localX] = { typeId: BlockType.cauldron, state: 0 };41
worldDb.saveChunkVersion(42
chunkX,43
chunkY,44
worldDb.getActiveRevisionId(),45
true,46
encodeChunkBlob(data)47
);48
}49
50
function countItem (slots, itemId)51
{52
return (slots ?? [])53
.filter((slot) => slot?.itemId === itemId)54
.reduce((sum, slot) => sum + (slot.quantity | 0), 0);55
}56
57
function setSkillLevel (harness, characterId, skillId, level)58
{59
const skills = harness.stateDb.getSkills(characterId);60
skills.xp[skillId] = totalXpForLevel(level);61
harness.stateDb.saveSkills(characterId, skills);62
}63
64
test("rock salt mines with bronze pick and uses salt-ore boulder state", () =>65
{66
assert.equal(oreBoulderState(GatherMaterialId.salt), "salt-ore");67
assert.equal(oreItemIdForMaterial(GatherMaterialId.salt), CraftingItemId.salt);68
assert.equal(canMineMaterial(1, MaterialTier.bronze, GatherMaterialId.salt).ok, true);69
const def = itemDefinition(CraftingItemId.salt);70
assert.equal(def.key, "rock-salt");71
assert.equal(def.iconKey, "ash");72
assert.equal(def.tier, GatherMaterialId.salt);73
});74
75
test("debarked logs keep oak itemId but change name and sprite", () =>76
{77
const plain = { itemId: WoodItemId.oakLog, quantity: 1 };78
const stripped = { itemId: WoodItemId.oakLog, quantity: 1, instance: debarkedLogInstance() };79
assert.equal(isLogDebarked(plain), false);80
assert.equal(isLogDebarked(stripped), true);81
assert.equal(itemDisplayName(plain), "Oak log");82
assert.equal(itemDisplayName(stripped), "Debarked Oak log");83
assert.match(itemSpriteNameForStack(stripped), /log-debarked/);84
assert.equal(barkItemIdForWood(WoodTier.oak), WoodItemId.oakBark);85
});86
87
test("debark-log on ground oak log yields bark and debarked flag", () =>88
{89
const harness = makeSimulation({ workerCount: 1 });90
try91
{92
harness.simulation.reloadWorld();93
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });94
setSkillLevel(harness, character.character_id, SkillId.woodcutting, 20);95
const inventory = emptySlots();96
inventory[0] = { itemId: ItemId.ironAxe, quantity: 1 };97
harness.stateDb.saveBag(character.character_id, {98
inventory,99
equipment: emptyEquipment(),100
vault: [],101
vaultReserved: []102
});103
const entityId = harness.simulation.spawnCharacter(1, character);104
const record = harness.simulation.entityRecord(entityId);105
const worker = harness.simulation.workers[record.workerId];106
107
const groundItemId = (worker.world.nextGroundItemId = (worker.world.nextGroundItemId ?? 1) + 1);108
addGroundItem(worker.world, {109
groundItemId,110
tileX: 8,111
tileY: 9,112
stack: { itemId: WoodItemId.oakLog, quantity: 1 },113
droppedAt: Date.now(),114
expiresAt: Date.now() + 600_000,115
source: "test"116
});117
118
harness.simulation.enqueue(1, {119
type: "debark-log",120
characterId: character.character_id,121
groundItemId122
});123
harness.simulation.step();124
125
const item = worker.world.groundItems.get(groundItemId);126
assert.ok(item);127
assert.equal(isLogDebarked(item.stack), true);128
assert.equal(item.stack.itemId, WoodItemId.oakLog);129
130
const bark = [...worker.world.groundItems.values()]131
.find((row) => row.stack?.itemId === WoodItemId.oakBark);132
assert.ok(bark);133
assert.equal(bark.stack.quantity, 1);134
}135
finally136
{ harness.close(); }137
});138
139
test("animal fat and tanning brew alchemy recipes resolve", () =>140
{141
clearResolvedAlchemyPotionsCache();142
const potions = resolvedAlchemyPotions();143
const fat = potions.find((row) => row.potionKey === "animalFat");144
const tan = potions.find((row) => row.potionKey === "tanningBrew");145
assert.ok(fat);146
assert.equal(fat.effect?.type, StatusEffectType.foodPoisoning);147
assert.ok(tan);148
assert.equal(tan.outputItemId, LeatherItemId.tanningBrew);149
assert.equal(tan.requiresEmptyBottles, false);150
151
const fatEval = evaluateAlchemyBottle({152
skills: { levels: { [SkillId.alchemy]: 1 } },153
brewStacks: [{ itemId: CraftingItemId.rawMeat, quantity: 1 }],154
takenSteps: fat.steps155
});156
assert.equal(fatEval.success, true);157
assert.equal(fatEval.result.potionKey, "animalFat");158
159
const fatBottle = potionItemInstance(fatEval.result);160
assert.equal(isFullPotionBottle({ itemId: ItemId.potion, instance: fatBottle }), true);161
162
const tanEval = evaluateAlchemyBottle({163
skills: { levels: { [SkillId.alchemy]: 10 } },164
brewStacks: [165
{ itemId: WoodItemId.oakBark, quantity: 2 },166
{ itemId: CraftingItemId.salt, quantity: 1 },167
{ itemId: ItemId.potion, quantity: 1, instance: fatBottle }168
],169
takenSteps: tan.steps170
});171
assert.equal(tanEval.success, true);172
assert.equal(tanEval.result.outputItemId, LeatherItemId.tanningBrew);173
});174
175
test("cauldron bottles animal fat then tanning brew returns the empty bottle", () =>176
{177
const harness = makeSimulation({ workerCount: 1 });178
try179
{180
placeCauldron(harness.worldDb, 8, 8);181
harness.simulation.reloadWorld();182
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 9 });183
setSkillLevel(harness, character.character_id, SkillId.alchemy, 10);184
const inventory = emptySlots();185
inventory[0] = { itemId: CraftingItemId.rawMeat, quantity: 1 };186
inventory[1] = { itemId: ItemId.glassBottle, quantity: 1 };187
inventory[2] = { itemId: WoodItemId.oakBark, quantity: 2 };188
inventory[3] = { itemId: CraftingItemId.salt, quantity: 1 };189
harness.stateDb.saveBag(character.character_id, {190
inventory,191
equipment: emptyEquipment(),192
vault: [],193
vaultReserved: []194
});195
const entityId = harness.simulation.spawnCharacter(1, character);196
const cid = character.character_id;197
198
harness.simulation.enqueue(1, { type: "open-cauldron", characterId: cid });199
harness.simulation.step();200
harness.simulation.enqueue(1, {201
type: "cauldron-insert",202
characterId: cid,203
itemId: CraftingItemId.rawMeat,204
quantity: 1205
});206
for (const action of [AlchemyStepKind.heat, AlchemyStepKind.stir, AlchemyStepKind.cool])207
{208
harness.simulation.enqueue(1, {209
type: "cauldron-action",210
characterId: cid,211
action212
});213
}214
harness.simulation.enqueue(1, { type: "cauldron-bottle", characterId: cid });215
harness.simulation.step();216
217
let bag = harness.simulation.bagOf(entityId);218
assert.equal(countItem(bag.inventory, CraftingItemId.rawMeat), 0);219
assert.equal(countItem(bag.inventory, ItemId.potion), 1);220
const fatSlot = bag.inventory.find((slot) => slot?.itemId === ItemId.potion);221
assert.equal(fatSlot.instance.potionKey, "animalFat");222
assert.equal(countItem(bag.inventory, ItemId.glassBottle), 0);223
224
harness.simulation.enqueue(1, { type: "cauldron-clear", characterId: cid });225
harness.simulation.step();226
harness.simulation.enqueue(1, {227
type: "cauldron-insert",228
characterId: cid,229
itemId: WoodItemId.oakBark,230
quantity: 2231
});232
harness.simulation.enqueue(1, {233
type: "cauldron-action",234
characterId: cid,235
action: AlchemyStepKind.heat236
});237
harness.simulation.enqueue(1, {238
type: "cauldron-insert",239
characterId: cid,240
itemId: CraftingItemId.salt,241
quantity: 1242
});243
harness.simulation.enqueue(1, {244
type: "cauldron-action",245
characterId: cid,246
action: AlchemyStepKind.stir247
});248
harness.simulation.enqueue(1, {249
type: "cauldron-insert",250
characterId: cid,251
itemId: ItemId.potion,252
quantity: 1,253
instance: structuredClone(fatSlot.instance)254
});255
harness.simulation.enqueue(1, {256
type: "cauldron-action",257
characterId: cid,258
action: AlchemyStepKind.cool259
});260
harness.simulation.enqueue(1, { type: "cauldron-bottle", characterId: cid });261
harness.simulation.step();262
263
bag = harness.simulation.bagOf(entityId);264
assert.equal(countItem(bag.inventory, LeatherItemId.tanningBrew), 1);265
assert.equal(countItem(bag.inventory, ItemId.potion), 0);266
assert.equal(countItem(bag.inventory, ItemId.glassBottle), 1);267
assert.equal(countItem(bag.inventory, WoodItemId.oakBark), 0);268
assert.equal(countItem(bag.inventory, CraftingItemId.salt), 0);269
}270
finally271
{ harness.close(); }272
});