Files
star-wars-wild-space/server/worldSeed.js
T
2026-04-03 14:25:19 +02:00

21 lines
787 B
JavaScript

/**
* One world seed per epoch-relative period.
* slot = floor((nowSec - epochSec) / rotationSeconds).
* Changing timing config resets epochSec, which resets the slot to 0.
*/
export function computeWorldSeedState(rotationSeconds, epochSec) {
const rot = Math.max(1, Math.floor(rotationSeconds));
const epoch = Math.max(0, Math.floor(epochSec));
const nowSec = Math.floor(Date.now() / 1000);
const elapsed = Math.max(0, nowSec - epoch);
const slot = Math.floor(elapsed / rot);
const periodStart = epoch + slot * rot;
const periodEnd = periodStart + rot;
return {
worldSeed: `swg-${epoch}-${slot}`,
seedSlot: slot,
seedPeriodEndsAtUtc: new Date(periodEnd * 1000).toISOString(),
seedPeriodStartsAtUtc: new Date(periodStart * 1000).toISOString(),
};
}