castle-web-cli 0.4.230 → 0.4.232

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.
Files changed (92) hide show
  1. package/dist/castle-host/host.js +81 -0
  2. package/dist/devSaveStorage.d.ts +36 -0
  3. package/dist/devSaveStorage.js +469 -0
  4. package/dist/devSessionChild.js +22 -12
  5. package/dist/devSessionServer.js +8 -2
  6. package/dist/devSessionStorage.d.ts +9 -0
  7. package/dist/devSessionStorage.js +66 -1
  8. package/dist/init.js +1 -1
  9. package/dist/serve.js +5 -1
  10. package/dist/serverBundle.js +5 -3
  11. package/kits/base/castle.json +1 -1
  12. package/kits/base/sdk/README.md +148 -1
  13. package/kits/base/sdk/castle.d.ts +4 -0
  14. package/kits/base/sdk/castle.js +2 -0
  15. package/kits/base/sdk/commands.d.ts +15 -0
  16. package/kits/base/sdk/multiplayer.js +52 -4
  17. package/kits/base/sdk/save.d.ts +197 -0
  18. package/kits/base/sdk/save.js +525 -0
  19. package/kits/base/sdk/saveCoordinator.d.ts +39 -0
  20. package/kits/base/sdk/saveCoordinator.js +252 -0
  21. package/kits/base/sdk/server/storage.d.ts +3 -2
  22. package/kits/base/sdk/server/storage.js +25 -5
  23. package/kits/base/sdk/server/wrapper.d.ts +4 -0
  24. package/kits/base/sdk/server/wrapper.js +2 -0
  25. package/kits/base/sdk/store.d.ts +3 -2
  26. package/kits/base/sdk/store.js +5 -0
  27. package/kits/hub-game/CLAUDE.md +29 -4
  28. package/kits/hub-game/code/client/avatar.js +39 -0
  29. package/kits/hub-game/code/client/chat.js +12 -0
  30. package/kits/hub-game/code/client/chrome.js +237 -13
  31. package/kits/hub-game/code/client/grab.js +166 -7
  32. package/kits/hub-game/code/client/hats.js +26 -0
  33. package/kits/hub-game/code/client/hookLayer.js +36 -3
  34. package/kits/hub-game/code/client/hudClear.js +126 -0
  35. package/kits/hub-game/code/client/state.js +35 -1
  36. package/kits/hub-game/code/client/talk.js +10 -36
  37. package/kits/hub-game/code/client/tiers.js +505 -0
  38. package/kits/hub-game/code/client/together.js +144 -4
  39. package/kits/hub-game/code/client/wear.js +96 -14
  40. package/kits/hub-game/code/server/actors.js +5 -0
  41. package/kits/hub-game/code/server/grab.js +299 -13
  42. package/kits/hub-game/code/server/hub.js +162 -7
  43. package/kits/hub-game/code/server/manifest.js +80 -8
  44. package/kits/hub-game/code/server/npcs.js +21 -33
  45. package/kits/hub-game/code/server/party.js +75 -6
  46. package/kits/hub-game/code/server/say.js +8 -2
  47. package/kits/hub-game/code/server/wear.js +116 -11
  48. package/kits/hub-game/code/systems/hub.js +386 -21
  49. package/kits/hub-game/docs/contract.md +285 -19
  50. package/kits/hub-game/package.json +1 -1
  51. package/kits/hub-game/scripts/test-chat.mjs +32 -0
  52. package/kits/hub-game/scripts/test-grab-client.mjs +511 -0
  53. package/kits/hub-game/scripts/test-grab.mjs +857 -3
  54. package/kits/hub-game/scripts/test-hats.mjs +229 -0
  55. package/kits/hub-game/scripts/test-hub-trip.mjs +721 -0
  56. package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
  57. package/kits/hub-game/scripts/test-manifest.mjs +122 -1
  58. package/kits/hub-game/scripts/test-npcs.mjs +34 -24
  59. package/kits/hub-game/scripts/test-party.mjs +108 -4
  60. package/kits/hub-game/scripts/test-say.mjs +59 -2
  61. package/kits/hub-game/scripts/test-tiers.mjs +854 -0
  62. package/kits/hub-game/scripts/test-together.mjs +33 -1
  63. package/kits/hub-game/scripts/test-try-on.mjs +940 -0
  64. package/kits/physics-2d/CLAUDE.md +2 -0
  65. package/kits/physics-2d/castle.json +2 -2
  66. package/kits/physics-2d/engine/scene.js +127 -0
  67. package/kits/physics-2d/package.json +1 -1
  68. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +298 -0
  69. package/kits/physics-3d/CLAUDE.md +531 -0
  70. package/kits/physics-3d/behaviors/Player.jsx +437 -3
  71. package/kits/physics-3d/castle.json +3 -3
  72. package/kits/physics-3d/docs/pxmodel-format.md +4 -0
  73. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -1
  74. package/kits/physics-3d/engine3d/actornode.js +253 -0
  75. package/kits/physics-3d/engine3d/nearshadows.js +600 -0
  76. package/kits/physics-3d/engine3d/optimize.js +49 -0
  77. package/kits/physics-3d/engine3d/orbitinput.js +277 -0
  78. package/kits/physics-3d/engine3d/unchanged.js +153 -0
  79. package/kits/physics-3d/engine3d/world3d.js +525 -11
  80. package/kits/physics-3d/package.json +1 -1
  81. package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
  82. package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
  83. package/kits/physics-3d/scripts/test-camera-follow.mjs +543 -0
  84. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2105 -0
  85. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
  86. package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
  87. package/kits/physics-3d/scripts/test-static-actors.mjs +667 -0
  88. package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
  89. package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
  90. package/kits/physics-3d/scripts/test-steady-hover.mjs +633 -0
  91. package/kits/physics-3d/systems/physics3d.js +273 -9
  92. package/package.json +1 -1
