@wildshard/engine 0.1.18 → 0.1.19

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 (293) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/budgets/shard-size-baseline.json +10 -4
  3. package/index.html +6 -4
  4. package/lint/engine-sides.json +14 -0
  5. package/lint/ratchet.json +0 -68
  6. package/lint/ratchet.mjs +1 -4
  7. package/package.json +17 -15
  8. package/scripts/agent-sync.mjs +27 -8
  9. package/scripts/app-build/appCook.ts +8 -2
  10. package/scripts/app-build/catalogue.ts +10 -7
  11. package/scripts/app-build/gen.ts +22 -2
  12. package/scripts/app-build/isolation.d.mts +10 -0
  13. package/scripts/app-build/isolation.mjs +47 -0
  14. package/scripts/app-build/outputProducts.mjs +4 -0
  15. package/scripts/app-build/previousDeploy.d.mts +2 -0
  16. package/scripts/app-build/previousDeploy.mjs +10 -1
  17. package/scripts/app-build/serviceWorker.ts +10 -3
  18. package/scripts/app-build/splitOutput.mjs +4 -2
  19. package/scripts/app-build/standaloneOutput.d.mts +1 -1
  20. package/scripts/app-build/standaloneOutput.mjs +5 -3
  21. package/scripts/app-build/titlePreloads.d.mts +8 -0
  22. package/scripts/app-build/titlePreloads.mjs +69 -0
  23. package/scripts/app-build/worldMapAtlas.ts +10 -6
  24. package/scripts/app-build-pipeline.mjs +31 -3
  25. package/scripts/built-product.mjs +1 -1
  26. package/scripts/cell-mem-bench.mjs +81 -23
  27. package/scripts/check-custom-sections-zero.mjs +1 -1
  28. package/scripts/check-devserver.mjs +2 -0
  29. package/scripts/check-models.mjs +2 -0
  30. package/scripts/check-paths.allow.json +0 -115
  31. package/scripts/check-paths.mjs +2 -2
  32. package/scripts/check-platform-ratchets.mjs +2 -3
  33. package/scripts/chromium-keychain.d.mts +1 -1
  34. package/scripts/ci-static.sh +1 -1
  35. package/scripts/committed-fast-checks.mjs +0 -2
  36. package/scripts/content-sw-proof.mjs +2 -1
  37. package/scripts/cook-worker.mjs +9 -3
  38. package/scripts/cook.mjs +18 -5
  39. package/scripts/docs-inputs-proof.mjs +6 -6
  40. package/scripts/e7-voice-staging-proof.mjs +1 -1
  41. package/scripts/gate-related-tests.mjs +1 -1
  42. package/scripts/git-source-view.mjs +1 -1
  43. package/scripts/goldens/capture.mjs +17 -5
  44. package/scripts/grid-crossing-nightly.mjs +59 -0
  45. package/scripts/grid-crossing-qa.mjs +44 -0
  46. package/scripts/grid-crossing-ratchet.d.mts +6 -0
  47. package/scripts/grid-crossing-ratchet.mjs +52 -0
  48. package/scripts/grid-crossing-report.mjs +122 -0
  49. package/scripts/grid-crossing-stages.mjs +47 -0
  50. package/scripts/grid-crossing-tour.mjs +277 -0
  51. package/scripts/grid-crossing-walk-proof.mjs +124 -17
  52. package/scripts/host-ruler/roots.mjs +2 -2
  53. package/scripts/host-ruler.d.mts +91 -0
  54. package/scripts/host-ruler.mjs +565 -0
  55. package/scripts/live-prepush.py +3 -5
  56. package/scripts/loading-flow/benchmax.mjs +3 -1
  57. package/scripts/look-loop/test_look_loop.py +1 -38
  58. package/scripts/memory-proof.mjs +61 -6
  59. package/scripts/mmo-bots.mjs +8 -2
  60. package/scripts/net-lag-proof.mjs +219 -0
  61. package/scripts/night-market-kit-budget.mjs +2 -2
  62. package/scripts/offline-proof-rules.d.mts +2 -2
  63. package/scripts/offline-proof-rules.mjs +15 -4
  64. package/scripts/offline-proof.mjs +74 -13
  65. package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
  66. package/scripts/page-release/content.d.mts +9 -1
  67. package/scripts/page-release/content.mjs +131 -17
  68. package/scripts/page-release/flow.mjs +36 -10
  69. package/scripts/page-release/stamp-content.mjs +24 -0
  70. package/scripts/page-release.mjs +28 -6
  71. package/scripts/page-size.mjs +2 -1
  72. package/scripts/pin-packs.ts +1 -1
  73. package/scripts/pins.ts +4 -4
  74. package/scripts/precommit-checks.mjs +1 -7
  75. package/scripts/precommit-jobs.mjs +0 -1
  76. package/scripts/precommit-source.py +1 -9
  77. package/scripts/program-discovery.mjs +1 -1
  78. package/scripts/ring-cook.mjs +2 -1
  79. package/scripts/ring-step.ts +1 -1
  80. package/scripts/script-scenario-metrics.mjs +1 -1
  81. package/scripts/shard-output-content.d.mts +1 -1
  82. package/scripts/shard-output-content.mjs +2 -2
  83. package/scripts/shard-outputs.mjs +1 -1
  84. package/scripts/shard-public.mjs +1 -1
  85. package/scripts/shard-wire-meter.mjs +24 -9
  86. package/scripts/side-parity.mjs +4 -2
  87. package/scripts/standalone-smoke.mjs +8 -3
  88. package/scripts/tier-textures.mjs +22 -4
  89. package/scripts/tile-bake-report.mjs +1 -1
  90. package/scripts/tile-bakes.mjs +1 -1
  91. package/scripts/title-assets.generated.json +2 -0
  92. package/scripts/tsconfig.json +0 -2
  93. package/scripts/vendor/basisu/LICENSE +201 -0
  94. package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
  95. package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
  96. package/scripts/vitest-push-guards.config.ts +1 -1
  97. package/scripts/vps/harden-apply.sh +4 -1
  98. package/scripts/vps/harden-prometheus.sh +176 -0
  99. package/scripts/vps/harden.sh +16 -0
  100. package/scripts/vps/rebuild.sh +18 -0
  101. package/scripts/vps/wildshard-config +6 -2
  102. package/scripts/worker-client-play.mjs +6 -2
  103. package/scripts/worktree-reap.mjs +5 -5
  104. package/src/.oxlintrc.json +3 -182
  105. package/src/client/app/entry.ts +10 -2
  106. package/src/client/engine/boot/bootCache.ts +2 -2
  107. package/src/client/engine/boot/bootTrace.ts +12 -4
  108. package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
  109. package/src/client/engine/boot/clearDownloads.ts +5 -2
  110. package/src/client/engine/boot/contentRead.ts +11 -0
  111. package/src/client/engine/boot/gpuFiles.ts +4 -2
  112. package/src/client/engine/boot/lastEnd.ts +99 -12
  113. package/src/client/engine/boot/texturePack.ts +2 -2
  114. package/src/client/engine/net/netPlayer.ts +19 -2
  115. package/src/client/engine/net/otherPlayers.ts +55 -8
  116. package/src/client/engine/net/predictor.ts +33 -9
  117. package/src/client/engine/net/redial.ts +29 -6
  118. package/src/client/engine/pwa/cacheNames.ts +58 -1
  119. package/src/client/engine/pwa/sw.js +41 -11
  120. package/src/client/engine/render/dataLook.ts +152 -40
  121. package/src/client/engine/render/families/detail.ts +89 -0
  122. package/src/client/engine/render/families/pbr.ts +7 -1
  123. package/src/client/engine/render/look.ts +6 -0
  124. package/src/client/engine/render/lookLight.ts +103 -11
  125. package/src/client/engine/render/lookRender.ts +105 -0
  126. package/src/client/engine/saves/indexed.ts +2 -2
  127. package/src/client/engine/telemetry/browserErrors.ts +24 -3
  128. package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
  129. package/src/client/engine/ui/debugOptions.ts +1 -1
  130. package/src/client/engine/ui/lookLightOption.ts +10 -6
  131. package/src/client/engine/ui/namePrompt.ts +7 -0
  132. package/src/client/game/boot/audio.generated.ts +114 -114
  133. package/src/client/game/boot/bytes.generated.ts +118 -220
  134. package/src/client/game/boot/placedSpawn.ts +35 -0
  135. package/src/client/game/boot/spawnDownload.ts +25 -6
  136. package/src/client/game/boot/versions.generated.ts +7 -5
  137. package/src/client/game/devScene/hook.ts +291 -0
  138. package/src/client/game/grid/cellLoading.ts +12 -2
  139. package/src/client/game/grid/live.ts +112 -16
  140. package/src/client/game/grid/liveSession.ts +33 -2
  141. package/src/client/game/grid/mapAtlas.ts +18 -4
  142. package/src/client/game/grid/minimapBlend.ts +15 -5
  143. package/src/client/game/grid/oneWayIn.ts +5 -1
  144. package/src/client/game/grid/placedCells.ts +114 -12
  145. package/src/client/game/grid/placedContent.ts +85 -0
  146. package/src/client/game/grid/prefetch.ts +9 -1
  147. package/src/client/game/grid/productInputs.ts +3 -1
  148. package/src/client/game/grid/productLeases.ts +4 -1
  149. package/src/client/game/grid/products.ts +8 -4
  150. package/src/client/game/grid/roadLook.ts +24 -15
  151. package/src/client/game/grid/roadLookPlatform.ts +4 -2
  152. package/src/client/game/grid/roadResources.ts +24 -0
  153. package/src/client/game/grid/roadSign.worker.ts +4 -3
  154. package/src/client/game/grid/roadSignPaint.ts +16 -5
  155. package/src/client/game/grid/roadSignPreparation.ts +4 -3
  156. package/src/client/game/grid/roadSignScale.ts +8 -0
  157. package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
  158. package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
  159. package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
  160. package/src/client/game/grid/roadTileWriter.ts +2 -1
  161. package/src/client/game/grid/screenReports.ts +39 -0
  162. package/src/client/game/grid/session.ts +20 -4
  163. package/src/client/game/grid/softWallLook.ts +25 -8
  164. package/src/client/game/mainMenu.ts +6 -2
  165. package/src/client/game/plugin/context.ts +2 -1
  166. package/src/client/game/plugin/followedMovers.ts +7 -1
  167. package/src/client/game/quest/figures.ts +2 -0
  168. package/src/client/game/session/finish.ts +6 -0
  169. package/src/client/game/shardfile/assetCache.ts +4 -4
  170. package/src/client/game/shardfile/client.ts +4 -1
  171. package/src/client/game/shardfile/clientAssets.ts +9 -5
  172. package/src/client/game/shardfile/clientLibrary.ts +1 -1
  173. package/src/client/game/shardfile/clientWater.ts +51 -9
  174. package/src/client/game/shardfile/clientWorker.ts +19 -7
  175. package/src/client/game/shardfile/look.ts +8 -3
  176. package/src/client/game/shardfile/product.ts +34 -7
  177. package/src/client/game/shardfile/productChecks.ts +2 -2
  178. package/src/client/game/shardfile/productCost.ts +2 -2
  179. package/src/client/game/shardfile/readAsset.ts +2 -2
  180. package/src/client/game/shardfile/reflectingWater.ts +73 -0
  181. package/src/client/game/shardfile/seatGrace.ts +9 -0
  182. package/src/client/game/shardfile/skinPlayback.ts +1 -1
  183. package/src/client/game/systems/npc/figureRows.ts +9 -0
  184. package/src/client/host/online/doctor.ts +2 -0
  185. package/src/client/host/online/linkScreens.ts +30 -4
  186. package/src/client/host/standalone/shell.ts +4 -0
  187. package/src/cook/game/astc6Encode.ts +55 -0
  188. package/src/cook/game/astc6Wasm.ts +176 -0
  189. package/src/cook/game/cookJob.ts +30 -6
  190. package/src/cook/game/cookWorker.ts +38 -11
  191. package/src/cook/game/entryTotals.ts +51 -24
  192. package/src/cook/game/shardCook.ts +35 -7
  193. package/src/cook/game/spawnParts.ts +33 -8
  194. package/src/cook/game/tierTextures.ts +87 -14
  195. package/src/server/engine/ai/bossContenders.ts +27 -3
  196. package/src/server/engine/ai/phases.ts +1 -1
  197. package/src/server/engine/entities/creatureRefill.ts +9 -2
  198. package/src/server/engine/net/ledgerBook.ts +2 -0
  199. package/src/server/engine/net/room.ts +15 -0
  200. package/src/server/engine/sim/respawn.ts +8 -0
  201. package/src/server/game/boss/arenaRoomEntry.ts +5 -1
  202. package/src/server/game/boss/arenaRoomNative.ts +2 -0
  203. package/src/server/game/boss/native.ts +2 -1
  204. package/src/server/game/boss/nativeWake.ts +9 -5
  205. package/src/server/game/boss/openArenaNative.ts +2 -2
  206. package/src/server/game/boss/openArenaRoom.ts +3 -1
  207. package/src/server/game/grid/room.ts +44 -3
  208. package/src/server/game/grid/simulation.ts +23 -0
  209. package/src/server/game/population/mixedRoster.ts +11 -3
  210. package/src/server/game/population/nativeBake.ts +8 -3
  211. package/src/server/game/population/nativeReturns.ts +6 -3
  212. package/src/server/game/population/roster.ts +5 -3
  213. package/src/server/game/quest/eliteDrops.ts +15 -4
  214. package/src/server/game/quest/nativeChapter.ts +1 -1
  215. package/src/server/game/quest/nativeComposition.ts +5 -1
  216. package/src/server/game/riding/nativeTaming.ts +10 -6
  217. package/src/server/game/riding/wildRefill.ts +3 -2
  218. package/src/server/game/shardfile/bossRow.ts +4 -2
  219. package/src/server/game/shardfile/homeKeeper.ts +4 -2
  220. package/src/server/host/bake/headlessWorker.ts +1 -1
  221. package/src/server/host/dedicated/cellHost.ts +98 -16
  222. package/src/server/host/dedicated/cellProtocol.ts +16 -1
  223. package/src/server/host/dedicated/cellWorker.ts +8 -5
  224. package/src/server/host/dedicated/dedicatedRoom.ts +16 -6
  225. package/src/server/host/dedicated/gridCells.ts +15 -6
  226. package/src/server/host/dedicated/loopLag.ts +21 -0
  227. package/src/server/host/dedicated/main.ts +13 -5
  228. package/src/server/host/dedicated/packReader.ts +3 -3
  229. package/src/server/host/dedicated/placementFile.ts +3 -2
  230. package/src/server/host/dedicated/roadRoom.ts +34 -4
  231. package/src/server/host/dedicated/serverMetrics.ts +126 -0
  232. package/src/server/host/dedicated/socketPump.ts +21 -4
  233. package/src/server/host/dedicated/workerTable.ts +15 -4
  234. package/src/server/host/dedicated/world.ts +65 -7
  235. package/src/server/host/headless.ts +1 -1
  236. package/src/server/host/headlessRuntime.ts +1 -1
  237. package/src/server/host/standalone/roadWorld.ts +15 -3
  238. package/src/server/host/standalone/serverHost.ts +4 -1
  239. package/src/server/host/standalone/serverProduct.ts +41 -11
  240. package/src/shared/engine/ai/BossBrain.ts +8 -0
  241. package/src/shared/game/boss/wake.ts +6 -0
  242. package/src/shared/game/devColliders.ts +47 -0
  243. package/src/shared/game/eliteSystem.ts +8 -0
  244. package/src/shared/game/grid/allocator.ts +3 -0
  245. package/src/shared/game/grid/placementRows.ts +5 -2
  246. package/src/shared/game/plugin/bossRecord.ts +3 -2
  247. package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
  248. package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
  249. package/src/shared/game/shardfile/packReads.ts +28 -3
  250. package/src/shared/game/shardfile/serverPack.ts +9 -0
  251. package/src/shared/game/systems/looks/trampleField.ts +2 -0
  252. package/src/shared/host/formatJsonSchema.ts +2 -2
  253. package/src/tsconfig.json +1 -27
  254. package/lint/host-reviews.json +0 -14
  255. package/lint/listed-view-code.json +0 -13
  256. package/lint/platform-pending-users.json +0 -2520
  257. package/lint/platform-pending-users.md +0 -18
  258. package/scripts/cell-mem/metrics-preload.mjs +0 -65
  259. package/scripts/check-closed-components.d.mts +0 -7
  260. package/scripts/check-closed-components.mjs +0 -87
  261. package/scripts/g571-hosts.d.mts +0 -3
  262. package/scripts/g571-hosts.mjs +0 -54
  263. package/scripts/host-ruler/register-migrate.mjs +0 -242
  264. package/scripts/listed-view-code.d.mts +0 -7
  265. package/scripts/listed-view-code.mjs +0 -93
  266. package/scripts/look-loop/fit-lut.py +0 -142
  267. package/scripts/look-loop/palette-delta.py +0 -183
  268. package/scripts/look-loop/regions/driftwood-isle.json +0 -25
  269. package/scripts/look-loop/regions/far-reach.json +0 -225
  270. package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
  271. package/scripts/look-loop/regions/pine-hollow.json +0 -22
  272. package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
  273. package/scripts/platform-chargebacks.d.mts +0 -9
  274. package/scripts/platform-chargebacks.mjs +0 -135
  275. package/scripts/shard-component-spans.d.mts +0 -15
  276. package/scripts/shard-component-spans.mjs +0 -18
  277. package/scripts/shard-components.d.mts +0 -16
  278. package/scripts/shard-components.mjs +0 -363
  279. package/scripts/shard-platform-hosts.d.mts +0 -2
  280. package/scripts/shard-platform-hosts.mjs +0 -93
  281. package/scripts/shard-platform-sections.d.mts +0 -2
  282. package/scripts/shard-platform-sections.mjs +0 -9
  283. package/scripts/shard-platform.d.mts +0 -76
  284. package/scripts/shard-platform.mjs +0 -1072
  285. package/src/.oxfmtrc.json +0 -48
  286. package/src/scripts/ask-new.sh +0 -29
  287. package/src/scripts/asks.mjs +0 -142
  288. package/src/scripts/herdr-prompt.sh +0 -34
  289. package/src/scripts/herdr-question-open.sh +0 -67
  290. package/src/scripts/md-wrap.mjs +0 -229
  291. /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
  292. /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
  293. /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
