castle-web-cli 0.4.229 → 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/agent-prompts.d.ts +2 -0
- package/dist/agent-prompts.js +16 -8
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +21 -21
- package/dist/api.d.ts +28 -2
- package/dist/api.js +74 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +860 -3
- package/dist/castleJson.d.ts +44 -0
- package/dist/castleJson.js +131 -0
- package/dist/check.js +27 -1
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +25 -13
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +237 -46
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +141 -31
- package/dist/index.js +3 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +126 -9
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +142 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +99 -14
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/webSourceSync.d.ts +2 -0
- package/dist/webSourceSync.js +2 -0
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +406 -53
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +9 -0
- package/kits/base/sdk/castle.js +5 -0
- package/kits/base/sdk/commands.d.ts +223 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +45 -1
- package/kits/base/sdk/multiplayer.js +158 -8
- 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/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +42 -1
- package/kits/base/sdk/server/storage.d.ts +58 -4
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +36 -2
- package/kits/base/sdk/server/wrapper.js +92 -11
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +149 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1035 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +376 -0
- package/kits/hub-game/code/client/hookLayer.js +236 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +143 -0
- package/kits/hub-game/code/client/talk.js +233 -0
- package/kits/hub-game/code/client/tiers.js +480 -0
- package/kits/hub-game/code/client/together.js +440 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +248 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1998 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +554 -0
- package/kits/hub-game/code/server/npcs.js +733 -0
- package/kits/hub-game/code/server/party.js +439 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2347 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1209 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +328 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1518 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +270 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +724 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +369 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-tiers.mjs +666 -0
- package/kits/hub-game/scripts/test-together.mjs +215 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +117 -5
- 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 +285 -1
- package/kits/physics-3d/behaviors/Player.jsx +74 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -5
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- 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 +527 -5
- 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 +187 -5
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
// Grabbing and throwing a place's loose objects (contract §6, v1.3), the
|
|
2
|
+
// server's half. The hub client holds and throws: it already simulates any
|
|
3
|
+
// loose object near its player as that object's owner (multiplayer-3d), so a
|
|
4
|
+
// held object is one it keeps putting in front of the player, and a throw is
|
|
5
|
+
// the velocity it lets go with. The owner's reports are bounded by
|
|
6
|
+
// multiplayer-3d exactly as before. Here the place hears about it, and may
|
|
7
|
+
// refuse a grab or end a hold:
|
|
8
|
+
//
|
|
9
|
+
// { k: 'hub-grab', actor, op: 'grab' | 'throw' } client -> server
|
|
10
|
+
// { k: 'hub-grab-deny', actor } server -> that client
|
|
11
|
+
// { k: 'hub-drop' } server -> that client
|
|
12
|
+
//
|
|
13
|
+
// `h` is the hub layer's state: `place`, `actors`, `sim`, `hidden`, `held`,
|
|
14
|
+
// `hooks`, `ctx`, `session`, and `grabs`, `grabBudget`, `flying` from
|
|
15
|
+
// `newGrabState`. Every message is a client's word, so each is checked
|
|
16
|
+
// against the simulation and bounded per player.
|
|
17
|
+
|
|
18
|
+
// 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 (with a place's `grab.reach`
|
|
20
|
+
// or `grab.steady`, v1.22, never one whose centre is past 3.5 m), and the
|
|
21
|
+
// server's poses lag a moving player's.
|
|
22
|
+
export const GRAB_REACH = 4;
|
|
23
|
+
// A held object is in front of its player; a throw is told as it leaves the
|
|
24
|
+
// hand, from about multiplayer-3d's claim reach.
|
|
25
|
+
export const THROW_REACH = 6;
|
|
26
|
+
// hub-grab messages each player may send a second, with a burst.
|
|
27
|
+
export const GRAB_RATE = 4;
|
|
28
|
+
export const GRAB_BURST = 4;
|
|
29
|
+
// How long a thrown object may fly at the place's throw speed before the
|
|
30
|
+
// server's shove cap (multiplayer-3d `MAX_PUSHED_SPEED`, 4 m/s) applies to it
|
|
31
|
+
// again, and the speed below which it has landed.
|
|
32
|
+
export const FLIGHT_MS = 3000;
|
|
33
|
+
const LANDED_SPEED = 4;
|
|
34
|
+
|
|
35
|
+
export function newGrabState() {
|
|
36
|
+
return {
|
|
37
|
+
// playerId -> the actor id they hold, as far as the place knows
|
|
38
|
+
grabs: new Map(),
|
|
39
|
+
// playerId -> { tokens, at }
|
|
40
|
+
grabBudget: new Map(),
|
|
41
|
+
// actorId -> { until }: thrown objects in flight (their sim entry carries
|
|
42
|
+
// the flight's `speedCap` meanwhile)
|
|
43
|
+
flying: new Map(),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// A scene actor whose body multiplayer-3d hands to clients: authored with a
|
|
48
|
+
// dynamic Body, built as a claimable object, and not hidden by the place.
|
|
49
|
+
function looseObject(h, actorId) {
|
|
50
|
+
if (typeof actorId !== 'string' || actorId.length > 128 || h.hidden.has(actorId)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const actor = h.actors.find((a) => a.id === actorId);
|
|
54
|
+
if (actor?.components.Body?.type !== 'dynamic') {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const entry = h.sim?.objects?.get(actorId);
|
|
58
|
+
return entry?.claimable && entry.body ? entry : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function near(h, playerId, entry, reach) {
|
|
62
|
+
const at = h.sim.players.get(playerId)?.at;
|
|
63
|
+
const t = entry.body.translation();
|
|
64
|
+
return Boolean(at && t) && Math.hypot(at.x - t.x, at.y - t.y, at.z - t.z) <= reach;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// One token per message, refilled at GRAB_RATE a second of simulation time.
|
|
68
|
+
function spend(h, playerId) {
|
|
69
|
+
const now = h.sim.timeMs;
|
|
70
|
+
const budget = h.grabBudget.get(playerId) ?? { tokens: GRAB_BURST, at: now };
|
|
71
|
+
budget.tokens = Math.min(GRAB_BURST, budget.tokens + ((now - budget.at) / 1000) * GRAB_RATE);
|
|
72
|
+
budget.at = now;
|
|
73
|
+
h.grabBudget.set(playerId, budget);
|
|
74
|
+
if (budget.tokens < 1) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
budget.tokens -= 1;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function deny(h, playerId, actorId) {
|
|
82
|
+
h.session?.send(playerId, { k: 'hub-grab-deny', actor: actorId });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The place's `grab` hook. It refuses a grab by returning false; a hook that
|
|
86
|
+
// throws refuses it too, so a broken rule errs toward nothing moving.
|
|
87
|
+
function ask(h, playerId, actorId, op) {
|
|
88
|
+
if (typeof h.hooks.grab !== 'function') {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return h.hooks.grab(h.ctx, playerId, actorId, op) !== false;
|
|
93
|
+
} catch (err) {
|
|
94
|
+
console.warn(`[hub] grab hook failed: ${err?.message ?? err}`);
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// `{ k: 'hub-grab', actor, op }` from a client. A malformed message is
|
|
100
|
+
// dropped. A grab that is refused -- past the rate, not a loose object of the
|
|
101
|
+
// place, too far, not this player's to simulate, a held or departed player,
|
|
102
|
+
// or the place's hook said no -- is answered `hub-grab-deny`, and the client
|
|
103
|
+
// lets go. A throw of something the place does not know this player holds is
|
|
104
|
+
// dropped.
|
|
105
|
+
export function message(h, playerId, data) {
|
|
106
|
+
const op = data?.op;
|
|
107
|
+
if (
|
|
108
|
+
playerId === undefined ||
|
|
109
|
+
playerId === null ||
|
|
110
|
+
!h.place.grab ||
|
|
111
|
+
!h.sim ||
|
|
112
|
+
(op !== 'grab' && op !== 'throw') ||
|
|
113
|
+
typeof data.actor !== 'string' ||
|
|
114
|
+
data.actor.length > 128
|
|
115
|
+
) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const actorId = data.actor;
|
|
119
|
+
if (!spend(h, playerId)) {
|
|
120
|
+
if (op === 'grab') {
|
|
121
|
+
deny(h, playerId, actorId);
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const entry = looseObject(h, actorId);
|
|
126
|
+
const entered = h.players.get(playerId)?.arrived && !h.players.get(playerId)?.ended;
|
|
127
|
+
if (op === 'throw') {
|
|
128
|
+
if (h.grabs.get(playerId) !== actorId) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
h.grabs.delete(playerId);
|
|
132
|
+
// Still theirs, now: the object may have been handed to someone else, or
|
|
133
|
+
// the player held, since the place last looked.
|
|
134
|
+
if (entry && entry.owner === playerId && entered && !h.held.has(playerId) && near(h, playerId, entry, THROW_REACH)) {
|
|
135
|
+
fly(h, actorId, entry);
|
|
136
|
+
ask(h, playerId, actorId, 'throw');
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// The client offers only what multiplayer-3d has handed it, so the object
|
|
141
|
+
// is this player's on the server too.
|
|
142
|
+
if (
|
|
143
|
+
!entered ||
|
|
144
|
+
h.held.has(playerId) ||
|
|
145
|
+
entry?.owner !== playerId ||
|
|
146
|
+
!near(h, playerId, entry, GRAB_REACH)
|
|
147
|
+
) {
|
|
148
|
+
deny(h, playerId, actorId);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (!ask(h, playerId, actorId, 'grab')) {
|
|
152
|
+
deny(h, playerId, actorId);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// One hold per player, and one holder per object.
|
|
156
|
+
for (const [other, held] of h.grabs) {
|
|
157
|
+
if (held === actorId && other !== playerId) {
|
|
158
|
+
h.grabs.delete(other);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
h.grabs.set(playerId, actorId);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// A thrown object is not slowed to a shove's speed while it flies: until it
|
|
165
|
+
// lands, or FLIGHT_MS, it has its own cap instead. But never faster
|
|
166
|
+
// than the place's throw: the release a client reports is its own word, so
|
|
167
|
+
// the server holds the flight to `throwSpeed` (and a little slack) itself.
|
|
168
|
+
export const THROW_SLACK = 1.1;
|
|
169
|
+
|
|
170
|
+
function throwCap(h) {
|
|
171
|
+
return (h.place.grab?.throwSpeed ?? 10) * THROW_SLACK + 0.5;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// The flight's cap is multiplayer-3d's own per-object `speedCap`, which its
|
|
175
|
+
// world enforces after every physics step (contacts included); an older
|
|
176
|
+
// multiplayer-3d ignores it and holds the flight to a shove's speed.
|
|
177
|
+
function fly(h, actorId, entry) {
|
|
178
|
+
h.flying.set(actorId, { until: h.sim.timeMs + FLIGHT_MS });
|
|
179
|
+
entry.speedCap = throwCap(h);
|
|
180
|
+
capSpeed(entry.body, entry.speedCap);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function capSpeed(body, cap) {
|
|
184
|
+
const v = body?.linvel?.();
|
|
185
|
+
const speed = v ? Math.hypot(v.x, v.y, v.z) : 0;
|
|
186
|
+
if (speed > cap) {
|
|
187
|
+
const k = cap / speed;
|
|
188
|
+
body.setLinvel({ x: v.x * k, y: v.y * k, z: v.z * k }, true);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// `hub.drop(playerId?)`: whoever holds something lets go (default: everyone).
|
|
193
|
+
// Only players the place knows hold something are told. Returns how many.
|
|
194
|
+
export function drop(h, playerId) {
|
|
195
|
+
let n = 0;
|
|
196
|
+
for (const [holder, actorId] of [...h.grabs]) {
|
|
197
|
+
if (playerId !== undefined && holder !== playerId) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
h.grabs.delete(holder);
|
|
201
|
+
h.session?.send(holder, { k: 'hub-drop', actor: actorId });
|
|
202
|
+
n += 1;
|
|
203
|
+
}
|
|
204
|
+
return n;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Each tick: forget holds that are over (the object went to someone else or
|
|
208
|
+
// back to the server, the place hid it, the player is held or gone), and end
|
|
209
|
+
// flights that have landed or run out.
|
|
210
|
+
export function tick(h) {
|
|
211
|
+
for (const [playerId, actorId] of [...h.grabs]) {
|
|
212
|
+
const entry = looseObject(h, actorId);
|
|
213
|
+
if (
|
|
214
|
+
!entry ||
|
|
215
|
+
entry.owner !== playerId ||
|
|
216
|
+
h.held.has(playerId) ||
|
|
217
|
+
!h.sim.players.has(playerId)
|
|
218
|
+
) {
|
|
219
|
+
h.grabs.delete(playerId);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const [actorId, flight] of [...h.flying]) {
|
|
223
|
+
const entry = h.sim.objects?.get(actorId);
|
|
224
|
+
// In the server's hands, a flight is held to the place's throw however
|
|
225
|
+
// it was released or handed back.
|
|
226
|
+
if (entry && !entry.owner) {
|
|
227
|
+
capSpeed(entry.body, throwCap(h));
|
|
228
|
+
}
|
|
229
|
+
const v = entry && !entry.owner ? entry.body.linvel?.() : null;
|
|
230
|
+
const landed = v ? Math.hypot(v.x, v.y, v.z) <= LANDED_SPEED : false;
|
|
231
|
+
if (!entry || landed || h.sim.timeMs >= flight.until) {
|
|
232
|
+
if (entry) {
|
|
233
|
+
delete entry.speedCap;
|
|
234
|
+
}
|
|
235
|
+
h.flying.delete(actorId);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function forget(h, playerId) {
|
|
241
|
+
h.grabs.delete(playerId);
|
|
242
|
+
h.grabBudget.delete(playerId);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Who holds what, for the place: actor id or null.
|
|
246
|
+
export function holding(h, playerId) {
|
|
247
|
+
return h.grabs.get(playerId) ?? null;
|
|
248
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// What ghost holds of each player's hub results (contract §7, v1.5): their
|
|
2
|
+
// newest results across places and their record per place, read with the
|
|
3
|
+
// arrival read the kit already makes and refreshed once a minute for everyone
|
|
4
|
+
// here, so a place's deck code asks `hub.results(playerId)` rather than
|
|
5
|
+
// calling the host's results read itself. Only where the host has hub ops;
|
|
6
|
+
// null on the dev serve and for an anonymous player.
|
|
7
|
+
|
|
8
|
+
export const HISTORY_EVERY_MS = 60000;
|
|
9
|
+
const MAX_ROWS = 20;
|
|
10
|
+
const MAX_USERS = 24;
|
|
11
|
+
|
|
12
|
+
const str = (v, n) => (typeof v === 'string' ? v.slice(0, n) : null);
|
|
13
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
|
|
14
|
+
|
|
15
|
+
function cleanRow(r) {
|
|
16
|
+
return {
|
|
17
|
+
deckId: str(r?.deckId, 64),
|
|
18
|
+
place: str(r?.place, 32),
|
|
19
|
+
title: str(r?.title, 40),
|
|
20
|
+
outcome: ['win', 'lose', 'draw'].includes(r?.outcome) ? r.outcome : null,
|
|
21
|
+
score: num(r?.score),
|
|
22
|
+
unit: ['ms', 's', 'points'].includes(r?.unit) ? r.unit : null,
|
|
23
|
+
better: r?.better === 'higher' || r?.better === 'lower' ? r.better : null,
|
|
24
|
+
stats: r?.stats && typeof r.stats === 'object' && !Array.isArray(r.stats) ? { ...r.stats } : {},
|
|
25
|
+
at: str(r?.at, 40),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function cleanRecord(r) {
|
|
30
|
+
const o = r?.outcomes ?? {};
|
|
31
|
+
return {
|
|
32
|
+
deckId: str(r?.deckId, 64),
|
|
33
|
+
place: str(r?.place, 32),
|
|
34
|
+
title: str(r?.title, 40),
|
|
35
|
+
plays: num(r?.plays) ?? 0,
|
|
36
|
+
outcomes: { win: num(o.win) ?? 0, lose: num(o.lose) ?? 0, draw: num(o.draw) ?? 0 },
|
|
37
|
+
bestScore: num(r?.bestScore),
|
|
38
|
+
unit: ['ms', 's', 'points'].includes(r?.unit) ? r.unit : null,
|
|
39
|
+
better: r?.better === 'higher' || r?.better === 'lower' ? r.better : null,
|
|
40
|
+
winStreak: num(r?.winStreak) ?? 0,
|
|
41
|
+
lastOutcome: ['win', 'lose', 'draw'].includes(r?.lastOutcome) ? r.lastOutcome : null,
|
|
42
|
+
lastScore: num(r?.lastScore),
|
|
43
|
+
lastAt: str(r?.lastAt, 40),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// One player's read, as ghost answered it, kept on their entry -- unless a
|
|
48
|
+
// read that started later has already landed (the arrival read and a
|
|
49
|
+
// refresh can be in flight together).
|
|
50
|
+
export function take(h, playerId, read, startedAt = Date.now()) {
|
|
51
|
+
const entry = h.players.get(playerId);
|
|
52
|
+
if (!entry || !read || (entry.historyFrom ?? -Infinity) > startedAt) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
entry.historyFrom = startedAt;
|
|
56
|
+
entry.history = {
|
|
57
|
+
recent: (Array.isArray(read.recent) ? read.recent : []).slice(0, MAX_ROWS).map(cleanRow),
|
|
58
|
+
records: (Array.isArray(read.records) ? read.records : []).slice(0, MAX_ROWS).map(cleanRecord),
|
|
59
|
+
readAt: Date.now(),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Each tick where the host has hub ops: once a minute, one read for every
|
|
64
|
+
// arrived signed-in player here (up to MAX_USERS a read).
|
|
65
|
+
export function refresh(h, hub, membersOf, refused) {
|
|
66
|
+
const now = Date.now();
|
|
67
|
+
if (h.historyReading || now - (h.historyAt ?? 0) < HISTORY_EVERY_MS) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
h.historyAt = now;
|
|
71
|
+
const arrived = [...h.players].filter(([, e]) => e.arrived && !e.ended).map(([id]) => id);
|
|
72
|
+
const users = membersOf(h, arrived);
|
|
73
|
+
if (!users.size) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const ids = [...users.keys()].slice(0, MAX_USERS);
|
|
77
|
+
h.historyReading = true;
|
|
78
|
+
const startedAt = now;
|
|
79
|
+
hub
|
|
80
|
+
.readResults({ userIds: ids })
|
|
81
|
+
.then((read) => {
|
|
82
|
+
for (const userId of ids) {
|
|
83
|
+
take(h, users.get(userId), read?.players?.[userId], startedAt);
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
.catch((err) => refused(h, 'history', err))
|
|
87
|
+
.finally(() => {
|
|
88
|
+
h.historyReading = false;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// `hub.results(playerId)`: { recent, records, readAt } (copies), or null.
|
|
93
|
+
export function results(h, playerId) {
|
|
94
|
+
const history = h.players.get(playerId)?.history;
|
|
95
|
+
return history ? structuredClone(history) : null;
|
|
96
|
+
}
|