@@ -10,14 +10,35 @@
10
10
  // { k: 'hub-grab-deny', actor } server -> that client
11
11
  // { k: 'hub-drop' } server -> that client
12
12
  //
13
+ // A place may keep a held object its holder's (v1.25, `grab.keepHeld`):
14
+ // multiplayer-3d hands a loose object to whichever player is nearer, so
15
+ // someone standing close takes a held object out of its holder's hands. In
16
+ // such a place the held object is pinned -- its sim entry's `claimable` is
17
+ // false, so multiplayer-3d refuses every other claim -- for as long as the
18
+ // hold lasts and its holder's client keeps saying it holds it:
19
+ //
20
+ // { k: 'hub-grab', actor, op: 'hold' } client -> server, about once a second
21
+ //
22
+ // A place without `keepHeld` never pins, and drops that message as malformed.
23
+ //
24
+ // A place may keep a loose object for one player (v1.27, `hub.keepFor`): a
25
+ // grab of it by anyone else is refused here, before the place's hook is asked,
26
+ // and every client is told whose it is (`hubKept`, `keptOf`) so it is offered
27
+ // to nobody else. `keptFor` is empty until a place calls `hub.keepFor`, and
28
+ // every line that reads it does nothing while it is: such a place is checked,
29
+ // asked and sent exactly what it was.
30
+ //
13
31
  // `h` is the hub layer's state: `place`, `actors`, `sim`, `hidden`, `held`,
14
32
  // `hooks`, `ctx`, `session`, and `grabs`, `grabBudget`, `flying` from
15
33
  // `newGrabState`. Every message is a client's word, so each is checked
16
34
  // against the simulation and bounded per player.
17
35
 
36
+ import { warnOnce } from './actors.js';
37
+
18
38
  // How far from a player's body (metres) an object they say they grabbed may
