Merge the final debarked log into existing ground piles.
Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -55,7 +55,7 @@ import {
55
55
SeasonId,
56
56
scaleRegrowDurationMs
57
57
} from "../../../shared/world/season.js";
58
import { bagView, placeOrMergeGroundStack, publicGroundItem } from "../items/bags.js";
58
import { bagView, placeOrMergeGroundStack, publicGroundItem, removeGroundItem } from "../items/bags.js";
59
59
import { clearEngage } from "../combat/service.js";
60
60
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
61
61
import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";
@@ -842,11 +842,15 @@ function completeDebark (world, handle, entityId, character, gather, events, pri
842
842
instance: debarkedLogInstance(),
843
843
origins: split.taken
844
844
});
845
const tileX = item.tileX;
846
const tileY = item.tileY;
847
let reuseGroundItemId = null;
845
848
846
849
if (qty === 1)
847
850
{
848
item.stack = debarkedStack;
849
events.push(publishGroundItem(item));
851
reuseGroundItemId = item.groundItemId;
852
removeGroundItem(world, item.groundItemId);
853
events.push({ type: "ground-item-despawn", ...publicGroundItem(item) });
850
854
}
851
855
else
852
856
{
@@ -857,21 +861,22 @@ function completeDebark (world, handle, entityId, character, gather, events, pri
857
861
origins: split.remain
858
862
};
859
863
events.push(publishGroundItem(item));
860
861
const placedDebarked = placeOrMergeGroundStack(world, {
862
tileX: item.tileX,
863
tileY: item.tileY,
864
stack: debarkedStack,
865
now,
866
source: "debark",
867
droppedByCharacterId: character.characterId
868
});
869
events.push(...placedDebarked.events);
870
864
}
871
865
866
const placedDebarked = placeOrMergeGroundStack(world, {
867
tileX,
868
tileY,
869
stack: debarkedStack,
870
now,
871
source: "debark",
872
droppedByCharacterId: character.characterId,
873
groundItemId: reuseGroundItemId
874
});
875
events.push(...placedDebarked.events);
876
872
877
const placedBark = placeOrMergeGroundStack(world, {
873
tileX: item.tileX,
874
tileY: item.tileY,
878
tileX,
879
tileY,
875
880
stack: attachOrigins({
876
881
itemId: gather.barkItemId,
877
882
quantity: 1,
@@ -55,7 +55,7 @@ import {55
SeasonId,55
SeasonId,56
scaleRegrowDurationMs56
scaleRegrowDurationMs57
} from "../../../shared/world/season.js";57
} from "../../../shared/world/season.js";58
import { bagView, placeOrMergeGroundStack, publicGroundItem } from "../items/bags.js";58
import { bagView, placeOrMergeGroundStack, publicGroundItem, removeGroundItem } from "../items/bags.js";59
import { clearEngage } from "../combat/service.js";59
import { clearEngage } from "../combat/service.js";60
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";60
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";61
import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";61
import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";@@ -842,11 +842,15 @@ function completeDebark (world, handle, entityId, character, gather, events, pri842
instance: debarkedLogInstance(),842
instance: debarkedLogInstance(),843
origins: split.taken843
origins: split.taken844
});844
});845
const tileX = item.tileX;846
const tileY = item.tileY;847
let reuseGroundItemId = null;845
848
846
if (qty === 1)849
if (qty === 1)847
{850
{848
item.stack = debarkedStack;851
reuseGroundItemId = item.groundItemId;849
events.push(publishGroundItem(item));852
removeGroundItem(world, item.groundItemId);853
events.push({ type: "ground-item-despawn", ...publicGroundItem(item) });850
}854
}851
else855
else852
{856
{@@ -857,21 +861,22 @@ function completeDebark (world, handle, entityId, character, gather, events, pri857
origins: split.remain861
origins: split.remain858
};862
};859
events.push(publishGroundItem(item));863
events.push(publishGroundItem(item));860
861
const placedDebarked = placeOrMergeGroundStack(world, {862
tileX: item.tileX,863
tileY: item.tileY,864
stack: debarkedStack,865
now,866
source: "debark",867
droppedByCharacterId: character.characterId868
});869
events.push(...placedDebarked.events);870
}864
}871
865
866
const placedDebarked = placeOrMergeGroundStack(world, {867
tileX,868
tileY,869
stack: debarkedStack,870
now,871
source: "debark",872
droppedByCharacterId: character.characterId,873
groundItemId: reuseGroundItemId874
});875
events.push(...placedDebarked.events);876
872
const placedBark = placeOrMergeGroundStack(world, {877
const placedBark = placeOrMergeGroundStack(world, {873
tileX: item.tileX,878
tileX,874
tileY: item.tileY,879
tileY,875
stack: attachOrigins({880
stack: attachOrigins({876
itemId: gather.barkItemId,881
itemId: gather.barkItemId,877
quantity: 1,882
quantity: 1,@@ -226,6 +226,73 @@ test("debark-log on a ground log stack strips only one log", () =>
226
226
{ harness.close(); }
227
227
});
228
228
229
test("debarking a ground log stack merges all debarked logs into one pile", () =>
230
{
231
const harness = makeSimulation({ workerCount: 1 });
232
try
233
{
234
harness.simulation.reloadWorld();
235
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
236
setSkillLevel(harness, character.character_id, SkillId.woodcutting, 20);
237
const inventory = emptySlots();
238
inventory[0] = { itemId: ItemId.ironAxe, quantity: 1 };
239
harness.stateDb.saveBag(character.character_id, {
240
inventory,
241
equipment: emptyEquipment(),
242
vault: [],
243
vaultReserved: []
244
});
245
const entityId = harness.simulation.spawnCharacter(1, character);
246
const record = harness.simulation.entityRecord(entityId);
247
const worker = harness.simulation.workers[record.workerId];
248
249
const groundItemId = (worker.world.nextGroundItemId = (worker.world.nextGroundItemId ?? 1) + 1);
250
addGroundItem(worker.world, {
251
groundItemId,
252
tileX: 8,
253
tileY: 9,
254
stack: { itemId: WoodItemId.oakLog, quantity: 3 },
255
droppedAt: Date.now(),
256
expiresAt: Date.now() + 600_000,
257
source: "test"
258
});
259
260
for (let n = 0; n < 3; n++)
261
{
262
const plain = [...worker.world.groundItems.values()]
263
.find((row) => row.stack?.itemId === WoodItemId.oakLog && !isLogDebarked(row.stack));
264
assert.ok(plain, `plain log pile before debark ${n + 1}`);
265
harness.simulation.enqueue(1, {
266
type: "debark-log",
267
characterId: character.character_id,
268
groundItemId: plain.groundItemId
269
});
270
harness.simulation.step();
271
for (let i = 0; i < 50; i++)
272
{
273
harness.advance(50);
274
harness.simulation.step();
275
}
276
}
277
278
const plainLeft = [...worker.world.groundItems.values()]
279
.filter((row) => row.stack?.itemId === WoodItemId.oakLog && !isLogDebarked(row.stack));
280
assert.equal(plainLeft.length, 0);
281
282
const debarkedPiles = [...worker.world.groundItems.values()]
283
.filter((row) => row.stack?.itemId === WoodItemId.oakLog && isLogDebarked(row.stack));
284
assert.equal(debarkedPiles.length, 1);
285
assert.equal(debarkedPiles[0].stack.quantity, 3);
286
287
const bark = [...worker.world.groundItems.values()]
288
.find((row) => row.stack?.itemId === WoodItemId.oakBark);
289
assert.ok(bark);
290
assert.equal(bark.stack.quantity, 3);
291
}
292
finally
293
{ harness.close(); }
294
});
295
229
296
test("animal fat and tanning brew alchemy recipes resolve", () =>
230
297
{
231
298
clearResolvedAlchemyPotionsCache();
@@ -226,6 +226,73 @@ test("debark-log on a ground log stack strips only one log", () =>226
{ harness.close(); }226
{ harness.close(); }227
});227
});228
228
229
test("debarking a ground log stack merges all debarked logs into one pile", () =>230
{231
const harness = makeSimulation({ workerCount: 1 });232
try233
{234
harness.simulation.reloadWorld();235
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });236
setSkillLevel(harness, character.character_id, SkillId.woodcutting, 20);237
const inventory = emptySlots();238
inventory[0] = { itemId: ItemId.ironAxe, quantity: 1 };239
harness.stateDb.saveBag(character.character_id, {240
inventory,241
equipment: emptyEquipment(),242
vault: [],243
vaultReserved: []244
});245
const entityId = harness.simulation.spawnCharacter(1, character);246
const record = harness.simulation.entityRecord(entityId);247
const worker = harness.simulation.workers[record.workerId];248
249
const groundItemId = (worker.world.nextGroundItemId = (worker.world.nextGroundItemId ?? 1) + 1);250
addGroundItem(worker.world, {251
groundItemId,252
tileX: 8,253
tileY: 9,254
stack: { itemId: WoodItemId.oakLog, quantity: 3 },255
droppedAt: Date.now(),256
expiresAt: Date.now() + 600_000,257
source: "test"258
});259
260
for (let n = 0; n < 3; n++)261
{262
const plain = [...worker.world.groundItems.values()]263
.find((row) => row.stack?.itemId === WoodItemId.oakLog && !isLogDebarked(row.stack));264
assert.ok(plain, `plain log pile before debark ${n + 1}`);265
harness.simulation.enqueue(1, {266
type: "debark-log",267
characterId: character.character_id,268
groundItemId: plain.groundItemId269
});270
harness.simulation.step();271
for (let i = 0; i < 50; i++)272
{273
harness.advance(50);274
harness.simulation.step();275
}276
}277
278
const plainLeft = [...worker.world.groundItems.values()]279
.filter((row) => row.stack?.itemId === WoodItemId.oakLog && !isLogDebarked(row.stack));280
assert.equal(plainLeft.length, 0);281
282
const debarkedPiles = [...worker.world.groundItems.values()]283
.filter((row) => row.stack?.itemId === WoodItemId.oakLog && isLogDebarked(row.stack));284
assert.equal(debarkedPiles.length, 1);285
assert.equal(debarkedPiles[0].stack.quantity, 3);286
287
const bark = [...worker.world.groundItems.values()]288
.find((row) => row.stack?.itemId === WoodItemId.oakBark);289
assert.ok(bark);290
assert.equal(bark.stack.quantity, 3);291
}292
finally293
{ harness.close(); }294
});295
229
test("animal fat and tanning brew alchemy recipes resolve", () =>296
test("animal fat and tanning brew alchemy recipes resolve", () =>230
{297
{231
clearResolvedAlchemyPotionsCache();298
clearResolvedAlchemyPotionsCache();