castle-web-cli 0.4.232 → 0.4.233
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/castle-host/host.d.ts +1 -0
- package/dist/castle-host/host.js +51 -3
- package/dist/castleJson.d.ts +4 -2
- package/dist/castleJson.js +2 -0
- package/dist/check.d.ts +3 -1
- package/dist/check.js +11 -1
- package/dist/devSessionStorage.js +47 -1
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +5 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +5 -0
- package/dist/save-deck.js +37 -4
- package/dist/serve.js +3 -0
- package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +79 -2
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +1 -1
- package/kits/base/sdk/commands.d.ts +14 -0
- package/kits/base/sdk/hub.d.ts +6 -2
- package/kits/base/sdk/hub.js +13 -0
- package/kits/base/sdk/multiplayer.js +17 -1
- package/kits/base/sdk/save.js +2 -1
- package/kits/base/sdk/server/hub.d.ts +87 -0
- package/kits/base/sdk/server/hub.js +70 -0
- package/kits/base/sdk/server/platformHandle.d.ts +31 -1
- package/kits/base/sdk/server/storage.d.ts +13 -0
- package/kits/base/sdk/server/storage.js +46 -0
- package/kits/base/sdk/server/wrapper.d.ts +36 -5
- package/kits/base/sdk/server/wrapper.js +83 -8
- package/kits/hub-game/CLAUDE.md +329 -11
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +309 -35
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +251 -0
- package/kits/hub-game/code/client/ballot.js +467 -0
- package/kits/hub-game/code/client/build.js +22 -0
- package/kits/hub-game/code/client/chrome.js +1144 -50
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/decor.js +509 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/grab.js +339 -20
- package/kits/hub-game/code/client/hookLayer.js +299 -13
- package/kits/hub-game/code/client/idle.js +163 -22
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +205 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/shot.js +92 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +109 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +538 -47
- package/kits/hub-game/code/client/tiers.js +516 -27
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +32 -0
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/yours.js +199 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/actions.js +133 -0
- package/kits/hub-game/code/server/actors.js +9 -1
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +82 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/earned.js +461 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +232 -0
- package/kits/hub-game/code/server/history.js +5 -0
- package/kits/hub-game/code/server/hub.js +1254 -50
- package/kits/hub-game/code/server/idle.js +30 -11
- package/kits/hub-game/code/server/index.js +2 -2
- package/kits/hub-game/code/server/labels.js +28 -2
- package/kits/hub-game/code/server/manifest.js +378 -7
- package/kits/hub-game/code/server/menu.js +133 -0
- package/kits/hub-game/code/server/npcs.js +830 -80
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +22 -0
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +124 -0
- package/kits/hub-game/code/server/vis.js +113 -0
- package/kits/hub-game/code/server/wear.js +12 -0
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/shot.js +19 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +845 -95
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +2244 -61
- package/kits/hub-game/docs/home-pieces.md +64 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +2 -0
- package/kits/hub-game/package.json +2 -1
- package/kits/hub-game/scripts/check.mjs +78 -11
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -17
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
- package/kits/hub-game/scripts/test-avatar.mjs +540 -7
- package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
- package/kits/hub-game/scripts/test-build.mjs +31 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +662 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
- package/kits/hub-game/scripts/test-decor.mjs +457 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1194 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
- package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
- package/kits/hub-game/scripts/test-idle.mjs +361 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +596 -0
- package/kits/hub-game/scripts/test-manifest.mjs +207 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
- package/kits/hub-game/scripts/test-menu.mjs +296 -0
- package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-picker.mjs +314 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-shot.mjs +756 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +416 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
- package/kits/hub-game/scripts/test-tiers.mjs +477 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- package/kits/hub-game/scripts/test-vis.mjs +343 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
- package/kits/hub-game/scripts/test-yours.mjs +372 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/physics-2d/CLAUDE.md +9 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +253 -1
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +1169 -30
- package/kits/physics-3d/behaviors/Player.jsx +629 -72
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +8 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
- package/kits/physics-3d/engine3d/actornode.js +86 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +96 -0
- package/kits/physics-3d/engine3d/gait.js +118 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +507 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +37 -19
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +487 -9
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/shadowfade.js +882 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +796 -69
- package/kits/physics-3d/main.jsx +5 -0
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +383 -6
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +97 -19
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Talking to a place's NPCs (contract §13), drawn by the hub chrome because a
|
|
2
2
|
// Tier 0 game has no client code of its own. Near a `HubNpc` actor the player
|
|
3
|
-
// gets a Talk button; the place's server decides whether the conversation
|
|
3
|
+
// gets a Chat or Talk button; the place's server decides whether the conversation
|
|
4
4
|
// opens (one player per NPC at a time) and whether it goes to the character's
|
|
5
5
|
// mind or to the place's authored lines.
|
|
6
6
|
//
|
|
@@ -23,6 +23,12 @@ const POLL_LIMIT_MS = 90_000;
|
|
|
23
23
|
const INPUT_MAX = 280;
|
|
24
24
|
// A turn refused for stale notes is sent again once, with the newest.
|
|
25
25
|
const NOTES_RETRY_MS = 400;
|
|
26
|
+
// The server silently drops authored words inside its 900 ms cooldown.
|
|
27
|
+
const AUTHORED_GAP_MS = 900;
|
|
28
|
+
const AUTHORED_WAIT_MS = 1200;
|
|
29
|
+
const ATTACH_WAIT_MS = 8000;
|
|
30
|
+
const INTERRUPTED_MS = 1800;
|
|
31
|
+
const INTERRUPTED_LINE = 'Lost the thread there. Tap to talk again.';
|
|
26
32
|
// Lines the place said because the mind was not answering, and how the panel
|
|
27
33
|
// says so.
|
|
28
34
|
const SCRIPTED = {
|
|
@@ -30,6 +36,12 @@ const SCRIPTED = {
|
|
|
30
36
|
budget: 'has a crowd to answer',
|
|
31
37
|
unavailable: "can't answer right now",
|
|
32
38
|
};
|
|
39
|
+
const REFUSAL_WHY = {
|
|
40
|
+
HUB_NPC_BUSY: 'busy',
|
|
41
|
+
HUB_NPC_BUDGET: 'budget',
|
|
42
|
+
CAULDRON_SHARED_CHARACTER_BUSY: 'busy',
|
|
43
|
+
CAULDRON_SHARED_CHARACTER_BUDGET: 'budget',
|
|
44
|
+
};
|
|
33
45
|
|
|
34
46
|
// The server strips a reply's wrapping quotes the same way for its bubble.
|
|
35
47
|
const unquote = (text) => {
|
|
@@ -42,13 +54,23 @@ const newId = () => globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(
|
|
|
42
54
|
export function makeTalk(chrome) {
|
|
43
55
|
const t = {
|
|
44
56
|
chrome,
|
|
45
|
-
// { npc, name, mind, character, prefix
|
|
57
|
+
// { npc, name, mind, character, prefix, canType, questions, sent } while open
|
|
46
58
|
open: null,
|
|
47
59
|
asking: null,
|
|
48
60
|
net: null,
|
|
49
|
-
//
|
|
61
|
+
// v1.46: only a successful inspect remembers permission to type.
|
|
50
62
|
inspected: new WeakSet(),
|
|
63
|
+
// v1.47: approach starts one read; refusals still retry on the next open.
|
|
64
|
+
approached: new WeakSet(),
|
|
65
|
+
inspecting: new WeakSet(),
|
|
66
|
+
inspectRefusals: new Set(),
|
|
67
|
+
// v1.76: ids only, consumed on approach or on opening that character.
|
|
68
|
+
hooks: new Map(),
|
|
69
|
+
greeted: new Set(),
|
|
51
70
|
waiting: false,
|
|
71
|
+
saidAt: -Infinity,
|
|
72
|
+
drafts: new Map(),
|
|
73
|
+
abandonedOpens: new Set(),
|
|
52
74
|
};
|
|
53
75
|
chrome.onTalk({
|
|
54
76
|
open: () => ask(t),
|
|
@@ -57,32 +79,155 @@ export function makeTalk(chrome) {
|
|
|
57
79
|
});
|
|
58
80
|
return {
|
|
59
81
|
frame: (scene, mp, idle) => frame(t, scene, mp, idle),
|
|
82
|
+
openCompanion(scene) {
|
|
83
|
+
const companion = companionNpc(scene);
|
|
84
|
+
if (companion && !t.open && t.net === scene.multiplayer?.net) {
|
|
85
|
+
ask(t, companion);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
60
88
|
typing: () => t.open !== null && chrome.talkFocused(),
|
|
61
89
|
talking: () => t.open !== null,
|
|
90
|
+
talkingToCompanion: () => Boolean(hub.place?.companionChat && t.open?.npc === `companion:${t.net?.selfId?.()}`),
|
|
62
91
|
// The NPC this player is talking with: its words are in the panel.
|
|
63
92
|
talkingWith: () => t.open?.npc ?? null,
|
|
93
|
+
// A second WORLD under the same id restores the body, not its chat.
|
|
94
|
+
// Never replay a turn whose admission is unknown: only NOT_TALKING
|
|
95
|
+
// proves the server did not send it to the mind.
|
|
96
|
+
resume() {
|
|
97
|
+
if (t.open && !t.open.interrupted) {
|
|
98
|
+
t.open.needsAttach = true;
|
|
99
|
+
if (!t.waiting) {
|
|
100
|
+
void reattach(t, t.open);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
// The same connection under another player id is another session, and the
|
|
105
|
+
// new one has no conversation with this player: words typed into the old
|
|
106
|
+
// panel would be refused there and never answered.
|
|
107
|
+
reset: () => reset(t),
|
|
64
108
|
};
|
|
65
109
|
}
|
|
66
110
|
|
|
111
|
+
// Whatever was being said belongs to the session it was said in.
|
|
112
|
+
function reset(t) {
|
|
113
|
+
clearAuthored(t.open);
|
|
114
|
+
if (t.open?.attachment) {
|
|
115
|
+
t.abandonedOpens.add(t.open.npc);
|
|
116
|
+
}
|
|
117
|
+
cancelAttach(t.open);
|
|
118
|
+
cancelNotesWait(t.open);
|
|
119
|
+
clearTimeout(t.open?.closeTimer);
|
|
120
|
+
clearTimeout(t.open?.interruptionTimer);
|
|
121
|
+
t.open = null;
|
|
122
|
+
t.asking = null;
|
|
123
|
+
t.waiting = false;
|
|
124
|
+
t.saidAt = -Infinity;
|
|
125
|
+
t.hooks.clear();
|
|
126
|
+
t.greeted.clear();
|
|
127
|
+
t.drafts.clear();
|
|
128
|
+
t.near = null;
|
|
129
|
+
t.preferred = null;
|
|
130
|
+
t.chrome.closeTalk();
|
|
131
|
+
}
|
|
132
|
+
|
|
67
133
|
function frame(t, scene, mp, idle) {
|
|
68
134
|
const net = mp.net;
|
|
69
135
|
if (net !== t.net) {
|
|
70
136
|
// A session switch ends whatever was being said in the old one.
|
|
71
137
|
t.net = net;
|
|
72
|
-
t
|
|
73
|
-
t.asking = null;
|
|
74
|
-
t.waiting = false;
|
|
75
|
-
t.chrome.closeTalk();
|
|
138
|
+
reset(t);
|
|
76
139
|
}
|
|
140
|
+
// The server sends panel events only to their speaker. A body may have
|
|
141
|
+
// other conversations; its ambient labels never open or close this panel.
|
|
77
142
|
for (const msg of hub.npcEvents.splice(0)) {
|
|
78
|
-
if (msg.k === 'hub-npc') {
|
|
143
|
+
if (msg.k === 'hub-npc-preferred') {
|
|
144
|
+
t.preferred = typeof msg.npc === 'string' ? msg.npc : null;
|
|
145
|
+
} else if (msg.k === 'hub-npc-hooks') {
|
|
146
|
+
for (const hook of Array.isArray(msg.hooks) ? msg.hooks : []) {
|
|
147
|
+
if (typeof hook?.npc === 'string' && typeof hook.character === 'string' && hook.character && !t.greeted.has(hook.character)) {
|
|
148
|
+
t.hooks.set(hook.npc, hook.character);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (t.open) {
|
|
152
|
+
dropHook(t, t.open.npc, t.open.character);
|
|
153
|
+
}
|
|
154
|
+
} else if (msg.k === 'hub-npc') {
|
|
155
|
+
if (msg.open && t.abandonedOpens.has(msg.npc) && t.asking !== msg.npc) {
|
|
156
|
+
t.net.send({ k: 'hub-npc-end', npc: msg.npc });
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (t.open?.npc === msg.npc && t.open.interrupted) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
79
162
|
if (msg.open) {
|
|
80
|
-
t.open
|
|
81
|
-
|
|
163
|
+
if (t.open?.npc === msg.npc && t.open.attachment) {
|
|
164
|
+
const open = t.open;
|
|
165
|
+
// Recovery cannot send private mind input down an authored/public
|
|
166
|
+
// path, or give an already-typed question to a different character.
|
|
167
|
+
if (open.mind !== Boolean(msg.mind) || open.character !== (msg.character ?? null)) {
|
|
168
|
+
interrupted(t, open);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
open.prefix = null;
|
|
172
|
+
open.questions = [...questionsOf(msg.opening?.asks), ...questionsOf(msg.opening?.more)];
|
|
173
|
+
delete open.persistentAsks;
|
|
174
|
+
delete open.withdrawnAsks;
|
|
175
|
+
open.needsAttach = false;
|
|
176
|
+
// A refused turn already counts this as its sole retry. An idle
|
|
177
|
+
// reconnect's open instead belongs to the next queued question.
|
|
178
|
+
open.reattached = !open.operationId;
|
|
179
|
+
t.asking = null;
|
|
180
|
+
open.attachment.opened = true;
|
|
181
|
+
// A body that required notes before the drop is not usable until
|
|
182
|
+
// its new notes arrive, even when the open is in an earlier frame.
|
|
183
|
+
// A prior no-note conversation uses bare words; the server sends
|
|
184
|
+
// no notes in that case.
|
|
185
|
+
if (!open.attachment.needsNotes) {
|
|
186
|
+
cancelAttach(open, true);
|
|
187
|
+
}
|
|
188
|
+
refill(t);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
dropHook(t, msg.npc, msg.character);
|
|
192
|
+
clearAuthored(t.open);
|
|
193
|
+
cancelNotesWait(t.open);
|
|
194
|
+
t.waiting = false;
|
|
195
|
+
t.open = {
|
|
196
|
+
npc: msg.npc, name: msg.name, mind: Boolean(msg.mind), character: msg.character ?? null, prefix: null,
|
|
197
|
+
canType: !msg.mind || t.inspected.has(net),
|
|
198
|
+
questions: [...questionsOf(msg.opening?.asks), ...questionsOf(msg.opening?.more)],
|
|
199
|
+
sent: new Set(),
|
|
200
|
+
};
|
|
201
|
+
t.chrome.openTalk(msg.name, { mind: t.open.mind, canType: t.open.canType });
|
|
202
|
+
if (t.drafts.has(msg.npc)) {
|
|
203
|
+
t.chrome.talkDraft?.(t.drafts.get(msg.npc));
|
|
204
|
+
t.drafts.delete(msg.npc);
|
|
205
|
+
}
|
|
206
|
+
// v1.37: the NPC speaks first -- the place's own words, here at once,
|
|
207
|
+
// and what a player might ask it, each a tap away.
|
|
208
|
+
const first = typeof msg.opening?.text === 'string' ? msg.opening.text : '';
|
|
209
|
+
if (first) {
|
|
210
|
+
t.chrome.talkLine('them', first);
|
|
211
|
+
}
|
|
212
|
+
refill(t);
|
|
82
213
|
if (t.open.mind) {
|
|
83
214
|
registerParticipant(t, net);
|
|
84
215
|
}
|
|
85
216
|
} else if (!t.open || t.open.npc === msg.npc) {
|
|
217
|
+
if (t.open?.attachment) {
|
|
218
|
+
// These end the old conversation, never refuse an open. They may
|
|
219
|
+
// have been queued just before a NOT_TALKING receipt or reconnect.
|
|
220
|
+
if (['left', 'idle', 'end'].includes(msg.why)) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
t.open.interrupted = true;
|
|
224
|
+
t.open.interruptionWhy = msg.why;
|
|
225
|
+
cancelAttach(t.open);
|
|
226
|
+
t.asking = null;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
clearAuthored(t.open);
|
|
230
|
+
cancelNotesWait(t.open);
|
|
86
231
|
t.open = null;
|
|
87
232
|
t.waiting = false;
|
|
88
233
|
t.chrome.closeTalk();
|
|
@@ -90,28 +235,137 @@ function frame(t, scene, mp, idle) {
|
|
|
90
235
|
if (t.asking === msg.npc) {
|
|
91
236
|
t.asking = null;
|
|
92
237
|
}
|
|
238
|
+
} else if (msg.k === 'hub-npc-opening' && t.open?.npc === msg.npc) {
|
|
239
|
+
// v1.47: a late greeting changes the first line only before we speak.
|
|
240
|
+
if (!t.open.sent.size && typeof msg.text === 'string' && msg.text) {
|
|
241
|
+
t.chrome.talkOpening?.(msg.text);
|
|
242
|
+
}
|
|
93
243
|
} else if (msg.k === 'hub-npc-line' && t.open?.npc === msg.npc) {
|
|
244
|
+
if (t.open.interrupted) {
|
|
245
|
+
if (SCRIPTED[msg.why]) {
|
|
246
|
+
t.open.interruptionLine = msg.text;
|
|
247
|
+
}
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
94
250
|
// With a mind, a line the place said instead is marked as scripted.
|
|
95
251
|
const scripted = t.open.mind ? SCRIPTED[msg.why] : null;
|
|
96
252
|
t.chrome.talkLine('them', msg.text, scripted ? `Scripted reply: ${t.open.name} ${scripted}` : null);
|
|
97
|
-
t.
|
|
253
|
+
if (scripted && msg.op && msg.op === t.open.recoveryOperationId) {
|
|
254
|
+
// The line itself proves a recovery turn was refused. Cleanup must
|
|
255
|
+
// not depend on whether the request's rejection has arrived yet.
|
|
256
|
+
t.open.interruptionLine = msg.text;
|
|
257
|
+
t.open.interruptionShown = true;
|
|
258
|
+
interrupted(t, t.open);
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (!t.open.mind && t.open.authored && msg.why === 'authored' && (msg.rid === undefined || msg.rid === t.open.authored.rid)) {
|
|
262
|
+
finishAuthored(t, t.open, true);
|
|
263
|
+
} else if (t.open.mind && msg.op && msg.op === t.open.operationId) {
|
|
264
|
+
t.open.operationId = null;
|
|
265
|
+
t.waiting = false;
|
|
266
|
+
refill(t);
|
|
267
|
+
} else if (!t.open.operationId && !t.open.authored && !t.open.attachment) {
|
|
268
|
+
t.waiting = false;
|
|
269
|
+
refill(t);
|
|
270
|
+
}
|
|
98
271
|
} else if (msg.k === 'hub-npc-notes' && t.open?.npc === msg.npc) {
|
|
99
272
|
t.open.prefix = typeof msg.prefix === 'string' ? msg.prefix : null;
|
|
273
|
+
t.open.notesVersion = (t.open.notesVersion ?? 0) + 1;
|
|
274
|
+
if (msg.persistentAsks !== undefined || t.open.persistentAsks !== undefined) {
|
|
275
|
+
const previous = t.open.persistentAsks ?? [];
|
|
276
|
+
const persistent = questionsOf(msg.persistentAsks);
|
|
277
|
+
const withdrawn = t.open.withdrawnAsks ??= new Set();
|
|
278
|
+
for (const ask of previous) {
|
|
279
|
+
if (!persistent.includes(ask)) {
|
|
280
|
+
withdrawn.add(ask);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
for (const ask of persistent) {
|
|
284
|
+
withdrawn.delete(ask);
|
|
285
|
+
}
|
|
286
|
+
t.open.persistentAsks = persistent;
|
|
287
|
+
if (!t.waiting && (previous.length !== persistent.length || previous.some((ask, i) => ask !== persistent[i]))) {
|
|
288
|
+
refill(t, t.suggestions);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (t.open.attachment?.opened) {
|
|
292
|
+
cancelAttach(t.open, true);
|
|
293
|
+
}
|
|
294
|
+
cancelNotesWait(t.open, true);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (t.open?.interrupted) {
|
|
298
|
+
const open = t.open;
|
|
299
|
+
// Close and scripted line are separate packets; allow the place's line
|
|
300
|
+
// to arrive on the next frame before choosing the fixed fallback.
|
|
301
|
+
if (open.interruptionLine || !SCRIPTED[open.interruptionWhy]) {
|
|
302
|
+
interrupted(t, open);
|
|
303
|
+
} else if (!open.interruptionTimer && !open.closeTimer) {
|
|
304
|
+
open.interruptionTimer = setTimeout(() => interrupted(t, open), 250);
|
|
100
305
|
}
|
|
101
306
|
}
|
|
102
307
|
t.chrome.talkWaiting(t.waiting);
|
|
103
308
|
|
|
104
|
-
const near = idle && net && !t.open ? nearestNpc(scene) : null;
|
|
309
|
+
const near = idle && net && !t.open ? nearestNpc(scene, t.preferred) : null;
|
|
105
310
|
t.near = near;
|
|
106
|
-
t.chrome.talkPrompt(near ? near.name : null);
|
|
311
|
+
t.chrome.talkPrompt(near ? near.name : null, near?.mind ?? false);
|
|
312
|
+
if (net && (near?.mind || companionNpc(scene)) && !t.approached.has(net)) {
|
|
313
|
+
t.approached.add(net);
|
|
314
|
+
registerParticipant(t, net);
|
|
315
|
+
}
|
|
316
|
+
const character = near && !t.asking ? t.hooks.get(near.id) : null;
|
|
317
|
+
if (character) {
|
|
318
|
+
dropHook(t, near.id, character);
|
|
319
|
+
void walkGreeting(net, character);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function dropHook(t, npc, character = t.hooks.get(npc)) {
|
|
324
|
+
t.hooks.delete(npc);
|
|
325
|
+
if (character) {
|
|
326
|
+
t.greeted.add(character);
|
|
327
|
+
for (const [id, mind] of t.hooks) {
|
|
328
|
+
if (mind === character) {
|
|
329
|
+
t.hooks.delete(id);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async function walkGreeting(net, character) {
|
|
336
|
+
try {
|
|
337
|
+
await net.characters.readCharacters({ requestId: newId(), query: { type: 'status', operationId: `greeting:${character}` } });
|
|
338
|
+
} catch {
|
|
339
|
+
// One attempt per hook; error details might contain private words.
|
|
340
|
+
console.log('[hub] NPC greeting read failed');
|
|
341
|
+
}
|
|
107
342
|
}
|
|
108
343
|
|
|
109
|
-
|
|
344
|
+
// v1.46: the next questions, without anything this player already sent.
|
|
345
|
+
function questionsOf(value) {
|
|
346
|
+
return Array.isArray(value) ? value.filter((ask) => typeof ask === 'string').map((ask) => ask.trim().slice(0, INPUT_MAX)).filter(Boolean) : [];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function refill(t, suggestions) {
|
|
350
|
+
// Notes may change the offers between replies; keep that reply's source.
|
|
351
|
+
t.suggestions = suggestions;
|
|
352
|
+
const open = t.open;
|
|
353
|
+
const source = Array.isArray(suggestions) && suggestions.every((ask) => typeof ask === 'string') ? questionsOf(suggestions) : open?.questions ?? [];
|
|
354
|
+
let asks = open?.canType ? [...new Set(source)].filter((ask) => !open.sent.has(ask)).slice(0, 3) : [];
|
|
355
|
+
if (open?.canType && open.persistentAsks !== undefined) {
|
|
356
|
+
const persistent = open.persistentAsks;
|
|
357
|
+
asks = [...new Set([...persistent, ...source])].filter((ask) => persistent.includes(ask) || (!open.withdrawnAsks.has(ask) && !open.sent.has(ask))).slice(0, 3);
|
|
358
|
+
}
|
|
359
|
+
t.chrome.talkAsks?.(asks, (ask) => send(t, ask));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function nearestNpc(scene, preferred) {
|
|
110
363
|
const local = scene.actorWith('Player')?.components.Transform;
|
|
111
364
|
if (!local) {
|
|
112
365
|
return null;
|
|
113
366
|
}
|
|
114
367
|
let best = null;
|
|
368
|
+
let choice = null;
|
|
115
369
|
for (const actor of scene.getActors()) {
|
|
116
370
|
const props = actor.components?.HubNpc;
|
|
117
371
|
const at = actor.components?.Transform;
|
|
@@ -120,64 +374,244 @@ function nearestNpc(scene) {
|
|
|
120
374
|
}
|
|
121
375
|
const d = Math.hypot(at.x - local.x, at.z - local.z);
|
|
122
376
|
const range = typeof props.talkRange === 'number' ? props.talkRange : TALK_RANGE_M;
|
|
123
|
-
if (d <= range && (!best || d < best.d)) {
|
|
124
|
-
best = { id: actor.id, name: typeof props.name === 'string' && props.name ? props.name : actor.id, d };
|
|
377
|
+
if (d <= range && (!best || d < best.d || actor.id === preferred)) {
|
|
378
|
+
best = { id: actor.id, name: typeof props.name === 'string' && props.name ? props.name : actor.id, mind: typeof props.character === 'string' && Boolean(props.character), character: props.character, d };
|
|
379
|
+
if (actor.id === preferred) {
|
|
380
|
+
choice = best;
|
|
381
|
+
}
|
|
125
382
|
}
|
|
126
383
|
}
|
|
127
|
-
return best;
|
|
384
|
+
return choice ?? best;
|
|
128
385
|
}
|
|
129
386
|
|
|
130
|
-
function
|
|
131
|
-
if (!
|
|
387
|
+
function companionNpc(scene) {
|
|
388
|
+
if (!hub.place?.companionChat) {
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
const playerId = scene.multiplayer?.net?.selfId?.();
|
|
392
|
+
return playerId && hub.companion?.c && scene.actorWith('Player')
|
|
393
|
+
? { id: `companion:${playerId}`, name: hub.place.companionChat.name, mind: true } : null;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function ask(t, near = t.near) {
|
|
397
|
+
if (!near || !t.net || t.asking) {
|
|
132
398
|
return;
|
|
133
399
|
}
|
|
134
|
-
t.asking =
|
|
135
|
-
t.
|
|
400
|
+
t.asking = near.id;
|
|
401
|
+
t.abandonedOpens.delete(near.id);
|
|
402
|
+
dropHook(t, near.id, near.character ?? t.hooks.get(near.id));
|
|
403
|
+
t.net.send({ k: 'hub-npc-open', npc: near.id });
|
|
136
404
|
}
|
|
137
405
|
|
|
138
406
|
function end(t) {
|
|
139
407
|
if (t.open && t.net) {
|
|
140
408
|
t.net.send({ k: 'hub-npc-end', npc: t.open.npc });
|
|
141
409
|
}
|
|
410
|
+
clearAuthored(t.open);
|
|
411
|
+
if (t.open?.attachment) {
|
|
412
|
+
t.abandonedOpens.add(t.open.npc);
|
|
413
|
+
}
|
|
414
|
+
cancelAttach(t.open);
|
|
415
|
+
cancelNotesWait(t.open);
|
|
416
|
+
clearTimeout(t.open?.closeTimer);
|
|
417
|
+
clearTimeout(t.open?.interruptionTimer);
|
|
142
418
|
t.open = null;
|
|
419
|
+
t.asking = null;
|
|
143
420
|
t.waiting = false;
|
|
144
421
|
t.chrome.closeTalk();
|
|
145
422
|
}
|
|
146
423
|
|
|
424
|
+
function cancelAttach(open, attached = false) {
|
|
425
|
+
const attachment = open?.attachment;
|
|
426
|
+
if (attachment) {
|
|
427
|
+
clearTimeout(attachment.timer);
|
|
428
|
+
open.attachment = null;
|
|
429
|
+
attachment.resolve(attached);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function reattach(t, open) {
|
|
434
|
+
if (t.open !== open || open.interrupted || !t.net) {
|
|
435
|
+
return Promise.resolve(false);
|
|
436
|
+
}
|
|
437
|
+
if (open.attachment) {
|
|
438
|
+
return open.attachment.promise;
|
|
439
|
+
}
|
|
440
|
+
const attachment = { needsNotes: open.mind && open.prefix !== null, opened: false };
|
|
441
|
+
attachment.promise = new Promise((resolve) => { attachment.resolve = resolve; });
|
|
442
|
+
open.attachment = attachment;
|
|
443
|
+
t.asking = open.npc;
|
|
444
|
+
attachment.timer = setTimeout(() => {
|
|
445
|
+
if (t.open === open && open.attachment === attachment) {
|
|
446
|
+
interrupted(t, open);
|
|
447
|
+
}
|
|
448
|
+
}, ATTACH_WAIT_MS);
|
|
449
|
+
t.net.send({ k: 'hub-npc-open', npc: open.npc });
|
|
450
|
+
return attachment.promise;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function cancelNotesWait(open, ready = false) {
|
|
454
|
+
if (open?.notesWait) {
|
|
455
|
+
clearTimeout(open.notesWait.timer);
|
|
456
|
+
open.notesWait.resolve(ready);
|
|
457
|
+
open.notesWait = null;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function waitForNotes(t, open, version) {
|
|
462
|
+
if (t.open !== open || open.interrupted) {
|
|
463
|
+
return Promise.resolve(false);
|
|
464
|
+
}
|
|
465
|
+
if ((open.notesVersion ?? 0) > version) {
|
|
466
|
+
return Promise.resolve(true);
|
|
467
|
+
}
|
|
468
|
+
const wait = {};
|
|
469
|
+
wait.promise = new Promise((resolve) => { wait.resolve = resolve; });
|
|
470
|
+
open.notesWait = wait;
|
|
471
|
+
wait.timer = setTimeout(() => {
|
|
472
|
+
if (t.open === open && open.notesWait === wait) {
|
|
473
|
+
interrupted(t, open);
|
|
474
|
+
}
|
|
475
|
+
}, ATTACH_WAIT_MS);
|
|
476
|
+
return wait.promise;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function interrupted(t, open) {
|
|
480
|
+
if (t.open !== open || open.closeTimer) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
open.interrupted = true;
|
|
484
|
+
clearTimeout(open.interruptionTimer);
|
|
485
|
+
if (open.attachment) {
|
|
486
|
+
t.abandonedOpens.add(open.npc);
|
|
487
|
+
}
|
|
488
|
+
cancelAttach(open);
|
|
489
|
+
cancelNotesWait(open);
|
|
490
|
+
clearAuthored(open);
|
|
491
|
+
open.operationId = null;
|
|
492
|
+
t.asking = null;
|
|
493
|
+
t.waiting = false;
|
|
494
|
+
t.chrome.talkWaiting(false);
|
|
495
|
+
t.chrome.talkAsks?.([], null);
|
|
496
|
+
if (!open.interruptionShown) {
|
|
497
|
+
t.chrome.talkLine('them', open.interruptionLine || INTERRUPTED_LINE);
|
|
498
|
+
open.interruptionShown = true;
|
|
499
|
+
}
|
|
500
|
+
const draft = open.pendingText || t.chrome.talkDraft?.();
|
|
501
|
+
if (draft) {
|
|
502
|
+
t.drafts.set(open.npc, draft);
|
|
503
|
+
t.chrome.talkDraft?.(draft);
|
|
504
|
+
open.sent.delete(draft);
|
|
505
|
+
}
|
|
506
|
+
t.chrome.talkTyping?.(false);
|
|
507
|
+
open.closeTimer = setTimeout(() => {
|
|
508
|
+
if (t.open === open) {
|
|
509
|
+
end(t);
|
|
510
|
+
}
|
|
511
|
+
}, INTERRUPTED_MS);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function clearAuthored(open) {
|
|
515
|
+
if (open?.authored) {
|
|
516
|
+
clearTimeout(open.authored.timer);
|
|
517
|
+
open.authored = null;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function finishAuthored(t, open, replied) {
|
|
522
|
+
if (t.open !== open || !open.authored) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (replied) {
|
|
526
|
+
open.sent.add(open.authored.text);
|
|
527
|
+
open.pendingText = null;
|
|
528
|
+
}
|
|
529
|
+
clearAuthored(open);
|
|
530
|
+
t.waiting = false;
|
|
531
|
+
t.chrome.talkWaiting(false);
|
|
532
|
+
refill(t);
|
|
533
|
+
}
|
|
534
|
+
|
|
147
535
|
// The world learns which player here is which participant from that player's
|
|
148
536
|
// own read; the place needs it to tell who a character chose to follow.
|
|
149
|
-
function registerParticipant(t, net) {
|
|
537
|
+
async function registerParticipant(t, net) {
|
|
150
538
|
const characters = net?.characters;
|
|
151
|
-
if (!characters || t.inspected.has(net)) {
|
|
539
|
+
if (!characters || t.inspected.has(net) || t.inspecting.has(net)) {
|
|
152
540
|
return;
|
|
153
541
|
}
|
|
154
|
-
t.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
542
|
+
t.inspecting.add(net);
|
|
543
|
+
try {
|
|
544
|
+
await characters.readCharacters({ requestId: newId(), query: { type: 'inspect' } });
|
|
545
|
+
t.inspected.add(net);
|
|
546
|
+
if (t.net === net && t.open?.mind) {
|
|
547
|
+
t.open.canType = true;
|
|
548
|
+
t.chrome.talkTyping(true);
|
|
549
|
+
refill(t);
|
|
550
|
+
}
|
|
551
|
+
} catch (err) {
|
|
552
|
+
const code = err?.code ?? err?.message ?? String(err);
|
|
553
|
+
if (!t.inspectRefusals.has(code)) {
|
|
554
|
+
t.inspectRefusals.add(code);
|
|
555
|
+
console.log(`[hub] NPC inspect failed: ${code}`);
|
|
556
|
+
}
|
|
557
|
+
} finally {
|
|
558
|
+
t.inspecting.delete(net);
|
|
559
|
+
}
|
|
158
560
|
}
|
|
159
561
|
|
|
160
562
|
function send(t, raw) {
|
|
161
563
|
const text = String(raw ?? '').trim().slice(0, INPUT_MAX);
|
|
162
564
|
const open = t.open;
|
|
163
|
-
if (!text || !open || t.waiting || !t.net) {
|
|
565
|
+
if (!text || !open?.canType || open.interrupted || t.waiting || !t.net) {
|
|
164
566
|
return;
|
|
165
567
|
}
|
|
568
|
+
if (!open.mind && performance.now() - t.saidAt < AUTHORED_GAP_MS) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
t.chrome.talkAsks?.([], null);
|
|
166
572
|
t.chrome.talkLine('me', text);
|
|
573
|
+
t.waiting = true;
|
|
574
|
+
open.pendingText = text;
|
|
575
|
+
t.chrome.talkWaiting(true);
|
|
576
|
+
if (open.needsAttach || open.attachment) {
|
|
577
|
+
void reattach(t, open).then((attached) => {
|
|
578
|
+
if (attached && t.open === open) {
|
|
579
|
+
dispatch(t, open, text, true);
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
dispatch(t, open, text);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function dispatch(t, open, text, reattached = false) {
|
|
588
|
+
reattached ||= open.reattached === true;
|
|
589
|
+
open.reattached = false;
|
|
167
590
|
if (!open.mind) {
|
|
168
|
-
t.
|
|
591
|
+
t.saidAt = performance.now();
|
|
592
|
+
// A reply to an earlier send must not acknowledge this question.
|
|
593
|
+
const rid = newId();
|
|
594
|
+
open.authored = { text, rid, timer: setTimeout(() => finishAuthored(t, open, false), AUTHORED_WAIT_MS) };
|
|
595
|
+
t.net.send({ k: 'hub-npc-say', npc: open.npc, text, rid });
|
|
169
596
|
return;
|
|
170
597
|
}
|
|
171
|
-
|
|
172
|
-
void turn(t, open, text);
|
|
598
|
+
open.sent.add(text);
|
|
599
|
+
void turn(t, open, text, reattached);
|
|
173
600
|
}
|
|
174
601
|
|
|
175
|
-
async function turn(t, open, text) {
|
|
602
|
+
async function turn(t, open, text, attachRetried = false) {
|
|
176
603
|
const net = t.net;
|
|
177
604
|
const characters = net?.characters;
|
|
178
605
|
let operationId = null;
|
|
606
|
+
let requests = 0;
|
|
607
|
+
let notesVersion = 0;
|
|
608
|
+
// A scripted line may end this wait and let the player send again.
|
|
609
|
+
const active = () => t.open === open && t.net === net && open.operationId === operationId;
|
|
179
610
|
const request = () => {
|
|
180
|
-
|
|
611
|
+
requests++;
|
|
612
|
+
notesVersion = open.notesVersion ?? 0;
|
|
613
|
+
open.operationId = operationId = newId();
|
|
614
|
+
open.recoveryOperationId = attachRetried ? operationId : null;
|
|
181
615
|
return characters.requestCharacterTurn({
|
|
182
616
|
requestId: newId(),
|
|
183
617
|
operationId,
|
|
@@ -187,32 +621,82 @@ async function turn(t, open, text) {
|
|
|
187
621
|
audience: { disclosure: 'participants', playerIds: [], characterIds: [] },
|
|
188
622
|
});
|
|
189
623
|
};
|
|
624
|
+
let notesRetried = false;
|
|
190
625
|
try {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
626
|
+
while (true) {
|
|
627
|
+
try {
|
|
628
|
+
await request();
|
|
629
|
+
if (open.recoveryOperationId === operationId) {
|
|
630
|
+
open.recoveryOperationId = null;
|
|
631
|
+
}
|
|
632
|
+
if (active()) {
|
|
633
|
+
open.pendingText = null;
|
|
634
|
+
}
|
|
635
|
+
break;
|
|
636
|
+
} catch (err) {
|
|
637
|
+
if (err?.code === 'HUB_NPC_NOT_TALKING' && active() && !attachRetried && requests < 2) {
|
|
638
|
+
attachRetried = true;
|
|
639
|
+
if (!(await reattach(t, open)) || !active()) {
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
// The notes changed under the words (a pad filled): once more, with
|
|
645
|
+
// the newest the server sent.
|
|
646
|
+
if (err?.code !== 'HUB_NPC_NOTES' || !active() || notesRetried || requests >= 2) {
|
|
647
|
+
throw err;
|
|
648
|
+
}
|
|
649
|
+
notesRetried = true;
|
|
650
|
+
if (attachRetried) {
|
|
651
|
+
if (!(await waitForNotes(t, open, notesVersion))) {
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
} else {
|
|
655
|
+
await new Promise((resolve) => setTimeout(resolve, NOTES_RETRY_MS));
|
|
656
|
+
}
|
|
657
|
+
if (!active()) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
198
660
|
}
|
|
199
|
-
await new Promise((resolve) => setTimeout(resolve, NOTES_RETRY_MS));
|
|
200
|
-
await request();
|
|
201
661
|
}
|
|
202
662
|
} catch (err) {
|
|
203
663
|
// A refusal (busy, over budget, too far) comes with the place's own line,
|
|
204
664
|
// which ends the wait; this only covers a refusal that brought none.
|
|
205
665
|
console.log(`[hub] NPC turn refused: ${err?.code ?? err?.message ?? err}`);
|
|
666
|
+
// The server holds no conversation for this panel (it ended there, or the
|
|
667
|
+
// session never had one) and sends no line with that: a panel left open
|
|
668
|
+
// would take more words and answer none. Closed, the talk button is back.
|
|
669
|
+
if (active() && (err?.code === 'HUB_NPC_NOT_TALKING' || attachRetried)) {
|
|
670
|
+
const why = REFUSAL_WHY[err?.code];
|
|
671
|
+
if (why) {
|
|
672
|
+
// A rejection may precede its separate scripted-line packet. Keep
|
|
673
|
+
// the pending words and allow that line the same grace as an open
|
|
674
|
+
// refusal; neither packet order can leave the panel accepting words.
|
|
675
|
+
open.interrupted = true;
|
|
676
|
+
open.interruptionWhy = why;
|
|
677
|
+
open.interruptionTimer = setTimeout(() => interrupted(t, open), 250);
|
|
678
|
+
} else {
|
|
679
|
+
interrupted(t, open);
|
|
680
|
+
}
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (open.interrupted) {
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
206
686
|
setTimeout(() => {
|
|
207
|
-
if (
|
|
687
|
+
if (active()) {
|
|
688
|
+
open.operationId = null;
|
|
208
689
|
t.waiting = false;
|
|
209
690
|
}
|
|
210
691
|
}, 1500);
|
|
211
692
|
return;
|
|
212
693
|
}
|
|
213
694
|
const started = performance.now();
|
|
214
|
-
while (
|
|
695
|
+
while (active() && performance.now() - started < POLL_LIMIT_MS) {
|
|
215
696
|
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
697
|
+
if (!active()) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
216
700
|
let status = null;
|
|
217
701
|
try {
|
|
218
702
|
status = await characters.readCharacters({ requestId: newId(), query: { type: 'status', operationId } });
|
|
@@ -220,14 +704,21 @@ async function turn(t, open, text) {
|
|
|
220
704
|
console.log(`[hub] NPC status read failed: ${err?.code ?? err?.message ?? err}`);
|
|
221
705
|
continue;
|
|
222
706
|
}
|
|
707
|
+
if (!active()) {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
223
710
|
if (status?.status === 'completed' || status?.status === 'interrupted') {
|
|
224
|
-
|
|
225
|
-
|
|
711
|
+
const reply = typeof status.response === 'string' ? status.response : status.response?.text;
|
|
712
|
+
if (typeof reply === 'string' && reply) {
|
|
713
|
+
t.chrome.talkLine('them', unquote(reply));
|
|
226
714
|
}
|
|
715
|
+
const suggestions = Array.isArray(status.suggestions) && status.suggestions.every((ask) => typeof ask === 'string') ? status.suggestions : status.response?.suggestions;
|
|
716
|
+
refill(t, suggestions);
|
|
227
717
|
break;
|
|
228
718
|
}
|
|
229
719
|
}
|
|
230
|
-
if (
|
|
720
|
+
if (active()) {
|
|
721
|
+
open.operationId = null;
|
|
231
722
|
t.waiting = false;
|
|
232
723
|
}
|
|
233
724
|
}
|