BlueGit

timfa questward

Pass death dimension into bounty payout office lookup.

settleKill now forwards deathDimensionId so payout letters originate
from the nearest bounty office in the death dimension (with XY fallback).

timfa Tim Falken · pushed by timfa

Authored 2026-09-13 · 2 months ago

Hash
66e2a9541d27436bca54b7a5cfcc21bfd9bdda0f
Parent
a5681860
3 files changed +90 −9
server/src/bounty/service.js +6 −5
@@ -232,7 +232,7 @@ export class BountyService
232 232 * Friend / same-account / mob kills leave the bounty untouched.
233 233 * @returns {{ paidCopper: number, victimName: string } | null}
234 234 */
235 settleKill (victimCharacterId, attackerEntityId, deathTileX, deathTileY)
235 settleKill (victimCharacterId, attackerEntityId, deathTileX, deathTileY, deathDimensionId = null)
236 236 {
237 237 const attackerId = attackerEntityId | 0;
238 238 if (!attackerId)
@@ -275,7 +275,8 @@ export class BountyService
275 275 victimName,
276 276 paidCopper,
277 277 deathTileX,
278 deathTileY
278 deathTileY,
279 deathDimensionId
279 280 });
280 281
281 282 this.simulation.pendingPrivate.push({
@@ -309,10 +310,10 @@ export class BountyService
309 310 };
310 311 }
311 312
312 #dispatchPayoutLetter ({ killerCharacterId, killerName, victimName, paidCopper, deathTileX, deathTileY })
313 #dispatchPayoutLetter ({ killerCharacterId, killerName, victimName, paidCopper, deathTileX, deathTileY, deathDimensionId = null })
313 314 {
314 const office = this.courier?.nearestBountyOffice?.(deathTileX | 0, deathTileY | 0)
315 ?? { tileX: deathTileX | 0, tileY: deathTileY | 0 };
315 const office = this.courier?.nearestBountyOffice?.(deathTileX | 0, deathTileY | 0, deathDimensionId)
316 ?? { tileX: deathTileX | 0, tileY: deathTileY | 0, dimensionId: deathDimensionId };
316 317 const body = bountyPayoutLetterBody({
317 318 killerName,
318 319 victimName,
@@ -232,7 +232,7 @@ export class BountyService
232 * Friend / same-account / mob kills leave the bounty untouched.
232 * Friend / same-account / mob kills leave the bounty untouched.
233 * @returns {{ paidCopper: number, victimName: string } | null}
233 * @returns {{ paidCopper: number, victimName: string } | null}
234 */
234 */
235 settleKill (victimCharacterId, attackerEntityId, deathTileX, deathTileY)
235 settleKill (victimCharacterId, attackerEntityId, deathTileX, deathTileY, deathDimensionId = null)
236 {
236 {
237 const attackerId = attackerEntityId | 0;
237 const attackerId = attackerEntityId | 0;
238 if (!attackerId)
238 if (!attackerId)
@@ -275,7 +275,8 @@ export class BountyService
275 victimName,
275 victimName,
276 paidCopper,
276 paidCopper,
277 deathTileX,
277 deathTileX,
278 deathTileY
278 deathTileY,
279 deathDimensionId
279 });
280 });
280
281
281 this.simulation.pendingPrivate.push({
282 this.simulation.pendingPrivate.push({
@@ -309,10 +310,10 @@ export class BountyService
309 };
310 };
310 }
311 }
311
312
312 #dispatchPayoutLetter ({ killerCharacterId, killerName, victimName, paidCopper, deathTileX, deathTileY })
313 #dispatchPayoutLetter ({ killerCharacterId, killerName, victimName, paidCopper, deathTileX, deathTileY, deathDimensionId = null })
313 {
314 {
314 const office = this.courier?.nearestBountyOffice?.(deathTileX | 0, deathTileY | 0)
315 const office = this.courier?.nearestBountyOffice?.(deathTileX | 0, deathTileY | 0, deathDimensionId)
315 ?? { tileX: deathTileX | 0, tileY: deathTileY | 0 };
316 ?? { tileX: deathTileX | 0, tileY: deathTileY | 0, dimensionId: deathDimensionId };
316 const body = bountyPayoutLetterBody({
317 const body = bountyPayoutLetterBody({
317 killerName,
318 killerName,
318 victimName,
319 victimName,
server/src/simulation/simulation.js +2 −1
@@ -2266,7 +2266,8 @@ export class Simulation
2266 2266 event.characterId,
2267 2267 event.attackerId,
2268 2268 event.tileX,
2269 event.tileY
2269 event.tileY,
2270 record.dimensionId ?? OVERWORLD_ID
2270 2271 );
2271 2272 const attackerRecord = event.attackerId != null ? this.directory.get(event.attackerId) : null;
2272 2273 const killerCharacterId = Number(attackerRecord?.characterId) || 0;
@@ -2266,7 +2266,8 @@ export class Simulation
2266 event.characterId,
2266 event.characterId,
2267 event.attackerId,
2267 event.attackerId,
2268 event.tileX,
2268 event.tileX,
2269 event.tileY
2269 event.tileY,
2270 record.dimensionId ?? OVERWORLD_ID
2270 );
2271 );
2271 const attackerRecord = event.attackerId != null ? this.directory.get(event.attackerId) : null;
2272 const attackerRecord = event.attackerId != null ? this.directory.get(event.attackerId) : null;
2272 const killerCharacterId = Number(attackerRecord?.characterId) || 0;
2273 const killerCharacterId = Number(attackerRecord?.characterId) || 0;
server/tests/bounty.test.js +82 −3
@@ -5,22 +5,35 @@ import { ItemId } from "../../shared/definitions/items.js";
5 5 import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js";
6 6 import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
7 7 import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
8 import { OVERWORLD_ID } from "../../shared/world/dimensions.js";
8 9
9 function placeBlock (worldDb, tileX, tileY, typeId)
10 function placeBlock (worldDb, tileX, tileY, typeId, dimensionId = OVERWORLD_ID)
10 11 {
11 12 const chunkX = Math.floor(tileX / 16);
12 13 const chunkY = Math.floor(tileY / 16);
14 const rev = worldDb.getActiveRevisionId();
15 const existing = worldDb.getChunkVersion(chunkX, chunkY, rev, dimensionId);
13 16 const data = createEmptyChunkData();
14 17 data.open = true;
18 if (existing?.data_blob)
19 {
20 const parsed = typeof existing.data_blob === "string"
21 ? JSON.parse(existing.data_blob)
22 : existing.data_blob;
23 data.grounds = parsed.grounds ?? data.grounds;
24 data.blocks = parsed.blocks ?? data.blocks;
25 data.open = parsed.open ?? true;
26 }
15 27 const localX = tileX - chunkX * 16;
16 28 const localY = tileY - chunkY * 16;
17 29 data.blocks[localY * 16 + localX] = { typeId, state: 0 };
18 30 worldDb.saveChunkVersion(
19 31 chunkX,
20 32 chunkY,
21 worldDb.getActiveRevisionId(),
33 rev,
22 34 true,
23 encodeChunkBlob(data)
35 encodeChunkBlob(data),
36 dimensionId
24 37 );
25 38 }
26 39
@@ -291,3 +304,69 @@ test("bounty decays one coin per calendar day", () =>
291 304 finally
292 305 { harness.close(); }
293 306 });
307
308
309 test("bounty payout letter prefers office in death dimension", () =>
310 {
311 const harness = makeSimulation({ workerCount: 1 });
312 const CAVE_ID = "bounty-cave";
313 try
314 {
315 const rev = harness.worldDb.getActiveRevisionId();
316 harness.worldDb.saveDimension(rev, {
317 dimensionId: CAVE_ID,
318 displayName: "Bounty Cave",
319 lightingMode: "alwaysLit",
320 seasonMode: "summer",
321 defaultGroundTypeId: 1
322 });
323 const cave = createEmptyChunkData();
324 cave.open = true;
325 harness.worldDb.saveChunkVersion(0, 0, rev, true, encodeChunkBlob(cave), CAVE_ID);
326
327 // Overworld office farther from death tile than cave office
328 placeBlock(harness.worldDb, 2, 2, BlockType.bountyOffice, OVERWORLD_ID);
329 placeBlock(harness.worldDb, 1, 2, BlockType.bank, OVERWORLD_ID);
330 placeBlock(harness.worldDb, 9, 9, BlockType.bountyOffice, CAVE_ID);
331 placeBlock(harness.worldDb, 8, 9, BlockType.bank, CAVE_ID);
332 harness.simulation.reloadWorld();
333
334 const victim = makeCharacter(harness.stateDb, {
335 firstName: "Vic",
336 lastName: "DimVictim",
337 tileX: 10,
338 tileY: 9
339 });
340 const killer = makeCharacter(harness.stateDb, {
341 firstName: "Kill",
342 lastName: "DimKiller",
343 tileX: 11,
344 tileY: 9
345 });
346 harness.stateDb.addCharacterBounty(victim.character_id, 400);
347
348 const killerId = harness.simulation.spawnCharacter(2, killer);
349 const settled = harness.simulation.bounty.settleKill(
350 victim.character_id,
351 killerId,
352 10,
353 9,
354 CAVE_ID
355 );
356 assert.equal(settled?.paidCopper, 400);
357
358 const office = harness.simulation.courier.nearestBountyOffice(10, 9, CAVE_ID);
359 assert.equal(office.dimensionId, CAVE_ID);
360 assert.equal(office.tileX, 9);
361 assert.equal(office.tileY, 9);
362
363 const open = harness.stateDb.listActiveCourierTransits();
364 assert.ok(open.length >= 1);
365 const row = open[open.length - 1];
366 assert.equal(row.originDimensionId, CAVE_ID);
367 assert.equal(Math.floor(row.originX), 9);
368 assert.equal(Math.floor(row.originY), 9);
369 }
370 finally
371 { harness.close(); }
372 });
@@ -5,22 +5,35 @@ import { ItemId } from "../../shared/definitions/items.js";
5import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js";
5import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js";
6import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
6import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
7import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
7import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
8import { OVERWORLD_ID } from "../../shared/world/dimensions.js";
8
9
9function placeBlock (worldDb, tileX, tileY, typeId)
10function placeBlock (worldDb, tileX, tileY, typeId, dimensionId = OVERWORLD_ID)
10{
11{
11 const chunkX = Math.floor(tileX / 16);
12 const chunkX = Math.floor(tileX / 16);
12 const chunkY = Math.floor(tileY / 16);
13 const chunkY = Math.floor(tileY / 16);
14 const rev = worldDb.getActiveRevisionId();
15 const existing = worldDb.getChunkVersion(chunkX, chunkY, rev, dimensionId);
13 const data = createEmptyChunkData();
16 const data = createEmptyChunkData();
14 data.open = true;
17 data.open = true;
18 if (existing?.data_blob)
19 {
20 const parsed = typeof existing.data_blob === "string"
21 ? JSON.parse(existing.data_blob)
22 : existing.data_blob;
23 data.grounds = parsed.grounds ?? data.grounds;
24 data.blocks = parsed.blocks ?? data.blocks;
25 data.open = parsed.open ?? true;
26 }
15 const localX = tileX - chunkX * 16;
27 const localX = tileX - chunkX * 16;
16 const localY = tileY - chunkY * 16;
28 const localY = tileY - chunkY * 16;
17 data.blocks[localY * 16 + localX] = { typeId, state: 0 };
29 data.blocks[localY * 16 + localX] = { typeId, state: 0 };
18 worldDb.saveChunkVersion(
30 worldDb.saveChunkVersion(
19 chunkX,
31 chunkX,
20 chunkY,
32 chunkY,
21 worldDb.getActiveRevisionId(),
33 rev,
22 true,
34 true,
23 encodeChunkBlob(data)
35 encodeChunkBlob(data),
36 dimensionId
24 );
37 );
25}
38}
26
39
@@ -291,3 +304,69 @@ test("bounty decays one coin per calendar day", () =>
291 finally
304 finally
292 { harness.close(); }
305 { harness.close(); }
293});
306});
307
308
309test("bounty payout letter prefers office in death dimension", () =>
310{
311 const harness = makeSimulation({ workerCount: 1 });
312 const CAVE_ID = "bounty-cave";
313 try
314 {
315 const rev = harness.worldDb.getActiveRevisionId();
316 harness.worldDb.saveDimension(rev, {
317 dimensionId: CAVE_ID,
318 displayName: "Bounty Cave",
319 lightingMode: "alwaysLit",
320 seasonMode: "summer",
321 defaultGroundTypeId: 1
322 });
323 const cave = createEmptyChunkData();
324 cave.open = true;
325 harness.worldDb.saveChunkVersion(0, 0, rev, true, encodeChunkBlob(cave), CAVE_ID);
326
327 // Overworld office farther from death tile than cave office
328 placeBlock(harness.worldDb, 2, 2, BlockType.bountyOffice, OVERWORLD_ID);
329 placeBlock(harness.worldDb, 1, 2, BlockType.bank, OVERWORLD_ID);
330 placeBlock(harness.worldDb, 9, 9, BlockType.bountyOffice, CAVE_ID);
331 placeBlock(harness.worldDb, 8, 9, BlockType.bank, CAVE_ID);
332 harness.simulation.reloadWorld();
333
334 const victim = makeCharacter(harness.stateDb, {
335 firstName: "Vic",
336 lastName: "DimVictim",
337 tileX: 10,
338 tileY: 9
339 });
340 const killer = makeCharacter(harness.stateDb, {
341 firstName: "Kill",
342 lastName: "DimKiller",
343 tileX: 11,
344 tileY: 9
345 });
346 harness.stateDb.addCharacterBounty(victim.character_id, 400);
347
348 const killerId = harness.simulation.spawnCharacter(2, killer);
349 const settled = harness.simulation.bounty.settleKill(
350 victim.character_id,
351 killerId,
352 10,
353 9,
354 CAVE_ID
355 );
356 assert.equal(settled?.paidCopper, 400);
357
358 const office = harness.simulation.courier.nearestBountyOffice(10, 9, CAVE_ID);
359 assert.equal(office.dimensionId, CAVE_ID);
360 assert.equal(office.tileX, 9);
361 assert.equal(office.tileY, 9);
362
363 const open = harness.stateDb.listActiveCourierTransits();
364 assert.ok(open.length >= 1);
365 const row = open[open.length - 1];
366 assert.equal(row.originDimensionId, CAVE_ID);
367 assert.equal(Math.floor(row.originX), 9);
368 assert.equal(Math.floor(row.originY), 9);
369 }
370 finally
371 { harness.close(); }
372});