merge: refresh ng_compare for logical game clock

This commit is contained in:
2026-08-04 12:09:58 +00:00
124 changed files with 2713 additions and 807 deletions
+12 -9
View File
@@ -110,12 +110,12 @@ function comparisonNpcState(): array
* @param array<string, mixed> $case
* @return array<string, mixed>
*/
function comparisonNpcRunCase(array $case, string|int $hiddenSeed, int $owner, string $now): array
function comparisonNpcRunCase(array $case, string|int $hiddenSeed, int $owner, int $now, GameClock $clock): array
{
$db = DB::db();
$db->delete('select_npc_token', '1=1');
$insertReserved = static function (int $reservedOwner, array $reservedIds, string $validUntil) use ($db): void {
$insertReserved = static function (int $reservedOwner, array $reservedIds, int $validUntil) use ($db, $now): void {
if ($reservedIds === []) {
return;
}
@@ -126,7 +126,7 @@ function comparisonNpcRunCase(array $case, string|int $hiddenSeed, int $owner, s
$db->insert('select_npc_token', [
'owner' => $reservedOwner,
'valid_until' => $validUntil,
'pick_more_from' => '2000-01-01 01:00:00',
'pick_more_from' => $now,
'pick_result' => json_encode((object)$reservedPick, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE),
'nonce' => 1,
]);
@@ -140,8 +140,8 @@ function comparisonNpcRunCase(array $case, string|int $hiddenSeed, int $owner, s
$case['expiredReservedIds'] ?? [],
'expiredReservedIds',
);
$expiredAt = (new \DateTimeImmutable($now))->modify('-1 second')->format('Y-m-d H:i:s');
$insertReserved($owner + 1, $reservedIds, '2099-12-31 23:59:59');
$expiredAt = $now - $clock->ticksFromSeconds(1);
$insertReserved($owner + 1, $reservedIds, GameClock::MAX_SAFE_TICK);
$insertReserved($owner + 2, $boundaryReservedIds, $now);
$insertReserved($owner + 3, $expiredReservedIds, $expiredAt);
@@ -156,7 +156,7 @@ function comparisonNpcRunCase(array $case, string|int $hiddenSeed, int $owner, s
$candidates,
$weights,
$db->queryFirstColumn(
'SELECT pick_result FROM select_npc_token WHERE `owner`!=%i AND valid_until >=%s',
'SELECT pick_result FROM select_npc_token WHERE `owner`!=%i AND valid_until >=%i',
$owner,
$now,
),
@@ -176,8 +176,8 @@ function comparisonNpcRunCase(array $case, string|int $hiddenSeed, int $owner, s
if ($hasPreviousToken) {
$db->insert('select_npc_token', [
'owner' => $owner,
'valid_until' => '2099-12-31 23:59:59',
'pick_more_from' => '2000-01-01 01:00:00',
'valid_until' => GameClock::MAX_SAFE_TICK,
'pick_more_from' => $now,
'pick_result' => json_encode((object)$oldPick, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE),
'nonce' => 2,
]);
@@ -259,6 +259,9 @@ if ($date === false || $date->format('Y-m-d H:i:s') !== $now) {
}
$db = DB::db();
$gameStorage = KVStorage::getStorage($db, 'game_env');
$clock = GameClock::fromStorage($gameStorage);
$nowTick = $clock->dateTimeToTick($date);
$db->update('general', ['npc' => 1], '1=1');
$fixtureIds = [];
foreach ($candidateFixtures as $candidate) {
@@ -295,7 +298,7 @@ foreach ($cases as $case) {
if (!is_array($case)) {
throw new \InvalidArgumentException('case must be an object');
}
$results[] = comparisonNpcRunCase($case, $hiddenSeed, $owner, $now);
$results[] = comparisonNpcRunCase($case, $hiddenSeed, $owner, $nowTick, $clock);
}
echo json_encode(