BlueGit

timfa questward

Add tanning ingredients: bark, animal fat, rock salt, and brew recipe.

Debark ground logs with a suitable axe (instance flag + bark), render salt ore, brew animal fat from venison (food poisoning if drunk), and craft tanning brew from oak bark, salt, and a full fat bottle—returning empty glass bottles (or dropping with a toast).

timfa Tim Falken · pushed by timfa

Authored 2026-09-03 · 2 months ago

Hash
c75e86ce7742c94879f12fddf789b639f6c9cb6b
Parent
9b8d59d3
22 files changed +943 −61
client/assets/items/wood/bark.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/items/wood/log-debarked.png added Binary file +0 −0

The contents of this binary file are not shown.

client/src/play/alchemy.js +12 −2
@@ -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_FLAVOR
12 CAULDRON_EMPTY_FLAVOR
13} from "/shared/definitions/alchemy.js";
13} from "/shared/definitions/alchemy.js";
14import { FLOWER_MAX_STACK } from "/shared/definitions/dyes.js";
14import { FLOWER_MAX_STACK } from "/shared/definitions/dyes.js";
15import { isFullPotionBottle } from "/shared/items/charges.js";
15import { applyItemIcon } from "../render/potionIcon.js";
16import { applyItemIcon } from "../render/potionIcon.js";
16
17
17export function initAlchemy ({
18export 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.equipment
363 if (!def || def.uniqueInstance || def.equipment
361 || 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.flower
379 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, {
client/src/play/main.js +39 −0
@@ -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";
43import { ItemId, itemDefinition } from "/shared/definitions/items.js";
43import { ItemId, itemDefinition } from "/shared/definitions/items.js";
44import { CraftingItemId, TINDERBOX_MAX_CHARGES } from "/shared/definitions/craftingItems.js";
44import { CraftingItemId, TINDERBOX_MAX_CHARGES } from "/shared/definitions/craftingItems.js";
45import { ItemFamilyId } from "/shared/definitions/tierFamilies.js";
45import { ItemFamilyId } from "/shared/definitions/tierFamilies.js";
46import { isLogDebarked } from "/shared/definitions/woodItems.js";
46import { EquipmentKind } from "/shared/definitions/equipmentKinds.js";
47import { EquipmentKind } from "/shared/definitions/equipmentKinds.js";
47import { countCoinsInSlots } from "/shared/items/inventory.js";
48import { 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
533function 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
532function requestFish (tileX, tileY)
551function 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.groundItemId
897 });
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))
server/src/alchemy/service.js +154 −37
@@ -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 mixFlowersForDye
20 mixFlowersForDye
21} from "../../../shared/definitions/dyes.js";
21} from "../../../shared/definitions/dyes.js";
22import { bagView } from "../items/bags.js";
22import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";
23import {
23import {
24 countItemInSlots,
24 countItemInSlots,
25 emptySlots,
25 emptySlots,
@@ -28,6 +28,7 @@ import {
28 takeMatchingFromSlots,
28 takeMatchingFromSlots,
29 stackQuantity
29 stackQuantity
30} from "../../../shared/items/inventory.js";
30} from "../../../shared/items/inventory.js";
31import { isFullPotionBottle } from "../../../shared/items/charges.js";
31import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";
32import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";
32import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
33import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
33import {
34import {
@@ -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.equipment
303 if (!def || def.uniqueInstance || def.equipment
300 || itemId === ItemId.potion || itemId === ItemId.glassBottle
304 || itemId === ItemId.glassBottle
301 || 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 = instance
317 const have = instance
307 ? 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 = isPotion
331 ? `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
376function 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
353function bottle (world, sessionId, command)
421function 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.instance
451 const have = row.instance
380 ? 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: false
409 });
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: 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 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: 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 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: alchemyPotionView
479 potionKey: instance.potionKey,
480 displayName: instance.displayName,
481 unstable: instance.unstable,
482 color: instance.color,
483 fillLevel: instance.fillLevel
484 }
485 }
602 }
486 };
603 };
487}
604}
server/src/debark/service.js added +162 −0
@@ -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 @@
1import { Component } from "../ecs/components.js";
2import {
3 barkItemIdForWood,
4 debarkedLogInstance,
5 isLogDebarked
6} from "../../../shared/definitions/woodItems.js";
7import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";
8import { itemDefinition } from "../../../shared/definitions/items.js";
9import { resolveWoodcuttingAxe } from "../../../shared/definitions/gathering.js";
10import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";
11import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
12import { attachOrigins, craftOrigin, CraftOriginVerb } from "../../../shared/items/origin.js";
13import { stackQuantity } from "../../../shared/items/inventory.js";
14
15function userError (message)
16{
17 const error = new Error(message);
18 error.userFacing = true;
19 return error;
20}
21
22function 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
29function 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
37function 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
50function 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 */
67export 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
157export 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}
server/src/gateway/websocket.js +8 −0
@@ -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 | 0
452 groundItemId: message.groundItemId | 0
453 });
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 | 0
461 });
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, {
server/src/items/bags.js +8 −1
@@ -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 ? instance
67 ? instance
63 : 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,
server/src/simulation/workerWorld.js +4 −0
@@ -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";
54import { handleCraftCommand, stepCrafting } from "../crafting/service.js";
54import { handleCraftCommand, stepCrafting } from "../crafting/service.js";
55import { handleFirestartingCommand, stepFirestarting } from "../firestarting/service.js";
55import { handleFirestartingCommand, stepFirestarting } from "../firestarting/service.js";
56import { handleDebarkCommand } from "../debark/service.js";
56import { handleFishingCommand, stepFishing } from "../fishing/service.js";
57import { handleFishingCommand, stepFishing } from "../fishing/service.js";
57import { handleShearingCommand, stepShearing, originIsBusyPinned } from "../shearing/service.js";
58import { handleShearingCommand, stepShearing, originIsBusyPinned } from "../shearing/service.js";
58import { handleAlchemyCommand } from "../alchemy/service.js";
59import { handleAlchemyCommand } from "../alchemy/service.js";
@@ -538,6 +539,9 @@ export class WorkerWorld
538 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; }
server/src/statusEffects/service.js +11 −0
@@ -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;
server/tests/tanning-ingredients.test.js added +272 −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 @@
1import test from "node:test";
2import assert from "node:assert/strict";
3import { BlockType } from "../../shared/definitions/tiles.js";
4import { ItemId, itemDefinition, itemDisplayName, itemSpriteNameForStack } from "../../shared/definitions/items.js";
5import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
6import {
7 WoodItemId,
8 debarkedLogInstance,
9 isLogDebarked,
10 barkItemIdForWood
11} from "../../shared/definitions/woodItems.js";
12import { WoodTier, GatherMaterialId, MaterialTier, oreBoulderState } from "../../shared/definitions/materialTiers.js";
13import { SkillId } from "../../shared/definitions/skills.js";
14import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
15import { AlchemyStepKind } from "../../shared/definitions/alchemy.js";
16import { canMineMaterial, oreItemIdForMaterial } from "../../shared/definitions/gathering.js";
17import {
18 clearResolvedAlchemyPotionsCache,
19 resolvedAlchemyPotions,
20 evaluateAlchemyBottle,
21 potionItemInstance
22} from "../../shared/alchemy/recipes.js";
23import { StatusEffectType } from "../../shared/statusEffects/rules.js";
24import { isFullPotionBottle } from "../../shared/items/charges.js";
25import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js";
26import { totalXpForLevel } from "../../shared/skills/progression.js";
27import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
28import { addGroundItem } from "../src/items/bags.js";
29import { Component } from "../src/ecs/components.js";
30import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
31
32function 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
50function countItem (slots, itemId)
51{
52 return (slots ?? [])
53 .filter((slot) => slot?.itemId === itemId)
54 .reduce((sum, slot) => sum + (slot.quantity | 0), 0);
55}
56
57function 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
64test("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
75test("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
87test("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
139test("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
175test("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});
shared/alchemy/recipes.js +90 −12
@@ -1,5 +1,5 @@
1 1 import { AlchemyStepKind, ALCHEMY_POTION_DEFINITIONS, UNSTABLE_POTION_EFFECTS, CAULDRON_FLAVOR_LINES, CAULDRON_EMPTY_FLAVOR, alchemyPotionDefinition } from "../definitions/alchemy.js";
2 import { ITEM_DEFINITIONS, itemDefinition } from "../definitions/items.js";
2 import { ITEM_DEFINITIONS, ItemId, itemDefinition } from "../definitions/items.js";
3 3 import { skillLevel, SkillId } from "../definitions/skills.js";
4 4
5 5 /** Serialize a step for hashing / recipe papers. */
@@ -7,6 +7,11 @@ export function formatAlchemyStep (step)
7 7 {
8 8 if (step.kind === AlchemyStepKind.insert)
9 9 {
10 if (step.potionKey)
11 {
12 const potion = alchemyPotionDefinition(step.potionKey);
13 return `insert ${potion?.displayName ?? step.potionKey}`;
14 }
10 15 const def = itemDefinition(step.itemId);
11 16 return `insert ${def?.displayName ?? step.itemKey ?? step.itemId}`;
12 17 }
@@ -18,7 +23,11 @@ export function hashAlchemySteps (steps)
18 23 const text = (steps ?? []).map((step) =>
19 24 {
20 25 if (step.kind === AlchemyStepKind.insert)
21 { return `insert:${step.itemId ?? step.itemKey}`; }
26 {
27 if (step.potionKey)
28 { return `insert:potion:${step.potionKey}`; }
29 return `insert:${step.itemId ?? step.itemKey}`;
30 }
22 31 return step.kind;
23 32 }).join("|");
24 33 let hash = 2166136261;
@@ -74,6 +83,15 @@ export function resolvePotionIngredientIds (potion, byKey = itemIdByKeyMap())
74 83 {
75 84 const ingredients = (potion.ingredients ?? []).map((row) =>
76 85 {
86 if (row.potionKey)
87 {
88 return {
89 itemId: ItemId.potion,
90 potionKey: row.potionKey,
91 key: row.key ?? row.potionKey,
92 quantity: row.quantity
93 };
94 }
77 95 const itemId = row.itemId ?? byKey.get(row.key) ?? null;
78 96 return { itemId, key: row.key, quantity: row.quantity };
79 97 });
@@ -81,6 +99,15 @@ export function resolvePotionIngredientIds (potion, byKey = itemIdByKeyMap())
81 99 {
82 100 if (step.kind !== AlchemyStepKind.insert)
83 101 { return { ...step }; }
102 if (step.potionKey)
103 {
104 return {
105 kind: AlchemyStepKind.insert,
106 itemId: ItemId.potion,
107 potionKey: step.potionKey,
108 itemKey: step.itemKey ?? "potion"
109 };
110 }
84 111 const itemId = step.itemId ?? byKey.get(step.itemKey) ?? null;
85 112 return { kind: AlchemyStepKind.insert, itemId, itemKey: step.itemKey };
86 113 });
@@ -100,18 +127,48 @@ export function resolvedAlchemyPotions ()
100 127 return cachedResolvedPotions;
101 128 }
102 129
130 /** Test helper when potion defs are patched mid-suite. */
131 export function clearResolvedAlchemyPotionsCache ()
132 {
133 cachedResolvedPotions = null;
134 }
135
136 export function alchemyIngredientNeedKey (row)
137 {
138 if (row?.potionKey)
139 { return `potion:${row.potionKey}`; }
140 return `item:${row?.itemId | 0}`;
141 }
142
143 export function alchemyStackHaveKey (stack)
144 {
145 if ((stack?.itemId | 0) === ItemId.potion && stack.instance?.potionKey)
146 { return `potion:${stack.instance.potionKey}`; }
147 return `item:${stack?.itemId | 0}`;
148 }
149
103 150 /**
104 151 * Greatest integer batch size for reserved slot quantities vs recipe ingredient ratios.
105 152 * Returns 0 if ratios do not match (wrong items or non-integer multiple).
153 * Potion ingredients match by potionKey (full bottles still counted as quantity).
106 154 */
107 155 export function alchemyBatchCount (recipeIngredients, reservedStacks)
108 156 {
109 157 const need = new Map();
110 158 for (const row of recipeIngredients ?? [])
111 159 {
160 if (row.potionKey)
161 {
162 if (!(row.quantity > 0))
163 { return 0; }
164 const key = alchemyIngredientNeedKey(row);
165 need.set(key, (need.get(key) ?? 0) + row.quantity);
166 continue;
167 }
112 168 if (row.itemId == null || row.quantity <= 0)
113 169 { return 0; }
114 need.set(row.itemId, (need.get(row.itemId) ?? 0) + row.quantity);
170 const key = alchemyIngredientNeedKey(row);
171 need.set(key, (need.get(key) ?? 0) + row.quantity);
115 172 }
116 173 if (need.size === 0 || need.size > 4)
117 174 { return 0; }
@@ -121,22 +178,23 @@ export function alchemyBatchCount (recipeIngredients, reservedStacks)
121 178 {
122 179 if (!stack?.itemId || !(stack.quantity > 0))
123 180 { continue; }
124 have.set(stack.itemId, (have.get(stack.itemId) ?? 0) + stack.quantity);
181 const key = alchemyStackHaveKey(stack);
182 have.set(key, (have.get(key) ?? 0) + (stack.quantity | 0));
125 183 }
126 184 if (have.size !== need.size)
127 185 { return 0; }
128 186
129 187 let batch = Infinity;
130 for (const [itemId, qty] of need)
188 for (const [key, qty] of need)
131 189 {
132 const got = have.get(itemId);
190 const got = have.get(key);
133 191 if (got == null || got % qty !== 0)
134 192 { return 0; }
135 193 batch = Math.min(batch, got / qty);
136 194 }
137 for (const itemId of have.keys())
195 for (const key of have.keys())
138 196 {
139 if (!need.has(itemId))
197 if (!need.has(key))
140 198 { return 0; }
141 199 }
142 200 return Number.isFinite(batch) && batch > 0 ? batch | 0 : 0;
@@ -154,8 +212,18 @@ export function stepsMatchRecipe (takenSteps, recipeSteps)
154 212 const got = takenSteps[i];
155 213 if (want.kind !== got.kind)
156 214 { return false; }
157 if (want.kind === AlchemyStepKind.insert && want.itemId !== got.itemId)
158 { return false; }
215 if (want.kind === AlchemyStepKind.insert)
216 {
217 if ((want.itemId | 0) !== (got.itemId | 0))
218 { return false; }
219 const wantPotion = want.potionKey ?? null;
220 const gotPotion = got.potionKey ?? null;
221 if (wantPotion || gotPotion)
222 {
223 if (wantPotion !== gotPotion)
224 { return false; }
225 }
226 }
159 227 }
160 228 return true;
161 229 }
@@ -186,7 +254,8 @@ export function evaluateAlchemyBottle ({
186 254 success: false,
187 255 batch: 1,
188 256 result: unstablePotionFromSteps(takenSteps),
189 reason: "alchemy-level"
257 reason: "alchemy-level",
258 recipe: potion
190 259 };
191 260 }
192 261 return {
@@ -201,7 +270,10 @@ export function evaluateAlchemyBottle ({
201 270 fillLevel: potion.fillLevel ?? 4,
202 271 effect: potion.effect,
203 272 effectKey: potion.effect?.type ?? potion.potionKey,
204 minAlchemyLevel: potion.minAlchemyLevel ?? 1
273 minAlchemyLevel: potion.minAlchemyLevel ?? 1,
274 outputItemId: potion.outputItemId ?? null,
275 outputQuantity: potion.outputQuantity ?? 1,
276 requiresEmptyBottles: potion.requiresEmptyBottles !== false
205 277 },
206 278 recipe: potion
207 279 };
@@ -225,6 +297,12 @@ export function recipePaperBody (potion)
225 297 ];
226 298 for (const row of potion.ingredients ?? [])
227 299 {
300 if (row.potionKey)
301 {
302 const brew = alchemyPotionDefinition(row.potionKey);
303 lines.push(`- ${row.quantity}× ${brew?.displayName ?? row.potionKey} (full bottle)`);
304 continue;
305 }
228 306 const def = itemDefinition(row.itemId);
229 307 lines.push(`- ${row.quantity}× ${def?.displayName ?? row.key ?? row.itemId}`);
230 308 }
@@ -1,5 +1,5 @@
1import { AlchemyStepKind, ALCHEMY_POTION_DEFINITIONS, UNSTABLE_POTION_EFFECTS, CAULDRON_FLAVOR_LINES, CAULDRON_EMPTY_FLAVOR, alchemyPotionDefinition } from "../definitions/alchemy.js";
1import { AlchemyStepKind, ALCHEMY_POTION_DEFINITIONS, UNSTABLE_POTION_EFFECTS, CAULDRON_FLAVOR_LINES, CAULDRON_EMPTY_FLAVOR, alchemyPotionDefinition } from "../definitions/alchemy.js";
2import { ITEM_DEFINITIONS, itemDefinition } from "../definitions/items.js";
2import { ITEM_DEFINITIONS, ItemId, itemDefinition } from "../definitions/items.js";
3import { skillLevel, SkillId } from "../definitions/skills.js";
3import { skillLevel, SkillId } from "../definitions/skills.js";
4
4
5/** Serialize a step for hashing / recipe papers. */
5/** Serialize a step for hashing / recipe papers. */
@@ -7,6 +7,11 @@ export function formatAlchemyStep (step)
7{
7{
8 if (step.kind === AlchemyStepKind.insert)
8 if (step.kind === AlchemyStepKind.insert)
9 {
9 {
10 if (step.potionKey)
11 {
12 const potion = alchemyPotionDefinition(step.potionKey);
13 return `insert ${potion?.displayName ?? step.potionKey}`;
14 }
10 const def = itemDefinition(step.itemId);
15 const def = itemDefinition(step.itemId);
11 return `insert ${def?.displayName ?? step.itemKey ?? step.itemId}`;
16 return `insert ${def?.displayName ?? step.itemKey ?? step.itemId}`;
12 }
17 }
@@ -18,7 +23,11 @@ export function hashAlchemySteps (steps)
18 const text = (steps ?? []).map((step) =>
23 const text = (steps ?? []).map((step) =>
19 {
24 {
20 if (step.kind === AlchemyStepKind.insert)
25 if (step.kind === AlchemyStepKind.insert)
21 { return `insert:${step.itemId ?? step.itemKey}`; }
26 {
27 if (step.potionKey)
28 { return `insert:potion:${step.potionKey}`; }
29 return `insert:${step.itemId ?? step.itemKey}`;
30 }
22 return step.kind;
31 return step.kind;
23 }).join("|");
32 }).join("|");
24 let hash = 2166136261;
33 let hash = 2166136261;
@@ -74,6 +83,15 @@ export function resolvePotionIngredientIds (potion, byKey = itemIdByKeyMap())
74{
83{
75 const ingredients = (potion.ingredients ?? []).map((row) =>
84 const ingredients = (potion.ingredients ?? []).map((row) =>
76 {
85 {
86 if (row.potionKey)
87 {
88 return {
89 itemId: ItemId.potion,
90 potionKey: row.potionKey,
91 key: row.key ?? row.potionKey,
92 quantity: row.quantity
93 };
94 }
77 const itemId = row.itemId ?? byKey.get(row.key) ?? null;
95 const itemId = row.itemId ?? byKey.get(row.key) ?? null;
78 return { itemId, key: row.key, quantity: row.quantity };
96 return { itemId, key: row.key, quantity: row.quantity };
79 });
97 });
@@ -81,6 +99,15 @@ export function resolvePotionIngredientIds (potion, byKey = itemIdByKeyMap())
81 {
99 {
82 if (step.kind !== AlchemyStepKind.insert)
100 if (step.kind !== AlchemyStepKind.insert)
83 { return { ...step }; }
101 { return { ...step }; }
102 if (step.potionKey)
103 {
104 return {
105 kind: AlchemyStepKind.insert,
106 itemId: ItemId.potion,
107 potionKey: step.potionKey,
108 itemKey: step.itemKey ?? "potion"
109 };
110 }
84 const itemId = step.itemId ?? byKey.get(step.itemKey) ?? null;
111 const itemId = step.itemId ?? byKey.get(step.itemKey) ?? null;
85 return { kind: AlchemyStepKind.insert, itemId, itemKey: step.itemKey };
112 return { kind: AlchemyStepKind.insert, itemId, itemKey: step.itemKey };
86 });
113 });
@@ -100,18 +127,48 @@ export function resolvedAlchemyPotions ()
100 return cachedResolvedPotions;
127 return cachedResolvedPotions;
101}
128}
102
129
130/** Test helper when potion defs are patched mid-suite. */
131export function clearResolvedAlchemyPotionsCache ()
132{
133 cachedResolvedPotions = null;
134}
135
136export function alchemyIngredientNeedKey (row)
137{
138 if (row?.potionKey)
139 { return `potion:${row.potionKey}`; }
140 return `item:${row?.itemId | 0}`;
141}
142
143export function alchemyStackHaveKey (stack)
144{
145 if ((stack?.itemId | 0) === ItemId.potion && stack.instance?.potionKey)
146 { return `potion:${stack.instance.potionKey}`; }
147 return `item:${stack?.itemId | 0}`;
148}
149
103/**
150/**
104 * Greatest integer batch size for reserved slot quantities vs recipe ingredient ratios.
151 * Greatest integer batch size for reserved slot quantities vs recipe ingredient ratios.
105 * Returns 0 if ratios do not match (wrong items or non-integer multiple).
152 * Returns 0 if ratios do not match (wrong items or non-integer multiple).
153 * Potion ingredients match by potionKey (full bottles still counted as quantity).
106 */
154 */
107export function alchemyBatchCount (recipeIngredients, reservedStacks)
155export function alchemyBatchCount (recipeIngredients, reservedStacks)
108{
156{
109 const need = new Map();
157 const need = new Map();
110 for (const row of recipeIngredients ?? [])
158 for (const row of recipeIngredients ?? [])
111 {
159 {
160 if (row.potionKey)
161 {
162 if (!(row.quantity > 0))
163 { return 0; }
164 const key = alchemyIngredientNeedKey(row);
165 need.set(key, (need.get(key) ?? 0) + row.quantity);
166 continue;
167 }
112 if (row.itemId == null || row.quantity <= 0)
168 if (row.itemId == null || row.quantity <= 0)
113 { return 0; }
169 { return 0; }
114 need.set(row.itemId, (need.get(row.itemId) ?? 0) + row.quantity);
170 const key = alchemyIngredientNeedKey(row);
171 need.set(key, (need.get(key) ?? 0) + row.quantity);
115 }
172 }
116 if (need.size === 0 || need.size > 4)
173 if (need.size === 0 || need.size > 4)
117 { return 0; }
174 { return 0; }
@@ -121,22 +178,23 @@ export function alchemyBatchCount (recipeIngredients, reservedStacks)
121 {
178 {
122 if (!stack?.itemId || !(stack.quantity > 0))
179 if (!stack?.itemId || !(stack.quantity > 0))
123 { continue; }
180 { continue; }
124 have.set(stack.itemId, (have.get(stack.itemId) ?? 0) + stack.quantity);
181 const key = alchemyStackHaveKey(stack);
182 have.set(key, (have.get(key) ?? 0) + (stack.quantity | 0));
125 }
183 }
126 if (have.size !== need.size)
184 if (have.size !== need.size)
127 { return 0; }
185 { return 0; }
128
186
129 let batch = Infinity;
187 let batch = Infinity;
130 for (const [itemId, qty] of need)
188 for (const [key, qty] of need)
131 {
189 {
132 const got = have.get(itemId);
190 const got = have.get(key);
133 if (got == null || got % qty !== 0)
191 if (got == null || got % qty !== 0)
134 { return 0; }
192 { return 0; }
135 batch = Math.min(batch, got / qty);
193 batch = Math.min(batch, got / qty);
136 }
194 }
137 for (const itemId of have.keys())
195 for (const key of have.keys())
138 {
196 {
139 if (!need.has(itemId))
197 if (!need.has(key))
140 { return 0; }
198 { return 0; }
141 }
199 }
142 return Number.isFinite(batch) && batch > 0 ? batch | 0 : 0;
200 return Number.isFinite(batch) && batch > 0 ? batch | 0 : 0;
@@ -154,8 +212,18 @@ export function stepsMatchRecipe (takenSteps, recipeSteps)
154 const got = takenSteps[i];
212 const got = takenSteps[i];
155 if (want.kind !== got.kind)
213 if (want.kind !== got.kind)
156 { return false; }
214 { return false; }
157 if (want.kind === AlchemyStepKind.insert && want.itemId !== got.itemId)
215 if (want.kind === AlchemyStepKind.insert)
158 { return false; }
216 {
217 if ((want.itemId | 0) !== (got.itemId | 0))
218 { return false; }
219 const wantPotion = want.potionKey ?? null;
220 const gotPotion = got.potionKey ?? null;
221 if (wantPotion || gotPotion)
222 {
223 if (wantPotion !== gotPotion)
224 { return false; }
225 }
226 }
159 }
227 }
160 return true;
228 return true;
161}
229}
@@ -186,7 +254,8 @@ export function evaluateAlchemyBottle ({
186 success: false,
254 success: false,
187 batch: 1,
255 batch: 1,
188 result: unstablePotionFromSteps(takenSteps),
256 result: unstablePotionFromSteps(takenSteps),
189 reason: "alchemy-level"
257 reason: "alchemy-level",
258 recipe: potion
190 };
259 };
191 }
260 }
192 return {
261 return {
@@ -201,7 +270,10 @@ export function evaluateAlchemyBottle ({
201 fillLevel: potion.fillLevel ?? 4,
270 fillLevel: potion.fillLevel ?? 4,
202 effect: potion.effect,
271 effect: potion.effect,
203 effectKey: potion.effect?.type ?? potion.potionKey,
272 effectKey: potion.effect?.type ?? potion.potionKey,
204 minAlchemyLevel: potion.minAlchemyLevel ?? 1
273 minAlchemyLevel: potion.minAlchemyLevel ?? 1,
274 outputItemId: potion.outputItemId ?? null,
275 outputQuantity: potion.outputQuantity ?? 1,
276 requiresEmptyBottles: potion.requiresEmptyBottles !== false
205 },
277 },
206 recipe: potion
278 recipe: potion
207 };
279 };
@@ -225,6 +297,12 @@ export function recipePaperBody (potion)
225 ];
297 ];
226 for (const row of potion.ingredients ?? [])
298 for (const row of potion.ingredients ?? [])
227 {
299 {
300 if (row.potionKey)
301 {
302 const brew = alchemyPotionDefinition(row.potionKey);
303 lines.push(`- ${row.quantity}× ${brew?.displayName ?? row.potionKey} (full bottle)`);
304 continue;
305 }
228 const def = itemDefinition(row.itemId);
306 const def = itemDefinition(row.itemId);
229 lines.push(`- ${row.quantity}× ${def?.displayName ?? row.key ?? row.itemId}`);
307 lines.push(`- ${row.quantity}× ${def?.displayName ?? row.key ?? row.itemId}`);
230 }
308 }
shared/definitions/alchemy.js +48 −0
@@ -5,6 +5,7 @@ import {
5 5 MAGIC_ELEMENT_TINT,
6 6 ASH_WOOD_FOR_ELEMENT
7 7 } from "./attackTypes.js";
8 import { LeatherItemId } from "./leatherItems.js";
8 9
9 10 export const AlchemyStepKind = Object.freeze({
10 11 heat: "heat",
@@ -130,6 +131,53 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
130 131 durationMs: 60_000
131 132 })
132 133 }),
134 animalFat: Object.freeze({
135 potionKey: "animalFat",
136 displayName: "Bottle of Animal Fat",
137 minAlchemyLevel: 1,
138 color: Object.freeze({ r: 0.92, g: 0.84, b: 0.52 }),
139 fillLevel: 4,
140 ingredients: Object.freeze([
141 Object.freeze({ key: "uncooked-venison", quantity: 1 })
142 ]),
143 steps: Object.freeze([
144 Object.freeze({ kind: AlchemyStepKind.insert, itemKey: "uncooked-venison" }),
145 Object.freeze({ kind: AlchemyStepKind.heat }),
146 Object.freeze({ kind: AlchemyStepKind.stir }),
147 Object.freeze({ kind: AlchemyStepKind.cool })
148 ]),
149 effect: Object.freeze({
150 type: "food-poisoning",
151 amountPerSecond: 1,
152 durationMs: 10_000
153 })
154 }),
155 tanningBrew: Object.freeze({
156 potionKey: "tanningBrew",
157 displayName: "Tanning brew",
158 minAlchemyLevel: 10,
159 color: Object.freeze({ r: 0.45, g: 0.28, b: 0.14 }),
160 fillLevel: 4,
161 /** Solid craft item — not a drinkable potion bottle. */
162 outputItemId: LeatherItemId.tanningBrew,
163 outputQuantity: 1,
164 /** Bottling does not consume empty glass bottles (fat bottle is the vessel). */
165 requiresEmptyBottles: false,
166 ingredients: Object.freeze([
167 Object.freeze({ key: "oak-bark", quantity: 2 }),
168 Object.freeze({ key: "rock-salt", quantity: 1 }),
169 Object.freeze({ potionKey: "animalFat", quantity: 1 })
170 ]),
171 steps: Object.freeze([
172 Object.freeze({ kind: AlchemyStepKind.insert, itemKey: "oak-bark" }),
173 Object.freeze({ kind: AlchemyStepKind.heat }),
174 Object.freeze({ kind: AlchemyStepKind.insert, itemKey: "rock-salt" }),
175 Object.freeze({ kind: AlchemyStepKind.stir }),
176 Object.freeze({ kind: AlchemyStepKind.insert, potionKey: "animalFat" }),
177 Object.freeze({ kind: AlchemyStepKind.cool })
178 ]),
179 effect: null
180 }),
133 181 ...buildArrowCoatingPotions()
134 182 });
135 183
@@ -5,6 +5,7 @@ import {
5 MAGIC_ELEMENT_TINT,
5 MAGIC_ELEMENT_TINT,
6 ASH_WOOD_FOR_ELEMENT
6 ASH_WOOD_FOR_ELEMENT
7} from "./attackTypes.js";
7} from "./attackTypes.js";
8import { LeatherItemId } from "./leatherItems.js";
8
9
9export const AlchemyStepKind = Object.freeze({
10export const AlchemyStepKind = Object.freeze({
10 heat: "heat",
11 heat: "heat",
@@ -130,6 +131,53 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
130 durationMs: 60_000
131 durationMs: 60_000
131 })
132 })
132 }),
133 }),
134 animalFat: Object.freeze({
135 potionKey: "animalFat",
136 displayName: "Bottle of Animal Fat",
137 minAlchemyLevel: 1,
138 color: Object.freeze({ r: 0.92, g: 0.84, b: 0.52 }),
139 fillLevel: 4,
140 ingredients: Object.freeze([
141 Object.freeze({ key: "uncooked-venison", quantity: 1 })
142 ]),
143 steps: Object.freeze([
144 Object.freeze({ kind: AlchemyStepKind.insert, itemKey: "uncooked-venison" }),
145 Object.freeze({ kind: AlchemyStepKind.heat }),
146 Object.freeze({ kind: AlchemyStepKind.stir }),
147 Object.freeze({ kind: AlchemyStepKind.cool })
148 ]),
149 effect: Object.freeze({
150 type: "food-poisoning",
151 amountPerSecond: 1,
152 durationMs: 10_000
153 })
154 }),
155 tanningBrew: Object.freeze({
156 potionKey: "tanningBrew",
157 displayName: "Tanning brew",
158 minAlchemyLevel: 10,
159 color: Object.freeze({ r: 0.45, g: 0.28, b: 0.14 }),
160 fillLevel: 4,
161 /** Solid craft item — not a drinkable potion bottle. */
162 outputItemId: LeatherItemId.tanningBrew,
163 outputQuantity: 1,
164 /** Bottling does not consume empty glass bottles (fat bottle is the vessel). */
165 requiresEmptyBottles: false,
166 ingredients: Object.freeze([
167 Object.freeze({ key: "oak-bark", quantity: 2 }),
168 Object.freeze({ key: "rock-salt", quantity: 1 }),
169 Object.freeze({ potionKey: "animalFat", quantity: 1 })
170 ]),
171 steps: Object.freeze([
172 Object.freeze({ kind: AlchemyStepKind.insert, itemKey: "oak-bark" }),
173 Object.freeze({ kind: AlchemyStepKind.heat }),
174 Object.freeze({ kind: AlchemyStepKind.insert, itemKey: "rock-salt" }),
175 Object.freeze({ kind: AlchemyStepKind.stir }),
176 Object.freeze({ kind: AlchemyStepKind.insert, potionKey: "animalFat" }),
177 Object.freeze({ kind: AlchemyStepKind.cool })
178 ]),
179 effect: null
180 }),
133 ...buildArrowCoatingPotions()
181 ...buildArrowCoatingPotions()
134});
182});
135
183
shared/definitions/craftingItems.js +19 −1
@@ -33,7 +33,9 @@ export const CraftingItemId = Object.freeze({
33 33 burntMutton: 508,
34 34 rawGoat: 509,
35 35 cookedGoat: 510,
36 burntGoat: 511
36 burntGoat: 511,
37 /** Mined rock salt (ash sprite, rock-salt tint). */
38 salt: 589
37 39 });
38 40
39 41 /** Magenta cookable base; tinted per cook state. */
@@ -320,5 +322,21 @@ export const CRAFTING_ITEM_STUBS = Object.freeze({
320 322 cookable: true,
321 323 cookState: "burnt",
322 324 tint: GOAT_COOK_COLORS.burnt
325 }),
326 [CraftingItemId.salt]: Object.freeze({
327 itemId: CraftingItemId.salt,
328 key: "rock-salt",
329 displayName: "Rock salt",
330 description: "Coarse crystals mined from salt rock, sharp on the tongue.",
331 seedValue: 2,
332 stackable: true,
333 maxStackSize: DEFAULT_STACK,
334 uniqueInstance: false,
335 category: ItemCategory.ingredient,
336 iconKey: "ash",
337 defaultState: "ash",
338 tier: GatherMaterialId.salt,
339 tintFromTier: true,
340 npcShopAllowed: true
323 341 })
324 342 });
@@ -33,7 +33,9 @@ export const CraftingItemId = Object.freeze({
33 burntMutton: 508,
33 burntMutton: 508,
34 rawGoat: 509,
34 rawGoat: 509,
35 cookedGoat: 510,
35 cookedGoat: 510,
36 burntGoat: 511
36 burntGoat: 511,
37 /** Mined rock salt (ash sprite, rock-salt tint). */
38 salt: 589
37});
39});
38
40
39/** Magenta cookable base; tinted per cook state. */
41/** Magenta cookable base; tinted per cook state. */
@@ -320,5 +322,21 @@ export const CRAFTING_ITEM_STUBS = Object.freeze({
320 cookable: true,
322 cookable: true,
321 cookState: "burnt",
323 cookState: "burnt",
322 tint: GOAT_COOK_COLORS.burnt
324 tint: GOAT_COOK_COLORS.burnt
325 }),
326 [CraftingItemId.salt]: Object.freeze({
327 itemId: CraftingItemId.salt,
328 key: "rock-salt",
329 displayName: "Rock salt",
330 description: "Coarse crystals mined from salt rock, sharp on the tongue.",
331 seedValue: 2,
332 stackable: true,
333 maxStackSize: DEFAULT_STACK,
334 uniqueInstance: false,
335 category: ItemCategory.ingredient,
336 iconKey: "ash",
337 defaultState: "ash",
338 tier: GatherMaterialId.salt,
339 tintFromTier: true,
340 npcShopAllowed: true
323 })
341 })
324});
342});
shared/definitions/gathering.js +1 −0
@@ -67,6 +67,7 @@ export const ORE_ITEM_BY_MATERIAL = Object.freeze({
67 67 [MaterialTier.orichalcum]: MetalItemId.orichalcumOre,
68 68 [MaterialTier.dragon]: MetalItemId.dragonOre,
69 69 [GatherMaterialId.coal]: MetalItemId.coal,
70 [GatherMaterialId.salt]: CraftingItemId.salt,
70 71 [GatherMaterialId.tourmaline]: gemItemId(GatherMaterialId.tourmaline),
71 72 [GatherMaterialId.alexandrite]: gemItemId(GatherMaterialId.alexandrite),
72 73 [GatherMaterialId.opal]: gemItemId(GatherMaterialId.opal),
@@ -67,6 +67,7 @@ export const ORE_ITEM_BY_MATERIAL = Object.freeze({
67 [MaterialTier.orichalcum]: MetalItemId.orichalcumOre,
67 [MaterialTier.orichalcum]: MetalItemId.orichalcumOre,
68 [MaterialTier.dragon]: MetalItemId.dragonOre,
68 [MaterialTier.dragon]: MetalItemId.dragonOre,
69 [GatherMaterialId.coal]: MetalItemId.coal,
69 [GatherMaterialId.coal]: MetalItemId.coal,
70 [GatherMaterialId.salt]: CraftingItemId.salt,
70 [GatherMaterialId.tourmaline]: gemItemId(GatherMaterialId.tourmaline),
71 [GatherMaterialId.tourmaline]: gemItemId(GatherMaterialId.tourmaline),
71 [GatherMaterialId.alexandrite]: gemItemId(GatherMaterialId.alexandrite),
72 [GatherMaterialId.alexandrite]: gemItemId(GatherMaterialId.alexandrite),
72 [GatherMaterialId.opal]: gemItemId(GatherMaterialId.opal),
73 [GatherMaterialId.opal]: gemItemId(GatherMaterialId.opal),
shared/definitions/items.js +9 −4
@@ -7,7 +7,8 @@ import { formatQuantity } from "../items/formatQuantity.js";
7 7 import { formatOriginBreakdown } from "../items/origin.js";
8 8 import { CraftingItemId, CRAFTING_ITEM_STUBS } from "./craftingItems.js";
9 9 import { MetalItemId, METAL_ITEM_DEFINITIONS } from "./metalItems.js";
10 import { WoodItemId, WOOD_ITEM_DEFINITIONS } from "./woodItems.js";
10 import { WoodItemId, WOOD_ITEM_DEFINITIONS, isLogDebarked } from "./woodItems.js";
11 import { ItemFamilyId } from "./tierFamilies.js";
11 12 import { ArmourItemId, ARMOUR_ITEM_DEFINITIONS } from "./armourItems.js";
12 13 import { ClothItemId, CLOTH_ITEM_DEFINITIONS } from "./clothItems.js";
13 14 import { LeatherItemId, LEATHER_ITEM_DEFINITIONS } from "./leatherItems.js";
@@ -399,6 +400,8 @@ export function itemDisplayName (stack, def = itemDefinition(stack?.itemId))
399 400 const charges = Math.max(0, stack.instance.charges | 0);
400 401 return `${def.displayName} (${charges})`;
401 402 }
403 if (def.familyId === ItemFamilyId.log && isLogDebarked(stack))
404 { return `Debarked ${def.displayName}`; }
402 405 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
403 406 {
404 407 const el = String(stack.instance.element);
@@ -481,8 +484,10 @@ export function itemOriginSummary (stack)
481 484 return formatOriginBreakdown(stack);
482 485 }
483 486
484 export function itemDefaultState (def)
487 export function itemDefaultState (def, instance = null)
485 488 {
489 if (def?.familyId === ItemFamilyId.log && isLogDebarked({ instance }))
490 { return "log-debarked"; }
486 491 return def?.defaultState ?? def?.key ?? "paper";
487 492 }
488 493
@@ -501,7 +506,7 @@ export function itemSpriteName (itemId, instance = null, quantity = null)
501 506 if (instance?.kind === "tipped-arrow")
502 507 { return spriteImageName("item", "arrow", "tipped-arrow"); }
503 508 const folderKey = def.iconKey ?? def.key;
504 return def.sprite ?? spriteImageName("item", folderKey, itemDefaultState(def));
509 return def.sprite ?? spriteImageName("item", folderKey, itemDefaultState(def, instance));
505 510 }
506 511
507 512 /** Stack-aware sprite key (coins use quantity tiers like inventory icons). */
@@ -590,7 +595,7 @@ export function itemAssetPath (itemId, companion = null, instance = null)
590 595 const key = def?.iconKey ?? def?.key ?? "paper";
591 596 const state = itemId === ItemId.letter
592 597 ? letterVisualState(instance)
593 : itemDefaultState(def ?? { key });
598 : itemDefaultState(def ?? { key }, instance);
594 599 const suffix = companion ? `-${companion}` : "";
595 600 return `/assets/items/${key}/${state}${suffix}.png`;
596 601 }
@@ -7,7 +7,8 @@ import { formatQuantity } from "../items/formatQuantity.js";
7import { formatOriginBreakdown } from "../items/origin.js";
7import { formatOriginBreakdown } from "../items/origin.js";
8import { CraftingItemId, CRAFTING_ITEM_STUBS } from "./craftingItems.js";
8import { CraftingItemId, CRAFTING_ITEM_STUBS } from "./craftingItems.js";
9import { MetalItemId, METAL_ITEM_DEFINITIONS } from "./metalItems.js";
9import { MetalItemId, METAL_ITEM_DEFINITIONS } from "./metalItems.js";
10import { WoodItemId, WOOD_ITEM_DEFINITIONS } from "./woodItems.js";
10import { WoodItemId, WOOD_ITEM_DEFINITIONS, isLogDebarked } from "./woodItems.js";
11import { ItemFamilyId } from "./tierFamilies.js";
11import { ArmourItemId, ARMOUR_ITEM_DEFINITIONS } from "./armourItems.js";
12import { ArmourItemId, ARMOUR_ITEM_DEFINITIONS } from "./armourItems.js";
12import { ClothItemId, CLOTH_ITEM_DEFINITIONS } from "./clothItems.js";
13import { ClothItemId, CLOTH_ITEM_DEFINITIONS } from "./clothItems.js";
13import { LeatherItemId, LEATHER_ITEM_DEFINITIONS } from "./leatherItems.js";
14import { LeatherItemId, LEATHER_ITEM_DEFINITIONS } from "./leatherItems.js";
@@ -399,6 +400,8 @@ export function itemDisplayName (stack, def = itemDefinition(stack?.itemId))
399 const charges = Math.max(0, stack.instance.charges | 0);
400 const charges = Math.max(0, stack.instance.charges | 0);
400 return `${def.displayName} (${charges})`;
401 return `${def.displayName} (${charges})`;
401 }
402 }
403 if (def.familyId === ItemFamilyId.log && isLogDebarked(stack))
404 { return `Debarked ${def.displayName}`; }
402 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
405 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
403 {
406 {
404 const el = String(stack.instance.element);
407 const el = String(stack.instance.element);
@@ -481,8 +484,10 @@ export function itemOriginSummary (stack)
481 return formatOriginBreakdown(stack);
484 return formatOriginBreakdown(stack);
482}
485}
483
486
484export function itemDefaultState (def)
487export function itemDefaultState (def, instance = null)
485{
488{
489 if (def?.familyId === ItemFamilyId.log && isLogDebarked({ instance }))
490 { return "log-debarked"; }
486 return def?.defaultState ?? def?.key ?? "paper";
491 return def?.defaultState ?? def?.key ?? "paper";
487}
492}
488
493
@@ -501,7 +506,7 @@ export function itemSpriteName (itemId, instance = null, quantity = null)
501 if (instance?.kind === "tipped-arrow")
506 if (instance?.kind === "tipped-arrow")
502 { return spriteImageName("item", "arrow", "tipped-arrow"); }
507 { return spriteImageName("item", "arrow", "tipped-arrow"); }
503 const folderKey = def.iconKey ?? def.key;
508 const folderKey = def.iconKey ?? def.key;
504 return def.sprite ?? spriteImageName("item", folderKey, itemDefaultState(def));
509 return def.sprite ?? spriteImageName("item", folderKey, itemDefaultState(def, instance));
505}
510}
506
511
507/** Stack-aware sprite key (coins use quantity tiers like inventory icons). */
512/** Stack-aware sprite key (coins use quantity tiers like inventory icons). */
@@ -590,7 +595,7 @@ export function itemAssetPath (itemId, companion = null, instance = null)
590 const key = def?.iconKey ?? def?.key ?? "paper";
595 const key = def?.iconKey ?? def?.key ?? "paper";
591 const state = itemId === ItemId.letter
596 const state = itemId === ItemId.letter
592 ? letterVisualState(instance)
597 ? letterVisualState(instance)
593 : itemDefaultState(def ?? { key });
598 : itemDefaultState(def ?? { key }, instance);
594 const suffix = companion ? `-${companion}` : "";
599 const suffix = companion ? `-${companion}` : "";
595 return `/assets/items/${key}/${state}${suffix}.png`;
600 return `/assets/items/${key}/${state}${suffix}.png`;
596}
601}
shared/definitions/materialTiers.js +16 −2
@@ -148,7 +148,9 @@ export const GatherMaterialId = Object.freeze({
148 148 silver: "silver",
149 149 gold: "gold",
150 150 /** Smelted only: 1 gold ore + 1 silver ore + 3 coal → electrum bar. */
151 electrum: "electrum"
151 electrum: "electrum",
152 /** Rock-salt boulder; mines with a bronze pickaxe or better. */
153 salt: "salt"
152 154 });
153 155
154 156 /** Minimum relevant skill level required to equip tools/gear of this tier. */
@@ -205,6 +207,7 @@ export const TIER_RANK = Object.freeze({
205 207 [GatherMaterialId.silver]: 2,
206 208 [GatherMaterialId.gold]: 3,
207 209 [GatherMaterialId.electrum]: 7,
210 [GatherMaterialId.salt]: 1,
208 211 [GemTier.tourmaline]: 1,
209 212 [GemTier.alexandrite]: 2,
210 213 [GemTier.opal]: 3,
@@ -282,6 +285,7 @@ export const MATERIAL_DISPLAY_NAME = Object.freeze({
282 285 [GatherMaterialId.silver]: "Silver",
283 286 [GatherMaterialId.gold]: "Gold",
284 287 [GatherMaterialId.electrum]: "Electrum",
288 [GatherMaterialId.salt]: "Rock salt",
285 289 [GemTier.tourmaline]: "Tourmaline",
286 290 [GemTier.alexandrite]: "Alexandrite",
287 291 [GemTier.opal]: "Opal",
@@ -342,6 +346,8 @@ export const MATERIAL_TINT_HEX = Object.freeze({
342 346 [GatherMaterialId.silver]: rgb(214, 220, 230),
343 347 [GatherMaterialId.gold]: rgb(255, 200, 0),
344 348 [GatherMaterialId.electrum]: rgb(232, 198, 128),
349 /** Pale pinkish crystalline rock salt. */
350 [GatherMaterialId.salt]: rgb(228, 198, 186),
345 351 [GemTier.tourmaline]: rgb(200, 55, 120),
346 352 [GemTier.alexandrite]: rgb(120, 70, 180),
347 353 [GemTier.opal]: rgb(230, 210, 220),
@@ -378,7 +384,8 @@ export const MATERIAL_TINT_HEX = Object.freeze({
378 384 */
379 385 export const MATERIAL_ORE_TINT_HEX = Object.freeze({
380 386 [MaterialTier.iron]: rgb(210, 118, 48),
381 [GatherMaterialId.copper]: rgb(81, 153, 105)
387 [GatherMaterialId.copper]: rgb(81, 153, 105),
388 [GatherMaterialId.salt]: rgb(236, 205, 192)
382 389 });
383 390
384 391 /**
@@ -473,6 +480,8 @@ export function associatedBarTier (materialId)
473 480 { return MaterialTier.bronze; }
474 481 if (materialId === GatherMaterialId.coal)
475 482 { return MaterialTier.steel; }
483 if (materialId === GatherMaterialId.salt)
484 { return MaterialTier.bronze; }
476 485 const gemIdx = GEM_TIER_ORDER.indexOf(materialId);
477 486 if (gemIdx >= 0)
478 487 { return MATERIAL_TIER_ORDER[gemIdx] ?? MaterialTier.bronze; }
@@ -668,6 +677,7 @@ export const ORE_BEARING_MATERIALS = Object.freeze([
668 677 MaterialTier.orichalcum,
669 678 MaterialTier.dragon,
670 679 GatherMaterialId.coal,
680 GatherMaterialId.salt,
671 681 ...GEM_TIER_ORDER
672 682 ]);
673 683
@@ -676,6 +686,8 @@ export function oreBoulderState (materialId)
676 686 {
677 687 if (materialId === GatherMaterialId.coal)
678 688 { return "coal"; }
689 if (materialId === GatherMaterialId.salt)
690 { return "salt-ore"; }
679 691 return `${materialId}-ore`;
680 692 }
681 693
@@ -685,6 +697,8 @@ export function materialFromOreBoulderState (state)
685 697 { return null; }
686 698 if (state === "coal")
687 699 { return GatherMaterialId.coal; }
700 if (state === "salt-ore")
701 { return GatherMaterialId.salt; }
688 702 if (state.endsWith("-ore"))
689 703 {
690 704 const id = state.slice(0, -"-ore".length);
@@ -148,7 +148,9 @@ export const GatherMaterialId = Object.freeze({
148 silver: "silver",
148 silver: "silver",
149 gold: "gold",
149 gold: "gold",
150 /** Smelted only: 1 gold ore + 1 silver ore + 3 coal → electrum bar. */
150 /** Smelted only: 1 gold ore + 1 silver ore + 3 coal → electrum bar. */
151 electrum: "electrum"
151 electrum: "electrum",
152 /** Rock-salt boulder; mines with a bronze pickaxe or better. */
153 salt: "salt"
152});
154});
153
155
154/** Minimum relevant skill level required to equip tools/gear of this tier. */
156/** Minimum relevant skill level required to equip tools/gear of this tier. */
@@ -205,6 +207,7 @@ export const TIER_RANK = Object.freeze({
205 [GatherMaterialId.silver]: 2,
207 [GatherMaterialId.silver]: 2,
206 [GatherMaterialId.gold]: 3,
208 [GatherMaterialId.gold]: 3,
207 [GatherMaterialId.electrum]: 7,
209 [GatherMaterialId.electrum]: 7,
210 [GatherMaterialId.salt]: 1,
208 [GemTier.tourmaline]: 1,
211 [GemTier.tourmaline]: 1,
209 [GemTier.alexandrite]: 2,
212 [GemTier.alexandrite]: 2,
210 [GemTier.opal]: 3,
213 [GemTier.opal]: 3,
@@ -282,6 +285,7 @@ export const MATERIAL_DISPLAY_NAME = Object.freeze({
282 [GatherMaterialId.silver]: "Silver",
285 [GatherMaterialId.silver]: "Silver",
283 [GatherMaterialId.gold]: "Gold",
286 [GatherMaterialId.gold]: "Gold",
284 [GatherMaterialId.electrum]: "Electrum",
287 [GatherMaterialId.electrum]: "Electrum",
288 [GatherMaterialId.salt]: "Rock salt",
285 [GemTier.tourmaline]: "Tourmaline",
289 [GemTier.tourmaline]: "Tourmaline",
286 [GemTier.alexandrite]: "Alexandrite",
290 [GemTier.alexandrite]: "Alexandrite",
287 [GemTier.opal]: "Opal",
291 [GemTier.opal]: "Opal",
@@ -342,6 +346,8 @@ export const MATERIAL_TINT_HEX = Object.freeze({
342 [GatherMaterialId.silver]: rgb(214, 220, 230),
346 [GatherMaterialId.silver]: rgb(214, 220, 230),
343 [GatherMaterialId.gold]: rgb(255, 200, 0),
347 [GatherMaterialId.gold]: rgb(255, 200, 0),
344 [GatherMaterialId.electrum]: rgb(232, 198, 128),
348 [GatherMaterialId.electrum]: rgb(232, 198, 128),
349 /** Pale pinkish crystalline rock salt. */
350 [GatherMaterialId.salt]: rgb(228, 198, 186),
345 [GemTier.tourmaline]: rgb(200, 55, 120),
351 [GemTier.tourmaline]: rgb(200, 55, 120),
346 [GemTier.alexandrite]: rgb(120, 70, 180),
352 [GemTier.alexandrite]: rgb(120, 70, 180),
347 [GemTier.opal]: rgb(230, 210, 220),
353 [GemTier.opal]: rgb(230, 210, 220),
@@ -378,7 +384,8 @@ export const MATERIAL_TINT_HEX = Object.freeze({
378 */
384 */
379export const MATERIAL_ORE_TINT_HEX = Object.freeze({
385export const MATERIAL_ORE_TINT_HEX = Object.freeze({
380 [MaterialTier.iron]: rgb(210, 118, 48),
386 [MaterialTier.iron]: rgb(210, 118, 48),
381 [GatherMaterialId.copper]: rgb(81, 153, 105)
387 [GatherMaterialId.copper]: rgb(81, 153, 105),
388 [GatherMaterialId.salt]: rgb(236, 205, 192)
382});
389});
383
390
384/**
391/**
@@ -473,6 +480,8 @@ export function associatedBarTier (materialId)
473 { return MaterialTier.bronze; }
480 { return MaterialTier.bronze; }
474 if (materialId === GatherMaterialId.coal)
481 if (materialId === GatherMaterialId.coal)
475 { return MaterialTier.steel; }
482 { return MaterialTier.steel; }
483 if (materialId === GatherMaterialId.salt)
484 { return MaterialTier.bronze; }
476 const gemIdx = GEM_TIER_ORDER.indexOf(materialId);
485 const gemIdx = GEM_TIER_ORDER.indexOf(materialId);
477 if (gemIdx >= 0)
486 if (gemIdx >= 0)
478 { return MATERIAL_TIER_ORDER[gemIdx] ?? MaterialTier.bronze; }
487 { return MATERIAL_TIER_ORDER[gemIdx] ?? MaterialTier.bronze; }
@@ -668,6 +677,7 @@ export const ORE_BEARING_MATERIALS = Object.freeze([
668 MaterialTier.orichalcum,
677 MaterialTier.orichalcum,
669 MaterialTier.dragon,
678 MaterialTier.dragon,
670 GatherMaterialId.coal,
679 GatherMaterialId.coal,
680 GatherMaterialId.salt,
671 ...GEM_TIER_ORDER
681 ...GEM_TIER_ORDER
672]);
682]);
673
683
@@ -676,6 +686,8 @@ export function oreBoulderState (materialId)
676{
686{
677 if (materialId === GatherMaterialId.coal)
687 if (materialId === GatherMaterialId.coal)
678 { return "coal"; }
688 { return "coal"; }
689 if (materialId === GatherMaterialId.salt)
690 { return "salt-ore"; }
679 return `${materialId}-ore`;
691 return `${materialId}-ore`;
680}
692}
681
693
@@ -685,6 +697,8 @@ export function materialFromOreBoulderState (state)
685 { return null; }
697 { return null; }
686 if (state === "coal")
698 if (state === "coal")
687 { return GatherMaterialId.coal; }
699 { return GatherMaterialId.coal; }
700 if (state === "salt-ore")
701 { return GatherMaterialId.salt; }
688 if (state.endsWith("-ore"))
702 if (state.endsWith("-ore"))
689 {
703 {
690 const id = state.slice(0, -"-ore".length);
704 const id = state.slice(0, -"-ore".length);
shared/definitions/woodItems.js +65 −2
@@ -42,7 +42,14 @@ export const WoodItemId = Object.freeze({
42 42 ebonyAsh: 284,
43 43 lignumAsh: 285,
44 44 heartwoodAsh: 286,
45 elderAsh: 287
45 elderAsh: 287,
46 pineBark: 582,
47 birchBark: 583,
48 oakBark: 584,
49 ebonyBark: 585,
50 lignumBark: 586,
51 heartwoodBark: 587,
52 elderBark: 588
46 53 });
47 54
48 55 const LOG_IDS = Object.freeze({
@@ -85,10 +92,21 @@ const ASH_IDS = Object.freeze({
85 92 [WoodTier.elder]: WoodItemId.elderAsh
86 93 });
87 94
95 const BARK_IDS = Object.freeze({
96 [WoodTier.pine]: WoodItemId.pineBark,
97 [WoodTier.birch]: WoodItemId.birchBark,
98 [WoodTier.oak]: WoodItemId.oakBark,
99 [WoodTier.ebony]: WoodItemId.ebonyBark,
100 [WoodTier.lignum]: WoodItemId.lignumBark,
101 [WoodTier.heartwood]: WoodItemId.heartwoodBark,
102 [WoodTier.elder]: WoodItemId.elderBark
103 });
104
88 105 export const LOG_ITEM_BY_WOOD = LOG_IDS;
89 106 export const HANDLE_ITEM_BY_WOOD = HANDLE_IDS;
90 107 export const QUARTERSTAFF_ITEM_BY_WOOD = QUARTERSTAFF_IDS;
91 108 export const ASH_ITEM_BY_WOOD = ASH_IDS;
109 export const BARK_ITEM_BY_WOOD = BARK_IDS;
92 110
93 111 export function logItemIdForWood (woodTier)
94 112 {
@@ -110,6 +128,23 @@ export function ashItemIdForWood (woodTier)
110 128 return itemIdForFamilyTier(ASH_IDS, woodTier);
111 129 }
112 130
131 export function barkItemIdForWood (woodTier)
132 {
133 return itemIdForFamilyTier(BARK_IDS, woodTier);
134 }
135
136 /** Instance flag on a wood log after bark has been stripped. Survives bag/ground/pigeon/CE. */
137 export function debarkedLogInstance ()
138 {
139 return { kind: "log", debarked: true };
140 }
141
142 export function isLogDebarked (stackOrInstance)
143 {
144 const instance = stackOrInstance?.instance ?? stackOrInstance;
145 return instance?.kind === "log" && !!instance.debarked;
146 }
147
113 148 function ashDefinitions ()
114 149 {
115 150 const out = {};
@@ -137,10 +172,38 @@ function ashDefinitions ()
137 172 return out;
138 173 }
139 174
175 function barkDefinitions ()
176 {
177 const out = {};
178 for (const woodTier of WOOD_TIER_ORDER)
179 {
180 const itemId = BARK_IDS[woodTier];
181 const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
182 out[itemId] = Object.freeze({
183 itemId,
184 key: `${woodTier}-bark`,
185 displayName: `${name} bark`,
186 description: `Rough ${name.toLowerCase()} bark, peeled from a log.`,
187 seedValue: 1,
188 stackable: true,
189 maxStackSize: 99,
190 uniqueInstance: false,
191 category: ItemCategory.ingredient,
192 iconKey: "wood",
193 defaultState: "bark",
194 tier: woodTier,
195 tintFromTier: true,
196 npcShopAllowed: true
197 });
198 }
199 return out;
200 }
201
140 202 /** Full defs for wood family (merged into ITEM_DEFINITIONS). */
141 203 export const WOOD_ITEM_DEFINITIONS = Object.freeze({
142 204 ...buildFamilyDefinitionMap(ItemFamilyId.log, LOG_IDS),
143 205 ...buildFamilyDefinitionMap(ItemFamilyId.handle, HANDLE_IDS),
144 206 ...buildFamilyDefinitionMap(ItemFamilyId.quarterstaff, QUARTERSTAFF_IDS),
145 ...ashDefinitions()
207 ...ashDefinitions(),
208 ...barkDefinitions()
146 209 });
@@ -42,7 +42,14 @@ export const WoodItemId = Object.freeze({
42 ebonyAsh: 284,
42 ebonyAsh: 284,
43 lignumAsh: 285,
43 lignumAsh: 285,
44 heartwoodAsh: 286,
44 heartwoodAsh: 286,
45 elderAsh: 287
45 elderAsh: 287,
46 pineBark: 582,
47 birchBark: 583,
48 oakBark: 584,
49 ebonyBark: 585,
50 lignumBark: 586,
51 heartwoodBark: 587,
52 elderBark: 588
46});
53});
47
54
48const LOG_IDS = Object.freeze({
55const LOG_IDS = Object.freeze({
@@ -85,10 +92,21 @@ const ASH_IDS = Object.freeze({
85 [WoodTier.elder]: WoodItemId.elderAsh
92 [WoodTier.elder]: WoodItemId.elderAsh
86});
93});
87
94
95const BARK_IDS = Object.freeze({
96 [WoodTier.pine]: WoodItemId.pineBark,
97 [WoodTier.birch]: WoodItemId.birchBark,
98 [WoodTier.oak]: WoodItemId.oakBark,
99 [WoodTier.ebony]: WoodItemId.ebonyBark,
100 [WoodTier.lignum]: WoodItemId.lignumBark,
101 [WoodTier.heartwood]: WoodItemId.heartwoodBark,
102 [WoodTier.elder]: WoodItemId.elderBark
103});
104
88export const LOG_ITEM_BY_WOOD = LOG_IDS;
105export const LOG_ITEM_BY_WOOD = LOG_IDS;
89export const HANDLE_ITEM_BY_WOOD = HANDLE_IDS;
106export const HANDLE_ITEM_BY_WOOD = HANDLE_IDS;
90export const QUARTERSTAFF_ITEM_BY_WOOD = QUARTERSTAFF_IDS;
107export const QUARTERSTAFF_ITEM_BY_WOOD = QUARTERSTAFF_IDS;
91export const ASH_ITEM_BY_WOOD = ASH_IDS;
108export const ASH_ITEM_BY_WOOD = ASH_IDS;
109export const BARK_ITEM_BY_WOOD = BARK_IDS;
92
110
93export function logItemIdForWood (woodTier)
111export function logItemIdForWood (woodTier)
94{
112{
@@ -110,6 +128,23 @@ export function ashItemIdForWood (woodTier)
110 return itemIdForFamilyTier(ASH_IDS, woodTier);
128 return itemIdForFamilyTier(ASH_IDS, woodTier);
111}
129}
112
130
131export function barkItemIdForWood (woodTier)
132{
133 return itemIdForFamilyTier(BARK_IDS, woodTier);
134}
135
136/** Instance flag on a wood log after bark has been stripped. Survives bag/ground/pigeon/CE. */
137export function debarkedLogInstance ()
138{
139 return { kind: "log", debarked: true };
140}
141
142export function isLogDebarked (stackOrInstance)
143{
144 const instance = stackOrInstance?.instance ?? stackOrInstance;
145 return instance?.kind === "log" && !!instance.debarked;
146}
147
113function ashDefinitions ()
148function ashDefinitions ()
114{
149{
115 const out = {};
150 const out = {};
@@ -137,10 +172,38 @@ function ashDefinitions ()
137 return out;
172 return out;
138}
173}
139
174
175function barkDefinitions ()
176{
177 const out = {};
178 for (const woodTier of WOOD_TIER_ORDER)
179 {
180 const itemId = BARK_IDS[woodTier];
181 const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
182 out[itemId] = Object.freeze({
183 itemId,
184 key: `${woodTier}-bark`,
185 displayName: `${name} bark`,
186 description: `Rough ${name.toLowerCase()} bark, peeled from a log.`,
187 seedValue: 1,
188 stackable: true,
189 maxStackSize: 99,
190 uniqueInstance: false,
191 category: ItemCategory.ingredient,
192 iconKey: "wood",
193 defaultState: "bark",
194 tier: woodTier,
195 tintFromTier: true,
196 npcShopAllowed: true
197 });
198 }
199 return out;
200}
201
140/** Full defs for wood family (merged into ITEM_DEFINITIONS). */
202/** Full defs for wood family (merged into ITEM_DEFINITIONS). */
141export const WOOD_ITEM_DEFINITIONS = Object.freeze({
203export const WOOD_ITEM_DEFINITIONS = Object.freeze({
142 ...buildFamilyDefinitionMap(ItemFamilyId.log, LOG_IDS),
204 ...buildFamilyDefinitionMap(ItemFamilyId.log, LOG_IDS),
143 ...buildFamilyDefinitionMap(ItemFamilyId.handle, HANDLE_IDS),
205 ...buildFamilyDefinitionMap(ItemFamilyId.handle, HANDLE_IDS),
144 ...buildFamilyDefinitionMap(ItemFamilyId.quarterstaff, QUARTERSTAFF_IDS),
206 ...buildFamilyDefinitionMap(ItemFamilyId.quarterstaff, QUARTERSTAFF_IDS),
145 ...ashDefinitions()
207 ...ashDefinitions(),
208 ...barkDefinitions()
146});
209});
shared/items/charges.js +11 −0
@@ -84,6 +84,17 @@ export function isFillWorn (stack)
84 84 return (stack.instance.fillLevel | 0) < full;
85 85 }
86 86
87 /** True when a potion bottle is still at its bottled fill (safe as a cauldron ingredient). */
88 export function isFullPotionBottle (stack)
89 {
90 if (stack?.instance?.kind !== "potion")
91 { return false; }
92 const full = bottleFullFillLevel(stack.instance);
93 if (full == null)
94 { return false; }
95 return (stack.instance.fillLevel | 0) >= full;
96 }
97
87 98 /** Any partially consumed charge tool, potion, or dye — unsafe for blind CE matching. */
88 99 export function isPartiallyConsumed (stack)
89 100 {
@@ -84,6 +84,17 @@ export function isFillWorn (stack)
84 return (stack.instance.fillLevel | 0) < full;
84 return (stack.instance.fillLevel | 0) < full;
85}
85}
86
86
87/** True when a potion bottle is still at its bottled fill (safe as a cauldron ingredient). */
88export function isFullPotionBottle (stack)
89{
90 if (stack?.instance?.kind !== "potion")
91 { return false; }
92 const full = bottleFullFillLevel(stack.instance);
93 if (full == null)
94 { return false; }
95 return (stack.instance.fillLevel | 0) >= full;
96}
97
87/** Any partially consumed charge tool, potion, or dye — unsafe for blind CE matching. */
98/** Any partially consumed charge tool, potion, or dye — unsafe for blind CE matching. */
88export function isPartiallyConsumed (stack)
99export function isPartiallyConsumed (stack)
89{
100{
shared/protocol/constants.js +1 −0
@@ -188,6 +188,7 @@ export const MessageType = Object.freeze({
188 188 tipArrows: "TIP_ARROWS",
189 189 startCraft: "START_CRAFT",
190 190 startFire: "START_FIRE",
191 debarkLog: "DEBARK_LOG",
191 192 startFish: "START_FISH",
192 193 shear: "SHEAR",
193 194 cancelCraft: "CANCEL_CRAFT",
@@ -188,6 +188,7 @@ export const MessageType = Object.freeze({
188 tipArrows: "TIP_ARROWS",
188 tipArrows: "TIP_ARROWS",
189 startCraft: "START_CRAFT",
189 startCraft: "START_CRAFT",
190 startFire: "START_FIRE",
190 startFire: "START_FIRE",
191 debarkLog: "DEBARK_LOG",
191 startFish: "START_FISH",
192 startFish: "START_FISH",
192 shear: "SHEAR",
193 shear: "SHEAR",
193 cancelCraft: "CANCEL_CRAFT",
194 cancelCraft: "CANCEL_CRAFT",
shared/statusEffects/display.js +10 −0
@@ -25,6 +25,16 @@ export const STATUS_EFFECT_DISPLAY = Object.freeze({
25 25 return `Loses ${rate} health each second.`;
26 26 }
27 27 }),
28 [StatusEffectType.foodPoisoning]: Object.freeze({
29 iconKey: "stamina-drain",
30 title: "Food Poisoning",
31 polarity: "debuff",
32 describe (effect)
33 {
34 const rate = Number(effect?.amountPerSecond) || 1;
35 return `Loses ${rate} health each second.`;
36 }
37 }),
28 38 [StatusEffectType.staminaRegen]: Object.freeze({
29 39 iconKey: "stamina-regen",
30 40 title: "Stamina regeneration",
@@ -25,6 +25,16 @@ export const STATUS_EFFECT_DISPLAY = Object.freeze({
25 return `Loses ${rate} health each second.`;
25 return `Loses ${rate} health each second.`;
26 }
26 }
27 }),
27 }),
28 [StatusEffectType.foodPoisoning]: Object.freeze({
29 iconKey: "stamina-drain",
30 title: "Food Poisoning",
31 polarity: "debuff",
32 describe (effect)
33 {
34 const rate = Number(effect?.amountPerSecond) || 1;
35 return `Loses ${rate} health each second.`;
36 }
37 }),
28 [StatusEffectType.staminaRegen]: Object.freeze({
38 [StatusEffectType.staminaRegen]: Object.freeze({
29 iconKey: "stamina-regen",
39 iconKey: "stamina-regen",
30 title: "Stamina regeneration",
40 title: "Stamina regeneration",
shared/statusEffects/rules.js +3 −0
@@ -6,6 +6,8 @@
6 6 export const StatusEffectType = Object.freeze({
7 7 healthRegen: "health-regen",
8 8 healthDrain: "health-drain",
9 /** Same drain tick as health-drain; distinct HUD title for spoiled/undrinkable food. */
10 foodPoisoning: "food-poisoning",
9 11 staminaRegen: "stamina-regen",
10 12 strengthBonus: "strength-bonus",
11 13 mindBonus: "mind-bonus",
@@ -21,6 +23,7 @@ const EXTEND_TYPES = new Set([
21 23 StatusEffectType.healthRegen,
22 24 StatusEffectType.staminaRegen,
23 25 StatusEffectType.healthDrain,
26 StatusEffectType.foodPoisoning,
24 27 StatusEffectType.staminaDrain,
25 28 StatusEffectType.staminaBlock
26 29 ]);
@@ -6,6 +6,8 @@
6export const StatusEffectType = Object.freeze({
6export const StatusEffectType = Object.freeze({
7 healthRegen: "health-regen",
7 healthRegen: "health-regen",
8 healthDrain: "health-drain",
8 healthDrain: "health-drain",
9 /** Same drain tick as health-drain; distinct HUD title for spoiled/undrinkable food. */
10 foodPoisoning: "food-poisoning",
9 staminaRegen: "stamina-regen",
11 staminaRegen: "stamina-regen",
10 strengthBonus: "strength-bonus",
12 strengthBonus: "strength-bonus",
11 mindBonus: "mind-bonus",
13 mindBonus: "mind-bonus",
@@ -21,6 +23,7 @@ const EXTEND_TYPES = new Set([
21 StatusEffectType.healthRegen,
23 StatusEffectType.healthRegen,
22 StatusEffectType.staminaRegen,
24 StatusEffectType.staminaRegen,
23 StatusEffectType.healthDrain,
25 StatusEffectType.healthDrain,
26 StatusEffectType.foodPoisoning,
24 StatusEffectType.staminaDrain,
27 StatusEffectType.staminaDrain,
25 StatusEffectType.staminaBlock
28 StatusEffectType.staminaBlock
26]);
29]);