19
- // be: the client offers one within about 2.5 m, and the server's poses lag a
20
- // moving player's.
39
+ // be: the client offers one within about 2.5 m (with a place's `grab.reach`
40
+ // or `grab.steady`, v1.22, never one whose centre is past 3.5 m), and the
41
+ // server's poses lag a moving player's.
21
42
  export const GRAB_REACH = 4;
22
43
  // A held object is in front of its player; a throw is told as it leaves the
23
44
  // hand, from about multiplayer-3d's claim reach.
@@ -30,6 +51,16 @@ export const GRAB_BURST = 4;
30
51
  // again, and the speed below which it has landed.
31
52
  export const FLIGHT_MS = 3000;
32
53
  const LANDED_SPEED = 4;
54
+ // v1.25 `keepHeld`: a pin lasts this long past the grab or the holder's last
55
+ // `hold`. The client ends a hold by itself without a word (a trip, the talk
56
+ // panel, a refusal), and one from before v1.25 never says `hold` at all, so a
57
+ // pin nobody renews lapses and the object is anyone's again, as before.
58
+ export const KEEP_LEASE_MS = 2500;
59
+ // A pinned object is in front of its holder (`holdDistance` is at most 3 m,
60
+ // `holdHeight` 2.5 m). Farther than this from the holder's body, by the
61
+ // server's own poses, it is not being held: the pin and the hold end, at each
62
+ // tick and at each `hold`, so a client cannot keep an object pinned from afar.
63
+ export const KEEP_REACH = THROW_REACH;
33
64
 
