castle-web-cli 0.4.230 → 0.4.231
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/castle-host/host.js +81 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +22 -12
- package/dist/devSessionServer.js +8 -2
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/init.js +1 -1
- package/dist/serve.js +5 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +148 -1
- package/kits/base/sdk/castle.d.ts +4 -0
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +15 -0
- package/kits/base/sdk/multiplayer.js +52 -4
- package/kits/base/sdk/save.d.ts +197 -0
- package/kits/base/sdk/save.js +525 -0
- package/kits/base/sdk/saveCoordinator.d.ts +39 -0
- package/kits/base/sdk/saveCoordinator.js +252 -0
- package/kits/base/sdk/server/storage.d.ts +3 -2
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +4 -0
- package/kits/base/sdk/server/wrapper.js +2 -0
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/hub-game/CLAUDE.md +4 -1
- package/kits/hub-game/code/client/chrome.js +43 -9
- package/kits/hub-game/code/client/grab.js +142 -7
- package/kits/hub-game/code/client/hookLayer.js +7 -1
- package/kits/hub-game/code/client/state.js +13 -1
- package/kits/hub-game/code/client/talk.js +10 -36
- package/kits/hub-game/code/client/tiers.js +480 -0
- package/kits/hub-game/code/client/together.js +78 -3
- package/kits/hub-game/code/server/grab.js +3 -2
- package/kits/hub-game/code/server/hub.js +99 -5
- package/kits/hub-game/code/server/manifest.js +34 -7
- package/kits/hub-game/code/server/npcs.js +21 -33
- package/kits/hub-game/code/server/party.js +64 -6
- package/kits/hub-game/code/systems/hub.js +133 -16
- package/kits/hub-game/docs/contract.md +84 -14
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/test-grab-client.mjs +328 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +208 -0
- package/kits/hub-game/scripts/test-manifest.mjs +47 -1
- package/kits/hub-game/scripts/test-npcs.mjs +34 -24
- package/kits/hub-game/scripts/test-party.mjs +87 -4
- package/kits/hub-game/scripts/test-tiers.mjs +666 -0
- package/kits/hub-game/scripts/test-together.mjs +33 -1
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +92 -0
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
- package/kits/physics-3d/CLAUDE.md +279 -0
- package/kits/physics-3d/behaviors/Player.jsx +74 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +1 -1
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +465 -7
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
- package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
- package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
- package/kits/physics-3d/systems/physics3d.js +182 -3
- package/package.json +1 -1
|
@@ -201,6 +201,7 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
|
|
|
201
201
|
readResults(h);
|
|
202
202
|
arrivals(h);
|
|
203
203
|
enforceHolds(h);
|
|
204
|
+
enforceSettle(h);
|
|
204
205
|
Idle.tick(h);
|
|
205
206
|
enforceDuration(h);
|
|
206
207
|
catchFalls(h);
|
|
@@ -398,6 +399,8 @@ function newState(manifest) {
|
|
|
398
399
|
jumpAt: new Map(),
|
|
399
400
|
// playerId -> when they last asked where others are (`hub-where`)
|
|
400
401
|
whereAt: new Map(),
|
|
402
|
+
// playerId -> { at, facing, until }: bodies kept where a jump put them (`settle`)
|
|
403
|
+
settling: new Map(),
|
|
401
404
|
// `logStats`: when the window began, the CPU reading then, ticks since
|
|
402
405
|
stats: { at: null, cpu: null, ticks: 0 },
|
|
403
406
|
// playerId -> { avatar, clientAvatar, from, fromDeckId, party, carry, read,
|
|
@@ -426,7 +429,7 @@ function newState(manifest) {
|
|
|
426
429
|
// actorId -> { text, style, until }
|
|
427
430
|
labels: new Map(),
|
|
428
431
|
// playerId -> Map(actorId -> label): words over an actor for some players
|
|
429
|
-
// only (an NPC's reply to
|
|
432
|
+
// only (an NPC's reply to the player it answers), and what was last sent
|
|
430
433
|
labelsMe: new Map(),
|
|
431
434
|
sentLabelsMe: new Map(),
|
|
432
435
|
// playerId -> JSON of the avatars last sent to that player alone
|
|
@@ -556,6 +559,8 @@ function makeContext(h) {
|
|
|
556
559
|
go: (door, playerIds, options) => go(h, door, playerIds, options),
|
|
557
560
|
pad: (door, playerIds) => gather(h, door, playerIds),
|
|
558
561
|
coming: (door) => Party.coming(h, door),
|
|
562
|
+
// v1.16: the other members of a player's party who are in this place now.
|
|
563
|
+
partyOf: (playerId) => Party.matesHere(h, playerId),
|
|
559
564
|
board: (door) => h.boards.get(door) ?? null,
|
|
560
565
|
doors: () => doors(h),
|
|
561
566
|
send: (playerId, data) => h.session?.send(playerId, data),
|
|
@@ -680,6 +685,7 @@ function forget(h, playerId) {
|
|
|
680
685
|
h.shut.delete(playerId);
|
|
681
686
|
h.jumpAt.delete(playerId);
|
|
682
687
|
h.whereAt.delete(playerId);
|
|
688
|
+
h.settling.delete(playerId);
|
|
683
689
|
Grab.forget(h, playerId);
|
|
684
690
|
Idle.forget(h, playerId);
|
|
685
691
|
Cabinets.forget(h, playerId);
|
|
@@ -755,6 +761,9 @@ function arrivals(h) {
|
|
|
755
761
|
fromDeckId: entry.fromDeckId,
|
|
756
762
|
near: entry.near ?? null,
|
|
757
763
|
carry: entry.carry,
|
|
764
|
+
// How many went through the door together, by the client's word (the
|
|
765
|
+
// way back carries what the way out was sent with): 1 for anyone else.
|
|
766
|
+
party: entry.party ?? 1,
|
|
758
767
|
};
|
|
759
768
|
});
|
|
760
769
|
placeGroup(h, group.map((g) => g.playerId));
|
|
@@ -835,10 +844,14 @@ function placeBeside(h, playerId, otherId, used = new Map()) {
|
|
|
835
844
|
[Math.sin(f), Math.cos(f)],
|
|
836
845
|
];
|
|
837
846
|
const taken = used.get(otherId) ?? [];
|
|
838
|
-
|
|
847
|
+
// Never on or at the edge of a door's pad, theirs included (v1.19): a pad
|
|
848
|
+
// takes whoever stands on it into its game, and nobody goes into a game
|
|
849
|
+
// they did not choose. Beside a friend on a pad is a step or two further
|
|
850
|
+
// out, just off its edge and facing them, so joining them is that step.
|
|
851
|
+
for (const step of [1, 1.5, 2, 2.5, 3, 3.5]) {
|
|
839
852
|
const spot = dirs
|
|
840
853
|
.map(([dx, dz]) => ({ x: other.at.x + dx * NEAR_STEP_M * step, y: other.at.y, z: other.at.z + dz * NEAR_STEP_M * step }))
|
|
841
|
-
.find((at) => !taken.some((t) => Math.hypot(t.x - at.x, t.z - at.z) < 2 * BODY_RADIUS_M) && spotClear(h, at));
|
|
854
|
+
.find((at) => !taken.some((t) => Math.hypot(t.x - at.x, t.z - at.z) < 2 * BODY_RADIUS_M) && spotClear(h, at) && padAt(h, at, BODY_RADIUS_M) === null);
|
|
842
855
|
if (spot) {
|
|
843
856
|
taken.push(spot);
|
|
844
857
|
used.set(otherId, taken);
|
|
@@ -849,6 +862,19 @@ function placeBeside(h, playerId, otherId, used = new Map()) {
|
|
|
849
862
|
return false;
|
|
850
863
|
}
|
|
851
864
|
|
|
865
|
+
// The id of the pad actor a body at `at` stands on, or within `margin` of, or
|
|
866
|
+
// null. A pad takes a player whose middle is inside its radius.
|
|
867
|
+
function padAt(h, at, margin) {
|
|
868
|
+
for (const actor of h.actors) {
|
|
869
|
+
const pad = actor.components.HubPad;
|
|
870
|
+
const t = actor.components.Transform;
|
|
871
|
+
if (pad && t && !h.hidden.has(actor.id) && Math.hypot(at.x - t.x, at.z - t.z) <= (pad.radius ?? actor.components.Shape?.radius ?? 2.3) + margin) {
|
|
872
|
+
return actor.id;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
|
|
852
878
|
// Whether a standing body fits at `at`: no solid scene actor overlaps it, and
|
|
853
879
|
// on a scene with no ground (`fallY`) a solid's top is under its feet.
|
|
854
880
|
function spotClear(h, at) {
|
|
@@ -903,6 +929,38 @@ function placeAt(h, playerId, at, facing) {
|
|
|
903
929
|
body.body.setTranslation(body.at, true);
|
|
904
930
|
}
|
|
905
931
|
|
|
932
|
+
// After a jump (to a door's pad, beside a player) the body is kept where it
|
|
933
|
+
// was put for a moment. The client's move reports already on their way still
|
|
934
|
+
// name the spot it left, and the server's movement clamp lets each one pull
|
|
935
|
+
// the body a step back toward it: on a slow phone that dragged a player a
|
|
936
|
+
// metre or two off the pad they had just been put on, and the pad never
|
|
937
|
+
// counted them. This is not a hold (contract §8): the player is not in the
|
|
938
|
+
// `held` list, keeps what they carry and may jump again at once; the body is
|
|
939
|
+
// only put back each tick it drifts, until the client has caught up.
|
|
940
|
+
const SETTLE_MS = 600;
|
|
941
|
+
|
|
942
|
+
function settle(h, playerId) {
|
|
943
|
+
const body = h.sim?.players.get(playerId);
|
|
944
|
+
if (body) {
|
|
945
|
+
h.settling.set(playerId, { at: { ...body.at }, facing: body.facing, until: Date.now() + SETTLE_MS });
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
function enforceSettle(h) {
|
|
950
|
+
const nowMs = Date.now();
|
|
951
|
+
for (const [playerId, spot] of h.settling) {
|
|
952
|
+
const body = h.sim.players.get(playerId);
|
|
953
|
+
// Over, gone, or held by the place (a hold has its own spot).
|
|
954
|
+
if (!body || nowMs >= spot.until || h.held.has(playerId)) {
|
|
955
|
+
h.settling.delete(playerId);
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
if (Math.hypot(body.at.x - spot.at.x, body.at.z - spot.at.z) > HOLD_SLACK) {
|
|
959
|
+
placeAt(h, playerId, spot.at, spot.facing);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
906
964
|
// A held body that drifted is put back, every tick it drifts (contract §8).
|
|
907
965
|
function enforceHolds(h) {
|
|
908
966
|
for (const [playerId, hold] of h.held) {
|
|
@@ -1034,6 +1092,11 @@ function doorList(h) {
|
|
|
1034
1092
|
if (h.boards.get(door.id)?.featured === true) {
|
|
1035
1093
|
row.featured = true;
|
|
1036
1094
|
}
|
|
1095
|
+
// Whether someone can still be followed in: a game under way takes late
|
|
1096
|
+
// joiners only where its door says so.
|
|
1097
|
+
if (door.lateJoin === true) {
|
|
1098
|
+
row.late = true;
|
|
1099
|
+
}
|
|
1037
1100
|
if (door.maxPlayers === 1) {
|
|
1038
1101
|
row.solo = true;
|
|
1039
1102
|
} else if (door.minPlayers > 1) {
|
|
@@ -1061,9 +1124,10 @@ function doorJump(h, player, data) {
|
|
|
1061
1124
|
h.jumpAt.set(player.playerId, now);
|
|
1062
1125
|
// Onto the door's pad where it has one (v1.10), a little off its middle so
|
|
1063
1126
|
// two who jump there do not land in one spot; else in front of the door.
|
|
1064
|
-
const at = Party.padPoint(h, door, Math.floor(Math.random() * 6)) ?? frontOf(door);
|
|
1127
|
+
const at = Party.padPoint(h, door, Math.floor(Math.random() * 6), player.playerId) ?? frontOf(door);
|
|
1065
1128
|
const facing = ((door.t.rotationY ?? 0) + 180) * DEG;
|
|
1066
1129
|
placeAt(h, player.playerId, { x: at.x, y: 1.2, z: at.z }, facing);
|
|
1130
|
+
settle(h, player.playerId);
|
|
1067
1131
|
h.session?.send(player.playerId, { k: 'hub-jumped', facing });
|
|
1068
1132
|
}
|
|
1069
1133
|
|
|
@@ -1075,7 +1139,12 @@ function frontOf(door) {
|
|
|
1075
1139
|
|
|
1076
1140
|
// What `party.js` uses of this layer.
|
|
1077
1141
|
function partyDeps(h) {
|
|
1078
|
-
|
|
1142
|
+
// A party member put on a pad is settled there like any jump.
|
|
1143
|
+
const placeAndSettle = (state, playerId, at, facing) => {
|
|
1144
|
+
placeAt(state, playerId, at, facing);
|
|
1145
|
+
settle(state, playerId);
|
|
1146
|
+
};
|
|
1147
|
+
return { h, blockedPairs, usernameOf, placeAt: placeAndSettle, stand: Idle.stand, jumpDoors, front: frontOf };
|
|
1079
1148
|
}
|
|
1080
1149
|
|
|
1081
1150
|
// Where the players a client asks about are (the chrome's People list and its
|
|
@@ -1156,9 +1225,32 @@ function goTo(h, player, data) {
|
|
|
1156
1225
|
return;
|
|
1157
1226
|
}
|
|
1158
1227
|
h.jumpAt.set(playerId, now);
|
|
1228
|
+
settle(h, playerId);
|
|
1159
1229
|
h.session?.send(playerId, { k: 'hub-jumped', facing: h.sim.players.get(playerId).facing, to: otherId });
|
|
1160
1230
|
}
|
|
1161
1231
|
|
|
1232
|
+
// The players staying in a town are told who went through which door
|
|
1233
|
+
// (`hub-went`, v1.15), so a friend left behind can follow: each client shows
|
|
1234
|
+
// it only for its own friends and party. Never across a block, and not for a
|
|
1235
|
+
// cabinet (a classic deck is played alone).
|
|
1236
|
+
function tellWent(h, goingIds, door) {
|
|
1237
|
+
if (!h.sim || h.place.result || !goingIds.length) {
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
const going = new Set(goingIds);
|
|
1241
|
+
const pairs = blockedPairs(h);
|
|
1242
|
+
for (const [playerId, entry] of h.players) {
|
|
1243
|
+
if (!entry.arrived || going.has(playerId)) {
|
|
1244
|
+
continue;
|
|
1245
|
+
}
|
|
1246
|
+
const hidden = pairs?.get(playerId);
|
|
1247
|
+
const who = goingIds.filter((id) => !hidden?.has(id));
|
|
1248
|
+
if (who.length) {
|
|
1249
|
+
h.session?.send(playerId, { k: 'hub-went', players: who, door });
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1162
1254
|
function doors(h) {
|
|
1163
1255
|
const out = [];
|
|
1164
1256
|
for (const actor of h.actors) {
|
|
@@ -1276,6 +1368,7 @@ function go(h, door, playerIds, { instance } = {}) {
|
|
|
1276
1368
|
const prefix = deck ? `deck:${deck}/` : here;
|
|
1277
1369
|
const key =
|
|
1278
1370
|
typeof instance === 'string' && instance.startsWith(`${prefix}hub.${to}.`) ? instance : prefix + Place.devKey(to);
|
|
1371
|
+
tellWent(h, playerIds, door);
|
|
1279
1372
|
for (const playerId of playerIds) {
|
|
1280
1373
|
h.session?.send(playerId, {
|
|
1281
1374
|
k: 'hub-go',
|
|
@@ -1532,6 +1625,7 @@ function padFired(h, door, pad, users, fired) {
|
|
|
1532
1625
|
const group = Array.isArray(fired) ? fired : [];
|
|
1533
1626
|
// The group is ghost's; anyone of it still here goes, on the pad now or not.
|
|
1534
1627
|
const here = membersOf(h, h.session?.players.map((p) => p.playerId));
|
|
1628
|
+
tellWent(h, group.map((userId) => users.get(userId) ?? here.get(userId)).filter(Boolean), door);
|
|
1535
1629
|
for (const userId of group) {
|
|
1536
1630
|
const playerId = users.get(userId) ?? here.get(userId);
|
|
1537
1631
|
if (playerId) {
|
|
@@ -28,6 +28,14 @@ export const NEAREST_PLAYERS_CAP = 100;
|
|
|
28
28
|
// owned object's reported speed (40 m/s), so a throw is never cut short by it.
|
|
29
29
|
export const GRAB_DEFAULTS = { throwSpeed: 10, holdDistance: 1.4, holdHeight: 1.2 };
|
|
30
30
|
const GRAB_LIMITS = { throwSpeed: [1, 14, 'm/s'], holdDistance: [0.8, 3, 'metres'], holdHeight: [0, 2.5, 'metres'] };
|
|
31
|
+
// v1.22: a place may lengthen the reach at which an object is offered (from
|
|
32
|
+
// the object's near side, flat metres; 1.6 is the reach without it) and ask
|
|
33
|
+
// for a steady offer (`code/client/grab.js`). Neither has a default written
|
|
34
|
+
// into the place: a place that sets neither is sent what it always was. The
|
|
35
|
+
// top stays inside the server's GRAB_REACH (4 m, centre to centre), and the
|
|
36
|
+
// client also never offers an object whose centre is past 3 m.
|
|
37
|
+
export const GRAB_REACH_LIMITS = [1.6, 3, 'metres'];
|
|
38
|
+
const GRAB_KEYS = [...Object.keys(GRAB_DEFAULTS), 'reach', 'steady'];
|
|
31
39
|
// Idle play (v1.6, §6): emotes, seats and the place's own sounds. Sounds are
|
|
32
40
|
// files of the deck, listed so the server can refuse any other name.
|
|
33
41
|
export const IDLE_KEYS = ['emotes', 'seats', 'sounds'];
|
|
@@ -52,7 +60,9 @@ const PLACE_KEYS = [
|
|
|
52
60
|
'grab',
|
|
53
61
|
'idle',
|
|
54
62
|
];
|
|
55
|
-
|
|
63
|
+
// `tiers` is the deck's, not a place's: the client's picture on a slow device
|
|
64
|
+
// (v1.21, `code/client/tiers.js`). The server reads nothing of it.
|
|
65
|
+
const TOP_KEYS = ['contract', 'places', 'tiers', ...PLACE_KEYS];
|
|
56
66
|
|
|
57
67
|
const DEFAULT_SCENE = 'scenes/main.scene';
|
|
58
68
|
|
|
@@ -70,6 +80,9 @@ export function readManifest(castleJson, sceneExists = () => true) {
|
|
|
70
80
|
);
|
|
71
81
|
}
|
|
72
82
|
unknownKeys(hub, TOP_KEYS, 'hub', errors);
|
|
83
|
+
if (hub.tiers !== undefined && typeof hub.tiers !== 'boolean') {
|
|
84
|
+
errors.push('hub.tiers must be true or false.');
|
|
85
|
+
}
|
|
73
86
|
const defaultScene =
|
|
74
87
|
typeof castleJson?.editor?.defaultPlayFile === 'string' ? castleJson.editor.defaultPlayFile : DEFAULT_SCENE;
|
|
75
88
|
const serverMax = Number.isInteger(castleJson?.server?.maxPlayers) ? castleJson.server.maxPlayers : MAX_PLAYERS_CAP;
|
|
@@ -178,7 +191,8 @@ function readPlace(block, where, defaultScene, serverMax, sceneExists, errors, d
|
|
|
178
191
|
}
|
|
179
192
|
|
|
180
193
|
// `grab`: absent or false is none; true is the defaults; an object sets any of
|
|
181
|
-
// them.
|
|
194
|
+
// them, and may add `reach` and `steady` (v1.22), which are kept only when
|
|
195
|
+
// set: `steady: false` is the same as leaving it out.
|
|
182
196
|
function readGrab(value, where, errors) {
|
|
183
197
|
if (value === undefined || value === false) {
|
|
184
198
|
return null;
|
|
@@ -190,7 +204,7 @@ function readGrab(value, where, errors) {
|
|
|
190
204
|
errors.push(`${where} must be true, false or an object.`);
|
|
191
205
|
return null;
|
|
192
206
|
}
|
|
193
|
-
unknownKeys(value,
|
|
207
|
+
unknownKeys(value, GRAB_KEYS, where, errors);
|
|
194
208
|
const grab = { ...GRAB_DEFAULTS };
|
|
195
209
|
for (const [key, [min, max, unit]] of Object.entries(GRAB_LIMITS)) {
|
|
196
210
|
if (value[key] === undefined) {
|
|
@@ -202,6 +216,19 @@ function readGrab(value, where, errors) {
|
|
|
202
216
|
grab[key] = value[key];
|
|
203
217
|
}
|
|
204
218
|
}
|
|
219
|
+
if (value.reach !== undefined) {
|
|
220
|
+
const [min, max, unit] = GRAB_REACH_LIMITS;
|
|
221
|
+
if (typeof value.reach !== 'number' || !(value.reach >= min && value.reach <= max)) {
|
|
222
|
+
errors.push(`${where}.reach must be a number of ${unit} from ${min} to ${max}.`);
|
|
223
|
+
} else {
|
|
224
|
+
grab.reach = value.reach;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (value.steady !== undefined && typeof value.steady !== 'boolean') {
|
|
228
|
+
errors.push(`${where}.steady must be true or false.`);
|
|
229
|
+
} else if (value.steady === true) {
|
|
230
|
+
grab.steady = true;
|
|
231
|
+
}
|
|
205
232
|
return grab;
|
|
206
233
|
}
|
|
207
234
|
|
|
@@ -281,8 +308,8 @@ function readNpcs(value, destinations, bundle, where, errors) {
|
|
|
281
308
|
} else {
|
|
282
309
|
npcs.route = value.route;
|
|
283
310
|
}
|
|
284
|
-
// A place's server, not a client, decides who hears a turn
|
|
285
|
-
// a turn's audience only for a bundle that says so.
|
|
311
|
+
// A place's server, not a client, decides who hears a turn (nobody but its
|
|
312
|
+
// speaker): ghost admits a turn's audience only for a bundle that says so.
|
|
286
313
|
if (!isObject(bundle) || !Array.isArray(bundle.characters) || !bundle.characters.length) {
|
|
287
314
|
errors.push(`${where} needs a castle.json characterBundle with the characters its NPCs speak for.`);
|
|
288
315
|
} else if (bundle.conversation?.version !== 1 || bundle.conversation?.authority !== 'server') {
|
|
@@ -298,10 +325,10 @@ function readNpcs(value, destinations, bundle, where, errors) {
|
|
|
298
325
|
npcs.turnsPerMinute = intIn(value.turnsPerMinute, 6, 1, 30, `${where}.turnsPerMinute`, errors);
|
|
299
326
|
npcs.followSec = intIn(value.followSec, 120, 10, 600, `${where}.followSec`, errors);
|
|
300
327
|
if (value.disclosure !== undefined) {
|
|
328
|
+
// Read for decks that set it, and no longer acted on (v1.17): a player's
|
|
329
|
+
// conversation with a character is theirs alone, whatever this says.
|
|
301
330
|
if (value.disclosure !== 'participants' && value.disclosure !== 'world') {
|
|
302
331
|
errors.push(`${where}.disclosure must be "participants" or "world".`);
|
|
303
|
-
} else {
|
|
304
|
-
npcs.disclosure = value.disclosure;
|
|
305
332
|
}
|
|
306
333
|
}
|
|
307
334
|
return npcs;
|
|
@@ -12,8 +12,11 @@
|
|
|
12
12
|
// grant, inside a per-character budget per minute; anywhere
|
|
13
13
|
// else, or over budget, the place's `npcLine` hook answers with
|
|
14
14
|
// an authored line and no model is called
|
|
15
|
-
// speech a reply is drawn over the body for
|
|
16
|
-
//
|
|
15
|
+
// speech a reply is drawn over the body for the player it answers
|
|
16
|
+
// and nobody else: what a player says to a character, and what
|
|
17
|
+
// it says back, is theirs alone (it is kept in ghost as that
|
|
18
|
+
// player's own conversation, and no turn names a listener).
|
|
19
|
+
// An authored line is the place's own words, for everyone
|
|
17
20
|
//
|
|
18
21
|
// notes what the place knows right now that the character should
|
|
19
22
|
// (a quest-giver's ledger, a barker's pad), from the place's
|
|
@@ -31,9 +34,8 @@
|
|
|
31
34
|
// message can neither start nor aim it.
|
|
32
35
|
|
|
33
36
|
const TALK_RANGE_M = 3.5;
|
|
34
|
-
// A speaker
|
|
35
|
-
|
|
36
|
-
const HEAR_RANGE_M = 6;
|
|
37
|
+
// A speaker who walks this far from the body has left the conversation.
|
|
38
|
+
const LEAVE_RANGE_M = 8;
|
|
37
39
|
const WALK_MPS = 2.6;
|
|
38
40
|
const FOLLOW_GAP_M = 1.6;
|
|
39
41
|
const SPEECH_MS = 7000;
|
|
@@ -54,7 +56,6 @@ const TURNS_KEPT = 128;
|
|
|
54
56
|
// this long, to see whether the character chose to follow someone.
|
|
55
57
|
const FOLLOW_POLL_MS = 2000;
|
|
56
58
|
const FOLLOW_WATCH_MS = 60_000;
|
|
57
|
-
const LISTENERS_MAX = 7;
|
|
58
59
|
// The place's notes for a turn (`npcContext`): at most NOTES_MAX characters,
|
|
59
60
|
// read for the body's speaker every NOTES_EVERY_MS, and any of the last
|
|
60
61
|
// NOTES_KEPT issued within NOTES_KEEP_MS is accepted (the speaker's client
|
|
@@ -70,7 +71,7 @@ export const NOTES_SAYS = '\n[The speaker says]\n';
|
|
|
70
71
|
export function makeNpcs(h) {
|
|
71
72
|
const n = {
|
|
72
73
|
bodies: new Map(),
|
|
73
|
-
// `${playerId}:${operationId}` -> { npc,
|
|
74
|
+
// `${playerId}:${operationId}` -> { npc, speaker, at, delivered }
|
|
74
75
|
turns: new Map(),
|
|
75
76
|
// playerId -> durable participant id, from that player's own inspect read
|
|
76
77
|
participants: new Map(),
|
|
@@ -253,11 +254,6 @@ function say(h, npc, text, { to, ttlMs = SPEECH_MS, about } = {}) {
|
|
|
253
254
|
h.npcLabel(npc.id, line, { style: 'speech', ttlMs, to, about });
|
|
254
255
|
}
|
|
255
256
|
|
|
256
|
-
// Whether a block hides these two players from each other.
|
|
257
|
-
function hiddenPair(h, a, b) {
|
|
258
|
-
return Boolean(h.blockedPairs?.()?.get(a)?.has(b));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
257
|
function distanceTo(h, npc, playerId) {
|
|
262
258
|
const player = h.sim?.players.get(playerId);
|
|
263
259
|
if (!player) {
|
|
@@ -306,8 +302,10 @@ function open(h, n, playerId, npcId) {
|
|
|
306
302
|
mind,
|
|
307
303
|
character: mind ? npc.character : null,
|
|
308
304
|
name: npc.name,
|
|
309
|
-
hearRange
|
|
310
|
-
|
|
305
|
+
// A client from before v1.17 named the players within `hearRange` as a
|
|
306
|
+
// turn's listeners: zero has it name nobody.
|
|
307
|
+
hearRange: 0,
|
|
308
|
+
disclosure: 'participants',
|
|
311
309
|
});
|
|
312
310
|
npc.notes = null;
|
|
313
311
|
if (!mind) {
|
|
@@ -449,8 +447,10 @@ function authoredSay(h, n, playerId, npcId, text) {
|
|
|
449
447
|
}
|
|
450
448
|
|
|
451
449
|
// A turn the host granted: the kit admits it only for the player this body is
|
|
452
|
-
// talking to, standing near it, with
|
|
453
|
-
//
|
|
450
|
+
// talking to, standing near it, with no listener of any kind (ghost keeps a
|
|
451
|
+
// turn's words for everyone its audience names, so a listener would be handed
|
|
452
|
+
// the speaker's words), inside the character's budget. Anything else is
|
|
453
|
+
// refused before a model is called.
|
|
454
454
|
async function admitTurn(h, n, turn) {
|
|
455
455
|
const speaker = turn.speaker.playerId;
|
|
456
456
|
// Several bodies may share one character (the town's barkers): the one this
|
|
@@ -467,14 +467,7 @@ async function admitTurn(h, n, turn) {
|
|
|
467
467
|
return;
|
|
468
468
|
}
|
|
469
469
|
const audience = turn.audience;
|
|
470
|
-
if (
|
|
471
|
-
audience.disclosure !== npcs.disclosure ||
|
|
472
|
-
audience.characterIds.length ||
|
|
473
|
-
audience.players.length > LISTENERS_MAX ||
|
|
474
|
-
audience.players.some((p) => distanceTo(h, npc, p.playerId) > HEAR_RANGE_M) ||
|
|
475
|
-
// A listener a block hides from the speaker never hears their conversation.
|
|
476
|
-
audience.players.some((p) => hiddenPair(h, speaker, p.playerId))
|
|
477
|
-
) {
|
|
470
|
+
if (audience.disclosure !== 'participants' || audience.characterIds.length || audience.players.length) {
|
|
478
471
|
turn.reject('HUB_NPC_AUDIENCE');
|
|
479
472
|
return;
|
|
480
473
|
}
|
|
@@ -510,7 +503,6 @@ async function admitTurn(h, n, turn) {
|
|
|
510
503
|
key,
|
|
511
504
|
npc: npc.id,
|
|
512
505
|
speaker,
|
|
513
|
-
recipients: new Set([speaker, ...audience.players.map((p) => p.playerId)]),
|
|
514
506
|
at: h.sim.timeMs,
|
|
515
507
|
delivered: false,
|
|
516
508
|
};
|
|
@@ -561,7 +553,7 @@ function trimTurns(h, n) {
|
|
|
561
553
|
}
|
|
562
554
|
|
|
563
555
|
// A player's own read. A status read that carries their turn's finished reply
|
|
564
|
-
// is when
|
|
556
|
+
// is when they see it over the body, and only they do: the reply is ghost's
|
|
565
557
|
// canonical text, never a client's message.
|
|
566
558
|
async function routeRead(h, n, request) {
|
|
567
559
|
const type = request.query?.type;
|
|
@@ -593,12 +585,8 @@ async function routeRead(h, n, request) {
|
|
|
593
585
|
if (npc.pending === turn) {
|
|
594
586
|
npc.pending = null;
|
|
595
587
|
}
|
|
596
|
-
if (typeof result.response === 'string' && result.response.trim()) {
|
|
597
|
-
|
|
598
|
-
const to = [...turn.recipients].filter(
|
|
599
|
-
(playerId) => h.sim?.players.has(playerId) && !hiddenPair(h, turn.speaker, playerId),
|
|
600
|
-
);
|
|
601
|
-
say(h, npc, unquote(result.response), { to, about: turn.speaker });
|
|
588
|
+
if (typeof result.response === 'string' && result.response.trim() && h.sim?.players.has(turn.speaker)) {
|
|
589
|
+
say(h, npc, unquote(result.response), { to: [turn.speaker], about: turn.speaker });
|
|
602
590
|
}
|
|
603
591
|
// The reply may have come with the character's follow action.
|
|
604
592
|
n.watchUntil = h.sim.timeMs + FOLLOW_WATCH_MS;
|
|
@@ -664,7 +652,7 @@ function moveBody(h, n, npc, dt) {
|
|
|
664
652
|
if (npc.talking) {
|
|
665
653
|
const gone = !h.sim.players.has(npc.talking.playerId);
|
|
666
654
|
const idle = now - npc.talking.at > IDLE_END_MS;
|
|
667
|
-
const far = distanceTo(h, npc, npc.talking.playerId) >
|
|
655
|
+
const far = distanceTo(h, npc, npc.talking.playerId) > LEAVE_RANGE_M;
|
|
668
656
|
if (gone || idle || far) {
|
|
669
657
|
endTalk(h, n, npc.id, npc.talking.playerId, gone ? 'left' : idle ? 'idle' : 'far');
|
|
670
658
|
}
|
|
@@ -25,8 +25,16 @@ const RATE_BURST = 6;
|
|
|
25
25
|
const RATE_EVERY_MS = 1000;
|
|
26
26
|
// A member who left the layer (through a door) is kept this long.
|
|
27
27
|
const AWAY_MS = 30 * 60 * 1000;
|
|
28
|
-
// How far from a pad's middle party members are put, in a ring
|
|
29
|
-
|
|
28
|
+
// How far from a pad's middle party members are put, in a ring (at most half
|
|
29
|
+
// the pad's radius). Six spots round it are this far apart.
|
|
30
|
+
export const PAD_RING_M = 1.2;
|
|
31
|
+
// A spot on a pad is taken when an NPC or a player stands within this of it.
|
|
32
|
+
// More than two bodies' width (2 x 0.45 m): a player put down touching another
|
|
33
|
+
// is pushed apart by physics, and the one already there can slide off the pad
|
|
34
|
+
// and stop counting, so a pad that needs both never fires.
|
|
35
|
+
export const PAD_CLEAR_M = 1.1;
|
|
36
|
+
// A standing body's radius.
|
|
37
|
+
const BODY_RADIUS_M = 0.45;
|
|
30
38
|
|
|
31
39
|
const DEG = Math.PI / 180;
|
|
32
40
|
|
|
@@ -247,7 +255,7 @@ export function toPad(d, playerId, door, n) {
|
|
|
247
255
|
return false;
|
|
248
256
|
}
|
|
249
257
|
const facing = ((door.t.rotationY ?? 0) + 180) * DEG;
|
|
250
|
-
const at = padPoint(h, door, n) ?? d.front(door);
|
|
258
|
+
const at = padPoint(h, door, n, playerId) ?? d.front(door);
|
|
251
259
|
d.placeAt(h, playerId, { x: at.x, y: 1.2, z: at.z }, facing);
|
|
252
260
|
h.session?.send(playerId, { k: 'hub-jumped', facing });
|
|
253
261
|
return true;
|
|
@@ -255,15 +263,59 @@ export function toPad(d, playerId, door, n) {
|
|
|
255
263
|
|
|
256
264
|
// Where the `n`th player sent to a door stands: on its pad, a ring about the
|
|
257
265
|
// middle, or null for a door with no pad.
|
|
258
|
-
export function padPoint(h, door, n) {
|
|
266
|
+
export function padPoint(h, door, n, moverId = null) {
|
|
259
267
|
const pad = h.actors.find((a) => a.components.HubPad?.door === door.id && a.components.Transform && !h.hidden.has(a.id));
|
|
260
268
|
if (!pad) {
|
|
261
269
|
return null;
|
|
262
270
|
}
|
|
263
271
|
const t = pad.components.Transform;
|
|
264
272
|
const radius = Math.min(PAD_RING_M, (pad.components.HubPad.radius ?? pad.components.Shape?.radius ?? 2.3) * 0.5);
|
|
265
|
-
|
|
266
|
-
|
|
273
|
+
// The `n`th spot of the ring, or the next one round that nobody stands on:
|
|
274
|
+
// a body put down inside an NPC or another player is pushed out by physics,
|
|
275
|
+
// off the pad, and the pad then never counts them.
|
|
276
|
+
const taken = [];
|
|
277
|
+
for (const npc of h.npcs?.list?.() ?? []) {
|
|
278
|
+
if (npc?.at) {
|
|
279
|
+
taken.push(npc.at);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// The mover's own body is not in its way.
|
|
283
|
+
for (const [playerId, body] of h.sim?.players ?? []) {
|
|
284
|
+
if (playerId !== moverId && body?.at) {
|
|
285
|
+
taken.push(body.at);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const padRadius = pad.components.HubPad.radius ?? pad.components.Shape?.radius ?? 2.3;
|
|
289
|
+
// The ring first (from the `n`th spot round), then an outer ring between
|
|
290
|
+
// its spots where the pad is wide enough, then the middle; the first with
|
|
291
|
+
// PAD_CLEAR_M clear. When none is, the one with the most room.
|
|
292
|
+
const outer = Math.max(radius, padRadius - BODY_RADIUS_M - 0.1);
|
|
293
|
+
const ring = (r, i, turn = 0) => {
|
|
294
|
+
const angle = ((i + turn) * 2 * Math.PI) / 6 + (door.t.rotationY ?? 0) * DEG;
|
|
295
|
+
return { x: t.x + Math.sin(angle) * r, z: t.z + Math.cos(angle) * r };
|
|
296
|
+
};
|
|
297
|
+
const spots = [];
|
|
298
|
+
for (let i = 0; i < 6; i += 1) {
|
|
299
|
+
spots.push(ring(radius, n + i));
|
|
300
|
+
}
|
|
301
|
+
if (outer > radius + 0.3) {
|
|
302
|
+
for (let i = 0; i < 6; i += 1) {
|
|
303
|
+
spots.push(ring(outer, n + i, 0.5));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
spots.push({ x: t.x, z: t.z });
|
|
307
|
+
const room = (at) => Math.min(Infinity, ...taken.map((other) => Math.hypot(other.x - at.x, other.z - at.z)));
|
|
308
|
+
let best = null;
|
|
309
|
+
for (const at of spots) {
|
|
310
|
+
const r = room(at);
|
|
311
|
+
if (r >= PAD_CLEAR_M) {
|
|
312
|
+
return at;
|
|
313
|
+
}
|
|
314
|
+
if (!best || r > best.r) {
|
|
315
|
+
best = { at, r };
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return best.at;
|
|
267
319
|
}
|
|
268
320
|
|
|
269
321
|
// Each tick: what has run out goes, and each player in a town is told their
|
|
@@ -353,6 +405,12 @@ export function coming(h, doorId) {
|
|
|
353
405
|
return n;
|
|
354
406
|
}
|
|
355
407
|
|
|
408
|
+
// `hub.partyOf(playerId)`: the other members of their party who are here.
|
|
409
|
+
export function matesHere(h, playerId) {
|
|
410
|
+
const partyId = h.party.of.get(keyOf(h, playerId));
|
|
411
|
+
return partyId ? present(h, partyId).filter((id) => id !== playerId) : [];
|
|
412
|
+
}
|
|
413
|
+
|
|
356
414
|
// Whether two players here are in one party (Join goes to a party member).
|
|
357
415
|
export function together(h, a, b) {
|
|
358
416
|
const partyId = h.party.of.get(keyOf(h, a));
|