@@ -226,6 +226,21 @@ export class NetRoom {
226
226
  this.remove(client);
227
227
  return to.adopt(client.transport, player, client.queue, { identity: client.identity, reader: client.reader, capabilities: client.capabilities ?? [] });
228
228
  }
229
+ /**
230
+ * GC15 (3): a player crossed into cell `toFrame` on another worker. Their client hears `travel` here, then this room lets it go with its
231
+ * link left open: the target room on the other worker hears the client's hello again and welcomes it (`travel`, `welcome`, full frame,
232
+ * as `handOff` does on one worker). False when there is nobody live to send.
233
+ */
234
+ handOut(id: number, toFrame: number): boolean {
235
+ const client = this.clients.find(entry => entry.id === id);
236
+ if (client?.state !== 'live') return false;
237
+ const tick = this.world.tick(), travel: NetEvent = { kind: 'travel', tick, from: this.world.cell(), to: toFrame };
238
+ client.transport.send('reliable', eventsMessage(tick, [travel]).buffer);
239
+ this.remove(client);
240
+ return true;
241
+ }
242
+ /** GC15 (3): a client whose hello this room heard again after a travel from another worker reads this room's receipts from the start, as an adopted one does (its hello's ledger was the first room's). */
243
+ travelled(id: number): void { const client = this.clients.find(entry => entry.id === id); if (client !== undefined) client.ledgerSeen = 0; }
229
244
  private adopt(transport: Transport, player: NetPlayer, queue: CommandQueue, said: { readonly identity: NetIdentity; readonly reader: WireClientReader | undefined; readonly capabilities: readonly number[] }): number | null {
230
245
  const id = this.join(transport, player, queue), client = this.clients.find(entry => entry.id === id), { identity } = said;
231
246
  if (client !== undefined) {
@@ -1,6 +1,14 @@
1
1
  import { LastPlace, type Feet, type LastPlaceSaved, type PlaceArea, type Stand } from '../../../shared/engine/quest/lastPlace';
2
2
  import type { PlayerHealth } from '../../../shared/engine/combat/health';
3
3
 
4
+ declare module '../../../client/engine/events/maps' {
5
+ interface EventMap {
6
+ /** SERVER-CELLS SC10 (J328): a grid cell's world takes no ticks while nobody is in it, and is never rebuilt. On its first seat after
7
+ * empty time the cell host says how long it slept, and what comes back on a clock (a beaten boss, a fallen creature, a lair) spends it. */
8
+ 'world.slept': { seconds: number };
9
+ }
10
+ }
11
+
4
12
  /** The page's death fade (ui/DeathFade: dark, then the fade back): no blow lands on the fallen until then. */
5
13
  export const FALL_FADE = 1.35;
6
14
  /** One player's record. A save holds a player only once they have one. */
@@ -75,7 +75,11 @@ export function installArenaEntry(host: SimHost, input: unknown, row: ArenaEntry
75
75
  spawnBody: () => spawn(`${row.id}.body`, row.body.kind, row.body.variant, room.origin.x, room.origin.z, 0),
76
76
  spawnAdd: (_index, ax, az, yaw) => spawn(`${row.id}.add.${String(adds++ % ADDS)}`, add.kind, add.variant, ax, az, yaw),
77
77
  retire: actor => { actor.hidden = true; }, find: id => body(id), seal, saved,
78
- persist: value => { if (value.defeated) host.flags.set(flag('defeated')); if (value.rewardTaken) host.flags.set(flag('paid')); },
78
+ // SC10 (J328): back to not beaten only when a served world's King stands again: the world's flags clear and the orb goes with them
79
+ persist: value => {
80
+ if (!value.defeated) { host.flags.clear(flag('defeated')); host.flags.clear(flag('paid')); orb = null; return; }
81
+ host.flags.set(flag('defeated')); if (value.rewardTaken) host.flags.set(flag('paid'));
82
+ },
79
83
  // a lone player earned it alone; a room's earners come from the book at the killing blow
80
84
  spawnReward: () => { if (!fight.bounty.room) fight.bounty.award([...host.players.keys()]); orb = orbAt; }, rewardPoint: () => orb });
81
85
  // J105: the orb on the pedestal is each earner's own, through the ledger, and it stands until the last of them has taken theirs.
@@ -126,6 +126,8 @@ export function installArenaRoom<A extends ArenaRoomBody>(host: SimHost, rows: A
126
126
  };
127
127
  host.onStep(`${rows.step}.brain`, dt => {
128
128
  if (portal !== undefined) for (const player of host.players.values()) through(player, portal, dt);
129
+ // SC10 (J328): a long-lived world forgets the doors of those who left (one who comes back starts outside, as a fresh world's would)
130
+ for (const id of doors.keys()) if (!host.players.has(id)) doors.delete(id);
129
131
  seal(); sand.advance(dt);
130
132
  const body = fight.body(); if (body === null || !body.alive) return;
131
133
  const foe = row.party.nearest(body.position).position, initial = rows.initialize;
@@ -165,7 +165,8 @@ export function installGroundBoss(host: SimHost, input: unknown, profile: unknow
165
165
  restoreRoamingFight(row, fight, value, actors);
166
166
  if (fight.body !== null) fight.body.hidden = hidden;
167
167
  },
168
- }, saved, persist: record.persist, rewardPoint: () => reward,
168
+ // SC10: a served world's boss standing again (its record back to not beaten) takes its untaken orb with it
169
+ }, saved, persist: value => { if (!value.defeated) reward = null; record.persist(value); }, rewardPoint: () => reward,
169
170
  spawnReward: () => { const at = itemPickupFloor(host.physics, fight.rewardPoint()); reward = { x: at.x, y: at.y + ITEM_PICKUP_HOVER + row.reward.hover, z: at.z }; } });
