BlueGit

timfa questward

Triple craft-station XP and double alchemy XP.

Scale tier-based craft XP by skill: 3× for smithing, jewelering, crafting,
leatherworking, tailoring, and cooking; 2× for alchemy (brews and dye flowers).

timfa Tim Falken · pushed by timfa

Authored 2026-09-01 · 2 months ago

Hash
fbce535f59348e1a5abc186d563d1f5694bd7fb2
Parent
4b4d19e3
6 files changed +53 −12
server/src/alchemy/service.js +10 −3
@@ -30,7 +30,10 @@ import {
30 30 } from "../../../shared/items/inventory.js";
31 31 import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";
32 32 import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
33 import { craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";
33 import {
34 craftXpForConsumedInputs,
35 craftXpMultiplierForSkill
36 } from "../../../shared/definitions/gathering.js";
34 37 import { tileToChunk, tileToLocal } from "../world/coordinates.js";
35 38 import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
36 39 import { randomUUID } from "node:crypto";
@@ -436,7 +439,7 @@ function bottle (world, sessionId, command)
436 439 itemId: row.itemId,
437 440 quantity: row.quantity
438 441 }));
439 const amount = craftXpForConsumedInputs(xpInputs);
442 const amount = craftXpForConsumedInputs(xpInputs, SkillId.alchemy);
440 443 if (amount > 0)
441 444 {
442 445 const result = applySkillXp(skills, SkillId.alchemy, amount);
@@ -558,7 +561,11 @@ function createDye (world, sessionId, command)
558 561 const flowerCount = rows.reduce((sum, row) => sum + (row.quantity | 0), 0);
559 562 if (skills?.xp && flowerCount > 0)
560 563 {
561 const result = applySkillXp(skills, SkillId.alchemy, flowerCount);
564 const result = applySkillXp(
565 skills,
566 SkillId.alchemy,
567 flowerCount * craftXpMultiplierForSkill(SkillId.alchemy)
568 );
562 569 if (result.changed)
563 570 {
564 571 events.push({
@@ -30,7 +30,10 @@ import {
30} from "../../../shared/items/inventory.js";
30} from "../../../shared/items/inventory.js";
31import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";
31import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";
32import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
32import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
33import { craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";
33import {
34 craftXpForConsumedInputs,
35 craftXpMultiplierForSkill
36} from "../../../shared/definitions/gathering.js";
34import { tileToChunk, tileToLocal } from "../world/coordinates.js";
37import { tileToChunk, tileToLocal } from "../world/coordinates.js";
35import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
38import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
36import { randomUUID } from "node:crypto";
39import { randomUUID } from "node:crypto";
@@ -436,7 +439,7 @@ function bottle (world, sessionId, command)
436 itemId: row.itemId,
439 itemId: row.itemId,
437 quantity: row.quantity
440 quantity: row.quantity
438 }));
441 }));
439 const amount = craftXpForConsumedInputs(xpInputs);
442 const amount = craftXpForConsumedInputs(xpInputs, SkillId.alchemy);
440 if (amount > 0)
443 if (amount > 0)
441 {
444 {
442 const result = applySkillXp(skills, SkillId.alchemy, amount);
445 const result = applySkillXp(skills, SkillId.alchemy, amount);
@@ -558,7 +561,11 @@ function createDye (world, sessionId, command)
558 const flowerCount = rows.reduce((sum, row) => sum + (row.quantity | 0), 0);
561 const flowerCount = rows.reduce((sum, row) => sum + (row.quantity | 0), 0);
559 if (skills?.xp && flowerCount > 0)
562 if (skills?.xp && flowerCount > 0)
560 {
563 {
561 const result = applySkillXp(skills, SkillId.alchemy, flowerCount);
564 const result = applySkillXp(
565 skills,
566 SkillId.alchemy,
567 flowerCount * craftXpMultiplierForSkill(SkillId.alchemy)
568 );
562 if (result.changed)
569 if (result.changed)
563 {
570 {
564 events.push({
571 events.push({
server/src/crafting/service.js +1 −1
@@ -428,7 +428,7 @@ export function stepCrafting (world, now)
428 428 const result = applySkillXp(
429 429 skills,
430 430 stationDef.skillId,
431 craftXpForConsumedInputs(recipe.inputs)
431 craftXpForConsumedInputs(recipe.inputs, stationDef.skillId)
432 432 );
433 433 if (result.changed)
434 434 { skillsChanged = true; }
@@ -428,7 +428,7 @@ export function stepCrafting (world, now)
428 const result = applySkillXp(
428 const result = applySkillXp(
429 skills,
429 skills,
430 stationDef.skillId,
430 stationDef.skillId,
431 craftXpForConsumedInputs(recipe.inputs)
431 craftXpForConsumedInputs(recipe.inputs, stationDef.skillId)
432 );
432 );
433 if (result.changed)
433 if (result.changed)
434 { skillsChanged = true; }
434 { skillsChanged = true; }
server/tests/alchemy.test.js +4 −4
@@ -151,8 +151,8 @@ test("cauldron bottles lesser health tonic when steps and ratios match", () =>
151 151 assert.equal(potion.instance?.potionKey, "lesserHealthTonic");
152 152 assert.equal(potion.instance?.unstable, false);
153 153 const alchemyAfter = harness.stateDb.getSkills(cid).xp.alchemy ?? 0;
154 // thyme×2 (tier 2) + mint×2 (tier 1)
155 assert.equal(alchemyAfter - alchemyBefore, 6);
154 // thyme×2 (tier 2) + mint×2 (tier 1), alchemy 2×
155 assert.equal(alchemyAfter - alchemyBefore, 12);
156 156
157 157 harness.simulation.enqueue(1, { type: "cauldron-save-recipe", characterId: cid });
158 158 harness.simulation.step();
@@ -321,7 +321,7 @@ test("drinking a lesser health tonic applies health regen", () =>
321 321 { harness.close(); }
322 322 });
323 323
324 test("creating dye awards 1 alchemy XP per flower and caps a slot at 16", () =>
324 test("creating dye awards 2 alchemy XP per flower and caps a slot at 16", () =>
325 325 {
326 326 const harness = makeSimulation({ workerCount: 1 });
327 327 try
@@ -357,7 +357,7 @@ test("creating dye awards 1 alchemy XP per flower and caps a slot at 16", () =>
357 357 const made = harness.simulation.step();
358 358 assert.equal(made.events.some((event) => event.type === "command-error"), false, JSON.stringify(made.events));
359 359 const alchemyAfter = harness.stateDb.getSkills(cid).xp.alchemy ?? 0;
360 assert.equal(alchemyAfter - alchemyBefore, 16);
360 assert.equal(alchemyAfter - alchemyBefore, 32);
361 361 const bag = harness.simulation.bagOf(entityId);
362 362 assert.equal(countItem(bag.inventory, ItemId.flower), 0);
363 363 assert.equal(countItem(bag.inventory, ItemId.dye), 16);
@@ -151,8 +151,8 @@ test("cauldron bottles lesser health tonic when steps and ratios match", () =>
151 assert.equal(potion.instance?.potionKey, "lesserHealthTonic");
151 assert.equal(potion.instance?.potionKey, "lesserHealthTonic");
152 assert.equal(potion.instance?.unstable, false);
152 assert.equal(potion.instance?.unstable, false);
153 const alchemyAfter = harness.stateDb.getSkills(cid).xp.alchemy ?? 0;
153 const alchemyAfter = harness.stateDb.getSkills(cid).xp.alchemy ?? 0;
154 // thyme×2 (tier 2) + mint×2 (tier 1)
154 // thyme×2 (tier 2) + mint×2 (tier 1), alchemy 2×
155 assert.equal(alchemyAfter - alchemyBefore, 6);
155 assert.equal(alchemyAfter - alchemyBefore, 12);
156
156
157 harness.simulation.enqueue(1, { type: "cauldron-save-recipe", characterId: cid });
157 harness.simulation.enqueue(1, { type: "cauldron-save-recipe", characterId: cid });
158 harness.simulation.step();
158 harness.simulation.step();
@@ -321,7 +321,7 @@ test("drinking a lesser health tonic applies health regen", () =>
321 { harness.close(); }
321 { harness.close(); }
322});
322});
323
323
324test("creating dye awards 1 alchemy XP per flower and caps a slot at 16", () =>
324test("creating dye awards 2 alchemy XP per flower and caps a slot at 16", () =>
325{
325{
326 const harness = makeSimulation({ workerCount: 1 });
326 const harness = makeSimulation({ workerCount: 1 });
327 try
327 try
@@ -357,7 +357,7 @@ test("creating dye awards 1 alchemy XP per flower and caps a slot at 16", () =>
357 const made = harness.simulation.step();
357 const made = harness.simulation.step();
358 assert.equal(made.events.some((event) => event.type === "command-error"), false, JSON.stringify(made.events));
358 assert.equal(made.events.some((event) => event.type === "command-error"), false, JSON.stringify(made.events));
359 const alchemyAfter = harness.stateDb.getSkills(cid).xp.alchemy ?? 0;
359 const alchemyAfter = harness.stateDb.getSkills(cid).xp.alchemy ?? 0;
360 assert.equal(alchemyAfter - alchemyBefore, 16);
360 assert.equal(alchemyAfter - alchemyBefore, 32);
361 const bag = harness.simulation.bagOf(entityId);
361 const bag = harness.simulation.bagOf(entityId);
362 assert.equal(countItem(bag.inventory, ItemId.flower), 0);
362 assert.equal(countItem(bag.inventory, ItemId.flower), 0);
363 assert.equal(countItem(bag.inventory, ItemId.dye), 16);
363 assert.equal(countItem(bag.inventory, ItemId.dye), 16);
server/tests/craft-xp.test.js +16 −0
@@ -4,6 +4,7 @@ import { ItemId, itemDefinition } from "../../shared/definitions/items.js";
4 4 import { MetalItemId } from "../../shared/definitions/metalItems.js";
5 5 import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
6 6 import { recipeDefinition } from "../../shared/crafting/stationRecipes.js";
7 import { SkillId } from "../../shared/definitions/skills.js";
7 8 import {
8 9 itemCraftXpValue,
9 10 craftXpForConsumedInputs
@@ -46,6 +47,21 @@ test("orichalcum smelt XP sums ore and three coal", () =>
46 47 assert.equal(craftXpForConsumedInputs(recipe.inputs), 6 + 3 * 3);
47 48 });
48 49
50 test("smithing craft XP is 3× base tier sum", () =>
51 {
52 const recipe = recipeDefinition("smelt-bronze");
53 assert.equal(craftXpForConsumedInputs(recipe.inputs, SkillId.smithing), 6);
54 });
55
56 test("alchemy craft XP is 2× base tier sum", () =>
57 {
58 const inputs = [
59 { itemId: ItemId.mint, quantity: 2 },
60 { itemId: ItemId.thyme, quantity: 2 }
61 ];
62 assert.equal(craftXpForConsumedInputs(inputs, SkillId.alchemy), 12);
63 });
64
49 65 test("flowers stack to 16", () =>
50 66 {
51 67 assert.equal(itemDefinition(ItemId.flower).maxStackSize, FLOWER_MAX_STACK);
@@ -4,6 +4,7 @@ import { ItemId, itemDefinition } from "../../shared/definitions/items.js";
4import { MetalItemId } from "../../shared/definitions/metalItems.js";
4import { MetalItemId } from "../../shared/definitions/metalItems.js";
5import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
5import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
6import { recipeDefinition } from "../../shared/crafting/stationRecipes.js";
6import { recipeDefinition } from "../../shared/crafting/stationRecipes.js";
7import { SkillId } from "../../shared/definitions/skills.js";
7import {
8import {
8 itemCraftXpValue,
9 itemCraftXpValue,
9 craftXpForConsumedInputs
10 craftXpForConsumedInputs
@@ -46,6 +47,21 @@ test("orichalcum smelt XP sums ore and three coal", () =>
46 assert.equal(craftXpForConsumedInputs(recipe.inputs), 6 + 3 * 3);
47 assert.equal(craftXpForConsumedInputs(recipe.inputs), 6 + 3 * 3);
47});
48});
48
49
50test("smithing craft XP is 3× base tier sum", () =>
51{
52 const recipe = recipeDefinition("smelt-bronze");
53 assert.equal(craftXpForConsumedInputs(recipe.inputs, SkillId.smithing), 6);
54});
55
56test("alchemy craft XP is 2× base tier sum", () =>
57{
58 const inputs = [
59 { itemId: ItemId.mint, quantity: 2 },
60 { itemId: ItemId.thyme, quantity: 2 }
61 ];
62 assert.equal(craftXpForConsumedInputs(inputs, SkillId.alchemy), 12);
63});
64
49test("flowers stack to 16", () =>
65test("flowers stack to 16", () =>
50{
66{
51 assert.equal(itemDefinition(ItemId.flower).maxStackSize, FLOWER_MAX_STACK);
67 assert.equal(itemDefinition(ItemId.flower).maxStackSize, FLOWER_MAX_STACK);
server/tests/crafting.test.js +1 −1
@@ -251,7 +251,7 @@ test("smelting bronze consumes tin and copper, grants bar and Smithing XP", () =
251 251 assert.equal(bar?.origins?.[0]?.origin?.verb, "Forged");
252 252 assert.match(bar?.origins?.[0]?.origin?.displayName ?? "", /^Ada/);
253 253 const smithingAfter = harness.stateDb.getSkills(character.character_id).xp.smithing ?? 0;
254 assert.equal(smithingAfter - smithingBefore, 2);
254 assert.equal(smithingAfter - smithingBefore, 6);
255 255 }
256 256 finally
257 257 { harness.close(); }
@@ -251,7 +251,7 @@ test("smelting bronze consumes tin and copper, grants bar and Smithing XP", () =
251 assert.equal(bar?.origins?.[0]?.origin?.verb, "Forged");
251 assert.equal(bar?.origins?.[0]?.origin?.verb, "Forged");
252 assert.match(bar?.origins?.[0]?.origin?.displayName ?? "", /^Ada/);
252 assert.match(bar?.origins?.[0]?.origin?.displayName ?? "", /^Ada/);
253 const smithingAfter = harness.stateDb.getSkills(character.character_id).xp.smithing ?? 0;
253 const smithingAfter = harness.stateDb.getSkills(character.character_id).xp.smithing ?? 0;
254 assert.equal(smithingAfter - smithingBefore, 2);
254 assert.equal(smithingAfter - smithingBefore, 6);
255 }
255 }
256 finally
256 finally
257 { harness.close(); }
257 { harness.close(); }
shared/definitions/gathering.js +21 −3
@@ -132,8 +132,24 @@ export function itemCraftXpValue (itemId)
132 132 return Math.max(1, tierRank(rawTier));
133 133 }
134 134
135 /** Sum of `itemCraftXpValue × quantity` over recipe inputs. */
136 export function craftXpForConsumedInputs (inputs)
135 /** Craft XP multiplier per skill (base XP is tier rank per consumed input). */
136 export const CRAFT_XP_MULTIPLIER_BY_SKILL = Object.freeze({
137 [SkillId.smithing]: 3,
138 [SkillId.jewelering]: 3,
139 [SkillId.crafting]: 3,
140 [SkillId.leatherworking]: 3,
141 [SkillId.tailoring]: 3,
142 [SkillId.cooking]: 3,
143 [SkillId.alchemy]: 2
144 });
145
146 export function craftXpMultiplierForSkill (skillId)
147 {
148 return CRAFT_XP_MULTIPLIER_BY_SKILL[skillId] ?? 1;
149 }
150
151 /** Sum of `itemCraftXpValue × quantity` over recipe inputs, scaled by skill. */
152 export function craftXpForConsumedInputs (inputs, skillId = null)
137 153 {
138 154 let total = 0;
139 155 for (const input of inputs ?? [])
@@ -143,7 +159,9 @@ export function craftXpForConsumedInputs (inputs)
143 159 { continue; }
144 160 total += itemCraftXpValue(input.itemId) * quantity;
145 161 }
146 return total;
162 if (!skillId)
163 { return total; }
164 return total * craftXpMultiplierForSkill(skillId);
147 165 }
148 166
149 167 /** Mine skill / tool gates use the associated bar's equip tier. */
@@ -132,8 +132,24 @@ export function itemCraftXpValue (itemId)
132 return Math.max(1, tierRank(rawTier));
132 return Math.max(1, tierRank(rawTier));
133}
133}
134
134
135/** Sum of `itemCraftXpValue × quantity` over recipe inputs. */
135/** Craft XP multiplier per skill (base XP is tier rank per consumed input). */
136export function craftXpForConsumedInputs (inputs)
136export const CRAFT_XP_MULTIPLIER_BY_SKILL = Object.freeze({
137 [SkillId.smithing]: 3,
138 [SkillId.jewelering]: 3,
139 [SkillId.crafting]: 3,
140 [SkillId.leatherworking]: 3,
141 [SkillId.tailoring]: 3,
142 [SkillId.cooking]: 3,
143 [SkillId.alchemy]: 2
144});
145
146export function craftXpMultiplierForSkill (skillId)
147{
148 return CRAFT_XP_MULTIPLIER_BY_SKILL[skillId] ?? 1;
149}
150
151/** Sum of `itemCraftXpValue × quantity` over recipe inputs, scaled by skill. */
152export function craftXpForConsumedInputs (inputs, skillId = null)
137{
153{
138 let total = 0;
154 let total = 0;
139 for (const input of inputs ?? [])
155 for (const input of inputs ?? [])
@@ -143,7 +159,9 @@ export function craftXpForConsumedInputs (inputs)
143 { continue; }
159 { continue; }
144 total += itemCraftXpValue(input.itemId) * quantity;
160 total += itemCraftXpValue(input.itemId) * quantity;
145 }
161 }
146 return total;
162 if (!skillId)
163 { return total; }
164 return total * craftXpMultiplierForSkill(skillId);
147}
165}
148
166
149/** Mine skill / tool gates use the associated bar's equip tier. */
167/** Mine skill / tool gates use the associated bar's equip tier. */