34
65
  export function newGrabState() {
35
66
  return {
@@ -40,11 +71,195 @@ export function newGrabState() {
40
71
  // actorId -> { until }: thrown objects in flight (their sim entry carries
41
72
  // the flight's `speedCap` meanwhile)
42
73
  flying: new Map(),
74
+ // actorId -> { holder, claimable, until }: held objects pinned to their
75
+ // holder (v1.25 `keepHeld`), with the `claimable` to put back
76
+ pins: new Map(),
77
+ // `keepHeld` only: how many times a hold of each player, or of each
78
+ // object, or everyone's, has been ended or ruled out (`ended`), so a grab
79
+ // being put to the place's hook can tell that the hook itself did so
80
+ ends: { players: new Map(), objects: new Map(), all: 0 },
81
+ // actorId -> the only player who may grab it (v1.27 `hub.keepFor`); empty
82
+ // in a place that never calls it
83
+ keptFor: new Map(),
43
84
  };
44
85
  }
45
86
 
87
+ // v1.27: whether this object is kept for a player other than this one. False
88
+ // for everything while nothing is kept.
89
+ function keptFromPlayer(h, playerId, actorId) {
90
+ return h.keptFor.size > 0 && h.keptFor.has(actorId) && h.keptFor.get(actorId) !== playerId;
91
+ }
92
+
93
+ // `hub.keepFor(actorId, playerId | null)` (v1.27): from now on only that
94
+ // player may grab this loose object; `null` makes it anyone's again. Anyone
95
+ // else holding it lets go (`hub-drop`, as `hub.drop` tells them). Returns
96
+ // whether the object is now kept as asked; a place without `grab`, an actor
97
+ // that is not a dynamic one of the place's scene, or a player who is not here
98
+ // is warned about once and changes nothing. The mark outlives `hub.reset` and
99
+ // ends with `hub.hide`, with the player's leaving, and with `null`.
100
+ export function keepFor(h, actorId, playerId) {
101
+ if (!h.place.grab) {
102
+ warnOnce(h, 'keepFor:grab', 'hub.keepFor: this place has no "grab" in its hub block');
103
+ return false;
104
+ }
105
+ const actor = typeof actorId === 'string' ? h.actors.find((a) => a.id === actorId) : null;
106
+ if (actor?.components.Body?.type !== 'dynamic' || !h.sim?.objects?.get(actorId)?.body) {
107
+ warnOnce(h, `keepFor:${actorId}`, `hub.keepFor: "${actorId}" is not a dynamic actor of this place's scene`);
108
+ return false;
109
+ }
110
+ // Only `null` clears: a player id that is missing (a lookup that failed) is
111
+ // an invalid player, warned about below, and never frees the object.
112
+ if (playerId === null) {
113
+ h.keptFor.delete(actorId);
114
+ return true;
115
+ }
116
+ if (!h.players.has(playerId)) {
117
+ warnOnce(h, `keepFor:player:${playerId}`, `hub.keepFor: "${playerId}" is not a player in this place`);
118
+ return false;
119
+ }
120
+ h.keptFor.set(actorId, playerId);
121
+ for (const [holder, held] of [...h.grabs]) {
122
+ if (held === actorId && holder !== playerId) {
123
+ endHold(h, holder);
124
+ h.session?.send(holder, { k: 'hub-drop', actor: actorId });
125
+ }
126
+ }
127
+ return true;
128
+ }
129
+
130
+ // The place hid an object (`hub.hide`): kept for nobody. (A copy made by
131
+ // `hub.spawn` is never a loose object, so `hub.despawn` has none to forget.)
132
+ export function unkeep(h, actorId) {
133
+ h.keptFor.delete(actorId);
134
+ }
135
+
136
+ // What clients are told (`hubKept`): actor id -> the player it is kept for.
137
+ export function keptOf(h) {
138
+ const out = Object.create(null);
139
+ for (const [actorId, playerId] of h.keptFor) {
140
+ out[actorId] = playerId;
141
+ }
142
+ return out;
143
+ }
144
+
145
+ // In a `keepHeld` place, note that this player's hold, this object's, or
146
+ // everyone's (neither given) is over, whether or not there was one.
147
+ function ended(h, playerId, actorId) {
148
+ if (!keeps(h)) {
149
+ return;
150
+ }
151
+ if (playerId === undefined && actorId === undefined) {
152
+ h.ends.all += 1;
153
+ }
154
+ if (playerId !== undefined) {
155
+ h.ends.players.set(playerId, (h.ends.players.get(playerId) ?? 0) + 1);
156
+ }
157
+ if (actorId !== undefined) {
158
+ h.ends.objects.set(actorId, (h.ends.objects.get(actorId) ?? 0) + 1);
159
+ }
160
+ }
161
+
162
+ function endsOf(h, playerId, actorId) {
163
+ return `${h.ends.all}:${h.ends.players.get(playerId) ?? 0}:${h.ends.objects.get(actorId) ?? 0}`;
164
+ }
165
+
166
+ function keeps(h) {
167
+ return h.place.grab?.keepHeld === true;
168
+ }
169
+
170
+ // Pin a held object to its holder, or renew the pin.
171
+ function pin(h, playerId, actorId, entry) {
172
+ if (!keeps(h)) {
173
+ return;
174
+ }
175
+ const until = h.sim.timeMs + KEEP_LEASE_MS;
176
+ const had = h.pins.get(actorId);
177
+ if (had) {
178
+ had.holder = playerId;
179
+ had.until = until;
180
+ return;
181
+ }
182
+ h.pins.set(actorId, { holder: playerId, claimable: entry.claimable, until });
183
+ entry.claimable = false;
184
+ }
185
+
186
+ // Take a pin off: the object is as claimable as it was before. With `holder`,
187
+ // only that player's pin. `hub.reset` unpins before its own hold on
188
+ // `claimable` (`actors.js`), so the two never save each other's `false`.
189
+ export function unpin(h, actorId, holder) {
190
+ const pinned = h.pins?.get(actorId);
191
+ if (!pinned || (holder !== undefined && pinned.holder !== holder)) {
192
+ return;
193
+ }
194
+ h.pins.delete(actorId);
195
+ const entry = h.sim?.objects?.get(actorId);
196
+ if (entry) {
197
+ entry.claimable = pinned.claimable;
198
+ }
199
+ }
200
+
201
+ // What a hold in a `keepHeld` place needs beyond what any hold does, checked
202
+ // at every tick and every `hold` whether or not it is pinned just now: a
203
+ // player who has arrived and whose game has not ended, with their body by
204
+ // the object.
205
+ function inForce(h, playerId, entry) {
206
+ const player = h.players.get(playerId);
207
+ return Boolean(player?.arrived && !player.ended && entry?.body && near(h, playerId, entry, KEEP_REACH));
208
+ }
209
+
210
+ // The place took an object out of play (`hub.hide`, `hub.reset`): unpinned,
211
+ // and in a `keepHeld` place its hold is over at once, not at the next tick.
212
+ export function taken(h, actorId) {
213
+ ended(h, undefined, actorId);
214
+ unpin(h, actorId);
215
+ if (keeps(h)) {
216
+ for (const [playerId, held] of [...h.grabs]) {
217
+ if (held === actorId) {
218
+ endHold(h, playerId);
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+ // The place held a player still (`hub.hold`): in a `keepHeld` place their
225
+ // hold is over at once.
226
+ export function stilled(h, playerId) {
227
+ ended(h, playerId);
228
+ if (keeps(h)) {
229
+ endHold(h, playerId);
230
+ }
231
+ }
232
+
233
+ // In a `keepHeld` place, after the place's hook has run: everything a grab
234
+ // had to pass before it, read again, since the hook may have ended the
235
+ // player's game, moved or removed their body, or taken the object away.
236
+ function stillGrabbable(h, playerId, actorId) {
237
+ const entry = looseObject(h, actorId);
238
+ const player = h.players.get(playerId);
239
+ return Boolean(
240
+ player?.arrived &&
241
+ !player.ended &&
242
+ h.sim.players.has(playerId) &&
243
+ !h.held.has(playerId) &&
244
+ entry?.owner === playerId &&
245
+ near(h, playerId, entry, GRAB_REACH),
246
+ );
247
+ }
248
+
249
+ // Every end of a hold goes through here, so its pin goes with it.
250
+ function endHold(h, playerId) {
251
+ const actorId = h.grabs.get(playerId);
252
+ if (actorId === undefined) {
253
+ return;
254
+ }
255
+ h.grabs.delete(playerId);
256
+ ended(h, playerId, actorId);
257
+ unpin(h, actorId, playerId);
258
+ }
259
+
46
260
  // A scene actor whose body multiplayer-3d hands to clients: authored with a
47
- // dynamic Body, built as a claimable object, and not hidden by the place.
261
+ // dynamic Body, built as a claimable object, and not hidden by the place. A
262
+ // pinned object (v1.25) is still one: it is unclaimable only because it is held.
48
263
  function looseObject(h, actorId) {
49
264
  if (typeof actorId !== 'string' || actorId.length > 128 || h.hidden.has(actorId)) {
50
265
  return null;
@@ -54,7 +269,7 @@ function looseObject(h, actorId) {
54
269
  return null;
55
270
  }
56
271
  const entry = h.sim?.objects?.get(actorId);
57
- return entry?.claimable && entry.body ? entry : null;
272
+ return (entry?.claimable || (entry && h.pins.has(actorId))) && entry.body ? entry : null;
58
273
  }
59
274
 
60
275
  function near(h, playerId, entry, reach) {
@@ -78,6 +293,13 @@ function spend(h, playerId) {
78
293
  }
79
294
 
80
295
  function deny(h, playerId, actorId) {
296
+ // In a `keepHeld` place a refusal of what the player holds ends that hold,
297
+ // record and pin: the client lets go, and no later `hold` may renew a pin
298
+ // the place's hook has since refused. (Elsewhere a refusal leaves the
299
+ // record as it always did, until the object moves on.)
300
+ if (keeps(h) && h.grabs.get(playerId) === actorId) {
301
+ endHold(h, playerId);
302
+ }
81
303
  h.session?.send(playerId, { k: 'hub-grab-deny', actor: actorId });
82
304
  }
83
305
 
@@ -99,8 +321,9 @@ function ask(h, playerId, actorId, op) {
99
321
  // dropped. A grab that is refused -- past the rate, not a loose object of the
100
322
  // place, too far, not this player's to simulate, a held or departed player,
101
323
  // or the place's hook said no -- is answered `hub-grab-deny`, and the client
102
- // lets go. A throw of something the place does not know this player holds is
103
- // dropped.
324
+ // lets go. So is a grab of an object the place keeps for another player
325
+ // (v1.27), which the hook is never asked about. A throw of something the
326
+ // place does not know this player holds is dropped.
104
327
  export function message(h, playerId, data) {
105
328
  const op = data?.op;
106
329
  if (
@@ -108,7 +331,7 @@ export function message(h, playerId, data) {
108
331
  playerId === null ||
109
332
  !h.place.grab ||
110
333
  !h.sim ||
111
- (op !== 'grab' && op !== 'throw') ||
334
+ (op !== 'grab' && op !== 'throw' && !(op === 'hold' && keeps(h))) ||
112
335
  typeof data.actor !== 'string' ||
113
336
  data.actor.length > 128
114
337
  ) {
@@ -118,16 +341,35 @@ export function message(h, playerId, data) {
118
341
  if (!spend(h, playerId)) {
119
342
  if (op === 'grab') {
120
343
  deny(h, playerId, actorId);
344
+ } else if (op === 'throw' && keeps(h) && h.grabs.get(playerId) === actorId) {
345
+ // Past the rate a throw is not heard, but in a `keepHeld` place the
346
+ // hold it ends is over all the same: no `hold` renews it.
347
+ endHold(h, playerId);
121
348
  }
122
349
  return;
123
350
  }
124
351
  const entry = looseObject(h, actorId);
125
352
  const entered = h.players.get(playerId)?.arrived && !h.players.get(playerId)?.ended;
353
+ if (op === 'hold') {
354
+ // Still holding it, says its holder's client: the pin is renewed (or put
355
+ // back after a lapse) while the hold is one the server still knows.
356
+ // A holder whose body is not by the object is not holding it, whatever
357
+ // poses its client reports for it: that hold is over.
358
+ if (h.grabs.get(playerId) !== actorId) {
359
+ return;
360
+ }
361
+ if (entry?.owner === playerId && !h.held.has(playerId) && inForce(h, playerId, entry)) {
362
+ pin(h, playerId, actorId, entry);
363
+ } else {
364
+ endHold(h, playerId);
365
+ }
366
+ return;
367
+ }
126
368
  if (op === 'throw') {
127
369
  if (h.grabs.get(playerId) !== actorId) {
128
370
  return;
129
371
  }
130
- h.grabs.delete(playerId);
372
+ endHold(h, playerId);
131
373
  // Still theirs, now: the object may have been handed to someone else, or
132
374
  // the player held, since the place last looked.
133
375
  if (entry && entry.owner === playerId && entered && !h.held.has(playerId) && near(h, playerId, entry, THROW_REACH)) {
@@ -147,7 +389,24 @@ export function message(h, playerId, data) {
147
389
  deny(h, playerId, actorId);
148
390
  return;
149
391
  }
150
- if (!ask(h, playerId, actorId, 'grab')) {
392
+ // v1.27: an object kept for someone else (`hub.keepFor`) is refused here,
393
+ // and the place's hook never hears of it.
394
+ if (keptFromPlayer(h, playerId, actorId)) {
395
+ deny(h, playerId, actorId);
396
+ return;
397
+ }
398
+ // In a `keepHeld` place the hook's own acts stand: if it dropped this
399
+ // player, hid or reset the object, or held the player still -- even if it
400
+ // undid that before returning -- the grab is refused, and the client is
401
+ // told so (`hub-grab-deny`) and lets go, rather than a hold the place just
402
+ // ended being recorded and pinned again.
403
+ const stamp = keeps(h) ? endsOf(h, playerId, actorId) : null;
404
+ if (
405
+ !ask(h, playerId, actorId, 'grab') ||
406
+ (stamp !== null && (endsOf(h, playerId, actorId) !== stamp || !stillGrabbable(h, playerId, actorId))) ||
407
+ // v1.27: the hook itself kept the object for someone else.
408
+ keptFromPlayer(h, playerId, actorId)
409
+ ) {
151
410
  deny(h, playerId, actorId);
152
411
  return;
153
412
  }
@@ -157,7 +416,14 @@ export function message(h, playerId, data) {
157
416
  h.grabs.delete(other);
158
417
  }
159
418
  }
419
+ // The object held before goes free. The record is set in place, as ever:
420
+ // the order of holders is the order `hub.drop` tells them in.
421
+ const before = h.grabs.get(playerId);
422
+ if (before !== undefined && before !== actorId) {
423
+ unpin(h, before, playerId);
424
+ }
160
425
  h.grabs.set(playerId, actorId);
426
+ pin(h, playerId, actorId, entry);
161
427
  }
162
428
 
163
429
  // A thrown object is not slowed to a shove's speed while it flies: until it
@@ -191,12 +457,13 @@ function capSpeed(body, cap) {
191
457
  // `hub.drop(playerId?)`: whoever holds something lets go (default: everyone).
192
458
  // Only players the place knows hold something are told. Returns how many.
193
459
  export function drop(h, playerId) {
460
+ ended(h, playerId);
194
461
  let n = 0;
195
462
  for (const [holder, actorId] of [...h.grabs]) {
196
463
  if (playerId !== undefined && holder !== playerId) {
197
464
  continue;
198
465
  }
199
- h.grabs.delete(holder);
466
+ endHold(h, holder);
200
467
  h.session?.send(holder, { k: 'hub-drop', actor: actorId });
201
468
  n += 1;
202
469
  }
@@ -213,9 +480,16 @@ export function tick(h) {
213
480
  !entry ||
214
481
  entry.owner !== playerId ||
215
482
  h.held.has(playerId) ||
216
- !h.sim.players.has(playerId)
483
+ !h.sim.players.has(playerId) ||
484
+ (keeps(h) && !inForce(h, playerId, entry))
217
485
  ) {
218
- h.grabs.delete(playerId);
486
+ endHold(h, playerId);
487
+ }
488
+ }
489
+ // A pin outlives nothing: not its hold, its lease, or its holder's visit.
490
+ for (const [actorId, pinned] of [...h.pins]) {
491
+ if (h.grabs.get(pinned.holder) !== actorId || h.sim.timeMs >= pinned.until) {
492
+ unpin(h, actorId);
219
493
  }
220
494
  }
221
495
  for (const [actorId, flight] of [...h.flying]) {
@@ -237,8 +511,20 @@ export function tick(h) {
237
511
  }
238
512
 
239
513
  export function forget(h, playerId) {
240
- h.grabs.delete(playerId);
514
+ endHold(h, playerId);
515
+ // Their count goes with them; `all` moves instead, so a grab in the hook
516
+ // just now still sees that something ended.
517
+ ended(h);
518
+ h.ends.players.delete(playerId);
241
519
  h.grabBudget.delete(playerId);
520
+ // v1.27: what was kept for them is anyone's again.
521
+ if (h.keptFor.size > 0) {
522
+ for (const [actorId, keeper] of [...h.keptFor]) {
523
+ if (keeper === playerId) {
524
+ h.keptFor.delete(actorId);
525
+ }
526
+ }
527
+ }
242
528
  }
243
529
 
244
530
  // Who holds what, for the place: actor id or null.