From aee98e15d7cb9634a198c2960a2cbe52ee43b1e4 Mon Sep 17 00:00:00 2001 From: hided62 Date: Sat, 25 Jul 2026 18:40:12 +0000 Subject: [PATCH] test: trace monthly NPC registration --- .../fixtures/monthly_reg_neutral_npc.json | 35 +++++++++++++++++ hwe/compare/fixtures/monthly_reg_npc.json | 36 +++++++++++++++++ hwe/compare/monthly_event_trace.php | 39 +++++++++++++------ 3 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 hwe/compare/fixtures/monthly_reg_neutral_npc.json create mode 100644 hwe/compare/fixtures/monthly_reg_npc.json diff --git a/hwe/compare/fixtures/monthly_reg_neutral_npc.json b/hwe/compare/fixtures/monthly_reg_neutral_npc.json new file mode 100644 index 00000000..7d57f7a4 --- /dev/null +++ b/hwe/compare/fixtures/monthly_reg_neutral_npc.json @@ -0,0 +1,35 @@ +{ + "action": "RegNeutralNPC", + "args": [ + 0, + "등록재야", + null, + 0, + 33, + 45, + 55, + 65, + 180, + 245, + null, + "무쌍", + "" + ], + "setup": { + "syncEnvironment": true + }, + "environment": { + "year": 200, + "month": 1, + "startyear": 190, + "turnterm": 10, + "turntime": "0200-01-01 00:00:00", + "show_img_level": 3, + "fiction": [0] + }, + "observe": { + "generalIds": [], + "cityIds": [33], + "nationIds": [1] + } +} diff --git a/hwe/compare/fixtures/monthly_reg_npc.json b/hwe/compare/fixtures/monthly_reg_npc.json new file mode 100644 index 00000000..1597f72a --- /dev/null +++ b/hwe/compare/fixtures/monthly_reg_npc.json @@ -0,0 +1,36 @@ +{ + "action": "RegNPC", + "args": [ + 0, + "등록장수", + null, + 0, + 33, + 60, + 50, + 40, + 7, + 186, + 240, + null, + "인덕", + "등록 대사" + ], + "setup": { + "syncEnvironment": true + }, + "environment": { + "year": 200, + "month": 1, + "startyear": 190, + "turnterm": 10, + "turntime": "0200-01-01 00:00:00", + "show_img_level": 3, + "fiction": [0] + }, + "observe": { + "generalIds": [], + "cityIds": [33], + "nationIds": [1] + } +} diff --git a/hwe/compare/monthly_event_trace.php b/hwe/compare/monthly_event_trace.php index b4051d9d..bc37147e 100644 --- a/hwe/compare/monthly_event_trace.php +++ b/hwe/compare/monthly_event_trace.php @@ -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(