BlueGit

timfa questward

Fix skull markers after PvP kills for the killer and everyone nearby.

Preserve skullValue across directory remember, enrich chunk snapshots, force-replicate on kill, and place the marker immediately when ENTITY_SKULL arrives.

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
4a779bdf9abf04c9caaa8b20e8c7e8a4e39fc5cb
Parent
a7a75075
4 files changed +148 −25
client/src/render/worldView.js +8 −2
@@ -754,7 +754,12 @@ export class WorldView
754 754 if (!entity)
755 755 { return; }
756 756 entity.skullValue = Math.max(0, skullValue | 0);
757 this.#syncSkullMarker(entity);
757 const pivotX = (entity.visualX ?? 0) + (entity.shoveOffsetX ?? 0) + (entity.stackOffsetX ?? 0);
758 const pivotY = (entity.visualY ?? 0) + (entity.shoveOffsetY ?? 0) + (entity.stackOffsetY ?? 0);
759 const tileShade = this.#entityShadeAlpha?.(entity, performance.now())
760 ?? this.tiles.get(`${entity.tileX},${entity.tileY}`)?.shadeAlpha
761 ?? 0;
762 this.#placeSkullMarker(entity, pivotX, pivotY, tileShade);
758 763 }
759 764
760 765 updateEntityHealth (entityId, health, maxHealth)
@@ -2869,7 +2874,8 @@ export class WorldView
2869 2874 entity.skullMarker = null;
2870 2875 return;
2871 2876 }
2872 const image = this.game.images[SKULL_SPRITE];
2877 const image = this.game.images[SKULL_SPRITE]
2878 ?? this.game.images["item:skull:skull"];
2873 2879 if (!image)
2874 2880 { return; }
2875 2881 if (!entity.skullMarker)
@@ -754,7 +754,12 @@ export class WorldView
754 if (!entity)
754 if (!entity)
755 { return; }
755 { return; }
756 entity.skullValue = Math.max(0, skullValue | 0);
756 entity.skullValue = Math.max(0, skullValue | 0);
757 this.#syncSkullMarker(entity);
757 const pivotX = (entity.visualX ?? 0) + (entity.shoveOffsetX ?? 0) + (entity.stackOffsetX ?? 0);
758 const pivotY = (entity.visualY ?? 0) + (entity.shoveOffsetY ?? 0) + (entity.stackOffsetY ?? 0);
759 const tileShade = this.#entityShadeAlpha?.(entity, performance.now())
760 ?? this.tiles.get(`${entity.tileX},${entity.tileY}`)?.shadeAlpha
761 ?? 0;
762 this.#placeSkullMarker(entity, pivotX, pivotY, tileShade);
758 }
763 }
759
764
760 updateEntityHealth (entityId, health, maxHealth)
765 updateEntityHealth (entityId, health, maxHealth)
@@ -2869,7 +2874,8 @@ export class WorldView
2869 entity.skullMarker = null;
2874 entity.skullMarker = null;
2870 return;
2875 return;
2871 }
2876 }
2872 const image = this.game.images[SKULL_SPRITE];
2877 const image = this.game.images[SKULL_SPRITE]
2878 ?? this.game.images["item:skull:skull"];
2873 if (!image)
2879 if (!image)
2874 { return; }
2880 { return; }
2875 if (!entity.skullMarker)
2881 if (!entity.skullMarker)
server/src/bounty/service.js +1 −1
@@ -183,7 +183,7 @@ export class BountyService
183 183 if (!attackerId)
184 184 { return null; }
185 185 const attackerRec = this.simulation.directory.get(attackerId);
186 const killerCharacterId = attackerRec?.characterId | 0;
186 const killerCharacterId = Number(attackerRec?.characterId) || 0;
187 187 if (!killerCharacterId || killerCharacterId === (victimCharacterId | 0))
188 188 { return null; }
189 189
@@ -183,7 +183,7 @@ export class BountyService
183 if (!attackerId)
183 if (!attackerId)
184 { return null; }
184 { return null; }
185 const attackerRec = this.simulation.directory.get(attackerId);
185 const attackerRec = this.simulation.directory.get(attackerId);
186 const killerCharacterId = attackerRec?.characterId | 0;
186 const killerCharacterId = Number(attackerRec?.characterId) || 0;
187 if (!killerCharacterId || killerCharacterId === (victimCharacterId | 0))
187 if (!killerCharacterId || killerCharacterId === (victimCharacterId | 0))
188 { return null; }
188 { return null; }
189
189
server/src/simulation/simulation.js +38 −22
@@ -505,11 +505,11 @@ export class Simulation
505 505 return skullValue(bounty, killCounter);
506 506 }
507 507
508 refreshCharacterSkull (characterId)
508 refreshCharacterSkull (characterId, { force = false } = {})
509 509 {
510 510 const id = characterId | 0;
511 511 if (!id)
512 { return; }
512 { return null; }
513 513 const state = this.stateDb.getKillCounterState(id);
514 514 const elapsed = Math.max(0, this.now - (state.updatedAt | 0));
515 515 const decayed = decayKillCounter(state.killCounter, elapsed);
@@ -519,17 +519,20 @@ export class Simulation
519 519 const entityId = this.characterEntities.get(id);
520 520 const record = entityId ? this.directory.get(entityId) : null;
521 521 if (!record)
522 { return; }
523 if ((record.skullValue | 0) === value)
524 { return; }
522 { return null; }
523 if (!force && (record.skullValue | 0) === value)
524 { return value; }
525 525 record.skullValue = value;
526 this.#queueReplication({
526 const event = {
527 527 type: "entity-skull",
528 528 entityId,
529 529 skullValue: value,
530 530 tileX: record.tileX,
531 tileY: record.tileY
532 });
531 tileY: record.tileY,
532 dimensionId: record.dimensionId ?? OVERWORLD_ID
533 };
534 this.#queueReplication(event);
535 return event;
533 536 }
534 537
535 538 #attachSkullToRecord (entityId, characterId)
@@ -962,7 +965,14 @@ export class Simulation
962 965 const key = chunkKey(coord.chunkX, coord.chunkY, dimensionId);
963 966 const staticOnly = !entityKeys.has(key);
964 967 const snapshot = this.snapshotChunk(coord.chunkX, coord.chunkY, staticOnly, dimensionId);
965 return { ...snapshot, staticOnly };
968 const entities = (snapshot.entities ?? []).map((entity) =>
969 {
970 const known = this.directory.get(entity.entityId);
971 if (!known || entity.characterId == null)
972 { return entity; }
973 return { ...entity, skullValue: known.skullValue | 0 };
974 });
975 return { ...snapshot, entities, staticOnly };
966 976 });
967 977 }
968 978
@@ -1726,13 +1736,10 @@ export class Simulation
1726 1736 event.tileY
1727 1737 );
1728 1738 const attackerRecord = event.attackerId != null ? this.directory.get(event.attackerId) : null;
1729 const killerCharacterId = attackerRecord?.characterId | 0;
1739 const killerCharacterId = Number(attackerRecord?.characterId) || 0;
1730 1740 if (killerCharacterId && killerCharacterId !== (event.characterId | 0))
1731 {
1732 this.stateDb.addKillCounter(killerCharacterId, SKULL_KILL_BONUS, this.now);
1733 this.refreshCharacterSkull(killerCharacterId);
1734 }
1735 this.refreshCharacterSkull(event.characterId);
1741 { this.stateDb.addKillCounter(killerCharacterId, SKULL_KILL_BONUS, this.now); }
1742 this.refreshCharacterSkull(event.characterId, { force: true });
1736 1743 for (const worker of this.workers)
1737 1744 {
1738 1745 worker.call({
@@ -1741,13 +1748,10 @@ export class Simulation
1741 1748 targetEntityId: event.entityId
1742 1749 });
1743 1750 }
1744 const victimName = `${record.appearance?.firstName ?? "someone"} ${record.appearance?.lastName ?? ""}`.trim()
1751 const victimName = `${record.firstName ?? "someone"} ${record.lastName ?? ""}`.trim()
1752 || "someone";
1753 const killerName = `${attackerRecord?.firstName ?? ""} ${attackerRecord?.lastName ?? ""}`.trim()
1745 1754 || "someone";
1746 const killerName = attackerRecord?.appearance
1747 ? (`${attackerRecord.appearance.firstName ?? ""} ${attackerRecord.appearance.lastName ?? ""}`.trim()
1748 || attackerRecord.appearance.displayName
1749 || "someone")
1750 : "someone";
1751 1755 const corpseOrigin = lootOrigin(victimName, killerName);
1752 1756 const result = this.workers[record.workerId].call({
1753 1757 type: WorkerMessage.spawnCorpseDrops,
@@ -1777,6 +1781,12 @@ export class Simulation
1777 1781 ]
1778 1782 });
1779 1783 const events = [event];
1784 if (killerCharacterId && killerCharacterId !== (event.characterId | 0))
1785 {
1786 const skullEvent = this.refreshCharacterSkull(killerCharacterId, { force: true });
1787 if (skullEvent)
1788 { events.push(skullEvent); }
1789 }
1780 1790 events.push({
1781 1791 type: "entity-despawn",
1782 1792 entityId: event.entityId,
@@ -2736,7 +2746,13 @@ export class Simulation
2736 2746 {
2737 2747 if (!view)
2738 2748 { return; }
2739 this.directory.set(view.entityId, { ...view, workerId });
2749 const previous = this.directory.get(view.entityId);
2750 this.directory.set(view.entityId, {
2751 ...view,
2752 workerId,
2753 // Keep simulation-only fields that publicEntityView does not carry.
2754 skullValue: previous?.skullValue ?? view.skullValue ?? 0
2755 });
2740 2756 if (view.characterId)
2741 2757 { this.characterEntities.set(view.characterId, view.entityId); }
2742 2758 }
@@ -505,11 +505,11 @@ export class Simulation
505 return skullValue(bounty, killCounter);
505 return skullValue(bounty, killCounter);
506 }
506 }
507
507
508 refreshCharacterSkull (characterId)
508 refreshCharacterSkull (characterId, { force = false } = {})
509 {
509 {
510 const id = characterId | 0;
510 const id = characterId | 0;
511 if (!id)
511 if (!id)
512 { return; }
512 { return null; }
513 const state = this.stateDb.getKillCounterState(id);
513 const state = this.stateDb.getKillCounterState(id);
514 const elapsed = Math.max(0, this.now - (state.updatedAt | 0));
514 const elapsed = Math.max(0, this.now - (state.updatedAt | 0));
515 const decayed = decayKillCounter(state.killCounter, elapsed);
515 const decayed = decayKillCounter(state.killCounter, elapsed);
@@ -519,17 +519,20 @@ export class Simulation
519 const entityId = this.characterEntities.get(id);
519 const entityId = this.characterEntities.get(id);
520 const record = entityId ? this.directory.get(entityId) : null;
520 const record = entityId ? this.directory.get(entityId) : null;
521 if (!record)
521 if (!record)
522 { return; }
522 { return null; }
523 if ((record.skullValue | 0) === value)
523 if (!force && (record.skullValue | 0) === value)
524 { return; }
524 { return value; }
525 record.skullValue = value;
525 record.skullValue = value;
526 this.#queueReplication({
526 const event = {
527 type: "entity-skull",
527 type: "entity-skull",
528 entityId,
528 entityId,
529 skullValue: value,
529 skullValue: value,
530 tileX: record.tileX,
530 tileX: record.tileX,
531 tileY: record.tileY
531 tileY: record.tileY,
532 });
532 dimensionId: record.dimensionId ?? OVERWORLD_ID
533 };
534 this.#queueReplication(event);
535 return event;
533 }
536 }
534
537
535 #attachSkullToRecord (entityId, characterId)
538 #attachSkullToRecord (entityId, characterId)
@@ -962,7 +965,14 @@ export class Simulation
962 const key = chunkKey(coord.chunkX, coord.chunkY, dimensionId);
965 const key = chunkKey(coord.chunkX, coord.chunkY, dimensionId);
963 const staticOnly = !entityKeys.has(key);
966 const staticOnly = !entityKeys.has(key);
964 const snapshot = this.snapshotChunk(coord.chunkX, coord.chunkY, staticOnly, dimensionId);
967 const snapshot = this.snapshotChunk(coord.chunkX, coord.chunkY, staticOnly, dimensionId);
965 return { ...snapshot, staticOnly };
968 const entities = (snapshot.entities ?? []).map((entity) =>
969 {
970 const known = this.directory.get(entity.entityId);
971 if (!known || entity.characterId == null)
972 { return entity; }
973 return { ...entity, skullValue: known.skullValue | 0 };
974 });
975 return { ...snapshot, entities, staticOnly };
966 });
976 });
967 }
977 }
968
978
@@ -1726,13 +1736,10 @@ export class Simulation
1726 event.tileY
1736 event.tileY
1727 );
1737 );
1728 const attackerRecord = event.attackerId != null ? this.directory.get(event.attackerId) : null;
1738 const attackerRecord = event.attackerId != null ? this.directory.get(event.attackerId) : null;
1729 const killerCharacterId = attackerRecord?.characterId | 0;
1739 const killerCharacterId = Number(attackerRecord?.characterId) || 0;
1730 if (killerCharacterId && killerCharacterId !== (event.characterId | 0))
1740 if (killerCharacterId && killerCharacterId !== (event.characterId | 0))
1731 {
1741 { this.stateDb.addKillCounter(killerCharacterId, SKULL_KILL_BONUS, this.now); }
1732 this.stateDb.addKillCounter(killerCharacterId, SKULL_KILL_BONUS, this.now);
1742 this.refreshCharacterSkull(event.characterId, { force: true });
1733 this.refreshCharacterSkull(killerCharacterId);
1734 }
1735 this.refreshCharacterSkull(event.characterId);
1736 for (const worker of this.workers)
1743 for (const worker of this.workers)
1737 {
1744 {
1738 worker.call({
1745 worker.call({
@@ -1741,13 +1748,10 @@ export class Simulation
1741 targetEntityId: event.entityId
1748 targetEntityId: event.entityId
1742 });
1749 });
1743 }
1750 }
1744 const victimName = `${record.appearance?.firstName ?? "someone"} ${record.appearance?.lastName ?? ""}`.trim()
1751 const victimName = `${record.firstName ?? "someone"} ${record.lastName ?? ""}`.trim()
1752 || "someone";
1753 const killerName = `${attackerRecord?.firstName ?? ""} ${attackerRecord?.lastName ?? ""}`.trim()
1745 || "someone";
1754 || "someone";
1746 const killerName = attackerRecord?.appearance
1747 ? (`${attackerRecord.appearance.firstName ?? ""} ${attackerRecord.appearance.lastName ?? ""}`.trim()
1748 || attackerRecord.appearance.displayName
1749 || "someone")
1750 : "someone";
1751 const corpseOrigin = lootOrigin(victimName, killerName);
1755 const corpseOrigin = lootOrigin(victimName, killerName);
1752 const result = this.workers[record.workerId].call({
1756 const result = this.workers[record.workerId].call({
1753 type: WorkerMessage.spawnCorpseDrops,
1757 type: WorkerMessage.spawnCorpseDrops,
@@ -1777,6 +1781,12 @@ export class Simulation
1777 ]
1781 ]
1778 });
1782 });
1779 const events = [event];
1783 const events = [event];
1784 if (killerCharacterId && killerCharacterId !== (event.characterId | 0))
1785 {
1786 const skullEvent = this.refreshCharacterSkull(killerCharacterId, { force: true });
1787 if (skullEvent)
1788 { events.push(skullEvent); }
1789 }
1780 events.push({
1790 events.push({
1781 type: "entity-despawn",
1791 type: "entity-despawn",
1782 entityId: event.entityId,
1792 entityId: event.entityId,
@@ -2736,7 +2746,13 @@ export class Simulation
2736 {
2746 {
2737 if (!view)
2747 if (!view)
2738 { return; }
2748 { return; }
2739 this.directory.set(view.entityId, { ...view, workerId });
2749 const previous = this.directory.get(view.entityId);
2750 this.directory.set(view.entityId, {
2751 ...view,
2752 workerId,
2753 // Keep simulation-only fields that publicEntityView does not carry.
2754 skullValue: previous?.skullValue ?? view.skullValue ?? 0
2755 });
2740 if (view.characterId)
2756 if (view.characterId)
2741 { this.characterEntities.set(view.characterId, view.entityId); }
2757 { this.characterEntities.set(view.characterId, view.entityId); }
2742 }
2758 }
server/tests/skull.test.js +101 −0
@@ -9,6 +9,19 @@ import
9 9 SKULL_DARK_RED_VALUE,
10 10 SKULL_KILL_BONUS
11 11 } from "../../shared/combat/skull.js";
12 import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
13 import { Component } from "../src/ecs/components.js";
14 import { totalXpForLevel } from "../../shared/skills/progression.js";
15 import { SkillId } from "../../shared/definitions/skills.js";
16 import { WorkerMessage } from "../src/simulation/protocol.js";
17
18 function componentsOf (simulation, entityId)
19 {
20 const record = simulation.entityRecord(entityId);
21 const worker = simulation.workers[record.workerId];
22 const handle = worker.world.ecs.handleOf(entityId);
23 return worker.world.ecs.componentsOf(handle);
24 }
12 25
13 26 test("skull value is bounty plus kill counter", () =>
14 27 {
@@ -33,3 +46,91 @@ test("skull tint: invisible, white, red, dark red", () =>
33 46 assert.equal(dark.g, 0);
34 47 assert.equal(dark.b, 0);
35 48 });
49
50 test("PvP kill awards temporary skull points that replicate", () =>
51 {
52 const random = Math.random;
53 Math.random = () => 0.5;
54 const harness = makeSimulation({ workerCount: 1 });
55 try
56 {
57 const victim = makeCharacter(harness.stateDb, {
58 firstName: "Vic",
59 lastName: "Victim",
60 tileX: 9,
61 tileY: 8
62 });
63 const killer = makeCharacter(harness.stateDb, {
64 firstName: "Kill",
65 lastName: "Attacker",
66 tileX: 8,
67 tileY: 8
68 });
69 const victimId = harness.simulation.spawnCharacter(1, victim);
70 const killerId = harness.simulation.spawnCharacter(2, killer);
71
72 const killerComps = componentsOf(harness.simulation, killerId);
73 killerComps.skills.xp[SkillId.unarmed] = totalXpForLevel(20);
74 killerComps.skills.xp[SkillId.strength] = totalXpForLevel(20);
75 componentsOf(harness.simulation, victimId).health.current = 1;
76
77 harness.simulation.enqueue(2, {
78 type: "attack",
79 characterId: killer.character_id,
80 targetEntityId: victimId
81 });
82 let skullEvent = null;
83 for (let i = 0; i < 40; i++)
84 {
85 harness.advance(200);
86 const result = harness.simulation.step();
87 skullEvent = result.events.find((event) =>
88 event.type === "entity-skull" && event.entityId === killerId
89 ) ?? result.replication?.find?.((event) =>
90 event.type === "entity-skull" && event.entityId === killerId
91 ) ?? skullEvent;
92 if (componentsOf(harness.simulation, victimId)[Component.dead])
93 { break; }
94 }
95 assert.ok(componentsOf(harness.simulation, victimId)[Component.dead], "victim should die");
96 assert.equal(harness.stateDb.peekKillCounter(killer.character_id, harness.now()), SKULL_KILL_BONUS);
97 assert.equal(harness.simulation.directory.get(killerId).skullValue, SKULL_KILL_BONUS);
98 assert.ok(skullEvent, "entity-skull must replicate to clients");
99 assert.equal(skullEvent.skullValue, SKULL_KILL_BONUS);
100
101 // Directory skull survives a remember overwrite from public entity view.
102 const worker = harness.simulation.workers[
103 harness.simulation.entityRecord(killerId).workerId
104 ];
105 const view = worker.call({ type: WorkerMessage.inspect, entityId: killerId });
106 harness.simulation.directory.set(killerId, { ...view, workerId: 0 });
107 harness.simulation.refreshCharacterSkull(killer.character_id, { force: true });
108 assert.equal(harness.simulation.directory.get(killerId).skullValue, SKULL_KILL_BONUS);
109 }
110 finally
111 {
112 Math.random = random;
113 harness.close();
114 }
115 });
116
117 test("snapshots include skullValue for other players", () =>
118 {
119 const harness = makeSimulation({ workerCount: 1 });
120 try
121 {
122 const a = makeCharacter(harness.stateDb, { firstName: "A", lastName: "One", tileX: 8, tileY: 8 });
123 const b = makeCharacter(harness.stateDb, { firstName: "B", lastName: "Two", tileX: 9, tileY: 8 });
124 const aId = harness.simulation.spawnCharacter(1, a);
125 const bId = harness.simulation.spawnCharacter(2, b);
126 harness.stateDb.addKillCounter(a.character_id, 500, harness.now());
127 harness.simulation.refreshCharacterSkull(a.character_id, { force: true });
128 const snaps = harness.simulation.snapshotsForView(bId, 2);
129 const entities = snaps.flatMap((snap) => snap.entities ?? []);
130 const seen = entities.find((entity) => entity.entityId === aId);
131 assert.ok(seen, "viewer should see killer in snapshot");
132 assert.equal(seen.skullValue, 500);
133 }
134 finally
135 { harness.close(); }
136 });
@@ -9,6 +9,19 @@ import
9 SKULL_DARK_RED_VALUE,
9 SKULL_DARK_RED_VALUE,
10 SKULL_KILL_BONUS
10 SKULL_KILL_BONUS
11 } from "../../shared/combat/skull.js";
11 } from "../../shared/combat/skull.js";
12import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
13import { Component } from "../src/ecs/components.js";
14import { totalXpForLevel } from "../../shared/skills/progression.js";
15import { SkillId } from "../../shared/definitions/skills.js";
16import { WorkerMessage } from "../src/simulation/protocol.js";
17
18function componentsOf (simulation, entityId)
19{
20 const record = simulation.entityRecord(entityId);
21 const worker = simulation.workers[record.workerId];
22 const handle = worker.world.ecs.handleOf(entityId);
23 return worker.world.ecs.componentsOf(handle);
24}
12
25
13test("skull value is bounty plus kill counter", () =>
26test("skull value is bounty plus kill counter", () =>
14{
27{
@@ -33,3 +46,91 @@ test("skull tint: invisible, white, red, dark red", () =>
33 assert.equal(dark.g, 0);
46 assert.equal(dark.g, 0);
34 assert.equal(dark.b, 0);
47 assert.equal(dark.b, 0);
35});
48});
49
50test("PvP kill awards temporary skull points that replicate", () =>
51{
52 const random = Math.random;
53 Math.random = () => 0.5;
54 const harness = makeSimulation({ workerCount: 1 });
55 try
56 {
57 const victim = makeCharacter(harness.stateDb, {
58 firstName: "Vic",
59 lastName: "Victim",
60 tileX: 9,
61 tileY: 8
62 });
63 const killer = makeCharacter(harness.stateDb, {
64 firstName: "Kill",
65 lastName: "Attacker",
66 tileX: 8,
67 tileY: 8
68 });
69 const victimId = harness.simulation.spawnCharacter(1, victim);
70 const killerId = harness.simulation.spawnCharacter(2, killer);
71
72 const killerComps = componentsOf(harness.simulation, killerId);
73 killerComps.skills.xp[SkillId.unarmed] = totalXpForLevel(20);
74 killerComps.skills.xp[SkillId.strength] = totalXpForLevel(20);
75 componentsOf(harness.simulation, victimId).health.current = 1;
76
77 harness.simulation.enqueue(2, {
78 type: "attack",
79 characterId: killer.character_id,
80 targetEntityId: victimId
81 });
82 let skullEvent = null;
83 for (let i = 0; i < 40; i++)
84 {
85 harness.advance(200);
86 const result = harness.simulation.step();
87 skullEvent = result.events.find((event) =>
88 event.type === "entity-skull" && event.entityId === killerId
89 ) ?? result.replication?.find?.((event) =>
90 event.type === "entity-skull" && event.entityId === killerId
91 ) ?? skullEvent;
92 if (componentsOf(harness.simulation, victimId)[Component.dead])
93 { break; }
94 }
95 assert.ok(componentsOf(harness.simulation, victimId)[Component.dead], "victim should die");
96 assert.equal(harness.stateDb.peekKillCounter(killer.character_id, harness.now()), SKULL_KILL_BONUS);
97 assert.equal(harness.simulation.directory.get(killerId).skullValue, SKULL_KILL_BONUS);
98 assert.ok(skullEvent, "entity-skull must replicate to clients");
99 assert.equal(skullEvent.skullValue, SKULL_KILL_BONUS);
100
101 // Directory skull survives a remember overwrite from public entity view.
102 const worker = harness.simulation.workers[
103 harness.simulation.entityRecord(killerId).workerId
104 ];
105 const view = worker.call({ type: WorkerMessage.inspect, entityId: killerId });
106 harness.simulation.directory.set(killerId, { ...view, workerId: 0 });
107 harness.simulation.refreshCharacterSkull(killer.character_id, { force: true });
108 assert.equal(harness.simulation.directory.get(killerId).skullValue, SKULL_KILL_BONUS);
109 }
110 finally
111 {
112 Math.random = random;
113 harness.close();
114 }
115});
116
117test("snapshots include skullValue for other players", () =>
118{
119 const harness = makeSimulation({ workerCount: 1 });
120 try
121 {
122 const a = makeCharacter(harness.stateDb, { firstName: "A", lastName: "One", tileX: 8, tileY: 8 });
123 const b = makeCharacter(harness.stateDb, { firstName: "B", lastName: "Two", tileX: 9, tileY: 8 });
124 const aId = harness.simulation.spawnCharacter(1, a);
125 const bId = harness.simulation.spawnCharacter(2, b);
126 harness.stateDb.addKillCounter(a.character_id, 500, harness.now());
127 harness.simulation.refreshCharacterSkull(a.character_id, { force: true });
128 const snaps = harness.simulation.snapshotsForView(bId, 2);
129 const entities = snaps.flatMap((snap) => snap.entities ?? []);
130 const seen = entities.find((entity) => entity.entityId === aId);
131 assert.ok(seen, "viewer should see killer in snapshot");
132 assert.equal(seen.skullValue, 500);
133 }
134 finally
135 { harness.close(); }
136});