BlueGit

timfa questward

Lock dead players to respawn/logout only, and tidy recipe paper labels.

Ignore all other intents server-side, close closeable UI on death, use lowercase "recipe", and show a single Written by line (you vs author name).

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
39fb3344776c034566bb235b4d0fd643a7b0210a
Parent
64b245dc
9 files changed +105 −13
client/src/play/inventory.js +14 −2
@@ -333,15 +333,19 @@ export function initInventory ({
333 333 }
334 334 if (slot.itemId === ItemId.recipePaper && slot.instance?.kind === "recipe-paper")
335 335 {
336 const byYou = slot.instance.authorCharacterId != null
337 && Number(slot.instance.authorCharacterId) === Number(localCharacterId);
336 338 items.push({
337 339 label: "Read",
338 340 onSelect: () => openLetter({
339 341 mode: "read",
340 342 slotIndex,
341 343 instance: {
342 documentTitle: slot.instance.displayName ?? "Recipe",
344 documentTitle: itemDisplayName(slot),
343 345 body: slot.instance.body ?? "",
344 authorDisplayName: slot.instance.authorDisplayName ?? "Unknown"
346 authorDisplayName: byYou
347 ? "you"
348 : (slot.instance.authorDisplayName ?? "Unknown")
345 349 }
346 350 })
347 351 });
@@ -949,6 +953,14 @@ export function initInventory ({
949 953 return bankOpen;
950 954 },
951 955 closeBank,
956 closeOverlays ()
957 {
958 closeBank();
959 closeSend();
960 closeLetter();
961 closeTransfer();
962 closeWriteCheque();
963 },
952 964 isBlocking ()
953 965 {
954 966 if (!sendPanel.hidden || !letterPanel.hidden || !sendTargetPanel.hidden
@@ -333,15 +333,19 @@ export function initInventory ({
333 }
333 }
334 if (slot.itemId === ItemId.recipePaper && slot.instance?.kind === "recipe-paper")
334 if (slot.itemId === ItemId.recipePaper && slot.instance?.kind === "recipe-paper")
335 {
335 {
336 const byYou = slot.instance.authorCharacterId != null
337 && Number(slot.instance.authorCharacterId) === Number(localCharacterId);
336 items.push({
338 items.push({
337 label: "Read",
339 label: "Read",
338 onSelect: () => openLetter({
340 onSelect: () => openLetter({
339 mode: "read",
341 mode: "read",
340 slotIndex,
342 slotIndex,
341 instance: {
343 instance: {
342 documentTitle: slot.instance.displayName ?? "Recipe",
344 documentTitle: itemDisplayName(slot),
343 body: slot.instance.body ?? "",
345 body: slot.instance.body ?? "",
344 authorDisplayName: slot.instance.authorDisplayName ?? "Unknown"
346 authorDisplayName: byYou
347 ? "you"
348 : (slot.instance.authorDisplayName ?? "Unknown")
345 }
349 }
346 })
350 })
347 });
351 });
@@ -949,6 +953,14 @@ export function initInventory ({
949 return bankOpen;
953 return bankOpen;
950 },
954 },
951 closeBank,
955 closeBank,
956 closeOverlays ()
957 {
958 closeBank();
959 closeSend();
960 closeLetter();
961 closeTransfer();
962 closeWriteCheque();
963 },
952 isBlocking ()
964 isBlocking ()
953 {
965 {
954 if (!sendPanel.hidden || !letterPanel.hidden || !sendTargetPanel.hidden
966 if (!sendPanel.hidden || !letterPanel.hidden || !sendTargetPanel.hidden
client/src/play/main.js +29 −0
@@ -591,6 +591,34 @@ function clearUiFocus ()
591 591 uiFocus = null;
592 592 }
593 593
594 /** Close stations, bank, dialogue, and other overlays when the local player dies. */
595 function closeCloseablePlayUi ()
596 {
597 clearUiFocus();
598 inventory?.closeBank?.();
599 inventory?.closeOverlays?.();
600 if (crafting?.isOpen?.())
601 { crafting.close(); }
602 if (alchemy?.isOpen?.())
603 { alchemy.close(); }
604 if (market?.isOpen?.())
605 { market.close(); }
606 if (bounty?.isOpen?.())
607 { bounty.close(); }
608 if (barber?.isOpen?.())
609 { barber.close(); }
610 if (shop?.isOpen?.())
611 { shop.close(); }
612 if (dialogueUi?.isOpen?.())
613 { dialogueUi.close(); }
614 questsUi?.hide?.();
615 chat?.close?.();
616 social?.closeOverlays?.();
617 contextMenu?.hide();
618 spells?.handleSpellDisarmed?.();
619 graphicsSettingsUi?.close?.();
620 }
621
594 622 /** Close bank / station / NPC UIs when the player walks out of adjacency. */
595 623 function closeOpenUiIfTooFar ()
596 624 {
@@ -2018,6 +2046,7 @@ async function main ()
2018 2046 clearAutorunFocus();
2019 2047 contextMenu?.hide();
2020 2048 spells?.handleSpellDisarmed?.();
2049 closeCloseablePlayUi();
2021 2050 death?.show();
2022 2051 if (message.entityId === view?.localEntityId)
2023 2052 {
@@ -591,6 +591,34 @@ function clearUiFocus ()
591 uiFocus = null;
591 uiFocus = null;
592}
592}
593
593
594/** Close stations, bank, dialogue, and other overlays when the local player dies. */
595function closeCloseablePlayUi ()
596{
597 clearUiFocus();
598 inventory?.closeBank?.();
599 inventory?.closeOverlays?.();
600 if (crafting?.isOpen?.())
601 { crafting.close(); }
602 if (alchemy?.isOpen?.())
603 { alchemy.close(); }
604 if (market?.isOpen?.())
605 { market.close(); }
606 if (bounty?.isOpen?.())
607 { bounty.close(); }
608 if (barber?.isOpen?.())
609 { barber.close(); }
610 if (shop?.isOpen?.())
611 { shop.close(); }
612 if (dialogueUi?.isOpen?.())
613 { dialogueUi.close(); }
614 questsUi?.hide?.();
615 chat?.close?.();
616 social?.closeOverlays?.();
617 contextMenu?.hide();
618 spells?.handleSpellDisarmed?.();
619 graphicsSettingsUi?.close?.();
620}
621
594/** Close bank / station / NPC UIs when the player walks out of adjacency. */
622/** Close bank / station / NPC UIs when the player walks out of adjacency. */
595function closeOpenUiIfTooFar ()
623function closeOpenUiIfTooFar ()
596{
624{
@@ -2018,6 +2046,7 @@ async function main ()
2018 clearAutorunFocus();
2046 clearAutorunFocus();
2019 contextMenu?.hide();
2047 contextMenu?.hide();
2020 spells?.handleSpellDisarmed?.();
2048 spells?.handleSpellDisarmed?.();
2049 closeCloseablePlayUi();
2021 death?.show();
2050 death?.show();
2022 if (message.entityId === view?.localEntityId)
2051 if (message.entityId === view?.localEntityId)
2023 {
2052 {
client/src/play/social.js +5 −0
@@ -352,6 +352,11 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null })
352 352 inspectBounty.textContent = `Bounty: ${target.amountLabel ?? amount}`;
353 353 },
354 354 hideInspect,
355 closeOverlays ()
356 {
357 hideInspect();
358 friendsPanel.hidden = true;
359 },
355 360 reset ()
356 361 {
357 362 hideInspect();
@@ -352,6 +352,11 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null })
352 inspectBounty.textContent = `Bounty: ${target.amountLabel ?? amount}`;
352 inspectBounty.textContent = `Bounty: ${target.amountLabel ?? amount}`;
353 },
353 },
354 hideInspect,
354 hideInspect,
355 closeOverlays ()
356 {
357 hideInspect();
358 friendsPanel.hidden = true;
359 },
355 reset ()
360 reset ()
356 {
361 {
357 hideInspect();
362 hideInspect();
server/src/alchemy/service.js +1 −1
@@ -667,7 +667,7 @@ function saveRecipe (world, sessionId, command)
667 667 kind: "recipe-paper",
668 668 recipeId: randomUUID(),
669 669 potionKey: recipe.potionKey,
670 displayName: `${recipe.displayName} Recipe`,
670 displayName: `${recipe.displayName} recipe`,
671 671 authorCharacterId: command.characterId,
672 672 authorDisplayName: characterDisplayName(world, handle),
673 673 minAlchemyLevel: recipe.minAlchemyLevel ?? 1,
@@ -667,7 +667,7 @@ function saveRecipe (world, sessionId, command)
667 kind: "recipe-paper",
667 kind: "recipe-paper",
668 recipeId: randomUUID(),
668 recipeId: randomUUID(),
669 potionKey: recipe.potionKey,
669 potionKey: recipe.potionKey,
670 displayName: `${recipe.displayName} Recipe`,
670 displayName: `${recipe.displayName} recipe`,
671 authorCharacterId: command.characterId,
671 authorCharacterId: command.characterId,
672 authorDisplayName: characterDisplayName(world, handle),
672 authorDisplayName: characterDisplayName(world, handle),
673 minAlchemyLevel: recipe.minAlchemyLevel ?? 1,
673 minAlchemyLevel: recipe.minAlchemyLevel ?? 1,
server/src/gateway/websocket.js +2 −3
@@ -136,9 +136,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
136 136 && message.type !== MessageType.respawn
137 137 && message.type !== MessageType.leaveWorld)
138 138 {
139 const error = new Error("You are dead.");
140 error.userFacing = true;
141 throw error;
139 // Dead bodies may only respawn or leave the world — ignore all other intents.
140 return;
142 141 }
143 142 switch (message.type)
144 143 {
@@ -136,9 +136,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
136 && message.type !== MessageType.respawn
136 && message.type !== MessageType.respawn
137 && message.type !== MessageType.leaveWorld)
137 && message.type !== MessageType.leaveWorld)
138 {
138 {
139 const error = new Error("You are dead.");
139 // Dead bodies may only respawn or leave the world — ignore all other intents.
140 error.userFacing = true;
140 return;
141 throw error;
142 }
141 }
143 switch (message.type)
142 switch (message.type)
144 {
143 {
server/src/simulation/simulation.js +32 −0
@@ -1159,6 +1159,12 @@ export class Simulation
1159 1159 {
1160 1160 if (item.command.type === "respawn")
1161 1161 { return this.#respawnCharacter(item.sessionId, item.command.characterId); }
1162 const routedCharacterId = item.command.characterId | 0;
1163 if (routedCharacterId && this.stateDb.getCharacter(routedCharacterId)?.is_dead)
1164 {
1165 // Queued intents after death (drop/use/send/craft/…) are discarded.
1166 return [];
1167 }
1162 1168 if (item.command.type === "enter-doorway")
1163 1169 {
1164 1170 return this.#relocateCharacterThroughDoorway(
@@ -1740,6 +1746,32 @@ export class Simulation
1740 1746 if (killerCharacterId && killerCharacterId !== (event.characterId | 0))
1741 1747 { this.stateDb.addKillCounter(killerCharacterId, SKULL_KILL_BONUS, this.now); }
1742 1748 const events = [event];
1749 const closedDialogue = this.quests?.closeDialogue(event.characterId, "death");
1750 if (closedDialogue?.events?.length)
1751 {
1752 events.push(...this.#mapQuestPrivateEvents(
1753 closedDialogue.events,
1754 event.sessionId,
1755 event.characterId
1756 ));
1757 }
1758 if (event.sessionId != null)
1759 {
1760 for (const commandType of ["cancel-craft", "cauldron-close"])
1761 {
1762 try
1763 {
1764 this.workers[record.workerId].call({
1765 type: WorkerMessage.command,
1766 sessionId: event.sessionId,
1767 command: { type: commandType, characterId: event.characterId },
1768 now: this.now
1769 });
1770 }
1771 catch
1772 { /* best-effort session cleanup */ }
1773 }
1774 }
1743 1775 // Bounty is cleared instantly on non-friend PvP death; only kill-counter decays over time.
1744 1776 const victimSkull = this.refreshCharacterSkull(event.characterId, { force: true });
1745 1777 if (victimSkull)
@@ -1159,6 +1159,12 @@ export class Simulation
1159 {
1159 {
1160 if (item.command.type === "respawn")
1160 if (item.command.type === "respawn")
1161 { return this.#respawnCharacter(item.sessionId, item.command.characterId); }
1161 { return this.#respawnCharacter(item.sessionId, item.command.characterId); }
1162 const routedCharacterId = item.command.characterId | 0;
1163 if (routedCharacterId && this.stateDb.getCharacter(routedCharacterId)?.is_dead)
1164 {
1165 // Queued intents after death (drop/use/send/craft/…) are discarded.
1166 return [];
1167 }
1162 if (item.command.type === "enter-doorway")
1168 if (item.command.type === "enter-doorway")
1163 {
1169 {
1164 return this.#relocateCharacterThroughDoorway(
1170 return this.#relocateCharacterThroughDoorway(
@@ -1740,6 +1746,32 @@ export class Simulation
1740 if (killerCharacterId && killerCharacterId !== (event.characterId | 0))
1746 if (killerCharacterId && killerCharacterId !== (event.characterId | 0))
1741 { this.stateDb.addKillCounter(killerCharacterId, SKULL_KILL_BONUS, this.now); }
1747 { this.stateDb.addKillCounter(killerCharacterId, SKULL_KILL_BONUS, this.now); }
1742 const events = [event];
1748 const events = [event];
1749 const closedDialogue = this.quests?.closeDialogue(event.characterId, "death");
1750 if (closedDialogue?.events?.length)
1751 {
1752 events.push(...this.#mapQuestPrivateEvents(
1753 closedDialogue.events,
1754 event.sessionId,
1755 event.characterId
1756 ));
1757 }
1758 if (event.sessionId != null)
1759 {
1760 for (const commandType of ["cancel-craft", "cauldron-close"])
1761 {
1762 try
1763 {
1764 this.workers[record.workerId].call({
1765 type: WorkerMessage.command,
1766 sessionId: event.sessionId,
1767 command: { type: commandType, characterId: event.characterId },
1768 now: this.now
1769 });
1770 }
1771 catch
1772 { /* best-effort session cleanup */ }
1773 }
1774 }
1743 // Bounty is cleared instantly on non-friend PvP death; only kill-counter decays over time.
1775 // Bounty is cleared instantly on non-friend PvP death; only kill-counter decays over time.
1744 const victimSkull = this.refreshCharacterSkull(event.characterId, { force: true });
1776 const victimSkull = this.refreshCharacterSkull(event.characterId, { force: true });
1745 if (victimSkull)
1777 if (victimSkull)
server/tests/alchemy.test.js +1 −1
@@ -162,7 +162,7 @@ test("cauldron bottles lesser health tonic when steps and ratios match", () =>
162 162 const recipe = after.inventory.find((slot) => slot?.itemId === ItemId.recipePaper);
163 163 assert.match(recipe.instance?.body ?? "", /Lesser health tonic/);
164 164 assert.match(recipe.instance?.body ?? "", /Alchemy level required/);
165 assert.equal(recipe.instance?.displayName, "Lesser health tonic Recipe");
165 assert.equal(recipe.instance?.displayName, "Lesser health tonic recipe");
166 166 assert.equal(recipe.instance?.authorDisplayName, `${character.first_name} ${character.last_name}`);
167 167 }
168 168 finally
@@ -162,7 +162,7 @@ test("cauldron bottles lesser health tonic when steps and ratios match", () =>
162 const recipe = after.inventory.find((slot) => slot?.itemId === ItemId.recipePaper);
162 const recipe = after.inventory.find((slot) => slot?.itemId === ItemId.recipePaper);
163 assert.match(recipe.instance?.body ?? "", /Lesser health tonic/);
163 assert.match(recipe.instance?.body ?? "", /Lesser health tonic/);
164 assert.match(recipe.instance?.body ?? "", /Alchemy level required/);
164 assert.match(recipe.instance?.body ?? "", /Alchemy level required/);
165 assert.equal(recipe.instance?.displayName, "Lesser health tonic Recipe");
165 assert.equal(recipe.instance?.displayName, "Lesser health tonic recipe");
166 assert.equal(recipe.instance?.authorDisplayName, `${character.first_name} ${character.last_name}`);
166 assert.equal(recipe.instance?.authorDisplayName, `${character.first_name} ${character.last_name}`);
167 }
167 }
168 finally
168 finally
server/tests/death.test.js +15 −5
@@ -250,12 +250,22 @@ test("dead players stop combat and auto-cast and cannot be targeted", () =>
250 250 characterId: character.character_id,
251 251 targetEntityId: deerId
252 252 });
253 harness.simulation.enqueue(1, {
254 type: "drop-item",
255 characterId: character.character_id,
256 slotIndex: 0,
257 quantity: 1
258 });
253 259 const result = harness.simulation.step();
254 assert.ok(
255 result.events.some((event) =>
256 event.type === "command-error" && /dead/i.test(event.message ?? "")
257 ),
258 "dead player commands must be rejected"
260 assert.equal(
261 result.events.some((event) => event.type === "command-error"),
262 false,
263 "dead player intents are ignored silently"
264 );
265 assert.equal(
266 componentsOf(harness.simulation, playerId).combat?.targetEntityId ?? null,
267 null,
268 "dead player cannot start new combat"
259 269 );
260 270 }
261 271 finally
@@ -250,12 +250,22 @@ test("dead players stop combat and auto-cast and cannot be targeted", () =>
250 characterId: character.character_id,
250 characterId: character.character_id,
251 targetEntityId: deerId
251 targetEntityId: deerId
252 });
252 });
253 harness.simulation.enqueue(1, {
254 type: "drop-item",
255 characterId: character.character_id,
256 slotIndex: 0,
257 quantity: 1
258 });
253 const result = harness.simulation.step();
259 const result = harness.simulation.step();
254 assert.ok(
260 assert.equal(
255 result.events.some((event) =>
261 result.events.some((event) => event.type === "command-error"),
256 event.type === "command-error" && /dead/i.test(event.message ?? "")
262 false,
257 ),
263 "dead player intents are ignored silently"
258 "dead player commands must be rejected"
264 );
265 assert.equal(
266 componentsOf(harness.simulation, playerId).combat?.targetEntityId ?? null,
267 null,
268 "dead player cannot start new combat"
259 );
269 );
260 }
270 }
261 finally
271 finally
shared/definitions/items.js +6 −1
@@ -343,7 +343,9 @@ export function itemDisplayName (stack, def = itemDefinition(stack?.itemId))
343 343 return `${FLOWER_COLOR_DISPLAY[stack.instance.colorId] ?? "Flower"} flower`;
344 344 }
345 345 if (stack?.itemId === ItemId.recipePaper && stack.instance?.displayName)
346 { return stack.instance.displayName; }
346 {
347 return String(stack.instance.displayName).replace(/\s+Recipe$/u, " recipe");
348 }
347 349 if (stack?.itemId === CraftingItemId.tinderbox && stack.instance?.kind === "tinderbox")
348 350 {
349 351 const charges = Math.max(0, stack.instance.charges | 0);
@@ -425,6 +427,9 @@ export function itemDescription (stack, { localCharacterId } = {})
425 427
426 428 export function itemOriginSummary (stack)
427 429 {
430 // Recipe papers already say "Written by …" in the description — avoid a duplicate origin line.
431 if (stack?.itemId === ItemId.recipePaper && stack.instance?.kind === "recipe-paper")
432 { return ""; }
428 433 return formatOriginBreakdown(stack);
429 434 }
430 435
@@ -343,7 +343,9 @@ export function itemDisplayName (stack, def = itemDefinition(stack?.itemId))
343 return `${FLOWER_COLOR_DISPLAY[stack.instance.colorId] ?? "Flower"} flower`;
343 return `${FLOWER_COLOR_DISPLAY[stack.instance.colorId] ?? "Flower"} flower`;
344 }
344 }
345 if (stack?.itemId === ItemId.recipePaper && stack.instance?.displayName)
345 if (stack?.itemId === ItemId.recipePaper && stack.instance?.displayName)
346 { return stack.instance.displayName; }
346 {
347 return String(stack.instance.displayName).replace(/\s+Recipe$/u, " recipe");
348 }
347 if (stack?.itemId === CraftingItemId.tinderbox && stack.instance?.kind === "tinderbox")
349 if (stack?.itemId === CraftingItemId.tinderbox && stack.instance?.kind === "tinderbox")
348 {
350 {
349 const charges = Math.max(0, stack.instance.charges | 0);
351 const charges = Math.max(0, stack.instance.charges | 0);
@@ -425,6 +427,9 @@ export function itemDescription (stack, { localCharacterId } = {})
425
427
426export function itemOriginSummary (stack)
428export function itemOriginSummary (stack)
427{
429{
430 // Recipe papers already say "Written by …" in the description — avoid a duplicate origin line.
431 if (stack?.itemId === ItemId.recipePaper && stack.instance?.kind === "recipe-paper")
432 { return ""; }
428 return formatOriginBreakdown(stack);
433 return formatOriginBreakdown(stack);
429}
434}
430
435