merge: expose nation command cooldowns
This commit is contained in:
@@ -85,6 +85,36 @@ function comparisonGeneralCooldownSelectors(mixed $value, string $label): array
|
|||||||
return array_values($result);
|
return array_values($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return list<array{nationId: int, actionName: string}> */
|
||||||
|
function comparisonNationCooldownSelectors(mixed $value, string $label): array
|
||||||
|
{
|
||||||
|
if ($value === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (!is_array($value)) {
|
||||||
|
throw new \InvalidArgumentException("{$label} must be an array");
|
||||||
|
}
|
||||||
|
$result = [];
|
||||||
|
foreach ($value as $entry) {
|
||||||
|
if (!is_array($entry)) {
|
||||||
|
throw new \InvalidArgumentException("{$label} entries must be objects");
|
||||||
|
}
|
||||||
|
$nationId = $entry['nationId'] ?? null;
|
||||||
|
$actionName = $entry['actionName'] ?? null;
|
||||||
|
if (!is_int($nationId) || $nationId < 1 || !is_string($actionName) || $actionName === '') {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
"{$label} entries require a positive nationId and non-empty actionName",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$result["{$nationId}:{$actionName}"] = [
|
||||||
|
'nationId' => $nationId,
|
||||||
|
'actionName' => $actionName,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
ksort($result, SORT_STRING);
|
||||||
|
return array_values($result);
|
||||||
|
}
|
||||||
|
|
||||||
/** @param array<string, mixed> $row */
|
/** @param array<string, mixed> $row */
|
||||||
function comparisonPickRow(array $row, array $mapping, array $jsonKeys = []): array
|
function comparisonPickRow(array $row, array $mapping, array $jsonKeys = []): array
|
||||||
{
|
{
|
||||||
@@ -134,6 +164,10 @@ function comparisonTurnStateSnapshot(array $request): array
|
|||||||
$observe['generalCooldowns'] ?? [],
|
$observe['generalCooldowns'] ?? [],
|
||||||
'generalCooldowns',
|
'generalCooldowns',
|
||||||
);
|
);
|
||||||
|
$nationCooldownSelectors = comparisonNationCooldownSelectors(
|
||||||
|
$observe['nationCooldowns'] ?? [],
|
||||||
|
'nationCooldowns',
|
||||||
|
);
|
||||||
if (!is_int($logAfterId) || $logAfterId < 0 || !is_int($messageAfterId) || $messageAfterId < 0) {
|
if (!is_int($logAfterId) || $logAfterId < 0 || !is_int($messageAfterId) || $messageAfterId < 0) {
|
||||||
throw new \InvalidArgumentException('logAfterId and messageAfterId must be non-negative integers');
|
throw new \InvalidArgumentException('logAfterId and messageAfterId must be non-negative integers');
|
||||||
}
|
}
|
||||||
@@ -165,6 +199,18 @@ function comparisonTurnStateSnapshot(array $request): array
|
|||||||
},
|
},
|
||||||
$generalCooldownSelectors,
|
$generalCooldownSelectors,
|
||||||
);
|
);
|
||||||
|
$nationCooldowns = array_map(
|
||||||
|
static function (array $selector) use ($db): array {
|
||||||
|
$nationStorage = KVStorage::getStorage($db, $selector['nationId'], 'nation_env');
|
||||||
|
$nationStorage->resetCache();
|
||||||
|
$value = $nationStorage->getValue("next_execute_{$selector['actionName']}");
|
||||||
|
return [
|
||||||
|
...$selector,
|
||||||
|
'nextAvailableTurn' => is_int($value) ? $value : null,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
$nationCooldownSelectors,
|
||||||
|
);
|
||||||
|
|
||||||
$generals = array_map(
|
$generals = array_map(
|
||||||
static function (array $row): array {
|
static function (array $row): array {
|
||||||
@@ -428,6 +474,7 @@ function comparisonTurnStateSnapshot(array $request): array
|
|||||||
'initMonth' => (int)$worldValues['init_month'],
|
'initMonth' => (int)$worldValues['init_month'],
|
||||||
'develCost' => (int)$worldValues['develcost'],
|
'develCost' => (int)$worldValues['develcost'],
|
||||||
'generalCooldowns' => $generalCooldowns,
|
'generalCooldowns' => $generalCooldowns,
|
||||||
|
'nationCooldowns' => $nationCooldowns,
|
||||||
],
|
],
|
||||||
'generals' => $generals,
|
'generals' => $generals,
|
||||||
'rankData' => $rankData,
|
'rankData' => $rankData,
|
||||||
|
|||||||
Reference in New Issue
Block a user