Private
Public Access
1
0
Files
star-wars-wild-space/server/worldSeed.js
2026-03-29 11:16:46 +02:00

18 lines
635 B
JavaScript

/**
* One world seed per UTC-aligned period: floor(utcUnixSeconds / rotationSeconds).
* Changing the slot triggers a full grid wipe on the server.
*/
export function computeWorldSeedState(rotationSeconds) {
const rot = Math.max(60, Math.floor(rotationSeconds));
const nowSec = Math.floor(Date.now() / 1000);
const slot = Math.floor(nowSec / rot);
const periodStart = slot * rot;
const periodEnd = periodStart + rot;
return {
worldSeed: `swg-${slot}`,
seedSlot: slot,
seedPeriodEndsAtUtc: new Date(periodEnd * 1000).toISOString(),
seedPeriodStartsAtUtc: new Date(periodStart * 1000).toISOString(),
};
}