BlueGit

timfa questward

Merge branch 'feature/tanning-brew-potion'

timfa Tim Falken · pushed by timfa

Authored 2026-09-04 · 2 months ago

Hash
be5ccd33e57e699bbd2fa996bf559a262958c15f
12 files changed +269 −23
client/assets/mobs/chicken/chicken.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/mobs/deer/deer.png Binary file +0 −0

The contents of this binary file are not shown.

client/src/play/crafting.js +44 −0
@@ -22,6 +22,12 @@ import
22 22 resolveDyeDisplayStack
23 23 } from "/shared/crafting/dye.js";
24 24 import
25 {
26 potionKeyDisplayName,
27 potionStacksForKey
28 } from "/shared/crafting/potionCharge.js";
29 import { stackQuantity } from "/shared/items/inventory.js";
30 import
25 31 {
26 32 CLOTH_TIER_ORDER,
27 33 CLOTH_DISPLAY_NAME,
@@ -518,6 +524,10 @@ export function initCrafting ({
518 524 : "Dye — none selected";
519 525 inputsList.append(row);
520 526 }
527 if (recipe.consumePotionKey)
528 {
529 inputsList.append(renderPotionChargeRow(recipe.consumePotionKey, slots));
530 }
521 531
522 532 if (dyePreview && dyeClearBtn)
523 533 {
@@ -558,6 +568,36 @@ export function initCrafting ({
558 568 return row;
559 569 }
560 570
571 function renderPotionChargeRow (potionKey, slots)
572 {
573 const matches = potionStacksForKey(slots, potionKey);
574 const totalFill = matches.reduce((sum, entry) => sum + entry.fill * stackQuantity(entry.stack.quantity), 0);
575 const label = potionKeyDisplayName(potionKey);
576 const sample = matches[0]?.stack ?? {
577 itemId: ItemId.potion,
578 quantity: 1,
579 instance: {
580 kind: "potion",
581 potionKey,
582 displayName: label,
583 fillLevel: 4
584 }
585 };
586 const row = document.createElement("li");
587 row.className = "craft-input-row";
588 if (totalFill < 1)
589 { row.classList.add("short"); }
590 const img = document.createElement("img");
591 img.alt = label;
592 applyItemIcon(img, sample, itemAssetPathForStack(sample));
593 const text = document.createElement("span");
594 text.textContent = totalFill >= 1
595 ? `${label} — 1 use (${totalFill} left)`
596 : `${label} — none`;
597 row.append(img, text);
598 return row;
599 }
600
561 601 function updateCraftState (slots, recipe)
562 602 {
563 603 // Recipe craft UI (not alchemy): always offer Craft 1 / Craft x / Craft all.
@@ -610,6 +650,10 @@ export function initCrafting ({
610 650 {
611 651 statusEl.textContent = "Not enough bag space (need room for the result or a partially used dye).";
612 652 }
653 else if (recipe.consumePotionKey)
654 {
655 statusEl.textContent = "Not enough bag space (need room for the result or a partially used brew).";
656 }
613 657 else
614 658 {
615 659 statusEl.textContent = "Not enough bag space for the result.";
@@ -22,6 +22,12 @@ import
22 resolveDyeDisplayStack
22 resolveDyeDisplayStack
23} from "/shared/crafting/dye.js";
23} from "/shared/crafting/dye.js";
24import
24import
25{
26 potionKeyDisplayName,
27 potionStacksForKey
28} from "/shared/crafting/potionCharge.js";
29import { stackQuantity } from "/shared/items/inventory.js";
30import
25{
31{
26 CLOTH_TIER_ORDER,
32 CLOTH_TIER_ORDER,
27 CLOTH_DISPLAY_NAME,
33 CLOTH_DISPLAY_NAME,
@@ -518,6 +524,10 @@ export function initCrafting ({
518 : "Dye — none selected";
524 : "Dye — none selected";
519 inputsList.append(row);
525 inputsList.append(row);
520 }
526 }
527 if (recipe.consumePotionKey)
528 {
529 inputsList.append(renderPotionChargeRow(recipe.consumePotionKey, slots));
530 }
521
531
522 if (dyePreview && dyeClearBtn)
532 if (dyePreview && dyeClearBtn)
523 {
533 {
@@ -558,6 +568,36 @@ export function initCrafting ({
558 return row;
568 return row;
559 }
569 }
560
570
571 function renderPotionChargeRow (potionKey, slots)
572 {
573 const matches = potionStacksForKey(slots, potionKey);
574 const totalFill = matches.reduce((sum, entry) => sum + entry.fill * stackQuantity(entry.stack.quantity), 0);
575 const label = potionKeyDisplayName(potionKey);
576 const sample = matches[0]?.stack ?? {
577 itemId: ItemId.potion,
578 quantity: 1,
579 instance: {
580 kind: "potion",
581 potionKey,
582 displayName: label,
583 fillLevel: 4
584 }
585 };
586 const row = document.createElement("li");
587 row.className = "craft-input-row";
588 if (totalFill < 1)
589 { row.classList.add("short"); }
590 const img = document.createElement("img");
591 img.alt = label;
592 applyItemIcon(img, sample, itemAssetPathForStack(sample));
593 const text = document.createElement("span");
594 text.textContent = totalFill >= 1
595 ? `${label} — 1 use (${totalFill} left)`
596 : `${label} — none`;
597 row.append(img, text);
598 return row;
599 }
600
561 function updateCraftState (slots, recipe)
601 function updateCraftState (slots, recipe)
562 {
602 {
563 // Recipe craft UI (not alchemy): always offer Craft 1 / Craft x / Craft all.
603 // Recipe craft UI (not alchemy): always offer Craft 1 / Craft x / Craft all.
@@ -610,6 +650,10 @@ export function initCrafting ({
610 {
650 {
611 statusEl.textContent = "Not enough bag space (need room for the result or a partially used dye).";
651 statusEl.textContent = "Not enough bag space (need room for the result or a partially used dye).";
612 }
652 }
653 else if (recipe.consumePotionKey)
654 {
655 statusEl.textContent = "Not enough bag space (need room for the result or a partially used brew).";
656 }
613 else
657 else
614 {
658 {
615 statusEl.textContent = "Not enough bag space for the result.";
659 statusEl.textContent = "Not enough bag space for the result.";
server/src/crafting/service.js +43 −0
@@ -13,6 +13,7 @@ import
13 13 } from "../../../shared/crafting/recipes.js";
14 14 import { resolveTailorCraft } from "../../../shared/crafting/tailor.js";
15 15 import { pickEmptiestDyeSlot } from "../../../shared/crafting/dye.js";
16 import { pickEmptiestPotionSlot } from "../../../shared/crafting/potionCharge.js";
16 17 import { dyeColorKey as dyeInstanceColorKey } from "../../../shared/definitions/dyes.js";
17 18 import { craftDurationMs, craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";
18 19 import { takeFromSlot, insertStack, stackQuantity, consumeFillCharge } from "../../../shared/items/inventory.js";
@@ -137,6 +138,16 @@ function consumeDyeUse (slots, slotIndex)
137 138 });
138 139 }
139 140
141 /** Spend one fill of a potion bottle; exhausted bottles become empty glass. */
142 function consumePotionUse (slots, slotIndex)
143 {
144 return consumeFillCharge(slots, slotIndex, {
145 kind: "potion",
146 itemId: ItemId.potion,
147 returnEmptyItemId: ItemId.glassBottle
148 });
149 }
150
140 151 export function startCraft (world, sessionId, characterId, stationId, recipeId, now, options = {})
141 152 {
142 153 const entityId = world.characterEntities.get(characterId);
@@ -210,6 +221,13 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
210 221 if (!dyeProbe.ok)
211 222 { throw userError("Need bag space to separate the partially used dye."); }
212 223 }
224 if (recipe.consumePotionKey)
225 {
226 const probeSlot = pickEmptiestPotionSlot(inventory?.slots ?? [], recipe.consumePotionKey);
227 const potionProbe = consumePotionUse(inventory?.slots ?? [], probeSlot);
228 if (!potionProbe.ok)
229 { throw userError("Need bag space to separate the partially used brew."); }
230 }
213 231 throw userError("Not enough bag space for the result.");
214 232 }
215 233 if (recipe.consumeDye && dyeColorKey != null)
@@ -219,6 +237,12 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
219 237 if (!dye || dye.itemId !== ItemId.dye)
220 238 { throw userError("Selected dye is missing."); }
221 239 }
240 if (recipe.consumePotionKey)
241 {
242 const probeSlot = pickEmptiestPotionSlot(inventory?.slots ?? [], recipe.consumePotionKey);
243 if (probeSlot == null)
244 { throw userError("Missing materials."); }
245 }
222 246
223 247 const sessions = ensureCraftSessions(world);
224 248 const equipment = world.ecs.get(handle, Component.equipment);
@@ -396,6 +420,25 @@ export function stepCrafting (world, now)
396 420 }
397 421 slotsAfter = dyeTaken.slots;
398 422 }
423 if (recipe.consumePotionKey)
424 {
425 const consumeSlot = pickEmptiestPotionSlot(slotsAfter, recipe.consumePotionKey);
426 const potionTaken = consumePotionUse(slotsAfter, consumeSlot);
427 if (!potionTaken.ok)
428 {
429 events.push({
430 type: "craft-result",
431 sessionId: session.sessionId,
432 recipeId: session.recipeId,
433 ok: false,
434 error: potionTaken.reason === "space"
435 ? "Need bag space to separate the partially used brew."
436 : "Missing materials."
437 });
438 continue;
439 }
440 slotsAfter = potionTaken.slots;
441 }
399 442
400 443 const burnChance = cookBurnChance(session.stationId);
401 444 const burned = burnChance > 0
@@ -13,6 +13,7 @@ import
13} from "../../../shared/crafting/recipes.js";
13} from "../../../shared/crafting/recipes.js";
14import { resolveTailorCraft } from "../../../shared/crafting/tailor.js";
14import { resolveTailorCraft } from "../../../shared/crafting/tailor.js";
15import { pickEmptiestDyeSlot } from "../../../shared/crafting/dye.js";
15import { pickEmptiestDyeSlot } from "../../../shared/crafting/dye.js";
16import { pickEmptiestPotionSlot } from "../../../shared/crafting/potionCharge.js";
16import { dyeColorKey as dyeInstanceColorKey } from "../../../shared/definitions/dyes.js";
17import { dyeColorKey as dyeInstanceColorKey } from "../../../shared/definitions/dyes.js";
17import { craftDurationMs, craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";
18import { craftDurationMs, craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";
18import { takeFromSlot, insertStack, stackQuantity, consumeFillCharge } from "../../../shared/items/inventory.js";
19import { takeFromSlot, insertStack, stackQuantity, consumeFillCharge } from "../../../shared/items/inventory.js";
@@ -137,6 +138,16 @@ function consumeDyeUse (slots, slotIndex)
137 });
138 });
138}
139}
139
140
141/** Spend one fill of a potion bottle; exhausted bottles become empty glass. */
142function consumePotionUse (slots, slotIndex)
143{
144 return consumeFillCharge(slots, slotIndex, {
145 kind: "potion",
146 itemId: ItemId.potion,
147 returnEmptyItemId: ItemId.glassBottle
148 });
149}
150
140export function startCraft (world, sessionId, characterId, stationId, recipeId, now, options = {})
151export function startCraft (world, sessionId, characterId, stationId, recipeId, now, options = {})
141{
152{
142 const entityId = world.characterEntities.get(characterId);
153 const entityId = world.characterEntities.get(characterId);
@@ -210,6 +221,13 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
210 if (!dyeProbe.ok)
221 if (!dyeProbe.ok)
211 { throw userError("Need bag space to separate the partially used dye."); }
222 { throw userError("Need bag space to separate the partially used dye."); }
212 }
223 }
224 if (recipe.consumePotionKey)
225 {
226 const probeSlot = pickEmptiestPotionSlot(inventory?.slots ?? [], recipe.consumePotionKey);
227 const potionProbe = consumePotionUse(inventory?.slots ?? [], probeSlot);
228 if (!potionProbe.ok)
229 { throw userError("Need bag space to separate the partially used brew."); }
230 }
213 throw userError("Not enough bag space for the result.");
231 throw userError("Not enough bag space for the result.");
214 }
232 }
215 if (recipe.consumeDye && dyeColorKey != null)
233 if (recipe.consumeDye && dyeColorKey != null)
@@ -219,6 +237,12 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
219 if (!dye || dye.itemId !== ItemId.dye)
237 if (!dye || dye.itemId !== ItemId.dye)
220 { throw userError("Selected dye is missing."); }
238 { throw userError("Selected dye is missing."); }
221 }
239 }
240 if (recipe.consumePotionKey)
241 {
242 const probeSlot = pickEmptiestPotionSlot(inventory?.slots ?? [], recipe.consumePotionKey);
243 if (probeSlot == null)
244 { throw userError("Missing materials."); }
245 }
222
246
223 const sessions = ensureCraftSessions(world);
247 const sessions = ensureCraftSessions(world);
224 const equipment = world.ecs.get(handle, Component.equipment);
248 const equipment = world.ecs.get(handle, Component.equipment);
@@ -396,6 +420,25 @@ export function stepCrafting (world, now)
396 }
420 }
397 slotsAfter = dyeTaken.slots;
421 slotsAfter = dyeTaken.slots;
398 }
422 }
423 if (recipe.consumePotionKey)
424 {
425 const consumeSlot = pickEmptiestPotionSlot(slotsAfter, recipe.consumePotionKey);
426 const potionTaken = consumePotionUse(slotsAfter, consumeSlot);
427 if (!potionTaken.ok)
428 {
429 events.push({
430 type: "craft-result",
431 sessionId: session.sessionId,
432 recipeId: session.recipeId,
433 ok: false,
434 error: potionTaken.reason === "space"
435 ? "Need bag space to separate the partially used brew."
436 : "Missing materials."
437 });
438 continue;
439 }
440 slotsAfter = potionTaken.slots;
441 }
399
442
400 const burnChance = cookBurnChance(session.stationId);
443 const burnChance = cookBurnChance(session.stationId);
401 const burned = burnChance > 0
444 const burned = burnChance > 0
server/tests/crafting.test.js +85 −1
@@ -59,7 +59,11 @@ function giveInventory (harness, playerId, items)
59 59 const inventory = emptySlots();
60 60 items.forEach((stack, index) =>
61 61 {
62 inventory[index] = { itemId: stack.itemId, quantity: stack.quantity };
62 inventory[index] = {
63 itemId: stack.itemId,
64 quantity: stack.quantity,
65 ...(stack.instance ? { instance: structuredClone(stack.instance) } : {})
66 };
63 67 });
64 68 harness.simulation.applyBag(playerId, {
65 69 inventory,
@@ -214,6 +218,86 @@ test("open leatherworking table near station emits station-open", () =>
214 218 { harness.close(); }
215 219 });
216 220
221 test("hard leather craft spends one tanning brew fill and returns empty glass when exhausted", () =>
222 {
223 const harness = makeSimulation({ workerCount: 1 });
224 try
225 {
226 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
227 const playerId = harness.simulation.spawnCharacter(1, character);
228 const record = harness.simulation.entityRecord(playerId);
229 const worker = harness.simulation.workers[record.workerId];
230 const data = worker.world.chunkData(0, 0);
231 data.blocks[8 * 16 + 9] = {
232 typeId: BlockType.leatherworkingTable,
233 state: "leatherworking-table",
234 config: null
235 };
236 setSkillLevel(worker, playerId, SkillId.leatherworking, 10);
237 giveInventory(harness, playerId, [
238 { itemId: LeatherItemId.softLeather, quantity: 2 },
239 {
240 itemId: ItemId.potion,
241 quantity: 1,
242 instance: {
243 kind: "potion",
244 potionKey: "tanningBrew",
245 displayName: "Tanning brew",
246 fillLevel: 2,
247 effect: { type: "food-poisoning", amountPerSecond: 1, durationMs: 10_000 },
248 effectKey: "food-poisoning"
249 }
250 }
251 ]);
252
253 const hard = recipeDefinition("leather-hard");
254 assert.equal(hard.consumePotionKey, "tanningBrew");
255 assert.deepEqual(hard.inputs, [{ itemId: LeatherItemId.softLeather, quantity: 1 }]);
256
257 harness.simulation.enqueue(1, {
258 type: "start-craft",
259 characterId: character.character_id,
260 stationId: CraftingStationId.leatherworkingStation,
261 recipeId: "leather-hard"
262 });
263 harness.simulation.step();
264 const hardDuration = craftDurationMs(hard, CRAFT_DURATION_MS);
265 advanceMs(harness, hardDuration);
266
267 let bag = harness.simulation.bagOf(playerId);
268 assert.equal(countItem(bag.inventory, LeatherItemId.hardLeather), 1);
269 assert.equal(countItem(bag.inventory, LeatherItemId.softLeather), 1);
270 const brew = bag.inventory.find((slot) =>
271 slot?.itemId === ItemId.potion && slot.instance?.potionKey === "tanningBrew"
272 );
273 assert.ok(brew);
274 assert.equal(brew.instance.fillLevel, 1);
275 assert.equal(countItem(bag.inventory, ItemId.glassBottle), 0);
276
277 harness.simulation.enqueue(1, {
278 type: "start-craft",
279 characterId: character.character_id,
280 stationId: CraftingStationId.leatherworkingStation,
281 recipeId: "leather-hard"
282 });
283 harness.simulation.step();
284 advanceMs(harness, hardDuration);
285
286 bag = harness.simulation.bagOf(playerId);
287 assert.equal(countItem(bag.inventory, LeatherItemId.hardLeather), 2);
288 assert.equal(countItem(bag.inventory, LeatherItemId.softLeather), 0);
289 assert.equal(
290 bag.inventory.some((slot) =>
291 slot?.itemId === ItemId.potion && slot.instance?.potionKey === "tanningBrew"
292 ),
293 false
294 );
295 assert.equal(countItem(bag.inventory, ItemId.glassBottle), 1);
296 }
297 finally
298 { harness.close(); }
299 });
300
217 301 test("smelting bronze consumes tin and copper, grants bar and Smithing XP", () =>
218 302 {
219 303 const harness = makeSimulation({ workerCount: 1 });
@@ -59,7 +59,11 @@ function giveInventory (harness, playerId, items)
59 const inventory = emptySlots();
59 const inventory = emptySlots();
60 items.forEach((stack, index) =>
60 items.forEach((stack, index) =>
61 {
61 {
62 inventory[index] = { itemId: stack.itemId, quantity: stack.quantity };
62 inventory[index] = {
63 itemId: stack.itemId,
64 quantity: stack.quantity,
65 ...(stack.instance ? { instance: structuredClone(stack.instance) } : {})
66 };
63 });
67 });
64 harness.simulation.applyBag(playerId, {
68 harness.simulation.applyBag(playerId, {
65 inventory,
69 inventory,
@@ -214,6 +218,86 @@ test("open leatherworking table near station emits station-open", () =>
214 { harness.close(); }
218 { harness.close(); }
215});
219});
216
220
221test("hard leather craft spends one tanning brew fill and returns empty glass when exhausted", () =>
222{
223 const harness = makeSimulation({ workerCount: 1 });
224 try
225 {
226 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
227 const playerId = harness.simulation.spawnCharacter(1, character);
228 const record = harness.simulation.entityRecord(playerId);
229 const worker = harness.simulation.workers[record.workerId];
230 const data = worker.world.chunkData(0, 0);
231 data.blocks[8 * 16 + 9] = {
232 typeId: BlockType.leatherworkingTable,
233 state: "leatherworking-table",
234 config: null
235 };
236 setSkillLevel(worker, playerId, SkillId.leatherworking, 10);
237 giveInventory(harness, playerId, [
238 { itemId: LeatherItemId.softLeather, quantity: 2 },
239 {
240 itemId: ItemId.potion,
241 quantity: 1,
242 instance: {
243 kind: "potion",
244 potionKey: "tanningBrew",
245 displayName: "Tanning brew",
246 fillLevel: 2,
247 effect: { type: "food-poisoning", amountPerSecond: 1, durationMs: 10_000 },
248 effectKey: "food-poisoning"
249 }
250 }
251 ]);
252
253 const hard = recipeDefinition("leather-hard");
254 assert.equal(hard.consumePotionKey, "tanningBrew");
255 assert.deepEqual(hard.inputs, [{ itemId: LeatherItemId.softLeather, quantity: 1 }]);
256
257 harness.simulation.enqueue(1, {
258 type: "start-craft",
259 characterId: character.character_id,
260 stationId: CraftingStationId.leatherworkingStation,
261 recipeId: "leather-hard"
262 });
263 harness.simulation.step();
264 const hardDuration = craftDurationMs(hard, CRAFT_DURATION_MS);
265 advanceMs(harness, hardDuration);
266
267 let bag = harness.simulation.bagOf(playerId);
268 assert.equal(countItem(bag.inventory, LeatherItemId.hardLeather), 1);
269 assert.equal(countItem(bag.inventory, LeatherItemId.softLeather), 1);
270 const brew = bag.inventory.find((slot) =>
271 slot?.itemId === ItemId.potion && slot.instance?.potionKey === "tanningBrew"
272 );
273 assert.ok(brew);
274 assert.equal(brew.instance.fillLevel, 1);
275 assert.equal(countItem(bag.inventory, ItemId.glassBottle), 0);
276
277 harness.simulation.enqueue(1, {
278 type: "start-craft",
279 characterId: character.character_id,
280 stationId: CraftingStationId.leatherworkingStation,
281 recipeId: "leather-hard"
282 });
283 harness.simulation.step();
284 advanceMs(harness, hardDuration);
285
286 bag = harness.simulation.bagOf(playerId);
287 assert.equal(countItem(bag.inventory, LeatherItemId.hardLeather), 2);
288 assert.equal(countItem(bag.inventory, LeatherItemId.softLeather), 0);
289 assert.equal(
290 bag.inventory.some((slot) =>
291 slot?.itemId === ItemId.potion && slot.instance?.potionKey === "tanningBrew"
292 ),
293 false
294 );
295 assert.equal(countItem(bag.inventory, ItemId.glassBottle), 1);
296 }
297 finally
298 { harness.close(); }
299});
300
217test("smelting bronze consumes tin and copper, grants bar and Smithing XP", () =>
301test("smelting bronze consumes tin and copper, grants bar and Smithing XP", () =>
218{
302{
219 const harness = makeSimulation({ workerCount: 1 });
303 const harness = makeSimulation({ workerCount: 1 });
server/tests/marketplace.test.js +2 −2
@@ -290,8 +290,8 @@ test("market catalog lists each drinkable potion brew separately", () =>
290 290 assert.equal(potions.some((entry) => entry.displayName === "Potion"), false);
291 291 assert.equal(
292 292 potions.some((entry) => entry.listingKey === potionListingKey("tanningBrew")),
293 false,
294 "solid tanning brew output stays its own item id"
293 true,
294 "tanning brew is listed as a drinkable potion"
295 295 );
296 296 });
297 297
@@ -290,8 +290,8 @@ test("market catalog lists each drinkable potion brew separately", () =>
290 assert.equal(potions.some((entry) => entry.displayName === "Potion"), false);
290 assert.equal(potions.some((entry) => entry.displayName === "Potion"), false);
291 assert.equal(
291 assert.equal(
292 potions.some((entry) => entry.listingKey === potionListingKey("tanningBrew")),
292 potions.some((entry) => entry.listingKey === potionListingKey("tanningBrew")),
293 false,
293 true,
294 "solid tanning brew output stays its own item id"
294 "tanning brew is listed as a drinkable potion"
295 );
295 );
296});
296});
297
297
server/tests/tanning-ingredients.test.js +12 −6
@@ -302,8 +302,8 @@ test("animal fat and tanning brew alchemy recipes resolve", () =>
302 302 assert.ok(fat);
303 303 assert.equal(fat.effect?.type, StatusEffectType.foodPoisoning);
304 304 assert.ok(tan);
305 assert.equal(tan.outputItemId, LeatherItemId.tanningBrew);
306 assert.equal(tan.requiresEmptyBottles, false);
305 assert.equal(tan.outputItemId ?? null, null);
306 assert.equal(tan.effect?.type, StatusEffectType.foodPoisoning);
307 307
308 308 const fatEval = evaluateAlchemyBottle({
309 309 skills: { levels: { [SkillId.alchemy]: 1 } },
@@ -326,10 +326,12 @@ test("animal fat and tanning brew alchemy recipes resolve", () =>
326 326 takenSteps: tan.steps
327 327 });
328 328 assert.equal(tanEval.success, true);
329 assert.equal(tanEval.result.outputItemId, LeatherItemId.tanningBrew);
329 assert.equal(tanEval.result.potionKey, "tanningBrew");
330 assert.equal(tanEval.result.outputItemId ?? null, null);
331 assert.equal(tanEval.result.effect?.type, StatusEffectType.foodPoisoning);
330 332 });
331 333
332 test("cauldron bottles animal fat then tanning brew returns the empty bottle", () =>
334 test("cauldron bottles animal fat then tanning brew as a potion", () =>
333 335 {
334 336 const harness = makeSimulation({ workerCount: 1 });
335 337 try
@@ -418,8 +420,12 @@ test("cauldron bottles animal fat then tanning brew returns the empty bottle", (
418 420 harness.simulation.step();
419 421
420 422 bag = harness.simulation.bagOf(entityId);
421 assert.equal(countItem(bag.inventory, LeatherItemId.tanningBrew), 1);
422 assert.equal(countItem(bag.inventory, ItemId.potion), 0);
423 const brew = bag.inventory.find((slot) =>
424 slot?.itemId === ItemId.potion && slot.instance?.potionKey === "tanningBrew"
425 );
426 assert.ok(brew);
427 assert.equal(brew.instance.fillLevel, 4);
428 assert.equal(countItem(bag.inventory, LeatherItemId.tanningBrew), 0);
423 429 assert.equal(countItem(bag.inventory, ItemId.glassBottle), 1);
424 430 assert.equal(countItem(bag.inventory, WoodItemId.oakBark), 0);
425 431 assert.equal(countItem(bag.inventory, CraftingItemId.salt), 0);
@@ -302,8 +302,8 @@ test("animal fat and tanning brew alchemy recipes resolve", () =>
302 assert.ok(fat);
302 assert.ok(fat);
303 assert.equal(fat.effect?.type, StatusEffectType.foodPoisoning);
303 assert.equal(fat.effect?.type, StatusEffectType.foodPoisoning);
304 assert.ok(tan);
304 assert.ok(tan);
305 assert.equal(tan.outputItemId, LeatherItemId.tanningBrew);
305 assert.equal(tan.outputItemId ?? null, null);
306 assert.equal(tan.requiresEmptyBottles, false);
306 assert.equal(tan.effect?.type, StatusEffectType.foodPoisoning);
307
307
308 const fatEval = evaluateAlchemyBottle({
308 const fatEval = evaluateAlchemyBottle({
309 skills: { levels: { [SkillId.alchemy]: 1 } },
309 skills: { levels: { [SkillId.alchemy]: 1 } },
@@ -326,10 +326,12 @@ test("animal fat and tanning brew alchemy recipes resolve", () =>
326 takenSteps: tan.steps
326 takenSteps: tan.steps
327 });
327 });
328 assert.equal(tanEval.success, true);
328 assert.equal(tanEval.success, true);
329 assert.equal(tanEval.result.outputItemId, LeatherItemId.tanningBrew);
329 assert.equal(tanEval.result.potionKey, "tanningBrew");
330 assert.equal(tanEval.result.outputItemId ?? null, null);
331 assert.equal(tanEval.result.effect?.type, StatusEffectType.foodPoisoning);
330});
332});
331
333
332test("cauldron bottles animal fat then tanning brew returns the empty bottle", () =>
334test("cauldron bottles animal fat then tanning brew as a potion", () =>
333{
335{
334 const harness = makeSimulation({ workerCount: 1 });
336 const harness = makeSimulation({ workerCount: 1 });
335 try
337 try
@@ -418,8 +420,12 @@ test("cauldron bottles animal fat then tanning brew returns the empty bottle", (
418 harness.simulation.step();
420 harness.simulation.step();
419
421
420 bag = harness.simulation.bagOf(entityId);
422 bag = harness.simulation.bagOf(entityId);
421 assert.equal(countItem(bag.inventory, LeatherItemId.tanningBrew), 1);
423 const brew = bag.inventory.find((slot) =>
422 assert.equal(countItem(bag.inventory, ItemId.potion), 0);
424 slot?.itemId === ItemId.potion && slot.instance?.potionKey === "tanningBrew"
425 );
426 assert.ok(brew);
427 assert.equal(brew.instance.fillLevel, 4);
428 assert.equal(countItem(bag.inventory, LeatherItemId.tanningBrew), 0);
423 assert.equal(countItem(bag.inventory, ItemId.glassBottle), 1);
429 assert.equal(countItem(bag.inventory, ItemId.glassBottle), 1);
424 assert.equal(countItem(bag.inventory, WoodItemId.oakBark), 0);
430 assert.equal(countItem(bag.inventory, WoodItemId.oakBark), 0);
425 assert.equal(countItem(bag.inventory, CraftingItemId.salt), 0);
431 assert.equal(countItem(bag.inventory, CraftingItemId.salt), 0);
shared/crafting/potionCharge.js added +50 −0
@@ -0,0 +1,50 @@
1 import { ItemId } from "../definitions/items.js";
2 import { alchemyPotionDefinition } from "../definitions/alchemy.js";
3
4 export function potionFillLevel (stack)
5 {
6 return Math.max(1, Math.min(5, stack?.instance?.fillLevel | 0 || 4));
7 }
8
9 /** Bag slots holding a success potion with the given potionKey. */
10 export function potionStacksForKey (slots, potionKey)
11 {
12 const key = String(potionKey ?? "");
13 const out = [];
14 if (!key)
15 { return out; }
16 for (let index = 0; index < (slots?.length ?? 0); index++)
17 {
18 const stack = slots[index];
19 if (!stack || (stack.itemId | 0) !== ItemId.potion)
20 { continue; }
21 if (stack.instance?.kind !== "potion")
22 { continue; }
23 if (String(stack.instance?.potionKey ?? "") !== key)
24 { continue; }
25 if (stack.instance?.unstable)
26 { continue; }
27 out.push({ index, stack, fill: potionFillLevel(stack) });
28 }
29 return out;
30 }
31
32 /** Bag slot of this brew with the least fill remaining. */
33 export function pickEmptiestPotionSlot (slots, potionKey)
34 {
35 const matches = potionStacksForKey(slots, potionKey);
36 if (!matches.length)
37 { return null; }
38 matches.sort((a, b) => a.fill - b.fill || a.index - b.index);
39 return matches[0].index;
40 }
41
42 export function hasPotionKey (slots, potionKey)
43 {
44 return potionStacksForKey(slots, potionKey).length > 0;
45 }
46
47 export function potionKeyDisplayName (potionKey)
48 {
49 return alchemyPotionDefinition(potionKey)?.displayName ?? "Brew";
50 }
@@ -0,0 +1,50 @@
1import { ItemId } from "../definitions/items.js";
2import { alchemyPotionDefinition } from "../definitions/alchemy.js";
3
4export function potionFillLevel (stack)
5{
6 return Math.max(1, Math.min(5, stack?.instance?.fillLevel | 0 || 4));
7}
8
9/** Bag slots holding a success potion with the given potionKey. */
10export function potionStacksForKey (slots, potionKey)
11{
12 const key = String(potionKey ?? "");
13 const out = [];
14 if (!key)
15 { return out; }
16 for (let index = 0; index < (slots?.length ?? 0); index++)
17 {
18 const stack = slots[index];
19 if (!stack || (stack.itemId | 0) !== ItemId.potion)
20 { continue; }
21 if (stack.instance?.kind !== "potion")
22 { continue; }
23 if (String(stack.instance?.potionKey ?? "") !== key)
24 { continue; }
25 if (stack.instance?.unstable)
26 { continue; }
27 out.push({ index, stack, fill: potionFillLevel(stack) });
28 }
29 return out;
30}
31
32/** Bag slot of this brew with the least fill remaining. */
33export function pickEmptiestPotionSlot (slots, potionKey)
34{
35 const matches = potionStacksForKey(slots, potionKey);
36 if (!matches.length)
37 { return null; }
38 matches.sort((a, b) => a.fill - b.fill || a.index - b.index);
39 return matches[0].index;
40}
41
42export function hasPotionKey (slots, potionKey)
43{
44 return potionStacksForKey(slots, potionKey).length > 0;
45}
46
47export function potionKeyDisplayName (potionKey)
48{
49 return alchemyPotionDefinition(potionKey)?.displayName ?? "Brew";
50}
shared/crafting/recipes.js +23 −4
@@ -1,6 +1,7 @@
1 import { itemDefinition } from "../definitions/items.js";
1 import { itemDefinition, ItemId } from "../definitions/items.js";
2 2 import { consumeFillCharge, insertStack, stackQuantity, takeFromSlot } from "../items/inventory.js";
3 3 import { resolveDyeConsumeSlot } from "./dye.js";
4 import { hasPotionKey, pickEmptiestPotionSlot } from "./potionCharge.js";
4 5
5 6 export { recipesForStation, recipeDefinition, recipeStationIds } from "./stationRecipes.js";
6 7
@@ -29,7 +30,7 @@ function takeItemPreservingSlots (slots, itemId, quantity)
29 30 /**
30 31 * Recipe shape: `{ output: { itemId, quantity }, inputs: [{ itemId, quantity }] }`.
31 32 * Returns whether the player has the inputs and, after consuming them (and optional dye
32 * charge), room for the output. Freed slots from consumed stacks count toward output space.
33 * / potion charge), room for the output. Freed slots from consumed stacks count toward output space.
33 34 */
34 35 export function canCraftFitInventory (slots, recipe, options = {})
35 36 {
@@ -56,6 +57,20 @@ export function canCraftFitInventory (slots, recipe, options = {})
56 57 { return false; }
57 58 next = dyeCheck.slots;
58 59 }
60 if (recipe.consumePotionKey)
61 {
62 const potionSlot = pickEmptiestPotionSlot(next, recipe.consumePotionKey);
63 if (potionSlot == null)
64 { return false; }
65 const potionCheck = consumeFillCharge(next, potionSlot, {
66 kind: "potion",
67 itemId: ItemId.potion,
68 returnEmptyItemId: ItemId.glassBottle
69 });
70 if (!potionCheck.ok)
71 { return false; }
72 next = potionCheck.slots;
73 }
59 74 const def = itemDefinition(recipe.output.itemId);
60 75 if (!def)
61 76 { return false; }
@@ -81,9 +96,9 @@ export function countItemInSlots (slots, itemId)
81 96
82 97 export function hasRecipeInputs (slots, recipe)
83 98 {
84 if (!recipe?.inputs?.length)
99 if (!recipe)
85 100 { return false; }
86 for (const input of recipe.inputs)
101 for (const input of recipe.inputs ?? [])
87 102 {
88 103 const need = input.quantity | 0;
89 104 if (need <= 0)
@@ -91,6 +106,10 @@ export function hasRecipeInputs (slots, recipe)
91 106 if (countItemInSlots(slots, input.itemId) < need)
92 107 { return false; }
93 108 }
109 if (recipe.consumePotionKey && !hasPotionKey(slots, recipe.consumePotionKey))
110 { return false; }
111 if (!(recipe.inputs?.length) && !recipe.consumePotionKey && !recipe.consumeDye)
112 { return false; }
94 113 return true;
95 114 }
96 115
@@ -1,6 +1,7 @@
1import { itemDefinition } from "../definitions/items.js";
1import { itemDefinition, ItemId } from "../definitions/items.js";
2import { consumeFillCharge, insertStack, stackQuantity, takeFromSlot } from "../items/inventory.js";
2import { consumeFillCharge, insertStack, stackQuantity, takeFromSlot } from "../items/inventory.js";
3import { resolveDyeConsumeSlot } from "./dye.js";
3import { resolveDyeConsumeSlot } from "./dye.js";
4import { hasPotionKey, pickEmptiestPotionSlot } from "./potionCharge.js";
4
5
5export { recipesForStation, recipeDefinition, recipeStationIds } from "./stationRecipes.js";
6export { recipesForStation, recipeDefinition, recipeStationIds } from "./stationRecipes.js";
6
7
@@ -29,7 +30,7 @@ function takeItemPreservingSlots (slots, itemId, quantity)
29/**
30/**
30 * Recipe shape: `{ output: { itemId, quantity }, inputs: [{ itemId, quantity }] }`.
31 * Recipe shape: `{ output: { itemId, quantity }, inputs: [{ itemId, quantity }] }`.
31 * Returns whether the player has the inputs and, after consuming them (and optional dye
32 * Returns whether the player has the inputs and, after consuming them (and optional dye
32 * charge), room for the output. Freed slots from consumed stacks count toward output space.
33 * / potion charge), room for the output. Freed slots from consumed stacks count toward output space.
33 */
34 */
34export function canCraftFitInventory (slots, recipe, options = {})
35export function canCraftFitInventory (slots, recipe, options = {})
35{
36{
@@ -56,6 +57,20 @@ export function canCraftFitInventory (slots, recipe, options = {})
56 { return false; }
57 { return false; }
57 next = dyeCheck.slots;
58 next = dyeCheck.slots;
58 }
59 }
60 if (recipe.consumePotionKey)
61 {
62 const potionSlot = pickEmptiestPotionSlot(next, recipe.consumePotionKey);
63 if (potionSlot == null)
64 { return false; }
65 const potionCheck = consumeFillCharge(next, potionSlot, {
66 kind: "potion",
67 itemId: ItemId.potion,
68 returnEmptyItemId: ItemId.glassBottle
69 });
70 if (!potionCheck.ok)
71 { return false; }
72 next = potionCheck.slots;
73 }
59 const def = itemDefinition(recipe.output.itemId);
74 const def = itemDefinition(recipe.output.itemId);
60 if (!def)
75 if (!def)
61 { return false; }
76 { return false; }
@@ -81,9 +96,9 @@ export function countItemInSlots (slots, itemId)
81
96
82export function hasRecipeInputs (slots, recipe)
97export function hasRecipeInputs (slots, recipe)
83{
98{
84 if (!recipe?.inputs?.length)
99 if (!recipe)
85 { return false; }
100 { return false; }
86 for (const input of recipe.inputs)
101 for (const input of recipe.inputs ?? [])
87 {
102 {
88 const need = input.quantity | 0;
103 const need = input.quantity | 0;
89 if (need <= 0)
104 if (need <= 0)
@@ -91,6 +106,10 @@ export function hasRecipeInputs (slots, recipe)
91 if (countItemInSlots(slots, input.itemId) < need)
106 if (countItemInSlots(slots, input.itemId) < need)
92 { return false; }
107 { return false; }
93 }
108 }
109 if (recipe.consumePotionKey && !hasPotionKey(slots, recipe.consumePotionKey))
110 { return false; }
111 if (!(recipe.inputs?.length) && !recipe.consumePotionKey && !recipe.consumeDye)
112 { return false; }
94 return true;
113 return true;
95}
114}
96
115
shared/crafting/stationRecipes.js +2 −2
@@ -169,9 +169,9 @@ export const CRAFT_RECIPES = Object.freeze([
169 169 stationId: CraftingStationId.leatherworkingStation,
170 170 output: { itemId: LeatherItemId.hardLeather, quantity: 1 },
171 171 inputs: [
172 { itemId: LeatherItemId.softLeather, quantity: 1 },
173 { itemId: LeatherItemId.tanningBrew, quantity: 1 }
172 { itemId: LeatherItemId.softLeather, quantity: 1 }
174 173 ],
174 consumePotionKey: "tanningBrew",
175 175 minSkillLevel: tierCraftSkillLevel(LeatherTier.hardLeather),
176 176 skillId: "leatherworking",
177 177 xpMaterial: LeatherTier.hardLeather
@@ -169,9 +169,9 @@ export const CRAFT_RECIPES = Object.freeze([
169 stationId: CraftingStationId.leatherworkingStation,
169 stationId: CraftingStationId.leatherworkingStation,
170 output: { itemId: LeatherItemId.hardLeather, quantity: 1 },
170 output: { itemId: LeatherItemId.hardLeather, quantity: 1 },
171 inputs: [
171 inputs: [
172 { itemId: LeatherItemId.softLeather, quantity: 1 },
172 { itemId: LeatherItemId.softLeather, quantity: 1 }
173 { itemId: LeatherItemId.tanningBrew, quantity: 1 }
174 ],
173 ],
174 consumePotionKey: "tanningBrew",
175 minSkillLevel: tierCraftSkillLevel(LeatherTier.hardLeather),
175 minSkillLevel: tierCraftSkillLevel(LeatherTier.hardLeather),
176 skillId: "leatherworking",
176 skillId: "leatherworking",
177 xpMaterial: LeatherTier.hardLeather
177 xpMaterial: LeatherTier.hardLeather
shared/definitions/alchemy.js +7 −7
@@ -5,7 +5,6 @@ import {
5 5 MAGIC_ELEMENT_TINT,
6 6 ASH_WOOD_FOR_ELEMENT
7 7 } from "./attackTypes.js";
8 import { LeatherItemId } from "./leatherItems.js";
9 8
10 9 export const AlchemyStepKind = Object.freeze({
11 10 heat: "heat",
@@ -160,14 +159,11 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
160 159 tanningBrew: Object.freeze({
161 160 potionKey: "tanningBrew",
162 161 displayName: "Tanning brew",
163 description: "A dark, bark-bitter liquor for curing hides into leather.",
162 description: "A dark, bark-bitter liquor for curing hides. Foul if drunk.",
164 163 minAlchemyLevel: 10,
165 164 color: Object.freeze({ r: 0.45, g: 0.28, b: 0.14 }),
166 165 fillLevel: 4,
167 /** Solid craft item — not a drinkable potion bottle. */
168 outputItemId: LeatherItemId.tanningBrew,
169 outputQuantity: 1,
170 /** Bottling does not consume empty glass bottles (fat bottle is the vessel). */
166 /** Fat bottle is the vessel — bottling does not consume empty glass bottles. */
171 167 requiresEmptyBottles: false,
172 168 ingredients: Object.freeze([
173 169 Object.freeze({ key: "oak-bark", quantity: 2 }),
@@ -182,7 +178,11 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
182 178 Object.freeze({ kind: AlchemyStepKind.insert, potionKey: "animalFat" }),
183 179 Object.freeze({ kind: AlchemyStepKind.cool })
184 180 ]),
185 effect: null
181 effect: Object.freeze({
182 type: "food-poisoning",
183 amountPerSecond: 1,
184 durationMs: 10_000
185 })
186 186 }),
187 187 ...buildArrowCoatingPotions()
188 188 });
@@ -5,7 +5,6 @@ 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";
9
8
10export const AlchemyStepKind = Object.freeze({
9export const AlchemyStepKind = Object.freeze({
11 heat: "heat",
10 heat: "heat",
@@ -160,14 +159,11 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
160 tanningBrew: Object.freeze({
159 tanningBrew: Object.freeze({
161 potionKey: "tanningBrew",
160 potionKey: "tanningBrew",
162 displayName: "Tanning brew",
161 displayName: "Tanning brew",
163 description: "A dark, bark-bitter liquor for curing hides into leather.",
162 description: "A dark, bark-bitter liquor for curing hides. Foul if drunk.",
164 minAlchemyLevel: 10,
163 minAlchemyLevel: 10,
165 color: Object.freeze({ r: 0.45, g: 0.28, b: 0.14 }),
164 color: Object.freeze({ r: 0.45, g: 0.28, b: 0.14 }),
166 fillLevel: 4,
165 fillLevel: 4,
167 /** Solid craft item — not a drinkable potion bottle. */
166 /** Fat bottle is the vessel — bottling does not consume empty glass bottles. */
168 outputItemId: LeatherItemId.tanningBrew,
169 outputQuantity: 1,
170 /** Bottling does not consume empty glass bottles (fat bottle is the vessel). */
171 requiresEmptyBottles: false,
167 requiresEmptyBottles: false,
172 ingredients: Object.freeze([
168 ingredients: Object.freeze([
173 Object.freeze({ key: "oak-bark", quantity: 2 }),
169 Object.freeze({ key: "oak-bark", quantity: 2 }),
@@ -182,7 +178,11 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
182 Object.freeze({ kind: AlchemyStepKind.insert, potionKey: "animalFat" }),
178 Object.freeze({ kind: AlchemyStepKind.insert, potionKey: "animalFat" }),
183 Object.freeze({ kind: AlchemyStepKind.cool })
179 Object.freeze({ kind: AlchemyStepKind.cool })
184 ]),
180 ]),
185 effect: null
181 effect: Object.freeze({
182 type: "food-poisoning",
183 amountPerSecond: 1,
184 durationMs: 10_000
185 })
186 }),
186 }),
187 ...buildArrowCoatingPotions()
187 ...buildArrowCoatingPotions()
188});
188});
shared/definitions/leatherItems.js +1 −1
@@ -158,7 +158,7 @@ export const LEATHER_ITEM_DEFINITIONS = Object.freeze({
158 158 itemId: LeatherItemId.tanningBrew,
159 159 key: "tanning-brew",
160 160 displayName: "Tanning brew",
161 description: "A sharp-smelling alchemy wash that cures hide into hard leather.",
161 description: "A jar of dark curing liquor left from older tannery work.",
162 162 seedValue: 8,
163 163 stackable: true,
164 164 maxStackSize: 99,
@@ -158,7 +158,7 @@ export const LEATHER_ITEM_DEFINITIONS = Object.freeze({
158 itemId: LeatherItemId.tanningBrew,
158 itemId: LeatherItemId.tanningBrew,
159 key: "tanning-brew",
159 key: "tanning-brew",
160 displayName: "Tanning brew",
160 displayName: "Tanning brew",
161 description: "A sharp-smelling alchemy wash that cures hide into hard leather.",
161 description: "A jar of dark curing liquor left from older tannery work.",
162 seedValue: 8,
162 seedValue: 8,
163 stackable: true,
163 stackable: true,
164 maxStackSize: 99,
164 maxStackSize: 99,