170
171
  const Reward = v.strictObject({ version: v.literal(1), point: v.nullable(v.strictObject({ x: finite, y: finite, z: finite })) });
171
172
  host.onStep(row.steps.reward, () => undefined, {
@@ -15,18 +15,22 @@ const Encounter = v.strictObject({ attempt: v.boolean(), waitForReturn: v.boolea
15
15
 
16
16
  /** Install from data. Spawn remains the existing AS director/roster command,
17
17
  * rather than an arbitrary callback lent to the encounter. */
18
- export function installWakeBoss(host: SimHost, input: unknown, placement: { pool: { x: number; z: number }; arena: number }): { encounter: WakeBossEncounter; publish: (event: string) => void } {
18
+ export function installWakeBoss(host: SimHost, input: unknown, placement: { pool: { x: number; z: number }; arena: number }, returned?: () => void): { encounter: WakeBossEncounter; publish: (event: string) => void } {
19
19
  const row = parseWakeEncounter(input), { pool, arena } = placement;
20
20
  const encounter = new WakeBossEncounter(row, pool);
21
21
  const body = () => Array.from(host.entities.values()).find(actor => actor.kind === row.kind) ?? null;
22
22
  // J104, J107: whom the fight deals with is the living player nearest the pool, so it runs while anyone is in the arena. Those
23
23
  // there when it wakes set its curves. A lone player runs the one-player encounter, unread.
24
24
  const near = (point: { readonly x: number; readonly z: number }): boolean => Math.hypot(point.x - pool.x, point.z - pool.z) < row.arena.radius;
25
- const party = new BossContenders(host.players, near, () => undefined);
26
- const contended = { get engaged() { return encounter.state === 'fight'; }, script: { respawnPoint: () => ({ pos: new Vector3(pool.x, 0, pool.z), yaw: 0 }) },
27
- disarm: () => undefined, arm: () => undefined, onPlayerDeath: () => false };
25
+ // SERVER-CELLS SC10 (J328): a grid cell's world is never rebuilt, so a served world's won fight stands again once nobody has stood
26
+ // in the arena five minutes: the world's death flag cleared and the body gone (`returned`), so the next wake cue starts it afresh.
27
+ const party = new BossContenders(host.players, near, () => undefined, { served: () => host.respawn.served, rearm: false });
28
+ const contended = { get engaged() { return encounter.state === 'fight'; }, get state() { return encounter.state; }, script: { respawnPoint: () => ({ pos: new Vector3(pool.x, 0, pool.z), yaw: 0 }) },
29
+ disarm: () => undefined, arm: () => undefined, onPlayerDeath: () => false,
30
+ returnBeaten: () => { host.flags.clear(row.deadFlag); returned?.(); encounter.returnBeaten(); } };
28
31
  const observation = (): WakeBossObservation => ({ player: nearestOnGround(host.players, pool.x, pool.z).position, animal: body(), wake: host.flags.has(row.wakeFlag), dead: host.flags.has(row.deadFlag) });
29
32
  const flush = (): void => { for (const effect of encounter.takeEffects()) if (effect.kind === 'outcome') host.events.emit('boss.attempt', { boss: row.id, level: row.level, outcome: effect.outcome }); };
33
+ host.events.on('world.slept', ({ seconds }) => { party.slept(seconds); }, host.scope);
30
34
  host.events.on('damage.dealt', ({ req, killed }) => {
31
35
  const actor = body(); if (killed && actor !== null && req.target === actor.combatActor()) host.flags.set(row.deadFlag);
32
36
  }, host.scope);
@@ -37,7 +41,7 @@ export function installWakeBoss(host: SimHost, input: unknown, placement: { pool
37
41
  for (const [id, player] of host.players) if (id !== actor.id && player.health.alive && near(player.position)) return;
38
42
  encounter.onPlayerDeath(host.players.get(actor.id)?.position ?? host.playerFocus); flush();
39
43
  }, host.scope);
40
- host.onStep(row.step, () => { party.observe(contended); encounter.update(observation()); flush(); }, {
44
+ host.onStep(row.step, dt => { party.observe(contended, dt); encounter.update(observation()); flush(); }, {
41
45
  snapshot: () => { const { engaged } = party; return JSON.stringify({ ...encounter.encounterSnapshot(), ...(engaged === 0 ? {} : { engaged }) }); },
42
46
  restore: value => { const saved = v.parse(Encounter, JSON.parse(v.parse(v.string(), value))); encounter.encounterRestore(saved); party.restoreEngaged(saved.engaged ?? 0); },
43
47
  });
@@ -128,7 +128,7 @@ export async function prepareOpenArena(product: Pick<ShardProduct, 'json' | 'sec
128
128
  easeViewToward(weapons().of(near).look,camera.position,target,dt);},spawnReward:()=>{
129
129
  room.heartFell();
130
130
  const at=itemPickupFloor(host.physics,fight.rewardPoint());rewardPoint=new Vector3(at.x,at.y+ITEM_PICKUP_HOVER+.5,at.z);reward=true;
131
- },persist:saved=>{records.bosses.write({...records.bosses.read(),[data.definition.id]:saved});},toast,feed},ui,current);
131
+ },persist:saved=>{if(!saved.defeated){reward=false;rewardPoint=null;}/* SC10: the heart stands again, its untaken orb goes */records.bosses.write({...records.bosses.read(),[data.definition.id]:saved});},toast,feed},ui,current);
132
132
  encounter.boss=boss;room.bind(boss,fight,()=>rewardPoint);first.health.checkpoint(host.scope,()=>room.party.died(boss));
133
133
  const boundaryPorts={boss,fight,prompt,get player(){return room.near.position;},toast,
134
134
  wall:()=>{hit('wall',room.near.position,data.view.wallDamage,data.lines.wall);},clear:()=>{actual.storm.weather.force(data.weather.clearing);},
@@ -154,7 +154,7 @@ export async function prepareOpenArena(product: Pick<ShardProduct, 'json' | 'sec
154
154
  if(pickPrompt([prompt],eye,host.physics)===prompt)
155
155
  arenaTie(fight.life,{engaged:boss.engaged,victory:boss.state==='victory',hit:reward,mounted:room.mounted(),storm:actual.storm.stormActive},data.tieLines,{boss,fight,toast:line=>{toast(line);sayFightView(host,arenaTieWord(data.definition.id),[data.tieLines.indexOf(line)]);}});
156
156
  }
157
- room.party.observe(boss);
157
+ room.party.observe(boss,dt);
158
158
  if(boss.state!=='dormant'||fight.body.visible)boss.update(dt,host.clock.now);else fight.update(dt,host.clock.now,false);
159
159
  const answer=fight.takeBoundary();if(answer!==null)arenaBoundary(answer,data.lines,data.record,boundaryPorts);
160
160
  sayLooks(dt);
@@ -32,8 +32,10 @@ export class OpenArenaRoom {
32
32
  const { center } = data.arena, radius = data.place.arenaRadius; this.centre = new Vector3(center.x, 0, center.z); this.tag = `boss.${data.record.kind}`;
33
33
  for (const [name, row] of Object.entries(data.contacts)) this.rows.set(name, strikeFromData(row));
34
34
  const inside = (point: { readonly x: number; readonly z: number }): boolean => (point.x - center.x) ** 2 + (point.z - center.z) ** 2 < radius ** 2;
35
- this.party = new BossContenders(host.players, inside, place);
35
+ // SC5 (J328): a served world's beaten heart stands again once the arena has stood empty; its prompt starts the next fight.
36
+ this.party = new BossContenders(host.players, inside, place, { served: () => host.respawn.served, rearm: false });
36
37
  this.bounty = new BossBounty(host, () => null, data.definition.id); this.inside = inside;
38
+ host.events.on('world.slept', ({ seconds }) => { this.party.slept(seconds); }, host.scope);
37
39
  }
38
40
  private readonly inside: (point: { readonly x: number; readonly z: number }) => boolean;
39
41
  /** The heart has fallen: name who earned it. Alone there is no one to name. */
@@ -4,6 +4,12 @@ import type { GridAssembly, GridPoint } from '../../../shared/game/grid/assembly
4
4
  import { installGridCrossing, type GridCrossingSession } from '../../../shared/game/grid/crossing';
5
5
  import type { GridSimulation } from './simulation';
6
6
  import type { GridLoadout } from '../../../shared/game/grid/wallet';
7
+ import { CHUNK_HALF } from '@wildshard/engine/core/config';
8
+
9
+ /** How far from a cell's edge a player on the road has its world opened (the road between two cells is 62.5 m). */
10
+ const WARM_ROAD_METRES = 55;
11
+ /** The least a tick's move toward it counts as heading there (a walk is 0.07 m a tick); a capsule settling is not. */
12
+ const WARM_STEP_METRES = 0.02;
7
13
 
8
14
  /** A player's completed hand-off: the `travel` a client's view follows (E5-REPLICATION §6.3.4). */
9
15
  export interface GridTravel { readonly player: string; readonly from: string | null; readonly to: string | null }
@@ -22,6 +28,12 @@ export class GridRoom {
22
28
  private readonly crossings = new Map<string, { readonly session: GridCrossingSession; readonly scope: Scope }>();
23
29
  private readonly travels: GridTravel[] = [];
24
30
  private readonly scope = new Scope('grid-room');
31
+ /** each player's last cell left for the road, and the cells opened ahead of them on this stretch of road (GC5): each at
32
+ * most once a stretch, so two players on the road never evict each other's cell tick after tick, and a failed open is not
33
+ * retried every tick (the crossing still prepares it at the line and reports a failure) */
34
+ private readonly departed = new Map<string, string>();
35
+ private readonly opened = new Map<string, Set<string>>();
36
+ private readonly feet = new Map<string, { x: number; z: number }>();
25
37
  constructor(grid: GridSimulation, assembly: GridAssembly, ports: GridRoomPorts) {
26
38
  this.grid = grid; this.assembly = assembly; this.ports = ports;
27
39
  for (const player of grid.players()) this.watch(player);
@@ -30,7 +42,7 @@ export class GridRoom {
30
42
  const { grid } = this, scope = this.scope.child(`crossing:${player}`);
31
43
  const session = installGridCrossing({ current: () => grid.current(player), prepare: (from, to) => grid.prepare(from, to, player), ready: instance => grid.ready(instance),
32
44
  checkpoint: instance => grid.checkpoint(instance), target: feet => grid.target(feet, player) }, this.assembly, instance => this.ports.loadout(player, instance), scope,
33
- (from, to) => { this.travels.push({ player, from, to }); });
45
+ (from, to) => { this.travels.push({ player, from, to }); if (from !== null) this.departed.set(player, from); });
34
46
  this.crossings.set(player, { session, scope });
35
47
  }
36
48
  /** Another player comes onto the highway at `at`, world coordinates, or into the world at `site`, in its own. */
@@ -39,11 +51,40 @@ export class GridRoom {
39
51
  leave(player: string): boolean {
40
52
  const crossing = this.crossings.get(player);
41
53
  if (crossing === undefined || !this.grid.leave(player)) return false;
42
- crossing.scope.dispose(); this.crossings.delete(player);
54
+ crossing.scope.dispose(); this.crossings.delete(player); this.departed.delete(player); this.feet.delete(player); this.opened.delete(player);
43
55
  return true;
44
56
  }
45
57
  /** Everyone's own crossing, once per fixed tick, before any world steps. */
46
- cross(): void { for (const [player, { session }] of this.crossings) session.step(this.grid.worldFeet(player)); }
58
+ cross(): void {
59
+ for (const [player, { session }] of this.crossings) {
60
+ const feet = this.grid.worldFeet(player);
61
+ this.warm(player, feet);
62
+ session.step(feet);
63
+ }
64
+ }
65
+ /** GC5 (preview's in-page server, J311): a player on the road has the nearest cell ahead opened before they reach its line,
66
+ * as the page builds its own: opened only at the 6 m line, a cell's world held them at its wall for its whole load. The
67
+ * cell they left is not ahead. A failed open stays the crossing's to report. */
68
+ private warm(player: string, feet: Readonly<GridPoint>): void {
69
+ const previous = this.feet.get(player);
70
+ this.feet.set(player, { x: feet.x, z: feet.z });
71
+ if (this.grid.current(player) !== null) { this.opened.delete(player); return; }
72
+ if (previous === undefined) return;
73
+ const left = this.departed.get(player), edge = (p: Readonly<{ x: number; z: number }>, cell: { readonly origin: GridPoint }): number =>
74
+ Math.max(Math.abs(p.x - cell.origin.x), Math.abs(p.z - cell.origin.z)) - CHUNK_HALF;
75
+ let best: string | undefined, bestDistance = WARM_ROAD_METRES;
76
+ for (const cell of this.assembly.cells) {
77
+ // only a cell they draw nearer to: not one behind them, nor the one they left
78
+ const distance = edge(feet, cell);
79
+ if (cell.instance === left || distance > bestDistance || distance > edge(previous, cell) - WARM_STEP_METRES) continue;
80
+ best = cell.instance; bestDistance = distance;
81
+ }
82
+ if (best === undefined || this.grid.ready(best)) return;
83
+ const opened = this.opened.get(player) ?? new Set<string>();
84
+ if (opened.has(best)) return;
85
+ opened.add(best); this.opened.set(player, opened);
86
+ void this.grid.prefetch([best]).catch(() => undefined);
87
+ }
47
88
  /** One fixed tick: everyone's own crossing, then every occupied world. */
48
89
  step(commands?: ReadonlyMap<string, SimTickCommand>): void { this.cross(); this.grid.stepAll(commands); }
49
90
  /** Every hand-off since the last call. */
@@ -50,6 +50,29 @@ interface Resident { value: GridResident; touched: number; reservations: number;
50
50
  * board, swim) they had, so a walk across the line never stops (it started from rest: RP1's ~0.3 s stop at x -260 while the page
51
51
  * caught it up), and an owner's seat parked in that cell never mixes the new speed with the mode it was left in. The dedicated server's
52
52
  * handover (`CrossTarget.admit`) carries the same. */
53
+ /**
54
+ * GC15 (3): a walker's motion as plain data, for a crossing onto another worker (a message between threads carries no class), and
55
+ * `applyMotion` puts it on the arrival body as `carryMotion` does on one worker. A swim's climb target stays behind.
56
+ */
57
+ export interface MotionSnapshot {
58
+ readonly board: { readonly on: boolean; readonly hoverAir: PlayerSim['board']['hoverAir']; readonly hoverBob: PlayerSim['board']['hoverBob'] };
59
+ readonly swim: Omit<PlayerSim['swim'], 'climbTo'>; readonly footing: PlayerSim['footing']; readonly moveScale: number;
60
+ readonly velocity: { readonly x: number; readonly y: number; readonly z: number }; readonly impulse: { readonly x: number; readonly y: number; readonly z: number };
61
+ readonly grounded: boolean; readonly shove: PlayerSim['shove']; readonly dash: PlayerSim['dash']; readonly dodge: PlayerSim['dodge']; readonly jump: PlayerSim['jump'];
62
+ }
63
+ export function motionOf(from: PlayerSim): MotionSnapshot {
64
+ const { climbTo: _climb, ...swim } = from.swim;
65
+ return { board: { on: from.board.on, hoverAir: from.board.hoverAir, hoverBob: from.board.hoverBob }, swim: { ...swim }, footing: { ...from.footing }, moveScale: from.moveScale,
66
+ velocity: { x: from.velocity.x, y: from.velocity.y, z: from.velocity.z }, impulse: { x: from.impulse.x, y: from.impulse.y, z: from.impulse.z }, grounded: from.fall.grounded,
67
+ shove: { ...from.shove }, dash: { ...from.dash }, dodge: { ...from.dodge }, jump: { ...from.jump } };
68
+ }
69
+ export function applyMotion(from: MotionSnapshot, to: PlayerSim): void {
70
+ if (to.board.on !== from.board.on) to.setBoard(from.board.on);
71
+ to.board.hoverAir = from.board.hoverAir; to.board.hoverBob = from.board.hoverBob;
72
+ Object.assign(to.swim, from.swim); Object.assign(to.footing, from.footing); to.moveScale = from.moveScale;
73
+ to.velocity.set(from.velocity.x, from.velocity.y, from.velocity.z); to.impulse.set(from.impulse.x, from.impulse.y, from.impulse.z); to.fall.grounded = from.grounded;
74
+ Object.assign(to.shove, from.shove); Object.assign(to.dash, from.dash); Object.assign(to.dodge, from.dodge); Object.assign(to.jump, from.jump);
75
+ }
53
76
  export function carryMotion(from: PlayerSim, to: PlayerSim): void {
54
77
  if (to.board.on !== from.board.on) to.setBoard(from.board.on);
55
78
  to.board.hoverAir = from.board.hoverAir; to.board.hoverBob = from.board.hoverBob;
@@ -89,7 +89,7 @@ export function mixedPopulation(host: SimHost, id: string): ReturnType<typeof in
89
89
  * The v8 continuation retains per-body policies, poses, ids and native handles. */
90
90
  export function installMixedPopulation(host: SimHost, ports: MixedPopulationInput, saved?: Readonly<Omit<SimSnapshot, 'physics'>>): {
91
91
  bodies: () => readonly MixedPopulationBody[]; hunt: ReturnType<typeof createNativeHunt>['hunt'];
92
- captain: () => HuntBody | null; spawnCaptain: () => HuntBody; alarm: () => void;
92
+ captain: () => HuntBody | null; spawnCaptain: () => HuntBody; retireCaptain: () => void; alarm: () => void;
93
93
  staggered: (actor: AnimalSim, strength: number, running: boolean) => void;
94
94
  settle: () => void; publishPoses: () => void;
95
95
  } {
@@ -222,7 +222,9 @@ export function installMixedPopulation(host: SimHost, ports: MixedPopulationInpu
222
222
 
223
223
  const first = roster.bodies[0]; if (first === undefined) throw new Error('Empty mixed population roster');
224
224
  const extra = Array.from({ length: ROSTER - BODY_COUNT - 1 }, () => enemyBody('', first.kind, first.variant, -1, { x: 0, z: 0 }, 0));
225
- const returns = intake.returns(roster.ecology);
225
+ // SC10: the captain is the wake fight's, which brings him back itself; owed as a roster body he would return with no scale row and
226
+ // throw in the tick (a served world owes every kind since SC5).
227
+ const returns = intake.returns(roster.ecology, id => captain?.id === id);
226
228
  /** A slot a retired body left. Boot slots stay their row's: a continuation rebuilds those from the rows, not the save. */
227
229
  const vacated = (): number => { for (let i = BODY_COUNT; i < bodies.length; i++) if (bodies[i]?.actor === null) return i; return -1; };
228
230
  const retireFallen = (id: string): void => { const fallen = intake.retireDead(id); if (fallen !== null) fallen.brain = null; };
@@ -310,6 +312,12 @@ export function installMixedPopulation(host: SimHost, ports: MixedPopulationInpu
310
312
  if (body.actor === null) throw new Error('The Mixed population captain did not spawn');
311
313
  return body.actor;
312
314
  };
315
+ /** SERVER-CELLS SC10 (J328): a served world's beaten captain leaves, so the next wake cue spawns him afresh, as a fresh world would. */
316
+ const retireCaptain = (): void => {
317
+ if (captain === null) return;
318
+ if (captain.actor !== null) intake.retire(captain);
319
+ captain = null; sight[BODY_COUNT] = null;
320
+ };
313
321
  const alarm = (): void => {
314
322
  for (let i = 0; i < Math.min(ROSTER, bodies.length); i++) { const body = bodies[i], a = body?.actor ?? null; if (a !== null && a.alive && (a.aggressive || hunt.sensed(a))) wake(body); }
315
323
  };
@@ -325,7 +333,7 @@ export function installMixedPopulation(host: SimHost, ports: MixedPopulationInpu
325
333
  if (book.has(rows.step)) throw new Error('Duplicate mixed population');
326
334
  book.set(rows.step, value); populations.set(host, book); host.scope.onDispose(() => { book.delete(rows.step); }); return value;
327
335
  };
328
- const population = { publishPoses, bodies: () => bodies, hunt, captain: () => captain?.actor ?? null, spawnCaptain, alarm, staggered };
336
+ const population = { publishPoses, bodies: () => bodies, hunt, captain: () => captain?.actor ?? null, spawnCaptain, retireCaptain, alarm, staggered };
329
337
  if (saved === undefined) { keep(); return publish({ ...population, settle: () => undefined }); }
330
338
 
331
339
  const keeper = v.parse(Saved, saved.adapters.find(adapter => adapter.id === ISLAND_STEP)?.state);
@@ -103,9 +103,14 @@ export function installNativeCollision(host:Pick<SimHost,'physics'|'scope'|'onSt
103
103
  if(omitted(solid))continue;
104
104
  // A world held near its player is a grid cell, whose edge is the platform's (`gridLevel`): a shard's own page walls don't stand there.
105
105
  if(near!==null&&solid.material==='edge')continue;
106
- const owner=policy===undefined?solid.owner??null:solid.ownerId===undefined?null:owners.get(solid.ownerId);
107
- // A hull or mesh is most of a Rapier heap; a declared owner's solid stays, since a script may look it up.
108
- if(near!==null&&typeof owner!=='string'&&solid.enabled!==false&&(solid.shape===9||solid.shape===6)&&solid.points!==undefined){
106
+ // With no policy a row names its owner itself: a tagged row's `owner`, or a piece row's `ownerId` (Nalati's bake,
107
+ // SERVER-PARITY SS10b): `piece:<id>` as written, a `declared:` id by its name, the one a script looks up.
108
+ const named=solid.ownerId===undefined?null:solid.ownerId.startsWith('declared:')?solid.ownerId.slice('declared:'.length):solid.ownerId;
109
+ const owner=policy===undefined?solid.owner??named:solid.ownerId===undefined?null:owners.get(solid.ownerId);
110
+ // A hull or mesh is most of a Rapier heap; a declared owner's solid stays, since a script may look it up. A `piece:`
111
+ // `ownerId` names the page piece a solid stands for (Nalati's bake, SERVER-PARITY SS10b): no script looks it up. A tagged
112
+ // row's own `owner` string is built at once, whatever it reads.
113
+ if(near!==null&&(typeof owner!=='string'||solid.owner===undefined&&solid.ownerId?.startsWith('piece:')===true)&&solid.enabled!==false&&(solid.shape===9||solid.shape===6)&&solid.points!==undefined){
109
114
  near.hold({x:solid.at[0],z:solid.at[2],reach:solidReach(solid.points),make:physics=>withOwner(host.scope,()=>tagged(physics,solid,owner))});
110
115
  continue;
111
116
  }
@@ -26,7 +26,8 @@ export class NativeReturns {
26
26
  private now = 0;
27
27
  private check = 0;
28
28
  private readonly host: SimHost;
29
- constructor(host: SimHost, bodies: ReadonlyMap<string, ReturnBody>, hunt: StalkerBrain<HuntBody>, input: unknown) {
29
+ /** `reserved`: a body its owner brings back itself (a wake fight's captain, SC10), never owed as a roster body. */
30
+ constructor(host: SimHost, bodies: ReadonlyMap<string, ReturnBody>, hunt: StalkerBrain<HuntBody>, input: unknown, reserved: (id: string) => boolean = () => false) {
30
31
  this.host = host;
31
32
  this.rows = v.parse(NativeReturnRowsSchema, input);
32
33
  this.queue = new RespawnQueue(this.rows.rules, this.rows.outOfSight,
@@ -38,13 +39,15 @@ export class NativeReturns {
38
39
  };
39
40
  host.events.on('actor.died', ({ actor }) => {
40
41
  const body = [...bodies.values()].find(row => row.actor?.combatActor() === actor), native = body?.actor;
41
- if (body === undefined || native === null || native === undefined || !(this.queue.accepts(body.kind) || host.players.size > 1)) return;
42
+ if (body === undefined || native === null || native === undefined || reserved(body.id) || !(this.queue.accepts(body.kind) || host.players.size > 1 || host.respawn.served)) return;
42
43
  const herd = hunt.herds[body.herd];
43
44
  owe(body.kind, body.variant, body.herd, herd?.cx ?? native.position.x, herd?.cz ?? native.position.z, body.id);
44
45
  }, host.scope);
46
+ // SC10: a cell asleep with nobody in it: what is owed comes due as if the clock had run, and nobody near brings it sooner
47
+ host.events.on('world.slept', ({ seconds }) => { this.now += seconds; this.check += seconds; }, host.scope);
45
48
  // J108: a tame leaves its spot empty on this roster too. Only a room owes it: one player's world stays as it was.
46
49
  host.events.on('creature.tamed', ({ kind, variant, herd, x, z, id }) => {
47
- if (host.players.size > 1 && bodies.has(id)) owe(kind, variant, herd, x, z, id);
50
+ if ((host.players.size > 1 || host.respawn.served) && bodies.has(id)) owe(kind, variant, herd, x, z, id);
48
51
  }, host.scope);
49
52
  }
50
53
  /** At most one bounded queue scan per declared interval; retry entries keep
@@ -180,7 +180,7 @@ export function installPopulationRoster(host: SimHost, ports: PopulationRosterPo
180
180
 
181
181
  // J109, J108: a room's herds fill again; one player's stay as they fell, and their saves never carry this row
182
182
  const REFILL_STATE = `${ROSTER_STEP}.refill`, room = (): readonly PlayerSim[] => [...host.players.values()];
183
- const refill = new CreatureRefill({ players: room, room: () => BODY_COUNT - list.filter(body => body.actor.alive).length,
183
+ const refill = new CreatureRefill({ players: room, served: () => host.respawn.served, room: () => BODY_COUNT - list.filter(body => body.actor.alive).length,
184
184
  random: () => host.rng.stream('spawn').next(), spawn: ({ kind, variant, herd, x, z, from }, yaw) => {
185
185
  const fallen = list.find(body => body.id === from)?.actor, group = hunt.herds[herd];
186
186
  if (fallen?.alive === false) retire(fallen);
@@ -190,13 +190,14 @@ export function installPopulationRoster(host: SimHost, ports: PopulationRosterPo
190
190
  const at = fallen === undefined ? -1 : group?.members.indexOf(fallen) ?? -1;
191
191
  if (at === -1) group?.members.push(a); else if (group !== undefined) group.members[at] = a;
192
192
  } });
193
+ host.events.on('world.slept', ({ seconds }) => { refill.slept(seconds); }, host.scope);
193
194
  host.events.on('actor.died', ({ actor }) => {
194
- if (host.players.size <= 1) return;
195
+ if (host.players.size <= 1 && !host.respawn.served) return;
195
196
  const a = list.find(body => body.actor.combatActor() === actor)?.actor, group = a === undefined ? undefined : hunt.herds[a.herd];
196
197
  if (a !== undefined && group !== undefined) refill.left({ kind: a.kind, variant: a.variant, herd: a.herd, x: group.cx, z: group.cz, from: a.entityId });
197
198
  }, host.scope);
198
199
  host.events.on('creature.tamed', tamed => {
199
- if (host.players.size > 1 && list.some(body => body.id === tamed.id)) refill.left({ ...tamed, from: tamed.id });
200
+ if ((host.players.size > 1 || host.respawn.served) && list.some(body => body.id === tamed.id)) refill.left({ ...tamed, from: tamed.id });
200
201
  }, host.scope);
201
202
  host.onStep(ROSTER_STEP, dt => {
202
203
  cadence.observe(dt); continuation.advance(dt); cadence.decide();
@@ -224,6 +225,7 @@ export function installPopulationRoster(host: SimHost, ports: PopulationRosterPo
224
225
  herdOwners();
225
226
  },
226
227
  });
228
+ host.events.on('world.slept', ({ seconds }) => { refill.slept(seconds); }, host.scope);
227
229
  // a restoring install: the saved list's live spawns from the host's own recipes, in order (a body retired in play leaves it)
228
230
  const saved = ports.saved, keeper = saved === undefined ? undefined : v.parse(Saved, saved.adapters.find(adapter => adapter.id === ROSTER_STEP)?.state);
229
231
  if (saved?.adapters.some(adapter => adapter.id === REFILL_STATE) === true) host.adapters.set(REFILL_STATE, refill.state);
@@ -1,4 +1,5 @@
1
1
  import { actRoutes } from '@wildshard/engine/sim/actRoutes';
2
+ import { questBooks } from '@wildshard/engine/quest/players';
2
3
  import type { SimHost } from '@wildshard/engine/sim';
3
4
  import { itemPickupFloor, ITEM_PICKUP_HOVER } from '@wildshard/engine/world/interact/pickup';
4
5
  import { pickPrompt } from '@wildshard/engine/world/interact/prompts';
@@ -10,24 +11,34 @@ const REACH_EYE = 1.68;
10
11
  const PROMPT_ABOVE = 0.5, PROMPT_RADIUS = 1.8;
11
12
  type Body = EliteCoreActor & { readonly position: { readonly x: number; readonly y: number; readonly z: number } };
12
13
 
14
+ /** SC10: the flag in each player's own book that says they took this lair's skin, in a served world. */
15
+ export const eliteSkinFlag = (id: string): string => `elite.${id}.skin`;
16
+
13
17
  /**
14
18
  * A first kill's orb on the server (J130). The rules say a lair's skin is untaken as it falls; this lays the orb out on the lair's
15
19
  * row, and a press in reach takes it. What the skin does to what's in hand is the page's, as a boss's is: the server keeps that it
16
20
  * went, so the next kill drops none.
21
+ *
22
+ * SERVER-CELLS SC10 (J328): a served world is never rebuilt, so there the skin is each player's own: a kill lays the orb out while a
23
+ * player present has not taken it, a press takes it for the presser (a flag in their own book, which goes with their save), and an
24
+ * owner's press is refused. The lair's world record (`skinTaken`) is a page's or a tape's alone.
17
25
  */
18
26
  export function eliteDrops<S extends EliteCoreScript<Body>>(host: SimHost): { readonly hooks: EliteCoreHooks<S>; readonly bind: (core: EliteCore<S>) => void } {
19
27
  const routes = actRoutes(host);
20
28
  let core: EliteCore<S> | null = null;
21
- return { bind: owner => { core = owner; }, hooks: { fell: (entry, first) => {
22
- const { animal, def } = entry.script;
23
- if (!first || animal === null || def.drop === undefined || def.drop.skin === null) return;
29
+ const owns = (player: string, id: string): boolean => { const books = questBooks(host), flag = eliteSkinFlag(id); books.claim([flag]); return books.of(player).flags.has(flag); };
30
+ const lacking = (id: string): boolean => [...host.players.keys()].some(player => !host.parked.has(player) && !owns(player, id));
31
+ return { bind: owner => { core = owner; host.events.on('world.slept', ({ seconds }) => { owner.slept(seconds); }, host.scope); }, hooks: { fell: (entry, first) => {
32
+ const { animal, def } = entry.script, served = host.respawn.served;
33
+ if (animal === null || def.drop === undefined || def.drop.skin === null || !(served ? lacking(def.id) : first)) return;
24
34
  const at = itemPickupFloor(host.physics, animal.position);
25
35
  entry.drop = { x: at.x, y: at.y + ITEM_PICKUP_HOVER, z: at.z };
26
36
  routes.claims.set(`${def.id}.reward`, player => {
27
37
  const feet = host.players.get(player)?.position, { drop } = entry;
28
- if (feet === undefined || drop === null) return;
38
+ if (feet === undefined || drop === null || (served && owns(player, def.id))) return;
29
39
  if (pickPrompt([{ position: { x: drop.x, y: drop.y + PROMPT_ABOVE, z: drop.z }, radius: PROMPT_RADIUS }], { x: feet.x, y: feet.y + REACH_EYE, z: feet.z }, host.physics) === undefined) return;
30
40
  entry.drop = null;
41
+ if (served) { questBooks(host).of(player).flags.set(eliteSkinFlag(def.id)); return; }
31
42
  const saved = core?.record(def.id);
32
43
  if (saved !== undefined) saved.skinTaken = true;
33
44
  core?.save();
@@ -37,7 +37,7 @@ export function installNativeChapterDirector(host: SimHost, director: Awaited<Re
37
37
  if (!['flag', 'phase', 'cue', 'reward'].includes(effect.kind)) throw new Error('Native chapter requires closed native effects');
38
38
  }
39
39
  const population = policy.wake === undefined ? null : mixedPopulation(host, policy.wake.population);
40
- const encounter = policy.wake === undefined ? null : installWakeBoss(host, policy.wake.encounter, policy.wake.placement);
40
+ const encounter = policy.wake === undefined || population === null ? null : installWakeBoss(host, policy.wake.encounter, policy.wake.placement, population.retireCaptain);
41
41
  const reward = policy.reward === undefined ? null : installNativeQuestChannels(host, policy.reward, { started: false, completed: false });
42
42
  const leadBody = host.players.get(books.lead.player); if (leadBody === undefined) throw new Error('Native chapter requires its player');
43
43
  const timeline = new ChapterClock(host.scope, director, rows, host.flags,
@@ -475,7 +475,11 @@ export function installNativeQuestComposition(host: SimHost, ports: NativeQuestC
475
475
  value => ammunition.prepareRestore(v.parse(v.optional(NativeAmmunitionSavedSchema), value)));
476
476
  const keys = new Set<string>(rows.saved.snapshot);
477
477
  if (rows.saved.snapshot.some(key => !parts.has(key))) throw new Error('Native saved role has no mechanic');
478
- host.onStep(rows.step, dt => { for (const phase of rows.phases) need(phases.get(phase), 'phase')(dt); secret?.(dt); countSeatFeats(); }, {
478
+ host.onStep(rows.step, dt => {
479
+ for (const phase of rows.phases) need(phases.get(phase), 'phase')(dt); secret?.(dt); countSeatFeats();
480
+ // SC10 (J328): a long-lived world forgets the purchase lines of those who left (their goods are in their own save)
481
+ if (purchases.size > 0) for (const player of purchases.keys()) if (!host.players.has(player)) purchases.delete(player);
482
+ }, {
479
483
  snapshot: () => entry.saved.encode(Object.fromEntries(rows.saved.snapshot.flatMap(key => {
480
484
  const value = need(parts.get(key), 'saved role').capture(); return value === undefined ? [] : [[key, value]];
481
485
  }))),
@@ -72,6 +72,8 @@ interface TamingSeat {
72
72
  readonly tick: (dt: number, read: boolean) => void;
73
73
  readonly shake: number; readonly roll: number;
74
74
  readonly holdOffer: (held: boolean) => void; readonly whistle: () => void;
75
+ /** SC5 (J328): its player left the room: the bodies it bonded go too, or a grid cell that never starts over gathers them past 64. */
76
+ readonly release: () => void;
75
77
  readonly save: () => { [Key in keyof v.InferOutput<typeof SessionSaved>]: v.InferOutput<typeof SessionSaved>[Key] };
76
78
  readonly load: (saved: v.InferOutput<typeof SessionSaved>, horses: readonly AnimalSim[]) => void;
77
79
  }
@@ -110,6 +112,10 @@ export function installNativeTaming(host: SimHost, context: NativeTamingContext,
110
112
  const mounted = mountedPlayerOf(host, player.id); if (mounted === undefined) throw new Error('Missing native mounted owner');
111
113
  let bond: string | null = null, pitch = 0, offer = false, heldOffer = false, calling = 0, lean = 0, shake = 0, roll = 0;
112
114
  const camera = new Vector3(), eye = new Vector3(), hurtDir = new Vector3(), mine = new Set<string>();
115
+ const retireBonded = (a: AnimalSim): void => {
116
+ mine.delete(a.entityId); creatures.retire(a.entityId); poses.delete(a.entityId);
117
+ const at = poseRows.indexOf(a); if (at === -1) throw new Error('Missing bonded pose'); poseRows.splice(at, 1);
118
+ };
113
119
  const law = new TamingSession<AnimalSim, HerdBrain<AnimalSim>>({
114
120
  profile: rows.binding,
115
121
  programs: rows.programs,
@@ -124,10 +130,7 @@ export function installNativeTaming(host: SimHost, context: NativeTamingContext,
124
130
  hud: { get offer() { return offer; }, get lean() { return lean; } }, herds: () => herds, rest: rows.rest,
125
131
  wind: () => wind, random: () => host.rng.stream('ai').next(),
126
132
  spawnBonded: (x, z, yaw, upgraded) => { const a = creatures.spawn(x, z, yaw, upgraded, mine.size); mine.add(a.entityId); addPose(a); return a; },
127
- hideStallion: a => { creatures.hide(a.entityId); }, retireBonded: a => {
128
- mine.delete(a.entityId); creatures.retire(a.entityId); poses.delete(a.entityId);
129
- const at = poseRows.indexOf(a); if (at === -1) throw new Error('Missing bonded pose'); poseRows.splice(at, 1);
130
- }, hurt: amount => {
133
+ hideStallion: a => { creatures.hide(a.entityId); }, retireBonded: a => { retireBonded(a); }, hurt: amount => {
131
134
  host.combat.hit({ source: 'env', sourceTags: ['env.ride'], target: player.health, amount, throughWalls: true,
132
135
  point: player.position, dir: hurtDir, cause: { kind: 'env.ride', label: rows.thrownLabel, text: rows.thrownLabel } });
133
136
  },
@@ -157,7 +160,8 @@ export function installNativeTaming(host: SimHost, context: NativeTamingContext,
157
160
  return taming;
158
161
  };
159
162
  const originalUpdate = law.update.bind(law);
160
- const session: TamingSeat = { player, law, get shake() { return shake; }, get roll() { return roll; }, holdOffer: held => { heldOffer = held; }, whistle: () => {
163
+ const session: TamingSeat = { player, law, get shake() { return shake; }, get roll() { return roll; }, holdOffer: held => { heldOffer = held; },
164
+ release: () => { for (const id of mine) { const a = poseRows.find(row => row.entityId === id); if (a === undefined) mine.delete(id); else retireBonded(a); } }, whistle: () => {
161
165
  const horse = law.companion;
162
166
  if (!mounted.mounted && horse !== null && horse.mem['whistle'] === 1 && mounted.canRide(horse.entityId) && horse.position.distanceTo(player.position) < 150) calling = 30;
163
167
  }, tick: (dt, read) => {
@@ -221,7 +225,7 @@ export function installNativeTaming(host: SimHost, context: NativeTamingContext,
221
225
  return best;
222
226
  };
223
227
  law.update = dt => {
224
- for (const [id, session] of sessions) if (host.players.get(id) !== session.player) sessions.delete(id);
228
+ for (const [id, session] of sessions) if (host.players.get(id) !== session.player) { session.release(); sessions.delete(id); }
225
229
  // Trust is the herd's: one voice speaks to it, the wild session closest to a stallion, or a far player would talk it down.
226
230
  const heard = sessions.size < 2 ? null : closestToWild();
227
231
  if (heard === null || first.law.phase !== 'wild' || heard === first) first.tick(dt, true);
@@ -18,16 +18,17 @@ export function installWildRefill(host: SimHost, mounts: BondedMountRoster, herd
18
18
  id: string, saved?: Readonly<Omit<SimSnapshot, 'physics'>>): (dt: number) => void {
19
19
  const state = `${id}.refill`;
20
20
  const herdOf = (actor: AnimalSim): HerdBrain<AnimalSim> | undefined => herds().find(row => row.members.includes(actor)) ?? herds()[0];
21
- const refill = new CreatureRefill({ players: () => [...host.players.values()], room: () => mounts.hidden.size,
21
+ const refill = new CreatureRefill({ players: () => [...host.players.values()], room: () => mounts.hidden.size, served: () => host.respawn.served,
22
22
  random: () => host.rng.stream('spawn').next(), spawn: ({ from, x, z }, yaw) => {
23
23
  const actor = host.entities.get(from), herd = actor === undefined ? undefined : herdOf(actor);
24
24
  if (actor === undefined || herd === undefined) return;
25
25
  mounts.reveal(from, x, z, yaw);
26
26
  herd.adoptStallion(actor); herd.addTrust(-100);
27
27
  } });
28
+ host.events.on('world.slept', ({ seconds }) => { refill.slept(seconds); }, host.scope);
28
29
  if (saved?.adapters.some(row => row.id === state) === true) host.adapters.set(state, refill.state);
29
30
  return dt => {
30
- if (host.players.size > 1) for (const hidden of mounts.hidden) {
31
+ if (host.players.size > 1 || host.respawn.served) for (const hidden of mounts.hidden) {
31
32
  if (refill.pending.some(entry => entry.from === hidden)) continue;
32
33
  const actor = host.entities.get(hidden), herd = actor === undefined ? undefined : herdOf(actor);
33
34
  if (actor !== undefined && herd !== undefined) refill.left({ kind: actor.kind, variant: actor.variant, herd: actor.herd, x: herd.cx, z: herd.cz, from: hidden });
@@ -76,8 +76,10 @@ const Saved = v.strictObject({ version: v.picklist([1, 2]), boss: Boss, fight: v
76
76
  * have this shape.
77
77
  */
78
78
  export function installBossRow(host: SimHost, spec: BossRowSpec): { boss: BossBrain; party: BossContenders; bounty: BossBounty; summon: () => void; locked: () => boolean } {
79
- const party = new BossContenders(host.players, point => spec.script.inArena(point), (player, position, yaw) => { player.position.copy(position); player.yaw = yaw; spec.returned?.(player); });
79
+ const party = new BossContenders(host.players, point => spec.script.inArena(point), (player, position, yaw) => { player.position.copy(position); player.yaw = yaw; spec.returned?.(player); },
80
+ { served: () => host.respawn.served, rearm: spec.armed === true });
80
81
  const bounty = new BossBounty(host, spec.body, spec.step);
82
+ host.events.on('world.slept', ({ seconds }) => { party.slept(seconds); }, host.scope);
81
83
  const ports = { events: host.events, player: party.player,
82
84
  lockInput: (on: boolean) => { if (actRoutes(host).introLocks === true) for (const player of host.players.values()) if (!on || spec.script.inArena(player.position)) player.moveScale = on ? 0 : 1; },
83
85
  skipHeld: () => actRoutes(host).skipHeld, respawn: party.respawn, faceToward: party.faceToward,
@@ -93,7 +95,7 @@ export function installBossRow(host: SimHost, spec: BossRowSpec): { boss: BossBr
93
95
  if (spec.armed === true) boss.arm();
94
96
  host.onStep(spec.step, dt => {
95
97
  const body = spec.body(); if (body !== null) host.focusOn(body.position);
96
- party.observe(boss);
98
+ party.observe(boss, dt);
97
99
  boss.update(dt, host.clock.now);
98
100
  }, {
99
101
  snapshot: () => { const { engaged } = party, { earned } = bounty; return JSON.stringify({ version: spec.stages === undefined ? 1 : 2, boss: boss.snapshot(), fight: spec.fight.snapshot(), ...(engaged === 0 ? {} : { engaged }), ...(earned.length === 0 ? {} : { earners: earned }) }); },
@@ -156,6 +156,8 @@ export function installHomeKeeper(host: SimHost, spec: HomeKeeperSpec, saved?: R
156
156
  const freeBody = (body: Body): void => { if (body.actor) { holders.delete(body.actor); host.retire(body.id); body.actor = null; body.brain = null; } };
157
157
  const respawn = (home: Home): void => { home.wait = 0; drawBody(home); };
158
158
  host.events.on('actor.died', ({ actor }) => { const home = homes.find(h => h.actor?.combatActor() === actor); if (home) home.wait = home.respawn; }, host.scope);
159
+ // SC10: a cell asleep with nobody in it: a fallen home's wait spends the time (it still respawns on its next tick, never asleep)
160
+ host.events.on('world.slept', ({ seconds }) => { for (const home of homes) if (home.wait > 0) home.wait = Math.max(Number.MIN_VALUE, home.wait - seconds); }, host.scope);
159
161
  host.onStep(step, dt => {
160
162
  // A boss's fight ends on blows, never on the plane: its flight follows a player down, and a fall would pay it out unstruck.
161
163
  // A held boss is a home body: under the plane it goes back to its anchor, never dies of it (HS3).
@@ -330,7 +332,7 @@ export function createNativeCreatureRoster<B extends NativeCreatureSlot>(host: S
330
332
  /** Identity lifecycle above the native body map, including dormant prewarm and permanent retirement. */
331
333
  identities: NativeActors<HuntBody>;
332
334
  /** Bind declared return rules to this roster's real identities and death events. */
333
- returns: (rows: unknown) => NativeReturns;
335
+ returns: (rows: unknown, reserved?: (id: string) => boolean) => NativeReturns;
334
336
  /** Advance native charge motion and report whether an owned live policy may move. */
335
337
  beforeBody: (id: string, dt: number) => boolean;
336
338
  /** Integrate the admitted pose, charge contact and hunted-body clearance in order. */
@@ -478,7 +480,7 @@ export function createNativeCreatureRoster<B extends NativeCreatureSlot>(host: S
478
480
  const level = saved.entities.find(entity => entity.id === item.id)?.state.flags.levelGround;
479
481
  return materialize(item, item.recipe, level ?? found.structure);
480
482
  };
481
- const returns = (input: unknown): NativeReturns => new NativeReturns(host, byId, hunt, input);
483
+ const returns = (input: unknown, reserved?: (id: string) => boolean): NativeReturns => new NativeReturns(host, byId, hunt, input, reserved);
482
484
  let poseNear = false;
483
485
  const beforeBody = (id: string, dt: number): boolean => {
484
486
  const actor = byId.get(id)?.actor;
@@ -23,7 +23,7 @@ import { simPlayerCommand, MAX_TICK_SNAPSHOT_CHARS, type HeadlessEffect, type He
23
23
  import { headlessSections } from '../../../shared/host/headlessSections';
24
24
  import { scriptAdmissionRows } from '@wildshard/format/scriptContract';
25
25
  import { validateShardfileAssets } from '@wildshard/format/assetAdmission';
26
- import { offlineMemoryAdmission, prepareAssetDecoders } from '@wildshard/format/product';
26
+ import { offlineMemoryAdmission, prepareAssetDecoders } from '@wildshard/format/shardfileAssets';
27
27
  import { leadCommands, leadPlayer } from '@wildshard/engine/sim/leadPlayer';
28
28
 
29
29
  await runTickWorker(async raw => {