test: trace monthly NPC registration
This commit is contained in:
@@ -186,6 +186,8 @@ function comparisonMonthlyEventTraceMain(): void
|
||||
'ProcessWarIncome',
|
||||
'CreateAdminNPC',
|
||||
'CreateManyNPC',
|
||||
'RegNPC',
|
||||
'RegNeutralNPC',
|
||||
];
|
||||
if (!in_array($actionName, $supportedActions, true)) {
|
||||
throw new \InvalidArgumentException('unsupported monthly action');
|
||||
@@ -276,10 +278,13 @@ function comparisonMonthlyEventTraceMain(): void
|
||||
throw new \InvalidArgumentException('ProcessSemiAnnual requires resource');
|
||||
}
|
||||
$action = new $actionClass($resource);
|
||||
} elseif ($actionName === 'CreateManyNPC') {
|
||||
} elseif (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC'], true)) {
|
||||
$args = $request['args'] ?? [];
|
||||
if (!is_array($args) || count($args) > 2) {
|
||||
throw new \InvalidArgumentException('CreateManyNPC args must be an array with at most two entries');
|
||||
if (!is_array($args)) {
|
||||
throw new \InvalidArgumentException("{$actionName} args must be an array");
|
||||
}
|
||||
if ($actionName === 'CreateManyNPC' && count($args) > 2) {
|
||||
throw new \InvalidArgumentException('CreateManyNPC args must have at most two entries');
|
||||
}
|
||||
$action = new $actionClass(...$args);
|
||||
} else {
|
||||
@@ -299,19 +304,29 @@ function comparisonMonthlyEventTraceMain(): void
|
||||
$actionEnvironment['killturn'] = $killturn;
|
||||
$actionEnvironment['turnterm'] = $turnterm;
|
||||
}
|
||||
if ($actionName === 'CreateManyNPC') {
|
||||
if (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC'], true)) {
|
||||
$turnterm = $environment['turnterm'] ?? null;
|
||||
$turntime = $environment['turntime'] ?? null;
|
||||
if (!is_int($turnterm) || $turnterm <= 0 || !is_string($turntime)) {
|
||||
throw new \InvalidArgumentException('CreateManyNPC requires positive turnterm and string turntime');
|
||||
$showImgLevel = $environment['show_img_level'] ?? 3;
|
||||
$fiction = $environment['fiction'] ?? [0];
|
||||
if (
|
||||
!is_int($turnterm)
|
||||
|| $turnterm <= 0
|
||||
|| !is_string($turntime)
|
||||
|| !is_int($showImgLevel)
|
||||
|| !is_array($fiction)
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
"{$actionName} requires positive turnterm, string turntime, integer show_img_level, and array fiction",
|
||||
);
|
||||
}
|
||||
$actionEnvironment += [
|
||||
'turnterm' => $turnterm,
|
||||
'turntime' => $turntime,
|
||||
'show_img_level' => 3,
|
||||
'stored_icons' => [],
|
||||
'icon_path' => '.',
|
||||
'fiction' => [0],
|
||||
'show_img_level' => $showImgLevel,
|
||||
'stored_icons' => $environment['stored_icons'] ?? [],
|
||||
'icon_path' => $environment['icon_path'] ?? '.',
|
||||
'fiction' => $fiction,
|
||||
];
|
||||
}
|
||||
$action->run($actionEnvironment);
|
||||
@@ -321,7 +336,7 @@ function comparisonMonthlyEventTraceMain(): void
|
||||
$after = comparisonTurnStateSnapshot($snapshotRequest);
|
||||
$afterDetails = comparisonMonthlyDetails($snapshotRequest['observe'], $worldHistoryAfterId);
|
||||
$createdGenerals = [];
|
||||
if ($actionName === 'CreateManyNPC') {
|
||||
if (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC'], true)) {
|
||||
foreach ($db->query('SELECT * FROM general WHERE no > %i ORDER BY no', $generalIdBeforeAction) as $row) {
|
||||
$generalId = (int)$row['no'];
|
||||
$turnRows = $db->query(
|
||||
@@ -385,7 +400,7 @@ function comparisonMonthlyEventTraceMain(): void
|
||||
'after' => $after,
|
||||
'afterDetails' => $afterDetails,
|
||||
];
|
||||
if ($actionName === 'CreateManyNPC') {
|
||||
if (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC'], true)) {
|
||||
$response['createdGenerals'] = $createdGenerals;
|
||||
}
|
||||
echo json_encode(
|
||||
|
||||
Reference in New Issue
Block a user