fix(parity): preserve legacy monthly turn ordering

This commit is contained in:
2026-08-15 09:40:14 +00:00
parent 47e629eb4b
commit b9e45c6e76
26 changed files with 393 additions and 58 deletions
@@ -1,4 +1,4 @@
import { JosaUtil, LiteHashDRBG, RandUtil, asRecord } from '@sammo-ts/common';
import { GAME_TICKS_PER_TURN, JosaUtil, LiteHashDRBG, RandUtil, asRecord } from '@sammo-ts/common';
import { LogCategory, LogFormat, LogScope, type TurnCommandEnv } from '@sammo-ts/logic';
import { simpleSerialize } from '@sammo-ts/logic/war/utils.js';
@@ -137,10 +137,12 @@ const buildNpc = (options: {
}
const turnSecond = rng.nextRangeInt(0, 60 * turnMinutes - 1);
const turnFraction = rng.nextRangeInt(0, 999_999);
// core DB는 millisecond precision이므로 레거시 microsecond 값을 내림해
// 저장한다. 먼 과거 연도에서 IEEE-754 덧셈이 반올림하지 않도록 먼저
// 정수화한다.
const turnTime = new Date(environment.turnTime.getTime() + turnSecond * 1_000 + Math.floor(turnFraction / 1_000));
const ticksPerSecond = GAME_TICKS_PER_TURN / world.getState().tickSeconds;
const turnTick =
world.dateToGameTick(environment.turnTime) +
turnSecond * ticksPerSecond +
Math.floor((turnFraction * ticksPerSecond) / 1_000_000);
const turnTime = world.gameTickToDate(turnTick);
const killturn = (deadYear - environment.year) * 12 + rng.nextRangeInt(0, 11) + environment.month - 1;
const id = world.getNextGeneralId();
const general: TurnGeneral = {
@@ -181,6 +183,7 @@ const buildNpc = (options: {
},
lastTurn: { command: '휴식' },
turnTime,
turnTick,
recentWarTime: null,
meta: {
killturn,