BlueGit

timfa questward

Award Crafting XP when debarking logs.

Woodworking uses Crafting; debark grants half the wood tier rank, rounded up.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-09-04 · 2 months ago

Hash
0d79462696d045e9540401f4644561eb1479a73d
Parent
d6ef491f
3 files changed +40 −3
server/src/gathering/service.js +19 −1
@@ -16,6 +16,7 @@ import {
16 16 resolveHerbGather,
17 17 woodcuttingDurationMs,
18 18 woodcuttingXpForWood,
19 woodworkingXpForDebark,
19 20 treeExhaustDurationMs,
20 21 logItemIdForWoodTier,
21 22 herbalismDurationMs,
@@ -889,8 +890,25 @@ function completeDebark (world, handle, entityId, character, gather, events, pri
889 890 addGroundItem(world, barkItem);
890 891 events.push(publishGroundItem(barkItem));
891 892
893 const skills = world.ecs.get(handle, Component.skills);
894 let skillsChanged = false;
895 const levelUps = [];
896 if (skills?.xp)
897 {
898 const result = applySkillXp(
899 skills,
900 SkillId.crafting,
901 woodworkingXpForDebark(gather.woodTier),
902 world.ecs.get(handle, Component.equipment)
903 );
904 if (result.changed)
905 { skillsChanged = true; }
906 if (result.levelUp)
907 { levelUps.push(result.levelUp); }
908 }
909
892 910 clearGather(world.ecs, handle);
893 pushBagUpdate(events, privates, world, handle, entityId, character, false, null, []);
911 pushBagUpdate(events, privates, world, handle, entityId, character, skillsChanged, skills, levelUps);
894 912 events.push({
895 913 type: "gather-complete",
896 914 characterId: character.characterId,
@@ -16,6 +16,7 @@ import {
16 resolveHerbGather,
16 resolveHerbGather,
17 woodcuttingDurationMs,
17 woodcuttingDurationMs,
18 woodcuttingXpForWood,
18 woodcuttingXpForWood,
19 woodworkingXpForDebark,
19 treeExhaustDurationMs,
20 treeExhaustDurationMs,
20 logItemIdForWoodTier,
21 logItemIdForWoodTier,
21 herbalismDurationMs,
22 herbalismDurationMs,
@@ -889,8 +890,25 @@ function completeDebark (world, handle, entityId, character, gather, events, pri
889 addGroundItem(world, barkItem);
890 addGroundItem(world, barkItem);
890 events.push(publishGroundItem(barkItem));
891 events.push(publishGroundItem(barkItem));
891
892
893 const skills = world.ecs.get(handle, Component.skills);
894 let skillsChanged = false;
895 const levelUps = [];
896 if (skills?.xp)
897 {
898 const result = applySkillXp(
899 skills,
900 SkillId.crafting,
901 woodworkingXpForDebark(gather.woodTier),
902 world.ecs.get(handle, Component.equipment)
903 );
904 if (result.changed)
905 { skillsChanged = true; }
906 if (result.levelUp)
907 { levelUps.push(result.levelUp); }
908 }
909
892 clearGather(world.ecs, handle);
910 clearGather(world.ecs, handle);
893 pushBagUpdate(events, privates, world, handle, entityId, character, false, null, []);
911 pushBagUpdate(events, privates, world, handle, entityId, character, skillsChanged, skills, levelUps);
894 events.push({
912 events.push({
895 type: "gather-complete",
913 type: "gather-complete",
896 characterId: character.characterId,
914 characterId: character.characterId,
server/tests/tanning-ingredients.test.js +15 −2
@@ -13,7 +13,7 @@ import { WoodTier, GatherMaterialId, MaterialTier, oreBoulderState } from "../..
13 13 import { SkillId } from "../../shared/definitions/skills.js";
14 14 import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
15 15 import { AlchemyStepKind } from "../../shared/definitions/alchemy.js";
16 import { canMineMaterial, oreItemIdForMaterial } from "../../shared/definitions/gathering.js";
16 import { canMineMaterial, oreItemIdForMaterial, woodworkingXpForDebark } from "../../shared/definitions/gathering.js";
17 17 import {
18 18 clearResolvedAlchemyPotionsCache,
19 19 resolvedAlchemyPotions,
@@ -84,6 +84,14 @@ test("debarked logs keep oak itemId but change name and sprite", () =>
84 84 assert.equal(barkItemIdForWood(WoodTier.oak), WoodItemId.oakBark);
85 85 });
86 86
87 test("debark Crafting XP is half wood tier rank rounded up", () =>
88 {
89 assert.equal(woodworkingXpForDebark(WoodTier.pine), 1);
90 assert.equal(woodworkingXpForDebark(WoodTier.birch), 1);
91 assert.equal(woodworkingXpForDebark(WoodTier.oak), 2);
92 assert.equal(woodworkingXpForDebark(WoodTier.elder), 4);
93 });
94
87 95 test("debark-log on ground oak log yields bark and debarked flag", () =>
88 96 {
89 97 const harness = makeSimulation({ workerCount: 1 });
@@ -92,6 +100,7 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
92 100 harness.simulation.reloadWorld();
93 101 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
94 102 setSkillLevel(harness, character.character_id, SkillId.woodcutting, 20);
103 setSkillLevel(harness, character.character_id, SkillId.crafting, 1);
95 104 const inventory = emptySlots();
96 105 inventory[0] = { itemId: ItemId.ironAxe, quantity: 1 };
97 106 harness.stateDb.saveBag(character.character_id, {
@@ -103,6 +112,8 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
103 112 const entityId = harness.simulation.spawnCharacter(1, character);
104 113 const record = harness.simulation.entityRecord(entityId);
105 114 const worker = harness.simulation.workers[record.workerId];
115 const handle = worker.world.ecs.handleOf(entityId);
116 const craftingXpBefore = worker.world.ecs.get(handle, Component.skills).xp[SkillId.crafting] | 0;
106 117
107 118 const groundItemId = (worker.world.nextGroundItemId = (worker.world.nextGroundItemId ?? 1) + 1);
108 119 addGroundItem(worker.world, {
@@ -122,7 +133,6 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
122 133 });
123 134 harness.simulation.step();
124 135
125 const handle = worker.world.ecs.handleOf(entityId);
126 136 const gather = worker.world.ecs.get(handle, Component.gather);
127 137 assert.equal(gather?.kind, "debark");
128 138 assert.equal(gather?.durationMs, 2000);
@@ -143,6 +153,9 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
143 153 assert.ok(bark);
144 154 assert.equal(bark.stack.quantity, 1);
145 155 assert.equal(worker.world.ecs.has(handle, Component.gather), false);
156
157 const craftingXpAfter = worker.world.ecs.get(handle, Component.skills).xp[SkillId.crafting] | 0;
158 assert.equal(craftingXpAfter - craftingXpBefore, woodworkingXpForDebark(WoodTier.oak));
146 159 }
147 160 finally
148 161 { harness.close(); }
@@ -13,7 +13,7 @@ import { WoodTier, GatherMaterialId, MaterialTier, oreBoulderState } from "../..
13import { SkillId } from "../../shared/definitions/skills.js";
13import { SkillId } from "../../shared/definitions/skills.js";
14import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
14import { LeatherItemId } from "../../shared/definitions/leatherItems.js";
15import { AlchemyStepKind } from "../../shared/definitions/alchemy.js";
15import { AlchemyStepKind } from "../../shared/definitions/alchemy.js";
16import { canMineMaterial, oreItemIdForMaterial } from "../../shared/definitions/gathering.js";
16import { canMineMaterial, oreItemIdForMaterial, woodworkingXpForDebark } from "../../shared/definitions/gathering.js";
17import {
17import {
18 clearResolvedAlchemyPotionsCache,
18 clearResolvedAlchemyPotionsCache,
19 resolvedAlchemyPotions,
19 resolvedAlchemyPotions,
@@ -84,6 +84,14 @@ test("debarked logs keep oak itemId but change name and sprite", () =>
84 assert.equal(barkItemIdForWood(WoodTier.oak), WoodItemId.oakBark);
84 assert.equal(barkItemIdForWood(WoodTier.oak), WoodItemId.oakBark);
85});
85});
86
86
87test("debark Crafting XP is half wood tier rank rounded up", () =>
88{
89 assert.equal(woodworkingXpForDebark(WoodTier.pine), 1);
90 assert.equal(woodworkingXpForDebark(WoodTier.birch), 1);
91 assert.equal(woodworkingXpForDebark(WoodTier.oak), 2);
92 assert.equal(woodworkingXpForDebark(WoodTier.elder), 4);
93});
94
87test("debark-log on ground oak log yields bark and debarked flag", () =>
95test("debark-log on ground oak log yields bark and debarked flag", () =>
88{
96{
89 const harness = makeSimulation({ workerCount: 1 });
97 const harness = makeSimulation({ workerCount: 1 });
@@ -92,6 +100,7 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
92 harness.simulation.reloadWorld();
100 harness.simulation.reloadWorld();
93 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
101 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
94 setSkillLevel(harness, character.character_id, SkillId.woodcutting, 20);
102 setSkillLevel(harness, character.character_id, SkillId.woodcutting, 20);
103 setSkillLevel(harness, character.character_id, SkillId.crafting, 1);
95 const inventory = emptySlots();
104 const inventory = emptySlots();
96 inventory[0] = { itemId: ItemId.ironAxe, quantity: 1 };
105 inventory[0] = { itemId: ItemId.ironAxe, quantity: 1 };
97 harness.stateDb.saveBag(character.character_id, {
106 harness.stateDb.saveBag(character.character_id, {
@@ -103,6 +112,8 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
103 const entityId = harness.simulation.spawnCharacter(1, character);
112 const entityId = harness.simulation.spawnCharacter(1, character);
104 const record = harness.simulation.entityRecord(entityId);
113 const record = harness.simulation.entityRecord(entityId);
105 const worker = harness.simulation.workers[record.workerId];
114 const worker = harness.simulation.workers[record.workerId];
115 const handle = worker.world.ecs.handleOf(entityId);
116 const craftingXpBefore = worker.world.ecs.get(handle, Component.skills).xp[SkillId.crafting] | 0;
106
117
107 const groundItemId = (worker.world.nextGroundItemId = (worker.world.nextGroundItemId ?? 1) + 1);
118 const groundItemId = (worker.world.nextGroundItemId = (worker.world.nextGroundItemId ?? 1) + 1);
108 addGroundItem(worker.world, {
119 addGroundItem(worker.world, {
@@ -122,7 +133,6 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
122 });
133 });
123 harness.simulation.step();
134 harness.simulation.step();
124
135
125 const handle = worker.world.ecs.handleOf(entityId);
126 const gather = worker.world.ecs.get(handle, Component.gather);
136 const gather = worker.world.ecs.get(handle, Component.gather);
127 assert.equal(gather?.kind, "debark");
137 assert.equal(gather?.kind, "debark");
128 assert.equal(gather?.durationMs, 2000);
138 assert.equal(gather?.durationMs, 2000);
@@ -143,6 +153,9 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
143 assert.ok(bark);
153 assert.ok(bark);
144 assert.equal(bark.stack.quantity, 1);
154 assert.equal(bark.stack.quantity, 1);
145 assert.equal(worker.world.ecs.has(handle, Component.gather), false);
155 assert.equal(worker.world.ecs.has(handle, Component.gather), false);
156
157 const craftingXpAfter = worker.world.ecs.get(handle, Component.skills).xp[SkillId.crafting] | 0;
158 assert.equal(craftingXpAfter - craftingXpBefore, woodworkingXpForDebark(WoodTier.oak));
146 }
159 }
147 finally
160 finally
148 { harness.close(); }
161 { harness.close(); }
shared/definitions/gathering.js +6 −0
@@ -117,6 +117,12 @@ export function woodcuttingXpForWood (woodTier)
117 117 return Math.max(1, tierRank(woodTier) * 5);
118 118 }
119 119
120 /** Crafting XP for stripping bark from a log (half of wood tier rank, rounded up). */
121 export function woodworkingXpForDebark (woodTier)
122 {
123 return Math.max(1, Math.ceil(tierRank(woodTier) / 2));
124 }
125
120 126 /** Smithing XP awarded per successful smelt (scales with bar rank). */
121 127 export function smeltingXpForMaterial (materialId)
122 128 {
@@ -117,6 +117,12 @@ export function woodcuttingXpForWood (woodTier)
117 return Math.max(1, tierRank(woodTier) * 5);
117 return Math.max(1, tierRank(woodTier) * 5);
118}
118}
119
119
120/** Crafting XP for stripping bark from a log (half of wood tier rank, rounded up). */
121export function woodworkingXpForDebark (woodTier)
122{
123 return Math.max(1, Math.ceil(tierRank(woodTier) / 2));
124}
125
120/** Smithing XP awarded per successful smelt (scales with bar rank). */
126/** Smithing XP awarded per successful smelt (scales with bar rank). */
121export function smeltingXpForMaterial (materialId)
127export function smeltingXpForMaterial (materialId)
122{
128{