Harden character logout despawn dimensionId for cave interest.
Stamp dimension from the entity record when queuing replicationDespawn so observers in non-overworld dims always get entity-despawn; add regression test.
@@ -964,16 +964,22 @@ export class Simulation
964
964
});
965
965
if (dropped)
966
966
{
967
const dimensionId = normalizeDimensionId(
968
dropped.dimensionId ?? record.dimensionId ?? OVERWORLD_ID
969
);
967
970
this.stateDb.saveCharacterPosition(
968
971
characterId,
969
972
dropped.tileX,
970
973
dropped.tileY,
971
974
dropped.gait ?? GAIT.walk,
972
dropped.dimensionId ?? OVERWORLD_ID
975
dimensionId
973
976
);
974
977
if (dropped.health != null)
975
978
{ this.stateDb.saveCharacterHealth(characterId, dropped.health); }
976
this.#queueReplication(replicationDespawn(dropped));
979
this.#queueReplication({
980
...replicationDespawn(dropped),
981
dimensionId
982
});
977
983
}
978
984
this.#forget(entityId);
979
985
this.combatLogouts.delete(characterId | 0);
@@ -964,16 +964,22 @@ export class Simulation964
});964
});965
if (dropped)965
if (dropped)966
{966
{967
const dimensionId = normalizeDimensionId(968
dropped.dimensionId ?? record.dimensionId ?? OVERWORLD_ID969
);967
this.stateDb.saveCharacterPosition(970
this.stateDb.saveCharacterPosition(968
characterId,971
characterId,969
dropped.tileX,972
dropped.tileX,970
dropped.tileY,973
dropped.tileY,971
dropped.gait ?? GAIT.walk,974
dropped.gait ?? GAIT.walk,972
dropped.dimensionId ?? OVERWORLD_ID975
dimensionId973
);976
);974
if (dropped.health != null)977
if (dropped.health != null)975
{ this.stateDb.saveCharacterHealth(characterId, dropped.health); }978
{ this.stateDb.saveCharacterHealth(characterId, dropped.health); }976
this.#queueReplication(replicationDespawn(dropped));979
this.#queueReplication({980
...replicationDespawn(dropped),981
dimensionId982
});977
}983
}978
this.#forget(entityId);984
this.#forget(entityId);979
this.combatLogouts.delete(characterId | 0);985
this.combatLogouts.delete(characterId | 0);@@ -242,3 +242,29 @@ test("cave rat kill advances killCount quest progress", () =>
242
242
finally
243
243
{ harness.close(); }
244
244
});
245
246
test("character logout despawn carries dimensionId for cave interest", () =>
247
{
248
const harness = makeCaveHarness();
249
try
250
{
251
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
252
harness.stateDb.saveCharacterPosition(character.character_id, 8, 8, "walk", CAVE_ID);
253
const entityId = harness.simulation.spawnCharacter(1, character);
254
assert.equal(harness.simulation.positionOf(entityId).dimensionId, CAVE_ID);
255
harness.simulation.drainReplication();
256
257
harness.simulation.despawnCharacter(character.character_id);
258
const gone = harness.simulation.drainReplication();
259
const despawn = gone.find((event) =>
260
event.type === "entity-despawn" && event.entityId === entityId
261
);
262
assert.ok(despawn, "expected entity-despawn replication");
263
assert.equal(despawn.dimensionId, CAVE_ID);
264
const keys = eventInterestKeys(despawn, () => null);
265
assert.equal(keys.dimensionId, CAVE_ID);
266
assert.equal(keys.toKey, chunkKey(tileToChunk(8), tileToChunk(8), CAVE_ID));
267
}
268
finally
269
{ harness.close(); }
270
});
@@ -242,3 +242,29 @@ test("cave rat kill advances killCount quest progress", () =>242
finally242
finally243
{ harness.close(); }243
{ harness.close(); }244
});244
});245
246
test("character logout despawn carries dimensionId for cave interest", () =>247
{248
const harness = makeCaveHarness();249
try250
{251
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });252
harness.stateDb.saveCharacterPosition(character.character_id, 8, 8, "walk", CAVE_ID);253
const entityId = harness.simulation.spawnCharacter(1, character);254
assert.equal(harness.simulation.positionOf(entityId).dimensionId, CAVE_ID);255
harness.simulation.drainReplication();256
257
harness.simulation.despawnCharacter(character.character_id);258
const gone = harness.simulation.drainReplication();259
const despawn = gone.find((event) =>260
event.type === "entity-despawn" && event.entityId === entityId261
);262
assert.ok(despawn, "expected entity-despawn replication");263
assert.equal(despawn.dimensionId, CAVE_ID);264
const keys = eventInterestKeys(despawn, () => null);265
assert.equal(keys.dimensionId, CAVE_ID);266
assert.equal(keys.toKey, chunkKey(tileToChunk(8), tileToChunk(8), CAVE_ID));267
}268
finally269
{ harness.close(); }270
});